@ryanatkn/gro 0.129.0 → 0.129.2

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 (80) hide show
  1. package/README.md +3 -3
  2. package/dist/args.d.ts +2 -2
  3. package/dist/args.js +2 -2
  4. package/dist/changelog.test.js +1 -1
  5. package/dist/changeset.task.js +6 -6
  6. package/dist/cli.js +1 -1
  7. package/dist/config.d.ts +1 -3
  8. package/dist/config.js +2 -2
  9. package/dist/deploy.task.js +1 -1
  10. package/dist/docs/README.gen.md.js +1 -1
  11. package/dist/docs/package_json.md +2 -1
  12. package/dist/env.d.ts +2 -2
  13. package/dist/env.js +10 -11
  14. package/dist/esbuild_helpers.js +2 -1
  15. package/dist/esbuild_plugin_external_worker.js +1 -1
  16. package/dist/esbuild_plugin_svelte.js +3 -3
  17. package/dist/esbuild_plugin_sveltekit_local_imports.js +2 -2
  18. package/dist/esbuild_plugin_sveltekit_shim_env.js +2 -2
  19. package/dist/format_file.js +2 -2
  20. package/dist/gen.d.ts +10 -12
  21. package/dist/gen.js +3 -3
  22. package/dist/gen.task.js +1 -1
  23. package/dist/gen.test.js +2 -5
  24. package/dist/git.d.ts +1 -1
  25. package/dist/gro.config.default.js +1 -1
  26. package/dist/gro.js +1 -1
  27. package/dist/gro_helpers.js +1 -2
  28. package/dist/gro_plugin_gen.js +3 -4
  29. package/dist/gro_plugin_server.d.ts +5 -7
  30. package/dist/gro_plugin_server.js +3 -3
  31. package/dist/gro_plugin_sveltekit_app.d.ts +3 -5
  32. package/dist/gro_plugin_sveltekit_app.js +38 -28
  33. package/dist/gro_plugin_sveltekit_library.d.ts +2 -2
  34. package/dist/gro_plugin_sveltekit_library.js +2 -2
  35. package/dist/input_path.test.js +1 -1
  36. package/dist/invoke_task.js +3 -3
  37. package/dist/lint.task.js +1 -2
  38. package/dist/loader.js +3 -3
  39. package/dist/package.d.ts +7 -10
  40. package/dist/package.gen.js +3 -3
  41. package/dist/package.js +18 -15
  42. package/dist/package_json.d.ts +4 -6
  43. package/dist/package_json.js +14 -15
  44. package/dist/package_json.test.js +12 -12
  45. package/dist/path.d.ts +2 -6
  46. package/dist/plugin.d.ts +1 -3
  47. package/dist/plugin.js +2 -2
  48. package/dist/plugin.test.js +3 -3
  49. package/dist/publish.task.js +4 -4
  50. package/dist/release.task.js +2 -2
  51. package/dist/resolve.task.d.ts +3 -0
  52. package/dist/resolve.task.js +22 -8
  53. package/dist/resolve_node_specifier.d.ts +1 -1
  54. package/dist/resolve_node_specifier.js +2 -2
  55. package/dist/resolve_node_specifier.test.js +6 -6
  56. package/dist/resolve_specifier.d.ts +1 -1
  57. package/dist/resolve_specifier.js +1 -1
  58. package/dist/resolve_specifier.test.js +16 -16
  59. package/dist/run_gen.test.js +11 -11
  60. package/dist/run_task.js +1 -1
  61. package/dist/run_task.test.js +3 -2
  62. package/dist/src_json.d.ts +3 -5
  63. package/dist/src_json.js +11 -13
  64. package/dist/src_json.test.js +2 -2
  65. package/dist/sveltekit_config.js +1 -1
  66. package/dist/sveltekit_helpers.d.ts +4 -4
  67. package/dist/sveltekit_helpers.js +4 -4
  68. package/dist/sveltekit_shim_env.d.ts +1 -1
  69. package/dist/sveltekit_shim_env.js +2 -2
  70. package/dist/task.d.ts +1 -1
  71. package/dist/task.js +6 -1
  72. package/dist/task.test.js +5 -0
  73. package/dist/task_logging.d.ts +1 -1
  74. package/dist/task_logging.js +3 -4
  75. package/dist/upgrade.task.js +9 -3
  76. package/dist/watch_dir.d.ts +1 -3
  77. package/dist/watch_dir.js +6 -6
  78. package/package.json +18 -21
  79. package/dist/fs.test.d.ts +0 -1
  80. package/dist/fs.test.js +0 -16
@@ -1,7 +1,7 @@
1
1
  import { test } from 'uvu';
2
2
  import * as assert from 'uvu/assert';
3
3
  import { replace_plugin } from './plugin.js';
