@ryanatkn/gro 0.182.0 → 0.184.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 (46) 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_config.d.ts +3 -3
  6. package/dist/gro_plugin_sveltekit_app.d.ts +1 -27
  7. package/dist/gro_plugin_sveltekit_app.d.ts.map +1 -1
  8. package/dist/gro_plugin_sveltekit_app.js +7 -156
  9. package/dist/gro_plugin_sveltekit_library.js +3 -3
  10. package/dist/index.d.ts +1 -1
  11. package/dist/index.js +1 -1
  12. package/dist/invoke_task.js +2 -2
  13. package/dist/package_json.d.ts +11 -11
  14. package/dist/package_json.d.ts.map +1 -1
  15. package/dist/package_json.js +19 -19
  16. package/dist/plugin.d.ts +3 -3
  17. package/dist/plugin.js +2 -2
  18. package/dist/publish.task.js +4 -4
  19. package/dist/release.task.js +2 -2
  20. package/dist/source_json.d.ts +1 -2
  21. package/dist/source_json.d.ts.map +1 -1
  22. package/dist/source_json.js +2 -6
  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 +3 -4
  29. package/src/lib/changeset.task.ts +2 -2
  30. package/src/lib/check.task.ts +2 -2
  31. package/src/lib/format_file.ts +2 -2
  32. package/src/lib/gro.config.default.ts +2 -2
  33. package/src/lib/gro_config.ts +3 -3
  34. package/src/lib/gro_plugin_sveltekit_app.ts +6 -216
  35. package/src/lib/gro_plugin_sveltekit_library.ts +3 -3
  36. package/src/lib/index.ts +1 -1
  37. package/src/lib/invoke_task.ts +2 -2
  38. package/src/lib/package_json.ts +22 -19
  39. package/src/lib/plugin.ts +3 -3
  40. package/src/lib/publish.task.ts +4 -4
  41. package/src/lib/release.task.ts +2 -2
  42. package/src/lib/source_json.ts +2 -7
  43. package/src/lib/sveltekit_helpers.ts +2 -2
  44. package/src/lib/sync.task.ts +2 -2
  45. package/src/lib/test.task.ts +3 -3
  46. package/src/lib/upgrade.task.ts +7 -3
@@ -9,7 +9,7 @@ import { TaskError } from "./task.js";
9
9
  import { find_cli, spawn_cli } from "./cli.js";
10
10
  import { has_sveltekit_library } from "./sveltekit_helpers.js";
11
11
  import { CHANGESET_CLI, CHANGESET_DIR, ChangesetAccess, ChangesetBump, CHANGESET_PUBLIC_ACCESS, CHANGESET_RESTRICTED_ACCESS, } from "./changeset_helpers.js";
12
- import { load_package_json } from "./package_json.js";
12
+ import { package_json_load } from "./package_json.js";
13
13
  /** @nodocs */
