-
-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure a separate webpack instance is created for different loader op…
…tions (#1104) * Ensure a separate webpack instance is created if different loader options are used Add execution test for this behaviour * Fix import order (lint error) * Update version to 7.04 and include in changelog * Tweak to Changelog
- Loading branch information
Showing
18 changed files
with
183 additions
and
3 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
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" |