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 minified source-map outputs format #504

Merged
merged 2 commits into from
Feb 12, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,10 @@ module.exports = (
// For some reason, auth0 returns "undefined"!
// custom terser phase used over Webpack integration for this reason
if (result.code !== undefined)
({ code, map } = { code: result.code, map: result.map });
({ code, map } = {
code: result.code,
map: sourceMap ? JSON.parse(result.map) : undefined
});
}

if (v8cache) {
Expand Down
35 changes: 32 additions & 3 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,32 @@ for (const unitTest of fs.readdirSync(`${__dirname}/unit`)) {
.trim()
// Windows support
.replace(/\r/g, "");
let expectedSoureMap;
try {
expectedSoureMap = fs
.readFileSync(`${testDir}/output${global.coverage ? '-coverage' : ''}.js.map`)
.toString()
.trim()
// Windows support
.replace(/\r/g, "");
} catch (_) {}

let opts;
try {
opts = fs.readFileSync(`${testDir}/opt.json`, 'utf8');
opts = JSON.parse(opts);
} catch (_) {}

// set env variable so tsconfig-paths can find the config
process.env.TS_NODE_PROJECT = `${testDir}/tsconfig.json`;
// find the name of the input file (e.g input.ts)
const inputFile = fs.readdirSync(testDir).find(file => file.includes("input"));
await ncc(`${testDir}/${inputFile}`, {
await ncc(`${testDir}/${inputFile}`, Object.assign({
externals: {
'externaltest': 'externalmapped'
}
}).then(
async ({ code, assets }) => {
}, opts)).then(
async ({ code, assets, map }) => {
const actual = code
.trim()
// Windows support
Expand All @@ -33,6 +48,20 @@ for (const unitTest of fs.readdirSync(`${__dirname}/unit`)) {
fs.writeFileSync(`${testDir}/actual.js`, actual);
throw e;
}

if (map) {
const actualSourceMap = map
.trim()
// Windows support
.replace(/\r/g, "");
try {
expect(actualSourceMap).toBe(expectedSoureMap);
} catch (e) {
// useful for updating fixtures
fs.writeFileSync(`${testDir}/actual.js.map`, actualSourceMap);
throw e;
}
}
}
);
});
Expand Down
2 changes: 2 additions & 0 deletions test/unit/minify/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const foobar = 'qux'
exports.foobar = foobar
5 changes: 5 additions & 0 deletions test/unit/minify/opt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"minify": true,
"sourceMap": true,
"sourceMapRegister": false
}
2 changes: 2 additions & 0 deletions test/unit/minify/output-coverage.js

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

1 change: 1 addition & 0 deletions test/unit/minify/output-coverage.js.map

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

2 changes: 2 additions & 0 deletions test/unit/minify/output.js

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

1 change: 1 addition & 0 deletions test/unit/minify/output.js.map

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