From f994a25b2bce19ac90d17755e0085aa03d12cead Mon Sep 17 00:00:00 2001 From: Andrew Lawson Date: Tue, 1 May 2018 22:02:02 -0400 Subject: [PATCH 01/10] Add allowTsInNodeModules loader option. --- src/index.ts | 6 ++++-- src/interfaces.ts | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4397c28bf..31d787d11 100644 --- a/src/index.ts +++ b/src/index.ts @@ -147,7 +147,8 @@ const validLoaderOptions: ValidLoaderOptions[] = [ 'happyPackMode', 'getCustomTransformers', 'reportFiles', - 'experimentalWatchApi' + 'experimentalWatchApi', + 'allowTsInNodeModules' ]; /** @@ -199,7 +200,8 @@ function makeLoaderOptions(instanceName: string, loaderOptions: LoaderOptions) { onlyCompileBundledFiles: false, reportFiles: [], // When the watch API usage stabilises look to remove this option and make watch usage the default behaviour when available - experimentalWatchApi: false + experimentalWatchApi: false, + allowTsInNodeModules: false } as Partial, loaderOptions ); diff --git a/src/interfaces.ts b/src/interfaces.ts index 2cfd5b283..94f0226aa 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -305,6 +305,7 @@ export interface LoaderOptions { | string | (() => typescript.CustomTransformers | undefined); experimentalWatchApi: boolean; + allowTsInNodeModules: boolean; } export interface TSFile { From 6c9cdb95e30db8d54f3fa123fd9ec042c2982299 Mon Sep 17 00:00:00 2001 From: Andrew Lawson Date: Wed, 2 May 2018 14:13:50 -0400 Subject: [PATCH 02/10] Add error text for allowTsInNodeModules option when importing .ts files from node_modules. Tweak existing error text and code style. --- src/index.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 31d787d11..1944bde5a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -69,10 +69,17 @@ function successLoader( : getEmit(rawFilePath, filePath, instance, loader); if (outputText === null || outputText === undefined) { - const additionalGuidance = - filePath.indexOf('node_modules') !== -1 - ? '\nYou should not need to recompile .ts files in node_modules.\nPlease contact the package author to advise them to use --declaration --outDir.\nMore https://github.com/Microsoft/TypeScript/issues/12358' - : ''; + let additionalGuidance: string; + + if (!options.allowTsInNodeModules && filePath.indexOf('node_modules') !== -1) { + additionalGuidance = " By default, ts-loader will not compile .ts files in node_modules.\n" + + "You should not need to recompile .ts files there, but if you really want to, use the allowTsInNodeModules option.\n" + + "See: https://github.com/Microsoft/TypeScript/issues/12358"; + } + else { + additionalGuidance = ""; + } + throw new Error( `Typescript emitted no output for ${filePath}.${additionalGuidance}` ); From bb13166c1859d05d9ffc6897e66b670710b43ece Mon Sep 17 00:00:00 2001 From: Andrew Lawson Date: Wed, 2 May 2018 13:34:39 -0400 Subject: [PATCH 03/10] Update nodeModulesMeaningfulErrorWhenImportingTs test outputs. --- .../expectedOutput-2.8/bundle.js | 2 +- .../expectedOutput-2.8/output.txt | 15 +++++++-------- .../expectedOutput-2.8/bundle.js | 2 +- .../expectedOutput-2.8/output.txt | 12 ++++++------ 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/test/comparison-tests/nodeModulesMeaningfulErrorWhenImportingTs/expectedOutput-2.8/bundle.js b/test/comparison-tests/nodeModulesMeaningfulErrorWhenImportingTs/expectedOutput-2.8/bundle.js index c1758738d..bcaa426ec 100644 --- a/test/comparison-tests/nodeModulesMeaningfulErrorWhenImportingTs/expectedOutput-2.8/bundle.js +++ b/test/comparison-tests/nodeModulesMeaningfulErrorWhenImportingTs/expectedOutput-2.8/bundle.js @@ -90,7 +90,7 @@ eval("\nexports.__esModule = true;\nvar a = __webpack_require__(/*! a */ \"./nod /*! no static exports found */ /***/ (function(module, exports) { -eval("throw new Error(\"Module build failed: Error: Typescript emitted no output for C://source//ts-loader//.test//nodeModulesMeaningfulErrorWhenImportingTs//node_modules//a//index.ts./nYou should not need to recompile .ts files in node_modules./nPlease contact the package author to advise them to use --declaration --outDir./nMore https://github.com/Microsoft/TypeScript/issues/12358/n at successLoader (C://source//ts-loader//dist//index.js:39:15)/n at Object.loader (C://source//ts-loader//dist//index.js:21:12)\");\n\n//# sourceURL=webpack:///./node_modules/a/index.ts?"); +eval("throw new Error(\"Module build failed: Error: Typescript emitted no output for /nodeModulesMeaningfulErrorWhenImportingTs/node_modules/a/index.ts. By default, ts-loader will not compile .ts files in node_modules./nYou should not need to recompile .ts files there, but if you really want to, use the allowTsInNodeModules option./nSee: https://github.com/Microsoft/TypeScript/issues/12358/n at successLoader (/Users/alawson/dev/ts-loader/dist/index.js:45:15)/n at Object.loader (/Users/alawson/dev/ts-loader/dist/index.js:21:12)\");\n\n//# sourceURL=webpack:///./node_modules/a/index.ts?"); /***/ }) diff --git a/test/comparison-tests/nodeModulesMeaningfulErrorWhenImportingTs/expectedOutput-2.8/output.txt b/test/comparison-tests/nodeModulesMeaningfulErrorWhenImportingTs/expectedOutput-2.8/output.txt index 9e93d8e83..5e2ab0d89 100644 --- a/test/comparison-tests/nodeModulesMeaningfulErrorWhenImportingTs/expectedOutput-2.8/output.txt +++ b/test/comparison-tests/nodeModulesMeaningfulErrorWhenImportingTs/expectedOutput-2.8/output.txt @@ -1,14 +1,13 @@ Asset Size Chunks Chunk Names -bundle.js 3.75 KiB main [emitted] main +bundle.js 3.77 KiB main [emitted] main Entrypoint main = bundle.js [./app.ts] 79 bytes {main} [built] -[./node_modules/a/index.ts] 517 bytes {main} [built] [failed] [1 error] +[./node_modules/a/index.ts] 568 bytes {main} [built] [failed] [1 error] ERROR in ./node_modules/a/index.ts -Module build failed: Error: Typescript emitted no output for node_modules\a\index.ts. -You should not need to recompile .ts files in node_modules. -Please contact the package author to advise them to use --declaration --outDir. -More https://github.com/Microsoft/TypeScript/issues/12358 - at successLoader (dist\index.js:39:15) - at Object.loader (dist\index.js:21:12) +Module build failed: Error: Typescript emitted no output for node_modules/a/index.ts. By default, ts-loader will not compile .ts files in node_modules. +You should not need to recompile .ts files there, but if you really want to, use the allowTsInNodeModules option. +See: https://github.com/Microsoft/TypeScript/issues/12358 + at successLoader (dist/index.js:45:15) + at Object.loader (dist/index.js:21:12) @ ./app.ts 3:8-20 \ No newline at end of file diff --git a/test/comparison-tests/validateLoaderOptionNames/expectedOutput-2.8/bundle.js b/test/comparison-tests/validateLoaderOptionNames/expectedOutput-2.8/bundle.js index 34d564b72..f8bf7f615 100644 --- a/test/comparison-tests/validateLoaderOptionNames/expectedOutput-2.8/bundle.js +++ b/test/comparison-tests/validateLoaderOptionNames/expectedOutput-2.8/bundle.js @@ -78,7 +78,7 @@ /*! no static exports found */ /***/ (function(module, exports) { -eval("throw new Error(\"Module build failed: Error: ts-loader was supplied with an unexpected loader option: notRealOption/n/nPlease take a look at the options you are supplying; the following are valid options:/nsilent / logLevel / logInfoToStdOut / instance / compiler / context / configFile / transpileOnly / ignoreDiagnostics / errorFormatter / colors / compilerOptions / appendTsSuffixTo / appendTsxSuffixTo / onlyCompileBundledFiles / happyPackMode / getCustomTransformers / reportFiles / experimentalWatchApi/n/n at validateLoaderOptions (C://source//ts-loader//dist//index.js:103:19)/n at getLoaderOptions (C://source//ts-loader//dist//index.js:66:5)/n at Object.loader (C://source//ts-loader//dist//index.js:15:21)\");\n\n//# sourceURL=webpack:///./app.ts?"); +eval("throw new Error(\"Module build failed: Error: ts-loader was supplied with an unexpected loader option: notRealOption/n/nPlease take a look at the options you are supplying; the following are valid options:/nsilent / logLevel / logInfoToStdOut / instance / compiler / context / configFile / transpileOnly / ignoreDiagnostics / errorFormatter / colors / compilerOptions / appendTsSuffixTo / appendTsxSuffixTo / onlyCompileBundledFiles / happyPackMode / getCustomTransformers / reportFiles / experimentalWatchApi / allowTsInNodeModules/n/n at validateLoaderOptions (/Users/alawson/dev/ts-loader/dist/index.js:110:19)/n at getLoaderOptions (/Users/alawson/dev/ts-loader/dist/index.js:72:5)/n at Object.loader (/Users/alawson/dev/ts-loader/dist/index.js:15:21)\");\n\n//# sourceURL=webpack:///./app.ts?"); /***/ }) diff --git a/test/comparison-tests/validateLoaderOptionNames/expectedOutput-2.8/output.txt b/test/comparison-tests/validateLoaderOptionNames/expectedOutput-2.8/output.txt index 6b4cb8fd5..e5b87bfde 100644 --- a/test/comparison-tests/validateLoaderOptionNames/expectedOutput-2.8/output.txt +++ b/test/comparison-tests/validateLoaderOptionNames/expectedOutput-2.8/output.txt @@ -1,14 +1,14 @@ Asset Size Chunks Chunk Names -bundle.js 3.51 KiB main [emitted] main +bundle.js 3.53 KiB main [emitted] main Entrypoint main = bundle.js -[./app.ts] 728 bytes {main} [built] [failed] [1 error] +[./app.ts] 766 bytes {main} [built] [failed] [1 error] ERROR in ./app.ts Module build failed: Error: ts-loader was supplied with an unexpected loader option: notRealOption Please take a look at the options you are supplying; the following are valid options: -silent / logLevel / logInfoToStdOut / instance / compiler / context / configFile / transpileOnly / ignoreDiagnostics / errorFormatter / colors / compilerOptions / appendTsSuffixTo / appendTsxSuffixTo / onlyCompileBundledFiles / happyPackMode / getCustomTransformers / reportFiles / experimentalWatchApi +silent / logLevel / logInfoToStdOut / instance / compiler / context / configFile / transpileOnly / ignoreDiagnostics / errorFormatter / colors / compilerOptions / appendTsSuffixTo / appendTsxSuffixTo / onlyCompileBundledFiles / happyPackMode / getCustomTransformers / reportFiles / experimentalWatchApi / allowTsInNodeModules - at validateLoaderOptions (dist\index.js:103:19) - at getLoaderOptions (dist\index.js:66:5) - at Object.loader (dist\index.js:15:21) \ No newline at end of file + at validateLoaderOptions (dist/index.js:110:19) + at getLoaderOptions (dist/index.js:72:5) + at Object.loader (dist/index.js:15:21) \ No newline at end of file From 31bec1f716f7b502faf75829c05597626a8ca0ab Mon Sep 17 00:00:00 2001 From: Andrew Lawson Date: Wed, 2 May 2018 14:35:40 -0400 Subject: [PATCH 04/10] Add test for enabling allowTsInNodeModules option. --- .../allowTsInNodeModules/app.ts | 3 + .../expectedOutput-2.8/bundle.js | 98 +++++++++++++++++++ .../expectedOutput-2.8/bundle.transpiled.js | 98 +++++++++++++++++++ .../expectedOutput-2.8/output.transpiled.txt | 5 + .../expectedOutput-2.8/output.txt | 5 + .../allowTsInNodeModules/tsconfig.json | 8 ++ .../allowTsInNodeModules/webpack.config.js | 17 ++++ 7 files changed, 234 insertions(+) create mode 100644 test/comparison-tests/allowTsInNodeModules/app.ts create mode 100644 test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/bundle.js create mode 100644 test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/bundle.transpiled.js create mode 100644 test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/output.transpiled.txt create mode 100644 test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/output.txt create mode 100644 test/comparison-tests/allowTsInNodeModules/tsconfig.json create mode 100644 test/comparison-tests/allowTsInNodeModules/webpack.config.js diff --git a/test/comparison-tests/allowTsInNodeModules/app.ts b/test/comparison-tests/allowTsInNodeModules/app.ts new file mode 100644 index 000000000..e4455c7c3 --- /dev/null +++ b/test/comparison-tests/allowTsInNodeModules/app.ts @@ -0,0 +1,3 @@ +import a = require('a'); + +console.log(a); \ No newline at end of file diff --git a/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/bundle.js b/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/bundle.js new file mode 100644 index 000000000..9c84bd3b2 --- /dev/null +++ b/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/bundle.js @@ -0,0 +1,98 @@ +/******/ (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] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = 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; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { +/******/ configurable: false, +/******/ enumerable: true, +/******/ get: getter +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = "./app.ts"); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ "./app.ts": +/*!****************!*\ + !*** ./app.ts ***! + \****************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; +eval("\nexports.__esModule = true;\nvar a = __webpack_require__(/*! a */ \"./node_modules/a/index.ts\");\nconsole.log(a);\n\n\n//# sourceURL=webpack:///./app.ts?"); + +/***/ }), + +/***/ "./node_modules/a/index.ts": +/*!*********************************!*\ + !*** ./node_modules/a/index.ts ***! + \*********************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; +eval("\nvar elephant = \"In the room\";\nmodule.exports = elephant;\n\n\n//# sourceURL=webpack:///./node_modules/a/index.ts?"); + +/***/ }) + +/******/ }); \ No newline at end of file diff --git a/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/bundle.transpiled.js b/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/bundle.transpiled.js new file mode 100644 index 000000000..9c84bd3b2 --- /dev/null +++ b/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/bundle.transpiled.js @@ -0,0 +1,98 @@ +/******/ (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] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = 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; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { +/******/ configurable: false, +/******/ enumerable: true, +/******/ get: getter +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = "./app.ts"); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ "./app.ts": +/*!****************!*\ + !*** ./app.ts ***! + \****************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; +eval("\nexports.__esModule = true;\nvar a = __webpack_require__(/*! a */ \"./node_modules/a/index.ts\");\nconsole.log(a);\n\n\n//# sourceURL=webpack:///./app.ts?"); + +/***/ }), + +/***/ "./node_modules/a/index.ts": +/*!*********************************!*\ + !*** ./node_modules/a/index.ts ***! + \*********************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; +eval("\nvar elephant = \"In the room\";\nmodule.exports = elephant;\n\n\n//# sourceURL=webpack:///./node_modules/a/index.ts?"); + +/***/ }) + +/******/ }); \ No newline at end of file diff --git a/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/output.transpiled.txt b/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/output.transpiled.txt new file mode 100644 index 000000000..0d34ef60e --- /dev/null +++ b/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/output.transpiled.txt @@ -0,0 +1,5 @@ + Asset Size Chunks Chunk Names +bundle.js 3.3 KiB main [emitted] main +Entrypoint main = bundle.js +[./app.ts] 79 bytes {main} [built] +[./node_modules/a/index.ts] 71 bytes {main} [built] \ No newline at end of file diff --git a/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/output.txt b/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/output.txt new file mode 100644 index 000000000..0d34ef60e --- /dev/null +++ b/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/output.txt @@ -0,0 +1,5 @@ + Asset Size Chunks Chunk Names +bundle.js 3.3 KiB main [emitted] main +Entrypoint main = bundle.js +[./app.ts] 79 bytes {main} [built] +[./node_modules/a/index.ts] 71 bytes {main} [built] \ No newline at end of file diff --git a/test/comparison-tests/allowTsInNodeModules/tsconfig.json b/test/comparison-tests/allowTsInNodeModules/tsconfig.json new file mode 100644 index 000000000..dff40218c --- /dev/null +++ b/test/comparison-tests/allowTsInNodeModules/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "noEmit": false + }, + "files": [ + "node_modules/a/index.ts" + ] +} \ No newline at end of file diff --git a/test/comparison-tests/allowTsInNodeModules/webpack.config.js b/test/comparison-tests/allowTsInNodeModules/webpack.config.js new file mode 100644 index 000000000..c5dfd5772 --- /dev/null +++ b/test/comparison-tests/allowTsInNodeModules/webpack.config.js @@ -0,0 +1,17 @@ +module.exports = { + mode: 'development', + entry: './app.ts', + output: { + filename: 'bundle.js' + }, + resolve: { + extensions: ['.ts', '.js'] + }, + module: { + rules: [ + { test: /\.ts$/, loader: 'ts-loader', options: { allowTsInNodeModules: true } } + ] + } +} + + From 84d7aa73f3b3c37c2ab530f601979aa89ce312f6 Mon Sep 17 00:00:00 2001 From: Andrew Lawson Date: Wed, 2 May 2018 15:13:13 -0400 Subject: [PATCH 05/10] Add option description to README.md --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index dcb5bb9c2..59515ae98 100644 --- a/README.md +++ b/README.md @@ -479,6 +479,34 @@ loading only those files that are actually bundled by webpack, as well as any `. by the `tsconfig.json` settings. `.d.ts` files are still included because they may be needed for compilation without being explicitly imported, and therefore not picked up by webpack. +#### allowTsInNodeModules _(boolean) (default=false)_ + +By default, ts-loader will not compile `.ts` files in `node_modules`. +You should not need to recompile `.ts` files there, but if you really want to, use this option. +Note that this option acts as a *whitelist* - any modules you desire to import must be included in +the `"files"` or `"include"` block of your project's `tsconfig.json`. + +See: https://github.com/Microsoft/TypeScript/issues/12358 + +```javascript + // in webpack.config.js + { + test: /\.ts$/, + loader: 'ts-loader', + options: { allowTsInNodeModules: true } + } +``` + +And in your `tsconfig.json`: + +```json + { + "files": [ + "node_modules/my_module/index.ts" + ] + } +``` + #### context _(string) (default=undefined)_ If set, will parse the TypeScript configuration file with given **absolute path** as base path. From 2c6e47ca152b013514e0c1886db163fbbf5330d1 Mon Sep 17 00:00:00 2001 From: Andrew Lawson Date: Wed, 2 May 2018 18:12:19 -0400 Subject: [PATCH 06/10] Change allowTsInNodeModules from comparison test to execution test. Add tests for successful import of module and file. --- .../allowTsInNodeModules/app.ts | 3 - .../expectedOutput-2.8/bundle.js | 98 ------------------- .../expectedOutput-2.8/bundle.transpiled.js | 98 ------------------- .../expectedOutput-2.8/output.transpiled.txt | 5 - .../expectedOutput-2.8/output.txt | 5 - .../allowTsInNodeModules/tsconfig.json | 8 -- .../allowTsInNodeModules/karma.conf.js | 47 +++++++++ .../allowTsInNodeModules/main.js | 2 + .../allowTsInNodeModules/package.json | 14 +++ .../allowTsInNodeModules/src/whitelisted.ts | 5 + .../src/whitelisted_file.ts | 5 + .../allowTsInNodeModules/test/app.tests.ts | 13 +++ .../allowTsInNodeModules/tsconfig.json | 9 ++ .../allowTsInNodeModules/webpack.config.js | 10 +- .../allowTsInNodeModules/yarn.lock | 17 ++++ test/testPackages/whitelistedFiles/file.ts | 3 + .../whitelistedFiles/package.json | 5 + test/testPackages/whitelistedModule/index.ts | 3 + .../whitelistedModule/package.json | 5 + 19 files changed, 136 insertions(+), 219 deletions(-) delete mode 100644 test/comparison-tests/allowTsInNodeModules/app.ts delete mode 100644 test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/bundle.js delete mode 100644 test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/bundle.transpiled.js delete mode 100644 test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/output.transpiled.txt delete mode 100644 test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/output.txt delete mode 100644 test/comparison-tests/allowTsInNodeModules/tsconfig.json create mode 100644 test/execution-tests/allowTsInNodeModules/karma.conf.js create mode 100644 test/execution-tests/allowTsInNodeModules/main.js create mode 100644 test/execution-tests/allowTsInNodeModules/package.json create mode 100644 test/execution-tests/allowTsInNodeModules/src/whitelisted.ts create mode 100644 test/execution-tests/allowTsInNodeModules/src/whitelisted_file.ts create mode 100644 test/execution-tests/allowTsInNodeModules/test/app.tests.ts create mode 100644 test/execution-tests/allowTsInNodeModules/tsconfig.json rename test/{comparison-tests => execution-tests}/allowTsInNodeModules/webpack.config.js (50%) create mode 100644 test/execution-tests/allowTsInNodeModules/yarn.lock create mode 100644 test/testPackages/whitelistedFiles/file.ts create mode 100644 test/testPackages/whitelistedFiles/package.json create mode 100644 test/testPackages/whitelistedModule/index.ts create mode 100644 test/testPackages/whitelistedModule/package.json diff --git a/test/comparison-tests/allowTsInNodeModules/app.ts b/test/comparison-tests/allowTsInNodeModules/app.ts deleted file mode 100644 index e4455c7c3..000000000 --- a/test/comparison-tests/allowTsInNodeModules/app.ts +++ /dev/null @@ -1,3 +0,0 @@ -import a = require('a'); - -console.log(a); \ No newline at end of file diff --git a/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/bundle.js b/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/bundle.js deleted file mode 100644 index 9c84bd3b2..000000000 --- a/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/bundle.js +++ /dev/null @@ -1,98 +0,0 @@ -/******/ (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] = { -/******/ i: moduleId, -/******/ l: false, -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Flag the module as loaded -/******/ module.l = 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; -/******/ -/******/ // define getter function for harmony exports -/******/ __webpack_require__.d = function(exports, name, getter) { -/******/ if(!__webpack_require__.o(exports, name)) { -/******/ Object.defineProperty(exports, name, { -/******/ configurable: false, -/******/ enumerable: true, -/******/ get: getter -/******/ }); -/******/ } -/******/ }; -/******/ -/******/ // define __esModule on exports -/******/ __webpack_require__.r = function(exports) { -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = function(module) { -/******/ var getter = module && module.__esModule ? -/******/ function getDefault() { return module['default']; } : -/******/ function getModuleExports() { return module; }; -/******/ __webpack_require__.d(getter, 'a', getter); -/******/ return getter; -/******/ }; -/******/ -/******/ // Object.prototype.hasOwnProperty.call -/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; -/******/ -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; -/******/ -/******/ -/******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = "./app.ts"); -/******/ }) -/************************************************************************/ -/******/ ({ - -/***/ "./app.ts": -/*!****************!*\ - !*** ./app.ts ***! - \****************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\nexports.__esModule = true;\nvar a = __webpack_require__(/*! a */ \"./node_modules/a/index.ts\");\nconsole.log(a);\n\n\n//# sourceURL=webpack:///./app.ts?"); - -/***/ }), - -/***/ "./node_modules/a/index.ts": -/*!*********************************!*\ - !*** ./node_modules/a/index.ts ***! - \*********************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\nvar elephant = \"In the room\";\nmodule.exports = elephant;\n\n\n//# sourceURL=webpack:///./node_modules/a/index.ts?"); - -/***/ }) - -/******/ }); \ No newline at end of file diff --git a/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/bundle.transpiled.js b/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/bundle.transpiled.js deleted file mode 100644 index 9c84bd3b2..000000000 --- a/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/bundle.transpiled.js +++ /dev/null @@ -1,98 +0,0 @@ -/******/ (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] = { -/******/ i: moduleId, -/******/ l: false, -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Flag the module as loaded -/******/ module.l = 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; -/******/ -/******/ // define getter function for harmony exports -/******/ __webpack_require__.d = function(exports, name, getter) { -/******/ if(!__webpack_require__.o(exports, name)) { -/******/ Object.defineProperty(exports, name, { -/******/ configurable: false, -/******/ enumerable: true, -/******/ get: getter -/******/ }); -/******/ } -/******/ }; -/******/ -/******/ // define __esModule on exports -/******/ __webpack_require__.r = function(exports) { -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = function(module) { -/******/ var getter = module && module.__esModule ? -/******/ function getDefault() { return module['default']; } : -/******/ function getModuleExports() { return module; }; -/******/ __webpack_require__.d(getter, 'a', getter); -/******/ return getter; -/******/ }; -/******/ -/******/ // Object.prototype.hasOwnProperty.call -/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; -/******/ -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; -/******/ -/******/ -/******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = "./app.ts"); -/******/ }) -/************************************************************************/ -/******/ ({ - -/***/ "./app.ts": -/*!****************!*\ - !*** ./app.ts ***! - \****************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\nexports.__esModule = true;\nvar a = __webpack_require__(/*! a */ \"./node_modules/a/index.ts\");\nconsole.log(a);\n\n\n//# sourceURL=webpack:///./app.ts?"); - -/***/ }), - -/***/ "./node_modules/a/index.ts": -/*!*********************************!*\ - !*** ./node_modules/a/index.ts ***! - \*********************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\nvar elephant = \"In the room\";\nmodule.exports = elephant;\n\n\n//# sourceURL=webpack:///./node_modules/a/index.ts?"); - -/***/ }) - -/******/ }); \ No newline at end of file diff --git a/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/output.transpiled.txt b/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/output.transpiled.txt deleted file mode 100644 index 0d34ef60e..000000000 --- a/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/output.transpiled.txt +++ /dev/null @@ -1,5 +0,0 @@ - Asset Size Chunks Chunk Names -bundle.js 3.3 KiB main [emitted] main -Entrypoint main = bundle.js -[./app.ts] 79 bytes {main} [built] -[./node_modules/a/index.ts] 71 bytes {main} [built] \ No newline at end of file diff --git a/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/output.txt b/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/output.txt deleted file mode 100644 index 0d34ef60e..000000000 --- a/test/comparison-tests/allowTsInNodeModules/expectedOutput-2.8/output.txt +++ /dev/null @@ -1,5 +0,0 @@ - Asset Size Chunks Chunk Names -bundle.js 3.3 KiB main [emitted] main -Entrypoint main = bundle.js -[./app.ts] 79 bytes {main} [built] -[./node_modules/a/index.ts] 71 bytes {main} [built] \ No newline at end of file diff --git a/test/comparison-tests/allowTsInNodeModules/tsconfig.json b/test/comparison-tests/allowTsInNodeModules/tsconfig.json deleted file mode 100644 index dff40218c..000000000 --- a/test/comparison-tests/allowTsInNodeModules/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "compilerOptions": { - "noEmit": false - }, - "files": [ - "node_modules/a/index.ts" - ] -} \ No newline at end of file diff --git a/test/execution-tests/allowTsInNodeModules/karma.conf.js b/test/execution-tests/allowTsInNodeModules/karma.conf.js new file mode 100644 index 000000000..70384116d --- /dev/null +++ b/test/execution-tests/allowTsInNodeModules/karma.conf.js @@ -0,0 +1,47 @@ +/* eslint-disable no-var, strict */ +'use strict'; +var path = require('path'); +var webpack = require('webpack'); +var webpackConfig = require('./webpack.config.js'); +var reporterOptions = require('../../reporterOptions'); + +module.exports = function(config) { + config.set({ + browsers: [ 'ChromeHeadless' ], + + files: [ + // This loads all the tests + 'main.js' + ], + + port: 9876, + + frameworks: [ 'jasmine' ], + + logLevel: config.LOG_INFO, //config.LOG_DEBUG + + preprocessors: { + 'main.js': [ 'webpack', 'sourcemap' ] + }, + + webpack: { + devtool: 'inline-source-map', + mode: webpackConfig.mode, + module: webpackConfig.module, + resolve: webpackConfig.resolve, + + // for test harness purposes only, you would not need this in a normal project + resolveLoader: webpackConfig.resolveLoader + }, + + webpackMiddleware: { + quiet: false, + stats: { + colors: true + } + }, + + // reporter options + mochaReporter: reporterOptions + }); +}; diff --git a/test/execution-tests/allowTsInNodeModules/main.js b/test/execution-tests/allowTsInNodeModules/main.js new file mode 100644 index 000000000..5708d2cf7 --- /dev/null +++ b/test/execution-tests/allowTsInNodeModules/main.js @@ -0,0 +1,2 @@ +const testsContext = require.context('./', true, /\.tests\.ts(x?)$/); +testsContext.keys().forEach(testsContext); \ No newline at end of file diff --git a/test/execution-tests/allowTsInNodeModules/package.json b/test/execution-tests/allowTsInNodeModules/package.json new file mode 100644 index 000000000..c8af49f22 --- /dev/null +++ b/test/execution-tests/allowTsInNodeModules/package.json @@ -0,0 +1,14 @@ +{ + "name": "basic", + "license": "MIT", + "version": "1.0.0", + "main": "index.js", + "dependencies": { + "whitelistedModule": "file:../../testPackages/whitelistedModule", + "whitelistedFiles": "file:../../testPackages/whitelistedFiles" + }, + "devDependencies": { + "@types/jasmine": "^2.5.35", + "jasmine-core": "^2.3.4" + } +} diff --git a/test/execution-tests/allowTsInNodeModules/src/whitelisted.ts b/test/execution-tests/allowTsInNodeModules/src/whitelisted.ts new file mode 100644 index 000000000..ac7021c58 --- /dev/null +++ b/test/execution-tests/allowTsInNodeModules/src/whitelisted.ts @@ -0,0 +1,5 @@ +import whitelistedModule = require('whitelistedModule'); + +export function get() { + return whitelistedModule; +} \ No newline at end of file diff --git a/test/execution-tests/allowTsInNodeModules/src/whitelisted_file.ts b/test/execution-tests/allowTsInNodeModules/src/whitelisted_file.ts new file mode 100644 index 000000000..e6e030c58 --- /dev/null +++ b/test/execution-tests/allowTsInNodeModules/src/whitelisted_file.ts @@ -0,0 +1,5 @@ +import whitelistedFile = require('whitelistedFiles/file'); + +export function get() { + return whitelistedFile; +} \ No newline at end of file diff --git a/test/execution-tests/allowTsInNodeModules/test/app.tests.ts b/test/execution-tests/allowTsInNodeModules/test/app.tests.ts new file mode 100644 index 000000000..0df8dd4b2 --- /dev/null +++ b/test/execution-tests/allowTsInNodeModules/test/app.tests.ts @@ -0,0 +1,13 @@ +describe("whitelisted", () => { + it("module can be imported", () => { + const whitelisted = require('../src/whitelisted'); + + expect(whitelisted.get()).toBe("my whitelisted module"); + }); + + it("file can be imported", () => { + const whitelisted = require('../src/whitelisted_file'); + + expect(whitelisted.get()).toBe("a whitelisted file"); + }); +}); \ No newline at end of file diff --git a/test/execution-tests/allowTsInNodeModules/tsconfig.json b/test/execution-tests/allowTsInNodeModules/tsconfig.json new file mode 100644 index 000000000..e391e0326 --- /dev/null +++ b/test/execution-tests/allowTsInNodeModules/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { }, + "include": [ + "./node_modules/whitelistedModule" + ], + "files": [ + "./node_modules/whitelistedFiles/file.ts" + ] +} \ No newline at end of file diff --git a/test/comparison-tests/allowTsInNodeModules/webpack.config.js b/test/execution-tests/allowTsInNodeModules/webpack.config.js similarity index 50% rename from test/comparison-tests/allowTsInNodeModules/webpack.config.js rename to test/execution-tests/allowTsInNodeModules/webpack.config.js index c5dfd5772..2b443a8ad 100644 --- a/test/comparison-tests/allowTsInNodeModules/webpack.config.js +++ b/test/execution-tests/allowTsInNodeModules/webpack.config.js @@ -1,6 +1,11 @@ +var path = require('path') + module.exports = { mode: 'development', - entry: './app.ts', + entry: [ + './src/whitelisted.ts', + './src/whitelisted_file.ts' + ], output: { filename: 'bundle.js' }, @@ -14,4 +19,5 @@ module.exports = { } } - +// for test harness purposes only, you would not need this in a normal project +module.exports.resolveLoader = { alias: { 'ts-loader': path.join(__dirname, "../../../index.js") } } \ No newline at end of file diff --git a/test/execution-tests/allowTsInNodeModules/yarn.lock b/test/execution-tests/allowTsInNodeModules/yarn.lock new file mode 100644 index 000000000..a8e06fe04 --- /dev/null +++ b/test/execution-tests/allowTsInNodeModules/yarn.lock @@ -0,0 +1,17 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@types/jasmine@^2.5.35": + version "2.8.6" + resolved "https://registry.yarnpkg.com/@types/jasmine/-/jasmine-2.8.6.tgz#14445b6a1613cf4e05dd61c3c3256d0e95c0421e" + +jasmine-core@^2.3.4: + version "2.99.1" + resolved "https://registry.yarnpkg.com/jasmine-core/-/jasmine-core-2.99.1.tgz#e6400df1e6b56e130b61c4bcd093daa7f6e8ca15" + +"whitelistedFiles@file:../../testPackages/whitelistedFiles": + version "1.0.0" + +"whitelistedModule@file:../../testPackages/whitelistedModule": + version "1.0.0" diff --git a/test/testPackages/whitelistedFiles/file.ts b/test/testPackages/whitelistedFiles/file.ts new file mode 100644 index 000000000..63e7124c2 --- /dev/null +++ b/test/testPackages/whitelistedFiles/file.ts @@ -0,0 +1,3 @@ +var whitelistedFile = "a whitelisted file"; + +export = whitelistedFile; \ No newline at end of file diff --git a/test/testPackages/whitelistedFiles/package.json b/test/testPackages/whitelistedFiles/package.json new file mode 100644 index 000000000..72ec1980b --- /dev/null +++ b/test/testPackages/whitelistedFiles/package.json @@ -0,0 +1,5 @@ +{ + "name": "whitelistedFiles", + "version": "1.0.0", + "main": "file.ts" +} \ No newline at end of file diff --git a/test/testPackages/whitelistedModule/index.ts b/test/testPackages/whitelistedModule/index.ts new file mode 100644 index 000000000..4e71d6b80 --- /dev/null +++ b/test/testPackages/whitelistedModule/index.ts @@ -0,0 +1,3 @@ +var whitelistedModule = "my whitelisted module"; + +export = whitelistedModule; \ No newline at end of file diff --git a/test/testPackages/whitelistedModule/package.json b/test/testPackages/whitelistedModule/package.json new file mode 100644 index 000000000..47805e425 --- /dev/null +++ b/test/testPackages/whitelistedModule/package.json @@ -0,0 +1,5 @@ +{ + "name": "whitelistedModule", + "version": "1.0.0", + "main": "index.js" +} \ No newline at end of file From f4ceb49d7384147cbc7110b415babaf785311c97 Mon Sep 17 00:00:00 2001 From: Andrew Lawson Date: Wed, 2 May 2018 22:39:38 -0400 Subject: [PATCH 07/10] Fix indentation. Remove webpack output during karma tests. --- test/execution-tests/allowTsInNodeModules/karma.conf.js | 2 +- test/execution-tests/allowTsInNodeModules/tsconfig.json | 2 +- test/testPackages/whitelistedFiles/package.json | 2 +- test/testPackages/whitelistedModule/package.json | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/execution-tests/allowTsInNodeModules/karma.conf.js b/test/execution-tests/allowTsInNodeModules/karma.conf.js index 70384116d..f0cb98bc7 100644 --- a/test/execution-tests/allowTsInNodeModules/karma.conf.js +++ b/test/execution-tests/allowTsInNodeModules/karma.conf.js @@ -35,7 +35,7 @@ module.exports = function(config) { }, webpackMiddleware: { - quiet: false, + quiet: true, stats: { colors: true } diff --git a/test/execution-tests/allowTsInNodeModules/tsconfig.json b/test/execution-tests/allowTsInNodeModules/tsconfig.json index e391e0326..c1f37a9b2 100644 --- a/test/execution-tests/allowTsInNodeModules/tsconfig.json +++ b/test/execution-tests/allowTsInNodeModules/tsconfig.json @@ -1,5 +1,5 @@ { - "compilerOptions": { }, + "compilerOptions": { }, "include": [ "./node_modules/whitelistedModule" ], diff --git a/test/testPackages/whitelistedFiles/package.json b/test/testPackages/whitelistedFiles/package.json index 72ec1980b..3caf8a8ca 100644 --- a/test/testPackages/whitelistedFiles/package.json +++ b/test/testPackages/whitelistedFiles/package.json @@ -1,5 +1,5 @@ { - "name": "whitelistedFiles", + "name": "whitelistedFiles", "version": "1.0.0", "main": "file.ts" } \ No newline at end of file diff --git a/test/testPackages/whitelistedModule/package.json b/test/testPackages/whitelistedModule/package.json index 47805e425..73aa7f31d 100644 --- a/test/testPackages/whitelistedModule/package.json +++ b/test/testPackages/whitelistedModule/package.json @@ -1,5 +1,5 @@ { - "name": "whitelistedModule", + "name": "whitelistedModule", "version": "1.0.0", - "main": "index.js" + "main": "index.js" } \ No newline at end of file From e0a0ff7f85f493c53c4ba4c65361dc498d9cbe8d Mon Sep 17 00:00:00 2001 From: Andrew Lawson Date: Thu, 3 May 2018 11:21:00 -0400 Subject: [PATCH 08/10] Linkify GitHub issue reference. Add better example for tsconfig.json. --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 59515ae98..3e18fdcad 100644 --- a/README.md +++ b/README.md @@ -486,7 +486,7 @@ You should not need to recompile `.ts` files there, but if you really want to, u Note that this option acts as a *whitelist* - any modules you desire to import must be included in the `"files"` or `"include"` block of your project's `tsconfig.json`. -See: https://github.com/Microsoft/TypeScript/issues/12358 +See: [https://github.com/Microsoft/TypeScript/issues/12358](https://github.com/Microsoft/TypeScript/issues/12358) ```javascript // in webpack.config.js @@ -501,8 +501,11 @@ And in your `tsconfig.json`: ```json { + "include": [ + "node_modules/whitelisted_module.ts" + ], "files": [ - "node_modules/my_module/index.ts" + "node_modules/my_module/whitelisted_file.ts" ] } ``` From 517af98f9447098956140a1ad8388a8af59b0cf1 Mon Sep 17 00:00:00 2001 From: Andrew Lawson Date: Thu, 3 May 2018 11:26:40 -0400 Subject: [PATCH 09/10] Update error message logic to use ternary. --- src/index.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1944bde5a..675d96ebe 100644 --- a/src/index.ts +++ b/src/index.ts @@ -69,16 +69,11 @@ function successLoader( : getEmit(rawFilePath, filePath, instance, loader); if (outputText === null || outputText === undefined) { - let additionalGuidance: string; - - if (!options.allowTsInNodeModules && filePath.indexOf('node_modules') !== -1) { - additionalGuidance = " By default, ts-loader will not compile .ts files in node_modules.\n" + + const additionalGuidance: string = (!options.allowTsInNodeModules && filePath.indexOf('node_modules') !== -1) + ? " By default, ts-loader will not compile .ts files in node_modules.\n" + "You should not need to recompile .ts files there, but if you really want to, use the allowTsInNodeModules option.\n" + - "See: https://github.com/Microsoft/TypeScript/issues/12358"; - } - else { - additionalGuidance = ""; - } + "See: https://github.com/Microsoft/TypeScript/issues/12358" + : ""; throw new Error( `Typescript emitted no output for ${filePath}.${additionalGuidance}` From c3af0545e7a13066c6b1f0ac6b7cf81c0e972a75 Mon Sep 17 00:00:00 2001 From: Andrew Lawson Date: Thu, 3 May 2018 12:41:28 -0400 Subject: [PATCH 10/10] Slight change in output for nodeModulesMeaningfulErrorWhenImportingTs comparison test. --- .../expectedOutput-2.8/bundle.js | 2 +- .../expectedOutput-2.8/output.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/comparison-tests/nodeModulesMeaningfulErrorWhenImportingTs/expectedOutput-2.8/bundle.js b/test/comparison-tests/nodeModulesMeaningfulErrorWhenImportingTs/expectedOutput-2.8/bundle.js index bcaa426ec..b9204db67 100644 --- a/test/comparison-tests/nodeModulesMeaningfulErrorWhenImportingTs/expectedOutput-2.8/bundle.js +++ b/test/comparison-tests/nodeModulesMeaningfulErrorWhenImportingTs/expectedOutput-2.8/bundle.js @@ -90,7 +90,7 @@ eval("\nexports.__esModule = true;\nvar a = __webpack_require__(/*! a */ \"./nod /*! no static exports found */ /***/ (function(module, exports) { -eval("throw new Error(\"Module build failed: Error: Typescript emitted no output for /nodeModulesMeaningfulErrorWhenImportingTs/node_modules/a/index.ts. By default, ts-loader will not compile .ts files in node_modules./nYou should not need to recompile .ts files there, but if you really want to, use the allowTsInNodeModules option./nSee: https://github.com/Microsoft/TypeScript/issues/12358/n at successLoader (/Users/alawson/dev/ts-loader/dist/index.js:45:15)/n at Object.loader (/Users/alawson/dev/ts-loader/dist/index.js:21:12)\");\n\n//# sourceURL=webpack:///./node_modules/a/index.ts?"); +eval("throw new Error(\"Module build failed: Error: Typescript emitted no output for /nodeModulesMeaningfulErrorWhenImportingTs/node_modules/a/index.ts. By default, ts-loader will not compile .ts files in node_modules./nYou should not need to recompile .ts files there, but if you really want to, use the allowTsInNodeModules option./nSee: https://github.com/Microsoft/TypeScript/issues/12358/n at successLoader (/Users/alawson/dev/ts-loader/dist/index.js:41:15)/n at Object.loader (/Users/alawson/dev/ts-loader/dist/index.js:21:12)\");\n\n//# sourceURL=webpack:///./node_modules/a/index.ts?"); /***/ }) diff --git a/test/comparison-tests/nodeModulesMeaningfulErrorWhenImportingTs/expectedOutput-2.8/output.txt b/test/comparison-tests/nodeModulesMeaningfulErrorWhenImportingTs/expectedOutput-2.8/output.txt index 5e2ab0d89..527f522b4 100644 --- a/test/comparison-tests/nodeModulesMeaningfulErrorWhenImportingTs/expectedOutput-2.8/output.txt +++ b/test/comparison-tests/nodeModulesMeaningfulErrorWhenImportingTs/expectedOutput-2.8/output.txt @@ -8,6 +8,6 @@ ERROR in ./node_modules/a/index.ts Module build failed: Error: Typescript emitted no output for node_modules/a/index.ts. By default, ts-loader will not compile .ts files in node_modules. You should not need to recompile .ts files there, but if you really want to, use the allowTsInNodeModules option. See: https://github.com/Microsoft/TypeScript/issues/12358 - at successLoader (dist/index.js:45:15) + at successLoader (dist/index.js:41:15) at Object.loader (dist/index.js:21:12) @ ./app.ts 3:8-20 \ No newline at end of file