@ryanatkn/gro 0.181.0 → 0.183.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 +1 -1
- package/README.md +6 -1
- package/dist/changeset.task.js +2 -2
- package/dist/check.task.js +2 -2
- package/dist/cli.d.ts +2 -2
- package/dist/cli.js +2 -2
- package/dist/format_file.js +2 -2
- package/dist/gro.config.default.d.ts.map +1 -1
- package/dist/gro.config.default.js +3 -5
- package/dist/gro_plugin_sveltekit_app.d.ts +1 -25
- package/dist/gro_plugin_sveltekit_app.d.ts.map +1 -1
- package/dist/gro_plugin_sveltekit_app.js +6 -160
- package/dist/gro_plugin_sveltekit_library.js +3 -3
- package/dist/invoke_task.js +2 -2
- package/dist/package_json.d.ts +12 -11
- package/dist/package_json.d.ts.map +1 -1
- package/dist/package_json.js +21 -19
- package/dist/publish.task.js +4 -4
- package/dist/release.task.js +2 -2
- package/dist/source_json.d.ts +0 -1
- package/dist/source_json.d.ts.map +1 -1
- package/dist/source_json.js +0 -4
- package/dist/sveltekit_helpers.js +2 -2
- package/dist/sync.task.js +2 -2
- package/dist/test.task.js +3 -3
- package/dist/upgrade.task.d.ts.map +1 -1
- package/dist/upgrade.task.js +3 -3
- package/package.json +11 -12
- package/src/lib/changeset.task.ts +2 -2
- package/src/lib/check.task.ts +2 -2
- package/src/lib/cli.ts +3 -3
- package/src/lib/format_file.ts +2 -2
- package/src/lib/gro.config.default.ts +3 -5
- package/src/lib/gro_plugin_sveltekit_app.ts +5 -216
- package/src/lib/gro_plugin_sveltekit_library.ts +3 -3
- package/src/lib/invoke_task.ts +2 -2
- package/src/lib/package_json.ts +25 -19
- package/src/lib/publish.task.ts +4 -4
- package/src/lib/release.task.ts +2 -2
- package/src/lib/source_json.ts +0 -5
- package/src/lib/sveltekit_helpers.ts +2 -2
- package/src/lib/sync.task.ts +2 -2
- package/src/lib/test.task.ts +3 -3
- package/src/lib/upgrade.task.ts +7 -3
package/dist/source_json.d.ts
CHANGED
|
@@ -3,6 +3,5 @@ import { SourceJson, type ModuleJson } from '@fuzdev/fuz_util/source_json.js';
|
|
|
3
3
|
import type { Logger } from '@fuzdev/fuz_util/log.js';
|
|
4
4
|
export type SourceJsonMapper = (source_json: SourceJson) => SourceJson | null | Promise<SourceJson | null>;
|
|
5
5
|
export declare const source_json_create: (package_json: PackageJson, lib_path?: string, log?: Logger) => Promise<SourceJson>;
|
|
6
|
-
export declare const source_json_serialize: (source_json: SourceJson) => string;
|
|
7
6
|
export declare const source_modules_create: (exports: PackageJsonExports | undefined, lib_path?: string, log?: Logger) => Promise<Array<ModuleJson> | undefined>;
|
|
8
7
|
//# sourceMappingURL=source_json.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source_json.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/source_json.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAE,kBAAkB,EAAC,MAAM,kCAAkC,CAAC;AACtF,OAAO,EAAC,UAAU,EAAE,KAAK,UAAU,EAAuB,MAAM,iCAAiC,CAAC;AAClG,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AAMpD,MAAM,MAAM,gBAAgB,GAAG,CAC9B,WAAW,EAAE,UAAU,KACnB,UAAU,GAAG,IAAI,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;AAEpD,eAAO,MAAM,kBAAkB,GAC9B,cAAc,WAAW,EACzB,WAAW,MAAM,EACjB,MAAM,MAAM,KACV,OAAO,CAAC,UAAU,CAKlB,CAAC;AAEJ,eAAO,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"source_json.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/source_json.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAE,kBAAkB,EAAC,MAAM,kCAAkC,CAAC;AACtF,OAAO,EAAC,UAAU,EAAE,KAAK,UAAU,EAAuB,MAAM,iCAAiC,CAAC;AAClG,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AAMpD,MAAM,MAAM,gBAAgB,GAAG,CAC9B,WAAW,EAAE,UAAU,KACnB,UAAU,GAAG,IAAI,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;AAEpD,eAAO,MAAM,kBAAkB,GAC9B,cAAc,WAAW,EACzB,WAAW,MAAM,EACjB,MAAM,MAAM,KACV,OAAO,CAAC,UAAU,CAKlB,CAAC;AAEJ,eAAO,MAAM,qBAAqB,GACjC,SAAS,kBAAkB,GAAG,SAAS,EACvC,iBAAoB,EACpB,MAAM,MAAM,KACV,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,SAAS,CAgDvC,CAAC"}
|
package/dist/source_json.js
CHANGED
|
@@ -11,10 +11,6 @@ export const source_json_create = async (package_json, lib_path, log) => SourceJ
|
|
|
11
11
|
version: package_json.version,
|
|
12
12
|
modules: await source_modules_create(package_json.exports, lib_path, log),
|
|
13
13
|
});
|
|
14
|
-
export const source_json_serialize = (source_json) => {
|
|
15
|
-
const parsed = SourceJson.parse(source_json);
|
|
16
|
-
return JSON.stringify(parsed, null, 2) + '\n';
|
|
17
|
-
};
|
|
18
14
|
export const source_modules_create = async (exports, lib_path = paths.lib, log) => {
|
|
19
15
|
if (!exports)
|
|
20
16
|
return;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
import { fs_exists } from '@fuzdev/fuz_util/fs.js';
|
|
3
|
-
import {
|
|
3
|
+
import { package_json_has_dependency } from "./package_json.js";
|
|
4
4
|
import { default_svelte_config } from "./svelte_config.js";
|
|
5
5
|
import { SVELTE_CONFIG_FILENAME, SVELTEKIT_DEV_DIRNAME, PM_CLI_DEFAULT, SVELTE_PACKAGE_DEP_NAME, SVELTEKIT_CLI, } from "./constants.js";
|
|
6
6
|
import { find_cli, spawn_cli, to_cli_name } from "./cli.js";
|
|
@@ -21,7 +21,7 @@ export const has_sveltekit_library = async (package_json, svelte_config = defaul
|
|
|
21
21
|
if (!(await fs_exists(svelte_config.lib_path))) {
|
|
22
22
|
return { ok: false, message: `no SvelteKit lib directory found at ${svelte_config.lib_path}` };
|
|
23
23
|
}
|
|
24
|
-
if (!
|
|
24
|
+
if (!package_json_has_dependency(dep_name, package_json)) {
|
|
25
25
|
return {
|
|
26
26
|
ok: false,
|
|
27
27
|
message: `no dependency found in package.json for ${dep_name}`,
|
package/dist/sync.task.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { spawn } from '@fuzdev/fuz_util/process.js';
|
|
3
3
|
import { TaskError } from "./task.js";
|
|
4
|
-
import {
|
|
4
|
+
import { package_json_sync } from "./package_json.js";
|
|
5
5
|
import { sveltekit_sync } from "./sveltekit_helpers.js";
|
|
6
6
|
/** @nodocs */
|
|
7
7
|
export const Args = z.strictObject({
|
|
@@ -30,7 +30,7 @@ export const task = {
|
|
|
30
30
|
log.info('synced SvelteKit');
|
|
31
31
|
}
|
|
32
32
|
if (package_json && config.map_package_json) {
|
|
33
|
-
await
|
|
33
|
+
await package_json_sync(config.map_package_json, log);
|
|
34
34
|
}
|
|
35
35
|
if (gen) {
|
|
36
36
|
await invoke_task('gen');
|
package/dist/test.task.js
CHANGED
|
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import { spawn_cli } from './cli.js';
|
|
3
3
|
import { TaskError } from "./task.js";
|
|
4
4
|
import { find_cli } from "./cli.js";
|
|
5
|
-
import {
|
|
5
|
+
import { package_json_has_dependency, package_json_load } from "./package_json.js";
|
|
6
6
|
import { serialize_args, to_implicit_forwarded_args } from "./args.js";
|
|
7
7
|
import { VITEST_CLI } from "./constants.js";
|
|
8
8
|
import { paths } from "./paths.js";
|
|
@@ -25,8 +25,8 @@ export const task = {
|
|
|
25
25
|
Args,
|
|
26
26
|
run: async ({ args }) => {
|
|
27
27
|
const { _: patterns, dir, fail_without_tests, t } = args;
|
|
28
|
-
const package_json = await
|
|
29
|
-
if (!
|
|
28
|
+
const package_json = await package_json_load();
|
|
29
|
+
if (!package_json_has_dependency(VITEST_CLI, package_json)) {
|
|
30
30
|
throw new TaskError('no test runner found, install vitest');
|
|
31
31
|
}
|
|
32
32
|
if (!(await find_cli(VITEST_CLI))) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upgrade.task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/upgrade.task.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAItB,OAAO,EAAY,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"upgrade.task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/upgrade.task.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAItB,OAAO,EAAY,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AAU/C,cAAc;AACd,eAAO,MAAM,IAAI;;;;;;;;;;;;kBAiCf,CAAC;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAExC,cAAc;AACd,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,IAAI,CA4E3B,CAAC"}
|
package/dist/upgrade.task.js
CHANGED
|
@@ -3,7 +3,7 @@ import { z } from 'zod';
|
|
|
3
3
|
import { rm } from 'node:fs/promises';
|
|
4
4
|
import { GitOrigin, git_pull } from '@fuzdev/fuz_util/git.js';
|
|
5
5
|
import { TaskError } from "./task.js";
|
|
6
|
-
import {
|
|
6
|
+
import { package_json_extract_dependencies, package_json_load, } from "./package_json.js";
|
|
7
7
|
import { spawn_cli } from "./cli.js";
|
|
8
8
|
import { serialize_args, to_forwarded_args } from "./args.js";
|
|
9
9
|
import { NODE_MODULES_DIRNAME } from "./constants.js";
|
|
@@ -63,8 +63,8 @@ export const task = {
|
|
|
63
63
|
log.info(`deleting lockfile at`, lockfile_path);
|
|
64
64
|
await rm(lockfile_path, { force: true });
|
|
65
65
|
}
|
|
66
|
-
const package_json = await
|
|
67
|
-
const all_deps =
|
|
66
|
+
const package_json = await package_json_load();
|
|
67
|
+
const all_deps = package_json_extract_dependencies(package_json);
|
|
68
68
|
const deps = only.length
|
|
69
69
|
? all_deps.filter((d) => only.includes(d.name))
|
|
70
70
|
: all_deps.filter((d) => !_.includes(d.name));
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ryanatkn/gro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.183.0",
|
|
4
4
|
"description": "task runner and toolkit extending SvelteKit",
|
|
5
5
|
"motto": "generate, run, optimize",
|
|
6
6
|
"glyph": "🌰",
|
|
7
7
|
"logo": "logo.svg",
|
|
8
8
|
"logo_alt": "a pixelated green oak acorn with a glint of sun",
|
|
9
|
-
"public": true,
|
|
10
9
|
"license": "MIT",
|
|
11
10
|
"homepage": "https://gro.ryanatkn.com/",
|
|
12
11
|
"author": {
|
|
@@ -82,24 +81,24 @@
|
|
|
82
81
|
"devDependencies": {
|
|
83
82
|
"@changesets/changelog-git": "^0.2.1",
|
|
84
83
|
"@changesets/types": "^6.1.0",
|
|
85
|
-
"@fuzdev/fuz_code": "^0.
|
|
86
|
-
"@fuzdev/fuz_css": "^0.
|
|
87
|
-
"@fuzdev/fuz_ui": "^0.
|
|
88
|
-
"@fuzdev/fuz_util": "^0.
|
|
84
|
+
"@fuzdev/fuz_code": "^0.38.0",
|
|
85
|
+
"@fuzdev/fuz_css": "^0.42.1",
|
|
86
|
+
"@fuzdev/fuz_ui": "^0.173.0",
|
|
87
|
+
"@fuzdev/fuz_util": "^0.45.0",
|
|
89
88
|
"@ryanatkn/eslint-config": "^0.9.0",
|
|
90
89
|
"@sveltejs/adapter-static": "^3.0.10",
|
|
91
|
-
"@sveltejs/kit": "^2.49.
|
|
90
|
+
"@sveltejs/kit": "^2.49.1",
|
|
92
91
|
"@sveltejs/package": "^2.5.7",
|
|
93
92
|
"@sveltejs/vite-plugin-svelte": "^6.2.1",
|
|
94
93
|
"@types/node": "^24.10.1",
|
|
95
|
-
"esbuild": "^0.27.
|
|
94
|
+
"esbuild": "^0.27.1",
|
|
96
95
|
"eslint": "^9.39.1",
|
|
97
|
-
"eslint-plugin-svelte": "^3.13.
|
|
98
|
-
"svelte": "^5.45.
|
|
96
|
+
"eslint-plugin-svelte": "^3.13.1",
|
|
97
|
+
"svelte": "^5.45.6",
|
|
99
98
|
"svelte-check": "^4.3.4",
|
|
100
99
|
"typescript": "^5.9.3",
|
|
101
|
-
"typescript-eslint": "^8.48.
|
|
102
|
-
"vitest": "^4.0.
|
|
100
|
+
"typescript-eslint": "^8.48.1",
|
|
101
|
+
"vitest": "^4.0.15"
|
|
103
102
|
},
|
|
104
103
|
"prettier": {
|
|
105
104
|
"plugins": [
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
CHANGESET_PUBLIC_ACCESS,
|
|
23
23
|
CHANGESET_RESTRICTED_ACCESS,
|
|
24
24
|
} from './changeset_helpers.ts';
|
|
25
|
-
import {
|
|
25
|
+
import {package_json_load} from './package_json.ts';
|
|
26
26
|
|
|
27
27
|
/** @nodocs */
|
|
28
28
|
export const Args = z.strictObject({
|
|
@@ -99,7 +99,7 @@ export const task: Task<Args> = {
|
|
|
99
99
|
);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
const package_json = await
|
|
102
|
+
const package_json = await package_json_load();
|
|
103
103
|
|
|
104
104
|
const has_sveltekit_library_result = await has_sveltekit_library(package_json, svelte_config);
|
|
105
105
|
if (!has_sveltekit_library_result.ok) {
|
package/src/lib/check.task.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {styleText as st} from 'node:util';
|
|
|
4
4
|
import {git_check_clean_workspace} from '@fuzdev/fuz_util/git.js';
|
|
5
5
|
|
|
6
6
|
import {TaskError, type Task} from './task.ts';
|
|
7
|
-
import {
|
|
7
|
+
import {package_json_sync} from './package_json.ts';
|
|
8
8
|
|
|
9
9
|
/** @nodocs */
|
|
10
10
|
export const Args = z.strictObject({
|
|
@@ -62,7 +62,7 @@ export const task: Task<Args> = {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
if (package_json && config.map_package_json) {
|
|
65
|
-
const {changed} = await
|
|
65
|
+
const {changed} = await package_json_sync(config.map_package_json, log, false);
|
|
66
66
|
if (changed) {
|
|
67
67
|
throw new TaskError('package.json is out of date, run `gro sync` to update it');
|
|
68
68
|
} else {
|
package/src/lib/cli.ts
CHANGED
|
@@ -15,7 +15,7 @@ import type {PathId} from '@fuzdev/fuz_util/path.js';
|
|
|
15
15
|
import {NODE_MODULES_DIRNAME} from './constants.ts';
|
|
16
16
|
import {print_command_args} from './args.ts';
|
|
17
17
|
|
|
18
|
-
// TODO maybe upstream to
|
|
18
|
+
// TODO maybe upstream to fuz_util?
|
|
19
19
|
|
|
20
20
|
export type Cli =
|
|
21
21
|
| {kind: 'local'; name: string; id: PathId}
|
|
@@ -42,7 +42,7 @@ export const find_cli = async (
|
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* Spawns a CLI if available using
|
|
45
|
+
* Spawns a CLI if available using fuz_util's `spawn`.
|
|
46
46
|
* If a string is provided for `name_or_cli`, it checks first local to the cwd and then globally.
|
|
47
47
|
* @returns `undefined` if no CLI is found, or the spawn result
|
|
48
48
|
*/
|
|
@@ -58,7 +58,7 @@ export const spawn_cli = async (
|
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
|
-
* Spawns a CLI if available using
|
|
61
|
+
* Spawns a CLI if available using fuz_util's `spawn_process`.
|
|
62
62
|
* If a string is provided for `name_or_cli`, it checks first local to the cwd and then globally.
|
|
63
63
|
* @returns `undefined` if no CLI is found, or the spawn result
|
|
64
64
|
*/
|
package/src/lib/format_file.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import prettier from 'prettier';
|
|
2
2
|
import {extname} from 'node:path';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {package_json_load} from './package_json.ts';
|
|
5
5
|
|
|
6
6
|
let cached_base_options: prettier.Options | undefined;
|
|
7
7
|
|
|
@@ -19,7 +19,7 @@ export const format_file = async (
|
|
|
19
19
|
const final_base_options =
|
|
20
20
|
base_options !== undefined
|
|
21
21
|
? base_options
|
|
22
|
-
: (cached_base_options = (await
|
|
22
|
+
: (cached_base_options = (await package_json_load()).prettier as any);
|
|
23
23
|
let final_options = options;
|
|
24
24
|
if (options.filepath && !options.parser) {
|
|
25
25
|
const {filepath, ...rest} = options;
|
|
@@ -4,7 +4,7 @@ import {has_server, gro_plugin_server} from './gro_plugin_server.ts';
|
|
|
4
4
|
import {gro_plugin_sveltekit_app} from './gro_plugin_sveltekit_app.ts';
|
|
5
5
|
import {has_sveltekit_app, has_sveltekit_library} from './sveltekit_helpers.ts';
|
|
6
6
|
import {gro_plugin_gen} from './gro_plugin_gen.ts';
|
|
7
|
-
import {
|
|
7
|
+
import {package_json_load} from './package_json.ts';
|
|
8
8
|
|
|
9
9
|
// TODO hacky, maybe extract utils?
|
|
10
10
|
|
|
@@ -18,7 +18,7 @@ import {load_package_json} from './package_json.ts';
|
|
|
18
18
|
* - if `src/lib/server/server.ts`, assumes a Node server - needs config
|
|
19
19
|
*/
|
|
20
20
|
const config: CreateGroConfig = async (cfg, svelte_config) => {
|
|
21
|
-
const package_json = await
|
|
21
|
+
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`?
|
|
22
22
|
|
|
23
23
|
const [has_server_result, has_sveltekit_library_result, has_sveltekit_app_result] =
|
|
24
24
|
await Promise.all([
|
|
@@ -33,9 +33,7 @@ const config: CreateGroConfig = async (cfg, svelte_config) => {
|
|
|
33
33
|
gro_plugin_gen(),
|
|
34
34
|
has_server_result.ok ? gro_plugin_server() : null,
|
|
35
35
|
has_sveltekit_library_result.ok ? gro_plugin_sveltekit_library() : null,
|
|
36
|
-
has_sveltekit_app_result.ok
|
|
37
|
-
? gro_plugin_sveltekit_app({host_target: has_server_result.ok ? 'node' : 'github_pages'})
|
|
38
|
-
: null,
|
|
36
|
+
has_sveltekit_app_result.ok ? gro_plugin_sveltekit_app() : null,
|
|
39
37
|
].filter((v) => v !== null);
|
|
40
38
|
|
|
41
39
|
return cfg;
|
|
@@ -1,57 +1,19 @@
|
|
|
1
1
|
import type {SpawnedProcess} from '@fuzdev/fuz_util/process.js';
|
|
2
|
-
import {cp, mkdir, rm, writeFile} from 'node:fs/promises';
|
|
3
|
-
import {dirname, join} from 'node:path';
|
|
4
|
-
import {fs_exists} from '@fuzdev/fuz_util/fs.js';
|
|
5
2
|
|
|
6
3
|
import type {Plugin} from './plugin.ts';
|
|
7
4
|
import {serialize_args, to_forwarded_args} from './args.ts';
|
|
8
|
-
import {serialize_package_json, type PackageJsonMapper, load_package_json} from './package_json.ts';
|
|
9
5
|
import {TaskError} from './task.ts';
|
|
10
6
|
import {find_cli, spawn_cli, spawn_cli_process} from './cli.ts';
|
|
11
|
-
import {
|
|
12
|
-
import {EXPORTS_EXCLUDER_DEFAULT} from './gro_config.ts';
|
|
13
|
-
import {default_svelte_config} from './svelte_config.ts';
|
|
14
|
-
import {SOURCE_DIRNAME, VITE_CLI} from './constants.ts';
|
|
7
|
+
import {VITE_CLI} from './constants.ts';
|
|
15
8
|
|
|
16
9
|
export interface GroPluginSveltekitAppOptions {
|
|
17
|
-
/**
|
|
18
|
-
* Used for finalizing a SvelteKit build like adding a `.nojekyll` file for GitHub Pages.
|
|
19
|
-
* @default 'github_pages'
|
|
20
|
-
*/
|
|
21
|
-
host_target?: HostTarget;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* If truthy, adds `/.well-known/package.json` to the static output.
|
|
25
|
-
* If a function, maps the value.
|
|
26
|
-
*/
|
|
27
|
-
well_known_package_json?: boolean | PackageJsonMapper;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* If truthy, adds `/.well-known/source.json` and `/.well-known/src/` to the static output.
|
|
31
|
-
* If a function, maps the value.
|
|
32
|
-
*/
|
|
33
|
-
well_known_source_json?: boolean | SourceJsonMapper;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* If truthy, copies `src/` to `/.well-known/src/` to the static output.
|
|
37
|
-
* Pass a function to customize which files get copied.
|
|
38
|
-
*/
|
|
39
|
-
well_known_src_files?: boolean | CopyFileFilter;
|
|
40
10
|
/**
|
|
41
11
|
* The Vite CLI to use.
|
|
42
12
|
*/
|
|
43
13
|
vite_cli?: string;
|
|
44
14
|
}
|
|
45
15
|
|
|
46
|
-
export type HostTarget = 'github_pages' | 'static' | 'node';
|
|
47
|
-
|
|
48
|
-
export type CopyFileFilter = (file_path: string) => boolean;
|
|
49
|
-
|
|
50
16
|
export const gro_plugin_sveltekit_app = ({
|
|
51
|
-
host_target = 'github_pages',
|
|
52
|
-
well_known_package_json,
|
|
53
|
-
well_known_source_json,
|
|
54
|
-
well_known_src_files,
|
|
55
17
|
vite_cli = VITE_CLI,
|
|
56
18
|
}: GroPluginSveltekitAppOptions = {}): Plugin => {
|
|
57
19
|
let sveltekit_process: SpawnedProcess | undefined = undefined;
|
|
@@ -76,89 +38,11 @@ export const gro_plugin_sveltekit_app = ({
|
|
|
76
38
|
}
|
|
77
39
|
} else {
|
|
78
40
|
// `vite build` in production mode
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
well_known_package_json = package_json.public; // eslint-disable-line no-param-reassign
|
|
84
|
-
}
|
|
85
|
-
const mapped_package_json = !well_known_package_json
|
|
86
|
-
? null
|
|
87
|
-
: well_known_package_json === true
|
|
88
|
-
? package_json
|
|
89
|
-
: await well_known_package_json(package_json);
|
|
90
|
-
const serialized_package_json =
|
|
91
|
-
mapped_package_json && serialize_package_json(mapped_package_json);
|
|
92
|
-
|
|
93
|
-
// `.well-known/source.json` and `.well-known/src/`
|
|
94
|
-
const final_package_json = mapped_package_json ?? package_json;
|
|
95
|
-
const source_json = await source_json_create(final_package_json, undefined, log);
|
|
96
|
-
if (well_known_source_json === undefined) {
|
|
97
|
-
well_known_source_json = final_package_json.public; // eslint-disable-line no-param-reassign
|
|
41
|
+
const serialized_args = ['build', ...serialize_args(to_forwarded_args(vite_cli))];
|
|
42
|
+
const spawned = await spawn_cli(found_vite_cli, serialized_args, log);
|
|
43
|
+
if (!spawned?.ok) {
|
|
44
|
+
throw new TaskError(`${vite_cli} build failed with exit code ${spawned?.code}`);
|
|
98
45
|
}
|
|
99
|
-
const mapped_source_json = !well_known_source_json
|
|
100
|
-
? null
|
|
101
|
-
: well_known_source_json === true
|
|
102
|
-
? source_json
|
|
103
|
-
: await well_known_source_json(source_json);
|
|
104
|
-
const serialized_source_json =
|
|
105
|
-
mapped_source_json && source_json_serialize(mapped_source_json);
|
|
106
|
-
|
|
107
|
-
// TODO this strategy means the files aren't available during development --
|
|
108
|
-
// maybe a Vite middleware is best? what if this plugin added its plugin to your `vite.config.ts`?
|
|
109
|
-
|
|
110
|
-
// copy files to `static` before building, in such a way
|
|
111
|
-
// that's non-destructive to existing files and dirs and easy to clean up
|
|
112
|
-
const {assets_path} = default_svelte_config;
|
|
113
|
-
const cleanup_promises = [
|
|
114
|
-
serialized_package_json
|
|
115
|
-
? create_temporarily(
|
|
116
|
-
join(assets_path, '.well-known/package.json'),
|
|
117
|
-
serialized_package_json,
|
|
118
|
-
)
|
|
119
|
-
: null,
|
|
120
|
-
serialized_source_json
|
|
121
|
-
? create_temporarily(
|
|
122
|
-
join(assets_path, '.well-known/source.json'),
|
|
123
|
-
serialized_source_json,
|
|
124
|
-
)
|
|
125
|
-
: null,
|
|
126
|
-
serialized_source_json && well_known_src_files
|
|
127
|
-
? copy_temporarily(
|
|
128
|
-
SOURCE_DIRNAME,
|
|
129
|
-
assets_path,
|
|
130
|
-
'.well-known',
|
|
131
|
-
well_known_src_files === true
|
|
132
|
-
? (file_path) => !EXPORTS_EXCLUDER_DEFAULT.test(file_path)
|
|
133
|
-
: well_known_src_files,
|
|
134
|
-
)
|
|
135
|
-
: null,
|
|
136
|
-
/**
|
|
137
|
-
* GitHub pages processes everything with Jekyll by default,
|
|
138
|
-
* breaking things like files and dirs prefixed with an underscore.
|
|
139
|
-
* This adds a `.nojekyll` file to the root of the output
|
|
140
|
-
* to tell GitHub Pages to treat the outputs as plain static files.
|
|
141
|
-
*/
|
|
142
|
-
host_target === 'github_pages'
|
|
143
|
-
? create_temporarily(join(assets_path, '.nojekyll'), '')
|
|
144
|
-
: null,
|
|
145
|
-
].filter((v): v is Promise<AsyncCleanup> => v != null);
|
|
146
|
-
const cleanups = await Promise.all(cleanup_promises);
|
|
147
|
-
const cleanup = async () => {
|
|
148
|
-
// eslint-disable-next-line no-await-in-loop
|
|
149
|
-
for (const c of cleanups) await c();
|
|
150
|
-
};
|
|
151
|
-
try {
|
|
152
|
-
const serialized_args = ['build', ...serialize_args(to_forwarded_args(vite_cli))];
|
|
153
|
-
const spawned = await spawn_cli(found_vite_cli, serialized_args, log);
|
|
154
|
-
if (!spawned?.ok) {
|
|
155
|
-
throw new TaskError(`${vite_cli} build failed with exit code ${spawned?.code}`);
|
|
156
|
-
}
|
|
157
|
-
} catch (error) {
|
|
158
|
-
await cleanup();
|
|
159
|
-
throw error;
|
|
160
|
-
}
|
|
161
|
-
await cleanup();
|
|
162
46
|
}
|
|
163
47
|
},
|
|
164
48
|
teardown: async () => {
|
|
@@ -169,98 +53,3 @@ export const gro_plugin_sveltekit_app = ({
|
|
|
169
53
|
},
|
|
170
54
|
};
|
|
171
55
|
};
|
|
172
|
-
|
|
173
|
-
type AsyncCleanup = () => Promise<void>;
|
|
174
|
-
|
|
175
|
-
// TODO probably extract these, and create a common helper or merge them
|
|
176
|
-
|
|
177
|
-
const copy_temporarily = async (
|
|
178
|
-
source_path: string,
|
|
179
|
-
dest_dir: string,
|
|
180
|
-
dest_base_dir = '',
|
|
181
|
-
filter?: CopyFileFilter,
|
|
182
|
-
): Promise<AsyncCleanup> => {
|
|
183
|
-
const path = join(dest_dir, dest_base_dir, source_path);
|
|
184
|
-
const dir = dirname(path);
|
|
185
|
-
|
|
186
|
-
const dir_already_exists = await fs_exists(dir);
|
|
187
|
-
let root_created_dir: string | undefined;
|
|
188
|
-
if (!dir_already_exists) {
|
|
189
|
-
root_created_dir = await to_root_dir_that_doesnt_exist(dir);
|
|
190
|
-
if (!root_created_dir) throw Error();
|
|
191
|
-
await mkdir(dir, {recursive: true});
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const path_already_exists = await fs_exists(path);
|
|
195
|
-
if (!path_already_exists) {
|
|
196
|
-
await cp(source_path, path, {recursive: true, filter});
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return async () => {
|
|
200
|
-
if (!dir_already_exists) {
|
|
201
|
-
if (!root_created_dir) throw Error();
|
|
202
|
-
if (await fs_exists(root_created_dir)) {
|
|
203
|
-
await rm(root_created_dir, {recursive: true});
|
|
204
|
-
}
|
|
205
|
-
} else if (!path_already_exists) {
|
|
206
|
-
if (await fs_exists(path)) {
|
|
207
|
-
await rm(path, {recursive: true});
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Creates a file at `path` with `contents` if it doesn't already exist,
|
|
215
|
-
* and returns a function that deletes the file and any created directories.
|
|
216
|
-
* @param path
|
|
217
|
-
* @param contents
|
|
218
|
-
* @returns cleanup function that deletes the file and any created dirs
|
|
219
|
-
*/
|
|
220
|
-
const create_temporarily = async (path: string, contents: string): Promise<AsyncCleanup> => {
|
|
221
|
-
const dir = dirname(path);
|
|
222
|
-
|
|
223
|
-
const dir_already_exists = await fs_exists(dir);
|
|
224
|
-
let root_created_dir: string | undefined;
|
|
225
|
-
if (!dir_already_exists) {
|
|
226
|
-
root_created_dir = await to_root_dir_that_doesnt_exist(dir);
|
|
227
|
-
if (!root_created_dir) throw Error();
|
|
228
|
-
await mkdir(dir, {recursive: true});
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
const path_already_exists = await fs_exists(path);
|
|
232
|
-
if (!path_already_exists) {
|
|
233
|
-
await writeFile(path, contents, 'utf8');
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return async () => {
|
|
237
|
-
if (!dir_already_exists) {
|
|
238
|
-
if (!root_created_dir) throw Error();
|
|
239
|
-
if (await fs_exists(root_created_dir)) {
|
|
240
|
-
await rm(root_created_dir, {recursive: true});
|
|
241
|
-
}
|
|
242
|
-
} else if (!path_already_exists) {
|
|
243
|
-
if (await fs_exists(path)) {
|
|
244
|
-
await rm(path);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Niche and probably needs refactoring,
|
|
252
|
-
* for `/a/b/DOESNT_EXIST/NOR_THIS/ETC` returns `/a/b/DOESNT_EXIST`
|
|
253
|
-
* where `/a/b` does exist on the filesystem and `DOESNT_EXIST` is not one of its subdirectories.
|
|
254
|
-
*/
|
|
255
|
-
const to_root_dir_that_doesnt_exist = async (dir: string): Promise<string | undefined> => {
|
|
256
|
-
let prev: string | undefined;
|
|
257
|
-
let d = dir;
|
|
258
|
-
do {
|
|
259
|
-
// eslint-disable-next-line no-await-in-loop
|
|
260
|
-
if (await fs_exists(d)) {
|
|
261
|
-
return prev;
|
|
262
|
-
}
|
|
263
|
-
prev = d;
|
|
264
|
-
} while ((d = dirname(d)));
|
|
265
|
-
throw Error('no dirs exist for ' + dir);
|
|
266
|
-
};
|
|
@@ -2,7 +2,7 @@ import {print_spawn_result, spawn} from '@fuzdev/fuz_util/process.js';
|
|
|
2
2
|
|
|
3
3
|
import type {Plugin} from './plugin.ts';
|
|
4
4
|
import {TaskError} from './task.ts';
|
|
5
|
-
import {
|
|
5
|
+
import {package_json_load} from './package_json.ts';
|
|
6
6
|
import {run_svelte_package, type SveltePackageOptions} from './sveltekit_helpers.ts';
|
|
7
7
|
import {SVELTE_PACKAGE_CLI} from './constants.ts';
|
|
8
8
|
|
|
@@ -27,7 +27,7 @@ export const gro_plugin_sveltekit_library = ({
|
|
|
27
27
|
name: 'gro_plugin_sveltekit_library',
|
|
28
28
|
setup: async ({dev, log, config}) => {
|
|
29
29
|
if (!dev) {
|
|
30
|
-
const package_json = await
|
|
30
|
+
const package_json = await package_json_load();
|
|
31
31
|
await run_svelte_package(
|
|
32
32
|
package_json,
|
|
33
33
|
svelte_package_options,
|
|
@@ -38,7 +38,7 @@ export const gro_plugin_sveltekit_library = ({
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
adapt: async ({log, timings, config}) => {
|
|
41
|
-
const package_json = await
|
|
41
|
+
const package_json = await package_json_load();
|
|
42
42
|
// link the CLI binaries if they exist
|
|
43
43
|
if (package_json.bin) {
|
|
44
44
|
const timing_to_link = timings.start(`${config.pm_cli} link`);
|
package/src/lib/invoke_task.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {to_forwarded_args, type Args} from './args.ts';
|
|
|
7
7
|
import {run_task} from './run_task.ts';
|
|
8
8
|
import {to_input_path, RawInputPath} from './input_path.ts';
|
|
9
9
|
import {find_tasks, load_tasks, SilentError} from './task.ts';
|
|
10
|
-
import {
|
|
10
|
+
import {package_json_load_for_gro} from './package_json.ts';
|
|
11
11
|
import {log_tasks, log_error_reasons} from './task_logging.ts';
|
|
12
12
|
import type {GroConfig} from './gro_config.ts';
|
|
13
13
|
import {Filer} from './filer.ts';
|
|
@@ -68,7 +68,7 @@ export const invoke_task = async (
|
|
|
68
68
|
|
|
69
69
|
// Check if the caller just wants to see the version.
|
|
70
70
|
if (!task_name && (args?.version || args?.v)) {
|
|
71
|
-
const gro_package_json = await
|
|
71
|
+
const gro_package_json = await package_json_load_for_gro();
|
|
72
72
|
log.info(`${st('gray', 'v')}${st('cyan', gro_package_json.version)}`);
|
|
73
73
|
await finish();
|
|
74
74
|
return;
|