@ms-cloudpack/file-watcher 0.4.21 → 0.4.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"BaseWatcher.d.ts","sourceRoot":"","sources":["../src/BaseWatcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EACnB,OAAO,EACP,YAAY,EACZ,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAE5B;;GAEG;AACH,8BAAsB,WAAY,YAAW,OAAO;IAClD,uCAAuC;IACvC,OAAO,CAAC,cAAc,CAAS;IAC/B,yCAAyC;IACzC,SAAS,CAAC,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAM;IACvE,0CAA0C;IAC1C,OAAO,CAAC,iBAAiB,CAAuC;IAEhE,oEAAoE;IACpE,IAAW,gBAAgB,IAAI,MAAM,CAEpC;IAEY,KAAK,CAAC,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,mBAAmB,GAAG,OAAO,CAAC,eAAe,CAAC;IA8BzF,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKlC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAOrC,SAAS,CAAC,QAAQ,CAAC,MAAM,CACvB,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,EAAE,mBAAmB,GAC5B,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe;IAE7C,sFAAsF;cACtE,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAIzC,SAAS,CAAC,WAAW,IAAI,OAAO;CAGjC"}
1
+ {"version":3,"file":"BaseWatcher.d.ts","sourceRoot":"","sources":["../src/BaseWatcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EACnB,OAAO,EACP,YAAY,EACZ,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAE5B;;GAEG;AACH,8BAAsB,WAAY,YAAW,OAAO;IAClD,uCAAuC;IACvC,OAAO,CAAC,cAAc,CAAS;IAC/B,yCAAyC;IACzC,SAAS,CAAC,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAM;IACvE,0CAA0C;IAC1C,OAAO,CAAC,iBAAiB,CAAuC;IAEhE,oEAAoE;IACpE,IAAW,gBAAgB,IAAI,MAAM,CAEpC;IAEY,KAAK,CAAC,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,mBAAmB,GAAG,OAAO,CAAC,eAAe,CAAC;IA8BzF,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKlC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAOrC,SAAS,CAAC,QAAQ,CAAC,MAAM,CACvB,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,EAAE,mBAAmB,GAC5B,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe;IAE7C,sFAAsF;cACtE,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAKzC,SAAS,CAAC,WAAW,IAAI,OAAO;CAGjC"}
@@ -48,6 +48,7 @@ export class BaseWatcher {
48
48
  }
49
49
  /** By default, calls all the unwatch callbacks. Override for custom dispose logic. */
50
50
  async _dispose() {
51
+ // eslint-disable-next-line @typescript-eslint/await-thenable -- mix of promise and not
51
52
  await Promise.all(Object.values(this._unwatchCallbacks).map((unwatch) => unwatch()));
52
53
  }
53
54
  _isDisposed() {
@@ -1 +1 @@
1
- {"version":3,"file":"BaseWatcher.js","sourceRoot":"","sources":["../src/BaseWatcher.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,OAAgB,WAAW;IAC/B,uCAAuC;IAC/B,cAAc,GAAG,KAAK,CAAC;IAC/B,yCAAyC;IAC/B,kBAAkB,GAAwC,EAAE,CAAC;IACvE,0CAA0C;IAClC,iBAAiB,GAAoC,EAA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C;IACvC,CAAC;IAEM,KAAK,CAAC,OAAO;QAClB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC3B,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACtB,IAAI,CAAC,iBAAiB,GAAG,EAAE,CAAC;QAC5B,IAAI,CAAC,kBAAkB,GAAG,EAAE,CAAC;IAC/B,CAAC;IAOD,sFAAsF;IAC5E,KAAK,CAAC,QAAQ;QACtB,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACvF,CAAC;IAES,WAAW;QACnB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;CACF","sourcesContent":["import type {\n UnwatchCallback,\n WatchChangeCallback,\n Watcher,\n WatchOptions,\n WatchOptionsWithId,\n} from './types/Watcher.js';\n\n/**\n * Base class for watcher implementations.\n */\nexport abstract class BaseWatcher implements Watcher {\n /** Watcher is disposed or disposing */\n private _disposeCalled = false;\n /** Mapping from ID to change callback */\n protected _onChangeCallbacks: Record<string, WatchChangeCallback> = {};\n /** Mapping from ID to unwatch callback */\n private _unwatchCallbacks: Record<string, UnwatchCallback> = {};\n\n /** Number of IDs currently being watched (just used for testing) */\n public get activeWatchCount(): number {\n return Object.keys(this._unwatchCallbacks).length;\n }\n\n public async watch(baseOptions: WatchOptions, onChange: WatchChangeCallback): Promise<UnwatchCallback> {\n if (this._isDisposed()) {\n throw new Error('Watcher has been disposed.');\n }\n\n const { id = baseOptions.path } = baseOptions;\n\n if (!this._unwatchCallbacks[id]) {\n this._onChangeCallbacks[id] = onChange;\n\n // Watch the path using the child class's implementation\n const unwatch = await this._watch({ ...baseOptions, id }, onChange);\n\n // Make an unwatch wrapper to clean up parent class state\n let calledUnwatch = false;\n this._unwatchCallbacks[id] = async () => {\n // The same unwatch callback might be returned multiple times in case of duplicate calls\n // for the same ID. Only do the cleanup once.\n if (!calledUnwatch) {\n calledUnwatch = true;\n await unwatch();\n delete this._unwatchCallbacks[id];\n delete this._onChangeCallbacks[id];\n }\n };\n }\n\n return this._unwatchCallbacks[id];\n }\n\n public async unwatch(id: string): Promise<void> {\n // The wrapper code at the callback definition in watch() handles cleanup of callback records.\n await this._unwatchCallbacks[id]?.();\n }\n\n public async dispose(): Promise<void> {\n this._disposeCalled = true;\n await this._dispose();\n this._unwatchCallbacks = {};\n this._onChangeCallbacks = {};\n }\n\n protected abstract _watch(\n options: WatchOptionsWithId,\n onChange: WatchChangeCallback,\n ): Promise<UnwatchCallback> | UnwatchCallback;\n\n /** By default, calls all the unwatch callbacks. Override for custom dispose logic. */\n protected async _dispose(): Promise<void> {\n await Promise.all(Object.values(this._unwatchCallbacks).map((unwatch) => unwatch()));\n }\n\n protected _isDisposed(): boolean {\n return this._disposeCalled;\n }\n}\n"]}
1
+ {"version":3,"file":"BaseWatcher.js","sourceRoot":"","sources":["../src/BaseWatcher.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,OAAgB,WAAW;IAC/B,uCAAuC;IAC/B,cAAc,GAAG,KAAK,CAAC;IAC/B,yCAAyC;IAC/B,kBAAkB,GAAwC,EAAE,CAAC;IACvE,0CAA0C;IAClC,iBAAiB,GAAoC,EAAE,CAAC;IAEhE,oEAAoE;IACpE,IAAW,gBAAgB;QACzB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC;IACpD,CAAC;IAEM,KAAK,CAAC,KAAK,CAAC,WAAyB,EAAE,QAA6B;QACzE,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;QAED,MAAM,EAAE,EAAE,GAAG,WAAW,CAAC,IAAI,EAAE,GAAG,WAAW,CAAC;QAE9C,IAAI,CAAC,IAAI,CAAC,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EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACvF,CAAC;IAES,WAAW;QACnB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;CACF","sourcesContent":["import type {\n UnwatchCallback,\n WatchChangeCallback,\n Watcher,\n WatchOptions,\n WatchOptionsWithId,\n} from './types/Watcher.js';\n\n/**\n * Base class for watcher implementations.\n */\nexport abstract class BaseWatcher implements Watcher {\n /** Watcher is disposed or disposing */\n private _disposeCalled = false;\n /** Mapping from ID to change callback */\n protected _onChangeCallbacks: Record<string, WatchChangeCallback> = {};\n /** Mapping from ID to unwatch callback */\n private _unwatchCallbacks: Record<string, UnwatchCallback> = {};\n\n /** Number of IDs currently being watched (just used for testing) */\n public get activeWatchCount(): number {\n return Object.keys(this._unwatchCallbacks).length;\n }\n\n public async watch(baseOptions: WatchOptions, onChange: WatchChangeCallback): Promise<UnwatchCallback> {\n if (this._isDisposed()) {\n throw new Error('Watcher has been disposed.');\n }\n\n const { id = baseOptions.path } = baseOptions;\n\n if (!this._unwatchCallbacks[id]) {\n this._onChangeCallbacks[id] = onChange;\n\n // Watch the path using the child class's implementation\n const unwatch = await this._watch({ ...baseOptions, id }, onChange);\n\n // Make an unwatch wrapper to clean up parent class state\n let calledUnwatch = false;\n this._unwatchCallbacks[id] = async () => {\n // The same unwatch callback might be returned multiple times in case of duplicate calls\n // for the same ID. Only do the cleanup once.\n if (!calledUnwatch) {\n calledUnwatch = true;\n await unwatch();\n delete this._unwatchCallbacks[id];\n delete this._onChangeCallbacks[id];\n }\n };\n }\n\n return this._unwatchCallbacks[id];\n }\n\n public async unwatch(id: string): Promise<void> {\n // The wrapper code at the callback definition in watch() handles cleanup of callback records.\n await this._unwatchCallbacks[id]?.();\n }\n\n public async dispose(): Promise<void> {\n this._disposeCalled = true;\n await this._dispose();\n this._unwatchCallbacks = {};\n this._onChangeCallbacks = {};\n }\n\n protected abstract _watch(\n options: WatchOptionsWithId,\n onChange: WatchChangeCallback,\n ): Promise<UnwatchCallback> | UnwatchCallback;\n\n /** By default, calls all the unwatch callbacks. Override for custom dispose logic. */\n protected async _dispose(): Promise<void> {\n // eslint-disable-next-line @typescript-eslint/await-thenable -- mix of promise and not\n await Promise.all(Object.values(this._unwatchCallbacks).map((unwatch) => unwatch()));\n }\n\n protected _isDisposed(): boolean {\n return this._disposeCalled;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"DefaultWatcher.d.ts","sourceRoot":"","sources":["../src/DefaultWatcher.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACnG,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAI/C;;GAEG;AACH,qBAAa,cAAe,SAAQ,WAAW;IAC7C,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,mBAAmB,GAAG,eAAe;CAwB9F"}
1
+ {"version":3,"file":"DefaultWatcher.d.ts","sourceRoot":"","sources":["../src/DefaultWatcher.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACnG,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAI/C;;GAEG;AACH,qBAAa,cAAe,SAAQ,WAAW;IAC7C,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,mBAAmB,GAAG,eAAe;CA2B9F"}
@@ -16,12 +16,15 @@ export class DefaultWatcher extends BaseWatcher {
16
16
  let watcher = chokidar
17
17
  .watch(paths, { ignored, followSymlinks: false, ignoreInitial: true })
18
18
  .on('change', (filePath) => {
19
+ console.debug(`DefaultWatcher detected change: ${filePath}`);
19
20
  onChange([filePath]);
20
21
  })
21
22
  .on('add', (filePath) => {
23
+ console.debug(`DefaultWatcher detected add: ${filePath}`);
22
24
  onChange([filePath]);
23
25
  })
24
26
  .on('unlink', (filePath) => {
27
+ console.debug(`DefaultWatcher detected delete: ${filePath}`);
25
28
  onChange([filePath]);
26
29
  });
27
30
  return async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"DefaultWatcher.js","sourceRoot":"","sources":["../src/DefaultWatcher.ts"],"names":[],"mappings":"AAAA,OAAO,QAA4B,MAAM,UAAU,CAAC;AACpD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,WAAW;IACnC,MAAM,CAAC,OAA2B,EAAE,QAA6B;QACzE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,GAAG,gBAAgB,EAAE,GAAG,OAAO,CAAC;QAClE,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;QACnE,MAAM,KAAK,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;QAC9E,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;QAEhF,6FAA6F;QAC7F,IAAI,OAAO,GAA0B,QAAQ;aAC1C,KAAK,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;aACrE,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,EAAE;YACzB,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;QACvB,CAAC,CAAC;aACD,EAAE,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,EAAE;YACtB,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;QACvB,CAAC,CAAC;aACD,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,EAAE;YACzB,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;QAEL,OAAO,KAAK,IAAI,EAAE;YAChB,MAAM,OAAO,EAAE,KAAK,EAAE,CAAC;YACvB,OAAO,GAAG,SAAS,CAAC;QACtB,CAAC,CAAC;IACJ,CAAC;CACF","sourcesContent":["import chokidar, { type FSWatcher } from 'chokidar';\nimport path from 'path';\nimport type { UnwatchCallback, WatchChangeCallback, WatchOptionsWithId } from './types/Watcher.js';\nimport { BaseWatcher } from './BaseWatcher.js';\nimport { sourceFilesGlobs } from '@ms-cloudpack/path-utilities';\nimport { separateGlobs } from './separateGlobs.js';\n\n/**\n * Watch for changes using chokidar in the current process.\n */\nexport class DefaultWatcher extends BaseWatcher {\n protected _watch(options: WatchOptionsWithId, onChange: WatchChangeCallback): UnwatchCallback {\n const { path: rootPath, watchPaths = sourceFilesGlobs } = options;\n const { positiveGlobs, negativeGlobs } = separateGlobs(watchPaths);\n const paths = positiveGlobs.map((relPath) => path.resolve(rootPath, relPath));\n const ignored = negativeGlobs.map((relPath) => path.resolve(rootPath, relPath));\n\n // For efficiency, don't follow symlinks, and don't send 'add' events after the initial scan.\n let watcher: FSWatcher | undefined = chokidar\n .watch(paths, { ignored, followSymlinks: false, ignoreInitial: true })\n .on('change', (filePath) => {\n onChange([filePath]);\n })\n .on('add', (filePath) => {\n onChange([filePath]);\n })\n .on('unlink', (filePath) => {\n onChange([filePath]);\n });\n\n return async () => {\n await watcher?.close();\n watcher = undefined;\n };\n }\n}\n"]}
1
+ {"version":3,"file":"DefaultWatcher.js","sourceRoot":"","sources":["../src/DefaultWatcher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CAAC,CAAC;YAC1D,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;QACvB,CAAC,CAAC;aACD,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,EAAE;YACzB,OAAO,CAAC,KAAK,CAAC,mCAAmC,QAAQ,EAAE,CAAC,CAAC;YAC7D,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;QAEL,OAAO,KAAK,IAAI,EAAE;YAChB,MAAM,OAAO,EAAE,KAAK,EAAE,CAAC;YACvB,OAAO,GAAG,SAAS,CAAC;QACtB,CAAC,CAAC;IACJ,CAAC;CACF","sourcesContent":["import chokidar, { type FSWatcher } from 'chokidar';\nimport path from 'path';\nimport type { UnwatchCallback, WatchChangeCallback, WatchOptionsWithId } from './types/Watcher.js';\nimport { BaseWatcher } from './BaseWatcher.js';\nimport { sourceFilesGlobs } from '@ms-cloudpack/path-utilities';\nimport { separateGlobs } from './separateGlobs.js';\n\n/**\n * Watch for changes using chokidar in the current process.\n */\nexport class DefaultWatcher extends BaseWatcher {\n protected _watch(options: WatchOptionsWithId, onChange: WatchChangeCallback): UnwatchCallback {\n const { path: rootPath, watchPaths = sourceFilesGlobs } = options;\n const { positiveGlobs, negativeGlobs } = separateGlobs(watchPaths);\n const paths = positiveGlobs.map((relPath) => path.resolve(rootPath, relPath));\n const ignored = negativeGlobs.map((relPath) => path.resolve(rootPath, relPath));\n\n // For efficiency, don't follow symlinks, and don't send 'add' events after the initial scan.\n let watcher: FSWatcher | undefined = chokidar\n .watch(paths, { ignored, followSymlinks: false, ignoreInitial: true })\n .on('change', (filePath) => {\n console.debug(`DefaultWatcher detected change: ${filePath}`);\n onChange([filePath]);\n })\n .on('add', (filePath) => {\n console.debug(`DefaultWatcher detected add: ${filePath}`);\n onChange([filePath]);\n })\n .on('unlink', (filePath) => {\n console.debug(`DefaultWatcher detected delete: ${filePath}`);\n onChange([filePath]);\n });\n\n return async () => {\n await watcher?.close();\n watcher = undefined;\n };\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ParcelWatcher.d.ts","sourceRoot":"","sources":["../src/ParcelWatcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACnG,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAI/C;;GAEG;AACH,qBAAa,aAAc,SAAQ,WAAW;IAK5C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAC2E;cAMpF,MAAM,CAAC,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,mBAAmB,GAAG,OAAO,CAAC,eAAe,CAAC;CAsB7G"}
1
+ {"version":3,"file":"ParcelWatcher.d.ts","sourceRoot":"","sources":["../src/ParcelWatcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACnG,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAI/C;;GAEG;AACH,qBAAa,aAAc,SAAQ,WAAW;IAK5C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAC2E;cAMpF,MAAM,CAAC,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,mBAAmB,GAAG,OAAO,CAAC,eAAe,CAAC;CAuB7G"}
@@ -24,6 +24,7 @@ export class ParcelWatcher extends BaseWatcher {
24
24
  }
25
25
  else if (events.length) {
26
26
  const uniquePaths = new Set(events.map((event) => event.path));
27
+ console.debug(`ParcelWatcher detected changes: ${[...uniquePaths].join(', ')}`);
27
28
  onChange([...uniquePaths]);
28
29
  }
29
30
  }, { ignore: negativeGlobs, backend: this._backend });
@@ -1 +1 @@
1
- {"version":3,"file":"ParcelWatcher.js","sourceRoot":"","sources":["../src/ParcelWatcher.ts"],"names":[],"mappings":"AAAA,OAAO,MAAkC,MAAM,iBAAiB,C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IAAI,CAAC,QAAQ,EAAE,CAClD,CAAC;QAEF,OAAO,KAAK,IAAI,EAAE;YAChB,MAAM,OAAO,EAAE,WAAW,EAAE,CAAC;YAC7B,OAAO,GAAG,SAAS,CAAC;QACtB,CAAC,CAAC;IACJ,CAAC;CACF","sourcesContent":["import parcel, { type AsyncSubscription } from '@parcel/watcher';\nimport type { UnwatchCallback, WatchChangeCallback, WatchOptionsWithId } from './types/Watcher.js';\nimport { BaseWatcher } from './BaseWatcher.js';\nimport { sourceFilesGlobs } from '@ms-cloudpack/path-utilities';\nimport { separateGlobs } from './separateGlobs.js';\n\n/**\n * Watch for changes using chokidar in the current process.\n */\nexport class ParcelWatcher extends BaseWatcher {\n // Using watchman in codespaces leads to the following error:\n // watchman::RootResolveError: failed to resolve root: unable to resolve root\n // So we use the default backend based on the platform, based on:\n // https://github.com/microsoft/vscode/blob/b482c0e99d5c424d85d6bd5eabccafca430e8072/src/vs/platform/files/node/watcher/parcel/parcelWatcher.ts#L158\n private readonly _backend =\n process.platform === 'win32' ? 'windows' : process.platform === 'linux' ? 'inotify' : 'fs-events';\n\n // TODO: Ideally if this is called multiple times with a different ID but the same root path and\n // same watch paths, a single watcher should be created and shared. But this involves a\n // lot of extra tracking logic and isn't essential until SSR is actually being used in an app.\n // Tracking: https://github.com/microsoft/cloudpack/issues/3046\n protected async _watch(options: WatchOptionsWithId, onChange: WatchChangeCallback): Promise<UnwatchCallback> {\n const { path: rootPath, watchPaths = sourceFilesGlobs } = options;\n const { negativeGlobs } = separateGlobs(watchPaths);\n\n let watcher: AsyncSubscription | undefined = await parcel.subscribe(\n rootPath,\n (err, events) => {\n if (err) {\n console.error(`Error watching files: ${err}`);\n } else if (events.length) {\n const uniquePaths = new Set(events.map((event) => event.path));\n onChange([...uniquePaths]);\n }\n },\n { ignore: negativeGlobs, backend: this._backend },\n );\n\n return async () => {\n await watcher?.unsubscribe();\n watcher = undefined;\n };\n }\n}\n"]}
1
+ {"version":3,"file":"ParcelWatcher.js","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,GAAG,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAChF,QAAQ,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC;YAC7B,CAAC;QACH,CAAC,EACD,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE,CAClD,CAAC;QAEF,OAAO,KAAK,IAAI,EAAE;YAChB,MAAM,OAAO,EAAE,WAAW,EAAE,CAAC;YAC7B,OAAO,GAAG,SAAS,CAAC;QACtB,CAAC,CAAC;IACJ,CAAC;CACF","sourcesContent":["import parcel, { type AsyncSubscription } from '@parcel/watcher';\nimport type { UnwatchCallback, WatchChangeCallback, WatchOptionsWithId } from './types/Watcher.js';\nimport { BaseWatcher } from './BaseWatcher.js';\nimport { sourceFilesGlobs } from '@ms-cloudpack/path-utilities';\nimport { separateGlobs } from './separateGlobs.js';\n\n/**\n * Watch for changes using chokidar in the current process.\n */\nexport class ParcelWatcher extends BaseWatcher {\n // Using watchman in codespaces leads to the following error:\n // watchman::RootResolveError: failed to resolve root: unable to resolve root\n // So we use the default backend based on the platform, based on:\n // https://github.com/microsoft/vscode/blob/b482c0e99d5c424d85d6bd5eabccafca430e8072/src/vs/platform/files/node/watcher/parcel/parcelWatcher.ts#L158\n private readonly _backend =\n process.platform === 'win32' ? 'windows' : process.platform === 'linux' ? 'inotify' : 'fs-events';\n\n // TODO: Ideally if this is called multiple times with a different ID but the same root path and\n // same watch paths, a single watcher should be created and shared. But this involves a\n // lot of extra tracking logic and isn't essential until SSR is actually being used in an app.\n // Tracking: https://github.com/microsoft/cloudpack/issues/3046\n protected async _watch(options: WatchOptionsWithId, onChange: WatchChangeCallback): Promise<UnwatchCallback> {\n const { path: rootPath, watchPaths = sourceFilesGlobs } = options;\n const { negativeGlobs } = separateGlobs(watchPaths);\n\n let watcher: AsyncSubscription | undefined = await parcel.subscribe(\n rootPath,\n (err, events) => {\n if (err) {\n console.error(`Error watching files: ${err}`);\n } else if (events.length) {\n const uniquePaths = new Set(events.map((event) => event.path));\n console.debug(`ParcelWatcher detected changes: ${[...uniquePaths].join(', ')}`);\n onChange([...uniquePaths]);\n }\n },\n { ignore: negativeGlobs, backend: this._backend },\n );\n\n return async () => {\n await watcher?.unsubscribe();\n watcher = undefined;\n };\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/file-watcher",
3
- "version": "0.4.21",
3
+ "version": "0.4.23",
4
4
  "description": "A file watcher abstraction for use with Cloudpack.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,9 +14,20 @@
14
14
  "import": "./lib/index.js"
15
15
  }
16
16
  },
17
+ "scripts": {
18
+ "api": "cloudpack-scripts api",
19
+ "build:watch": "cloudpack-scripts build-watch",
20
+ "build": "cloudpack-scripts build",
21
+ "lint:update": "cloudpack-scripts lint-update",
22
+ "lint": "cloudpack-scripts lint",
23
+ "start": "node ./lib/test.js",
24
+ "test:update": "cloudpack-scripts test-update",
25
+ "test:watch": "cloudpack-scripts test-watch",
26
+ "test": "cloudpack-scripts test"
27
+ },
17
28
  "dependencies": {
18
29
  "@ms-cloudpack/path-string-parsing": "^1.2.7",
19
- "@ms-cloudpack/path-utilities": "^3.1.34",
30
+ "@ms-cloudpack/path-utilities": "^3.2.1",
20
31
  "@parcel/watcher": "^2.5.1",
21
32
  "chokidar": "^3.5.3",
22
33
  "picomatch": "^4.0.3"
@@ -28,17 +39,6 @@
28
39
  "@ms-cloudpack/test-utilities": "^0.5.0",
29
40
  "@types/picomatch": "^4"
30
41
  },
31
- "scripts": {
32
- "api": "cloudpack-scripts api",
33
- "build:watch": "cloudpack-scripts build-watch",
34
- "build": "cloudpack-scripts build",
35
- "lint:update": "cloudpack-scripts lint-update",
36
- "lint": "cloudpack-scripts lint",
37
- "start": "node ./lib/test.js",
38
- "test:update": "cloudpack-scripts test-update",
39
- "test:watch": "cloudpack-scripts test-watch",
40
- "test": "cloudpack-scripts test"
41
- },
42
42
  "files": [
43
43
  "lib/**/!(*.test.*)",
44
44
  "lib-commonjs/**/!(*.test.*)"