-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@angular-devkit/build-angular): add
buildTarget
option to dev-…
…server and `extract-i18n` builders This is to better match the nature of the application builder where the target can be both browser and server. DEPRECATED: The `browserTarget` in the dev-server and extract-i18n builders have been deprecated in favor of `buildTarget`.
- Loading branch information
1 parent
258ccae
commit c48982d
Showing
18 changed files
with
190 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/schematics/angular/migrations/update-17/update-workspace-config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { Rule, chain } from '@angular-devkit/schematics'; | ||
import { removePackageJsonDependency } from '../../utility/dependencies'; | ||
import { allTargetOptions, updateWorkspace } from '../../utility/workspace'; | ||
import { Builders, ProjectType } from '../../utility/workspace-models'; | ||
|
||
export default function (): Rule { | ||
return updateWorkspace((workspace) => { | ||
for (const [, project] of workspace.projects) { | ||
if (project.extensions.projectType !== ProjectType.Application) { | ||
// Only interested in application projects since these changes only effects application builders | ||
continue; | ||
} | ||
|
||
for (const [, target] of project.targets) { | ||
if (target.builder === Builders.ExtractI18n || target.builder === Builders.DevServer) { | ||
for (const [, options] of allTargetOptions(target, false)) { | ||
options['buildTarget'] = options['browserTarget']; | ||
delete options['browserTarget']; | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
} |
112 changes: 112 additions & 0 deletions
112
packages/schematics/angular/migrations/update-17/update-workspace-config_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { EmptyTree } from '@angular-devkit/schematics'; | ||
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; | ||
import { Builders, ProjectType, WorkspaceSchema } from '../../utility/workspace-models'; | ||
|
||
function createWorkSpaceConfig(tree: UnitTestTree) { | ||
const angularConfig: WorkspaceSchema = { | ||
version: 1, | ||
projects: { | ||
app: { | ||
root: '/project/lib', | ||
sourceRoot: '/project/app/src', | ||
projectType: ProjectType.Application, | ||
prefix: 'app', | ||
architect: { | ||
'app-shell': { | ||
builder: Builders.AppShell, | ||
options: { | ||
browserTarget: 'app:build', | ||
serverTarget: 'app:server', | ||
route: '', | ||
}, | ||
configurations: { | ||
production: { | ||
browserTarget: 'app:build:production', | ||
serverTarget: 'app:server:production', | ||
}, | ||
}, | ||
}, | ||
serve: { | ||
builder: Builders.DevServer, | ||
options: { | ||
browserTarget: 'app:build:development', | ||
}, | ||
configurations: { | ||
production: { | ||
browserTarget: 'app:build:production', | ||
}, | ||
}, | ||
}, | ||
i18n: { | ||
builder: Builders.ExtractI18n, | ||
options: { | ||
browserTarget: 'app:build:production', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2)); | ||
} | ||
|
||
describe(`Migration to update 'angular.json'.`, () => { | ||
const schematicName = 'update-workspace-config'; | ||
const schematicRunner = new SchematicTestRunner( | ||
'migrations', | ||
require.resolve('../migration-collection.json'), | ||
); | ||
|
||
let tree: UnitTestTree; | ||
beforeEach(() => { | ||
tree = new UnitTestTree(new EmptyTree()); | ||
createWorkSpaceConfig(tree); | ||
}); | ||
|
||
it(`should replace 'browserTarget' when using '@angular-devkit/build-angular:dev-server'`, async () => { | ||
const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); | ||
const { | ||
projects: { app }, | ||
} = JSON.parse(newTree.readContent('/angular.json')); | ||
|
||
const { browserTarget, buildTarget } = app.architect['serve'].options; | ||
expect(browserTarget).toBeUndefined(); | ||
expect(buildTarget).toBe('app:build:development'); | ||
|
||
const { browserTarget: browserTargetProd, buildTarget: buildTargetProd } = | ||
app.architect['serve'].configurations['production']; | ||
expect(browserTargetProd).toBeUndefined(); | ||
expect(buildTargetProd).toBe('app:build:production'); | ||
}); | ||
|
||
it(`should replace 'browserTarget' when using '@angular-devkit/build-angular:extract-i18n'`, async () => { | ||
const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); | ||
const { | ||
projects: { app }, | ||
} = JSON.parse(newTree.readContent('/angular.json')); | ||
|
||
const { browserTarget, buildTarget } = app.architect['i18n'].options; | ||
expect(browserTarget).toBeUndefined(); | ||
expect(buildTarget).toBe('app:build:production'); | ||
}); | ||
|
||
it(`should not replace 'browserTarget' when using other builders`, async () => { | ||
const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); | ||
const { | ||
projects: { app }, | ||
} = JSON.parse(newTree.readContent('/angular.json')); | ||
|
||
const { browserTarget, buildTarget } = app.architect['app-shell'].options; | ||
expect(browserTarget).toBe('app:build'); | ||
expect(buildTarget).toBeUndefined(); | ||
}); | ||
}); |