@ryanatkn/gro 0.152.0 → 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 (79) 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.js +2 -2
  15. package/dist/format_directory.js +2 -2
  16. package/dist/gen.d.ts +2 -2
  17. package/dist/gen.d.ts.map +1 -1
  18. package/dist/gro.config.default.d.ts +4 -4
  19. package/dist/gro.config.default.d.ts.map +1 -1
  20. package/dist/gro.config.default.js +22 -12
  21. package/dist/gro_config.d.ts +4 -1
  22. package/dist/gro_config.d.ts.map +1 -1
  23. package/dist/gro_plugin_server.d.ts +5 -5
  24. package/dist/gro_plugin_server.d.ts.map +1 -1
  25. package/dist/gro_plugin_server.js +9 -6
  26. package/dist/gro_plugin_sveltekit_app.js +2 -2
  27. package/dist/loader.js +2 -2
  28. package/dist/package.d.ts +10 -10
  29. package/dist/package.d.ts.map +1 -1
  30. package/dist/package.js +16 -19
  31. package/dist/package_json.d.ts +0 -1
  32. package/dist/package_json.d.ts.map +1 -1
  33. package/dist/package_json.js +0 -1
  34. package/dist/paths.d.ts.map +1 -1
  35. package/dist/paths.js +3 -3
  36. package/dist/run_gen.js +2 -2
  37. package/dist/run_task.js +2 -2
  38. package/dist/search_fs.d.ts +1 -0
  39. package/dist/search_fs.d.ts.map +1 -1
  40. package/dist/search_fs.js +8 -0
  41. package/dist/{sveltekit_config.d.ts → svelte_config.d.ts} +16 -10
  42. package/dist/svelte_config.d.ts.map +1 -0
  43. package/dist/{sveltekit_config.js → svelte_config.js} +16 -12
  44. package/dist/sveltekit_helpers.d.ts +3 -3
  45. package/dist/sveltekit_helpers.d.ts.map +1 -1
  46. package/dist/sveltekit_helpers.js +8 -8
  47. package/dist/sveltekit_shim_app.d.ts +2 -2
  48. package/dist/sveltekit_shim_app.d.ts.map +1 -1
  49. package/dist/task.d.ts +2 -2
  50. package/dist/task.d.ts.map +1 -1
  51. package/dist/upgrade.task.d.ts.map +1 -1
  52. package/dist/upgrade.task.js +8 -0
  53. package/package.json +6 -6
  54. package/src/lib/changeset.task.ts +2 -2
  55. package/src/lib/constants.ts +1 -1
  56. package/src/lib/esbuild_helpers.ts +2 -2
  57. package/src/lib/esbuild_plugin_external_worker.ts +3 -3
  58. package/src/lib/esbuild_plugin_svelte.ts +5 -5
  59. package/src/lib/esbuild_plugin_sveltekit_shim_app.ts +3 -3
  60. package/src/lib/filer.ts +2 -2
  61. package/src/lib/format_directory.ts +2 -2
  62. package/src/lib/gen.ts +2 -2
  63. package/src/lib/gro.config.default.ts +25 -12
  64. package/src/lib/gro_config.ts +4 -0
  65. package/src/lib/gro_plugin_server.ts +14 -11
  66. package/src/lib/gro_plugin_sveltekit_app.ts +2 -2
  67. package/src/lib/loader.ts +2 -2
  68. package/src/lib/package.ts +16 -19
  69. package/src/lib/package_json.ts +0 -5
  70. package/src/lib/paths.ts +3 -3
  71. package/src/lib/run_gen.ts +2 -2
  72. package/src/lib/run_task.ts +2 -2
  73. package/src/lib/search_fs.ts +9 -0
  74. package/src/lib/{sveltekit_config.ts → svelte_config.ts} +31 -21
  75. package/src/lib/sveltekit_helpers.ts +10 -8
  76. package/src/lib/sveltekit_shim_app.ts +3 -3
  77. package/src/lib/task.ts +3 -3
  78. package/src/lib/upgrade.task.ts +9 -0
  79. package/dist/sveltekit_config.d.ts.map +0 -1
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(
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,
@@ -5,7 +5,7 @@ import type {Src_Json} from './src_json.js';
5
5
 
6
6
  export const package_json = {
7
7
  name: '@ryanatkn/gro',
8
- version: '0.152.0',
8
+ version: '0.153.0',
9
9
  description: 'task runner and toolkit extending SvelteKit',
10
10
  motto: 'generate, run, optimize',
11
11
  glyph: '🌰',
@@ -61,7 +61,7 @@ export const package_json = {
61
61
  '@changesets/changelog-git': '^0.2.1',
62
62
  '@changesets/types': '^6.1.0',
63
63
  '@ryanatkn/eslint-config': '^0.8.0',
64
- '@ryanatkn/fuz': '^0.139.1',
64
+ '@ryanatkn/fuz': '^0.139.2',
65
65
  '@ryanatkn/moss': '^0.26.0',
66
66
  '@sveltejs/adapter-static': '^3.0.8',
67
67
  '@sveltejs/kit': '^2.20.8',
@@ -211,14 +211,11 @@ export const package_json = {
211
211
  './run.task.js': {types: './dist/run.task.d.ts', default: './dist/run.task.js'},
212
212
  './search_fs.js': {types: './dist/search_fs.d.ts', default: './dist/search_fs.js'},
213
213
  './src_json.js': {types: './dist/src_json.d.ts', default: './dist/src_json.js'},
214
+ './svelte_config.js': {types: './dist/svelte_config.d.ts', default: './dist/svelte_config.js'},
214
215
  './svelte_helpers.js': {
215
216
  types: './dist/svelte_helpers.d.ts',
216
217
  default: './dist/svelte_helpers.js',
217
218
  },
218
- './sveltekit_config.js': {
219
- types: './dist/sveltekit_config.d.ts',
220
- default: './dist/sveltekit_config.js',
221
- },
222
219
  './sveltekit_helpers.js': {
223
220
  types: './dist/sveltekit_helpers.d.ts',
224
221
  default: './dist/sveltekit_helpers.js',
@@ -266,7 +263,7 @@ export const package_json = {
266
263
 
267
264
  export const src_json = {
268
265
  name: '@ryanatkn/gro',
269
- version: '0.152.0',
266
+ version: '0.153.0',
270
267
  modules: {
271
268
  '.': {
272
269
  path: 'index.ts',
@@ -381,7 +378,7 @@ export const src_json = {
381
378
  {name: 'GRO_DEV_DIR', kind: 'variable'},
382
379
  {name: 'GRO_CONFIG_PATH', kind: 'variable'},
383
380
  {name: 'README_FILENAME', kind: 'variable'},
384
- {name: 'SVELTEKIT_CONFIG_FILENAME', kind: 'variable'},
381
+ {name: 'SVELTE_CONFIG_FILENAME', kind: 'variable'},
385
382
  {name: 'VITE_CONFIG_FILENAME', kind: 'variable'},
386
383
  {name: 'NODE_MODULES_DIRNAME', kind: 'variable'},
387
384
  {name: 'LOCKFILE_FILENAME', kind: 'variable'},
@@ -717,7 +714,6 @@ export const src_json = {
717
714
  {name: 'update_package_json', kind: 'function'},
718
715
  {name: 'to_package_exports', kind: 'function'},
719
716
  {name: 'parse_repo_url', kind: 'function'},
720
- {name: 'is_dep', kind: 'function'},
721
717
  {name: 'has_dep', kind: 'function'},
722
718
  {name: 'Package_Json_Dep', kind: 'type'},
723
719
  {name: 'extract_deps', kind: 'function'},
@@ -853,6 +849,7 @@ export const src_json = {
853
849
  declarations: [
854
850
  {name: 'Search_Fs_Options', kind: 'type'},
855
851
  {name: 'search_fs', kind: 'function'},
852
+ {name: 'find_first_existing_file', kind: 'function'},
856
853
  ],
857
854
  },
858
855
  './src_json.js': {
@@ -868,6 +865,16 @@ export const src_json = {
868
865
  {name: 'to_src_modules', kind: 'function'},
869
866
  ],
870
867
  },
868
+ './svelte_config.js': {
869
+ path: 'svelte_config.ts',
870
+ declarations: [
871
+ {name: 'load_svelte_config', kind: 'function'},
872
+ {name: 'Parsed_Svelte_Config', kind: 'type'},
873
+ {name: 'parse_svelte_config', kind: 'function'},
874
+ {name: 'to_default_compile_module_options', kind: 'function'},
875
+ {name: 'default_svelte_config', kind: 'variable'},
876
+ ],
877
+ },
871
878
  './svelte_helpers.js': {
872
879
  path: 'svelte_helpers.ts',
873
880
  declarations: [
@@ -875,16 +882,6 @@ export const src_json = {
875
882
  {name: 'SVELTE_RUNES_MATCHER', kind: 'variable'},
876
883
  ],
877
884
  },
878
- './sveltekit_config.js': {
879
- path: 'sveltekit_config.ts',
880
- declarations: [
881
- {name: 'load_sveltekit_config', kind: 'function'},
882
- {name: 'Parsed_Sveltekit_Config', kind: 'type'},
883
- {name: 'init_sveltekit_config', kind: 'function'},
884
- {name: 'to_default_compile_module_options', kind: 'function'},
885
- {name: 'default_sveltekit_config', kind: 'variable'},
886
- ],
887
- },
888
885
  './sveltekit_helpers.js': {
889
886
  path: 'sveltekit_helpers.ts',
890
887
  declarations: [
@@ -347,11 +347,6 @@ const parse_or_throw_formatted_error = <T extends z.ZodTypeAny>(
347
347
  return parsed.data;
348
348
  };
349
349
 
350
- export const is_dep = (
351
- dep_name: string,
352
- package_json: Package_Json = load_package_json(),
353
- ): boolean => package_json.name === dep_name;
354
-
355
350
  export const has_dep = (
356
351
  dep_name: string,
357
352
  package_json: Package_Json = load_package_json(),
package/src/lib/paths.ts CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  SOURCE_DIR,
11
11
  SVELTEKIT_DIST_DIRNAME,
12
12
  } from './constants.js';
13
- import {default_sveltekit_config} from './sveltekit_config.js';
13
+ import {default_svelte_config} from './svelte_config.js';
14
14
  import type {Path_Id} from './path.js';
15
15
 
16
16
  /*
@@ -20,10 +20,10 @@ It's the same name that Rollup uses.
20
20
 
21
21
  */
22
22
 
23
- export const LIB_DIRNAME = basename(default_sveltekit_config.lib_path);
23
+ export const LIB_DIRNAME = basename(default_svelte_config.lib_path);
24
24
  export const LIB_PATH = SOURCE_DIR + LIB_DIRNAME;
25
25
  export const LIB_DIR = LIB_PATH + '/';
26
- export const ROUTES_DIRNAME = basename(default_sveltekit_config.routes_path);
26
+ export const ROUTES_DIRNAME = basename(default_svelte_config.routes_path);
27
27
 
28
28
  export interface Paths {
29
29
  root: string;
@@ -14,7 +14,7 @@ import {
14
14
  import {print_path, to_root_path} from './paths.js';
15
15
  import type {format_file as base_format_file} from './format_file.js';
16
16
  import type {Gro_Config} from './gro_config.js';
17
- import {default_sveltekit_config} from './sveltekit_config.js';
17
+ import {default_svelte_config} from './svelte_config.js';
18
18
 
19
19
  export const GEN_NO_PROD_MESSAGE = 'gen runs only during development';
20
20
 
@@ -37,7 +37,7 @@ export const run_gen = async (
37
37
  // Perform code generation by calling `gen` on the module.
38
38
  const gen_ctx: Gen_Context = {
39
39
  config,
40
- sveltekit_config: default_sveltekit_config,
40
+ svelte_config: default_svelte_config,
41
41
  origin_id: id,
42
42
  origin_path: to_root_path(id),
43
43
  log,
@@ -8,7 +8,7 @@ import type {invoke_task as base_invoke_task} from './invoke_task.js';
8
8
  import {log_task_help} from './task_logging.js';
9
9
  import type {Gro_Config} from './gro_config.js';
10
10
  import {Task_Error, type Task_Module_Meta} from './task.js';
11
- import {default_sveltekit_config} from './sveltekit_config.js';
11
+ import {default_svelte_config} from './svelte_config.js';
12
12
  import type {Filer} from './filer.js';
13
13
 
14
14
  export type Run_Task_Result =
@@ -55,7 +55,7 @@ export const run_task = async (
55
55
  output = await task.run({
56
56
  args,
57
57
  config,
58
- sveltekit_config: default_sveltekit_config,
58
+ svelte_config: default_svelte_config,
59
59
  filer,
60
60
  log,
61
61
  timings,
@@ -90,3 +90,12 @@ const crawl = (
90
90
  }
91
91
  return paths;
92
92
  };
93
+
94
+ export const find_first_existing_file = (paths: Array<string>): string | null => {
95
+ for (const path of paths) {
96
+ if (existsSync(path)) {
97
+ return path;
98
+ }
99
+ }
100
+ return null;
101
+ };
@@ -1,8 +1,9 @@
1
- import type {Config as SveltekitConfig} from '@sveltejs/kit';
1
+ import type {Config as SvelteConfig} from '@sveltejs/kit';
2
2
  import type {CompileOptions, ModuleCompileOptions, PreprocessorGroup} from 'svelte/compiler';
3
3
  import {join} from 'node:path';
4
+ import {EMPTY_OBJECT} from '@ryanatkn/belt/object.js';
4
5
 
5
- import {SVELTEKIT_CONFIG_FILENAME} from './constants.js';
6
+ import {SVELTE_CONFIG_FILENAME} from './constants.js';
6
7
 
7
8
  /*
8
9
 
@@ -14,11 +15,12 @@ This module is intended to have minimal dependencies to avoid over-imports in th
14
15
  * Loads a SvelteKit config at `dir`.
15
16
  * @returns `null` if no config is found
16
17
  */
17
- export const load_sveltekit_config = async (
18
- dir: string = process.cwd(),
19
- ): Promise<SveltekitConfig | null> => {
18
+ export const load_svelte_config = async ({
19
+ dir = process.cwd(),
20
+ config_filename = SVELTE_CONFIG_FILENAME,
21
+ }: {dir?: string; config_filename?: string} = EMPTY_OBJECT): Promise<SvelteConfig | null> => {
20
22
  try {
21
- return (await import(join(dir, SVELTEKIT_CONFIG_FILENAME))).default;
23
+ return (await import(join(dir, config_filename))).default;
22
24
  } catch (_err) {
23
25
  return null;
24
26
  }
@@ -28,13 +30,13 @@ export const load_sveltekit_config = async (
28
30
  * A subset of SvelteKit's config in a form that Gro uses
29
31
  * because SvelteKit doesn't expose its config resolver.
30
32
  * Flattens things out to keep them simple and easy to pass around,
31
- * and doesn't deal with most properties.
33
+ * and doesn't deal with most properties, but includes the full `svelte_config`.
32
34
  * The `base` and `assets` in particular are renamed for clarity with Gro's internal systems,
33
35
  * so these properties become first-class vocabulary inside Gro.
34
36
  */
35
- export interface Parsed_Sveltekit_Config {
37
+ export interface Parsed_Svelte_Config {
36
38
  // TODO probably fill these out with defaults
37
- sveltekit_config: SveltekitConfig | null;
39
+ svelte_config: SvelteConfig | null;
38
40
  alias: Record<string, string>;
39
41
  base_url: '' | `/${string}` | undefined;
40
42
  assets_url: '' | `http://${string}` | `https://${string}` | undefined;
@@ -64,15 +66,22 @@ export interface Parsed_Sveltekit_Config {
64
66
  // TODO currently incomplete and hack - maybe rethink
65
67
  /**
66
68
  * Returns Gro-relevant properties of a SvelteKit config
67
- * as a convenience wrapper around `load_sveltekit_config`.
69
+ * as a convenience wrapper around `load_svelte_config`.
68
70
  * Needed because SvelteKit doesn't expose its config resolver.
69
71
  */
70
- export const init_sveltekit_config = async (
71
- dir_or_config: string | SveltekitConfig = process.cwd(),
72
- ): Promise<Parsed_Sveltekit_Config> => {
73
- const sveltekit_config =
74
- typeof dir_or_config === 'string' ? await load_sveltekit_config(dir_or_config) : dir_or_config;
75
- const kit = sveltekit_config?.kit;
72
+ export const parse_svelte_config = async ({
73
+ dir_or_config = process.cwd(), // TODO maybe not the best API, maybe a type union? `({svelte_config} | {dir}) & {config_filename}`
74
+ config_filename = SVELTE_CONFIG_FILENAME,
75
+ }: {
76
+ dir_or_config?: string | SvelteConfig;
77
+ config_filename?: string;
78
+ } = EMPTY_OBJECT): Promise<Parsed_Svelte_Config> => {
79
+ const svelte_config =
80
+ typeof dir_or_config === 'string'
81
+ ? await load_svelte_config({dir: dir_or_config, config_filename})
82
+ : dir_or_config;
83
+
84
+ const kit = svelte_config?.kit;
76
85
 
77
86
  const alias = {$lib: 'src/lib', ...kit?.alias};
78
87
 
@@ -88,17 +97,17 @@ export const init_sveltekit_config = async (
88
97
  const private_prefix = kit?.env?.privatePrefix;
89
98
  const public_prefix = kit?.env?.publicPrefix;
90
99
 
91
- const svelte_compile_options: CompileOptions = sveltekit_config?.compilerOptions ?? {};
100
+ const svelte_compile_options: CompileOptions = svelte_config?.compilerOptions ?? {};
92
101
  // Change the default to `generate: 'server'`,
93
102
  // because SvelteKit handles the client in the normal cases.
94
103
  if (svelte_compile_options.generate === undefined) {
95
104
  svelte_compile_options.generate = 'server';
96
105
  }
97
106
  const svelte_compile_module_options = to_default_compile_module_options(svelte_compile_options); // TODO will kit have these separately?
98
- const svelte_preprocessors = sveltekit_config?.preprocess;
107
+ const svelte_preprocessors = svelte_config?.preprocess;
99
108
 
100
109
  return {
101
- sveltekit_config,
110
+ svelte_config,
102
111
  alias,
103
112
  base_url,
104
113
  assets_url,
@@ -119,9 +128,10 @@ export const to_default_compile_module_options = ({
119
128
  generate,
120
129
  filename,
121
130
  rootDir,
122
- }: CompileOptions): ModuleCompileOptions => ({dev, generate, filename, rootDir});
131
+ warningFilter,
132
+ }: CompileOptions): ModuleCompileOptions => ({dev, generate, filename, rootDir, warningFilter});
123
133
 
124
134
  /**
125
135
  * The parsed SvelteKit config for the cwd, cached globally at the module level.
126
136
  */
127
- export const default_sveltekit_config = await init_sveltekit_config(); // always load it to keep things simple ahead
137
+ export const default_svelte_config = await parse_svelte_config(); // always load it to keep things simple ahead
@@ -4,8 +4,8 @@ import type {Logger} from '@ryanatkn/belt/log.js';
4
4
  import {join} from 'node:path';
5
5
 
6
6
  import {Package_Json, has_dep} from './package_json.js';
7
- import {default_sveltekit_config, type Parsed_Sveltekit_Config} from './sveltekit_config.js';
8
- import {SVELTEKIT_CONFIG_FILENAME, SVELTEKIT_DEV_DIRNAME, PM_CLI_DEFAULT} from './constants.js';
7
+ import {default_svelte_config, type Parsed_Svelte_Config} from './svelte_config.js';
8
+ import {SVELTE_CONFIG_FILENAME, SVELTEKIT_DEV_DIRNAME, PM_CLI_DEFAULT} from './constants.js';
9
9
  import {find_cli, spawn_cli, to_cli_name, type Cli} from './cli.js';
10
10
  import {Task_Error} from './task.js';
11
11
  import {serialize_args, to_forwarded_args} from './args.js';
@@ -22,9 +22,11 @@ export const VITE_CLI = 'vite';
22
22
  export const SVELTEKIT_ENV_MATCHER = /^\$env\/(static|dynamic)\/(public|private)$/;
23
23
  export const SVELTEKIT_GLOBAL_SPECIFIER = /^\$(env|app)\//;
24
24
 
25
- export const has_sveltekit_app = (): Result<object, {message: string}> => {
26
- if (!existsSync(SVELTEKIT_CONFIG_FILENAME)) {
27
- return {ok: false, message: `no SvelteKit config found at ${SVELTEKIT_CONFIG_FILENAME}`};
25
+ export const has_sveltekit_app = (
26
+ svelte_config_path: string = SVELTE_CONFIG_FILENAME,
27
+ ): Result<object, {message: string}> => {
28
+ if (!existsSync(svelte_config_path)) {
29
+ return {ok: false, message: `no SvelteKit config found at ${SVELTE_CONFIG_FILENAME}`};
28
30
  }
29
31
  // TODO check for routes?
30
32
  return {ok: true};
@@ -32,7 +34,7 @@ export const has_sveltekit_app = (): Result<object, {message: string}> => {
32
34
 
33
35
  export const has_sveltekit_library = (
34
36
  package_json: Package_Json,
35
- sveltekit_config: Parsed_Sveltekit_Config = default_sveltekit_config,
37
+ svelte_config: Parsed_Svelte_Config = default_svelte_config,
36
38
  dep_name = SVELTE_PACKAGE_DEP_NAME,
37
39
  ): Result<object, {message: string}> => {
38
40
  const has_sveltekit_app_result = has_sveltekit_app();
@@ -40,8 +42,8 @@ export const has_sveltekit_library = (
40
42
  return has_sveltekit_app_result;
41
43
  }
42
44
 
43
- if (!existsSync(sveltekit_config.lib_path)) {
44
- return {ok: false, message: `no SvelteKit lib directory found at ${sveltekit_config.lib_path}`};
45
+ if (!existsSync(svelte_config.lib_path)) {
46
+ return {ok: false, message: `no SvelteKit lib directory found at ${svelte_config.lib_path}`};
45
47
  }
46
48
 
47
49
  if (!has_dep(dep_name, package_json)) {
@@ -1,4 +1,4 @@
1
- import type {Parsed_Sveltekit_Config} from './sveltekit_config.js';
1
+ import type {Parsed_Svelte_Config} from './svelte_config.js';
2
2
 
3
3
  export const SVELTEKIT_SHIM_APP_PATHS_MATCHER = /\/util\/sveltekit_shim_app_paths\.js$/;
4
4
  export const SVELTEKIT_SHIM_APP_ENVIRONMENT_MATCHER = /\/util\/sveltekit_shim_app_environment\.js$/;
@@ -16,8 +16,8 @@ export const sveltekit_shim_app_specifiers = new Map([
16
16
  ]);
17
17
 
18
18
  export const render_sveltekit_shim_app_paths = (
19
- base_url: Parsed_Sveltekit_Config['base_url'] = '',
20
- assets_url: Parsed_Sveltekit_Config['assets_url'] = '',
19
+ base_url: Parsed_Svelte_Config['base_url'] = '',
20
+ assets_url: Parsed_Svelte_Config['assets_url'] = '',
21
21
  ): string => `// shim for $app/paths
22
22
  // @see https://github.com/sveltejs/kit/issues/1485
23
23
 
package/src/lib/task.ts CHANGED
@@ -9,7 +9,7 @@ import {isAbsolute, join, relative} from 'node:path';
9
9
  import type {Args} from './args.js';
10
10
  import type {Path_Id} from './path.js';
11
11
  import type {Gro_Config} from './gro_config.js';
12
- import type {Parsed_Sveltekit_Config} from './sveltekit_config.js';
12
+ import type {Parsed_Svelte_Config} from './svelte_config.js';
13
13
  import {
14
14
  resolve_input_files,
15
15
  resolve_input_paths,
@@ -35,10 +35,10 @@ export interface Task<
35
35
  export interface Task_Context<T_Args = object> {
36
36
  args: T_Args;
37
37
  config: Gro_Config;
38
- sveltekit_config: Parsed_Sveltekit_Config;
38
+ svelte_config: Parsed_Svelte_Config;
39
39
  filer: Filer;
40
40
  // TODO should this go here or on `config` for convenience?
41
- // sveltekit_config: Parsed_Sveltekit_Config;
41
+ // svelte_config: Parsed_Svelte_Config;
42
42
  log: Logger;
43
43
  timings: Timings;
44
44
  invoke_task: (task_name: string, args?: Args, config?: Gro_Config) => Promise<void>;
@@ -66,10 +66,12 @@ export const task: Task<Args> = {
66
66
  }
67
67
 
68
68
  if (delete_node_modules) {
69
+ log.info(`deleting node_modules at `, node_modules_path);
69
70
  rmSync(node_modules_path, {recursive: true, force: true});
70
71
  }
71
72
 
72
73
  if (delete_lockfile) {
74
+ log.info(`deleting lockfile at`, lockfile_path);
73
75
  rmSync(lockfile_path, {force: true});
74
76
  }
75
77
 
@@ -102,6 +104,13 @@ export const task: Task<Args> = {
102
104
  install_args.push(...serialize_args(to_forwarded_args(config.pm_cli)));
103
105
  await spawn(config.pm_cli, install_args);
104
106
 
107
+ // If we deleted the lockfile or node modules, `npm install` again
108
+ // to fix a recurring npm bug getting the lockfile to its final state.
109
+ if (!dry && (delete_node_modules || delete_lockfile)) {
110
+ log.info(`installing again to fix npm lockfile bugs`);
111
+ await spawn(config.pm_cli, ['install']);
112
+ }
113
+
105
114
  // Sync in a new process to pick up any changes after installing, avoiding some errors.
106
115
  await spawn_cli('gro', ['sync', '--no-install']); // don't install because we do above
107
116
  },
@@ -1 +0,0 @@
1
- {"version":3,"file":"sveltekit_config.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/sveltekit_config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,IAAI,eAAe,EAAC,MAAM,eAAe,CAAC;AAC7D,OAAO,KAAK,EAAC,cAAc,EAAE,oBAAoB,EAAE,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAW7F;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GACjC,MAAK,MAAsB,KACzB,OAAO,CAAC,eAAe,GAAG,IAAI,CAMhC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,WAAW,uBAAuB;IAEvC,gBAAgB,EAAE,eAAe,GAAG,IAAI,CAAC;IACzC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,QAAQ,EAAE,EAAE,GAAG,IAAI,MAAM,EAAE,GAAG,SAAS,CAAC;IACxC,UAAU,EAAE,EAAE,GAAG,UAAU,MAAM,EAAE,GAAG,WAAW,MAAM,EAAE,GAAG,SAAS,CAAC;IAGtE;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,sBAAsB,EAAE,cAAc,CAAC;IACvC,6BAA6B,EAAE,oBAAoB,CAAC;IACpD,oBAAoB,EAAE,iBAAiB,GAAG,KAAK,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAAC;CAC/E;AAGD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,GACjC,gBAAe,MAAM,GAAG,eAA+B,KACrD,OAAO,CAAC,uBAAuB,CA2CjC,CAAC;AAEF,eAAO,MAAM,iCAAiC,GAAI,uCAK/C,cAAc,KAAG,oBAA4D,CAAC;AAEjF;;GAEG;AACH,eAAO,MAAM,wBAAwB,yBAAgC,CAAC"}