@ryanatkn/gro 0.118.0 → 0.119.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 (56) hide show
  1. package/README.md +6 -4
  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 +9 -5
  6. package/dist/check.task.js +1 -1
  7. package/dist/deploy.task.d.ts +0 -6
  8. package/dist/deploy.task.js +2 -7
  9. package/dist/dev.task.d.ts +2 -2
  10. package/dist/docs/gen.md +11 -0
  11. package/dist/docs/publish.md +1 -8
  12. package/dist/docs/task.md +7 -0
  13. package/dist/docs/tasks.md +1 -0
  14. package/dist/format_directory.d.ts +8 -2
  15. package/dist/format_directory.js +15 -10
  16. package/dist/gen.d.ts +14 -0
  17. package/dist/gen.js +45 -0
  18. package/dist/gen.task.js +17 -17
  19. package/dist/gen_module.d.ts +1 -14
  20. package/dist/gen_module.js +0 -22
  21. package/dist/git.d.ts +5 -0
  22. package/dist/git.js +15 -0
  23. package/dist/git.test.js +4 -1
  24. package/dist/gro.config.default.js +5 -9
  25. package/dist/gro_plugin_gen.js +1 -1
  26. package/dist/gro_plugin_server.d.ts +4 -1
  27. package/dist/gro_plugin_server.js +6 -1
  28. package/dist/gro_plugin_sveltekit_library.js +9 -4
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.js +0 -1
  31. package/dist/invoke.js +2 -0
  32. package/dist/invoke_task.d.ts +1 -1
  33. package/dist/invoke_task.js +1 -1
  34. package/dist/package.d.ts +11 -0
  35. package/dist/package.js +26 -8
  36. package/dist/package_json.js +1 -1
  37. package/dist/path_constants.d.ts +1 -0
  38. package/dist/path_constants.js +1 -0
  39. package/dist/publish.task.d.ts +9 -6
  40. package/dist/publish.task.js +25 -13
  41. package/dist/reinstall.task.d.ts +5 -0
  42. package/dist/reinstall.task.js +32 -0
  43. package/dist/release.task.js +4 -5
  44. package/dist/run.task.js +1 -1
  45. package/dist/run_task.js +1 -1
  46. package/dist/sveltekit_helpers.d.ts +15 -2
  47. package/dist/sveltekit_helpers.js +48 -6
  48. package/dist/sync.task.d.ts +0 -1
  49. package/dist/sync.task.js +2 -11
  50. package/dist/task.js +11 -7
  51. package/dist/task.test.js +6 -0
  52. package/dist/task_logging.js +25 -11
  53. package/dist/typecheck.task.js +1 -1
  54. package/dist/upgrade.task.d.ts +4 -1
  55. package/dist/upgrade.task.js +30 -5
  56. package/package.json +7 -3
package/dist/task.js CHANGED
@@ -3,15 +3,19 @@ export const TASK_FILE_SUFFIX_TS = '.task.ts';
3
3
  export const TASK_FILE_SUFFIX_JS = '.task.js';
4
4
  export const is_task_path = (path) => path.endsWith(TASK_FILE_SUFFIX_TS) || path.endsWith(TASK_FILE_SUFFIX_JS);
5
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;
6
+ // If the id is in any of the task root paths, use the longest available match and strip it.
7
+ // This is convoluted because we're not tracking which root path was resolved against the id.
8
+ // TODO improve the data flow of id from task root path so this is unnecessary
9
+ let longest_matching_path = '';
10
+ for (const path of task_root_paths) {
11
+ if (id.startsWith(path) && path.length > longest_matching_path.length) {
12
+ longest_matching_path = path;
12
13
  }
13
14
  }
14
- return strip_end(strip_end(base_path, TASK_FILE_SUFFIX_TS), TASK_FILE_SUFFIX_JS);
15
+ const task_name = longest_matching_path
16
+ ? strip_start(strip_start(id, longest_matching_path), '/')
17
+ : id;
18
+ return strip_end(strip_end(task_name, TASK_FILE_SUFFIX_TS), TASK_FILE_SUFFIX_JS);
15
19
  };
