Skip to content

Commit eb5643e

Browse files
alexeaglevikerman
authored andcommitted
feat(@angular-devkit/core): Remove dep on chokidar
It is unused within our code, as webpack will do the file watching. This removes 1.4 MB from the download size of the package. See https://codepen.io/alexeagle/full/zbZWRM BREAKING CHANGE: Users who rely on angular-devkit/core to do the file watching must add chokidar to their devDependencies.
1 parent e0acac9 commit eb5643e

File tree

6 files changed

+20
-9
lines changed

6 files changed

+20
-9
lines changed

packages/angular_devkit/core/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ jasmine_node_test(
7272
deps = [
7373
"@npm//jasmine",
7474
"@npm//source-map",
75-
"@npm//chokidar",
7675
],
7776
)
7877

packages/angular_devkit/core/node/host.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,24 @@ interface ChokidarWatcher {
3838
close(): void;
3939
}
4040

41-
const { FSWatcher }: { FSWatcher: ChokidarWatcher } = require('chokidar');
42-
41+
// This will only be initialized if the watch() method is called.
42+
// Otherwise chokidar appears only in type positions, and shouldn't be referenced
43+
// in the JavaScript output.
44+
let FSWatcher: ChokidarWatcher;
45+
function loadFSWatcher() {
46+
if (!FSWatcher) {
47+
try {
48+
// tslint:disable-next-line:no-implicit-dependencies
49+
FSWatcher = require('chokidar').FSWatcher;
50+
} catch (e) {
51+
if (e.code !== 'MODULE_NOT_FOUND') {
52+
throw new Error('As of angular-devkit version 8.0, the "chokidar" package ' +
53+
'must be installed in order to use watch() features.');
54+
}
55+
throw e;
56+
}
57+
}
58+
}
4359

4460
type FsFunction0<R> = (cb: (err?: Error, result?: R) => void) => void;
4561
type FsFunction1<R, T1> = (p1: T1, cb: (err?: Error, result?: R) => void) => void;
@@ -180,6 +196,7 @@ export class NodeJsAsyncHost implements virtualFs.Host<fs.Stats> {
180196
_options?: virtualFs.HostWatchOptions,
181197
): Observable<virtualFs.HostWatchEvent> | null {
182198
return new Observable<virtualFs.HostWatchEvent>(obs => {
199+
loadFSWatcher();
183200
const watcher = new FSWatcher({ persistent: true }).add(getSystemPath(path));
184201

185202
watcher
@@ -365,6 +382,7 @@ export class NodeJsSyncHost implements virtualFs.Host<fs.Stats> {
365382
): Observable<virtualFs.HostWatchEvent> | null {
366383
return new Observable<virtualFs.HostWatchEvent>(obs => {
367384
const opts = { persistent: false };
385+
loadFSWatcher();
368386
const watcher = new FSWatcher(opts).add(getSystemPath(path));
369387

370388
watcher

packages/angular_devkit/core/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
],
1010
"dependencies": {
1111
"ajv": "6.10.0",
12-
"chokidar": "2.1.2",
1312
"fast-json-stable-stringify": "2.0.0",
1413
"rxjs": "6.4.0",
1514
"source-map": "0.7.3"

packages/angular_devkit/schematics/BUILD

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ jasmine_node_test(
6161
name = "schematics_test",
6262
srcs = [":schematics_test_lib"],
6363
deps = [
64-
"@npm//chokidar",
6564
"@npm//jasmine",
6665
"@npm//source-map",
6766
],
@@ -159,7 +158,6 @@ jasmine_node_test(
159158
deps = [
160159
"@npm//jasmine",
161160
"@npm//source-map",
162-
"@npm//chokidar",
163161
],
164162
)
165163

@@ -225,7 +223,6 @@ jasmine_node_test(
225223
deps = [
226224
"@npm//jasmine",
227225
"@npm//source-map",
228-
"@npm//chokidar",
229226
],
230227
)
231228

packages/schematics/angular/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ jasmine_node_test(
102102
deps = [
103103
"@npm//jasmine",
104104
"@npm//source-map",
105-
"@npm//chokidar",
106105
"//packages/schematics/angular/third_party/github.com/Microsoft/TypeScript",
107106
],
108107
)

packages/schematics/update/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ jasmine_node_test(
8383
deps = [
8484
"@npm//jasmine",
8585
"@npm//source-map",
86-
"@npm//chokidar",
8786
"@npm//npm-registry-client",
8887
],
8988
)

0 commit comments

Comments
 (0)