Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(angular): generate public directory instead of assets #22801

Merged
merged 3 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/generated/packages/angular/executors/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@
},
"output": {
"type": "string",
"default": "",
"description": "Absolute path within the output."
}
},
"additionalProperties": false,
"required": ["glob", "input", "output"]
"required": ["glob", "input"]
},
{ "type": "string" }
]
Expand Down Expand Up @@ -663,11 +664,12 @@
},
"output": {
"type": "string",
"default": "",
"description": "Absolute path within the output."
}
},
"additionalProperties": false,
"required": ["glob", "input", "output"]
"required": ["glob", "input"]
},
{ "type": "string" }
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@
},
"output": {
"type": "string",
"default": "",
"description": "Absolute path within the output."
}
},
"additionalProperties": false,
"required": ["glob", "input", "output"]
"required": ["glob", "input"]
},
{ "type": "string" }
]
Expand Down Expand Up @@ -572,11 +573,12 @@
},
"output": {
"type": "string",
"default": "",
"description": "Absolute path within the output."
}
},
"additionalProperties": false,
"required": ["glob", "input", "output"]
"required": ["glob", "input"]
},
{ "type": "string" }
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@
},
"output": {
"type": "string",
"default": "",
"description": "Absolute path within the output."
}
},
"additionalProperties": false,
"required": ["glob", "input", "output"]
"required": ["glob", "input"]
},
{ "type": "string" }
]
Expand Down Expand Up @@ -592,11 +593,12 @@
},
"output": {
"type": "string",
"default": "",
"description": "Absolute path within the output."
}
},
"additionalProperties": false,
"required": ["glob", "input", "output"]
"required": ["glob", "input"]
},
{ "type": "string" }
]
Expand Down
6 changes: 4 additions & 2 deletions docs/generated/packages/angular/executors/webpack-server.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@
},
"output": {
"type": "string",
"default": "",
"description": "Absolute path within the output."
}
},
"additionalProperties": false,
"required": ["glob", "input", "output"]
"required": ["glob", "input"]
},
{ "type": "string" }
]
Expand Down Expand Up @@ -323,11 +324,12 @@
},
"output": {
"type": "string",
"default": "",
"description": "Absolute path within the output."
}
},
"additionalProperties": false,
"required": ["glob", "input", "output"]
"required": ["glob", "input"]
},
{ "type": "string" }
]
Expand Down
12 changes: 3 additions & 9 deletions e2e/angular-core/src/ng-add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
cleanupProject();
});

