@ryanatkn/gro 0.133.2 → 0.133.3
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/build.task.d.ts +6 -0
- package/dist/build.task.d.ts.map +1 -1
- package/dist/build.task.js +6 -3
- package/dist/check.task.d.ts +2 -2
- package/dist/dev.task.d.ts +2 -2
- package/dist/esbuild_helpers.d.ts +1 -1
- package/dist/esbuild_helpers.d.ts.map +1 -1
- package/dist/esbuild_helpers.js +1 -1
- package/dist/esbuild_plugin_external_worker.d.ts +2 -2
- package/dist/esbuild_plugin_external_worker.d.ts.map +1 -1
- package/dist/esbuild_plugin_external_worker.js +3 -1
- package/dist/esbuild_plugin_svelte.d.ts +7 -2
- package/dist/esbuild_plugin_svelte.d.ts.map +1 -1
- package/dist/esbuild_plugin_svelte.js +20 -9
- package/dist/esbuild_plugin_sveltekit_local_imports.d.ts.map +1 -1
- package/dist/esbuild_plugin_sveltekit_local_imports.js +3 -2
- package/dist/esbuild_plugin_sveltekit_shim_app.d.ts.map +1 -1
- package/dist/esbuild_plugin_sveltekit_shim_app.js +3 -2
- package/dist/esbuild_plugin_sveltekit_shim_env.d.ts.map +1 -1
- package/dist/esbuild_plugin_sveltekit_shim_env.js +6 -5
- package/dist/gro_plugin_server.d.ts.map +1 -1
- package/dist/gro_plugin_server.js +4 -10
- package/dist/gro_plugin_sveltekit_app.js +2 -2
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +14 -14
- package/dist/package.d.ts +0 -11
- package/dist/package.d.ts.map +1 -1
- package/dist/package.js +9 -11
- package/dist/path_constants.d.ts +3 -0
- package/dist/path_constants.d.ts.map +1 -1
- package/dist/path_constants.js +3 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +3 -3
- package/dist/run_gen.js +2 -2
- package/dist/run_task.js +2 -2
- package/dist/sveltekit_config.d.ts +7 -2
- package/dist/sveltekit_config.d.ts.map +1 -1
- package/dist/sveltekit_config.js +11 -1
- package/dist/sveltekit_helpers.d.ts +2 -1
- package/dist/sveltekit_helpers.d.ts.map +1 -1
- package/dist/sveltekit_helpers.js +3 -2
- package/dist/task_logging.js +2 -4
- package/package.json +1 -5
- package/src/lib/build.task.ts +6 -3
- package/src/lib/esbuild_helpers.ts +1 -1
- package/src/lib/esbuild_plugin_external_worker.ts +4 -2
- package/src/lib/esbuild_plugin_svelte.ts +38 -11
- package/src/lib/esbuild_plugin_sveltekit_local_imports.ts +16 -9
- package/src/lib/esbuild_plugin_sveltekit_shim_app.ts +3 -2
- package/src/lib/esbuild_plugin_sveltekit_shim_env.ts +7 -5
- package/src/lib/gro_plugin_server.ts +4 -11
- package/src/lib/gro_plugin_sveltekit_app.ts +2 -2
- package/src/lib/loader.ts +14 -16
- package/src/lib/package.ts +9 -11
- package/src/lib/path_constants.ts +4 -0
- package/src/lib/paths.ts +3 -3
- package/src/lib/run_gen.ts +2 -2
- package/src/lib/run_task.ts +2 -2
- package/src/lib/sveltekit_config.ts +21 -4
- package/src/lib/sveltekit_helpers.ts +4 -3
- package/src/lib/task_logging.ts +4 -6
- package/dist/sveltekit_config_global.d.ts +0 -5
- package/dist/sveltekit_config_global.d.ts.map +0 -1
- package/dist/sveltekit_config_global.js +0 -5
- package/src/lib/sveltekit_config_global.ts +0 -6
package/dist/paths.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.d.ts","sourceRoot":"../src/lib/","sources":["paths.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AASvC,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"../src/lib/","sources":["paths.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AASvC,eAAO,MAAM,WAAW,QAA8C,CAAC;AACvE,eAAO,MAAM,QAAQ,QAA2B,CAAC;AACjD,eAAO,MAAM,OAAO,QAAiB,CAAC;AACtC,eAAO,MAAM,cAAc,QAAiD,CAAC;AAE7E,MAAM,WAAW,KAAK;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,YAAY,aAAc,MAAM,KAAG,KAW/C,CAAC;AAEF,eAAO,MAAM,WAAW,OAAQ,OAAO,KAAG,KAA4C,CAAC;AACvF,eAAO,MAAM,SAAS,OAAQ,OAAO,KAAG,OAAwD,CAAC;AAGjG,eAAO,MAAM,YAAY,OAAQ,OAAO,gBAAwB,MACnC,CAAC;AAG9B,eAAO,MAAM,oBAAoB,YAAa,OAAO,gBAA6B,MACtD,CAAC;AAI7B,eAAO,MAAM,oBAAoB,cAAe,MAAM,gBAA+B,OAC3D,CAAC;AAE3B,eAAO,MAAM,UAAU,SAAU,MAAM,gBAA0B,MAMhE,CAAC;AAEF,eAAO,MAAM,iBAAiB,SAAU,MAAM,iBAAiB,MAAM,KAAG,MAGvE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,KAAK,OAA8B,CAAC;AAEjD,eAAO,MAAM,eAAe,SAAS,CAAC;AAYtC,eAAO,MAAM,WAAW,SAAsC,CAAC;AAC/D;;GAEG;AACH,eAAO,MAAM,SAAS,OAA2D,CAAC;AAClF,eAAO,MAAM,YAAY,QAAgD,CAAC"}
|
package/dist/paths.js
CHANGED
|
@@ -3,17 +3,17 @@ import { fileURLToPath } from 'node:url';
|
|
|
3
3
|
import { strip_end } from '@ryanatkn/belt/string.js';
|
|
4
4
|
import { gray } from '@ryanatkn/belt/styletext.js';
|
|
5
5
|
import { GRO_CONFIG_PATH, GRO_DEV_DIR, GRO_DIR, SOURCE_DIR, SVELTEKIT_DIST_DIRNAME, } from './path_constants.js';
|
|
6
|
-
import {
|
|
6
|
+
import { default_sveltekit_config } from './sveltekit_config.js';
|
|
7
7
|
/*
|
|
8
8
|
|
|
9
9
|
A path `id` is an absolute path to the source/.gro/dist directory.
|
|
10
10
|
It's the same name that Rollup uses.
|
|
11
11
|
|
|
12
12
|
*/
|
|
13
|
-
export const LIB_DIRNAME = basename(
|
|
13
|
+
export const LIB_DIRNAME = basename(default_sveltekit_config.lib_path);
|
|
14
14
|
export const LIB_PATH = SOURCE_DIR + LIB_DIRNAME;
|
|
15
15
|
export const LIB_DIR = LIB_PATH + '/';
|
|
16
|
-
export const ROUTES_DIRNAME = basename(
|
|
16
|
+
export const ROUTES_DIRNAME = basename(default_sveltekit_config.routes_path);
|
|
17
17
|
export const create_paths = (root_dir) => {
|
|
18
18
|
// TODO remove reliance on trailing slash towards windows support
|
|
19
19
|
const root = strip_end(root_dir, '/') + '/';
|
package/dist/run_gen.js
CHANGED
|
@@ -2,7 +2,7 @@ import { red } from '@ryanatkn/belt/styletext.js';
|
|
|
2
2
|
import { print_error } from '@ryanatkn/belt/print.js';
|
|
3
3
|
import { to_gen_result, } from './gen.js';
|
|
4
4
|
import { print_path } from './paths.js';
|
|
5
|
-
import {
|
|
5
|
+
import { default_sveltekit_config } from './sveltekit_config.js';
|
|
6
6
|
export const GEN_NO_PROD_MESSAGE = 'gen runs only during development';
|
|
7
7
|
export const run_gen = async (gen_modules, config, log, timings, format_file) => {
|
|
8
8
|
let input_count = 0;
|
|
@@ -15,7 +15,7 @@ export const run_gen = async (gen_modules, config, log, timings, format_file) =>
|
|
|
15
15
|
// Perform code generation by calling `gen` on the module.
|
|
16
16
|
const gen_ctx = {
|
|
17
17
|
config,
|
|
18
|
-
sveltekit_config:
|
|
18
|
+
sveltekit_config: default_sveltekit_config,
|
|
19
19
|
origin_id: id,
|
|
20
20
|
log,
|
|
21
21
|
};
|
package/dist/run_task.js
CHANGED
|
@@ -3,7 +3,7 @@ import { print_log_label, System_Logger } from '@ryanatkn/belt/log.js';
|
|
|
3
3
|
import { parse_args } from './args.js';
|
|
4
4
|
import { log_task_help } from './task_logging.js';
|
|
5
5
|
import { Task_Error } from './task.js';
|
|
6
|
-
import {
|
|
6
|
+
import { default_sveltekit_config } from './sveltekit_config.js';
|
|
7
7
|
export const run_task = async (task_meta, unparsed_args, invoke_task, config, timings) => {
|
|
8
8
|
const { task } = task_meta.mod;
|
|
9
9
|
const log = new System_Logger(print_log_label(task_meta.name));
|
|
@@ -27,7 +27,7 @@ export const run_task = async (task_meta, unparsed_args, invoke_task, config, ti
|
|
|
27
27
|
output = await task.run({
|
|
28
28
|
args,
|
|
29
29
|
config,
|
|
30
|
-
sveltekit_config:
|
|
30
|
+
sveltekit_config: default_sveltekit_config,
|
|
31
31
|
log,
|
|
32
32
|
timings,
|
|
33
33
|
invoke_task: (invoked_task_name, invoked_args, invoked_config) => invoke_task(invoked_task_name, invoked_args, invoked_config ?? config, timings),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Config as SveltekitConfig } from '@sveltejs/kit';
|
|
2
|
-
import type { CompileOptions,
|
|
2
|
+
import type { CompileOptions, ModuleCompileOptions, PreprocessorGroup } from 'svelte/compiler';
|
|
3
3
|
/**
|
|
4
4
|
* Loads a SvelteKit config at `dir`.
|
|
5
5
|
* @returns `null` if no config is found
|
|
@@ -34,7 +34,7 @@ export interface Parsed_Sveltekit_Config {
|
|
|
34
34
|
private_prefix: string | undefined;
|
|
35
35
|
public_prefix: string | undefined;
|
|
36
36
|
svelte_compile_options: CompileOptions;
|
|
37
|
-
svelte_compile_module_options:
|
|
37
|
+
svelte_compile_module_options: CompileOptions;
|
|
38
38
|
svelte_preprocessors: PreprocessorGroup | PreprocessorGroup[] | undefined;
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
@@ -43,4 +43,9 @@ export interface Parsed_Sveltekit_Config {
|
|
|
43
43
|
* Needed because SvelteKit doesn't expose its config resolver.
|
|
44
44
|
*/
|
|
45
45
|
export declare const init_sveltekit_config: (dir_or_config?: string | SveltekitConfig) => Promise<Parsed_Sveltekit_Config>;
|
|
46
|
+
export declare const to_default_compile_module_options: ({ dev, generate, filename, rootDir, }: CompileOptions) => ModuleCompileOptions;
|
|
47
|
+
/**
|
|
48
|
+
* The parsed SvelteKit config for the cwd, cached globally at the module level.
|
|
49
|
+
*/
|
|
50
|
+
export declare const default_sveltekit_config: Parsed_Sveltekit_Config;
|
|
46
51
|
//# sourceMappingURL=sveltekit_config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sveltekit_config.d.ts","sourceRoot":"../src/lib/","sources":["sveltekit_config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,IAAI,eAAe,EAAC,MAAM,eAAe,CAAC;AAC7D,OAAO,KAAK,EAAC,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"sveltekit_config.d.ts","sourceRoot":"../src/lib/","sources":["sveltekit_config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,IAAI,eAAe,EAAC,MAAM,eAAe,CAAC;AAC7D,OAAO,KAAK,EAAC,cAAc,EAAE,oBAAoB,EAAE,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAW7F;;;GAGG;AACH,eAAO,MAAM,qBAAqB,SAC5B,MAAM,KACT,OAAO,CAAC,eAAe,GAAG,IAAI,CAMhC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,WAAW,uBAAuB;IAEvC,gBAAgB,EAAE,eAAe,GAAG,IAAI,CAAC;IACzC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IAC1C,QAAQ,EAAE,EAAE,GAAG,IAAI,MAAM,EAAE,GAAG,SAAS,CAAC;IACxC,UAAU,EAAE,EAAE,GAAG,UAAU,MAAM,EAAE,GAAG,WAAW,MAAM,EAAE,GAAG,SAAS,CAAC;IAGtE;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,sBAAsB,EAAE,cAAc,CAAC;IACvC,6BAA6B,EAAE,cAAc,CAAC;IAC9C,oBAAoB,EAAE,iBAAiB,GAAG,iBAAiB,EAAE,GAAG,SAAS,CAAC;CAC1E;AAGD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,mBAClB,MAAM,GAAG,eAAe,KACrC,OAAO,CAAC,uBAAuB,CA2CjC,CAAC;AAEF,eAAO,MAAM,iCAAiC,0CAK3C,cAAc,KAAG,oBAA4D,CAAC;AAEjF;;GAEG;AACH,eAAO,MAAM,wBAAwB,yBAAgC,CAAC"}
|
package/dist/sveltekit_config.js
CHANGED
|
@@ -37,7 +37,12 @@ export const init_sveltekit_config = async (dir_or_config = process.cwd()) => {
|
|
|
37
37
|
const private_prefix = kit?.env?.privatePrefix;
|
|
38
38
|
const public_prefix = kit?.env?.publicPrefix;
|
|
39
39
|
const svelte_compile_options = sveltekit_config?.compilerOptions ?? {};
|
|
40
|
-
|
|
40
|
+
// Change the default to `generate: 'server'`,
|
|
41
|
+
// because SvelteKit handles the client in the normal cases.
|
|
42
|
+
if (svelte_compile_options.generate === undefined) {
|
|
43
|
+
svelte_compile_options.generate = 'server';
|
|
44
|
+
}
|
|
45
|
+
const svelte_compile_module_options = to_default_compile_module_options(svelte_compile_options); // TODO will kit have these separately?
|
|
41
46
|
const svelte_preprocessors = sveltekit_config?.preprocess;
|
|
42
47
|
return {
|
|
43
48
|
sveltekit_config,
|
|
@@ -55,3 +60,8 @@ export const init_sveltekit_config = async (dir_or_config = process.cwd()) => {
|
|
|
55
60
|
svelte_preprocessors,
|
|
56
61
|
};
|
|
57
62
|
};
|
|
63
|
+
export const to_default_compile_module_options = ({ dev, generate, filename, rootDir, }) => ({ dev, generate, filename, rootDir });
|
|
64
|
+
/**
|
|
65
|
+
* The parsed SvelteKit config for the cwd, cached globally at the module level.
|
|
66
|
+
*/
|
|
67
|
+
export const default_sveltekit_config = await init_sveltekit_config(); // always load it to keep things simple ahead
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { Result } from '@ryanatkn/belt/result.js';
|
|
2
2
|
import { Package_Json } from './package_json.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type Parsed_Sveltekit_Config } from './sveltekit_config.js';
|
|
4
4
|
import { type Cli } from './cli.js';
|
|
5
5
|
export declare const SVELTEKIT_CLI = "svelte-kit";
|
|
6
6
|
export declare const SVELTE_CHECK_CLI = "svelte-check";
|
|
7
7
|
export declare const SVELTE_PACKAGE_CLI = "svelte-package";
|
|
8
8
|
export declare const SVELTE_PACKAGE_DEP_NAME = "@sveltejs/package";
|
|
9
9
|
export declare const VITE_CLI = "vite";
|
|
10
|
+
export declare const SVELTEKIT_ENV_MATCHER: RegExp;
|
|
10
11
|
export declare const has_sveltekit_app: () => Result<object, {
|
|
11
12
|
message: string;
|
|
12
13
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sveltekit_helpers.d.ts","sourceRoot":"../src/lib/","sources":["sveltekit_helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAGrD,OAAO,EAAC,YAAY,EAAoB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"sveltekit_helpers.d.ts","sourceRoot":"../src/lib/","sources":["sveltekit_helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAGrD,OAAO,EAAC,YAAY,EAAoB,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAA2B,KAAK,uBAAuB,EAAC,MAAM,uBAAuB,CAAC;AAE7F,OAAO,EAAmC,KAAK,GAAG,EAAC,MAAM,UAAU,CAAC;AAGpE,eAAO,MAAM,aAAa,eAAe,CAAC;AAE1C,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AAE/C,eAAO,MAAM,kBAAkB,mBAAmB,CAAC;AACnD,eAAO,MAAM,uBAAuB,sBAAsB,CAAC;AAE3D,eAAO,MAAM,QAAQ,SAAS,CAAC;AAE/B,eAAO,MAAM,qBAAqB,QAAgD,CAAC;AAEnF,eAAO,MAAM,iBAAiB,QAAO,MAAM,CAAC,MAAM,EAAE;IAAC,OAAO,EAAE,MAAM,CAAA;CAAC,CAMpE,CAAC;AAEF,eAAO,MAAM,qBAAqB,kBAClB,YAAY,qBACT,uBAAuB,KACvC,MAAM,CAAC,MAAM,EAAE;IAAC,OAAO,EAAE,MAAM,CAAA;CAAC,CAqBlC,CAAC;AAEF,eAAO,MAAM,cAAc,mBACX,MAAM,GAAG,GAAG,KACzB,OAAO,CAAC,IAAI,CASd,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kCAAkC,mBAC/B,MAAM,GAAG,GAAG,KACzB,OAAO,CAAC,IAAI,CAUd,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACtC;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;OAEG;IACH,CAAC,CAAC,EAAE,OAAO,CAAC;IACZ;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,CAAC,CAAC,EAAE,MAAM,CAAC;IACX;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,CAAC,CAAC,EAAE,MAAM,CAAC;IACX;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;OAEG;IACH,CAAC,CAAC,EAAE,OAAO,CAAC;IACZ;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
import { Package_Json, load_package_json } from './package_json.js';
|
|
3
|
-
import {
|
|
3
|
+
import { default_sveltekit_config } from './sveltekit_config.js';
|
|
4
4
|
import { SVELTEKIT_CONFIG_FILENAME, SVELTEKIT_DEV_DIRNAME } from './path_constants.js';
|
|
5
5
|
import { find_cli, spawn_cli, to_cli_name } from './cli.js';
|
|
6
6
|
import { Task_Error } from './task.js';
|
|
@@ -9,6 +9,7 @@ export const SVELTE_CHECK_CLI = 'svelte-check';
|
|
|
9
9
|
export const SVELTE_PACKAGE_CLI = 'svelte-package';
|
|
10
10
|
export const SVELTE_PACKAGE_DEP_NAME = '@sveltejs/package';
|
|
11
11
|
export const VITE_CLI = 'vite';
|
|
12
|
+
export const SVELTEKIT_ENV_MATCHER = /^\$env\/(static|dynamic)\/(public|private)$/;
|
|
12
13
|
export const has_sveltekit_app = () => {
|
|
13
14
|
if (!existsSync(SVELTEKIT_CONFIG_FILENAME)) {
|
|
14
15
|
return { ok: false, message: `no SvelteKit config found at ${SVELTEKIT_CONFIG_FILENAME}` };
|
|
@@ -16,7 +17,7 @@ export const has_sveltekit_app = () => {
|
|
|
16
17
|
// TODO check for routes?
|
|
17
18
|
return { ok: true };
|
|
18
19
|
};
|
|
19
|
-
export const has_sveltekit_library = (package_json, sveltekit_config =
|
|
20
|
+
export const has_sveltekit_library = (package_json, sveltekit_config = default_sveltekit_config) => {
|
|
20
21
|
const has_sveltekit_app_result = has_sveltekit_app();
|
|
21
22
|
if (!has_sveltekit_app_result.ok) {
|
|
22
23
|
return has_sveltekit_app_result;
|
package/dist/task_logging.js
CHANGED
|
@@ -20,7 +20,7 @@ export const log_tasks = (log, loaded_tasks, log_intro = true) => {
|
|
|
20
20
|
const longest_task_name = to_max_length(modules, (m) => m.name);
|
|
21
21
|
for (const resolved_input_file of resolved_input_files) {
|
|
22
22
|
const meta = modules.find((m) => m.id === resolved_input_file.id);
|
|
23
|
-
logged.push('\n' + cyan(
|
|
23
|
+
logged.push('\n' + cyan(meta.name.padEnd(longest_task_name)), ' ', meta.mod.task.summary ?? '');
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
log[log_intro ? 'info' : 'plain'](logged.join('') + '\n');
|
|
@@ -43,7 +43,7 @@ export const log_task_help = (log, meta) => {
|
|
|
43
43
|
const longest_default = to_max_length(properties, (p) => print_value(p.schema.default));
|
|
44
44
|
for (const property of properties) {
|
|
45
45
|
const name = property.name === '_' ? ARGS_PROPERTY_NAME : property.name;
|
|
46
|
-
logged.push(`\n${green(
|
|
46
|
+
logged.push(`\n${green(name.padEnd(longest_task_name))} `, gray(property.schema.type.padEnd(longest_type)) + ' ', print_value(property.schema.default).padEnd(longest_default) + ' ', property.schema.description || '(no description available)');
|
|
47
47
|
}
|
|
48
48
|
if (!properties.length) {
|
|
49
49
|
logged.push('\n' + gray('this task has no args'));
|
|
@@ -71,8 +71,6 @@ const to_arg_properties = (def, meta) => {
|
|
|
71
71
|
}
|
|
72
72
|
return properties;
|
|
73
73
|
};
|
|
74
|
-
// quick n dirty padding logic
|
|
75
|
-
const pad = (s, n) => s + ' '.repeat(n - s.length);
|
|
76
74
|
const to_max_length = (items, toString) => items.reduce((max, m) => Math.max(toString(m).length, max), 0);
|
|
77
75
|
// The following Zod helpers only need to support single-depth schemas for CLI args,
|
|
78
76
|
// but there's generic recursion to handle things like `ZodOptional` and `ZodDefault`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ryanatkn/gro",
|
|
3
|
-
"version": "0.133.
|
|
3
|
+
"version": "0.133.3",
|
|
4
4
|
"description": "task runner and toolkit extending SvelteKit",
|
|
5
5
|
"motto": "generate, run, optimize",
|
|
6
6
|
"glyph": "🌰",
|
|
@@ -378,10 +378,6 @@
|
|
|
378
378
|
"types": "./dist/svelte_helpers.d.ts",
|
|
379
379
|
"default": "./dist/svelte_helpers.js"
|
|
380
380
|
},
|
|
381
|
-
"./sveltekit_config_global.js": {
|
|
382
|
-
"types": "./dist/sveltekit_config_global.d.ts",
|
|
383
|
-
"default": "./dist/sveltekit_config_global.js"
|
|
384
|
-
},
|
|
385
381
|
"./sveltekit_config.js": {
|
|
386
382
|
"types": "./dist/sveltekit_config.d.ts",
|
|
387
383
|
"default": "./dist/sveltekit_config.js"
|
package/src/lib/build.task.ts
CHANGED
|
@@ -6,6 +6,8 @@ import {clean_fs} from './clean_fs.js';
|
|
|
6
6
|
|
|
7
7
|
export const Args = z
|
|
8
8
|
.object({
|
|
9
|
+
sync: z.boolean({description: 'dual of no-sync'}).default(true),
|
|
10
|
+
'no-sync': z.boolean({description: 'opt out of gro sync'}).default(false),
|
|
9
11
|
install: z.boolean({description: 'dual of no-install'}).default(true),
|
|
10
12
|
'no-install': z // convenience, same as `gro build -- gro sync --no-install` but the latter takes precedence
|
|
11
13
|
.boolean({description: 'opt out of `npm install` before building'})
|
|
@@ -19,10 +21,11 @@ export const task: Task<Args> = {
|
|
|
19
21
|
Args,
|
|
20
22
|
run: async (ctx): Promise<void> => {
|
|
21
23
|
const {args, invoke_task} = ctx;
|
|
22
|
-
const {install} = args;
|
|
24
|
+
const {sync, install} = args;
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
if (sync) {
|
|
27
|
+
await invoke_task('sync', {install});
|
|
28
|
+
}
|
|
26
29
|
|
|
27
30
|
// TODO possibly detect if the git workspace is clean, and ask for confirmation if not,
|
|
28
31
|
// because we're not doing things like `gro gen` here because that's a dev/CI concern
|
|
@@ -41,7 +41,7 @@ export const to_define_import_meta_env = (
|
|
|
41
41
|
[import_meta_env + 'BASE_URL']: JSON.stringify(base_url || '/'), // eslint-disable-line @typescript-eslint/prefer-nullish-coalescing
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
export const
|
|
44
|
+
export const default_ts_transform_options: esbuild.TransformOptions = {
|
|
45
45
|
target: 'esnext',
|
|
46
46
|
format: 'esm',
|
|
47
47
|
loader: 'ts',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as esbuild from 'esbuild';
|
|
2
2
|
import type {Logger} from '@ryanatkn/belt/log.js';
|
|
3
3
|
import {basename} from 'node:path';
|
|
4
|
-
import type {CompileOptions,
|
|
4
|
+
import type {CompileOptions, ModuleCompileOptions, PreprocessorGroup} from 'svelte/compiler';
|
|
5
5
|
|
|
6
6
|
import {print_build_result, to_define_import_meta_env} from './esbuild_helpers.js';
|
|
7
7
|
import {resolve_specifier} from './resolve_specifier.js';
|
|
@@ -36,8 +36,8 @@ export const esbuild_plugin_external_worker = ({
|
|
|
36
36
|
build_options,
|
|
37
37
|
dir = process.cwd(),
|
|
38
38
|
svelte_compile_options,
|
|
39
|
-
svelte_preprocessors,
|
|
40
39
|
svelte_compile_module_options,
|
|
40
|
+
svelte_preprocessors,
|
|
41
41
|
alias,
|
|
42
42
|
base_url,
|
|
43
43
|
assets_url,
|
|
@@ -67,6 +67,8 @@ export const esbuild_plugin_external_worker = ({
|
|
|
67
67
|
}),
|
|
68
68
|
esbuild_plugin_sveltekit_shim_alias({dir, alias}),
|
|
69
69
|
esbuild_plugin_svelte({
|
|
70
|
+
dev,
|
|
71
|
+
base_url,
|
|
70
72
|
dir,
|
|
71
73
|
svelte_compile_options,
|
|
72
74
|
svelte_compile_module_options,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as esbuild from 'esbuild';
|
|
2
2
|
import {
|
|
3
3
|
compile,
|
|
4
4
|
compileModule,
|
|
@@ -11,21 +11,43 @@ import {readFile} from 'node:fs/promises';
|
|
|
11
11
|
import {relative} from 'node:path';
|
|
12
12
|
|
|
13
13
|
import {SVELTE_MATCHER, SVELTE_RUNES_MATCHER} from './svelte_helpers.js';
|
|
14
|
+
import {to_define_import_meta_env, default_ts_transform_options} from './esbuild_helpers.js';
|
|
15
|
+
import {
|
|
16
|
+
default_sveltekit_config,
|
|
17
|
+
to_default_compile_module_options,
|
|
18
|
+
type Parsed_Sveltekit_Config,
|
|
19
|
+
} from './sveltekit_config.js';
|
|
20
|
+
import {TS_MATCHER} from './path_constants.js';
|
|
14
21
|
|
|
15
22
|
export interface Options {
|
|
23
|
+
dev: boolean;
|
|
24
|
+
base_url: Parsed_Sveltekit_Config['base_url'];
|
|
16
25
|
dir?: string;
|
|
17
26
|
svelte_compile_options?: CompileOptions;
|
|
18
27
|
svelte_compile_module_options?: ModuleCompileOptions;
|
|
19
28
|
svelte_preprocessors?: PreprocessorGroup | PreprocessorGroup[];
|
|
29
|
+
ts_transform_options?: esbuild.TransformOptions;
|
|
30
|
+
is_ts?: (filename: string) => boolean;
|
|
20
31
|
}
|
|
21
32
|
|
|
22
|
-
export const esbuild_plugin_svelte = (options: Options
|
|
33
|
+
export const esbuild_plugin_svelte = (options: Options): esbuild.Plugin => {
|
|
23
34
|
const {
|
|
35
|
+
dev,
|
|
36
|
+
base_url,
|
|
24
37
|
dir = process.cwd(),
|
|
25
|
-
svelte_compile_options =
|
|
26
|
-
svelte_compile_module_options =
|
|
38
|
+
svelte_compile_options = default_sveltekit_config.svelte_compile_options,
|
|
39
|
+
svelte_compile_module_options = to_default_compile_module_options(svelte_compile_options),
|
|
27
40
|
svelte_preprocessors,
|
|
41
|
+
ts_transform_options = default_ts_transform_options,
|
|
42
|
+
is_ts = (f) => TS_MATCHER.test(f),
|
|
28
43
|
} = options;
|
|
44
|
+
|
|
45
|
+
const final_ts_transform_options: esbuild.TransformOptions = {
|
|
46
|
+
...ts_transform_options,
|
|
47
|
+
define: to_define_import_meta_env(dev, base_url),
|
|
48
|
+
sourcemap: 'inline',
|
|
49
|
+
};
|
|
50
|
+
|
|
29
51
|
return {
|
|
30
52
|
name: 'svelte',
|
|
31
53
|
setup: (build) => {
|
|
@@ -33,9 +55,17 @@ export const esbuild_plugin_svelte = (options: Options = {}): esbuild.Plugin =>
|
|
|
33
55
|
const source = await readFile(path, 'utf8');
|
|
34
56
|
try {
|
|
35
57
|
const filename = relative(dir, path);
|
|
36
|
-
const
|
|
37
|
-
|
|
58
|
+
const js_source = is_ts(filename)
|
|
59
|
+
? (
|
|
60
|
+
await esbuild.transform(source, {
|
|
61
|
+
...final_ts_transform_options,
|
|
62
|
+
sourcefile: filename,
|
|
63
|
+
})
|
|
64
|
+
).code // TODO @many use warnings? handle not-inline sourcemaps?
|
|
65
|
+
: source;
|
|
66
|
+
const {js, warnings} = compileModule(js_source, {
|
|
38
67
|
...svelte_compile_module_options,
|
|
68
|
+
filename,
|
|
39
69
|
});
|
|
40
70
|
const contents = js.code + '//# sourceMappingURL=' + js.map.toUrl();
|
|
41
71
|
return {
|
|
@@ -46,6 +76,7 @@ export const esbuild_plugin_svelte = (options: Options = {}): esbuild.Plugin =>
|
|
|
46
76
|
return {errors: [convert_svelte_message_to_esbuild(path, source, err)]};
|
|
47
77
|
}
|
|
48
78
|
});
|
|
79
|
+
|
|
49
80
|
build.onLoad({filter: SVELTE_MATCHER}, async ({path}) => {
|
|
50
81
|
let source = await readFile(path, 'utf8');
|
|
51
82
|
try {
|
|
@@ -53,12 +84,8 @@ export const esbuild_plugin_svelte = (options: Options = {}): esbuild.Plugin =>
|
|
|
53
84
|
const preprocessed = svelte_preprocessors
|
|
54
85
|
? await preprocess(source, svelte_preprocessors, {filename})
|
|
55
86
|
: null;
|
|
56
|
-
// TODO handle preprocessor sourcemaps, same as in loader - merge?
|
|
57
87
|
if (preprocessed?.code) source = preprocessed.code;
|
|
58
|
-
const {js, warnings} = compile(source, {
|
|
59
|
-
filename,
|
|
60
|
-
...svelte_compile_options,
|
|
61
|
-
});
|
|
88
|
+
const {js, warnings} = compile(source, {...svelte_compile_options, filename});
|
|
62
89
|
const contents = js.code + '//# sourceMappingURL=' + js.map.toUrl();
|
|
63
90
|
return {
|
|
64
91
|
contents,
|
|
@@ -3,6 +3,7 @@ import {readFile} from 'node:fs/promises';
|
|
|
3
3
|
import {dirname} from 'node:path';
|
|
4
4
|
|
|
5
5
|
import {resolve_specifier} from './resolve_specifier.js';
|
|
6
|
+
import {EVERYTHING_MATCHER} from './path_constants.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Adds support for imports to both `.ts` and `.js`,
|
|
@@ -18,14 +19,20 @@ export const esbuild_plugin_sveltekit_local_imports = (): esbuild.Plugin => ({
|
|
|
18
19
|
const {path_id, namespace} = resolve_specifier(path, dirname(importer));
|
|
19
20
|
return {path: path_id, namespace}; // `namespace` may be `undefined`, but esbuild needs the absolute path for json etc
|
|
20
21
|
});
|
|
21
|
-
build.onLoad(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
build.onLoad(
|
|
23
|
+
{filter: EVERYTHING_MATCHER, namespace: 'sveltekit_local_imports_ts'},
|
|
24
|
+
async ({path}) => ({
|
|
25
|
+
contents: await readFile(path),
|
|
26
|
+
loader: 'ts',
|
|
27
|
+
resolveDir: dirname(path),
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
build.onLoad(
|
|
31
|
+
{filter: EVERYTHING_MATCHER, namespace: 'sveltekit_local_imports_js'},
|
|
32
|
+
async ({path}) => ({
|
|
33
|
+
contents: await readFile(path),
|
|
34
|
+
resolveDir: dirname(path),
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
30
37
|
},
|
|
31
38
|
});
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
sveltekit_shim_app_specifiers,
|
|
7
7
|
} from './sveltekit_shim_app.js';
|
|
8
8
|
import type {Parsed_Sveltekit_Config} from './sveltekit_config.js';
|
|
9
|
+
import {EVERYTHING_MATCHER} from './path_constants.js';
|
|
9
10
|
|
|
10
11
|
export interface Options {
|
|
11
12
|
dev: boolean;
|
|
@@ -27,14 +28,14 @@ export const esbuild_plugin_sveltekit_shim_app = ({
|
|
|
27
28
|
path: sveltekit_shim_app_specifiers.get(path)!,
|
|
28
29
|
namespace: 'sveltekit_shim_app_paths',
|
|
29
30
|
}));
|
|
30
|
-
build.onLoad({filter:
|
|
31
|
+
build.onLoad({filter: EVERYTHING_MATCHER, namespace: 'sveltekit_shim_app_paths'}, () => ({
|
|
31
32
|
contents: render_sveltekit_shim_app_paths(base_url, assets_url),
|
|
32
33
|
}));
|
|
33
34
|
build.onResolve({filter: /^\$app\/environment$/}, ({path}) => ({
|
|
34
35
|
path: sveltekit_shim_app_specifiers.get(path)!,
|
|
35
36
|
namespace: 'sveltekit_shim_app_environment',
|
|
36
37
|
}));
|
|
37
|
-
build.onLoad({filter:
|
|
38
|
+
build.onLoad({filter: EVERYTHING_MATCHER, namespace: 'sveltekit_shim_app_environment'}, () => ({
|
|
38
39
|
contents: render_sveltekit_shim_app_environment(dev),
|
|
39
40
|
}));
|
|
40
41
|
},
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type * as esbuild from 'esbuild';
|
|
2
2
|
|
|
3
3
|
import {render_env_shim_module} from './sveltekit_shim_env.js';
|
|
4
|
+
import {EVERYTHING_MATCHER} from './path_constants.js';
|
|
5
|
+
import {SVELTEKIT_ENV_MATCHER} from './sveltekit_helpers.js';
|
|
4
6
|
|
|
5
7
|
export interface Options {
|
|
6
8
|
dev: boolean;
|
|
@@ -11,6 +13,8 @@ export interface Options {
|
|
|
11
13
|
ambient_env?: Record<string, string>;
|
|
12
14
|
}
|
|
13
15
|
|
|
16
|
+
const namespace = 'sveltekit_shim_env';
|
|
17
|
+
|
|
14
18
|
export const esbuild_plugin_sveltekit_shim_env = ({
|
|
15
19
|
dev,
|
|
16
20
|
public_prefix,
|
|
@@ -21,11 +25,9 @@ export const esbuild_plugin_sveltekit_shim_env = ({
|
|
|
21
25
|
}: Options): esbuild.Plugin => ({
|
|
22
26
|
name: 'sveltekit_shim_env',
|
|
23
27
|
setup: (build) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
build.onLoad({filter: /.*/, namespace}, ({path}) => {
|
|
28
|
-
const matches = filter.exec(path);
|
|
28
|
+
build.onResolve({filter: SVELTEKIT_ENV_MATCHER}, ({path}) => ({path, namespace}));
|
|
29
|
+
build.onLoad({filter: EVERYTHING_MATCHER, namespace}, ({path}) => {
|
|
30
|
+
const matches = SVELTEKIT_ENV_MATCHER.exec(path);
|
|
29
31
|
const mode = matches![1] as 'static' | 'dynamic';
|
|
30
32
|
const visibility = matches![2] as 'public' | 'private';
|
|
31
33
|
return {
|
|
@@ -12,7 +12,7 @@ import {base_path_to_path_id, LIB_DIRNAME, paths} from './paths.js';
|
|
|
12
12
|
import type {Path_Id} from './path.js';
|
|
13
13
|
import {GRO_DEV_DIRNAME, SERVER_DIST_PATH} from './path_constants.js';
|
|
14
14
|
import {watch_dir, type Watch_Node_Fs} from './watch_dir.js';
|
|
15
|
-
import {init_sveltekit_config} from './sveltekit_config.js';
|
|
15
|
+
import {init_sveltekit_config, default_sveltekit_config} from './sveltekit_config.js';
|
|
16
16
|
import {esbuild_plugin_sveltekit_shim_app} from './esbuild_plugin_sveltekit_shim_app.js';
|
|
17
17
|
import {esbuild_plugin_sveltekit_shim_env} from './esbuild_plugin_sveltekit_shim_env.js';
|
|
18
18
|
import {print_build_result, to_define_import_meta_env} from './esbuild_helpers.js';
|
|
@@ -21,7 +21,6 @@ import {esbuild_plugin_external_worker} from './esbuild_plugin_external_worker.j
|
|
|
21
21
|
import {esbuild_plugin_sveltekit_local_imports} from './esbuild_plugin_sveltekit_local_imports.js';
|
|
22
22
|
import {esbuild_plugin_svelte} from './esbuild_plugin_svelte.js';
|
|
23
23
|
import {throttle} from './throttle.js';
|
|
24
|
-
import {sveltekit_config_global} from './sveltekit_config_global.js';
|
|
25
24
|
|
|
26
25
|
// TODO sourcemap as a hoisted option? disable for production by default - or like `outpaths`, passed a `dev` param
|
|
27
26
|
|
|
@@ -133,7 +132,7 @@ export const gro_plugin_server = ({
|
|
|
133
132
|
setup: async ({dev, watch, timings, log}) => {
|
|
134
133
|
const parsed_sveltekit_config =
|
|
135
134
|
!sveltekit_config && strip_end(dir, '/') === process.cwd()
|
|
136
|
-
?
|
|
135
|
+
? default_sveltekit_config
|
|
137
136
|
: await init_sveltekit_config(sveltekit_config ?? dir);
|
|
138
137
|
const {
|
|
139
138
|
alias,
|
|
@@ -147,14 +146,6 @@ export const gro_plugin_server = ({
|
|
|
147
146
|
svelte_preprocessors,
|
|
148
147
|
} = parsed_sveltekit_config;
|
|
149
148
|
|
|
150
|
-
// TODO hacky
|
|
151
|
-
if (svelte_compile_options.generate === undefined) {
|
|
152
|
-
svelte_compile_options.generate = 'server';
|
|
153
|
-
}
|
|
154
|
-
if (svelte_compile_module_options.generate === undefined) {
|
|
155
|
-
svelte_compile_module_options.generate = 'server';
|
|
156
|
-
}
|
|
157
|
-
|
|
158
149
|
const {outbase, outdir, outname} = outpaths(dev);
|
|
159
150
|
|
|
160
151
|
const server_outpath = join(outdir, outname);
|
|
@@ -202,6 +193,8 @@ export const gro_plugin_server = ({
|
|
|
202
193
|
log,
|
|
203
194
|
}),
|
|
204
195
|
esbuild_plugin_svelte({
|
|
196
|
+
dev,
|
|
197
|
+
base_url,
|
|
205
198
|
dir,
|
|
206
199
|
svelte_compile_options,
|
|
207
200
|
svelte_compile_module_options,
|
|
@@ -9,7 +9,7 @@ import {Task_Error} from './task.js';
|
|
|
9
9
|
import {find_cli, spawn_cli, spawn_cli_process} from './cli.js';
|
|
10
10
|
import {type Map_Src_Json, serialize_src_json, create_src_json} from './src_json.js';
|
|
11
11
|
import {DEFAULT_EXPORTS_EXCLUDER} from './gro_config.js';
|
|
12
|
-
import {
|
|
12
|
+
import {default_sveltekit_config} from './sveltekit_config.js';
|
|
13
13
|
import {SOURCE_DIRNAME} from './path_constants.js';
|
|
14
14
|
import {VITE_CLI} from './sveltekit_helpers.js';
|
|
15
15
|
|
|
@@ -106,7 +106,7 @@ export const gro_plugin_sveltekit_app = ({
|
|
|
106
106
|
|
|
107
107
|
// copy files to `static` before building, in such a way
|
|
108
108
|
// that's non-destructive to existing files and dirs and easy to clean up
|
|
109
|
-
const {assets_path} =
|
|
109
|
+
const {assets_path} = default_sveltekit_config;
|
|
110
110
|
const cleanups: Cleanup[] = [
|
|
111
111
|
serialized_package_json
|
|
112
112
|
? create_temporarily(
|
package/src/lib/loader.ts
CHANGED
|
@@ -13,11 +13,11 @@ import {
|
|
|
13
13
|
SVELTEKIT_SHIM_APP_PATHS_MATCHER,
|
|
14
14
|
sveltekit_shim_app_specifiers,
|
|
15
15
|
} from './sveltekit_shim_app.js';
|
|
16
|
-
import {
|
|
16
|
+
import {default_sveltekit_config} from './sveltekit_config.js';
|
|
17
17
|
import {SVELTE_MATCHER, SVELTE_RUNES_MATCHER} from './svelte_helpers.js';
|
|
18
18
|
import {paths} from './paths.js';
|
|
19
|
-
import {NODE_MODULES_DIRNAME} from './path_constants.js';
|
|
20
|
-
import {to_define_import_meta_env,
|
|
19
|
+
import {JSON_MATCHER, NODE_MODULES_DIRNAME, TS_MATCHER} from './path_constants.js';
|
|
20
|
+
import {to_define_import_meta_env, default_ts_transform_options} from './esbuild_helpers.js';
|
|
21
21
|
import {resolve_specifier} from './resolve_specifier.js';
|
|
22
22
|
import {resolve_node_specifier} from './resolve_node_specifier.js';
|
|
23
23
|
import type {Package_Json} from './package_json.js';
|
|
@@ -65,18 +65,16 @@ const {
|
|
|
65
65
|
svelte_compile_options,
|
|
66
66
|
svelte_compile_module_options,
|
|
67
67
|
svelte_preprocessors,
|
|
68
|
-
} =
|
|
68
|
+
} = default_sveltekit_config;
|
|
69
69
|
|
|
70
|
-
const
|
|
71
|
-
...
|
|
70
|
+
const ts_transform_options: esbuild.TransformOptions = {
|
|
71
|
+
...default_ts_transform_options,
|
|
72
72
|
define: to_define_import_meta_env(dev, base_url),
|
|
73
73
|
sourcemap: 'inline',
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
const aliases = Object.entries({$lib: 'src/lib', ...alias});
|
|
77
77
|
|
|
78
|
-
const TS_MATCHER = /\.(ts|tsx|mts|cts)$/;
|
|
79
|
-
const JSON_MATCHER = /\.(json)$/;
|
|
80
78
|
const NOOP_MATCHER = /\.(css|svg)$/; // TODO others? configurable?
|
|
81
79
|
const ENV_MATCHER = /src\/lib\/\$env\/(static|dynamic)\/(public|private)$/;
|
|
82
80
|
const NODE_MODULES_MATCHER = new RegExp(escape_regexp('/' + NODE_MODULES_DIRNAME + '/'), 'u');
|
|
@@ -100,14 +98,16 @@ export const load: LoadHook = async (url, context, nextLoad) => {
|
|
|
100
98
|
};
|
|
101
99
|
} else if (SVELTE_RUNES_MATCHER.test(url)) {
|
|
102
100
|
// Svelte runes in js/ts
|
|
103
|
-
// TODO support sourcemaps
|
|
104
101
|
const loaded = await nextLoad(
|
|
105
102
|
url,
|
|
106
103
|
context.format === 'module' ? context : {...context, format: 'module'}, // TODO dunno why this is needed, specifically with tests
|
|
107
104
|
);
|
|
108
105
|
const filename = fileURLToPath(url);
|
|
109
106
|
const source = loaded.source!.toString(); // eslint-disable-line @typescript-eslint/no-base-to-string
|
|
110
|
-
const
|
|
107
|
+
const js_source = TS_MATCHER.test(url)
|
|
108
|
+
? (await esbuild.transform(source, {...ts_transform_options, sourcefile: url})).code // TODO @many use warnings? handle not-inline sourcemaps?
|
|
109
|
+
: source;
|
|
110
|
+
const transformed = compileModule(js_source, {...svelte_compile_module_options, dev, filename});
|
|
111
111
|
return {format: 'module', shortCircuit: true, source: transformed.js.code};
|
|
112
112
|
} else if (TS_MATCHER.test(url)) {
|
|
113
113
|
// ts
|
|
@@ -115,10 +115,8 @@ export const load: LoadHook = async (url, context, nextLoad) => {
|
|
|
115
115
|
url,
|
|
116
116
|
context.format === 'module' ? context : {...context, format: 'module'}, // TODO dunno why this is needed, specifically with tests
|
|
117
117
|
);
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
{...final_ts_transform_options, sourcefile: url},
|
|
121
|
-
);
|
|
118
|
+
const source = loaded.source!.toString(); // eslint-disable-line @typescript-eslint/no-base-to-string
|
|
119
|
+
const transformed = await esbuild.transform(source, {...ts_transform_options, sourcefile: url}); // TODO @many use warnings? handle not-inline sourcemaps?
|
|
122
120
|
return {format: 'module', shortCircuit: true, source: transformed.code};
|
|
123
121
|
} else if (SVELTE_MATCHER.test(url)) {
|
|
124
122
|
// Svelte
|
|
@@ -129,11 +127,11 @@ export const load: LoadHook = async (url, context, nextLoad) => {
|
|
|
129
127
|
);
|
|
130
128
|
const filename = fileURLToPath(url);
|
|
131
129
|
const raw_source = loaded.source!.toString(); // eslint-disable-line @typescript-eslint/no-base-to-string
|
|
132
|
-
const preprocessed = svelte_preprocessors
|
|
130
|
+
const preprocessed = svelte_preprocessors // TODO @many use sourcemaps (and diagnostics?)
|
|
133
131
|
? await preprocess(raw_source, svelte_preprocessors, {filename})
|
|
134
132
|
: null;
|
|
135
133
|
const source = preprocessed?.code ?? raw_source;
|
|
136
|
-
const transformed = compile(source, {...svelte_compile_options, filename});
|
|
134
|
+
const transformed = compile(source, {...svelte_compile_options, dev, filename});
|
|
137
135
|
return {format: 'module', shortCircuit: true, source: transformed.js.code};
|
|
138
136
|
} else if (JSON_MATCHER.test(url)) {
|
|
139
137
|
// json
|