forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
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 angular#26349
- Loading branch information
1 parent
ffa2d07
commit a731cec
Showing
5 changed files
with
155 additions
and
3 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
40 changes: 40 additions & 0 deletions
40
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,40 @@ | ||
/** | ||
* @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 { getWorkspace } from '../../utility/workspace'; | ||
import { Builders, ProjectType } from '../../utility/workspace-models'; | ||
|
||
const BROWSER_SYNC_VERSION = '^2.29.3'; | ||
const BROWSER_SYNC_NAME = 'browser-sync'; | ||
|
||
export default function (): Rule { | ||
return async (tree) => { | ||
if (getPackageJsonDependency(tree, BROWSER_SYNC_NAME)?.version === BROWSER_SYNC_VERSION) { | ||
return; | ||
} | ||
|
||
const workspace = await getWorkspace(tree); | ||
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.values()) { | ||
if (target.builder === Builders.SsrDevServer) { | ||
return addDependency(BROWSER_SYNC_NAME, BROWSER_SYNC_VERSION, { | ||
type: DependencyType.Dev, | ||
}); | ||
} | ||
} | ||
} | ||
}; | ||
} |
93 changes: 93 additions & 0 deletions
93
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,93 @@ | ||
/** | ||
* @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'; | ||
|
||
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('^2.29.3'); | ||
}); | ||
|
||
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(); | ||
}); | ||
}); |