Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 97fe63d

Browse files
committed
fix(@schematics/angular): fix migration asset paths
Fix angular/angular-cli#10146
1 parent d75cd23 commit 97fe63d

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

‎packages/schematics/angular/migrations/update-6/index.ts‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,22 +179,25 @@ function extractProjectsConfig(config: CliConfig, tree: Tree): JsonObject {
179179

180180
function _mapAssets(asset: string | JsonObject) {
181181
if (typeof asset === 'string') {
182-
return { glob: asset, input: normalize('/' + appRoot + '/'), output: '/' };
182+
if (tree.exists(app.root + '/' + asset)) {
183+
// If it exists in the tree, then it is a file.
184+
return { glob: asset, input: normalize(appRoot + '/'), output: '/' };
185+
} else {
186+
// If it does not exist, it is either a folder or something we can't statically know.
187+
// Folders must get a recursive star glob.
188+
return { glob: '**/*', input: normalize(appRoot + '/' + asset), output: '/' + asset };
189+
}
183190
} else {
184191
if (asset.output) {
185192
return {
186193
glob: asset.glob,
187-
input: normalize('/' + appRoot + '/' + asset.input),
188-
output: normalize('/'
189-
+ ((asset.output as string).startsWith(outDir)
190-
? (asset.output as string).slice(outDir.length)
191-
: (asset.output as string)),
192-
),
194+
input: normalize(appRoot + '/' + asset.input),
195+
output: normalize('/' + asset.output as string),
193196
};
194197
} else {
195198
return {
196199
glob: asset.glob,
197-
input: normalize('/' + appRoot + '/' + asset.input),
200+
input: normalize(appRoot + '/' + asset.input),
198201
output: '/',
199202
};
200203
}

‎packages/schematics/angular/migrations/update-6/index_spec.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ describe('Migration to v6', () => {
3838
assets: [
3939
'assets',
4040
'favicon.ico',
41+
{ glob: '**/*', input: './assets/', output: './assets/' },
42+
{ glob: 'favicon.ico', input: './', output: './' },
4143
],
4244
index: 'index.html',
4345
main: 'main.ts',
@@ -97,6 +99,7 @@ describe('Migration to v6', () => {
9799
production: true
98100
};
99101
`);
102+
tree.create('/src/favicon.ico', '');
100103
});
101104

102105
describe('file creation/deletion', () => {
@@ -499,8 +502,10 @@ describe('Migration to v6', () => {
499502
expect(build.options.scripts).toEqual([]);
500503
expect(build.options.styles).toEqual([{ input: 'src/styles.css' }]);
501504
expect(build.options.assets).toEqual([
502-
{ glob: 'assets', input: '/src', output: '/' },
503-
{ glob: 'favicon.ico', input: '/src', output: '/' },
505+
{ glob: '**/*', input: 'src/assets', output: '/assets' },
506+
{ glob: 'favicon.ico', input: 'src', output: '/' },
507+
{ glob: '**/*', input: 'src/assets', output: '/assets' },
508+
{ glob: 'favicon.ico', input: 'src', output: '/' },
504509
]);
505510
const prodConfig = build.configurations.production;
506511
expect(prodConfig.outputHashing).toEqual('all');
@@ -535,8 +540,10 @@ describe('Migration to v6', () => {
535540
expect(test.options.scripts).toEqual([]);
536541
expect(test.options.styles).toEqual([{ input: 'src/styles.css' }]);
537542
expect(test.options.assets).toEqual([
538-
{ glob: 'assets', input: '/src', output: '/' },
539-
{ glob: 'favicon.ico', input: '/src', output: '/' },
543+
{ glob: '**/*', input: 'src/assets', output: '/assets' },
544+
{ glob: 'favicon.ico', input: 'src', output: '/' },
545+
{ glob: '**/*', input: 'src/assets', output: '/assets' },
546+
{ glob: 'favicon.ico', input: 'src', output: '/' },
540547
]);
541548
});
542549

0 commit comments

Comments
 (0)