@ryanatkn/gro 0.176.0 → 0.177.1
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/args.d.ts +5 -5
- package/dist/args.d.ts.map +1 -1
- package/dist/build.task.d.ts.map +1 -1
- package/dist/build.task.js +2 -2
- package/dist/build_cache.d.ts +12 -12
- package/dist/build_cache.d.ts.map +1 -1
- package/dist/build_cache.js +4 -4
- package/dist/changelog.d.ts +2 -2
- package/dist/changelog.d.ts.map +1 -1
- package/dist/changelog.js +1 -1
- package/dist/changeset.task.d.ts.map +1 -1
- package/dist/changeset.task.js +9 -9
- package/dist/changeset_helpers.d.ts +4 -4
- package/dist/changeset_helpers.d.ts.map +1 -1
- package/dist/changeset_helpers.js +2 -2
- package/dist/check.task.d.ts.map +1 -1
- package/dist/check.task.js +3 -3
- package/dist/clean.task.js +2 -2
- package/dist/cli.d.ts +6 -6
- package/dist/cli.d.ts.map +1 -1
- package/dist/commit.task.js +2 -2
- package/dist/deploy.task.d.ts.map +1 -1
- package/dist/deploy.task.js +13 -13
- package/dist/dev.task.d.ts +2 -2
- package/dist/dev.task.d.ts.map +1 -1
- package/dist/disknode.d.ts +4 -4
- package/dist/disknode.d.ts.map +1 -1
- package/dist/esbuild_helpers.d.ts +2 -2
- package/dist/esbuild_helpers.d.ts.map +1 -1
- package/dist/esbuild_plugin_external_worker.d.ts +5 -5
- package/dist/esbuild_plugin_external_worker.d.ts.map +1 -1
- package/dist/esbuild_plugin_svelte.d.ts +4 -4
- package/dist/esbuild_plugin_svelte.d.ts.map +1 -1
- package/dist/esbuild_plugin_sveltekit_shim_alias.d.ts +2 -2
- package/dist/esbuild_plugin_sveltekit_shim_alias.d.ts.map +1 -1
- package/dist/esbuild_plugin_sveltekit_shim_app.d.ts +5 -5
- package/dist/esbuild_plugin_sveltekit_shim_app.d.ts.map +1 -1
- package/dist/esbuild_plugin_sveltekit_shim_env.d.ts +2 -2
- package/dist/esbuild_plugin_sveltekit_shim_env.d.ts.map +1 -1
- package/dist/filer.d.ts +15 -15
- package/dist/filer.d.ts.map +1 -1
- package/dist/filer.js +2 -2
- package/dist/format.task.d.ts.map +1 -1
- package/dist/format.task.js +2 -2
- package/dist/format_directory.d.ts +2 -2
- package/dist/format_directory.d.ts.map +1 -1
- package/dist/gen.d.ts +73 -73
- package/dist/gen.d.ts.map +1 -1
- package/dist/gen.js +1 -1
- package/dist/gen.task.d.ts.map +1 -1
- package/dist/gen.task.js +8 -8
- package/dist/gen_helpers.d.ts +4 -4
- package/dist/gen_helpers.d.ts.map +1 -1
- package/dist/gen_helpers.js +1 -1
- package/dist/github.d.ts +4 -4
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +3 -3
- package/dist/gro.config.default.d.ts +2 -2
- package/dist/gro.config.default.d.ts.map +1 -1
- package/dist/gro_config.d.ts +25 -25
- package/dist/gro_config.d.ts.map +1 -1
- package/dist/gro_config.js +2 -2
- package/dist/gro_helpers.d.ts +2 -2
- package/dist/gro_helpers.d.ts.map +1 -1
- package/dist/gro_plugin_gen.d.ts +3 -3
- package/dist/gro_plugin_gen.d.ts.map +1 -1
- package/dist/gro_plugin_gen.js +2 -2
- package/dist/gro_plugin_server.d.ts +7 -7
- package/dist/gro_plugin_server.d.ts.map +1 -1
- package/dist/gro_plugin_sveltekit_app.d.ts +10 -10
- package/dist/gro_plugin_sveltekit_app.d.ts.map +1 -1
- package/dist/gro_plugin_sveltekit_app.js +2 -2
- package/dist/gro_plugin_sveltekit_library.d.ts +4 -4
- package/dist/gro_plugin_sveltekit_library.d.ts.map +1 -1
- package/dist/gro_plugin_sveltekit_library.js +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/input_path.d.ts +30 -30
- package/dist/input_path.d.ts.map +1 -1
- package/dist/input_path.js +2 -2
- package/dist/invoke.js +1 -1
- package/dist/invoke_task.d.ts +3 -3
- package/dist/invoke_task.d.ts.map +1 -1
- package/dist/invoke_task.js +4 -4
- package/dist/lint.task.d.ts.map +1 -1
- package/dist/lint.task.js +2 -2
- package/dist/modules.d.ts +20 -20
- package/dist/modules.d.ts.map +1 -1
- package/dist/modules.js +2 -2
- package/dist/package_json.d.ts +16 -16
- package/dist/package_json.d.ts.map +1 -1
- package/dist/package_json.js +6 -6
- package/dist/parse_exports.d.ts +7 -7
- package/dist/parse_exports.d.ts.map +1 -1
- package/dist/parse_exports.js +3 -3
- package/dist/parse_exports_context.d.ts +3 -3
- package/dist/parse_exports_context.d.ts.map +1 -1
- package/dist/parse_exports_context.js +1 -1
- package/dist/parse_imports.d.ts +3 -3
- package/dist/parse_imports.d.ts.map +1 -1
- package/dist/parse_imports.js +2 -2
- package/dist/paths.d.ts +6 -6
- package/dist/paths.d.ts.map +1 -1
- package/dist/plugin.d.ts +13 -13
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +1 -1
- package/dist/publish.task.d.ts.map +1 -1
- package/dist/publish.task.js +12 -12
- package/dist/reinstall.task.d.ts.map +1 -1
- package/dist/reinstall.task.js +4 -4
- package/dist/resolve_specifier.d.ts +4 -4
- package/dist/resolve_specifier.d.ts.map +1 -1
- package/dist/run.task.d.ts.map +1 -1
- package/dist/run.task.js +9 -6
- package/dist/run_gen.d.ts +4 -4
- package/dist/run_gen.d.ts.map +1 -1
- package/dist/run_task.d.ts +4 -4
- package/dist/run_task.d.ts.map +1 -1
- package/dist/run_task.js +3 -3
- package/dist/search_fs.d.ts +6 -6
- package/dist/search_fs.d.ts.map +1 -1
- package/dist/src_json.d.ts +6 -6
- package/dist/src_json.d.ts.map +1 -1
- package/dist/src_json.js +3 -3
- package/dist/svelte_config.d.ts +3 -3
- package/dist/svelte_config.d.ts.map +1 -1
- package/dist/sveltekit_helpers.d.ts +5 -5
- package/dist/sveltekit_helpers.d.ts.map +1 -1
- package/dist/sveltekit_helpers.js +5 -5
- package/dist/sveltekit_shim_app.d.ts +2 -2
- package/dist/sveltekit_shim_app.d.ts.map +1 -1
- package/dist/sync.task.d.ts.map +1 -1
- package/dist/sync.task.js +2 -2
- package/dist/task.d.ts +54 -54
- package/dist/task.d.ts.map +1 -1
- package/dist/task.js +3 -3
- package/dist/task_logging.d.ts +3 -3
- package/dist/task_logging.d.ts.map +1 -1
- package/dist/test.task.d.ts.map +1 -1
- package/dist/test.task.js +4 -4
- package/dist/typecheck.task.d.ts.map +1 -1
- package/dist/typecheck.task.js +4 -4
- package/dist/upgrade.task.d.ts.map +1 -1
- package/dist/upgrade.task.js +5 -5
- package/dist/watch_dir.d.ts +10 -10
- package/dist/watch_dir.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/lib/args.ts +9 -9
- package/src/lib/build.task.ts +2 -2
- package/src/lib/build_cache.ts +18 -18
- package/src/lib/changelog.ts +10 -10
- package/src/lib/changeset.task.ts +16 -16
- package/src/lib/changeset_helpers.ts +4 -4
- package/src/lib/check.task.ts +3 -3
- package/src/lib/clean.task.ts +2 -2
- package/src/lib/cli.ts +7 -7
- package/src/lib/commit.task.ts +2 -2
- package/src/lib/deploy.task.ts +15 -15
- package/src/lib/dev.task.ts +2 -2
- package/src/lib/disknode.ts +4 -4
- package/src/lib/esbuild_helpers.ts +2 -2
- package/src/lib/esbuild_plugin_external_worker.ts +7 -7
- package/src/lib/esbuild_plugin_svelte.ts +4 -4
- package/src/lib/esbuild_plugin_sveltekit_shim_alias.ts +2 -2
- package/src/lib/esbuild_plugin_sveltekit_shim_app.ts +5 -5
- package/src/lib/esbuild_plugin_sveltekit_shim_env.ts +2 -2
- package/src/lib/filer.ts +35 -35
- package/src/lib/format.task.ts +2 -2
- package/src/lib/format_directory.ts +2 -2
- package/src/lib/gen.task.ts +19 -19
- package/src/lib/gen.ts +85 -85
- package/src/lib/gen_helpers.ts +17 -17
- package/src/lib/github.ts +6 -6
- package/src/lib/gro.config.default.ts +2 -2
- package/src/lib/gro_config.ts +28 -28
- package/src/lib/gro_helpers.ts +2 -2
- package/src/lib/gro_plugin_gen.ts +5 -5
- package/src/lib/gro_plugin_server.ts +8 -8
- package/src/lib/gro_plugin_sveltekit_app.ts +15 -15
- package/src/lib/gro_plugin_sveltekit_library.ts +6 -6
- package/src/lib/index.ts +3 -3
- package/src/lib/input_path.ts +56 -56
- package/src/lib/invoke.ts +2 -2
- package/src/lib/invoke_task.ts +7 -7
- package/src/lib/lint.task.ts +2 -2
- package/src/lib/modules.ts +31 -31
- package/src/lib/package_json.ts +27 -27
- package/src/lib/parse_exports.ts +15 -15
- package/src/lib/parse_exports_context.ts +9 -9
- package/src/lib/parse_imports.ts +6 -6
- package/src/lib/paths.ts +6 -6
- package/src/lib/plugin.ts +17 -17
- package/src/lib/publish.task.ts +13 -13
- package/src/lib/reinstall.task.ts +4 -4
- package/src/lib/resolve_specifier.ts +5 -5
- package/src/lib/run.task.ts +10 -6
- package/src/lib/run_gen.ts +14 -14
- package/src/lib/run_task.ts +8 -8
- package/src/lib/search_fs.ts +13 -13
- package/src/lib/src_json.ts +13 -13
- package/src/lib/svelte_config.ts +2 -2
- package/src/lib/sveltekit_helpers.ts +12 -12
- package/src/lib/sveltekit_shim_app.ts +3 -3
- package/src/lib/sync.task.ts +2 -2
- package/src/lib/task.ts +63 -63
- package/src/lib/task_logging.ts +11 -11
- package/src/lib/test.task.ts +4 -4
- package/src/lib/typecheck.task.ts +4 -4
- package/src/lib/upgrade.task.ts +7 -7
- package/src/lib/watch_dir.ts +10 -10
package/src/lib/changelog.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {readFile, writeFile} from 'node:fs/promises';
|
|
2
2
|
import {z} from 'zod';
|
|
3
3
|
import type {Logger} from '@ryanatkn/belt/log.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type {FetchValueCache} from '@ryanatkn/belt/fetch.js';
|
|
5
5
|
|
|
6
6
|
import {github_fetch_commit_prs} from './github.ts';
|
|
7
7
|
|
|
@@ -18,7 +18,7 @@ export const update_changelog = async (
|
|
|
18
18
|
path = 'CHANGELOG.md',
|
|
19
19
|
token?: string,
|
|
20
20
|
log?: Logger,
|
|
21
|
-
cache:
|
|
21
|
+
cache: FetchValueCache = new Map(), // include a default cache to efficiently handle multiple changesets per commit
|
|
22
22
|
): Promise<boolean> => {
|
|
23
23
|
const contents = await readFile(path, 'utf8');
|
|
24
24
|
const parsed = parse_changelog(contents);
|
|
@@ -32,22 +32,22 @@ export const update_changelog = async (
|
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
// keeping this really simple for now, no need to parse further for our current usecases
|
|
35
|
-
const
|
|
36
|
-
type
|
|
37
|
-
const parse_changelog = (contents: string):
|
|
38
|
-
const serialize_changelog = (parsed:
|
|
35
|
+
const ParsedChangelog = z.array(z.string());
|
|
36
|
+
type ParsedChangelog = z.infer<typeof ParsedChangelog>;
|
|
37
|
+
const parse_changelog = (contents: string): ParsedChangelog => contents.split('\n');
|
|
38
|
+
const serialize_changelog = (parsed: ParsedChangelog): string => parsed.join('\n');
|
|
39
39
|
|
|
40
40
|
const LINE_WITH_SHA_MATCHER = /^- ([a-z0-9]{7,8}): /;
|
|
41
41
|
|
|
42
42
|
const map_changelog = async (
|
|
43
|
-
parsed:
|
|
43
|
+
parsed: ParsedChangelog,
|
|
44
44
|
owner: string,
|
|
45
45
|
repo: string,
|
|
46
46
|
token?: string,
|
|
47
47
|
log?: Logger,
|
|
48
|
-
cache?:
|
|
49
|
-
): Promise<
|
|
50
|
-
const mapped:
|
|
48
|
+
cache?: FetchValueCache,
|
|
49
|
+
): Promise<ParsedChangelog> => {
|
|
50
|
+
const mapped: ParsedChangelog = [];
|
|
51
51
|
for (const line of parsed) {
|
|
52
52
|
const matches = LINE_WITH_SHA_MATCHER.exec(line);
|
|
53
53
|
if (matches) {
|
|
@@ -6,19 +6,19 @@ import {readFile, writeFile} from 'node:fs/promises';
|
|
|
6
6
|
import {join} from 'node:path';
|
|
7
7
|
import {existsSync, readdirSync} from 'node:fs';
|
|
8
8
|
import {
|
|
9
|
-
|
|
9
|
+
GitOrigin,
|
|
10
10
|
git_check_fully_staged_workspace,
|
|
11
11
|
git_push_to_create,
|
|
12
12
|
} from '@ryanatkn/belt/git.js';
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import {TaskError, type Task} from './task.ts';
|
|
15
15
|
import {find_cli, spawn_cli} from './cli.ts';
|
|
16
16
|
import {has_sveltekit_library} from './sveltekit_helpers.ts';
|
|
17
17
|
import {
|
|
18
18
|
CHANGESET_CLI,
|
|
19
19
|
CHANGESET_DIR,
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
ChangesetAccess,
|
|
21
|
+
ChangesetBump,
|
|
22
22
|
CHANGESET_PUBLIC_ACCESS,
|
|
23
23
|
CHANGESET_RESTRICTED_ACCESS,
|
|
24
24
|
} from './changeset_helpers.ts';
|
|
@@ -37,7 +37,7 @@ export const Args = z.strictObject({
|
|
|
37
37
|
minor: z.boolean().meta({description: 'bump the minor version'}).default(false),
|
|
38
38
|
major: z.boolean().meta({description: 'bump the major version'}).default(false),
|
|
39
39
|
dir: z.string().meta({description: 'changeset dir'}).default(CHANGESET_DIR),
|
|
40
|
-
access:
|
|
40
|
+
access: ChangesetAccess.describe(
|
|
41
41
|
"changeset 'access' config value, the default depends on package.json#private",
|
|
42
42
|
).optional(),
|
|
43
43
|
changelog: z
|
|
@@ -49,7 +49,7 @@ export const Args = z.strictObject({
|
|
|
49
49
|
.boolean()
|
|
50
50
|
.meta({description: 'opt out of installing the changelog package'})
|
|
51
51
|
.default(false),
|
|
52
|
-
origin:
|
|
52
|
+
origin: GitOrigin.describe('git origin to deploy to').default('origin'),
|
|
53
53
|
changeset_cli: z.string().meta({description: 'the changeset CLI to use'}).default(CHANGESET_CLI),
|
|
54
54
|
});
|
|
55
55
|
export type Args = z.infer<typeof Args>;
|
|
@@ -87,14 +87,14 @@ export const task: Task<Args> = {
|
|
|
87
87
|
config,
|
|
88
88
|
} = ctx;
|
|
89
89
|
|
|
90
|
-
if (!message && (minor || major)) throw new
|
|
91
|
-
if (minor && major) throw new
|
|
90
|
+
if (!message && (minor || major)) throw new TaskError('cannot bump version without a message');
|
|
91
|
+
if (minor && major) throw new TaskError('cannot bump both minor and major');
|
|
92
92
|
|
|
93
|
-
const bump:
|
|
93
|
+
const bump: ChangesetBump = minor ? 'minor' : major ? 'major' : 'patch';
|
|
94
94
|
|
|
95
95
|
const found_changeset_cli = find_cli(changeset_cli);
|
|
96
96
|
if (!found_changeset_cli) {
|
|
97
|
-
throw new
|
|
97
|
+
throw new TaskError(
|
|
98
98
|
'changeset command not found: install @changesets/cli locally or globally',
|
|
99
99
|
);
|
|
100
100
|
}
|
|
@@ -103,7 +103,7 @@ export const task: Task<Args> = {
|
|
|
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) {
|
|
106
|
-
throw new
|
|
106
|
+
throw new TaskError(
|
|
107
107
|
'Failed to find SvelteKit library: ' + has_sveltekit_library_result.message,
|
|
108
108
|
);
|
|
109
109
|
}
|
|
@@ -165,7 +165,7 @@ const create_changeset_adder = (
|
|
|
165
165
|
repo_name: string,
|
|
166
166
|
dir: string,
|
|
167
167
|
message: string,
|
|
168
|
-
bump:
|
|
168
|
+
bump: ChangesetBump,
|
|
169
169
|
) => {
|
|
170
170
|
const filenames_before = readdirSync(dir);
|
|
171
171
|
return async () => {
|
|
@@ -187,7 +187,7 @@ const create_changeset_adder = (
|
|
|
187
187
|
const create_new_changeset = (
|
|
188
188
|
repo_name: string,
|
|
189
189
|
message: string,
|
|
190
|
-
bump:
|
|
190
|
+
bump: ChangesetBump,
|
|
191
191
|
): string => `---
|
|
192
192
|
"${repo_name}": ${bump}
|
|
193
193
|
---
|
|
@@ -195,13 +195,13 @@ const create_new_changeset = (
|
|
|
195
195
|
${message}
|
|
196
196
|
`;
|
|
197
197
|
|
|
198
|
-
type
|
|
198
|
+
type ChangesetCallback = (config: WrittenConfig) => WrittenConfig | Promise<WrittenConfig>;
|
|
199
199
|
|
|
200
|
-
type
|
|
200
|
+
type UpdateWrittenConfig = (path: string, cb: ChangesetCallback) => Promise<boolean>;
|
|
201
201
|
|
|
202
202
|
// TODO refactor all of this with zod and package_json helpers - util file helper? JSON parse pluggable
|
|
203
203
|
|
|
204
|
-
const update_changeset_config:
|
|
204
|
+
const update_changeset_config: UpdateWrittenConfig = async (path, cb) => {
|
|
205
205
|
const config_contents = await load_changeset_config_contents(path);
|
|
206
206
|
const config = parse_changeset_config(config_contents);
|
|
207
207
|
|
|
@@ -3,12 +3,12 @@ import {z} from 'zod';
|
|
|
3
3
|
export const CHANGESET_RESTRICTED_ACCESS = 'restricted';
|
|
4
4
|
export const CHANGESET_PUBLIC_ACCESS = 'public';
|
|
5
5
|
|
|
6
|
-
export const
|
|
7
|
-
export type
|
|
6
|
+
export const ChangesetAccess = z.enum([CHANGESET_RESTRICTED_ACCESS, CHANGESET_PUBLIC_ACCESS]);
|
|
7
|
+
export type ChangesetAccess = z.infer<typeof ChangesetAccess>;
|
|
8
8
|
|
|
9
9
|
export const CHANGESET_CLI = 'changeset';
|
|
10
10
|
|
|
11
11
|
export const CHANGESET_DIR = '.changeset';
|
|
12
12
|
|
|
13
|
-
export const
|
|
14
|
-
export type
|
|
13
|
+
export const ChangesetBump = z.enum(['patch', 'minor', 'major']);
|
|
14
|
+
export type ChangesetBump = z.infer<typeof ChangesetBump>;
|
package/src/lib/check.task.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {spawn} from '@ryanatkn/belt/process.js';
|
|
|
3
3
|
import {styleText as st} from 'node:util';
|
|
4
4
|
import {git_check_clean_workspace} from '@ryanatkn/belt/git.js';
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {TaskError, type Task} from './task.ts';
|
|
7
7
|
import {sync_package_json} from './package_json.ts';
|
|
8
8
|
|
|
9
9
|
/** @nodocs */
|
|
@@ -64,7 +64,7 @@ export const task: Task<Args> = {
|
|
|
64
64
|
if (package_json && config.map_package_json) {
|
|
65
65
|
const {changed} = await sync_package_json(config.map_package_json, log, false);
|
|
66
66
|
if (changed) {
|
|
67
|
-
throw new
|
|
67
|
+
throw new TaskError('package.json is out of date, run `gro sync` to update it');
|
|
68
68
|
} else {
|
|
69
69
|
log.info('check passed for package.json');
|
|
70
70
|
}
|
|
@@ -86,7 +86,7 @@ export const task: Task<Args> = {
|
|
|
86
86
|
if (error_message) {
|
|
87
87
|
log.error(st('red', 'git status'));
|
|
88
88
|
await spawn('git', ['status']);
|
|
89
|
-
throw new
|
|
89
|
+
throw new TaskError(
|
|
90
90
|
'Failed check for git_check_clean_workspace:' +
|
|
91
91
|
error_message +
|
|
92
92
|
' - do you need to run `gro sync` or commit some files?',
|
package/src/lib/clean.task.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {spawn} from '@ryanatkn/belt/process.js';
|
|
2
2
|
import {z} from 'zod';
|
|
3
|
-
import {
|
|
3
|
+
import {GitOrigin} from '@ryanatkn/belt/git.js';
|
|
4
4
|
|
|
5
5
|
import type {Task} from './task.ts';
|
|
6
6
|
import {clean_fs} from './clean_fs.ts';
|
|
@@ -21,7 +21,7 @@ export const Args = z.strictObject({
|
|
|
21
21
|
'run "git remote prune" to delete local branches referencing nonexistent remote branches',
|
|
22
22
|
})
|
|
23
23
|
.default(false),
|
|
24
|
-
git_origin:
|
|
24
|
+
git_origin: GitOrigin.describe('the origin to "git remote prune"').default('origin'),
|
|
25
25
|
});
|
|
26
26
|
export type Args = z.infer<typeof Args>;
|
|
27
27
|
|
package/src/lib/cli.ts
CHANGED
|
@@ -2,14 +2,14 @@ import {spawnSync, type SpawnOptions} from 'node:child_process';
|
|
|
2
2
|
import {
|
|
3
3
|
spawn,
|
|
4
4
|
spawn_process,
|
|
5
|
-
type
|
|
6
|
-
type
|
|
5
|
+
type SpawnResult,
|
|
6
|
+
type SpawnedProcess,
|
|
7
7
|
} from '@ryanatkn/belt/process.js';
|
|
8
8
|
import {join} from 'node:path';
|
|
9
9
|
import {existsSync} from 'node:fs';
|
|
10
10
|
import {fileURLToPath, type URL} from 'node:url';
|
|
11
11
|
import type {Logger} from '@ryanatkn/belt/log.js';
|
|
12
|
-
import type {
|
|
12
|
+
import type {PathId} from '@ryanatkn/belt/path.js';
|
|
13
13
|
|
|
14
14
|
import {NODE_MODULES_DIRNAME} from './constants.ts';
|
|
15
15
|
import {print_command_args} from './args.ts';
|
|
@@ -17,8 +17,8 @@ import {print_command_args} from './args.ts';
|
|
|
17
17
|
// TODO maybe upstream to Belt?
|
|
18
18
|
|
|
19
19
|
export type Cli =
|
|
20
|
-
| {kind: 'local'; name: string; id:
|
|
21
|
-
| {kind: 'global'; name: string; id:
|
|
20
|
+
| {kind: 'local'; name: string; id: PathId}
|
|
21
|
+
| {kind: 'global'; name: string; id: PathId};
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Searches the filesystem for the CLI `name`, first local to the cwd and then globally.
|
|
@@ -50,7 +50,7 @@ export const spawn_cli = async (
|
|
|
50
50
|
args: Array<string> = [],
|
|
51
51
|
log?: Logger,
|
|
52
52
|
options?: SpawnOptions,
|
|
53
|
-
): Promise<
|
|
53
|
+
): Promise<SpawnResult | undefined> => {
|
|
54
54
|
const cli = resolve_cli(name_or_cli, args, options?.cwd, log, options);
|
|
55
55
|
if (!cli) return;
|
|
56
56
|
return spawn(cli.id, args, options);
|
|
@@ -66,7 +66,7 @@ export const spawn_cli_process = (
|
|
|
66
66
|
args: Array<string> = [],
|
|
67
67
|
log?: Logger,
|
|
68
68
|
options?: SpawnOptions,
|
|
69
|
-
):
|
|
69
|
+
): SpawnedProcess | undefined => {
|
|
70
70
|
const cli = resolve_cli(name_or_cli, args, options?.cwd, log, options);
|
|
71
71
|
if (!cli) return;
|
|
72
72
|
return spawn_process(cli.id, args, options);
|
package/src/lib/commit.task.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {spawn} from '@ryanatkn/belt/process.js';
|
|
2
2
|
import {z} from 'zod';
|
|
3
|
-
import {
|
|
3
|
+
import {GitOrigin, git_current_branch_name, git_push} from '@ryanatkn/belt/git.js';
|
|
4
4
|
|
|
5
5
|
import type {Task} from './task.ts';
|
|
6
6
|
|
|
@@ -12,7 +12,7 @@ export const Args = z.strictObject({
|
|
|
12
12
|
description: 'the git commit message, the same as git commit -m or --message',
|
|
13
13
|
})
|
|
14
14
|
.default([]),
|
|
15
|
-
origin:
|
|
15
|
+
origin: GitOrigin.describe('git origin to commit to').default('origin'),
|
|
16
16
|
});
|
|
17
17
|
export type Args = z.infer<typeof Args>;
|
|
18
18
|
|
package/src/lib/deploy.task.ts
CHANGED
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
git_checkout,
|
|
11
11
|
git_local_branch_exists,
|
|
12
12
|
git_remote_branch_exists,
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
GitOrigin,
|
|
14
|
+
GitBranch,
|
|
15
15
|
git_delete_local_branch,
|
|
16
16
|
git_push_to_create,
|
|
17
17
|
git_reset_branch_to_first_commit,
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
} from '@ryanatkn/belt/git.js';
|
|
24
24
|
import {fs_empty_dir} from '@ryanatkn/belt/fs.js';
|
|
25
25
|
|
|
26
|
-
import {
|
|
26
|
+
import {TaskError, type Task} from './task.ts';
|
|
27
27
|
import {print_path} from './paths.ts';
|
|
28
28
|
import {GRO_DIRNAME, GIT_DIRNAME, SVELTEKIT_BUILD_DIRNAME} from './constants.ts';
|
|
29
29
|
|
|
@@ -42,9 +42,9 @@ const DANGEROUS_BRANCHES = [SOURCE_BRANCH, 'master'];
|
|
|
42
42
|
|
|
43
43
|
/** @nodocs */
|
|
44
44
|
export const Args = z.strictObject({
|
|
45
|
-
source:
|
|
46
|
-
target:
|
|
47
|
-
origin:
|
|
45
|
+
source: GitBranch.describe('git source branch to build and deploy from').default(SOURCE_BRANCH),
|
|
46
|
+
target: GitBranch.describe('git target branch to deploy to').default(TARGET_BRANCH),
|
|
47
|
+
origin: GitOrigin.describe('git origin to deploy to').default('origin'),
|
|
48
48
|
deploy_dir: z.string().meta({description: 'the deploy output directory'}).default(DEPLOY_DIR),
|
|
49
49
|
build_dir: z
|
|
50
50
|
.string()
|
|
@@ -98,7 +98,7 @@ export const task: Task<Args> = {
|
|
|
98
98
|
|
|
99
99
|
// Checks
|
|
100
100
|
if (!force && target !== TARGET_BRANCH) {
|
|
101
|
-
throw new
|
|
101
|
+
throw new TaskError(
|
|
102
102
|
`Warning! You are deploying to a custom target branch '${target}',` +
|
|
103
103
|
` instead of the default '${TARGET_BRANCH}' branch.` +
|
|
104
104
|
` This is destructive to your '${target}' branch!` +
|
|
@@ -107,7 +107,7 @@ export const task: Task<Args> = {
|
|
|
107
107
|
);
|
|
108
108
|
}
|
|
109
109
|
if (!dangerous && DANGEROUS_BRANCHES.includes(target)) {
|
|
110
|
-
throw new
|
|
110
|
+
throw new TaskError(
|
|
111
111
|
`Warning! You are deploying to a custom target branch '${target}'` +
|
|
112
112
|
` and that appears very dangerous: it is destructive to your '${target}' branch!` +
|
|
113
113
|
` If you understand and are OK with deleting your branch '${target}',` +
|
|
@@ -116,12 +116,12 @@ export const task: Task<Args> = {
|
|
|
116
116
|
}
|
|
117
117
|
const clean_error_message = await git_check_clean_workspace();
|
|
118
118
|
if (clean_error_message) {
|
|
119
|
-
throw new
|
|
119
|
+
throw new TaskError(
|
|
120
120
|
'Deploy failed because the git workspace has uncommitted changes: ' + clean_error_message,
|
|
121
121
|
);
|
|
122
122
|
}
|
|
123
123
|
if (!(await git_check_setting_pull_rebase())) {
|
|
124
|
-
throw new
|
|
124
|
+
throw new TaskError(
|
|
125
125
|
'Deploying currently requires `git config --global pull.rebase true`,' +
|
|
126
126
|
' but this restriction could be lifted with more work',
|
|
127
127
|
);
|
|
@@ -138,7 +138,7 @@ export const task: Task<Args> = {
|
|
|
138
138
|
await git_pull(origin, source);
|
|
139
139
|
}
|
|
140
140
|
if (await git_check_clean_workspace()) {
|
|
141
|
-
throw new
|
|
141
|
+
throw new TaskError(
|
|
142
142
|
'Deploy failed because the local source branch is out of sync with the remote one,' +
|
|
143
143
|
' finish rebasing manually or reset with `git rebase --abort`',
|
|
144
144
|
);
|
|
@@ -177,7 +177,7 @@ export const task: Task<Args> = {
|
|
|
177
177
|
// It may not exist, or it may have been deleted after failing to sync above.
|
|
178
178
|
if (!existsSync(resolved_deploy_dir)) {
|
|
179
179
|
const local_deploy_branch_exists = await git_local_branch_exists(target);
|
|
180
|
-
await git_fetch(origin, ('+' + target + ':' + target) as
|
|
180
|
+
await git_fetch(origin, ('+' + target + ':' + target) as GitBranch); // fetch+merge and allow non-fastforward updates with the +
|
|
181
181
|
await git_clone_locally(origin, target, dir, resolved_deploy_dir);
|
|
182
182
|
// Clean up if we created the target branch in the cwd
|
|
183
183
|
if (!local_deploy_branch_exists) {
|
|
@@ -234,12 +234,12 @@ export const task: Task<Args> = {
|
|
|
234
234
|
if (dry) {
|
|
235
235
|
log.info(st('red', 'dry deploy failed'));
|
|
236
236
|
}
|
|
237
|
-
throw new
|
|
237
|
+
throw new TaskError(`Deploy safely canceled due to build failure. See the error above.`);
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
// Verify build output exists
|
|
241
241
|
if (!existsSync(build_dir)) {
|
|
242
|
-
throw new
|
|
242
|
+
throw new TaskError(`Directory to deploy does not exist after building: ${build_dir}`);
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
// Copy the build
|
|
@@ -262,7 +262,7 @@ export const task: Task<Args> = {
|
|
|
262
262
|
await spawn('git', ['push', origin, target, '-f'], target_spawn_options); // force push because we may be resetting the branch, see the checks above to make this safer
|
|
263
263
|
} catch (err) {
|
|
264
264
|
log.error(st('red', 'updating git failed:'), print_error(err));
|
|
265
|
-
throw new
|
|
265
|
+
throw new TaskError(`Deploy failed in a bad state: built but not pushed, see error above.`);
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
log.info(st('green', 'deployed')); // TODO log a different message if "Everything up-to-date"
|
package/src/lib/dev.task.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {z} from 'zod';
|
|
2
2
|
|
|
3
3
|
import type {Task} from './task.ts';
|
|
4
|
-
import {Plugins, type
|
|
4
|
+
import {Plugins, type PluginContext} from './plugin.ts';
|
|
5
5
|
import {clean_fs} from './clean_fs.ts';
|
|
6
6
|
|
|
7
7
|
/** @nodocs */
|
|
@@ -19,7 +19,7 @@ export const Args = z.strictObject({
|
|
|
19
19
|
});
|
|
20
20
|
export type Args = z.infer<typeof Args>;
|
|
21
21
|
|
|
22
|
-
export type DevTask_Context =
|
|
22
|
+
export type DevTask_Context = PluginContext<Args>;
|
|
23
23
|
|
|
24
24
|
/** @nodocs */
|
|
25
25
|
export const task: Task<Args> = {
|
package/src/lib/disknode.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {PathId} from '@ryanatkn/belt/path.js';
|
|
2
2
|
|
|
3
3
|
// TODO extract more here from Filer
|
|
4
4
|
|
|
5
5
|
export interface Disknode {
|
|
6
|
-
id:
|
|
6
|
+
id: PathId;
|
|
7
7
|
// TODO figure out the best API that makes this lazy
|
|
8
8
|
/**
|
|
9
9
|
* `null` contents means it doesn't exist.
|
|
@@ -16,6 +16,6 @@ export interface Disknode {
|
|
|
16
16
|
external: boolean;
|
|
17
17
|
ctime: number | null;
|
|
18
18
|
mtime: number | null;
|
|
19
|
-
dependents: Map<
|
|
20
|
-
dependencies: Map<
|
|
19
|
+
dependents: Map<PathId, Disknode>;
|
|
20
|
+
dependencies: Map<PathId, Disknode>;
|
|
21
21
|
}
|
|
@@ -2,7 +2,7 @@ import {styleText as st} from 'node:util';
|
|
|
2
2
|
import type {Logger} from '@ryanatkn/belt/log.js';
|
|
3
3
|
import type * as esbuild from 'esbuild';
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type {ParsedSvelteConfig} from './svelte_config.ts';
|
|
6
6
|
|
|
7
7
|
export const print_build_result = (log: Logger, build_result: esbuild.BuildResult): void => {
|
|
8
8
|
for (const error of build_result.errors) {
|
|
@@ -28,7 +28,7 @@ const import_meta_env = 'import.' + 'meta.env.'; // eslint-disable-line no-usele
|
|
|
28
28
|
*/
|
|
29
29
|
export const to_define_import_meta_env = (
|
|
30
30
|
dev: boolean,
|
|
31
|
-
base_url:
|
|
31
|
+
base_url: ParsedSvelteConfig['base_url'],
|
|
32
32
|
ssr = true,
|
|
33
33
|
mode = dev ? 'development' : 'production',
|
|
34
34
|
): Record<string, string> => ({
|
|
@@ -2,7 +2,7 @@ import * as esbuild from 'esbuild';
|
|
|
2
2
|
import type {Logger} from '@ryanatkn/belt/log.js';
|
|
3
3
|
import {basename} from 'node:path';
|
|
4
4
|
import type {CompileOptions, ModuleCompileOptions, PreprocessorGroup} from 'svelte/compiler';
|
|
5
|
-
import type {
|
|
5
|
+
import type {PathId} from '@ryanatkn/belt/path.js';
|
|
6
6
|
|
|
7
7
|
import {print_build_result, to_define_import_meta_env} from './esbuild_helpers.ts';
|
|
8
8
|
import {resolve_specifier} from './resolve_specifier.ts';
|
|
@@ -11,9 +11,9 @@ import {esbuild_plugin_sveltekit_shim_env} from './esbuild_plugin_sveltekit_shim
|
|
|
11
11
|
import {esbuild_plugin_sveltekit_shim_app} from './esbuild_plugin_sveltekit_shim_app.ts';
|
|
12
12
|
import {esbuild_plugin_sveltekit_local_imports} from './esbuild_plugin_sveltekit_local_imports.ts';
|
|
13
13
|
import {esbuild_plugin_svelte} from './esbuild_plugin_svelte.ts';
|
|
14
|
-
import type {
|
|
14
|
+
import type {ParsedSvelteConfig} from './svelte_config.ts';
|
|
15
15
|
|
|
16
|
-
export interface
|
|
16
|
+
export interface EsbuildPluginExternalWorkerOptions {
|
|
17
17
|
dev: boolean;
|
|
18
18
|
build_options: esbuild.BuildOptions;
|
|
19
19
|
dir?: string;
|
|
@@ -21,8 +21,8 @@ export interface Esbuild_Plugin_External_Worker_Options {
|
|
|
21
21
|
svelte_compile_module_options?: ModuleCompileOptions;
|
|
22
22
|
svelte_preprocessors?: PreprocessorGroup | Array<PreprocessorGroup>;
|
|
23
23
|
alias?: Record<string, string>;
|
|
24
|
-
base_url?:
|
|
25
|
-
assets_url?:
|
|
24
|
+
base_url?: ParsedSvelteConfig['base_url'];
|
|
25
|
+
assets_url?: ParsedSvelteConfig['assets_url'];
|
|
26
26
|
public_prefix?: string;
|
|
27
27
|
private_prefix?: string;
|
|
28
28
|
env_dir?: string;
|
|
@@ -47,11 +47,11 @@ export const esbuild_plugin_external_worker = ({
|
|
|
47
47
|
env_files,
|
|
48
48
|
ambient_env,
|
|
49
49
|
log,
|
|
50
|
-
}:
|
|
50
|
+
}: EsbuildPluginExternalWorkerOptions): esbuild.Plugin => ({
|
|
51
51
|
name: 'external_worker',
|
|
52
52
|
setup: (build) => {
|
|
53
53
|
const builds: Map<string, Promise<esbuild.BuildResult>> = new Map();
|
|
54
|
-
const build_worker = async (path_id:
|
|
54
|
+
const build_worker = async (path_id: PathId): Promise<esbuild.BuildResult> => {
|
|
55
55
|
if (builds.has(path_id)) return builds.get(path_id)!;
|
|
56
56
|
const building = esbuild.build({
|
|
57
57
|
entryPoints: [path_id],
|
|
@@ -14,13 +14,13 @@ import {to_define_import_meta_env, default_ts_transform_options} from './esbuild
|
|
|
14
14
|
import {
|
|
15
15
|
default_svelte_config,
|
|
16
16
|
to_default_compile_module_options,
|
|
17
|
-
type
|
|
17
|
+
type ParsedSvelteConfig,
|
|
18
18
|
} from './svelte_config.ts';
|
|
19
19
|
import {TS_MATCHER, SVELTE_MATCHER, SVELTE_RUNES_MATCHER} from './constants.ts';
|
|
20
20
|
|
|
21
|
-
export interface
|
|
21
|
+
export interface EsbuildPluginSvelteOptions {
|
|
22
22
|
dev: boolean;
|
|
23
|
-
base_url:
|
|
23
|
+
base_url: ParsedSvelteConfig['base_url'];
|
|
24
24
|
dir?: string;
|
|
25
25
|
svelte_compile_options?: CompileOptions;
|
|
26
26
|
svelte_compile_module_options?: ModuleCompileOptions;
|
|
@@ -29,7 +29,7 @@ export interface Esbuild_Plugin_Svelte_Options {
|
|
|
29
29
|
is_ts?: (filename: string) => boolean;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export const esbuild_plugin_svelte = (options:
|
|
32
|
+
export const esbuild_plugin_svelte = (options: EsbuildPluginSvelteOptions): esbuild.Plugin => {
|
|
33
33
|
const {
|
|
34
34
|
dev,
|
|
35
35
|
base_url,
|
|
@@ -2,7 +2,7 @@ import type * as esbuild from 'esbuild';
|
|
|
2
2
|
import {escape_regexp} from '@ryanatkn/belt/regexp.js';
|
|
3
3
|
import {join} from 'node:path';
|
|
4
4
|
|
|
5
|
-
export interface
|
|
5
|
+
export interface EsbuildPluginSveltekitShimAliasOptions {
|
|
6
6
|
dir?: string;
|
|
7
7
|
alias?: Record<string, string>;
|
|
8
8
|
}
|
|
@@ -10,7 +10,7 @@ export interface Esbuild_Plugin_Sveltekit_Shim_Alias_Options {
|
|
|
10
10
|
export const esbuild_plugin_sveltekit_shim_alias = ({
|
|
11
11
|
dir = process.cwd(),
|
|
12
12
|
alias,
|
|
13
|
-
}:
|
|
13
|
+
}: EsbuildPluginSveltekitShimAliasOptions): esbuild.Plugin => ({
|
|
14
14
|
name: 'sveltekit_shim_alias',
|
|
15
15
|
setup: (build) => {
|
|
16
16
|
const aliases: Record<string, string> = {$lib: 'src/lib', ...alias};
|
|
@@ -5,20 +5,20 @@ import {
|
|
|
5
5
|
render_sveltekit_shim_app_paths,
|
|
6
6
|
sveltekit_shim_app_specifiers,
|
|
7
7
|
} from './sveltekit_shim_app.ts';
|
|
8
|
-
import type {
|
|
8
|
+
import type {ParsedSvelteConfig} from './svelte_config.ts';
|
|
9
9
|
import {EVERYTHING_MATCHER} from './constants.ts';
|
|
10
10
|
|
|
11
|
-
export interface
|
|
11
|
+
export interface EsbuildPluginSveltekitShimAppOptions {
|
|
12
12
|
dev: boolean;
|
|
13
|
-
base_url:
|
|
14
|
-
assets_url:
|
|
13
|
+
base_url: ParsedSvelteConfig['base_url'];
|
|
14
|
+
assets_url: ParsedSvelteConfig['assets_url'];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export const esbuild_plugin_sveltekit_shim_app = ({
|
|
18
18
|
dev,
|
|
19
19
|
base_url,
|
|
20
20
|
assets_url,
|
|
21
|
-
}:
|
|
21
|
+
}: EsbuildPluginSveltekitShimAppOptions): esbuild.Plugin => ({
|
|
22
22
|
name: 'sveltekit_shim_app',
|
|
23
23
|
setup: (build) => {
|
|
24
24
|
build.onResolve({filter: /^\$app\/(forms|navigation|stores)$/}, ({path, ...rest}) =>
|
|
@@ -3,7 +3,7 @@ import type * as esbuild from 'esbuild';
|
|
|
3
3
|
import {render_env_shim_module} from './sveltekit_shim_env.ts';
|
|
4
4
|
import {SVELTEKIT_ENV_MATCHER, EVERYTHING_MATCHER} from './constants.ts';
|
|
5
5
|
|
|
6
|
-
export interface
|
|
6
|
+
export interface EsbuildPluginSveltekitShimEnvOptions {
|
|
7
7
|
dev: boolean;
|
|
8
8
|
public_prefix?: string;
|
|
9
9
|
private_prefix?: string;
|
|
@@ -21,7 +21,7 @@ export const esbuild_plugin_sveltekit_shim_env = ({
|
|
|
21
21
|
env_dir,
|
|
22
22
|
env_files,
|
|
23
23
|
ambient_env,
|
|
24
|
-
}:
|
|
24
|
+
}: EsbuildPluginSveltekitShimEnvOptions): esbuild.Plugin => ({
|
|
25
25
|
name: 'sveltekit_shim_env',
|
|
26
26
|
setup: (build) => {
|
|
27
27
|
build.onResolve({filter: SVELTEKIT_ENV_MATCHER}, ({path}) => ({path, namespace}));
|