-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathrelative-sourcemap.ts
More file actions
57 lines (51 loc) · 2.13 KB
/
relative-sourcemap.ts
File metadata and controls
57 lines (51 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import assert from 'node:assert/strict';
import * as fs from 'node:fs';
import { isAbsolute } from 'node:path';
import { getGlobalVariable } from '../../utils/env';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
export default async function () {
// General secondary application project
await ng('generate', 'application', 'secondary-project', '--skip-install');
// Setup webpack builder if esbuild is not requested on the commandline
const useWebpackBuilder = !getGlobalVariable('argv')['esbuild'];
if (useWebpackBuilder) {
await updateJsonFile('angular.json', (json) => {
const build = json['projects']['secondary-project']['architect']['build'];
build.builder = '@angular-devkit/build-angular:browser';
build.options = {
...build.options,
main: build.options.browser,
browser: undefined,
outputPath: 'dist/secondary-project',
index: 'src/index.html',
};
build.configurations.development = {
...build.configurations.development,
vendorChunk: true,
namedChunks: true,
buildOptimizer: false,
};
});
}
await ng('build', 'secondary-project', '--configuration=development');
await ng('build', '--output-hashing=none', '--source-map', '--configuration=development');
const sourceMapPath = getGlobalVariable('argv')['esbuild']
? './dist/secondary-project/browser/main.js.map'
: './dist/secondary-project/main.js.map';
const content = fs.readFileSync(sourceMapPath, 'utf8');
const { sources } = JSON.parse(content) as { sources: string[] };
let mainFileFound = false;
for (const source of sources) {
assert(!isAbsolute(source), `Expected ${source} to be relative.`);
if (source.endsWith('main.ts')) {
mainFileFound = true;
assert(
source === 'projects/secondary-project/src/main.ts' ||
source === './projects/secondary-project/src/main.ts',
`Expected main file ${source} to be relative to the workspace root.`,
);
}
}
assert(mainFileFound, 'Could not find the main file in the application sourcemap sources array.');
}