@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/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -6,7 +6,12 @@
|
|
|
6
6
|
|
|
7
7
|
[`npm i -D @ryanatkn/gro`](https://www.npmjs.com/package/@ryanatkn/gro)
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
> ⚠️ I still use Gro heavily but I'm transitioning to Rust-based tooling
|
|
10
|
+
> with [Fuz](https://github.com/fuzdev) using [Deno](https://github.com/denoland) as a sidecar.
|
|
11
|
+
> I consider Gro deprecated but there should be a migration path.
|
|
12
|
+
> Please open issues if you need help.
|
|
13
|
+
|
|
14
|
+
> ⚠️[Windows won't be supported](https://github.com/ryanatkn/gro/issues/319), I chose Bash instead.
|
|
10
15
|
|
|
11
16
|
Docs at [gro.ryanatkn.com/docs](https://gro.ryanatkn.com/docs) and [src/docs](./src/docs).
|
|
12
17
|
|
package/dist/changeset.task.js
CHANGED
|
@@ -9,7 +9,7 @@ import { TaskError } from "./task.js";
|
|
|
9
9
|
import { find_cli, spawn_cli } from "./cli.js";
|
|
10
10
|
import { has_sveltekit_library } from "./sveltekit_helpers.js";
|
|
11
11
|
import { CHANGESET_CLI, CHANGESET_DIR, ChangesetAccess, ChangesetBump, CHANGESET_PUBLIC_ACCESS, CHANGESET_RESTRICTED_ACCESS, } from "./changeset_helpers.js";
|
|
12
|
-
import {
|
|
12
|
+
import { package_json_load } from "./package_json.js";
|
|
13
13
|
/** @nodocs */
|
|
14
14
|
export const Args = z.strictObject({
|
|
15
15
|
/**
|
|
@@ -61,7 +61,7 @@ export const task = {
|
|
|
61
61
|
if (!found_changeset_cli) {
|
|
62
62
|
throw new TaskError('changeset command not found: install @changesets/cli locally or globally');
|
|
63
63
|
}
|
|
64
|
-
const package_json = await
|
|
64
|
+
const package_json = await package_json_load();
|
|
65
65
|
const has_sveltekit_library_result = await has_sveltekit_library(package_json, svelte_config);
|
|
66
66
|
if (!has_sveltekit_library_result.ok) {
|
|
67
67
|
throw new TaskError('Failed to find SvelteKit library: ' + has_sveltekit_library_result.message);
|
package/dist/check.task.js
CHANGED
|
@@ -3,7 +3,7 @@ import { spawn } from '@fuzdev/fuz_util/process.js';
|
|
|
3
3
|
import { styleText as st } from 'node:util';
|
|
4
4
|
import { git_check_clean_workspace } from '@fuzdev/fuz_util/git.js';
|
|
5
5
|
import { TaskError } from "./task.js";
|
|
6
|
-
import {
|
|
6
|
+
import { package_json_sync } from "./package_json.js";
|
|
7
7
|
/** @nodocs */
|
|
8
8
|
export const Args = z.strictObject({
|
|
9
9
|
typecheck: z.boolean().meta({ description: 'dual of no-typecheck' }).default(true),
|
|
@@ -54,7 +54,7 @@ export const task = {
|
|
|
54
54
|
await invoke_task('gen', { check: true });
|
|
55
55
|
}
|
|
56
56
|
if (package_json && config.map_package_json) {
|
|
57
|
-
const { changed } = await
|
|
57
|
+
const { changed } = await package_json_sync(config.map_package_json, log, false);
|
|
58
58
|
if (changed) {
|
|
59
59
|
throw new TaskError('package.json is out of date, run `gro sync` to update it');
|
|
60
60
|
}
|
package/dist/cli.d.ts
CHANGED
|
@@ -18,13 +18,13 @@ export type Cli = {
|
|
|
18
18
|
*/
|
|
19
19
|
export declare const find_cli: (name: string, cwd?: string | URL, options?: SpawnOptions) => Promise<Cli | null>;
|
|
20
20
|
/**
|
|
21
|
-
* Spawns a CLI if available using
|
|
21
|
+
* Spawns a CLI if available using fuz_util's `spawn`.
|
|
22
22
|
* If a string is provided for `name_or_cli`, it checks first local to the cwd and then globally.
|
|
23
23
|
* @returns `undefined` if no CLI is found, or the spawn result
|
|
24
24
|
*/
|
|
25
25
|
export declare const spawn_cli: (name_or_cli: string | Cli, args?: Array<string>, log?: Logger, options?: SpawnOptions) => Promise<SpawnResult | undefined>;
|
|
26
26
|
/**
|
|
27
|
-
* Spawns a CLI if available using
|
|
27
|
+
* Spawns a CLI if available using fuz_util's `spawn_process`.
|
|
28
28
|
* If a string is provided for `name_or_cli`, it checks first local to the cwd and then globally.
|
|
29
29
|
* @returns `undefined` if no CLI is found, or the spawn result
|
|
30
30
|
*/
|
package/dist/cli.js
CHANGED
|
@@ -21,7 +21,7 @@ export const find_cli = async (name, cwd = process.cwd(), options) => {
|
|
|
21
21
|
return { name, id: global_id, kind: 'global' };
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
24
|
-
* Spawns a CLI if available using
|
|
24
|
+
* Spawns a CLI if available using fuz_util's `spawn`.
|
|
25
25
|
* If a string is provided for `name_or_cli`, it checks first local to the cwd and then globally.
|
|
26
26
|
* @returns `undefined` if no CLI is found, or the spawn result
|
|
27
27
|
*/
|
|
@@ -32,7 +32,7 @@ export const spawn_cli = async (name_or_cli, args = [], log, options) => {
|
|
|
32
32
|
return spawn(cli.id, args, options);
|
|
33
33
|
};
|
|
34
34
|
/**
|
|
35
|
-
* Spawns a CLI if available using
|
|
35
|
+
* Spawns a CLI if available using fuz_util's `spawn_process`.
|
|
36
36
|
* If a string is provided for `name_or_cli`, it checks first local to the cwd and then globally.
|
|
37
37
|
* @returns `undefined` if no CLI is found, or the spawn result
|
|
38
38
|
*/
|
package/dist/format_file.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import prettier from 'prettier';
|
|
2
2
|
import { extname } from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { package_json_load } from "./package_json.js";
|
|
4
4
|
let cached_base_options;
|
|
5
5
|
/**
|
|
6
6
|
* Formats a file with Prettier.
|
|
@@ -11,7 +11,7 @@ let cached_base_options;
|
|
|
11
11
|
export const format_file = async (content, options, base_options = cached_base_options) => {
|
|
12
12
|
const final_base_options = base_options !== undefined
|
|
13
13
|
? base_options
|
|
14
|
-
: (cached_base_options = (await
|
|
14
|
+
: (cached_base_options = (await package_json_load()).prettier);
|
|
15
15
|
let final_options = options;
|
|
16
16
|
if (options.filepath && !options.parser) {
|
|
17
17
|
const { filepath, ...rest } = options;
|
|
@@ -1 +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,
|
|
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"}
|
|
@@ -3,7 +3,7 @@ import { has_server, gro_plugin_server } from "./gro_plugin_server.js";
|
|
|
3
3
|
import { gro_plugin_sveltekit_app } from "./gro_plugin_sveltekit_app.js";
|
|
4
4
|
import { has_sveltekit_app, has_sveltekit_library } from "./sveltekit_helpers.js";
|
|
5
5
|
import { gro_plugin_gen } from "./gro_plugin_gen.js";
|
|
6
|
-
import {
|
|
6
|
+
import { package_json_load } from "./package_json.js";
|
|
7
7
|
// TODO hacky, maybe extract utils?
|
|
8
8
|
/**
|
|
9
9
|
* This is the default config that's passed to `gro.config.ts`
|
|
@@ -15,7 +15,7 @@ import { load_package_json } from "./package_json.js";
|
|
|
15
15
|
* - if `src/lib/server/server.ts`, assumes a Node server - needs config
|
|
16
16
|
*/
|
|
17
17
|
const config = async (cfg, svelte_config) => {
|
|
18
|
-
const package_json = await
|
|
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
19
|
const [has_server_result, has_sveltekit_library_result, has_sveltekit_app_result] = await Promise.all([
|
|
20
20
|
has_server(),
|
|
21
21
|
has_sveltekit_library(package_json, svelte_config),
|
|
@@ -26,9 +26,7 @@ const config = async (cfg, svelte_config) => {
|
|
|
26
26
|
gro_plugin_gen(),
|
|
27
27
|
has_server_result.ok ? gro_plugin_server() : null,
|
|
28
28
|
has_sveltekit_library_result.ok ? gro_plugin_sveltekit_library() : null,
|
|
29
|
-
has_sveltekit_app_result.ok
|
|
30
|
-
? gro_plugin_sveltekit_app({ host_target: has_server_result.ok ? 'node' : 'github_pages' })
|
|
31
|
-
: null,
|
|
29
|
+
has_sveltekit_app_result.ok ? gro_plugin_sveltekit_app() : null,
|
|
32
30
|
].filter((v) => v !== null);
|
|
33
31
|
return cfg;
|
|
34
32
|
};
|
|
@@ -1,33 +1,9 @@
|
|
|
1
1
|
import type { Plugin } from './plugin.ts';
|
|
2
|
-
import { type PackageJsonMapper } from './package_json.ts';
|
|
3
|
-
import { type SourceJsonMapper } from './source_json.ts';
|
|
4
2
|
export interface GroPluginSveltekitAppOptions {
|
|
5
|
-
/**
|
|
6
|
-
* Used for finalizing a SvelteKit build like adding a `.nojekyll` file for GitHub Pages.
|
|
7
|
-
* @default 'github_pages'
|
|
8
|
-
*/
|
|
9
|
-
host_target?: HostTarget;
|
|
10
|
-
/**
|
|
11
|
-
* If truthy, adds `/.well-known/package.json` to the static output.
|
|
12
|
-
* If a function, maps the value.
|
|
13
|
-
*/
|
|
14
|
-
well_known_package_json?: boolean | PackageJsonMapper;
|
|
15
|
-
/**
|
|
16
|
-
* If truthy, adds `/.well-known/source.json` and `/.well-known/src/` to the static output.
|
|
17
|
-
* If a function, maps the value.
|
|
18
|
-
*/
|
|
19
|
-
well_known_source_json?: boolean | SourceJsonMapper;
|
|
20
|
-
/**
|
|
21
|
-
* If truthy, copies `src/` to `/.well-known/src/` to the static output.
|
|
22
|
-
* Pass a function to customize which files get copied.
|
|
23
|
-
*/
|
|
24
|
-
well_known_src_files?: boolean | CopyFileFilter;
|
|
25
3
|
/**
|
|
26
4
|
* The Vite CLI to use.
|
|
27
5
|
*/
|
|
28
6
|
vite_cli?: string;
|
|
29
7
|
}
|
|
30
|
-
export
|
|
31
|
-
export type CopyFileFilter = (file_path: string) => boolean;
|
|
32
|
-
export declare const gro_plugin_sveltekit_app: ({ host_target, well_known_package_json, well_known_source_json, well_known_src_files, vite_cli, }?: GroPluginSveltekitAppOptions) => Plugin;
|
|
8
|
+
export declare const gro_plugin_sveltekit_app: ({ vite_cli, }?: GroPluginSveltekitAppOptions) => Plugin;
|
|
33
9
|
//# sourceMappingURL=gro_plugin_sveltekit_app.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gro_plugin_sveltekit_app.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gro_plugin_sveltekit_app.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gro_plugin_sveltekit_app.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gro_plugin_sveltekit_app.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAMxC,MAAM,WAAW,4BAA4B;IAC5C;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,wBAAwB,GAAI,gBAEtC,4BAAiC,KAAG,MAqCtC,CAAC"}
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import { cp, mkdir, rm, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { dirname, join } from 'node:path';
|
|
3
|
-
import { fs_exists } from '@fuzdev/fuz_util/fs.js';
|
|
4
1
|
import { serialize_args, to_forwarded_args } from "./args.js";
|
|
5
|
-
import { serialize_package_json, load_package_json } from "./package_json.js";
|
|
6
2
|
import { TaskError } from "./task.js";
|
|
7
3
|
import { find_cli, spawn_cli, spawn_cli_process } from "./cli.js";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
import { default_svelte_config } from "./svelte_config.js";
|
|
11
|
-
import { SOURCE_DIRNAME, VITE_CLI } from "./constants.js";
|
|
12
|
-
export const gro_plugin_sveltekit_app = ({ host_target = 'github_pages', well_known_package_json, well_known_source_json, well_known_src_files, vite_cli = VITE_CLI, } = {}) => {
|
|
4
|
+
import { VITE_CLI } from "./constants.js";
|
|
5
|
+
export const gro_plugin_sveltekit_app = ({ vite_cli = VITE_CLI, } = {}) => {
|
|
13
6
|
let sveltekit_process = undefined;
|
|
14
7
|
return {
|
|
15
8
|
name: 'gro_plugin_sveltekit_app',
|
|
@@ -30,74 +23,11 @@ export const gro_plugin_sveltekit_app = ({ host_target = 'github_pages', well_kn
|
|
|
30
23
|
}
|
|
31
24
|
else {
|
|
32
25
|
// `vite build` in production mode
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
if (
|
|
36
|
-
|
|
26
|
+
const serialized_args = ['build', ...serialize_args(to_forwarded_args(vite_cli))];
|
|
27
|
+
const spawned = await spawn_cli(found_vite_cli, serialized_args, log);
|
|
28
|
+
if (!spawned?.ok) {
|
|
29
|
+
throw new TaskError(`${vite_cli} build failed with exit code ${spawned?.code}`);
|
|
37
30
|
}
|
|
38
|
-
const mapped_package_json = !well_known_package_json
|
|
39
|
-
? null
|
|
40
|
-
: well_known_package_json === true
|
|
41
|
-
? package_json
|
|
42
|
-
: await well_known_package_json(package_json);
|
|
43
|
-
const serialized_package_json = mapped_package_json && serialize_package_json(mapped_package_json);
|
|
44
|
-
// `.well-known/source.json` and `.well-known/src/`
|
|
45
|
-
const final_package_json = mapped_package_json ?? package_json;
|
|
46
|
-
const source_json = await source_json_create(final_package_json, undefined, log);
|
|
47
|
-
if (well_known_source_json === undefined) {
|
|
48
|
-
well_known_source_json = final_package_json.public; // eslint-disable-line no-param-reassign
|
|
49
|
-
}
|
|
50
|
-
const mapped_source_json = !well_known_source_json
|
|
51
|
-
? null
|
|
52
|
-
: well_known_source_json === true
|
|
53
|
-
? source_json
|
|
54
|
-
: await well_known_source_json(source_json);
|
|
55
|
-
const serialized_source_json = mapped_source_json && source_json_serialize(mapped_source_json);
|
|
56
|
-
// TODO this strategy means the files aren't available during development --
|
|
57
|
-
// maybe a Vite middleware is best? what if this plugin added its plugin to your `vite.config.ts`?
|
|
58
|
-
// copy files to `static` before building, in such a way
|
|
59
|
-
// that's non-destructive to existing files and dirs and easy to clean up
|
|
60
|
-
const { assets_path } = default_svelte_config;
|
|
61
|
-
const cleanup_promises = [
|
|
62
|
-
serialized_package_json
|
|
63
|
-
? create_temporarily(join(assets_path, '.well-known/package.json'), serialized_package_json)
|
|
64
|
-
: null,
|
|
65
|
-
serialized_source_json
|
|
66
|
-
? create_temporarily(join(assets_path, '.well-known/source.json'), serialized_source_json)
|
|
67
|
-
: null,
|
|
68
|
-
serialized_source_json && well_known_src_files
|
|
69
|
-
? copy_temporarily(SOURCE_DIRNAME, assets_path, '.well-known', well_known_src_files === true
|
|
70
|
-
? (file_path) => !EXPORTS_EXCLUDER_DEFAULT.test(file_path)
|
|
71
|
-
: well_known_src_files)
|
|
72
|
-
: null,
|
|
73
|
-
/**
|
|
74
|
-
* GitHub pages processes everything with Jekyll by default,
|
|
75
|
-
* breaking things like files and dirs prefixed with an underscore.
|
|
76
|
-
* This adds a `.nojekyll` file to the root of the output
|
|
77
|
-
* to tell GitHub Pages to treat the outputs as plain static files.
|
|
78
|
-
*/
|
|
79
|
-
host_target === 'github_pages'
|
|
80
|
-
? create_temporarily(join(assets_path, '.nojekyll'), '')
|
|
81
|
-
: null,
|
|
82
|
-
].filter((v) => v != null);
|
|
83
|
-
const cleanups = await Promise.all(cleanup_promises);
|
|
84
|
-
const cleanup = async () => {
|
|
85
|
-
// eslint-disable-next-line no-await-in-loop
|
|
86
|
-
for (const c of cleanups)
|
|
87
|
-
await c();
|
|
88
|
-
};
|
|
89
|
-
try {
|
|
90
|
-
const serialized_args = ['build', ...serialize_args(to_forwarded_args(vite_cli))];
|
|
91
|
-
const spawned = await spawn_cli(found_vite_cli, serialized_args, log);
|
|
92
|
-
if (!spawned?.ok) {
|
|
93
|
-
throw new TaskError(`${vite_cli} build failed with exit code ${spawned?.code}`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
await cleanup();
|
|
98
|
-
throw error;
|
|
99
|
-
}
|
|
100
|
-
await cleanup();
|
|
101
31
|
}
|
|
102
32
|
},
|
|
103
33
|
teardown: async () => {
|
|
@@ -108,87 +38,3 @@ export const gro_plugin_sveltekit_app = ({ host_target = 'github_pages', well_kn
|
|
|
108
38
|
},
|
|
109
39
|
};
|
|
110
40
|
};
|
|
111
|
-
// TODO probably extract these, and create a common helper or merge them
|
|
112
|
-
const copy_temporarily = async (source_path, dest_dir, dest_base_dir = '', filter) => {
|
|
113
|
-
const path = join(dest_dir, dest_base_dir, source_path);
|
|
114
|
-
const dir = dirname(path);
|
|
115
|
-
const dir_already_exists = await fs_exists(dir);
|
|
116
|
-
let root_created_dir;
|
|
117
|
-
if (!dir_already_exists) {
|
|
118
|
-
root_created_dir = await to_root_dir_that_doesnt_exist(dir);
|
|
119
|
-
if (!root_created_dir)
|
|
120
|
-
throw Error();
|
|
121
|
-
await mkdir(dir, { recursive: true });
|
|
122
|
-
}
|
|
123
|
-
const path_already_exists = await fs_exists(path);
|
|
124
|
-
if (!path_already_exists) {
|
|
125
|
-
await cp(source_path, path, { recursive: true, filter });
|
|
126
|
-
}
|
|
127
|
-
return async () => {
|
|
128
|
-
if (!dir_already_exists) {
|
|
129
|
-
if (!root_created_dir)
|
|
130
|
-
throw Error();
|
|
131
|
-
if (await fs_exists(root_created_dir)) {
|
|
132
|
-
await rm(root_created_dir, { recursive: true });
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
else if (!path_already_exists) {
|
|
136
|
-
if (await fs_exists(path)) {
|
|
137
|
-
await rm(path, { recursive: true });
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
};
|
|
142
|
-
/**
|
|
143
|
-
* Creates a file at `path` with `contents` if it doesn't already exist,
|
|
144
|
-
* and returns a function that deletes the file and any created directories.
|
|
145
|
-
* @param path
|
|
146
|
-
* @param contents
|
|
147
|
-
* @returns cleanup function that deletes the file and any created dirs
|
|
148
|
-
*/
|
|
149
|
-
const create_temporarily = async (path, contents) => {
|
|
150
|
-
const dir = dirname(path);
|
|
151
|
-
const dir_already_exists = await fs_exists(dir);
|
|
152
|
-
let root_created_dir;
|
|
153
|
-
if (!dir_already_exists) {
|
|
154
|
-
root_created_dir = await to_root_dir_that_doesnt_exist(dir);
|
|
155
|
-
if (!root_created_dir)
|
|
156
|
-
throw Error();
|
|
157
|
-
await mkdir(dir, { recursive: true });
|
|
158
|
-
}
|
|
159
|
-
const path_already_exists = await fs_exists(path);
|
|
160
|
-
if (!path_already_exists) {
|
|
161
|
-
await writeFile(path, contents, 'utf8');
|
|
162
|
-
}
|
|
163
|
-
return async () => {
|
|
164
|
-
if (!dir_already_exists) {
|
|
165
|
-
if (!root_created_dir)
|
|
166
|
-
throw Error();
|
|
167
|
-
if (await fs_exists(root_created_dir)) {
|
|
168
|
-
await rm(root_created_dir, { recursive: true });
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
else if (!path_already_exists) {
|
|
172
|
-
if (await fs_exists(path)) {
|
|
173
|
-
await rm(path);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
};
|
|
178
|
-
/**
|
|
179
|
-
* Niche and probably needs refactoring,
|
|
180
|
-
* for `/a/b/DOESNT_EXIST/NOR_THIS/ETC` returns `/a/b/DOESNT_EXIST`
|
|
181
|
-
* where `/a/b` does exist on the filesystem and `DOESNT_EXIST` is not one of its subdirectories.
|
|
182
|
-
*/
|
|
183
|
-
const to_root_dir_that_doesnt_exist = async (dir) => {
|
|
184
|
-
let prev;
|
|
185
|
-
let d = dir;
|
|
186
|
-
do {
|
|
187
|
-
// eslint-disable-next-line no-await-in-loop
|
|
188
|
-
if (await fs_exists(d)) {
|
|
189
|
-
return prev;
|
|
190
|
-
}
|
|
191
|
-
prev = d;
|
|
192
|
-
} while ((d = dirname(d)));
|
|
193
|
-
throw Error('no dirs exist for ' + dir);
|
|
194
|
-
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { print_spawn_result, spawn } from '@fuzdev/fuz_util/process.js';
|
|
2
2
|
import { TaskError } from "./task.js";
|
|
3
|
-
import {
|
|
3
|
+
import { package_json_load } from "./package_json.js";
|
|
4
4
|
import { run_svelte_package } from "./sveltekit_helpers.js";
|
|
5
5
|
import { SVELTE_PACKAGE_CLI } from "./constants.js";
|
|
6
6
|
export const gro_plugin_sveltekit_library = ({ svelte_package_options, svelte_package_cli = SVELTE_PACKAGE_CLI, } = {}) => {
|
|
@@ -8,12 +8,12 @@ export const gro_plugin_sveltekit_library = ({ svelte_package_options, svelte_pa
|
|
|
8
8
|
name: 'gro_plugin_sveltekit_library',
|
|
9
9
|
setup: async ({ dev, log, config }) => {
|
|
10
10
|
if (!dev) {
|
|
11
|
-
const package_json = await
|
|
11
|
+
const package_json = await package_json_load();
|
|
12
12
|
await run_svelte_package(package_json, svelte_package_options, svelte_package_cli, log, config.pm_cli);
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
adapt: async ({ log, timings, config }) => {
|
|
16
|
-
const package_json = await
|
|
16
|
+
const package_json = await package_json_load();
|
|
17
17
|
// link the CLI binaries if they exist
|
|
18
18
|
if (package_json.bin) {
|
|
19
19
|
const timing_to_link = timings.start(`${config.pm_cli} link`);
|
package/dist/invoke_task.js
CHANGED
|
@@ -6,7 +6,7 @@ import { to_forwarded_args } from "./args.js";
|
|
|
6
6
|
import { run_task } from "./run_task.js";
|
|
7
7
|
import { to_input_path, RawInputPath } from "./input_path.js";
|
|
8
8
|
import { find_tasks, load_tasks, SilentError } from "./task.js";
|
|
9
|
-
import {
|
|
9
|
+
import { package_json_load_for_gro } from "./package_json.js";
|
|
10
10
|
import { log_tasks, log_error_reasons } from "./task_logging.js";
|
|
11
11
|
import { Filer } from "./filer.js";
|
|
12
12
|
/**
|
|
@@ -54,7 +54,7 @@ export const invoke_task = async (task_name, args, config, initial_filer, initia
|
|
|
54
54
|
};
|
|
55
55
|
// Check if the caller just wants to see the version.
|
|
56
56
|
if (!task_name && (args?.version || args?.v)) {
|
|
57
|
-
const gro_package_json = await
|
|
57
|
+
const gro_package_json = await package_json_load_for_gro();
|
|
58
58
|
log.info(`${st('gray', 'v')}${st('cyan', gro_package_json.version)}`);
|
|
59
59
|
await finish();
|
|
60
60
|
return;
|
package/dist/package_json.d.ts
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
import type { Logger } from '@fuzdev/fuz_util/log.js';
|
|
2
2
|
import { PackageJson, PackageJsonExports } from '@fuzdev/fuz_util/package_json.js';
|
|
3
3
|
export type PackageJsonMapper = (package_json: PackageJson) => PackageJson | null | Promise<PackageJson | null>;
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
4
|
+
export declare const PACKAGE_JSON_EMPTY: PackageJson;
|
|
5
|
+
export declare const package_json_load: (dir?: string, cache?: Record<string, PackageJson>, parse?: boolean, // TODO pass `false` here in more places, especially anything perf-sensitive like work on startup
|
|
6
6
|
log?: Logger) => Promise<PackageJson>;
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const load_package_json: (dir?: string, cache?: Record<string, PackageJson>, parse?: boolean, log?: Logger) => Promise<PackageJson>;
|
|
8
|
+
export declare const package_json_sync: (map_package_json: PackageJsonMapper, log: Logger, write?: boolean, dir?: string, exports_dir?: string) => Promise<{
|
|
8
9
|
package_json: PackageJson | null;
|
|
9
10
|
changed: boolean;
|
|
10
11
|
}>;
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
12
|
+
export declare const package_json_load_for_gro: () => Promise<PackageJson>;
|
|
13
|
+
export declare const package_json_write: (serialized_package_json: string) => Promise<void>;
|
|
14
|
+
export declare const package_json_serialize: (package_json: PackageJson) => string;
|
|
14
15
|
/**
|
|
15
16
|
* Updates package.json. Writes to the filesystem only when contents change.
|
|
16
17
|
*/
|
|
17
|
-
export declare const
|
|
18
|
+
export declare const package_json_update: (update: (package_json: PackageJson) => PackageJson | null | Promise<PackageJson | null>, dir?: string, write?: boolean) => Promise<{
|
|
18
19
|
package_json: PackageJson | null;
|
|
19
20
|
changed: boolean;
|
|
20
21
|
}>;
|
|
21
|
-
export declare const
|
|
22
|
-
export declare const
|
|
22
|
+
export declare const package_json_to_exports: (paths: Array<string>) => PackageJsonExports;
|
|
23
|
+
export declare const package_json_parse_repo_url: (package_json: PackageJson) => {
|
|
23
24
|
owner: string;
|
|
24
25
|
repo: string;
|
|
25
26
|
} | undefined;
|
|
26
|
-
export declare const
|
|
27
|
+
export declare const package_json_has_dependency: (dep_name: string, package_json: PackageJson) => boolean;
|
|
27
28
|
export interface PackageJsonDep {
|
|
28
29
|
name: string;
|
|
29
30
|
version: string;
|
|
30
31
|
}
|
|
31
|
-
export declare const
|
|
32
|
+
export declare const package_json_extract_dependencies: (package_json: PackageJson) => Array<PackageJsonDep>;
|
|
32
33
|
//# sourceMappingURL=package_json.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package_json.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/package_json.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAC,WAAW,EAAE,kBAAkB,EAAC,MAAM,kCAAkC,CAAC;AAgBjF,MAAM,MAAM,iBAAiB,GAAG,CAC/B,YAAY,EAAE,WAAW,KACrB,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;AAEtD,eAAO,MAAM,kBAAkB,EAAE,WAAqC,CAAC;AAEvE,eAAO,MAAM,iBAAiB,GAC7B,YAA+C,EAC/C,QAAQ,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACnC,eAAY,EAAE,iGAAiG;AAC/G,MAAM,MAAM,KACV,OAAO,CAAC,WAAW,CAkBrB,CAAC;
|
|
1
|
+
{"version":3,"file":"package_json.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/package_json.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAC,WAAW,EAAE,kBAAkB,EAAC,MAAM,kCAAkC,CAAC;AAgBjF,MAAM,MAAM,iBAAiB,GAAG,CAC/B,YAAY,EAAE,WAAW,KACrB,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;AAEtD,eAAO,MAAM,kBAAkB,EAAE,WAAqC,CAAC;AAEvE,eAAO,MAAM,iBAAiB,GAC7B,YAA+C,EAC/C,QAAQ,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACnC,eAAY,EAAE,iGAAiG;AAC/G,MAAM,MAAM,KACV,OAAO,CAAC,WAAW,CAkBrB,CAAC;AAGF,eAAO,MAAM,iBAAiB,yBAxBrB,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,yBAE7B,MAAM,KACV,OAAO,CAAC,WAAW,CAqB4B,CAAC;AAEnD,eAAO,MAAM,iBAAiB,GAC7B,kBAAkB,iBAAiB,EACnC,KAAK,MAAM,EACX,eAAY,EACZ,YAAgB,EAChB,oBAAuB,KACrB,OAAO,CAAC;IAAC,YAAY,EAAE,WAAW,GAAG,IAAI,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAC,CA0B9D,CAAC;AAEF,eAAO,MAAM,yBAAyB,QAAO,OAAO,CAAC,WAAW,CAC9B,CAAC;AAMnC,eAAO,MAAM,kBAAkB,GAAI,yBAAyB,MAAM,KAAG,OAAO,CAAC,IAAI,CACL,CAAC;AAE7E,eAAO,MAAM,sBAAsB,GAAI,cAAc,WAAW,KAAG,MACW,CAAC;AAE/E;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAC/B,QAAQ,CAAC,YAAY,EAAE,WAAW,KAAK,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,EACvF,YAAgB,EAChB,eAAY,KACV,OAAO,CAAC;IAAC,YAAY,EAAE,WAAW,GAAG,IAAI,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAC,CAa9D,CAAC;AAIF,eAAO,MAAM,uBAAuB,GAAI,OAAO,KAAK,CAAC,MAAM,CAAC,KAAG,kBAmD9D,CAAC;AAIF,eAAO,MAAM,2BAA2B,GACvC,cAAc,WAAW,KACvB;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,GAAG,SAgBlC,CAAC;AA8BF,eAAO,MAAM,2BAA2B,GAAI,UAAU,MAAM,EAAE,cAAc,WAAW,KAAG,OAG9C,CAAC;AAE7C,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,iCAAiC,GAC7C,cAAc,WAAW,KACvB,KAAK,CAAC,cAAc,CAetB,CAAC"}
|
package/dist/package_json.js
CHANGED
|
@@ -9,19 +9,19 @@ import { paths, gro_paths, IS_THIS_GRO } from "./paths.js";
|
|
|
9
9
|
import { PACKAGE_JSON_FILENAME, SVELTEKIT_DIST_DIRNAME, TS_MATCHER, JS_MATCHER, SVELTE_MATCHER, JSON_MATCHER, CSS_MATCHER, } from "./constants.js";
|
|
10
10
|
import { has_sveltekit_library } from "./sveltekit_helpers.js";
|
|
11
11
|
import { GITHUB_REPO_MATCHER } from "./github.js";
|
|
12
|
-
export const
|
|
13
|
-
export const
|
|
12
|
+
export const PACKAGE_JSON_EMPTY = { name: '', version: '' };
|
|
13
|
+
export const package_json_load = async (dir = IS_THIS_GRO ? gro_paths.root : paths.root, cache, parse = true, // TODO pass `false` here in more places, especially anything perf-sensitive like work on startup
|
|
14
14
|
log) => {
|
|
15
15
|
let package_json;
|
|
16
16
|
if (cache && dir in cache) {
|
|
17
17
|
return cache[dir];
|
|
18
18
|
}
|
|
19
19
|
try {
|
|
20
|
-
package_json = JSON.parse(await
|
|
20
|
+
package_json = JSON.parse(await package_json_load_contents(dir));
|
|
21
21
|
}
|
|
22
22
|
catch (error) {
|
|
23
23
|
log?.error(st('yellow', `Failed to load package.json in ${dir}`), error);
|
|
24
|
-
return
|
|
24
|
+
return PACKAGE_JSON_EMPTY;
|
|
25
25
|
}
|
|
26
26
|
if (parse) {
|
|
27
27
|
package_json = parse_package_json(PackageJson, package_json);
|
|
@@ -31,12 +31,14 @@ log) => {
|
|
|
31
31
|
}
|
|
32
32
|
return package_json;
|
|
33
33
|
};
|
|
34
|
-
|
|
34
|
+
// TODO remove
|
|
35
|
+
export const load_package_json = package_json_load;
|
|
36
|
+
export const package_json_sync = async (map_package_json, log, write = true, dir = paths.root, exports_dir = paths.lib) => {
|
|
35
37
|
const exported_files = await fs_search(exports_dir);
|
|
36
38
|
const exported_paths = exported_files.map((f) => f.path);
|
|
37
|
-
const updated = await
|
|
39
|
+
const updated = await package_json_update(async (package_json) => {
|
|
38
40
|
if ((await has_sveltekit_library(package_json)).ok) {
|
|
39
|
-
package_json.exports =
|
|
41
|
+
package_json.exports = package_json_to_exports(exported_paths);
|
|
40
42
|
}
|
|
41
43
|
const mapped = await map_package_json(package_json);
|
|
42
44
|
return mapped ? parse_package_json(PackageJson, mapped) : mapped;
|
|
@@ -49,31 +51,31 @@ export const sync_package_json = async (map_package_json, log, write = true, dir
|
|
|
49
51
|
: 'no changes to exports in package.json');
|
|
50
52
|
return updated;
|
|
51
53
|
};
|
|
52
|
-
export const
|
|
54
|
+
export const package_json_load_for_gro = () => package_json_load(gro_paths.root);
|
|
53
55
|
// TODO probably make this nullable and make callers handle failures
|
|
54
|
-
const
|
|
55
|
-
export const
|
|
56
|
-
export const
|
|
56
|
+
const package_json_load_contents = (dir) => readFile(join(dir, PACKAGE_JSON_FILENAME), 'utf8');
|
|
57
|
+
export const package_json_write = (serialized_package_json) => writeFile(join(paths.root, PACKAGE_JSON_FILENAME), serialized_package_json);
|
|
58
|
+
export const package_json_serialize = (package_json) => JSON.stringify(parse_package_json(PackageJson, package_json), null, 2) + '\n';
|
|
57
59
|
/**
|
|
58
60
|
* Updates package.json. Writes to the filesystem only when contents change.
|
|
59
61
|
*/
|
|
60
|
-
export const
|
|
61
|
-
const original_contents = await
|
|
62
|
+
export const package_json_update = async (update, dir = paths.root, write = true) => {
|
|
63
|
+
const original_contents = await package_json_load_contents(dir);
|
|
62
64
|
const original = JSON.parse(original_contents);
|
|
63
65
|
const updated = await update(original);
|
|
64
66
|
if (updated === null) {
|
|
65
67
|
return { package_json: original, changed: false };
|
|
66
68
|
}
|
|
67
|
-
const updated_contents =
|
|
69
|
+
const updated_contents = package_json_serialize(updated);
|
|
68
70
|
if (updated_contents === original_contents) {
|
|
69
71
|
return { package_json: original, changed: false };
|
|
70
72
|
}
|
|
71
73
|
if (write)
|
|
72
|
-
await
|
|
74
|
+
await package_json_write(updated_contents);
|
|
73
75
|
return { package_json: updated, changed: true };
|
|
74
76
|
};
|
|
75
77
|
const is_index = (path) => path === 'index.ts' || path === 'index.js';
|
|
76
|
-
export const
|
|
78
|
+
export const package_json_to_exports = (paths) => {
|
|
77
79
|
const has_index = paths.some(is_index);
|
|
78
80
|
const has_js = paths.some((p) => TS_MATCHER.test(p) || JS_MATCHER.test(p));
|
|
79
81
|
const has_svelte = paths.some((p) => SVELTE_MATCHER.test(p));
|
|
@@ -119,7 +121,7 @@ export const to_package_exports = (paths) => {
|
|
|
119
121
|
return parse_or_throw_formatted_error('package.json#exports', PackageJsonExports, exports);
|
|
120
122
|
};
|
|
121
123
|
const IMPORT_PREFIX = './' + SVELTEKIT_DIST_DIRNAME + '/';
|
|
122
|
-
export const
|
|
124
|
+
export const package_json_parse_repo_url = (package_json) => {
|
|
123
125
|
const { repository } = package_json;
|
|
124
126
|
const repo_url = repository
|
|
125
127
|
? typeof repository === 'string'
|
|
@@ -156,10 +158,10 @@ const parse_or_throw_formatted_error = (name, schema, value) => {
|
|
|
156
158
|
}
|
|
157
159
|
return parsed.data;
|
|
158
160
|
};
|
|
159
|
-
export const
|
|
161
|
+
export const package_json_has_dependency = (dep_name, package_json) => !!package_json.devDependencies?.[dep_name] ||
|
|
160
162
|
!!package_json.dependencies?.[dep_name] ||
|
|
161
163
|
!!package_json.peerDependencies?.[dep_name];
|
|
162
|
-
export const
|
|
164
|
+
export const package_json_extract_dependencies = (package_json) => {
|
|
163
165
|
const deps_by_name = new Map();
|
|
164
166
|
// Earlier versions override later ones, so peer deps goes last.
|
|
165
167
|
const add_deps = (deps) => {
|
package/dist/publish.task.js
CHANGED
|
@@ -4,7 +4,7 @@ import { styleText as st } from 'node:util';
|
|
|
4
4
|
import { fs_exists } from '@fuzdev/fuz_util/fs.js';
|
|
5
5
|
import { GitBranch, GitOrigin, git_check_clean_workspace, git_checkout, git_fetch, git_pull, } from '@fuzdev/fuz_util/git.js';
|
|
6
6
|
import { TaskError } from "./task.js";
|
|
7
|
-
import {
|
|
7
|
+
import { package_json_load, package_json_parse_repo_url } from "./package_json.js";
|
|
8
8
|
import { find_cli, spawn_cli } from "./cli.js";
|
|
9
9
|
import { has_sveltekit_library } from "./sveltekit_helpers.js";
|
|
10
10
|
import { update_changelog } from "./changelog.js";
|
|
@@ -59,7 +59,7 @@ export const task = {
|
|
|
59
59
|
if (dry) {
|
|
60
60
|
log.info(st('green', 'dry run!'));
|
|
61
61
|
}
|
|
62
|
-
const package_json = await
|
|
62
|
+
const package_json = await package_json_load();
|
|
63
63
|
const has_sveltekit_library_result = await has_sveltekit_library(package_json);
|
|
64
64
|
if (!has_sveltekit_library_result.ok) {
|
|
65
65
|
throw new TaskError('Failed to find SvelteKit library: ' + has_sveltekit_library_result.message);
|
|
@@ -104,7 +104,7 @@ export const task = {
|
|
|
104
104
|
if (typeof package_json.version !== 'string') {
|
|
105
105
|
throw new TaskError('Failed to find package.json version');
|
|
106
106
|
}
|
|
107
|
-
const parsed_repo_url =
|
|
107
|
+
const parsed_repo_url = package_json_parse_repo_url(package_json);
|
|
108
108
|
if (!parsed_repo_url) {
|
|
109
109
|
throw new TaskError('package.json `repository` must contain a repo url (and GitHub only for now, sorry),' +
|
|
110
110
|
' like `git+https://github.com/ryanatkn/gro.git` or `https://github.com/ryanatkn/gro`' +
|
|
@@ -132,7 +132,7 @@ export const task = {
|
|
|
132
132
|
// Regenerate files that depend on package.json version.
|
|
133
133
|
// The check above ensures gen is updated.
|
|
134
134
|
await invoke_task('gen');
|
|
135
|
-
const package_json_after_versioning = await
|
|
135
|
+
const package_json_after_versioning = await package_json_load();
|
|
136
136
|
version = package_json_after_versioning.version;
|
|
137
137
|
if (package_json.version === version) {
|
|
138
138
|
// The version didn't change.
|
package/dist/release.task.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { has_sveltekit_library, has_sveltekit_app } from "./sveltekit_helpers.js";
|
|
3
|
-
import {
|
|
3
|
+
import { package_json_load } from "./package_json.js";
|
|
4
4
|
/** @nodocs */
|
|
5
5
|
export const Args = z.strictObject({});
|
|
6
6
|
/** @nodocs */
|
|
@@ -8,7 +8,7 @@ export const task = {
|
|
|
8
8
|
summary: 'publish and deploy',
|
|
9
9
|
Args,
|
|
10
10
|
run: async ({ invoke_task }) => {
|
|
11
|
-
const package_json = await
|
|
11
|
+
const package_json = await package_json_load();
|
|
12
12
|
const publish = (await has_sveltekit_library(package_json)).ok;
|
|
13
13
|
if (publish) {
|
|
14
14
|
await invoke_task('publish', { optional: true });
|