@ryanatkn/gro 0.115.2 → 0.116.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.
@@ -27,14 +27,14 @@ export declare const Args: z.ZodObject<{
27
27
  access?: "public" | "restricted" | undefined;
28
28
  }, {
29
29
  _?: string[] | undefined;
30
+ dir?: string | undefined;
31
+ install?: boolean | undefined;
32
+ origin?: string | undefined;
30
33
  minor?: boolean | undefined;
31
34
  major?: boolean | undefined;
32
- dir?: string | undefined;
33
35
  access?: "public" | "restricted" | undefined;
34
36
  changelog?: string | undefined;
35
- install?: boolean | undefined;
36
37
  'no-install'?: boolean | undefined;
37
- origin?: string | undefined;
38
38
  }>;
39
39
  export type Args = z.infer<typeof Args>;
40
40
  /**
@@ -29,15 +29,15 @@ export declare const Args: z.ZodObject<{
29
29
  'no-lint': boolean;
30
30
  workspace: boolean;
31
31
  }, {
32
+ package_json?: boolean | undefined;
33
+ format?: boolean | undefined;
32
34
  typecheck?: boolean | undefined;
33
35
  'no-typecheck'?: boolean | undefined;
34
36
  test?: boolean | undefined;
35
37
  'no-test'?: boolean | undefined;
36
38
  gen?: boolean | undefined;
37
39
  'no-gen'?: boolean | undefined;
38
- format?: boolean | undefined;
39
40
  'no-format'?: boolean | undefined;
40
- package_json?: boolean | undefined;
41
41
  'no-package_json'?: boolean | undefined;
42
42
  lint?: boolean | undefined;
43
43
  'no-lint'?: boolean | undefined;
@@ -1,9 +1,9 @@
1
1
  /// <reference types="node" />
2
2
  import type { RmOptions } from 'node:fs';
3
3
  export declare const clean_fs: ({ build, build_dev, build_dist, sveltekit, nodemodules, }: {
4
- build?: boolean | undefined;
5
- build_dev?: boolean | undefined;
6
- build_dist?: boolean | undefined;
7
- sveltekit?: boolean | undefined;
8
- nodemodules?: boolean | undefined;
4
+ build?: boolean;
5
+ build_dev?: boolean;
6
+ build_dist?: boolean;
7
+ sveltekit?: boolean;
8
+ nodemodules?: boolean;
9
9
  }, rm_options?: RmOptions) => Promise<void>;
@@ -29,18 +29,18 @@ export declare const Args: z.ZodObject<{
29
29
  dangerous: boolean;
30
30
  'no-build': boolean;
31
31
  }, {
32
- source?: string | undefined;
32
+ build?: boolean | undefined;
33
33
  target?: string | undefined;
34
+ install?: boolean | undefined;
34
35
  origin?: string | undefined;
36
+ reset?: boolean | undefined;
37
+ 'no-install'?: boolean | undefined;
38
+ source?: string | undefined;
35
39
  deploy_dir?: string | undefined;
36
40
  build_dir?: string | undefined;
37
41
  dry?: boolean | undefined;
38
42
  force?: boolean | undefined;
39
43
  dangerous?: boolean | undefined;
40
- reset?: boolean | undefined;
41
- install?: boolean | undefined;
42
- 'no-install'?: boolean | undefined;
43
- build?: boolean | undefined;
44
44
  'no-build'?: boolean | undefined;
45
45
  }>;
46
46
  export type Args = z.infer<typeof Args>;
@@ -13,8 +13,8 @@ export declare const Args: z.ZodObject<{
13
13
  'no-sync': boolean;
14
14
  }, {
15
15
  watch?: boolean | undefined;
16
- 'no-watch'?: boolean | undefined;
17
16
  sync?: boolean | undefined;
17
+ 'no-watch'?: boolean | undefined;
18
18
  'no-sync'?: boolean | undefined;
19
19
  }>;
20
20
  export type Args = z.infer<typeof Args>;
@@ -1,9 +1,10 @@
1
1
  /// <reference types="svelte" />
2
2
  import type * as esbuild from 'esbuild';
3
- import { type CompileOptions, type PreprocessorGroup } from 'svelte/compiler';
3
+ import { type CompileOptions, type ModuleCompileOptions, type PreprocessorGroup } from 'svelte/compiler';
4
4
  export interface Options {
5
5
  dir?: string;
6
6
  svelte_compile_options?: CompileOptions;
7
+ svelte_compile_module_options?: ModuleCompileOptions;
7
8
  svelte_preprocessors?: PreprocessorGroup | PreprocessorGroup[];
8
9
  }
9
- export declare const esbuild_plugin_svelte: ({ dir, svelte_compile_options, svelte_preprocessors, }: Options) => esbuild.Plugin;
10
+ export declare const esbuild_plugin_svelte: (options?: Options) => esbuild.Plugin;
@@ -1,38 +1,63 @@
1
- import { compile, preprocess } from 'svelte/compiler';
1
+ import { compile, compileModule, preprocess, } from 'svelte/compiler';
2
2
  import { readFile } from 'node:fs/promises';
3
3
  import { relative } from 'node:path';
4
4
  import { cwd } from 'node:process';
5
- export const esbuild_plugin_svelte = ({ dir = cwd(), svelte_compile_options, svelte_preprocessors, }) => ({
6
- name: 'svelte',
7
- setup: (build) => {
8
- build.onLoad({ filter: /\.svelte$/u }, async ({ path }) => {
9
- let source = await readFile(path, 'utf8');
10
- try {
11
- const filename = relative(dir, path);
12
- const preprocessed = svelte_preprocessors
13
- ? await preprocess(source, svelte_preprocessors, { filename })
14
- : null;
15
- // TODO handle preprocessor sourcemaps, same as in loader - merge?
16
- if (preprocessed?.code)
17
- source = preprocessed?.code;
18
- const { js, warnings } = compile(source, svelte_compile_options);
19
- const contents = js.map ? js.code + '//# sourceMappingURL=' + js.map.toUrl() : js.code;
20
- return {
21
- contents,
22
- warnings: warnings.map((w) => to_sveltekit_message(filename, source, w)),
23
- };
24
- }
25
- catch (err) {
26
- return { errors: [to_sveltekit_message(path, source, err)] };
27
- }
28
- });
29
- },
30
- });
5
+ import { SVELTE_MATCHER, SVELTE_RUNES_MATCHER } from './svelte_helpers.js';
6
+ export const esbuild_plugin_svelte = (options = {}) => {
7
+ const { dir = cwd(), svelte_compile_options = {}, svelte_compile_module_options = {}, svelte_preprocessors, } = options;
8
+ return {
9
+ name: 'svelte',
10
+ setup: (build) => {
11
+ build.onLoad({ filter: SVELTE_RUNES_MATCHER }, async ({ path }) => {
12
+ const source = await readFile(path, 'utf8');
13
+ try {
14
+ const filename = relative(dir, path);
15
+ const { js, warnings } = compileModule(source, {
16
+ filename,
17
+ ...svelte_compile_module_options,
18
+ });
19
+ const contents = js.map ? js.code + '//# sourceMappingURL=' + js.map.toUrl() : js.code;
20
+ return {
21
+ contents,
22
+ warnings: warnings.map((w) => convert_svelte_message_to_esbuild(filename, source, w)),
23
+ };
24
+ }
25
+ catch (err) {
26
+ return { errors: [convert_svelte_message_to_esbuild(path, source, err)] };
27
+ }
28
+ });
29
+ build.onLoad({ filter: SVELTE_MATCHER }, async ({ path }) => {
30
+ let source = await readFile(path, 'utf8');
31
+ try {
32
+ const filename = relative(dir, path);
33
+ const preprocessed = svelte_preprocessors
34
+ ? await preprocess(source, svelte_preprocessors, { filename })
35
+ : null;
36
+ // TODO handle preprocessor sourcemaps, same as in loader - merge?
37
+ if (preprocessed?.code)
38
+ source = preprocessed?.code;
39
+ const { js, warnings } = compile(source, {
40
+ filename,
41
+ ...svelte_compile_options,
42
+ });
43
+ const contents = js.map ? js.code + '//# sourceMappingURL=' + js.map.toUrl() : js.code;
44
+ return {
45
+ contents,
46
+ warnings: warnings.map((w) => convert_svelte_message_to_esbuild(filename, source, w)),
47
+ };
48
+ }
49
+ catch (err) {
50
+ return { errors: [convert_svelte_message_to_esbuild(path, source, err)] };
51
+ }
52
+ });
53
+ },
54
+ };
55
+ };
31
56
  /**
32
57
  * Following the example in the esbuild docs:
33
58
  * https://esbuild.github.io/plugins/#svelte-plugin
34
59
  */
