@ryanatkn/gro 0.163.0 → 0.164.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/dist/filer.d.ts CHANGED
@@ -4,8 +4,7 @@ import type { Package_Json } from '@ryanatkn/belt/package_json.js';
4
4
  import type { File_Filter, Path_Id } from './path.ts';
5
5
  import { watch_dir, type Watcher_Change, type Watch_Dir_Options } from './watch_dir.ts';
6
6
  import type { Disknode } from './disknode.ts';
7
- export type Cleanup_Watch = () => Promise<void>;
8
- export type On_Filer_Change = (change: Watcher_Change, source_file: Disknode) => void;
7
+ export type On_Filer_Change = (change: Watcher_Change, disknode: Disknode) => void;
9
8
  export interface Filer_Options {
10
9
  watch_dir?: typeof watch_dir;
11
10
  watch_dir_options?: Partial<Omit_Strict<Watch_Dir_Options, 'on_change'>>;
@@ -17,10 +16,17 @@ export declare class Filer {
17
16
  readonly root_dir: Path_Id;
18
17
  readonly files: Map<Path_Id, Disknode>;
19
18
  constructor(options?: Filer_Options);
19
+ get inited(): boolean;
20
20
  get_by_id: (id: Path_Id) => Disknode | undefined;
21
21
  get_or_create: (id: Path_Id) => Disknode;
22
- watch(listener: On_Filer_Change): Promise<Cleanup_Watch>;
22
+ /**
23
+ * Initialize the filer to populate files without watching.
24
+ * Safe to call multiple times - subsequent calls are no-ops.
25
+ * Used by gen files to access the file graph.
26
+ */
27
+ init(): Promise<void>;
28
+ watch(listener: On_Filer_Change): Promise<() => void>;
23
29
  close(): Promise<void>;
24
30
  }
25
- export declare const filter_dependents: (source_file: Disknode, get_by_id: (id: Path_Id) => Disknode | undefined, filter?: File_Filter, results?: Set<string>, searched?: Set<string>, log?: Logger) => Set<string>;
31
+ export declare const filter_dependents: (disknode: Disknode, get_by_id: (id: Path_Id) => Disknode | undefined, filter?: File_Filter, results?: Set<string>, searched?: Set<string>, log?: Logger) => Set<string>;
26
32
  //# sourceMappingURL=filer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"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AG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAa;gBAYvC,OAAO,GAAE,aAA4B;IAUjD,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,SAAS,GAAI,IAAI,OAAO,KAAG,QAAQ,GAAG,SAAS,CAE7C;IAEF,aAAa,GAAI,IAAI,OAAO,KAAG,QAAQ,CAkBrC;IAEF;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAmDrB,KAAK,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC;IAiB3D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAkLtB;AAGD,eAAO,MAAM,iBAAiB,GAC7B,UAAU,QAAQ,EAClB,WAAW,CAAC,EAAE,EAAE,OAAO,KAAK,QAAQ,GAAG,SAAS,EAChD,SAAS,WAAW,EACpB,UAAS,GAAG,CAAC,MAAM,CAAa,EAChC,WAAU,GAAG,CAAC,MAAM,CAAa,EACjC,MAAM,MAAM,KACV,GAAG,CAAC,MAAM,CAkBZ,CAAC"}
package/dist/filer.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { EMPTY_OBJECT } from '@ryanatkn/belt/object.js';
2
2
  import { existsSync, readFileSync, statSync } from 'node:fs';
3
3
  import { dirname, resolve } from 'node:path';
4
- import { wait } from '@ryanatkn/belt/async.js';
5
4
  import { isBuiltin } from 'node:module';
6
5
  import { fileURLToPath, pathToFileURL } from 'node:url';
7
6
  import { Unreachable_Error } from '@ryanatkn/belt/error.js';
@@ -15,10 +14,15 @@ import { SVELTEKIT_GLOBAL_SPECIFIER } from "./constants.js";
15
14
  const aliases = Object.entries(default_svelte_config.alias);
16
15
  export class Filer {
17
16
  root_dir;
17
+ // TODO rename everything to `disknode`
18
18
  files = new Map();
19
19
  #watch_dir;
20
20
  #watch_dir_options;
21
21
  #log;
22
+ #listeners = new Set();
23
+ #watching;
24
+ #initing;
25
+ #closing;
22
26
  constructor(options = EMPTY_OBJECT) {
23
27
  this.#watch_dir = options.watch_dir ?? watch_dir;
24
28
  this.#watch_dir_options = options.watch_dir_options ?? EMPTY_OBJECT;
@@ -29,9 +33,9 @@ export class Filer {
29
33
  // package.json/gro.config.ts/tsconfig.json/svelte.config.js/vite.config.ts to invalidate everything
30
34
  this.#log = options.log;
31
35
  }
32
- #watching;
33
- #listeners = new Set();
34
- #ready = false;
36
+ get inited() {
37
+ return this.#watching !== undefined;
38
+ }
35
39
  get_by_id = (id) => {
36
40
  return this.files.get(id);
37
41
  };
@@ -55,6 +59,111 @@ export class Filer {
55
59
  }
56
60
  return file;
57
61
  };
62
+ /**
63
+ * Initialize the filer to populate files without watching.
64
+ * Safe to call multiple times - subsequent calls are no-ops.
65
+ * Used by gen files to access the file graph.
66
+ */
67
+ async init() {
68
+ // if already initing, return the existing promise
69
+ if (this.#initing)
70
+ return this.#initing;
71
+ // if already initialized, just ensure ready
72
+ if (this.#watching) {
73
+ return this.#watching.init();
74
+ }
75
+ // start new initialization
76
+ this.#initing = this.#init();
77
+ try {
78
+ await this.#initing;
79
+ }
80
+ catch (err) {
81
+ // use shared cleanup logic
82
+ this.#cleanup();
83
+ throw err;
84
+ }
85
+ finally {
86
+ this.#initing = undefined;
87
+ }
88
+ }
89
+ async #init() {
90
+ const watcher = this.#watch_dir({
91
+ ...this.#watch_dir_options,
92
+ dir: this.root_dir,
93
+ on_change: this.#on_change,
94
+ });
95
+ try {
96
+ await watcher.init();
97
+ // check if close() was called during init
98
+ if (this.#closing) {
99
+ await watcher.close();
100
+ return;
101
+ }
102
+ // only set after successful init and not closing
103
+ this.#watching = watcher;
104
+ }
105
+ catch (err) {
106
+ // clean up watcher on error, but don't let close error mask init error
107
+ try {
108
+ await watcher.close();
109
+ }
110
+ catch {
111
+ // ignore close errors - init error is more important
112
+ }
113
+ throw err;
114
+ }
115
+ }
116
+ async watch(listener) {
117
+ await this.#add_listener(listener);
118
+ return () => {
119
+ this.#remove_listener(listener);
120
+ };
121
+ }
122
+ /**
123
+ * Internal cleanup of all state - can be called safely from anywhere
124
+ */
125
+ #cleanup() {
126
+ this.#listeners.clear();
127
+ this.files.clear();
128
+ this.#watching = undefined;
129
+ // #initing is handled in finally block of init()
130
+ }
131
+ close() {
132
+ // if already closing, return existing promise
133
+ if (this.#closing)
134
+ return this.#closing;
135
+ // if already closed and not initing, nothing to do
136
+ if (!this.#watching && !this.#initing)
137
+ return Promise.resolve();
138
+ // start new close operation
139
+ const closing = this.#close();
140
+ this.#closing = closing;
141
+ // Clean up after completion, but don't change the returned promise
142
+ // Use void to ensure we don't accidentally return the .then() promise
143
+ void closing.then(() => {
144
+ this.#closing = undefined;
145
+ }, () => {
146
+ this.#closing = undefined;
147
+ });
148
+ return this.#closing;
149
+ }
150
+ async #close() {
151
+ // wait for any pending initialization to complete
152
+ if (this.#initing) {
153
+ try {
154
+ await this.#initing;
155
+ }
156
+ catch {
157
+ // ignore errors during close
158
+ }
159
+ }
160
+ // close watcher if it exists
161
+ if (this.#watching) {
162
+ await this.#watching.close();
163
+ }
164
+ // clean up all state
165
+ this.#cleanup();
166
+ }
58
167
  #update(id) {
59
168
  const file = this.get_or_create(id);
60
169
  const stats = existsSync(id) ? statSync(id) : null;
@@ -112,96 +221,75 @@ export class Filer {
112
221
  if (!file)
113
222
  return null; // this is safe because the object would exist if any other file referenced it as a dependency or dependent
114
223
  file.contents = null; // clear contents in case it gets re-added later, we want the change to be detected
115
- let found = false;
116
- for (const d of this.files.values()) {
117
- if (d.dependencies.has(file.id)) {
118
- found = true;
119
- break;
120
- }
121
- }
122
- if (!found)
224
+ file.dependencies.clear();
225
+ // keep the file in memory if other files still depend on it
226
+ if (file.dependents.size === 0) {
123
227
  this.files.delete(id);
228
+ }
124
229
  return file;
125
230
  }
126
231
  #sync_listener_with_files(listener) {
127
- if (!this.#ready)
128
- return;
129
- for (const source_file of this.files.values()) {
130
- listener({ type: 'add', path: source_file.id, is_directory: false }, source_file);
232
+ for (const disknode of this.files.values()) {
233
+ try {
234
+ listener({ type: 'add', path: disknode.id, is_directory: false }, disknode);
235
+ }
236
+ catch (err) {
237
+ this.#log?.error('[filer] Listener error during sync:', err);
238
+ }
131
239
  }
132
240
  }
133
- #notify_change(change, source_file) {
134
- if (!this.#ready)
135
- return;
241
+ #notify_change(change, disknode) {
136
242
  for (const listener of this.#listeners) {
137
- listener(change, source_file);
243
+ try {
244
+ listener(change, disknode);
245
+ }
246
+ catch (err) {
247
+ this.#log?.error('[filer] Listener error during change notification:', err);
248
+ }
138
249
  }
139
250
  }
140
251
  async #add_listener(listener) {
141
252
  this.#listeners.add(listener);
142
- if (this.#watching) {
143
- // if already watching, call the listener for all existing files after init
144
- await this.#watching.init();
145
- await wait(); // wait a tick to ensure the `this.#ready` value is updated below first
146
- this.#sync_listener_with_files(listener);
147
- return;
148
- }
149
- this.#watching = this.#watch_dir({
150
- ...this.#watch_dir_options,
151
- dir: this.root_dir,
152
- on_change: this.#on_change,
153
- });
154
- await this.#watching.init();
155
- this.#ready = true;
253
+ // ensure initialized
254
+ await this.init();
255
+ // notify of existing files
156
256
  this.#sync_listener_with_files(listener);
