Skip to content

Commit d3c476c

Browse files
committed
fix(scripts): extract the packed plugin without a Windows drive path
`packPlugin` handed tar the tarball path and its `-C` destination as the full `C:\…` path. GNU tar reads a colon before the first slash as a remote `host:path`, so on windows-latest every plugin's pack step died with `tar (child): Cannot connect to C: resolve failed` and the plugin lint and the four plugin suites never started there (#3296). The archive now goes in as a bare name resolved against the child's working directory, and the destination is that cwd instead of `-C`, so no tar argument carries a drive path. That also keeps the call portable to the bsdtar Windows ships, which does not know `--force-local`. Docs-not-needed: only scripts/lint-plugins.mjs and its test change; no subsystem page describes how the tarball is extracted.
1 parent 16473c0 commit d3c476c

3 files changed

Lines changed: 43 additions & 7 deletions

File tree

‎.github/scripts/plugin-imports.test.mjs‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
// packed install (`plugin add github:…&path:/plugins/social`) can load (#153).
33
import { test } from 'node:test'
44
import assert from 'node:assert/strict'
5-
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
5+
import { execFileSync } from 'node:child_process'
6+
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
67
import { tmpdir } from 'node:os'
7-
import { dirname, join } from 'node:path'
8+
import { basename, dirname, join, resolve } from 'node:path'
89
import { fileURLToPath } from 'node:url'
9-
import { importPackedPlugin, outboundImports, specifiersOf } from '../../scripts/lint-plugins.mjs'
10+
import { extractPackedTarball, importPackedPlugin, outboundImports, specifiersOf } from '../../scripts/lint-plugins.mjs'
1011

1112
const repo = join(dirname(fileURLToPath(import.meta.url)), '..', '..')
1213
const fake = (files) => {
@@ -62,6 +63,32 @@ test('social, tree, timeline and workflow runtime sources stay inside their pack
6263
assert.deepEqual(outboundImports(join(repo, 'plugins/workflow')), [])
6364
})
6465

66+
test('a packed plugin extracts with the destination as cwd, so tar never receives a drive path (#3296)', () => {
67+
// GNU tar reads the `C:` of `C:\…` as a remote `host:path` and fails with "Cannot connect to C:
68+
// resolve failed" when the archive or `-C` carries a drive path (#3296). A POSIX path only has that
69+
// shape — a colon before the first slash — while it is cwd-relative, so the case builds one instead
70+
// of trusting the platform; on Windows every temp path already has it.
71+
const root = mkdtempSync(join(tmpdir(), 'plugin-pack-3296-'))
72+
const dest = process.platform === 'win32'
73+
? join(root, 'flybot-pack-3296')
74+
: join('C:\\Users\\runneradmin\\AppData\\Local\\Temp', `flybot-pack-${basename(root)}`)
75+
const cwd = process.cwd()
76+
try {
77+
process.chdir(root)
78+
mkdirSync(dest, { recursive: true })
79+
const [info] = JSON.parse(execFileSync('npm', ['pack', '--json', '--ignore-scripts', '--pack-destination', resolve(dest)], {
80+
cwd: join(repo, 'plugins/project'),
81+
encoding: 'utf8',
82+
shell: process.platform === 'win32',
83+
}))
84+
const packed = extractPackedTarball(join(dest, info.filename), dest)
85+
assert.ok(existsSync(join(packed, 'package.json')), 'the packed package.json was extracted')
86+
} finally {
87+
process.chdir(cwd)
88+
rmSync(root, { recursive: true, force: true })
89+
}
90+
})
91+
6592
test('packed @flybot/social, @flybot/tree, @flybot/timeline and @flybot/workflow import', async () => {
6693
const social = await importPackedPlugin(join(repo, 'plugins/social'))
6794
assert.equal(social.name, 'flybot-social')

‎changelog.d/3296.fixed.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`node scripts/lint-plugins.mjs` — and with it `npm run verify` and the windows-latest leg of the compatibility workflow — now runs on Windows: the pack-and-import step handed GNU tar the tarball path and its `-C` destination as the full `C:\…` path, and tar reads the `C:` of a path that has a colon before its first slash as a remote `host:path`, so every plugin's pack step died with `tar (child): Cannot connect to C: resolve failed` and the four plugin suites never started there. The archive now goes in as a bare name resolved against the child's working directory, and the destination is that `cwd` instead of `-C`, so no tar argument carries a drive path — the shape is safe for the bsdtar Windows ships as well, which does not know `--force-local` ([#3296](https://github.com/ThinkFlowLab/FlyBot/issues/3296)).

‎scripts/lint-plugins.mjs‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { execFileSync, spawnSync } from 'node:child_process'
66
import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync } from 'node:fs'
77
import { builtinModules } from 'node:module'
8-
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
8+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
99
import { fileURLToPath, pathToFileURL } from 'node:url'
1010
import { tmpdir } from 'node:os'
1111

@@ -92,15 +92,23 @@ export function outboundImports(pluginDir, pkg = JSON.parse(readFileSync(join(pl
9292
return problems
9393
}
9494

95+
// GNU tar reads `C:\…` — a colon before the first slash — as a remote `host:path` and dies with
96+
// "Cannot connect to C: resolve failed", so neither the archive nor `-C` may carry a drive path (#3296).
97+
// The archive goes in by bare name, resolved against `cwd`, and the destination is that `cwd`; no
98+
// argument then holds a colon, which also keeps this portable to the bsdtar Windows ships (`--force-local`
99+
// would not be).
100+
export function extractPackedTarball(tarball, destDir) {
101+
execFileSync('tar', ['-xzf', basename(tarball)], { cwd: destDir })
102+
return join(destDir, 'package')
103+
}
104+
95105
export function packPlugin(pluginDir, destDir) {
96106
const [info] = JSON.parse(execFileSync('npm', ['pack', '--json', '--ignore-scripts', '--pack-destination', destDir], {
97107
cwd: pluginDir,
98108
encoding: 'utf8',
99109
shell: process.platform === 'win32',
100110
}))
101-
const tgz = join(destDir, info.filename)
102-
execFileSync('tar', ['-xzf', tgz, '-C', destDir])
103-
return join(destDir, 'package')
111+
return extractPackedTarball(join(destDir, info.filename), destDir)
104112
}
105113

106114
export async function importPackedPlugin(pluginDir) {

0 commit comments

Comments
 (0)