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
Ensure a separate webpack instance is created for different loader options #1104
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## Loader Options Test | ||
|
||
This test includes 3 submodules, only 1 of which should have the transformer applied via the options. This tests that separate webpack instances are created when module options are different. |
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 @@ | ||
/* eslint-disable no-var, strict */ | ||
'use strict'; | ||
var webpackConfig = require('./webpack.config.js'); | ||
var makeKarmaConfig = require('../../karmaConfig'); | ||
|
||
module.exports = function(config) { | ||
config.set( | ||
makeKarmaConfig({ | ||
config, | ||
webpackConfig, | ||
files: [ | ||
// This ensures we have the es6 shims in place from babel and then loads all the tests | ||
'main.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,7 @@ | ||
declare module externalLib { | ||
export function doSomething(arg: any): void; | ||
} | ||
|
||
declare module 'externalLib' { | ||
export = externalLib | ||
} |
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 @@ | ||
module.exports = { | ||
doSomething: function() { } | ||
} |
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,3 @@ | ||
import submodule = require('./submodule/submodule'); | ||
import externalLib = require('externalLib'); | ||
externalLib.doSomething(submodule); |
5 changes: 5 additions & 0 deletions
5
test/execution-tests/loaderOptions/src/submodule/submodule.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 externalLib = require('externalLib'); | ||
|
||
externalLib.doSomething(""); | ||
var message = "Hello from submodule" | ||
export = message |
5 changes: 5 additions & 0 deletions
5
test/execution-tests/loaderOptions/src/submodule/submodule2.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 externalLib = require('externalLib'); | ||
|
||
externalLib.doSomething(""); | ||
var message = "Hello from submodule2" | ||
export = message |
5 changes: 5 additions & 0 deletions
5
test/execution-tests/loaderOptions/src/submodule/submodule3.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 externalLib = require('externalLib'); | ||
|
||
externalLib.doSomething(""); | ||
var message = "Hello from submodule3" | ||
export = message |
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,22 @@ | ||
import submodule = require('../src/submodule/submodule'); | ||
import submodule2 = require('../src/submodule/submodule2'); | ||
import submodule3 = require('../src/submodule/submodule3'); | ||
import externalLib = require('externalLib'); | ||
|
||
describe("app", () => { | ||
it("externalLib can be called", () => { | ||
expect(externalLib.doSomething(submodule)).toBeUndefined(); | ||
}); | ||
|
||
it("submodule return value should not be transformed", () => { | ||
expect(submodule).toBe("Hello "+"from submodule"); | ||
}); | ||
|
||
it("submodule2 return value should be transformed", () => { | ||
expect(submodule2).toBe("HELLO "+"FROM SUBMODULE2"); | ||
}); | ||
|
||
it("submodule3 return value should not be transformed", () => { | ||
expect(submodule3).toBe("Hello "+"from submodule3"); | ||
}); | ||
}); |
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 | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
test/execution-tests/loaderOptions/uppercaseStringLiteralTransformer.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,18 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var ts = require("typescript"); | ||
var transformer = function (context) { | ||
var visitor = function (node) { | ||
if (node.kind === ts.SyntaxKind.StringLiteral) { | ||
var text = node.text; | ||
if (text.match(/^Hello from submodule/) !== null) { | ||
if (text !== text.toUpperCase()) { | ||
return ts.createLiteral(text.toUpperCase()); | ||
} | ||
} | ||
} | ||
return ts.visitEachChild(node, visitor, context); | ||
}; | ||
return function (node) { return ts.visitNode(node, visitor); }; | ||
}; | ||
exports["default"] = transformer; |
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,40 @@ | ||
var path = require('path') | ||
|
||
var uppercaseStringLiteralTransformer = require('./uppercaseStringLiteralTransformer').default; | ||
|
||
module.exports = { | ||
mode: 'development', | ||
entry: './src/app.ts', | ||
output: { | ||
filename: 'bundle.js' | ||
}, | ||
resolve: { | ||
alias: { externalLib: path.join(__dirname, "./lib/externalLib.js") }, | ||
extensions: ['.ts', '.js'] | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /submodule3\.ts$/, | ||
loader: 'ts-loader', | ||
}, | ||
{ | ||
test: /submodule2\.ts$/, | ||
loader: 'ts-loader', | ||
options: { | ||
getCustomTransformers: (program) => ({ | ||
before: [uppercaseStringLiteralTransformer] | ||
}) | ||
}, | ||
}, | ||
{ | ||
test: /\.ts$/, | ||
exclude: /submodule\d\.ts$/, | ||
loader: 'ts-loader', | ||
} | ||
] | ||
} | ||
} | ||
|
||
// for test harness purposes only, you would not need this in a normal project | ||
module.exports.resolveLoader = { alias: { 'ts-loader': require('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.
Can you thank yourself please? It's traditional now 🤗