-
-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add allowTsInNodeModules option for importing .ts files from node_mod…
…ules. (#773) * Add allowTsInNodeModules loader option. * Add error text for allowTsInNodeModules option when importing .ts files from node_modules. Tweak existing error text and code style. * Update nodeModulesMeaningfulErrorWhenImportingTs test outputs. * Add test for enabling allowTsInNodeModules option. * Add option description to README.md * Change allowTsInNodeModules from comparison test to execution test. Add tests for successful import of module and file. * Fix indentation. Remove webpack output during karma tests. * Linkify GitHub issue reference. Add better example for tsconfig.json. * Update error message logic to use ternary. * Slight change in output for nodeModulesMeaningfulErrorWhenImportingTs comparison test.
- Loading branch information
1 parent
ec679ed
commit a150671
Showing
20 changed files
with
208 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 7 additions & 8 deletions
15
.../comparison-tests/nodeModulesMeaningfulErrorWhenImportingTs/expectedOutput-2.8/output.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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:41:15) | ||
at Object.loader (dist/index.js:21:12) | ||
@ ./app.ts 3:8-20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
test/comparison-tests/validateLoaderOptionNames/expectedOutput-2.8/output.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
at validateLoaderOptions (dist/index.js:110:19) | ||
at getLoaderOptions (dist/index.js:72:5) | ||
at Object.loader (dist/index.js:15:21) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: true, | ||
stats: { | ||
colors: true | ||
} | ||
}, | ||
|
||
// reporter options | ||
mochaReporter: reporterOptions | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const testsContext = require.context('./', true, /\.tests\.ts(x?)$/); | ||
testsContext.keys().forEach(testsContext); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import whitelistedModule = require('whitelistedModule'); | ||
|
||
export function get() { | ||
return whitelistedModule; | ||
} |
5 changes: 5 additions & 0 deletions
5
test/execution-tests/allowTsInNodeModules/src/whitelisted_file.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import whitelistedFile = require('whitelistedFiles/file'); | ||
|
||
export function get() { | ||
return whitelistedFile; | ||
} |
13 changes: 13 additions & 0 deletions
13
test/execution-tests/allowTsInNodeModules/test/app.tests.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { }, | ||
"include": [ | ||
"./node_modules/whitelistedModule" | ||
], | ||
"files": [ | ||
"./node_modules/whitelistedFiles/file.ts" | ||
] | ||
} |
23 changes: 23 additions & 0 deletions
23
test/execution-tests/allowTsInNodeModules/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
var path = require('path') | ||
|
||
module.exports = { | ||
mode: 'development', | ||
entry: [ | ||
'./src/whitelisted.ts', | ||
'./src/whitelisted_file.ts' | ||
], | ||
output: { | ||
filename: 'bundle.js' | ||
}, | ||
resolve: { | ||
extensions: ['.ts', '.js'] | ||
}, | ||
module: { | ||
rules: [ | ||
{ test: /\.ts$/, loader: 'ts-loader', options: { allowTsInNodeModules: true } } | ||
] | ||
} | ||
} | ||
|
||
// 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") } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var whitelistedFile = "a whitelisted file"; | ||
|
||
export = whitelistedFile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "whitelistedFiles", | ||
"version": "1.0.0", | ||
"main": "file.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var whitelistedModule = "my whitelisted module"; | ||
|
||
export = whitelistedModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "whitelistedModule", | ||
"version": "1.0.0", | ||
"main": "index.js" | ||
} |