35
- const to_sveltekit_message = (path, source, { message, start, end }) => {
60
+ const convert_svelte_message_to_esbuild = (path, source, { message, start, end }) => {
36
61
  let location = null;
37
62
  if (start && end) {
38
63
  const lineText = source.split(/\r\n|\r|\n/gu)[start.line - 1];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,74 @@
1
+ import { test } from 'uvu';
2
+ import * as assert from 'uvu/assert';
3
+ import * as esbuild from 'esbuild';
4
+ import { readFile, rm } from 'node:fs/promises';
5
+ import { esbuild_plugin_svelte } from './esbuild_plugin_svelte.js';
6
+ test('build for the client', async () => {
7
+ const outfile = './src/fixtures/modules/some_test_server_bundle_DELETEME.js';
8
+ const built = await esbuild.build({
9
+ entryPoints: ['./src/fixtures/modules/some_test_server.ts'],
10
+ plugins: [esbuild_plugin_svelte()],
11
+ outfile,
12
+ format: 'esm',
13
+ platform: 'node',
14
+ packages: 'external',
15
+ bundle: true,
16
+ target: 'esnext',
17
+ });
18
+ assert.is(built.errors.length, 0);
19
+ assert.is(built.warnings.length, 0);
20
+ const built_output = await readFile(outfile, 'utf8');
21
+ assert.is(built_output, `// src/fixtures/modules/some_test_svelte_ts.svelte.ts
22
+ import * as $ from "svelte/internal/client";
23
+ var Some_Test_Svelte_Ts = class {
24
+ #a = $.source("ok");
25
+ get a() {
26
+ return $.get(this.#a);
27
+ }
28
+ set a(value) {
29
+ $.set(this.#a, $.proxy(value));
30
+ }
31
+ };
32
+
33
+ // src/fixtures/modules/some_test_server.ts
34
+ var some_test_server = "some_test_server";
35
+ var Rexported_Some_Test_Svelte_Ts = Some_Test_Svelte_Ts;
36
+ export {
37
+ Rexported_Some_Test_Svelte_Ts,
38
+ some_test_server
39
+ };
40
+ `);
41
+ await rm(outfile); // TODO could be cleaner
42
+ });
43
+ test('build for the server', async () => {
44
+ const outfile = './src/fixtures/modules/some_test_client_bundle_DELETEME.js';
45
+ const built = await esbuild.build({
46
+ entryPoints: ['./src/fixtures/modules/some_test_server.ts'],
47
+ plugins: [esbuild_plugin_svelte({ svelte_compile_module_options: { generate: 'server' } })],
48
+ outfile,
49
+ format: 'esm',
50
+ platform: 'node',
51
+ packages: 'external',
52
+ bundle: true,
53
+ target: 'esnext',
54
+ });
55
+ assert.is(built.errors.length, 0);
56
+ assert.is(built.warnings.length, 0);
57
+ const built_output = await readFile(outfile, 'utf8');
58
+ assert.is(built_output, `// src/fixtures/modules/some_test_svelte_ts.svelte.ts
59
+ import * as $ from "svelte/internal/server";
60
+ var Some_Test_Svelte_Ts = class {
61
+ a = "ok";
62
+ };
63
+
64
+ // src/fixtures/modules/some_test_server.ts
65
+ var some_test_server = "some_test_server";
66
+ var Rexported_Some_Test_Svelte_Ts = Some_Test_Svelte_Ts;
67
+ export {
68
+ Rexported_Some_Test_Svelte_Ts,
69
+ some_test_server
70
+ };
71
+ `);
72
+ await rm(outfile); // TODO could be cleaner
73
+ });
74
+ test.run();
@@ -23,7 +23,6 @@ export const esbuild_plugin_sveltekit_local_imports = () => ({
23
23
  }));
24
24
  build.onLoad({ filter: /.*/u, namespace: 'sveltekit_local_imports_js' }, async ({ path }) => ({
25
25
  contents: await readFile(path),
26
- loader: 'js',
27
26
  resolveDir: dirname(path),
28
27
  }));
29
28
  },
@@ -8,7 +8,6 @@ export const esbuild_plugin_sveltekit_shim_app = ({ dev, base_url, assets_url, }
8
8
  namespace: 'sveltekit_shim_app_paths',
9
9
  }));
