@ryanatkn/gro 0.182.0 → 0.184.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/dist/changeset.task.js +2 -2
- package/dist/check.task.js +2 -2
- package/dist/format_file.js +2 -2
- package/dist/gro.config.default.js +2 -2
- package/dist/gro_config.d.ts +3 -3
- package/dist/gro_plugin_sveltekit_app.d.ts +1 -27
- package/dist/gro_plugin_sveltekit_app.d.ts.map +1 -1
- package/dist/gro_plugin_sveltekit_app.js +7 -156
- package/dist/gro_plugin_sveltekit_library.js +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/invoke_task.js +2 -2
- package/dist/package_json.d.ts +11 -11
- package/dist/package_json.d.ts.map +1 -1
- package/dist/package_json.js +19 -19
- package/dist/plugin.d.ts +3 -3
- package/dist/plugin.js +2 -2
- package/dist/publish.task.js +4 -4
- package/dist/release.task.js +2 -2
- package/dist/source_json.d.ts +1 -2
- package/dist/source_json.d.ts.map +1 -1
- package/dist/source_json.js +2 -6
- 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 +3 -4
- package/src/lib/changeset.task.ts +2 -2
- package/src/lib/check.task.ts +2 -2
- package/src/lib/format_file.ts +2 -2
- package/src/lib/gro.config.default.ts +2 -2
- package/src/lib/gro_config.ts +3 -3
- package/src/lib/gro_plugin_sveltekit_app.ts +6 -216
- package/src/lib/gro_plugin_sveltekit_library.ts +3 -3
- package/src/lib/index.ts +1 -1
- package/src/lib/invoke_task.ts +2 -2
- package/src/lib/package_json.ts +22 -19
- package/src/lib/plugin.ts +3 -3
- package/src/lib/publish.task.ts +4 -4
- package/src/lib/release.task.ts +2 -2
- package/src/lib/source_json.ts +2 -7
- 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/src/lib/package_json.ts
CHANGED
|
@@ -24,9 +24,9 @@ export type PackageJsonMapper = (
|
|
|
24
24
|
package_json: PackageJson,
|
|
25
25
|
) => PackageJson | null | Promise<PackageJson | null>;
|
|
26
26
|
|
|
27
|
-
export const
|
|
27
|
+
export const PACKAGE_JSON_EMPTY: PackageJson = {name: '', version: ''};
|
|
28
28
|
|
|
29
|
-
export const
|
|
29
|
+
export const package_json_load = async (
|
|
30
30
|
dir = IS_THIS_GRO ? gro_paths.root : paths.root,
|
|
31
31
|
cache?: Record<string, PackageJson>,
|
|
32
32
|
parse = true, // TODO pass `false` here in more places, especially anything perf-sensitive like work on startup
|
|
@@ -37,10 +37,10 @@ export const load_package_json = async (
|
|
|
37
37
|
return cache[dir]!;
|
|
38
38
|
}
|
|
39
39
|
try {
|
|
40
|
-
package_json = JSON.parse(await
|
|
40
|
+
package_json = JSON.parse(await package_json_load_contents(dir));
|
|
41
41
|
} catch (error) {
|
|
42
42
|
log?.error(st('yellow', `Failed to load package.json in ${dir}`), error);
|
|
43
|
-
return
|
|
43
|
+
return PACKAGE_JSON_EMPTY;
|
|
44
44
|
}
|
|
45
45
|
if (parse) {
|
|
46
46
|
package_json = parse_package_json(PackageJson, package_json);
|
|
@@ -51,7 +51,7 @@ export const load_package_json = async (
|
|
|
51
51
|
return package_json;
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
export const
|
|
54
|
+
export const package_json_sync = async (
|
|
55
55
|
map_package_json: PackageJsonMapper,
|
|
56
56
|
log: Logger,
|
|
57
57
|
write = true,
|
|
@@ -60,10 +60,10 @@ export const sync_package_json = async (
|
|
|
60
60
|
): Promise<{package_json: PackageJson | null; changed: boolean}> => {
|
|
61
61
|
const exported_files = await fs_search(exports_dir);
|
|
62
62
|
const exported_paths = exported_files.map((f) => f.path);
|
|
63
|
-
const updated = await
|
|
63
|
+
const updated = await package_json_update(
|
|
64
64
|
async (package_json) => {
|
|
65
65
|
if ((await has_sveltekit_library(package_json)).ok) {
|
|
66
|
-
package_json.exports =
|
|
66
|
+
package_json.exports = package_json_to_exports(exported_paths);
|
|
67
67
|
}
|
|
68
68
|
const mapped = await map_package_json(package_json);
|
|
69
69
|
return mapped ? parse_package_json(PackageJson, mapped) : mapped;
|
|
@@ -85,43 +85,44 @@ export const sync_package_json = async (
|
|
|
85
85
|
return updated;
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
-
export const
|
|
88
|
+
export const package_json_load_for_gro = (): Promise<PackageJson> =>
|
|
89
|
+
package_json_load(gro_paths.root);
|
|
89
90
|
|
|
90
91
|
// TODO probably make this nullable and make callers handle failures
|
|
91
|
-
const
|
|
92
|
+
const package_json_load_contents = (dir: string): Promise<string> =>
|
|
92
93
|
readFile(join(dir, PACKAGE_JSON_FILENAME), 'utf8');
|
|
93
94
|
|
|
94
|
-
export const
|
|
95
|
+
export const package_json_write = (serialized_package_json: string): Promise<void> =>
|
|
95
96
|
writeFile(join(paths.root, PACKAGE_JSON_FILENAME), serialized_package_json);
|
|
96
97
|
|
|
97
|
-
export const
|
|
98
|
+
export const package_json_serialize = (package_json: PackageJson): string =>
|
|
98
99
|
JSON.stringify(parse_package_json(PackageJson, package_json), null, 2) + '\n';
|
|
99
100
|
|
|
100
101
|
/**
|
|
101
102
|
* Updates package.json. Writes to the filesystem only when contents change.
|
|
102
103
|
*/
|
|
103
|
-
export const
|
|
104
|
+
export const package_json_update = async (
|
|
104
105
|
update: (package_json: PackageJson) => PackageJson | null | Promise<PackageJson | null>,
|
|
105
106
|
dir = paths.root,
|
|
106
107
|
write = true,
|
|
107
108
|
): Promise<{package_json: PackageJson | null; changed: boolean}> => {
|
|
108
|
-
const original_contents = await
|
|
109
|
+
const original_contents = await package_json_load_contents(dir);
|
|
109
110
|
const original = JSON.parse(original_contents);
|
|
110
111
|
const updated = await update(original);
|
|
111
112
|
if (updated === null) {
|
|
112
113
|
return {package_json: original, changed: false};
|
|
113
114
|
}
|
|
114
|
-
const updated_contents =
|
|
115
|
+
const updated_contents = package_json_serialize(updated);
|
|
115
116
|
if (updated_contents === original_contents) {
|
|
116
117
|
return {package_json: original, changed: false};
|
|
117
118
|
}
|
|
118
|
-
if (write) await
|
|
119
|
+
if (write) await package_json_write(updated_contents);
|
|
119
120
|
return {package_json: updated, changed: true};
|
|
120
121
|
};
|
|
121
122
|
|
|
122
123
|
const is_index = (path: string): boolean => path === 'index.ts' || path === 'index.js';
|
|
123
124
|
|
|
124
|
-
export const
|
|
125
|
+
export const package_json_to_exports = (paths: Array<string>): PackageJsonExports => {
|
|
125
126
|
const has_index = paths.some(is_index);
|
|
126
127
|
const has_js = paths.some((p) => TS_MATCHER.test(p) || JS_MATCHER.test(p));
|
|
127
128
|
const has_svelte = paths.some((p) => SVELTE_MATCHER.test(p));
|
|
@@ -176,7 +177,7 @@ export const to_package_exports = (paths: Array<string>): PackageJsonExports =>
|
|
|
176
177
|
|
|
177
178
|
const IMPORT_PREFIX = './' + SVELTEKIT_DIST_DIRNAME + '/';
|
|
178
179
|
|
|
179
|
-
export const
|
|
180
|
+
export const package_json_parse_repo_url = (
|
|
180
181
|
package_json: PackageJson,
|
|
181
182
|
): {owner: string; repo: string} | undefined => {
|
|
182
183
|
const {repository} = package_json;
|
|
@@ -224,7 +225,7 @@ const parse_or_throw_formatted_error = <T extends z.ZodType>(
|
|
|
224
225
|
return parsed.data;
|
|
225
226
|
};
|
|
226
227
|
|
|
227
|
-
export const
|
|
228
|
+
export const package_json_has_dependency = (dep_name: string, package_json: PackageJson): boolean =>
|
|
228
229
|
!!package_json.devDependencies?.[dep_name] ||
|
|
229
230
|
!!package_json.dependencies?.[dep_name] ||
|
|
230
231
|
!!package_json.peerDependencies?.[dep_name];
|
|
@@ -234,7 +235,9 @@ export interface PackageJsonDep {
|
|
|
234
235
|
version: string;
|
|
235
236
|
}
|
|
236
237
|
|
|
237
|
-
export const
|
|
238
|
+
export const package_json_extract_dependencies = (
|
|
239
|
+
package_json: PackageJson,
|
|
240
|
+
): Array<PackageJsonDep> => {
|
|
238
241
|
const deps_by_name: Map<string, PackageJsonDep> = new Map();
|
|
239
242
|
// Earlier versions override later ones, so peer deps goes last.
|
|
240
243
|
const add_deps = (deps: Record<string, string> | undefined) => {
|
package/src/lib/plugin.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface Plugin<TPluginContext extends PluginContext = PluginContext> {
|
|
|
11
11
|
teardown?: (ctx: TPluginContext) => void | Promise<void>;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export type
|
|
14
|
+
export type PluginsCreateConfig<TPluginContext extends PluginContext = PluginContext> = (
|
|
15
15
|
ctx: TPluginContext,
|
|
16
16
|
) => Array<Plugin<TPluginContext>> | Promise<Array<Plugin<TPluginContext>>>;
|
|
17
17
|
|
|
@@ -88,12 +88,12 @@ export class Plugins<TPluginContext extends PluginContext> {
|
|
|
88
88
|
/**
|
|
89
89
|
* Replaces a plugin by name in `plugins` without mutating the param.
|
|
90
90
|
* Throws if the plugin name cannot be found.
|
|
91
|
-
* @param plugins - accepts the same types as the return value of `
|
|
91
|
+
* @param plugins - accepts the same types as the return value of `PluginsCreateConfig`
|
|
92
92
|
* @param new_plugin
|
|
93
93
|
* @param name - @default new_plugin.name
|
|
94
94
|
* @returns `plugins` with `new_plugin` at the index of the plugin with `name`
|
|
95
95
|
*/
|
|
96
|
-
export const
|
|
96
|
+
export const plugin_replace = (
|
|
97
97
|
plugins: Array<Plugin>,
|
|
98
98
|
new_plugin: Plugin,
|
|
99
99
|
name = new_plugin.name,
|
package/src/lib/publish.task.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from '@fuzdev/fuz_util/git.js';
|
|
13
13
|
|
|
14
14
|
import {TaskError, type Task} from './task.ts';
|
|
15
|
-
import {
|
|
15
|
+
import {package_json_load, package_json_parse_repo_url} from './package_json.ts';
|
|
16
16
|
import {find_cli, spawn_cli} from './cli.ts';
|
|
17
17
|
import {has_sveltekit_library} from './sveltekit_helpers.ts';
|
|
18
18
|
import {update_changelog} from './changelog.ts';
|
|
@@ -85,7 +85,7 @@ export const task: Task<Args> = {
|
|
|
85
85
|
log.info(st('green', 'dry run!'));
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
const package_json = await
|
|
88
|
+
const package_json = await package_json_load();
|
|
89
89
|
|
|
90
90
|
const has_sveltekit_library_result = await has_sveltekit_library(package_json);
|
|
91
91
|
if (!has_sveltekit_library_result.ok) {
|
|
@@ -140,7 +140,7 @@ export const task: Task<Args> = {
|
|
|
140
140
|
if (typeof package_json.version !== 'string') {
|
|
141
141
|
throw new TaskError('Failed to find package.json version');
|
|
142
142
|
}
|
|
143
|
-
const parsed_repo_url =
|
|
143
|
+
const parsed_repo_url = package_json_parse_repo_url(package_json);
|
|
144
144
|
if (!parsed_repo_url) {
|
|
145
145
|
throw new TaskError(
|
|
146
146
|
'package.json `repository` must contain a repo url (and GitHub only for now, sorry),' +
|
|
@@ -178,7 +178,7 @@ export const task: Task<Args> = {
|
|
|
178
178
|
// The check above ensures gen is updated.
|
|
179
179
|
await invoke_task('gen');
|
|
180
180
|
|
|
181
|
-
const package_json_after_versioning = await
|
|
181
|
+
const package_json_after_versioning = await package_json_load();
|
|
182
182
|
version = package_json_after_versioning.version!;
|
|
183
183
|
if (package_json.version === version) {
|
|
184
184
|
// The version didn't change.
|
package/src/lib/release.task.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {z} from 'zod';
|
|
|
2
2
|
|
|
3
3
|
import type {Task} from './task.ts';
|
|
4
4
|
import {has_sveltekit_library, has_sveltekit_app} from './sveltekit_helpers.ts';
|
|
5
|
-
import {
|
|
5
|
+
import {package_json_load} from './package_json.ts';
|
|
6
6
|
|
|
7
7
|
/** @nodocs */
|
|
8
8
|
export const Args = z.strictObject({});
|
|
@@ -13,7 +13,7 @@ export const task: Task<Args> = {
|
|
|
13
13
|
summary: 'publish and deploy',
|
|
14
14
|
Args,
|
|
15
15
|
run: async ({invoke_task}) => {
|
|
16
|
-
const package_json = await
|
|
16
|
+
const package_json = await package_json_load();
|
|
17
17
|
|
|
18
18
|
const publish = (await has_sveltekit_library(package_json)).ok;
|
|
19
19
|
if (publish) {
|
package/src/lib/source_json.ts
CHANGED
|
@@ -22,15 +22,10 @@ export const source_json_create = async (
|
|
|
22
22
|
SourceJson.parse({
|
|
23
23
|
name: package_json.name,
|
|
24
24
|
version: package_json.version,
|
|
25
|
-
modules: await
|
|
25
|
+
modules: await source_json_modules_create(package_json.exports, lib_path, log),
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
export const
|
|
29
|
-
const parsed = SourceJson.parse(source_json);
|
|
30
|
-
return JSON.stringify(parsed, null, 2) + '\n';
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const source_modules_create = async (
|
|
28
|
+
export const source_json_modules_create = async (
|
|
34
29
|
exports: PackageJsonExports | undefined,
|
|
35
30
|
lib_path = paths.lib,
|
|
36
31
|
log?: Logger,
|
|
@@ -4,7 +4,7 @@ import {join} from 'node:path';
|
|
|
4
4
|
import type {PackageJson} from '@fuzdev/fuz_util/package_json.js';
|
|
5
5
|
import {fs_exists} from '@fuzdev/fuz_util/fs.js';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {package_json_has_dependency} from './package_json.ts';
|
|
8
8
|
import {default_svelte_config, type ParsedSvelteConfig} from './svelte_config.ts';
|
|
9
9
|
import {
|
|
10
10
|
SVELTE_CONFIG_FILENAME,
|
|
@@ -41,7 +41,7 @@ export const has_sveltekit_library = async (
|
|
|
41
41
|
return {ok: false, message: `no SvelteKit lib directory found at ${svelte_config.lib_path}`};
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
if (!
|
|
44
|
+
if (!package_json_has_dependency(dep_name, package_json)) {
|
|
45
45
|
return {
|
|
46
46
|
ok: false,
|
|
47
47
|
message: `no dependency found in package.json for ${dep_name}`,
|
package/src/lib/sync.task.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {z} from 'zod';
|
|
|
2
2
|
import {spawn} from '@fuzdev/fuz_util/process.js';
|
|
3
3
|
|
|
4
4
|
import {TaskError, type Task} from './task.ts';
|
|
5
|
-
import {
|
|
5
|
+
import {package_json_sync} from './package_json.ts';
|
|
6
6
|
import {sveltekit_sync} from './sveltekit_helpers.ts';
|
|
7
7
|
|
|
8
8
|
/** @nodocs */
|
|
@@ -37,7 +37,7 @@ export const task: Task<Args> = {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
if (package_json && config.map_package_json) {
|
|
40
|
-
await
|
|
40
|
+
await package_json_sync(config.map_package_json, log);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
if (gen) {
|
package/src/lib/test.task.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {spawn_cli} from '@ryanatkn/gro/cli.js';
|
|
|
3
3
|
|
|
4
4
|
import {TaskError, type Task} from './task.ts';
|
|
5
5
|
import {find_cli} from './cli.ts';
|
|
6
|
-
import {
|
|
6
|
+
import {package_json_has_dependency, package_json_load} from './package_json.ts';
|
|
7
7
|
import {serialize_args, to_implicit_forwarded_args} from './args.ts';
|
|
8
8
|
import {VITEST_CLI} from './constants.ts';
|
|
9
9
|
import {paths} from './paths.ts';
|
|
@@ -30,8 +30,8 @@ export const task: Task<Args> = {
|
|
|
30
30
|
run: async ({args}): Promise<void> => {
|
|
31
31
|
const {_: patterns, dir, fail_without_tests, t} = args;
|
|
32
32
|
|
|
33
|
-
const package_json = await
|
|
34
|
-
if (!
|
|
33
|
+
const package_json = await package_json_load();
|
|
34
|
+
if (!package_json_has_dependency(VITEST_CLI, package_json)) {
|
|
35
35
|
throw new TaskError('no test runner found, install vitest');
|
|
36
36
|
}
|
|
37
37
|
|
package/src/lib/upgrade.task.ts
CHANGED
|
@@ -4,7 +4,11 @@ import {rm} from 'node:fs/promises';
|
|
|
4
4
|
import {GitOrigin, git_pull} from '@fuzdev/fuz_util/git.js';
|
|
5
5
|
|
|
6
6
|
import {TaskError, type Task} from './task.ts';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
package_json_extract_dependencies,
|
|
9
|
+
package_json_load,
|
|
10
|
+
type PackageJsonDep,
|
|
11
|
+
} from './package_json.ts';
|
|
8
12
|
import {spawn_cli} from './cli.ts';
|
|
9
13
|
import {serialize_args, to_forwarded_args} from './args.ts';
|
|
10
14
|
import {NODE_MODULES_DIRNAME} from './constants.ts';
|
|
@@ -83,9 +87,9 @@ export const task: Task<Args> = {
|
|
|
83
87
|
await rm(lockfile_path, {force: true});
|
|
84
88
|
}
|
|
85
89
|
|
|
86
|
-
const package_json = await
|
|
90
|
+
const package_json = await package_json_load();
|
|
87
91
|
|
|
88
|
-
const all_deps =
|
|
92
|
+
const all_deps = package_json_extract_dependencies(package_json);
|
|
89
93
|
|
|
90
94
|
const deps = only.length
|
|
91
95
|
? all_deps.filter((d) => only.includes(d.name))
|