Files

35 lines
1.7 KiB
TypeScript

import { existsSync, readFileSync } from 'node:fs'
import { describe, expect, it } from 'vitest'
// The platform builder installs a Next.js project with `npm install` on node:22,
// whose npm 10 arborist crashes resolving vitest's optional peer set:
// "npm error Cannot read properties of null (reading 'edgesOut')" in
// #loadPeerSet (build.conusai.com, 2026-10-18: every Showcase deploy failed in
// build_image; reproduced on node:22 / npm 10.9.9 with this package.json, vitest
// 4.1.12 and 5.x alike, and an explicit vite alone does not avoid it). The
// project .npmrc turns the peer auto-install off (the preset copies `.npmrc*`
// next to package.json for the install step), so vitest's own peer, vite, is
// declared here instead.
describe('npm install on the platform builder', () => {
const npmrcUrl = new URL('../.npmrc', import.meta.url)
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'))
it('ships an .npmrc that keeps npm 10 out of the optional-peer crash', () => {
expect(existsSync(npmrcUrl)).toBe(true)
const npmrc = readFileSync(npmrcUrl, 'utf8')
expect(npmrc).toMatch(/^legacy-peer-deps=true$/m)
})
it('carries no registry or credential in that .npmrc', () => {
// Registry mappings and tokens reach the build as the npmrc secret, never
// the repository (crates/conusai-presets/src/nextjs.rs).
const npmrc = existsSync(npmrcUrl) ? readFileSync(npmrcUrl, 'utf8') : ''
expect(npmrc).not.toMatch(/registry|_authToken|_auth|token/i)
})
it('declares vitest\'s vite peer itself, since npm no longer installs peers', () => {
expect(pkg.devDependencies.vitest).toBeDefined()
expect(pkg.devDependencies.vite).toMatch(/^\d+\.\d+\.\d+$/)
})
})