GeezerVison is showing github.com — fix(cli): npx no longer skips the install offer for a directory or no… · pingdotgg/t3code@1df56f6
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/cli/install.test.ts +16-1Lines changed: 16 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -212,17 +212,32 @@ it.layer(NodeServices.layer)("t3 install", (it) => { | 212 | 212 | const globalBin = path.join(root, "global-bin"); | 213 | 213 | yield* fs.makeDirectory(globalBin); | 214 | 214 | yield* fs.writeFileString(path.join(globalBin, "t3"), ""); | | 215 | + yield* fs.chmod(path.join(globalBin, "t3"), 0o755); | 215 | 216 | yield* offer(false, { env: { PATH: globalBin } }); | 216 | 217 | assert.equal(asked, 0); | 217 | 218 | assert.isFalse(yield* fs.exists(link)); | 218 | 219 |
| 219 | | - // A runner's own .bin on PATH is not an installed t3. | | 220 | + // A directory or non-executable file named `t3` on PATH is not an installed t3. | | 221 | + const dirBin = path.join(root, "dir-bin"); | | 222 | + yield* fs.makeDirectory(path.join(dirBin, "t3"), { recursive: true }); | | 223 | + const nonExecBin = path.join(root, "non-exec-bin"); | | 224 | + yield* fs.makeDirectory(nonExecBin); | | 225 | + yield* fs.writeFileString(path.join(nonExecBin, "t3"), ""); | | 226 | + assert.isFalse(yield* offer(undefined, { env: { PATH: dirBin } })); | | 227 | + assert.equal(asked, 1); | | 228 | + assert.isFalse(yield* offer(undefined, { env: { PATH: nonExecBin } })); | | 229 | + assert.equal(asked, 2); | | 230 | + asked = 0; | | 231 | + | | 232 | + // A runner's own .bin on PATH, even found through a bare launcher record, is not an installed t3. | 220 | 233 | const npxBin = path.join(npmPackage, "../.bin"); | 221 | 234 | const pnpmBin = path.join(root, ".cache/pnpm/dlx/abc/node_modules/.bin"); | 222 | 235 | for (const bin of [npxBin, pnpmBin]) { | 223 | 236 | yield* fs.makeDirectory(bin, { recursive: true }); | 224 | 237 | yield* fs.writeFileString(path.join(bin, "t3"), ""); | | 238 | + yield* fs.chmod(path.join(bin, "t3"), 0o755); | 225 | 239 | } | | 240 | + yield* fs.writeFileString(path.join(runtimeDir, "launchers"), "t3\n"); | 226 | 241 | assert.isFalse(yield* offer(undefined, { env: { PATH: `${npxBin}:${pnpmBin}` } })); | 227 | 242 | assert.equal(asked, 1); | 228 | 243 | assert.isFalse(yield* fs.exists(path.join(runtimeDir, "install-prompt-declined"))); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/cli/install.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -322,7 +322,7 @@ export const offerCliInstall = Effect.fn("cli.install.offer")(function* <E, R, E | 322 | 322 | .readFileString(path.join(runtimeDir, "launchers")) | 323 | 323 | .pipe(Effect.orElseSucceed(() => "")); | 324 | 324 | const candidates = [ | 325 | | - ...launchers.split(/\r?\n/).filter(Boolean), | | 325 | + ...launchers.split(/\r?\n/).filter((launcher) => path.isAbsolute(launcher)), | 326 | 326 | path.join(path.dirname(runtimeDir), "bin", windows ? "t3.cmd" : "t3"), | 327 | 327 | ...(environment.PATH ?? environment.Path ?? "") | 328 | 328 | .split(windows ? ";" : ":") | @@ -332,7 +332,7 @@ export const offerCliInstall = Effect.fn("cli.install.offer")(function* <E, R, E | 332 | 332 | .flatMap((directory) => names.map((name) => path.join(directory, name))), | 333 | 333 | ]; | 334 | 334 | for (const candidate of candidates) { | 335 | | - if (yield* fs.exists(candidate).pipe(Effect.orElseSucceed(() => false))) return true; | | 335 | + if (yield* resolveCommandPath(candidate, { env: environment })) return true; | 336 | 336 | } | 337 | 337 |
| 338 | 338 | const declinedFile = path.join(runtimeDir, "install-prompt-declined"); | |
|