157
257
  }
158
- async #remove_listener(listener) {
258
+ #remove_listener(listener) {
159
259
  this.#listeners.delete(listener);
160
- if (this.#listeners.size === 0) {
161
- await this.close(); // TODO is this right? should `watch` be async?
162
- }
260
+ // keep watching active even with no listeners, only close() tears down
163
261
  }
164
262
  #on_change = (change) => {
263
+ if (this.#closing)
264
+ return; // ignore changes during close
165
265
  if (change.is_directory)
166
266
  return; // TODO manage directories?
167
- let source_file;
267
+ let disknode;
168
268
  switch (change.type) {
169
269
  case 'add':
170
270
  case 'update': {
171
- source_file = this.#update(change.path);
271
+ disknode = this.#update(change.path);
172
272
  break;
173
273
  }
174
274
  case 'delete': {
175
- source_file = this.#remove(change.path);
275
+ disknode = this.#remove(change.path);
176
276
  break;
177
277
  }
178
278
  default:
179
279
  throw new Unreachable_Error(change.type);
180
280
  }
181
- if (source_file) {
182
- this.#notify_change(change, source_file);
281
+ if (disknode && this.#listeners.size > 0) {
282
+ this.#notify_change(change, disknode);
183
283
  }
184
284
  };
185
- async watch(listener) {
186
- await this.#add_listener(listener);
187
- return () => this.#remove_listener(listener);
188
- }
189
- async close() {
190
- this.#ready = false;
191
- this.#listeners.clear();
192
- if (this.#watching) {
193
- await this.#watching.close();
194
- this.#watching = undefined;
195
- }
196
- }
197
285
  #is_external(id) {
198
286
  const { filter } = this.#watch_dir_options;
199
287
  return !id.startsWith(this.root_dir + '/') || (!!filter && !filter(id, false));
200
288
  }
