diff --git a/package.json b/package.json index 7d7e819..1b28bdb 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ }, "scripts": { "audit:workflow-permissions": "node scripts/audit-workflow-permissions.mjs", - "build": "tsc -p tsconfig.build.json", + "build": "tsc -p tsconfig.build.json && node -e \"require('node:fs').chmodSync('dist/cli.js', 0o755)\"", "typecheck": "tsc -p tsconfig.json --noEmit", "lint": "eslint .", "format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\" \"eslint.config.js\" \"vitest.config.ts\" \"package.json\" \"tsconfig*.json\" \".prettierrc\"", diff --git a/scripts/e2e-smoke.mjs b/scripts/e2e-smoke.mjs index fb47371..356ae04 100644 --- a/scripts/e2e-smoke.mjs +++ b/scripts/e2e-smoke.mjs @@ -8,6 +8,7 @@ import { mkdtempSync, readFileSync, rmSync, + statSync, writeFileSync, } from 'node:fs'; import { tmpdir } from 'node:os'; @@ -24,7 +25,7 @@ function runCli(args, cwd, env = process.env) { env, encoding: 'utf8', shell: false, - timeout: 30_000, + timeout: 60_000, }); } @@ -41,6 +42,12 @@ function expectSuccessful(result, label) { const root = mkdtempSync(join(tmpdir(), 'stellarforge-e2e-')); try { + assert.match( + readFileSync(cliPath, 'utf8'), + /^#!\/usr\/bin\/env node\r?\n/, + 'built CLI must start with the Node shebang', + ); + const help = runCli(['--help'], root); expectSuccessful(help, 'help'); assert.match(help.stdout, /Usage: stellarforge \[options\] \[command\]/); @@ -217,10 +224,17 @@ try { const [packEntry] = JSON.parse(packInspect.stdout); assert.ok(packEntry, 'pack dry-run returned no entry'); const packedFiles = packEntry.files.map((file) => file.path); + const packedCli = packEntry.files.find((file) => file.path === 'dist/cli.js'); assert.ok( - packedFiles.some((path) => path.startsWith('dist/cli.js')), + packedCli, 'tarball must contain dist/cli.js', ); + if (process.platform !== 'win32') { + assert.ok( + packedCli.mode & 0o111, + 'packed dist/cli.js must be executable on POSIX', + ); + } assert.ok( packedFiles.some((path) => path.startsWith('templates/basic-app/')), 'tarball must contain templates/basic-app/', @@ -293,6 +307,20 @@ try { '@diginodes', 'stellarforge-cli', ); + const installedPackageJson = JSON.parse( + readFileSync(join(installedPackage, 'package.json'), 'utf8'), + ); + assert.equal( + installedPackageJson.bin?.stellarforge, + 'dist/cli.js', + 'packed package bin must point to dist/cli.js', + ); + if (process.platform !== 'win32') { + assert.ok( + statSync(join(installedPackage, 'dist', 'cli.js')).mode & 0o111, + 'installed dist/cli.js must be executable on POSIX', + ); + } assert.equal( existsSync(join(installedPackage, 'dist', 'cli.js')), true, @@ -367,5 +395,16 @@ try { 'StellarForge packed tarball consumer smoke test passed.\n', ); } finally { - rmSync(root, { recursive: true, force: true }); + try { + rmSync(root, { + recursive: true, + force: true, + maxRetries: 5, + retryDelay: 100, + }); + } catch (error) { + process.stderr.write( + `Warning: could not remove smoke temp directory ${root}: ${error.message}\n`, + ); + } }