@travetto/manifest 3.0.1 → 3.0.2-rc.1

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.
package/README.md CHANGED
@@ -96,14 +96,14 @@ The module also leverages [fetch](https://www.npmjs.com/package/@parcel/watcher)
96
96
  **Code: Watch Folder Signature**
97
97
  ```typescript
98
98
  export type WatchEvent = { action: 'create' | 'update' | 'delete', file: string };
99
- type EventFilter = (ev: WatchEvent) => boolean;
99
+ export type WatchEventFilter = (ev: WatchEvent) => boolean;
100
100
 
101
101
  export type WatchEventListener = (ev: WatchEvent, folder: string) => void;
102
102
  export type WatchConfig = {
103
103
  /**
104
104
  * Predicate for filtering events
105
105
  */
106
- filter?: EventFilter;
106
+ filter?: WatchEventFilter;
107
107
  /**
108
108
  * List of top level folders to ignore
109
109
  */
@@ -116,18 +116,22 @@ export type WatchConfig = {
116
116
  * Include files that start with '.'
117
117
  */
118
118
  includeHidden?: boolean;
119
+ /**
120
+ * Should watching prevent normal exiting, until watch is removed?
121
+ */
122
+ persistent?: boolean;
119
123
  };
120
124
 
121
125
  /**
122
- * Leverages @parcel/watcher to watch a series of folders
123
- * @param folders
126
+ * Watch files for a given folder
127
+ * @param folder
124
128
  * @param onEvent
125
- * @private
129
+ * @param options
126
130
  */
127
- export async function watchFolders(
128
- folders: string[] | [folder: string, targetFolder: string][],
131
+ export async function watchFolderImmediate(
132
+ folder: string,
129
133
  onEvent: WatchEventListener,
130
- config: WatchConfig = {}
134
+ options: WatchConfig = {}
131
135
  ): Promise<() => Promise<void>> {
132
136
  ```
133
137
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/manifest",
3
- "version": "3.0.1",
3
+ "version": "3.0.2-rc.1",
4
4
  "description": "Support for project indexing, manifesting, along with file watching",
5
5
  "keywords": [
6
6
  "path",
package/src/watch.ts CHANGED
@@ -32,6 +32,10 @@ export type WatchConfig = {
32
32
  * Include files that start with '.'
33
33
  */
34
34
  includeHidden?: boolean;
35
+ /**
36
+ * Should watching prevent normal exiting, until watch is removed?
37
+ */
38
+ persistent?: boolean;
35
39
  };
36
40
 
37
41
  /**
@@ -46,7 +50,7 @@ export async function watchFolderImmediate(
46
50
  options: WatchConfig = {}
47
51
  ): Promise<() => Promise<void>> {
48
52
  const watchPath = path.resolve(folder);
49
- const watcher = watch(watchPath, { persistent: true, encoding: 'utf8' });
53
+ const watcher = watch(watchPath, { persistent: options.persistent, encoding: 'utf8' });
50
54
  const lastStats: Record<string, Stats | undefined> = {};
51
55
  const invalidFilter = (el: string): boolean =>
52
56
  (el === '.' || el === '..' || (!options.includeHidden && el.startsWith('.')) || !!options.ignore?.includes(el));
@@ -130,6 +134,11 @@ export async function watchFolders(
130
134
  let finalProm: Promise<void> | undefined;
131
135
  const remove = (): Promise<void> => finalProm ??= Promise.all(subs.map(x => x?.unsubscribe())).then(() => { });
132
136
 
137
+ // Cleanup on intent to exit
138
+ if (!config.persistent) {
139
+ process.on('SIGUSR2', remove);
140
+ }
141
+
133
142
  // Cleanup on exit
134
143
  process.on('exit', remove);
135
144
 
@@ -7,6 +7,7 @@ import {
7
7
 
8
8
  const MANIFEST_MOD = '@travetto/manifest';
9
9
  const MANIFEST_IDX = `${MANIFEST_MOD}/__index__`;
10
+ const ENTRY_POINT = 'support/entry';
10
11
 
11
12
  const ROOT_IDX_IMPORT = `${MANIFEST_MOD}/src/root-index`;
12
13
  const ROOT_IDX_CLS = 'RootIndex';
@@ -30,13 +31,10 @@ interface MetadataInfo {
30
31
  */
31
32
  export class RegisterTransformer {
32
33
 
33
- static #valid(state: TransformerState): boolean {
34
- return !state.importName.startsWith(MANIFEST_MOD) ||
35
- (
36
- !state.importName.includes('/src/') &&
37
- !state.importName.includes('/support/') &&
38
- state.importName !== MANIFEST_IDX
39
- );
34
+ static #valid({ importName: imp }: TransformerState): boolean {
35
+ return !imp.startsWith(MANIFEST_MOD) ?
36
+ !imp.includes(ENTRY_POINT) :
37
+ !(/[/](src|support)[/]/.test(imp) || imp === MANIFEST_IDX);
40
38
  }
41
39
 
42
40
  /**