diff --git a/web/lib/flow-local.ts b/web/lib/flow-local.ts index b1f6850..0d1a742 100644 --- a/web/lib/flow-local.ts +++ b/web/lib/flow-local.ts @@ -319,8 +319,10 @@ try { // not pass on a node_modules sitting next to the script. Skipping step 2 used // to reach "Preconditions met", then die on npm's "could not determine // executable to run", which names neither the package nor the directory. +// relayflows ships only a CLI (no "main", no "exports"), so the bare name never +// resolves even when it is installed; its package.json always does. try { - createRequire(join(process.cwd(), "package.json")).resolve("relayflows"); + createRequire(join(process.cwd(), "package.json")).resolve("relayflows/package.json"); } catch { fail("relayflows is not installed in this repository.", "npx flows would fail here with: could not determine executable to run", diff --git a/web/lib/test/flow-local.test.ts b/web/lib/test/flow-local.test.ts index 19c980d..11b5f5b 100644 --- a/web/lib/test/flow-local.test.ts +++ b/web/lib/test/flow-local.test.ts @@ -486,8 +486,12 @@ describe('relocating a kit that was extracted outside a repository', () => { if (options.dependency) { const pkg = join(target, 'node_modules', 'relayflows'); mkdirSync(pkg, { recursive: true }); - writeFileSync(join(pkg, 'package.json'), '{ "name": "relayflows", "version": "0.0.0", "main": "index.js" }\n'); - writeFileSync(join(pkg, 'index.js'), 'module.exports = {};\n'); + // The shape relayflows@2.0.15 really publishes: a bin and nothing to + // import. A fake with a "main" let a bare resolve("relayflows") pass here + // while it failed against every real install. + mkdirSync(join(pkg, 'bin'), { recursive: true }); + writeFileSync(join(pkg, 'package.json'), '{ "name": "relayflows", "version": "0.0.0", "type": "module", "bin": { "flows": "./bin/flows.js" } }\n'); + writeFileSync(join(pkg, 'bin', 'flows.js'), '#!/usr/bin/env node\n'); } if (options.ticket) { writeFileSync(join(target, 'flow-input.json'), JSON.stringify({ approver: 'local', @@ -530,7 +534,7 @@ describe('relocating a kit that was extracted outside a repository', () => { expect(code).toBe(0); // Resolved from the repository, not from the kit: node_modules next to the // script says nothing about where npx will look. - expect(localKitFiles(draft)[LOCAL_PREFLIGHT]).toContain('createRequire(join(process.cwd(), "package.json")).resolve("relayflows")'); + expect(localKitFiles(draft)[LOCAL_PREFLIGHT]).toContain('createRequire(join(process.cwd(), "package.json")).resolve("relayflows/package.json")'); }, 30_000); it('offers the move for the throwaway directory only, from one file list', () => {