@fuzdev/gro 0.192.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.
- package/LICENSE +21 -0
- package/README.md +283 -0
- package/dist/args.d.ts +37 -0
- package/dist/args.d.ts.map +1 -0
- package/dist/args.js +102 -0
- package/dist/build.task.d.ts +20 -0
- package/dist/build.task.d.ts.map +1 -0
- package/dist/build.task.js +119 -0
- package/dist/build_cache.d.ts +100 -0
- package/dist/build_cache.d.ts.map +1 -0
- package/dist/build_cache.js +299 -0
- package/dist/changelog.d.ts +11 -0
- package/dist/changelog.d.ts.map +1 -0
- package/dist/changelog.js +47 -0
- package/dist/changeset.task.d.ts +35 -0
- package/dist/changeset.task.d.ts.map +1 -0
- package/dist/changeset.task.js +151 -0
- package/dist/changeset_helpers.d.ts +17 -0
- package/dist/changeset_helpers.d.ts.map +1 -0
- package/dist/changeset_helpers.js +7 -0
- package/dist/check.task.d.ts +28 -0
- package/dist/check.task.d.ts.map +1 -0
- package/dist/check.task.js +104 -0
- package/dist/child_process_logging.d.ts +10 -0
- package/dist/child_process_logging.d.ts.map +1 -0
- package/dist/child_process_logging.js +26 -0
- package/dist/clean.task.d.ts +15 -0
- package/dist/clean.task.d.ts.map +1 -0
- package/dist/clean.task.js +40 -0
- package/dist/clean_fs.d.ts +9 -0
- package/dist/clean_fs.d.ts.map +1 -0
- package/dist/clean_fs.js +28 -0
- package/dist/cli.d.ts +34 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +61 -0
- package/dist/commit.task.d.ts +11 -0
- package/dist/commit.task.d.ts.map +1 -0
- package/dist/commit.task.js +24 -0
- package/dist/constants.d.ts +46 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +52 -0
- package/dist/deploy.task.d.ts +29 -0
- package/dist/deploy.task.d.ts.map +1 -0
- package/dist/deploy.task.js +217 -0
- package/dist/dev.task.d.ts +16 -0
- package/dist/dev.task.d.ts.map +1 -0
- package/dist/dev.task.js +44 -0
- package/dist/disknode.d.ts +23 -0
- package/dist/disknode.d.ts.map +1 -0
- package/dist/disknode.js +1 -0
- package/dist/env.d.ts +11 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +49 -0
- package/dist/esbuild_helpers.d.ts +16 -0
- package/dist/esbuild_helpers.d.ts.map +1 -0
- package/dist/esbuild_helpers.js +36 -0
- package/dist/esbuild_plugin_external_worker.d.ts +23 -0
- package/dist/esbuild_plugin_external_worker.d.ts.map +1 -0
- package/dist/esbuild_plugin_external_worker.js +55 -0
- package/dist/esbuild_plugin_svelte.d.ts +15 -0
- package/dist/esbuild_plugin_svelte.d.ts.map +1 -0
- package/dist/esbuild_plugin_svelte.js +83 -0
- package/dist/esbuild_plugin_sveltekit_local_imports.d.ts +8 -0
- package/dist/esbuild_plugin_sveltekit_local_imports.d.ts.map +1 -0
- package/dist/esbuild_plugin_sveltekit_local_imports.js +30 -0
- package/dist/esbuild_plugin_sveltekit_shim_alias.d.ts +7 -0
- package/dist/esbuild_plugin_sveltekit_shim_alias.d.ts.map +1 -0
- package/dist/esbuild_plugin_sveltekit_shim_alias.js +18 -0
- package/dist/esbuild_plugin_sveltekit_shim_app.d.ts +9 -0
- package/dist/esbuild_plugin_sveltekit_shim_app.d.ts.map +1 -0
- package/dist/esbuild_plugin_sveltekit_shim_app.js +22 -0
- package/dist/esbuild_plugin_sveltekit_shim_env.d.ts +11 -0
- package/dist/esbuild_plugin_sveltekit_shim_env.d.ts.map +1 -0
- package/dist/esbuild_plugin_sveltekit_shim_env.js +18 -0
- package/dist/filer.d.ts +33 -0
- package/dist/filer.d.ts.map +1 -0
- package/dist/filer.js +385 -0
- package/dist/format.task.d.ts +11 -0
- package/dist/format.task.d.ts.map +1 -0
- package/dist/format.task.js +27 -0
- package/dist/format_directory.d.ts +13 -0
- package/dist/format_directory.d.ts.map +1 -0
- package/dist/format_directory.js +40 -0
- package/dist/format_file.d.ts +9 -0
- package/dist/format_file.d.ts.map +1 -0
- package/dist/format_file.js +42 -0
- package/dist/gen.d.ts +142 -0
- package/dist/gen.d.ts.map +1 -0
- package/dist/gen.js +199 -0
- package/dist/gen.task.d.ts +12 -0
- package/dist/gen.task.d.ts.map +1 -0
- package/dist/gen.task.js +149 -0
- package/dist/gen_helpers.d.ts +11 -0
- package/dist/gen_helpers.d.ts.map +1 -0
- package/dist/gen_helpers.js +76 -0
- package/dist/github.d.ts +19 -0
- package/dist/github.d.ts.map +1 -0
- package/dist/github.js +33 -0
- package/dist/gro.config.default.d.ts +13 -0
- package/dist/gro.config.default.d.ts.map +1 -0
- package/dist/gro.config.default.js +33 -0
- package/dist/gro.d.ts +3 -0
- package/dist/gro.d.ts.map +1 -0
- package/dist/gro.js +21 -0
- package/dist/gro_config.d.ts +115 -0
- package/dist/gro_config.d.ts.map +1 -0
- package/dist/gro_config.js +114 -0
- package/dist/gro_helpers.d.ts +49 -0
- package/dist/gro_helpers.d.ts.map +1 -0
- package/dist/gro_helpers.js +97 -0
- package/dist/gro_plugin_gen.d.ts +12 -0
- package/dist/gro_plugin_gen.d.ts.map +1 -0
- package/dist/gro_plugin_gen.js +101 -0
- package/dist/gro_plugin_server.d.ts +80 -0
- package/dist/gro_plugin_server.d.ts.map +1 -0
- package/dist/gro_plugin_server.js +167 -0
- package/dist/gro_plugin_sveltekit_app.d.ts +9 -0
- package/dist/gro_plugin_sveltekit_app.d.ts.map +1 -0
- package/dist/gro_plugin_sveltekit_app.js +42 -0
- package/dist/gro_plugin_sveltekit_library.d.ts +16 -0
- package/dist/gro_plugin_sveltekit_library.d.ts.map +1 -0
- package/dist/gro_plugin_sveltekit_library.js +34 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/input_path.d.ts +64 -0
- package/dist/input_path.d.ts.map +1 -0
- package/dist/input_path.js +199 -0
- package/dist/invoke.d.ts +2 -0
- package/dist/invoke.d.ts.map +1 -0
- package/dist/invoke.js +28 -0
- package/dist/invoke_task.d.ts +30 -0
- package/dist/invoke_task.d.ts.map +1 -0
- package/dist/invoke_task.js +104 -0
- package/dist/lint.task.d.ts +11 -0
- package/dist/lint.task.d.ts.map +1 -0
- package/dist/lint.task.js +32 -0
- package/dist/loader.d.ts +6 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +192 -0
- package/dist/module.d.ts +4 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +6 -0
- package/dist/modules.d.ts +36 -0
- package/dist/modules.d.ts.map +1 -0
- package/dist/modules.js +71 -0
- package/dist/package_json.d.ts +32 -0
- package/dist/package_json.d.ts.map +1 -0
- package/dist/package_json.js +178 -0
- package/dist/parse_exports.d.ts +20 -0
- package/dist/parse_exports.d.ts.map +1 -0
- package/dist/parse_exports.js +65 -0
- package/dist/parse_exports_context.d.ts +21 -0
- package/dist/parse_exports_context.d.ts.map +1 -0
- package/dist/parse_exports_context.js +332 -0
- package/dist/parse_imports.d.ts +5 -0
- package/dist/parse_imports.d.ts.map +1 -0
- package/dist/parse_imports.js +140 -0
- package/dist/paths.d.ts +41 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +69 -0
- package/dist/plugin.d.ts +36 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +78 -0
- package/dist/publish.task.d.ts +26 -0
- package/dist/publish.task.d.ts.map +1 -0
- package/dist/publish.task.js +176 -0
- package/dist/register.d.ts +2 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +2 -0
- package/dist/reinstall.task.d.ts +8 -0
- package/dist/reinstall.task.d.ts.map +1 -0
- package/dist/reinstall.task.js +35 -0
- package/dist/release.task.d.ts +8 -0
- package/dist/release.task.d.ts.map +1 -0
- package/dist/release.task.js +20 -0
- package/dist/resolve.task.d.ts +11 -0
- package/dist/resolve.task.d.ts.map +1 -0
- package/dist/resolve.task.js +38 -0
- package/dist/resolve_specifier.d.ts +22 -0
- package/dist/resolve_specifier.d.ts.map +1 -0
- package/dist/resolve_specifier.js +57 -0
- package/dist/run.task.d.ts +16 -0
- package/dist/run.task.d.ts.map +1 -0
- package/dist/run.task.js +52 -0
- package/dist/run_gen.d.ts +10 -0
- package/dist/run_gen.d.ts.map +1 -0
- package/dist/run_gen.js +73 -0
- package/dist/run_task.d.ts +17 -0
- package/dist/run_task.d.ts.map +1 -0
- package/dist/run_task.js +45 -0
- package/dist/source_json.d.ts +7 -0
- package/dist/source_json.d.ts.map +1 -0
- package/dist/source_json.js +145 -0
- package/dist/svelte_config.d.ts +57 -0
- package/dist/svelte_config.d.ts.map +1 -0
- package/dist/svelte_config.js +81 -0
- package/dist/sveltekit_helpers.d.ts +75 -0
- package/dist/sveltekit_helpers.d.ts.map +1 -0
- package/dist/sveltekit_helpers.js +94 -0
- package/dist/sveltekit_shim_app.d.ts +11 -0
- package/dist/sveltekit_shim_app.d.ts.map +1 -0
- package/dist/sveltekit_shim_app.js +31 -0
- package/dist/sveltekit_shim_app_environment.d.ts +13 -0
- package/dist/sveltekit_shim_app_environment.d.ts.map +1 -0
- package/dist/sveltekit_shim_app_environment.js +14 -0
- package/dist/sveltekit_shim_app_forms.d.ts +5 -0
- package/dist/sveltekit_shim_app_forms.d.ts.map +1 -0
- package/dist/sveltekit_shim_app_forms.js +6 -0
- package/dist/sveltekit_shim_app_navigation.d.ts +10 -0
- package/dist/sveltekit_shim_app_navigation.d.ts.map +1 -0
- package/dist/sveltekit_shim_app_navigation.js +11 -0
- package/dist/sveltekit_shim_app_paths.d.ts +17 -0
- package/dist/sveltekit_shim_app_paths.d.ts.map +1 -0
- package/dist/sveltekit_shim_app_paths.js +10 -0
- package/dist/sveltekit_shim_app_state.d.ts +5 -0
- package/dist/sveltekit_shim_app_state.d.ts.map +1 -0
- package/dist/sveltekit_shim_app_state.js +26 -0
- package/dist/sveltekit_shim_env.d.ts +5 -0
- package/dist/sveltekit_shim_env.d.ts.map +1 -0
- package/dist/sveltekit_shim_env.js +23 -0
- package/dist/sync.task.d.ts +16 -0
- package/dist/sync.task.d.ts.map +1 -0
- package/dist/sync.task.js +39 -0
- package/dist/task.d.ts +98 -0
- package/dist/task.d.ts.map +1 -0
- package/dist/task.js +109 -0
- package/dist/task_logging.d.ts +6 -0
- package/dist/task_logging.d.ts.map +1 -0
- package/dist/task_logging.js +201 -0
- package/dist/test.task.d.ts +13 -0
- package/dist/test.task.d.ts.map +1 -0
- package/dist/test.task.js +53 -0
- package/dist/typecheck.task.d.ts +13 -0
- package/dist/typecheck.task.d.ts.map +1 -0
- package/dist/typecheck.task.js +68 -0
- package/dist/upgrade.task.d.ts +20 -0
- package/dist/upgrade.task.d.ts.map +1 -0
- package/dist/upgrade.task.js +111 -0
- package/dist/watch_dir.d.ts +36 -0
- package/dist/watch_dir.d.ts.map +1 -0
- package/dist/watch_dir.js +69 -0
- package/package.json +149 -0
- package/src/lib/args.ts +115 -0
- package/src/lib/build.task.ts +151 -0
- package/src/lib/build_cache.ts +378 -0
- package/src/lib/changelog.ts +69 -0
- package/src/lib/changeset.task.ts +228 -0
- package/src/lib/changeset_helpers.ts +14 -0
- package/src/lib/check.task.ts +132 -0
- package/src/lib/child_process_logging.ts +38 -0
- package/src/lib/clean.task.ts +48 -0
- package/src/lib/clean_fs.ts +54 -0
- package/src/lib/cli.ts +98 -0
- package/src/lib/commit.task.ts +34 -0
- package/src/lib/constants.ts +56 -0
- package/src/lib/deploy.task.ts +287 -0
- package/src/lib/dev.task.ts +52 -0
- package/src/lib/disknode.ts +26 -0
- package/src/lib/env.ts +78 -0
- package/src/lib/esbuild_helpers.ts +49 -0
- package/src/lib/esbuild_plugin_external_worker.ts +94 -0
- package/src/lib/esbuild_plugin_svelte.ts +134 -0
- package/src/lib/esbuild_plugin_sveltekit_local_imports.ts +38 -0
- package/src/lib/esbuild_plugin_sveltekit_shim_alias.ts +27 -0
- package/src/lib/esbuild_plugin_sveltekit_shim_app.ts +42 -0
- package/src/lib/esbuild_plugin_sveltekit_shim_env.ts +47 -0
- package/src/lib/filer.ts +458 -0
- package/src/lib/format.task.ts +44 -0
- package/src/lib/format_directory.ts +65 -0
- package/src/lib/format_file.ts +49 -0
- package/src/lib/gen.task.ts +206 -0
- package/src/lib/gen.ts +406 -0
- package/src/lib/gen_helpers.ts +131 -0
- package/src/lib/github.ts +46 -0
- package/src/lib/gro.config.default.ts +42 -0
- package/src/lib/gro.ts +29 -0
- package/src/lib/gro_config.ts +254 -0
- package/src/lib/gro_helpers.ts +108 -0
- package/src/lib/gro_plugin_gen.ts +149 -0
- package/src/lib/gro_plugin_server.ts +288 -0
- package/src/lib/gro_plugin_sveltekit_app.ts +58 -0
- package/src/lib/gro_plugin_sveltekit_library.ts +63 -0
- package/src/lib/index.ts +8 -0
- package/src/lib/input_path.ts +254 -0
- package/src/lib/invoke.ts +34 -0
- package/src/lib/invoke_task.ts +139 -0
- package/src/lib/lint.task.ts +39 -0
- package/src/lib/loader.ts +229 -0
- package/src/lib/module.ts +13 -0
- package/src/lib/modules.ts +117 -0
- package/src/lib/package_json.ts +255 -0
- package/src/lib/parse_exports.ts +100 -0
- package/src/lib/parse_exports_context.ts +395 -0
- package/src/lib/parse_imports.ts +180 -0
- package/src/lib/paths.ts +111 -0
- package/src/lib/plugin.ts +106 -0
- package/src/lib/publish.task.ts +228 -0
- package/src/lib/register.ts +3 -0
- package/src/lib/reinstall.task.ts +45 -0
- package/src/lib/release.task.ts +26 -0
- package/src/lib/resolve.task.ts +43 -0
- package/src/lib/resolve_specifier.ts +81 -0
- package/src/lib/run.task.ts +65 -0
- package/src/lib/run_gen.ts +110 -0
- package/src/lib/run_task.ts +82 -0
- package/src/lib/source_json.ts +183 -0
- package/src/lib/svelte_config.ts +140 -0
- package/src/lib/sveltekit_helpers.ts +193 -0
- package/src/lib/sveltekit_shim_app.ts +41 -0
- package/src/lib/sveltekit_shim_app_environment.ts +16 -0
- package/src/lib/sveltekit_shim_app_forms.ts +13 -0
- package/src/lib/sveltekit_shim_app_navigation.ts +23 -0
- package/src/lib/sveltekit_shim_app_paths.ts +26 -0
- package/src/lib/sveltekit_shim_app_state.ts +35 -0
- package/src/lib/sveltekit_shim_env.ts +45 -0
- package/src/lib/sync.task.ts +47 -0
- package/src/lib/task.ts +245 -0
- package/src/lib/task_logging.ts +255 -0
- package/src/lib/test.task.ts +63 -0
- package/src/lib/typecheck.task.ts +81 -0
- package/src/lib/upgrade.task.ts +148 -0
- package/src/lib/watch_dir.ts +115 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import * as esbuild from 'esbuild';
|
|
2
|
+
import {
|
|
3
|
+
compile,
|
|
4
|
+
compileModule,
|
|
5
|
+
preprocess,
|
|
6
|
+
type CompileOptions,
|
|
7
|
+
type ModuleCompileOptions,
|
|
8
|
+
type PreprocessorGroup,
|
|
9
|
+
} from 'svelte/compiler';
|
|
10
|
+
import {readFile} from 'node:fs/promises';
|
|
11
|
+
import {relative} from 'node:path';
|
|
12
|
+
|
|
13
|
+
import {to_define_import_meta_env, default_ts_transform_options} from './esbuild_helpers.ts';
|
|
14
|
+
import {
|
|
15
|
+
default_svelte_config,
|
|
16
|
+
to_default_compile_module_options,
|
|
17
|
+
type ParsedSvelteConfig,
|
|
18
|
+
} from './svelte_config.ts';
|
|
19
|
+
import {TS_MATCHER, SVELTE_MATCHER, SVELTE_RUNES_MATCHER} from './constants.ts';
|
|
20
|
+
|
|
21
|
+
export interface EsbuildPluginSvelteOptions {
|
|
22
|
+
dev: boolean;
|
|
23
|
+
base_url: ParsedSvelteConfig['base_url'];
|
|
24
|
+
dir?: string;
|
|
25
|
+
svelte_compile_options?: CompileOptions;
|
|
26
|
+
svelte_compile_module_options?: ModuleCompileOptions;
|
|
27
|
+
svelte_preprocessors?: PreprocessorGroup | Array<PreprocessorGroup>;
|
|
28
|
+
ts_transform_options?: esbuild.TransformOptions;
|
|
29
|
+
is_ts?: (filename: string) => boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const esbuild_plugin_svelte = (options: EsbuildPluginSvelteOptions): esbuild.Plugin => {
|
|
33
|
+
const {
|
|
34
|
+
dev,
|
|
35
|
+
base_url,
|
|
36
|
+
dir = process.cwd(),
|
|
37
|
+
svelte_compile_options = default_svelte_config.svelte_compile_options,
|
|
38
|
+
svelte_compile_module_options = to_default_compile_module_options(svelte_compile_options),
|
|
39
|
+
svelte_preprocessors,
|
|
40
|
+
ts_transform_options = default_ts_transform_options,
|
|
41
|
+
is_ts = (f) => TS_MATCHER.test(f),
|
|
42
|
+
} = options;
|
|
43
|
+
|
|
44
|
+
const final_ts_transform_options: esbuild.TransformOptions = {
|
|
45
|
+
...ts_transform_options,
|
|
46
|
+
define: to_define_import_meta_env(dev, base_url),
|
|
47
|
+
sourcemap: 'inline',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
name: 'svelte',
|
|
52
|
+
setup: (build) => {
|
|
53
|
+
build.onLoad({filter: SVELTE_RUNES_MATCHER}, async ({path}) => {
|
|
54
|
+
const source = await readFile(path, 'utf8');
|
|
55
|
+
try {
|
|
56
|
+
const filename = relative(dir, path);
|
|
57
|
+
const js_source = is_ts(filename)
|
|
58
|
+
? (
|
|
59
|
+
await esbuild.transform(source, {
|
|
60
|
+
...final_ts_transform_options,
|
|
61
|
+
sourcefile: filename,
|
|
62
|
+
})
|
|
63
|
+
).code // TODO @many use warnings? handle not-inline sourcemaps?
|
|
64
|
+
: source;
|
|
65
|
+
const {js, warnings} = compileModule(js_source, {
|
|
66
|
+
...svelte_compile_module_options,
|
|
67
|
+
filename,
|
|
68
|
+
});
|
|
69
|
+
const contents = js.code + '//# sourceMappingURL=' + js.map.toUrl();
|
|
70
|
+
return {
|
|
71
|
+
contents,
|
|
72
|
+
warnings: warnings.map((w) => convert_svelte_message_to_esbuild(filename, source, w)),
|
|
73
|
+
};
|
|
74
|
+
} catch (error) {
|
|
75
|
+
return {errors: [convert_svelte_message_to_esbuild(path, source, error)]};
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
build.onLoad({filter: SVELTE_MATCHER}, async ({path}) => {
|
|
80
|
+
let source = await readFile(path, 'utf8');
|
|
81
|
+
try {
|
|
82
|
+
const filename = relative(dir, path);
|
|
83
|
+
const preprocessed = svelte_preprocessors
|
|
84
|
+
? await preprocess(source, svelte_preprocessors, {filename})
|
|
85
|
+
: null;
|
|
86
|
+
if (preprocessed?.code) source = preprocessed.code;
|
|
87
|
+
const {js, warnings} = compile(source, {...svelte_compile_options, filename});
|
|
88
|
+
const contents = js.code + '//# sourceMappingURL=' + js.map.toUrl();
|
|
89
|
+
return {
|
|
90
|
+
contents,
|
|
91
|
+
warnings: warnings.map((w) => convert_svelte_message_to_esbuild(filename, source, w)),
|
|
92
|
+
};
|
|
93
|
+
} catch (error) {
|
|
94
|
+
return {errors: [convert_svelte_message_to_esbuild(path, source, error)]};
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Following the example in the esbuild docs:
|
|
103
|
+
* https://esbuild.github.io/plugins/#svelte-plugin
|
|
104
|
+
*/
|
|
105
|
+
const convert_svelte_message_to_esbuild = (
|
|
106
|
+
path: string,
|
|
107
|
+
source: string,
|
|
108
|
+
{message, start, end}: SvelteError,
|
|
109
|
+
): esbuild.PartialMessage => {
|
|
110
|
+
let location: esbuild.PartialMessage['location'] = null;
|
|
111
|
+
if (start && end) {
|
|
112
|
+
const lineText = source.split(/\r\n|\r|\n/g)[start.line - 1] ?? '';
|
|
113
|
+
const lineEnd = start.line === end.line ? end.column : lineText.length;
|
|
114
|
+
location = {
|
|
115
|
+
file: path,
|
|
116
|
+
line: start.line,
|
|
117
|
+
lineText,
|
|
118
|
+
column: start.column,
|
|
119
|
+
length: lineEnd - start.column,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return {text: message, location};
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// these are not exported by Svelte
|
|
126
|
+
interface SvelteError {
|
|
127
|
+
message: string;
|
|
128
|
+
start?: LineInfo;
|
|
129
|
+
end?: LineInfo;
|
|
130
|
+
}
|
|
131
|
+
interface LineInfo {
|
|
132
|
+
line: number;
|
|
133
|
+
column: number;
|
|
134
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type * as esbuild from 'esbuild';
|
|
2
|
+
import {readFile} from 'node:fs/promises';
|
|
3
|
+
import {dirname} from 'node:path';
|
|
4
|
+
|
|
5
|
+
import {resolve_specifier} from './resolve_specifier.ts';
|
|
6
|
+
import {EVERYTHING_MATCHER} from './constants.ts';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Adds support for imports to both `.ts` and `.js`,
|
|
10
|
+
* as well as imports without extensions that resolve to `.js` or `.ts`.
|
|
11
|
+
* Prefers `.ts` over any `.js`, and falls back to `.ts` if no file is found.
|
|
12
|
+
*/
|
|
13
|
+
export const esbuild_plugin_sveltekit_local_imports = (): esbuild.Plugin => ({
|
|
14
|
+
name: 'sveltekit_local_imports',
|
|
15
|
+
setup: (build) => {
|
|
16
|
+
build.onResolve({filter: /^(\/|\.)/}, async (args) => {
|
|
17
|
+
const {path, importer} = args;
|
|
18
|
+
if (!importer) return {path};
|
|
19
|
+
const {path_id, namespace} = await resolve_specifier(path, dirname(importer));
|
|
20
|
+
return {path: path_id, namespace}; // `namespace` may be `undefined`, but esbuild needs the absolute path for json etc
|
|
21
|
+
});
|
|
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
|
+
);
|
|
37
|
+
},
|
|
38
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type * as esbuild from 'esbuild';
|
|
2
|
+
import {escape_regexp} from '@fuzdev/fuz_util/regexp.js';
|
|
3
|
+
import {join} from 'node:path';
|
|
4
|
+
|
|
5
|
+
export interface EsbuildPluginSveltekitShimAliasOptions {
|
|
6
|
+
dir?: string;
|
|
7
|
+
alias?: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const esbuild_plugin_sveltekit_shim_alias = ({
|
|
11
|
+
dir = process.cwd(),
|
|
12
|
+
alias,
|
|
13
|
+
}: EsbuildPluginSveltekitShimAliasOptions): esbuild.Plugin => ({
|
|
14
|
+
name: 'sveltekit_shim_alias',
|
|
15
|
+
setup: (build) => {
|
|
16
|
+
const aliases: Record<string, string> = {$lib: 'src/lib', ...alias};
|
|
17
|
+
// Create a Go-compatible regexp
|
|
18
|
+
const filter = new RegExp(`^(?:${Object.keys(aliases).map(escape_regexp).join('|')})`);
|
|
19
|
+
build.onResolve({filter}, async (args) => {
|
|
20
|
+
const {path, ...rest} = args;
|
|
21
|
+
// Find which alias prefix matches
|
|
22
|
+
const prefix = Object.keys(aliases).find((key) => path.startsWith(key));
|
|
23
|
+
if (!prefix) return null;
|
|
24
|
+
return build.resolve(join(dir, aliases[prefix] + path.substring(prefix.length)), rest);
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type * as esbuild from 'esbuild';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
render_sveltekit_shim_app_environment,
|
|
5
|
+
render_sveltekit_shim_app_paths,
|
|
6
|
+
sveltekit_shim_app_specifiers,
|
|
7
|
+
} from './sveltekit_shim_app.ts';
|
|
8
|
+
import type {ParsedSvelteConfig} from './svelte_config.ts';
|
|
9
|
+
import {EVERYTHING_MATCHER} from './constants.ts';
|
|
10
|
+
|
|
11
|
+
export interface EsbuildPluginSveltekitShimAppOptions {
|
|
12
|
+
dev: boolean;
|
|
13
|
+
base_url: ParsedSvelteConfig['base_url'];
|
|
14
|
+
assets_url: ParsedSvelteConfig['assets_url'];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const esbuild_plugin_sveltekit_shim_app = ({
|
|
18
|
+
dev,
|
|
19
|
+
base_url,
|
|
20
|
+
assets_url,
|
|
21
|
+
}: EsbuildPluginSveltekitShimAppOptions): esbuild.Plugin => ({
|
|
22
|
+
name: 'sveltekit_shim_app',
|
|
23
|
+
setup: (build) => {
|
|
24
|
+
build.onResolve({filter: /^\$app\/(forms|navigation|stores)$/}, ({path, ...rest}) =>
|
|
25
|
+
build.resolve(sveltekit_shim_app_specifiers.get(path)!, rest),
|
|
26
|
+
);
|
|
27
|
+
build.onResolve({filter: /^\$app\/paths$/}, ({path}) => ({
|
|
28
|
+
path: sveltekit_shim_app_specifiers.get(path)!,
|
|
29
|
+
namespace: 'sveltekit_shim_app_paths',
|
|
30
|
+
}));
|
|
31
|
+
build.onLoad({filter: EVERYTHING_MATCHER, namespace: 'sveltekit_shim_app_paths'}, () => ({
|
|
32
|
+
contents: render_sveltekit_shim_app_paths(base_url, assets_url),
|
|
33
|
+
}));
|
|
34
|
+
build.onResolve({filter: /^\$app\/environment$/}, ({path}) => ({
|
|
35
|
+
path: sveltekit_shim_app_specifiers.get(path)!,
|
|
36
|
+
namespace: 'sveltekit_shim_app_environment',
|
|
37
|
+
}));
|
|
38
|
+
build.onLoad({filter: EVERYTHING_MATCHER, namespace: 'sveltekit_shim_app_environment'}, () => ({
|
|
39
|
+
contents: render_sveltekit_shim_app_environment(dev),
|
|
40
|
+
}));
|
|
41
|
+
},
|
|
42
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type * as esbuild from 'esbuild';
|
|
2
|
+
|
|
3
|
+
import {render_env_shim_module} from './sveltekit_shim_env.ts';
|
|
4
|
+
import {SVELTEKIT_ENV_MATCHER, EVERYTHING_MATCHER} from './constants.ts';
|
|
5
|
+
|
|
6
|
+
export interface EsbuildPluginSveltekitShimEnvOptions {
|
|
7
|
+
dev: boolean;
|
|
8
|
+
public_prefix?: string;
|
|
9
|
+
private_prefix?: string;
|
|
10
|
+
env_dir?: string;
|
|
11
|
+
env_files?: Array<string>;
|
|
12
|
+
ambient_env?: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const namespace = 'sveltekit_shim_env';
|
|
16
|
+
|
|
17
|
+
export const esbuild_plugin_sveltekit_shim_env = ({
|
|
18
|
+
dev,
|
|
19
|
+
public_prefix,
|
|
20
|
+
private_prefix,
|
|
21
|
+
env_dir,
|
|
22
|
+
env_files,
|
|
23
|
+
ambient_env,
|
|
24
|
+
}: EsbuildPluginSveltekitShimEnvOptions): esbuild.Plugin => ({
|
|
25
|
+
name: 'sveltekit_shim_env',
|
|
26
|
+
setup: (build) => {
|
|
27
|
+
build.onResolve({filter: SVELTEKIT_ENV_MATCHER}, ({path}) => ({path, namespace}));
|
|
28
|
+
build.onLoad({filter: EVERYTHING_MATCHER, namespace}, ({path}) => {
|
|
29
|
+
const matches = SVELTEKIT_ENV_MATCHER.exec(path);
|
|
30
|
+
const mode = matches![1] as 'static' | 'dynamic';
|
|
31
|
+
const visibility = matches![2] as 'public' | 'private';
|
|
32
|
+
return {
|
|
33
|
+
loader: 'ts',
|
|
34
|
+
contents: render_env_shim_module(
|
|
35
|
+
dev,
|
|
36
|
+
mode,
|
|
37
|
+
visibility,
|
|
38
|
+
public_prefix,
|
|
39
|
+
private_prefix,
|
|
40
|
+
env_dir,
|
|
41
|
+
env_files,
|
|
42
|
+
ambient_env,
|
|
43
|
+
),
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
});
|