-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added the
executableFile
option (#65)
- Loading branch information
1 parent
0099efe
commit b46090f
Showing
7 changed files
with
223 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`executableFile option should emit error: errors 1`] = ` | ||
Array [ | ||
"ModuleBuildError: Module build failed (from \`replaced original path\`): | ||
Error: Unable to require \\"/test/fixtures/error-require.js\\": Error: This is a typical require() error", | ||
"ChunkRenderError: Cannot read property 'get' of undefined", | ||
] | ||
`; | ||
|
||
exports[`executableFile option should emit error: warnings 1`] = `Array []`; | ||
|
||
exports[`executableFile option should work: errors 1`] = `Array []`; | ||
|
||
exports[`executableFile option should work: result 1`] = ` | ||
"{ | ||
\\"content\\": \\"module.exports = 315360000000\\", | ||
\\"map\\": null, | ||
\\"meta\\": null, | ||
\\"dependencies\\": [ | ||
\\"test/fixtures/data.json\\" | ||
], | ||
\\"contextDependencies\\": [], | ||
\\"buildDependencies\\": [] | ||
}" | ||
`; | ||
|
||
exports[`executableFile option should work: warnings 1`] = `Array []`; |
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,90 @@ | ||
import path from "path"; | ||
|
||
import { getCompiler, compile, readAsset, normalizeErrors } from "./helpers"; | ||
|
||
describe("executableFile option", () => { | ||
it("should work", async () => { | ||
const compiler = getCompiler( | ||
"executableFileEntry.js", | ||
{}, | ||
{ | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(json)$/i, | ||
rules: [ | ||
{ | ||
loader: require.resolve("./helpers/helperLoader.js"), | ||
}, | ||
{ | ||
loader: require.resolve("../src"), | ||
options: { | ||
executableFile: path.resolve( | ||
__dirname, | ||
"fixtures", | ||
"executableFile.js" | ||
), | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
test: /\.json$/i, | ||
type: "asset/resource", | ||
}, | ||
], | ||
}, | ||
} | ||
); | ||
const stats = await compile(compiler); | ||
|
||
expect(readAsset("val-loader.js", compiler, stats)).toMatchSnapshot( | ||
"result" | ||
); | ||
expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( | ||
"warnings" | ||
); | ||
expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot("errors"); | ||
}); | ||
|
||
it("should emit error", async () => { | ||
const compiler = getCompiler( | ||
"executableFileEntry.js", | ||
{}, | ||
{ | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(json)$/i, | ||
rules: [ | ||
{ | ||
loader: require.resolve("./helpers/helperLoader.js"), | ||
}, | ||
{ | ||
loader: require.resolve("../src"), | ||
options: { | ||
executableFile: path.resolve( | ||
__dirname, | ||
"fixtures", | ||
"error-require.js" | ||
), | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
test: /\.json$/i, | ||
type: "asset/resource", | ||
}, | ||
], | ||
}, | ||
} | ||
); | ||
const stats = await compile(compiler); | ||
|
||
expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( | ||
"warnings" | ||
); | ||
expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot("errors"); | ||
}); | ||
}); |
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 @@ | ||
{ | ||
"years": "10" | ||
} |
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 @@ | ||
module.exports = function yearsInMs(options, loaderContext, content) { | ||
const {years} = JSON.parse(content); | ||
const value = years * 365 * 24 * 60 * 60 * 1000; | ||
|
||
return { | ||
cacheable: true, | ||
code: "module.exports = " + value, | ||
}; | ||
}; |
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 @@ | ||
const data = require('./data.json'); | ||
|
||
module.exports = {data}; |