also looking at this
fix(release): build and verify all npm package artifacts
#289
11 files
+290
-3
| @@ -0,0 +1,42 @@ | ||
| 1 | import { expect, test } from 'bun:test' | |
| 2 | import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs' | |
| 3 | import { tmpdir } from 'node:os' | |
| 4 | import { join, resolve } from 'node:path' | |
| 5 | ||
| 6 | const root = resolve(import.meta.dir, '..') | |
| 7 | ||
| 8 | for (const platform of ['android', 'ios']) { | |
| 9 | test(`${platform} tarball exposes usable standalone declarations`, () => { | |
| 10 | const temp = mkdtempSync(join(tmpdir(), `craft-${platform}-package-`)) | |
| 11 | const packageDir = join(root, 'packages', platform) | |
| 12 | const run = (args: string[], cwd = temp): void => { | |
| 13 | const result = Bun.spawnSync(args, { cwd, stdout: 'pipe', stderr: 'pipe' }) | |
| 14 | expect(`${result.stdout}\n${result.stderr}`).not.toContain('error TS') | |
| 15 | expect(result.exitCode).toBe(0) | |
| 16 | } | |
| 17 | ||
| 18 | try { | |
| 19 | run([process.execPath, 'run', 'build'], packageDir) | |
| 20 | run([process.execPath, 'pm', 'pack', '--filename', join(temp, 'package.tgz')], packageDir) | |
| 21 | const installed = join(temp, 'node_modules', '@craft-native', platform) | |
| 22 | mkdirSync(installed, { recursive: true }) | |
| 23 | run(['tar', '-xzf', join(temp, 'package.tgz'), '--strip-components=1', '-C', installed]) | |
| 24 | writeFileSync(join(temp, 'consumer.mts'), ` | |
| 25 | import { init, type InitOptions } from '@craft-native/${platform}' | |
| 26 | const options: InitOptions = { name: 'Consumer', output: '/tmp/consumer', runtimeDir: null } | |
| 27 | const result: Promise<void> = init(options) | |
| 28 | // @ts-expect-error name must be a string, even outside the workspace | |
| 29 | init({ name: 42, output: '/tmp/consumer' }) | |
| 30 | void result | |
| 31 | `) | |
| 32 | run([ | |
| 33 | process.execPath, join(root, 'packages/typescript/scripts/tsc.ts'), | |
| 34 | 'consumer.mts', '--noEmit', '--strict', '--module', 'nodenext', | |
| 35 | '--moduleResolution', 'nodenext', '--target', 'esnext', '--ignoreConfig', | |
| 36 | ]) | |
| 37 | } | |
| 38 | finally { | |
| 39 | rmSync(temp, { recursive: true, force: true }) | |
| 40 | } | |
| 41 | }, 60_000) | |
| 42 | } | |