@ryanatkn/gro 0.128.0 → 0.129.1

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 (82) hide show
  1. package/README.md +5 -5
  2. package/dist/args.d.ts +2 -2
  3. package/dist/args.js +2 -2
  4. package/dist/changelog.js +1 -1
  5. package/dist/changelog.test.js +2 -2
  6. package/dist/changeset.task.js +6 -6
  7. package/dist/cli.js +1 -1
  8. package/dist/config.d.ts +1 -3
  9. package/dist/config.js +2 -2
  10. package/dist/deploy.task.js +1 -1
  11. package/dist/docs/README.gen.md.js +1 -1
  12. package/dist/docs/dev.md +1 -1
  13. package/dist/docs/package_json.md +2 -1
  14. package/dist/env.d.ts +2 -2
  15. package/dist/env.js +10 -11
  16. package/dist/esbuild_helpers.js +2 -1
  17. package/dist/esbuild_plugin_external_worker.js +1 -1
  18. package/dist/esbuild_plugin_svelte.js +3 -3
  19. package/dist/esbuild_plugin_sveltekit_local_imports.js +2 -2
  20. package/dist/esbuild_plugin_sveltekit_shim_env.js +2 -2
  21. package/dist/format_file.js +2 -2
  22. package/dist/gen.d.ts +10 -12
  23. package/dist/gen.js +3 -3
  24. package/dist/gen.task.js +1 -1
  25. package/dist/gen.test.js +2 -5
  26. package/dist/git.d.ts +2 -2
  27. package/dist/gro.config.default.js +1 -1
  28. package/dist/gro.js +2 -2
  29. package/dist/gro_helpers.d.ts +6 -1
  30. package/dist/gro_helpers.js +22 -11
  31. package/dist/gro_plugin_gen.js +3 -4
  32. package/dist/gro_plugin_server.d.ts +5 -7
  33. package/dist/gro_plugin_server.js +3 -3
  34. package/dist/gro_plugin_sveltekit_app.d.ts +3 -5
  35. package/dist/gro_plugin_sveltekit_app.js +38 -28
  36. package/dist/gro_plugin_sveltekit_library.d.ts +2 -2
  37. package/dist/gro_plugin_sveltekit_library.js +2 -2
  38. package/dist/input_path.test.js +1 -1
  39. package/dist/invoke_task.js +3 -3
  40. package/dist/lint.task.js +1 -2
  41. package/dist/loader.js +3 -3
  42. package/dist/package.d.ts +8 -10
  43. package/dist/package.gen.js +3 -3
  44. package/dist/package.js +20 -16
  45. package/dist/package_json.d.ts +4 -6
  46. package/dist/package_json.js +14 -15
  47. package/dist/package_json.test.js +12 -12
  48. package/dist/path.d.ts +2 -6
  49. package/dist/plugin.d.ts +1 -3
  50. package/dist/plugin.js +2 -2
  51. package/dist/plugin.test.js +3 -3
  52. package/dist/publish.task.js +4 -4
  53. package/dist/reinstall.task.js +1 -1
  54. package/dist/release.task.js +2 -2
  55. package/dist/resolve.task.js +1 -1
  56. package/dist/resolve_node_specifier.d.ts +1 -1
  57. package/dist/resolve_node_specifier.js +2 -2
  58. package/dist/resolve_node_specifier.test.js +6 -6
  59. package/dist/resolve_specifier.d.ts +1 -1
  60. package/dist/resolve_specifier.js +1 -1
  61. package/dist/resolve_specifier.test.js +16 -16
  62. package/dist/run.task.js +1 -1
  63. package/dist/run_gen.test.js +11 -11
  64. package/dist/run_task.js +1 -1
  65. package/dist/run_task.test.js +3 -2
  66. package/dist/src_json.d.ts +3 -5
  67. package/dist/src_json.js +11 -13
  68. package/dist/src_json.test.js +2 -2
  69. package/dist/sveltekit_config.js +1 -1
  70. package/dist/sveltekit_helpers.d.ts +4 -4
  71. package/dist/sveltekit_helpers.js +4 -4
  72. package/dist/sveltekit_shim_env.d.ts +1 -1
  73. package/dist/sveltekit_shim_env.js +2 -2
  74. package/dist/task.d.ts +1 -1
  75. package/dist/task_logging.d.ts +1 -1
  76. package/dist/task_logging.js +3 -4
  77. package/dist/upgrade.task.js +1 -1
  78. package/dist/watch_dir.d.ts +1 -3
  79. package/dist/watch_dir.js +6 -6
  80. package/package.json +20 -22
  81. package/dist/fs.test.d.ts +0 -1
  82. package/dist/fs.test.js +0 -16
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # gro <img src="static/favicon.png" width="32" height="32">
1
+ # gro <img src="static/logo.svg" alt="a pixelated green oak acorn with a glint of sun" width="32" height="32">
2
2
 
