Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: automatic file: protocol handling #167

Merged
merged 9 commits into from
Dec 6, 2022
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
with:
node-version: 18
- run: corepack enable
- run: pnpm --version
- uses: actions/setup-node@v3
with:
node-version: 18
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ecosystem-ci-from-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ jobs:
deno-version: v1.x
continue-on-error: true
- run: corepack enable
- run: pnpm --version
- run: pnpm i --frozen-lockfile
- run: >-
pnpm tsx ecosystem-ci.ts
Expand Down Expand Up @@ -137,6 +138,7 @@ jobs:
deno-version: v1.x
continue-on-error: true
- run: corepack enable
- run: pnpm --version
- run: pnpm i --frozen-lockfile
- run: >-
pnpm tsx ecosystem-ci.ts
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ecosystem-ci-selected.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ jobs:
id: setup-deno
continue-on-error: true
- run: corepack enable
- run: pnpm --version
- run: pnpm i --frozen-lockfile
- run: >-
pnpm tsx ecosystem-ci.ts
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ecosystem-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:
id: setup-deno
continue-on-error: true
- run: corepack enable
- run: pnpm --version
- run: pnpm i --frozen-lockfile
- run: >-
pnpm tsx ecosystem-ci.ts
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
"eslint"
]
},
"packageManager": "pnpm@7.17.1",
"packageManager": "pnpm@7.18.1",
"type": "module",
"engines": {
"node": ">=18",
"pnpm": "^7.17.1"
"pnpm": "^7.18.1"
},
"repository": {
"type": "git",
Expand Down
33 changes: 30 additions & 3 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,19 +339,33 @@ export async function bisectVite(
}
}

function isLocalOverride(v: string): boolean {
if (!v.includes('/') || v.startsWith('@')) {
// not path-like (either a version number or a package name)
return false
}
try {
return !!fs.lstatSync(v)?.isDirectory()
} catch (e) {
if (e.code !== 'ENOENT') {
throw e
}
return false
}
}
export async function applyPackageOverrides(
dir: string,
pkg: any,
overrides: Overrides = {},
) {
const prependFileProtocol = (v: string) =>
fs.existsSync(v) ? `file:${v}` : v
const useFileProtocol = (v: string) =>
isLocalOverride(v) ? `file:${path.resolve(v)}` : v
// remove boolean flags
overrides = Object.fromEntries(
Object.entries(overrides)
//eslint-disable-next-line @typescript-eslint/no-unused-vars
.filter(([key, value]) => typeof value === 'string')
.map(([key, value]) => [key, prependFileProtocol(value as string)]),
.map(([key, value]) => [key, useFileProtocol(value as string)]),
)
await $`git clean -fdxq` // remove current install

Expand All @@ -363,6 +377,19 @@ export async function applyPackageOverrides(
const pm = agent?.split('@')[0]

if (pm === 'pnpm') {
const version = await $`pnpm --version`
// avoid bug with absolute overrides in pnpm 7.18.0
if (version === '7.18.0') {
console.warn(
'detected pnpm@7.18.0, changing pkg.packageManager and pkg.engines.pnpm to enforce use of pnpm@7.18.1',
)
// corepack reads this and uses pnpm 7.18.1 then
pkg.packageManager = 'pnpm@7.18.1'
if (!pkg.engines) {
pkg.engines = {}
}
pkg.engines.pnpm = '7.18.1'
}
if (!pkg.devDependencies) {
pkg.devDependencies = {}
}
Expand Down