Skip to content

fix(@schematics/angular): remove explicit index option from new applications #30192

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 13 additions & 0 deletions packages/angular/pwa/pwa/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,12 @@ export default function (options: PwaOptions): Rule {

// Find all index.html files in build targets
const indexFiles = new Set<string>();
let checkForDefaultIndex = false;
for (const target of buildTargets) {
if (typeof target.options?.index === 'string') {
indexFiles.add(target.options.index);
} else if (target.options?.index === undefined) {
checkForDefaultIndex = true;
}

if (!target.configurations) {
Expand All @@ -122,13 +125,23 @@ export default function (options: PwaOptions): Rule {
for (const options of Object.values(target.configurations)) {
if (typeof options?.index === 'string') {
indexFiles.add(options.index);
} else if (options?.index === undefined) {
checkForDefaultIndex = true;
}
}
}

// Setup sources for the assets files to add to the project
const sourcePath = project.sourceRoot ?? posix.join(project.root, 'src');

// Check for a default index file if a configuration path allows for a default usage
if (checkForDefaultIndex) {
const defaultIndexFile = posix.join(sourcePath, 'index.html');
if (host.exists(defaultIndexFile)) {
indexFiles.add(defaultIndexFile);
}
}

// Setup service worker schematic options
const { title, ...swOptions } = options;

Expand Down
1 change: 0 additions & 1 deletion packages/schematics/angular/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ function addAppToWorkspaceFile(
builder: Builders.BuildApplication,
defaultConfiguration: 'production',
options: {
index: `${sourceRoot}/index.html`,
browser: `${sourceRoot}/main.ts`,
polyfills: options.experimentalZoneless ? [] : ['zone.js'],
tsConfig: `${projectRoot}tsconfig.app.json`,
Expand Down
3 changes: 1 addition & 2 deletions packages/schematics/angular/application/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ describe('Application Schematic', () => {
const prj = config.projects.foo;
expect(prj.root).toEqual('');
const buildOpt = prj.architect.build.options;
expect(buildOpt.index).toEqual('src/index.html');
expect(buildOpt.index).toBeUndefined();
expect(buildOpt.browser).toEqual('src/main.ts');
expect(buildOpt.assets).toEqual([{ 'glob': '**/*', 'input': 'public' }]);
expect(buildOpt.polyfills).toEqual(['zone.js']);
Expand Down Expand Up @@ -405,7 +405,6 @@ describe('Application Schematic', () => {
const project = config.projects.foo;
expect(project.root).toEqual('foo');
const buildOpt = project.architect.build.options;
expect(buildOpt.index).toEqual('foo/src/index.html');
expect(buildOpt.browser).toEqual('foo/src/main.ts');
expect(buildOpt.polyfills).toEqual(['zone.js']);
expect(buildOpt.tsConfig).toEqual('foo/tsconfig.app.json');
Expand Down
1 change: 1 addition & 0 deletions tests/legacy-cli/e2e/initialize/500-create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default async function () {
main: build.options.browser,
browser: undefined,
outputPath: 'dist/test-project/browser',
index: 'src/index.html',
};

build.configurations.development = {
Expand Down
1 change: 1 addition & 0 deletions tests/legacy-cli/e2e/tests/build/jit-ngmodule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default async function () {
browser: undefined,
buildOptimizer: false,
outputPath: 'dist/test-project-two',
index: 'src/index.html',
};

build.configurations.development = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default async function () {
...build.options,
main: build.options.browser,
browser: undefined,
index: 'src/index.html',
};

build.configurations.development = {
Expand Down
1 change: 1 addition & 0 deletions tests/legacy-cli/e2e/tests/build/rebuild-dot-dirname.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default async function () {
main: build.options.browser,
browser: undefined,
outputPath: 'dist/subdirectory-test-project',
index: 'src/index.html',
};

build.configurations.development = {
Expand Down
1 change: 1 addition & 0 deletions tests/legacy-cli/e2e/tests/build/relative-sourcemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default async function () {
main: build.options.browser,
browser: undefined,
outputPath: 'dist/secondary-project',
index: 'src/index.html',
};

build.configurations.development = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default async function () {
...build.options,
main: build.options.browser,
browser: undefined,
index: 'src/index.html',
};

build.configurations.development = {
Expand Down
Loading