@joberthel/worktree 1.2.0 → 1.3.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/README.md +2 -1
- package/dist/config/json-schema.js +37 -0
- package/dist/config/schema.js +17 -15
- package/package.json +4 -2
- package/schema/wt.schema.json +208 -0
package/README.md
CHANGED
|
@@ -115,6 +115,7 @@ Agents work with the [JSON output](docs/json-output.md): results, published port
|
|
|
115
115
|
`wt` works without a configuration file. Put `.wt.yml` at the root of your checkout to copy files into new worktrees, run setup hooks, or change the worktree directory:
|
|
116
116
|
|
|
117
117
|
```yaml
|
|
118
|
+
# yaml-language-server: $schema=https://unpkg.com/@joberthel/worktree@1/schema/wt.schema.json
|
|
118
119
|
worktrees:
|
|
119
120
|
directory: ../worktrees
|
|
120
121
|
|
|
@@ -130,7 +131,7 @@ hooks:
|
|
|
130
131
|
docker compose exec -T app bin/migrate
|
|
131
132
|
```
|
|
132
133
|
|
|
133
|
-
See [Configuration](docs/configuration.md) for every option, the hook order and variables, and how volumes are cloned. For a repository that runs inside another one, such as a Shopware plugin, see [Nested repositories](docs/nested-repositories.md).
|
|
134
|
+
The first line enables completion and validation in editors; see [Editor support](docs/configuration.md#editor-support). See [Configuration](docs/configuration.md) for every option, the hook order and variables, and how volumes are cloned. For a repository that runs inside another one, such as a Shopware plugin, see [Nested repositories](docs/nested-repositories.md).
|
|
134
135
|
|
|
135
136
|
Before you clone a database volume, stop writes to it or stop the source services if you need a consistent snapshot. Use dynamic host ports and leave out fixed `container_name` values, so the source and worktree projects can run side by side.
|
|
136
137
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { configSchema } from './schema.js';
|
|
3
|
+
export const configSchemaUrl = 'https://unpkg.com/@joberthel/worktree@1/schema/wt.schema.json';
|
|
4
|
+
// Sections accept an empty value such as `copy:`, which YAML reads as null.
|
|
5
|
+
// The Zod schema allows that through a preprocess step, which JSON Schema cannot express.
|
|
6
|
+
function allowEmptySection(zodSchema, jsonSchema) {
|
|
7
|
+
const def = zodSchema._zod.def;
|
|
8
|
+
if (def.type !== 'pipe' || !def.in._zod.traits.has('$ZodTransform'))
|
|
9
|
+
return;
|
|
10
|
+
const { description, default: fallback, ...section } = jsonSchema;
|
|
11
|
+
for (const key of Object.keys(jsonSchema))
|
|
12
|
+
delete jsonSchema[key];
|
|
13
|
+
Object.assign(jsonSchema, {
|
|
14
|
+
description,
|
|
15
|
+
default: fallback,
|
|
16
|
+
anyOf: [
|
|
17
|
+
section,
|
|
18
|
+
{ type: 'null' },
|
|
19
|
+
],
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export function configJsonSchema() {
|
|
23
|
+
const schema = z.toJSONSchema(configSchema, {
|
|
24
|
+
io: 'input',
|
|
25
|
+
override: ({ zodSchema, jsonSchema }) => allowEmptySection(zodSchema, jsonSchema),
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
$schema: schema.$schema,
|
|
29
|
+
$id: configSchemaUrl,
|
|
30
|
+
title: 'wt configuration',
|
|
31
|
+
description: 'Configuration for wt, read from .wt.yml at the root of the source checkout.',
|
|
32
|
+
...schema,
|
|
33
|
+
not: {
|
|
34
|
+
required: ['host', 'worktrees'],
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
package/dist/config/schema.js
CHANGED
|
@@ -5,9 +5,9 @@ const relativePath = z.string().min(1).transform(value => value.split('/').filte
|
|
|
5
5
|
return value.split('/').every(part => part !== '..' && part.toLowerCase() !== '.git' && part !== '');
|
|
6
6
|
}, 'must be a normalized relative path without ..');
|
|
7
7
|
const hook = z.union([
|
|
8
|
-
relativePath,
|
|
8
|
+
relativePath.meta({ description: 'Path to an executable, relative to the directory the hook runs in.' }),
|
|
9
9
|
z.object({
|
|
10
|
-
script: z.string().refine(value => value.trim().length > 0, 'must not be empty'),
|
|
10
|
+
script: z.string().refine(value => value.trim().length > 0, 'must not be empty').meta({ description: 'Inline shell script run with /bin/sh. Start it with `set -eu` to stop at the first failure.' }),
|
|
11
11
|
}).strict(),
|
|
12
12
|
]);
|
|
13
13
|
function emptySection(input) {
|
|
@@ -15,24 +15,26 @@ function emptySection(input) {
|
|
|
15
15
|
? undefined
|
|
16
16
|
: input;
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
function hookGroup(description) {
|
|
19
|
+
return z.preprocess(emptySection, z.object({
|
|
20
|
+
before_create: hook.optional().meta({ description: 'Runs after the worktree, copied files, and cloned volumes are in place, before Docker Compose starts the services.' }),
|
|
21
|
+
after_create: hook.optional().meta({ description: 'Runs after Docker Compose has started the services.' }),
|
|
22
|
+
}).strict().optional()).meta({ description });
|
|
23
|
+
}
|
|
22
24
|
const host = z.object({
|
|
23
|
-
path: z.string().min(1).refine(value => !value.startsWith('~'), 'use an absolute path or a path relative to this checkout'),
|
|
24
|
-
from: z.string().min(1).optional(),
|
|
25
|
+
path: z.string().min(1).refine(value => !value.startsWith('~'), 'use an absolute path or a path relative to this checkout').meta({ description: 'Root of the host checkout, absolute or relative to this checkout.' }),
|
|
26
|
+
from: z.string().min(1).optional().meta({ description: 'Host ref to check out. Defaults to the host checkout\'s HEAD.' }),
|
|
25
27
|
}).strict();
|
|
26
28
|
export const configSchema = z.object({
|
|
27
|
-
host: host.optional(),
|
|
29
|
+
host: host.optional().meta({ description: 'Runs this repository inside the Docker environment of a host repository. Cannot be combined with `worktrees`.' }),
|
|
28
30
|
worktrees: z.preprocess(emptySection, z.object({
|
|
29
|
-
directory: z.string().min(1).refine(value => !value.startsWith('~'), 'use an absolute path or a path relative to the main checkout').default('../worktrees'),
|
|
30
|
-
}).strict().default({ directory: '../worktrees' })),
|
|
31
|
-
copy: z.preprocess(emptySection, z.array(relativePath).default([])),
|
|
31
|
+
directory: z.string().min(1).refine(value => !value.startsWith('~'), 'use an absolute path or a path relative to the main checkout').default('../worktrees').meta({ description: 'Where worktrees are created, absolute or relative to the main checkout.' }),
|
|
32
|
+
}).strict().default({ directory: '../worktrees' })).meta({ description: 'Worktree placement.' }),
|
|
33
|
+
copy: z.preprocess(emptySection, z.array(relativePath).default([])).meta({ description: 'Relative files and directories copied from the source checkout into each new worktree. Entries must not overlap.' }),
|
|
32
34
|
hooks: z.preprocess(emptySection, z.object({
|
|
33
|
-
worktree: hookGroup,
|
|
34
|
-
source: hookGroup,
|
|
35
|
-
}).strict().default({})),
|
|
35
|
+
worktree: hookGroup('Hooks that run in the new worktree.'),
|
|
36
|
+
source: hookGroup('Hooks that run in the source checkout.'),
|
|
37
|
+
}).strict().default({})).meta({ description: 'Commands run by `wt create` and `wt reset`.' }),
|
|
36
38
|
}).strict().superRefine((config, ctx) => {
|
|
37
39
|
const paths = new Set();
|
|
38
40
|
for (const path of config.copy) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joberthel/worktree",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"description": "Isolated development environments from Git worktrees, each with its own Docker Compose project and cloned volumes.",
|
|
6
6
|
"author": "Johannes Berthel",
|
|
7
7
|
"license": "MIT",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"wt": "./dist/cli.js"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
|
-
"dist"
|
|
28
|
+
"dist",
|
|
29
|
+
"schema"
|
|
29
30
|
],
|
|
30
31
|
"engines": {
|
|
31
32
|
"node": ">=22"
|
|
@@ -66,6 +67,7 @@
|
|
|
66
67
|
"test:unit": "vitest run --exclude 'e2e/**/*.e2e.test.ts'",
|
|
67
68
|
"test:coverage": "pnpm test:unit --coverage",
|
|
68
69
|
"test:e2e": "pnpm build && vitest run e2e",
|
|
70
|
+
"schema": "vitest run src/config/json-schema.test.ts --update",
|
|
69
71
|
"lint": "eslint . --max-warnings 0",
|
|
70
72
|
"lint:fix": "eslint . --fix",
|
|
71
73
|
"commitlint": "commitlint",
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://unpkg.com/@joberthel/worktree@1/schema/wt.schema.json",
|
|
4
|
+
"title": "wt configuration",
|
|
5
|
+
"description": "Configuration for wt, read from .wt.yml at the root of the source checkout.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"host": {
|
|
9
|
+
"description": "Runs this repository inside the Docker environment of a host repository. Cannot be combined with `worktrees`.",
|
|
10
|
+
"type": "object",
|
|
11
|
+
"properties": {
|
|
12
|
+
"path": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"minLength": 1,
|
|
15
|
+
"description": "Root of the host checkout, absolute or relative to this checkout."
|
|
16
|
+
},
|
|
17
|
+
"from": {
|
|
18
|
+
"description": "Host ref to check out. Defaults to the host checkout's HEAD.",
|
|
19
|
+
"type": "string",
|
|
20
|
+
"minLength": 1
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"required": [
|
|
24
|
+
"path"
|
|
25
|
+
],
|
|
26
|
+
"additionalProperties": false
|
|
27
|
+
},
|
|
28
|
+
"worktrees": {
|
|
29
|
+
"description": "Worktree placement.",
|
|
30
|
+
"default": {
|
|
31
|
+
"directory": "../worktrees"
|
|
32
|
+
},
|
|
33
|
+
"anyOf": [
|
|
34
|
+
{
|
|
35
|
+
"type": "object",
|
|
36
|
+
"properties": {
|
|
37
|
+
"directory": {
|
|
38
|
+
"default": "../worktrees",
|
|
39
|
+
"description": "Where worktrees are created, absolute or relative to the main checkout.",
|
|
40
|
+
"type": "string",
|
|
41
|
+
"minLength": 1
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"additionalProperties": false
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"type": "null"
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
"copy": {
|
|
52
|
+
"description": "Relative files and directories copied from the source checkout into each new worktree. Entries must not overlap.",
|
|
53
|
+
"anyOf": [
|
|
54
|
+
{
|
|
55
|
+
"type": "array",
|
|
56
|
+
"items": {
|
|
57
|
+
"type": "string",
|
|
58
|
+
"minLength": 1
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"type": "null"
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
"hooks": {
|
|
67
|
+
"description": "Commands run by `wt create` and `wt reset`.",
|
|
68
|
+
"anyOf": [
|
|
69
|
+
{
|
|
70
|
+
"type": "object",
|
|
71
|
+
"properties": {
|
|
72
|
+
"worktree": {
|
|
73
|
+
"description": "Hooks that run in the new worktree.",
|
|
74
|
+
"anyOf": [
|
|
75
|
+
{
|
|
76
|
+
"type": "object",
|
|
77
|
+
"properties": {
|
|
78
|
+
"before_create": {
|
|
79
|
+
"description": "Runs after the worktree, copied files, and cloned volumes are in place, before Docker Compose starts the services.",
|
|
80
|
+
"anyOf": [
|
|
81
|
+
{
|
|
82
|
+
"description": "Path to an executable, relative to the directory the hook runs in.",
|
|
83
|
+
"type": "string",
|
|
84
|
+
"minLength": 1
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"type": "object",
|
|
88
|
+
"properties": {
|
|
89
|
+
"script": {
|
|
90
|
+
"type": "string",
|
|
91
|
+
"description": "Inline shell script run with /bin/sh. Start it with `set -eu` to stop at the first failure."
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
"required": [
|
|
95
|
+
"script"
|
|
96
|
+
],
|
|
97
|
+
"additionalProperties": false
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
},
|
|
101
|
+
"after_create": {
|
|
102
|
+
"description": "Runs after Docker Compose has started the services.",
|
|
103
|
+
"anyOf": [
|
|
104
|
+
{
|
|
105
|
+
"description": "Path to an executable, relative to the directory the hook runs in.",
|
|
106
|
+
"type": "string",
|
|
107
|
+
"minLength": 1
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"type": "object",
|
|
111
|
+
"properties": {
|
|
112
|
+
"script": {
|
|
113
|
+
"type": "string",
|
|
114
|
+
"description": "Inline shell script run with /bin/sh. Start it with `set -eu` to stop at the first failure."
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
"required": [
|
|
118
|
+
"script"
|
|
119
|
+
],
|
|
120
|
+
"additionalProperties": false
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
"additionalProperties": false
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"type": "null"
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
"source": {
|
|
133
|
+
"description": "Hooks that run in the source checkout.",
|
|
134
|
+
"anyOf": [
|
|
135
|
+
{
|
|
136
|
+
"type": "object",
|
|
137
|
+
"properties": {
|
|
138
|
+
"before_create": {
|
|
139
|
+
"description": "Runs after the worktree, copied files, and cloned volumes are in place, before Docker Compose starts the services.",
|
|
140
|
+
"anyOf": [
|
|
141
|
+
{
|
|
142
|
+
"description": "Path to an executable, relative to the directory the hook runs in.",
|
|
143
|
+
"type": "string",
|
|
144
|
+
"minLength": 1
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"type": "object",
|
|
148
|
+
"properties": {
|
|
149
|
+
"script": {
|
|
150
|
+
"type": "string",
|
|
151
|
+
"description": "Inline shell script run with /bin/sh. Start it with `set -eu` to stop at the first failure."
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
"required": [
|
|
155
|
+
"script"
|
|
156
|
+
],
|
|
157
|
+
"additionalProperties": false
|
|
158
|
+
}
|
|
159
|
+
]
|
|
160
|
+
},
|
|
161
|
+
"after_create": {
|
|
162
|
+
"description": "Runs after Docker Compose has started the services.",
|
|
163
|
+
"anyOf": [
|
|
164
|
+
{
|
|
165
|
+
"description": "Path to an executable, relative to the directory the hook runs in.",
|
|
166
|
+
"type": "string",
|
|
167
|
+
"minLength": 1
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"type": "object",
|
|
171
|
+
"properties": {
|
|
172
|
+
"script": {
|
|
173
|
+
"type": "string",
|
|
174
|
+
"description": "Inline shell script run with /bin/sh. Start it with `set -eu` to stop at the first failure."
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
"required": [
|
|
178
|
+
"script"
|
|
179
|
+
],
|
|
180
|
+
"additionalProperties": false
|
|
181
|
+
}
|
|
182
|
+
]
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
"additionalProperties": false
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
"type": "null"
|
|
189
|
+
}
|
|
190
|
+
]
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
"additionalProperties": false
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
"type": "null"
|
|
197
|
+
}
|
|
198
|
+
]
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
"additionalProperties": false,
|
|
202
|
+
"not": {
|
|
203
|
+
"required": [
|
|
204
|
+
"host",
|
|
205
|
+
"worktrees"
|
|
206
|
+
]
|
|
207
|
+
}
|
|
208
|
+
}
|