@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
package/dist/github.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FetchValueCache } from '@fuzdev/fuz_util/fetch.js';
|
|
2
|
+
import type { Logger } from '@fuzdev/fuz_util/log.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
export declare const GITHUB_REPO_MATCHER: RegExp;
|
|
5
|
+
export declare const GithubPullRequest: z.ZodObject<{
|
|
6
|
+
url: z.ZodString;
|
|
7
|
+
id: z.ZodNumber;
|
|
8
|
+
html_url: z.ZodString;
|
|
9
|
+
number: z.ZodNumber;
|
|
10
|
+
user: z.ZodObject<{
|
|
11
|
+
login: z.ZodString;
|
|
12
|
+
}, z.core.$loose>;
|
|
13
|
+
}, z.core.$loose>;
|
|
14
|
+
export type GithubPullRequest = z.infer<typeof GithubPullRequest>;
|
|
15
|
+
/**
|
|
16
|
+
* @see https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#list-pull-requests-associated-with-a-commit
|
|
17
|
+
*/
|
|
18
|
+
export declare const github_fetch_commit_prs: (owner: string, repo: string, commit_sha: string, token?: string, log?: Logger, cache?: FetchValueCache, api_version?: string) => Promise<Array<GithubPullRequest> | null>;
|
|
19
|
+
//# sourceMappingURL=github.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/github.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,eAAe,EAAc,MAAM,2BAA2B,CAAC;AACvE,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,eAAO,MAAM,mBAAmB,QAA6B,CAAC;AAE9D,eAAO,MAAM,iBAAiB;;;;;;;;iBAQ5B,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAElE;;GAEG;AACH,eAAO,MAAM,uBAAuB,GACnC,OAAO,MAAM,EACb,MAAM,MAAM,EACZ,YAAY,MAAM,EAClB,QAAQ,MAAM,EACd,MAAM,MAAM,EACZ,QAAQ,eAAe,EACvB,cAAc,MAAM,KAClB,OAAO,CAAC,KAAK,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAazC,CAAC"}
|
package/dist/github.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// TODO if this grows at all, use `@octokit/request`,
|
|
2
|
+
// for now it's just calling a single endpoint so we do it manually
|
|
3
|
+
// and we specify just the types we need
|
|
4
|
+
import { FetchValueCache, fetch_value } from '@fuzdev/fuz_util/fetch.js';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
export const GITHUB_REPO_MATCHER = /.+github.com\/(.+)\/(.+)/;
|
|
7
|
+
export const GithubPullRequest = z.looseObject({
|
|
8
|
+
url: z.string(),
|
|
9
|
+
id: z.number(),
|
|
10
|
+
html_url: z.string(),
|
|
11
|
+
number: z.number(),
|
|
12
|
+
user: z.looseObject({
|
|
13
|
+
login: z.string(),
|
|
14
|
+
}),
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* @see https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#list-pull-requests-associated-with-a-commit
|
|
18
|
+
*/
|
|
19
|
+
export const github_fetch_commit_prs = async (owner, repo, commit_sha, token, log, cache, api_version) => {
|
|
20
|
+
const headers = api_version ? new Headers({ 'x-github-api-version': api_version }) : undefined;
|
|
21
|
+
const url = `https://api.github.com/repos/${owner}/${repo}/commits/${commit_sha}/pulls`;
|
|
22
|
+
const fetched = await fetch_value(url, {
|
|
23
|
+
request: { headers },
|
|
24
|
+
parse: (v) => v.map((p) => GithubPullRequest.parse(p)),
|
|
25
|
+
token,
|
|
26
|
+
cache,
|
|
27
|
+
return_early_from_cache: true,
|
|
28
|
+
log,
|
|
29
|
+
});
|
|
30
|
+
if (!fetched.ok)
|
|
31
|
+
return null;
|
|
32
|
+
return fetched.value;
|
|
33
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CreateGroConfig } from './gro_config.ts';
|
|
2
|
+
/**
|
|
3
|
+
* This is the default config that's passed to `gro.config.ts`
|
|
4
|
+
* if it exists in the current project, and if not, this is the final config.
|
|
5
|
+
* It looks at the SvelteKit config and filesystem and tries to do the right thing:
|
|
6
|
+
*
|
|
7
|
+
* - if `src/routes`, assumes a SvelteKit frontend - respects `KitConfig.kit.files.routes`
|
|
8
|
+
* - if `src/lib`, assumes a Node library - respects `KitConfig.kit.files.lib`
|
|
9
|
+
* - if `src/lib/server/server.ts`, assumes a Node server - needs config
|
|
10
|
+
*/
|
|
11
|
+
declare const config: CreateGroConfig;
|
|
12
|
+
export default config;
|
|
13
|
+
//# sourceMappingURL=gro.config.default.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gro.config.default.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gro.config.default.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,iBAAiB,CAAC;AAUrD;;;;;;;;GAQG;AACH,QAAA,MAAM,MAAM,EAAE,eAoBb,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { gro_plugin_sveltekit_library } from "./gro_plugin_sveltekit_library.js";
|
|
2
|
+
import { has_server, gro_plugin_server } from "./gro_plugin_server.js";
|
|
3
|
+
import { gro_plugin_sveltekit_app } from "./gro_plugin_sveltekit_app.js";
|
|
4
|
+
import { has_sveltekit_app, has_sveltekit_library } from "./sveltekit_helpers.js";
|
|
5
|
+
import { gro_plugin_gen } from "./gro_plugin_gen.js";
|
|
6
|
+
import { package_json_load } from "./package_json.js";
|
|
7
|
+
// TODO hacky, maybe extract utils?
|
|
8
|
+
/**
|
|
9
|
+
* This is the default config that's passed to `gro.config.ts`
|
|
10
|
+
* if it exists in the current project, and if not, this is the final config.
|
|
11
|
+
* It looks at the SvelteKit config and filesystem and tries to do the right thing:
|
|
12
|
+
*
|
|
13
|
+
* - if `src/routes`, assumes a SvelteKit frontend - respects `KitConfig.kit.files.routes`
|
|
14
|
+
* - if `src/lib`, assumes a Node library - respects `KitConfig.kit.files.lib`
|
|
15
|
+
* - if `src/lib/server/server.ts`, assumes a Node server - needs config
|
|
16
|
+
*/
|
|
17
|
+
const config = async (cfg, svelte_config) => {
|
|
18
|
+
const package_json = await package_json_load(); // TODO gets wastefully loaded by some plugins, maybe put in plugin/task context? how does that interact with `map_package_json`?
|
|
19
|
+
const [has_server_result, has_sveltekit_library_result, has_sveltekit_app_result] = await Promise.all([
|
|
20
|
+
has_server(),
|
|
21
|
+
has_sveltekit_library(package_json, svelte_config),
|
|
22
|
+
has_sveltekit_app(),
|
|
23
|
+
]);
|
|
24
|
+
// put things that generate files before SvelteKit so it can see them
|
|
25
|
+
cfg.plugins = () => [
|
|
26
|
+
gro_plugin_gen(),
|
|
27
|
+
has_server_result.ok ? gro_plugin_server() : null,
|
|
28
|
+
has_sveltekit_library_result.ok ? gro_plugin_sveltekit_library() : null,
|
|
29
|
+
has_sveltekit_app_result.ok ? gro_plugin_sveltekit_app() : null,
|
|
30
|
+
].filter((v) => v !== null);
|
|
31
|
+
return cfg;
|
|
32
|
+
};
|
|
33
|
+
export default config;
|
package/dist/gro.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gro.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gro.ts"],"names":[],"mappings":""}
|
package/dist/gro.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env -S node --experimental-import-meta-resolve --experimental-strip-types --disable-warning=ExperimentalWarning
|
|
2
|
+
// @sync Node options to `$lib/gro_helpers.ts`
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { spawn_result_is_exited } from '@fuzdev/fuz_util/process.js';
|
|
5
|
+
import { resolve_gro_module_path, spawn_with_loader } from "./gro_helpers.js";
|
|
6
|
+
/*
|
|
7
|
+
|
|
8
|
+
This file is a loader for the Gro CLI.
|
|
9
|
+
Its only purpose is to import the `invoke.js` script in the correct directory.
|
|
10
|
+
By using `resolve_gro_module_path` it lets the global Gro CLI defer
|
|
11
|
+
to a local installation of Gro if one is available,
|
|
12
|
+
and it also provides special handling for the case
|
|
13
|
+
where we're running Gro inside Gro's own repo for development.
|
|
14
|
+
|
|
15
|
+
*/
|
|
16
|
+
const invoke_path = resolve_gro_module_path('invoke.js');
|
|
17
|
+
const loader_path = join(invoke_path, '../loader.js');
|
|
18
|
+
const spawned = await spawn_with_loader(loader_path, invoke_path, process.argv.slice(2));
|
|
19
|
+
if (!spawned.ok) {
|
|
20
|
+
process.exitCode = spawn_result_is_exited(spawned) ? spawned.code : 1;
|
|
21
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { PathFilter, PathId } from '@fuzdev/fuz_util/path.js';
|
|
2
|
+
import type { PluginsCreateConfig } from './plugin.ts';
|
|
3
|
+
import type { PackageJsonMapper } from './package_json.ts';
|
|
4
|
+
import type { ParsedSvelteConfig } from './svelte_config.ts';
|
|
5
|
+
import type { FilerOptions } from './filer.ts';
|
|
6
|
+
/**
|
|
7
|
+
* SHA-256 hash of empty string, used for configs without build_cache_config.
|
|
8
|
+
* This ensures consistent cache behavior when no custom config is provided.
|
|
9
|
+
*/
|
|
10
|
+
export declare const EMPTY_BUILD_CACHE_CONFIG_HASH = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
|
|
11
|
+
/**
|
|
12
|
+
* The config that users can extend via `gro.config.ts`.
|
|
13
|
+
* This is exposed to users in places like tasks and genfiles.
|
|
14
|
+
* @see https://github.com/fuzdev/gro/blob/main/src/docs/config.md
|
|
15
|
+
*/
|
|
16
|
+
export interface GroConfig extends RawGroConfig {
|
|
17
|
+
/**
|
|
18
|
+
* @see https://github.com/fuzdev/gro/blob/main/src/docs/plugin.md
|
|
19
|
+
*/
|
|
20
|
+
plugins: PluginsCreateConfig;
|
|
21
|
+
/**
|
|
22
|
+
* Maps the project's `package.json` before writing it to the filesystem.
|
|
23
|
+
* The `package_json` argument may be mutated, but the return value is what's used by the caller.
|
|
24
|
+
* Returning `null` is a no-op for the caller.
|
|
25
|
+
*/
|
|
26
|
+
map_package_json: PackageJsonMapper | null;
|
|
27
|
+
/**
|
|
28
|
+
* The root directories to search for tasks given implicit relative input paths.
|
|
29
|
+
* Defaults to `./src/lib`, then the cwd, then the Gro package dist.
|
|
30
|
+
*/
|
|
31
|
+
task_root_dirs: Array<PathId>;
|
|
32
|
+
/**
|
|
33
|
+
* When searching the filsystem for tasks and genfiles,
|
|
34
|
+
* directories and files are included if they pass all of these filters.
|
|
35
|
+
*/
|
|
36
|
+
search_filters: Array<PathFilter>;
|
|
37
|
+
/**
|
|
38
|
+
* The CLI to use that's compatible with `node`.
|
|
39
|
+
*/
|
|
40
|
+
js_cli: string;
|
|
41
|
+
/**
|
|
42
|
+
* The CLI to use that's compatible with `npm install` and `npm link`. Defaults to `'npm'`.
|
|
43
|
+
*/
|
|
44
|
+
pm_cli: string;
|
|
45
|
+
/** @default SVELTE_CONFIG_FILENAME */
|
|
46
|
+
svelte_config_filename?: string;
|
|
47
|
+
/**
|
|
48
|
+
* SHA-256 hash of the user's `build_cache_config` from `gro.config.ts`.
|
|
49
|
+
* This is computed during config normalization and the raw value is immediately deleted.
|
|
50
|
+
* If no `build_cache_config` was provided, this is the hash of an empty string.
|
|
51
|
+
* @see RawGroConfig.build_cache_config
|
|
52
|
+
*/
|
|
53
|
+
build_cache_config_hash: string;
|
|
54
|
+
/**
|
|
55
|
+
* Options passed to the `Filer` for file watching and import resolution.
|
|
56
|
+
* @see FilerOptions
|
|
57
|
+
*/
|
|
58
|
+
filer_options: Partial<FilerOptions> | null;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The relaxed variant of `GroConfig` that users can provide via `gro.config.ts`.
|
|
62
|
+
* Superset of `GroConfig`.
|
|
63
|
+
* @see https://github.com/fuzdev/gro/blob/main/src/docs/config.md
|
|
64
|
+
*/
|
|
65
|
+
export interface RawGroConfig {
|
|
66
|
+
plugins?: PluginsCreateConfig;
|
|
67
|
+
map_package_json?: PackageJsonMapper | null;
|
|
68
|
+
task_root_dirs?: Array<string>;
|
|
69
|
+
search_filters?: PathFilter | Array<PathFilter> | null;
|
|
70
|
+
js_cli?: string;
|
|
71
|
+
pm_cli?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Optional object defining custom build inputs for cache invalidation.
|
|
74
|
+
* This value is hashed during config normalization and used to detect
|
|
75
|
+
* when builds need to be regenerated due to non-source changes.
|
|
76
|
+
*
|
|
77
|
+
* Use cases:
|
|
78
|
+
* - Environment variables baked into build: `{api_url: process.env.PUBLIC_API_URL}`
|
|
79
|
+
* - External data files: `{data: fs.readFileSync('data.json', 'utf-8')}`
|
|
80
|
+
* - Build feature flags: `{enable_analytics: true}`
|
|
81
|
+
*
|
|
82
|
+
* Can be a static object or an async function that returns an object.
|
|
83
|
+
*
|
|
84
|
+
* IMPORTANT: It's safe to include secrets here because they are hashed and `delete`d
|
|
85
|
+
* during config normalization. The raw value is never logged or persisted.
|
|
86
|
+
*/
|
|
87
|
+
build_cache_config?: Record<string, unknown> | (() => Record<string, unknown> | Promise<Record<string, unknown>>);
|
|
88
|
+
/**
|
|
89
|
+
* Options passed to the `Filer` for file watching and import resolution.
|
|
90
|
+
* @see FilerOptions
|
|
91
|
+
*/
|
|
92
|
+
filer_options?: Partial<FilerOptions> | null;
|
|
93
|
+
}
|
|
94
|
+
export type CreateGroConfig = (base_config: GroConfig, svelte_config?: ParsedSvelteConfig) => RawGroConfig | Promise<RawGroConfig>;
|
|
95
|
+
export declare const create_empty_gro_config: () => GroConfig;
|
|
96
|
+
/**
|
|
97
|
+
* The regexp used by default to exclude directories and files
|
|
98
|
+
* when searching the filesystem for tasks and genfiles.
|
|
99
|
+
* Customize via `search_filters` in the `GroConfig`.
|
|
100
|
+
* See the test cases for the exact behavior.
|
|
101
|
+
*/
|
|
102
|
+
export declare const SEARCH_EXCLUDER_DEFAULT: RegExp;
|
|
103
|
+
export declare const EXPORTS_EXCLUDER_DEFAULT: RegExp;
|
|
104
|
+
/**
|
|
105
|
+
* Transforms a `RawGroConfig` to the more strict `GroConfig`.
|
|
106
|
+
* This allows users to provide a more relaxed config.
|
|
107
|
+
* Hashes the `build_cache_config` and deletes the raw value for security.
|
|
108
|
+
*/
|
|
109
|
+
export declare const cook_gro_config: (raw_config: RawGroConfig) => Promise<GroConfig>;
|
|
110
|
+
export interface GroConfigModule {
|
|
111
|
+
readonly default: RawGroConfig | CreateGroConfig;
|
|
112
|
+
}
|
|
113
|
+
export declare const load_gro_config: (dir?: string) => Promise<GroConfig>;
|
|
114
|
+
export declare const validate_gro_config_module: (config_module: any, config_path: string) => asserts config_module is GroConfigModule;
|
|
115
|
+
//# sourceMappingURL=gro_config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gro_config.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gro_config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,UAAU,EAAE,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAejE,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AAE7C;;;GAGG;AACH,eAAO,MAAM,6BAA6B,qEACyB,CAAC;AAEpE;;;;GAIG;AACH,MAAM,WAAW,SAAU,SAAQ,YAAY;IAC9C;;OAEG;IACH,OAAO,EAAE,mBAAmB,CAAC;IAC7B;;;;OAIG;IACH,gBAAgB,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC3C;;;OAGG;IACH,cAAc,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9B;;;OAGG;IACH,cAAc,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IAClC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC;;;;;OAKG;IACH,uBAAuB,EAAE,MAAM,CAAC;IAChC;;;OAGG;IACH,aAAa,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;CAC5C;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC5B,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,gBAAgB,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC5C,cAAc,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC/B,cAAc,CAAC,EAAE,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAAC,EAChB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvB,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACtE;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;CAC7C;AAED,MAAM,MAAM,eAAe,GAAG,CAC7B,WAAW,EAAE,SAAS,EACtB,aAAa,CAAC,EAAE,kBAAkB,KAC9B,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAE1C,eAAO,MAAM,uBAAuB,QAAO,SAczC,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,QAYnC,CAAC;AAEF,eAAO,MAAM,wBAAwB,QAA+C,CAAC;AAErF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAU,YAAY,YAAY,KAAG,OAAO,CAAC,SAAS,CA+CjF,CAAC;AAEF,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,eAAe,CAAC;CACjD;AAED,eAAO,MAAM,eAAe,GAAU,YAAgB,KAAG,OAAO,CAAC,SAAS,CAqBzE,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,CACxC,aAAa,EAAE,GAAG,EAClB,WAAW,EAAE,MAAM,KACf,OAAO,CAAC,aAAa,IAAI,eAS7B,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { join, resolve } from 'node:path';
|
|
10
|
+
import { fs_exists } from '@fuzdev/fuz_util/fs.js';
|
|
11
|
+
import { identity } from '@fuzdev/fuz_util/function.js';
|
|
12
|
+
import { json_stringify_deterministic } from '@fuzdev/fuz_util/json.js';
|
|
13
|
+
import { hash_secure } from '@fuzdev/fuz_util/hash.js';
|
|
14
|
+
import { GRO_DIST_DIR, IS_THIS_GRO, paths } from "./paths.js";
|
|
15
|
+
import { GRO_CONFIG_FILENAME, JS_CLI_DEFAULT, NODE_MODULES_DIRNAME, PM_CLI_DEFAULT, SERVER_DIST_PATH, SVELTEKIT_BUILD_DIRNAME, SVELTEKIT_DIST_DIRNAME, } from "./constants.js";
|
|
16
|
+
import create_default_config from "./gro.config.default.js";
|
|
17
|
+
/**
|
|
18
|
+
* SHA-256 hash of empty string, used for configs without build_cache_config.
|
|
19
|
+
* This ensures consistent cache behavior when no custom config is provided.
|
|
20
|
+
*/
|
|
21
|
+
export const EMPTY_BUILD_CACHE_CONFIG_HASH = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855';
|
|
22
|
+
export const create_empty_gro_config = () => ({
|
|
23
|
+
plugins: () => [],
|
|
24
|
+
map_package_json: identity,
|
|
25
|
+
task_root_dirs: [
|
|
26
|
+
// TODO maybe disable if no SvelteKit `lib` directory? or other detection to improve defaults
|
|
27
|
+
paths.lib,
|
|
28
|
+
IS_THIS_GRO ? null : paths.root,
|
|
29
|
+
IS_THIS_GRO ? null : GRO_DIST_DIR,
|
|
30
|
+
].filter((v) => v !== null),
|
|
31
|
+
search_filters: [(id) => !SEARCH_EXCLUDER_DEFAULT.test(id)],
|
|
32
|
+
js_cli: JS_CLI_DEFAULT,
|
|
33
|
+
pm_cli: PM_CLI_DEFAULT,
|
|
34
|
+
build_cache_config_hash: EMPTY_BUILD_CACHE_CONFIG_HASH,
|
|
35
|
+
filer_options: null,
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* The regexp used by default to exclude directories and files
|
|
39
|
+
* when searching the filesystem for tasks and genfiles.
|
|
40
|
+
* Customize via `search_filters` in the `GroConfig`.
|
|
41
|
+
* See the test cases for the exact behavior.
|
|
42
|
+
*/
|
|
43
|
+
export const SEARCH_EXCLUDER_DEFAULT = new RegExp(`(${'(^|/)\\.[^/]+' + // exclude all `.`-prefixed directories
|
|
44
|
+
// TODO probably change to `pkg.name` instead of this catch-all (also `gro` below)
|
|
45
|
+
`|(^|/)${NODE_MODULES_DIRNAME}(?!/(@[^/]+/)?gro/${SVELTEKIT_DIST_DIRNAME})` + // exclude `node_modules` unless it's to the Gro directory
|
|
46
|
+
`|(^|/)${SVELTEKIT_BUILD_DIRNAME}` + // exclude the SvelteKit build directory
|
|
47
|
+
`|(^|/)(?<!(^|/)gro/)${SVELTEKIT_DIST_DIRNAME}` + // exclude the SvelteKit dist directory unless it's in the Gro directory
|
|
48
|
+
`|(^|/)${SERVER_DIST_PATH}` + // exclude the Gro server plugin dist directory
|
|
49
|
+
'|(^|/)test' + // exclude test directories
|
|
50
|
+
'|(^|/)benchmark' // exclude benchmark directories
|
|
51
|
+
})($|/)`, 'u');
|
|
52
|
+
export const EXPORTS_EXCLUDER_DEFAULT = /(\.md|\.(test|ignore)\.|\/(test|ignore)\/)/;
|
|
53
|
+
/**
|
|
54
|
+
* Transforms a `RawGroConfig` to the more strict `GroConfig`.
|
|
55
|
+
* This allows users to provide a more relaxed config.
|
|
56
|
+
* Hashes the `build_cache_config` and deletes the raw value for security.
|
|
57
|
+
*/
|
|
58
|
+
export const cook_gro_config = async (raw_config) => {
|
|
59
|
+
const empty_config = create_empty_gro_config();
|
|
60
|
+
// All of the raw config properties are optional,
|
|
61
|
+
// so fall back to the empty values when `undefined`.
|
|
62
|
+
const { plugins = empty_config.plugins, map_package_json = empty_config.map_package_json, task_root_dirs = empty_config.task_root_dirs, search_filters = empty_config.search_filters, js_cli = empty_config.js_cli, pm_cli = empty_config.pm_cli, build_cache_config, filer_options = empty_config.filer_options, } = raw_config;
|
|
63
|
+
// Hash build_cache_config and delete the raw value
|
|
64
|
+
// IMPORTANT: Raw value may contain secrets - hash it and delete immediately
|
|
65
|
+
let build_cache_config_hash;
|
|
66
|
+
if (!build_cache_config) {
|
|
67
|
+
build_cache_config_hash = EMPTY_BUILD_CACHE_CONFIG_HASH;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// Resolve if it's a function
|
|
71
|
+
const resolved = typeof build_cache_config === 'function' ? await build_cache_config() : build_cache_config;
|
|
72
|
+
// Hash the JSON representation with deterministic key ordering
|
|
73
|
+
build_cache_config_hash = await hash_secure(json_stringify_deterministic(resolved));
|
|
74
|
+
}
|
|
75
|
+
// Delete the raw value to ensure it doesn't persist in memory
|
|
76
|
+
delete raw_config.build_cache_config;
|
|
77
|
+
return {
|
|
78
|
+
plugins,
|
|
79
|
+
map_package_json,
|
|
80
|
+
task_root_dirs: task_root_dirs.map((p) => resolve(p)),
|
|
81
|
+
search_filters: Array.isArray(search_filters)
|
|
82
|
+
? search_filters
|
|
83
|
+
: search_filters
|
|
84
|
+
? [search_filters]
|
|
85
|
+
: [],
|
|
86
|
+
js_cli,
|
|
87
|
+
pm_cli,
|
|
88
|
+
build_cache_config_hash,
|
|
89
|
+
filer_options: filer_options ?? null,
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
export const load_gro_config = async (dir = paths.root) => {
|
|
93
|
+
const default_config = await cook_gro_config(await create_default_config(create_empty_gro_config()));
|
|
94
|
+
const config_path = join(dir, GRO_CONFIG_FILENAME);
|
|
95
|
+
if (!(await fs_exists(config_path))) {
|
|
96
|
+
// No user config file found, so return the default.
|
|
97
|
+
return default_config;
|
|
98
|
+
}
|
|
99
|
+
// Import the user's `gro.config.ts`.
|
|
100
|
+
const config_module = await import(__rewriteRelativeImportExtension(config_path, true));
|
|
101
|
+
validate_gro_config_module(config_module, config_path);
|
|
102
|
+
return await cook_gro_config(typeof config_module.default === 'function'
|
|
103
|
+
? await config_module.default(default_config)
|
|
104
|
+
: config_module.default);
|
|
105
|
+
};
|
|
106
|
+
export const validate_gro_config_module = (config_module, config_path) => {
|
|
107
|
+
const config = config_module.default;
|
|
108
|
+
if (!config) {
|
|
109
|
+
throw Error(`Invalid Gro config module at ${config_path}: expected a default export`);
|
|
110
|
+
}
|
|
111
|
+
else if (!(typeof config === 'function' || typeof config === 'object')) {
|
|
112
|
+
throw Error(`Invalid Gro config module at ${config_path}: the default export must be a function or object`);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type SpawnResult } from '@fuzdev/fuz_util/process.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a path to an internal Gro file.
|
|
4
|
+
* Prefers any local installation of Gro and falls back to the current CLI context.
|
|
5
|
+
*
|
|
6
|
+
* Uses heuristics to find `path`, so may fail in some rare corner cases.
|
|
7
|
+
* Currently looks for `gro.js` as a sibling to the `path` arg for detection.
|
|
8
|
+
* If this fails for your usecases, rename `gro.js` or open an issue/PR!
|
|
9
|
+
*
|
|
10
|
+
* Used by the CLI and `gro run`.
|
|
11
|
+
*
|
|
12
|
+
* case 1:
|
|
13
|
+
*
|
|
14
|
+
* We're in a directory that has a local installation of Gro at `node_modules/.bin/gro`.
|
|
15
|
+
* Use this local version instead of the global.
|
|
16
|
+
*
|
|
17
|
+
* case 2:
|
|
18
|
+
*
|
|
19
|
+
* We're running Gro inside the Gro repo itself.
|
|
20
|
+
*
|
|
21
|
+
* In this case, we use the build directory instead of dist.
|
|
22
|
+
* There's a paradox here for using Gro inside itself -
|
|
23
|
+
* ideally we use the dist directory because that's what's shipped,
|
|
24
|
+
* but the build directory has all of the tests,
|
|
25
|
+
* and loading two instances of its modules causes problems
|
|
26
|
+
* like `instanceof` checks failing.
|
|
27
|
+
* For now we'll just run from build and see if it causes any problems.
|
|
28
|
+
* There's probably a better design in here somewhere.
|
|
29
|
+
*
|
|
30
|
+
* case 3:
|
|
31
|
+
*
|
|
32
|
+
* Fall back to invoking Gro from wherever the CLI is being executed.
|
|
33
|
+
* When using the global CLI, this uses the global Gro installation.
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
export declare const resolve_gro_module_path: (path?: string) => string;
|
|
37
|
+
/**
|
|
38
|
+
* Runs a file using the Gro loader.
|
|
39
|
+
*
|
|
40
|
+
* Uses conditional exports to correctly set up `esm-env` as development by default,
|
|
41
|
+
* so if you want production set `NODE_ENV=production`.
|
|
42
|
+
*
|
|
43
|
+
* @see https://nodejs.org/api/packages.html#conditional-exports
|
|
44
|
+
*
|
|
45
|
+
* @param loader_path path to loader
|
|
46
|
+
* @param invoke_path path to file to spawn with `node`
|
|
47
|
+
*/
|
|
48
|
+
export declare const spawn_with_loader: (loader_path: string, invoke_path: string, argv: Array<string>, js_cli?: string) => Promise<SpawnResult>;
|
|
49
|
+
//# sourceMappingURL=gro_helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gro_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gro_helpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAQ,KAAK,WAAW,EAAC,MAAM,6BAA6B,CAAC;AAUpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,uBAAuB,GAAI,aAAS,KAAG,MAsBnD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,GAC7B,aAAa,MAAM,EACnB,aAAa,MAAM,EACnB,MAAM,KAAK,CAAC,MAAM,CAAC,EACnB,eAAuB,KACrB,OAAO,CAAC,WAAW,CAoBrB,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { realpathSync, existsSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { spawn } from '@fuzdev/fuz_util/process.js';
|
|
5
|
+
import { JS_CLI_DEFAULT, NODE_MODULES_DIRNAME, SVELTEKIT_DIST_DIRNAME } from "./constants.js";
|
|
6
|
+
/*
|
|
7
|
+
|
|
8
|
+
This module is intended to have minimal dependencies to avoid over-imports in the CLI.
|
|
9
|
+
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Resolves a path to an internal Gro file.
|
|
13
|
+
* Prefers any local installation of Gro and falls back to the current CLI context.
|
|
14
|
+
*
|
|
15
|
+
* Uses heuristics to find `path`, so may fail in some rare corner cases.
|
|
16
|
+
* Currently looks for `gro.js` as a sibling to the `path` arg for detection.
|
|
17
|
+
* If this fails for your usecases, rename `gro.js` or open an issue/PR!
|
|
18
|
+
*
|
|
19
|
+
* Used by the CLI and `gro run`.
|
|
20
|
+
*
|
|
21
|
+
* case 1:
|
|
22
|
+
*
|
|
23
|
+
* We're in a directory that has a local installation of Gro at `node_modules/.bin/gro`.
|
|
24
|
+
* Use this local version instead of the global.
|
|
25
|
+
*
|
|
26
|
+
* case 2:
|
|
27
|
+
*
|
|
28
|
+
* We're running Gro inside the Gro repo itself.
|
|
29
|
+
*
|
|
30
|
+
* In this case, we use the build directory instead of dist.
|
|
31
|
+
* There's a paradox here for using Gro inside itself -
|
|
32
|
+
* ideally we use the dist directory because that's what's shipped,
|
|
33
|
+
* but the build directory has all of the tests,
|
|
34
|
+
* and loading two instances of its modules causes problems
|
|
35
|
+
* like `instanceof` checks failing.
|
|
36
|
+
* For now we'll just run from build and see if it causes any problems.
|
|
37
|
+
* There's probably a better design in here somewhere.
|
|
38
|
+
*
|
|
39
|
+
* case 3:
|
|
40
|
+
*
|
|
41
|
+
* Fall back to invoking Gro from wherever the CLI is being executed.
|
|
42
|
+
* When using the global CLI, this uses the global Gro installation.
|
|
43
|
+
*
|
|
44
|
+
*/
|
|
45
|
+
export const resolve_gro_module_path = (path = '') => {
|
|
46
|
+
const gro_bin_path = resolve(NODE_MODULES_DIRNAME, '.bin/gro');
|
|
47
|
+
// case 1
|
|
48
|
+
// Prefer any locally installed version of Gro.
|
|
49
|
+
// This is really confusing if Gro is installed inside Gro itself,
|
|
50
|
+
// so avoid that when developing Gro.
|
|
51
|
+
if (existsSync(gro_bin_path)) {
|
|
52
|
+
return join(realpathSync(gro_bin_path), '..', path);
|
|
53
|
+
}
|
|
54
|
+
// case 2
|
|
55
|
+
// If running Gro inside its own repo, require the local dist.
|
|
56
|
+
// If the local dist is not yet built it will fall back to the global.
|
|
57
|
+
if (existsSync(join(SVELTEKIT_DIST_DIRNAME, 'gro.js')) &&
|
|
58
|
+
existsSync(join(SVELTEKIT_DIST_DIRNAME, path))) {
|
|
59
|
+
return resolve(SVELTEKIT_DIST_DIRNAME, path);
|
|
60
|
+
}
|
|
61
|
+
// case 3
|
|
62
|
+
// Fall back to the version associated with the running CLI.
|
|
63
|
+
const file_path = fileURLToPath(import.meta.url);
|
|
64
|
+
return join(file_path, '..', path);
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Runs a file using the Gro loader.
|
|
68
|
+
*
|
|
69
|
+
* Uses conditional exports to correctly set up `esm-env` as development by default,
|
|
70
|
+
* so if you want production set `NODE_ENV=production`.
|
|
71
|
+
*
|
|
72
|
+
* @see https://nodejs.org/api/packages.html#conditional-exports
|
|
73
|
+
*
|
|
74
|
+
* @param loader_path path to loader
|
|
75
|
+
* @param invoke_path path to file to spawn with `node`
|
|
76
|
+
*/
|
|
77
|
+
export const spawn_with_loader = (loader_path, invoke_path, argv, js_cli = JS_CLI_DEFAULT) => {
|
|
78
|
+
const args = [
|
|
79
|
+
'--import',
|
|
80
|
+
// This does the same as `$lib/register.ts` but without the cost of importing another file.
|
|
81
|
+
`data:text/javascript,
|
|
82
|
+
import {register} from "node:module";
|
|
83
|
+
import {pathToFileURL} from "node:url";
|
|
84
|
+
register("${loader_path}", pathToFileURL("./"));`,
|
|
85
|
+
// @sync Node options to `$lib/gro.ts`
|
|
86
|
+
'--experimental-import-meta-resolve', // for `import.meta.resolve`
|
|
87
|
+
'--experimental-strip-types',
|
|
88
|
+
'--disable-warning',
|
|
89
|
+
'ExperimentalWarning',
|
|
90
|
+
];
|
|
91
|
+
// In almost all cases we want the exports condition to be `"development"`. Needed for `esm-env`.
|
|
92
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
93
|
+
args.push('-C', 'development'); // same as `--conditions`
|
|
94
|
+
}
|
|
95
|
+
args.push(invoke_path, ...argv);
|
|
96
|
+
return spawn(js_cli, args);
|
|
97
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Args } from '@fuzdev/fuz_util/args.js';
|
|
2
|
+
import type { Plugin } from './plugin.ts';
|
|
3
|
+
export interface TaskArgs extends Args {
|
|
4
|
+
watch?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface GroPluginGenOptions {
|
|
7
|
+
input_paths?: Array<string>;
|
|
8
|
+
root_dirs?: Array<string>;
|
|
9
|
+
flush_debounce_delay?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare const gro_plugin_gen: ({ input_paths, root_dirs, flush_debounce_delay, }?: GroPluginGenOptions) => Plugin;
|
|
12
|
+
//# sourceMappingURL=gro_plugin_gen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gro_plugin_gen.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gro_plugin_gen.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,0BAA0B,CAAC;AAKnD,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAaxC,MAAM,WAAW,QAAS,SAAQ,IAAI;IACrC,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IACnC,WAAW,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5B,SAAS,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,eAAO,MAAM,cAAc,GAAI,oDAI5B,mBAAkC,KAAG,MAoHvC,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { UnreachableError } from '@fuzdev/fuz_util/error.js';
|
|
2
|
+
import { EMPTY_OBJECT } from '@fuzdev/fuz_util/object.js';
|
|
3
|
+
import { throttle } from '@fuzdev/fuz_util/throttle.js';
|
|
4
|
+
import { paths } from "./paths.js";
|
|
5
|
+
import { find_genfiles, is_gen_path } from "./gen.js";
|
|
6
|
+
import { filter_dependents } from "./filer.js";
|
|
7
|
+
import { should_trigger_gen } from "./gen_helpers.js";
|
|
8
|
+
import { spawn_cli } from "./cli.js";
|
|
9
|
+
const FLUSH_DEBOUNCE_DELAY = 500;
|
|
10
|
+
// TODO is cache busting a good idea here to speed up and run in-process?
|
|
11
|
+
// await invoke_task('gen', {_: files, bust_cache: true});
|
|
12
|
+
const gen = (files = []) => spawn_cli('gro', ['gen', ...files]);
|
|
13
|
+
export const gro_plugin_gen = ({ input_paths = [paths.source], root_dirs = [paths.source], flush_debounce_delay = FLUSH_DEBOUNCE_DELAY, } = EMPTY_OBJECT) => {
|
|
14
|
+
const queued_files = new Set();
|
|
15
|
+
let cleanup_watch;
|
|
16
|
+
return {
|
|
17
|
+
name: 'gro_plugin_gen',
|
|
18
|
+
setup: async ({ watch, dev, log, config, filer, invoke_task, timings }) => {
|
|
19
|
+
// For production builds, we assume `gen` is already fresh,
|
|
20
|
+
// which should be checked by CI via `gro check` which calls `gro gen --check`.
|
|
21
|
+
if (!dev)
|
|
22
|
+
return;
|
|
23
|
+
// Do we need to just generate everything once and exit?
|
|
24
|
+
if (!watch) {
|
|
25
|
+
// Run `gen`, first checking if there are any modules to avoid a console error.
|
|
26
|
+
// Some parts of the build may have already happened,
|
|
27
|
+
// making us miss `build` events for gen dependencies,
|
|
28
|
+
// so we run a full `gen` here even if it's usually wasteful.
|
|
29
|
+
const found = await find_genfiles(input_paths, root_dirs, config);
|
|
30
|
+
if (found.ok && found.value.resolved_input_files.length > 0) {
|
|
31
|
+
await gen();
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const queue_gen = (gen_file_id) => {
|
|
36
|
+
queued_files.add(gen_file_id);
|
|
37
|
+
void flush_gen_queue();
|
|
38
|
+
};
|
|
39
|
+
const flush_gen_queue = throttle(async () => {
|
|
40
|
+
const files = Array.from(queued_files);
|
|
41
|
+
log.info(files.length === 0
|
|
42
|
+
? '[gen] generating all files'
|
|
43
|
+
: `[gen] generating ${files.length} file${files.length === 1 ? '' : 's'}`);
|
|
44
|
+
queued_files.clear();
|
|
45
|
+
await gen(files);
|
|
46
|
+
// run again?
|
|
47
|
+
if (queued_files.size > 0) {
|
|
48
|
+
log.info(`[gen] re-running for ${queued_files.size} more queued file${queued_files.size === 1 ? '' : 's'}`);
|
|
49
|
+
setTimeout(flush_gen_queue); // setTimeout is needed bc of throttle behavior
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
log.info('[gen] queue empty, done');
|
|
53
|
+
}
|
|
54
|
+
}, { delay: flush_debounce_delay, when: 'trailing' });
|
|
55
|
+
// When a file builds, check it and its tree of dependents
|
|
56
|
+
// for any `.gen.` files that need to run.
|
|
57
|
+
cleanup_watch = await filer.watch(async (change, source_file) => {
|
|
58
|
+
if (source_file.external)
|
|
59
|
+
return;
|
|
60
|
+
switch (change.type) {
|
|
61
|
+
case 'add':
|
|
62
|
+
case 'update': {
|
|
63
|
+
// Queue the gen file itself if it changed
|
|
64
|
+
if (is_gen_path(source_file.id)) {
|
|
65
|
+
queue_gen(source_file.id);
|
|
66
|
+
}
|
|
67
|
+
// Find all current gen files and check their dependencies
|
|
68
|
+
const gen_files = filer.filter((d) => !d.external && is_gen_path(d.id));
|
|
69
|
+
if (gen_files) {
|
|
70
|
+
for (const gen_file of gen_files) {
|
|
71
|
+
// eslint-disable-next-line no-await-in-loop
|
|
72
|
+
const should_trigger = await should_trigger_gen(gen_file.id, source_file.id, config, filer, log, timings, invoke_task);
|
|
73
|
+
if (should_trigger) {
|
|
74
|
+
queue_gen(gen_file.id);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Check import-based dependents
|
|
79
|
+
const dependent_gen_file_ids = filter_dependents(source_file, filer.get_by_id, is_gen_path, undefined, undefined, log);
|
|
80
|
+
for (const dependent_gen_file_id of dependent_gen_file_ids) {
|
|
81
|
+
queue_gen(dependent_gen_file_id);
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
case 'delete': {
|
|
86
|
+
// I think for the gen plugin this is best as a no-op? avoids broken attempts
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
default:
|
|
90
|
+
throw new UnreachableError(change.type);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
teardown: () => {
|
|
95
|
+
if (cleanup_watch) {
|
|
96
|
+
cleanup_watch();
|
|
97
|
+
cleanup_watch = undefined;
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
};
|