@ryanatkn/gro 0.151.2 → 0.153.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 (93) hide show
  1. package/dist/changeset.task.js +2 -2
  2. package/dist/constants.d.ts +1 -1
  3. package/dist/constants.d.ts.map +1 -1
  4. package/dist/constants.js +1 -1
  5. package/dist/esbuild_helpers.d.ts +2 -2
  6. package/dist/esbuild_helpers.d.ts.map +1 -1
  7. package/dist/esbuild_plugin_external_worker.d.ts +3 -3
  8. package/dist/esbuild_plugin_external_worker.d.ts.map +1 -1
  9. package/dist/esbuild_plugin_svelte.d.ts +2 -2
  10. package/dist/esbuild_plugin_svelte.d.ts.map +1 -1
  11. package/dist/esbuild_plugin_svelte.js +2 -2
  12. package/dist/esbuild_plugin_sveltekit_shim_app.d.ts +3 -3
  13. package/dist/esbuild_plugin_sveltekit_shim_app.d.ts.map +1 -1
  14. package/dist/filer.d.ts +1 -0
  15. package/dist/filer.d.ts.map +1 -1
  16. package/dist/filer.js +10 -9
  17. package/dist/format_directory.js +2 -2
  18. package/dist/gen.d.ts +2 -2
  19. package/dist/gen.d.ts.map +1 -1
  20. package/dist/gro.config.default.d.ts +4 -4
  21. package/dist/gro.config.default.d.ts.map +1 -1
  22. package/dist/gro.config.default.js +22 -12
  23. package/dist/gro_config.d.ts +4 -1
  24. package/dist/gro_config.d.ts.map +1 -1
  25. package/dist/gro_plugin_server.d.ts +5 -5
  26. package/dist/gro_plugin_server.d.ts.map +1 -1
  27. package/dist/gro_plugin_server.js +9 -6
  28. package/dist/gro_plugin_sveltekit_app.js +2 -2
  29. package/dist/invoke_task.js +1 -1
  30. package/dist/loader.js +2 -2
  31. package/dist/package.d.ts +14 -17
  32. package/dist/package.d.ts.map +1 -1
  33. package/dist/package.js +29 -33
  34. package/dist/package_json.d.ts +0 -1
  35. package/dist/package_json.d.ts.map +1 -1
  36. package/dist/package_json.js +0 -1
  37. package/dist/paths.d.ts.map +1 -1
  38. package/dist/paths.js +3 -3
  39. package/dist/run_gen.js +2 -2
  40. package/dist/run_task.js +2 -2
  41. package/dist/search_fs.d.ts +1 -0
  42. package/dist/search_fs.d.ts.map +1 -1
  43. package/dist/search_fs.js +8 -0
  44. package/dist/{sveltekit_config.d.ts → svelte_config.d.ts} +16 -10
  45. package/dist/svelte_config.d.ts.map +1 -0
  46. package/dist/{sveltekit_config.js → svelte_config.js} +16 -12
  47. package/dist/sveltekit_helpers.d.ts +3 -3
  48. package/dist/sveltekit_helpers.d.ts.map +1 -1
  49. package/dist/sveltekit_helpers.js +8 -8
  50. package/dist/sveltekit_shim_app.d.ts +2 -2
  51. package/dist/sveltekit_shim_app.d.ts.map +1 -1
  52. package/dist/sveltekit_shim_app.js +1 -1
  53. package/dist/sveltekit_shim_app_state.d.ts +5 -0
  54. package/dist/sveltekit_shim_app_state.d.ts.map +1 -0
  55. package/dist/sveltekit_shim_app_state.js +26 -0
  56. package/dist/task.d.ts +2 -2
  57. package/dist/task.d.ts.map +1 -1
  58. package/dist/upgrade.task.d.ts +12 -0
  59. package/dist/upgrade.task.d.ts.map +1 -1
  60. package/dist/upgrade.task.js +29 -1
  61. package/package.json +17 -17
  62. package/src/lib/changeset.task.ts +2 -2
  63. package/src/lib/constants.ts +1 -1
  64. package/src/lib/esbuild_helpers.ts +2 -2
  65. package/src/lib/esbuild_plugin_external_worker.ts +3 -3
  66. package/src/lib/esbuild_plugin_svelte.ts +5 -5
  67. package/src/lib/esbuild_plugin_sveltekit_shim_app.ts +3 -3
  68. package/src/lib/filer.ts +13 -9
  69. package/src/lib/format_directory.ts +2 -2
  70. package/src/lib/gen.ts +2 -2
  71. package/src/lib/gro.config.default.ts +25 -12
  72. package/src/lib/gro_config.ts +4 -0
  73. package/src/lib/gro_plugin_server.ts +14 -11
  74. package/src/lib/gro_plugin_sveltekit_app.ts +2 -2
  75. package/src/lib/invoke_task.ts +1 -1
  76. package/src/lib/loader.ts +2 -2
  77. package/src/lib/package.ts +29 -33
  78. package/src/lib/package_json.ts +0 -5
  79. package/src/lib/paths.ts +3 -3
  80. package/src/lib/run_gen.ts +2 -2
  81. package/src/lib/run_task.ts +2 -2
  82. package/src/lib/search_fs.ts +9 -0
  83. package/src/lib/{sveltekit_config.ts → svelte_config.ts} +31 -21
  84. package/src/lib/sveltekit_helpers.ts +10 -8
  85. package/src/lib/sveltekit_shim_app.ts +4 -4
  86. package/src/lib/sveltekit_shim_app_state.ts +35 -0
  87. package/src/lib/task.ts +3 -3
  88. package/src/lib/upgrade.task.ts +43 -1
  89. package/dist/sveltekit_config.d.ts.map +0 -1
  90. package/dist/sveltekit_shim_app_stores.d.ts +0 -6
  91. package/dist/sveltekit_shim_app_stores.d.ts.map +0 -1
  92. package/dist/sveltekit_shim_app_stores.js +0 -17
  93. package/src/lib/sveltekit_shim_app_stores.ts +0 -28
