@ryanatkn/gro 0.133.5 → 0.133.6

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.
package/dist/gro.js CHANGED
@@ -15,5 +15,5 @@ const invoke_path = resolve_gro_module_path('invoke.js');
15
15
  const loader_path = join(invoke_path, '../loader.js');
16
16
  const spawned = await spawn_with_loader(loader_path, invoke_path, process.argv.slice(2));
17
17
  if (!spawned.ok) {
18
- process.exit(spawned.code || 1); // eslint-disable-line @typescript-eslint/prefer-nullish-coalescing
18
+ process.exitCode = spawned.code || 1; // eslint-disable-line @typescript-eslint/prefer-nullish-coalescing
19
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"../src/lib/","sources":["loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,QAAQ,EAAE,WAAW,EAAC,MAAM,aAAa,CAAC;AA+EvD,eAAO,MAAM,IAAI,EAAE,QAsFlB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,WAoDrB,CAAC"}
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"../src/lib/","sources":["loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,QAAQ,EAAE,WAAW,EAAC,MAAM,aAAa,CAAC;AA+EvD,eAAO,MAAM,IAAI,EAAE,QAwFlB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,WA4DrB,CAAC"}
package/dist/loader.js CHANGED
@@ -3,6 +3,7 @@ import { compile, compileModule, preprocess } from 'svelte/compiler';
3
3
  import { fileURLToPath, pathToFileURL } from 'node:url';
4
4
  import { dirname, join } from 'node:path';
5
5
  import { escape_regexp } from '@ryanatkn/belt/regexp.js';
6
+ import { readFileSync } from 'node:fs';
6
7
  import { render_env_shim_module } from './sveltekit_shim_env.js';
7
8
  import { render_sveltekit_shim_app_environment, render_sveltekit_shim_app_paths, SVELTEKIT_SHIM_APP_ENVIRONMENT_MATCHER, SVELTEKIT_SHIM_APP_PATHS_MATCHER, sveltekit_shim_app_specifiers, } from './sveltekit_shim_app.js';
8
9
  import { default_sveltekit_config } from './sveltekit_config.js';
@@ -35,8 +36,7 @@ node --import 'data:text/javascript,import {register} from "node:module"; import
35
36
  TODO how to improve that gnarly import line? was originally designed for the now-deprecated `--loader`
36
37
 
37
38
  */
38
- // TODO support `?raw` import variants
39
- // TODO sourcemaps for svelte and the svelte preprocessors
39
+ // TODO sourcemaps for the svelte preprocessors
40
40
  // TODO `import.meta.resolve` wasn't available in loaders when this was first implemented, but might be now
41
41
  // dev is always true in the loader
42
42
  const dev = true;
@@ -48,7 +48,7 @@ const ts_transform_options = {
48
48
  sourcemap: 'inline',
49
49
  };
50
50
  const aliases = Object.entries({ $lib: 'src/lib', ...alias });
51
- const NOOP_MATCHER = /\.(css|svg)$/; // TODO others? configurable?
51
+ const RAW_MATCHER = /(%3Fraw|\.css|\.svg)$/; // TODO others? configurable?
52
52
  const ENV_MATCHER = /src\/lib\/\$env\/(static|dynamic)\/(public|private)$/;
53
53
  const NODE_MODULES_MATCHER = new RegExp(escape_regexp('/' + NODE_MODULES_DIRNAME + '/'), 'u');
54
54
  const package_json_cache = {};
@@ -89,10 +89,9 @@ export const load = async (url, context, nextLoad) => {
89
89
  }
90
90
  else if (SVELTE_MATCHER.test(url)) {
91
91
  // Svelte
92
- // TODO support sourcemaps
93
92
  const loaded = await nextLoad(url, context.format === 'module' ? context : { ...context, format: 'module' });
94
- const filename = fileURLToPath(url);
95
93
  const raw_source = loaded.source.toString(); // eslint-disable-line @typescript-eslint/no-base-to-string
94
+ const filename = fileURLToPath(url);
96
95
  const preprocessed = svelte_preprocessors // TODO @many use sourcemaps (and diagnostics?)
97
96
  ? await preprocess(raw_source, svelte_preprocessors, { filename })
98
97
  : null;
@@ -108,9 +107,11 @@ export const load = async (url, context, nextLoad) => {
108
107
  const source = `export default ` + raw_source;
109
108
  return { format: 'module', shortCircuit: true, source };
110
109
  }
111
- else if (NOOP_MATCHER.test(url)) {
112
- // no-ops like `.css` and `.svg`
113
- const source = `export default 'no-op import from ${url}'`;
110
+ else if (RAW_MATCHER.test(url)) {
111
+ // raw text imports like `?raw`, `.css`, `.svg`
112
+ const filename = fileURLToPath(url.endsWith('%3Fraw') ? url.substring(0, url.length - 6) : url);
113
+ const raw_source = readFileSync(filename, 'utf8');
114
+ const source = 'export default `' + raw_source.replaceAll('\\', '\\\\').replaceAll('`', '\\`') + '`;';
114
115
  return { format: 'module', shortCircuit: true, source };
115
116
  }
116
117
  else {
@@ -163,14 +164,22 @@ export const resolve = async (specifier, context, nextResolve) => {
163
164
  // Resolve to `node_modules`.
164
165
  if (SVELTE_MATCHER.test(path) || JSON_MATCHER.test(path)) {
165
166
  // Match the behavior of Vite and esbuild for Svelte and JSON imports.
166
- // TODO maybe `.ts` too
167
- const path_id = resolve_node_specifier(path, dir, parent_url, package_json_cache);
168
- return { url: pathToFileURL(path_id).href, format: 'module', shortCircuit: true };
167
+ // TODO `.ts` too
168
+ const resolved = resolve_node_specifier(path, dir, parent_url, package_json_cache);
169
+ return {
170
+ url: pathToFileURL(resolved.path_id_with_querystring).href,
171
+ format: 'module',
172
+ shortCircuit: true,
173
+ };
169
174
  }
170
175
  else {
171
176
  return nextResolve(path, context);
172
177
  }
173
178
  }
174
- const { path_id } = resolve_specifier(path, dirname(fileURLToPath(parent_url)));
175
- return { url: pathToFileURL(path_id).href, format: 'module', shortCircuit: true };
179
+ const resolved = resolve_specifier(path, dirname(fileURLToPath(parent_url)));
180
+ return {
181
+ url: pathToFileURL(resolved.path_id_with_querystring).href,
182
+ format: 'module',
183
+ shortCircuit: true,
184
+ };
176
185
  };
@@ -1 +1 @@
1
- {"version":3,"file":"package.d.ts","sourceRoot":"../src/lib/","sources":["package.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAquBD,CAAC"}
package/dist/package.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // generated by src/lib/package.gen.ts
2
2
  export const package_json = {
3
3
  name: '@ryanatkn/gro',
4
- version: '0.133.5',
4
+ version: '0.133.6',
5
5
  description: 'task runner and toolkit extending SvelteKit',
6
6
  motto: 'generate, run, optimize',
7
7
  glyph: '🌰',
@@ -56,18 +56,18 @@ export const package_json = {
56
56
  '@changesets/changelog-git': '^0.2.0',
57
57
  '@changesets/types': '^6.0.0',
58
58
  '@ryanatkn/eslint-config': '^0.4.2',
59
- '@ryanatkn/fuz': '^0.118.2',
60
- '@ryanatkn/moss': '^0.11.1',
59
+ '@ryanatkn/fuz': '^0.119.0',
60
+ '@ryanatkn/moss': '^0.12.0',
61
61
  '@sveltejs/adapter-static': '^3.0.2',
62
62
  '@sveltejs/kit': '^2.5.18',
63
63
  '@sveltejs/package': '^2.3.2',
64
64
  '@sveltejs/vite-plugin-svelte': '^3.1.1',
65
65
  '@types/fs-extra': '^11.0.4',
66
- '@types/node': '^20.14.11',
66
+ '@types/node': '^20.14.12',
67
67
  esbuild: '^0.21.5',
68
68
  eslint: '^9.7.0',
69
69
  'eslint-plugin-svelte': '^2.43.0',
70
- svelte: '^5.0.0-next.195',
70
+ svelte: '^5.0.0-next.197',
71
71
  'svelte-check': '^3.8.4',
72
72
  typescript: '^5.5.4',
73
73
  'typescript-eslint': '^8.0.0-alpha.44',
@@ -262,7 +262,7 @@ export const package_json = {
262
262
  };
263
263
  export const src_json = {
264
264
  name: '@ryanatkn/gro',
265
- version: '0.133.5',
265
+ version: '0.133.6',
266
266
  modules: {
267
267
  '.': {
268
268
  path: 'index.ts',
@@ -775,11 +775,7 @@ export const src_json = {
775
775
  },
776
776
  './resolve_node_specifier.js': {
777
777
  path: 'resolve_node_specifier.ts',
778
- declarations: [
779
- { name: 'resolve_node_specifier', kind: 'function' },
780
- { name: 'Parsed_Node_Specifier', kind: 'type' },
781
- { name: 'parse_node_specifier', kind: 'function' },
782
- ],
778
+ declarations: [{ name: 'resolve_node_specifier', kind: 'function' }],
783
779
  },
784
780
  './resolve_specifier.js': {
785
781
  path: 'resolve_specifier.ts',
@@ -1,9 +1,4 @@
1
1
  import { Package_Json } from './package_json.js';
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) => Path_Id;
4
- export interface Parsed_Node_Specifier {
5
- name: string;
6
- path: string;
7
- }
8
- export declare const parse_node_specifier: (specifier: string) => Parsed_Node_Specifier;
2
+ import type { Resolved_Specifier } from './resolve_specifier.js';
3
+ export declare const resolve_node_specifier: (specifier: string, dir?: string, parent_url?: string, cache?: Record<string, Package_Json>, exports_key?: string) => Resolved_Specifier;
9
4
  //# sourceMappingURL=resolve_node_specifier.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve_node_specifier.d.ts","sourceRoot":"../src/lib/","sources":["resolve_node_specifier.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,YAAY,EAAoB,MAAM,mBAAmB,CAAC;AAClE,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAIvC,eAAO,MAAM,sBAAsB,cACvB,MAAM,6BAEJ,MAAM,UACX,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,2BAElC,OAeF,CAAC;AAEF,MAAM,WAAW,qBAAqB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACb;AAED,eAAO,MAAM,oBAAoB,cAAe,MAAM,KAAG,qBAmBxD,CAAC"}
1
+ {"version":3,"file":"resolve_node_specifier.d.ts","sourceRoot":"../src/lib/","sources":["resolve_node_specifier.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,YAAY,EAAoB,MAAM,mBAAmB,CAAC;AAGlE,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,wBAAwB,CAAC;AAE/D,eAAO,MAAM,sBAAsB,cACvB,MAAM,6BAEJ,MAAM,UACX,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,2BAElC,kBA0CF,CAAC"}
@@ -3,26 +3,14 @@ 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
5
  export const resolve_node_specifier = (specifier, dir = paths.root, parent_url, cache, exports_key = specifier.endsWith('.svelte') ? 'svelte' : 'default') => {
6
- const parsed = parse_node_specifier(specifier);
7
- const subpath = './' + parsed.path;
8
- const package_dir = join(dir, NODE_MODULES_DIRNAME, parsed.name);
9
- const package_json = load_package_json(package_dir, cache);
10
- const exported = package_json.exports?.[subpath];
11
- if (!exported) {
12
- // same error message as Node
13
- throw Error(`[ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath '${subpath}' is not defined by "exports" in ${package_dir}/package.json` +
14
- (parent_url ? ` imported from ${parent_url}` : ''));
15
- }
16
- const path_id = join(package_dir, exported[exports_key]);
17
- return path_id;
18
- };
19
- export const parse_node_specifier = (specifier) => {
6
+ const raw = specifier.endsWith('?raw');
7
+ const mapped_specifier = raw ? specifier.substring(0, specifier.length - 4) : specifier;
20
8
  let idx;
21
- if (specifier[0] === '@') {
9
+ if (mapped_specifier[0] === '@') {
22
10
  // get the index of the second `/`
23
11
  let count = 0;
24
- for (let i = 0; i < specifier.length; i++) {
25
- if (specifier[i] === '/')
12
+ for (let i = 0; i < mapped_specifier.length; i++) {
13
+ if (mapped_specifier[i] === '/')
26
14
  count++;
27
15
  if (count === 2) {
28
16
  idx = i;
@@ -31,10 +19,26 @@ export const parse_node_specifier = (specifier) => {
31
19
  }
32
20
  }
33
21
  else {
34
- idx = specifier.indexOf('/');
22
+ idx = mapped_specifier.indexOf('/');
35
23
  }
24
+ const name = mapped_specifier.substring(0, idx);
25
+ const path = mapped_specifier.substring(idx + 1);
26
+ const subpath = './' + path;
27
+ const package_dir = join(dir, NODE_MODULES_DIRNAME, name);
28
+ const package_json = load_package_json(package_dir, cache);
29
+ const exported = package_json.exports?.[subpath];
30
+ if (!exported) {
31
+ // same error message as Node
32
+ throw Error(`[ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath '${subpath}' is not defined by "exports" in ${package_dir}/package.json` +
33
+ (parent_url ? ` imported from ${parent_url}` : ''));
34
+ }
35
+ const path_id = join(package_dir, exported[exports_key]);
36
36
  return {
37
- name: specifier.substring(0, idx),
38
- path: specifier.substring(idx + 1),
37
+ path_id,
38
+ path_id_with_querystring: raw ? path_id + '?raw' : path_id,
39
+ raw,
40
+ specifier,
41
+ mapped_specifier,
42
+ namespace: undefined,
39
43
  };
40
44
  };
@@ -1,17 +1,26 @@
1
1
  import type { Path_Id } from './path.js';
2
2
  export interface Resolved_Specifier {
3
- specifier: string;
3
+ /**
4
+ * The resolved filesystem path for the specifier.
5
+ */
4
6
  path_id: Path_Id;
7
+ /**
8
+ * Same as `path_id` but includes `?raw` and other querystrings. (currently none)
9
+ */
10
+ path_id_with_querystring: string;
11
+ specifier: string;
12
+ mapped_specifier: string;
5
13
  namespace: undefined | 'sveltekit_local_imports_ts' | 'sveltekit_local_imports_js';
14
+ raw: boolean;
6
15
  }
7
16
  /**
8
17
  * Maps a `path` import specifier relative to the `importer`,
9
18
  * and infer the correct extension following Vite conventions.
10
19
  * If no `.js` file is found for the `path` on the filesystem, it assumes `.ts`.
11
- * @param path
20
+ * @param specifier
12
21
  * @param dir - if defined, enables relative importers like from esbuild plugins
13
22
  * @param passthrough_extensions - used to support specifiers that have no file extention, which Vite supports, so we do our best effort
14
23
  * @returns
15
24
  */
16
- export declare const resolve_specifier: (path: string, dir: string) => Resolved_Specifier;
25
+ export declare const resolve_specifier: (specifier: string, dir: string) => Resolved_Specifier;
17
26
  //# sourceMappingURL=resolve_specifier.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve_specifier.d.ts","sourceRoot":"../src/lib/","sources":["resolve_specifier.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAEvC,MAAM,WAAW,kBAAkB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,SAAS,GAAG,4BAA4B,GAAG,4BAA4B,CAAC;CACnF;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,SAAU,MAAM,OAAO,MAAM,KAAG,kBAuC7D,CAAC"}
1
+ {"version":3,"file":"resolve_specifier.d.ts","sourceRoot":"../src/lib/","sources":["resolve_specifier.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAEvC,MAAM,WAAW,kBAAkB;IAClC;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;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;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,cAAe,MAAM,OAAO,MAAM,KAAG,kBAgDlE,CAAC"}
@@ -5,13 +5,15 @@ import { replace_extension } from './paths.js';
5
5
  * Maps a `path` import specifier relative to the `importer`,
6
6
  * and infer the correct extension following Vite conventions.
7
7
  * If no `.js` file is found for the `path` on the filesystem, it assumes `.ts`.
8
- * @param path
8
+ * @param specifier
9
9
  * @param dir - if defined, enables relative importers like from esbuild plugins
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 = (path, dir) => {
14
- const absolute_path = isAbsolute(path) ? path : join(dir, path);
13
+ export const resolve_specifier = (specifier, dir) => {
14
+ const raw = specifier.endsWith('?raw');
15
+ const final_specifier = raw ? specifier.substring(0, specifier.length - 4) : specifier;
16
+ const absolute_path = isAbsolute(final_specifier) ? final_specifier : join(dir, final_specifier);
15
17
  let mapped_path;
16
18
  let path_id;
17
19
  let namespace;
@@ -44,8 +46,15 @@ export const resolve_specifier = (path, dir) => {
44
46
  namespace = 'sveltekit_local_imports_ts';
45
47
  }
46
48
  }
47
- let specifier = relative(dir, mapped_path);
48
- if (specifier[0] !== '.')
49
- specifier = './' + specifier;
50
- return { specifier, path_id, namespace };
49
+ let mapped_specifier = relative(dir, mapped_path);
50
+ if (mapped_specifier[0] !== '.')
51
+ mapped_specifier = './' + mapped_specifier;
52
+ return {
53
+ path_id,
54
+ path_id_with_querystring: raw ? path_id + '?raw' : path_id,
55
+ raw,
56
+ specifier,
57
+ mapped_specifier,
58
+ namespace,
59
+ };
51
60
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ryanatkn/gro",
3
- "version": "0.133.5",
3
+ "version": "0.133.6",
4
4
  "description": "task runner and toolkit extending SvelteKit",
5
5
  "motto": "generate, run, optimize",
6
6
  "glyph": "🌰",
@@ -69,18 +69,18 @@
69
69
  "@changesets/changelog-git": "^0.2.0",
70
70
  "@changesets/types": "^6.0.0",
71
71
  "@ryanatkn/eslint-config": "^0.4.2",
72
- "@ryanatkn/fuz": "^0.118.2",
73
- "@ryanatkn/moss": "^0.11.1",
72
+ "@ryanatkn/fuz": "^0.119.0",
73
+ "@ryanatkn/moss": "^0.12.0",
74
74
  "@sveltejs/adapter-static": "^3.0.2",
75
75
  "@sveltejs/kit": "^2.5.18",
76
76
  "@sveltejs/package": "^2.3.2",
77
77
  "@sveltejs/vite-plugin-svelte": "^3.1.1",
78
78
  "@types/fs-extra": "^11.0.4",
79
- "@types/node": "^20.14.11",
79
+ "@types/node": "^20.14.12",
80
80
  "esbuild": "^0.21.5",
81
81
  "eslint": "^9.7.0",
82
82
  "eslint-plugin-svelte": "^2.43.0",
83
- "svelte": "^5.0.0-next.195",
83
+ "svelte": "^5.0.0-next.197",
84
84
  "svelte-check": "^3.8.4",
85
85
  "typescript": "^5.5.4",
86
86
  "typescript-eslint": "^8.0.0-alpha.44",
package/src/lib/gro.ts CHANGED
@@ -21,5 +21,5 @@ const loader_path = join(invoke_path, '../loader.js');
21
21
 
22
22
  const spawned = await spawn_with_loader(loader_path, invoke_path, process.argv.slice(2));
23
23
  if (!spawned.ok) {
24
- process.exit(spawned.code || 1); // eslint-disable-line @typescript-eslint/prefer-nullish-coalescing
24
+ process.exitCode = spawned.code || 1; // eslint-disable-line @typescript-eslint/prefer-nullish-coalescing
25
25
  }
package/src/lib/loader.ts CHANGED
@@ -4,6 +4,7 @@ import {fileURLToPath, pathToFileURL} from 'node:url';
4
4
  import {dirname, join} from 'node:path';
5
5
  import type {LoadHook, ResolveHook} from 'node:module';
6
6
  import {escape_regexp} from '@ryanatkn/belt/regexp.js';
7
+ import {readFileSync} from 'node:fs';
7
8
 
8
9
  import {render_env_shim_module} from './sveltekit_shim_env.js';
9
10
  import {
@@ -46,8 +47,7 @@ TODO how to improve that gnarly import line? was originally designed for the now
46
47
 
47
48
  */
48
49
 
49
- // TODO support `?raw` import variants
50
- // TODO sourcemaps for svelte and the svelte preprocessors
50
+ // TODO sourcemaps for the svelte preprocessors
51
51
  // TODO `import.meta.resolve` wasn't available in loaders when this was first implemented, but might be now
52
52
 
53
53
  // dev is always true in the loader
@@ -75,7 +75,7 @@ const ts_transform_options: esbuild.TransformOptions = {
75
75
 
76
76
  const aliases = Object.entries({$lib: 'src/lib', ...alias});
77
77
 
78
- const NOOP_MATCHER = /\.(css|svg)$/; // TODO others? configurable?
78
+ const RAW_MATCHER = /(%3Fraw|\.css|\.svg)$/; // TODO others? configurable?
79
79
  const ENV_MATCHER = /src\/lib\/\$env\/(static|dynamic)\/(public|private)$/;
80
80
  const NODE_MODULES_MATCHER = new RegExp(escape_regexp('/' + NODE_MODULES_DIRNAME + '/'), 'u');
81
81
 
@@ -120,13 +120,12 @@ export const load: LoadHook = async (url, context, nextLoad) => {
120
120
  return {format: 'module', shortCircuit: true, source: transformed.code};
121
121
  } else if (SVELTE_MATCHER.test(url)) {
122
122
  // Svelte
123
- // TODO support sourcemaps
124
123
  const loaded = await nextLoad(
125
124
  url,
126
125
  context.format === 'module' ? context : {...context, format: 'module'}, // TODO dunno why this is needed, specifically with tests
127
126
  );
128
- const filename = fileURLToPath(url);
129
127
  const raw_source = loaded.source!.toString(); // eslint-disable-line @typescript-eslint/no-base-to-string
128
+ const filename = fileURLToPath(url);
130
129
  const preprocessed = svelte_preprocessors // TODO @many use sourcemaps (and diagnostics?)
131
130
  ? await preprocess(raw_source, svelte_preprocessors, {filename})
132
131
  : null;
@@ -140,9 +139,12 @@ export const load: LoadHook = async (url, context, nextLoad) => {
140
139
  const raw_source = loaded.source!.toString(); // eslint-disable-line @typescript-eslint/no-base-to-string
141
140
  const source = `export default ` + raw_source;
142
141
  return {format: 'module', shortCircuit: true, source};
143
- } else if (NOOP_MATCHER.test(url)) {
144
- // no-ops like `.css` and `.svg`
145
- const source = `export default 'no-op import from ${url}'`;
142
+ } else if (RAW_MATCHER.test(url)) {
143
+ // raw text imports like `?raw`, `.css`, `.svg`
144
+ const filename = fileURLToPath(url.endsWith('%3Fraw') ? url.substring(0, url.length - 6) : url);
145
+ const raw_source = readFileSync(filename, 'utf8');
146
+ const source =
147
+ 'export default `' + raw_source.replaceAll('\\', '\\\\').replaceAll('`', '\\`') + '`;';
146
148
  return {format: 'module', shortCircuit: true, source};
147
149
  } else {
148
150
  const matched_env = ENV_MATCHER.exec(url);
@@ -210,15 +212,23 @@ export const resolve: ResolveHook = async (specifier, context, nextResolve) => {
210
212
  // Resolve to `node_modules`.
211
213
  if (SVELTE_MATCHER.test(path) || JSON_MATCHER.test(path)) {
212
214
  // Match the behavior of Vite and esbuild for Svelte and JSON imports.
213
- // TODO maybe `.ts` too
214
- const path_id = resolve_node_specifier(path, dir, parent_url, package_json_cache);
215
- return {url: pathToFileURL(path_id).href, format: 'module', shortCircuit: true};
215
+ // TODO `.ts` too
216
+ const resolved = resolve_node_specifier(path, dir, parent_url, package_json_cache);
217
+ return {
218
+ url: pathToFileURL(resolved.path_id_with_querystring).href,
219
+ format: 'module',
220
+ shortCircuit: true,
221
+ };
216
222
  } else {
217
223
  return nextResolve(path, context);
218
224
  }
219
225
  }
220
226
 
221
- const {path_id} = resolve_specifier(path, dirname(fileURLToPath(parent_url)));
227
+ const resolved = resolve_specifier(path, dirname(fileURLToPath(parent_url)));
222
228
 
223
- return {url: pathToFileURL(path_id).href, format: 'module', shortCircuit: true};
229
+ return {
230
+ url: pathToFileURL(resolved.path_id_with_querystring).href,
231
+ format: 'module',
232
+ shortCircuit: true,
233
+ };
224
234
  };
@@ -5,7 +5,7 @@ import type {Src_Json} from './src_json.js';
5
5
 
6
6
  export const package_json = {
7
7
  name: '@ryanatkn/gro',
8
- version: '0.133.5',
8
+ version: '0.133.6',
9
9
  description: 'task runner and toolkit extending SvelteKit',
10
10
  motto: 'generate, run, optimize',
11
11
  glyph: '🌰',
@@ -61,18 +61,18 @@ export const package_json = {
61
61
  '@changesets/changelog-git': '^0.2.0',
62
62
  '@changesets/types': '^6.0.0',
63
63
  '@ryanatkn/eslint-config': '^0.4.2',
64
- '@ryanatkn/fuz': '^0.118.2',
65
- '@ryanatkn/moss': '^0.11.1',
64
+ '@ryanatkn/fuz': '^0.119.0',
65
+ '@ryanatkn/moss': '^0.12.0',
66
66
  '@sveltejs/adapter-static': '^3.0.2',
67
67
  '@sveltejs/kit': '^2.5.18',
68
68
  '@sveltejs/package': '^2.3.2',
69
69
  '@sveltejs/vite-plugin-svelte': '^3.1.1',
70
70
  '@types/fs-extra': '^11.0.4',
71
- '@types/node': '^20.14.11',
71
+ '@types/node': '^20.14.12',
72
72
  esbuild: '^0.21.5',
73
73
  eslint: '^9.7.0',
74
74
  'eslint-plugin-svelte': '^2.43.0',
75
- svelte: '^5.0.0-next.195',
75
+ svelte: '^5.0.0-next.197',
76
76
  'svelte-check': '^3.8.4',
77
77
  typescript: '^5.5.4',
78
78
  'typescript-eslint': '^8.0.0-alpha.44',
@@ -268,7 +268,7 @@ export const package_json = {
268
268
 
269
269
  export const src_json = {
270
270
  name: '@ryanatkn/gro',
271
- version: '0.133.5',
271
+ version: '0.133.6',
272
272
  modules: {
273
273
  '.': {
274
274
  path: 'index.ts',
@@ -781,11 +781,7 @@ export const src_json = {
781
781
  },
782
782
  './resolve_node_specifier.js': {
783
783
  path: 'resolve_node_specifier.ts',
784
- declarations: [
785
- {name: 'resolve_node_specifier', kind: 'function'},
786
- {name: 'Parsed_Node_Specifier', kind: 'type'},
787
- {name: 'parse_node_specifier', kind: 'function'},
788
- ],
784
+ declarations: [{name: 'resolve_node_specifier', kind: 'function'}],
789
785
  },
790
786
  './resolve_specifier.js': {
791
787
  path: 'resolve_specifier.ts',
@@ -1,9 +1,9 @@
1
1
  import {join} from 'node:path';
2
2
 
3
3
  import {Package_Json, load_package_json} from './package_json.js';
4
- import type {Path_Id} from './path.js';
5
4
  import {paths} from './paths.js';
6
5
  import {NODE_MODULES_DIRNAME} from './path_constants.js';
6
+ import type {Resolved_Specifier} from './resolve_specifier.js';
7
7
 
8
8
  export const resolve_node_specifier = (
9
9
  specifier: string,
@@ -11,45 +11,46 @@ export const resolve_node_specifier = (
11
11
  parent_url?: string,
12
12
  cache?: Record<string, Package_Json>,
13
13
  exports_key = specifier.endsWith('.svelte') ? 'svelte' : 'default',
14
- ): Path_Id => {
15
- const parsed = parse_node_specifier(specifier);
16
- const subpath = './' + parsed.path;
17
- const package_dir = join(dir, NODE_MODULES_DIRNAME, parsed.name);
18
- const package_json = load_package_json(package_dir, cache);
19
- const exported = package_json.exports?.[subpath];
20
- if (!exported) {
21
- // same error message as Node
22
- throw Error(
23
- `[ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath '${subpath}' is not defined by "exports" in ${package_dir}/package.json` +
24
- (parent_url ? ` imported from ${parent_url}` : ''),
25
- );
26
- }
27
- const path_id = join(package_dir, exported[exports_key]);
28
- return path_id;
29
- };
30
-
31
- export interface Parsed_Node_Specifier {
32
- name: string;
33
- path: string;
34
- }
14
+ ): Resolved_Specifier => {
15
+ const raw = specifier.endsWith('?raw');
16
+ const mapped_specifier = raw ? specifier.substring(0, specifier.length - 4) : specifier;
35
17
 
36
- export const parse_node_specifier = (specifier: string): Parsed_Node_Specifier => {
37
18
  let idx!: number;
38
- if (specifier[0] === '@') {
19
+ if (mapped_specifier[0] === '@') {
39
20
  // get the index of the second `/`
40
21
  let count = 0;
41
- for (let i = 0; i < specifier.length; i++) {
42
- if (specifier[i] === '/') count++;
22
+ for (let i = 0; i < mapped_specifier.length; i++) {
23
+ if (mapped_specifier[i] === '/') count++;
43
24
  if (count === 2) {
44
25
  idx = i;
45
26
  break;
46
27
  }
47
28
  }
48
29
  } else {
49
- idx = specifier.indexOf('/');
30
+ idx = mapped_specifier.indexOf('/');
50
31
  }
32
+ const name = mapped_specifier.substring(0, idx);
33
+ const path = mapped_specifier.substring(idx + 1);
34
+
35
+ const subpath = './' + path;
36
+ const package_dir = join(dir, NODE_MODULES_DIRNAME, name);
37
+ const package_json = load_package_json(package_dir, cache);
38
+ const exported = package_json.exports?.[subpath];
39
+ if (!exported) {
40
+ // same error message as Node
41
+ throw Error(
42
+ `[ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath '${subpath}' is not defined by "exports" in ${package_dir}/package.json` +
43
+ (parent_url ? ` imported from ${parent_url}` : ''),
44
+ );
45
+ }
46
+ const path_id = join(package_dir, exported[exports_key]);
47
+
51
48
  return {
52
- name: specifier.substring(0, idx),
53
- path: specifier.substring(idx + 1),
49
+ path_id,
50
+ path_id_with_querystring: raw ? path_id + '?raw' : path_id,
51
+ raw,
52
+ specifier,
53
+ mapped_specifier,
54
+ namespace: undefined,
54
55
  };
55
56
  };
@@ -5,22 +5,33 @@ import {replace_extension} from './paths.js';
5
5
  import type {Path_Id} from './path.js';
6
6
 
7
7
  export interface Resolved_Specifier {
8
- specifier: string;
8
+ /**
9
+ * The resolved filesystem path for the specifier.
10
+ */
9
11
  path_id: Path_Id;
12
+ /**
13
+ * Same as `path_id` but includes `?raw` and other querystrings. (currently none)
14
+ */
15
+ path_id_with_querystring: string;
16
+ specifier: string;
17
+ mapped_specifier: string;
10
18
  namespace: undefined | 'sveltekit_local_imports_ts' | 'sveltekit_local_imports_js';
19
+ raw: boolean;
11
20
  }
12
21
 
13
22
  /**
14
23
  * Maps a `path` import specifier relative to the `importer`,
15
24
  * and infer the correct extension following Vite conventions.
16
25
  * If no `.js` file is found for the `path` on the filesystem, it assumes `.ts`.
17
- * @param path
26
+ * @param specifier
18
27
  * @param dir - if defined, enables relative importers like from esbuild plugins
19
28
  * @param passthrough_extensions - used to support specifiers that have no file extention, which Vite supports, so we do our best effort
20
29
  * @returns
21
30
  */
22
- export const resolve_specifier = (path: string, dir: string): Resolved_Specifier => {
23
- const absolute_path = isAbsolute(path) ? path : join(dir, path);
31
+ export const resolve_specifier = (specifier: string, dir: string): Resolved_Specifier => {
32
+ const raw = specifier.endsWith('?raw');
33
+ const final_specifier = raw ? specifier.substring(0, specifier.length - 4) : specifier;
34
+ const absolute_path = isAbsolute(final_specifier) ? final_specifier : join(dir, final_specifier);
24
35
 
25
36
  let mapped_path;
26
37
  let path_id;
@@ -54,8 +65,15 @@ export const resolve_specifier = (path: string, dir: string): Resolved_Specifier
54
65
  }
55
66
  }
56
67
 
57
- let specifier = relative(dir, mapped_path);
58
- if (specifier[0] !== '.') specifier = './' + specifier;
68
+ let mapped_specifier = relative(dir, mapped_path);
69
+ if (mapped_specifier[0] !== '.') mapped_specifier = './' + mapped_specifier;
59
70
 
60
- return {specifier, path_id, namespace};
71
+ return {
72
+ path_id,
73
+ path_id_with_querystring: raw ? path_id + '?raw' : path_id,
74
+ raw,
75
+ specifier,
76
+ mapped_specifier,
77
+ namespace,
78
+ };
61
79
  };