-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathts-paths.ts
More file actions
53 lines (45 loc) · 1.73 KB
/
ts-paths.ts
File metadata and controls
53 lines (45 loc) · 1.73 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
import { appendToFile, createDir, replaceInFile, rimraf, writeMultipleFiles } from '../../utils/fs';
import { ng } from '../../utils/process';
import { updateTsConfig } from '../../utils/project';
export default async function () {
await updateTsConfig((json) => {
json['compilerOptions']['paths'] = {
'@shared': ['./src/app/shared'],
'@shared/*': ['./src/app/shared/*'],
'@root/*': ['./src/*'],
'src/*': ['./src/*'],
};
});
await createDir('src/app/shared');
await writeMultipleFiles({
'src/meaning-too.ts': 'export var meaning = 42;',
'src/app/shared/meaning.ts': 'export var meaning = 42;',
'src/app/shared/index.ts': `export * from './meaning'`,
});
await replaceInFile('src/main.ts', './app/app', '@root/app/app');
await ng('build', '--configuration=development');
await updateTsConfig((json) => {
json['compilerOptions']['paths']['*'] = ['./*', './src/app/shared/*'];
});
await appendToFile(
'src/app/app.ts',
`
import { meaning } from 'src/app/shared/meaning';
import { meaning as meaning2 } from '@shared';
import { meaning as meaning3 } from '@shared/meaning';
import { meaning as meaning4 } from 'meaning';
import { meaning as meaning5 } from 'src/meaning-too';
// need to use imports otherwise they are ignored and
// no error is outputted, even if baseUrl/paths don't work
console.log(meaning)
console.log(meaning2)
console.log(meaning3)
console.log(meaning4)
console.log(meaning5)
`,
);
await ng('build', '--configuration=development');
// Simulate no package.json file which causes Webpack to have an undefined 'descriptionFileData'.
await rimraf('package.json');
await ng('build', '--configuration=development');
}