201
289
  }
202
290
  // TODO maybe `Disknode` class?
203
- export const filter_dependents = (source_file, get_by_id, filter, results = new Set(), searched = new Set(), log) => {
204
- const { dependents } = source_file;
291
+ export const filter_dependents = (disknode, get_by_id, filter, results = new Set(), searched = new Set(), log) => {
292
+ const { dependents } = disknode;
205
293
  for (const dependent_id of dependents.keys()) {
206
294
  if (searched.has(dependent_id))
207
295
  continue;
@@ -209,12 +297,12 @@ export const filter_dependents = (source_file, get_by_id, filter, results = new
209
297
  if (!filter || filter(dependent_id)) {
210
298
  results.add(dependent_id);
211
299
  }
212
- const dependent_source_file = get_by_id(dependent_id);
213
- if (!dependent_source_file) {
214
- log?.warn(`[filer.filter_dependents] dependent source file ${dependent_id} not found for ${source_file.id}`);
300
+ const dependent_disknode = get_by_id(dependent_id);
301
+ if (!dependent_disknode) {
302
+ log?.warn(`[filer.filter_dependents] dependent source file ${dependent_id} not found for ${disknode.id}`);
215
303
  continue;
216
304
  }
217
- filter_dependents(dependent_source_file, get_by_id, filter, results, searched);
305
+ filter_dependents(dependent_disknode, get_by_id, filter, results, searched);
218
306
  }
219
307
  return results;
220
308
  };
package/dist/gen.d.ts CHANGED
@@ -6,6 +6,8 @@ import type { Gro_Config } from './gro_config.ts';
6
6
  import type { Parsed_Svelte_Config } from './svelte_config.ts';
7
7
  import { type Load_Modules_Failure, type Module_Meta } from './modules.ts';
8
8
  import { Input_Path, type Resolved_Input_File, type Resolved_Input_Path } from './input_path.ts';
9
+ import type { Filer } from './filer.ts';
10
+ import type { Invoke_Task } from './task.ts';
9
11
  export declare const GEN_FILE_PATTERN_TEXT = "gen";
10
12
  export declare const GEN_FILE_PATTERN: string;
11
13
  export declare const is_gen_path: (path: string) => boolean;
@@ -23,6 +25,10 @@ export type Gen = (ctx: Gen_Context) => Raw_Gen_Result | Promise<Raw_Gen_Result>
23
25
  export interface Gen_Context {
24
26
  config: Gro_Config;
25
27
  svelte_config: Parsed_Svelte_Config;
28
+ filer: Filer;
29
+ log: Logger;
30
+ timings: Timings;
31
+ invoke_task: Invoke_Task;
26
32
  /**
27
33
  * Same as `import.meta.url` but in path form.
28
34
  */
@@ -31,7 +37,6 @@ export interface Gen_Context {
31
37
  * The `origin_id` relative to the root dir.
32
38
  */
33
39
  origin_path: string;
34
- log: Logger;
35
40
  }
36
41
  export type Raw_Gen_Result = string | Raw_Gen_File | null | Array<Raw_Gen_Result>;
37
42
  export interface Raw_Gen_File {
package/dist/gen.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"gen.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gen.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,uBAAuB,CAAC;AAGlD,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAC;AACrD,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,2BAA2B,CAAC;AAKvD,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAe,KAAK,oBAAoB,EAAE,KAAK,WAAW,EAAC,MAAM,cAAc,CAAC;AACvF,OAAO,EACN,UAAU,EAGV,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,MAAM,iBAAiB,CAAC;AAGzB,eAAO,MAAM,qBAAqB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qB,CAAC,CAAC;AAC3F,MAAM,MAAM,qBAAqB,GAAG,oBAAoB,CAAC,mBAAmB,CAAC,CAAC;AAE9E,eAAO,MAAM,aAAa,GACzB,gBAAgB,cAAc,EAC9B,UAAU,OAAO,KACf,OAAO,CAAC,oBAAoB,CAc9B,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,KAAK,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAG,GAAG,IAAI,cACxC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"gen.task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gen.task.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAa,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AAgBhD,eAAO,MAAM,IAAI;;;;kBAaf,CAAC;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAIxC,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,IAAI,CA+F3B,CAAC"}
1
+ {"version":3,"file":"gen.task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gen.task.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAa,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AAgBhD,eAAO,MAAM,IAAI;;;;kBAaf,CAAC;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAExC,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,IAAI,CAqH3B,CAAC"}
package/dist/gen.task.js CHANGED
@@ -24,12 +24,10 @@ export const Args = z.strictObject({
24
24
  .meta({ description: 'exit with a nonzero code if any files need to be generated' })
25
25
  .default(false),
26
26
  });
27
- // TODO test - especially making sure nothing gets genned
28
- // if there's any validation or import errors
29
27
  export const task = {
30
28
  summary: 'run code generation scripts',
31
29
  Args,
32
- run: async ({ args, log, timings, config }) => {
30
+ run: async ({ args, filer, log, timings, config, invoke_task }) => {
33
31
  const { _: raw_input_paths, root_dirs, check } = args;
34
32
  const input_paths = to_input_paths(raw_input_paths);
35
33
  // load all of the gen modules
@@ -55,7 +53,7 @@ export const task = {
55
53
  const loaded_genfiles = loaded.value;
56
54
  // run `gen` on each of the modules
57
55
  const timing_to_generate_code = timings.start('generate code'); // TODO this ignores `gen_results.elapsed` - should it return `Timings` instead?
58
- const gen_results = await run_gen(loaded_genfiles.modules, config, log, timings, format_file);
56
+ const gen_results = await run_gen(loaded_genfiles.modules, config, filer, log, timings, invoke_task, format_file);
59
57
  timing_to_generate_code();
60
58
  const fail_count = gen_results.failures.length;
61
59
  const analyzed_gen_results = await analyze_gen_results(gen_results);
@@ -72,6 +70,14 @@ export const task = {
72
70
  continue;
73
71
  has_unexpected_changes = true;
74
72
  log.error(st('red', `Generated file ${print_path(analyzed.file.id)} via ${print_path(analyzed.file.origin_id)} ${analyzed.is_new ? 'is new' : 'has changed'}.`));
73
+ // DEBUG HACK: Show current vs changed content
74
+ if (!analyzed.is_new) {
75
+ log.info(`\n=== CURRENT CONTENT (${print_path(analyzed.file.id)}) ===\n${analyzed.existing_content}\n=== END CURRENT ===`);
76
+ log.info(`\n=== CHANGED CONTENT (${print_path(analyzed.file.id)}) ===\n${analyzed.file.content}\n=== END CHANGED ===`);
77
+ }
78
+ else {
79
+ log.info(`\n=== NEW FILE CONTENT (${print_path(analyzed.file.id)}) ===\n${analyzed.file.content}\n=== END NEW ===`);
80
+ }
75
81
  }
76
82
  if (has_unexpected_changes) {
77
83
  throw new Task_Error('Failed gen check. Some generated files have unexpectedly changed.' +
@@ -1 +1 @@
1
- {"version":3,"file":"gro.config.default.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gro.config.default.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAWvD;;;;;;;;GAQG;AACH,QAAA,MAAM,MAAM,EAAE,iBAmCb,CAAC;AAEF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"gro.config.default.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gro.config.default.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAUvD;;;;;;;;GAQG;AACH,QAAA,MAAM,MAAM,EAAE,iBAsBb,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -1,19 +1,9 @@
1
- var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
- if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
- return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
- return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
- });
6
- }
7
- return path;
8
- };
9
- import { resolve } from 'node:path';
10
1
  import { gro_plugin_sveltekit_library } from "./gro_plugin_sveltekit_library.js";
11
2
  import { has_server, gro_plugin_server } from "./gro_plugin_server.js";
12
3
  import { gro_plugin_sveltekit_app } from "./gro_plugin_sveltekit_app.js";
13
4
  import { has_sveltekit_app, has_sveltekit_library } from "./sveltekit_helpers.js";
14
5
  import { gro_plugin_gen } from "./gro_plugin_gen.js";
15
- import { has_dep, load_package_json } from "./package_json.js";
16
- import { find_first_existing_file } from "./search_fs.js";
6
+ import { load_package_json } from "./package_json.js";
17
7
  // TODO hacky, maybe extract utils?
18
8
  /**
19
9
  * This is the default config that's passed to `gro.config.ts`
@@ -26,25 +16,13 @@ import { find_first_existing_file } from "./search_fs.js";
26
16
  */
27
17
  const config = async (cfg, svelte_config) => {
28
18
  const package_json = load_package_json(); // TODO gets wastefully loaded by some plugins, maybe put in plugin/task context? how does that interact with `map_package_json`?
29
- const [has_moss_dep, has_server_result, has_sveltekit_library_result, has_sveltekit_app_result] = await Promise.all([
30
- has_dep('@ryanatkn/moss', package_json),
19
+ const [has_server_result, has_sveltekit_library_result, has_sveltekit_app_result] = await Promise.all([
31
20
  has_server(),
32
21
  has_sveltekit_library(package_json, svelte_config),
33
22
  has_sveltekit_app(),
34
23
  ]);
35
- const local_moss_plugin_path = find_first_existing_file([
36
- './src/lib/gro_plugin_moss.ts',
37
- './src/gro_plugin_moss.ts',
38
- './src/routes/gro_plugin_moss.ts', // TODO probably remove this
39
- ]);
40
24
  // put things that generate files before SvelteKit so it can see them
41
- cfg.plugins = async () => [
42
- // TODO probably belongs in the gen system
43
- local_moss_plugin_path
44
- ? (await import(__rewriteRelativeImportExtension(resolve(local_moss_plugin_path), true))).gro_plugin_moss()
45
- : has_moss_dep
46
- ? (await import('@ryanatkn/moss/gro_plugin_moss.js')).gro_plugin_moss()
47
- : null, // lazy load to avoid errors if it's not installed
25
+ cfg.plugins = () => [
48
26
  gro_plugin_gen(),
49
27
  has_server_result.ok ? gro_plugin_server() : null,
50
28
  has_sveltekit_library_result.ok ? gro_plugin_sveltekit_library() : null,
@@ -72,9 +72,9 @@ export const gro_plugin_gen = ({ input_paths = [paths.source], root_dirs = [path
72
72
  }
73
73
  });
74
74
  },
75
- teardown: async () => {
75
+ teardown: () => {
76
76
  if (cleanup_watch) {
77
- await cleanup_watch();
77
+ cleanup_watch();
78
78
  cleanup_watch = undefined;
79
79
  }
80
80
  },
@@ -1 +1 @@
1
- {"version":3,"file":"invoke_task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/invoke_task.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,OAAO,EAAC,MAAM,2BAA2B,CAAC;AAGpE,OAAO,EAAoB,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AAEvD,OAAO,EAAgB,cAAc,EAAC,MAAM,iBAAiB,CAAC;AAI9D,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AAEjC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,WAAW,GACvB,WAAW,cAAc,EACzB,MAAM,IAAI,GAAG,SAAS,EACtB,QAAQ,UAAU,EAClB,gBAAgB,KAAK,EACrB,kBAAkB,OAAO,GAAG,IAAI,KAC9B,OAAO,CAAC,IAAI,CAgFd,CAAC"}
1
+ {"version":3,"file":"invoke_task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/invoke_task.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,OAAO,EAAC,MAAM,2BAA2B,CAAC;AAGpE,OAAO,EAAoB,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AAEvD,OAAO,EAAgB,cAAc,EAAC,MAAM,iBAAiB,CAAC;AAI9D,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AAEjC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,WAAW,GACvB,WAAW,cAAc,EACzB,MAAM,IAAI,GAAG,SAAS,EACtB,QAAQ,UAAU,EAClB,gBAAgB,KAAK,EACrB,kBAAkB,OAAO,GAAG,IAAI,KAC9B,OAAO,CAAC,IAAI,CAwFd,CAAC"}
@@ -34,12 +34,19 @@ import { Filer } from "./filer.js";
34
34
  export const invoke_task = async (task_name, args, config, initial_filer, initial_timings) => {
35
35
  const log = new System_Logger(print_log_label(task_name || 'gro'));
36
36
  log.info('invoking', task_name ? st('cyan', task_name) : 'gro');
37
+ // track if we created the filer
38
+ const owns_filer = !initial_filer;
37
39
  const filer = initial_filer ?? new Filer({ log });
40
+ const owns_timings = !initial_timings;
38
41
  const timings = initial_timings ?? new Timings();
39
42
  const total_timing = create_stopwatch();
40
- const finish = () => {
41
- if (!initial_timings)
42
- return; // print timings only for the top-level task
43
+ const finish = async () => {
44
+ // cleanup filer only if we created it and it was initialized
45
+ if (owns_filer && filer.inited) {
46
+ await filer.close();
47
+ }
48
+ if (owns_timings)
49
+ return; // kinda weird, print timings only for the top-level task
43
50
  print_timings(timings, log);
44
51
  log.info(`🕒 ${print_ms(total_timing())}`);
45
52
  };
@@ -47,7 +54,7 @@ export const invoke_task = async (task_name, args, config, initial_filer, initia
47
54
  if (!task_name && (args?.version || args?.v)) {
48
55
  const gro_package_json = load_gro_package_json();
49
56
  log.info(`${st('gray', 'v')}${st('cyan', gro_package_json.version)}`);
50
- finish();
57
+ await finish();
51
58
  return;
52
59
  }
53
60
  // Resolve the input path for the provided task name.
@@ -73,7 +80,7 @@ export const invoke_task = async (task_name, args, config, initial_filer, initia
73
80
  if (resolved_input_files.length > 1 || resolved_input_files[0].resolved_input_path.is_directory) {
74
81
  // The input path matches a directory. Log the tasks but don't run them.
75
82
  log_tasks(log, loaded_tasks);
76
- finish();
83
+ await finish();
77
84
  return;
78
85
  }
79
86
  // The input path matches a file that's presumable a task, so load and run it.
@@ -90,5 +97,5 @@ export const invoke_task = async (task_name, args, config, initial_filer, initia
90
97
  throw result.error;
91
98
  }
92
99
  log.info(`✓ ${st('cyan', task.name)}`);
93
- finish();
100
+ await finish();
94
101
  };
package/dist/package.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // generated by src/lib/package.gen.ts
2
2
  export const package_json = {
3
3
  name: '@ryanatkn/gro',
4
- version: '0.163.0',
4
+ version: '0.164.1',
5
5
  description: 'task runner and toolkit extending SvelteKit',
6
6
  motto: 'generate, run, optimize',
7
7
  glyph: '🌰',
@@ -59,13 +59,13 @@ export const package_json = {
59
59
  vitest: '^3',
60
60
  },
61
61
  peerDependenciesMeta: { '@sveltejs/kit': { optional: true }, vitest: { optional: true } },
62
- optionalDependencies: { '@ryanatkn/moss': '>=0.31.0', vitest: '^3' },
62
+ optionalDependencies: { '@ryanatkn/moss': '>=0.33.0', vitest: '^3' },
63
63
  devDependencies: {
64
64
  '@changesets/changelog-git': '^0.2.1',
65
65
  '@changesets/types': '^6.1.0',
66
66
  '@ryanatkn/eslint-config': '^0.8.0',
67
67
  '@ryanatkn/fuz': '^0.145.0',
68
- '@ryanatkn/moss': '^0.32.0',
68
+ '@ryanatkn/moss': '^0.33.0',
69
69
  '@sveltejs/adapter-static': '^3.0.9',
70
70
  '@sveltejs/kit': '^2.37.1',
71
71
  '@sveltejs/package': '^2.5.0',
@@ -266,7 +266,7 @@ export const package_json = {
266
266
  };
267
267
  export const src_json = {
268
268
  name: '@ryanatkn/gro',
269
- version: '0.163.0',
269
+ version: '0.164.1',
270
270
  modules: {
271
271
  '.': {
272
272
  path: 'index.ts',
@@ -489,7 +489,6 @@ export const src_json = {
489
489
  './filer.js': {
490
490
  path: 'filer.ts',
491
491
  declarations: [
492
- { name: 'Cleanup_Watch', kind: 'type' },
493
492
  { name: 'On_Filer_Change', kind: 'type' },
494
493
  { name: 'Filer_Options', kind: 'type' },
495
494
  { name: 'Filer', kind: 'class' },
@@ -975,6 +974,7 @@ export const src_json = {
975
974
  declarations: [
976
975
  { name: 'Task', kind: 'type' },
977
976
  { name: 'Task_Context', kind: 'type' },
977
+ { name: 'Invoke_Task', kind: 'type' },
978
978
  { name: 'TASK_FILE_SUFFIX_TS', kind: 'variable' },
979
979
  { name: 'TASK_FILE_SUFFIX_JS', kind: 'variable' },
980
980
  { name: 'TASK_FILE_SUFFIXES', kind: 'variable' },
@@ -1 +1 @@
1
- {"version":3,"file":"package_json.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/package_json.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,uBAAuB,CAAC;AAElD,OAAO,EAAC,YAAY,EAAE,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AAQlF,MAAM,MAAM,gBAAgB,GAAG,CAC9B,YAAY,EAAE,YAAY,KACtB,YAAY,GAAG,IAAI,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;AAExD,eAAO,MAAM,k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YAAY,GAAG,IAAI,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAC,CAa/D,CAAC;AAOF,eAAO,MAAM,kBAAkB,GAAI,OAAO,KAAK,CAAC,MAAM,CAAC,KAAG,oBA6CzD,CAAC;AAIF,eAAO,MAAM,cAAc,GAC1B,cAAc,YAAY,KACxB;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,GAAG,SAgBlC,CAAC;AA8BF,eAAO,MAAM,OAAO,GACnB,UAAU,MAAM,EAChB,eAAc,YAAkC,KAC9C,OAGyC,CAAC;AAE7C,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,YAAY,GAAI,cAAc,YAAY,KAAG,KAAK,CAAC,gBAAgB,CAe/E,CAAC"}
@@ -76,6 +76,8 @@ export const update_package_json = async (update, dir = paths.root, write = true
76
76
  return { package_json: updated, changed: true };
77
77
  };
78
78
  const is_index = (path) => path === 'index.ts' || path === 'index.js';
79
+ // TODO support subpath patterns as the main concise way to do things
80
+ // https://nodejs.org/api/packages.html#subpath-patterns
79
81
  export const to_package_exports = (paths) => {
80
82
  const sorted = paths
81
83
  .slice()
package/dist/run_gen.d.ts CHANGED
@@ -3,6 +3,8 @@ import type { Logger } from '@ryanatkn/belt/log.js';
3
3
  import { type Gen_Results, type Genfile_Module_Meta } from './gen.ts';
4
4
  import type { format_file as base_format_file } from './format_file.ts';
5
5
  import type { Gro_Config } from './gro_config.ts';
6
+ import type { Filer } from './filer.ts';
7
+ import type { Invoke_Task } from './task.ts';
6
8
  export declare const GEN_NO_PROD_MESSAGE = "gen runs only during development";
7
- export declare const run_gen: (gen_modules: Array<Genfile_Module_Meta>, config: Gro_Config, log: Logger, timings: Timings, format_file?: typeof base_format_file) => Promise<Gen_Results>;
9
+ export declare const run_gen: (gen_modules: Array<Genfile_Module_Meta>, config: Gro_Config, filer: Filer, log: Logger, timings: Timings, invoke_task: Invoke_Task, format_file?: typeof base_format_file) => Promise<Gen_Results>;
8
10
  //# sourceMappingURL=run_gen.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"run_gen.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/run_gen.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,2BAA2B,CAAC;AACvD,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,uBAAuB,CAAC;AAElD,OAAO,EACN,KAAK,WAAW,EAGhB,KAAK,mBAAmB,EAGxB,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAC,WAAW,IAAI,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AACtE,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAGhD,eAAO,MAAM,mBAAmB,qCAAqC,CAAC;AAEtE,eAAO,MAAM,OAAO,GACnB,aAAa,KAAK,CAAC,mBAAmB,CAAC,EACvC,QAAQ,UAAU,EAClB,KAAK,MAAM,EACX,SAAS,OAAO,EAChB,cAAc,OAAO,gBAAgB,KACnC,OAAO,CAAC,WAAW,CAqErB,CAAC"}
1
+ {"version":3,"file":"run_gen.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/run_gen.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,2BAA2B,CAAC;AACvD,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,uBAAuB,CAAC;AAElD,OAAO,EACN,KAAK,WAAW,EAGhB,KAAK,mBAAmB,EAGxB,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAC,WAAW,IAAI,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AACtE,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAEhD,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAC,WAAW,EAAC,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