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
61 changes: 61 additions & 0 deletions .github/scripts/windows-app.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// The Windows job's helpers (ci.yml), in Node so they behave the same in every shell.
//
// node windows-app.mjs prepare <app> <plugin.tgz>
// Points a scaffolded app at the packed plugin and sets `engine: 'wasm'` everywhere it calls
// ngp(): the package carries no native engine for Windows.
// node windows-app.mjs serve <app> <port> <url path> <regexp> [-- <command...>]
// Starts the app's dev server (or the command given), waits for <url path> to answer, checks
// the body matches <regexp>, and stops the server.
import assert from 'node:assert/strict';
import {spawn} from 'node:child_process';
import {copyFileSync, readFileSync, writeFileSync} from 'node:fs';
import {join} from 'node:path';
import {setTimeout as delay} from 'node:timers/promises';

const [command, ...args] = process.argv.slice(2);

if (command === 'prepare') {
const [app, tarball] = args;
const pkgPath = join(app, 'package.json');
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
// Copied in and named relatively, so the specifier has no backslash or drive letter in it.
copyFileSync(tarball, join(app, 'vite-plugin-ngp.tgz'));
pkg.devDependencies['@push-based/vite-plugin-ngp'] = 'file:./vite-plugin-ngp.tgz';
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
for (const name of ['vite.config.ts', 'vitest.config.ts']) {
const file = join(app, name);
const before = readFileSync(file, 'utf8');
const after = before.replace('ngp({', "ngp({\n engine: 'wasm',").replace('ngp()', "ngp({ engine: 'wasm' })");
assert.notEqual(after, before, `${file} has no ngp() call to set the engine on`);
writeFileSync(file, after);
console.log(`${name}:\n${after}`);
}
} else if (command === 'serve') {
const [app, port, urlPath, pattern, separator, ...rest] = args;
const cmd = separator === '--' ? rest : [join(app, 'node_modules/vite/bin/vite.js'), '--port', port, '--strictPort'];
// Node itself, never a .cmd shim, so stopping the child stops the server.
const child = spawn(process.execPath, cmd, {cwd: app, env: {...process.env, PORT: port}, stdio: ['ignore', 'pipe', 'pipe']});
let output = '';
child.stdout.on('data', (d) => (output += d));
child.stderr.on('data', (d) => (output += d));
try {
let body;
for (let i = 0; i < 240 && body === undefined && child.exitCode === null; i++) {
try {
const response = await fetch(`http://localhost:${port}${urlPath}`, {headers: {Accept: 'text/html,*/*'}});
if (response.ok) body = await response.text();
} catch {
// Not listening yet.
}
if (body === undefined) await delay(250);
}
assert.ok(body !== undefined, `${cmd.join(' ')} never answered ${urlPath}:\n${output}`);
assert.match(body, new RegExp(pattern), `${urlPath} answered, but not with ${pattern}:\n${body.slice(0, 2000)}\n${output}`);
console.log(`${urlPath} on port ${port} matches ${pattern}`);
} finally {
child.kill();
}
} else {
console.error(`unknown command ${command}`);
process.exit(1);
}
84 changes: 84 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Builds ngp from source, then the plugin, its tests, create-ngp's apps with and without Vite+, the
# playground's Vitest specs and the playground itself, on a clean machine.
# Then the tests, the specs and the playground build once more, on the newest Angular the plugin accepts.
# The windows job installs the packed plugin into create-ngp's templates on Windows, with the wasm engine.
# This is the check that the build instructions in docs/building.md work.
name: ci

Expand Down Expand Up @@ -41,6 +42,22 @@ jobs:
# so toolchain/bundle.mjs can't break between releases. The tests below still use toolchain/out.
- run: node toolchain/bundle.mjs --host-only

# The plugin as npm would ship it, with this bundle (and so the wasm engine), and create-ngp,
# for the windows job below. --config.ignore-scripts skips the plugin's four-engine prepack check.
- name: Pack the plugin and create-ngp for the windows job
run: |
pnpm build
mkdir -p packed
(cd packages/vite-plugin-ngp && pnpm pack --pack-destination ../../packed --config.ignore-scripts=true)
(cd packages/create-ngp && pnpm pack --pack-destination ../../packed)
tar -tzf packed/push-based-vite-plugin-ngp-*.tgz | grep -x 'package/ngp/engines/wasm/ng_analyze_bg.wasm'

