@ryanatkn/gro 0.143.3 → 0.144.0

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.
Files changed (51) hide show
  1. package/dist/esbuild_plugin_external_worker.d.ts +2 -2
  2. package/dist/esbuild_plugin_external_worker.d.ts.map +1 -1
  3. package/dist/esbuild_plugin_svelte.d.ts +2 -2
  4. package/dist/esbuild_plugin_svelte.d.ts.map +1 -1
  5. package/dist/esbuild_plugin_sveltekit_shim_alias.d.ts +2 -2
  6. package/dist/esbuild_plugin_sveltekit_shim_alias.d.ts.map +1 -1
  7. package/dist/esbuild_plugin_sveltekit_shim_app.d.ts +2 -2
  8. package/dist/esbuild_plugin_sveltekit_shim_app.d.ts.map +1 -1
  9. package/dist/esbuild_plugin_sveltekit_shim_env.d.ts +2 -2
  10. package/dist/esbuild_plugin_sveltekit_shim_env.d.ts.map +1 -1
  11. package/dist/filer.d.ts +3 -3
  12. package/dist/filer.d.ts.map +1 -1
  13. package/dist/filer.js +0 -2
  14. package/dist/gro_plugin_gen.d.ts +2 -2
  15. package/dist/gro_plugin_gen.d.ts.map +1 -1
  16. package/dist/gro_plugin_moss.d.ts +16 -0
  17. package/dist/gro_plugin_moss.d.ts.map +1 -0
  18. package/dist/gro_plugin_moss.js +89 -0
  19. package/dist/gro_plugin_server.d.ts +2 -2
  20. package/dist/gro_plugin_server.d.ts.map +1 -1
  21. package/dist/gro_plugin_sveltekit_app.d.ts +2 -2
  22. package/dist/gro_plugin_sveltekit_app.d.ts.map +1 -1
  23. package/dist/gro_plugin_sveltekit_library.d.ts +2 -2
  24. package/dist/gro_plugin_sveltekit_library.d.ts.map +1 -1
  25. package/dist/package.d.ts +14 -0
  26. package/dist/package.d.ts.map +1 -1
  27. package/dist/package.js +33 -19
  28. package/dist/package_json.d.ts +6 -4
  29. package/dist/package_json.d.ts.map +1 -1
  30. package/dist/package_json.js +12 -12
  31. package/dist/resolve_node_specifier.d.ts +2 -5
  32. package/dist/resolve_node_specifier.d.ts.map +1 -1
  33. package/dist/resolve_node_specifier.js +233 -44
  34. package/dist/watch_dir.d.ts +2 -2
  35. package/dist/watch_dir.d.ts.map +1 -1
  36. package/package.json +11 -7
  37. package/src/lib/esbuild_plugin_external_worker.ts +2 -2
  38. package/src/lib/esbuild_plugin_svelte.ts +2 -2
  39. package/src/lib/esbuild_plugin_sveltekit_shim_alias.ts +2 -2
  40. package/src/lib/esbuild_plugin_sveltekit_shim_app.ts +2 -2
  41. package/src/lib/esbuild_plugin_sveltekit_shim_env.ts +2 -2
  42. package/src/lib/filer.ts +3 -6
  43. package/src/lib/gro_plugin_gen.ts +2 -2
  44. package/src/lib/gro_plugin_moss.ts +122 -0
  45. package/src/lib/gro_plugin_server.ts +2 -2
  46. package/src/lib/gro_plugin_sveltekit_app.ts +2 -2
  47. package/src/lib/gro_plugin_sveltekit_library.ts +2 -2
  48. package/src/lib/package.ts +33 -19
  49. package/src/lib/package_json.ts +15 -14
  50. package/src/lib/resolve_node_specifier.ts +267 -49
  51. package/src/lib/watch_dir.ts +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"package_json.d.ts","sourceRoot":"../src/lib/","sources":["package_json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAItB,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,yBAAyB,CAAC;AAUtD,eAAO,MAAM,GAAG,aAAa,CAAC;AAC9B,MAAM,MAAM,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;AAGvD,eAAO,MAAM,KAAK,aAAa,CAAC;AAChC,MAAM,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC;AAG7D,eAAO,MAAM,m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,OAAO,CAAA;CAAC,CAa/D,CAAC;AAIF,eAAO,MAAM,kBAAkB,UAAW,MAAM,EAAE,KAAG,oBA6CpD,CAAC;AAIF,eAAO,MAAM,cAAc,iBACZ,YAAY,KACxB;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,GAAG,SAgBlC,CAAC;AA8BF,eAAO,MAAM,OAAO,aACT,MAAM,iBACF,YAAY,KACxB,OAGyC,CAAC;AAE7C,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,YAAY,iBAAkB,YAAY,KAAG,gBAAgB,EAezE,CAAC"}