14
14
  export const Args = z.strictObject({
15
15
  /**
@@ -61,7 +61,7 @@ export const task = {
61
61
  if (!found_changeset_cli) {
62
62
  throw new TaskError('changeset command not found: install @changesets/cli locally or globally');
63
63
  }
64
- const package_json = await load_package_json();
64
+ const package_json = await package_json_load();
65
65
  const has_sveltekit_library_result = await has_sveltekit_library(package_json, svelte_config);
66
66
  if (!has_sveltekit_library_result.ok) {
67
67
  throw new TaskError('Failed to find SvelteKit library: ' + has_sveltekit_library_result.message);
@@ -3,7 +3,7 @@ import { spawn } from '@fuzdev/fuz_util/process.js';
3
3
  import { styleText as st } from 'node:util';
4
4
  import { git_check_clean_workspace } from '@fuzdev/fuz_util/git.js';
5
5
  import { TaskError } from "./task.js";
6
- import { sync_package_json } from "./package_json.js";
6
+ import { package_json_sync } from "./package_json.js";
7
7
  /** @nodocs */
8
8
  export const Args = z.strictObject({
9
9
  typecheck: z.boolean().meta({ description: 'dual of no-typecheck' }).default(true),
@@ -54,7 +54,7 @@ export const task = {
54
54
  await invoke_task('gen', { check: true });
55
55
  }
56
56
  if (package_json && config.map_package_json) {
57
- const { changed } = await sync_package_json(config.map_package_json, log, false);
57
+ const { changed } = await package_json_sync(config.map_package_json, log, false);
58
58
  if (changed) {
59
59
  throw new TaskError('package.json is out of date, run `gro sync` to update it');
60
60
  }
@@ -1,6 +1,6 @@
1
1
  import prettier from 'prettier';
2
2
  import { extname } from 'node:path';
3
- import { load_package_json } from "./package_json.js";
3
+ import { package_json_load } from "./package_json.js";
4
4
  let cached_base_options;
5
5
  /**
6
6
  * Formats a file with Prettier.
@@ -11,7 +11,7 @@ let cached_base_options;
11
11
  export const format_file = async (content, options, base_options = cached_base_options) => {
12
12
  const final_base_options = base_options !== undefined
13
13
  ? base_options
14
- : (cached_base_options = (await load_package_json()).prettier);
14
+ : (cached_base_options = (await package_json_load()).prettier);
15
15
  let final_options = options;
16
16
  if (options.filepath && !options.parser) {
17
17
  const { filepath, ...rest } = options;
@@ -3,7 +3,7 @@ import { has_server, gro_plugin_server } from "./gro_plugin_server.js";
3
3
  import { gro_plugin_sveltekit_app } from "./gro_plugin_sveltekit_app.js";
4
4
  import { has_sveltekit_app, has_sveltekit_library } from "./sveltekit_helpers.js";
5
5
  import { gro_plugin_gen } from "./gro_plugin_gen.js";
6
- import { load_package_json } from "./package_json.js";
6
+ import { package_json_load } from "./package_json.js";
7
7
  // TODO hacky, maybe extract utils?
8
8
  /**
9
9
  * This is the default config that's passed to `gro.config.ts`
@@ -15,7 +15,7 @@ import { load_package_json } from "./package_json.js";
15
15
  * - if `src/lib/server/server.ts`, assumes a Node server - needs config
16
16
  */
17
17
  const config = async (cfg, svelte_config) => {
18
- 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`?
18
+ 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`?
19
19
  const [has_server_result, has_sveltekit_library_result, has_sveltekit_app_result] = await Promise.all([
20
20
  has_server(),
21
21
  has_sveltekit_library(package_json, svelte_config),
@@ -1,5 +1,5 @@
1
1
  import type { PathFilter, PathId } from '@fuzdev/fuz_util/path.js';
2
- import type { CreateConfigPlugins } from './plugin.ts';
2
+ import type { PluginsCreateConfig } from './plugin.ts';
3
3
  import type { PackageJsonMapper } from './package_json.ts';
4
4
  import type { ParsedSvelteConfig } from './svelte_config.ts';
5
5
  /**
@@ -16,7 +16,7 @@ export interface GroConfig extends RawGroConfig {
16
16
  /**
17
17
  * @see https://github.com/ryanatkn/gro/blob/main/src/docs/plugin.md
18
18
  */
19
- plugins: CreateConfigPlugins;
19
+ plugins: PluginsCreateConfig;
20
20
  /**
21
21
  * Maps the project's `package.json` before writing it to the filesystem.
22
22
  * The `package_json` argument may be mutated, but the return value is what's used by the caller.
@@ -57,7 +57,7 @@ export interface GroConfig extends RawGroConfig {
57
57
  * @see https://github.com/ryanatkn/gro/blob/main/src/docs/config.md
58
58
  */
59
59
  export interface RawGroConfig {
60
- plugins?: CreateConfigPlugins;
60
+ plugins?: PluginsCreateConfig;
61
61
  map_package_json?: PackageJsonMapper | null;
62
62
  task_root_dirs?: Array<string>;
63
63
  search_filters?: PathFilter | Array<PathFilter> | null;
@@ -1,35 +1,9 @@
1
1
  import type { Plugin } from './plugin.ts';
2
- import { type PackageJsonMapper } from './package_json.ts';
3
- import { type SourceJsonMapper } from './source_json.ts';
4
2
  export interface GroPluginSveltekitAppOptions {
5
- /**
6
- * Whether to include a `.nojekyll` file in the build output.
7
- * GitHub Pages processes files with Jekyll by default, breaking files/dirs prefixed with `_`.
8
- * The `.nojekyll` file tells GitHub Pages to skip Jekyll processing.
9
- *
10
- * @default `true` if the SvelteKit adapter name contains 'static'
11
- */
12
- include_nojekyll?: boolean;
13
- /**
14
- * If truthy, adds `/.well-known/package.json` to the static output.
15
- * If a function, maps the value.
16
- */
17
- well_known_package_json?: boolean | PackageJsonMapper;
18
- /**
19
- * If truthy, adds `/.well-known/source.json` and `/.well-known/src/` to the static output.
20
- * If a function, maps the value.
21
- */
22
- well_known_source_json?: boolean | SourceJsonMapper;
23
- /**
24
- * If truthy, copies `src/` to `/.well-known/src/` to the static output.
25
- * Pass a function to customize which files get copied.
26
- */
27
- well_known_src_files?: boolean | CopyFileFilter;
28
3
  /**
29
4
  * The Vite CLI to use.
30
5
  */
31
6
  vite_cli?: string;
32
7
  }
33
- export type CopyFileFilter = (file_path: string) => boolean;
34
- export declare const gro_plugin_sveltekit_app: ({ include_nojekyll, well_known_package_json, well_known_source_json, well_known_src_files, vite_cli, }?: GroPluginSveltekitAppOptions) => Plugin;
8
+ export declare const gro_plugin_sveltekit_app: ({ vite_cli, }?: GroPluginSveltekitAppOptions) => Plugin;
35
9
  //# sourceMappingURL=gro_plugin_sveltekit_app.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gro_plugin_sveltekit_app.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gro_plugin_sveltekit_app.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAExC,OAAO,EAAyB,KAAK,iBAAiB,EAAoB,MAAM,mBAAmB,CAAC;AAGpG,OAAO,EAAC,KAAK,gBAAgB,EAA4C,MAAM,kBAAkB,CAAC;AAKlG,MAAM,WAAW,4BAA4B;IAC5C;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;OAGG;IACH,uBAAuB,CAAC,EAAE,OAAO,GAAG,iBAAiB,CAAC;IAEtD;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,GAAG,gBAAgB,CAAC;IAEpD;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,GAAG,cAAc,CAAC;IAChD;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;AAE5D,eAAO,MAAM,wBAAwB,GAAI,yGAMtC,4BAAiC,KAAG,MAiHtC,CAAC"}
1
+ {"version":3,"file":"gro_plugin_sveltekit_app.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gro_plugin_sveltekit_app.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAMxC,MAAM,WAAW,4BAA4B;IAC5C;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,wBAAwB,GAAI,gBAEtC,4BAAiC,KAAG,MAqCtC,CAAC"}
@@ -1,19 +1,12 @@
1
- import { cp, mkdir, rm, writeFile } from 'node:fs/promises';
2
- import { dirname, join } from 'node:path';
3
- import { fs_exists } from '@fuzdev/fuz_util/fs.js';
4
1
  import { serialize_args, to_forwarded_args } from "./args.js";
5
- import { serialize_package_json, load_package_json } from "./package_json.js";
6
2
  import { TaskError } from "./task.js";
7
3
  import { find_cli, spawn_cli, spawn_cli_process } from "./cli.js";
8
- import { source_json_serialize, source_json_create } from "./source_json.js";
9
- import { EXPORTS_EXCLUDER_DEFAULT } from "./gro_config.js";
10
- import { default_svelte_config } from "./svelte_config.js";
11
- import { SOURCE_DIRNAME, VITE_CLI } from "./constants.js";
12
- export const gro_plugin_sveltekit_app = ({ include_nojekyll, well_known_package_json, well_known_source_json, well_known_src_files, vite_cli = VITE_CLI, } = {}) => {
4
+ import { VITE_CLI } from "./constants.js";
5
+ export const gro_plugin_sveltekit_app = ({ vite_cli = VITE_CLI, } = {}) => {
13
6
  let sveltekit_process = undefined;
14
7
  return {
15
8
  name: 'gro_plugin_sveltekit_app',
16
- setup: async ({ dev, watch, log, config, svelte_config }) => {
9
+ setup: async ({ dev, watch, log, config }) => {
17
10
  const found_vite_cli = await find_cli(vite_cli);
18
11
  if (!found_vite_cli)
19
12
  throw Error(`Failed to find Vite CLI \`${vite_cli}\`, do you need to run \`${config.pm_cli} i\`?`);
@@ -30,69 +23,11 @@ export const gro_plugin_sveltekit_app = ({ include_nojekyll, well_known_package_
30
23
  }
31
24
  else {
32
25
  // `vite build` in production mode
33
- // `.well-known/package.json`
34
- const package_json = await load_package_json(); // TODO put in plugin context? same with sveltekit config?
35
- if (well_known_package_json === undefined) {
36
- well_known_package_json = package_json.public; // eslint-disable-line no-param-reassign
26
+ const serialized_args = ['build', ...serialize_args(to_forwarded_args(vite_cli))];
27
+ const spawned = await spawn_cli(found_vite_cli, serialized_args, log);
28
+ if (!spawned?.ok) {
29
+ throw new TaskError(`${vite_cli} build failed with exit code ${spawned?.code}`);
37
30
  }
38
- const mapped_package_json = !well_known_package_json
39
- ? null
40
- : well_known_package_json === true
41
- ? package_json
42
- : await well_known_package_json(package_json);
43
- const serialized_package_json = mapped_package_json && serialize_package_json(mapped_package_json);
44
- // `.well-known/source.json` and `.well-known/src/`
45
- const final_package_json = mapped_package_json ?? package_json;
46
- const source_json = await source_json_create(final_package_json, undefined, log);
47
- if (well_known_source_json === undefined) {
48
- well_known_source_json = final_package_json.public; // eslint-disable-line no-param-reassign
49
- }
50
- const mapped_source_json = !well_known_source_json
51
- ? null
52
- : well_known_source_json === true
53
- ? source_json
54
- : await well_known_source_json(source_json);
55
- const serialized_source_json = mapped_source_json && source_json_serialize(mapped_source_json);
56
- // TODO this strategy means the files aren't available during development --
57
- // maybe a Vite middleware is best? what if this plugin added its plugin to your `vite.config.ts`?
58
- // copy files to `static` before building, in such a way
59
- // that's non-destructive to existing files and dirs and easy to clean up
60
- const { assets_path } = default_svelte_config;
61
- // detect whether to include .nojekyll based on adapter if not explicitly set
62
- const adapter_name = svelte_config.svelte_config?.kit?.adapter?.name;
63
- const should_include_nojekyll = include_nojekyll ?? (adapter_name ? adapter_name.includes('static') : false);
64
- const cleanup_promises = [
65
- serialized_package_json
66
- ? create_temporarily(join(assets_path, '.well-known/package.json'), serialized_package_json)
67
- : null,
68
- serialized_source_json
69
- ? create_temporarily(join(assets_path, '.well-known/source.json'), serialized_source_json)
70
- : null,
71
- serialized_source_json && well_known_src_files
72
- ? copy_temporarily(SOURCE_DIRNAME, assets_path, '.well-known', well_known_src_files === true
73
- ? (file_path) => !EXPORTS_EXCLUDER_DEFAULT.test(file_path)
74
- : well_known_src_files)
75
- : null,
76
- should_include_nojekyll ? create_temporarily(join(assets_path, '.nojekyll'), '') : null,
77
- ].filter((v) => v != null);
78
- const cleanups = await Promise.all(cleanup_promises);
79
- const cleanup = async () => {
80
- // eslint-disable-next-line no-await-in-loop
81
- for (const c of cleanups)
82
- await c();
83
- };
84
- try {
85
- const serialized_args = ['build', ...serialize_args(to_forwarded_args(vite_cli))];
86
- const spawned = await spawn_cli(found_vite_cli, serialized_args, log);
87
- if (!spawned?.ok) {
88
- throw new TaskError(`${vite_cli} build failed with exit code ${spawned?.code}`);
89
- }
90
- }
91
- catch (error) {
92
- await cleanup();
93
- throw error;
94
- }
95
- await cleanup();
96
31
  }
97
32
  },
98
33
  teardown: async () => {
@@ -103,87 +38,3 @@ export const gro_plugin_sveltekit_app = ({ include_nojekyll, well_known_package_
103
38
  },
104
39
  };
105
40
  };
106
- // TODO probably extract these, and create a common helper or merge them
107
- const copy_temporarily = async (source_path, dest_dir, dest_base_dir = '', filter) => {
108
- const path = join(dest_dir, dest_base_dir, source_path);
109
- const dir = dirname(path);
110
- const dir_already_exists = await fs_exists(dir);
111
- let root_created_dir;
112
- if (!dir_already_exists) {
113
- root_created_dir = await to_root_dir_that_doesnt_exist(dir);
114
- if (!root_created_dir)
115
- throw Error();
116
- await mkdir(dir, { recursive: true });
117
- }
118
- const path_already_exists = await fs_exists(path);
119
- if (!path_already_exists) {
120
- await cp(source_path, path, { recursive: true, filter });
121
- }
122
- return async () => {
123
- if (!dir_already_exists) {
124
- if (!root_created_dir)
125
- throw Error();
126
- if (await fs_exists(root_created_dir)) {
127
- await rm(root_created_dir, { recursive: true });
128
- }
129
- }
130
- else if (!path_already_exists) {
131
- if (await fs_exists(path)) {
132
- await rm(path, { recursive: true });
133
- }
134
- }
135
- };
136
- };
137
- /**
138
- * Creates a file at `path` with `contents` if it doesn't already exist,
139
- * and returns a function that deletes the file and any created directories.
140
- * @param path
141
- * @param contents
142
- * @returns cleanup function that deletes the file and any created dirs
143
- */
144
- const create_temporarily = async (path, contents) => {
145
- const dir = dirname(path);
146
- const dir_already_exists = await fs_exists(dir);
147
- let root_created_dir;
148
- if (!dir_already_exists) {
149
- root_created_dir = await to_root_dir_that_doesnt_exist(dir);
150
- if (!root_created_dir)
151
- throw Error();
152
- await mkdir(dir, { recursive: true });
153
- }
154
- const path_already_exists = await fs_exists(path);
155
- if (!path_already_exists) {
156
- await writeFile(path, contents, 'utf8');
157
- }
158
- return async () => {
159
- if (!dir_already_exists) {
160
- if (!root_created_dir)
161
- throw Error();
162
- if (await fs_exists(root_created_dir)) {
163
- await rm(root_created_dir, { recursive: true });
164
- }
165
- }
166
- else if (!path_already_exists) {
167
- if (await fs_exists(path)) {
168
- await rm(path);
169
- }
170
- }
171
- };
172
- };
173
- /**
174
- * Niche and probably needs refactoring,
175
- * for `/a/b/DOESNT_EXIST/NOR_THIS/ETC` returns `/a/b/DOESNT_EXIST`
176
- * where `/a/b` does exist on the filesystem and `DOESNT_EXIST` is not one of its subdirectories.
177
- */
178
- const to_root_dir_that_doesnt_exist = async (dir) => {
179
- let prev;
180
- let d = dir;
181
- do {
182
- // eslint-disable-next-line no-await-in-loop
183
- if (await fs_exists(d)) {
184
- return prev;
185
- }
186
- prev = d;
187
- } while ((d = dirname(d)));
188
- throw Error('no dirs exist for ' + dir);
189
- };
@@ -1,6 +1,6 @@
1
1
  import { print_spawn_result, spawn } from '@fuzdev/fuz_util/process.js';
2
2
  import { TaskError } from "./task.js";
3
- import { load_package_json } from "./package_json.js";
3
+ import { package_json_load } from "./package_json.js";
4
4
  import { run_svelte_package } from "./sveltekit_helpers.js";
5
5
  import { SVELTE_PACKAGE_CLI } from "./constants.js";
6
6
  export const gro_plugin_sveltekit_library = ({ svelte_package_options, svelte_package_cli = SVELTE_PACKAGE_CLI, } = {}) => {
@@ -8,12 +8,12 @@ export const gro_plugin_sveltekit_library = ({ svelte_package_options, svelte_pa
8
8
  name: 'gro_plugin_sveltekit_library',
9
9
  setup: async ({ dev, log, config }) => {
10
10
  if (!dev) {
11
- const package_json = await load_package_json();
11
+ const package_json = await package_json_load();
12
12
  await run_svelte_package(package_json, svelte_package_options, svelte_package_cli, log, config.pm_cli);
13
13
  }
14
14
  },
15
15
  adapt: async ({ log, timings, config }) => {
16
- const package_json = await load_package_json();
16
+ const package_json = await package_json_load();
17
17
  // link the CLI binaries if they exist
18
18
  if (package_json.bin) {
19
19
  const timing_to_link = timings.start(`${config.pm_cli} link`);
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /** @nodocs */
2
2
  export type { GroConfig, CreateGroConfig, RawGroConfig } from './gro_config.ts';
3
3
  /** @nodocs */
4
- export { type Plugin, replace_plugin } from './plugin.ts';
4
+ export { type Plugin, plugin_replace } from './plugin.ts';
5
5
  /** @nodocs */
6
6
  export type { Gen, GenContext } from './gen.ts';
7
7
  /** @nodocs */
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  /** @nodocs */
2
- export { replace_plugin } from "./plugin.js";
2
+ export { plugin_replace } from "./plugin.js";
3
3
  /** @nodocs */
4
4
  export { TaskError } from "./task.js";
@@ -6,7 +6,7 @@ import { to_forwarded_args } from "./args.js";
6
6
  import { run_task } from "./run_task.js";
7
7
  import { to_input_path, RawInputPath } from "./input_path.js";
8
8
  import { find_tasks, load_tasks, SilentError } from "./task.js";
9
- import { load_gro_package_json } from "./package_json.js";
9
+ import { package_json_load_for_gro } from "./package_json.js";
10
10
  import { log_tasks, log_error_reasons } from "./task_logging.js";
11
11
  import { Filer } from "./filer.js";
12
12
  /**
@@ -54,7 +54,7 @@ export const invoke_task = async (task_name, args, config, initial_filer, initia
54
54
  };
55
55
  // Check if the caller just wants to see the version.
56
56
  if (!task_name && (args?.version || args?.v)) {
57
- const gro_package_json = await load_gro_package_json();
57
+ const gro_package_json = await package_json_load_for_gro();
58
58
  log.info(`${st('gray', 'v')}${st('cyan', gro_package_json.version)}`);
59
59
  await finish();
60
60
  return;
@@ -1,32 +1,32 @@
1
1
  import type { Logger } from '@fuzdev/fuz_util/log.js';
2
2
  import { PackageJson, PackageJsonExports } from '@fuzdev/fuz_util/package_json.js';
3
3
  export type PackageJsonMapper = (package_json: PackageJson) => PackageJson | null | Promise<PackageJson | null>;
4
- export declare const EMPTY_PACKAGE_JSON: PackageJson;
5
- export declare const load_package_json: (dir?: string, cache?: Record<string, PackageJson>, parse?: boolean, // TODO pass `false` here in more places, especially anything perf-sensitive like work on startup
4
+ export declare const PACKAGE_JSON_EMPTY: PackageJson;
5
+ export declare const package_json_load: (dir?: string, cache?: Record<string, PackageJson>, parse?: boolean, // TODO pass `false` here in more places, especially anything perf-sensitive like work on startup
6
6
  log?: Logger) => Promise<PackageJson>;
7
- export declare const sync_package_json: (map_package_json: PackageJsonMapper, log: Logger, write?: boolean, dir?: string, exports_dir?: string) => Promise<{
7
+ export declare const package_json_sync: (map_package_json: PackageJsonMapper, log: Logger, write?: boolean, dir?: string, exports_dir?: string) => Promise<{
8
8
  package_json: PackageJson | null;
9
9
  changed: boolean;
10
10
  }>;
11
- export declare const load_gro_package_json: () => Promise<PackageJson>;
12
- export declare const write_package_json: (serialized_package_json: string) => Promise<void>;
13
- export declare const serialize_package_json: (package_json: PackageJson) => string;
11
+ export declare const package_json_load_for_gro: () => Promise<PackageJson>;
12
+ export declare const package_json_write: (serialized_package_json: string) => Promise<void>;
13
+ export declare const package_json_serialize: (package_json: PackageJson) => string;
14
14
  /**
15
15
  * Updates package.json. Writes to the filesystem only when contents change.
16
16
  */
17
- export declare const update_package_json: (update: (package_json: PackageJson) => PackageJson | null | Promise<PackageJson | null>, dir?: string, write?: boolean) => Promise<{
17
+ export declare const package_json_update: (update: (package_json: PackageJson) => PackageJson | null | Promise<PackageJson | null>, dir?: string, write?: boolean) => Promise<{
18
18
  package_json: PackageJson | null;
19
19
  changed: boolean;
20
20
  }>;
21
- export declare const to_package_exports: (paths: Array<string>) => PackageJsonExports;
22
- export declare const parse_repo_url: (package_json: PackageJson) => {
21
+ export declare const package_json_to_exports: (paths: Array<string>) => PackageJsonExports;
22
+ export declare const package_json_parse_repo_url: (package_json: PackageJson) => {
23
23
  owner: string;
24
24
  repo: string;
25
25
  } | undefined;
26
- export declare const has_dep: (dep_name: string, package_json: PackageJson) => boolean;
26
+ export declare const package_json_has_dependency: (dep_name: string, package_json: PackageJson) => boolean;
27
27
  export interface PackageJsonDep {
28
28
  name: string;
29
29
  version: string;
30
30
  }
31
- export declare const extract_deps: (package_json: PackageJson) => Array<PackageJsonDep>;
31
+ export declare const package_json_extract_dependencies: (package_json: PackageJson) => Array<PackageJsonDep>;
32
32
  //# sourceMappingURL=package_json.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"package_json.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/package_json.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAC,WAAW,EAAE,kBAAkB,EAAC,MAAM,kCAAkC,CAAC;AAgBjF,MAAM,MAAM,iBAAiB,GAAG,CAC/B,YAAY,EAAE,WAAW,KACrB,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;AAEtD,eAAO,MAAM,kBAAkB,EAAE,WAAqC,CAAC;AAEvE,eAAO,MAAM,iBAAiB,GAC7B,YAA+C,EAC/C,QAAQ,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACnC,eAAY,EAAE,iGAAiG;AAC/G,MAAM,MAAM,KACV,OAAO,CAAC,WAAW,CAkBrB,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC7B,kBAAkB,iBAAiB,EACnC,KAAK,MAAM,EACX,eAAY,EACZ,YAAgB,EAChB,oBAAuB,KACrB,OAAO,CAAC;IAAC,YAAY,EAAE,WAAW,GAAG,IAAI,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAC,CA0B9D,CAAC;AAEF,eAAO,MAAM,qBAAqB,QAAO,OAAO,CAAC,WAAW,CAAsC,CAAC;AAMnG,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MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,iCAAiC,GAC7C,cAAc,WAAW,KACvB,KAAK,CAAC,cAAc,CAetB,CAAC"}
@@ -9,19 +9,19 @@ import { paths, gro_paths, IS_THIS_GRO } from "./paths.js";
9
9
  import { PACKAGE_JSON_FILENAME, SVELTEKIT_DIST_DIRNAME, TS_MATCHER, JS_MATCHER, SVELTE_MATCHER, JSON_MATCHER, CSS_MATCHER, } from "./constants.js";
10
10
  import { has_sveltekit_library } from "./sveltekit_helpers.js";
11
11
  import { GITHUB_REPO_MATCHER } from "./github.js";
12
- export const EMPTY_PACKAGE_JSON = { name: '', version: '' };
13
- export const load_package_json = async (dir = IS_THIS_GRO ? gro_paths.root : paths.root, cache, parse = true, // TODO pass `false` here in more places, especially anything perf-sensitive like work on startup
12
+ export const PACKAGE_JSON_EMPTY = { name: '', version: '' };
13
+ export const package_json_load = async (dir = IS_THIS_GRO ? gro_paths.root : paths.root, cache, parse = true, // TODO pass `false` here in more places, especially anything perf-sensitive like work on startup
14
14
  log) => {
15
15
  let package_json;
16
16
  if (cache && dir in cache) {
17
17
  return cache[dir];
18
18
  }
19
19
  try {
20
- package_json = JSON.parse(await load_package_json_contents(dir));
20
+ package_json = JSON.parse(await package_json_load_contents(dir));
21
21
  }
22
22
  catch (error) {
23
23
  log?.error(st('yellow', `Failed to load package.json in ${dir}`), error);
24
- return EMPTY_PACKAGE_JSON;
24
+ return PACKAGE_JSON_EMPTY;
25
25
  }
26
26
  if (parse) {
27
27
  package_json = parse_package_json(PackageJson, package_json);
@@ -31,12 +31,12 @@ log) => {
31
31
  }
32
32
  return package_json;
33
33
  };
34
- export const sync_package_json = async (map_package_json, log, write = true, dir = paths.root, exports_dir = paths.lib) => {
34
+ export const package_json_sync = async (map_package_json, log, write = true, dir = paths.root, exports_dir = paths.lib) => {
35
35
  const exported_files = await fs_search(exports_dir);
36
36
  const exported_paths = exported_files.map((f) => f.path);
37
- const updated = await update_package_json(async (package_json) => {
37
+ const updated = await package_json_update(async (package_json) => {
38
38
  if ((await has_sveltekit_library(package_json)).ok) {
39
- package_json.exports = to_package_exports(exported_paths);
39
+ package_json.exports = package_json_to_exports(exported_paths);
40
40
  }
41
41
  const mapped = await map_package_json(package_json);
42
42
  return mapped ? parse_package_json(PackageJson, mapped) : mapped;
@@ -49,31 +49,31 @@ export const sync_package_json = async (map_package_json, log, write = true, dir
49
49
  : 'no changes to exports in package.json');
50
50
  return updated;
51
51
  };
52
- export const load_gro_package_json = () => load_package_json(gro_paths.root);
52
+ export const package_json_load_for_gro = () => package_json_load(gro_paths.root);
53
53
  // TODO probably make this nullable and make callers handle failures
54
- const load_package_json_contents = (dir) => readFile(join(dir, PACKAGE_JSON_FILENAME), 'utf8');
55
- export const write_package_json = (serialized_package_json) => writeFile(join(paths.root, PACKAGE_JSON_FILENAME), serialized_package_json);
56
- export const serialize_package_json = (package_json) => JSON.stringify(parse_package_json(PackageJson, package_json), null, 2) + '\n';
54
+ const package_json_load_contents = (dir) => readFile(join(dir, PACKAGE_JSON_FILENAME), 'utf8');
55
+ export const package_json_write = (serialized_package_json) => writeFile(join(paths.root, PACKAGE_JSON_FILENAME), serialized_package_json);
56
+ export const package_json_serialize = (package_json) => JSON.stringify(parse_package_json(PackageJson, package_json), null, 2) + '\n';
57
57
  /**
58
58
  * Updates package.json. Writes to the filesystem only when contents change.
59
59
  */
60
- export const update_package_json = async (update, dir = paths.root, write = true) => {
61
- const original_contents = await load_package_json_contents(dir);
60
+ export const package_json_update = async (update, dir = paths.root, write = true) => {
61
+ const original_contents = await package_json_load_contents(dir);
62
62
  const original = JSON.parse(original_contents);
63
63
  const updated = await update(original);
64
64
  if (updated === null) {
65
65
  return { package_json: original, changed: false };
66
66
  }
67
- const updated_contents = serialize_package_json(updated);
67
+ const updated_contents = package_json_serialize(updated);
68
68
  if (updated_contents === original_contents) {
69
69
  return { package_json: original, changed: false };
70
70
  }
71
71
  if (write)
72
- await write_package_json(updated_contents);
72
+ await package_json_write(updated_contents);
73
73
  return { package_json: updated, changed: true };
74
74
  };
75
75
  const is_index = (path) => path === 'index.ts' || path === 'index.js';
76
- export const to_package_exports = (paths) => {
76
+ export const package_json_to_exports = (paths) => {
77
77
  const has_index = paths.some(is_index);
78
78
  const has_js = paths.some((p) => TS_MATCHER.test(p) || JS_MATCHER.test(p));
79
79
  const has_svelte = paths.some((p) => SVELTE_MATCHER.test(p));
@@ -119,7 +119,7 @@ export const to_package_exports = (paths) => {
119
119
  return parse_or_throw_formatted_error('package.json#exports', PackageJsonExports, exports);
120
120
  };
121
121
  const IMPORT_PREFIX = './' + SVELTEKIT_DIST_DIRNAME + '/';
122
- export const parse_repo_url = (package_json) => {
122
+ export const package_json_parse_repo_url = (package_json) => {
123
123
  const { repository } = package_json;
124
124
  const repo_url = repository
125
125
  ? typeof repository === 'string'
@@ -156,10 +156,10 @@ const parse_or_throw_formatted_error = (name, schema, value) => {
156
156
  }
157
157
  return parsed.data;
158
158
  };
159
- export const has_dep = (dep_name, package_json) => !!package_json.devDependencies?.[dep_name] ||
159
+ export const package_json_has_dependency = (dep_name, package_json) => !!package_json.devDependencies?.[dep_name] ||
160
160
  !!package_json.dependencies?.[dep_name] ||
161
161
  !!package_json.peerDependencies?.[dep_name];
162
- export const extract_deps = (package_json) => {
162
+ export const package_json_extract_dependencies = (package_json) => {
163
163
  const deps_by_name = new Map();
164
164
  // Earlier versions override later ones, so peer deps goes last.
165
165
  const add_deps = (deps) => {
package/dist/plugin.d.ts CHANGED
@@ -9,7 +9,7 @@ export interface Plugin<TPluginContext extends PluginContext = PluginContext> {
9
9
  adapt?: (ctx: TPluginContext) => void | Promise<void>;
10
10
  teardown?: (ctx: TPluginContext) => void | Promise<void>;
11
11
  }
12
- export type CreateConfigPlugins<TPluginContext extends PluginContext = PluginContext> = (ctx: TPluginContext) => Array<Plugin<TPluginContext>> | Promise<Array<Plugin<TPluginContext>>>;
12
+ export type PluginsCreateConfig<TPluginContext extends PluginContext = PluginContext> = (ctx: TPluginContext) => Array<Plugin<TPluginContext>> | Promise<Array<Plugin<TPluginContext>>>;
13
13
  export interface PluginContext<TArgs = object> extends TaskContext<TArgs> {
14
14
  dev: boolean;
15
15
  watch: boolean;
@@ -27,10 +27,10 @@ export declare class Plugins<TPluginContext extends PluginContext> {
27
27
  /**
28
28
  * Replaces a plugin by name in `plugins` without mutating the param.
29
29
  * Throws if the plugin name cannot be found.
30
- * @param plugins - accepts the same types as the return value of `CreateConfigPlugins`
30
+ * @param plugins - accepts the same types as the return value of `PluginsCreateConfig`
31
31
  * @param new_plugin
32
32
  * @param name - @default new_plugin.name
33
33
  * @returns `plugins` with `new_plugin` at the index of the plugin with `name`
34
34
  */
35
- export declare const replace_plugin: (plugins: Array<Plugin>, new_plugin: Plugin, name?: string) => Array<Plugin>;
35
+ export declare const plugin_replace: (plugins: Array<Plugin>, new_plugin: Plugin, name?: string) => Array<Plugin>;
36
36
  //# sourceMappingURL=plugin.d.ts.map
package/dist/plugin.js CHANGED
@@ -63,12 +63,12 @@ export class Plugins {
63
63
  /**
64
64
  * Replaces a plugin by name in `plugins` without mutating the param.
65
65
  * Throws if the plugin name cannot be found.
66
- * @param plugins - accepts the same types as the return value of `CreateConfigPlugins`
66
+ * @param plugins - accepts the same types as the return value of `PluginsCreateConfig`
67
67
  * @param new_plugin
68
68
  * @param name - @default new_plugin.name
69
69
  * @returns `plugins` with `new_plugin` at the index of the plugin with `name`
70
70
  */
71
- export const replace_plugin = (plugins, new_plugin, name = new_plugin.name) => {
71
+ export const plugin_replace = (plugins, new_plugin, name = new_plugin.name) => {
72
72
  const index = plugins.findIndex((p) => p.name === name);
73
73
  if (index === -1)
74
74
  throw Error('Failed to find plugin to replace: ' + name);
@@ -4,7 +4,7 @@ import { styleText as st } from 'node:util';
4
4
  import { fs_exists } from '@fuzdev/fuz_util/fs.js';
5
5
  import { GitBranch, GitOrigin, git_check_clean_workspace, git_checkout, git_fetch, git_pull, } from '@fuzdev/fuz_util/git.js';
6
6
  import { TaskError } from "./task.js";
7
- import { load_package_json, parse_repo_url } from "./package_json.js";
7
+ import { package_json_load, package_json_parse_repo_url } from "./package_json.js";
8
8
  import { find_cli, spawn_cli } from "./cli.js";
9
9
  import { has_sveltekit_library } from "./sveltekit_helpers.js";
10
10
  import { update_changelog } from "./changelog.js";
@@ -59,7 +59,7 @@ export const task = {
59
59
  if (dry) {
60
60
  log.info(st('green', 'dry run!'));
61
61
  }
62
- const package_json = await load_package_json();
62
+ const package_json = await package_json_load();
63
63
  const has_sveltekit_library_result = await has_sveltekit_library(package_json);
64
64
  if (!has_sveltekit_library_result.ok) {
65
65
  throw new TaskError('Failed to find SvelteKit library: ' + has_sveltekit_library_result.message);
@@ -104,7 +104,7 @@ export const task = {
104
104
  if (typeof package_json.version !== 'string') {
105
105
  throw new TaskError('Failed to find package.json version');
106
106
  }
107
- const parsed_repo_url = parse_repo_url(package_json);
107
+ const parsed_repo_url = package_json_parse_repo_url(package_json);
108
108
  if (!parsed_repo_url) {
109
109
  throw new TaskError('package.json `repository` must contain a repo url (and GitHub only for now, sorry),' +
110
110
  ' like `git+https://github.com/ryanatkn/gro.git` or `https://github.com/ryanatkn/gro`' +
@@ -132,7 +132,7 @@ export const task = {
132
132
  // Regenerate files that depend on package.json version.
133
133
  // The check above ensures gen is updated.
134
134
  await invoke_task('gen');
135
- const package_json_after_versioning = await load_package_json();
135
+ const package_json_after_versioning = await package_json_load();
136
136
  version = package_json_after_versioning.version;
137
137
  if (package_json.version === version) {
138
138
  // The version didn't change.
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { has_sveltekit_library, has_sveltekit_app } from "./sveltekit_helpers.js";
3
- import { load_package_json } from "./package_json.js";
3
+ import { package_json_load } from "./package_json.js";
4
4
  /** @nodocs */
5
5
  export const Args = z.strictObject({});
6
6
  /** @nodocs */
@@ -8,7 +8,7 @@ export const task = {
8
8
  summary: 'publish and deploy',
9
9
  Args,
10
10
  run: async ({ invoke_task }) => {
11
- const package_json = await load_package_json();
11
+ const package_json = await package_json_load();
12
12
  const publish = (await has_sveltekit_library(package_json)).ok;
13
13
  if (publish) {
14
14
  await invoke_task('publish', { optional: true });