Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ these entries stays in the GitHub releases and the Git history.

### Fixed

- Restore the terminal prompt with exit code 1 when `wf dev` starts without a project or a selectable entry; compilation errors still keep watching for edits. Environment sources 0.9.2, not published yet (#560).
- Read all six developer integration reports in CTest after a part fails, and keep the successful parts' dependent tests runnable, also when the session's native deadline ends it (#556).
- On Windows, `wf install`, `wf build` and `wf test` no longer fail with `rename: Access is denied` while another process, such as an antivirus scan, still reads the files just written: the developer store tries the rename again for up to 635 ms; `wf test` also empties the directory of an interrupted run (#542).
- Run the commit attribution regression checks with older Git versions by dropping the unsupported `git log --no-graph` option (#525).
Expand Down
3 changes: 3 additions & 0 deletions docs/DEVELOPER_ENVIRONMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@ files; the developer HTTP provider serves only the environment and preview direc

`wf dev [entry.tsx|name]` selects `entries.main` or the sole entry when omitted, builds, opens the preview
and keeps running until Ctrl+C. It reuses one compiler Worker and esbuild context across rebuilds.
At startup only a missing project or an omitted entry that cannot be selected ends the command with exit
code 1 and restores the terminal prompt. Any other error (an unreadable or malformed manifest or lock, a
compilation error, including a failed first build) keeps the watcher running so that editing the inputs can recover.
Changing the selected entry or locked graph recreates the context. It uses the installed lock, without
resolving packages or downloading dependencies; `wf install`/`wf restore` remain explicit actions.

Expand Down
4 changes: 2 additions & 2 deletions js/developer/environment/bundles.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"js/developer/environment/paths.mjs": "3b6114df78eb193161c5c84499dda084cb7ff91c56a4496371c30295d00880e3",
"js/developer/environment/runtime.mjs": "2c9ef449c44ddbdcc327ffb126e61c3e8e8076edbe73a0dce99e3dc9bb42b5a9",
"js/developer/environment/automation.mjs": "79405c89ba7025c1774bc13c9b78d814a07592755dcde018c8659a8015c4b8ed",
"js/developer/environment/development.mjs": "168a2619c4d74544eed2b2ae1121e87c3afc776dc6140a3c7d1ba1d0d6168cd8",
"js/developer/environment/development.mjs": "1f32f911610c72ad3e935de1c2b138fa275ce9eda04bb63c824d5e09923305a6",
"js/developer/environment/testing.mjs": "aeb584505fab5957b9c02e78536e12f7d7f3d12f8adb2e17f1a1a6e395e43f3c",
"js/developer/environment/terminal.mjs": "7ffcf7ac6ef63c35cdf5ef70284b384525b13ba18422af069289e53b6c4f6be1",
"js/developer/environment/workspace.mjs": "4fe794b140515579c4f80a226d8b1beca254a3488e2e4d9f6ba580e077a11558",
Expand All @@ -40,7 +40,7 @@
"js/developer/environment/embed.mjs": "3d3b5036c34c23a1fa0512c1eea42f26d5f30e054545b61fe83a5c378b74e09e",
"examples/life/ui/main.tsx": "7b1ff285d2a6b8f897ef12df872886e61ef4b24e2358a9423b76b38ab75c85d3",
"examples/life/ui/style.css": "9bb55eb0f0a3287e5b7dc78af9d69608b87ff42c4d9c8a653bc83a52fe293c44",
"js/developer/tools/distribution.json": "0de03c0bd22fdcfe87c686d6c1456d26eeb57b09b03d0d680bb81557906f31a0",
"js/developer/tools/distribution.json": "1f2934587eeed1c88630e1693f7ddc91c65315d08a151b6427a3edac36368690",
"js/developer/tools/archive.mjs": "da63bb9d796ddfd24ed945b15c53f66a0400eb177886fd4f1c8fd10cafb5a91b",
"js/developer/tools/distribution.mjs": "43dfdccc912693db46fd095fd78ae79325abab672d99f89fd569914ef3499cad",
"js/developer/scripts/build.mjs": "def3c0ccecbc776b76e20571d015f9a1f23a267c0bd6c0c7a07a81ce9293a663",
Expand Down
10 changes: 8 additions & 2 deletions js/developer/environment/development.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,11 @@ export async function dev(args, {bridge, signal, preview: frame, write = () => {
catch (error) { if (configReads.get(path) !== 'missing') throw error; }
}
const project = await loadProject(bridge);
if (!project.manifest && args[0] === undefined) throw new Error(noManifest);
const entry = resolveEntry(project.manifest, args[0], 'wf dev <entry.tsx>');
let entry;
try {
if (!project.manifest && args[0] === undefined) throw new Error(noManifest);
entry = resolveEntry(project.manifest, args[0], 'wf dev <entry.tsx>');
} catch (error) { error.invalidStart = true; throw error; }
if (!session || session.closed) session = compilerSession(bridge, active);
const files = await session.rebuild({entry, lock: project.lock ?? {format: 1, roots: {}, packages: {}}});
files.set('index.html', previewPage(files));
Expand All @@ -238,6 +241,9 @@ export async function dev(args, {bridge, signal, preview: frame, write = () => {
} catch (error) {
if (active.aborted) throw stopped();
if (error?.code === 'busy') { await waitForPoll(active); continue; }
// A missing project or an omitted entry at startup finishes the command; every other failure
// (unreadable or malformed files, compilation errors, later edits) stays recoverable.
if (!session && error?.invalidStart) throw error;
diagnostic = diagnosticsText(error);
report('failed');
write(diagnostic + '\n');
Expand Down
2 changes: 1 addition & 1 deletion js/developer/tools/distribution.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "0.9.1",
"version": "0.9.2",
"baseUrl": "https://dist.webfront.fr/"
}
41 changes: 41 additions & 0 deletions test/developer/specs/development-specs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,47 @@ describe('wf dev', () => {
const encode = text => new TextEncoder().encode(text);

const lock = {format: 1, roots: {}, packages: {}};
for (const [label, manifest, message] of [
['without a project', null, /No webfront.project.json: run wf init/],
['without an entry', {format: 1, name: 'empty', version: '0.1.0'}, /Usage: wf dev <entry.tsx>/],
]) it(`rejects ${label} without waiting for Ctrl+C or starting a compiler`, async () => {
const {bridge} = memoryBridge(new Map(manifest ? [['webfront.project.json', encode(JSON.stringify(manifest))]] : []));
const controller = new AbortController();
// Bound the regression: the broken command stays in its polling loop until this aborts it.
const timer = setTimeout(() => controller.abort(), 1000);
const states = [], output = [];
const frame = new EventTarget();
frame.addEventListener('webfront-dev-status', event => states.push(event.detail.state));
const worker = spyOn(globalThis, 'Worker').and.throwError('The compiler must not start');
try {
await rejects(dev([], {bridge, signal: controller.signal, preview: frame, write: text => output.push(text)}), message);
expect(controller.signal.aborted).toBe(false);
expect(worker).not.toHaveBeenCalled();
expect(states.at(-1)).toBe('stopped');
expect(output).toEqual([]);
} finally { clearTimeout(timer); controller.abort(); }
});

it('keeps watching when the manifest is malformed at startup', async () => {
const {bridge} = memoryBridge(new Map([['webfront.project.json', encode('{not json')]]));
const controller = new AbortController();
const states = [], output = [];
const frame = new EventTarget();
frame.addEventListener('webfront-dev-status', event => {
states.push(event.detail.state);
if (event.detail.state === 'failed') controller.abort();
});
const worker = spyOn(globalThis, 'Worker').and.throwError('The compiler must not start');
const timer = setTimeout(() => controller.abort(), 5000);
try {
await dev([], {bridge, signal: controller.signal, preview: frame, write: text => output.push(text)}).then(
() => fail('dev must not resolve'), () => {});
expect(states).toContain('failed');
expect(output.join('')).not.toBe('');
expect(worker).not.toHaveBeenCalled();
} finally { clearTimeout(timer); controller.abort(); }
});

it('one esbuild context reads changed imports, reports syntax errors and recovers', async () => {
const files = new Map([['main.ts', encode("import {value} from './value'; console.log(value)")], ['value.ts', encode('export const value = 1')]]);
const context = await bundleContext(await esbuild(), {entry: 'main.ts', lock, readProject: async path => {
Expand Down
36 changes: 33 additions & 3 deletions test/web/developer-specs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ try {
const scriptOutput = [];
const runContext = (signal = new AbortController().signal) => ({...context, signal, write: text => { scriptOutput.push(text); console.log(text); }});
const printed = async text => {
for (let attempt = 0; !scriptOutput.some(line => line.includes(text)); ++attempt) {
if (attempt === 200) throw new Error(`The script did not print ${text}`);
// Starting a real Worker and compiling WASM can take more than five seconds while the other panes build.
const deadline = performance.now() + 30000;
while (!scriptOutput.some(line => line.includes(text))) {
if (performance.now() >= deadline) throw new Error(`The script did not print ${text} within 30 seconds`);
await delay(25);
}
};
Expand Down Expand Up @@ -1240,8 +1242,16 @@ try {
host.style.cssText = 'width:640px;height:240px';
document.body.append(host);
let exitedWith = null;
let startupFiles;
const terminalBridge = {socket: webFront.socket, cppFunction: name => name !== 'webfront.developer.read' ? webFront.cppFunction(name) :
async (path, offset) => {
if (!startupFiles || !['webfront.project.json', 'webfront-packages.lock.json'].includes(path))
return webFront.cppFunction(name)(path, offset);
if (!startupFiles.has(path)) throw new Error('Cannot read project file: ' + path);
return startupFiles.get(path).subarray(offset, offset + 256 * 1024);
}};
// The test sets the terminal's size itself: an observer following the element would race with it.
const mounted = async () => runtime.mount({bridge: webFront, config, terminal: host, preview: context.preview, onExit: code => { exitedWith = code; }, fitToElement: false});
const mounted = async () => runtime.mount({bridge: terminalBridge, config, terminal: host, preview: context.preview, onExit: code => { exitedWith = code; }, fitToElement: false});
const {terminal, editor} = await mounted();
terminal.resize(80, 12);
const buffer = () => terminal.buffer.active;
Expand All @@ -1263,6 +1273,26 @@ try {
const lastRows = count => rows().slice(cursorRow() - count + 1, cursorRow() + 1);
await type('echo hello\r');
assert(JSON.stringify(lastRows(3)) === JSON.stringify(['> echo hello', 'hello', '> ']), `A C++ command must run from the terminal: ${lastRows(3)}`);
// Initial dev errors must finish the session command, without requiring Ctrl+C (#560).
for (const [manifest, message] of [[null, 'No webfront.project.json: run wf init'],
[{format: 1, name: 'empty', version: '0.1.0'}, 'Usage: wf dev <entry.tsx>']]) {
startupFiles = new Map(manifest ? [['webfront.project.json', new TextEncoder().encode(JSON.stringify(manifest))]] : []);
try {
terminal.input('wf dev\r');
await delay(10);
for (let attempt = 0; attempt < 200 && editor.busy; ++attempt) await delay(10);
assert(!editor.busy, 'An invalid wf dev invocation must finish without Ctrl+C');
await editor.whenIdle();
await rendered();
assert(editor.status === 1 && rows().some(row => row.includes(message)) && lastRows(1)[0] === '> ',
`wf dev must report its error and restore the prompt: ${lastRows(4)}`);
await type('echo recovered\r');
assert(editor.status === 0 && lastRows(2)[0] === 'recovered', 'The next command must run after the startup error');
} finally {
startupFiles = undefined;
if (editor.busy) await type('\x03');
}
}
// Cell widths: CJK, emoji, a flag, a ZWJ sequence and a combining mark.
await type('漢字😀🇫🇷👨‍👩‍👧éx');
assert(buffer().cursorX === 2 + 2 + 2 + 2 + 2 + 2 + 1 + 1, `Wide characters must take two cells: ${buffer().cursorX}`);
Expand Down
Loading