@ryanatkn/gro 0.178.0 → 0.180.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 (108) hide show
  1. package/dist/build.task.d.ts +2 -0
  2. package/dist/build.task.d.ts.map +1 -1
  3. package/dist/build.task.js +14 -10
  4. package/dist/build_cache.d.ts +3 -3
  5. package/dist/build_cache.d.ts.map +1 -1
  6. package/dist/build_cache.js +53 -43
  7. package/dist/changeset.task.js +9 -9
  8. package/dist/clean_fs.d.ts +1 -1
  9. package/dist/clean_fs.d.ts.map +1 -1
  10. package/dist/clean_fs.js +3 -4
  11. package/dist/cli.d.ts +4 -4
  12. package/dist/cli.d.ts.map +1 -1
  13. package/dist/cli.js +11 -12
  14. package/dist/deploy.task.d.ts +7 -0
  15. package/dist/deploy.task.d.ts.map +1 -1
  16. package/dist/deploy.task.js +27 -14
  17. package/dist/esbuild_plugin_external_worker.js +1 -1
  18. package/dist/esbuild_plugin_svelte.js +4 -4
  19. package/dist/esbuild_plugin_sveltekit_local_imports.js +2 -2
  20. package/dist/filer.d.ts.map +1 -1
  21. package/dist/filer.js +103 -52
  22. package/dist/format_file.js +1 -1
  23. package/dist/gen.d.ts +1 -1
  24. package/dist/gen.d.ts.map +1 -1
  25. package/dist/gen.js +28 -22
  26. package/dist/gen.task.js +1 -1
  27. package/dist/gro.config.default.js +1 -1
  28. package/dist/gro_config.js +2 -2
  29. package/dist/gro_plugin_gen.js +1 -1
  30. package/dist/gro_plugin_server.js +2 -2
  31. package/dist/gro_plugin_sveltekit_app.d.ts.map +1 -1
  32. package/dist/gro_plugin_sveltekit_app.js +40 -36
  33. package/dist/gro_plugin_sveltekit_library.js +2 -1
  34. package/dist/input_path.d.ts +3 -3
  35. package/dist/input_path.d.ts.map +1 -1
  36. package/dist/input_path.js +16 -14
  37. package/dist/invoke_task.js +2 -2
  38. package/dist/lint.task.js +1 -1
  39. package/dist/loader.js +1 -1
  40. package/dist/modules.js +2 -2
  41. package/dist/package_json.d.ts +4 -4
  42. package/dist/package_json.d.ts.map +1 -1
  43. package/dist/package_json.js +12 -14
  44. package/dist/publish.task.js +6 -6
  45. package/dist/release.task.js +1 -1
  46. package/dist/resolve.task.js +2 -2
  47. package/dist/resolve_specifier.d.ts +1 -1
  48. package/dist/resolve_specifier.d.ts.map +1 -1
  49. package/dist/resolve_specifier.js +5 -4
  50. package/dist/run.task.js +2 -2
  51. package/dist/run_gen.d.ts.map +1 -1
  52. package/dist/run_gen.js +9 -8
  53. package/dist/run_task.js +4 -4
  54. package/dist/source_json.d.ts +2 -2
  55. package/dist/source_json.d.ts.map +1 -1
  56. package/dist/source_json.js +16 -15
  57. package/dist/sveltekit_helpers.js +3 -3
  58. package/dist/sveltekit_shim_env.js +1 -1
  59. package/dist/task.d.ts +1 -1
  60. package/dist/task.d.ts.map +1 -1
  61. package/dist/task.js +4 -4
  62. package/dist/test.task.d.ts.map +1 -1
  63. package/dist/test.task.js +5 -4
  64. package/dist/typecheck.task.js +3 -3
  65. package/dist/upgrade.task.js +4 -4
  66. package/package.json +7 -7
  67. package/src/lib/build.task.ts +15 -10
  68. package/src/lib/build_cache.ts +79 -63
  69. package/src/lib/changeset.task.ts +10 -10
  70. package/src/lib/clean_fs.ts +4 -4
  71. package/src/lib/cli.ts +15 -14
  72. package/src/lib/deploy.task.ts +30 -13
  73. package/src/lib/esbuild_plugin_external_worker.ts +1 -1
  74. package/src/lib/esbuild_plugin_svelte.ts +4 -4
  75. package/src/lib/esbuild_plugin_sveltekit_local_imports.ts +2 -2
  76. package/src/lib/filer.ts +111 -52
  77. package/src/lib/format_file.ts +1 -1
  78. package/src/lib/gen.task.ts +1 -1
  79. package/src/lib/gen.ts +52 -46
  80. package/src/lib/gro.config.default.ts +1 -1
  81. package/src/lib/gro_config.ts +2 -2
  82. package/src/lib/gro_plugin_gen.ts +1 -1
  83. package/src/lib/gro_plugin_server.ts +2 -2
  84. package/src/lib/gro_plugin_sveltekit_app.ts +49 -41
  85. package/src/lib/gro_plugin_sveltekit_library.ts +2 -2
  86. package/src/lib/input_path.ts +20 -21
  87. package/src/lib/invoke_task.ts +2 -2
  88. package/src/lib/lint.task.ts +1 -1
  89. package/src/lib/loader.ts +1 -1
  90. package/src/lib/modules.ts +2 -2
  91. package/src/lib/package_json.ts +16 -20
  92. package/src/lib/publish.task.ts +6 -6
  93. package/src/lib/release.task.ts +1 -1
  94. package/src/lib/resolve.task.ts +2 -2
  95. package/src/lib/resolve_specifier.ts +8 -4
  96. package/src/lib/run.task.ts +2 -2
  97. package/src/lib/run_gen.ts +15 -10
  98. package/src/lib/run_task.ts +4 -4
  99. package/src/lib/source_json.ts +25 -19
  100. package/src/lib/sveltekit_helpers.ts +3 -3
  101. package/src/lib/task.ts +11 -9
  102. package/src/lib/test.task.ts +4 -3
  103. package/src/lib/typecheck.task.ts +3 -3
  104. package/src/lib/upgrade.task.ts +4 -4
  105. package/dist/search_fs.d.ts +0 -26
  106. package/dist/search_fs.d.ts.map +0 -1
  107. package/dist/search_fs.js +0 -52
  108. package/src/lib/search_fs.ts +0 -100
