@ryanatkn/gro 0.117.0 → 0.119.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 (94) hide show
  1. package/README.md +37 -19
  2. package/dist/build.task.d.ts +3 -0
  3. package/dist/build.task.js +5 -1
  4. package/dist/changeset.task.d.ts +2 -2
  5. package/dist/changeset.task.js +10 -6
  6. package/dist/check.task.js +1 -1
  7. package/dist/clean_fs.js +2 -1
  8. package/dist/cli.js +1 -1
  9. package/dist/config.js +3 -2
  10. package/dist/deploy.task.d.ts +0 -6
  11. package/dist/deploy.task.js +7 -11
  12. package/dist/dev.task.d.ts +2 -2
  13. package/dist/docs/gen.md +27 -0
  14. package/dist/docs/publish.md +1 -8
  15. package/dist/docs/task.md +7 -0
  16. package/dist/docs/tasks.gen.md.js +2 -3
  17. package/dist/docs/tasks.md +1 -0
  18. package/dist/esbuild_plugin_external_worker.js +1 -2
  19. package/dist/esbuild_plugin_svelte.js +1 -2
  20. package/dist/esbuild_plugin_sveltekit_shim_alias.js +1 -2
  21. package/dist/format_directory.d.ts +8 -2
  22. package/dist/format_directory.js +18 -12
  23. package/dist/gen.d.ts +19 -0
  24. package/dist/gen.js +45 -0
  25. package/dist/gen.task.js +19 -19
  26. package/dist/gen_module.d.ts +1 -14
  27. package/dist/gen_module.js +0 -22
  28. package/dist/git.d.ts +5 -0
  29. package/dist/git.js +15 -0
  30. package/dist/git.test.js +4 -1
  31. package/dist/gro.config.default.js +8 -11
  32. package/dist/gro_helpers.js +18 -17
  33. package/dist/gro_plugin_gen.js +1 -1
  34. package/dist/gro_plugin_server.d.ts +4 -1
  35. package/dist/gro_plugin_server.js +15 -6
  36. package/dist/gro_plugin_sveltekit_app.d.ts +0 -1
  37. package/dist/gro_plugin_sveltekit_app.js +2 -4
  38. package/dist/gro_plugin_sveltekit_library.d.ts +0 -2
  39. package/dist/gro_plugin_sveltekit_library.js +10 -11
  40. package/dist/index.d.ts +1 -1
  41. package/dist/index.js +0 -1
  42. package/dist/input_path.d.ts +1 -1
  43. package/dist/input_path.js +1 -1
  44. package/dist/input_path.test.js +3 -3
  45. package/dist/invoke.js +2 -0
  46. package/dist/invoke_task.d.ts +1 -1
  47. package/dist/invoke_task.js +10 -11
  48. package/dist/lint.task.js +1 -1
  49. package/dist/loader.js +11 -4
  50. package/dist/module.d.ts +1 -1
  51. package/dist/module.js +2 -2
  52. package/dist/modules.test.js +2 -2
  53. package/dist/package.d.ts +52 -0
  54. package/dist/package.js +80 -36
  55. package/dist/package_json.d.ts +5 -0
  56. package/dist/package_json.js +8 -3
  57. package/dist/package_meta.d.ts +1 -2
  58. package/dist/path_constants.d.ts +21 -0
  59. package/dist/path_constants.js +28 -0
  60. package/dist/paths.d.ts +2 -26
  61. package/dist/paths.js +10 -33
  62. package/dist/publish.task.d.ts +9 -6
  63. package/dist/publish.task.js +26 -14
  64. package/dist/register.d.ts +1 -0
  65. package/dist/register.js +2 -0
  66. package/dist/reinstall.task.d.ts +5 -0
  67. package/dist/reinstall.task.js +32 -0
  68. package/dist/release.task.js +5 -7
  69. package/dist/resolve_node_specifier.js +2 -1
  70. package/dist/run.task.js +1 -1
  71. package/dist/run_gen.d.ts +2 -1
  72. package/dist/run_gen.js +2 -2
  73. package/dist/run_gen.test.js +3 -2
  74. package/dist/run_task.js +1 -1
  75. package/dist/sveltekit_config.d.ts +1 -1
  76. package/dist/sveltekit_config.js +9 -5
  77. package/dist/sveltekit_config_global.d.ts +4 -0
  78. package/dist/sveltekit_config_global.js +5 -0
  79. package/dist/sveltekit_helpers.d.ts +17 -0
  80. package/dist/sveltekit_helpers.js +54 -0
  81. package/dist/sync.task.d.ts +0 -1
  82. package/dist/sync.task.js +5 -11
  83. package/dist/task.d.ts +1 -1
  84. package/dist/task.js +11 -7
  85. package/dist/task.test.js +9 -13
  86. package/dist/task_logging.d.ts +2 -2
  87. package/dist/task_logging.js +29 -15
  88. package/dist/task_module.d.ts +3 -3
  89. package/dist/task_module.js +6 -6
  90. package/dist/task_module.test.js +4 -7
  91. package/dist/typecheck.task.js +1 -1
  92. package/dist/upgrade.task.d.ts +4 -1
  93. package/dist/upgrade.task.js +30 -5
  94. package/package.json +23 -3
