@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,140 @@
|
|
|
1
|
+
import { parseSync } from 'oxc-parser';
|
|
2
|
+
import { UnreachableError } from '@fuzdev/fuz_util/error.js';
|
|
3
|
+
import { JS_MATCHER, TS_MATCHER, SVELTE_MATCHER, SVELTE_SCRIPT_MATCHER } from "./constants.js";
|
|
4
|
+
// TODO this is probably way more complicated that it should be, maybe report the issues upstream unless I made a mistake here
|
|
5
|
+
/**
|
|
6
|
+
* Extracts the string value from a module request, handling different quote styles.
|
|
7
|
+
* Returns null if the value is not a valid string literal.
|
|
8
|
+
*/
|
|
9
|
+
const extract_string_literal = (content, start, end) => {
|
|
10
|
+
const value = content.substring(start, end);
|
|
11
|
+
// Check if it's a string literal (starts and ends with quotes)
|
|
12
|
+
if ((value.startsWith("'") && value.endsWith("'")) ||
|
|
13
|
+
(value.startsWith('"') && value.endsWith('"')) ||
|
|
14
|
+
(value.startsWith('`') && value.endsWith('`'))) {
|
|
15
|
+
// Remove the quotes
|
|
16
|
+
return value.slice(1, -1);
|
|
17
|
+
}
|
|
18
|
+
// Not a valid string literal
|
|
19
|
+
return null;
|
|
20
|
+
};
|
|
21
|
+
export const parse_imports = (id, contents, ignore_types = true) => {
|
|
22
|
+
const specifiers = [];
|
|
23
|
+
const is_svelte = SVELTE_MATCHER.test(id);
|
|
24
|
+
const parse_from = (s) => {
|
|
25
|
+
const parsed = parseSync(is_svelte ? id + '.ts' : id, s, {});
|
|
26
|
+
// Process static imports
|
|
27
|
+
for (const static_import of parsed.module.staticImports) {
|
|
28
|
+
// Get the module source node
|
|
29
|
+
const import_decl = parsed.program.body.find((node) => node.type === 'ImportDeclaration' && node.start === static_import.start);
|
|
30
|
+
if (!import_decl?.source)
|
|
31
|
+
continue;
|
|
32
|
+
// Extract the module request string value
|
|
33
|
+
const value = extract_string_literal(s, import_decl.source.start, import_decl.source.end);
|
|
34
|
+
if (!value)
|
|
35
|
+
continue;
|
|
36
|
+
// Skip type-only imports if ignore_types is true
|
|
37
|
+
if (ignore_types) {
|
|
38
|
+
// Handle import type {...} (type-only imports)
|
|
39
|
+
if (import_decl.importKind === 'type') {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
// Handle inline type imports ({type foo})
|
|
43
|
+
if (static_import.entries.length > 0) {
|
|
44
|
+
// If all imports are type imports, skip this import
|
|
45
|
+
const has_non_type_specifier = static_import.entries.some((entry) => !entry.isType);
|
|
46
|
+
if (!has_non_type_specifier) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
specifiers.push(value);
|
|
52
|
+
}
|
|
53
|
+
// Process dynamic imports
|
|
54
|
+
for (const dynamic_import of parsed.module.dynamicImports) {
|
|
55
|
+
// Find the corresponding AST node
|
|
56
|
+
let found = false;
|
|
57
|
+
for (const node of parsed.program.body) {
|
|
58
|
+
if (node.type === 'ExpressionStatement' &&
|
|
59
|
+
node.expression.type === 'AwaitExpression' &&
|
|
60
|
+
node.expression.argument.type === 'ImportExpression') {
|
|
61
|
+
const import_expr = node.expression.argument;
|
|
62
|
+
if (import_expr.start === dynamic_import.start) {
|
|
63
|
+
// Only process string literals (not expressions or variables)
|
|
64
|
+
if (import_expr.source.type === 'Literal') {
|
|
65
|
+
const value = String(import_expr.source.value);
|
|
66
|
+
if (value) {
|
|
67
|
+
specifiers.push(value);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
found = true;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// If we didn't find a match through AST, fall back to the original approach
|
|
76
|
+
// but only for simple string literals
|
|
77
|
+
if (!found) {
|
|
78
|
+
const value = extract_string_literal(s, dynamic_import.moduleRequest.start, dynamic_import.moduleRequest.end);
|
|
79
|
+
if (value) {
|
|
80
|
+
specifiers.push(value);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Process re-exports
|
|
85
|
+
for (const node of parsed.program.body) {
|
|
86
|
+
if (node.type === 'ExportNamedDeclaration' && node.source) {
|
|
87
|
+
// Skip type-only exports if ignore_types is true
|
|
88
|
+
if (ignore_types && node.exportKind === 'type') {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
92
|
+
if (node.source.type === 'Literal') {
|
|
93
|
+
const value = node.source.value;
|
|
94
|
+
if (value) {
|
|
95
|
+
specifiers.push(value);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
throw new UnreachableError(node.source.type);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
if (is_svelte) {
|
|
105
|
+
// Reset the regexp state between calls
|
|
106
|
+
SVELTE_SCRIPT_MATCHER.lastIndex = 0;
|
|
107
|
+
// Capture script tags at the top level (not nested in HTML)
|
|
108
|
+
let last_index = 0;
|
|
109
|
+
const script_blocks = [];
|
|
110
|
+
// First collect all script blocks
|
|
111
|
+
let match;
|
|
112
|
+
while ((match = SVELTE_SCRIPT_MATCHER.exec(contents)) !== null) {
|
|
113
|
+
// Save position of the script tag
|
|
114
|
+
const start = match.index;
|
|
115
|
+
const end = SVELTE_SCRIPT_MATCHER.lastIndex;
|
|
116
|
+
// Only process top-level script tags (skip nested ones)
|
|
117
|
+
// A nested script would be inside another HTML tag between lastIndex and start
|
|
118
|
+
const text_between = contents.substring(last_index, start);
|
|
119
|
+
const contains_opening_tag = /<[a-z][^>]*>/i.test(text_between);
|
|
120
|
+
const contains_closing_tag = /<\/[a-z][^>]*>/i.test(text_between);
|
|
121
|
+
// If we're not nested (no HTML tag nesting), process this script
|
|
122
|
+
if (!(contains_opening_tag && !contains_closing_tag)) {
|
|
123
|
+
script_blocks.push({
|
|
124
|
+
content: match[1],
|
|
125
|
+
start,
|
|
126
|
+
end,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
last_index = end;
|
|
130
|
+
}
|
|
131
|
+
// Process all the collected script blocks
|
|
132
|
+
for (const script_block of script_blocks) {
|
|
133
|
+
parse_from(script_block.content);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else if (TS_MATCHER.test(id) || JS_MATCHER.test(id)) {
|
|
137
|
+
parse_from(contents);
|
|
138
|
+
}
|
|
139
|
+
return specifiers;
|
|
140
|
+
};
|
package/dist/paths.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { PathId } from '@fuzdev/fuz_util/path.js';
|
|
2
|
+
export declare const LIB_DIRNAME: string;
|
|
3
|
+
export declare const LIB_PATH: string;
|
|
4
|
+
/** @trailing_slash */
|
|
5
|
+
export declare const LIB_DIR: string;
|
|
6
|
+
export declare const ROUTES_DIRNAME: string;
|
|
7
|
+
export interface Paths {
|
|
8
|
+
/** @trailing_slash */
|
|
9
|
+
root: string;
|
|
10
|
+
/** @trailing_slash */
|
|
11
|
+
source: string;
|
|
12
|
+
/** @trailing_slash */
|
|
13
|
+
lib: string;
|
|
14
|
+
/** @trailing_slash */
|
|
15
|
+
build: string;
|
|
16
|
+
/** @trailing_slash */
|
|
17
|
+
build_dev: string;
|
|
18
|
+
config: string;
|
|
19
|
+
}
|
|
20
|
+
export declare const create_paths: (root_dir: string) => Paths;
|
|
21
|
+
export declare const infer_paths: (id: PathId) => Paths;
|
|
22
|
+
export declare const is_gro_id: (id: PathId) => boolean;
|
|
23
|
+
export declare const to_root_path: (id: PathId, p?: Paths) => string;
|
|
24
|
+
export declare const path_id_to_base_path: (path_id: PathId, p?: Paths) => string;
|
|
25
|
+
export declare const base_path_to_path_id: (base_path: string, p?: Paths) => PathId;
|
|
26
|
+
export declare const print_path: (path: string, p?: Paths) => string;
|
|
27
|
+
export declare const replace_extension: (path: string, new_extension: string) => string;
|
|
28
|
+
/**
|
|
29
|
+
* Paths for the user repo.
|
|
30
|
+
*/
|
|
31
|
+
export declare const paths: Paths;
|
|
32
|
+
/** @trailing_slash */
|
|
33
|
+
export declare const GRO_PACKAGE_DIR = "gro/";
|
|
34
|
+
export declare const IS_THIS_GRO: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Paths for the Gro package being used by the user repo.
|
|
37
|
+
*/
|
|
38
|
+
export declare const gro_paths: Paths;
|
|
39
|
+
/** @trailing_slash */
|
|
40
|
+
export declare const GRO_DIST_DIR: string;
|
|
41
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/paths.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAkBrD,eAAO,MAAM,WAAW,QAA2C,CAAC;AACpE,eAAO,MAAM,QAAQ,QAA2B,CAAC;AACjD,sBAAsB;AACtB,eAAO,MAAM,OAAO,QAAiB,CAAC;AACtC,eAAO,MAAM,cAAc,QAA8C,CAAC;AAE1E,MAAM,WAAW,KAAK;IACrB,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,sBAAsB;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,sBAAsB;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,sBAAsB;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,sBAAsB;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,YAAY,GAAI,UAAU,MAAM,KAAG,KAW/C,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,IAAI,MAAM,KAAG,KAA4C,CAAC;AAEtF,eAAO,MAAM,SAAS,GAAI,IAAI,MAAM,KAAG,OACiC,CAAC;AAGzE,eAAO,MAAM,YAAY,GAAI,IAAI,MAAM,EAAE,SAAmB,KAAG,MAClC,CAAC;AAG9B,eAAO,MAAM,oBAAoB,GAAI,SAAS,MAAM,EAAE,SAAwB,KAAG,MACrD,CAAC;AAI7B,eAAO,MAAM,oBAAoB,GAAI,WAAW,MAAM,EAAE,SAA0B,KAAG,MAC3D,CAAC;AAE3B,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,EAAE,SAAqB,KAAG,MAMhE,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,EAAE,eAAe,MAAM,KAAG,MAGvE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,KAAK,OAA8B,CAAC;AAEjD,sBAAsB;AACtB,eAAO,MAAM,eAAe,SAAS,CAAC;AAYtC,eAAO,MAAM,WAAW,SAAsC,CAAC;AAC/D;;GAEG;AACH,eAAO,MAAM,SAAS,OAA2D,CAAC;AAClF,sBAAsB;AACtB,eAAO,MAAM,YAAY,QAAgD,CAAC"}
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { join, extname, relative, basename } from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { ensure_end, strip_end } from '@fuzdev/fuz_util/string.js';
|
|
4
|
+
import { styleText as st } from 'node:util';
|
|
5
|
+
import { GRO_CONFIG_FILENAME, GRO_DEV_DIR, GRO_DIR, SOURCE_DIR, SVELTEKIT_DIST_DIRNAME, } from "./constants.js";
|
|
6
|
+
import { default_svelte_config } from "./svelte_config.js";
|
|
7
|
+
/*
|
|
8
|
+
|
|
9
|
+
A path `id` is an absolute path to the source/.gro/dist directory.
|
|
10
|
+
It's the same name that Rollup uses.
|
|
11
|
+
|
|
12
|
+
*/
|
|
13
|
+
export const LIB_DIRNAME = basename(default_svelte_config.lib_path);
|
|
14
|
+
export const LIB_PATH = SOURCE_DIR + LIB_DIRNAME;
|
|
15
|
+
/** @trailing_slash */
|
|
16
|
+
export const LIB_DIR = LIB_PATH + '/';
|
|
17
|
+
export const ROUTES_DIRNAME = basename(default_svelte_config.routes_path);
|
|
18
|
+
export const create_paths = (root_dir) => {
|
|
19
|
+
// TODO remove reliance on trailing slash towards windows support
|
|
20
|
+
const root = ensure_end(root_dir, '/');
|
|
21
|
+
return {
|
|
22
|
+
root,
|
|
23
|
+
source: root + SOURCE_DIR,
|
|
24
|
+
lib: root + LIB_DIR,
|
|
25
|
+
build: root + GRO_DIR,
|
|
26
|
+
build_dev: root + GRO_DEV_DIR,
|
|
27
|
+
config: root + GRO_CONFIG_FILENAME,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export const infer_paths = (id) => (is_gro_id(id) ? gro_paths : paths);
|
|
31
|
+
export const is_gro_id = (id) => id.startsWith(gro_paths.root) || gro_paths.root === ensure_end(id, '/');
|
|
32
|
+
// '/home/me/app/src/foo/bar/baz.ts' → 'src/foo/bar/baz.ts'
|
|
33
|
+
export const to_root_path = (id, p = infer_paths(id)) => relative(p.root, id) || './';
|
|
34
|
+
// '/home/me/app/src/foo/bar/baz.ts' → 'foo/bar/baz.ts'
|
|
35
|
+
export const path_id_to_base_path = (path_id, p = infer_paths(path_id)) => relative(p.source, path_id);
|
|
36
|
+
// TODO base_path is an obsolete concept, it was a remnant from forcing `src/`
|
|
37
|
+
// 'foo/bar/baz.ts' → '/home/me/app/src/foo/bar/baz.ts'
|
|
38
|
+
export const base_path_to_path_id = (base_path, p = infer_paths(base_path)) => join(p.source, base_path);
|
|
39
|
+
export const print_path = (path, p = infer_paths(path)) => {
|
|
40
|
+
let final_path = strip_end(path, '/') === strip_end(GRO_DIST_DIR, '/') ? 'gro' : to_root_path(path, p);
|
|
41
|
+
final_path =
|
|
42
|
+
final_path === 'gro' ? final_path : final_path[0] === '.' ? final_path : './' + final_path;
|
|
43
|
+
return st('gray', final_path);
|
|
44
|
+
};
|
|
45
|
+
export const replace_extension = (path, new_extension) => {
|
|
46
|
+
const { length } = extname(path);
|
|
47
|
+
return (length === 0 ? path : path.substring(0, path.length - length)) + new_extension;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Paths for the user repo.
|
|
51
|
+
*/
|
|
52
|
+
export const paths = create_paths(process.cwd());
|
|
53
|
+
/** @trailing_slash */
|
|
54
|
+
export const GRO_PACKAGE_DIR = 'gro/';
|
|
55
|
+
// TODO document these conditions with comments
|
|
56
|
+
// TODO there's probably a more robust way to do this
|
|
57
|
+
const filename = fileURLToPath(import.meta.url);
|
|
58
|
+
const gro_package_dir_path = join(filename, filename.includes('/gro/src/lib/')
|
|
59
|
+
? '../../../'
|
|
60
|
+
: filename.includes('/gro/dist/')
|
|
61
|
+
? '../../'
|
|
62
|
+
: '../');
|
|
63
|
+
export const IS_THIS_GRO = gro_package_dir_path === paths.root;
|
|
64
|
+
/**
|
|
65
|
+
* Paths for the Gro package being used by the user repo.
|
|
66
|
+
*/
|
|
67
|
+
export const gro_paths = IS_THIS_GRO ? paths : create_paths(gro_package_dir_path);
|
|
68
|
+
/** @trailing_slash */
|
|
69
|
+
export const GRO_DIST_DIR = gro_paths.root + SVELTEKIT_DIST_DIRNAME + '/';
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { TaskContext } from './task.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Gro `Plugin`s enable custom behavior during `gro dev` and `gro build`.
|
|
4
|
+
* In contrast, `Adapter`s use the results of `gro build` to produce final artifacts.
|
|
5
|
+
*/
|
|
6
|
+
export interface Plugin<TPluginContext extends PluginContext = PluginContext> {
|
|
7
|
+
name: string;
|
|
8
|
+
setup?: (ctx: TPluginContext) => void | Promise<void>;
|
|
9
|
+
adapt?: (ctx: TPluginContext) => void | Promise<void>;
|
|
10
|
+
teardown?: (ctx: TPluginContext) => void | Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export type PluginsCreateConfig<TPluginContext extends PluginContext = PluginContext> = (ctx: TPluginContext) => Array<Plugin<TPluginContext>> | Promise<Array<Plugin<TPluginContext>>>;
|
|
13
|
+
export interface PluginContext<TArgs = object> extends TaskContext<TArgs> {
|
|
14
|
+
dev: boolean;
|
|
15
|
+
watch: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** See `Plugins.create` for a usage example. */
|
|
18
|
+
export declare class Plugins<TPluginContext extends PluginContext> {
|
|
19
|
+
readonly ctx: TPluginContext;
|
|
20
|
+
readonly instances: Array<Plugin<TPluginContext>>;
|
|
21
|
+
constructor(ctx: TPluginContext, instances: Array<Plugin>);
|
|
22
|
+
static create<TPluginContext extends PluginContext>(ctx: TPluginContext): Promise<Plugins<TPluginContext>>;
|
|
23
|
+
setup(): Promise<void>;
|
|
24
|
+
adapt(): Promise<void>;
|
|
25
|
+
teardown(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Replaces a plugin by name in `plugins` without mutating the param.
|
|
29
|
+
* Throws if the plugin name cannot be found.
|
|
30
|
+
* @param plugins - accepts the same types as the return value of `PluginsCreateConfig`
|
|
31
|
+
* @param new_plugin
|
|
32
|
+
* @param name - @default new_plugin.name
|
|
33
|
+
* @returns `plugins` with `new_plugin` at the index of the plugin with `name`
|
|
34
|
+
*/
|
|
35
|
+
export declare const plugin_replace: (plugins: Array<Plugin>, new_plugin: Plugin, name?: string) => Array<Plugin>;
|
|
36
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,WAAW,CAAC;AAE3C;;;GAGG;AACH,MAAM,WAAW,MAAM,CAAC,cAAc,SAAS,aAAa,GAAG,aAAa;IAC3E,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzD;AAED,MAAM,MAAM,mBAAmB,CAAC,cAAc,SAAS,aAAa,GAAG,aAAa,IAAI,CACvF,GAAG,EAAE,cAAc,KACf,KAAK,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;AAE5E,MAAM,WAAW,aAAa,CAAC,KAAK,GAAG,MAAM,CAAE,SAAQ,WAAW,CAAC,KAAK,CAAC;IACxE,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;CACf;AAED,gDAAgD;AAChD,qBAAa,OAAO,CAAC,cAAc,SAAS,aAAa;IACxD,QAAQ,CAAC,GAAG,EAAE,cAAc,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC;gBAEtC,GAAG,EAAE,cAAc,EAAE,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC;WAK5C,MAAM,CAAC,cAAc,SAAS,aAAa,EACvD,GAAG,EAAE,cAAc,GACjB,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAS7B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAetB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAatB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAc/B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GAC1B,SAAS,KAAK,CAAC,MAAM,CAAC,EACtB,YAAY,MAAM,EAClB,aAAsB,KACpB,KAAK,CAAC,MAAM,CAMd,CAAC"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** See `Plugins.create` for a usage example. */
|
|
2
|
+
export class Plugins {
|
|
3
|
+
ctx;
|
|
4
|
+
instances;
|
|
5
|
+
constructor(ctx, instances) {
|
|
6
|
+
this.ctx = ctx;
|
|
7
|
+
this.instances = instances;
|
|
8
|
+
}
|
|
9
|
+
static async create(ctx) {
|
|
10
|
+
const { timings } = ctx;
|
|
11
|
+
const timing_to_create = timings.start('plugins.create');
|
|
12
|
+
const instances = await ctx.config.plugins(ctx);
|
|
13
|
+
const plugins = new Plugins(ctx, instances);
|
|
14
|
+
timing_to_create();
|
|
15
|
+
return plugins;
|
|
16
|
+
}
|
|
17
|
+
async setup() {
|
|
18
|
+
const { ctx, instances } = this;
|
|
19
|
+
if (!instances.length)
|
|
20
|
+
return;
|
|
21
|
+
const { timings, log } = ctx;
|
|
22
|
+
const timing_to_setup = timings.start('plugins.setup');
|
|
23
|
+
for (const plugin of instances) {
|
|
24
|
+
if (!plugin.setup)
|
|
25
|
+
continue;
|
|
26
|
+
log.debug('setup plugin', plugin.name);
|
|
27
|
+
const timing = timings.start(`setup:${plugin.name}`);
|
|
28
|
+
await plugin.setup(ctx); // eslint-disable-line no-await-in-loop
|
|
29
|
+
timing();
|
|
30
|
+
}
|
|
31
|
+
timing_to_setup();
|
|
32
|
+
}
|
|
33
|
+
async adapt() {
|
|
34
|
+
const { ctx, instances } = this;
|
|
35
|
+
const { timings } = ctx;
|
|
36
|
+
const timing_to_run_adapters = timings.start('plugins.adapt');
|
|
37
|
+
for (const plugin of instances) {
|
|
38
|
+
if (!plugin.adapt)
|
|
39
|
+
continue;
|
|
40
|
+
const timing = timings.start(`adapt:${plugin.name}`);
|
|
41
|
+
await plugin.adapt(ctx); // eslint-disable-line no-await-in-loop
|
|
42
|
+
timing();
|
|
43
|
+
}
|
|
44
|
+
timing_to_run_adapters();
|
|
45
|
+
}
|
|
46
|
+
async teardown() {
|
|
47
|
+
const { ctx, instances } = this;
|
|
48
|
+
if (!instances.length)
|
|
49
|
+
return;
|
|
50
|
+
const { timings, log } = ctx;
|
|
51
|
+
const timing_to_teardown = timings.start('plugins.teardown');
|
|
52
|
+
for (const plugin of instances) {
|
|
53
|
+
if (!plugin.teardown)
|
|
54
|
+
continue;
|
|
55
|
+
log.debug('teardown plugin', plugin.name);
|
|
56
|
+
const timing = timings.start(`teardown:${plugin.name}`);
|
|
57
|
+
await plugin.teardown(ctx); // eslint-disable-line no-await-in-loop
|
|
58
|
+
timing();
|
|
59
|
+
}
|
|
60
|
+
timing_to_teardown();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Replaces a plugin by name in `plugins` without mutating the param.
|
|
65
|
+
* Throws if the plugin name cannot be found.
|
|
66
|
+
* @param plugins - accepts the same types as the return value of `PluginsCreateConfig`
|
|
67
|
+
* @param new_plugin
|
|
68
|
+
* @param name - @default new_plugin.name
|
|
69
|
+
* @returns `plugins` with `new_plugin` at the index of the plugin with `name`
|
|
70
|
+
*/
|
|
71
|
+
export const plugin_replace = (plugins, new_plugin, name = new_plugin.name) => {
|
|
72
|
+
const index = plugins.findIndex((p) => p.name === name);
|
|
73
|
+
if (index === -1)
|
|
74
|
+
throw Error('Failed to find plugin to replace: ' + name);
|
|
75
|
+
const replaced = plugins.slice();
|
|
76
|
+
replaced[index] = new_plugin;
|
|
77
|
+
return replaced;
|
|
78
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type Task } from './task.ts';
|
|
3
|
+
/** @nodocs */
|
|
4
|
+
export declare const Args: z.ZodObject<{
|
|
5
|
+
branch: z.ZodDefault<z.ZodString>;
|
|
6
|
+
origin: z.ZodDefault<z.ZodString>;
|
|
7
|
+
changelog: z.ZodDefault<z.ZodString>;
|
|
8
|
+
preserve_changelog: z.ZodDefault<z.ZodBoolean>;
|
|
9
|
+
optional: z.ZodDefault<z.ZodBoolean>;
|
|
10
|
+
dry: z.ZodDefault<z.ZodBoolean>;
|
|
11
|
+
check: z.ZodDefault<z.ZodBoolean>;
|
|
12
|
+
'no-check': z.ZodDefault<z.ZodBoolean>;
|
|
13
|
+
build: z.ZodDefault<z.ZodBoolean>;
|
|
14
|
+
'no-build': z.ZodDefault<z.ZodBoolean>;
|
|
15
|
+
pull: z.ZodDefault<z.ZodBoolean>;
|
|
16
|
+
'no-pull': z.ZodDefault<z.ZodBoolean>;
|
|
17
|
+
sync: z.ZodDefault<z.ZodBoolean>;
|
|
18
|
+
'no-sync': z.ZodDefault<z.ZodBoolean>;
|
|
19
|
+
install: z.ZodDefault<z.ZodBoolean>;
|
|
20
|
+
'no-install': z.ZodDefault<z.ZodBoolean>;
|
|
21
|
+
changeset_cli: z.ZodDefault<z.ZodString>;
|
|
22
|
+
}, z.core.$strict>;
|
|
23
|
+
export type Args = z.infer<typeof Args>;
|
|
24
|
+
/** @nodocs */
|
|
25
|
+
export declare const task: Task<Args>;
|
|
26
|
+
//# sourceMappingURL=publish.task.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish.task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/publish.task.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAYtB,OAAO,EAAY,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AAQ/C,cAAc;AACd,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;kBAuCf,CAAC;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAExC,cAAc;AACd,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,IAAI,CAkK3B,CAAC"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { spawn } from '@fuzdev/fuz_util/process.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { styleText as st } from 'node:util';
|
|
4
|
+
import { fs_exists } from '@fuzdev/fuz_util/fs.js';
|
|
5
|
+
import { GitBranch, GitOrigin, git_check_clean_workspace, git_checkout, git_fetch, git_pull, } from '@fuzdev/fuz_util/git.js';
|
|
6
|
+
import { TaskError } from "./task.js";
|
|
7
|
+
import { package_json_load, package_json_parse_repo_url } from "./package_json.js";
|
|
8
|
+
import { find_cli, spawn_cli } from "./cli.js";
|
|
9
|
+
import { has_sveltekit_library } from "./sveltekit_helpers.js";
|
|
10
|
+
import { update_changelog } from "./changelog.js";
|
|
11
|
+
import { load_from_env } from "./env.js";
|
|
12
|
+
import { CHANGESET_CLI } from "./changeset_helpers.js";
|
|
13
|
+
/** @nodocs */
|
|
14
|
+
export const Args = z.strictObject({
|
|
15
|
+
branch: GitBranch.describe('branch to publish from').default('main'),
|
|
16
|
+
origin: GitOrigin.describe('git origin to publish from').default('origin'),
|
|
17
|
+
changelog: z
|
|
18
|
+
.string()
|
|
19
|
+
.meta({ description: 'file name and path of the changelog' })
|
|
20
|
+
.default('CHANGELOG.md'),
|
|
21
|
+
preserve_changelog: z
|
|
22
|
+
.boolean()
|
|
23
|
+
.meta({
|
|
24
|
+
description: 'opt out of linkifying and formatting the changelog from @changesets/changelog-git',
|
|
25
|
+
})
|
|
26
|
+
.default(false),
|
|
27
|
+
optional: z
|
|
28
|
+
.boolean()
|
|
29
|
+
.meta({ description: 'exit gracefully if there are no changesets' })
|
|
30
|
+
.default(false),
|
|
31
|
+
dry: z
|
|
32
|
+
.boolean()
|
|
33
|
+
.meta({ description: 'build and prepare to publish without actually publishing' })
|
|
34
|
+
.default(false),
|
|
35
|
+
check: z.boolean().meta({ description: 'dual of no-check' }).default(true),
|
|
36
|
+
'no-check': z
|
|
37
|
+
.boolean()
|
|
38
|
+
.meta({ description: 'opt out of checking before publishing' })
|
|
39
|
+
.default(false),
|
|
40
|
+
build: z.boolean().meta({ description: 'dual of no-build' }).default(true),
|
|
41
|
+
'no-build': z.boolean().meta({ description: 'opt out of building' }).default(false),
|
|
42
|
+
pull: z.boolean().meta({ description: 'dual of no-pull' }).default(true),
|
|
43
|
+
'no-pull': z.boolean().meta({ description: 'opt out of git pull' }).default(false),
|
|
44
|
+
sync: z.boolean().meta({ description: 'dual of no-sync' }).default(true),
|
|
45
|
+
'no-sync': z.boolean().meta({ description: 'opt out of gro sync' }).default(false),
|
|
46
|
+
install: z.boolean().meta({ description: 'dual of no-install' }).default(true),
|
|
47
|
+
'no-install': z
|
|
48
|
+
.boolean()
|
|
49
|
+
.meta({ description: 'opt out of installing packages before publishing' })
|
|
50
|
+
.default(false),
|
|
51
|
+
changeset_cli: z.string().meta({ description: 'the changeset CLI to use' }).default(CHANGESET_CLI),
|
|
52
|
+
});
|
|
53
|
+
/** @nodocs */
|
|
54
|
+
export const task = {
|
|
55
|
+
summary: 'bump version, publish to the configured registry, and git push',
|
|
56
|
+
Args,
|
|
57
|
+
run: async ({ args, log, invoke_task, config }) => {
|
|
58
|
+
const { branch, origin, changelog, preserve_changelog, dry, check, build, pull, sync, install, optional, changeset_cli, } = args;
|
|
59
|
+
if (dry) {
|
|
60
|
+
log.info(st('green', 'dry run!'));
|
|
61
|
+
}
|
|
62
|
+
const package_json = await package_json_load();
|
|
63
|
+
const has_sveltekit_library_result = await has_sveltekit_library(package_json);
|
|
64
|
+
if (!has_sveltekit_library_result.ok) {
|
|
65
|
+
throw new TaskError('Failed to find SvelteKit library: ' + has_sveltekit_library_result.message);
|
|
66
|
+
}
|
|
67
|
+
const changelog_exists = await fs_exists(changelog);
|
|
68
|
+
const found_changeset_cli = await find_cli(changeset_cli);
|
|
69
|
+
if (!found_changeset_cli) {
|
|
70
|
+
throw new TaskError('changeset command not found, install @changesets/cli locally or globally');
|
|
71
|
+
}
|
|
72
|
+
// Make sure we're on the right branch:
|
|
73
|
+
await git_fetch(origin, branch);
|
|
74
|
+
await git_checkout(branch);
|
|
75
|
+
if (pull) {
|
|
76
|
+
if (await git_check_clean_workspace()) {
|
|
77
|
+
throw new TaskError('The git workspace is not clean, pass --no-pull to bypass git pull');
|
|
78
|
+
}
|
|
79
|
+
await git_pull(origin, branch);
|
|
80
|
+
}
|
|
81
|
+
// Install packages to ensure deps are current.
|
|
82
|
+
// Handles cases like branch switches where package.json changed.
|
|
83
|
+
// Skip gen because it will run after version bump.
|
|
84
|
+
if (sync || install) {
|
|
85
|
+
if (!sync)
|
|
86
|
+
log.warn('sync is false but install is true, so running sync for install only');
|
|
87
|
+
await invoke_task('sync', { install, gen: false });
|
|
88
|
+
}
|
|
89
|
+
// Check before proceeding, defaults to true.
|
|
90
|
+
if (check) {
|
|
91
|
+
await invoke_task('check', { workspace: true, sync: false });
|
|
92
|
+
}
|
|
93
|
+
let version;
|
|
94
|
+
let optional_and_version_unchanged = false;
|
|
95
|
+
// Bump the version so the package.json is updated before building:
|
|
96
|
+
// TODO problem here is build may fail and put us in a bad state,
|
|
97
|
+
// but I don't see how we could do this to robustly
|
|
98
|
+
// have the new version in the build without building twice -
|
|
99
|
+
// maybe the code should catch the error and revert the version and delete the tag?
|
|
100
|
+
if (dry) {
|
|
101
|
+
log.info('dry run, skipping changeset version');
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
if (typeof package_json.version !== 'string') {
|
|
105
|
+
throw new TaskError('Failed to find package.json version');
|
|
106
|
+
}
|
|
107
|
+
const parsed_repo_url = package_json_parse_repo_url(package_json);
|
|
108
|
+
if (!parsed_repo_url) {
|
|
109
|
+
throw new TaskError('package.json `repository` must contain a repo url (and GitHub only for now, sorry),' +
|
|
110
|
+
' like `git+https://github.com/fuzdev/gro.git` or `https://github.com/fuzdev/gro`' +
|
|
111
|
+
' or an object with the `url` key');
|
|
112
|
+
}
|
|
113
|
+
// This is the first line that alters the repo.
|
|
114
|
+
const changeset_version_result = await spawn_cli(found_changeset_cli, ['version'], log);
|
|
115
|
+
if (!changeset_version_result?.ok) {
|
|
116
|
+
throw Error('changeset version failed: no commits were made: see the error above');
|
|
117
|
+
}
|
|
118
|
+
if (!preserve_changelog) {
|
|
119
|
+
const token = load_from_env('SECRET_GITHUB_API_TOKEN');
|
|
120
|
+
if (!token) {
|
|
121
|
+
log.warn('the env var SECRET_GITHUB_API_TOKEN was not found, so API calls with be unauthorized');
|
|
122
|
+
}
|
|
123
|
+
await update_changelog(parsed_repo_url.owner, parsed_repo_url.repo, changelog, token, log);
|
|
124
|
+
}
|
|
125
|
+
// Update package-lock.json to reflect the new version.
|
|
126
|
+
if (install) {
|
|
127
|
+
const install_result = await spawn(config.pm_cli, ['install']);
|
|
128
|
+
if (!install_result.ok) {
|
|
129
|
+
throw new TaskError(`Failed \`${config.pm_cli} install\` after version bump`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Regenerate files that depend on package.json version.
|
|
133
|
+
// The check above ensures gen is updated.
|
|
134
|
+
await invoke_task('gen');
|
|
135
|
+
const package_json_after_versioning = await package_json_load();
|
|
136
|
+
version = package_json_after_versioning.version;
|
|
137
|
+
if (package_json.version === version) {
|
|
138
|
+
// The version didn't change.
|
|
139
|
+
// For now this is the best detection we have for a no-op `changeset version`.
|
|
140
|
+
if (optional) {
|
|
141
|
+
optional_and_version_unchanged = true;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
// Doesn't build if the version didn't change and publishing isn't optional.
|
|
145
|
+
throw new TaskError(`\`${changeset_cli} version\` failed: are there any changes?`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// Build after the version is bumped so the new version is in the build as needed.
|
|
150
|
+
// Skip sync and install because we already handled both above.
|
|
151
|
+
if (build) {
|
|
152
|
+
await invoke_task('build', { sync: false, install: false });
|
|
153
|
+
}
|
|
154
|
+
// Return early if there are no changes and publishing is optional, but after building,
|
|
155
|
+
// so if callers want to optimize away building
|
|
156
|
+
// they need to do so manually like in `gro release`.
|
|
157
|
+
// TODO this could be cleaned up if tasks had a return value to callers, it could specifiy that it didn't build
|
|
158
|
+
if (optional_and_version_unchanged)
|
|
159
|
+
return;
|
|
160
|
+
if (dry) {
|
|
161
|
+
log.info('publishing branch ' + branch);
|
|
162
|
+
log.info(st('green', 'dry run complete!'));
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const changeset_publish_result = await spawn_cli(found_changeset_cli, ['publish'], log);
|
|
166
|
+
if (!changeset_publish_result?.ok) {
|
|
167
|
+
throw new TaskError(`\`${changeset_cli} publish\` failed - continue manually or try again after running \`git reset --hard\``);
|
|
168
|
+
}
|
|
169
|
+
if (!changelog_exists && (await fs_exists(changelog))) {
|
|
170
|
+
await spawn('git', ['add', changelog]);
|
|
171
|
+
}
|
|
172
|
+
await spawn('git', ['commit', '-a', '-m', `publish v${version}`]);
|
|
173
|
+
await spawn('git', ['push', '--follow-tags']);
|
|
174
|
+
log.info(st('green', `published to branch ${st('cyan', branch)}!`));
|
|
175
|
+
},
|
|
176
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/register.ts"],"names":[],"mappings":""}
|
package/dist/register.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type Task } from './task.ts';
|
|
3
|
+
/** @nodocs */
|
|
4
|
+
export declare const Args: z.ZodObject<{}, z.core.$strict>;
|
|
5
|
+
export type Args = z.infer<typeof Args>;
|
|
6
|
+
/** @nodocs */
|
|
7
|
+
export declare const task: Task<Args>;
|
|
8
|
+
//# sourceMappingURL=reinstall.task.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reinstall.task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/reinstall.task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAItB,OAAO,EAAY,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AAG/C,cAAc;AACd,eAAO,MAAM,IAAI,iCAAqB,CAAC;AACvC,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAExC,cAAc;AACd,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,IAAI,CAgC3B,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { spawn } from '@fuzdev/fuz_util/process.js';
|
|
3
|
+
import { rm } from 'node:fs/promises';
|
|
4
|
+
import { TaskError } from "./task.js";
|
|
5
|
+
import { LOCKFILE_FILENAME, NODE_MODULES_DIRNAME } from "./constants.js";
|
|
6
|
+
/** @nodocs */
|
|
7
|
+
export const Args = z.strictObject({});
|
|
8
|
+
/** @nodocs */
|
|
9
|
+
export const task = {
|
|
10
|
+
summary: `refreshes ${LOCKFILE_FILENAME} with the latest and cleanest deps`,
|
|
11
|
+
Args,
|
|
12
|
+
run: async ({ log, config }) => {
|
|
13
|
+
log.info(`running the initial \`${config.pm_cli} install\``);
|
|
14
|
+
const initial_install_result = await spawn(config.pm_cli, ['install']);
|
|
15
|
+
if (!initial_install_result.ok) {
|
|
16
|
+
throw new TaskError(`Failed initial \`${config.pm_cli} install\``);
|
|
17
|
+
}
|
|
18
|
+
// Deleting both the lockfile and node_modules upgrades to the latest minor/patch versions.
|
|
19
|
+
await Promise.all([rm(LOCKFILE_FILENAME), rm(NODE_MODULES_DIRNAME, { recursive: true })]);
|
|
20
|
+
log.info(`running \`${config.pm_cli} install\` after deleting ${LOCKFILE_FILENAME} and ${NODE_MODULES_DIRNAME}, this can take a while...`);
|
|
21
|
+
const second_install_result = await spawn(config.pm_cli, ['install']);
|
|
22
|
+
if (!second_install_result.ok) {
|
|
23
|
+
throw new TaskError(`Failed \`${config.pm_cli} install\` after deleting ${LOCKFILE_FILENAME} and ${NODE_MODULES_DIRNAME}`);
|
|
24
|
+
}
|
|
25
|
+
// TODO @many this relies on npm behavior that changed in v11
|
|
26
|
+
// Deleting the lockfile and reinstalling cleans the lockfile of unnecessary dep noise,
|
|
27
|
+
// like esbuild's many packages for each platform.
|
|
28
|
+
await rm(LOCKFILE_FILENAME);
|
|
29
|
+
log.info(`running \`${config.pm_cli} install\` one last time to clean ${LOCKFILE_FILENAME}`);
|
|
30
|
+
const final_install_result = await spawn(config.pm_cli, ['install']);
|
|
31
|
+
if (!final_install_result.ok) {
|
|
32
|
+
throw new TaskError(`Failed \`${config.pm_cli} install\``);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { Task } from './task.ts';
|
|
3
|
+
/** @nodocs */
|
|
4
|
+
export declare const Args: z.ZodObject<{}, z.core.$strict>;
|
|
5
|
+
export type Args = z.infer<typeof Args>;
|
|
6
|
+
/** @nodocs */
|
|
7
|
+
export declare const task: Task<Args>;
|
|
8
|
+
//# sourceMappingURL=release.task.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"release.task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/release.task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AAIpC,cAAc;AACd,eAAO,MAAM,IAAI,iCAAqB,CAAC;AACvC,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAExC,cAAc;AACd,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,IAAI,CAc3B,CAAC"}
|