@ryanatkn/gro 0.182.0 → 0.183.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 (38) hide show
  1. package/dist/changeset.task.js +2 -2
  2. package/dist/check.task.js +2 -2
  3. package/dist/format_file.js +2 -2
  4. package/dist/gro.config.default.js +2 -2
  5. package/dist/gro_plugin_sveltekit_app.d.ts +1 -27
  6. package/dist/gro_plugin_sveltekit_app.d.ts.map +1 -1
  7. package/dist/gro_plugin_sveltekit_app.js +7 -156
  8. package/dist/gro_plugin_sveltekit_library.js +3 -3
  9. package/dist/invoke_task.js +2 -2
  10. package/dist/package_json.d.ts +12 -11
  11. package/dist/package_json.d.ts.map +1 -1
  12. package/dist/package_json.js +21 -19
  13. package/dist/publish.task.js +4 -4
  14. package/dist/release.task.js +2 -2
  15. package/dist/source_json.d.ts +0 -1
  16. package/dist/source_json.d.ts.map +1 -1
  17. package/dist/source_json.js +0 -4
  18. package/dist/sveltekit_helpers.js +2 -2
  19. package/dist/sync.task.js +2 -2
  20. package/dist/test.task.js +3 -3
  21. package/dist/upgrade.task.d.ts.map +1 -1
  22. package/dist/upgrade.task.js +3 -3
  23. package/package.json +3 -4
  24. package/src/lib/changeset.task.ts +2 -2
  25. package/src/lib/check.task.ts +2 -2
  26. package/src/lib/format_file.ts +2 -2
  27. package/src/lib/gro.config.default.ts +2 -2
  28. package/src/lib/gro_plugin_sveltekit_app.ts +6 -216
  29. package/src/lib/gro_plugin_sveltekit_library.ts +3 -3
  30. package/src/lib/invoke_task.ts +2 -2
  31. package/src/lib/package_json.ts +25 -19
  32. package/src/lib/publish.task.ts +4 -4
  33. package/src/lib/release.task.ts +2 -2
  34. package/src/lib/source_json.ts +0 -5
  35. package/src/lib/sveltekit_helpers.ts +2 -2
  36. package/src/lib/sync.task.ts +2 -2
  37. package/src/lib/test.task.ts +3 -3
  38. package/src/lib/upgrade.task.ts +7 -3
package/dist/test.task.js CHANGED
@@ -2,7 +2,7 @@ import { z } from 'zod';
2
2
  import { spawn_cli } from './cli.js';
3
3
  import { TaskError } from "./task.js";
4
4
  import { find_cli } from "./cli.js";
5
- import { has_dep, load_package_json } from "./package_json.js";
5
+ import { package_json_has_dependency, package_json_load } from "./package_json.js";
6
6
  import { serialize_args, to_implicit_forwarded_args } from "./args.js";
7
7
  import { VITEST_CLI } from "./constants.js";
8
8
  import { paths } from "./paths.js";