10
10
  build.onLoad({ filter: /.*/u, namespace: 'sveltekit_shim_app_paths' }, () => ({
11
- loader: 'js',
12
11
  contents: render_sveltekit_shim_app_paths(base_url, assets_url),
13
12
  }));
14
13
  build.onResolve({ filter: /^\$app\/environment$/u }, ({ path }) => ({
@@ -16,7 +15,6 @@ export const esbuild_plugin_sveltekit_shim_app = ({ dev, base_url, assets_url, }
16
15
  namespace: 'sveltekit_shim_app_environment',
17
16
  }));
18
17
  build.onLoad({ filter: /.*/u, namespace: 'sveltekit_shim_app_environment' }, () => ({
19
- loader: 'js',
20
18
  contents: render_sveltekit_shim_app_environment(dev),
21
19
  }));
22
20
  },
package/dist/fs.d.ts CHANGED
@@ -4,4 +4,4 @@ export declare const exists: (path: string) => Promise<boolean>;
4
4
  /**
5
5
  * Empties a directory with an optional `filter`.
6
6
  */
7
- export declare const empty_dir: (dir: string, filter?: ((path: string) => boolean) | undefined, options?: RmOptions) => Promise<void>;
7
+ export declare const empty_dir: (dir: string, filter?: (path: string) => boolean, options?: RmOptions) => Promise<void>;
@@ -33,6 +33,10 @@ export const gro_plugin_server = ({ entry_points = [SERVER_SOURCE_ID], dir = cwd
33
33
  name: 'gro_plugin_server',
34
34
  setup: async ({ dev, watch, timings, log }) => {
35
35
  const { alias, base_url, assets_url, env_dir, private_prefix, public_prefix, svelte_compile_options, svelte_preprocessors, } = await init_sveltekit_config(sveltekit_config ?? dir);
36
+ // TODO feels hacky
37
+ if (svelte_compile_options.generate === undefined) {
38
+ svelte_compile_options.generate = 'server';
39
+ }
36
40
  const { outbase, outdir, outname } = outpaths(dev);
37
41
  const server_outpath = join(outdir, outname);
38
42
  const timing_to_esbuild_create_context = timings.start('create build context');
@@ -33,7 +33,7 @@ export declare const get_possible_source_ids: (input_path: string, extensions: s
33
33
  * and stopping at the first match.
34
34
  * Parameterized by `exists` and `stat` so it's fs-agnostic.
35
35
  */
36
- export declare const load_source_path_data_by_input_path: (input_paths: string[], get_possible_source_ids_for_input_path?: ((input_path: string) => string[]) | undefined) => Promise<{
36
+ export declare const load_source_path_data_by_input_path: (input_paths: string[], get_possible_source_ids_for_input_path?: (input_path: string) => string[]) => Promise<{
37
37
  source_id_path_data_by_input_path: Map<string, Path_Data>;
38
38
  unmapped_input_paths: string[];
39
39
  }>;
package/dist/loader.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import * as esbuild from 'esbuild';
2
- import { compile, preprocess } from 'svelte/compiler';
2
+ import { compile, compileModule, preprocess } from 'svelte/compiler';
3
3
  import { fileURLToPath, pathToFileURL } from 'node:url';
4
- import { dirname, join, relative } from 'node:path';
4
+ import { dirname, join } from 'node:path';
5
5
  import { escape_regexp } from '@ryanatkn/belt/regexp.js';
6
6
  import { render_env_shim_module } from './sveltekit_shim_env.js';
7
7
  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
8
  import { init_sveltekit_config } from './sveltekit_config.js';
9
+ import { SVELTE_MATCHER, SVELTE_RUNES_MATCHER } from './svelte_helpers.js';
9
10
  import { paths, NODE_MODULES_DIRNAME } from './paths.js';
10
11
  import { to_define_import_meta_env, ts_transform_options } from './esbuild_helpers.js';
11
12
  import { resolve_specifier } from './resolve_specifier.js';
@@ -27,12 +28,13 @@ node --import 'data:text/javascript,import {register} from "node:module"; import
27
28
  TODO how to improve that gnarly import line? was originally designed for the now-deprecated `--loader`
28
29
 
29
30
  */
31
+ // TODO support `?raw` import variants
30
32
  // TODO sourcemaps for svelte and the svelte preprocessors
31
33
  // TODO `import.meta.resolve` wasn't available in loaders when this was first implemented, but might be now
32
34
  // dev is always true in the loader
33
35
  const dev = true;
34
36
  const dir = paths.root;
35
- const { alias, base_url, assets_url, env_dir, private_prefix, public_prefix, svelte_compile_options, svelte_preprocessors, } = await init_sveltekit_config(dir); // always load it to keep things simple ahead
37
+ const { alias, base_url, assets_url, env_dir, private_prefix, public_prefix, svelte_compile_options, svelte_compile_module_options, svelte_preprocessors, } = await init_sveltekit_config(dir); // always load it to keep things simple ahead
36
38
  const final_ts_transform_options = {
37
39
  ...ts_transform_options,
38
40
  define: to_define_import_meta_env(dev, base_url),
@@ -40,14 +42,14 @@ const final_ts_transform_options = {
40
42
  };
41
43
  const aliases = Object.entries({ $lib: 'src/lib', ...alias });
42
44
  const ts_matcher = /\.(ts|tsx|mts|cts)$/u;
43
- const svelte_matcher = /\.(svelte)$/u;
44
45
  const json_matcher = /\.(json)$/u;
46
+ const noop_matcher = /\.(css|svg)$/u; // TODO others? configurable?
45
47
  const env_matcher = /src\/lib\/\$env\/(static|dynamic)\/(public|private)$/u;
46
48
  const node_modules_matcher = new RegExp(escape_regexp('/' + NODE_MODULES_DIRNAME + '/'), 'u');
47
49
  const package_json_cache = {};
48
50
  export const load = async (url, context, nextLoad) => {
49
51
  if (sveltekit_shim_app_paths_matcher.test(url)) {
50
- // $app/paths shim
52
+ // SvelteKit `$app/paths` shim
51
53
  return {
52
54
  format: 'module',
53
55
  shortCircuit: true,
@@ -55,13 +57,22 @@ export const load = async (url, context, nextLoad) => {
55
57
  };
56
58
  }
57
59
  else if (sveltekit_shim_app_environment_matcher.test(url)) {
58
- // $app/environment shim
60
+ // SvelteKit `$app/environment` shim
59
61
  return {
60
62
  format: 'module',
61
63
  shortCircuit: true,
62
64
  source: render_sveltekit_shim_app_environment(dev),
63
65
  };
64
66
  }
67
+ else if (SVELTE_RUNES_MATCHER.test(url)) {
68
+ // Svelte runes in js/ts
69
+ // TODO support sourcemaps
70
+ const loaded = await nextLoad(url, context.format === 'module' ? context : { ...context, format: 'module' });
71
+ const filename = fileURLToPath(url);
72
+ const source = loaded.source.toString(); // eslint-disable-line @typescript-eslint/no-base-to-string
73
+ const transformed = compileModule(source, { ...svelte_compile_module_options, filename });
74
+ return { format: 'module', shortCircuit: true, source: transformed.js.code };
75
+ }
65
76
  else if (ts_matcher.test(url)) {
66
77
  // ts
67
78
  const loaded = await nextLoad(url, context.format === 'module' ? context : { ...context, format: 'module' });
@@ -69,18 +80,17 @@ export const load = async (url, context, nextLoad) => {
69
80
  { ...final_ts_transform_options, sourcefile: url });
70
81
  return { format: 'module', shortCircuit: true, source: transformed.code };
71
82
  }
72
- else if (svelte_matcher.test(url)) {
73
- // svelte
83
+ else if (SVELTE_MATCHER.test(url)) {
84
+ // Svelte
74
85
  // TODO support sourcemaps
75
86
  const loaded = await nextLoad(url, context.format === 'module' ? context : { ...context, format: 'module' });
87
+ const filename = fileURLToPath(url);
76
88
  const raw_source = loaded.source.toString(); // eslint-disable-line @typescript-eslint/no-base-to-string
77
89
  const preprocessed = svelte_preprocessors
78
- ? await preprocess(raw_source, svelte_preprocessors, {
79
- filename: relative(dir, fileURLToPath(url)),
80
- })
90
+ ? await preprocess(raw_source, svelte_preprocessors, { filename })
81
91
  : null;
82
92
  const source = preprocessed?.code ?? raw_source;
83
- const transformed = compile(source, svelte_compile_options);
93
+ const transformed = compile(source, { ...svelte_compile_options, filename });
84
94
  return { format: 'module', shortCircuit: true, source: transformed.js.code };
85
95
  }
86
96
  else if (json_matcher.test(url)) {
@@ -91,10 +101,15 @@ export const load = async (url, context, nextLoad) => {
91
101
  const source = `export default ` + raw_source;
92
102
  return { format: 'module', shortCircuit: true, source };
93
103
  }
104
+ else if (noop_matcher.test(url)) {
105
+ // no-ops like `.css` and `.svg`
106
+ const source = `export default 'no-op import from ${url}'`;
107
+ return { format: 'module', shortCircuit: true, source };
108
+ }
94
109
  else {
95
- // neither ts nor svelte
96
110
  const matched_env = env_matcher.exec(url);
97
111
  if (matched_env) {
112
+ // SvelteKit `$env`
98
113
  const mode = matched_env[1];
99
114
  const visibility = matched_env[2];
100
115
  return {
@@ -104,6 +119,7 @@ export const load = async (url, context, nextLoad) => {
104
119
  };
105
120
  }
106
121
  }
122
+ // fallback to default behavior
107
123
  return nextLoad(url, context);
108
124
  };
109
125
  export const resolve = async (specifier, context, nextResolve) => {
@@ -138,7 +154,7 @@ export const resolve = async (specifier, context, nextResolve) => {
138
154
  // The specifier `path` has now been mapped to its final form, so we can inspect it.
139
155
  if (path[0] !== '.' && path[0] !== '/') {
140
156
  // Resolve to `node_modules`.
141
- if (svelte_matcher.test(path) || json_matcher.test(path)) {
157
+ if (SVELTE_MATCHER.test(path) || json_matcher.test(path)) {
142
158
  // Match the behavior of Vite and esbuild for Svelte and JSON imports.
143
159
  // TODO maybe `.ts` too
144
160
  const source_id = await resolve_node_specifier(path, dir, parent_url, package_json_cache);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,41 @@
1
+ import { test } from 'uvu';
2
+ import * as assert from 'uvu/assert';
3
+ import { resolve } from 'node:path';
4
+ test('import js', async () => {
5
+ const imported = await import(resolve('src/fixtures/modules/some_test_ts.js'));
6
+ assert.ok(imported);
7
+ assert.is(imported.a, 'ok');
8
+ });
9
+ test('import ts', async () => {
10
+ const imported = await import(resolve('src/fixtures/modules/some_test_ts.ts'));
11
+ assert.ok(imported);
12
+ assert.is(imported.a, 'ok');
13
+ });
14
+ test('import json', async () => {
15
+ const imported = await import(resolve('src/fixtures/modules/some_test_json.json'));
16
+ assert.ok(imported);
17
+ assert.is(imported.default.a, 'ok');
18
+ });
19
+ test('import css as a no-op', async () => {
20
+ const imported = await import(resolve('src/fixtures/modules/some_test_css.css'));
21
+ assert.is(typeof imported.default, 'string');
22
+ assert.ok(imported);
23
+ });
24
+ test('import svelte', async () => {
25
+ const imported = await import(resolve('src/fixtures/modules/Some_Test_Svelte.svelte'));
26
+ assert.ok(imported);
27
+ assert.is(imported.a, 'ok');
28
+ });
29
+ test('import svelte.js', async () => {
30
+ const imported = await import(resolve('src/fixtures/modules/some_test_svelte_js.svelte.js'));
31
+ assert.ok(imported.Some_Test_Svelte_Js);
32
+ const instance = new imported.Some_Test_Svelte_Js();
33
+ assert.is(instance.a, 'ok');
34
+ });
35
+ test('import svelte.ts', async () => {
36
+ const imported = await import(resolve('src/fixtures/modules/some_test_svelte_ts.svelte.ts'));
37
+ assert.ok(imported.Some_Test_Svelte_Ts);
38
+ const instance = new imported.Some_Test_Svelte_Ts();
39
+ assert.is(instance.a, 'ok');
40
+ });
41
+ test.run();
package/dist/modules.d.ts CHANGED
@@ -20,7 +20,7 @@ export type Load_Module_Failure = {
20
20
  mod: Record<string, any>;
21
21
  validation: string;
22
22
  };
23
- export declare const load_module: <T extends Record<string, any>>(id: string, validate?: ((mod: Record<string, any>) => mod is T) | undefined) => Promise<Load_Module_Result<Module_Meta<T>>>;
23
+ export declare const load_module: <T extends Record<string, any>>(id: string, validate?: (mod: Record<string, any>) => mod is T) => Promise<Load_Module_Result<Module_Meta<T>>>;
24
24
  export type Find_Modules_Result = Result<{
25
25
  source_ids_by_input_path: Map<string, string[]>;
26
26
  source_id_path_data_by_input_path: Map<string, Path_Data>;
@@ -45,5 +45,5 @@ export type Load_Modules_Result<T_Module_Meta extends Module_Meta> = Result<{
45
45
  reasons: string[];
46
46
  modules: T_Module_Meta[];
47
47
  }>;
48
- export declare const find_modules: (input_paths: string[], custom_search_fs?: (dir: string, options?: import("./search_fs.js").Search_Fs_Options) => Promise<Map<string, import("./path.js").Path_Stats>>, get_possible_source_ids?: ((input_path: string) => string[]) | undefined, timings?: any) => Promise<Find_Modules_Result>;
49
- export declare const load_modules: <Module_Type extends Record<string, any>, T_Module_Meta extends Module_Meta<Module_Type>>(source_ids_by_input_path: Map<string, string[]>, load_module_by_id: (source_id: Flavored<string, "Source_Id">) => Promise<Load_Module_Result<T_Module_Meta>>, timings?: any) => Promise<Load_Modules_Result<T_Module_Meta>>;
48
+ export declare const find_modules: (input_paths: string[], custom_search_fs?: (dir: string, options?: import("./search_fs.js").Search_Fs_Options) => Promise<Map<string, import("./path.js").Path_Stats>>, get_possible_source_ids?: (input_path: string) => string[], timings?: any) => Promise<Find_Modules_Result>;
49
+ export declare const load_modules: <Module_Type extends Record<string, any>, T_Module_Meta extends Module_Meta<Module_Type>>(source_ids_by_input_path: Map<string, string[]>, load_module_by_id: (source_id: Source_Id) => Promise<Load_Module_Result<T_Module_Meta>>, timings?: any) => Promise<Load_Modules_Result<T_Module_Meta>>;
package/dist/package.d.ts CHANGED
@@ -55,6 +55,7 @@ export declare const package_json: {
55
55
  '@changesets/types': string;
56
56
  '@ryanatkn/eslint-config': string;
57
57
  '@ryanatkn/fuz': string;
58
+ '@ryanatkn/moss': string;
58
59
  '@sveltejs/adapter-static': string;
59
60
  '@sveltejs/kit': string;
60
61
  '@sveltejs/package': string;
@@ -341,6 +342,10 @@ export declare const package_json: {
341
342
  default: string;
342
343
  types: string;
343
344
  };
345
+ './svelte_helpers.js': {
346
+ default: string;
347
+ types: string;
348
+ };
344
349
  './sveltekit_config.js': {
345
350
  default: string;
346
351
  types: string;
@@ -840,6 +845,13 @@ export declare const src_json: {
840
845
  kind: string;
841
846
  }[];
842
847
  };
848
+ './svelte_helpers.js': {
849
+ path: string;
850
+ declarations: {
851
+ name: string;
852
+ kind: string;
853
+ }[];
854
+ };
843
855
  './sveltekit_config.js': {
844
856
  path: string;
845
857
  declarations: {
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.115.2',
4
+ version: '0.116.0',
5
5
  description: 'task runner and toolkit extending SvelteKit',
6
6
  motto: 'generate, run, optimize',
7
7
  icon: '🌰',
@@ -16,7 +16,7 @@ export const package_json = {
16
16
  type: 'module',
17
17
  engines: { node: '>=20.10' },
18
18
  scripts: {
19
- build: 'rm -rf .gro dist && svelte-package && chmod +x ./dist/gro.js && npm link -f',
19
+ build: 'rm -rf .gro dist && svelte-kit sync && svelte-package && chmod +x ./dist/gro.js && npm link -f',
20
20
  start: 'gro dev',
21
21
  test: 'gro test',
22
22
  },
@@ -36,36 +36,37 @@ export const package_json = {
36
36
  '@ryanatkn/belt': '^0.20.10',
37
37
  chokidar: '^3.6.0',
38
38
  dotenv: '^16.4.5',
39
- 'es-module-lexer': '^1.5.0',
39
+ 'es-module-lexer': '^1.5.3',
40
40
  kleur: '^4.1.5',
41
41
  mri: '^1.2.0',
42
42
  prettier: '^3.2.5',
43
- 'prettier-plugin-svelte': '^3.2.2',
43
+ 'prettier-plugin-svelte': '^3.2.3',
44
44
  'tiny-glob': '^0.2.9',
45
45
  'ts-morph': '^22.0.0',
46
46
  tslib: '^2.6.2',
47
- zod: '^3.22.4',
47
+ zod: '^3.23.8',
48
48
  },
49
- peerDependencies: { esbuild: '^0.19', svelte: '*' },
49
+ peerDependencies: { esbuild: '^0.20', svelte: '^5.0.0-next.0' },
50
50
  devDependencies: {
51
51
  '@changesets/changelog-git': '^0.2.0',
52
52
  '@changesets/types': '^6.0.0',
53
- '@ryanatkn/eslint-config': '^0.1.0',
54
- '@ryanatkn/fuz': '^0.92.0',
53
+ '@ryanatkn/eslint-config': '^0.1.2',
54
+ '@ryanatkn/fuz': '^0.101.2',
55
+ '@ryanatkn/moss': '^0.3.0',
55
56
  '@sveltejs/adapter-static': '^3.0.1',
56
- '@sveltejs/kit': '^2.5.4',
57
- '@sveltejs/package': '^2.3.0',
58
- '@sveltejs/vite-plugin-svelte': '^3.0.2',
57
+ '@sveltejs/kit': '^2.5.10',
58
+ '@sveltejs/package': '^2.3.1',
59
+ '@sveltejs/vite-plugin-svelte': '^3.1.0',
59
60
  '@types/fs-extra': '^11.0.4',
60
- '@types/node': '^20.11.30',
61
- '@typescript-eslint/eslint-plugin': '^7.4.0',
62
- '@typescript-eslint/parser': '^7.4.0',
63
- esbuild: '^0.19.0',
61
+ '@types/node': '^20.12.12',
62
+ '@typescript-eslint/eslint-plugin': '^7.10.0',
63
+ '@typescript-eslint/parser': '^7.10.0',
64
+ esbuild: '^0.20.2',
64
65
  eslint: '^8.57.0',
65
- 'eslint-plugin-svelte': '^2.35.1',
66
- svelte: '^4.2.12',
67
- 'svelte-check': '^3.6.8',
68
- typescript: '^5.4.3',
66
+ 'eslint-plugin-svelte': '^2.39.0',
67
+ svelte: '^5.0.0-next.141',
68
+ 'svelte-check': '^3.7.1',
69
+ typescript: '^5.4.5',
69
70
  uvu: '^0.5.6',
70
71
  },
71
72
  eslintConfig: { root: true, extends: '@ryanatkn', rules: { 'no-console': 1 } },
@@ -189,6 +190,10 @@ export const package_json = {
189
190
  './run.task.js': { default: './dist/run.task.js', types: './dist/run.task.d.ts' },
190
191
  './search_fs.js': { default: './dist/search_fs.js', types: './dist/search_fs.d.ts' },
191
192
  './src_json.js': { default: './dist/src_json.js', types: './dist/src_json.d.ts' },
193
+ './svelte_helpers.js': {
194
+ default: './dist/svelte_helpers.js',
195
+ types: './dist/svelte_helpers.d.ts',
196
+ },
192
197
  './sveltekit_config.js': {
193
198
  default: './dist/sveltekit_config.js',
194
199
  types: './dist/sveltekit_config.d.ts',
@@ -236,7 +241,7 @@ export const package_json = {
236
241
  };
237
242
  export const src_json = {
238
243
  name: '@ryanatkn/gro',
239
- version: '0.115.2',
244
+ version: '0.116.0',
240
245
  modules: {
241
246
  '.': {
242
247
  path: 'index.ts',
@@ -778,6 +783,13 @@ export const src_json = {
778
783
  { name: 'to_src_modules', kind: 'function' },
779
784
  ],
780
785
  },
786
+ './svelte_helpers.js': {
787
+ path: 'svelte_helpers.ts',
788
+ declarations: [
789
+ { name: 'SVELTE_MATCHER', kind: 'variable' },
790
+ { name: 'SVELTE_RUNES_MATCHER', kind: 'variable' },
791
+ ],
792
+ },
781
793
  './sveltekit_config.js': {
782
794
  path: 'sveltekit_config.ts',
783
795
  declarations: [
@@ -10,7 +10,10 @@ export declare const Args: z.ZodObject<{
10
10
  'no-check': z.ZodDefault<z.ZodBoolean>;
11
11
  install: z.ZodDefault<z.ZodBoolean>;
12
12
  'no-install': z.ZodDefault<z.ZodBoolean>;
13
+ build: z.ZodDefault<z.ZodBoolean>;
14
+ 'no-build': z.ZodDefault<z.ZodBoolean>;
13
15
  }, "strict", z.ZodTypeAny, {
16
+ build: boolean;
14
17
  install: boolean;
15
18
  origin: string & z.BRAND<"Git_Origin">;
16
19
  branch: string & z.BRAND<"Git_Branch">;
@@ -18,18 +21,21 @@ export declare const Args: z.ZodObject<{
18
21
  'no-install': boolean;
19
22
  check: boolean;
20
23
  dry: boolean;
24
+ 'no-build': boolean;
21
25
  preserve_changelog: boolean;
22
26
  'no-check': boolean;
23
27
  }, {
24
- branch?: string | undefined;
28
+ build?: boolean | undefined;
29
+ install?: boolean | undefined;
25
30
  origin?: string | undefined;
31
+ branch?: string | undefined;
26
32
  changelog?: string | undefined;
27
- preserve_changelog?: boolean | undefined;
28
- dry?: boolean | undefined;
33
+ 'no-install'?: boolean | undefined;
29
34
  check?: boolean | undefined;
35
+ dry?: boolean | undefined;
36
+ 'no-build'?: boolean | undefined;
37
+ preserve_changelog?: boolean | undefined;
30
38
  'no-check'?: boolean | undefined;
31
- install?: boolean | undefined;
32
- 'no-install'?: boolean | undefined;
33
39
  }>;
34
40
  export type Args = z.infer<typeof Args>;
35
41
  export declare const task: Task<Args>;
@@ -39,13 +39,15 @@ export const Args = z
39
39
  'no-install': z
40
40
  .boolean({ description: 'opt out of npm installing before building' })
41
41
  .default(false),
42
+ build: z.boolean({ description: 'dual of no-build' }).default(true),
43
+ 'no-build': z.boolean({ description: 'opt out of building' }).default(false),
42
44
  })
43
45
  .strict();
44
46
  export const task = {
45
47
  summary: 'bump version, publish to npm, and git push',
46
48
  Args,
47
49
  run: async ({ args, log, invoke_task }) => {
48
- const { branch, changelog, preserve_changelog, dry, check, install, origin } = args;
50
+ const { branch, origin, changelog, preserve_changelog, dry, check, install, build } = args;
49
51
  if (dry) {
50
52
  log.info(green('dry run!'));
51
53
  }
@@ -106,8 +108,9 @@ export const task = {
106
108
  throw new Task_Error('changeset version failed: are there any changes?');
107
109
  }
108
110
  }
109
- // Build to create the final artifacts:
110
- await invoke_task('build', { install });
111
+ if (build) {
112
+ await invoke_task('build', { install });
113
+ }
111
114
  if (dry) {
112
115
  log.info('publishing branch ' + branch);
113
116
  log.info(green('dry run complete!'));
@@ -31,7 +31,11 @@ test__search_fs('basic behavior', async () => {
31
31
  'some_test_exports.ts',
32
32
  'modules/some_test_ts.ts',
33
33
  'modules/Some_Test_Svelte.svelte',
34
+ 'modules/some_test_svelte_ts.svelte.ts',
35
+ 'modules/some_test_svelte_js.svelte.js',
36
+ 'modules/some_test_server.ts',
34
37
  'modules/some_test_json.json',
38
+ 'modules/some_test_js.js',
35
39
  'modules/some_test_css.css',
36
40
  'changelog_example.md',
37
41
  'changelog_cache.json',
@@ -26,26 +26,12 @@ test('to_package_modules', async () => {
26
26
  './fixtures/modules/some_test_ts.js': {
27
27
  path: 'fixtures/modules/some_test_ts.ts',
28
28
  declarations: [
29
- {
30
- name: 'some_test_ts',
31
- kind: 'variable',
32
- },
33
- {
34
- name: 'some_test_fn',
35
- kind: 'function',
36
- },
37
- {
38
- name: 'Some_Test_Type',
39
- kind: 'type',
40
- },
41
- {
42
- name: 'Some_Test_Interface',
43
- kind: 'type',
44
- },
45
- {
46
- name: 'Some_Test_Class',
47
- kind: 'class',
48
- },
29
+ { name: 'a', kind: 'variable' },
30
+ { name: 'some_test_ts', kind: 'variable' },
31
+ { name: 'some_test_fn', kind: 'function' },
32
+ { name: 'Some_Test_Type', kind: 'type' },
33
+ { name: 'Some_Test_Interface', kind: 'type' },
34
+ { name: 'Some_Test_Class', kind: 'class' },
49
35
  ],
50
36
  },
51
37
  });
@@ -0,0 +1,2 @@
1
+ export declare const SVELTE_MATCHER: RegExp;
2
+ export declare const SVELTE_RUNES_MATCHER: RegExp;
@@ -0,0 +1,2 @@
1
+ export const SVELTE_MATCHER = /\.svelte$/u;
2
+ export const SVELTE_RUNES_MATCHER = /\.svelte\.(js|ts)$/u; // TODO probably let `.svelte.` appear anywhere - https://github.com/sveltejs/svelte/issues/11536
@@ -1,6 +1,6 @@
1
1
  /// <reference types="svelte" />
2
2
  import type { Config as SveltekitConfig } from '@sveltejs/kit';
3
- import type { CompileOptions, PreprocessorGroup } from 'svelte/compiler';
3
+ import type { CompileOptions, PreprocessorGroup, ModuleCompileOptions } from 'svelte/compiler';
4
4
  /**
5
5
  * Loads a SvelteKit config at `dir`.
6
6
  * @returns
@@ -25,7 +25,8 @@ export interface Parsed_Sveltekit_Config {
25
25
  env_dir: string | undefined;
26
26
  private_prefix: string | undefined;
27
27
  public_prefix: string | undefined;
28
- svelte_compile_options: CompileOptions | undefined;
28
+ svelte_compile_options: CompileOptions;
29
+ svelte_compile_module_options: ModuleCompileOptions;
29
30
  svelte_preprocessors: PreprocessorGroup | PreprocessorGroup[] | undefined;
30
31
  }
31
32
  /**
@@ -32,7 +32,8 @@ export const init_sveltekit_config = async (dir_or_config = cwd()) => {
32
32
  const env_dir = kit?.env?.dir;
33
33
  const private_prefix = kit?.env?.privatePrefix;
34
34
  const public_prefix = kit?.env?.publicPrefix;
35
- const svelte_compile_options = sveltekit_config?.compilerOptions;
35
+ const svelte_compile_options = sveltekit_config?.compilerOptions ?? {};
36
+ const svelte_compile_module_options = {}; // TODO from `kit`? or subset of `svelte_compile_options`?
36
37
  const svelte_preprocessors = sveltekit_config?.preprocess;
37
38
  return {
38
39
  sveltekit_config,
@@ -46,6 +47,7 @@ export const init_sveltekit_config = async (dir_or_config = cwd()) => {
46
47
  private_prefix,
47
48
  public_prefix,
48
49
  svelte_compile_options,
50
+ svelte_compile_module_options,
49
51
  svelte_preprocessors,
50
52
  };
51
53
  };
@@ -17,13 +17,13 @@ export declare const Args: z.ZodObject<{
17
17
  'no-package_json': boolean;
18
18
  'no-sveltekit': boolean;
19
19
  }, {
20
- sveltekit?: boolean | undefined;
21
- 'no-sveltekit'?: boolean | undefined;
22
20
  package_json?: boolean | undefined;
23
- 'no-package_json'?: boolean | undefined;
21
+ sveltekit?: boolean | undefined;
22
+ install?: boolean | undefined;
24
23
  gen?: boolean | undefined;
25
24
  'no-gen'?: boolean | undefined;
26
- install?: boolean | undefined;
25
+ 'no-package_json'?: boolean | undefined;
26
+ 'no-sveltekit'?: boolean | undefined;
27
27
  }>;
28
28
  export type Args = z.infer<typeof Args>;
29
29
  export declare const task: Task<Args>;
package/dist/sync.task.js CHANGED
@@ -36,7 +36,7 @@ export const task = {
36
36
  };
37
37
  export const sveltekit_sync = async () => {
38
38
  if (!(await find_cli('svelte-kit'))) {
39
- return;
39
+ throw new Task_Error('failed to find svelte-kit CLI - do you need to run `npm i`?');
40
40
  }
41
41
  const result = await spawn_cli('svelte-kit', ['sync']);
42
42
  if (!result?.ok) {
@@ -12,9 +12,9 @@ export declare const Args: z.ZodObject<{
12
12
  ignore?: string | string[] | undefined;
13
13
  }, {
14
14
  _?: string[] | undefined;
15
- bail?: boolean | undefined;
16
15
  cwd?: string | undefined;
17
16
  ignore?: string | string[] | undefined;
17
+ bail?: boolean | undefined;
18
18
  }>;
19
19
  export type Args = z.infer<typeof Args>;
20
20
  export declare const task: Task<Args>;
@@ -17,10 +17,10 @@ export declare const Args: z.ZodObject<{
17
17
  }, {
18
18
  _?: string[] | undefined;
19
19
  origin?: string | undefined;
20
- force?: boolean | undefined;
21
20
  pull?: boolean | undefined;
22
- 'no-pull'?: boolean | undefined;
23
21
  dry?: boolean | undefined;
22
+ force?: boolean | undefined;
23
+ 'no-pull'?: boolean | undefined;
24
24
  }>;
25
25
  export type Args = z.infer<typeof Args>;
26
26
  export declare const task: Task<Args>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ryanatkn/gro",
3
- "version": "0.115.2",
3
+ "version": "0.116.0",
4
4
  "description": "task runner and toolkit extending SvelteKit",
5
5
  "motto": "generate, run, optimize",
6
6
  "icon": "🌰",
@@ -26,7 +26,7 @@
26
26
  "node": ">=20.10"
27
27
  },
28
28
  "scripts": {
29
- "build": "rm -rf .gro dist && svelte-package && chmod +x ./dist/gro.js && npm link -f",
29
+ "build": "rm -rf .gro dist && svelte-kit sync && svelte-package && chmod +x ./dist/gro.js && npm link -f",
30
30
  "start": "gro dev",
31
31
  "test": "gro test"
32
32
  },
@@ -48,39 +48,40 @@
48
48
  "@ryanatkn/belt": "^0.20.10",
49
49
  "chokidar": "^3.6.0",
50
50
  "dotenv": "^16.4.5",
51
- "es-module-lexer": "^1.5.0",
51
+ "es-module-lexer": "^1.5.3",
52
52
  "kleur": "^4.1.5",
53
53
  "mri": "^1.2.0",
54
54
  "prettier": "^3.2.5",
55
- "prettier-plugin-svelte": "^3.2.2",
55
+ "prettier-plugin-svelte": "^3.2.3",
56
56
  "tiny-glob": "^0.2.9",
57
57
  "ts-morph": "^22.0.0",
58
58
  "tslib": "^2.6.2",
59
- "zod": "^3.22.4"
59
+ "zod": "^3.23.8"
60
60
  },
61
61
  "peerDependencies": {
62
- "esbuild": "^0.19",
63
- "svelte": "*"
62
+ "esbuild": "^0.20",
63
+ "svelte": "^5.0.0-next.0"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@changesets/changelog-git": "^0.2.0",
67
67
  "@changesets/types": "^6.0.0",
68
- "@ryanatkn/eslint-config": "^0.1.0",
69
- "@ryanatkn/fuz": "^0.92.0",
68
+ "@ryanatkn/eslint-config": "^0.1.2",
69
+ "@ryanatkn/fuz": "^0.101.2",
70
+ "@ryanatkn/moss": "^0.3.0",
70
71
  "@sveltejs/adapter-static": "^3.0.1",
71
- "@sveltejs/kit": "^2.5.4",
72
- "@sveltejs/package": "^2.3.0",
73
- "@sveltejs/vite-plugin-svelte": "^3.0.2",
72
+ "@sveltejs/kit": "^2.5.10",
73
+ "@sveltejs/package": "^2.3.1",
74
+ "@sveltejs/vite-plugin-svelte": "^3.1.0",
74
75
  "@types/fs-extra": "^11.0.4",
75
- "@types/node": "^20.11.30",
76
- "@typescript-eslint/eslint-plugin": "^7.4.0",
77
- "@typescript-eslint/parser": "^7.4.0",
78
- "esbuild": "^0.19.0",
76
+ "@types/node": "^20.12.12",
77
+ "@typescript-eslint/eslint-plugin": "^7.10.0",
78
+ "@typescript-eslint/parser": "^7.10.0",
79
+ "esbuild": "^0.20.2",
79
80
  "eslint": "^8.57.0",
80
- "eslint-plugin-svelte": "^2.35.1",
81
- "svelte": "^4.2.12",
82
- "svelte-check": "^3.6.8",
83
- "typescript": "^5.4.3",
81
+ "eslint-plugin-svelte": "^2.39.0",
82
+ "svelte": "^5.0.0-next.141",
83
+ "svelte-check": "^3.7.1",
84
+ "typescript": "^5.4.5",
84
85
  "uvu": "^0.5.6"
85
86
  },
86
87
  "eslintConfig": {
@@ -357,6 +358,10 @@
357
358
  "default": "./dist/src_json.js",
358
359
  "types": "./dist/src_json.d.ts"
359
360
  },
361
+ "./svelte_helpers.js": {
362
+ "default": "./dist/svelte_helpers.js",
363
+ "types": "./dist/svelte_helpers.d.ts"
364
+ },
360
365
  "./sveltekit_config.js": {
361
366
  "default": "./dist/sveltekit_config.js",
362
367
  "types": "./dist/sveltekit_config.d.ts"