@@ -1 +1 @@
1
- {"version":3,"file":"gro_plugin_sveltekit_app.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gro_plugin_sveltekit_app.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAExC,OAAO,EAAyB,KAAK,iBAAiB,EAAoB,MAAM,mBAAmB,CAAC;AAGpG,OAAO,EAAC,KAAK,gBAAgB,EAA4C,MAAM,kBAAkB,CAAC;AAKlG,MAAM,WAAW,4BAA4B;IAC5C;;;OAGG;IACH,WAAW,CAAC,EAAE,UAAU,CAAC;IAEzB;;;OAGG;IACH,uBAAuB,CAAC,EAAE,OAAO,GAAG,iBAAiB,CAAC;IAEtD;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,GAAG,gBAAgB,CAAC;IAEpD;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,GAAG,cAAc,CAAC;IAChD;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE5D,MAAM,MAAM,cAAc,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;AAE5D,eAAO,MAAM,wBAAwB,GAAI,oGAMtC,4BAAiC,KAAG,MA6GtC,CAAC"}
1
+ {"version":3,"file":"gro_plugin_sveltekit_app.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gro_plugin_sveltekit_app.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAExC,OAAO,EAAyB,KAAK,iBAAiB,EAAoB,MAAM,mBAAmB,CAAC;AAGpG,OAAO,EAAC,KAAK,gBAAgB,EAA4C,MAAM,kBAAkB,CAAC;AAKlG,MAAM,WAAW,4BAA4B;IAC5C;;;OAGG;IACH,WAAW,CAAC,EAAE,UAAU,CAAC;IAEzB;;;OAGG;IACH,uBAAuB,CAAC,EAAE,OAAO,GAAG,iBAAiB,CAAC;IAEtD;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,GAAG,gBAAgB,CAAC;IAEpD;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,GAAG,cAAc,CAAC;IAChD;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE5D,MAAM,MAAM,cAAc,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;AAE5D,eAAO,MAAM,wBAAwB,GAAI,oGAMtC,4BAAiC,KAAG,MAmHtC,CAAC"}
@@ -1,5 +1,6 @@
1
- import { cpSync, mkdirSync, rmSync, writeFileSync, existsSync } from 'node:fs';
1
+ import { cp, mkdir, rm, writeFile } from 'node:fs/promises';
2
2
  import { dirname, join } from 'node:path';
3
+ import { fs_exists } from '@ryanatkn/belt/fs.js';
3
4
  import { serialize_args, to_forwarded_args } from "./args.js";
4
5
  import { serialize_package_json, load_package_json } from "./package_json.js";
5
6
  import { TaskError } from "./task.js";