@@ -48,18 +48,18 @@ export const Package_Json_Funding = z.union([
48
48
  })
49
49
  .passthrough(),
50
50
  ]);
51
- // exports: {
52
- // './': './index.js',
53
- // './record': {default: './record.js'},
54
- // './export_condition': {default: {development: './ec1', default: './ec2.js'}},
55
- // }
56
- export const Package_Json_Exports = z.record(z
57
- .union([
58
- z.string(),
59
- z.record(z.string().optional()),
60
- z.record(z.record(z.string().optional()).optional()),
61
- ])
62
- .optional());
51
+ // Helper to create a recursive type that represents export conditions and values
52
+ const create_export_value_schema = () => {
53
+ return z.lazy(() => z.union([z.string(), z.null(), z.record(z.lazy(() => export_value_schema))]));
54
+ };
55
+ // The base export value schema that can be a string, null, or nested conditions
56
+ const export_value_schema = create_export_value_schema();
57
+ export const Export_Value = export_value_schema;
58
+ // Package exports can be:
59
+ // 1. A string (shorthand for main export)
60
+ // 2. null (to block exports)
61
+ // 3. A record of export conditions/paths
62
+ export const Package_Json_Exports = z.union([z.string(), z.null(), z.record(export_value_schema)]);
63
63
  /**
64
64
  * @see https://docs.npmjs.com/cli/v10/configuring-npm/package-json
65
65
  */
@@ -1,10 +1,7 @@
1
1
  import { Package_Json } from './package_json.js';
2
2
  import type { Resolved_Specifier } from './resolve_specifier.js';
3
3
  /**
4
- * Like `resolve_specifier` but for Node specifiers,
5
- * typically those that aren't relative or absolute.
6
- * Optionally return `null` instead of throwing by setting
7
- * `throw_on_missing_package` to `false`.
4
+ * This likely has differences from Node - they should be fixed on a case-by-case basis.
8
5
  */
9
- export declare const resolve_node_specifier: (specifier: string, dir?: string, parent_path?: string, cache?: Record<string, Package_Json>, throw_on_missing_package?: boolean, exports_condition?: string) => Resolved_Specifier | null;
6
+ export declare const resolve_node_specifier: (specifier: string, dir?: string, parent_path?: string, cache?: Record<string, Package_Json>, throw_on_missing_package?: boolean, exports_conditions?: string[]) => Resolved_Specifier | null;
10
7
  //# sourceMappingURL=resolve_node_specifier.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve_node_specifier.d.ts","sourceRoot":"../src/lib/","sources":["resolve_node_specifier.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAA0C,MAAM,mBAAmB,CAAC;AAGxF,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,wBAAwB,CAAC;AAE/D;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,cACvB,MAAM,8BAEH,MAAM,UACZ,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,qEAIlC,kBAAkB,GAAG,IAqEvB,CAAC"}
1
+ {"version":3,"file":"resolve_node_specifier.d.ts","sourceRoot":"../src/lib/","sources":["resolve_node_specifier.ts"],"names":[],"mappings":"AAIA,OAAO,EAAe,YAAY,EAAoB,MAAM,mBAAmB,CAAC;AAGhF,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,wBAAwB,CAAC;AAG/D;;GAEG;AACH,eAAO,MAAM,sBAAsB,cACvB,MAAM,8BAEH,MAAM,UACZ,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,wEAGlC,kBAAkB,GAAG,IA6FvB,CAAC"}
@@ -1,24 +1,19 @@
1
- import { join } from 'node:path';
1
+ import { join, extname } from 'node:path';
2
2
  import { existsSync } from 'node:fs';
3
3
  import { DEV } from 'esm-env';
4
- import { Package_Json, Package_Json_Exports, load_package_json } from './package_json.js';
4
+ import { Export_Value, Package_Json, load_package_json } from './package_json.js';
5
5
  import { paths } from './paths.js';
6
6
  import { NODE_MODULES_DIRNAME } from './constants.js';
7
+ import { escape_regexp } from '@ryanatkn/belt/regexp.js';
7
8
  /**
8
- * Like `resolve_specifier` but for Node specifiers,
9
- * typically those that aren't relative or absolute.
10
- * Optionally return `null` instead of throwing by setting
11
- * `throw_on_missing_package` to `false`.
9
+ * This likely has differences from Node - they should be fixed on a case-by-case basis.
12
10
  */