package/dist/paths.d.ts CHANGED
@@ -1,29 +1,9 @@
1
1
  import type { Flavored } from '@ryanatkn/belt/types.js';
2
2
  import { z } from 'zod';
3
- export declare const SOURCE_DIRNAME = "src";
4
- export declare const GRO_DIRNAME = ".gro";
5
- export declare const GRO_DIST_PREFIX = "dist_";
6
- export declare const SERVER_DIST_PATH = "dist_server";
7
- export declare const LIB_DIRNAME = "lib";
8
- export declare const ROUTES_DIRNAME = "routes";
9
- export declare const GRO_DEV_DIRNAME: string;
10
- export declare const SOURCE_DIR: string;
11
- export declare const GRO_DIR: string;
12
- export declare const GRO_DEV_DIR: string;
3
+ export declare const LIB_DIRNAME: string;
13
4
  export declare const LIB_PATH: string;
14
5
  export declare const LIB_DIR: string;
15
- export declare const CONFIG_PATH = "gro.config.ts";
16
- export declare const README_FILENAME = "README.md";
17
- export declare const SVELTEKIT_CONFIG_FILENAME = "svelte.config.js";
18
- export declare const VITE_CONFIG_FILENAME = "vite.config.ts";
19
- export declare const SVELTEKIT_DEV_DIRNAME = ".svelte-kit";
20
- export declare const SVELTEKIT_BUILD_DIRNAME = "build";
21
- export declare const SVELTEKIT_DIST_DIRNAME = "dist";
22
- export declare const NODE_MODULES_DIRNAME = "node_modules";
23
- export declare const SVELTEKIT_VITE_CACHE_PATH: string;
24
- export declare const GITHUB_DIRNAME = ".github";
25
- export declare const GIT_DIRNAME = ".git";
26
- export declare const TSCONFIG_FILENAME = "tsconfig.json";
6
+ export declare const ROUTES_DIRNAME: string;
27
7
  export interface Paths {
28
8
  root: string;
29
9
  source: string;
@@ -34,10 +14,6 @@ export interface Paths {
34
14
  }
35
15
  export declare const Source_Id: z.ZodString;
36
16
  export type Source_Id = Flavored<z.infer<typeof Source_Id>, 'Source_Id'>;
37
- export declare const Url: z.ZodString;
38
- export type Url = Flavored<z.infer<typeof Url>, 'Url'>;
39
- export declare const Email: z.ZodString;
40
- export type Email = Flavored<z.infer<typeof Email>, 'Email'>;
41
17
  export declare const create_paths: (root_dir: string) => Paths;
42
18
  export declare const paths_from_id: (id: string) => Paths;
43
19
  export declare const is_gro_id: (id: string) => boolean;
package/dist/paths.js CHANGED
@@ -1,56 +1,33 @@
1
- import { join, extname, relative } from 'node:path';
1
+ import { join, extname, relative, basename } from 'node:path';
2
2
  import { fileURLToPath } from 'node:url';
3
3
  import { strip_end, strip_start } from '@ryanatkn/belt/string.js';
4
4
  import { gray } from 'kleur/colors';
5
5
  import { z } from 'zod';
6
+ import { GRO_CONFIG_PATH, GRO_DEV_DIR, GRO_DIR, SOURCE_DIR, SVELTEKIT_DIST_DIRNAME, } from './path_constants.js';
7
+ import { sveltekit_config_global } from './sveltekit_config_global.js';
6
8
  /*
7
9
 
8
10
  A path `id` is an absolute path to the source/.gro/dist directory.
9
11
  It's the same name that Rollup uses.
10
12
 
11
13
  */
12
- // TODO pass these to `create_paths` and override from gro config
13
- // TODO this is kinda gross - do we want to maintain the convention to have the trailing slash in most usage?
14
- export const SOURCE_DIRNAME = 'src';
15
- export const GRO_DIRNAME = '.gro';
16
- export const GRO_DIST_PREFIX = 'dist_'; //
17
- export const SERVER_DIST_PATH = 'dist_server'; // TODO should all of these be `_PATH` or should this be `DIRNAME`?
18
- export const LIB_DIRNAME = 'lib'; // TODO use Svelte config `files.lib`
19
- export const ROUTES_DIRNAME = 'routes'; // TODO use Svelte config `files.lib`
20
- export const GRO_DEV_DIRNAME = GRO_DIRNAME + '/dev';
21
- export const SOURCE_DIR = SOURCE_DIRNAME + '/';
22
- export const GRO_DIR = GRO_DIRNAME + '/';
23
- export const GRO_DEV_DIR = GRO_DEV_DIRNAME + '/';
14
+ export const LIB_DIRNAME = basename(sveltekit_config_global.lib_path);
24
15
  export const LIB_PATH = SOURCE_DIR + LIB_DIRNAME;
25
- export const LIB_DIR = LIB_PATH + '/'; // TODO @multiple get from the sveltekit config
26
- export const CONFIG_PATH = 'gro.config.ts';
27
- export const README_FILENAME = 'README.md';
28
- export const SVELTEKIT_CONFIG_FILENAME = 'svelte.config.js';
29
- export const VITE_CONFIG_FILENAME = 'vite.config.ts';
30
- export const SVELTEKIT_DEV_DIRNAME = '.svelte-kit'; // TODO use Svelte config value `outDir`
31
- export const SVELTEKIT_BUILD_DIRNAME = 'build';
32
- export const SVELTEKIT_DIST_DIRNAME = 'dist';
33
- export const NODE_MODULES_DIRNAME = 'node_modules';
34
- export const SVELTEKIT_VITE_CACHE_PATH = NODE_MODULES_DIRNAME + '/.vite';
35
- export const GITHUB_DIRNAME = '.github';
36
- export const GIT_DIRNAME = '.git';
37
- export const TSCONFIG_FILENAME = 'tsconfig.json';
16
+ export const LIB_DIR = LIB_PATH + '/';
17
+ export const ROUTES_DIRNAME = basename(sveltekit_config_global.routes_path);
18
+ // TODO probably rename to `Path_Id` from `Source_Id`?
38
19
  // TODO Flavored doesn't work when used in schemas, use Zod brand instead? problem is ergonomics
39
20
  export const Source_Id = z.string();
40
- // TODO @multiple belongs elsewhere
41
- export const Url = z.string();
42
- // TODO @multiple belongs elsewhere
43
- export const Email = z.string();
44
21
  export const create_paths = (root_dir) => {
45
22
  // TODO remove reliance on trailing slash towards windows support
46
23
  const root = strip_end(root_dir, '/') + '/';
47
24
  return {
48
25
  root,
49
26
  source: root + SOURCE_DIR,
50
- lib: root + LIB_DIR, // TODO @multiple get from the sveltekit config
27
+ lib: root + LIB_DIR,
51
28
  build: root + GRO_DIR,
52
29
  build_dev: root + GRO_DEV_DIR,
53
- config: root + CONFIG_PATH,
30
+ config: root + GRO_CONFIG_PATH,
54
31
  };
55
32
  };
56
33
  export const paths_from_id = (id) => (is_gro_id(id) ? gro_paths : paths);
@@ -94,7 +71,7 @@ export const replace_extension = (path, new_extension) => {
94
71
  /**
95
72
  * Paths for the user repo.
96
73
  */
97
- export const paths = create_paths(process.cwd() + '/');
74
+ export const paths = create_paths(process.cwd());
98
75
  export const GRO_PACKAGE_DIR = 'gro/';
99
76
  // TODO document these conditions with comments
100
77
  // TODO there's probably a more robust way to do this
@@ -5,37 +5,40 @@ export declare const Args: z.ZodObject<{
5
5
  origin: z.ZodDefault<z.ZodBranded<z.ZodString, "Git_Origin">>;
6
6
  changelog: z.ZodDefault<z.ZodString>;
7
7
  preserve_changelog: z.ZodDefault<z.ZodBoolean>;
8
+ optional: z.ZodDefault<z.ZodBoolean>;
8
9
  dry: z.ZodDefault<z.ZodBoolean>;
9
10
  check: z.ZodDefault<z.ZodBoolean>;
10
11
  'no-check': z.ZodDefault<z.ZodBoolean>;
11
- install: z.ZodDefault<z.ZodBoolean>;
12
- 'no-install': z.ZodDefault<z.ZodBoolean>;
13
12
  build: z.ZodDefault<z.ZodBoolean>;
14
13
  'no-build': z.ZodDefault<z.ZodBoolean>;
14
+ pull: z.ZodDefault<z.ZodBoolean>;
15
+ 'no-pull': z.ZodDefault<z.ZodBoolean>;
15
16
  }, "strict", z.ZodTypeAny, {
16
17
  build: boolean;
17
- install: boolean;
18
18
  origin: string & z.BRAND<"Git_Origin">;
19
+ pull: boolean;
19
20
  branch: string & z.BRAND<"Git_Branch">;
20
21
  changelog: string;
21
- 'no-install': boolean;
22
22
  check: boolean;
23
23
  dry: boolean;
24
24
  'no-build': boolean;
25
25
  preserve_changelog: boolean;
26
+ optional: boolean;
26
27
  'no-check': boolean;
28
+ 'no-pull': boolean;
27
29
  }, {
28
30
  build?: boolean | undefined;
29
- install?: boolean | undefined;
30
31
  origin?: string | undefined;
32
+ pull?: boolean | undefined;
31
33
  branch?: string | undefined;
32
34
  changelog?: string | undefined;
33
- 'no-install'?: boolean | undefined;
34
35
  check?: boolean | undefined;
35
36
  dry?: boolean | undefined;
36
37
  'no-build'?: boolean | undefined;
37
38
  preserve_changelog?: boolean | undefined;
39
+ optional?: boolean | undefined;
38
40
  'no-check'?: boolean | undefined;
41
+ 'no-pull'?: boolean | undefined;
39
42
  }>;
40
43
  export type Args = z.infer<typeof Args>;
41
44
  export declare const task: Task<Args>;
@@ -6,10 +6,10 @@ import { load_package_json, parse_repo_url } from './package_json.js';
6
6
  import { find_cli, spawn_cli } from './cli.js';
7
7
  import { exists } from './fs.js';
8
8
  import { IS_THIS_GRO } from './paths.js';
9
- import { has_sveltekit_library } from './gro_plugin_sveltekit_library.js';
9
+ import { has_sveltekit_library } from './sveltekit_helpers.js';
10
10
  import { update_changelog } from './changelog.js';
11
11
  import { load_from_env } from './env.js';
12
- import { Git_Branch, Git_Origin, git_checkout, git_fetch, git_pull } from './git.js';
12
+ import { Git_Branch, Git_Origin, git_check_clean_workspace, git_checkout, git_fetch, git_pull, } from './git.js';
13
13
  // publish.task.ts
14
14
  // - usage: `gro publish patch`
15
15
  // - forwards args to `npm version`: https://docs.npmjs.com/v6/commands/npm-version
@@ -28,6 +28,7 @@ export const Args = z
28
28
  description: 'opt out of linkifying and formatting the changelog from @changesets/changelog-git',
29
29
  })
