@ryanatkn/gro 0.181.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 (44) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +6 -1
  3. package/dist/changeset.task.js +2 -2
  4. package/dist/check.task.js +2 -2
  5. package/dist/cli.d.ts +2 -2
  6. package/dist/cli.js +2 -2
  7. package/dist/format_file.js +2 -2
  8. package/dist/gro.config.default.d.ts.map +1 -1
  9. package/dist/gro.config.default.js +3 -5
  10. package/dist/gro_plugin_sveltekit_app.d.ts +1 -25
  11. package/dist/gro_plugin_sveltekit_app.d.ts.map +1 -1
  12. package/dist/gro_plugin_sveltekit_app.js +6 -160
  13. package/dist/gro_plugin_sveltekit_library.js +3 -3
  14. package/dist/invoke_task.js +2 -2
  15. package/dist/package_json.d.ts +12 -11
  16. package/dist/package_json.d.ts.map +1 -1
  17. package/dist/package_json.js +21 -19
  18. package/dist/publish.task.js +4 -4
  19. package/dist/release.task.js +2 -2
  20. package/dist/source_json.d.ts +0 -1
  21. package/dist/source_json.d.ts.map +1 -1
  22. package/dist/source_json.js +0 -4
  23. package/dist/sveltekit_helpers.js +2 -2
  24. package/dist/sync.task.js +2 -2
  25. package/dist/test.task.js +3 -3
  26. package/dist/upgrade.task.d.ts.map +1 -1
  27. package/dist/upgrade.task.js +3 -3
  28. package/package.json +11 -12
  29. package/src/lib/changeset.task.ts +2 -2
  30. package/src/lib/check.task.ts +2 -2
  31. package/src/lib/cli.ts +3 -3
  32. package/src/lib/format_file.ts +2 -2
  33. package/src/lib/gro.config.default.ts +3 -5
  34. package/src/lib/gro_plugin_sveltekit_app.ts +5 -216
  35. package/src/lib/gro_plugin_sveltekit_library.ts +3 -3
  36. package/src/lib/invoke_task.ts +2 -2
  37. package/src/lib/package_json.ts +25 -19
  38. package/src/lib/publish.task.ts +4 -4
  39. package/src/lib/release.task.ts +2 -2
  40. package/src/lib/source_json.ts +0 -5
  41. package/src/lib/sveltekit_helpers.ts +2 -2
  42. package/src/lib/sync.task.ts +2 -2
  43. package/src/lib/test.task.ts +3 -3
  44. package/src/lib/upgrade.task.ts +7 -3
@@ -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}`,
@@ -2,7 +2,7 @@ import {z} from 'zod';
2
2
  import {spawn} from '@fuzdev/fuz_util/process.js';
3
3
 
4
4
  import {TaskError, type Task} from './task.ts';
5
- import {sync_package_json} from './package_json.ts';
5
+ import {package_json_sync} from './package_json.ts';
6
6
  import {sveltekit_sync} from './sveltekit_helpers.ts';
7
7
 
8
8
  /** @nodocs */
@@ -37,7 +37,7 @@ export const task: Task<Args> = {
37
37
  }
38
38
 
39
39
  if (package_json && config.map_package_json) {
40
- await sync_package_json(config.map_package_json, log);
40
+ await package_json_sync(config.map_package_json, log);
41
41
  }
42
42
 
43
43
  if (gen) {
@@ -3,7 +3,7 @@ import {spawn_cli} from '@ryanatkn/gro/cli.js';
3
3
 
4
4
  import {TaskError, type Task} from './task.ts';
5
5
  import {find_cli} from './cli.ts';
6
- import {has_dep, load_package_json} from './package_json.ts';
6
+ import {package_json_has_dependency, package_json_load} from './package_json.ts';
7
7
  import {serialize_args, to_implicit_forwarded_args} from './args.ts';
8
8
  import {VITEST_CLI} from './constants.ts';
9
9
  import {paths} from './paths.ts';
@@ -30,8 +30,8 @@ export const task: Task<Args> = {
30
30
  run: async ({args}): Promise<void> => {
31
31
  const {_: patterns, dir, fail_without_tests, t} = args;
32
32
 
33
- const package_json = await load_package_json();
34
- if (!has_dep(VITEST_CLI, package_json)) {
33
+ const package_json = await package_json_load();
34
+ if (!package_json_has_dependency(VITEST_CLI, package_json)) {
35
35
  throw new TaskError('no test runner found, install vitest');
36
36
  }
37
37
 
@@ -4,7 +4,11 @@ import {rm} from 'node:fs/promises';
4
4
  import {GitOrigin, git_pull} from '@fuzdev/fuz_util/git.js';
5
5
 
6
6
  import {TaskError, type Task} from './task.ts';
7
- import {extract_deps, load_package_json, type PackageJsonDep} from './package_json.ts';
7
+ import {
8
+ package_json_extract_dependencies,
9
+ package_json_load,
10
+ type PackageJsonDep,
11
+ } from './package_json.ts';
8
12
  import {spawn_cli} from './cli.ts';
9
13
  import {serialize_args, to_forwarded_args} from './args.ts';
10
14
  import {NODE_MODULES_DIRNAME} from './constants.ts';
@@ -83,9 +87,9 @@ export const task: Task<Args> = {
83
87
  await rm(lockfile_path, {force: true});
84
88
  }
85
89
 
86
- const package_json = await load_package_json();
90
+ const package_json = await package_json_load();
87
91
 
88
- const all_deps = extract_deps(package_json);
92
+ const all_deps = package_json_extract_dependencies(package_json);
89
93
 
90
94
  const deps = only.length
91
95
  ? all_deps.filter((d) => only.includes(d.name))