Skip to content

Commit

Permalink
Source map referenced but not included in published package. Fixes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli committed Oct 25, 2019
1 parent b814cdc commit 324426b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
32 changes: 32 additions & 0 deletions build/remove-sourcemap-refs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

const fs = require('fs');
const path = require('path');

function deleteRefs(dir) {
const files = fs.readdirSync(dir);
for (let file of files) {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
deleteRefs(filePath);
} else if (path.extname(file) === '.js') {
const content = fs.readFileSync(filePath, 'utf8');
const newContent = content.replace(/\/\/\# sourceMappingURL=[^]+.js.map/, '')
if (content.length !== newContent.length) {
console.log('remove sourceMappingURL in ' + filePath);
fs.writeFileSync(filePath, newContent);
}
} else if (path.extname(file) === '.map') {
fs.unlinkSync(filePath)
console.log('remove ' + filePath);
}
}
}

let location = path.join(__dirname, '..', 'lib');
console.log('process ' + location);
deleteRefs(location);
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
"rimraf": "^3.0.0"
},
"scripts": {
"prepublishOnly": "npm run clean && npm run compile-esm && npm run test",
"prepublishOnly": "npm run clean && npm run compile-esm && npm run test && npm run remove-sourcemap-refs",
"postpublish": "node ./build/post-publish.js",
"compile": "tsc -p ./src",
"compile-esm": "tsc -p ./src/tsconfig.esm.json",
"remove-sourcemap-refs": "node ./build/remove-sourcemap-refs.js",
"clean": "rimraf lib",
"watch": "tsc -w -p ./src",
"test": "npm run compile && mocha",
Expand Down

0 comments on commit 324426b

Please sign in to comment.