- uses: actions/upload-artifact@v4
with:
name: packed
path: packed/*.tgz
retention-days: 7

# The playground's browser-mode project runs its specs in headless Chromium, and so does
# create-ngp's Vite+ test, with the same Playwright version.
- run: pnpm --filter playground exec playwright install --with-deps chromium
Expand Down Expand Up @@ -85,3 +102,70 @@ jobs:
pnpm --filter @push-based/vite-plugin-ngp test
pnpm --filter playground test
pnpm --filter playground build

# The package has no native ngp engine for Windows (publish.yml builds darwin and linux), so this
# runs the plugin there the only way it can: engine: 'wasm'. ngp isn't built here. The plugin and
# create-ngp come packed from the build job, as npm would ship them, and the scaffolder, the
# install, `vite build`, the spec and a server all run on Windows.
#
# It fails today, and continue-on-error keeps that from failing the workflow. The scaffold and the
# install pass; `vite build` stops with TsconfigNotFound, because the wasm engine reads paths by
# Unix rules, where `D:\...` is relative. #148 has what the engine sees and the ways out. Drop
# continue-on-error once the job passes.
windows:
needs: build
runs-on: windows-latest
continue-on-error: true
timeout-minutes: 30
defaults:
run:
shell: bash
env:
CI: 'true'
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
.nvmrc
package.json
.github/scripts
sparse-checkout-cone-mode: false

- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- uses: actions/download-artifact@v4
with:
name: packed
path: ${{ runner.temp }}/packed

- name: Scaffold app and app-ssr with create-ngp
working-directory: ${{ runner.temp }}
run: |
npm install --no-save --prefix create-ngp ./packed/push-based-create-ngp-*.tgz
for template in app app-ssr; do
node create-ngp/node_modules/@push-based/create-ngp/index.js "$template" --no-interactive --template "$template"
node "$GITHUB_WORKSPACE/.github/scripts/windows-app.mjs" prepare "$template" packed/push-based-vite-plugin-ngp-*.tgz
done

- name: 'app: install, build, spec, dev server'
working-directory: ${{ runner.temp }}/app
run: |
pnpm install
pnpm run build
test -f dist/index.html
pnpm test
node "$GITHUB_WORKSPACE/.github/scripts/windows-app.mjs" serve . 5281 /src/app/app.ts 'ɵɵdefineComponent'

- name: 'app-ssr: install, build and prerender, spec, dev server, built server'
working-directory: ${{ runner.temp }}/app-ssr
run: |
pnpm install
pnpm run build
grep -q 'ng-server-context="ssg"' dist/client/index.html
pnpm test
node "$GITHUB_WORKSPACE/.github/scripts/windows-app.mjs" serve . 5282 / 'Clicks: 0'
node "$GITHUB_WORKSPACE/.github/scripts/windows-app.mjs" serve . 5283 / 'ng-server-context="ssg"' -- dist/server/server.js
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ A first version on top of a prototype compiler. Everything below was checked in
- Builds and test runs reuse compiled output from the last run, for every module whose inputs haven't changed.
- Vite+: `vp create @push-based/ngp` for a new app, `vp migrate` for an existing one, then `vp dev`, `vp build`, `vp test` and `vp check`.

**Not yet:** preprocessors in inline `styles`, `@angular/ssr` with i18n, the service worker, library builds, and Windows outside WSL 2, which is untested.
**Not yet:** preprocessors in inline `styles`, `@angular/ssr` with i18n, the service worker, library builds, and Windows outside WSL 2: CI runs it there with the wasm engine, and the build fails ([#148](https://github.com/push-based/vite-plugin-ngp/issues/148)).

**The catch.** It's on npm as [`@push-based/vite-plugin-ngp`](https://www.npmjs.com/package/@push-based/vite-plugin-ngp), but ngp isn't published, so the package carries its own build of it, made from Angular's source at `22.3.2`, and it runs on Angular 22.3 only, from `22.3.0-rc.0` on. The plugin also uses ngp below its intended surface, so any Angular commit can break it. The [status page](https://push-based.github.io/vite-plugin-ngp/status/) lists every limit.

Expand Down
19 changes: 19 additions & 0 deletions docs/decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1122,3 +1122,22 @@ The move itself was small on the plugin's side. Of the 52 JavaScript files `tsc`
**Cost.** The plugin now repeats what TypeScript's launcher does to find the binary (`lib/getExePath.js`): the package name, `lib/tsc`, `.exe` and the `\\?\` prefix for Windows paths of 248 characters or more. The Windows half is untested, with no Windows CI yet. If a later TypeScript 7 moves the binary or adds a platform, the launcher would follow and the plugin won't until someone moves its pins; the test compares the pins with a list written into it, not with npm, so it can't notice a new platform. When bumping, copy the list from `npm view typescript@<version> optionalDependencies`. An install without optional dependencies (`--no-optional`, `--omit=optional`) gets an error from the check instead of a checker, as it did with the launcher, whose platform packages were optional too; the error now says so.

**Revisit when** TypeScript 7 publishes its CLI under a name other than `typescript`, or pnpm stops linking aliases under their real names, so a launcher dependency stops counting as the plugin's TypeScript. Or when the plugin moves to TypeScript 7's API, as decision 29's revisit hopes.

## 87. Run Windows in CI with the wasm engine, non-blocking, and send Windows users to WSL 2

*4 December 2026*

**Decision.** A `windows` job in `ci.yml` runs the plugin on `windows-latest` with `engine: 'wasm'`. It builds nothing: the `build` job packs the plugin, with the ngp bundle `toolchain/bundle.mjs --host-only` made (so the wasm engine is in it), and packs create-ngp, then uploads both. The Windows job scaffolds `app` and `app-ssr` with the packed scaffolder, installs the packed plugin, and runs `vite build`, the spec and the servers ([windows-app.mjs](../.github/scripts/windows-app.mjs)). It is `continue-on-error: true` until it passes. When the package has no native engine and the platform is Windows, the plugin's error no longer says to set `engine: 'wasm'`. It says the plugin doesn't run on Windows yet, and to use WSL 2.

**Why.** Status said "untested", and the only way to say more was to run it. The job sits in `ci.yml` rather than a workflow of its own, because the packed plugin is an artifact of the `build` job. A separate workflow would build ngp again, or wire itself to `ci` through `workflow_run`. Building ngp on Windows isn't possible: `toolchain/` is bash with Darwin and Linux branches. Wasm is the only engine the package can offer Windows.

The first run answered the question. The scaffold and the install pass, and `vite build` stops before compiling with `TsconfigNotFound("D:\\a\\_temp\\app\\tsconfig.app.json")`. The wasm engine is built for `wasm32-unknown-unknown`, so its Rust code reads paths by Unix rules, where `D:\…` and `D:/…` are relative. A probe on the runner loaded the engine with the tsconfig path written three ways:
- `D:\…` resolved only because the working directory was the app, and wrote import specifiers like `./D:/a/_temp/app/src/app/app`.
- `D:/…` joined `include` onto itself and walked the whole folder: 12,401 filesystem calls.
- `/D:/…`, with a host filesystem that drops the slash, came back right.

A fix in the plugin would wrap every path that goes into or comes out of ngp's analyzer, whose API isn't public. That is a design of its own, not a small fix, so it's written up in [#148](https://github.com/push-based/vite-plugin-ngp/issues/148) next to the other way out, a native `win32-x64` engine. Until one of them lands, a Windows user who followed the old message to `engine: 'wasm'` got the engine's error with no hint that the platform was the problem, so the message changed.

**Cost.** A job whose failure doesn't fail the workflow is easy to stop reading. The comment above it in `ci.yml` and the Status page say what it fails on today, and a different failure there is news. It adds a Windows runner after `build` on every CI run: 40 seconds while it stops at `vite build` (CI run 47261854821), more once it gets further. It doesn't hold up the workflow's other work, since `build` has finished by then. Nothing past `vite build` has run on Windows, so the plugin's own Windows bugs, if any, are still unknown.

**Revisit when** either fix in #148 lands. Then drop `continue-on-error`, and switch the job to the native engine if that's the fix.
2 changes: 1 addition & 1 deletion docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Verified in the [playground](../playground): `vite build` and `vite preview`, de
## Where it's weak

- **ngp is a prototype, and the plugin uses it as one.** The plugin types the API by hand and reaches into `HybridCompiler.applyInvalidations`, `analyzer.updateFileContent` and `analyzer.invalidateFiles`, below the public `updateFileContent` that runs the delta. Any Angular commit can break that. The repo holds it still by pinning Angular to exactly `22.3.2`, the latest stable patch ([decision 81](decisions.md#81-pin-the-latest-stable-angular-patch-and-give-angularssr-its-own-version)). The package accepts `>=22.3.0-rc.0 <22.4.0`, measured on the three 22.3 releases that exist, and CI runs the newest release in that range ([decision 72](decisions.md)). A 22.3 patch can still break it between two CI runs.
- **It ships an unofficial ngp.** The npm package carries ngp built from Angular's source by our CI, with native engines for macOS and glibc Linux only ([decision 60](decisions.md#60-ngp-ships-inside-the-plugins-package-with-a-native-engine-for-four-platforms)). Everywhere else needs the slower wasm engine, and moving to another Angular commit means a new plugin release.
- **It ships an unofficial ngp.** The npm package carries ngp built from Angular's source by our CI, with native engines for macOS and glibc Linux only ([decision 60](decisions.md#60-ngp-ships-inside-the-plugins-package-with-a-native-engine-for-four-platforms)). Other Linux needs the slower wasm engine. Windows needs WSL 2, because the wasm engine reads paths by Unix rules and fails on Windows itself (CI's `windows` job, [decision 87](decisions.md#87-run-windows-in-ci-with-the-wasm-engine-non-blocking-and-send-windows-users-to-wsl-2)). Moving to another Angular commit means a new plugin release.
- **The output cache's key is a list someone wrote down.** It hashes the analyzer's whole result for a file, so anything the analyzer knows is covered, but an input ngp reads from somewhere else, such as a file the analyzer doesn't report, would be missed, and a hit on a stale entry is a wrong module with no error. Each known input has a test; `cache: false` is the check for an unknown one.
- **File changes are tested on one small app.** The test app has three components. Nobody has added or deleted a file in a large app, deleted a whole directory, or moved files with a tool that writes them seconds apart. Deleting a component that's still used fails with ngp's "'app-greeting' is not a known element", which names the element but not the missing file; Vite's own "Failed to resolve import" would, but ngp runs first. A missing `styleUrl` file isn't checked at all.
- **SSR runs two analyzers.** The browser and server compilers each hold their own ngp analyzer, so a dev server with SSR needs about twice the analyzer memory, and every edit is analyzed twice. One analyzer serving both would need a way to compile with and without HMR from the same state.
Expand Down
15 changes: 12 additions & 3 deletions packages/vite-plugin-ngp/src/ngp-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,19 @@ export function nativeBindingPath(toolchainDir: string, platform = `${process.pl
if (!musl && existsSync(perPlatform)) return perPlatform;
const host = path.join(toolchainDir, 'engines/native/ng_analyze.node');
if (existsSync(host)) return host;
const missing = `vite-plugin-ngp: ${toolchainDir} has no native ngp engine for ${platform}${musl ? ' (musl)' : ''}. `;
// The wasm engine reads paths by Unix rules, so on Windows it can't find the app's tsconfig.
if (platform.startsWith('win32-')) {
throw new Error(
missing +
`The plugin doesn't run on Windows yet: \`engine: 'wasm'\` fails there too. Run it under ` +
`WSL 2, which gets the Linux engine. https://github.com/push-based/vite-plugin-ngp/issues/148`,
);
}
throw new Error(
`vite-plugin-ngp: ${toolchainDir} has no native ngp engine for ${platform}${musl ? ' (musl)' : ''}. ` +
`Set \`engine: 'wasm'\`, which runs anywhere but analyzes up to twice as slowly, or build ngp ` +
`on this machine with \`pnpm toolchain\` in the vite-plugin-ngp repo.`,
missing +
`Set \`engine: 'wasm'\`, which analyzes up to twice as slowly, or build ngp on this machine ` +
`with \`pnpm toolchain\` in the vite-plugin-ngp repo.`,
);
}

Expand Down
16 changes: 14 additions & 2 deletions packages/vite-plugin-ngp/test/toolchain.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ test('toolchain/out, with only the host engine, still loads', async () => {

test("musl skips the bundled glibc engines, and a platform with none says to use wasm", async () => {
const dir = await layout(['engines/native/linux-x64/ng_analyze.node']);
assert.throws(() => nativeBindingPath(dir, 'linux-x64', true), /no native ngp engine for linux-x64 \(musl\).*engine: 'wasm'/);
assert.throws(() => nativeBindingPath(dir, 'win32-x64', false), /no native ngp engine for win32-x64/);
assert.throws(() => nativeBindingPath(dir, 'linux-x64', true), /no native ngp engine for linux-x64 \(musl\)\. Set `engine: 'wasm'`/);
assert.throws(() => nativeBindingPath(dir, 'freebsd-x64', false), /no native ngp engine for freebsd-x64\. Set `engine: 'wasm'`/);
});

test('windows, which wasm fails on too, is told to use WSL 2 instead', async () => {
const dir = await layout(['engines/native/linux-x64/ng_analyze.node']);
for (const platform of ['win32-x64', 'win32-arm64']) {
assert.throws(() => nativeBindingPath(dir, platform, false), (error) => {
assert.match(error.message, new RegExp(`no native ngp engine for ${platform}\\. The plugin doesn't run on Windows yet`));
assert.match(error.message, /WSL 2/);
assert.doesNotMatch(error.message, /Set `engine: 'wasm'`/);
return true;
});
}
});
Loading
Loading