-
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): move
browser-sync
as optional …
…dependency `browser-sync` is now an optional dependency of `@angular-devkit/build-angular`. This package is only needed when using the legacy `@angular-devkit/build-angular:ssr-dev-server` builder. Closes #26349
- Loading branch information
1 parent
10588c2
commit 364a16b
Showing
7 changed files
with
169 additions
and
6 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
39 changes: 39 additions & 0 deletions
39
packages/schematics/angular/migrations/update-17/add-browser-sync-dependency.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,39 @@ | ||
/** | ||
* @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 } from '@angular-devkit/schematics'; | ||
import { DependencyType, addDependency } from '../../utility'; | ||
import { getPackageJsonDependency } from '../../utility/dependencies'; | ||
import { latestVersions } from '../../utility/latest-versions'; | ||
import { getWorkspace } from '../../utility/workspace'; | ||
import { Builders, ProjectType } from '../../utility/workspace-models'; | ||
|
||
const BROWSER_SYNC_VERSION = latestVersions['browser-sync']; | ||
|
||
export default function (): Rule { | ||
return async (tree) => { | ||
if (getPackageJsonDependency(tree, 'browser-sync')?.version === BROWSER_SYNC_VERSION) { | ||
return; | ||
} | ||
|
||
const workspace = await getWorkspace(tree); | ||
for (const project of workspace.projects.values()) { | ||
if (project.extensions.projectType !== ProjectType.Application) { | ||
continue; | ||
} | ||
|
||
for (const target of project.targets.values()) { | ||
if (target.builder === Builders.SsrDevServer) { | ||
return addDependency('browser-sync', BROWSER_SYNC_VERSION, { | ||
type: DependencyType.Dev, | ||
}); | ||
} | ||
} | ||
} | ||
}; | ||
} |
94 changes: 94 additions & 0 deletions
94
packages/schematics/angular/migrations/update-17/add-browser-sync-dependency_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,94 @@ | ||
/** | ||
* @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 { latestVersions } from '../../utility/latest-versions'; | ||
import { Builders, ProjectType } from '../../utility/workspace-models'; | ||
|
||
describe(`Migration to add 'browser-sync' as a dev dependency`, () => { | ||
const schematicName = 'add-browser-sync-dependency'; | ||
const schematicRunner = new SchematicTestRunner( | ||
'migrations', | ||
require.resolve('../migration-collection.json'), | ||
); | ||
|
||
let tree: UnitTestTree; | ||
beforeEach(() => { | ||
tree = new UnitTestTree(new EmptyTree()); | ||
tree.create( | ||
'/package.json', | ||
JSON.stringify( | ||
{ | ||
devDependencies: {}, | ||
}, | ||
undefined, | ||
2, | ||
), | ||
); | ||
}); | ||
|
||
it(`should add 'browser-sync' as devDependencies when '@angular-devkit/build-angular:ssr-dev-server' is used`, async () => { | ||
tree.create( | ||
'/angular.json', | ||
JSON.stringify( | ||
{ | ||
version: 1, | ||
projects: { | ||
app: { | ||
root: '', | ||
projectType: ProjectType.Application, | ||
prefix: 'app', | ||
architect: { | ||
'serve-ssr': { | ||
builder: Builders.SsrDevServer, | ||
options: {}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
undefined, | ||
2, | ||
), | ||
); | ||
|
||
const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); | ||
const { devDependencies } = JSON.parse(newTree.readContent('/package.json')); | ||
expect(devDependencies['browser-sync']).toBe(latestVersions['browser-sync']); | ||
}); | ||
|
||
it(`should not add 'browser-sync' as devDependencies when '@angular-devkit/build-angular:ssr-dev-server' is not used`, async () => { | ||
tree.create( | ||
'/angular.json', | ||
JSON.stringify( | ||
{ | ||
version: 1, | ||
projects: { | ||
app: { | ||
root: '', | ||
projectType: ProjectType.Application, | ||
prefix: 'app', | ||
architect: { | ||
'serve-ssr': { | ||
builder: Builders.Browser, | ||
options: {}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
undefined, | ||
2, | ||
), | ||
); | ||
const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); | ||
const { devDependencies } = JSON.parse(newTree.readContent('/package.json')); | ||
expect(devDependencies['browser-sync']).toBeUndefined(); | ||
}); | ||
}); |
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