ReviewOS

also looking at this

craft-native/craft

fix(release): build and verify all npm package artifacts

#289
Merged glennmichael123 wants to merge codex/npm-release-artifacts into main
11 files +290 -3
scripts/npm-packages.test.tsadded+33-0
Changes to scripts/npm-packages.test.ts
@@ -0,0 +1,33 @@
1import { expect, test } from 'bun:test'
2import { manifestTargets, verifyArchiveTargets } from './npm-packages'
3
4test('rejects absent built entries even when the manifest advertises them', () => {
5 const pkg = { name: '@craft-native/react', main: 'dist/index.js', exports: { '.': { import: './dist/index.mjs', types: './dist/index.d.ts' } } }
6 expect(() => verifyArchiveTargets(pkg, ['package/package.json', 'package/README.md']))
7 .toThrow('packed artifact is missing dist/index.js')
8})
9
10test('checks each export condition, legacy field and string or named bin', () => {
11 const pkg = {
12 name: 'fixture', main: 'dist/index.cjs', module: 'dist/index.js', types: 'dist/index.d.ts', svelte: 'src/index.ts',
13 bin: { fixture: './dist/cli.js' },
14 exports: { '.': { types: './dist/index.d.ts', import: './dist/index.js', require: './dist/index.cjs', svelte: './src/index.ts' }, './mobile': './dist/mobile.js' },
15 }
16 const targets = manifestTargets(pkg)
17 expect(targets).toHaveLength(6)
18 const entries = targets.map(target => `package/${target}`)
19 expect(() => verifyArchiveTargets(pkg, entries)).not.toThrow()
20 for (const missing of entries)
21 expect(() => verifyArchiveTargets(pkg, entries.filter(entry => entry !== missing))).toThrow('packed artifact is missing')
22 expect(manifestTargets({ name: 'cli', bin: './bin/cli.ts' })).toEqual(['bin/cli.ts'])
23})
24
25test('a directory with the target name does not count as a file', () => {
26 expect(() => verifyArchiveTargets({ name: 'fixture', types: './dist/index.d.ts' }, ['package/dist/index.d.ts/']))
27 .toThrow('packed artifact is missing')
28})
29
30test('fails closed for targets that escape the package or need wildcard handling', () => {
31 for (const target of ['../outside.js', '/outside.js', './dist/../outside.js', '.\\outside.js', './dist/*.js'])
32 expect(() => manifestTargets({ name: 'fixture', exports: target })).toThrow()
33})