Skip to content

Commit

Permalink
Fix paths in source maps with inline sources and ensure resources are…
Browse files Browse the repository at this point in the history
… copied first in watch script
  • Loading branch information
bryanforbes committed Dec 19, 2016
1 parent 43aae29 commit b828cf9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
16 changes: 13 additions & 3 deletions src/intern-dev-build.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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');
13 changes: 7 additions & 6 deletions src/intern-dev-watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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 });
});

0 comments on commit b828cf9

Please sign in to comment.