Add standalone self-host output and align init production scripts#178
Add standalone self-host output and align init production scripts#178sankalpmukim wants to merge 1 commit intocloudflare:mainfrom
Conversation
|
/bigbonk review this PR |
commit: |
There was a problem hiding this comment.
Review: Standalone self-host output
The overall approach is solid — extracting computeLazyChunks to break the circular import, adding standalone output as a post-build step, and the transitive dependency copying are all well-structured. A few issues to address before merge:
Must-fix
server.jsmixes CJS and ESM in an incompatible way — usesrequire()and__dirname(CJS) alongside top-levelawait import()(ESM-ish). This will break if the standalone directory has apackage.jsonwith"type": "module"or if Node runs it as ESM. Needs to be consistently CJS or ESM.HOSTNAMEenv var collides with the system-set hostname — on Linux,HOSTNAMEis set by the OS to the machine's hostname (e.g.ip-172-31-1-42), which would override the default0.0.0.0binding. Next.js standalone usesHOSTNAMEtoo, but that's a known footgun. Consider usingHOSTor documenting theHOSTNAMEpitfall.- Regex objects are shared across files but only reset at the inner loop — the three regexes (
importExportRE, etc.) are created once and reused across all files. ThelastIndex = 0reset on line 89 is correct, but only because the regexes are declared inside the function (not at module scope). This is fine but fragile — a future refactor moving them to module scope would silently break. A comment would help.
Should-fix
- No
package.jsonwritten intostandalone/— without apackage.jsonwith"type": "module", the embeddedvinextpackage (which has"type": "module") may have module resolution issues since Node walks up to find the nearestpackage.json. optionalDependenciesfailures are silently swallowed —copyPackageAndRuntimeDepscatches resolve failures andcontinues. This is correct for optional deps but also silently drops required deps that fail to resolve (e.g. if they useexportsmaps that don't exposepackage.json).- Missing test for symlinked
node_modules—dereference: trueis used incpSync, which is correct, but there's no test covering symlinked packages (common with pnpm).
|
Review posted with "Request Changes". Here's a summary of the key findings: Must-fix issues:
Should-fix issues:
Additional suggestions:
|
|
Working on the suggestions |
Generate dist/standalone from output: 'standalone' with a runnable server entry and runtime deps, and align init scripts with vinext build/start for production self-host workflows.
e64eebc to
17a416e
Compare
|
Implemented the requested updates and rebased on latest upstream main (commit Addressed must-fix items:
Addressed key should-fix items:
Validation run:
|
|
@southpolesteve gentle nudge... |
Summary
output: \"standalone\"support invinext buildthat emitsdist/standalonewith a runnableserver.js, built artifacts, and copied runtime dependencies for self-hosted VPS deploymentsnext.configloading for build mode, and extractcomputeLazyChunksinto a shared utility so the production server no longer imports the full plugin modulevinext initto adddev:vinext,build:vinext, andstart:vinextscripts using the vinext CLI, plus docs/check metadata and new unit coverageTesting
corepack pnpm vitest run tests/init.test.ts tests/standalone-build.test.tscorepack pnpm exec oxlint packages/vinext/src/build/standalone.ts packages/vinext/src/cli.ts packages/vinext/src/init.ts packages/vinext/src/utils/lazy-chunks.ts tests/standalone-build.test.ts tests/init.test.ts packages/vinext/src/config/next-config.ts packages/vinext/src/server/prod-server.ts packages/vinext/src/index.ts packages/vinext/src/check.tscorepack pnpm --filter vinext run build