@@ -7,6 +7,10 @@ export declare const Args: z.ZodObject<{
7
7
  force: z.ZodDefault<z.ZodBoolean>;
8
8
  pull: z.ZodDefault<z.ZodBoolean>;
9
9
  'no-pull': z.ZodDefault<z.ZodBoolean>;
10
+ delete_node_modules: z.ZodDefault<z.ZodBoolean>;
11
+ node_modules_path: z.ZodDefault<z.ZodString>;
12
+ delete_lockfile: z.ZodDefault<z.ZodBoolean>;
13
+ lockfile_path: z.ZodDefault<z.ZodString>;
10
14
  dry: z.ZodDefault<z.ZodBoolean>;
11
15
  }, "strict", z.ZodTypeAny, {
12
16
  _: string[];
@@ -16,6 +20,10 @@ export declare const Args: z.ZodObject<{
16
20
  force: boolean;
17
21
  'no-pull': boolean;
18
22
  only: string[];
23
+ delete_node_modules: boolean;
24
+ node_modules_path: string;
25
+ delete_lockfile: boolean;
26
+ lockfile_path: string;
19
27
  }, {
20
28
  _?: string[] | undefined;
21
29
  origin?: string | undefined;
@@ -24,6 +32,10 @@ export declare const Args: z.ZodObject<{
24
32
  force?: boolean | undefined;
25
33
  'no-pull'?: boolean | undefined;
26
34
  only?: string | string[] | undefined;
35
+ delete_node_modules?: boolean | undefined;
36
+ node_modules_path?: string | undefined;
37
+ delete_lockfile?: boolean | undefined;
38
+ lockfile_path?: string | undefined;
27
39
  }>;
28
40
  export type Args = z.infer<typeof Args>;
29
41
  export declare const task: Task<Args>;
@@ -1 +1 @@
1
- {"version":3,"file":"upgrade.task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/upgrade.task.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAa,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AAMhD,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;EAeP,CAAC;AACX,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAExC,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,IAAI,CA+C3B,CAAC"}
1
+ {"version":3,"file":"upgrade.task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/upgrade.task.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAGtB,OAAO,EAAa,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AAOhD,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2BP,CAAC;AACX,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAExC,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,IAAI,CA2E3B,CAAC"}
@@ -1,10 +1,12 @@
1
1
  import { spawn } from '@ryanatkn/belt/process.js';
2
2
  import { z } from 'zod';
3
+ import { rmSync } from 'node:fs';
3
4
  import { Task_Error } from './task.js';
4
5
  import { extract_deps, load_package_json } from './package_json.js';
5
6
  import { Git_Origin, git_pull } from './git.js';
6
7
  import { spawn_cli } from './cli.js';
7
8
  import { serialize_args, to_forwarded_args } from './args.js';
9
+ import { NODE_MODULES_DIRNAME } from './constants.js';
8
10
  export const Args = z
9
11
  .object({
10
12
  _: z.array(z.string(), { description: 'names of deps to exclude from the upgrade' }).default([]),
@@ -18,6 +20,18 @@ export const Args = z
18
20
  force: z.boolean({ description: 'if true, print out the planned upgrades' }).default(false),
19
21
  pull: z.boolean({ description: 'dual of no-pull' }).default(true),
20
22
  'no-pull': z.boolean({ description: 'opt out of git pull' }).default(false),
23
+ delete_node_modules: z
24
+ .boolean({ description: 'if true, deletes node_modules before upgrading' })
25
+ .default(false),
26
+ node_modules_path: z // TODO maybe configured globally instead
27
+ .string({ description: 'path to modules directory to delete' })
28
+ .default(NODE_MODULES_DIRNAME),
29
+ delete_lockfile: z
30
+ .boolean({ description: 'if true, deletes the lockfile before upgrading' })
31
+ .default(false),
32
+ lockfile_path: z
33
+ .string({ description: 'path to the lockfile to delete' })
34
+ .default('package-lock.json'),
21
35
  dry: z.boolean({ description: 'if true, print out the planned upgrades' }).default(false),
22
36
  })
23
37
  .strict();
@@ -25,7 +39,7 @@ export const task = {
25
39
  summary: 'upgrade deps',
26
40
  Args,
27
41
  run: async ({ args, log, config }) => {
28
- const { _, only, origin, force, pull, dry } = args;
42
+ const { _, only, origin, force, pull, delete_node_modules, node_modules_path, delete_lockfile, lockfile_path, dry, } = args;
29
43
  if (_.length && only.length) {
30
44
  throw new Task_Error('Cannot call `gro upgrade` with both rest args and --only.');
31
45
  }
@@ -33,6 +47,14 @@ export const task = {
33
47
  if (pull) {
34
48
  await git_pull(origin);
35
49
  }
50
+ if (delete_node_modules) {
51
+ log.info(`deleting node_modules at `, node_modules_path);
52
+ rmSync(node_modules_path, { recursive: true, force: true });
53
+ }
54
+ if (delete_lockfile) {
55
+ log.info(`deleting lockfile at`, lockfile_path);
56
+ rmSync(lockfile_path, { force: true });
57
+ }
36
58
  const package_json = load_package_json();
37
59
  const all_deps = extract_deps(package_json);
38
60
  const deps = only.length
@@ -53,6 +75,12 @@ export const task = {
53
75
  }
54
76
  install_args.push(...serialize_args(to_forwarded_args(config.pm_cli)));
55
77
  await spawn(config.pm_cli, install_args);
78
+ // If we deleted the lockfile or node modules, `npm install` again
79
+ // to fix a recurring npm bug getting the lockfile to its final state.
80
+ if (!dry && (delete_node_modules || delete_lockfile)) {
81
+ log.info(`installing again to fix npm lockfile bugs`);
82
+ await spawn(config.pm_cli, ['install']);
83
+ }
56
84
  // Sync in a new process to pick up any changes after installing, avoiding some errors.
57
85
  await spawn_cli('gro', ['sync', '--no-install']); // don't install because we do above
58
86
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ryanatkn/gro",
3
- "version": "0.151.2",
3
+ "version": "0.153.0",
4
4
  "description": "task runner and toolkit extending SvelteKit",
5
5
  "motto": "generate, run, optimize",
6
6
  "glyph": "🌰",
@@ -54,12 +54,12 @@
54
54
  "dotenv": "^16.5.0",
55
55
  "esm-env": "^1.2.2",
56
56
  "mri": "^1.2.0",
57
- "oxc-parser": "^0.63.0",
57
+ "oxc-parser": "^0.67.0",
58
58
  "prettier": "^3.5.3",
59
59
  "prettier-plugin-svelte": "^3.3.3",
60
60
  "ts-morph": "^25.0.1",
61
61
  "tslib": "^2.8.1",
62
- "zod": "^3.24.2"
62
+ "zod": "^3.24.3"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "esbuild": "^0.25",
@@ -69,20 +69,20 @@
69
69
  "@changesets/changelog-git": "^0.2.1",
70
70
  "@changesets/types": "^6.1.0",
71
71
  "@ryanatkn/eslint-config": "^0.8.0",
72
- "@ryanatkn/fuz": "^0.139.0",
72
+ "@ryanatkn/fuz": "^0.139.2",
73
73
  "@ryanatkn/moss": "^0.26.0",
74
74
  "@sveltejs/adapter-static": "^3.0.8",
75
- "@sveltejs/kit": "^2.20.7",
75
+ "@sveltejs/kit": "^2.20.8",
76
76
  "@sveltejs/package": "^2.3.11",
77
77
  "@sveltejs/vite-plugin-svelte": "^5.0.3",
78
- "@types/node": "^22.14.1",
79
- "esbuild": "^0.25.2",
80
- "eslint": "^9.24.0",
78
+ "@types/node": "^22.15.3",
79
+ "esbuild": "^0.25.3",
80
+ "eslint": "^9.25.1",
81
81
  "eslint-plugin-svelte": "^3.5.1",
82
- "svelte": "^5.27.0",
82
+ "svelte": "^5.28.2",
83
83
  "svelte-check": "^4.1.6",
84
84
  "typescript": "^5.8.3",
85
- "typescript-eslint": "^8.30.1",
85
+ "typescript-eslint": "^8.31.1",
86
86
  "uvu": "^0.5.6"
87
87
  },
88
88
  "optionalDependencies": {
@@ -384,14 +384,14 @@
384
384
  "types": "./dist/src_json.d.ts",
385
385
  "default": "./dist/src_json.js"
386
386
  },
387
+ "./svelte_config.js": {
388
+ "types": "./dist/svelte_config.d.ts",
389
+ "default": "./dist/svelte_config.js"
390
+ },
387
391
  "./svelte_helpers.js": {
388
392
  "types": "./dist/svelte_helpers.d.ts",
389
393
  "default": "./dist/svelte_helpers.js"
390
394
  },
391
- "./sveltekit_config.js": {
392
- "types": "./dist/sveltekit_config.d.ts",
393
- "default": "./dist/sveltekit_config.js"
394
- },
395
395
  "./sveltekit_helpers.js": {
396
396
  "types": "./dist/sveltekit_helpers.d.ts",
397
397
  "default": "./dist/sveltekit_helpers.js"
@@ -412,9 +412,9 @@
412
412
  "types": "./dist/sveltekit_shim_app_paths.d.ts",
413
413
  "default": "./dist/sveltekit_shim_app_paths.js"
414
414
  },
415
- "./sveltekit_shim_app_stores.js": {
416
- "types": "./dist/sveltekit_shim_app_stores.d.ts",
417
- "default": "./dist/sveltekit_shim_app_stores.js"
415
+ "./sveltekit_shim_app_state.js": {
416
+ "types": "./dist/sveltekit_shim_app_state.d.ts",
417
+ "default": "./dist/sveltekit_shim_app_state.js"
418
418
  },
419
419
  "./sveltekit_shim_app.js": {
420
420
  "types": "./dist/sveltekit_shim_app.d.ts",
@@ -75,7 +75,7 @@ export const task: Task<Args> = {
75
75
  changeset_cli,
76
76
  },
77
77
  log,
78
- sveltekit_config,
78
+ svelte_config,
79
79
  config,
80
80
  } = ctx;
81
81
 
@@ -93,7 +93,7 @@ export const task: Task<Args> = {
93
93
 
94
94
  const package_json = load_package_json();
95
95
 
96
- const has_sveltekit_library_result = has_sveltekit_library(package_json, sveltekit_config);
96
+ const has_sveltekit_library_result = has_sveltekit_library(package_json, svelte_config);
97
97
  if (!has_sveltekit_library_result.ok) {
98
98
  throw new Task_Error(
99
99
  'Failed to find SvelteKit library: ' + has_sveltekit_library_result.message,
@@ -17,7 +17,7 @@ export const GRO_DIR = GRO_DIRNAME + '/';
17
17
  export const GRO_DEV_DIR = GRO_DEV_DIRNAME + '/';
18
18
  export const GRO_CONFIG_PATH = 'gro.config.ts';
19
19
  export const README_FILENAME = 'README.md';
20
- export const SVELTEKIT_CONFIG_FILENAME = 'svelte.config.js';
20
+ export const SVELTE_CONFIG_FILENAME = 'svelte.config.js';
21
21
  export const VITE_CONFIG_FILENAME = 'vite.config.ts';
22
22
  export const NODE_MODULES_DIRNAME = 'node_modules';
23
23
  export const LOCKFILE_FILENAME = 'package-lock.json';
@@ -2,7 +2,7 @@ import {styleText as st} from 'node:util';
2
2
  import type {Logger} from '@ryanatkn/belt/log.js';
3
3
  import type * as esbuild from 'esbuild';
4
4
 
5
- import type {Parsed_Sveltekit_Config} from './sveltekit_config.js';
5
+ import type {Parsed_Svelte_Config} from './svelte_config.js';
6
6
 
7
7
  export const print_build_result = (log: Logger, build_result: esbuild.BuildResult): void => {
8
8
  for (const error of build_result.errors) {
@@ -28,7 +28,7 @@ const import_meta_env = 'import.' + 'meta.env.'; // eslint-disable-line no-usele
28
28
  */
29
29
  export const to_define_import_meta_env = (
30
30
  dev: boolean,
31
- base_url: Parsed_Sveltekit_Config['base_url'],
31
+ base_url: Parsed_Svelte_Config['base_url'],
32
32
  ssr = true,
33
33
  mode = dev ? 'development' : 'production',
34
34
  ): Record<string, string> => ({
@@ -10,7 +10,7 @@ import {esbuild_plugin_sveltekit_shim_env} from './esbuild_plugin_sveltekit_shim
10
10
  import {esbuild_plugin_sveltekit_shim_app} from './esbuild_plugin_sveltekit_shim_app.js';
11
11
  import {esbuild_plugin_sveltekit_local_imports} from './esbuild_plugin_sveltekit_local_imports.js';
12
12
  import {esbuild_plugin_svelte} from './esbuild_plugin_svelte.js';
13
- import type {Parsed_Sveltekit_Config} from './sveltekit_config.js';
13
+ import type {Parsed_Svelte_Config} from './svelte_config.js';
14
14
  import type {Path_Id} from './path.js';
15
15
 
16
16
  export interface Esbuild_Plugin_External_Worker_Options {
@@ -21,8 +21,8 @@ export interface Esbuild_Plugin_External_Worker_Options {
21
21
  svelte_compile_module_options?: ModuleCompileOptions;
22
22
  svelte_preprocessors?: PreprocessorGroup | Array<PreprocessorGroup>;
23
23
  alias?: Record<string, string>;
24
- base_url?: Parsed_Sveltekit_Config['base_url'];
25
- assets_url?: Parsed_Sveltekit_Config['assets_url'];
24
+ base_url?: Parsed_Svelte_Config['base_url'];
25
+ assets_url?: Parsed_Svelte_Config['assets_url'];
26
26
  public_prefix?: string;
27
27
  private_prefix?: string;
28
28
  env_dir?: string;
@@ -13,15 +13,15 @@ import {relative} from 'node:path';
13
13
  import {SVELTE_MATCHER, SVELTE_RUNES_MATCHER} from './svelte_helpers.js';
14
14
  import {to_define_import_meta_env, default_ts_transform_options} from './esbuild_helpers.js';
15
15
  import {
16
- default_sveltekit_config,
16
+ default_svelte_config,
17
17
  to_default_compile_module_options,
18
- type Parsed_Sveltekit_Config,
19
- } from './sveltekit_config.js';
18
+ type Parsed_Svelte_Config,
19
+ } from './svelte_config.js';
20
20
  import {TS_MATCHER} from './constants.js';
21
21
 
22
22
  export interface Esbuild_Plugin_Svelte_Options {
23
23
  dev: boolean;
24
- base_url: Parsed_Sveltekit_Config['base_url'];
24
+ base_url: Parsed_Svelte_Config['base_url'];
25
25
  dir?: string;
26
26
  svelte_compile_options?: CompileOptions;
27
27
  svelte_compile_module_options?: ModuleCompileOptions;
@@ -35,7 +35,7 @@ export const esbuild_plugin_svelte = (options: Esbuild_Plugin_Svelte_Options): e
35
35
  dev,
36
36
  base_url,
37
37
  dir = process.cwd(),
38
- svelte_compile_options = default_sveltekit_config.svelte_compile_options,
38
+ svelte_compile_options = default_svelte_config.svelte_compile_options,
39
39
  svelte_compile_module_options = to_default_compile_module_options(svelte_compile_options),
40
40
  svelte_preprocessors,
41
41
  ts_transform_options = default_ts_transform_options,
@@ -5,13 +5,13 @@ import {
5
5
  render_sveltekit_shim_app_paths,
6
6
  sveltekit_shim_app_specifiers,
7
7
  } from './sveltekit_shim_app.js';
8
- import type {Parsed_Sveltekit_Config} from './sveltekit_config.js';
8
+ import type {Parsed_Svelte_Config} from './svelte_config.js';
9
9
  import {EVERYTHING_MATCHER} from './constants.js';
10
10
 
11
11
  export interface Esbuild_Plugin_Sveltekit_Shim_App_Options {
12
12
  dev: boolean;
13
- base_url: Parsed_Sveltekit_Config['base_url'];
14
- assets_url: Parsed_Sveltekit_Config['assets_url'];
13
+ base_url: Parsed_Svelte_Config['base_url'];
14
+ assets_url: Parsed_Svelte_Config['assets_url'];
15
15
  }
16
16
 
17
17
  export const esbuild_plugin_sveltekit_shim_app = ({
package/src/lib/filer.ts CHANGED
@@ -19,14 +19,15 @@ import {
19
19
  import {paths} from './paths.js';
20
20
  import {parse_imports} from './parse_imports.js';
21
21
  import {resolve_specifier} from './resolve_specifier.js';
22
- import {default_sveltekit_config} from './sveltekit_config.js';
22
+ import {default_svelte_config} from './svelte_config.js';
23
23
  import {map_sveltekit_aliases, SVELTEKIT_GLOBAL_SPECIFIER} from './sveltekit_helpers.js';
24
24
  import type {Package_Json} from './package_json.js';
25
25
 
26
- const aliases = Object.entries(default_sveltekit_config.alias);
26
+ const aliases = Object.entries(default_svelte_config.alias);
27
27
 
28
28
  export interface Source_File {
29
29
  id: Path_Id;
30
+ // TODO figure out the best API that makes this lazy
30
31
  /**
31
32
  * `null` contents means it doesn't exist.
32
33
  * We create the file in memory to track its dependents regardless of its existence on disk.
@@ -50,6 +51,7 @@ export interface Filer_Options {
50
51
  watch_dir?: typeof watch_dir;
51
52
  watch_dir_options?: Partial<Omit_Strict<Watch_Dir_Options, 'on_change'>>;
52
53
  package_json_cache?: Record<string, Package_Json>;
54
+ log?: Logger;
53
55
  }
54
56
 
55
57
  export class Filer {
@@ -60,10 +62,13 @@ export class Filer {
60
62
  #watch_dir: typeof watch_dir;
61
63
  #watch_dir_options: Partial<Watch_Dir_Options>;
62
64
 
65
+ #log?: Logger;
66
+
63
67
  constructor(options: Filer_Options = EMPTY_OBJECT) {
64
68
  this.#watch_dir = options.watch_dir ?? watch_dir;
65
69
  this.#watch_dir_options = options.watch_dir_options ?? EMPTY_OBJECT;
66
70
  this.root_dir = resolve(options.watch_dir_options?.dir ?? paths.source);
71
+ this.#log = options.log;
67
72
  }
68
73
 
69
74
  #watching: Watch_Node_Fs | undefined;
@@ -121,20 +126,19 @@ export class Filer {
121
126
  const path = map_sveltekit_aliases(specifier, aliases);
122
127
 
123
128
  let path_id;
129
+ // TODO can we replace `resolve_specifier` with `import.meta.resolve` completely now outside of esbuild plugins?
124
130
  if (path[0] === '.' || path[0] === '/') {
125
131
  const resolved = resolve_specifier(path, dir);
126
132
  path_id = resolved.path_id;
127
133
  } else {
128
134
  if (isBuiltin(path)) continue;
135
+ const file_url = pathToFileURL(file.id);
129
136
  try {
130
- const file_url = pathToFileURL(file.id);
131
137
  path_id = fileURLToPath(import.meta.resolve(path, file_url.href));
132
138
  } catch (error) {
133
- // If it's imported from an external module, ignore any import errors.
134
- if (error.code === 'ERR_MODULE_NOT_FOUND' && file.external) {
135
- continue;
136
- }
137
- throw error;
139
+ // if resolving fails for any reason, just log and ignore it
140
+ this.#log?.error('[filer] failed to resolve path', path, file_url.href, error);
141
+ continue;
138
142
  }
139
143
  }
140
144
  dependencies_removed.delete(path_id);
@@ -273,7 +277,7 @@ export const filter_dependents = (
273
277
  const dependent_source_file = get_by_id(dependent_id);
274
278
  if (!dependent_source_file) {
275
279
  log?.warn(
276
- `[filer.filter_dependents]: dependent source file ${dependent_id} not found for ${source_file.id}`,
280
+ `[filer.filter_dependents] dependent source file ${dependent_id} not found for ${source_file.id}`,
277
281
  );
278
282
  continue;
279
283
  }
@@ -5,7 +5,7 @@ import {paths} from './paths.js';
5
5
  import {
6
6
  GITHUB_DIRNAME,
7
7
  README_FILENAME,
8
- SVELTEKIT_CONFIG_FILENAME,
8
+ SVELTE_CONFIG_FILENAME,
9
9
  VITE_CONFIG_FILENAME,
10
10
  TSCONFIG_FILENAME,
11
11
  GRO_CONFIG_PATH,
@@ -19,7 +19,7 @@ const EXTENSIONS_DEFAULT = 'ts,js,json,svelte,html,css,md,yml';
19
19
  const ROOT_PATHS_DEFAULT = `${[
20
20
  README_FILENAME,
21
21
  GRO_CONFIG_PATH,
22
- SVELTEKIT_CONFIG_FILENAME,
22
+ SVELTE_CONFIG_FILENAME,
23
23
  VITE_CONFIG_FILENAME,
24
24
  TSCONFIG_FILENAME,
25
25
  GITHUB_DIRNAME,
package/src/lib/gen.ts CHANGED
@@ -10,7 +10,7 @@ import {existsSync} from 'node:fs';
10
10
  import {print_path} from './paths.js';
11
11
  import type {Path_Id} from './path.js';
12
12
  import type {Gro_Config} from './gro_config.js';
13
- import type {Parsed_Sveltekit_Config} from './sveltekit_config.js';
13
+ import type {Parsed_Svelte_Config} from './svelte_config.js';
14
14
  import {load_modules, type Load_Modules_Failure, type Module_Meta} from './modules.js';
15
15
  import {
16
16
  Input_Path,
@@ -40,7 +40,7 @@ export interface Gen_File {
40
40
  export type Gen = (ctx: Gen_Context) => Raw_Gen_Result | Promise<Raw_Gen_Result>;
41
41
  export interface Gen_Context {
42
42
  config: Gro_Config;
43
- sveltekit_config: Parsed_Sveltekit_Config;
43
+ svelte_config: Parsed_Svelte_Config;
44
44
  /**
45
45
  * Same as `import.meta.url` but in path form.
46
46
  */
@@ -1,37 +1,50 @@
1
+ import {resolve} from 'node:path';
2
+
1
3
  import type {Create_Gro_Config} from './gro_config.js';
2
4
  import {gro_plugin_sveltekit_library} from './gro_plugin_sveltekit_library.js';
3
5
  import {has_server, gro_plugin_server} from './gro_plugin_server.js';
4
6
  import {gro_plugin_sveltekit_app} from './gro_plugin_sveltekit_app.js';
5
7
  import {has_sveltekit_app, has_sveltekit_library} from './sveltekit_helpers.js';
6
8
  import {gro_plugin_gen} from './gro_plugin_gen.js';
7
- import {has_dep, is_dep, load_package_json} from './package_json.js';
9
+ import {has_dep, load_package_json} from './package_json.js';
10
+ import {find_first_existing_file} from './search_fs.js';
11
+
12
+ // TODO hacky, maybe extract utils?
8
13
 
9
14
  /**
10
15
  * This is the default config that's passed to `gro.config.ts`
11
16
  * if it exists in the current project, and if not, this is the final config.
12
- * It looks at the project and tries to do the right thing:
17
+ * It looks at the SvelteKit config and filesystem and tries to do the right thing:
13
18
  *
14
- * - if `src/routes`, assumes a SvelteKit frontend
15
- * - if `src/lib`, assumes a Node library
16
- * - if `src/lib/server/server.ts`, assumes a Node server
19
+ * - if `src/routes`, assumes a SvelteKit frontend - respects `KitConfig.kit.files.routes`
20
+ * - if `src/lib`, assumes a Node library - respects `KitConfig.kit.files.lib`
21
+ * - if `src/lib/server/server.ts`, assumes a Node server - needs config
17
22
  */
18
- const config: Create_Gro_Config = async (cfg) => {
23
+ const config: Create_Gro_Config = async (cfg, svelte_config) => {
19
24
  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`?
20
25
 
21
26
  const [has_moss_dep, has_server_result, has_sveltekit_library_result, has_sveltekit_app_result] =
22
27
  await Promise.all([
23
- has_dep('@ryanatkn/moss', package_json) || is_dep('@ryanatkn/moss', package_json),
28
+ has_dep('@ryanatkn/moss', package_json),
24
29
  has_server(),
25
- has_sveltekit_library(package_json),
30
+ has_sveltekit_library(package_json, svelte_config),
26
31
  has_sveltekit_app(),
27
32
  ]);
28
33
 
34
+ const local_moss_plugin_path = find_first_existing_file([
35
+ './src/lib/gro_plugin_moss.ts',
36
+ './src/routes/gro_plugin_moss.ts',
37
+ ]);
38
+
39
+ // put things that generate files before SvelteKit so it can see them
29
40
  cfg.plugins = async () =>
30
41
  [
31
- // put things that generate files before SvelteKit so it can see them
32
- has_moss_dep
33
- ? ((await import('@ryanatkn/moss/gro_plugin_moss.js')) as any).gro_plugin_moss()
34
- : null, // lazy load to avoid errors if it's not installed
42
+ // TODO probably belongs in the gen system
43
+ local_moss_plugin_path
44
+ ? (await import(resolve(local_moss_plugin_path))).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
35
48
  gro_plugin_gen(),
36
49
  has_server_result.ok ? gro_plugin_server() : null,
37
50
  has_sveltekit_library_result.ok ? gro_plugin_sveltekit_library() : null,
@@ -15,6 +15,7 @@ import create_default_config from './gro.config.default.js';
15
15
  import type {Create_Config_Plugins} from './plugin.js';
16
16
  import type {Map_Package_Json} from './package_json.js';
17
17
  import type {Path_Filter, Path_Id} from './path.js';
18
+ import type {Parsed_Svelte_Config} from './svelte_config.js';
18
19
 
19
20
  /**
20
21
  * The config that users can extend via `gro.config.ts`.
@@ -50,6 +51,8 @@ export interface Gro_Config extends Raw_Gro_Config {
50
51
  * The CLI to use that's compatible with `npm install` and `npm link`. Defaults to `'npm'`.
51
52
  */
52
53
  pm_cli: string;
54
+ /** @default SVELTE_CONFIG_FILENAME */
55
+ svelte_config_filename?: string;
53
56
  }
54
57
 
55
58
  /**
@@ -68,6 +71,7 @@ export interface Raw_Gro_Config {
68
71
 
69
72
  export type Create_Gro_Config = (
70
73
  base_config: Gro_Config,
74
+ svelte_config?: Parsed_Svelte_Config,
71
75
  ) => Raw_Gro_Config | Promise<Raw_Gro_Config>;
72
76
 
73
77
  export const create_empty_gro_config = (): Gro_Config => ({
@@ -1,6 +1,6 @@
1
1
  import {spawn_restartable_process, type Restartable_Process} from '@ryanatkn/belt/process.js';
2
2
  import * as esbuild from 'esbuild';
3
- import type {Config as SvelteKitConfig} from '@sveltejs/kit';
3
+ import type {Config as SvelteConfig} from '@sveltejs/kit';
4
4
  import {join, resolve} from 'node:path';
5
5
  import {identity} from '@ryanatkn/belt/function.js';
6
6
  import {strip_before, strip_end} from '@ryanatkn/belt/string.js';
@@ -13,7 +13,7 @@ import {base_path_to_path_id, LIB_DIRNAME, paths} from './paths.js';
13
13
  import type {Path_Id} from './path.js';
14
14
  import {GRO_DEV_DIRNAME, SERVER_DIST_PATH} from './constants.js';
15
15
  import {watch_dir, type Watch_Node_Fs} from './watch_dir.js';
16
- import {init_sveltekit_config, default_sveltekit_config} from './sveltekit_config.js';
16
+ import {parse_svelte_config, default_svelte_config} from './svelte_config.js';
17
17
  import {esbuild_plugin_sveltekit_shim_app} from './esbuild_plugin_sveltekit_shim_app.js';
18
18
  import {esbuild_plugin_sveltekit_shim_env} from './esbuild_plugin_sveltekit_shim_env.js';
19
19
  import {print_build_result, to_define_import_meta_env} from './esbuild_helpers.js';
@@ -49,7 +49,7 @@ export interface Gro_Plugin_Server_Options {
49
49
  */
50
50
  outpaths?: Create_Outpaths;
51
51
  /**
52
- * @default SvelteKit's `.env`, `.env.development`, and `.env.production`
52
+ * @default ```SvelteKit's `.env`, `.env.development`, and `.env.production````
53
53
  */
54
54
  env_files?: Array<string>;
55
55
  /**
@@ -57,9 +57,9 @@ export interface Gro_Plugin_Server_Options {
57
57
  */
58
58
  ambient_env?: Record<string, string>;
59
59
  /**
60
- * @default loaded from `${cwd}/${SVELTEKIT_CONFIG_FILENAME}`
60
+ * @default ```loaded from `${cwd}/${SVELTE_CONFIG_FILENAME}````
61
61
  */
62
- sveltekit_config?: SvelteKitConfig;
62
+ svelte_config?: SvelteConfig;
63
63
  /**
64
64
  * @default 'esnext'
65
65
  */
@@ -115,7 +115,7 @@ export const gro_plugin_server = ({
115
115
  }),
116
116
  env_files,
117
117
  ambient_env,
118
- sveltekit_config,
118
+ svelte_config,
119
119
  target = 'esnext',
120
120
  esbuild_build_options = identity,
121
121
  rebuild_throttle_delay = 1000,
@@ -130,10 +130,13 @@ export const gro_plugin_server = ({
130
130
  return {
131
131
  name: 'gro_plugin_server',
132
132
  setup: async ({dev, watch, timings, log, config}) => {
133
- const parsed_sveltekit_config =
134
- !sveltekit_config && strip_end(dir, '/') === process.cwd()
135
- ? default_sveltekit_config
136
- : await init_sveltekit_config(sveltekit_config ?? dir);
133
+ const parsed_svelte_config =
134
+ !svelte_config && strip_end(dir, '/') === process.cwd()
135
+ ? default_svelte_config
136
+ : await parse_svelte_config({
137
+ dir_or_config: svelte_config ?? dir,
138
+ config_filename: config.svelte_config_filename,
139
+ });
137
140
  const {
138
141
  alias,
139
142
  base_url,
@@ -144,7 +147,7 @@ export const gro_plugin_server = ({
144
147
  svelte_compile_options,
145
148
  svelte_compile_module_options,
146
149
  svelte_preprocessors,
147
- } = parsed_sveltekit_config;
150
+ } = parsed_svelte_config;
148
151
 
149
152
  const {outbase, outdir, outname} = outpaths(dev);
150
153
 
@@ -9,7 +9,7 @@ import {Task_Error} from './task.js';
9
9
  import {find_cli, spawn_cli, spawn_cli_process} from './cli.js';
10
10
  import {type Map_Src_Json, serialize_src_json, create_src_json} from './src_json.js';
11
11
  import {EXPORTS_EXCLUDER_DEFAULT} from './gro_config.js';
12
- import {default_sveltekit_config} from './sveltekit_config.js';
12
+ import {default_svelte_config} from './svelte_config.js';
13
13
  import {SOURCE_DIRNAME} from './constants.js';
14
14
  import {VITE_CLI} from './sveltekit_helpers.js';
15
15
 
@@ -108,7 +108,7 @@ export const gro_plugin_sveltekit_app = ({
108
108
 
109
109
  // copy files to `static` before building, in such a way
110
110
  // that's non-destructive to existing files and dirs and easy to clean up
111
- const {assets_path} = default_sveltekit_config;
111
+ const {assets_path} = default_svelte_config;
112
112
  const cleanups: Array<Cleanup> = [
113
113
  serialized_package_json
114
114
  ? create_temporarily(
@@ -44,7 +44,7 @@ export const invoke_task = async (
44
44
  const log = new System_Logger(print_log_label(task_name || 'gro'));
45
45
  log.info('invoking', task_name ? st('cyan', task_name) : 'gro');
46
46
 
47
- const filer = initial_filer ?? new Filer();
47
+ const filer = initial_filer ?? new Filer({log});
48
48
 
49
49
  const timings = initial_timings ?? new Timings();
50
50
 
package/src/lib/loader.ts CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  SVELTEKIT_SHIM_APP_PATHS_MATCHER,
15
15
  sveltekit_shim_app_specifiers,
16
16
  } from './sveltekit_shim_app.js';
17
- import {default_sveltekit_config} from './sveltekit_config.js';
17
+ import {default_svelte_config} from './svelte_config.js';
18
18
  import {SVELTE_MATCHER, SVELTE_RUNES_MATCHER} from './svelte_helpers.js';
19
19
  import {IS_THIS_GRO, paths} from './paths.js';
20
20
  import {JSON_MATCHER, NODE_MODULES_DIRNAME, TS_MATCHER} from './constants.js';
@@ -66,7 +66,7 @@ const {
66
66
  svelte_compile_options,
67
67
  svelte_compile_module_options,
68
68
  svelte_preprocessors,
69
- } = default_sveltekit_config;
69
+ } = default_svelte_config;
70
70
 
71
71
  const ts_transform_options: esbuild.TransformOptions = {
72
72
  ...default_ts_transform_options,