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

fix: do not add js extension for eval source maps #17331

Merged
merged 1 commit into from Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/EvalSourceMapDevToolPlugin.js
Expand Up @@ -160,7 +160,8 @@ class EvalSourceMapDevToolPlugin {
}
sourceMap.sourceRoot = options.sourceRoot || "";
const moduleId = chunkGraph.getModuleId(m);
sourceMap.file = `${moduleId}.js`;
sourceMap.file =
typeof moduleId === "number" ? `${moduleId}.js` : moduleId;

const footer =
this.sourceMapComment.replace(
Expand Down
Expand Up @@ -5,6 +5,7 @@ it("should not include sourcesContent if noSources option is used", function() {
var mapString = Buffer.from(match[1], 'base64').toString('utf-8');
var map = JSON.parse(mapString);
expect(map).not.toHaveProperty("sourcesContent");
expect(/\.js(\?.+)?$/.test(map.file)).toBe(true);
});

if (Math.random() < 0) require("./test.js");
11 changes: 11 additions & 0 deletions test/configCases/devtools/eval-nosources-source-map/index.ts
@@ -0,0 +1,11 @@
it("should not include sourcesContent if noSources option is used", function() {
var fs = require("fs");
var source = fs.readFileSync(__filename, "utf-8");
var match = /\/\/# sourceMappingURL\s*=\s*data:application\/json;charset=utf-8;base64,(.*)\\n\/\/#/.exec(source);
var mapString = Buffer.from(match[1], 'base64').toString('utf-8');
var map = JSON.parse(mapString);
expect(map).not.toHaveProperty("sourcesContent");
expect(/\.ts(\?.+)?$/.test(map.file)).toBe(true);
});

if (Math.random() < 0) require("./test.js");

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -1,4 +1,83 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
devtool: "eval-nosources-source-map"
};
const devtool = "eval-nosources-source-map";

/** @type {import("../../../../").Configuration[]} */
module.exports = [
{
devtool
},
{
devtool,
optimization: {
moduleIds: "natural"
}
},
{
devtool,
optimization: {
moduleIds: "named"
}
},
{
devtool,
optimization: {
moduleIds: "deterministic"
}
},
{
devtool,
optimization: {
moduleIds: "size"
}
},
{
entry: "./index?foo=bar",
devtool,
optimization: {
moduleIds: "named"
}
},
{
entry: "./index.js?foo=bar",
devtool,
optimization: {
moduleIds: "named"
}
},
{
entry: "alias",
devtool,
optimization: {
moduleIds: "named"
},
resolve: {
alias: {
alias: "./index?foo=bar"
}
}
},
{
entry: "pkg",
devtool,
optimization: {
moduleIds: "named"
}
},
{
entry: "./index.ts?foo=bar",
devtool,
optimization: {
moduleIds: "named"
},
module: {
rules: [
{
test: /\.ts$/,
loader: "ts-loader",
options: {
transpileOnly: true
}
}
]
}
}
];
11 changes: 11 additions & 0 deletions test/configCases/devtools/eval-source-map/index.js
@@ -0,0 +1,11 @@
it("should not include sourcesContent if noSources option is used", function() {
var fs = require("fs");
var source = fs.readFileSync(__filename, "utf-8");
var match = /\/\/# sourceMappingURL\s*=\s*data:application\/json;charset=utf-8;base64,(.*)\\n\/\/#/.exec(source);
var mapString = Buffer.from(match[1], 'base64').toString('utf-8');
var map = JSON.parse(mapString);
expect(map).toHaveProperty("sourcesContent");
expect(/\.js(\?.+)?$/.test(map.file)).toBe(true);
});

if (Math.random() < 0) require("./test.js");
11 changes: 11 additions & 0 deletions test/configCases/devtools/eval-source-map/index.ts
@@ -0,0 +1,11 @@
it("should not include sourcesContent if noSources option is used", function() {
var fs = require("fs");
var source = fs.readFileSync(__filename, "utf-8");
var match = /\/\/# sourceMappingURL\s*=\s*data:application\/json;charset=utf-8;base64,(.*)\\n\/\/#/.exec(source);
var mapString = Buffer.from(match[1], 'base64').toString('utf-8');
var map = JSON.parse(mapString);
expect(map).toHaveProperty("sourcesContent");
expect(/\.ts(\?.+)?$/.test(map.file)).toBe(true);
});

if (Math.random() < 0) require("./test.js");

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/configCases/devtools/eval-source-map/test.js
@@ -0,0 +1,3 @@
var foo = {};

module.exports = foo;
83 changes: 83 additions & 0 deletions test/configCases/devtools/eval-source-map/webpack.config.js
@@ -0,0 +1,83 @@
const devtool = "eval-source-map";

/** @type {import("../../../../").Configuration[]} */
module.exports = [
{
devtool
},
{
devtool,
optimization: {
moduleIds: "natural"
}
},
{
devtool,
optimization: {
moduleIds: "named"
}
},
{
devtool,
optimization: {
moduleIds: "deterministic"
}
},
{
devtool,
optimization: {
moduleIds: "size"
}
},
{
entry: "./index?foo=bar",
devtool,
optimization: {
moduleIds: "named"
}
},
{
entry: "./index.js?foo=bar",
devtool,
optimization: {
moduleIds: "named"
}
},
{
entry: "alias",
devtool,
optimization: {
moduleIds: "named"
},
resolve: {
alias: {
alias: "./index?foo=bar"
}
}
},
{
entry: "pkg",
devtool,
optimization: {
moduleIds: "named"
}
},
{
entry: "./index.ts?foo=bar",
devtool,
optimization: {
moduleIds: "named"
},
module: {
rules: [
{
test: /\.ts$/,
loader: "ts-loader",
options: {
transpileOnly: true
}
}
]
}
}
];