Skip to content

Commit 324426b

Browse files
committed
Source map referenced but not included in published package. Fixes #4
1 parent b814cdc commit 324426b

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

build/remove-sourcemap-refs.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
const fs = require('fs');
7+
const path = require('path');
8+
9+
function deleteRefs(dir) {
10+
const files = fs.readdirSync(dir);
11+
for (let file of files) {
12+
const filePath = path.join(dir, file);
13+
const stat = fs.statSync(filePath);
14+
if (stat.isDirectory()) {
15+
deleteRefs(filePath);
16+
} else if (path.extname(file) === '.js') {
17+
const content = fs.readFileSync(filePath, 'utf8');
18+
const newContent = content.replace(/\/\/\# sourceMappingURL=[^]+.js.map/, '')
19+
if (content.length !== newContent.length) {
20+
console.log('remove sourceMappingURL in ' + filePath);
21+
fs.writeFileSync(filePath, newContent);
22+
}
23+
} else if (path.extname(file) === '.map') {
24+
fs.unlinkSync(filePath)
25+
console.log('remove ' + filePath);
26+
}
27+
}
28+
}
29+
30+
let location = path.join(__dirname, '..', 'lib');
31+
console.log('process ' + location);
32+
deleteRefs(location);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
"rimraf": "^3.0.0"
2424
},
2525
"scripts": {
26-
"prepublishOnly": "npm run clean && npm run compile-esm && npm run test",
26+
"prepublishOnly": "npm run clean && npm run compile-esm && npm run test && npm run remove-sourcemap-refs",
2727
"postpublish": "node ./build/post-publish.js",
2828
"compile": "tsc -p ./src",
2929
"compile-esm": "tsc -p ./src/tsconfig.esm.json",
30+
"remove-sourcemap-refs": "node ./build/remove-sourcemap-refs.js",
3031
"clean": "rimraf lib",
3132
"watch": "tsc -w -p ./src",
3233
"test": "npm run compile && mocha",

0 commit comments

Comments
 (0)