-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathdedupe-duplicate-modules.ts
More file actions
65 lines (58 loc) · 2.12 KB
/
dedupe-duplicate-modules.ts
File metadata and controls
65 lines (58 loc) · 2.12 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
58
59
60
61
62
63
64
65
import { expectFileToMatch, rimraf, writeFile } from '../../utils/fs';
import { gitClean } from '../../utils/git';
import { installWorkspacePackages } from '../../utils/packages';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { expectToFail } from '../../utils/utils';
export default async function () {
try {
// Force duplicate modules
await updateJsonFile('package.json', (json) => {
json.dependencies = {
...json.dependencies,
'tslib': '^2.0.0',
'tslib-1': 'npm:tslib@1.13.0',
'tslib-1-copy': 'npm:tslib@1.13.0',
};
});
await installWorkspacePackages();
await writeFile(
'./src/main.ts',
`
import { __assign as __assign_0 } from 'tslib';
import { __assign as __assign_1 } from 'tslib-1';
import { __assign as __assign_2 } from 'tslib-1-copy';
console.log({
__assign_0,
__assign_1,
__assign_2,
})
`,
);
const { stderr } = await ng(
'build',
'--verbose',
'--no-vendor-chunk',
'--no-progress',
'--configuration=development',
);
const outFile = 'dist/test-project/browser/main.js';
if (/\[DedupeModuleResolvePlugin\]:.+tslib-1-copy.+ -> .+tslib-1.+/.test(stderr)) {
await expectFileToMatch(outFile, './node_modules/tslib-1/tslib.es6.js');
await expectToFail(() =>
expectFileToMatch(outFile, './node_modules/tslib-1-copy/tslib.es6.js'),
);
} else if (/\[DedupeModuleResolvePlugin\]:.+tslib-1.+ -> .+tslib-1-copy.+/.test(stderr)) {
await expectFileToMatch(outFile, './node_modules/tslib-1-copy/tslib.es6.js');
await expectToFail(() => expectFileToMatch(outFile, './node_modules/tslib-1/tslib.es6.js'));
} else {
console.error(`\n\n\n${stderr}\n\n\n`);
throw new Error('Expected stderr to contain [DedupeModuleResolvePlugin] log for tslib.');
}
await expectFileToMatch(outFile, './node_modules/tslib/tslib.es6.mjs');
} finally {
await rimraf('node_modules/tslib');
await gitClean();
await installWorkspacePackages();
}
}