Skip to content

Commit

Permalink
fix(sourceMaps): Embed typescript sources in sourcemaps
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen committed Aug 12, 2017
1 parent 264d027 commit 10558a3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"version": "5.0.5",
"scripts": {
"clean": "shx rm -rf lib lib-esm _bundles",
"build": "npm run clean && tsc && tsc -m es6 --outDir lib-esm && npm run fixdts && npm run bundle",
"build": "npm run clean && tsc && tsc -m es6 --outDir lib-esm && npm run fixdts && npm run bundle && npm run fixmaps",
"bundle": "rollup -c && rollup -c --environment MINIFY",
"fixdts": "dts-downlevel 'lib/**/*.d.ts' 'lib-esm/**/*.d.ts'",
"install": "node ./migrate/migratewarn.js",
"fixmaps": "node scripts/modify_sourcemap_paths.js",
"install": "node migrate/migratewarn.js",
"prepare": "npm run build",
"test": "karma start",
"watch": "run-p watch:*",
Expand Down Expand Up @@ -55,8 +56,8 @@
"engines": {
"node": ">=4.0.0"
},
"main": "_bundles/ui-router-core.js",

This comment has been minimized.

Copy link
@christopherthielen

christopherthielen Oct 5, 2017

Author Member

this change seems to have caused problems with angular-cli bundling. It seems to bundle two copies of core.

"jsnext:main": "lib-esm/index.js",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"license": "MIT",
"devDependencies": {
Expand All @@ -68,6 +69,7 @@
"conventional-changelog-ui-router-core": "^1.4.1",
"core-js": "^2.4.1",
"dts-downlevel": "^0.3.0",
"glob": "^7.1.2",
"jasmine-core": "^2.4.1",
"karma": "^1.2.0",
"karma-chrome-launcher": "~0.1.0",
Expand Down
8 changes: 8 additions & 0 deletions scripts/artifacts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"ARTIFACTS": [
"lib",
"lib-esm",
"_bundles",
"package.json"
]
}
27 changes: 27 additions & 0 deletions scripts/modify_sourcemap_paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!env node
"use strict";

require('shelljs/global');
const fs = require('fs');
const path = require('path');
const glob = require('glob');
const pkgName = require('../package.json').name;
const prefix = path.resolve(__dirname, '..');

const allartifacts = require('./artifacts.json').ARTIFACTS;
const globs = allartifacts
.map(dir => path.resolve(prefix, dir))
.filter(dir => fs.lstatSync(dir).isDirectory())
.map(dir => `${dir}/**/*.js.map`);

const files = globs
.map(pattern => glob.sync(pattern))
.reduce((acc, arr) => acc.concat(arr), []);

files.forEach(file => {
const data = JSON.parse(fs.readFileSync(file));
if (Array.isArray(data.sources)) {
data.sources = data.sources.map(source => source.replace(/^(?:\.\.\/)*src/, pkgName));
fs.writeFileSync(file, JSON.stringify(data));
}
});
3 changes: 2 additions & 1 deletion tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"rootDir": "src",
"outDir": "lib-esm",
"declaration": true,
"sourceMap": true
"sourceMap": true,
"inlineSources": true
},
"files": [
"src/index.ts", "src/vanilla.ts"
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"rootDir": "src",
"outDir": "lib",
"declaration": true,
"sourceMap": true
"sourceMap": true,
"inlineSources": true
},
"files": [
"src/index.ts", "src/vanilla.ts"
Expand Down

0 comments on commit 10558a3

Please sign in to comment.