Skip to content

Commit

Permalink
fix(@schematics/angular): set builders assets option correctly for …
Browse files Browse the repository at this point in the history
…new applications

This commit ensures that the `assets` option value accurately reflects the source location.

Closes: #27709
(cherry picked from commit 8ea94eb)
  • Loading branch information
alan-agius4 committed May 28, 2024
1 parent 3bb06c3 commit 92b48ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/schematics/angular/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function addAppToWorkspaceFile(
polyfills: ['zone.js'],
tsConfig: `${projectRoot}tsconfig.app.json`,
inlineStyleLanguage,
assets: [{ 'glob': '**/*', 'input': 'public' }],
assets: [{ 'glob': '**/*', 'input': `${projectRoot}public` }],
styles: [`${sourceRoot}/styles.${options.style}`],
scripts: [],
},
Expand Down Expand Up @@ -282,7 +282,7 @@ function addAppToWorkspaceFile(
polyfills: ['zone.js', 'zone.js/testing'],
tsConfig: `${projectRoot}tsconfig.spec.json`,
inlineStyleLanguage,
assets: [{ 'glob': '**/*', 'input': 'public' }],
assets: [{ 'glob': '**/*', 'input': `${projectRoot}public` }],
styles: [`${sourceRoot}/styles.${options.style}`],
scripts: [],
},
Expand Down
10 changes: 9 additions & 1 deletion packages/schematics/angular/application/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ describe('Application Schematic', () => {

it('should set values in angular.json correctly', async () => {
const options = { ...defaultOptions, projectRoot: '' };

const tree = await schematicRunner.runSchematic('application', options, workspaceTree);

const config = JSON.parse(tree.readContent('/angular.json'));
Expand All @@ -286,12 +285,14 @@ describe('Application Schematic', () => {
const buildOpt = prj.architect.build.options;
expect(buildOpt.index).toEqual('src/index.html');
expect(buildOpt.browser).toEqual('src/main.ts');
expect(buildOpt.assets).toEqual([{ 'glob': '**/*', 'input': 'public' }]);
expect(buildOpt.polyfills).toEqual(['zone.js']);
expect(buildOpt.tsConfig).toEqual('tsconfig.app.json');

const testOpt = prj.architect.test.options;
expect(testOpt.tsConfig).toEqual('tsconfig.spec.json');
expect(testOpt.karmaConfig).toBeUndefined();
expect(testOpt.assets).toEqual([{ 'glob': '**/*', 'input': 'public' }]);
expect(testOpt.styles).toEqual(['src/styles.css']);
});

Expand Down Expand Up @@ -377,6 +378,13 @@ describe('Application Schematic', () => {
expect(buildOpt.browser).toEqual('foo/src/main.ts');
expect(buildOpt.polyfills).toEqual(['zone.js']);
expect(buildOpt.tsConfig).toEqual('foo/tsconfig.app.json');
expect(buildOpt.assets).toEqual([{ 'glob': '**/*', 'input': 'foo/public' }]);

const testOpt = project.architect.test.options;
expect(testOpt.tsConfig).toEqual('foo/tsconfig.spec.json');
expect(testOpt.karmaConfig).toBeUndefined();
expect(testOpt.assets).toEqual([{ 'glob': '**/*', 'input': 'foo/public' }]);
expect(testOpt.styles).toEqual(['foo/src/styles.css']);

const appTsConfig = readJsonFile(tree, '/foo/tsconfig.app.json');
expect(appTsConfig.extends).toEqual('../tsconfig.json');
Expand Down

0 comments on commit 92b48ab

Please sign in to comment.