-
-
Notifications
You must be signed in to change notification settings - Fork 429
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
Implements a custom resolveModuleName option #862
Merged
johnnyreilly
merged 11 commits into
TypeStrong:master
from
arcanis:custom-resolve-module-name
Oct 31, 2018
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6367073
Implements a custom resolveModuleName option
arcanis 46d721a
Addresses feedback
arcanis f2f6026
Adds a test
arcanis 289d904
Adresses feedback
arcanis 9a0540a
Expands the test scope
arcanis 0bc78bd
Fix validateLoaderOptionNames test
johnnyreilly 8b694a8
prettier formatting
johnnyreilly afa570d
Be explicit about the possible value of customResolveModuleName
johnnyreilly ad4ed7b
Feedback round 3
arcanis d8f3735
Fix lint issues
johnnyreilly bee1c37
Bumps package.json, updates changelog
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
10 changes: 5 additions & 5 deletions
10
test/comparison-tests/validateLoaderOptionNames/expectedOutput-3.1/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,15 +1,15 @@ | ||
Asset Size Chunks Chunk Names | ||
bundle.js 4.58 KiB main [emitted] main | ||
Asset Size Chunks Chunk Names | ||
bundle.js 4.6 KiB main [emitted] main | ||
Entrypoint main = bundle.js | ||
[./app.ts] 835 bytes {main} [built] [failed] [1 error] | ||
[./app.ts] 855 bytes {main} [built] [failed] [1 error] | ||
|
||
ERROR in ./app.ts | ||
Module build failed (from /index.js): | ||
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 / allowTsInNodeModules / experimentalFileCaching / projectReferences | ||
silent / logLevel / logInfoToStdOut / instance / compiler / context / configFile / transpileOnly / ignoreDiagnostics / errorFormatter / colors / compilerOptions / appendTsSuffixTo / appendTsxSuffixTo / onlyCompileBundledFiles / happyPackMode / getCustomTransformers / reportFiles / experimentalWatchApi / allowTsInNodeModules / experimentalFileCaching / projectReferences / resolveModuleName | ||
|
||
at validateLoaderOptions (dist\index.js:151:19) | ||
at validateLoaderOptions (dist\index.js:152:19) | ||
at getLoaderOptions (dist\index.js:110:5) | ||
at Object.loader (dist\index.js:16:21) |
3 changes: 3 additions & 0 deletions
3
test/execution-tests/3.0.1_resolveModuleName/bar-pkg/index.d.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 @@ | ||
import {HelloWorld} from 'foo'; | ||
|
||
export type HelloBuilder = (hello: number, world: number) => HelloWorld; |
5 changes: 5 additions & 0 deletions
5
test/execution-tests/3.0.1_resolveModuleName/bar-pkg/package.json
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": "bar", | ||
"version": "1.0.0", | ||
"typings": "./index.d.ts" | ||
} |
6 changes: 6 additions & 0 deletions
6
test/execution-tests/3.0.1_resolveModuleName/baz-pkg/index.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,6 @@ | ||
import {HelloBuilder} from 'bar'; | ||
|
||
export const makeHello: HelloBuilder = (hello: number, world: number) => ({ | ||
hello, | ||
world, | ||
}); |
5 changes: 5 additions & 0 deletions
5
test/execution-tests/3.0.1_resolveModuleName/baz-pkg/package.json
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": "baz", | ||
"version": "1.0.0", | ||
"main": "index.ts" | ||
} |
4 changes: 4 additions & 0 deletions
4
test/execution-tests/3.0.1_resolveModuleName/foo-pkg/index.d.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,4 @@ | ||
export type HelloWorld = { | ||
hello: number, | ||
world: number, | ||
}; |
5 changes: 5 additions & 0 deletions
5
test/execution-tests/3.0.1_resolveModuleName/foo-pkg/package.json
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": "foo", | ||
"version": "1.0.0", | ||
"typings": "./index.d.ts" | ||
} |
47 changes: 47 additions & 0 deletions
47
test/execution-tests/3.0.1_resolveModuleName/karma.conf.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,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,10 @@ | ||
{ | ||
"name": "basic", | ||
"license": "MIT", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"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,4 @@ | ||
import {HelloWorld} from 'foo'; | ||
import {makeHello} from 'baz'; | ||
|
||
export const def: HelloWorld = makeHello(1, 2); |
13 changes: 13 additions & 0 deletions
13
test/execution-tests/3.0.1_resolveModuleName/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 @@ | ||
import * as app from '../src/app'; | ||
|
||
// We don't actually care about the result of the following operations; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not true actually; we do care about the result of the following operations! Can we amend the comment to make test intent clearer please? We care both about type resolution and that the code executes... |
||
// what we care about is typescript resolving modules using our custom | ||
// logic, allowing this code to compile without errors, hence this: | ||
// "noEmitOnError": true | ||
// in tsconfig.json | ||
describe("app", () => { | ||
it("app.def to have been setup", () => { | ||
expect(app.def.hello).toEqual(1); | ||
expect(app.def.world).toEqual(2); | ||
}); | ||
}); |
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 @@ | ||
{ | ||
"compilerOptions": { | ||
"noEmitOnError": true | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
test/execution-tests/3.0.1_resolveModuleName/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,30 @@ | ||
var path = require('path') | ||
|
||
module.exports = { | ||
mode: 'development', | ||
entry: './app.ts', | ||
output: { | ||
filename: 'bundle.js' | ||
}, | ||
resolve: { | ||
extensions: ['.ts', '.js'], | ||
alias: { baz: path.join(__dirname, 'baz-pkg') }, | ||
}, | ||
module: { | ||
rules: [ | ||
{ test: /\.ts$/, loader: 'ts-loader', options: { | ||
resolveModuleName: (moduleName, containingFile, compilerOptions, compilerHost, parentResolver) => { | ||
switch (moduleName) { | ||
case 'foo': return parentResolver(path.join(__dirname, 'foo-pkg'), containingFile, compilerOptions, compilerHost); | ||
case 'bar': return parentResolver(path.join(__dirname, 'bar-pkg'), containingFile, compilerOptions, compilerHost); | ||
case 'baz': return parentResolver(path.join(__dirname, 'baz-pkg'), containingFile, compilerOptions, compilerHost); | ||
default: return parentResolver(moduleName, containingFile, compilerOptions, compilerHost); | ||
} | ||
}, | ||
} } | ||
] | ||
} | ||
} | ||
|
||
// 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,11 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
"@types/jasmine@^2.5.35": | ||
version "2.8.5" | ||
resolved "https://registry.yarnpkg.com/@types/jasmine/-/jasmine-2.8.5.tgz#96e58872583fa80c7ea0dd29024b180d5e133678" | ||
|
||
jasmine-core@^2.3.4: | ||
version "2.9.1" | ||
resolved "https://registry.yarnpkg.com/jasmine-core/-/jasmine-core-2.9.1.tgz#b6bbc1d8e65250d56f5888461705ebeeeb88f22f" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing a
.bind
my perf spider sense is tingling!https://stackoverflow.com/questions/42117911/lambda-functions-vs-bind-memory-and-performance
I wonder if we could switch this to a lamba instead? It'll be slightly more verbose but hopefully should perform better...