13
- export const resolve_node_specifier = (specifier, dir = paths.root, parent_path, cache, throw_on_missing_package = true,
14
- // TODO this needs to use `--conditions`/`-C` to determine the correct key
15
- exports_condition = DEV ? 'development' : 'default') => {
11
+ export const resolve_node_specifier = (specifier, dir = paths.root, parent_path, cache, throw_on_missing_package = true, exports_conditions = DEV ? ['development', 'node', 'import'] : ['production', 'node', 'import']) => {
16
12
  const raw = specifier.endsWith('?raw');
17
13
  const mapped_specifier = raw ? specifier.substring(0, specifier.length - 4) : specifier;
18
14
  // Parse the specifier
19
15
  let idx = -1;
20
16
  if (mapped_specifier[0] === '@') {
21
- // get the index of the second `/`
22
17
  let count = 0;
23
18
  for (let i = 0; i < mapped_specifier.length; i++) {
24
19
  if (mapped_specifier[i] === '/')
@@ -36,7 +31,12 @@ exports_condition = DEV ? 'development' : 'default') => {
36
31
  const module_path = idx === -1 ? '' : mapped_specifier.substring(idx + 1);
37
32
  const subpath = module_path ? './' + module_path : '.';
38
33
  const package_dir = join(dir, NODE_MODULES_DIRNAME, pkg_name);
39
- if (!existsSync(package_dir)) {
34
+ // Check cache first
35
+ let package_json;
36
+ if (cache?.[pkg_name]) {
37
+ package_json = cache[pkg_name];
38
+ }
39
+ else if (!existsSync(package_dir)) {
40
40
  if (throw_on_missing_package) {
41
41
  throw Error(`Package not found at ${package_dir} for specifier ${specifier}, you may need to install packages or fix the path` +
42
42
  (parent_path ? ` imported from ${parent_path}` : ''));
@@ -45,11 +45,25 @@ exports_condition = DEV ? 'development' : 'default') => {
45
45
  return null;
46
46
  }
47
47
  }
48
- const package_json = load_package_json(package_dir, cache, false);
49
- const { exported, exports_key } = resolve_subpath(package_json, specifier, subpath);
48
+ else {
49
+ package_json = load_package_json(package_dir, cache, false);
50
+ }
51
+ // Handle self-referencing
52
+ if (parent_path?.startsWith(package_dir)) {
53
+ if (!package_json.exports) {
54
+ throw Error(`Self-referencing is only available if package.json has "exports" field: ${specifier}` +
55
+ (parent_path ? ` imported from ${parent_path}` : ''));
56
+ }
57
+ }
58
+ const exported = resolve_subpath(package_json, subpath);
59
+ if (typeof exported === 'string') {
60
+ const validated = validate_export_target(exported, throw_on_missing_package);
61
+ if (validated === null) {
62
+ return null;
63
+ }
64
+ }
50
65
  if (!exported) {
51
66
  if (throw_on_missing_package) {
52
- // same error message as Node
53
67
  throw Error(`[ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath '${subpath}' is not defined by 'exports' in ${package_dir}/package.json` +
54
68
  (parent_path ? ` imported from ${parent_path}` : ''));
55
69
  }
@@ -57,17 +71,17 @@ exports_condition = DEV ? 'development' : 'default') => {
57
71
  return null;
58
72
  }
59
73
  }
60
- const exported_value = resolve_exported_value(exported, exports_key, exports_condition);
74
+ const exported_value = resolve_exported_value(exported, exports_conditions);
61
75
  if (exported_value === undefined) {
62
76
  if (throw_on_missing_package) {
63
- throw Error(`Package subpath '${subpath}' does not define the key '${exports_key}' in 'exports' in ${package_dir}/package.json` +
77
+ throw Error(`No valid export found for subpath '${subpath}' in ${package_dir}/package.json with the following conditions: ${exports_conditions.join(', ')}` +
64
78
  (parent_path ? ` imported from ${parent_path}` : ''));
65
79
  }
66
80
  else {
67
81
  return null;
68
82
  }
69
83
  }
70
- const path_id = join(package_dir, exported_value);
84
+ const path_id = normalize_extension(join(package_dir, exported_value));
71
85
  return {
72
86
  path_id,
73
87
  path_id_with_querystring: raw ? path_id + '?raw' : path_id,
@@ -77,32 +91,207 @@ exports_condition = DEV ? 'development' : 'default') => {
77
91
  namespace: undefined,
78
92
  };
79
93
  };
80
- /**
81
- * Resolves the subpath of a package.json `exports` field based on the `specifier`.
82
- */
83
- const resolve_subpath = (package_json, specifier, subpath) => {
84
- const exports_key = specifier.endsWith('.svelte') ? 'svelte' : 'default';
85
- const exported = subpath === '.' && !package_json.exports
86
- ? { [exports_key]: package_json.main }
87
- : package_json.exports?.[subpath];
88
- return { exported, exports_key };
94
+ const replace_wildcards = (pattern, wildcards) => {
95
+ if (!pattern.includes('*'))
96
+ return pattern;
97
+ let result = pattern;
98
+ let wildcard_index = 0;
99
+ while (result.includes('*') && wildcard_index < wildcards.length) {
100
+ result = result.replace('*', wildcards[wildcard_index++]);
101
+ }
102
+ return result;
89
103
  };
90
- /**
91
- * Resolves the exported value based on the exports key and condition.
92
- */
93
- const resolve_exported_value = (exported, exports_key, exports_condition) => {
94
- let exported_value = typeof exported === 'string' ? exported : exported[exports_key];
95
- // TODO best effort fallback, support `default` but fall back to `import` or `node` as the exports key.
96
- if (exported_value === undefined && typeof exported !== 'string' && exports_key === 'default') {
97
- exported_value = exported.import ?? exported.node;
98
- }
99
- // Possibly resolve to conditional exports.
100
- exported_value =
101
- exported_value === undefined || typeof exported_value === 'string'
102
- ? exported_value
103
- : (exported_value[exports_condition] ??
104
- exported_value.default ??
105
- exported_value.import ??
106
- exported_value.node); // TODO this fallback has corner case bugs for off-spec exports
107
- return exported_value;
104
+ const resolve_subpath = (package_json, subpath) => {
105
+ // If no exports field exists, fallback to main field for the root subpath
106
+ if (!package_json.exports) {
107
+ return subpath === '.' && package_json.main ? package_json.main : null;
108
+ }
109
+ const exports = package_json.exports;
110
+ // Handle exports sugar syntax
111
+ if (typeof exports === 'string') {
112
+ return subpath === '.' ? exports : null;
113
+ }
114
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
115
+ if (typeof exports === 'object' && exports !== null) {
116
+ // Check for exact match first
117
+ if (subpath in exports) {
118
+ return exports[subpath];
119
+ }
120
+ // Sort patterns by specificity
121
+ const patterns = Object.entries(exports)
122
+ .filter(([pattern]) => pattern.includes('*'))
123
+ .map(([pattern, target]) => ({
124
+ pattern,
125
+ target,
126
+ static_prefix: pattern.split('*')[0],
127
+ segments: pattern.split('/').length,
128
+ wildcards: (pattern.match(/\*/g) ?? []).length,
129
+ }))
130
+ .sort((a, b) => {
131
+ // Sort by static prefix length first
132
+ const prefix_diff = b.static_prefix.length - a.static_prefix.length;
133
+ if (prefix_diff !== 0)
134
+ return prefix_diff;
135
+ // Then by number of segments
136
+ const segment_diff = b.segments - a.segments;
137
+ if (segment_diff !== 0)
138
+ return segment_diff;
139
+ // Then by number of wildcards (fewer is more specific)
140
+ const wildcard_diff = a.wildcards - b.wildcards;
141
+ if (wildcard_diff !== 0)
142
+ return wildcard_diff;
143
+ // Finally by total pattern length
144
+ return b.pattern.length - a.pattern.length;
145
+ });
146
+ // Track matched wildcards for later use
147
+ let matched_wildcards = [];
148
+ // Check patterns in order of specificity
149
+ for (const { pattern, target } of patterns) {
150
+ // Convert pattern to regex, handling path segments properly
151
+ const regex_pattern = pattern.split('*').map(escape_regexp).join('([^/]+)');
152
+ const regex = new RegExp(`^${regex_pattern}$`);
153
+ const match = subpath.match(regex);
154
+ if (match) {
155
+ // If this is a null pattern and it matches, block access
156
+ if (target === null)
157
+ return null;
158
+ // Extract captured wildcards and store them
159
+ matched_wildcards = match.slice(1);
160
+ if (typeof target === 'string') {
161
+ return replace_wildcards(target, matched_wildcards);
162
+ }
163
+ if (typeof target === 'object' && target !== null) {
164
+ // For conditional exports, return an object with resolved wildcards
165
+ return Object.fromEntries(Object.entries(target).map(([key, value]) => {
166
+ if (typeof value === 'string') {
167
+ return [key, replace_wildcards(value, matched_wildcards)];
168
+ }
169
+ // Handle nested conditions
170
+ if (typeof value === 'object' && value !== null) {
171
+ return [
172
+ key,
173
+ Object.fromEntries(Object.entries(value).map(([nested_key, nested_value]) => [
174
+ nested_key,
175
+ typeof nested_value === 'string'
176
+ ? replace_wildcards(nested_value, matched_wildcards)
177
+ : nested_value,
178
+ ])),
179
+ ];
180
+ }
181
+ return [key, value];
182
+ }));
183
+ }
184
+ }
185
+ }
186
+ // Handle catch-all patterns for remaining cases
187
+ const catch_all_patterns = patterns.filter(({ pattern }) => pattern.endsWith('/*') || pattern === './*');
188
+ for (const { pattern, target } of catch_all_patterns) {
189
+ const base_pattern = pattern.slice(0, -1); // Remove trailing '*'
190
+ if (subpath.startsWith(base_pattern)) {
191
+ if (target === null)
192
+ return null;
193
+ const remainder = subpath.slice(base_pattern.length);
194
+ if (typeof target === 'string') {
195
+ return target.slice(0, -1) + remainder;
196
+ }
197
+ }
198
+ }
199
+ }
200
+ return null;
201
+ };
202
+ const resolve_exported_value = (exported, conditions) => {
203
+ if (typeof exported === 'string') {
204
+ return exported;
205
+ }
206
+ if (typeof exported !== 'object' || exported === null) {
207
+ return undefined;
208
+ }
209
+ const exported_obj = exported;
210
+ // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
211
+ let default_value;
212
+ // For each key in exported_obj, in order
213
+ for (const [condition, value] of Object.entries(exported_obj)) {
214
+ // Skip invalid conditions
215
+ if (!is_valid_condition(condition)) {
216
+ continue;
217
+ }
218
+ if (condition === 'default') {
219
+ // Store default value to try last
220
+ default_value = value;
221
+ }
222
+ else if (conditions.includes(condition)) {
223
+ const resolved = resolve_exported_value(value, conditions);
224
+ if (resolved !== undefined) {
225
+ return resolved;
226
+ }
227
+ }
228
+ }
229
+ // If no conditions matched, try default
230
+ if (default_value !== undefined) {
231
+ const resolved = resolve_exported_value(default_value, conditions);
232
+ if (resolved !== undefined) {
233
+ return resolved;
234
+ }
235
+ }
236
+ return undefined;
237
+ };
238
+ const is_valid_condition = (condition) => {
239
+ if (condition.length === 0 ||
240
+ condition.startsWith('.') ||
241
+ condition.includes(',') ||
242
+ /^\d+$/.test(condition)) {
243
+ return false;
244
+ }
245
+ return /^[a-zA-Z0-9:_\-=]+$/.test(condition);
246
+ };
247
+ const normalize_extension = (path) => {
248
+ if (path.endsWith('.d.ts')) {
249
+ return path.slice(0, -5) + '.js';
250
+ }
251
+ // No extension handling needed if path already has an extension
252
+ if (extname(path)) {
253
+ return path;
254
+ }
255
+ // If no extension at all, add .js
256
+ return path + '.js';
257
+ };
258
+ const validate_export_target = (target, throw_on_missing_package) => {
259
+ // Must start with './'
260
+ if (!target.startsWith('./') && !target.startsWith('../')) {
261
+ if (throw_on_missing_package) {
262
+ throw new Error('ERR_INVALID_PACKAGE_TARGET: Export target must start with "./" or "../"');
263
+ }
264
+ else {
265
+ return null;
266
+ }
267
+ }
268
+ // Can't contain node_modules
269
+ if (target.includes('node_modules')) {
270
+ if (throw_on_missing_package) {
271
+ throw new Error('ERR_INVALID_PACKAGE_TARGET: Export target cannot contain node_modules');
272
+ }
273
+ else {
274
+ return null;
275
+ }
276
+ }
277
+ // Check for package boundary escape
278
+ const parts = target.split('/');
279
+ let depth = 0;
280
+ for (const part of parts) {
281
+ if (part === '..') {
282
+ depth--;
283
+ // If we go above root, it's escaping the package boundary
284
+ if (depth < 0) {
285
+ if (throw_on_missing_package) {
286
+ throw new Error('ERR_INVALID_PACKAGE_TARGET: Export target cannot escape package boundary');
287
+ }
288
+ else {
289
+ return null;
290
+ }
291
+ }
292
+ }
293
+ else if (part !== '.' && part !== '') {
294
+ depth++;
295
+ }
296
+ }
108
297
  };
@@ -11,7 +11,7 @@ export interface Watcher_Change {
11
11
  }
12
12
  export type Watcher_Change_Type = 'add' | 'update' | 'delete';
13
13
  export type Watcher_Change_Callback = (change: Watcher_Change) => void;
14
- export interface Options {
14
+ export interface Watch_Dir_Options {
15
15
  dir: string;
16
16
  on_change: Watcher_Change_Callback;
17
17
  filter?: Path_Filter | null | undefined;
@@ -25,5 +25,5 @@ export interface Options {
25
25
  /**
26
26
  * Watch for changes on the filesystem using chokidar.
27
27
  */
28
- export declare const watch_dir: ({ dir, on_change, filter, absolute, chokidar, }: Options) => Watch_Node_Fs;
28
+ export declare const watch_dir: ({ dir, on_change, filter, absolute, chokidar, }: Watch_Dir_Options) => Watch_Node_Fs;
29
29
  //# sourceMappingURL=watch_dir.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"watch_dir.d.ts","sourceRoot":"../src/lib/","sources":["watch_dir.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,eAAe,EAAiB,MAAM,UAAU,CAAC;AAKrE,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,WAAW,CAAC;AAI3C,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,mBAAmB,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,OAAO,CAAC;CACtB;AACD,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAC9D,MAAM,MAAM,uBAAuB,GAAG,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;AAEvE,MAAM,WAAW,OAAO;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,uBAAuB,CAAC;IACnC,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,oDAMnB,OAAO,KAAG,aA6CZ,CAAC"}
1
+ {"version":3,"file":"watch_dir.d.ts","sourceRoot":"../src/lib/","sources":["watch_dir.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,eAAe,EAAiB,MAAM,UAAU,CAAC;AAKrE,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,WAAW,CAAC;AAI3C,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,mBAAmB,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,OAAO,CAAC;CACtB;AACD,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAC9D,MAAM,MAAM,uBAAuB,GAAG,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;AAEvE,MAAM,WAAW,iBAAiB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,uBAAuB,CAAC;IACnC,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,oDAMnB,iBAAiB,KAAG,aA6CtB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ryanatkn/gro",
3
- "version": "0.143.3",
3
+ "version": "0.144.0",
4
4
  "description": "task runner and toolkit extending SvelteKit",
5
5
  "motto": "generate, run, optimize",
6
6
  "glyph": "🌰",
@@ -49,11 +49,11 @@
49
49
  "typescript"
50
50
  ],
51
51
  "dependencies": {
52
- "@ryanatkn/belt": "^0.25.3",
52
+ "@ryanatkn/belt": "^0.26.0",
53
53
  "chokidar": "^4.0.1",
54
54
  "dotenv": "^16.4.5",
55
55
  "es-module-lexer": "^1.5.4",
56
- "esm-env": "^1.0.0",
56
+ "esm-env": "^1.1.4",
57
57
  "mri": "^1.2.0",
58
58
  "prettier": "^3.3.3",
59
59
  "prettier-plugin-svelte": "^3.2.7",
@@ -69,21 +69,21 @@
69
69
  "@changesets/changelog-git": "^0.2.0",
70
70
  "@changesets/types": "^6.0.0",
71
71
  "@ryanatkn/eslint-config": "^0.5.5",
72
- "@ryanatkn/fuz": "^0.130.1",
72
+ "@ryanatkn/fuz": "^0.130.3",
73
73
  "@ryanatkn/moss": "^0.18.2",
74
74
  "@sveltejs/adapter-static": "^3.0.6",
75
75
  "@sveltejs/kit": "^2.7.3",
76
76
  "@sveltejs/package": "^2.3.7",
77
77
  "@sveltejs/vite-plugin-svelte": "^4.0.0",
78
78
  "@types/fs-extra": "^11.0.4",
79
- "@types/node": "^22.8.1",
79
+ "@types/node": "^22.8.4",
80
80
  "esbuild": "^0.21.5",
81
81
  "eslint": "^9.13.0",
82
82
  "eslint-plugin-svelte": "^2.46.0",
83
- "svelte": "^5.1.3",
83
+ "svelte": "^5.1.5",
84
84
  "svelte-check": "^4.0.5",
85
85
  "typescript": "^5.6.3",
86
- "typescript-eslint": "^8.11.0",
86
+ "typescript-eslint": "^8.12.1",
87
87
  "uvu": "^0.5.6"
88
88
  },
89
89
  "prettier": {
@@ -250,6 +250,10 @@
250
250
  "types": "./dist/gro_plugin_gen.d.ts",
251
251
  "default": "./dist/gro_plugin_gen.js"
252
252
  },
253
+ "./gro_plugin_moss.js": {
254
+ "types": "./dist/gro_plugin_moss.d.ts",
255
+ "default": "./dist/gro_plugin_moss.js"
256
+ },
253
257
  "./gro_plugin_server.js": {
254
258
  "types": "./dist/gro_plugin_server.d.ts",
255
259
  "default": "./dist/gro_plugin_server.js"
@@ -13,7 +13,7 @@ import {esbuild_plugin_svelte} from './esbuild_plugin_svelte.js';
13
13
  import type {Parsed_Sveltekit_Config} from './sveltekit_config.js';
14
14
  import type {Path_Id} from './path.js';
15
15
 
16
- export interface Options {
16
+ export interface Esbuild_Plugin_External_Worker_Options {
17
17
  dev: boolean;
18
18
  build_options: esbuild.BuildOptions;
19
19
  dir?: string;
@@ -47,7 +47,7 @@ export const esbuild_plugin_external_worker = ({
47
47
  env_files,
48
48
  ambient_env,
49
49
  log,
50
- }: Options): esbuild.Plugin => ({
50
+ }: Esbuild_Plugin_External_Worker_Options): esbuild.Plugin => ({
51
51
  name: 'external_worker',
52
52
  setup: (build) => {
53
53
  const builds: Map<string, Promise<esbuild.BuildResult>> = new Map();
@@ -19,7 +19,7 @@ import {
19
19
  } from './sveltekit_config.js';
20
20
  import {TS_MATCHER} from './constants.js';
21
21
 
22
- export interface Options {
22
+ export interface Esbuild_Plugin_Svelte_Options {
23
23
  dev: boolean;
24
24
  base_url: Parsed_Sveltekit_Config['base_url'];
25
25
  dir?: string;
@@ -30,7 +30,7 @@ export interface Options {
30
30
  is_ts?: (filename: string) => boolean;
31
31
  }
32
32
 
33
- export const esbuild_plugin_svelte = (options: Options): esbuild.Plugin => {
33
+ export const esbuild_plugin_svelte = (options: Esbuild_Plugin_Svelte_Options): esbuild.Plugin => {
34
34
  const {
35
35
  dev,
36
36
  base_url,
@@ -2,7 +2,7 @@ import type * as esbuild from 'esbuild';
2
2
  import {escape_regexp} from '@ryanatkn/belt/regexp.js';
3
3
  import {join} from 'node:path';
4
4
 
5
- export interface Options {
5
+ export interface Esbuild_Plugin_Sveltekit_Shim_Alias_Options {
6
6
  dir?: string;
7
7
  alias?: Record<string, string>;
8
8
  }
@@ -10,7 +10,7 @@ export interface Options {
10
10
  export const esbuild_plugin_sveltekit_shim_alias = ({
11
11
  dir = process.cwd(),
12
12
  alias,
13
- }: Options): esbuild.Plugin => ({
13
+ }: Esbuild_Plugin_Sveltekit_Shim_Alias_Options): esbuild.Plugin => ({
14
14
  name: 'sveltekit_shim_alias',
15
15
  setup: (build) => {
16
16
  const aliases: Record<string, string> = {$lib: 'src/lib', ...alias};
@@ -8,7 +8,7 @@ import {
8
8
  import type {Parsed_Sveltekit_Config} from './sveltekit_config.js';
9
9
  import {EVERYTHING_MATCHER} from './constants.js';
10
10
 
11
- export interface Options {
11
+ export interface Esbuild_Plugin_Sveltekit_Shim_App_Options {
12
12
  dev: boolean;
13
13
  base_url: Parsed_Sveltekit_Config['base_url'];
14
14
  assets_url: Parsed_Sveltekit_Config['assets_url'];
@@ -18,7 +18,7 @@ export const esbuild_plugin_sveltekit_shim_app = ({
18
18
  dev,
19
19
  base_url,
20
20
  assets_url,
21
- }: Options): esbuild.Plugin => ({
21
+ }: Esbuild_Plugin_Sveltekit_Shim_App_Options): esbuild.Plugin => ({
22
22
  name: 'sveltekit_shim_app',
23
23
  setup: (build) => {
24
24
  build.onResolve({filter: /^\$app\/(forms|navigation|stores)$/}, ({path, ...rest}) =>
@@ -4,7 +4,7 @@ import {render_env_shim_module} from './sveltekit_shim_env.js';
4
4
  import {EVERYTHING_MATCHER} from './constants.js';
5
5
  import {SVELTEKIT_ENV_MATCHER} from './sveltekit_helpers.js';
6
6
 
7
- export interface Options {
7
+ export interface Esbuild_Plugin_Sveltekit_Shim_Env_Options {
8
8
  dev: boolean;
9
9
  public_prefix?: string;
10
10
  private_prefix?: string;
@@ -22,7 +22,7 @@ export const esbuild_plugin_sveltekit_shim_env = ({
22
22
  env_dir,
23
23
  env_files,
24
24
  ambient_env,
25
- }: Options): esbuild.Plugin => ({
25
+ }: Esbuild_Plugin_Sveltekit_Shim_Env_Options): esbuild.Plugin => ({
26
26
  name: 'sveltekit_shim_env',
27
27
  setup: (build) => {
28
28
  build.onResolve({filter: SVELTEKIT_ENV_MATCHER}, ({path}) => ({path, namespace}));
package/src/lib/filer.ts CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  watch_dir,
10
10
  type Watch_Node_Fs,
11
11
  type Watcher_Change,
12
- type Options as Watch_Dir_Options,
12
+ type Watch_Dir_Options,
13
13
  type Watcher_Change_Callback,
14
14
  } from './watch_dir.js';
15
15
  import {paths} from './paths.js';
@@ -20,14 +20,11 @@ import {map_sveltekit_aliases} from './sveltekit_helpers.js';
20
20
  import {Unreachable_Error} from '@ryanatkn/belt/error.js';
21
21
  import {resolve_node_specifier} from './resolve_node_specifier.js';
22
22
  import type {Package_Json} from './package_json.js';
23
- // TODO see below
24
- // import {resolve_node_specifier} from './resolve_node_specifier.js';
25
23
 
26
24
  const aliases = Object.entries(default_sveltekit_config.alias);
27
25
 
28
26
  export interface Source_File {
29
27
  id: Path_Id;
30
- // TODO add // mtime: number;
31
28
  /**
32
29
  * `null` contents means it doesn't exist.
33
30
  * We create the file in memory to track its dependents regardless of its existence on disk.
@@ -47,7 +44,7 @@ export type Cleanup_Watch = () => Promise<void>;
47
44
 
48
45
  export type On_Filer_Change = (change: Watcher_Change, source_file: Source_File) => void;
49
46
 
50
- export interface Options {
47
+ export interface Filer_Options {
51
48
  watch_dir?: typeof watch_dir;
52
49
  watch_dir_options?: Partial<Omit_Strict<Watch_Dir_Options, 'on_change'>>;
53
50
  package_json_cache?: Record<string, Package_Json>;
@@ -63,7 +60,7 @@ export class Filer {
63
60
 
64
61
  #package_json_cache: Record<string, Package_Json>;
65
62
 
66
- constructor(options: Options = EMPTY_OBJECT) {
63
+ constructor(options: Filer_Options = EMPTY_OBJECT) {
67
64
  this.#watch_dir = options.watch_dir ?? watch_dir;
68
65
  this.#watch_dir_options = options.watch_dir_options ?? EMPTY_OBJECT;
69
66
  this.root_dir = resolve(options.watch_dir_options?.dir ?? paths.source);
@@ -16,7 +16,7 @@ export interface Task_Args extends Args {
16
16
  watch?: boolean;
17
17
  }
18
18
 
19
- export interface Options {
19
+ export interface Gro_Plugin_Gen_Options {
20
20
  input_paths?: string[];
21
21
  root_dirs?: string[];
22
22
  flush_debounce_delay?: number;
@@ -26,7 +26,7 @@ export const gro_plugin_gen = ({
26
26
  input_paths = [paths.source],
27
27
  root_dirs = [paths.source],
28
28
  flush_debounce_delay = FLUSH_DEBOUNCE_DELAY,
29
- }: Options = EMPTY_OBJECT): Plugin => {
29
+ }: Gro_Plugin_Gen_Options = EMPTY_OBJECT): Plugin => {
30
30
  let flushing_timeout: NodeJS.Timeout | undefined;
31
31
  const queued_files: Set<string> = new Set();
32
32
  const queue_gen = (gen_file_id: string) => {