@@ -25,8 +25,8 @@ export const task = {
25
25
  Args,
26
26
  run: async ({ args }) => {
27
27
  const { _: patterns, dir, fail_without_tests, t } = args;
28
- const package_json = await load_package_json();
29
- if (!has_dep(VITEST_CLI, package_json)) {
28
+ const package_json = await package_json_load();
29
+ if (!package_json_has_dependency(VITEST_CLI, package_json)) {
30
30
  throw new TaskError('no test runner found, install vitest');
31
31
  }
32
32
  if (!(await find_cli(VITEST_CLI))) {
@@ -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;AAItB,OAAO,EAAY,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AAM/C,cAAc;AACd,eAAO,MAAM,IAAI;;;;;;;;;;;;kBAiCf,CAAC;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAExC,cAAc;AACd,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,IAAI,CA4E3B,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;AAItB,OAAO,EAAY,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AAU/C,cAAc;AACd,eAAO,MAAM,IAAI;;;;;;;;;;;;kBAiCf,CAAC;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAExC,cAAc;AACd,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,IAAI,CA4E3B,CAAC"}
@@ -3,7 +3,7 @@ import { z } from 'zod';
3
3
  import { rm } from 'node:fs/promises';
4
4
  import { GitOrigin, git_pull } from '@fuzdev/fuz_util/git.js';
5
5
  import { TaskError } from "./task.js";
6
- import { extract_deps, load_package_json } from "./package_json.js";
6
+ import { package_json_extract_dependencies, package_json_load, } from "./package_json.js";
7
7
  import { spawn_cli } from "./cli.js";
8
8
  import { serialize_args, to_forwarded_args } from "./args.js";
9
9
  import { NODE_MODULES_DIRNAME } from "./constants.js";
@@ -63,8 +63,8 @@ export const task = {
63
63
  log.info(`deleting lockfile at`, lockfile_path);
64
64
  await rm(lockfile_path, { force: true });
65
65
  }
66
- const package_json = await load_package_json();
67
- const all_deps = extract_deps(package_json);
66
+ const package_json = await package_json_load();
67
+ const all_deps = package_json_extract_dependencies(package_json);
68
68
  const deps = only.length
69
69
  ? all_deps.filter((d) => only.includes(d.name))
70
70
  : all_deps.filter((d) => !_.includes(d.name));
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@ryanatkn/gro",
3
- "version": "0.182.0",
3
+ "version": "0.183.0",
4
4
  "description": "task runner and toolkit extending SvelteKit",
5
5
  "motto": "generate, run, optimize",
6
6
  "glyph": "🌰",
7
7
  "logo": "logo.svg",
8
8
  "logo_alt": "a pixelated green oak acorn with a glint of sun",
9
- "public": true,
10
9
  "license": "MIT",
11
10
  "homepage": "https://gro.ryanatkn.com/",
12
11
  "author": {
@@ -84,8 +83,8 @@
84
83
  "@changesets/types": "^6.1.0",
85
84
  "@fuzdev/fuz_code": "^0.38.0",
86
85
  "@fuzdev/fuz_css": "^0.42.1",
87
- "@fuzdev/fuz_ui": "^0.172.0",
88
- "@fuzdev/fuz_util": "^0.43.0",
86
+ "@fuzdev/fuz_ui": "^0.173.0",
87
+ "@fuzdev/fuz_util": "^0.45.0",
89
88
  "@ryanatkn/eslint-config": "^0.9.0",
90
89
  "@sveltejs/adapter-static": "^3.0.10",
91
90
  "@sveltejs/kit": "^2.49.1",
@@ -22,7 +22,7 @@ import {
22
22
  CHANGESET_PUBLIC_ACCESS,
23
23
  CHANGESET_RESTRICTED_ACCESS,
24
24
  } from './changeset_helpers.ts';
25
- import {load_package_json} from './package_json.ts';
25
+ import {package_json_load} from './package_json.ts';
26
26
 
27
27
  /** @nodocs */
28
28
  export const Args = z.strictObject({
@@ -99,7 +99,7 @@ export const task: Task<Args> = {
99
99
  );
100
100
  }
101
101
 
102
- const package_json = await load_package_json();
102
+ const package_json = await package_json_load();
103
103
 
104
104
  const has_sveltekit_library_result = await has_sveltekit_library(package_json, svelte_config);
105
105
  if (!has_sveltekit_library_result.ok) {
@@ -4,7 +4,7 @@ import {styleText as st} from 'node:util';
4
4
  import {git_check_clean_workspace} from '@fuzdev/fuz_util/git.js';
5
5
 
6
6
  import {TaskError, type Task} from './task.ts';
7
- import {sync_package_json} from './package_json.ts';
7
+ import {package_json_sync} from './package_json.ts';
8
8
 
9
9
  /** @nodocs */
10
10
  export const Args = z.strictObject({
@@ -62,7 +62,7 @@ export const task: Task<Args> = {
62
62
  }
63
63
 
64
64
  if (package_json && config.map_package_json) {
65
- const {changed} = await sync_package_json(config.map_package_json, log, false);
65
+ const {changed} = await package_json_sync(config.map_package_json, log, false);
66
66
  if (changed) {
67
67
  throw new TaskError('package.json is out of date, run `gro sync` to update it');
68
68
  } else {
@@ -1,7 +1,7 @@
1
1
  import prettier from 'prettier';
2
2
  import {extname} from 'node:path';
3
3
 
4
- import {load_package_json} from './package_json.ts';
4
+ import {package_json_load} from './package_json.ts';
5
5
 
6
6
  let cached_base_options: prettier.Options | undefined;
7
7
 
@@ -19,7 +19,7 @@ export const format_file = async (
19
19
  const final_base_options =
20
20
  base_options !== undefined
21
21
  ? base_options
22
- : (cached_base_options = (await load_package_json()).prettier as any);
22
+ : (cached_base_options = (await package_json_load()).prettier as any);
23
23
  let final_options = options;
24
24
  if (options.filepath && !options.parser) {
25
25
  const {filepath, ...rest} = options;
@@ -4,7 +4,7 @@ import {has_server, gro_plugin_server} from './gro_plugin_server.ts';
4
4
  import {gro_plugin_sveltekit_app} from './gro_plugin_sveltekit_app.ts';
5
5
  import {has_sveltekit_app, has_sveltekit_library} from './sveltekit_helpers.ts';
6
6
  import {gro_plugin_gen} from './gro_plugin_gen.ts';
7
- import {load_package_json} from './package_json.ts';
7
+ import {package_json_load} from './package_json.ts';
8
8
 
9
9
  // TODO hacky, maybe extract utils?
10
10
 
@@ -18,7 +18,7 @@ import {load_package_json} from './package_json.ts';
18
18
  * - if `src/lib/server/server.ts`, assumes a Node server - needs config
19
19
  */
20
20
  const config: CreateGroConfig = async (cfg, svelte_config) => {
21
- const package_json = await load_package_json(); // TODO gets wastefully loaded by some plugins, maybe put in plugin/task context? how does that interact with `map_package_json`?
21
+ const package_json = await package_json_load(); // TODO gets wastefully loaded by some plugins, maybe put in plugin/task context? how does that interact with `map_package_json`?
22
22
 
23
23
  const [has_server_result, has_sveltekit_library_result, has_sveltekit_app_result] =
24
24
  await Promise.all([
@@ -1,64 +1,25 @@
1
1
  import type {SpawnedProcess} from '@fuzdev/fuz_util/process.js';
2
- import {cp, mkdir, rm, writeFile} from 'node:fs/promises';
3
- import {dirname, join} from 'node:path';
4
- import {fs_exists} from '@fuzdev/fuz_util/fs.js';
5
2
 
6
3
  import type {Plugin} from './plugin.ts';
7
4
  import {serialize_args, to_forwarded_args} from './args.ts';
8
- import {serialize_package_json, type PackageJsonMapper, load_package_json} from './package_json.ts';
9
5
  import {TaskError} from './task.ts';
10
6
  import {find_cli, spawn_cli, spawn_cli_process} from './cli.ts';
11
- import {type SourceJsonMapper, source_json_serialize, source_json_create} from './source_json.ts';
12
- import {EXPORTS_EXCLUDER_DEFAULT} from './gro_config.ts';
13
- import {default_svelte_config} from './svelte_config.ts';
14
- import {SOURCE_DIRNAME, VITE_CLI} from './constants.ts';
7
+ import {VITE_CLI} from './constants.ts';
15
8
 
16
9
  export interface GroPluginSveltekitAppOptions {
17
- /**
18
- * Whether to include a `.nojekyll` file in the build output.
19
- * GitHub Pages processes files with Jekyll by default, breaking files/dirs prefixed with `_`.
20
- * The `.nojekyll` file tells GitHub Pages to skip Jekyll processing.
21
- *
22
- * @default `true` if the SvelteKit adapter name contains 'static'
23
- */
24
- include_nojekyll?: boolean;
25
-
26
- /**
27
- * If truthy, adds `/.well-known/package.json` to the static output.
28
- * If a function, maps the value.
29
- */
30
- well_known_package_json?: boolean | PackageJsonMapper;
31
-
32
- /**
33
- * If truthy, adds `/.well-known/source.json` and `/.well-known/src/` to the static output.
34
- * If a function, maps the value.
35
- */
36
- well_known_source_json?: boolean | SourceJsonMapper;
37
-
38
- /**
39
- * If truthy, copies `src/` to `/.well-known/src/` to the static output.
40
- * Pass a function to customize which files get copied.
41
- */
42
- well_known_src_files?: boolean | CopyFileFilter;
43
10
  /**
44
11
  * The Vite CLI to use.
45
12
  */
46
13
  vite_cli?: string;
47
14
  }
48
15
 
49
- export type CopyFileFilter = (file_path: string) => boolean;
50
-
51
16
  export const gro_plugin_sveltekit_app = ({
52
- include_nojekyll,
53
- well_known_package_json,
54
- well_known_source_json,
55
- well_known_src_files,
56
17
  vite_cli = VITE_CLI,
57
18
  }: GroPluginSveltekitAppOptions = {}): Plugin => {
58
19
  let sveltekit_process: SpawnedProcess | undefined = undefined;
59
20
  return {
60
21
  name: 'gro_plugin_sveltekit_app',
61
- setup: async ({dev, watch, log, config, svelte_config}) => {
22
+ setup: async ({dev, watch, log, config}) => {
62
23
  const found_vite_cli = await find_cli(vite_cli);
63
24
  if (!found_vite_cli)
64
25
  throw Error(
@@ -77,87 +38,11 @@ export const gro_plugin_sveltekit_app = ({
77
38
  }
78
39
  } else {
79
40
  // `vite build` in production mode
80
-
81
- // `.well-known/package.json`
82
- const package_json = await load_package_json(); // TODO put in plugin context? same with sveltekit config?
83
- if (well_known_package_json === undefined) {
84
- well_known_package_json = package_json.public; // eslint-disable-line no-param-reassign
85
- }
86
- const mapped_package_json = !well_known_package_json
87
- ? null
88
- : well_known_package_json === true
89
- ? package_json
90
- : await well_known_package_json(package_json);
91
- const serialized_package_json =
92
- mapped_package_json && serialize_package_json(mapped_package_json);
93
-
94
- // `.well-known/source.json` and `.well-known/src/`
95
- const final_package_json = mapped_package_json ?? package_json;
96
- const source_json = await source_json_create(final_package_json, undefined, log);
97
- if (well_known_source_json === undefined) {
98
- well_known_source_json = final_package_json.public; // eslint-disable-line no-param-reassign
99
- }
100
- const mapped_source_json = !well_known_source_json
101
- ? null
102
- : well_known_source_json === true
103
- ? source_json
104
- : await well_known_source_json(source_json);
105
- const serialized_source_json =
106
- mapped_source_json && source_json_serialize(mapped_source_json);
107
-
108
- // TODO this strategy means the files aren't available during development --
109
- // maybe a Vite middleware is best? what if this plugin added its plugin to your `vite.config.ts`?
110
-
111
- // copy files to `static` before building, in such a way
112
- // that's non-destructive to existing files and dirs and easy to clean up
113
- const {assets_path} = default_svelte_config;
114
-
115
- // detect whether to include .nojekyll based on adapter if not explicitly set
116
- const adapter_name = svelte_config.svelte_config?.kit?.adapter?.name;
117
- const should_include_nojekyll =
118
- include_nojekyll ?? (adapter_name ? adapter_name.includes('static') : false);
119
-
120
- const cleanup_promises = [
121
- serialized_package_json
122
- ? create_temporarily(
123
- join(assets_path, '.well-known/package.json'),
124
- serialized_package_json,
125
- )
126
- : null,
127
- serialized_source_json
128
- ? create_temporarily(
129
- join(assets_path, '.well-known/source.json'),
130
- serialized_source_json,
131
- )
132
- : null,
133
- serialized_source_json && well_known_src_files
134
- ? copy_temporarily(
135
- SOURCE_DIRNAME,
136
- assets_path,
137
- '.well-known',
138
- well_known_src_files === true
139
- ? (file_path) => !EXPORTS_EXCLUDER_DEFAULT.test(file_path)
140
- : well_known_src_files,
141
- )
142
- : null,
143
- should_include_nojekyll ? create_temporarily(join(assets_path, '.nojekyll'), '') : null,
144
- ].filter((v): v is Promise<AsyncCleanup> => v != null);
145
- const cleanups = await Promise.all(cleanup_promises);
146
- const cleanup = async () => {
147
- // eslint-disable-next-line no-await-in-loop
148
- for (const c of cleanups) await c();
149
- };
150
- try {
151
- const serialized_args = ['build', ...serialize_args(to_forwarded_args(vite_cli))];
152
- const spawned = await spawn_cli(found_vite_cli, serialized_args, log);
153
- if (!spawned?.ok) {
154
- throw new TaskError(`${vite_cli} build failed with exit code ${spawned?.code}`);
155
- }
156
- } catch (error) {
157
- await cleanup();
158
- throw error;
41
+ const serialized_args = ['build', ...serialize_args(to_forwarded_args(vite_cli))];
42
+ const spawned = await spawn_cli(found_vite_cli, serialized_args, log);
43
+ if (!spawned?.ok) {
44
+ throw new TaskError(`${vite_cli} build failed with exit code ${spawned?.code}`);
159
45
  }
160
- await cleanup();
161
46
  }
162
47
  },
163
48
  teardown: async () => {
@@ -168,98 +53,3 @@ export const gro_plugin_sveltekit_app = ({
168
53
  },
169
54
  };
170
55
  };
171
-
172
- type AsyncCleanup = () => Promise<void>;
173
-
174
- // TODO probably extract these, and create a common helper or merge them
175
-
176
- const copy_temporarily = async (
177
- source_path: string,
178
- dest_dir: string,
179
- dest_base_dir = '',
180
- filter?: CopyFileFilter,
181
- ): Promise<AsyncCleanup> => {
182
- const path = join(dest_dir, dest_base_dir, source_path);
183
- const dir = dirname(path);
184
-
185
- const dir_already_exists = await fs_exists(dir);
186
- let root_created_dir: string | undefined;
187
- if (!dir_already_exists) {
188
- root_created_dir = await to_root_dir_that_doesnt_exist(dir);
189
- if (!root_created_dir) throw Error();
190
- await mkdir(dir, {recursive: true});
191
- }
192
-
193
- const path_already_exists = await fs_exists(path);
194
- if (!path_already_exists) {
195
- await cp(source_path, path, {recursive: true, filter});
196
- }
197
-
198
- return async () => {
199
- if (!dir_already_exists) {
200
- if (!root_created_dir) throw Error();
201
- if (await fs_exists(root_created_dir)) {
202
- await rm(root_created_dir, {recursive: true});
203
- }
204
- } else if (!path_already_exists) {
205
- if (await fs_exists(path)) {
206
- await rm(path, {recursive: true});
207
- }
208
- }
209
- };
210
- };
211
-
212
- /**
213
- * Creates a file at `path` with `contents` if it doesn't already exist,
214
- * and returns a function that deletes the file and any created directories.
215
- * @param path
216
- * @param contents
217
- * @returns cleanup function that deletes the file and any created dirs
218
- */
219
- const create_temporarily = async (path: string, contents: string): Promise<AsyncCleanup> => {
220
- const dir = dirname(path);
221
-
222
- const dir_already_exists = await fs_exists(dir);
223
- let root_created_dir: string | undefined;
224
- if (!dir_already_exists) {
225
- root_created_dir = await to_root_dir_that_doesnt_exist(dir);
226
- if (!root_created_dir) throw Error();
227
- await mkdir(dir, {recursive: true});
228
- }
229
-
230
- const path_already_exists = await fs_exists(path);
231
- if (!path_already_exists) {
232
- await writeFile(path, contents, 'utf8');
233
- }
234
-
235
- return async () => {
236
- if (!dir_already_exists) {
237
- if (!root_created_dir) throw Error();
238
- if (await fs_exists(root_created_dir)) {
239
- await rm(root_created_dir, {recursive: true});
240
- }
241
- } else if (!path_already_exists) {
242
- if (await fs_exists(path)) {
243
- await rm(path);
244
- }
245
- }
246
- };
247
- };
248
-
249
- /**
250
- * Niche and probably needs refactoring,
251
- * for `/a/b/DOESNT_EXIST/NOR_THIS/ETC` returns `/a/b/DOESNT_EXIST`
252
- * where `/a/b` does exist on the filesystem and `DOESNT_EXIST` is not one of its subdirectories.
253
- */
254
- const to_root_dir_that_doesnt_exist = async (dir: string): Promise<string | undefined> => {
255
- let prev: string | undefined;
256
- let d = dir;
257
- do {
258
- // eslint-disable-next-line no-await-in-loop
259
- if (await fs_exists(d)) {
260
- return prev;
261
- }
262
- prev = d;
263
- } while ((d = dirname(d)));
264
- throw Error('no dirs exist for ' + dir);
265
- };
@@ -2,7 +2,7 @@ import {print_spawn_result, spawn} from '@fuzdev/fuz_util/process.js';
2
2
 
3
3
  import type {Plugin} from './plugin.ts';
4
4
  import {TaskError} from './task.ts';
5
- import {load_package_json} from './package_json.ts';
5
+ import {package_json_load} from './package_json.ts';
6
6
  import {run_svelte_package, type SveltePackageOptions} from './sveltekit_helpers.ts';
7
7
  import {SVELTE_PACKAGE_CLI} from './constants.ts';
8
8
 
@@ -27,7 +27,7 @@ export const gro_plugin_sveltekit_library = ({
27
27
  name: 'gro_plugin_sveltekit_library',
28
28
  setup: async ({dev, log, config}) => {
29
29
  if (!dev) {
30
- const package_json = await load_package_json();
30
+ const package_json = await package_json_load();
31
31
  await run_svelte_package(
32
32
  package_json,
33
33
  svelte_package_options,
@@ -38,7 +38,7 @@ export const gro_plugin_sveltekit_library = ({
38
38
  }
39
39
  },
40
40
  adapt: async ({log, timings, config}) => {
41
- const package_json = await load_package_json();
41
+ const package_json = await package_json_load();
42
42
  // link the CLI binaries if they exist
43
43
  if (package_json.bin) {
44
44
  const timing_to_link = timings.start(`${config.pm_cli} link`);
@@ -7,7 +7,7 @@ import {to_forwarded_args, type Args} from './args.ts';
7
7
  import {run_task} from './run_task.ts';
8
8
  import {to_input_path, RawInputPath} from './input_path.ts';
9
9
  import {find_tasks, load_tasks, SilentError} from './task.ts';
10
- import {load_gro_package_json} from './package_json.ts';
10
+ import {package_json_load_for_gro} from './package_json.ts';
11
11
  import {log_tasks, log_error_reasons} from './task_logging.ts';
12
12
  import type {GroConfig} from './gro_config.ts';
13
13
  import {Filer} from './filer.ts';
@@ -68,7 +68,7 @@ export const invoke_task = async (
68
68
 
69
69
  // Check if the caller just wants to see the version.
70
70
  if (!task_name && (args?.version || args?.v)) {
71
- const gro_package_json = await load_gro_package_json();
71
+ const gro_package_json = await package_json_load_for_gro();
72
72
  log.info(`${st('gray', 'v')}${st('cyan', gro_package_json.version)}`);
73
73
  await finish();
74
74
  return;
@@ -24,9 +24,9 @@ export type PackageJsonMapper = (
24
24
  package_json: PackageJson,
25
25
  ) => PackageJson | null | Promise<PackageJson | null>;
26
26
 
27
- export const EMPTY_PACKAGE_JSON: PackageJson = {name: '', version: ''};
27
+ export const PACKAGE_JSON_EMPTY: PackageJson = {name: '', version: ''};
28
28
 
29
- export const load_package_json = async (
29
+ export const package_json_load = async (
30
30
  dir = IS_THIS_GRO ? gro_paths.root : paths.root,
31
31
  cache?: Record<string, PackageJson>,
32
32
  parse = true, // TODO pass `false` here in more places, especially anything perf-sensitive like work on startup
@@ -37,10 +37,10 @@ export const load_package_json = async (
37
37
  return cache[dir]!;
38
38
  }
39
39
  try {
40
- package_json = JSON.parse(await load_package_json_contents(dir));
40
+ package_json = JSON.parse(await package_json_load_contents(dir));
41
41
  } catch (error) {
42
42
  log?.error(st('yellow', `Failed to load package.json in ${dir}`), error);
43
- return EMPTY_PACKAGE_JSON;
43
+ return PACKAGE_JSON_EMPTY;
44
44
  }
45
45
  if (parse) {
46
46
  package_json = parse_package_json(PackageJson, package_json);
@@ -51,7 +51,10 @@ export const load_package_json = async (
51
51
  return package_json;
52
52
  };
53
53
 
54
- export const sync_package_json = async (
54
+ // TODO remove
55
+ export const load_package_json = package_json_load;
56
+
57
+ export const package_json_sync = async (
55
58
  map_package_json: PackageJsonMapper,
56
59
  log: Logger,
57
60
  write = true,
@@ -60,10 +63,10 @@ export const sync_package_json = async (
60
63
  ): Promise<{package_json: PackageJson | null; changed: boolean}> => {
61
64
  const exported_files = await fs_search(exports_dir);
62
65
  const exported_paths = exported_files.map((f) => f.path);
63
- const updated = await update_package_json(
66
+ const updated = await package_json_update(
64
67
  async (package_json) => {
65
68
  if ((await has_sveltekit_library(package_json)).ok) {
66
- package_json.exports = to_package_exports(exported_paths);
69
+ package_json.exports = package_json_to_exports(exported_paths);
67
70
  }
68
71
  const mapped = await map_package_json(package_json);
69
72
  return mapped ? parse_package_json(PackageJson, mapped) : mapped;
@@ -85,43 +88,44 @@ export const sync_package_json = async (
85
88
  return updated;
86
89
  };
87
90
 
88
- export const load_gro_package_json = (): Promise<PackageJson> => load_package_json(gro_paths.root);
91
+ export const package_json_load_for_gro = (): Promise<PackageJson> =>
92
+ package_json_load(gro_paths.root);
89
93
 
90
94
  // TODO probably make this nullable and make callers handle failures
91
- const load_package_json_contents = (dir: string): Promise<string> =>
95
+ const package_json_load_contents = (dir: string): Promise<string> =>
92
96
  readFile(join(dir, PACKAGE_JSON_FILENAME), 'utf8');
93
97
 
94
- export const write_package_json = (serialized_package_json: string): Promise<void> =>
98
+ export const package_json_write = (serialized_package_json: string): Promise<void> =>
95
99
  writeFile(join(paths.root, PACKAGE_JSON_FILENAME), serialized_package_json);
96
100
 
97
- export const serialize_package_json = (package_json: PackageJson): string =>
101
+ export const package_json_serialize = (package_json: PackageJson): string =>
98
102
  JSON.stringify(parse_package_json(PackageJson, package_json), null, 2) + '\n';
99
103
 
100
104
  /**
101
105
  * Updates package.json. Writes to the filesystem only when contents change.
102
106
  */
103
- export const update_package_json = async (
107
+ export const package_json_update = async (
104
108
  update: (package_json: PackageJson) => PackageJson | null | Promise<PackageJson | null>,
105
109
  dir = paths.root,
106
110
  write = true,
107
111
  ): Promise<{package_json: PackageJson | null; changed: boolean}> => {
108
- const original_contents = await load_package_json_contents(dir);
112
+ const original_contents = await package_json_load_contents(dir);
109
113
  const original = JSON.parse(original_contents);
110
114
  const updated = await update(original);
111
115
  if (updated === null) {
112
116
  return {package_json: original, changed: false};
113
117
  }
114
- const updated_contents = serialize_package_json(updated);
118
+ const updated_contents = package_json_serialize(updated);
115
119
  if (updated_contents === original_contents) {
116
120
  return {package_json: original, changed: false};
117
121
  }
118
- if (write) await write_package_json(updated_contents);
122
+ if (write) await package_json_write(updated_contents);
119
123
  return {package_json: updated, changed: true};
120
124
  };
121
125
 
122
126
  const is_index = (path: string): boolean => path === 'index.ts' || path === 'index.js';
123
127
 
124
- export const to_package_exports = (paths: Array<string>): PackageJsonExports => {
128
+ export const package_json_to_exports = (paths: Array<string>): PackageJsonExports => {
125
129
  const has_index = paths.some(is_index);
126
130
  const has_js = paths.some((p) => TS_MATCHER.test(p) || JS_MATCHER.test(p));
127
131
  const has_svelte = paths.some((p) => SVELTE_MATCHER.test(p));
@@ -176,7 +180,7 @@ export const to_package_exports = (paths: Array<string>): PackageJsonExports =>
176
180
 
177
181
  const IMPORT_PREFIX = './' + SVELTEKIT_DIST_DIRNAME + '/';
178
182
 
179
- export const parse_repo_url = (
183
+ export const package_json_parse_repo_url = (
180
184
  package_json: PackageJson,
181
185
  ): {owner: string; repo: string} | undefined => {
182
186
  const {repository} = package_json;
@@ -224,7 +228,7 @@ const parse_or_throw_formatted_error = <T extends z.ZodType>(
224
228
  return parsed.data;
225
229
  };
226
230
 
227
- export const has_dep = (dep_name: string, package_json: PackageJson): boolean =>
231
+ export const package_json_has_dependency = (dep_name: string, package_json: PackageJson): boolean =>
228
232
  !!package_json.devDependencies?.[dep_name] ||
229
233
  !!package_json.dependencies?.[dep_name] ||
230
234
  !!package_json.peerDependencies?.[dep_name];
@@ -234,7 +238,9 @@ export interface PackageJsonDep {
234
238
  version: string;
235
239
  }
236
240
 
237
- export const extract_deps = (package_json: PackageJson): Array<PackageJsonDep> => {
241
+ export const package_json_extract_dependencies = (
242
+ package_json: PackageJson,
243
+ ): Array<PackageJsonDep> => {
238
244
  const deps_by_name: Map<string, PackageJsonDep> = new Map();
239
245
  // Earlier versions override later ones, so peer deps goes last.
240
246
  const add_deps = (deps: Record<string, string> | undefined) => {
@@ -12,7 +12,7 @@ import {
12
12
  } from '@fuzdev/fuz_util/git.js';
13
13
 
14
14
  import {TaskError, type Task} from './task.ts';
15
- import {load_package_json, parse_repo_url} from './package_json.ts';
15
+ import {package_json_load, package_json_parse_repo_url} from './package_json.ts';
16
16
  import {find_cli, spawn_cli} from './cli.ts';
17
17
  import {has_sveltekit_library} from './sveltekit_helpers.ts';
18
18
  import {update_changelog} from './changelog.ts';
@@ -85,7 +85,7 @@ export const task: Task<Args> = {
85
85
  log.info(st('green', 'dry run!'));
86
86
  }
87
87
 
88
- const package_json = await load_package_json();
88
+ const package_json = await package_json_load();
89
89
 
90
90
  const has_sveltekit_library_result = await has_sveltekit_library(package_json);
91
91
  if (!has_sveltekit_library_result.ok) {
@@ -140,7 +140,7 @@ export const task: Task<Args> = {
140
140
  if (typeof package_json.version !== 'string') {
141
141
  throw new TaskError('Failed to find package.json version');
142
142
  }
143
- const parsed_repo_url = parse_repo_url(package_json);
143
+ const parsed_repo_url = package_json_parse_repo_url(package_json);
144
144
  if (!parsed_repo_url) {
145
145
  throw new TaskError(
146
146
  'package.json `repository` must contain a repo url (and GitHub only for now, sorry),' +
@@ -178,7 +178,7 @@ export const task: Task<Args> = {
178
178
  // The check above ensures gen is updated.
179
179
  await invoke_task('gen');
180
180
 
181
- const package_json_after_versioning = await load_package_json();
181
+ const package_json_after_versioning = await package_json_load();
182
182
  version = package_json_after_versioning.version!;
183
183
  if (package_json.version === version) {
184
184
  // The version didn't change.
@@ -2,7 +2,7 @@ import {z} from 'zod';
2
2
 
3
3
  import type {Task} from './task.ts';
4
4
  import {has_sveltekit_library, has_sveltekit_app} from './sveltekit_helpers.ts';
5
- import {load_package_json} from './package_json.ts';
5
+ import {package_json_load} from './package_json.ts';
6
6
 
7
7
  /** @nodocs */
8
8
  export const Args = z.strictObject({});
@@ -13,7 +13,7 @@ export const task: Task<Args> = {
13
13
  summary: 'publish and deploy',
14
14
  Args,
15
15
  run: async ({invoke_task}) => {
16
- const package_json = await load_package_json();
16
+ const package_json = await package_json_load();
17
17
 
18
18
  const publish = (await has_sveltekit_library(package_json)).ok;
19
19
  if (publish) {
@@ -25,11 +25,6 @@ export const source_json_create = async (
25
25
  modules: await source_modules_create(package_json.exports, lib_path, log),
26
26
  });
27
27
 
28
- export const source_json_serialize = (source_json: SourceJson): string => {
29
- const parsed = SourceJson.parse(source_json);
30
- return JSON.stringify(parsed, null, 2) + '\n';
31
- };
32
-
33
28
  export const source_modules_create = async (
34
29
  exports: PackageJsonExports | undefined,
35
30
  lib_path = paths.lib,
@@ -4,7 +4,7 @@ import {join} from 'node:path';
4
4
  import type {PackageJson} from '@fuzdev/fuz_util/package_json.js';
5
5
  import {fs_exists} from '@fuzdev/fuz_util/fs.js';
6
6
 
7
- import {has_dep} from './package_json.ts';
7
+ import {package_json_has_dependency} from './package_json.ts';
8
8
  import {default_svelte_config, type ParsedSvelteConfig} from './svelte_config.ts';
9
9
  import {
10
10
  SVELTE_CONFIG_FILENAME,
@@ -41,7 +41,7 @@ export const has_sveltekit_library = async (
41
41
  return {ok: false, message: `no SvelteKit lib directory found at ${svelte_config.lib_path}`};
42
42
  }
43
43
 
44
- if (!has_dep(dep_name, package_json)) {
44
+ if (!package_json_has_dependency(dep_name, package_json)) {
45
45
  return {
46
46
  ok: false,
47
47
  message: `no dependency found in package.json for ${dep_name}`,