it('should generate a workspace', () => {
it('hhhhhhshould generate a workspace', () => {
leosvelperez marked this conversation as resolved.
Show resolved Hide resolved
addProtractor();

// update package.json
Expand Down Expand Up @@ -185,10 +185,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
browser: `apps/${project}/src/main.ts`,
polyfills: [`zone.js`],
tsConfig: `apps/${project}/tsconfig.app.json`,
assets: [
`apps/${project}/src/favicon.ico`,
`apps/${project}/src/assets`,
],
assets: [{ glob: '**/*', input: `apps/${project}/public` }],
styles: [`apps/${project}/src/styles.css`],
scripts: [`apps/${project}/src/scripts.js`],
},
Expand Down Expand Up @@ -229,10 +226,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
options: {
polyfills: [`zone.js`, `zone.js/testing`],
tsConfig: `apps/${project}/tsconfig.spec.json`,
assets: [
`apps/${project}/src/favicon.ico`,
`apps/${project}/src/assets`,
],
assets: [{ glob: '**/*', input: `apps/${project}/public` }],
styles: [`apps/${project}/src/styles.css`],
scripts: [`apps/${project}/src/scripts.js`],
},
Expand Down
3 changes: 1 addition & 2 deletions e2e/angular-extensions/src/misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Move Angular Project', () => {
expect(moveOutput).toContain(`CREATE ${newPath}/tsconfig.json`);
expect(moveOutput).toContain(`CREATE ${newPath}/tsconfig.spec.json`);
expect(moveOutput).toContain(`CREATE ${newPath}/.eslintrc.json`);
expect(moveOutput).toContain(`CREATE ${newPath}/src/favicon.ico`);
expect(moveOutput).toContain(`CREATE ${newPath}/public/favicon.ico`);
expect(moveOutput).toContain(`CREATE ${newPath}/src/index.html`);
expect(moveOutput).toContain(`CREATE ${newPath}/src/main.ts`);
expect(moveOutput).toContain(`CREATE ${newPath}/src/styles.css`);
Expand All @@ -52,7 +52,6 @@ describe('Move Angular Project', () => {
);
expect(moveOutput).toContain(`CREATE ${newPath}/src/app/app.component.ts`);
expect(moveOutput).toContain(`CREATE ${newPath}/src/app/app.config.ts`);
expect(moveOutput).toContain(`CREATE ${newPath}/src/assets/.gitkeep`);
});

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/angular/src/builders/webpack-browser/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,12 @@
},
"output": {
"type": "string",
"default": "",
"description": "Absolute path within the output."
}
},
"additionalProperties": false,
"required": ["glob", "input", "output"]
"required": ["glob", "input"]
},
{
"type": "string"
Expand Down
3 changes: 2 additions & 1 deletion packages/angular/src/builders/webpack-server/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,12 @@
},
"output": {
"type": "string",
"default": "",
"description": "Absolute path within the output."
}
},
"additionalProperties": false,
"required": ["glob", "input", "output"]
"required": ["glob", "input"]
},
{
"type": "string"
Expand Down
3 changes: 2 additions & 1 deletion packages/angular/src/executors/application/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,12 @@
},
"output": {
"type": "string",
"default": "",
"description": "Absolute path within the output."
}
},
"additionalProperties": false,
"required": ["glob", "input", "output"]
"required": ["glob", "input"]
},
{
"type": "string"
Expand Down
3 changes: 2 additions & 1 deletion packages/angular/src/executors/browser-esbuild/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,12 @@
},
"output": {
"type": "string",
"default": "",
"description": "Absolute path within the output."
}
},
"additionalProperties": false,
"required": ["glob", "input", "output"]
"required": ["glob", "input"]
},
{
"type": "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,10 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh
"executor": "@angular-devkit/build-angular:application",
"options": {
"assets": [
"apps/my-dir/my-app/src/favicon.ico",
"apps/my-dir/my-app/src/assets",
{
"glob": "**/*",
"input": "apps/my-dir/my-app/public",
},
],
"browser": "apps/my-dir/my-app/src/main.ts",
"index": "apps/my-dir/my-app/src/index.html",
Expand Down Expand Up @@ -444,8 +446,10 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh
"executor": "@angular-devkit/build-angular:application",
"options": {
"assets": [
"apps/my-app/src/favicon.ico",
"apps/my-app/src/assets",
{
"glob": "**/*",
"input": "apps/my-app/public",
},
],
"browser": "apps/my-app/src/main.ts",
"index": "apps/my-app/src/index.html",
Expand Down Expand Up @@ -819,7 +823,7 @@ exports[`app --strict should enable strict type checking: e2e tsconfig.json 1`]
}
`;

exports[`app angular v15 support should import "ApplicationConfig" from "@angular/platform-browser" 1`] = `
exports[`app angular compat support should import "ApplicationConfig" from "@angular/platform-browser" 1`] = `
"import { ApplicationConfig } from '@angular/platform-browser';
import { provideRouter } from '@angular/router';
import { appRoutes } from './app.routes';
Expand Down Expand Up @@ -940,8 +944,10 @@ exports[`app nested should create project configs 1`] = `
"executor": "@angular-devkit/build-angular:application",
"options": {
"assets": [
"my-dir/my-app/src/favicon.ico",
"my-dir/my-app/src/assets",
{
"glob": "**/*",
"input": "my-dir/my-app/public",
},
],
"browser": "my-dir/my-app/src/main.ts",
"index": "my-dir/my-app/src/index.html",
Expand Down Expand Up @@ -1054,8 +1060,10 @@ exports[`app not nested should create project configs 1`] = `
"executor": "@angular-devkit/build-angular:application",
"options": {
"assets": [
"my-app/src/favicon.ico",
"my-app/src/assets",
{
"glob": "**/*",
"input": "my-app/public",
},
],
"browser": "my-app/src/main.ts",
"index": "my-app/src/index.html",
Expand Down
17 changes: 16 additions & 1 deletion packages/angular/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ describe('app', () => {
});
});

describe('angular v15 support', () => {
describe('angular compat support', () => {
beforeEach(() => {
appTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
updateJson(appTree, 'package.json', (json) => ({
Expand Down Expand Up @@ -1260,6 +1260,21 @@ describe('app', () => {
.esModuleInterop
).toBeUndefined();
});

it('should configure the correct assets for versions lower than v18', async () => {
updateJson(appTree, 'package.json', (json) => ({
...json,
dependencies: { ...json.dependencies, '@angular/core': '~17.0.0' },
}));

await generateApp(appTree, 'my-app', { rootProject: true });

const project = readProjectConfiguration(appTree, 'my-app');
expect(project.targets.build.options.assets).toStrictEqual([
'./src/favicon.ico',
'./src/assets',
]);
});
});
});

Expand Down
Binary file not shown.
16 changes: 16 additions & 0 deletions packages/angular/src/generators/application/lib/create-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ export async function createFiles(
substitutions
);

if (angularMajorVersion >= 18) {
generateFiles(
tree,
joinPathFragments(__dirname, '../files/base-18+'),
options.appProjectRoot,
substitutions
);
} else {
generateFiles(
tree,
joinPathFragments(__dirname, '../files/base-pre18'),
options.appProjectRoot,
substitutions
);
}

if (options.standalone) {
generateFiles(
tree,
Expand Down
23 changes: 17 additions & 6 deletions packages/angular/src/generators/application/lib/create-project.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addProjectConfiguration, Tree } from '@nx/devkit';
import { addProjectConfiguration, joinPathFragments, Tree } from '@nx/devkit';
import type { AngularProjectConfiguration } from '../../../utils/types';
import { getInstalledAngularVersionInfo } from '../../utils/version-utils';
import type { NormalizedSchema } from './normalized-schema';
Expand Down Expand Up @@ -64,12 +64,23 @@ export function createProject(tree: Tree, options: NormalizedSchema) {
index: `${options.appProjectSourceRoot}/index.html`,
[buildMainOptionName]: `${options.appProjectSourceRoot}/main.ts`,
polyfills: ['zone.js'],
tsConfig: `${options.appProjectRoot}/tsconfig.app.json`,
tsConfig: joinPathFragments(
options.appProjectRoot,
'tsconfig.app.json'
),
inlineStyleLanguage,
assets: [
`${options.appProjectSourceRoot}/favicon.ico`,
`${options.appProjectSourceRoot}/assets`,
],
assets:
angularMajorVersion >= 18
? [
{
glob: '**/*',
input: joinPathFragments(options.appProjectRoot, 'public'),
},
]
: [
`${options.appProjectSourceRoot}/favicon.ico`,
`${options.appProjectSourceRoot}/assets`,
],
styles: [`${options.appProjectSourceRoot}/styles.${options.style}`],
scripts: [],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ export class AngularDevkitKarmaMigrator extends BuilderMigrator {
target.options.main =
target.options.main && this.convertAsset(target.options.main);
target.options.polyfills = Array.isArray(target.options.polyfills)
? target.options.polyfills.map((p) => this.convertAsset(p))
: target.options.polyfills && this.convertAsset(target.options.polyfills);
? target.options.polyfills.map((p) => this.convertSourceRootPath(p))
: target.options.polyfills &&
this.convertSourceRootPath(target.options.polyfills);
target.options.tsConfig =
target.options.tsConfig &&
joinPathFragments(
Expand Down
Loading