Skip to content
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

Webpack 5 fixes #108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ node_modules
.node_repl_history

# NYC covergae information
.nyc_output
.nyc_output

# WebStorm/IntelliJ Project Files
*.iml
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ os:
language: node_js
node_js:
- "node"
- "14"
- "12"
- "10"
- "8"

script:
- npm test
Expand Down
3,341 changes: 700 additions & 2,641 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"rimraf": "^2.6.2",
"standard-version": "^4.4.0",
"style-loader": "^0.23.0",
"webpack": "^4.17.1",
"webpack": "^5.39.1",
"webpack-command": "^0.4.1"
},
"dependencies": {
Expand Down
18 changes: 8 additions & 10 deletions src/extractLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,17 @@ function rndNumber() {
* @returns {string}
*/
function getPublicPath(options, context) {
if ("publicPath" in options) {
return typeof options.publicPath === "function" ? options.publicPath(context) : options.publicPath;
}
let publicPath = "";

if (context.options && context.options.output && "publicPath" in context.options.output) {
return context.options.output.publicPath;
}

if (context._compilation && context._compilation.outputOptions && "publicPath" in context._compilation.outputOptions) {
return context._compilation.outputOptions.publicPath;
if ("publicPath" in options) {
publicPath = typeof options.publicPath === "function" ? options.publicPath(context) : options.publicPath;
} else if (context.options && context.options.output && "publicPath" in context.options.output) {
publicPath = context.options.output.publicPath;
} else if (context._compilation && context._compilation.outputOptions && "publicPath" in context._compilation.outputOptions) {
publicPath = context._compilation.outputOptions.publicPath;
}

return "";
return publicPath === "auto" ? "" : publicPath;
}
/* eslint-enable complexity */

Expand Down
13 changes: 7 additions & 6 deletions test/extractLoader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,8 @@ describe("extractLoader", () => {
dependency => dependency.slice(basePath.length)
);

expect(dependencies.sort()).to.eql(
expect(dependencies.sort()).to.include.members(
[
"/node_modules/css-loader/lib/css-base.js",
"/node_modules/css-loader/lib/url/escape.js",
"/test/modules/hi.jpg",
"/test/modules/img.css",
"/test/modules/stylesheet.html",
Expand Down Expand Up @@ -221,15 +219,18 @@ describe("extractLoader", () => {
expect(message).to.match(/Error: Can't resolve 'does-not-exist'/);
}
));
it("should not leak globals when there is an error during toString()", () =>
compile({testModule: "error-to-string.js"}).then(
it("should not leak globals when there is an error during toString()", () => {
delete global.btoa;

return compile({testModule: "error-to-string.js"}).then(
() => {
throw new Error("Did not throw expected error");
},
() => {
expect("btoa" in global).to.be.false;
}
));
);
});
it("should restore the original globals when there is an error during toString()", () => {
const myBtoa = {};

Expand Down
4 changes: 2 additions & 2 deletions test/support/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function compile({testModule, publicPath, loaderOptions}) {
},
{
test: /\.css$/,
loaders: [
use: [
{
loader: "file-loader",
options: {
Expand All @@ -82,7 +82,7 @@ function compile({testModule, publicPath, loaderOptions}) {
},
{
test: /\.jpg$/,
loaders: [
use: [
{
loader: "file-loader",
options: {
Expand Down