Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add a trailing slash automatically for sourcemapBaseUrl (#5022)
fix: add a trailing slash automatically
- Loading branch information
Showing
5 changed files
with
32 additions
and
11 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
17 changes: 17 additions & 0 deletions
17
test/sourcemaps/samples/sourcemap-base-url-without-trailing-slash/_config.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,17 @@ | ||
const assert = require('node:assert'); | ||
|
||
module.exports = defineTest({ | ||
description: 'add a trailing slash automatically if it is missing', | ||
options: { | ||
output: { | ||
sourcemapBaseUrl: 'https://example.com/a' | ||
} | ||
}, | ||
test: (code, map, { format }) => { | ||
const sourceMappingURL = code.split('\n').slice(-2)[0]; | ||
assert.strictEqual( | ||
sourceMappingURL, | ||
`//# sourceMappingURL=https://example.com/a/bundle.${format}.js.map` | ||
); | ||
} | ||
}); |
1 change: 1 addition & 0 deletions
1
test/sourcemaps/samples/sourcemap-base-url-without-trailing-slash/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 @@ | ||
assert.ok(true); |
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 |
---|---|---|
@@ -1,22 +1,18 @@ | ||
const assert = require('node:assert'); | ||
const fs = require('node:fs'); | ||
const path = require('node:path'); | ||
|
||
module.exports = defineTest({ | ||
description: 'adds a sourcemap base url', | ||
options: { | ||
output: { | ||
sourcemapBaseUrl: 'https://example.com' | ||
sourcemapBaseUrl: 'https://example.com/a/' | ||
} | ||
}, | ||
test: (code, map, profile) => { | ||
assert.equal(map.file, `bundle.${profile.format}.js`); | ||
const bundlePath = path.join(__dirname, `_actual/bundle.${profile.format}.js`); | ||
const bundledCode = fs.readFileSync(bundlePath, { encoding: 'utf8', flag: 'r' }); | ||
const sourceMappingURL = bundledCode.split('\n').slice(-2)[0]; | ||
test: (code, map, { format }) => { | ||
assert.equal(map.file, `bundle.${format}.js`); | ||
const sourceMappingURL = code.split('\n').slice(-2)[0]; | ||
assert.equal( | ||
sourceMappingURL, | ||
`//# sourceMappingURL=https://example.com/bundle.${profile.format}.js.map` | ||
`//# sourceMappingURL=https://example.com/a/bundle.${format}.js.map` | ||
); | ||
} | ||
}); |