@ms-cloudpack/file-watcher 0.1.3 → 0.1.4

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,11 +1,4 @@
1
- export interface WatchOptions {
2
- path: string;
3
- watchPaths?: string[];
4
- }
5
- export interface Watcher {
6
- watch(options: WatchOptions, onPackageChanged: () => void): () => Promise<void>;
7
- unwatchAll(): Promise<void>;
8
- }
1
+ import type { Watcher } from './types/Watcher.js';
9
2
  /**
10
3
  * Creates a watcher which can watch a package and notify the client when it changes.
11
4
  */
@@ -1 +1 @@
1
- {"version":3,"file":"createWatcher.d.ts","sourceRoot":"","sources":["../src/createWatcher.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,OAAO;IACtB,KAAK,CAAC,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAChF,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AAQD;;GAEG;AACH,wBAAgB,aAAa,IAAI,OAAO,CA4CvC"}
1
+ {"version":3,"file":"createWatcher.d.ts","sourceRoot":"","sources":["../src/createWatcher.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAgB,MAAM,oBAAoB,CAAC;AAKhE;;GAEG;AACH,wBAAgB,aAAa,IAAI,OAAO,CA4CvC"}
@@ -1,9 +1,6 @@
1
1
  import chokidar from 'chokidar';
2
2
  import { resolve } from 'path';
3
- // TODO: This list of watched paths is hardcoded, but really it shouldn't be. In fact, this whole file
4
- // probably shouldn't be here. I think lage should be responsible for understanding what "bundle" means
5
- // (we can provide a definition) and what its inputs are and what it depends on. Then when we call
6
- // ensurePackageBundled, lage can ensure watching is happening for the full graph of tasks.
3
+ // TODO: This list of watched paths is hardcoded, but really it shouldn't be.
7
4
  const defaultWatchPaths = ['src/**', '*.json', '!**/node_modules/**'];
8
5
  /**
9
6
  * Creates a watcher which can watch a package and notify the client when it changes.
@@ -1 +1 @@
1
- {"version":3,"file":"createWatcher.js","sourceRoot":"","sources":["../src/createWatcher.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAY/B,sGAAsG;AACtG,uGAAuG;AACvG,kGAAkG;AAClG,2FAA2F;AAC3F,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,qBAAqB,CAAC,CAAC;AAEtE;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,YAAY,GAAG,IAAI,GAAG,EAAU,CAAC;IACvC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAa,CAAC;IAEtC,OAAO;QACL,KAAK,CAAC,OAAqB,EAAE,gBAA4B;YACvD,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,iBAAiB,EAAE,GAAG,OAAO,CAAC;YACzD,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YACtG,IAAI,OAA8B,CAAC;YAEnC,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;gBACjB,0DAA0D;gBAC1D,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;gBAE1C,uGAAuG;gBACvG,uGAAuG;gBACvG,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;gBAE/D,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACxB,CAAC;YAED,sDAAsD;YACtD,OAAO,KAAK,IAAI,EAAE;gBAChB,IAAI,OAAO,EAAE,CAAC;oBACZ,MAAM,CAAC,GAAG,OAAO,CAAC;oBAElB,OAAO,GAAG,SAAS,CAAC;oBACpB,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;oBAEnB,KAAK,MAAM,WAAW,IAAI,KAAK,EAAE,CAAC;wBAChC,YAAY,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;oBACnC,CAAC;oBAED,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC;gBAClB,CAAC;YACH,CAAC,CAAC;QACJ,CAAC;QAED,KAAK,CAAC,UAAU;YACd,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YAC9D,QAAQ,CAAC,KAAK,EAAE,CAAC;YACjB,YAAY,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { FSWatcher } from 'chokidar';\nimport chokidar from 'chokidar';\nimport { resolve } from 'path';\n\nexport interface WatchOptions {\n path: string;\n watchPaths?: string[];\n}\n\nexport interface Watcher {\n watch(options: WatchOptions, onPackageChanged: () => void): () => Promise<void>;\n unwatchAll(): Promise<void>;\n}\n\n// TODO: This list of watched paths is hardcoded, but really it shouldn't be. In fact, this whole file\n// probably shouldn't be here. I think lage should be responsible for understanding what \"bundle\" means\n// (we can provide a definition) and what its inputs are and what it depends on. Then when we call\n// ensurePackageBundled, lage can ensure watching is happening for the full graph of tasks.\nconst defaultWatchPaths = ['src/**', '*.json', '!**/node_modules/**'];\n\n/**\n * Creates a watcher which can watch a package and notify the client when it changes.\n */\nexport function createWatcher(): Watcher {\n const watchedPaths = new Set<string>();\n const watchers = new Set<FSWatcher>();\n\n return {\n watch(options: WatchOptions, onPackageChanged: () => void) {\n const { path, watchPaths = defaultWatchPaths } = options;\n const paths = watchPaths.map((relPath) => resolve(path, relPath)).filter((p) => !watchedPaths.has(p));\n let watcher: FSWatcher | undefined;\n\n if (paths.length) {\n // Add paths to watchedPaths to avoid watching them again.\n paths.forEach((p) => watchedPaths.add(p));\n\n // Watch source and register a handler which will rebundle the changed package and notify the client on\n // success. Note that if failures happen, the client will receive the error notification automatically.\n watcher = chokidar.watch(paths).on('change', onPackageChanged);\n\n watchers.add(watcher);\n }\n\n // Return a dispose function to individually clean up.\n return async () => {\n if (watcher) {\n const w = watcher;\n\n watcher = undefined;\n watchers.delete(w);\n\n for (const watchedPath of paths) {\n watchedPaths.delete(watchedPath);\n }\n\n await w.close();\n }\n };\n },\n\n async unwatchAll() {\n await Promise.all(Array.from(watchers).map((w) => w.close()));\n watchers.clear();\n watchedPaths.clear();\n },\n };\n}\n"]}
1
+ {"version":3,"file":"createWatcher.js","sourceRoot":"","sources":["../src/createWatcher.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAG/B,6EAA6E;AAC7E,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,qBAAqB,CAAC,CAAC;AAEtE;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,YAAY,GAAG,IAAI,GAAG,EAAU,CAAC;IACvC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAa,CAAC;IAEtC,OAAO;QACL,KAAK,CAAC,OAAqB,EAAE,gBAA4B;YACvD,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,iBAAiB,EAAE,GAAG,OAAO,CAAC;YACzD,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CA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type { FSWatcher } from 'chokidar';\nimport chokidar from 'chokidar';\nimport { resolve } from 'path';\nimport type { Watcher, WatchOptions } from './types/Watcher.js';\n\n// TODO: This list of watched paths is hardcoded, but really it shouldn't be.\nconst defaultWatchPaths = ['src/**', '*.json', '!**/node_modules/**'];\n\n/**\n * Creates a watcher which can watch a package and notify the client when it changes.\n */\nexport function createWatcher(): Watcher {\n const watchedPaths = new Set<string>();\n const watchers = new Set<FSWatcher>();\n\n return {\n watch(options: WatchOptions, onPackageChanged: () => void) {\n const { path, watchPaths = defaultWatchPaths } = options;\n const paths = watchPaths.map((relPath) => resolve(path, relPath)).filter((p) => !watchedPaths.has(p));\n let watcher: FSWatcher | undefined;\n\n if (paths.length) {\n // Add paths to watchedPaths to avoid watching them again.\n paths.forEach((p) => watchedPaths.add(p));\n\n // Watch source and register a handler which will rebundle the changed package and notify the client on\n // success. Note that if failures happen, the client will receive the error notification automatically.\n watcher = chokidar.watch(paths).on('change', onPackageChanged);\n\n watchers.add(watcher);\n }\n\n // Return a dispose function to individually clean up.\n return async () => {\n if (watcher) {\n const w = watcher;\n\n watcher = undefined;\n watchers.delete(w);\n\n for (const watchedPath of paths) {\n watchedPaths.delete(watchedPath);\n }\n\n await w.close();\n }\n };\n },\n\n async unwatchAll() {\n await Promise.all(Array.from(watchers).map((w) => w.close()));\n watchers.clear();\n watchedPaths.clear();\n },\n };\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import type { Watcher } from './types/Watcher.js';
2
+ /**
3
+ * Creates a watcher in a fork which can watch a package and notify the client when it changes.
4
+ */
5
+ export declare function createWatcherInFork(): Watcher;
6
+ //# sourceMappingURL=createWatcherInFork.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createWatcherInFork.d.ts","sourceRoot":"","sources":["../src/createWatcherInFork.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAgB,MAAM,oBAAoB,CAAC;AAKhE;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CA0C7C"}
@@ -0,0 +1,47 @@
1
+ import { resolve, dirname } from 'path';
2
+ import { fork } from 'child_process';
3
+ import { fileURLToPath } from 'url';
4
+ const currentDir = dirname(fileURLToPath(import.meta.url));
5
+ const fileWatcher = resolve(currentDir, 'watcherForkWrapper.js');
6
+ /**
7
+ * Creates a watcher in a fork which can watch a package and notify the client when it changes.
8
+ */
9
+ export function createWatcherInFork() {
10
+ const callbackMap = new Map();
11
+ const child = fork(fileWatcher);
12
+ child.on('message', (message) => {
13
+ switch (message.type) {
14
+ case 'change':
15
+ callbackMap.get(message.path)?.();
16
+ break;
17
+ case 'error':
18
+ console.error(`An error occurred while watching files: ${message.error}`);
19
+ break;
20
+ default:
21
+ console.warn(`Unknown message type: ${JSON.stringify(message)}`);
22
+ }
23
+ });
24
+ return {
25
+ watch(options, onPackageChanged) {
26
+ const { path } = options;
27
+ const watchMessage = { type: 'watch', options };
28
+ child.send(watchMessage);
29
+ callbackMap.set(path, onPackageChanged);
30
+ // Marking this function as async to match the return type of the function in createWatcher.ts
31
+ // This function is only ever used for testing purposes, so it's fine to mark it as async.
32
+ // eslint-disable-next-line @typescript-eslint/require-await
33
+ return async () => {
34
+ const unwatchMessage = { type: 'unwatch', path };
35
+ child.send(unwatchMessage);
36
+ };
37
+ },
38
+ async unwatchAll() {
39
+ await new Promise((r) => {
40
+ child.on('close', r);
41
+ const shutDownMessage = { type: 'shutdown' };
42
+ child.send(shutDownMessage);
43
+ });
44
+ },
45
+ };
46
+ }
47
+ //# sourceMappingURL=createWatcherInFork.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createWatcherInFork.js","sourceRoot":"","sources":["../src/createWatcherInFork.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAIpC,MAAM,U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AC;YAC7B,CAAC,CAAC;QACJ,CAAC;QAED,KAAK,CAAC,UAAU;YACd,MAAM,IAAI,OAAO,CAAO,CAAC,CAAC,EAAE,EAAE;gBAC5B,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;gBACrB,MAAM,eAAe,GAAoB,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;gBAC9D,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;YAC9B,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { resolve, dirname } from 'path';\nimport { fork } from 'child_process';\nimport { fileURLToPath } from 'url';\nimport type { ChildMessage, ShutdownMessage, UnwatchMessage, WatchMessage } from './types/WatchMessages.js';\nimport type { Watcher, WatchOptions } from './types/Watcher.js';\n\nconst currentDir = dirname(fileURLToPath(import.meta.url));\nconst fileWatcher = resolve(currentDir, 'watcherForkWrapper.js');\n\n/**\n * Creates a watcher in a fork which can watch a package and notify the client when it changes.\n */\nexport function createWatcherInFork(): Watcher {\n const callbackMap = new Map<string, () => void>();\n const child = fork(fileWatcher);\n child.on('message', (message: ChildMessage) => {\n switch (message.type) {\n case 'change':\n callbackMap.get(message.path)?.();\n break;\n\n case 'error':\n console.error(`An error occurred while watching files: ${message.error}`);\n break;\n\n default:\n console.warn(`Unknown message type: ${JSON.stringify(message)}`);\n }\n });\n\n return {\n watch(options: WatchOptions, onPackageChanged: () => void) {\n const { path } = options;\n const watchMessage: WatchMessage = { type: 'watch', options };\n child.send(watchMessage);\n callbackMap.set(path, onPackageChanged);\n\n // Marking this function as async to match the return type of the function in createWatcher.ts\n // This function is only ever used for testing purposes, so it's fine to mark it as async.\n // eslint-disable-next-line @typescript-eslint/require-await\n return async () => {\n const unwatchMessage: UnwatchMessage = { type: 'unwatch', path };\n child.send(unwatchMessage);\n };\n },\n\n async unwatchAll() {\n await new Promise<void>((r) => {\n child.on('close', r);\n const shutDownMessage: ShutdownMessage = { type: 'shutdown' };\n child.send(shutDownMessage);\n });\n },\n };\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { createWatcher } from './createWatcher.js';
2
- export type { Watcher, WatchOptions } from './createWatcher.js';
2
+ export { createWatcherInFork } from './createWatcherInFork.js';
3
+ export type { Watcher, WatchOptions } from './types/Watcher.js';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
package/lib/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { createWatcher } from './createWatcher.js';
2
+ export { createWatcherInFork } from './createWatcherInFork.js';
2
3
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { createWatcher } from './createWatcher.js';\nexport type { Watcher, WatchOptions } from './createWatcher.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["export { createWatcher } from './createWatcher.js';\nexport { createWatcherInFork } from './createWatcherInFork.js';\nexport type { Watcher, WatchOptions } from './types/Watcher.js';\n"]}
@@ -0,0 +1,23 @@
1
+ import type { WatchOptions } from './Watcher.js';
2
+ export interface WatchMessage {
3
+ type: 'watch';
4
+ options: WatchOptions;
5
+ }
6
+ export interface UnwatchMessage {
7
+ type: 'unwatch';
8
+ path: string;
9
+ }
10
+ export interface ShutdownMessage {
11
+ type: 'shutdown';
12
+ }
13
+ export type ParentMessage = WatchMessage | UnwatchMessage | ShutdownMessage;
14
+ export type ChangeMessage = {
15
+ type: 'change';
16
+ path: string;
17
+ };
18
+ export type ErrorMessage = {
19
+ type: 'error';
20
+ error: Error;
21
+ };
22
+ export type ChildMessage = ChangeMessage | ErrorMessage;
23
+ //# sourceMappingURL=WatchMessages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WatchMessages.d.ts","sourceRoot":"","sources":["../../src/types/WatchMessages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,YAAY,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG,cAAc,GAAG,eAAe,CAAC;AAE5E,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG,YAAY,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=WatchMessages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WatchMessages.js","sourceRoot":"","sources":["../../src/types/WatchMessages.ts"],"names":[],"mappings":"","sourcesContent":["import type { WatchOptions } from './Watcher.js';\n\nexport interface WatchMessage {\n type: 'watch';\n options: WatchOptions;\n}\n\nexport interface UnwatchMessage {\n type: 'unwatch';\n path: string;\n}\n\nexport interface ShutdownMessage {\n type: 'shutdown';\n}\n\nexport type ParentMessage = WatchMessage | UnwatchMessage | ShutdownMessage;\n\nexport type ChangeMessage = {\n type: 'change';\n path: string;\n};\n\nexport type ErrorMessage = {\n type: 'error';\n error: Error;\n};\n\nexport type ChildMessage = ChangeMessage | ErrorMessage;\n"]}
@@ -0,0 +1,9 @@
1
+ export interface WatchOptions {
2
+ path: string;
3
+ watchPaths?: string[];
4
+ }
5
+ export interface Watcher {
6
+ watch(options: WatchOptions, onPackageChanged: () => void): () => Promise<void>;
7
+ unwatchAll(): Promise<void>;
8
+ }
9
+ //# sourceMappingURL=Watcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Watcher.d.ts","sourceRoot":"","sources":["../../src/types/Watcher.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,OAAO;IACtB,KAAK,CAAC,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAChF,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Watcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Watcher.js","sourceRoot":"","sources":["../../src/types/Watcher.ts"],"names":[],"mappings":"","sourcesContent":["export interface WatchOptions {\n path: string;\n watchPaths?: string[];\n}\n\nexport interface Watcher {\n watch(options: WatchOptions, onPackageChanged: () => void): () => Promise<void>;\n unwatchAll(): Promise<void>;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=watcherForkWrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watcherForkWrapper.d.ts","sourceRoot":"","sources":["../src/watcherForkWrapper.ts"],"names":[],"mappings":""}
@@ -0,0 +1,39 @@
1
+ import { createWatcher } from './createWatcher.js';
2
+ /**
3
+ * Initializes the watcher in a child process.
4
+ */
5
+ function initializeWatcher() {
6
+ const watcher = createWatcher();
7
+ const unwatches = new Map();
8
+ process.on('message', (message) => {
9
+ (async () => {
10
+ switch (message.type) {
11
+ case 'watch':
12
+ {
13
+ const { path } = message.options;
14
+ const unwatch = watcher.watch(message.options, () => {
15
+ process.send?.({ type: 'change', path });
16
+ });
17
+ unwatches.set(path, unwatch);
18
+ }
19
+ break;
20
+ case 'unwatch':
21
+ await unwatches.get(message.path)?.();
22
+ unwatches.delete(message.path);
23
+ break;
24
+ case 'shutdown':
25
+ await watcher.unwatchAll();
26
+ // eslint-disable-next-line no-restricted-properties
27
+ process.exit(0);
28
+ break;
29
+ }
30
+ })().catch((error) => {
31
+ process.send?.({ type: 'error', error: error });
32
+ });
33
+ });
34
+ }
35
+ // Prevent the process from exiting immediately.
36
+ // This is handled by the parent process instead with the shutdown message.
37
+ process.on('SIGINT', () => { });
38
+ initializeWatcher();
39
+ //# sourceMappingURL=watcherForkWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watcherForkWrapper.js","sourceRoot":"","sources":["../src/watcherForkWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAInD;;GAEG;AACH,SAAS,iBAAiB;IACxB,MAAM,OAAO,GAAG,aAAa,EAAE,CAAC;IAChC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAwC,CAAC;IAElE,OAAO,CA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{ Watcher } from './types/Watcher.js';\nimport type { ParentMessage } from './types/WatchMessages.js';\n\n/**\n * Initializes the watcher in a child process.\n */\nfunction initializeWatcher() {\n const watcher = createWatcher();\n const unwatches = new Map<string, ReturnType<Watcher['watch']>>();\n\n process.on('message', (message: ParentMessage) => {\n (async () => {\n switch (message.type) {\n case 'watch':\n {\n const { path } = message.options;\n const unwatch = watcher.watch(message.options, () => {\n process.send?.({ type: 'change', path });\n });\n unwatches.set(path, unwatch);\n }\n break;\n\n case 'unwatch':\n await unwatches.get(message.path)?.();\n unwatches.delete(message.path);\n break;\n\n case 'shutdown':\n await watcher.unwatchAll();\n // eslint-disable-next-line no-restricted-properties\n process.exit(0);\n break;\n }\n })().catch((error) => {\n process.send?.({ type: 'error', error: error as Error });\n });\n });\n}\n\n// Prevent the process from exiting immediately.\n// This is handled by the parent process instead with the shutdown message.\nprocess.on('SIGINT', () => {});\n\ninitializeWatcher();\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/file-watcher",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "A file watcher abstraction for use with Cloudpack.",
5
5
  "license": "MIT",
6
6
  "type": "module",