Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion web/lib/flow-local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions web/lib/test/flow-local.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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', () => {
Expand Down
Loading