@@ -13,14 +14,14 @@ export const gro_plugin_sveltekit_app = ({ host_target = 'github_pages', well_kn
13
14
  return {
14
15
  name: 'gro_plugin_sveltekit_app',
15
16
  setup: async ({ dev, watch, log, config }) => {
16
- const found_vite_cli = find_cli(vite_cli);
17
+ const found_vite_cli = await find_cli(vite_cli);
17
18
  if (!found_vite_cli)
18
19
  throw Error(`Failed to find Vite CLI \`${vite_cli}\`, do you need to run \`${config.pm_cli} i\`?`);
19
20
  if (dev) {
20
21
  // `vite dev` in development mode
21
22
  if (watch) {
22
23
  const serialized_args = ['dev', ...serialize_args(to_forwarded_args(vite_cli))];
23
- sveltekit_process = spawn_cli_process(found_vite_cli, serialized_args, log);
24
+ sveltekit_process = await spawn_cli_process(found_vite_cli, serialized_args, log);
24
25
  }
25
26
  else {
26
27
  log.debug(`the SvelteKit app plugin is loaded but will not output anything` +
@@ -30,7 +31,7 @@ export const gro_plugin_sveltekit_app = ({ host_target = 'github_pages', well_kn
30
31
  else {
31
32
  // `vite build` in production mode
32
33
  // `.well-known/package.json`
33
- const package_json = load_package_json(); // TODO put in plugin context? same with sveltekit config?
34
+ const package_json = await load_package_json(); // TODO put in plugin context? same with sveltekit config?
34
35
  if (well_known_package_json === undefined) {
35
36
  well_known_package_json = package_json.public; // eslint-disable-line no-param-reassign
36
37
  }
@@ -42,7 +43,7 @@ export const gro_plugin_sveltekit_app = ({ host_target = 'github_pages', well_kn
42
43
  const serialized_package_json = mapped_package_json && serialize_package_json(mapped_package_json);
43
44
  // `.well-known/source.json` and `.well-known/src/`
44
45
  const final_package_json = mapped_package_json ?? package_json;
45
- const source_json = source_json_create(final_package_json, undefined, log);
46
+ const source_json = await source_json_create(final_package_json, undefined, log);
46
47
  if (well_known_source_json === undefined) {
47
48
  well_known_source_json = final_package_json.public; // eslint-disable-line no-param-reassign
48
49
  }
@@ -57,7 +58,7 @@ export const gro_plugin_sveltekit_app = ({ host_target = 'github_pages', well_kn
57
58
  // copy files to `static` before building, in such a way
58
59
  // that's non-destructive to existing files and dirs and easy to clean up
59
60
  const { assets_path } = default_svelte_config;
60
- const cleanups = [
61
+ const cleanup_promises = [
61
62
  serialized_package_json
62
63
  ? create_temporarily(join(assets_path, '.well-known/package.json'), serialized_package_json)
63
64
  : null,
@@ -79,9 +80,11 @@ export const gro_plugin_sveltekit_app = ({ host_target = 'github_pages', well_kn
79
80
  ? create_temporarily(join(assets_path, '.nojekyll'), '')
80
81
  : null,
81
82
  ].filter((v) => v != null);
82
- const cleanup = () => {
83
+ const cleanups = await Promise.all(cleanup_promises);
84
+ const cleanup = async () => {
85
+ // eslint-disable-next-line no-await-in-loop
83
86
  for (const c of cleanups)
84
- c();
87
+ await c();
85
88
  };
86
89
  try {
87
90
  const serialized_args = ['build', ...serialize_args(to_forwarded_args(vite_cli))];
@@ -90,11 +93,11 @@ export const gro_plugin_sveltekit_app = ({ host_target = 'github_pages', well_kn
90
93
  throw new TaskError(`${vite_cli} build failed with exit code ${spawned?.code}`);
91
94
  }
92
95
  }
93
- catch (err) {
94
- cleanup();
95
- throw err;
96
+ catch (error) {
97
+ await cleanup();
98
+ throw error;
96
99
  }
97
- cleanup();
100
+ await cleanup();
98
101
  }
99
102
  },
100
103
  teardown: async () => {
@@ -106,32 +109,32 @@ export const gro_plugin_sveltekit_app = ({ host_target = 'github_pages', well_kn
106
109
  };
107
110
  };
108
111
  // TODO probably extract these, and create a common helper or merge them
109
- const copy_temporarily = (source_path, dest_dir, dest_base_dir = '', filter) => {
112
+ const copy_temporarily = async (source_path, dest_dir, dest_base_dir = '', filter) => {
110
113
  const path = join(dest_dir, dest_base_dir, source_path);
111
114
  const dir = dirname(path);
112
- const dir_already_exists = existsSync(dir);
115
+ const dir_already_exists = await fs_exists(dir);
113
116
  let root_created_dir;
114
117
  if (!dir_already_exists) {
115
- root_created_dir = to_root_dir_that_doesnt_exist(dir);
118
+ root_created_dir = await to_root_dir_that_doesnt_exist(dir);
116
119
  if (!root_created_dir)
117
120
  throw Error();
118
- mkdirSync(dir, { recursive: true });
121
+ await mkdir(dir, { recursive: true });
119
122
  }
120
- const path_already_exists = existsSync(path);
123
+ const path_already_exists = await fs_exists(path);
121
124
  if (!path_already_exists) {
122
- cpSync(source_path, path, { recursive: true, filter });
125
+ await cp(source_path, path, { recursive: true, filter });
123
126
  }
124
- return () => {
127
+ return async () => {
125
128
  if (!dir_already_exists) {
126
129
  if (!root_created_dir)
127
130
  throw Error();
128
- if (existsSync(root_created_dir)) {
129
- rmSync(root_created_dir, { recursive: true });
131
+ if (await fs_exists(root_created_dir)) {
132
+ await rm(root_created_dir, { recursive: true });
130
133
  }
131
134
  }
132
135
  else if (!path_already_exists) {
133
- if (existsSync(path)) {
134
- rmSync(path, { recursive: true });
136
+ if (await fs_exists(path)) {
137
+ await rm(path, { recursive: true });
135
138
  }
136
139
  }
137
140
  };
@@ -143,31 +146,31 @@ const copy_temporarily = (source_path, dest_dir, dest_base_dir = '', filter) =>
143
146
  * @param contents
144
147
  * @returns cleanup function that deletes the file and any created dirs
145
148
  */
146
- const create_temporarily = (path, contents) => {
149
+ const create_temporarily = async (path, contents) => {
147
150
  const dir = dirname(path);
148
- const dir_already_exists = existsSync(dir);
151
+ const dir_already_exists = await fs_exists(dir);
149
152
  let root_created_dir;
150
153
  if (!dir_already_exists) {
151
- root_created_dir = to_root_dir_that_doesnt_exist(dir);
154
+ root_created_dir = await to_root_dir_that_doesnt_exist(dir);
152
155
  if (!root_created_dir)
153
156
  throw Error();
154
- mkdirSync(dir, { recursive: true });
157
+ await mkdir(dir, { recursive: true });
155
158
  }
156
- const path_already_exists = existsSync(path);
159
+ const path_already_exists = await fs_exists(path);
157
160
  if (!path_already_exists) {
158
- writeFileSync(path, contents, 'utf8');
161
+ await writeFile(path, contents, 'utf8');
159
162
  }
160
- return () => {
163
+ return async () => {
161
164
  if (!dir_already_exists) {
162
165
  if (!root_created_dir)
163
166
  throw Error();
164
- if (existsSync(root_created_dir)) {
165
- rmSync(root_created_dir, { recursive: true });
167
+ if (await fs_exists(root_created_dir)) {
168
+ await rm(root_created_dir, { recursive: true });
166
169
  }
167
170
  }
168
171
  else if (!path_already_exists) {
169
- if (existsSync(path)) {
170
- rmSync(path);
172
+ if (await fs_exists(path)) {
173
+ await rm(path);
171
174
  }
172
175
  }
173
176
  };
@@ -177,11 +180,12 @@ const create_temporarily = (path, contents) => {
177
180
  * for `/a/b/DOESNT_EXIST/NOR_THIS/ETC` returns `/a/b/DOESNT_EXIST`
178
181
  * where `/a/b` does exist on the filesystem and `DOESNT_EXIST` is not one of its subdirectories.
179
182
  */
180
- const to_root_dir_that_doesnt_exist = (dir) => {
183
+ const to_root_dir_that_doesnt_exist = async (dir) => {
181
184
  let prev;
182
185
  let d = dir;
183
186
  do {
184
- if (existsSync(d)) {
187
+ // eslint-disable-next-line no-await-in-loop
188
+ if (await fs_exists(d)) {
185
189
  return prev;
186
190
  }
187
191
  prev = d;
@@ -4,15 +4,16 @@ import { load_package_json } from "./package_json.js";
4
4
  import { run_svelte_package } from "./sveltekit_helpers.js";
5
5
  import { SVELTE_PACKAGE_CLI } from "./constants.js";
6
6
  export const gro_plugin_sveltekit_library = ({ svelte_package_options, svelte_package_cli = SVELTE_PACKAGE_CLI, } = {}) => {
7
- const package_json = load_package_json();
8
7
  return {
9
8
  name: 'gro_plugin_sveltekit_library',
10
9
  setup: async ({ dev, log, config }) => {
11
10
  if (!dev) {
11
+ const package_json = await load_package_json();
12
12
  await run_svelte_package(package_json, svelte_package_options, svelte_package_cli, log, config.pm_cli);
13
13
  }
14
14
  },
15
15
  adapt: async ({ log, timings, config }) => {
16
+ const package_json = await load_package_json();
16
17
  // link the CLI binaries if they exist
17
18
  if (package_json.bin) {
18
19
  const timing_to_link = timings.start(`${config.pm_cli} link`);
@@ -28,7 +28,7 @@ export interface PossiblePath {
28
28
  * Gets a list of possible source ids for each input path with `extensions`,
29
29
  * duplicating each under `root_dirs`, without checking the filesystem.
30
30
  */
31
- export declare const get_possible_paths: (input_path: InputPath, root_dirs: Array<PathId>, extensions: Array<string>) => Array<PossiblePath>;
31
+ export declare const get_possible_paths: (input_path: InputPath, root_dirs: Array<PathId>, extensions: Array<string>) => Promise<Array<PossiblePath>>;
32
32
  export interface ResolvedInputPath {
33
33
  input_path: InputPath;
34
34
  id: PathId;
@@ -50,7 +50,7 @@ export interface ResolvedInputPaths {
50
50
  * and stopping at the first existing file or falling back to the first existing directory.
51
51
  * If none is found for an input path, it's added to `unmapped_input_paths`.
52
52
  */
53
- export declare const resolve_input_paths: (input_paths: Array<InputPath>, root_dirs: Array<PathId>, extensions: Array<string>) => ResolvedInputPaths;
53
+ export declare const resolve_input_paths: (input_paths: Array<InputPath>, root_dirs: Array<PathId>, extensions: Array<string>) => Promise<ResolvedInputPaths>;
54
54
  export interface ResolvedInputFiles {
55
55
  resolved_input_files: Array<ResolvedInputFile>;
56
56
  resolved_input_files_by_root_dir: Map<PathId, Array<ResolvedInputFile>>;
@@ -60,5 +60,5 @@ export interface ResolvedInputFiles {
60
60
  * Finds all of the matching files for the given input paths.
61
61
  * De-dupes source ids.
62
62
  */
63
- export declare const resolve_input_files: (resolved_input_paths: Array<ResolvedInputPath>, search?: (dir: string) => Array<ResolvedPath>) => ResolvedInputFiles;
63
+ export declare const resolve_input_files: (resolved_input_paths: Array<ResolvedInputPath>, search?: (dir: string) => Promise<Array<ResolvedPath>>) => Promise<ResolvedInputFiles>;
64
64
  //# sourceMappingURL=input_path.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"input_path.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/input_path.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,yBAAyB,C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AC;AAEF,MAAM,WAAW,kBAAkB;IAClC,oBAAoB,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAC/C,gCAAgC,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACxE,+BAA+B,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;CAClD;AAED;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAC/B,sBAAsB,KAAK,CAAC,iBAAiB,CAAC,EAC9C,SAAQ,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAa,KAC/D,OAAO,CAAC,kBAAkB,CAgE5B,CAAC"}
@@ -1,9 +1,9 @@
1
1
  import { dirname, isAbsolute, join, resolve } from 'node:path';
2
- import { existsSync, statSync } from 'node:fs';
2
+ import { stat } from 'node:fs/promises';
3
+ import { fs_exists, fs_search } from '@ryanatkn/belt/fs.js';
3
4
  import { strip_start } from '@ryanatkn/belt/string.js';
4
5
  import { z } from 'zod';
5
6
  import { GRO_PACKAGE_DIR, GRO_DIST_DIR } from "./paths.js";
6
- import { search_fs } from "./search_fs.js";
7
7
  import { TASK_FILE_SUFFIX_JS } from "./task.js";
8
8
  // TODO Flavored doesn't work when used in schemas, use Zod brand instead? problem is ergonomics
9
9
  export const InputPath = z.string();
@@ -34,7 +34,7 @@ export const to_input_paths = (raw_input_paths, root_path) => raw_input_paths.ma
34
34
  * Gets a list of possible source ids for each input path with `extensions`,
35
35
  * duplicating each under `root_dirs`, without checking the filesystem.
36
36
  */
37
- export const get_possible_paths = (input_path, root_dirs, extensions) => {
37
+ export const get_possible_paths = async (input_path, root_dirs, extensions) => {
38
38
  const possible_paths = new Set();
39
39
  const add_possible_paths = (path, root_dir) => {
40
40
  // Specifically for paths to the Gro package dist, optimize by only looking for `.task.js`.
@@ -57,11 +57,9 @@ export const get_possible_paths = (input_path, root_dirs, extensions) => {
57
57
  }
58
58
  };
59
59
  if (isAbsolute(input_path)) {
60
- // TODO this is hacky because it's the only place we're using sync fs calls (even if they're faster, it's oddly inconsistent),
61
- // we probably should just change this function to check the filesystem and not return non-existing paths
62
- add_possible_paths(input_path, existsSync(input_path) && statSync(input_path).isDirectory()
63
- ? input_path
64
- : dirname(input_path));
60
+ const exists = await fs_exists(input_path);
61
+ const is_directory = exists && (await stat(input_path)).isDirectory();
62
+ add_possible_paths(input_path, is_directory ? input_path : dirname(input_path));
65
63
  }
66
64
  else {
67
65
  for (const root_dir of root_dirs) {
@@ -75,20 +73,23 @@ export const get_possible_paths = (input_path, root_dirs, extensions) => {
75
73
  * and stopping at the first existing file or falling back to the first existing directory.
76
74
  * If none is found for an input path, it's added to `unmapped_input_paths`.
77
75
  */
78
- export const resolve_input_paths = (input_paths, root_dirs, extensions) => {
76
+ export const resolve_input_paths = async (input_paths, root_dirs, extensions) => {
79
77
  const resolved_input_paths = [];
80
78
  const possible_paths_by_input_path = new Map();
81
79
  const unmapped_input_paths = [];
82
80
  for (const input_path of input_paths) {
83
81
  let found_file = null;
84
82
  let found_dirs = null;
85
- const possible_paths = get_possible_paths(input_path, root_dirs, extensions);
83
+ // eslint-disable-next-line no-await-in-loop
84
+ const possible_paths = await get_possible_paths(input_path, root_dirs, extensions);
86
85
  possible_paths_by_input_path.set(input_path, possible_paths);
87
86
  // Find the first existing file path or fallback to the first directory path.
88
87
  for (const possible_path of possible_paths) {
89
- if (!existsSync(possible_path.id))
88
+ // eslint-disable-next-line no-await-in-loop
89
+ if (!(await fs_exists(possible_path.id)))
90
90
  continue;
91
- const stats = statSync(possible_path.id);
91
+ // eslint-disable-next-line no-await-in-loop
92
+ const stats = await stat(possible_path.id);
92
93
  if (stats.isDirectory()) {
93
94
  found_dirs ??= [];
94
95
  found_dirs.push([{ id: possible_path.id, is_directory: stats.isDirectory() }, possible_path]);
@@ -130,7 +131,7 @@ export const resolve_input_paths = (input_paths, root_dirs, extensions) => {
130
131
  * Finds all of the matching files for the given input paths.
131
132
  * De-dupes source ids.
132
133
  */
133
- export const resolve_input_files = (resolved_input_paths, search = search_fs) => {
134
+ export const resolve_input_files = async (resolved_input_paths, search = fs_search) => {
134
135
  const resolved_input_files = [];
135
136
  // Add all input paths initially, and remove each when resolved to a file.
136
137
  const existing_path_ids = new Set();
@@ -143,7 +144,8 @@ export const resolve_input_files = (resolved_input_paths, search = search_fs) =>
143
144
  const { input_path, id, is_directory } = resolved_input_path;
144
145
  if (is_directory) {
145
146
  // Handle input paths that resolve to directories.
146
- const files = search(id);
147
+ // eslint-disable-next-line no-await-in-loop
148
+ const files = await search(id);
147
149
  if (!files.length)
148
150
  continue;
149
151
  const path_ids = [];
@@ -54,7 +54,7 @@ export const invoke_task = async (task_name, args, config, initial_filer, initia
54
54
  };
55
55
  // Check if the caller just wants to see the version.
56
56
  if (!task_name && (args?.version || args?.v)) {
57
- const gro_package_json = load_gro_package_json();
57
+ const gro_package_json = await load_gro_package_json();
58
58
  log.info(`${st('gray', 'v')}${st('cyan', gro_package_json.version)}`);
59
59
  await finish();
60
60
  return;
@@ -64,7 +64,7 @@ export const invoke_task = async (task_name, args, config, initial_filer, initia
64
64
  const { task_root_dirs } = config;
65
65
  // Find the task or directory specified by the `input_path`.
66
66
  // Fall back to searching the Gro directory as well.
67
- const found = find_tasks([input_path], task_root_dirs, config);
67
+ const found = await find_tasks([input_path], task_root_dirs, config);
68
68
  if (!found.ok) {
69
69
  log_error_reasons(log, found.reasons);
70
70
  throw new SilentError();
package/dist/lint.task.js CHANGED
@@ -15,7 +15,7 @@ export const task = {
15
15
  Args,
16
16
  run: async ({ log, args }) => {
17
17
  const { _, eslint_cli } = args;
18
- const found_eslint_cli = find_cli(eslint_cli);
18
+ const found_eslint_cli = await find_cli(eslint_cli);
19
19
  if (!found_eslint_cli) {
20
20
  // TODO maybe make this an option?
21
21
  log.info('ESLint is not installed; skipping linting');
package/dist/loader.js CHANGED
@@ -190,7 +190,7 @@ export const resolve = async (specifier, context, nextResolve) => {
190
190
  if (s[0] !== '.' && s[0] !== '/') {
191
191
  return nextResolve(s, context);
192
192
  }
193
- const resolved = resolve_specifier(s, dirname(fileURLToPath(parent_url)));
193
+ const resolved = await resolve_specifier(s, dirname(fileURLToPath(parent_url)));
194
194
  return {
195
195
  url: pathToFileURL(resolved.path_id_with_querystring).href,
196
196
  format: 'module',
package/dist/modules.js CHANGED
@@ -21,8 +21,8 @@ export const load_module = async (id, validate, bust_cache) => {
21
21
  }
22
22
  mod = await import(__rewriteRelativeImportExtension(import_path, true));
23
23
  }
24
- catch (err) {
25
- return { ok: false, type: 'failed_import', id, error: err };
24
+ catch (error) {
25
+ return { ok: false, type: 'failed_import', id, error };
26
26
  }
27
27
  if (validate && !validate(mod)) {
28
28
  return { ok: false, type: 'failed_validation', id, mod, validation: validate.name };
@@ -3,13 +3,13 @@ import { PackageJson, PackageJsonExports } from '@ryanatkn/belt/package_json.js'
3
3
  export type PackageJsonMapper = (package_json: PackageJson) => PackageJson | null | Promise<PackageJson | null>;
4
4
  export declare const EMPTY_PACKAGE_JSON: PackageJson;
5
5
  export declare const load_package_json: (dir?: string, cache?: Record<string, PackageJson>, parse?: boolean, // TODO pass `false` here in more places, especially anything perf-sensitive like work on startup
6
- log?: Logger) => PackageJson;
6
+ log?: Logger) => Promise<PackageJson>;
7
7
  export declare const sync_package_json: (map_package_json: PackageJsonMapper, log: Logger, write?: boolean, dir?: string, exports_dir?: string) => Promise<{
8
8
  package_json: PackageJson | null;
9
9
  changed: boolean;
10
10
  }>;
11
- export declare const load_gro_package_json: () => PackageJson;
12
- export declare const write_package_json: (serialized_package_json: string) => void;
11
+ export declare const load_gro_package_json: () => Promise<PackageJson>;
12
+ export declare const write_package_json: (serialized_package_json: string) => Promise<void>;
13
13
  export declare const serialize_package_json: (package_json: PackageJson) => string;
14
14
  /**
15
15
  * Updates package.json. Writes to the filesystem only when contents change.
@@ -23,7 +23,7 @@ export declare const parse_repo_url: (package_json: PackageJson) => {
23
23
  owner: string;
24
24
  repo: string;
25
25
  } | undefined;
26
- export declare const has_dep: (dep_name: string, package_json?: PackageJson) => boolean;
26
+ export declare const has_dep: (dep_name: string, package_json: PackageJson) => boolean;
27
27
  export interface PackageJsonDep {
28
28
  name: string;
29
29
  version: string;
@@ -1 +1 @@
1
- {"version":3,"file":"package_json.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/package_json.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,uBAAuB,CAAC;AAElD,OAAO,EAAC,WAAW,EAAE,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAgB/E,MAAM,MAAM,iBAAiB,GAAG,CAC/B,YAAY,EAAE,WAAW,KACrB,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;AAEtD,eAAO,MAAM,kBAAkB,EAAE,WAAqC,CAAC;AAEvE,eAAO,MAAM,iBAAiB,GAC7B,YAA+C,EAC/C,QAAQ,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACnC,eAAY,EAAE,iGAAiG;AAC/G,MAAM,MAAM,KACV,WAkBF,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC7B,kBAAkB,iBAAiB,EACnC,KAAK,MAAM,EACX,eAAY,EACZ,YAAgB,EAChB,oBAAuB,KACrB,OAAO,CAAC;IAAC,YAAY,EAAE,WAAW,GAAG,IAAI,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAC,CA0B9D,CAAC;AAEF,eAAO,MAAM,qBAAqB,QAAO,WAAgD,CAAC;AAM1F,eAAO,MAAM,kBAAkB,GAAI,yBAAyB,MAAM,KAAG,IAEpE,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,cAAc,WAAW,KAAG,MACW,CAAC;AAE/E;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAC/B,QAAQ,CAAC,YAAY,EAAE,WAAW,KAAK,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,EACvF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X,eAAY,EACZ,YAAgB,EAChB,oBAAuB,KACrB,OAAO,CAAC;IAAC,YAAY,EAAE,WAAW,GAAG,IAAI,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAC,CA0B9D,CAAC;AAEF,eAAO,MAAM,qBAAqB,QAAO,OAAO,CAAC,WAAW,CAAsC,CAAC;AAMnG,eAAO,MAAM,kBAAkB,GAAI,yBAAyB,MAAM,KAAG,OAAO,CAAC,IAAI,CACL,CAAC;AAE7E,eAAO,MAAM,sBAAsB,GAAI,cAAc,WAAW,KAAG,MACW,CAAC;AAE/E;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAC/B,QAAQ,CAAC,YAAY,EAAE,WAAW,KAAK,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,EACvF,YAAgB,EAChB,eAAY,KACV,OAAO,CAAC;IAAC,YAAY,EAAE,WAAW,GAAG,IAAI,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAC,CAa9D,CAAC;AAIF,eAAO,MAAM,kBAAkB,GAAI,OAAO,KAAK,CAAC,MAAM,CAAC,KAAG,kBAmDzD,CAAC;AAIF,eAAO,MAAM,cAAc,GAC1B,cAAc,WAAW,KACvB;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,GAAG,SAgBlC,CAAC;AA8BF,eAAO,MAAM,OAAO,GAAI,UAAU,MAAM,EAAE,cAAc,WAAW,KAAG,OAG1B,CAAC;AAE7C,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,YAAY,GAAI,cAAc,WAAW,KAAG,KAAK,CAAC,cAAc,CAe5E,CAAC"}
@@ -1,26 +1,26 @@
1
1
  import { z } from 'zod';
2
2
  import { join } from 'node:path';
3
- import { readFileSync, writeFileSync } from 'node:fs';
3
+ import { readFile, writeFile } from 'node:fs/promises';
4
4
  import { plural, strip_end } from '@ryanatkn/belt/string.js';
5
5
  import { styleText as st } from 'node:util';
6
6
  import { PackageJson, PackageJsonExports } from '@ryanatkn/belt/package_json.js';
7
+ import { fs_search } from '@ryanatkn/belt/fs.js';
7
8
  import { paths, gro_paths, IS_THIS_GRO } from "./paths.js";
8
9
  import { PACKAGE_JSON_FILENAME, SVELTEKIT_DIST_DIRNAME, TS_MATCHER, JS_MATCHER, SVELTE_MATCHER, JSON_MATCHER, CSS_MATCHER, } from "./constants.js";
9
- import { search_fs } from "./search_fs.js";
10
10
  import { has_sveltekit_library } from "./sveltekit_helpers.js";
11
11
  import { GITHUB_REPO_MATCHER } from "./github.js";
12
12
  export const EMPTY_PACKAGE_JSON = { name: '', version: '' };
13
- export const load_package_json = (dir = IS_THIS_GRO ? gro_paths.root : paths.root, cache, parse = true, // TODO pass `false` here in more places, especially anything perf-sensitive like work on startup
13
+ export const load_package_json = async (dir = IS_THIS_GRO ? gro_paths.root : paths.root, cache, parse = true, // TODO pass `false` here in more places, especially anything perf-sensitive like work on startup
14
14
  log) => {
15
15
  let package_json;
16
16
  if (cache && dir in cache) {
17
17
  return cache[dir];
18
18
  }
19
19
  try {
20
- package_json = JSON.parse(load_package_json_contents(dir));
20
+ package_json = JSON.parse(await load_package_json_contents(dir));
21
21
  }
22
- catch (err) {
23
- log?.error(st('yellow', `Failed to load package.json in ${dir}`), err);
22
+ catch (error) {
23
+ log?.error(st('yellow', `Failed to load package.json in ${dir}`), error);
24
24
  return EMPTY_PACKAGE_JSON;
25
25
  }
26
26
  if (parse) {
@@ -32,7 +32,7 @@ log) => {
32
32
  return package_json;
33
33
  };
34
34
  export const sync_package_json = async (map_package_json, log, write = true, dir = paths.root, exports_dir = paths.lib) => {
35
- const exported_files = search_fs(exports_dir);
35
+ const exported_files = await fs_search(exports_dir);
36
36
  const exported_paths = exported_files.map((f) => f.path);
37
37
  const updated = await update_package_json(async (package_json) => {
38
38
  if ((await has_sveltekit_library(package_json)).ok) {
@@ -51,16 +51,14 @@ export const sync_package_json = async (map_package_json, log, write = true, dir
51
51
  };
52
52
  export const load_gro_package_json = () => load_package_json(gro_paths.root);
53
53
  // TODO probably make this nullable and make callers handle failures
54
- const load_package_json_contents = (dir) => readFileSync(join(dir, PACKAGE_JSON_FILENAME), 'utf8');
55
- export const write_package_json = (serialized_package_json) => {
56
- writeFileSync(join(paths.root, PACKAGE_JSON_FILENAME), serialized_package_json);
57
- };
54
+ const load_package_json_contents = (dir) => readFile(join(dir, PACKAGE_JSON_FILENAME), 'utf8');
55
+ export const write_package_json = (serialized_package_json) => writeFile(join(paths.root, PACKAGE_JSON_FILENAME), serialized_package_json);
58
56
  export const serialize_package_json = (package_json) => JSON.stringify(parse_package_json(PackageJson, package_json), null, 2) + '\n';
59
57
  /**
60
58
  * Updates package.json. Writes to the filesystem only when contents change.
61
59
  */
62
60
  export const update_package_json = async (update, dir = paths.root, write = true) => {
63
- const original_contents = load_package_json_contents(dir);
61
+ const original_contents = await load_package_json_contents(dir);
64
62
  const original = JSON.parse(original_contents);
65
63
  const updated = await update(original);
66
64
  if (updated === null) {
@@ -71,7 +69,7 @@ export const update_package_json = async (update, dir = paths.root, write = true
71
69
  return { package_json: original, changed: false };
72
70
  }
73
71
  if (write)
74
- write_package_json(updated_contents);
72
+ await write_package_json(updated_contents);
75
73
  return { package_json: updated, changed: true };
76
74
  };
77
75
  const is_index = (path) => path === 'index.ts' || path === 'index.js';
@@ -158,7 +156,7 @@ const parse_or_throw_formatted_error = (name, schema, value) => {
158
156
  }
159
157
  return parsed.data;
160
158
  };
161
- export const has_dep = (dep_name, package_json = load_package_json()) => !!package_json.devDependencies?.[dep_name] ||
159
+ export const has_dep = (dep_name, package_json) => !!package_json.devDependencies?.[dep_name] ||
162
160
  !!package_json.dependencies?.[dep_name] ||
163
161
  !!package_json.peerDependencies?.[dep_name];
164
162
  export const extract_deps = (package_json) => {
@@ -1,7 +1,7 @@
1
1
  import { spawn } from '@ryanatkn/belt/process.js';
2
2
  import { z } from 'zod';
3
3
  import { styleText as st } from 'node:util';
4
- import { existsSync } from 'node:fs';
4
+ import { fs_exists } from '@ryanatkn/belt/fs.js';
5
5
  import { GitBranch, GitOrigin, git_check_clean_workspace, git_checkout, git_fetch, git_pull, } from '@ryanatkn/belt/git.js';
6
6
  import { TaskError } from "./task.js";
7
7
  import { load_package_json, parse_repo_url } from "./package_json.js";
@@ -59,13 +59,13 @@ export const task = {
59
59
  if (dry) {
60
60
  log.info(st('green', 'dry run!'));
61
61
  }
62
- const package_json = load_package_json();
62
+ const package_json = await load_package_json();
63
63
  const has_sveltekit_library_result = await has_sveltekit_library(package_json);
64
64
  if (!has_sveltekit_library_result.ok) {
65
65
  throw new TaskError('Failed to find SvelteKit library: ' + has_sveltekit_library_result.message);
66
66
  }
67
- const changelog_exists = existsSync(changelog);
68
- const found_changeset_cli = find_cli(changeset_cli);
67
+ const changelog_exists = await fs_exists(changelog);
68
+ const found_changeset_cli = await find_cli(changeset_cli);
69
69
  if (!found_changeset_cli) {
70
70
  throw new TaskError('changeset command not found, install @changesets/cli locally or globally');
71
71
  }
@@ -132,7 +132,7 @@ export const task = {
132
132
  // Regenerate files that depend on package.json version.
133
133
  // The check above ensures gen is updated.
134
134
  await invoke_task('gen');
135
- const package_json_after_versioning = load_package_json();
135
+ const package_json_after_versioning = await load_package_json();
136
136
  version = package_json_after_versioning.version;
137
137
  if (package_json.version === version) {
138
138
  // The version didn't change.
@@ -166,7 +166,7 @@ export const task = {
166
166
  if (!changeset_publish_result?.ok) {
167
167
  throw new TaskError(`\`${changeset_cli} publish\` failed - continue manually or try again after running \`git reset --hard\``);
168
168
  }
169
- if (!changelog_exists && existsSync(changelog)) {
169
+ if (!changelog_exists && (await fs_exists(changelog))) {
170
170
  await spawn('git', ['add', changelog]);
171
171
  }
172
172
  await spawn('git', ['commit', '-a', '-m', `publish v${version}`]);
@@ -8,7 +8,7 @@ export const task = {
8
8
  summary: 'publish and deploy',
9
9
  Args,
10
10
  run: async ({ invoke_task }) => {
11
- const package_json = load_package_json();
11
+ const package_json = await load_package_json();
12
12
  const publish = (await has_sveltekit_library(package_json)).ok;
13
13
  if (publish) {
14
14
  await invoke_task('publish', { optional: true });
@@ -11,7 +11,7 @@ export const Args = z.strictObject({
11
11
  export const task = {
12
12
  summary: 'diagnostic that logs resolved filesystem info for the given input paths',
13
13
  Args,
14
- run: ({ args, config, log }) => {
14
+ run: async ({ args, config, log }) => {
15
15
  const { _, verbose } = args;
16
16
  if (verbose)
17
17
  log.info('raw input paths:', _);
@@ -21,7 +21,7 @@ export const task = {
21
21
  const { task_root_dirs } = config;
22
22
  if (verbose)
23
23
  log.info('task root paths:', task_root_dirs);
24
- const { resolved_input_paths, possible_paths_by_input_path, unmapped_input_paths } = resolve_input_paths(input_paths, task_root_dirs, TASK_FILE_SUFFIXES);
24
+ const { resolved_input_paths, possible_paths_by_input_path, unmapped_input_paths } = await resolve_input_paths(input_paths, task_root_dirs, TASK_FILE_SUFFIXES);
25
25
  if (verbose)
26
26
  log.info('resolved_input_paths:', resolved_input_paths);
27
27
  if (verbose)
@@ -18,5 +18,5 @@ export interface ResolvedSpecifier {
18
18
  * and infer the correct extension following Vite conventions.
19
19
  * If no `.js` file is found for the specifier on the filesystem, it assumes `.ts`.
20
20
  */
21
- export declare const resolve_specifier: (specifier: string, dir: string) => ResolvedSpecifier;
21
+ export declare const resolve_specifier: (specifier: string, dir: string) => Promise<ResolvedSpecifier>;
22
22
  //# sourceMappingURL=resolve_specifier.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve_specifier.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/resolve_specifier.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,wBAAwB,CAAC;AAMnD,MAAM,WAAW,iBAAiB;IACjC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,wBAAwB,EAAE,MAAM,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,SAAS,GAAG,4BAA4B,GAAG,4BAA4B,CAAC;IACnF,GAAG,EAAE,OAAO,CAAC;CACb;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,WAAW,MAAM,EAAE,KAAK,MAAM,KAAG,iBAgDlE,CAAC"}
1
+ {"version":3,"file":"resolve_specifier.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/resolve_specifier.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,wBAAwB,CAAC;AAMnD,MAAM,WAAW,iBAAiB;IACjC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,wBAAwB,EAAE,MAAM,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,SAAS,GAAG,4BAA4B,GAAG,4BAA4B,CAAC;IACnF,GAAG,EAAE,OAAO,CAAC;CACb;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAC7B,WAAW,MAAM,EACjB,KAAK,MAAM,KACT,OAAO,CAAC,iBAAiB,CAiD3B,CAAC"}
@@ -1,12 +1,12 @@
1
1
  import { extname, isAbsolute, join, relative } from 'node:path';
2
- import { existsSync } from 'node:fs';
2
+ import { fs_exists } from '@ryanatkn/belt/fs.js';
3
3
  import { replace_extension } from "./paths.js";
4
4
  /**
5
5
  * Maps an import `specifier` relative to `dir`,
6
6
  * and infer the correct extension following Vite conventions.
7
7
  * If no `.js` file is found for the specifier on the filesystem, it assumes `.ts`.
8
8
  */
9
- export const resolve_specifier = (specifier, dir) => {
9
+ export const resolve_specifier = async (specifier, dir) => {
10
10
  const raw = specifier.endsWith('?raw'); // TODO more robust detection? other values?
11
11
  const final_specifier = raw ? specifier.substring(0, specifier.length - 4) : specifier;
12
12
  const absolute_path = isAbsolute(final_specifier) ? final_specifier : join(dir, final_specifier);
@@ -16,7 +16,7 @@ export const resolve_specifier = (specifier, dir) => {
16
16
  const ext = extname(absolute_path);
17
17
  const is_js = ext === '.js';
18
18
  const is_ts = ext === '.ts';
19
- if (!is_js && !is_ts && existsSync(absolute_path)) {
19
+ if (!is_js && !is_ts && (await fs_exists(absolute_path))) {
20
20
  // unrecognized extension and the file exists
21
21
  mapped_path = absolute_path;
22
22
  path_id = absolute_path;
@@ -31,7 +31,8 @@ export const resolve_specifier = (specifier, dir) => {
31
31
  // extensionless, or js that points to ts, or just js
32
32
  const js_id = is_js ? absolute_path : absolute_path + '.js';
33
33
  const ts_id = is_js ? replace_extension(absolute_path, '.ts') : absolute_path + '.ts';
34
- if (!existsSync(ts_id) && existsSync(js_id)) {
34
+ const [ts_exists, js_exists] = await Promise.all([fs_exists(ts_id), fs_exists(js_id)]);
35
+ if (!ts_exists && js_exists) {
35
36
  mapped_path = js_id;
36
37
  path_id = js_id;
37
38
  namespace = 'sveltekit_local_imports_js';