@ryanatkn/gro 0.167.1 → 0.169.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.d.ts +1 -1
- package/dist/changeset.task.d.ts.map +1 -1
- package/dist/changeset.task.js +1 -1
- package/dist/check.task.d.ts.map +1 -1
- package/dist/check.task.js +1 -1
- package/dist/clean.task.d.ts +1 -1
- package/dist/clean.task.d.ts.map +1 -1
- package/dist/clean.task.js +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/commit.task.d.ts +1 -1
- package/dist/commit.task.d.ts.map +1 -1
- package/dist/commit.task.js +1 -1
- package/dist/deploy.task.d.ts +3 -3
- package/dist/deploy.task.d.ts.map +1 -1
- package/dist/deploy.task.js +1 -1
- package/dist/disknode.d.ts +1 -1
- package/dist/disknode.d.ts.map +1 -1
- package/dist/env.d.ts +4 -3
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +17 -14
- package/dist/esbuild_plugin_external_worker.d.ts.map +1 -1
- package/dist/filer.d.ts +1 -1
- package/dist/filer.d.ts.map +1 -1
- package/dist/gen.d.ts +1 -1
- package/dist/gen.d.ts.map +1 -1
- package/dist/gen_helpers.d.ts +1 -1
- package/dist/gen_helpers.d.ts.map +1 -1
- package/dist/gro_config.d.ts +1 -1
- package/dist/gro_config.d.ts.map +1 -1
- package/dist/gro_plugin_server.d.ts +2 -2
- package/dist/gro_plugin_server.d.ts.map +1 -1
- package/dist/gro_plugin_sveltekit_app.js +1 -1
- package/dist/input_path.d.ts +1 -1
- package/dist/input_path.d.ts.map +1 -1
- package/dist/modules.d.ts +1 -1
- package/dist/modules.d.ts.map +1 -1
- package/dist/package.d.ts.map +1 -1
- package/dist/package.gen.js +2 -2
- package/dist/package.js +7 -41
- package/dist/package_json.d.ts.map +1 -1
- package/dist/package_json.js +4 -0
- package/dist/parse_exports.d.ts +1 -1
- package/dist/parse_exports.d.ts.map +1 -1
- package/dist/parse_imports.d.ts +1 -1
- package/dist/parse_imports.d.ts.map +1 -1
- package/dist/paths.d.ts +1 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/publish.task.d.ts +2 -2
- package/dist/publish.task.d.ts.map +1 -1
- package/dist/publish.task.js +1 -1
- package/dist/resolve_specifier.d.ts +1 -1
- package/dist/resolve_specifier.d.ts.map +1 -1
- package/dist/run_task.js +1 -1
- package/dist/search_fs.d.ts +1 -1
- package/dist/search_fs.d.ts.map +1 -1
- package/dist/src_json.d.ts +3 -2
- package/dist/src_json.d.ts.map +1 -1
- package/dist/src_json.js +7 -4
- package/dist/task.d.ts +1 -1
- package/dist/task.d.ts.map +1 -1
- package/dist/upgrade.task.d.ts +1 -1
- package/dist/upgrade.task.d.ts.map +1 -1
- package/dist/upgrade.task.js +1 -1
- package/dist/watch_dir.d.ts +10 -3
- package/dist/watch_dir.d.ts.map +1 -1
- package/dist/watch_dir.js +11 -2
- package/package.json +8 -4
- package/src/lib/changeset.task.ts +5 -1
- package/src/lib/check.task.ts +1 -1
- package/src/lib/clean.task.ts +1 -1
- package/src/lib/cli.ts +1 -1
- package/src/lib/commit.task.ts +1 -1
- package/src/lib/deploy.task.ts +6 -6
- package/src/lib/disknode.ts +1 -1
- package/src/lib/env.ts +16 -13
- package/src/lib/esbuild_plugin_external_worker.ts +1 -1
- package/src/lib/filer.ts +1 -1
- package/src/lib/gen.ts +1 -1
- package/src/lib/gen_helpers.ts +1 -1
- package/src/lib/gro_config.ts +1 -1
- package/src/lib/gro_plugin_server.ts +1 -1
- package/src/lib/gro_plugin_sveltekit_app.ts +1 -1
- package/src/lib/input_path.ts +1 -1
- package/src/lib/modules.ts +1 -1
- package/src/lib/package.gen.ts +2 -2
- package/src/lib/package.ts +7 -41
- package/src/lib/package_json.ts +4 -0
- package/src/lib/parse_exports.ts +1 -1
- package/src/lib/parse_imports.ts +1 -1
- package/src/lib/paths.ts +1 -1
- package/src/lib/publish.task.ts +8 -8
- package/src/lib/resolve_specifier.ts +1 -1
- package/src/lib/run_task.ts +1 -1
- package/src/lib/search_fs.ts +1 -2
- package/src/lib/src_json.ts +12 -3
- package/src/lib/task.ts +1 -1
- package/src/lib/upgrade.task.ts +1 -1
- package/src/lib/watch_dir.ts +27 -3
- package/dist/git.d.ts +0 -81
- package/dist/git.d.ts.map +0 -1
- package/dist/git.js +0 -218
- package/dist/path.d.ts +0 -17
- package/dist/path.d.ts.map +0 -1
- package/dist/path.js +0 -2
- package/src/lib/git.ts +0 -298
- package/src/lib/path.ts +0 -23
package/src/lib/package.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {Src_Json} from '@ryanatkn/belt/src_json.js';
|
|
|
5
5
|
|
|
6
6
|
export const package_json: Package_Json = {
|
|
7
7
|
name: '@ryanatkn/gro',
|
|
8
|
-
version: '0.
|
|
8
|
+
version: '0.169.0',
|
|
9
9
|
description: 'task runner and toolkit extending SvelteKit',
|
|
10
10
|
motto: 'generate, run, optimize',
|
|
11
11
|
glyph: '🌰',
|
|
@@ -44,7 +44,7 @@ export const package_json: Package_Json = {
|
|
|
44
44
|
'typescript',
|
|
45
45
|
],
|
|
46
46
|
dependencies: {
|
|
47
|
-
'@ryanatkn/belt': '^0.
|
|
47
|
+
'@ryanatkn/belt': '^0.35.1',
|
|
48
48
|
chokidar: '^4.0.3',
|
|
49
49
|
dotenv: '^17.2.2',
|
|
50
50
|
'esm-env': '^1.2.2',
|
|
@@ -69,8 +69,8 @@ export const package_json: Package_Json = {
|
|
|
69
69
|
'@changesets/changelog-git': '^0.2.1',
|
|
70
70
|
'@changesets/types': '^6.1.0',
|
|
71
71
|
'@ryanatkn/eslint-config': '^0.8.0',
|
|
72
|
-
'@ryanatkn/fuz': '^0.
|
|
73
|
-
'@ryanatkn/moss': '^0.
|
|
72
|
+
'@ryanatkn/fuz': '^0.147.0',
|
|
73
|
+
'@ryanatkn/moss': '^0.36.0',
|
|
74
74
|
'@sveltejs/adapter-static': '^3.0.9',
|
|
75
75
|
'@sveltejs/kit': '^2.37.1',
|
|
76
76
|
'@sveltejs/package': '^2.5.0',
|
|
@@ -99,12 +99,13 @@ export const package_json: Package_Json = {
|
|
|
99
99
|
'./package.json': './package.json',
|
|
100
100
|
'.': {types: './dist/index.d.ts', default: './dist/index.js'},
|
|
101
101
|
'./*.js': {types: './dist/*.d.ts', default: './dist/*.js'},
|
|
102
|
+
'./*.ts': {types: './dist/*.d.ts', default: './dist/*.js'},
|
|
102
103
|
},
|
|
103
104
|
} as any;
|
|
104
105
|
|
|
105
106
|
export const src_json: Src_Json = {
|
|
106
107
|
name: '@ryanatkn/gro',
|
|
107
|
-
version: '0.
|
|
108
|
+
version: '0.169.0',
|
|
108
109
|
modules: {
|
|
109
110
|
'.': {
|
|
110
111
|
path: 'index.ts',
|
|
@@ -271,10 +272,10 @@ export const src_json: Src_Json = {
|
|
|
271
272
|
path: 'env.ts',
|
|
272
273
|
declarations: [
|
|
273
274
|
{name: 'load_env', kind: 'function'},
|
|
275
|
+
{name: 'load_from_env', kind: 'function'},
|
|
274
276
|
{name: 'merge_envs', kind: 'function'},
|
|
275
277
|
{name: 'is_private_env', kind: 'function'},
|
|
276
278
|
{name: 'is_public_env', kind: 'function'},
|
|
277
|
-
{name: 'load_from_env', kind: 'function'},
|
|
278
279
|
],
|
|
279
280
|
},
|
|
280
281
|
'./esbuild_helpers.js': {
|
|
@@ -401,30 +402,6 @@ export const src_json: Src_Json = {
|
|
|
401
402
|
{name: 'normalize_gen_config', kind: 'function'},
|
|
402
403
|
],
|
|
403
404
|
},
|
|
404
|
-
'./git.js': {
|
|
405
|
-
path: 'git.ts',
|
|
406
|
-
declarations: [
|
|
407
|
-
{name: 'Git_Origin', kind: 'variable'},
|
|
408
|
-
{name: 'Git_Branch', kind: 'variable'},
|
|
409
|
-
{name: 'git_current_branch_name', kind: 'function'},
|
|
410
|
-
{name: 'git_remote_branch_exists', kind: 'function'},
|
|
411
|
-
{name: 'git_local_branch_exists', kind: 'function'},
|
|
412
|
-
{name: 'git_check_clean_workspace', kind: 'function'},
|
|
413
|
-
{name: 'git_check_fully_staged_workspace', kind: 'function'},
|
|
414
|
-
{name: 'git_fetch', kind: 'function'},
|
|
415
|
-
{name: 'git_checkout', kind: 'function'},
|
|
416
|
-
{name: 'git_pull', kind: 'function'},
|
|
417
|
-
{name: 'git_push', kind: 'function'},
|
|
418
|
-
{name: 'git_push_to_create', kind: 'function'},
|
|
419
|
-
{name: 'git_delete_local_branch', kind: 'function'},
|
|
420
|
-
{name: 'git_delete_remote_branch', kind: 'function'},
|
|
421
|
-
{name: 'git_reset_branch_to_first_commit', kind: 'function'},
|
|
422
|
-
{name: 'git_current_commit_hash', kind: 'function'},
|
|
423
|
-
{name: 'git_current_branch_first_commit_hash', kind: 'function'},
|
|
424
|
-
{name: 'git_check_setting_pull_rebase', kind: 'function'},
|
|
425
|
-
{name: 'git_clone_locally', kind: 'function'},
|
|
426
|
-
],
|
|
427
|
-
},
|
|
428
405
|
'./github.js': {
|
|
429
406
|
path: 'github.ts',
|
|
430
407
|
declarations: [
|
|
@@ -614,17 +591,6 @@ export const src_json: Src_Json = {
|
|
|
614
591
|
{name: 'parse_imports', kind: 'function'},
|
|
615
592
|
],
|
|
616
593
|
},
|
|
617
|
-
'./path.js': {
|
|
618
|
-
path: 'path.ts',
|
|
619
|
-
declarations: [
|
|
620
|
-
{name: 'Path_Id', kind: 'type'},
|
|
621
|
-
{name: 'Path_Info', kind: 'type'},
|
|
622
|
-
{name: 'Resolved_Path', kind: 'type'},
|
|
623
|
-
{name: 'Path_Filter', kind: 'type'},
|
|
624
|
-
{name: 'File_Filter', kind: 'type'},
|
|
625
|
-
{name: 'to_file_path', kind: 'function'},
|
|
626
|
-
],
|
|
627
|
-
},
|
|
628
594
|
'./paths.js': {
|
|
629
595
|
path: 'paths.ts',
|
|
630
596
|
declarations: [
|
package/src/lib/package_json.ts
CHANGED
|
@@ -145,6 +145,10 @@ export const to_package_exports = (paths: Array<string>): Package_Json_Exports =
|
|
|
145
145
|
types: IMPORT_PREFIX + '*.d.ts',
|
|
146
146
|
default: IMPORT_PREFIX + '*.js',
|
|
147
147
|
};
|
|
148
|
+
exports['./*.ts'] = {
|
|
149
|
+
types: IMPORT_PREFIX + '*.d.ts',
|
|
150
|
+
default: IMPORT_PREFIX + '*.js',
|
|
151
|
+
};
|
|
148
152
|
}
|
|
149
153
|
|
|
150
154
|
if (has_svelte) {
|
package/src/lib/parse_exports.ts
CHANGED
|
@@ -3,8 +3,8 @@ import {extname} from 'node:path';
|
|
|
3
3
|
import type {Flavored} from '@ryanatkn/belt/types.js';
|
|
4
4
|
import type {Logger} from '@ryanatkn/belt/log.js';
|
|
5
5
|
import type {Src_Module_Declaration_Kind} from '@ryanatkn/belt/src_json.js';
|
|
6
|
+
import type {Path_Id} from '@ryanatkn/belt/path.js';
|
|
6
7
|
|
|
7
|
-
import type {Path_Id} from './path.ts';
|
|
8
8
|
import {TS_MATCHER} from './constants.ts';
|
|
9
9
|
import {Parse_Exports_Context} from './parse_exports_context.ts';
|
|
10
10
|
|
package/src/lib/parse_imports.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {parseSync, type ImportDeclaration} from 'oxc-parser';
|
|
2
2
|
import type {Flavored} from '@ryanatkn/belt/types.js';
|
|
3
3
|
import {Unreachable_Error} from '@ryanatkn/belt/error.js';
|
|
4
|
+
import type {Path_Id} from '@ryanatkn/belt/path.js';
|
|
4
5
|
|
|
5
|
-
import type {Path_Id} from './path.ts';
|
|
6
6
|
import {JS_MATCHER, TS_MATCHER, SVELTE_MATCHER, SVELTE_SCRIPT_MATCHER} from './constants.ts';
|
|
7
7
|
|
|
8
8
|
export type Import_Specifier = Flavored<string, 'Import_Specifier'>;
|
package/src/lib/paths.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {join, extname, relative, basename} from 'node:path';
|
|
|
2
2
|
import {fileURLToPath} from 'node:url';
|
|
3
3
|
import {ensure_end, strip_end} from '@ryanatkn/belt/string.js';
|
|
4
4
|
import {styleText as st} from 'node:util';
|
|
5
|
+
import type {Path_Id} from '@ryanatkn/belt/path.js';
|
|
5
6
|
|
|
6
7
|
import {
|
|
7
8
|
GRO_CONFIG_FILENAME,
|
|
@@ -11,7 +12,6 @@ import {
|
|
|
11
12
|
SVELTEKIT_DIST_DIRNAME,
|
|
12
13
|
} from './constants.ts';
|
|
13
14
|
import {default_svelte_config} from './svelte_config.ts';
|
|
14
|
-
import type {Path_Id} from './path.ts';
|
|
15
15
|
|
|
16
16
|
/*
|
|
17
17
|
|
package/src/lib/publish.task.ts
CHANGED
|
@@ -2,13 +2,6 @@ import {spawn} from '@ryanatkn/belt/process.js';
|
|
|
2
2
|
import {z} from 'zod';
|
|
3
3
|
import {styleText as st} from 'node:util';
|
|
4
4
|
import {existsSync} from 'node:fs';
|
|
5
|
-
|
|
6
|
-
import {Task_Error, type Task} from './task.ts';
|
|
7
|
-
import {load_package_json, parse_repo_url} from './package_json.ts';
|
|
8
|
-
import {find_cli, spawn_cli} from './cli.ts';
|
|
9
|
-
import {has_sveltekit_library} from './sveltekit_helpers.ts';
|
|
10
|
-
import {update_changelog} from './changelog.ts';
|
|
11
|
-
import {load_from_env} from './env.ts';
|
|
12
5
|
import {
|
|
13
6
|
Git_Branch,
|
|
14
7
|
Git_Origin,
|
|
@@ -16,7 +9,14 @@ import {
|
|
|
16
9
|
git_checkout,
|
|
17
10
|
git_fetch,
|
|
18
11
|
git_pull,
|
|
19
|
-
} from '
|
|
12
|
+
} from '@ryanatkn/belt/git.js';
|
|
13
|
+
|
|
14
|
+
import {Task_Error, type Task} from './task.ts';
|
|
15
|
+
import {load_package_json, parse_repo_url} from './package_json.ts';
|
|
16
|
+
import {find_cli, spawn_cli} from './cli.ts';
|
|
17
|
+
import {has_sveltekit_library} from './sveltekit_helpers.ts';
|
|
18
|
+
import {update_changelog} from './changelog.ts';
|
|
19
|
+
import {load_from_env} from './env.ts';
|
|
20
20
|
import {CHANGESET_CLI} from './changeset_helpers.ts';
|
|
21
21
|
|
|
22
22
|
export const Args = z.strictObject({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {extname, isAbsolute, join, relative} from 'node:path';
|
|
2
2
|
import {existsSync} from 'node:fs';
|
|
3
|
+
import type {Path_Id} from '@ryanatkn/belt/path.js';
|
|
3
4
|
|
|
4
5
|
import {replace_extension} from './paths.ts';
|
|
5
|
-
import type {Path_Id} from './path.ts';
|
|
6
6
|
|
|
7
7
|
// TODO ideally this module doesnt exist, but import.meta.resolve doesn't work in loaders last I tried
|
|
8
8
|
|
package/src/lib/run_task.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {styleText as st} from 'node:util';
|
|
|
2
2
|
import {print_log_label} from '@ryanatkn/belt/print.js';
|
|
3
3
|
import {System_Logger} from '@ryanatkn/belt/log.js';
|
|
4
4
|
import type {Timings} from '@ryanatkn/belt/timings.js';
|
|
5
|
-
import z from 'zod';
|
|
5
|
+
import {z} from 'zod';
|
|
6
6
|
|
|
7
7
|
import {parse_args, type Args} from './args.ts';
|
|
8
8
|
import type {invoke_task as base_invoke_task} from './invoke_task.ts';
|
package/src/lib/search_fs.ts
CHANGED
|
@@ -3,8 +3,7 @@ import {to_array} from '@ryanatkn/belt/array.js';
|
|
|
3
3
|
import {ensure_end} from '@ryanatkn/belt/string.js';
|
|
4
4
|
import {isAbsolute, join} from 'node:path';
|
|
5
5
|
import {existsSync, readdirSync} from 'node:fs';
|
|
6
|
-
|
|
7
|
-
import type {File_Filter, Resolved_Path, Path_Filter} from './path.ts';
|
|
6
|
+
import type {File_Filter, Resolved_Path, Path_Filter} from '@ryanatkn/belt/path.js';
|
|
8
7
|
|
|
9
8
|
export interface Search_Fs_Options {
|
|
10
9
|
/**
|
package/src/lib/src_json.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {existsSync} from 'node:fs';
|
|
|
4
4
|
import ts from 'typescript';
|
|
5
5
|
import type {Package_Json, Package_Json_Exports} from '@ryanatkn/belt/package_json.js';
|
|
6
6
|
import {Src_Json, Src_Modules} from '@ryanatkn/belt/src_json.js';
|
|
7
|
+
import type {Logger} from '@ryanatkn/belt/log.js';
|
|
7
8
|
|
|
8
9
|
import {paths, replace_extension} from './paths.ts';
|
|
9
10
|
import {parse_exports} from './parse_exports.ts';
|
|
@@ -12,11 +13,15 @@ import {search_fs} from './search_fs.ts';
|
|
|
12
13
|
|
|
13
14
|
export type Map_Src_Json = (src_json: Src_Json) => Src_Json | null | Promise<Src_Json | null>;
|
|
14
15
|
|
|
15
|
-
export const create_src_json = (
|
|
16
|
+
export const create_src_json = (
|
|
17
|
+
package_json: Package_Json,
|
|
18
|
+
lib_path?: string,
|
|
19
|
+
log?: Logger,
|
|
20
|
+
): Src_Json =>
|
|
16
21
|
Src_Json.parse({
|
|
17
22
|
name: package_json.name,
|
|
18
23
|
version: package_json.version,
|
|
19
|
-
modules: to_src_modules(package_json.exports, lib_path),
|
|
24
|
+
modules: to_src_modules(package_json.exports, lib_path, log),
|
|
20
25
|
});
|
|
21
26
|
|
|
22
27
|
export const serialize_src_json = (src_json: Src_Json): string => {
|
|
@@ -27,6 +32,7 @@ export const serialize_src_json = (src_json: Src_Json): string => {
|
|
|
27
32
|
export const to_src_modules = (
|
|
28
33
|
exports: Package_Json_Exports | undefined,
|
|
29
34
|
lib_path = paths.lib,
|
|
35
|
+
log?: Logger,
|
|
30
36
|
): Src_Modules | undefined => {
|
|
31
37
|
if (!exports) return;
|
|
32
38
|
|
|
@@ -58,7 +64,10 @@ export const to_src_modules = (
|
|
|
58
64
|
for (const {export_key, file_path} of file_paths) {
|
|
59
65
|
const relative_path = file_path.replace(ensure_end(lib_path, '/'), '');
|
|
60
66
|
|
|
61
|
-
const declarations = parse_exports(file_path, program).map(({name, kind}) => ({
|
|
67
|
+
const declarations = parse_exports(file_path, program, undefined, log).map(({name, kind}) => ({
|
|
68
|
+
name,
|
|
69
|
+
kind,
|
|
70
|
+
}));
|
|
62
71
|
|
|
63
72
|
result[export_key] = declarations.length
|
|
64
73
|
? {
|
package/src/lib/task.ts
CHANGED
|
@@ -5,9 +5,9 @@ import type {Timings} from '@ryanatkn/belt/timings.js';
|
|
|
5
5
|
import {styleText as st} from 'node:util';
|
|
6
6
|
import type {Result} from '@ryanatkn/belt/result.js';
|
|
7
7
|
import {isAbsolute, join, relative} from 'node:path';
|
|
8
|
+
import type {Path_Id} from '@ryanatkn/belt/path.js';
|
|
8
9
|
|
|
9
10
|
import type {Args} from './args.ts';
|
|
10
|
-
import type {Path_Id} from './path.ts';
|
|
11
11
|
import type {Gro_Config} from './gro_config.ts';
|
|
12
12
|
import type {Parsed_Svelte_Config} from './svelte_config.ts';
|
|
13
13
|
import {
|
package/src/lib/upgrade.task.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {spawn} from '@ryanatkn/belt/process.js';
|
|
2
2
|
import {z} from 'zod';
|
|
3
3
|
import {rmSync} from 'node:fs';
|
|
4
|
+
import {Git_Origin, git_pull} from '@ryanatkn/belt/git.js';
|
|
4
5
|
|
|
5
6
|
import {Task_Error, type Task} from './task.ts';
|
|
6
7
|
import {extract_deps, load_package_json, type Package_Json_Dep} from './package_json.ts';
|
|
7
|
-
import {Git_Origin, git_pull} from './git.ts';
|
|
8
8
|
import {spawn_cli} from './cli.ts';
|
|
9
9
|
import {serialize_args, to_forwarded_args} from './args.ts';
|
|
10
10
|
import {NODE_MODULES_DIRNAME} from './constants.ts';
|
package/src/lib/watch_dir.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {watch, type ChokidarOptions, type FSWatcher} from 'chokidar';
|
|
1
|
+
import {watch, type ChokidarOptions, type FSWatcher, type Matcher} from 'chokidar';
|
|
2
2
|
import {relative} from 'node:path';
|
|
3
3
|
import {statSync} from 'node:fs';
|
|
4
4
|
import {create_deferred, type Deferred} from '@ryanatkn/belt/async.js';
|
|
5
|
+
import type {Path_Filter} from '@ryanatkn/belt/path.js';
|
|
6
|
+
import {EMPTY_OBJECT} from '@ryanatkn/belt/object.js';
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
const TMP_FILE_PATTERN = /\.tmp\./;
|
|
7
9
|
|
|
8
10
|
// TODO pretty hacky
|
|
9
11
|
|
|
@@ -30,6 +32,13 @@ export interface Watch_Dir_Options {
|
|
|
30
32
|
* @default true
|
|
31
33
|
*/
|
|
32
34
|
absolute?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Pattern to ignore files, merged into `chokidar.ignored` if also provided.
|
|
37
|
+
* - `undefined` (default) ignores files matching `.tmp.` pattern
|
|
38
|
+
* - `null` sets no default ignore pattern
|
|
39
|
+
* - or some custom pattern
|
|
40
|
+
*/
|
|
41
|
+
ignored?: Matcher | null;
|
|
33
42
|
}
|
|
34
43
|
|
|
35
44
|
/**
|
|
@@ -41,6 +50,7 @@ export const watch_dir = ({
|
|
|
41
50
|
filter,
|
|
42
51
|
absolute = true,
|
|
43
52
|
chokidar,
|
|
53
|
+
ignored = TMP_FILE_PATTERN,
|
|
44
54
|
}: Watch_Dir_Options): Watch_Node_Fs => {
|
|
45
55
|
let watcher: FSWatcher | undefined;
|
|
46
56
|
let initing: Deferred<void> | undefined;
|
|
@@ -49,7 +59,7 @@ export const watch_dir = ({
|
|
|
49
59
|
init: async () => {
|
|
50
60
|
if (initing) return initing.promise;
|
|
51
61
|
initing = create_deferred();
|
|
52
|
-
watcher = watch(dir,
|
|
62
|
+
watcher = watch(dir, resolve_chokidar_options(chokidar, ignored));
|
|
53
63
|
watcher.on('add', (path) => {
|
|
54
64
|
const final_path = absolute ? path : relative(dir, path);
|
|
55
65
|
if (filter && !filter(final_path, false)) return;
|
|
@@ -89,3 +99,17 @@ export const watch_dir = ({
|
|
|
89
99
|
},
|
|
90
100
|
};
|
|
91
101
|
};
|
|
102
|
+
|
|
103
|
+
const resolve_chokidar_options = (
|
|
104
|
+
options: ChokidarOptions | undefined,
|
|
105
|
+
ignored: Matcher | null,
|
|
106
|
+
): ChokidarOptions | undefined => {
|
|
107
|
+
if (ignored === null) return options;
|
|
108
|
+
|
|
109
|
+
const {ignored: i, ...rest} = options ?? EMPTY_OBJECT;
|
|
110
|
+
|
|
111
|
+
const resolved_ignored =
|
|
112
|
+
i === undefined ? ignored : Array.isArray(i) ? [...i, ignored] : [i, ignored];
|
|
113
|
+
|
|
114
|
+
return {...rest, ignored: resolved_ignored};
|
|
115
|
+
};
|
package/dist/git.d.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import type { SpawnOptions } from 'node:child_process';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import type { Flavored } from '@ryanatkn/belt/types.js';
|
|
4
|
-
export declare const Git_Origin: z.ZodString;
|
|
5
|
-
export type Git_Origin = Flavored<string, 'Git_Origin'>;
|
|
6
|
-
export declare const Git_Branch: z.ZodString;
|
|
7
|
-
export type Git_Branch = Flavored<string, 'Git_Branch'>;
|
|
8
|
-
/**
|
|
9
|
-
* Returns the current git branch name or throws if something goes wrong.
|
|
10
|
-
*/
|
|
11
|
-
export declare const git_current_branch_name: (options?: SpawnOptions) => Promise<Git_Branch>;
|
|
12
|
-
/**
|
|
13
|
-
* @returns a boolean indicating if the remote git branch exists
|
|
14
|
-
*/
|
|
15
|
-
export declare const git_remote_branch_exists: (origin?: Git_Origin, branch?: Git_Branch, options?: SpawnOptions) => Promise<boolean>;
|
|
16
|
-
/**
|
|
17
|
-
* @returns a boolean indicating if the local git branch exists
|
|
18
|
-
*/
|
|
19
|
-
export declare const git_local_branch_exists: (branch: Git_Branch, options?: SpawnOptions) => Promise<boolean>;
|
|
20
|
-
/**
|
|
21
|
-
* TODO make this return an enum and separate the text into a different function
|
|
22
|
-
* @returns an error message if the git workspace has any unstaged or uncommitted changes, or `null` if it's clean
|
|
23
|
-
*/
|
|
24
|
-
export declare const git_check_clean_workspace: (options?: SpawnOptions) => Promise<string | null>;
|
|
25
|
-
/**
|
|
26
|
-
* TODO make this return an enum and separate the text into a different function
|
|
27
|
-
* @returns an error message if the git workspace has any unstaged stages, or `null` if it's clean
|
|
28
|
-
*/
|
|
29
|
-
export declare const git_check_fully_staged_workspace: (options?: SpawnOptions) => Promise<string | null>;
|
|
30
|
-
/**
|
|
31
|
-
* Calls `git fetch` and throws if anything goes wrong.
|
|
32
|
-
*/
|
|
33
|
-
export declare const git_fetch: (origin?: Git_Origin, branch?: Git_Branch, options?: SpawnOptions) => Promise<void>;
|
|
34
|
-
/**
|
|
35
|
-
* Calls `git checkout` and throws if anything goes wrong.
|
|
36
|
-
* @returns the previous branch name, if it changed
|
|
37
|
-
*/
|
|
38
|
-
export declare const git_checkout: (branch: Git_Branch, options?: SpawnOptions) => Promise<Git_Branch | null>;
|
|
39
|
-
/**
|
|
40
|
-
* Calls `git pull` and throws if anything goes wrong.
|
|
41
|
-
*/
|
|
42
|
-
export declare const git_pull: (origin?: Git_Origin, branch?: Git_Branch, options?: SpawnOptions) => Promise<void>;
|
|
43
|
-
/**
|
|
44
|
-
* Calls `git push` and throws if anything goes wrong.
|
|
45
|
-
*/
|
|
46
|
-
export declare const git_push: (origin: Git_Origin, branch?: Git_Branch, options?: SpawnOptions, set_upstream?: boolean) => Promise<void>;
|
|
47
|
-
/**
|
|
48
|
-
* Calls `git push` and throws if anything goes wrong.
|
|
49
|
-
*/
|
|
50
|
-
export declare const git_push_to_create: (origin?: Git_Origin, branch?: Git_Branch, options?: SpawnOptions) => Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Deletes a branch locally and throws if anything goes wrong.
|
|
53
|
-
*/
|
|
54
|
-
export declare const git_delete_local_branch: (branch: Git_Branch, options?: SpawnOptions) => Promise<void>;
|
|
55
|
-
/**
|
|
56
|
-
* Deletes a branch remotely and throws if anything goes wrong.
|
|
57
|
-
*/
|
|
58
|
-
export declare const git_delete_remote_branch: (origin: Git_Origin, branch: Git_Branch, options?: SpawnOptions) => Promise<void>;
|
|
59
|
-
/**
|
|
60
|
-
* Resets the `target` branch back to its first commit both locally and remotely.
|
|
61
|
-
*/
|
|
62
|
-
export declare const git_reset_branch_to_first_commit: (origin: Git_Origin, branch: Git_Branch, options?: SpawnOptions) => Promise<void>;
|
|
63
|
-
/**
|
|
64
|
-
* Returns the branch's latest commit hash or throws if something goes wrong.
|
|
65
|
-
*/
|
|
66
|
-
export declare const git_current_commit_hash: (branch?: string, options?: SpawnOptions) => Promise<string | null>;
|
|
67
|
-
/**
|
|
68
|
-
* Returns the hash of the current branch's first commit or throws if something goes wrong.
|
|
69
|
-
*/
|
|
70
|
-
export declare const git_current_branch_first_commit_hash: (options?: SpawnOptions) => Promise<string>;
|
|
71
|
-
/**
|
|
72
|
-
* Returns the global git config setting for `pull.rebase`.
|
|
73
|
-
* Gro is currently written to expect `true`,
|
|
74
|
-
* but the restriction could be loosened with additional work.
|
|
75
|
-
*/
|
|
76
|
-
export declare const git_check_setting_pull_rebase: (options?: SpawnOptions) => Promise<boolean>;
|
|
77
|
-
/**
|
|
78
|
-
* Clones a branch locally to another directory and updates the origin to match the source.
|
|
79
|
-
*/
|
|
80
|
-
export declare const git_clone_locally: (origin: Git_Origin, branch: Git_Branch, source_dir: string, target_dir: string, options?: SpawnOptions) => Promise<void>;
|
|
81
|
-
//# sourceMappingURL=git.d.ts.map
|
package/dist/git.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"git.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/git.ts"],"names":[],"mappings":"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"}
|
package/dist/git.js
DELETED
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import { spawn, spawn_out } from '@ryanatkn/belt/process.js';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { existsSync } from 'node:fs';
|
|
4
|
-
import { to_file_path } from "./path.js";
|
|
5
|
-
// TODO maybe extract to `util-git`
|
|
6
|
-
export const Git_Origin = z.string();
|
|
7
|
-
export const Git_Branch = z.string();
|
|
8
|
-
/**
|
|
9
|
-
* Returns the current git branch name or throws if something goes wrong.
|
|
10
|
-
*/
|
|
11
|
-
export const git_current_branch_name = async (options) => {
|
|
12
|
-
const { stdout } = await spawn_out('git', ['rev-parse', '--abbrev-ref', 'HEAD'], options);
|
|
13
|
-
if (!stdout)
|
|
14
|
-
throw Error('git_current_branch_name failed');
|
|
15
|
-
const branch_name = stdout.trim();
|
|
16
|
-
return branch_name;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* @returns a boolean indicating if the remote git branch exists
|
|
20
|
-
*/
|
|
21
|
-
export const git_remote_branch_exists = async (origin = 'origin', branch, options) => {
|
|
22
|
-
const final_branch = branch ?? (await git_current_branch_name(options));
|
|
23
|
-
if (options?.cwd && !existsSync(to_file_path(options.cwd))) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
const result = await spawn('git', ['ls-remote', '--exit-code', '--heads', origin, 'refs/heads/' + final_branch], options);
|
|
27
|
-
if (result.ok) {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
else if (result.code === 2) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
throw Error(`git_remote_branch_exists failed for origin '${origin}' and branch '${final_branch}' with code ${result.code}`);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* @returns a boolean indicating if the local git branch exists
|
|
39
|
-
*/
|
|
40
|
-
export const git_local_branch_exists = async (branch, options) => {
|
|
41
|
-
if (options?.cwd && !existsSync(to_file_path(options.cwd))) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
const result = await spawn('git', ['show-ref', '--quiet', 'refs/heads/' + branch], options);
|
|
45
|
-
return result.ok;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* TODO make this return an enum and separate the text into a different function
|
|
49
|
-
* @returns an error message if the git workspace has any unstaged or uncommitted changes, or `null` if it's clean
|
|
50
|
-
*/
|
|
51
|
-
export const git_check_clean_workspace = async (options) => {
|
|
52
|
-
const unstaged_result = await spawn('git', ['diff', '--exit-code', '--quiet'], options);
|
|
53
|
-
if (!unstaged_result.ok) {
|
|
54
|
-
return 'git has unstaged changes';
|
|
55
|
-
}
|
|
56
|
-
const staged_result = await spawn('git', ['diff', '--exit-code', '--cached', '--quiet'], options);
|
|
57
|
-
if (!staged_result.ok) {
|
|
58
|
-
return 'git has staged but uncommitted changes';
|
|
59
|
-
}
|
|
60
|
-
const status_result = await spawn_out('git', ['status', '--porcelain'], options);
|
|
61
|
-
if (status_result.stdout?.length) {
|
|
62
|
-
return 'git has untracked files';
|
|
63
|
-
}
|
|
64
|
-
return null;
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* TODO make this return an enum and separate the text into a different function
|
|
68
|
-
* @returns an error message if the git workspace has any unstaged stages, or `null` if it's clean
|
|
69
|
-
*/
|
|
70
|
-
export const git_check_fully_staged_workspace = async (options) => {
|
|
71
|
-
const unstaged_result = await spawn('git', ['diff', '--exit-code', '--quiet'], options);
|
|
72
|
-
if (!unstaged_result.ok) {
|
|
73
|
-
return 'git has unstaged changes';
|
|
74
|
-
}
|
|
75
|
-
const status_result = await spawn_out('git', ['status', '--porcelain'], options);
|
|
76
|
-
if (status_result.stdout?.includes('??')) {
|
|
77
|
-
return 'git has untracked files';
|
|
78
|
-
}
|
|
79
|
-
return null;
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Calls `git fetch` and throws if anything goes wrong.
|
|
83
|
-
*/
|
|
84
|
-
export const git_fetch = async (origin = 'origin', branch, options) => {
|
|
85
|
-
const args = ['fetch', origin];
|
|
86
|
-
if (branch)
|
|
87
|
-
args.push(branch);
|
|
88
|
-
const result = await spawn('git', args, options);
|
|
89
|
-
if (!result.ok) {
|
|
90
|
-
throw Error(`git_fetch failed for origin '${origin}' and branch '${branch}' with code ${result.code}`);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* Calls `git checkout` and throws if anything goes wrong.
|
|
95
|
-
* @returns the previous branch name, if it changed
|
|
96
|
-
*/
|
|
97
|
-
export const git_checkout = async (branch, options) => {
|
|
98
|
-
const current_branch = await git_current_branch_name(options);
|
|
99
|
-
if (branch === current_branch) {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
const result = await spawn('git', ['checkout', branch], options);
|
|
103
|
-
if (!result.ok) {
|
|
104
|
-
throw Error(`git_checkout failed for branch '${branch}' with code ${result.code}`);
|
|
105
|
-
}
|
|
106
|
-
return current_branch;
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* Calls `git pull` and throws if anything goes wrong.
|
|
110
|
-
*/
|
|
111
|
-
export const git_pull = async (origin = 'origin', branch, options) => {
|
|
112
|
-
const args = ['pull', origin];
|
|
113
|
-
if (branch)
|
|
114
|
-
args.push(branch);
|
|
115
|
-
const result = await spawn('git', args, options);
|
|
116
|
-
if (!result.ok) {
|
|
117
|
-
throw Error(`git_pull failed for branch '${branch}' with code ${result.code}`);
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
/**
|
|
121
|
-
* Calls `git push` and throws if anything goes wrong.
|
|
122
|
-
*/
|
|
123
|
-
export const git_push = async (origin, branch, options, set_upstream = false) => {
|
|
124
|
-
const final_branch = branch ?? (await git_current_branch_name(options));
|
|
125
|
-
const args = ['push', origin, final_branch];
|
|
126
|
-
if (set_upstream)
|
|
127
|
-
args.push('-u');
|
|
128
|
-
const result = await spawn('git', args, options);
|
|
129
|
-
if (!result.ok) {
|
|
130
|
-
throw Error(`git_push failed for branch '${final_branch}' with code ${result.code}`);
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
/**
|
|
134
|
-
* Calls `git push` and throws if anything goes wrong.
|
|
135
|
-
*/
|
|
136
|
-
export const git_push_to_create = async (origin = 'origin', branch, options) => {
|
|
137
|
-
const final_branch = branch ?? (await git_current_branch_name(options));
|
|
138
|
-
const push_args = ['push'];
|
|
139
|
-
if (await git_remote_branch_exists(origin, final_branch, options)) {
|
|
140
|
-
push_args.push(origin);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
push_args.push('-u', origin);
|
|
144
|
-
}
|
|
145
|
-
push_args.push(final_branch);
|
|
146
|
-
const result = await spawn('git', push_args, options);
|
|
147
|
-
if (!result.ok) {
|
|
148
|
-
throw Error(`git_push failed for branch '${final_branch}' with code ${result.code}`);
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
/**
|
|
152
|
-
* Deletes a branch locally and throws if anything goes wrong.
|
|
153
|
-
*/
|
|
154
|
-
export const git_delete_local_branch = async (branch, options) => {
|
|
155
|
-
const result = await spawn('git', ['branch', '-D', branch], options);
|
|
156
|
-
if (!result.ok) {
|
|
157
|
-
throw Error(`git_delete_local_branch failed for branch '${branch}' with code ${result.code}`);
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
/**
|
|
161
|
-
* Deletes a branch remotely and throws if anything goes wrong.
|
|
162
|
-
*/
|
|
163
|
-
export const git_delete_remote_branch = async (origin, branch, options) => {
|
|
164
|
-
const result = await spawn('git', ['push', origin, ':' + branch], options);
|
|
165
|
-
if (!result.ok) {
|
|
166
|
-
throw Error(`git_delete_remote_branch failed for branch '${branch}' with code ${result.code}`);
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
/**
|
|
170
|
-
* Resets the `target` branch back to its first commit both locally and remotely.
|
|
171
|
-
*/
|
|
172
|
-
export const git_reset_branch_to_first_commit = async (origin, branch, options) => {
|
|
173
|
-
const previous_branch = await git_checkout(branch, options);
|
|
174
|
-
const first_commit_hash = await git_current_branch_first_commit_hash(options);
|
|
175
|
-
await spawn('git', ['reset', '--hard', first_commit_hash], options);
|
|
176
|
-
await spawn('git', ['push', origin, branch, '--force'], options);
|
|
177
|
-
if (previous_branch) {
|
|
178
|
-
await git_checkout(previous_branch, options);
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
/**
|
|
182
|
-
* Returns the branch's latest commit hash or throws if something goes wrong.
|
|
183
|
-
*/
|
|
184
|
-
export const git_current_commit_hash = async (branch, options) => {
|
|
185
|
-
const final_branch = branch ?? (await git_current_branch_name(options));
|
|
186
|
-
const { stdout } = await spawn_out('git', ['show-ref', '-s', final_branch], options);
|
|
187
|
-
if (!stdout)
|
|
188
|
-
return null; // TODO hack for CI
|
|
189
|
-
return stdout.split('\n')[0].trim();
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* Returns the hash of the current branch's first commit or throws if something goes wrong.
|
|
193
|
-
*/
|
|
194
|
-
export const git_current_branch_first_commit_hash = async (options) => {
|
|
195
|
-
const { stdout } = await spawn_out('git', ['rev-list', '--max-parents=0', '--abbrev-commit', 'HEAD'], options);
|
|
196
|
-
if (!stdout)
|
|
197
|
-
throw Error('git_current_branch_first_commit_hash failed');
|
|
198
|
-
return stdout.trim();
|
|
199
|
-
};
|
|
200
|
-
/**
|
|
201
|
-
* Returns the global git config setting for `pull.rebase`.
|
|
202
|
-
* Gro is currently written to expect `true`,
|
|
203
|
-
* but the restriction could be loosened with additional work.
|
|
204
|
-
*/
|
|
205
|
-
export const git_check_setting_pull_rebase = async (options) => {
|
|
206
|
-
const value = await spawn_out('git', ['config', '--global', 'pull.rebase'], options);
|
|
207
|
-
return value.stdout?.trim() === 'true';
|
|
208
|
-
};
|
|
209
|
-
/**
|
|
210
|
-
* Clones a branch locally to another directory and updates the origin to match the source.
|
|
211
|
-
*/
|
|
212
|
-
export const git_clone_locally = async (origin, branch, source_dir, target_dir, options) => {
|
|
213
|
-
await spawn('git', ['clone', '-b', branch, '--single-branch', source_dir, target_dir], options);
|
|
214
|
-
const origin_url = (await spawn_out('git', ['remote', 'get-url', origin], { ...options, cwd: source_dir })).stdout?.trim();
|
|
215
|
-
if (!origin_url)
|
|
216
|
-
throw Error('Failed to get the origin url with git in ' + source_dir);
|
|
217
|
-
await spawn('git', ['remote', 'set-url', origin, origin_url], { ...options, cwd: target_dir });
|
|
218
|
-
};
|