16
20
  /**
17
21
  * This is used by tasks to signal a known failure.
package/dist/task.test.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { test } from 'uvu';
2
2
  import * as assert from 'uvu/assert';
3
+ import { resolve } from 'node:path';
3
4
  import { is_task_path, to_task_name } from './task.js';
4
5
  test('is_task_path basic behavior', () => {
5
6
  assert.ok(is_task_path('foo.task.ts'));
@@ -14,5 +15,10 @@ test('to_task_name basic behavior', () => {
14
15
  assert.is(to_task_name('a/b/c/foo.task.ts', ['a/b/c', 'a']), 'foo');
15
16
  assert.is(to_task_name('a/b/c/foo.task.ts', ['a']), 'b/c/foo');
16
17
  assert.is(to_task_name('a/b/c/foo.task.ts', ['a/b', 'a']), 'c/foo');
18
+ assert.is(to_task_name(resolve('node_modules/@ryanatkn/gro/dist/foo'), [
19
+ resolve('./'),
20
+ resolve('node_modules/@ryanatkn/gro/dist/'),
21
+ ]), 'foo', 'resolves to node_modules before the cwd');
22
+ assert.is(to_task_name(resolve('a/b'), [resolve('b')]), resolve('a/b'), 'falls back to the id when unresolved');
17
23
  });
18
24
  test.run();
@@ -111,11 +111,9 @@ const to_args_schema_type = ({ _def }) => {
111
111
  case ZodFirstPartyTypeKind.ZodUnion:
112
112
  return 'string | string[]'; // TODO support unions of arbitrary types, or more hardcoded ones as needed
113
113
  default: {
114
- if ('type' in _def) {
115
- return to_args_schema_type(_def.type);
116
- }
117
- else if ('innerType' in _def) {
118
- return to_args_schema_type(_def.innerType);
114
+ const subschema = to_subschema(_def);
115
+ if (subschema) {
116
+ return to_args_schema_type(subschema);
119
117
  }
120
118
  else {
121
119
  throw Error('Unknown zod type ' + t);
@@ -124,18 +122,34 @@ const to_args_schema_type = ({ _def }) => {
124
122
  }
125
123
  };
126
124
  const to_args_schema_description = ({ _def }) => {
127
- if (_def.description)
125
+ if (_def.description) {
128
126
  return _def.description;
129
- if ('innerType' in _def) {
130
- return to_args_schema_description(_def.innerType);
127
+ }
128
+ const subschema = to_subschema(_def);
129
+ if (subschema) {
130
+ return to_args_schema_description(subschema);
131
131
  }
132
132
  return '';
133
133
  };
134
134
  const to_args_schema_default = ({ _def }) => {
135
- if (_def.defaultValue)
135
+ if (_def.defaultValue) {
136
136
  return _def.defaultValue();
137
- if ('innerType' in _def) {
138
- return to_args_schema_default(_def.innerType);
137
+ }
138
+ const subschema = to_subschema(_def);
139
+ if (subschema) {
140
+ return to_args_schema_default(subschema);
141
+ }
142
+ return undefined;
143
+ };
144
+ const to_subschema = (_def) => {
145
+ if ('type' in _def) {
146
+ return _def.type;
147
+ }
148
+ else if ('innerType' in _def) {
149
+ return _def.innerType;
150
+ }
151
+ else if ('schema' in _def) {
152
+ return _def.schema;
139
153
  }
140
154
  return undefined;
141
155
  };
@@ -3,7 +3,7 @@ import { z } from 'zod';
3
3
  import { Task_Error } from './task.js';
4
4
  import { print_command_args, serialize_args, to_forwarded_args } from './args.js';
5
5
  import { find_cli, spawn_cli } from './cli.js';
6
- import { sveltekit_sync } from './sync.task.js';
6
+ import { sveltekit_sync } from './sveltekit_helpers.js';
7
7
  export const Args = z.object({}).strict();
8
8
  export const task = {
9
9
  summary: 'run tsc on the project without emitting any files',
@@ -1,7 +1,8 @@
1
1
  import { z } from 'zod';
2
- import type { Task } from './task.js';
2
+ import { type Task } from './task.js';
3
3
  export declare const Args: z.ZodObject<{
4
4
  _: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
5
+ only: z.ZodEffects<z.ZodDefault<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>, string[], string | string[] | undefined>;
5
6
  origin: z.ZodDefault<z.ZodBranded<z.ZodString, "Git_Origin">>;
6
7
  force: z.ZodDefault<z.ZodBoolean>;
7
8
  pull: z.ZodDefault<z.ZodBoolean>;
@@ -14,6 +15,7 @@ export declare const Args: z.ZodObject<{
14
15
  dry: boolean;
15
16
  force: boolean;
16
17
  'no-pull': boolean;
18
+ only: string[];
17
19
  }, {
18
20
  _?: string[] | undefined;
19
21
  origin?: string | undefined;
@@ -21,6 +23,7 @@ export declare const Args: z.ZodObject<{
21
23
  dry?: boolean | undefined;
22
24
  force?: boolean | undefined;
23
25
  'no-pull'?: boolean | undefined;
26
+ only?: string | string[] | undefined;
24
27
  }>;
25
28
  export type Args = z.infer<typeof Args>;
26
29
  export declare const task: Task<Args>;
@@ -1,10 +1,18 @@
1
1
  import { spawn } from '@ryanatkn/belt/process.js';
2
2
  import { z } from 'zod';
3
+ import { Task_Error } from './task.js';
3
4
  import { load_package_json } from './package_json.js';
4
5
  import { Git_Origin, git_pull } from './git.js';
6
+ import { spawn_cli } from './cli.js';
5
7
  export const Args = z
6
8
  .object({
7
9
  _: z.array(z.string(), { description: 'names of deps to exclude from the upgrade' }).default([]),
10
+ only: z
11
+ .union([z.string(), z.array(z.string())], {
12
+ description: 'names of deps to include in the upgrade',
13
+ })
14
+ .default([])
15
+ .transform((v) => (Array.isArray(v) ? v : [v])),
8
16
  origin: Git_Origin.describe('git origin to deploy to').default('origin'),
9
17
  force: z.boolean({ description: 'if true, print out the planned upgrades' }).default(false),
10
18
  pull: z.boolean({ description: 'dual of no-pull' }).default(true),
@@ -15,14 +23,23 @@ export const Args = z
15
23
  export const task = {
16
24
  summary: 'upgrade deps',
17
25
  Args,
18
- run: async ({ args, log, invoke_task }) => {
19
- const { _, origin, force, pull, dry } = args;
26
+ run: async ({ args, log }) => {
27
+ const { _, only, origin, force, pull, dry } = args;
28
+ if (_.length && only.length) {
29
+ throw new Task_Error('Cannot call `gro upgrade` with both rest args and --only.');
30
+ }
20
31
  // TODO maybe a different task that pulls and does other things, like `gro ready`
21
32
  if (pull) {
22
33
  await git_pull(origin);
23
34
  }
24
35
  const package_json = await load_package_json();
25
- const deps = to_deps(package_json).filter((d) => !_.includes(d.key));
36
+ const all_deps = to_deps(package_json);
37
+ const deps = only.length
38
+ ? all_deps.filter((d) => only.includes(d.key))
39
+ : all_deps.filter((d) => !_.includes(d.key));
40
+ if (only.length && only.length !== deps.length) {
41
+ throw new Task_Error(`Some deps to upgrade were not found: ${only.filter((o) => !deps.find((d) => d.key === o)).join(', ')}`);
42
+ }
26
43
  const upgrade_items = to_upgrade_items(deps);
27
44
  log.info(`upgrading:`, upgrade_items.join(' '));
28
45
  const install_args = ['install'].concat(upgrade_items);
@@ -34,7 +51,8 @@ export const task = {
34
51
  install_args.push('--force');
35
52
  }
36
53
  await spawn('npm', install_args);
37
- await invoke_task('sync');
54
+ // Sync in a new process to pick up any changes after installing, avoiding some errors.
55
+ await spawn_cli('gro', ['sync']);
38
56
  },
39
57
  };
40
58
  const to_deps = (package_json) => {
@@ -46,4 +64,11 @@ const to_deps = (package_json) => {
46
64
  : [];
47
65
  return prod_deps.concat(dev_deps);
48
66
  };
49
- const to_upgrade_items = (deps) => deps.map((dep) => dep.key + (dep.value.includes('-next.') ? '@next' : '@latest'));
67
+ // TODO hacky and limited
68
+ // TODO probably want to pass through exact deps as well, e.g. @foo/bar@1
69
+ const to_upgrade_items = (deps) => deps.map((dep) => {
70
+ if (dep.key.endsWith('@next') || dep.key.endsWith('@latest')) {
71
+ return dep.key;
72
+ }
73
+ return dep.key + (dep.value.includes('-next.') ? '@next' : '@latest');
74
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ryanatkn/gro",
3
- "version": "0.118.0",
3
+ "version": "0.119.1",
4
4
  "description": "task runner and toolkit extending SvelteKit",
5
5
  "motto": "generate, run, optimize",
6
6
  "icon": "🌰",
@@ -69,7 +69,7 @@
69
69
  "@ryanatkn/fuz": "^0.102.1",
70
70
  "@ryanatkn/moss": "^0.4.0",
71
71
  "@sveltejs/adapter-static": "^3.0.2",
72
- "@sveltejs/kit": "^2.5.15",
72
+ "@sveltejs/kit": "^2.5.16",
73
73
  "@sveltejs/package": "^2.3.2",
74
74
  "@sveltejs/vite-plugin-svelte": "^3.1.1",
75
75
  "@types/fs-extra": "^11.0.4",
@@ -78,7 +78,7 @@
78
78
  "@typescript-eslint/parser": "^7.13.0",
79
79
  "esbuild": "^0.20.2",
80
80
  "eslint": "^8.57.0",
81
- "eslint-plugin-svelte": "^2.39.3",
81
+ "eslint-plugin-svelte": "^2.39.4",
82
82
  "svelte": "^5.0.0-next.155",
83
83
  "svelte-check": "^3.8.0",
84
84
  "typescript": "^5.4.5",
@@ -330,6 +330,10 @@
330
330
  "default": "./dist/register.js",
331
331
  "types": "./dist/register.d.ts"
332
332
  },
333
+ "./reinstall.task.js": {
334
+ "default": "./dist/reinstall.task.js",
335
+ "types": "./dist/reinstall.task.d.ts"
336
+ },
333
337
  "./release.task.js": {
334
338
  "default": "./dist/release.task.js",
335
339
  "types": "./dist/release.task.d.ts"