diff --git a/src/intern-dev-build.ts b/src/intern-dev-build.ts index db00bf0..e29a7f0 100644 --- a/src/intern-dev-build.ts +++ b/src/intern-dev-build.ts @@ -1,8 +1,9 @@ #!/usr/bin/env node -import { echo } from 'shelljs'; -import { join, dirname } from 'path'; -import { buildDir, copyAll, exec, getConfigs, getResources } from './common'; +import { echo, sed } from 'shelljs'; +import { join, dirname, basename } from 'path'; +import { buildDir, copyAll, exec, getConfigs, getResources, tsconfig } from './common'; +import { sync as glob } from 'glob'; // Copy resources first in case some of them are needed for builds const resources = getResources(); @@ -15,4 +16,13 @@ getConfigs().forEach(function (tsconfig) { exec(`tsc -p "${tsconfig}"`); }); +if (tsconfig.compilerOptions.inlineSources) { + // If the project has inline sources in source maps set, set the path + // to the source file to be a sibling of the compiled file + echo('## Fixing source map paths'); + glob(join(buildDir, '**', '*.js.map'), { nodir: true }).forEach(function (filename) { + sed('-i', /("sources":\[")(.*?)("\])/, `$1${basename(filename, '.js.map')}.ts$3`, filename); + }); +} + echo('## Done building'); diff --git a/src/intern-dev-watch.ts b/src/intern-dev-watch.ts index b1e4148..1d96ad6 100644 --- a/src/intern-dev-watch.ts +++ b/src/intern-dev-watch.ts @@ -3,7 +3,7 @@ import { watch } from 'chokidar'; import { echo, exec } from 'shelljs'; import { join } from 'path'; -import { buildDir, copyAll, getResources, glob } from './common'; +import { buildDir, copyAll, getConfigs, getResources } from './common'; function createCopier(dest: string) { let outDir = join(buildDir, dest); @@ -12,11 +12,7 @@ function createCopier(dest: string) { }; } -glob('**/tsconfig.json').forEach(function (tsconfig) { - echo(`## Starting tsc watcher for ${tsconfig}`); - exec(`tsc --project "${tsconfig}" --watch`, { async: true }); -}); - +// Copy resources first in case some of them are needed for builds const resources = getResources(); Object.keys(resources).forEach(function (dest) { @@ -30,3 +26,8 @@ Object.keys(resources).forEach(function (dest) { echo('Watcher error:', error); }); }); + +getConfigs().forEach(function (tsconfig) { + echo(`## Starting tsc watcher for ${tsconfig}`); + exec(`tsc --project "${tsconfig}" --watch`, { async: true }); +});