/
universal-bundle-dependencies.ts
66 lines (60 loc) · 1.86 KB
/
universal-bundle-dependencies.ts
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
58
59
60
61
62
63
64
65
66
import * as path from 'path';
import {
createDir,
expectFileToMatch,
rimraf,
symlinkFile,
writeMultipleFiles,
} from '../../utils/fs';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
export default async function () {
await updateJsonFile('angular.json', (workspaceJson) => {
const appArchitect = workspaceJson.projects['test-project'].architect;
appArchitect['server'] = {
builder: '@angular-devkit/build-angular:server',
options: {
bundleDependencies: false,
outputPath: 'dist/test-project-server',
main: 'src/main.server.ts',
tsConfig: 'tsconfig.server.json',
},
};
});
await createDir('./dummy-lib');
await writeMultipleFiles({
'./tsconfig.server.json': `
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../dist-server",
"baseUrl": "./",
"module": "commonjs",
"types": []
},
"include": [
"src/main.server.ts"
]
}
`,
'./src/main.server.ts': `
import { dummyVersion } from 'dummy-lib';
console.log(dummyVersion);
`,
// create a dummy library
'./dummy-lib/package.json': `{
"name": "dummy-lib",
"version": "0.0.0",
"typings": "./main.d.ts",
"main": "./main.js"
}`,
'./dummy-lib/main.js': 'export const dummyVersion = 1',
'./dummy-lib/main.d.ts': 'export declare const dummyVersion = 1',
});
await symlinkFile(path.resolve('./dummy-lib'), path.resolve('./node_modules/dummy-lib'), 'dir');
await ng('run', 'test-project:server');
// when preserve symlinks is true, it should not included node_modules in the bundle
await expectFileToMatch('dist/test-project-server/main.js', 'require("dummy-lib")');
// cleanup the package
await rimraf('node_modules/dummy-lib');
}