Skip to content

Commit

Permalink
Merge pull request #17331 from webpack/issue-16415
Browse files Browse the repository at this point in the history
fix: do not add `js` extension for eval source maps
  • Loading branch information
TheLarkInn committed Jun 7, 2023
2 parents 7a2d3d8 + aa27d49 commit 7c1cdda
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 5 deletions.
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
}
}
]
}
}
];

0 comments on commit 7c1cdda

Please sign in to comment.