Skip to content

Commit 10558a3

Browse files
fix(sourceMaps): Embed typescript sources in sourcemaps
1 parent 264d027 commit 10558a3

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
"version": "5.0.5",
55
"scripts": {
66
"clean": "shx rm -rf lib lib-esm _bundles",
7-
"build": "npm run clean && tsc && tsc -m es6 --outDir lib-esm && npm run fixdts && npm run bundle",
7+
"build": "npm run clean && tsc && tsc -m es6 --outDir lib-esm && npm run fixdts && npm run bundle && npm run fixmaps",
88
"bundle": "rollup -c && rollup -c --environment MINIFY",
99
"fixdts": "dts-downlevel 'lib/**/*.d.ts' 'lib-esm/**/*.d.ts'",
10-
"install": "node ./migrate/migratewarn.js",
10+
"fixmaps": "node scripts/modify_sourcemap_paths.js",
11+
"install": "node migrate/migratewarn.js",
1112
"prepare": "npm run build",
1213
"test": "karma start",
1314
"watch": "run-p watch:*",
@@ -55,8 +56,8 @@
5556
"engines": {
5657
"node": ">=4.0.0"
5758
},
59+
"main": "_bundles/ui-router-core.js",
5860
"jsnext:main": "lib-esm/index.js",
59-
"main": "lib/index.js",
6061
"typings": "lib/index.d.ts",
6162
"license": "MIT",
6263
"devDependencies": {
@@ -68,6 +69,7 @@
6869
"conventional-changelog-ui-router-core": "^1.4.1",
6970
"core-js": "^2.4.1",
7071
"dts-downlevel": "^0.3.0",
72+
"glob": "^7.1.2",
7173
"jasmine-core": "^2.4.1",
7274
"karma": "^1.2.0",
7375
"karma-chrome-launcher": "~0.1.0",

scripts/artifacts.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"ARTIFACTS": [
3+
"lib",
4+
"lib-esm",
5+
"_bundles",
6+
"package.json"
7+
]
8+
}

scripts/modify_sourcemap_paths.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!env node
2+
"use strict";
3+
4+
require('shelljs/global');
5+
const fs = require('fs');
6+
const path = require('path');
7+
const glob = require('glob');
8+
const pkgName = require('../package.json').name;
9+
const prefix = path.resolve(__dirname, '..');
10+
11+
const allartifacts = require('./artifacts.json').ARTIFACTS;
12+
const globs = allartifacts
13+
.map(dir => path.resolve(prefix, dir))
14+
.filter(dir => fs.lstatSync(dir).isDirectory())
15+
.map(dir => `${dir}/**/*.js.map`);
16+
17+
const files = globs
18+
.map(pattern => glob.sync(pattern))
19+
.reduce((acc, arr) => acc.concat(arr), []);
20+
21+
files.forEach(file => {
22+
const data = JSON.parse(fs.readFileSync(file));
23+
if (Array.isArray(data.sources)) {
24+
data.sources = data.sources.map(source => source.replace(/^(?:\.\.\/)*src/, pkgName));
25+
fs.writeFileSync(file, JSON.stringify(data));
26+
}
27+
});

tsconfig.esm.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"rootDir": "src",
1111
"outDir": "lib-esm",
1212
"declaration": true,
13-
"sourceMap": true
13+
"sourceMap": true,
14+
"inlineSources": true
1415
},
1516
"files": [
1617
"src/index.ts", "src/vanilla.ts"

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"rootDir": "src",
1111
"outDir": "lib",
1212
"declaration": true,
13-
"sourceMap": true
13+
"sourceMap": true,
14+
"inlineSources": true
1415
},
1516
"files": [
1617
"src/index.ts", "src/vanilla.ts"

0 commit comments

Comments
 (0)