Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile bundled files and typing files #671

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/index.ts
Expand Up @@ -110,7 +110,7 @@ function getLoaderOptions(loader: Webpack) {
}

type ValidLoaderOptions = keyof LoaderOptions;
const validLoaderOptions: ValidLoaderOptions[] = ['silent', 'logLevel', 'logInfoToStdOut', 'instance', 'compiler', 'configFile', 'transpileOnly', 'ignoreDiagnostics', 'errorFormatter', 'colors', 'compilerOptions', 'appendTsSuffixTo', 'appendTsxSuffixTo', 'entryFileCannotBeJs' /* DEPRECATED */, 'happyPackMode', 'getCustomTransformers'];
const validLoaderOptions: ValidLoaderOptions[] = ['silent', 'logLevel', 'logInfoToStdOut', 'instance', 'compiler', 'configFile', 'transpileOnly', 'ignoreDiagnostics', 'errorFormatter', 'colors', 'compilerOptions', 'appendTsSuffixTo', 'appendTsxSuffixTo', 'entryFileCannotBeJs', 'onlyCompileBundledFiles' /* DEPRECATED */, 'happyPackMode', 'getCustomTransformers'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you move /* DEPRECATED */ back to after 'entryFileCannotBeJs?


/**
* Validate the supplied loader options.
Expand Down Expand Up @@ -146,7 +146,8 @@ function makeLoaderOptions(instanceName: string, configFileOptions: Partial<Load
transformers: {},
entryFileCannotBeJs: false,
happyPackMode: false,
colors: true
colors: true,
onlyCompileBundledFiles: false
} as Partial<LoaderOptions>, configFileOptions, loaderOptions);

options.ignoreDiagnostics = arrify(options.ignoreDiagnostics).map(Number);
Expand Down
4 changes: 2 additions & 2 deletions src/instances.ts
Expand Up @@ -5,7 +5,7 @@ import chalk, { Chalk } from 'chalk';

import { makeAfterCompile } from './after-compile';
import { getConfigFile, getConfigParseResult } from './config';
import { EOL } from './constants';
import { EOL, dtsDtsxRegex } from './constants';
import { getCompilerOptions, getCompiler } from './compilerSetup';
import { hasOwnProperty, makeError, formatErrors, registerWebpackErrors } from './utils';
import * as logger from './logger';
Expand Down Expand Up @@ -118,7 +118,7 @@ function successfulTypeScriptInstance(
// Load initial files (core lib files, any files specified in tsconfig.json)
let normalizedFilePath: string;
try {
const filesToLoad = configParseResult.fileNames;
const filesToLoad = loaderOptions.onlyCompileBundledFiles ? configParseResult.fileNames.filter(fileName => dtsDtsxRegex.test(fileName)) : configParseResult.fileNames;
filesToLoad.forEach(filePath => {
normalizedFilePath = path.normalize(filePath);
files[normalizedFilePath] = {
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Expand Up @@ -269,6 +269,7 @@ export interface LoaderOptions {
transpileOnly: boolean;
ignoreDiagnostics: number[];
errorFormatter: (message: ErrorInfo, colors: Chalk) => string;
onlyCompileBundledFiles: boolean;
colors: boolean;
compilerOptions: typescript.CompilerOptions;
appendTsSuffixTo: RegExp[];
Expand Down
3 changes: 3 additions & 0 deletions test/comparison-tests/onlyCompileBundledFiles/app.ts
@@ -0,0 +1,3 @@
import submodule = require('./submodule/submodule');
import externalLib = require('externalLib');
externalLib.doSomething(submodule);
@@ -0,0 +1,71 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};

/******/ // The require function
/******/ function __webpack_require__(moduleId) {

/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;

/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };

/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ // Flag the module as loaded
/******/ module.loaded = true;

/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }


/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;

/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;

/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";

/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

var submodule = __webpack_require__(1);
var externalLib = __webpack_require__(2);
externalLib.doSomething(submodule);


/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {

var externalLib = __webpack_require__(2);
externalLib.doSomething("");
var message = "Hello from submodule";
module.exports = message;


/***/ },
/* 2 */
/***/ function(module, exports) {

module.exports = {
doSomething: function() { }
}

/***/ }
/******/ ]);
@@ -0,0 +1,6 @@
Asset Size Chunks Chunk Names
bundle.js 1.85 kB 0 [emitted] main
chunk {0} bundle.js (main) 318 bytes [rendered]
[0] ./.test/onlyCompileBundledFiles/app.ts 128 bytes {0} [built]
[1] ./.test/onlyCompileBundledFiles/submodule/submodule.ts 135 bytes {0} [built]
[2] ./.test/onlyCompileBundledFiles/lib/externalLib.js 55 bytes {0} [built]
@@ -0,0 +1,71 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};