4
- test('replace_plugin', async () => {
4
+ test('replace_plugin', () => {
5
5
  const a = { name: 'a' };
6
6
  const b = { name: 'b' };
7
7
  const c = { name: 'c' };
@@ -32,13 +32,13 @@ test('replace_plugin', async () => {
32
32
  assert.is(p[1], b2);
33
33
  assert.is(p[2], c2);
34
34
  });
35
- test('replace_plugin without an array', async () => {
35
+ test('replace_plugin without an array', () => {
36
36
  const a = { name: 'a' };
37
37
  const a2 = { name: 'a' };
38
38
  const p = replace_plugin(a, a2);
39
39
  assert.is(p[0], a2);
40
40
  });
41
- test('replace_plugin throws if it cannot find the given name', async () => {
41
+ test('replace_plugin throws if it cannot find the given name', () => {
42
42
  const a = { name: 'a' };
43
43
  const plugins = [a];
44
44
  let err;
@@ -52,7 +52,7 @@ export const task = {
52
52
  if (dry) {
53
53
  log.info(green('dry run!'));
54
54
  }
55
- const has_sveltekit_library_result = await has_sveltekit_library();
55
+ const has_sveltekit_library_result = has_sveltekit_library();
56
56
  if (!has_sveltekit_library_result.ok) {
57
57
  throw new Task_Error('Failed to find SvelteKit library: ' + has_sveltekit_library_result.message);
58
58
  }
@@ -88,7 +88,7 @@ export const task = {
88
88
  log.info('dry run, skipping changeset version');
89
89
  }
90
90
  else {
91
- const package_json_before = await load_package_json();
91
+ const package_json_before = load_package_json();
92
92
  if (typeof package_json_before.version !== 'string') {
93
93
  throw new Task_Error('Failed to find package.json version');
94
94
  }
@@ -104,13 +104,13 @@ export const task = {
104
104
  throw Error('npm version failed: no commits were made: see the error above');
105
105
  }
106
106
  if (!preserve_changelog) {
107
- const token = await load_from_env('GITHUB_TOKEN_SECRET');
107
+ const token = load_from_env('GITHUB_TOKEN_SECRET');
108
108
  if (!token) {
109
109
  log.warn('the env var GITHUB_TOKEN_SECRET was not found, so API calls with be unauthorized');
110
110
  }
111
111
  await update_changelog(parsed_repo_url.owner, parsed_repo_url.repo, changelog, token, log);
112
112
  }
113
- const package_json_after = await load_package_json();
113
+ const package_json_after = load_package_json();
114
114
  version = package_json_after.version;
115
115
  if (package_json_before.version === version) {
116
116
  // The version didn't change.
@@ -5,11 +5,11 @@ export const task = {
5
5
  summary: 'publish and deploy',
6
6
  Args,
7
7
  run: async ({ invoke_task }) => {
8
- const publish = (await has_sveltekit_library()).ok;
8
+ const publish = has_sveltekit_library().ok;
9
9
  if (publish) {
10
10
  await invoke_task('publish', { optional: true });
11
11
  }
12
- if ((await has_sveltekit_app()).ok) {
12
+ if (has_sveltekit_app().ok) {
13
13
  await invoke_task('deploy', { build: !publish });
14
14
  }
15
15
  },
@@ -2,10 +2,13 @@ import { z } from 'zod';
2
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
+ verbose: z.ZodDefault<z.ZodBoolean>;
5
6
  }, "strict", z.ZodTypeAny, {
6
7
  _: string[];
8
+ verbose: boolean;
7
9
  }, {
8
10
  _?: string[] | undefined;
11
+ verbose?: boolean | undefined;
9
12
  }>;
10
13
  export type Args = z.infer<typeof Args>;
11
14
  export declare const task: Task<Args>;
@@ -1,24 +1,38 @@
1
1
  import { z } from 'zod';
2
+ import { green, yellow } from '@ryanatkn/belt/styletext.js';
2
3
  import { TASK_FILE_SUFFIXES } from './task.js';
3
4
  import { resolve_input_paths, to_input_paths } from './input_path.js';
4
5
  export const Args = z
5
6
  .object({
6
7
  _: z.array(z.string(), { description: 'the input paths to resolve' }).default(['']),
8
+ verbose: z.boolean({ description: 'log diagnostics' }).default(false),
7
9
  })
8
10
  .strict();
9
11
  export const task = {
10
12
  summary: 'diagnostic that logs resolved filesystem info for the given input paths',
11
13
  Args,
12
- run: async ({ args, config, log }) => {
13
- const { _ } = args;
14
- log.info('raw input paths:', _);
14
+ run: ({ args, config, log }) => {
15
+ const { _, verbose } = args;
16
+ if (verbose)
17
+ log.info('raw input paths:', _);
15
18
  const input_paths = to_input_paths(_);
16
- log.info('input paths:', input_paths);
19
+ if (verbose)
20
+ log.info('input paths:', input_paths);
17
21
  const { task_root_dirs } = config;
18
- log.info('task root paths:', task_root_dirs);
22
+ if (verbose)
23
+ log.info('task root paths:', task_root_dirs);
19
24
  const { resolved_input_paths, possible_paths_by_input_path, unmapped_input_paths } = resolve_input_paths(input_paths, task_root_dirs, TASK_FILE_SUFFIXES);
20
- log.info('resolved_input_paths:', resolved_input_paths);
21
- log.info('possible_paths_by_input_path:', possible_paths_by_input_path);
22
- log.info('unmapped_input_paths:', unmapped_input_paths);
25
+ if (verbose)
26
+ log.info('resolved_input_paths:', resolved_input_paths);
27
+ if (verbose)
28
+ log.info('possible_paths_by_input_path:', possible_paths_by_input_path);
29
+ if (verbose)
30
+ log.info('unmapped_input_paths:', unmapped_input_paths);
31
+ for (const p of resolved_input_paths) {
32
+ log.info('resolved:', green(p.id));
33
+ }
34
+ if (!resolved_input_paths.length) {
35
+ log.warn(yellow('no input paths were resolved'));
36
+ }
23
37
  },
24
38
  };
@@ -1,6 +1,6 @@
1
1
  import { Package_Json } from './package_json.js';
2
2
  import type { Path_Id } from './path.js';
3
- export declare const resolve_node_specifier: (specifier: string, dir?: string, parent_url?: string, cache?: Record<string, Package_Json>, exports_key?: string) => Promise<Path_Id>;
3
+ export declare const resolve_node_specifier: (specifier: string, dir?: string, parent_url?: string, cache?: Record<string, Package_Json>, exports_key?: string) => Path_Id;
4
4
  export interface Parsed_Node_Specifier {
5
5
  name: string;
6
6
  path: string;
@@ -2,11 +2,11 @@ import { join } from 'node:path';
2
2
  import { Package_Json, load_package_json } from './package_json.js';
3
3
  import { paths } from './paths.js';
4
4
  import { NODE_MODULES_DIRNAME } from './path_constants.js';
5
- export const resolve_node_specifier = async (specifier, dir = paths.root, parent_url, cache, exports_key = specifier.endsWith('.svelte') ? 'svelte' : 'default') => {
5
+ export const resolve_node_specifier = (specifier, dir = paths.root, parent_url, cache, exports_key = specifier.endsWith('.svelte') ? 'svelte' : 'default') => {
6
6
  const parsed = parse_node_specifier(specifier);
7
7
  const subpath = './' + parsed.path;
8
8
  const package_dir = join(dir, NODE_MODULES_DIRNAME, parsed.name);
9
- const package_json = await load_package_json(package_dir, cache);
9
+ const package_json = load_package_json(package_dir, cache);
10
10
  const exported = package_json.exports?.[subpath];
11
11
  if (!exported) {
12
12
  // same error message as Node
@@ -2,16 +2,16 @@ import { test } from 'uvu';
2
2
  import * as assert from 'uvu/assert';
3
3
  import { resolve_node_specifier } from './resolve_node_specifier.js';
4
4
  import { paths } from './paths.js';
5
- test('resolves a JS specifier', async () => {
6
- assert.is(await resolve_node_specifier('@ryanatkn/fuz/tome.js'), paths.root + 'node_modules/@ryanatkn/fuz/dist/tome.js');
5
+ test('resolves a JS specifier', () => {
6
+ assert.is(resolve_node_specifier('@ryanatkn/fuz/tome.js'), paths.root + 'node_modules/@ryanatkn/fuz/dist/tome.js');
7
7
  });
8
- test('resolves a Svelte specifier', async () => {
9
- assert.is(await resolve_node_specifier('@ryanatkn/fuz/Library.svelte'), paths.root + 'node_modules/@ryanatkn/fuz/dist/Library.svelte');
8
+ test('resolves a Svelte specifier', () => {
9
+ assert.is(resolve_node_specifier('@ryanatkn/fuz/Library.svelte'), paths.root + 'node_modules/@ryanatkn/fuz/dist/Library.svelte');
10
10
  });
11
- test('throws for a specifier that does not exist', async () => {
11
+ test('throws for a specifier that does not exist', () => {
12
12
  let err;
13
13
  try {
14
- await resolve_node_specifier('@ryanatkn/fuz/this_does_not_exist');
14
+ resolve_node_specifier('@ryanatkn/fuz/this_does_not_exist');
15
15
  }
16
16
  catch (_err) {
17
17
  err = _err;
@@ -13,4 +13,4 @@ export interface Resolved_Specifier {
13
13
  * @param passthrough_extensions - used to support specifiers that have no file extention, which Vite supports, so we do our best effort
14
14
  * @returns
15
15
  */
16
- export declare const resolve_specifier: (path: string, dir: string) => Promise<Resolved_Specifier>;
16
+ export declare const resolve_specifier: (path: string, dir: string) => Resolved_Specifier;
@@ -10,7 +10,7 @@ import { replace_extension } from './paths.js';
10
10
  * @param passthrough_extensions - used to support specifiers that have no file extention, which Vite supports, so we do our best effort
11
11
  * @returns
12
12
  */
13
- export const resolve_specifier = async (path, dir) => {
13
+ export const resolve_specifier = (path, dir) => {
14
14
  const absolute_path = isAbsolute(path) ? path : join(dir, path);
15
15
  let mapped_path;
16
16
  let path_id;
@@ -4,60 +4,60 @@ import { join } from 'node:path';
4
4
  import { resolve_specifier } from './resolve_specifier.js';
5
5
  import { paths } from './paths.js';
6
6
  const dir = paths.source + 'fixtures/';
7
- test('resolves a specifier to a file that exists with an unknown file extension', async () => {
8
- assert.equal(await resolve_specifier(join(dir, 'test_file.other.ext'), dir), {
7
+ test('resolves a specifier to a file that exists with an unknown file extension', () => {
8
+ assert.equal(resolve_specifier(join(dir, 'test_file.other.ext'), dir), {
9
9
  specifier: './test_file.other.ext',
10
10
  path_id: join(dir, 'test_file.other.ext'),
11
11
  namespace: undefined,
12
12
  });
13
13
  });
14
- test('resolves a ts specifier', async () => {
15
- assert.equal(await resolve_specifier(join(dir, 'test_ts.ts'), dir), {
14
+ test('resolves a ts specifier', () => {
15
+ assert.equal(resolve_specifier(join(dir, 'test_ts.ts'), dir), {
16
16
  specifier: './test_ts.js',
17
17
  path_id: join(dir, 'test_ts.ts'),
18
18
  namespace: 'sveltekit_local_imports_ts',
19
19
  });
20
20
  });
21
- test('resolves relative ts specifiers', async () => {
22
- assert.equal(await resolve_specifier('./test_ts.ts', dir), {
21
+ test('resolves relative ts specifiers', () => {
22
+ assert.equal(resolve_specifier('./test_ts.ts', dir), {
23
23
  specifier: './test_ts.js',
24
24
  path_id: join(dir, 'test_ts.ts'),
25
25
  namespace: 'sveltekit_local_imports_ts',
26
26
  });
27
- assert.equal(await resolve_specifier('./a/b/test_ts.ts', dir), {
27
+ assert.equal(resolve_specifier('./a/b/test_ts.ts', dir), {
28
28
  specifier: './a/b/test_ts.js',
29
29
  path_id: join(dir, 'a/b/test_ts.ts'),
30
30
  namespace: 'sveltekit_local_imports_ts',
31
31
  });
32
- assert.equal(await resolve_specifier('../../test_ts.ts', dir), {
32
+ assert.equal(resolve_specifier('../../test_ts.ts', dir), {
33
33
  specifier: '../../test_ts.js',
34
34
  path_id: join(dir, '../../test_ts.ts'),
35
35
  namespace: 'sveltekit_local_imports_ts',
36
36
  });
37
37
  });
38
- test('resolves an extensionless specifier', async () => {
39
- assert.equal(await resolve_specifier(join(dir, 'test_ts'), dir), {
38
+ test('resolves an extensionless specifier', () => {
39
+ assert.equal(resolve_specifier(join(dir, 'test_ts'), dir), {
40
40
  specifier: './test_ts.js',
41
41
  path_id: join(dir, 'test_ts.ts'),
42
42
  namespace: 'sveltekit_local_imports_ts',
43
43
  });
44
44
  });
45
- test('resolves a js specifier', async () => {
46
- assert.equal(await resolve_specifier(join(dir, 'test_js.js'), dir), {
45
+ test('resolves a js specifier', () => {
46
+ assert.equal(resolve_specifier(join(dir, 'test_js.js'), dir), {
47
47
  specifier: './test_js.js',
48
48
  path_id: join(dir, 'test_js.js'),
49
49
  namespace: 'sveltekit_local_imports_js',
50
50
  });
51
51
  });
52
- test('resolves a js specifier as ts for a file that does not exist', async () => {
53
- assert.equal(await resolve_specifier(join(dir, 'test_missing.js'), dir), {
52
+ test('resolves a js specifier as ts for a file that does not exist', () => {
53
+ assert.equal(resolve_specifier(join(dir, 'test_missing.js'), dir), {
54
54
  specifier: './test_missing.js',
55
55
  path_id: join(dir, 'test_missing.ts'),
56
56
  namespace: 'sveltekit_local_imports_ts',
57
57
  });
58
58
  });
59
- test('resolves an extensionless specifier for a file that does not exist', async () => {
60
- assert.equal(await resolve_specifier(join(dir, 'test_missing'), dir), {
59
+ test('resolves an extensionless specifier for a file that does not exist', () => {
60
+ assert.equal(resolve_specifier(join(dir, 'test_missing'), dir), {
61
61
  specifier: './test_missing.js',
62
62
  path_id: join(dir, 'test_missing.ts'),
63
63
  namespace: 'sveltekit_local_imports_ts',
@@ -18,7 +18,7 @@ test__gen('basic behavior', async () => {
18
18
  const mod_a = {
19
19
  id: path_id_a,
20
20
  mod: {
21
- gen: async (ctx) => {
21
+ gen: (ctx) => {
22
22
  assert.is(ctx.origin_id, path_id_a);
23
23
  if (file_a)
24
24
  throw Error('Already generated file_a');
@@ -33,7 +33,7 @@ test__gen('basic behavior', async () => {
33
33
  const mod_b = {
34
34
  id: join(path_id_bc, 'mod_b.gen.ts'),
35
35
  mod: {
36
- gen: async (ctx) => {
36
+ gen: (ctx) => {
37
37
  assert.is(ctx.origin_id, mod_b.id);
38
38
  if (file_b)
39
39
  throw Error('Already generated file_b');
@@ -48,7 +48,7 @@ test__gen('basic behavior', async () => {
48
48
  const mod_c = {
49
49
  id: join(path_id_bc, 'mod_c.gen.ts'),
50
50
  mod: {
51
- gen: async (ctx) => {
51
+ gen: (ctx) => {
52
52
  assert.is(ctx.origin_id, mod_c.id);
53
53
  if (file_c1)
54
54
  throw Error('Already generated file_c1');
@@ -67,7 +67,7 @@ test__gen('basic behavior', async () => {
67
67
  },
68
68
  };
69
69
  const gen_modules_by_input_path = [mod_a, mod_b, mod_c];
70
- 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);
70
+ const gen_results = await run_gen(gen_modules_by_input_path, await load_config(), log, new Timings(), (content, opts) => Promise.resolve(opts.filepath.endsWith('output_b.ts') ? `${content}/*FORMATTED*/` : content));
71
71
  assert.is(gen_results.input_count, 3);
72
72
  assert.is(gen_results.output_count, 4);
73
73
  assert.is(gen_results.successes.length, 3);
@@ -77,7 +77,7 @@ test__gen('basic behavior', async () => {
77
77
  assert.is(gen_results.results[1], gen_results.successes[1]);
78
78
  assert.is(gen_results.results[2], gen_results.successes[2]);
79
79
  const result_a = gen_results.results[0];
80
- assert.ok(result_a?.ok);
80
+ assert.ok(result_a.ok);
81
81
  assert.ok(file_a);
82
82
  assert.equal(result_a.files, [
83
83
  {
@@ -88,7 +88,7 @@ test__gen('basic behavior', async () => {
88
88
  },
89
89
  ]);
90
90
  const result_b = gen_results.results[1];
91
- assert.ok(result_b?.ok);
91
+ assert.ok(result_b.ok);
92
92
  assert.ok(file_b);
93
93
  assert.equal(result_b.files, [
94
94
  {
@@ -99,7 +99,7 @@ test__gen('basic behavior', async () => {
99
99
  },
100
100
  ]);
101
101
  const result_c = gen_results.results[2];
102
- assert.ok(result_c?.ok);
102
+ assert.ok(result_c.ok);
103
103
  assert.ok(file_c1);
104
104
  assert.ok(file_c2);
105
105
  assert.equal(result_c.files, [
@@ -127,7 +127,7 @@ test__gen('failing gen function', async () => {
127
127
  const mod_a = {
128
128
  id: path_id_a,
129
129
  mod: {
130
- gen: async () => {
130
+ gen: () => {
131
131
  genError = Error('This fails for testing');
132
132
  throw genError;
133
133
  },
@@ -136,7 +136,7 @@ test__gen('failing gen function', async () => {
136
136
  const mod_b = {
137
137
  id: join(path_idB, 'mod_b.gen.ts'),
138
138
  mod: {
139
- gen: async (ctx) => {
139
+ gen: (ctx) => {
140
140
  assert.is(ctx.origin_id, mod_b.id);
141
141
  if (file_b)
142
142
  throw Error('Already generated file_b');
@@ -159,11 +159,11 @@ test__gen('failing gen function', async () => {
159
159
  assert.is(gen_results.results[1], gen_results.successes[0]);
160
160
  const result_a = gen_results.results[0];
161
161
  assert.ok(result_a);
162
- assert.ok(!result_a?.ok);
162
+ assert.ok(!result_a.ok);
163
163
  assert.ok(result_a.reason);
164
164
  assert.ok(result_a.error);
165
165
  const result_b = gen_results.results[1];
166
- assert.ok(result_b?.ok);
166
+ assert.ok(result_b.ok);
167
167
  assert.ok(file_b);
168
168
  assert.equal(result_b.files, [
169
169
  {
package/dist/run_task.js CHANGED
@@ -30,7 +30,7 @@ export const run_task = async (task_meta, unparsed_args, invoke_task, config, ti
30
30
  sveltekit_config: sveltekit_config_global,
31
31
  log,
32
32
  timings,
33
- invoke_task: (invoked_task_name, invoked_args, invoked_config) => invoke_task(invoked_task_name, invoked_args, invoked_config || config, timings),
33
+ invoke_task: (invoked_task_name, invoked_args, invoked_config) => invoke_task(invoked_task_name, invoked_args, invoked_config ?? config, timings),
34
34
  });
35
35
  }
36
36
  catch (err) {
@@ -32,9 +32,10 @@ test('invokes a sub task', async () => {
32
32
  },
33
33
  },
34
34
  },
35
- }, args, async (invoking_task_name, invoking_args) => {
35
+ }, args, (invoking_task_name, invoking_args) => {
36
36
  invoked_task_name = invoking_task_name;
37
37
  invoked_args = invoking_args;
38
+ return Promise.resolve();
38
39
  }, await load_config(), new Timings());
39
40
  assert.ok(result.ok);
40
41
  assert.is(invoked_task_name, 'bar/testTask');
@@ -48,7 +49,7 @@ test('failing task', async () => {
48
49
  id: 'foo/testTask',
49
50
  mod: {
50
51
  task: {
51
- run: async () => {
52
+ run: () => {
52
53
  err = Error();
53
54
  throw err;
54
55
  },
@@ -248,9 +248,7 @@ export declare const Src_Json: z.ZodIntersection<z.ZodRecord<z.ZodString, z.ZodU
248
248
  }, z.ZodTypeAny, "passthrough">>>>;
249
249
  }, z.ZodTypeAny, "passthrough">>>;
250
250
  export type Src_Json = z.infer<typeof Src_Json>;
251
- export interface Map_Src_Json {
252
- (src_json: Src_Json): Src_Json | null | Promise<Src_Json | null>;
253
- }
254
- export declare const create_src_json: (package_json: Package_Json, log?: any, lib_path?: string) => Promise<Src_Json>;
251
+ export type Map_Src_Json = (src_json: Src_Json) => Src_Json | null | Promise<Src_Json | null>;
252
+ export declare const create_src_json: (package_json: Package_Json, log?: any, lib_path?: string) => Src_Json;
255
253
  export declare const serialize_src_json: (src_json: Src_Json) => string;
256
- export declare const to_src_modules: (exports: Package_Json_Exports | undefined, log?: any, lib_path?: string) => Promise<Src_Modules | undefined>;
254
+ export declare const to_src_modules: (exports: Package_Json_Exports | undefined, log?: any, lib_path?: string) => Src_Modules | undefined;
package/dist/src_json.js CHANGED
@@ -32,23 +32,22 @@ z
32
32
  modules: Src_Modules.transform(transform_empty_object_to_undefined).optional(),
33
33
  })
34
34
  .passthrough());
35
- export const create_src_json = async (package_json, log, lib_path) => {
36
- return Src_Json.parse({
37
- name: package_json.name,
38
- version: package_json.version,
39
- modules: await to_src_modules(package_json.exports, log, lib_path),
40
- });
41
- };
35
+ export const create_src_json = (package_json, log, lib_path) => Src_Json.parse({
36
+ name: package_json.name,
37
+ version: package_json.version,
38
+ modules: to_src_modules(package_json.exports, log, lib_path),
39
+ });
42
40
  export const serialize_src_json = (src_json) => {
43
41
  const parsed = Src_Json.parse(src_json); // TODO can parse do the logic that normalize does? see `.transform`
44
42
  return JSON.stringify(parsed, null, 2) + '\n';
45
43
  };
46
- export const to_src_modules = async (exports, log, lib_path = paths.lib) => {
44
+ export const to_src_modules = (exports, log, lib_path = paths.lib) => {
47
45
  if (!exports)
48
- return undefined;
46
+ return;
49
47
  const project = new Project();
50
48
  project.addSourceFilesAtPaths('src/**/*.ts'); // TODO dir? maybe rewrite with `lib_path`?
51
- return Object.fromEntries((await Promise.all(Object.entries(exports).map(async ([k, _v]) => {
49
+ return Object.fromEntries(Object.entries(exports)
50
+ .map(([k, _v]) => {
52
51
  // TODO hacky - doesn't handle any but the normal mappings, also add a helper?
53
52
  const source_file_path = k === '.' || k === './'
54
53
  ? 'index.ts'
@@ -68,8 +67,6 @@ export const to_src_modules = async (exports, log, lib_path = paths.lib) => {
68
67
  const source_file = project.getSourceFile((f) => f.getFilePath().endsWith(source_file_path)); // TODO expected this to work without the callback, according to my read of the docs it is, but `project.getSourceFile(source_file_path)` fails
69
68
  if (source_file) {
70
69
  for (const [name, decls] of source_file.getExportedDeclarations()) {
71
- if (!decls)
72
- continue;
73
70
  // TODO how to correctly handle multiples?
74
71
  for (const decl of decls) {
75
72
  // TODO helper
@@ -106,5 +103,6 @@ export const to_src_modules = async (exports, log, lib_path = paths.lib) => {
106
103
  }
107
104
  const src_module = { path: source_file_path, declarations };
108
105
  return [k, src_module];
109
- }))).filter(Boolean));
106
+ })
107
+ .filter((v) => v !== null));
110
108
  };
@@ -3,8 +3,8 @@ import * as assert from 'uvu/assert';
3
3
  import { to_src_modules } from './src_json.js';
4
4
  import { to_package_exports } from './package_json.js';
5
5
  import { paths } from './paths.js';
6
- test('to_package_modules', async () => {
7
- assert.equal(await to_src_modules(to_package_exports([
6
+ test('to_package_modules', () => {
7
+ assert.equal(to_src_modules(to_package_exports([
8
8
  'fixtures/modules/some_test_css.css',
9
9
  'fixtures/modules/Some_Test_Svelte.svelte',
10
10
  'fixtures/modules/some_test_ts.ts',
@@ -13,7 +13,7 @@ export const load_sveltekit_config = async (dir = process.cwd()) => {
13
13
  try {
14
14
  return (await import(join(dir, SVELTEKIT_CONFIG_FILENAME))).default;
15
15
  }
16
- catch (err) {
16
+ catch (_err) {
17
17
  return null;
18
18
  }
19
19
  };
@@ -7,12 +7,12 @@ export declare const SVELTE_CHECK_CLI = "svelte-check";
7
7
  export declare const SVELTE_PACKAGE_CLI = "svelte-package";
8
8
  export declare const SVELTE_PACKAGE_DEP_NAME = "@sveltejs/package";
9
9
  export declare const VITE_CLI = "vite";
10
- export declare const has_sveltekit_app: () => Promise<Result<object, {
10
+ export declare const has_sveltekit_app: () => Result<object, {
11
11
  message: string;
12
- }>>;
13
- export declare const has_sveltekit_library: (package_json?: Package_Json, sveltekit_config?: Parsed_Sveltekit_Config) => Promise<Result<object, {
12
+ }>;
13
+ export declare const has_sveltekit_library: (package_json?: Package_Json, sveltekit_config?: Parsed_Sveltekit_Config) => Result<object, {
14
14
  message: string;
15
- }>>;
15
+ }>;
16
16
  export declare const sveltekit_sync: (sveltekit_cli?: string | Cli) => Promise<void>;
17
17
  /**
18
18
  * If the SvelteKit CLI is found and its `.svelte-kit` directory is not, run `svelte-kit sync`.
@@ -9,22 +9,22 @@ export const SVELTE_CHECK_CLI = 'svelte-check';
9
9
  export const SVELTE_PACKAGE_CLI = 'svelte-package';
10
10
  export const SVELTE_PACKAGE_DEP_NAME = '@sveltejs/package';
11
11
  export const VITE_CLI = 'vite';
12
- export const has_sveltekit_app = async () => {
12
+ export const has_sveltekit_app = () => {
13
13
  if (!existsSync(SVELTEKIT_CONFIG_FILENAME)) {
14
14
  return { ok: false, message: `no SvelteKit config found at ${SVELTEKIT_CONFIG_FILENAME}` };
15
15
  }
16
16
  // TODO check for routes?
17
17
  return { ok: true };
18
18
  };
19
- export const has_sveltekit_library = async (package_json, sveltekit_config = sveltekit_config_global) => {
20
- const has_sveltekit_app_result = await has_sveltekit_app();
19
+ export const has_sveltekit_library = (package_json, sveltekit_config = sveltekit_config_global) => {
20
+ const has_sveltekit_app_result = has_sveltekit_app();
21
21
  if (!has_sveltekit_app_result.ok) {
22
22
  return has_sveltekit_app_result;
23
23
  }
24
24
  if (!existsSync(sveltekit_config.lib_path)) {
25
25
  return { ok: false, message: `no SvelteKit lib directory found at ${sveltekit_config.lib_path}` };
26
26
  }
27
- const pkg = package_json ?? (await load_package_json());
27
+ const pkg = package_json ?? load_package_json();
28
28
  if (!(pkg.devDependencies?.[SVELTE_PACKAGE_DEP_NAME] || pkg.dependencies?.[SVELTE_PACKAGE_DEP_NAME])) {
29
29
  return {
30
30
  ok: false,
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Generates a module shim for SvelteKit's `$env` imports.
3
3
  */
4
- export declare const render_env_shim_module: (dev: boolean, mode: "static" | "dynamic", visibility: "public" | "private", public_prefix?: string, private_prefix?: string, env_dir?: string, env_files?: string[], ambient_env?: Record<string, string | undefined>) => Promise<string>;
4
+ export declare const render_env_shim_module: (dev: boolean, mode: "static" | "dynamic", visibility: "public" | "private", public_prefix?: string, private_prefix?: string, env_dir?: string, env_files?: string[], ambient_env?: Record<string, string | undefined>) => string;
@@ -3,8 +3,8 @@ import { load_env } from './env.js';
3
3
  /**
4
4
  * Generates a module shim for SvelteKit's `$env` imports.
5
5
  */
6
- export const render_env_shim_module = async (dev, mode, visibility, public_prefix = 'PUBLIC_', private_prefix = '', env_dir, env_files, ambient_env) => {
7
- const env = await load_env(dev, visibility, public_prefix, private_prefix, env_dir, env_files, ambient_env);
6
+ export const render_env_shim_module = (dev, mode, visibility, public_prefix = 'PUBLIC_', private_prefix = '', env_dir, env_files, ambient_env) => {
7
+ const env = load_env(dev, visibility, public_prefix, private_prefix, env_dir, env_files, ambient_env);
8
8
  if (mode === 'static') {
9
9
  return `// shim for $env/static/${visibility}
10
10
  // @see https://github.com/sveltejs/kit/issues/1485
package/dist/task.d.ts CHANGED
@@ -10,7 +10,7 @@ import { type Input_Path, type Resolved_Input_File, type Resolved_Input_Path } f
10
10
  import { type Load_Modules_Failure, type Module_Meta } from './modules.js';
11
11
  export interface Task<T_Args = Args, // same as `z.infer<typeof Args>`
12
12
  T_Args_Schema extends z.ZodType = z.ZodType, T_Return = unknown> {
13
- run: (ctx: Task_Context<T_Args>) => Promise<T_Return>;
13
+ run: (ctx: Task_Context<T_Args>) => T_Return | Promise<T_Return>;
14
14
  summary?: string;
15
15
  Args?: T_Args_Schema;
16
16
  }
package/dist/task.js CHANGED
@@ -17,7 +17,12 @@ export const to_task_name = (id, task_root_dir, input_path, root_path) => {
17
17
  task_name = strip_end(task_name, suffix);
18
18
  }
19
19
  if (isAbsolute(input_path)) {
20
- return relative(root_path, join(input_path, task_name));
20
+ // is a bit hacky, but does what we want
21
+ const relative_to_root = relative(root_path, join(task_root_dir, task_name));
22
+ if (relative_to_root.startsWith('node_modules/')) {
23
+ return task_name;
24
+ }
25
+ return relative_to_root;
21
26
  }
22
27
  return task_name;
23
28
  };
package/dist/task.test.js CHANGED
@@ -20,6 +20,11 @@ test('to_task_name basic behavior', () => {
20
20
  assert.is(to_task_name('/a/b/c/foo.task.ts', '/a/b', '/a/b', '/a/b/d'), '../c/foo');
21
21
  assert.is(to_task_name('/a/b/c/foo.task.ts', '/a/b', '/a/b', '/a/b'), 'c/foo');
22
22
  assert.is(to_task_name('/a/b/c/foo.task.ts', '/a/b', '/a/b', '/a/b/c'), 'foo');
23
+ assert.is(to_task_name('/a/b/d/foo.task.js', '/a/b/d', '/a/b/d/foo', '/a/c'), '../b/d/foo');
24
+ assert.is(to_task_name('/a/node_modules/b/c/foo.task.js', '/a/node_modules/b/c', '/a/node_modules/b/c/foo', '/a'), 'foo');
25
+ assert.is(to_task_name('/a/node_modules/b/c/foo.task.js', '/a/node_modules/b/c/', // compared to the above, adds a trailing slash here
26
+ '/a/node_modules/b/c/foo', '/a'), 'foo');
27
+ assert.is(to_task_name('/a/node_modules/b/c/foo.task.js', '/a/node_modules/b/c', '/a/node_modules/b/c/foo', '/a/'), 'foo');
23
28
  assert.is(to_task_name(resolve('a/b'), resolve('b'), '', ''), resolve('a/b'), 'falls back to the id when unresolved');
24
29
  });
25
30
  // TODO if we import directly, svelte-package generates types in `src/fixtures`
@@ -1,5 +1,5 @@
1
1
  import type { Logger } from '@ryanatkn/belt/log.js';
2
2
  import type { Loaded_Tasks, Task_Module_Meta } from './task.js';
3
- export declare const log_tasks: (log: Logger, loaded_tasks: Loaded_Tasks, log_intro?: boolean) => Promise<void>;
3
+ export declare const log_tasks: (log: Logger, loaded_tasks: Loaded_Tasks, log_intro?: boolean) => void;
4
4
  export declare const log_error_reasons: (log: Logger, reasons: string[]) => void;
5
5
  export declare const log_task_help: (log: Logger, meta: Task_Module_Meta) => void;