Skip to content

Commit 9e69263

Browse files
committed
Repack GitHub tarballs to preserve test files
After extracting and modifying package.json, create a new tarball that includes all files. This ensures pnpm includes test files when installing, as pnpm respects the files field even with file:// URLs.
1 parent 00584a1 commit 9e69263

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

scripts/install-npm-packages.mjs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,9 @@ async function installPackage(packageInfo) {
582582
// 1. Download and extract the GitHub tarball ourselves (with validation to catch HTTP errors)
583583
// 2. Wait for filesystem to flush, then verify the downloaded tarball and extracted package.json are not empty
584584
// 3. Retry reading package.json up to 3 times with exponential backoff to handle filesystem delays on slow CI
585-
// 4. Remove the "files" field from package.json
586-
// 5. Point pnpm to our modified local directory instead of the GitHub URL
585+
// 4. Remove the "files" field from package.json and .npmignore to preserve test files
586+
// 5. Repack into a new tarball (ensures pnpm includes all files regardless of files field)
587+
// 6. Point pnpm to our repacked tarball instead of the GitHub URL
587588
// If extraction fails (HTTP error, empty files, or JSON parse error after retries), fall back to GitHub URL.
588589
let packageSpec = versionSpec
589590

@@ -688,8 +689,23 @@ async function installPackage(packageInfo) {
688689
})
689690
await editablePkgJson.save()
690691

691-
// Use file:// URL to point pnpm to our modified local directory.
692-
packageSpec = pathToFileURL(extractedPath).href
692+
// Remove .npmignore if it exists, as it can also filter out test files.
693+
const npmignorePath = path.join(extractedPath, '.npmignore')
694+
try {
695+
await fs.unlink(npmignorePath)
696+
} catch {
697+
// File doesn't exist, ignore.
698+
}
699+
700+
// Create a new tarball with all files included (no files field filtering).
701+
// This ensures test files are preserved when pnpm installs the package.
702+
const repackedTarball = path.join(tempExtractDir, 'repacked.tgz')
703+
await runCommand('tar', ['-czf', 'repacked.tgz', extractedDir.name], {
704+
cwd: tempExtractDir,
705+
})
706+
707+
// Use file:// URL to point pnpm to our repacked tarball.
708+
packageSpec = pathToFileURL(repackedTarball).href
693709
modifiedPackagePath = tempExtractDir
694710
}
695711
} catch (e) {

0 commit comments

Comments
 (0)