diff --git a/package.json b/package.json index 6e4d0aab..1c5e22cf 100644 --- a/package.json +++ b/package.json @@ -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:*", @@ -55,8 +56,8 @@ "engines": { "node": ">=4.0.0" }, + "main": "_bundles/ui-router-core.js", "jsnext:main": "lib-esm/index.js", - "main": "lib/index.js", "typings": "lib/index.d.ts", "license": "MIT", "devDependencies": { @@ -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", diff --git a/scripts/artifacts.json b/scripts/artifacts.json new file mode 100644 index 00000000..363bb1a5 --- /dev/null +++ b/scripts/artifacts.json @@ -0,0 +1,8 @@ +{ + "ARTIFACTS": [ + "lib", + "lib-esm", + "_bundles", + "package.json" + ] +} diff --git a/scripts/modify_sourcemap_paths.js b/scripts/modify_sourcemap_paths.js new file mode 100644 index 00000000..dba78c4b --- /dev/null +++ b/scripts/modify_sourcemap_paths.js @@ -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)); + } +}); diff --git a/tsconfig.esm.json b/tsconfig.esm.json index c6f0f26a..d0368a07 100644 --- a/tsconfig.esm.json +++ b/tsconfig.esm.json @@ -10,7 +10,8 @@ "rootDir": "src", "outDir": "lib-esm", "declaration": true, - "sourceMap": true + "sourceMap": true, + "inlineSources": true }, "files": [ "src/index.ts", "src/vanilla.ts" diff --git a/tsconfig.json b/tsconfig.json index 55d96a4a..173c1dbf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,8 @@ "rootDir": "src", "outDir": "lib", "declaration": true, - "sourceMap": true + "sourceMap": true, + "inlineSources": true }, "files": [ "src/index.ts", "src/vanilla.ts"