@astryxdesign/cli 0.7.1-canary.655fc29 → 0.7.1-canary.664eae9
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.
|
@@ -112,9 +112,11 @@ function resolveCliBin() {
|
|
|
112
112
|
* @param {{out?: string, iconsSpecifier?: string, detail?: string}} options -
|
|
113
113
|
* Parsed command options that affect generated output, plus the detail
|
|
114
114
|
* level the user chose.
|
|
115
|
+
* @param {(child: import('node:child_process').ChildProcess) => void} [onSpawn] -
|
|
116
|
+
* Receives the child, so a watcher that stops can stop it too.
|
|
115
117
|
* @returns {Promise<number>}
|
|
116
118
|
*/
|
|
117
|
-
function runThemeBuildOnceChild(file, options) {
|
|
119
|
+
function runThemeBuildOnceChild(file, options, onSpawn) {
|
|
118
120
|
const cliBin = resolveCliBin();
|
|
119
121
|
// A detail level the user chose applies to every rebuild.
|
|
120
122
|
const args = options.detail
|
|
@@ -128,6 +130,7 @@ function runThemeBuildOnceChild(file, options) {
|
|
|
128
130
|
stdio: 'inherit',
|
|
129
131
|
env: process.env,
|
|
130
132
|
});
|
|
133
|
+
onSpawn?.(child);
|
|
131
134
|
child.on('close', code => resolve(code ?? 0));
|
|
132
135
|
child.on('error', () => resolve(1));
|
|
133
136
|
});
|
|
@@ -139,7 +142,9 @@ function runThemeBuildOnceChild(file, options) {
|
|
|
139
142
|
* Rebuilds are serialized: one at a time, in the order the changes arrived, so
|
|
140
143
|
* the log stays readable. Each rebuild runs in a child process so a build error
|
|
141
144
|
* (which the single-build path reports via a hard exit) is contained and the
|
|
142
|
-
* watcher keeps running.
|
|
145
|
+
* watcher keeps running. Stopping ends the watch at once: queued changes are
|
|
146
|
+
* dropped, the signal reaches a rebuild in progress, as Ctrl-C in a terminal
|
|
147
|
+
* reaches the whole process group, and "Stopped watching." is the last line.
|
|
143
148
|
*
|
|
144
149
|
* @param {Array<{file: string, filePath: string}>} entries - The theme file
|
|
145
150
|
* arguments as the user passed them, with their resolved absolute paths.
|
|
@@ -159,6 +164,11 @@ async function runThemeBuildWatch(entries, options) {
|
|
|
159
164
|
}
|
|
160
165
|
|
|
161
166
|
let building = false;
|
|
167
|
+
let stopped = false;
|
|
168
|
+
/** @type {import('node:child_process').ChildProcess | null} */
|
|
169
|
+
let rebuildChild = null;
|
|
170
|
+
/** @type {Promise<void> | null} */
|
|
171
|
+
let rebuildDone = null;
|
|
162
172
|
/** @type {Set<{file: string, filePath: string}>} */
|
|
163
173
|
const queued = new Set();
|
|
164
174
|
/** @type {Map<string, ReturnType<typeof setTimeout>>} */
|
|
@@ -166,6 +176,7 @@ async function runThemeBuildWatch(entries, options) {
|
|
|
166
176
|
|
|
167
177
|
/** @param {{file: string, filePath: string}} entry */
|
|
168
178
|
const rebuild = async entry => {
|
|
179
|
+
if (stopped) return;
|
|
169
180
|
if (building) {
|
|
170
181
|
// Coalesce changes that land mid-build into a single follow-up run.
|
|
171
182
|
queued.add(entry);
|
|
@@ -173,8 +184,16 @@ async function runThemeBuildWatch(entries, options) {
|
|
|
173
184
|
}
|
|
174
185
|
building = true;
|
|
175
186
|
emit(text(`\nChange detected — rebuilding ${rel(entry.filePath)}...`));
|
|
176
|
-
|
|
187
|
+
const done = runThemeBuildOnceChild(entry.file, options, child => {
|
|
188
|
+
rebuildChild = child;
|
|
189
|
+
});
|
|
190
|
+
rebuildDone = done.then(() => {});
|
|
191
|
+
await done;
|
|
192
|
+
rebuildChild = null;
|
|
193
|
+
rebuildDone = null;
|
|
177
194
|
building = false;
|
|
195
|
+
// A stop during this build has already ended the watch.
|
|
196
|
+
if (stopped) return;
|
|
178
197
|
emit(text(watchingLine));
|
|
179
198
|
const next = queued.values().next();
|
|
180
199
|
if (!next.done) {
|
|
@@ -205,9 +224,18 @@ async function runThemeBuildWatch(entries, options) {
|
|
|
205
224
|
emit(text(watchingLine));
|
|
206
225
|
|
|
207
226
|
await new Promise((/** @type {(value?: void) => void} */ resolve) => {
|
|
208
|
-
|
|
227
|
+
/** @param {NodeJS.Signals} signal */
|
|
228
|
+
const stop = async signal => {
|
|
229
|
+
process.removeListener('SIGINT', stop);
|
|
230
|
+
process.removeListener('SIGTERM', stop);
|
|
231
|
+
stopped = true;
|
|
232
|
+
queued.clear();
|
|
209
233
|
for (const d of debounces.values()) clearTimeout(d);
|
|
210
234
|
for (const w of watchers) w.close();
|
|
235
|
+
// A rebuild in progress would otherwise keep the process alive after
|
|
236
|
+
// "Stopped watching.". In a terminal, Ctrl-C already reached it.
|
|
237
|
+
rebuildChild?.kill(signal);
|
|
238
|
+
await rebuildDone;
|
|
211
239
|
emit(text('\nStopped watching.'));
|
|
212
240
|
resolve();
|
|
213
241
|
};
|
|
@@ -124,7 +124,8 @@ describe('theme build --watch', () => {
|
|
|
124
124
|
const rebuilt = await waitFor(
|
|
125
125
|
() => {
|
|
126
126
|
try {
|
|
127
|
-
if (fs.readFileSync(cssFile, 'utf-8').includes('#010203'))
|
|
127
|
+
if (fs.readFileSync(cssFile, 'utf-8').includes('#010203'))
|
|
128
|
+
return true;
|
|
128
129
|
} catch {
|
|
129
130
|
// CSS mid-write; fall through to re-touch.
|
|
130
131
|
}
|
|
@@ -157,6 +158,63 @@ describe('theme build --watch', () => {
|
|
|
157
158
|
expect(stdout).toMatch(/Stopped watching/);
|
|
158
159
|
}, 30_000);
|
|
159
160
|
|
|
161
|
+
it('stops at once when interrupted mid-rebuild, and drops a queued change', async () => {
|
|
162
|
+
const themeFile = path.join(tmpDir, 'ws.mjs');
|
|
163
|
+
fs.writeFileSync(
|
|
164
|
+
themeFile,
|
|
165
|
+
`export default { name: 'ws', tokens: { '--color-bg': '#ffffff' } };\n`,
|
|
166
|
+
);
|
|
167
|
+
// Top-level await holds every rebuild of this version in progress for 20 s,
|
|
168
|
+
// far longer than a stop may take.
|
|
169
|
+
const slow =
|
|
170
|
+
`await new Promise(resolve => setTimeout(resolve, 20000));\n` +
|
|
171
|
+
`export default { name: 'ws', tokens: { '--color-bg': '#010203' } };\n`;
|
|
172
|
+
|
|
173
|
+
const child = spawn(
|
|
174
|
+
process.execPath,
|
|
175
|
+
[CLI_BIN, 'theme', 'build', 'ws.mjs', '--watch'],
|
|
176
|
+
{cwd: tmpDir, env: {...process.env, FORCE_COLOR: '0'}},
|
|
177
|
+
);
|
|
178
|
+
let stdout = '';
|
|
179
|
+
child.stdout.on('data', d => (stdout += d.toString()));
|
|
180
|
+
child.stderr.on('data', d => (stdout += d.toString()));
|
|
181
|
+
const exited = new Promise(resolve =>
|
|
182
|
+
child.once('exit', () => resolve(Date.now())),
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
let stoppedAt;
|
|
186
|
+
try {
|
|
187
|
+
expect(await waitFor(() => /Watching/i.test(stdout))).toBe(true);
|
|
188
|
+
// Start the slow rebuild, re-touching in case a watch event is dropped.
|
|
189
|
+
const started = await waitFor(
|
|
190
|
+
() => {
|
|
191
|
+
if (/rebuilding ws\.mjs/.test(stdout)) return true;
|
|
192
|
+
fs.writeFileSync(themeFile, slow);
|
|
193
|
+
return false;
|
|
194
|
+
},
|
|
195
|
+
{timeout: 20000, interval: 200},
|
|
196
|
+
);
|
|
197
|
+
expect(started).toBe(true);
|
|
198
|
+
// Queue a change behind the rebuild in progress (debounce is 100 ms).
|
|
199
|
+
fs.writeFileSync(themeFile, `${slow}// queued\n`);
|
|
200
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
201
|
+
} finally {
|
|
202
|
+
stoppedAt = Date.now();
|
|
203
|
+
child.kill('SIGINT');
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const exitedAt = await Promise.race([
|
|
207
|
+
exited,
|
|
208
|
+
new Promise(resolve => setTimeout(() => resolve(null), 15000)),
|
|
209
|
+
]);
|
|
210
|
+
if (exitedAt === null) child.kill('SIGKILL');
|
|
211
|
+
// Finishing the interrupted rebuild, or starting the queued one, takes 20 s.
|
|
212
|
+
expect(exitedAt).not.toBeNull();
|
|
213
|
+
expect(exitedAt - stoppedAt).toBeLessThan(10000);
|
|
214
|
+
expect(stdout.match(/rebuilding/g)).toHaveLength(1);
|
|
215
|
+
expect(stdout.trimEnd().endsWith('Stopped watching.')).toBe(true);
|
|
216
|
+
}, 60_000);
|
|
217
|
+
|
|
160
218
|
it.each([
|
|
161
219
|
[[], false],
|
|
162
220
|
[['--detail', 'full'], true],
|
|
@@ -219,7 +277,10 @@ describe('theme build --watch', () => {
|
|
|
219
277
|
);
|
|
220
278
|
expect(built).toBe(true);
|
|
221
279
|
await waitFor(() => /Watching w1\.mjs, w2\.mjs/.test(stdout));
|
|
222
|
-
const firstCssBefore = fs.readFileSync(
|
|
280
|
+
const firstCssBefore = fs.readFileSync(
|
|
281
|
+
path.join(tmpDir, 'w1.css'),
|
|
282
|
+
'utf-8',
|
|
283
|
+
);
|
|
223
284
|
|
|
224
285
|
const changed = `export default { name: 'w2', tokens: { '--color-bg': '#010203' } };\n`;
|
|
225
286
|
fs.writeFileSync(second, changed);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.7.1-canary.
|
|
3
|
+
"version": "0.7.1-canary.664eae9",
|
|
4
4
|
"displayName": "CLI",
|
|
5
5
|
"description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
@@ -101,10 +101,10 @@
|
|
|
101
101
|
"zod": "^4.4.3"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
|
-
"@astryxdesign/charts": "0.7.1-canary.
|
|
105
|
-
"@astryxdesign/core": "0.7.1-canary.
|
|
106
|
-
"@astryxdesign/lab": "0.7.1-canary.
|
|
107
|
-
"@astryxdesign/theme-neutral": "0.7.1-canary.
|
|
104
|
+
"@astryxdesign/charts": "0.7.1-canary.664eae9",
|
|
105
|
+
"@astryxdesign/core": "0.7.1-canary.664eae9",
|
|
106
|
+
"@astryxdesign/lab": "0.7.1-canary.664eae9",
|
|
107
|
+
"@astryxdesign/theme-neutral": "0.7.1-canary.664eae9"
|
|
108
108
|
},
|
|
109
109
|
"peerDependenciesMeta": {
|
|
110
110
|
"@astryxdesign/charts": {
|
|
@@ -121,10 +121,10 @@
|
|
|
121
121
|
}
|
|
122
122
|
},
|
|
123
123
|
"devDependencies": {
|
|
124
|
-
"@astryxdesign/charts": "0.7.1-canary.
|
|
125
|
-
"@astryxdesign/core": "0.7.1-canary.
|
|
126
|
-
"@astryxdesign/lab": "0.7.1-canary.
|
|
127
|
-
"@astryxdesign/theme-neutral": "0.7.1-canary.
|
|
124
|
+
"@astryxdesign/charts": "0.7.1-canary.664eae9",
|
|
125
|
+
"@astryxdesign/core": "0.7.1-canary.664eae9",
|
|
126
|
+
"@astryxdesign/lab": "0.7.1-canary.664eae9",
|
|
127
|
+
"@astryxdesign/theme-neutral": "0.7.1-canary.664eae9",
|
|
128
128
|
"@heroicons/react": "^2.2.0",
|
|
129
129
|
"@stylexjs/stylex": "^0.19.0",
|
|
130
130
|
"@types/babel__core": "^7.20.5",
|