/******/ // The require function
/******/ function __webpack_require__(moduleId) {

/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;

/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };

/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ // Flag the module as loaded
/******/ module.loaded = true;

/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }


/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;

/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;

/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";

/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

var submodule = __webpack_require__(1);
var externalLib = __webpack_require__(2);
externalLib.doSomething2(submodule);


/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {

var externalLib = __webpack_require__(2);
externalLib.doSomething("");
var message = "Hello from submodule";
module.exports = message;


/***/ },
/* 2 */
/***/ function(module, exports) {

module.exports = {
doSomething: function() { }
}

/***/ }
/******/ ]);
@@ -0,0 +1,6 @@
Asset Size Chunks Chunk Names
bundle.js 1.86 kB 0 [emitted] main
chunk {0} bundle.js (main) 319 bytes [rendered]
[0] ./.test/onlyCompileBundledFiles/app.ts 129 bytes {0} [built]
[1] ./.test/onlyCompileBundledFiles/submodule/submodule.ts 135 bytes {0}
[2] ./.test/onlyCompileBundledFiles/lib/externalLib.js 55 bytes {0}
@@ -0,0 +1,9 @@
Asset Size Chunks Chunk Names
bundle.js 1.86 kB 0 [emitted] main
chunk {0} bundle.js (main) 319 bytes [rendered]
[0] ./.test/onlyCompileBundledFiles/app.ts 129 bytes {0} [built] [1 error]
[1] ./.test/onlyCompileBundledFiles/submodule/submodule.ts 135 bytes {0}
[2] ./.test/onlyCompileBundledFiles/lib/externalLib.js 55 bytes {0}

ERROR in ./.test/onlyCompileBundledFiles/app.ts
(3,13): error TS2339: Property 'doSomething2' does not exist on type 'typeof externalLib'.
@@ -0,0 +1,71 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};

/******/ // The require function
/******/ function __webpack_require__(moduleId) {

/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;

/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };

/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ // Flag the module as loaded
/******/ module.loaded = true;

/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }


/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;

/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;

/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";

/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

var submodule = __webpack_require__(1);
var externalLib = __webpack_require__(2);
externalLib.doSomething(submodule);


/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {

var externalLib = __webpack_require__(2);
externalLib.doSomething("");
var message = "Hello from submodule";
module.exports = message;


/***/ },
/* 2 */
/***/ function(module, exports) {

module.exports = {
doSomething: function() { }
}

/***/ }
/******/ ]);
@@ -0,0 +1,6 @@
Asset Size Chunks Chunk Names
bundle.js 1.85 kB 0 [emitted] main
chunk {0} bundle.js (main) 318 bytes [rendered]
[0] ./.test/onlyCompileBundledFiles/app.ts 128 bytes {0} [built]
[1] ./.test/onlyCompileBundledFiles/submodule/submodule.ts 135 bytes {0}
[2] ./.test/onlyCompileBundledFiles/lib/externalLib.js 55 bytes {0}
@@ -0,0 +1,71 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};

/******/ // The require function
/******/ function __webpack_require__(moduleId) {

/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;

/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };

/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ // Flag the module as loaded
/******/ module.loaded = true;

/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }


/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;

/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;

/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";

/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

var submodule = __webpack_require__(1);
var externalLib = __webpack_require__(2);
externalLib.doSomething(submodule);


/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {

var externalLib = __webpack_require__(2);
externalLib.doSomething("");
var message = "Hello from submodule";
module.exports = message;


/***/ },
/* 2 */
/***/ function(module, exports) {

module.exports = {
doSomething: function() { }
}

/***/ }
/******/ ]);
@@ -0,0 +1,6 @@
Asset Size Chunks Chunk Names
bundle.js 1.85 kB 0 [emitted] main
chunk {0} bundle.js (main) 318 bytes [rendered]
[0] ./.test/onlyCompileBundledFiles/app.ts 128 bytes {0} [built]
[1] ./.test/onlyCompileBundledFiles/submodule/submodule.ts 135 bytes {0} [built]
[2] ./.test/onlyCompileBundledFiles/lib/externalLib.js 55 bytes {0} [built]