Browse Source
* allow to automatically enable corepack * update command docs * add changeset * fix clippy * don't show the value of corepack * fix test * test against more shells * Make exec handle errors more nicely * nicer i think * set corepack as debug * fix windows-style paths in Bash #390 * fix clippy * run cygpath on `use` validation too * trim whitespace * fix test? * fix test * add changesetremotes/origin/list-filter
Gal Schlezinger
2 years ago
committed by
GitHub
21 changed files with 331 additions and 12 deletions
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
--- |
||||
"fnm": minor |
||||
--- |
||||
|
||||
Add --corepack-enabled flag for automatically enabling corepack on fnm install |
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
--- |
||||
"fnm": patch |
||||
--- |
||||
|
||||
use cygwinpath to make the path posix-like on Windows Bash usage |
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP |
||||
|
||||
exports[`Bash installs corepack: Bash 1`] = ` |
||||
"set -e |
||||
eval "$(fnm env --corepack-enabled)" |
||||
fnm install 18 |
||||
fnm exec --using=18 node test-pnpm-corepack.js" |
||||
`; |
||||
|
||||
exports[`Fish installs corepack: Fish 1`] = ` |
||||
"fnm env --corepack-enabled | source |
||||
fnm install 18 |
||||
fnm exec --using=18 node test-pnpm-corepack.js" |
||||
`; |
||||
|
||||
exports[`PowerShell installs corepack: PowerShell 1`] = ` |
||||
"$ErrorActionPreference = "Stop" |
||||
fnm env --corepack-enabled | Out-String | Invoke-Expression |
||||
fnm install 18 |
||||
fnm exec --using=18 node test-pnpm-corepack.js" |
||||
`; |
||||
|
||||
exports[`Zsh installs corepack: Zsh 1`] = ` |
||||
"set -e |
||||
eval "$(fnm env --corepack-enabled)" |
||||
fnm install 18 |
||||
fnm exec --using=18 node test-pnpm-corepack.js" |
||||
`; |
@ -0,0 +1,54 @@
@@ -0,0 +1,54 @@
|
||||
import fs from "fs" |
||||
import { script } from "./shellcode/script.js" |
||||
import { Bash, Fish, PowerShell, Zsh } from "./shellcode/shells.js" |
||||
import describe from "./describe.js" |
||||
import path from "path" |
||||
import testCwd from "./shellcode/test-cwd.js" |
||||
import { createRequire } from "module" |
||||
|
||||
const require = createRequire(import.meta.url) |
||||
const whichPath = require.resolve("which") |
||||
|
||||
const nodescript = ` |
||||
const which = require(${JSON.stringify(whichPath)}); |
||||
const pnpmBinary = which.sync('pnpm') |
||||
const nodeBinary = which.sync('node') |
||||
|
||||
const binPath = require('path').dirname(nodeBinary); |
||||
|
||||
if (!pnpmBinary.includes(binPath)) { |
||||
console.log('pnpm not found in current Node.js bin', { binPath, pnpmBinary }); |
||||
process.exit(1); |
||||
} |
||||
const scriptContents = require('fs').readFileSync(pnpmBinary, 'utf8'); |
||||
console.log('scriptContents', scriptContents) |
||||
if (!scriptContents.includes('corepack')) { |
||||
console.log('corepack not found in pnpm script'); |
||||
process.exit(1); |
||||
} |
||||
` |
||||
|
||||
for (const shell of [Bash, Fish, PowerShell, Zsh]) { |
||||
describe(shell, () => { |
||||
test(`installs corepack`, async () => { |
||||
const cwd = testCwd() |
||||
const filepath = path.join(cwd, "test-pnpm-corepack.js") |
||||
fs.writeFileSync(filepath, nodescript) |
||||
|
||||
await script(shell) |
||||
.then(shell.env({ corepackEnabled: true })) |
||||
.then(shell.call("fnm", ["install", "18"])) |
||||
.then( |
||||
shell.call("fnm", [ |
||||
"exec", |
||||
"--using=18", |
||||
"node", |
||||
"test-pnpm-corepack.js", |
||||
]) |
||||
) |
||||
.takeSnapshot(shell) |
||||
// .addExtraEnvVar("RUST_LOG", "fnm=debug")
|
||||
.execute(shell) |
||||
}) |
||||
}) |
||||
} |
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
/// On Bash for Windows, we need to convert the path from a Windows-style
|
||||
/// path to a Unix-style path. This is because Bash for Windows doesn't
|
||||
/// understand Windows-style paths. We use `cygpath` to do this conversion.
|
||||
/// If `cygpath` fails, we assume we're not on Bash for Windows and just
|
||||
/// return the original path.
|
||||
pub fn maybe_fix_windows_path(path: &str) -> Option<String> { |
||||
if !cfg!(windows) { |
||||
return None; |
||||
} |
||||
|
||||
let output = std::process::Command::new("cygpath") |
||||
.arg(path) |
||||
.output() |
||||
.ok()?; |
||||
if output.status.success() { |
||||
let output = String::from_utf8(output.stdout).ok()?; |
||||
Some(output.trim().to_string()) |
||||
} else { |
||||
None |
||||
} |
||||
} |
Loading…
Reference in new issue