3
- <img src="static/favicon.png" align="right" width="192" height="192">
3
+ [<img src="static/logo.svg" alt="a pixelated green oak acorn with a glint of sun" align="right" width="192" height="192">](https://gro.ryanatkn.com/)
4
4
 
5
5
  > task runner and toolkit extending SvelteKit 🌰 generate, run, optimize
6
6
 
@@ -237,13 +237,13 @@ For more see [the tasks index](/src/lib/docs/tasks.md),
237
237
 
238
238
  ```bash
239
239
  npm i
240
- npm run build # build and link `gro` - needed only once
241
- gro build # same as `npm run build` when the `gro` CLI is available
240
+ npm run bootstrap # build and link `gro` without itself - needed only once
241
+ gro build # same as `npm run bootstrap` when the `gro` CLI is available
242
242
  gro test # make sure everything looks good - same as `npm test`
243
243
  gro test some.test another.test
244
244
 
245
245
  # use your development version of `gro` locally in another project:
246
- gro build # updates the `gro` CLI, same as `npm run build`
246
+ gro build # updates the `gro` CLI, same as `npm run bootstrap`
247
247
  cd ../otherproject
248
248
  npm link ../gro # from `otherproject/`
249
249
  gro build # from `../gro` on changes
package/dist/args.d.ts CHANGED
@@ -54,6 +54,6 @@ export declare const to_raw_rest_args: (argv?: string[]) => string[];
54
54
  * the `command` `'eslint'` returns `eslintarg1 --eslintarg2`
55
55
  * and `'tsc'` returns `--tscarg1` and `--tscarg2`.
56
56
  */
57
- export declare const to_forwarded_args: (command: string, raw_rest_args?: string[], cache?: Record<string, Args>) => Args;
58
- export declare const to_forwarded_args_by_command: (raw_rest_args?: string[]) => Record<string, Args>;
57
+ export declare const to_forwarded_args: (command: string, raw_rest_args?: string[], cache?: Record<string, Args | undefined>) => Args;
58
+ export declare const to_forwarded_args_by_command: (raw_rest_args?: string[]) => Record<string, Args | undefined>;
59
59
  export declare const print_command_args: (serialized_args: string[]) => string;
package/dist/args.js CHANGED
@@ -69,7 +69,7 @@ export const serialize_args = (args) => {
69
69
  export const to_task_args = (argv = process.argv) => {
70
70
  const forwarded_index = argv.indexOf('--');
71
71
  const args = mri(forwarded_index === -1 ? argv.slice(2) : argv.slice(2, forwarded_index));
72
- const task_name = args._.shift() || '';
72
+ const task_name = args._.shift() ?? '';
73
73
  if (!args._.length)
74
74
  delete args._; // enable schema defaults
75
75
  return { task_name, args };
@@ -87,7 +87,7 @@ export const to_raw_rest_args = (argv = process.argv) => {
87
87
  * the `command` `'eslint'` returns `eslintarg1 --eslintarg2`
88
88
  * and `'tsc'` returns `--tscarg1` and `--tscarg2`.
89
89
  */
90
- export const to_forwarded_args = (command, raw_rest_args, cache = to_forwarded_args_by_command(raw_rest_args)) => cache[command] || {};
90
+ export const to_forwarded_args = (command, raw_rest_args, cache = to_forwarded_args_by_command(raw_rest_args)) => cache[command] ?? {};
91
91
  export const to_forwarded_args_by_command = (raw_rest_args = to_raw_rest_args()) => {
92
92
  // Parse each segment of `argv` separated by `--`.
93
93
  const argvs = [];
package/dist/changelog.js CHANGED
@@ -1,4 +1,4 @@
1
- import { readFile, writeFile } from 'fs/promises';
1
+ import { readFile, writeFile } from 'node:fs/promises';
2
2
  import { z } from 'zod';
3
3
  import { github_fetch_commit_prs } from './github.js';
4
4
  /**
@@ -1,11 +1,11 @@
1
1
  import { test } from 'uvu';
2
2
  import * as assert from 'uvu/assert';
3
3
  import { Logger } from '@ryanatkn/belt/log.js';
4
- import { readFile, writeFile } from 'fs/promises';
4
+ import { readFile, writeFile } from 'node:fs/promises';
5
5
  import { update_changelog } from './changelog.js';
6
6
  import { load_from_env } from './env.js';
7
7
  const log = new Logger();
8
- const token = await load_from_env('GITHUB_TOKEN_SECRET');
8
+ const token = load_from_env('GITHUB_TOKEN_SECRET');
9
9
  if (!token) {
10
10
  log.warn('the env var GITHUB_TOKEN_SECRET was not found, so API calls with be unauthorized');
11
11
  }
@@ -5,11 +5,11 @@ import { readFile, writeFile } from 'node:fs/promises';
5
5
  import { join } from 'node:path';
6
6
  import { existsSync, readdirSync } from 'node:fs';
7
7
  import { Task_Error } from './task.js';
8
- import { load_package_json } from './package_json.js';
9
8
  import { find_cli, spawn_cli } from './cli.js';
10
9
  import { Git_Origin, git_check_fully_staged_workspace, git_push_to_create } from './git.js';
11
10
  import { has_sveltekit_library } from './sveltekit_helpers.js';
12
11
  import { CHANGESET_CLI, CHANGESET_DIR, Changeset_Access, Changeset_Bump, CHANGESET_PUBLIC_ACCESS, CHANGESET_RESTRICTED_ACCESS, } from './changeset_helpers.js';
12
+ import { load_package_json } from './package_json.js';
13
13
  export const Args = z
14
14
  .object({
15
15
  /**
@@ -44,7 +44,7 @@ export const task = {
44
44
  summary: 'call changeset with gro patterns',
45
45
  Args,
46
46
  run: async (ctx) => {
47
- const { invoke_task, args: { _, minor, major, dir, access: access_arg, changelog, install, origin, changeset_cli }, log, } = ctx;
47
+ const { invoke_task, args: { _, minor, major, dir, access: access_arg, changelog, install, origin, changeset_cli }, log, sveltekit_config, } = ctx;
48
48
  const message = _.join(' ');
49
49
  if (!message && (minor || major))
50
50
  throw new Task_Error('cannot bump version without a message');
@@ -55,8 +55,8 @@ export const task = {
55
55
  if (!found_changeset_cli) {
56
56
  throw new Task_Error('changeset command not found: install @changesets/cli locally or globally');
57
57
  }
58
- const package_json = await load_package_json();
59
- const has_sveltekit_library_result = await has_sveltekit_library(package_json);
58
+ const package_json = load_package_json();
59
+ const has_sveltekit_library_result = has_sveltekit_library(package_json, sveltekit_config);
60
60
  if (!has_sveltekit_library_result.ok) {
61
61
  throw new Task_Error('Failed to find SvelteKit library: ' + has_sveltekit_library_result.message);
62
62
  }
@@ -84,7 +84,7 @@ export const task = {
84
84
  await invoke_task('sync'); // after the `npm i` above, and in all cases
85
85
  if (message) {
86
86
  // TODO see the helper below, simplify this to CLI flags when support is added to Changesets
87
- const changeset_adder = await create_changeset_adder(package_json.name, dir, message, bump);
87
+ const changeset_adder = create_changeset_adder(package_json.name, dir, message, bump);
88
88
  await spawn_cli(found_changeset_cli, ['add', '--empty'], log);
89
89
  await changeset_adder();
90
90
  if (!(await git_check_fully_staged_workspace())) {
@@ -102,7 +102,7 @@ export const task = {
102
102
  * TODO ideally this wouldn't exist and we'd use CLI flags, but they doesn't exist yet
103
103
  * @see https://github.com/changesets/changesets/pull/1121
104
104
  */
105
- const create_changeset_adder = async (repo_name, dir, message, bump) => {
105
+ const create_changeset_adder = (repo_name, dir, message, bump) => {
106
106
  const filenames_before = readdirSync(dir);
107
107
  return async () => {
108
108
  const filenames_after = readdirSync(dir);
package/dist/cli.js CHANGED
@@ -16,7 +16,7 @@ export const find_cli = (name, cwd = process.cwd(), options) => {
16
16
  return { name, id: local_id, kind: 'local' };
17
17
  }
18
18
  const { stdout } = spawnSync('which', [name], options);
19
- const global_id = stdout?.toString().trim();
19
+ const global_id = stdout.toString().trim();
20
20
  if (!global_id)
21
21
  return null;
22
22
  return { name, id: global_id, kind: 'global' };
package/dist/config.d.ts CHANGED
@@ -39,9 +39,7 @@ export interface Raw_Gro_Config {
39
39
  task_root_dirs?: string[];
40
40
  search_filters?: Path_Filter | Path_Filter[] | null;
41
41
  }
42
- export interface Create_Gro_Config {
43
- (base_config: Gro_Config): Raw_Gro_Config | Promise<Raw_Gro_Config>;
44
- }
42
+ export type Create_Gro_Config = (base_config: Gro_Config) => Raw_Gro_Config | Promise<Raw_Gro_Config>;
45
43
  export declare const create_empty_config: () => Gro_Config;
46
44
  /**
47
45
  * The regexp used by default to exclude directories and files
package/dist/config.js CHANGED
@@ -11,7 +11,7 @@ export const create_empty_config = () => ({
11
11
  paths.lib,
12
12
  IS_THIS_GRO ? null : paths.root,
13
13
  IS_THIS_GRO ? null : GRO_DIST_DIR,
14
- ].filter(Boolean),
14
+ ].filter((v) => v !== null),
15
15
  search_filters: [(id) => !DEFAULT_SEARCH_EXCLUDER.test(id)],
16
16
  });
17
17
  /**
@@ -27,7 +27,7 @@ export const DEFAULT_SEARCH_EXCLUDER = new RegExp(`(${'(^|/)\\.[^/]+' + // exclu
27
27
  `|(^|/)(?<!(^|/)gro/)${SVELTEKIT_DIST_DIRNAME}` + // exclude the SvelteKit dist directory unless it's in the Gro directory
28
28
  `|(^|/)${SERVER_DIST_PATH}` // exclude the Gro server plugin dist directory
29
29
  })($|/)`, 'u');
30
- const default_map_package_json = async (package_json) => {
30
+ const default_map_package_json = (package_json) => {
31
31
  if (package_json.exports) {
32
32
  package_json.exports = Object.fromEntries(Object.entries(package_json.exports).filter(([k]) => !DEFAULT_EXPORTS_EXCLUDER.test(k)));
33
33
  }
@@ -12,7 +12,7 @@ import { empty_dir } from './fs.js';
12
12
  import { git_check_clean_workspace, git_checkout, git_local_branch_exists, git_remote_branch_exists, Git_Origin, Git_Branch, git_delete_local_branch, git_push_to_create, git_reset_branch_to_first_commit, git_pull, git_fetch, git_check_setting_pull_rebase, git_clone_locally, git_current_branch_name, } from './git.js';
13
13
  // docs at ./docs/deploy.md
14
14
  // terminal command for testing:
15
- // npm run build && rm -rf .gro && clear && gro deploy --source no-git-workspace --no-build --dry
15
+ // npm run bootstrap && rm -rf .gro && clear && gro deploy --source no-git-workspace --no-build --dry
16
16
  // TODO customize
17
17
  const dir = process.cwd();
18
18
  const INITIAL_FILE_PATH = '.gitkeep';
@@ -10,7 +10,7 @@ import { search_fs } from '../search_fs.js';
10
10
  /**
11
11
  * Renders a simple index of a possibly nested directory of files.
12
12
  */
13
- export const gen = async ({ origin_id }) => {
13
+ export const gen = ({ origin_id }) => {
14
14
  // TODO need to get this from project config or something
15
15
  const root_path = parse_path_segments(paths.root).at(-1);
16
16
  const origin_dir = dirname(origin_id);
package/dist/docs/dev.md CHANGED
@@ -35,6 +35,6 @@ See [plugin.md](plugin.md) to learn more.
35
35
 
36
36
  <p align="center">
37
37
  <a href="https://github.com/ryanatkn/gro">
38
- <img src="static/favicon.png" width="192" height="192">
38
+ <img src="static/logo.svg" alt="a pixelated green oak acorn with a glint of sun" width="192" height="192">
39
39
  </a>
40
40
  </p>
@@ -18,7 +18,8 @@ behavior designed for public open source projects:
18
18
  containing additional information about the source modules,
19
19
  mapping it with the optional
20
20
  [`well_known_src_json` option](./gro_plugin_sveltekit_app.md#well_known_src_json).
21
- - If you opt in with `well_known_src_files`,
21
+ - If you define a truthy value for the
22
+ [`well_known_src_files` option](./gro_plugin_sveltekit_app.md#well_known_src_files),
22
23
  `gro_plugin_sveltekit_app` outputs `.well-known/src/` by
23
24
  copying over `src/` during `vite build`, filtered by `well_known_src_files` if it's a function.
24
25
  This is costly (usually more than doubling the final output size
package/dist/env.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const load_env: (dev: boolean, visibility: "public" | "private", public_prefix: string, private_prefix: string, env_dir?: string, env_files?: string[], ambient_env?: NodeJS.ProcessEnv) => Promise<Record<string, string>>;
1
+ export declare const load_env: (dev: boolean, visibility: "public" | "private", public_prefix: string, private_prefix: string, env_dir?: string, env_files?: string[], ambient_env?: NodeJS.ProcessEnv) => Record<string, string>;
2
2
  export declare const merge_envs: (envs: Array<Record<string, string | undefined>>, visibility: "public" | "private", public_prefix: string, private_prefix: string) => Record<string, string>;
3
3
  export declare const is_private_env: (key: string, public_prefix: string, private_prefix: string) => boolean;
4
4
  export declare const is_public_env: (key: string, public_prefix: string, private_prefix: string) => boolean;
@@ -6,4 +6,4 @@ export declare const is_public_env: (key: string, public_prefix: string, private
6
6
  * Loads a single env value without merging it into `process.env`.
7
7
  * By default searches process.env, then a local `.env` if one exists, then `../.env` if it exists.
8
8
  */
9
- export declare const load_from_env: (key: string, paths?: string[]) => Promise<string | undefined>;
9
+ export declare const load_from_env: (key: string, paths?: string[]) => string | undefined;
package/dist/env.js CHANGED
@@ -1,18 +1,17 @@
1
1
  import dotenv from 'dotenv';
2
- import { readFile } from 'node:fs/promises';
3
2
  import { resolve } from 'node:path';
4
- import { existsSync } from 'node:fs';
5
- export const load_env = async (dev, visibility, public_prefix, private_prefix, env_dir, env_files = ['.env', '.env.' + (dev ? 'development' : 'production')], ambient_env = process.env) => {
6
- const envs = await Promise.all(env_files
7
- .map(async (path) => (await load(env_dir === undefined ? path : resolve(env_dir, path))))
8
- .filter(Boolean));
3
+ import { existsSync, readFileSync } from 'node:fs';
4
+ export const load_env = (dev, visibility, public_prefix, private_prefix, env_dir, env_files = ['.env', '.env.' + (dev ? 'development' : 'production')], ambient_env = process.env) => {
5
+ const envs = env_files
6
+ .map((path) => load(env_dir === undefined ? path : resolve(env_dir, path)))
7
+ .filter((v) => v !== undefined);
9
8
  envs.push(ambient_env);
10
9
  return merge_envs(envs, visibility, public_prefix, private_prefix);
11
10
  };
12
- const load = async (path) => {
11
+ const load = (path) => {
13
12
  if (!existsSync(path))
14
- return undefined;
15
- const loaded = await readFile(path, 'utf8');
13
+ return;
14
+ const loaded = readFileSync(path, 'utf8');
16
15
  return dotenv.parse(loaded);
17
16
  };
18
17
  export const merge_envs = (envs, visibility, public_prefix, private_prefix) => {
@@ -35,11 +34,11 @@ export const is_public_env = (key, public_prefix, private_prefix) => key.startsW
35
34
  * Loads a single env value without merging it into `process.env`.
36
35
  * By default searches process.env, then a local `.env` if one exists, then `../.env` if it exists.
37
36
  */
38
- export const load_from_env = async (key, paths = ['.env', '../.env']) => {
37
+ export const load_from_env = (key, paths = ['.env', '../.env']) => {
39
38
  if (process.env[key])
40
39
  return process.env[key];
41
40
  for (const path of paths) {
42
- const env = await load(path); // eslint-disable-line no-await-in-loop
41
+ const env = load(path);
43
42
  if (env?.[key])
44
43
  return env[key];
45
44
  }
@@ -25,7 +25,8 @@ export const to_define_import_meta_env = (dev, base_url, ssr = true, mode = dev
25
25
  [import_meta_env + 'PROD']: JSON.stringify(!dev),
26
26
  [import_meta_env + 'SSR']: JSON.stringify(ssr),
27
27
  [import_meta_env + 'MODE']: JSON.stringify(mode),
28
- [import_meta_env + 'BASE_URL']: JSON.stringify(base_url || '/'), // it appears SvelteKit's `''` translates to Vite's `'/'`, so this intentionally falls back for falsy values, not just undefined
28
+ // it appears SvelteKit's `''` translates to Vite's `'/'`, so this intentionally falls back for falsy values, not just undefined
29
+ [import_meta_env + 'BASE_URL']: JSON.stringify(base_url || '/'), // eslint-disable-line @typescript-eslint/prefer-nullish-coalescing
29
30
  });
30
31
  export const ts_transform_options = {
31
32
  target: 'esnext',
@@ -42,7 +42,7 @@ export const esbuild_plugin_external_worker = ({ dev, build_options, dir = proce
42
42
  return building;
43
43
  };
44
44
  build.onResolve({ filter: /\.worker(|\.js|\.ts)$/u }, async ({ path, resolveDir }) => {
45
- const parsed = await resolve_specifier(path, resolveDir);
45
+ const parsed = resolve_specifier(path, resolveDir);
46
46
  const { specifier, path_id, namespace } = parsed;
47
47
  const build_result = await build_worker(path_id);
48
48
  if (log)
@@ -15,7 +15,7 @@ export const esbuild_plugin_svelte = (options = {}) => {
15
15
  filename,
16
16
  ...svelte_compile_module_options,
17
17
  });
18
- const contents = js.map ? js.code + '//# sourceMappingURL=' + js.map.toUrl() : js.code;
18
+ const contents = js.code + '//# sourceMappingURL=' + js.map.toUrl();
19
19
  return {
20
20
  contents,
21
21
  warnings: warnings.map((w) => convert_svelte_message_to_esbuild(filename, source, w)),
@@ -34,12 +34,12 @@ export const esbuild_plugin_svelte = (options = {}) => {
34
34
  : null;
35
35
  // TODO handle preprocessor sourcemaps, same as in loader - merge?
36
36
  if (preprocessed?.code)
37
- source = preprocessed?.code;
37
+ source = preprocessed.code;
38
38
  const { js, warnings } = compile(source, {
39
39
  filename,
40
40
  ...svelte_compile_options,
41
41
  });
42
- const contents = js.map ? js.code + '//# sourceMappingURL=' + js.map.toUrl() : js.code;
42
+ const contents = js.code + '//# sourceMappingURL=' + js.map.toUrl();
43
43
  return {
44
44
  contents,
45
45
  warnings: warnings.map((w) => convert_svelte_message_to_esbuild(filename, source, w)),
@@ -9,11 +9,11 @@ import { resolve_specifier } from './resolve_specifier.js';
9
9
  export const esbuild_plugin_sveltekit_local_imports = () => ({
10
10
  name: 'sveltekit_local_imports',
11
11
  setup: (build) => {
12
- build.onResolve({ filter: /^(\/|\.)/u }, async (args) => {
12
+ build.onResolve({ filter: /^(\/|\.)/u }, (args) => {
13
13
  const { path, importer } = args;
14
14
  if (!importer)
15
15
  return { path };
16
- const { path_id, namespace } = await resolve_specifier(path, dirname(importer));
16
+ const { path_id, namespace } = resolve_specifier(path, dirname(importer));
17
17
  return { path: path_id, namespace }; // `namespace` may be `undefined`, but esbuild needs the absolute path for json etc
18
18
  });
19
19
  build.onLoad({ filter: /.*/u, namespace: 'sveltekit_local_imports_ts' }, async ({ path }) => ({
@@ -5,13 +5,13 @@ export const esbuild_plugin_sveltekit_shim_env = ({ dev, public_prefix, private_
5
5
  const namespace = 'sveltekit_shim_env';
6
6
  const filter = /^\$env\/(static|dynamic)\/(public|private)$/u;
7
7
  build.onResolve({ filter }, ({ path }) => ({ path, namespace }));
8
- build.onLoad({ filter: /.*/u, namespace }, async ({ path }) => {
8
+ build.onLoad({ filter: /.*/u, namespace }, ({ path }) => {
9
9
  const matches = filter.exec(path);
10
10
  const mode = matches[1];
11
11
  const visibility = matches[2];
12
12
  return {
13
13
  loader: 'ts',
14
- contents: await render_env_shim_module(dev, mode, visibility, public_prefix, private_prefix, env_dir, env_files, ambient_env),
14
+ contents: render_env_shim_module(dev, mode, visibility, public_prefix, private_prefix, env_dir, env_files, ambient_env),
15
15
  };
16
16
  });
17
17
  },
@@ -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 = load_package_json().prettier);
15
15
  let final_options = options;
16
16
  if (options.filepath && !options.parser) {
17
17
  const { filepath, ...rest } = options;
@@ -22,7 +22,7 @@ export const format_file = async (content, options, base_options = cached_base_o
22
22
  try {
23
23
  return await prettier.format(content, { ...final_base_options, ...final_options });
24
24
  }
25
- catch (err) {
25
+ catch (_err) {
26
26
  return content;
27
27
  }
28
28
  };
package/dist/gen.d.ts CHANGED
@@ -9,19 +9,17 @@ import { Input_Path, type Resolved_Input_File, type Resolved_Input_Path } from '
9
9
  export declare const GEN_FILE_PATTERN_TEXT = "gen";
10
10
  export declare const GEN_FILE_PATTERN: string;
11
11
  export declare const is_gen_path: (path: string) => boolean;
12
- export type Gen_Result = {
12
+ export interface Gen_Result {
13
13
  origin_id: Path_Id;
14
14
  files: Gen_File[];
15
- };
15
+ }
16
16
  export interface Gen_File {
17
17
  id: Path_Id;
18
18
  content: string;
19
19
  origin_id: Path_Id;
20
20
  format: boolean;
21
21
  }
22
- export interface Gen {
23
- (ctx: Gen_Context): Raw_Gen_Result | Promise<Raw_Gen_Result>;
24
- }
22
+ export type Gen = (ctx: Gen_Context) => Raw_Gen_Result | Promise<Raw_Gen_Result>;
25
23
  export interface Gen_Context {
26
24
  config: Gro_Config;
27
25
  sveltekit_config: Parsed_Sveltekit_Config;
@@ -45,28 +43,28 @@ export declare const Gen_Config: z.ZodObject<{
45
43
  imports?: Record<string, string> | undefined;
46
44
  }>;
47
45
  export type Gen_Config = z.infer<typeof Gen_Config>;
48
- export type Gen_Results = {
46
+ export interface Gen_Results {
49
47
  results: Genfile_Module_Result[];
50
48
  successes: Genfile_Module_Result_Success[];
51
49
  failures: Genfile_Module_Result_Failure[];
52
50
  input_count: number;
53
51
  output_count: number;
54
52
  elapsed: number;
55
- };
53
+ }
56
54
  export type Genfile_Module_Result = Genfile_Module_Result_Success | Genfile_Module_Result_Failure;
57
- export type Genfile_Module_Result_Success = {
55
+ export interface Genfile_Module_Result_Success {
58
56
  ok: true;
59
57
  id: Path_Id;
60
58
  files: Gen_File[];
61
59
  elapsed: number;
62
- };
63
- export type Genfile_Module_Result_Failure = {
60
+ }
61
+ export interface Genfile_Module_Result_Failure {
64
62
  ok: false;
65
63
  id: Path_Id;
66
64
  reason: string;
67
65
  error: Error;
68
66
  elapsed: number;
69
- };
67
+ }
70
68
  export declare const to_gen_result: (origin_id: Path_Id, raw_result: Raw_Gen_Result) => Gen_Result;
71
69
  export declare const to_output_file_name: (filename: string) => string;
72
70
  export type Analyzed_Gen_Result = {
@@ -107,7 +105,7 @@ export type Find_Genfiles_Failure = {
107
105
  /**
108
106
  * Finds modules from input paths. (see `src/lib/input_path.ts` for more)
109
107
  */
110
- export declare const find_genfiles: (input_paths: Input_Path[], root_dirs: Path_Id[], config: Gro_Config, timings?: any) => Promise<Find_Genfiles_Result>;
108
+ export declare const find_genfiles: (input_paths: Input_Path[], root_dirs: Path_Id[], config: Gro_Config, timings?: any) => Find_Genfiles_Result;
111
109
  export interface Genfile_Module {
112
110
  gen: Gen;
113
111
  }
package/dist/gen.js CHANGED
@@ -42,7 +42,7 @@ const to_output_file_id = (origin_id, raw_file_name) => {
42
42
  if (raw_file_name === '') {
43
43
  throw Error(`Output file name cannot be an empty string`);
44
44
  }
45
- const filename = raw_file_name || to_output_file_name(basename(origin_id));
45
+ const filename = raw_file_name ?? to_output_file_name(basename(origin_id));
46
46
  if (isAbsolute(filename))
47
47
  return filename;
48
48
  const dir = dirname(origin_id);
@@ -132,7 +132,7 @@ export const write_gen_results = async (gen_results, analyzed_gen_results, log)
132
132
  /**
133
133
  * Finds modules from input paths. (see `src/lib/input_path.ts` for more)
134
134
  */
135
- export const find_genfiles = async (input_paths, root_dirs, config, timings) => {
135
+ export const find_genfiles = (input_paths, root_dirs, config, timings) => {
136
136
  const extensions = [GEN_FILE_PATTERN];
137
137
  // Check which extension variation works - if it's a directory, prefer others first!
138
138
  const timing_to_resolve_input_paths = timings?.start('resolve input paths');
@@ -186,4 +186,4 @@ export const load_genfiles = async (found_genfiles, timings) => {
186
186
  value: { modules: loaded_modules.modules, found_genfiles },
187
187
  };
188
188
  };
189
- export const validate_gen_module = (mod) => typeof mod?.gen === 'function';
189
+ export const validate_gen_module = (mod) => typeof mod.gen === 'function';
package/dist/gen.task.js CHANGED
@@ -30,7 +30,7 @@ export const task = {
30
30
  const { _: raw_input_paths, root_dirs, check } = args;
31
31
  const input_paths = to_input_paths(raw_input_paths);
32
32
  // load all of the gen modules
33
- const found = await find_genfiles(input_paths, root_dirs, config, timings);
33
+ const found = find_genfiles(input_paths, root_dirs, config, timings);
34
34
  if (!found.ok) {
35
35
  if (found.type === 'input_directories_with_no_files') {
36
36
  // TODO maybe let this error like the normal case, but only call `gro gen` if we find gen files? problem is the args would need to be hoisted to callers like `gro sync`
package/dist/gen.test.js CHANGED
@@ -239,12 +239,9 @@ test('validate_gen_module basic behavior', () => {
239
239
  assert.ok(validate_gen_module({ gen: Function.prototype }));
240
240
  assert.ok(!validate_gen_module({ gen: {} }));
241
241
  assert.ok(!validate_gen_module({ task: { run: {} } }));
242
- assert.ok(!validate_gen_module(undefined));
243
- assert.ok(!validate_gen_module(null));
244
- assert.ok(!validate_gen_module(false));
245
242
  });
246
- test('find_genfiles_result finds gen modules in a directory', async () => {
247
- const find_genfiles_result = await find_genfiles(['docs'], [paths.lib], create_empty_config());
243
+ test('find_genfiles_result finds gen modules in a directory', () => {
244
+ const find_genfiles_result = find_genfiles(['docs'], [paths.lib], create_empty_config());
248
245
  assert.ok(find_genfiles_result.ok);
249
246
  assert.ok(find_genfiles_result.value.resolved_input_paths.length);
250
247
  });
package/dist/git.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { SpawnOptions } from 'child_process';
1
+ import type { SpawnOptions } from 'node:child_process';
2
2
  import { z } from 'zod';
3
3
  export declare const Git_Origin: z.ZodBranded<z.ZodString, "Git_Origin">;
4
4
  export type Git_Origin = z.infer<typeof Git_Origin>;
@@ -42,7 +42,7 @@ export declare const git_pull: (origin?: Git_Origin, branch?: Git_Branch, option
42
42
  /**
43
43
  * Calls `git push` and throws if anything goes wrong.
44
44
  */
45
- export declare const git_push: (origin: Git_Origin, branch: Git_Branch, options?: SpawnOptions, set_upstream?: boolean) => Promise<void>;
45
+ export declare const git_push: (origin: Git_Origin, branch?: Git_Branch, options?: SpawnOptions, set_upstream?: boolean) => Promise<void>;
46
46
  /**
47
47
  * Calls `git push` and throws if anything goes wrong.
48
48
  */
@@ -13,7 +13,7 @@ import { has_sveltekit_app, has_sveltekit_library } from './sveltekit_helpers.js
13
13
  */
14
14
  const config = async (cfg) => {
15
15
  const [has_sveltekit_library_result, has_server_result, has_sveltekit_app_result] = await Promise.all([has_sveltekit_library(), has_server(), has_sveltekit_app()]);
16
- cfg.plugins = async () => [
16
+ cfg.plugins = () => [
17
17
  has_sveltekit_library_result.ok ? gro_plugin_sveltekit_library() : null,
18
18
  has_server_result.ok ? gro_plugin_server() : null,
19
19
  has_sveltekit_app_result.ok
package/dist/gro.js CHANGED
@@ -11,9 +11,9 @@ and it also provides special handling for the case
11
11
  where we're running Gro inside Gro's own repo for development.
12
12
 
13
13
  */
14
- const invoke_path = await resolve_gro_module_path('invoke.js');
14
+ const invoke_path = resolve_gro_module_path('invoke.js');
15
15
  const loader_path = join(invoke_path, '../loader.js');
16
16
  const spawned = await spawn_with_loader(loader_path, invoke_path, process.argv.slice(2));
17
17
  if (!spawned.ok) {
18
- process.exit(spawned.code || 1);
18
+ process.exit(spawned.code || 1); // eslint-disable-line @typescript-eslint/prefer-nullish-coalescing
19
19
  }
@@ -33,10 +33,15 @@ import { type Spawn_Result } from '@ryanatkn/belt/process.js';
33
33
  * When using the global CLI, this uses the global Gro installation.
34
34
  *
35
35
  */
36
- export declare const resolve_gro_module_path: (path?: string) => Promise<string>;
36
+ export declare const resolve_gro_module_path: (path?: string) => string;
37
37
  /**
38
38
  * Runs a file using the Gro loader.
39
39
  *
40
+ * Uses conditional exports to correctly set up `esm-env` as development by default,
41
+ * so if you want production set `NODE_ENV=production`.
42
+ *
43
+ * @see https://nodejs.org/api/packages.html#conditional-exports
44
+ *
40
45
  * @param loader_path path to loader
41
46
  * @param invoke_path path to file to spawn with `node`
42
47
  */
@@ -1,8 +1,7 @@
1
- import { realpath } from 'node:fs/promises';
1
+ import { realpathSync, existsSync } from 'node:fs';
2
2
  import { join, resolve } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { spawn } from '@ryanatkn/belt/process.js';
5
- import { existsSync } from 'node:fs';
6
5
  import { NODE_MODULES_DIRNAME, SVELTEKIT_DIST_DIRNAME } from './path_constants.js';
7
6
  /*
8
7
 
@@ -43,12 +42,12 @@ This module is intended to have minimal dependencies to avoid over-imports in th
43
42
  * When using the global CLI, this uses the global Gro installation.
44
43
  *
45
44
  */
46
- export const resolve_gro_module_path = async (path = '') => {
45
+ export const resolve_gro_module_path = (path = '') => {
47
46
  const gro_bin_path = resolve(NODE_MODULES_DIRNAME, '.bin/gro');
48
47
  // case 1
49
48
  // Prefer any locally installed version of Gro.
50
49
  if (existsSync(gro_bin_path)) {
51
- return join(await realpath(gro_bin_path), '..', path);
50
+ return join(realpathSync(gro_bin_path), '..', path);
52
51
  }
53
52
  // case 2
54
53
  // If running Gro inside its own repo, require the local dist.
@@ -65,16 +64,28 @@ export const resolve_gro_module_path = async (path = '') => {
65
64
  /**
66
65
  * Runs a file using the Gro loader.
67
66
  *
67
+ * Uses conditional exports to correctly set up `esm-env` as development by default,
68
+ * so if you want production set `NODE_ENV=production`.
69
+ *
70
+ * @see https://nodejs.org/api/packages.html#conditional-exports
71
+ *
68
72
  * @param loader_path path to loader
69
73
  * @param invoke_path path to file to spawn with `node`
70
74
  */
71
- export const spawn_with_loader = async (loader_path, invoke_path, argv) => spawn('node', [
72
- '--import',
73
- `data:text/javascript,
75
+ export const spawn_with_loader = (loader_path, invoke_path, argv) => {
76
+ const args = [
77
+ '--import',
78
+ // This does the same as `$lib/register.ts` but without the cost of importing another file.
79
+ `data:text/javascript,
74
80
  import {register} from "node:module";
75
81
  import {pathToFileURL} from "node:url";
76
82
  register("${loader_path}", pathToFileURL("./"));`,
77
- '--enable-source-maps',
78
- invoke_path,
79
- ...argv,
80
- ]);
83
+ '--enable-source-maps', // because TypeScript
84
+ ];
85
+ // In almost all cases we want the exports condition to be `"development"`.
86
+ if (process.env.NODE_ENV !== 'production') {
87
+ args.push('-C', 'development'); // same as `--conditions`
88
+ }
89
+ args.push(invoke_path, ...argv);
90
+ return spawn('node', args);
91
+ };