30
30
  .default(false),
31
+ optional: z.boolean({ description: 'exit gracefully if there are no changesets' }).default(false),
31
32
  dry: z
32
33
  .boolean({ description: 'build and prepare to publish without actually publishing' })
33
34
  .default(false),
@@ -35,24 +36,23 @@ export const Args = z
35
36
  'no-check': z
36
37
  .boolean({ description: 'opt out of npm checking before publishing' })
37
38
  .default(false),
38
- install: z.boolean({ description: 'dual of no-install' }).default(true),
39
- 'no-install': z
40
- .boolean({ description: 'opt out of npm installing before building' })
41
- .default(false),
42
39
  build: z.boolean({ description: 'dual of no-build' }).default(true),
43
40
  'no-build': z.boolean({ description: 'opt out of building' }).default(false),
41
+ pull: z.boolean({ description: 'dual of no-pull' }).default(true),
42
+ 'no-pull': z.boolean({ description: 'opt out of git pull' }).default(false),
44
43
  })
45
44
  .strict();
46
45
  export const task = {
47
46
  summary: 'bump version, publish to npm, and git push',
48
47
  Args,
49
48
  run: async ({ args, log, invoke_task }) => {
50
- const { branch, origin, changelog, preserve_changelog, dry, check, install, build } = args;
49
+ const { branch, origin, changelog, preserve_changelog, dry, check, build, pull, optional } = args;
51
50
  if (dry) {
52
51
  log.info(green('dry run!'));
53
52
  }
54
- if (!(await has_sveltekit_library())) {
55
- throw new Task_Error('gro publish failed to detect a library, run `npm i -D @sveltejs/package` to enable it');
53
+ const has_sveltekit_library_result = await has_sveltekit_library();
54
+ if (!has_sveltekit_library_result.ok) {
55
+ throw new Task_Error('Failed to find SvelteKit library: ' + has_sveltekit_library_result.message);
56
56
  }
57
57
  // TODO hacky, ensures Gro bootstraps itself
58
58
  if (IS_THIS_GRO) {
@@ -60,12 +60,17 @@ export const task = {
60
60
  }
61
61
  const changelog_exists = await exists(changelog);
62
62
  if (!(await find_cli('changeset'))) {
63
- throw new Task_Error('changeset command not found: install @changesets/cli locally or globally');
63
+ throw new Task_Error('changeset command not found, install @changesets/cli locally or globally');
64
64
  }
65
65
  // Make sure we're on the right branch:
66
66
  await git_fetch(origin, branch);
67
67
  await git_checkout(branch);
68
- await git_pull(origin, branch);
68
+ if (pull) {
69
+ if (await git_check_clean_workspace()) {
70
+ throw new Task_Error('The git workspace is not clean, pass --no-pull to bypass git pull');
71
+ }
72
+ await git_pull(origin, branch);
73
+ }
69
74
  // Check before proceeding.
70
75
  if (check) {
71
76
  await invoke_task('check', { workspace: true });
@@ -82,7 +87,7 @@ export const task = {
82
87
  else {
83
88
  const package_json_before = await load_package_json();
84
89
  if (typeof package_json_before.version !== 'string') {
85
- throw new Task_Error('failed to find package.json version');
90
+ throw new Task_Error('Failed to find package.json version');
86
91
  }
87
92
  const parsed_repo_url = parse_repo_url(package_json_before);
88
93
  if (!parsed_repo_url) {
@@ -105,11 +110,18 @@ export const task = {
105
110
  const package_json_after = await load_package_json();
106
111
  version = package_json_after.version;
107
112
  if (package_json_before.version === version) {
108
- throw new Task_Error('changeset version failed: are there any changes?');
113
+ // The version didn't change.
114
+ // For now this is the best detection we have for a no-op `changeset version`.
115
+ if (optional) {
116
+ return; // exit gracefully
117
+ }
118
+ else {
119
+ throw new Task_Error('changeset version failed: are there any changes?');
120
+ }
109
121
  }
110
122
  }
111
123
  if (build) {
112
- await invoke_task('build', { install });
124
+ await invoke_task('build');
113
125
  }
114
126
  if (dry) {
115
127
  log.info('publishing branch ' + branch);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { register } from 'node:module';
2
+ register('./loader.js', import.meta.url);
@@ -0,0 +1,5 @@
1
+ import { z } from 'zod';
2
+ import { type Task } from './task.js';
3
+ export declare const Args: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
4
+ export type Args = z.infer<typeof Args>;
5
+ export declare const task: Task<Args>;
@@ -0,0 +1,32 @@
1
+ import { z } from 'zod';
2
+ import { spawn } from '@ryanatkn/belt/process.js';
3
+ import { rm } from 'fs/promises';
4
+ import { Task_Error } from './task.js';
5
+ import { LOCKFILE_FILENAME, NODE_MODULES_DIRNAME } from './path_constants.js';
6
+ export const Args = z.object({}).strict();
7
+ export const task = {
8
+ summary: `refreshes ${LOCKFILE_FILENAME} with the latest and cleanest deps`,
9
+ Args,
10
+ run: async ({ log }) => {
11
+ log.info('running the initial npm install');
12
+ const initial_install_result = await spawn('npm', ['i']);
13
+ if (!initial_install_result.ok) {
14
+ throw new Task_Error('Failed initial npm install');
15
+ }
16
+ // Deleting both the lockfile and node_modules upgrades to the latest minor/patch versions.
17
+ await Promise.all([rm(LOCKFILE_FILENAME), rm(NODE_MODULES_DIRNAME, { recursive: true })]);
18
+ log.info(`running npm install after deleting ${LOCKFILE_FILENAME} and ${NODE_MODULES_DIRNAME}, this can take a while...`);
19
+ const second_install_result = await spawn('npm', ['i']);
20
+ if (!second_install_result.ok) {
21
+ throw new Task_Error(`Failed npm install after deleting ${LOCKFILE_FILENAME} and ${NODE_MODULES_DIRNAME}`);
22
+ }
23
+ // Deleting the lockfile and reinstalling cleans the lockfile of unnecessary dep noise,
24
+ // like esbuild's many packages for each platform.
25
+ await rm(LOCKFILE_FILENAME);
26
+ log.info(`running npm install one last time to clean ${LOCKFILE_FILENAME}`);
27
+ const final_install_result = await spawn('npm', ['i']);
28
+ if (!final_install_result.ok) {
29
+ throw new Task_Error('Failed npm install');
30
+ }
31
+ },
32
+ };
@@ -1,18 +1,16 @@
1
1
  import { z } from 'zod';
2
- import { has_sveltekit_library } from './gro_plugin_sveltekit_library.js';
3
- import { has_sveltekit_app } from './gro_plugin_sveltekit_app.js';
2
+ import { has_sveltekit_library, has_sveltekit_app } from './sveltekit_helpers.js';
4
3
  export const Args = z.object({}).strict();
5
4
  export const task = {
6
5
  summary: 'publish and deploy',
7
6
  Args,
8
7
  run: async ({ invoke_task }) => {
9
- const publish = await has_sveltekit_library();
8
+ const publish = (await has_sveltekit_library()).ok;
10
9
  if (publish) {
11
- await invoke_task('publish'); // TODO use `to_forwarded_args`
10
+ await invoke_task('publish', { optional: true });
12
11
  }
13
- const deploy = await has_sveltekit_app();
14
- if (deploy) {
15
- await invoke_task('deploy', { build: !publish }); // TODO use `to_forwarded_args`
12
+ if ((await has_sveltekit_app()).ok) {
13
+ await invoke_task('deploy', { build: !publish });
16
14
  }
17
15
  },
18
16
  };
@@ -1,6 +1,7 @@
1
1
  import { join } from 'node:path';
2
2
  import { Package_Json, load_package_json } from './package_json.js';
3
- import { NODE_MODULES_DIRNAME, Source_Id, paths } from './paths.js';
3
+ import { Source_Id, paths } from './paths.js';
4
+ import { NODE_MODULES_DIRNAME } from './path_constants.js';
4
5
  export const resolve_node_specifier = async (specifier, dir = paths.root, parent_url, cache, exports_key = specifier.endsWith('.svelte') ? 'svelte' : 'default') => {
5
6
  const parsed = parse_node_specifier(specifier);
6
7
  const subpath = './' + parsed.path;
package/dist/run.task.js CHANGED
@@ -20,7 +20,7 @@ export const task = {
20
20
  return;
21
21
  }
22
22
  if (!(await exists(path))) {
23
- throw new Task_Error('cannot find file to run at path: ' + path);
23
+ throw new Task_Error('Cannot find file to run at path: ' + path);
24
24
  }
25
25
  const loader_path = await resolve_gro_module_path('loader.js');
26
26
  const spawned = await spawn_with_loader(loader_path, path, argv);
package/dist/run_gen.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { type Gen_Module_Meta } from './gen_module.js';
2
2
  import { type Gen_Results } from './gen.js';
3
3
  import type { format_file as base_format_file } from './format_file.js';
4
+ import type { Gro_Config } from './config.js';
4
5
  export declare const GEN_NO_PROD_MESSAGE = "gen runs only during development";
5
- export declare const run_gen: (gen_modules: Gen_Module_Meta[], log: Logger, timings: Timings, format_file?: typeof base_format_file) => Promise<Gen_Results>;
6
+ export declare const run_gen: (gen_modules: Gen_Module_Meta[], config: Gro_Config, log: Logger, timings: Timings, format_file?: typeof base_format_file) => Promise<Gen_Results>;
6
7
  export declare const to_gen_import_path: (id: string) => string;
package/dist/run_gen.js CHANGED
@@ -6,7 +6,7 @@ import { GEN_SCHEMA_PATH_SUFFIX } from './gen_module.js';
6
6
  import { to_gen_result, } from './gen.js';
7
7
  import { print_path, source_id_to_base_path } from './paths.js';
8
8
  export const GEN_NO_PROD_MESSAGE = 'gen runs only during development';
9
- export const run_gen = async (gen_modules, log, timings, format_file) => {
9
+ export const run_gen = async (gen_modules, config, log, timings, format_file) => {
10
10
  let input_count = 0;
11
11
  let output_count = 0;
12
12
  const timing_for_run_gen = timings.start('run_gen');
@@ -15,7 +15,7 @@ export const run_gen = async (gen_modules, log, timings, format_file) => {
15
15
  const { id } = module_meta;
16
16
  const timing_for_module = timings.start(id);
17
17
  // Perform code generation by calling `gen` on the module.
18
- const gen_ctx = { origin_id: id, log };
18
+ const gen_ctx = { origin_id: id, config, log };
19
19
  let raw_gen_result;
20
20
  try {
21
21
  switch (module_meta.type) {
@@ -4,6 +4,7 @@ import { resolve, join } from 'node:path';
4
4
  import { Logger } from '@ryanatkn/belt/log.js';
5
5
  import { Timings } from '@ryanatkn/belt/timings.js';
6
6
  import { run_gen } from './run_gen.js';
7
+ import { load_config } from './config.js';
7
8
  const log = new Logger('test__gen'); // TODO test logger?
8
9
  /* test__gen */
9
10
  const test__gen = suite('gen');
@@ -69,7 +70,7 @@ test__gen('basic behavior', async () => {
69
70
  },
70
71
  };
71
72
  const gen_modules_by_input_path = [mod_a, mod_b, mod_c];
72
- const gen_results = await run_gen(gen_modules_by_input_path, log, new Timings(), async (content, opts) => opts.filepath.endsWith('output_b.ts') ? `${content}/*FORMATTED*/` : content);
73
+ const gen_results = await run_gen(gen_modules_by_input_path, await load_config(), log, new Timings(), async (content, opts) => opts.filepath.endsWith('output_b.ts') ? `${content}/*FORMATTED*/` : content);
73
74
  assert.is(gen_results.input_count, 3);
74
75
  assert.is(gen_results.output_count, 4);
75
76
  assert.is(gen_results.successes.length, 3);
@@ -153,7 +154,7 @@ test__gen('failing gen function', async () => {
153
154
  },
154
155
  };
155
156
  const gen_modules_by_input_path = [mod_a, mod_b];
156
- const gen_results = await run_gen(gen_modules_by_input_path, log, new Timings());
157
+ const gen_results = await run_gen(gen_modules_by_input_path, await load_config(), log, new Timings());
157
158
  assert.is(gen_results.input_count, 2);
158
159
  assert.is(gen_results.output_count, 1);
159
160
  assert.is(gen_results.successes.length, 1);
package/dist/run_task.js CHANGED
@@ -28,7 +28,7 @@ export const run_task = async (task_meta, unparsed_args, invoke_task, config, ti
28
28
  config,
29
29
  log,
30
30
  timings,
31
- invoke_task: (invoked_task_name, invoked_args = {}, invoked_config) => invoke_task(invoked_task_name, invoked_args, invoked_config || config, timings),
31
+ invoke_task: (invoked_task_name, invoked_args, invoked_config) => invoke_task(invoked_task_name, invoked_args, invoked_config || config, timings),
32
32
  });
33
33
  }
34
34
  catch (err) {
@@ -3,7 +3,7 @@ import type { Config as SveltekitConfig } from '@sveltejs/kit';
3
3
  import type { CompileOptions, PreprocessorGroup, ModuleCompileOptions } from 'svelte/compiler';
4
4
  /**
5
5
  * Loads a SvelteKit config at `dir`.
6
- * @returns
6
+ * @returns `null` if no config is found
7
7
  */
8
8
  export declare const load_sveltekit_config: (dir?: string) => Promise<SveltekitConfig | null>;
9
9
  /**
@@ -1,11 +1,15 @@
1
1
  import { join } from 'node:path';
2
- import { cwd } from 'node:process';
3
- import { SVELTEKIT_CONFIG_FILENAME } from './paths.js';
2
+ import { SVELTEKIT_CONFIG_FILENAME } from './path_constants.js';
3
+ /*
4
+
5
+ This module is intended to have minimal dependencies to avoid over-imports in the CLI.
6
+
7
+ */
4
8
  /**
5
9
  * Loads a SvelteKit config at `dir`.
6
- * @returns
10
+ * @returns `null` if no config is found
7
11
  */
8
- export const load_sveltekit_config = async (dir = cwd()) => {
12
+ export const load_sveltekit_config = async (dir = process.cwd()) => {
9
13
  try {
10
14
  return (await import(join(dir, SVELTEKIT_CONFIG_FILENAME))).default;
11
15
  }
@@ -19,7 +23,7 @@ export const load_sveltekit_config = async (dir = cwd()) => {
19
23
  * as a convenience wrapper around `load_sveltekit_config`.
20
24
  * Needed because SvelteKit doesn't expose its config resolver.
21
25
  */
22
- export const init_sveltekit_config = async (dir_or_config = cwd()) => {
26
+ export const init_sveltekit_config = async (dir_or_config = process.cwd()) => {
23
27
  const sveltekit_config = typeof dir_or_config === 'string' ? await load_sveltekit_config(dir_or_config) : dir_or_config;
24
28
  const kit = sveltekit_config?.kit;
25
29
  const alias = kit?.alias;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * The parsed SvelteKit config for the cwd, cached globally at the module level.
3
+ */
4
+ export declare const sveltekit_config_global: import("./sveltekit_config.js").Parsed_Sveltekit_Config;
@@ -0,0 +1,5 @@
1
+ import { init_sveltekit_config } from './sveltekit_config.js';
2
+ /**
3
+ * The parsed SvelteKit config for the cwd, cached globally at the module level.
4
+ */
5
+ export const sveltekit_config_global = await init_sveltekit_config(); // always load it to keep things simple ahead
@@ -0,0 +1,17 @@
1
+ import type { Result } from '@ryanatkn/belt/result.js';
2
+ import { Package_Json } from './package_json.js';
3
+ import type { Parsed_Sveltekit_Config } from './sveltekit_config.js';
4
+ export declare const SVELTEKIT_CLI = "svelte-kit";
5
+ export declare const SVELTE_PACKAGE_CLI = "svelte-package";
6
+ export declare const SVELTE_PACKAGE_DEP_NAME = "@sveltejs/package";
7
+ export declare const has_sveltekit_app: () => Promise<Result<object, {
8
+ message: string;
9
+ }>>;
10
+ export declare const has_sveltekit_library: (package_json?: Package_Json, sveltekit_config?: Parsed_Sveltekit_Config) => Promise<Result<object, {
11
+ message: string;
12
+ }>>;
13
+ export declare const sveltekit_sync: () => Promise<void>;
14
+ /**
15
+ * If the SvelteKit CLI is found and its `.svelte-kit` directory is not, run `svelte-kit sync`.
16
+ */
17
+ export declare const sveltekit_sync_if_obviously_needed: () => Promise<void>;
@@ -0,0 +1,54 @@
1
+ import { Package_Json, load_package_json } from './package_json.js';
2
+ import { exists } from './fs.js';
3
+ import { sveltekit_config_global } from './sveltekit_config_global.js';
4
+ import { SVELTEKIT_CONFIG_FILENAME, SVELTEKIT_DEV_DIRNAME } from './path_constants.js';
5
+ import { find_cli, spawn_cli } from './cli.js';
6
+ import { Task_Error } from './task.js';
7
+ export const SVELTEKIT_CLI = 'svelte-kit';
8
+ export const SVELTE_PACKAGE_CLI = 'svelte-package';
9
+ export const SVELTE_PACKAGE_DEP_NAME = '@sveltejs/package';
10
+ export const has_sveltekit_app = async () => {
11
+ if (!(await exists(SVELTEKIT_CONFIG_FILENAME))) {
12
+ return { ok: false, message: `no SvelteKit config found at ${SVELTEKIT_CONFIG_FILENAME}` };
13
+ }
14
+ // TODO check for routes?
15
+ return { ok: true };
16
+ };
17
+ export const has_sveltekit_library = async (package_json, sveltekit_config = sveltekit_config_global) => {
18
+ const has_sveltekit_app_result = await has_sveltekit_app();
19
+ if (!has_sveltekit_app_result.ok) {
20
+ return has_sveltekit_app_result;
21
+ }
22
+ if (!(await exists(sveltekit_config.lib_path))) {
23
+ return { ok: false, message: `no SvelteKit lib directory found at ${sveltekit_config.lib_path}` };
24
+ }
25
+ const pkg = package_json ?? (await load_package_json());
26
+ if (!(pkg.devDependencies?.[SVELTE_PACKAGE_DEP_NAME] || pkg.dependencies?.[SVELTE_PACKAGE_DEP_NAME])) {
27
+ return {
28
+ ok: false,
29
+ message: `no dependency found in package.json for ${SVELTE_PACKAGE_DEP_NAME}, install it with \`npm i -D ${SVELTE_PACKAGE_DEP_NAME}\``,
30
+ };
31
+ }
32
+ return { ok: true };
33
+ };
34
+ export const sveltekit_sync = async () => {
35
+ if (!(await find_cli(SVELTEKIT_CLI))) {
36
+ throw new Task_Error(`Failed to find ${SVELTEKIT_CLI} CLI - do you need to run \`npm i\`?`);
37
+ }
38
+ const result = await spawn_cli(SVELTEKIT_CLI, ['sync']);
39
+ if (!result?.ok) {
40
+ throw new Task_Error(`Failed ${SVELTEKIT_CLI} sync`);
41
+ }
42
+ };
43
+ /**
44
+ * If the SvelteKit CLI is found and its `.svelte-kit` directory is not, run `svelte-kit sync`.
45
+ */
46
+ export const sveltekit_sync_if_obviously_needed = async () => {
47
+ if (await exists(SVELTEKIT_DEV_DIRNAME)) {
48
+ return;
49
+ }
50
+ if (!(await find_cli(SVELTEKIT_CLI))) {
51
+ return;
52
+ }
53
+ return sveltekit_sync();
54
+ };
@@ -27,4 +27,3 @@ export declare const Args: z.ZodObject<{
27
27
  }>;
28
28
  export type Args = z.infer<typeof Args>;
29
29
  export declare const task: Task<Args>;
30
- export declare const sveltekit_sync: () => Promise<void>;
package/dist/sync.task.js CHANGED
@@ -2,7 +2,7 @@ import { z } from 'zod';
2
2
  import { spawn } from '@ryanatkn/belt/process.js';
3
3
  import { Task_Error } from './task.js';
4
4
  import { sync_package_json } from './package_json.js';
5
- import { find_cli, spawn_cli } from './cli.js';
5
+ import { sveltekit_sync } from './sveltekit_helpers.js';
6
6
  export const Args = z
7
7
  .object({
8
8
  sveltekit: z.boolean({ description: 'dual of no-sveltekit' }).default(true),
@@ -20,7 +20,10 @@ export const task = {
20
20
  run: async ({ args, invoke_task, config, log }) => {
21
21
  const { sveltekit, package_json, gen, install } = args;
22
22
  if (install) {
23
- await spawn('npm', ['i']);
23
+ const result = await spawn('npm', ['i']);
24
+ if (!result.ok) {
25
+ throw new Task_Error('Failed npm install');
26
+ }
24
27
  }
25
28
  if (sveltekit) {
26
29
  await sveltekit_sync();
@@ -34,12 +37,3 @@ export const task = {
34
37
  }
35
38
  },
36
39
  };
37
- export const sveltekit_sync = async () => {
38
- if (!(await find_cli('svelte-kit'))) {
39
- throw new Task_Error('failed to find svelte-kit CLI - do you need to run `npm i`?');
40
- }
41
- const result = await spawn_cli('svelte-kit', ['sync']);
42
- if (!result?.ok) {
43
- throw new Task_Error(`failed svelte-kit sync`);
44
- }
45
- };
package/dist/task.d.ts CHANGED
@@ -19,7 +19,7 @@ export interface Task_Context<T_Args = object> {
19
19
  export declare const TASK_FILE_SUFFIX_TS = ".task.ts";
20
20
  export declare const TASK_FILE_SUFFIX_JS = ".task.js";
21
21
  export declare const is_task_path: (path: string) => boolean;
22
- export declare const to_task_name: (id: Flavored<string, "Source_Id">) => string;
22
+ export declare const to_task_name: (id: Flavored<string, "Source_Id">, task_root_paths: string[]) => string;
23
23
  /**
24
24
  * This is used by tasks to signal a known failure.
25
25
  * It's useful for cleaning up logging because
package/dist/task.js CHANGED
@@ -1,13 +1,17 @@
1
- import { strip_end } from '@ryanatkn/belt/string.js';
2
- import { import_id_to_lib_path } from './paths.js';
1
+ import { strip_end, strip_start } from '@ryanatkn/belt/string.js';
3
2
  export const TASK_FILE_SUFFIX_TS = '.task.ts';
4
3
  export const TASK_FILE_SUFFIX_JS = '.task.js';
5
4
  export const is_task_path = (path) => path.endsWith(TASK_FILE_SUFFIX_TS) || path.endsWith(TASK_FILE_SUFFIX_JS);
6
- // TODO use task root paths? what's the right behavior?
7
- export const to_task_name = (id) => {
8
- const lib_path = import_id_to_lib_path(id);
9
- const name = strip_end(strip_end(lib_path, TASK_FILE_SUFFIX_TS), TASK_FILE_SUFFIX_JS);
10
- return name;
5
+ export const to_task_name = (id, task_root_paths) => {
6
+ let base_path = id;
7
+ // If the id is in any of the task root paths, use the first match and strip it.
8
+ for (const task_root_path of task_root_paths) {
9
+ if (id.startsWith(task_root_path)) {
10
+ base_path = strip_start(strip_start(id, task_root_path), '/');
11
+ break;
12
+ }
13
+ }
14
+ return strip_end(strip_end(base_path, TASK_FILE_SUFFIX_TS), TASK_FILE_SUFFIX_JS);
11
15
  };
12
16
  /**
13
17
  * This is used by tasks to signal a known failure.