-
Notifications
You must be signed in to change notification settings - Fork 5.1k
install: keep a bundled file: dependency bundled when installing from bun.lock #42884
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
Merged
Jarred-Sumner
merged 3 commits into
main
from
robobun/13c4c301/bundled-file-dep-lockfile
Sep 17, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+379 Bytes
test/cli/install/registry/packages/bundled-file/bundled-file-1.0.0.tgz
Binary file not shown.
Binary file added
BIN
+365 Bytes
test/cli/install/registry/packages/bundled-file/bundled-file-2.0.0.tgz
Binary file not shown.
38 changes: 38 additions & 0 deletions
38
test/cli/install/registry/packages/bundled-file/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| { | ||
| "_id": "bundled-file", | ||
| "name": "bundled-file", | ||
| "dist-tags": { | ||
| "latest": "2.0.0" | ||
| }, | ||
| "versions": { | ||
| "1.0.0": { | ||
| "name": "bundled-file", | ||
| "version": "1.0.0", | ||
| "dependencies": { | ||
| "bundled-file-dep": "file:vendor/bundled-file-dep" | ||
| }, | ||
| "bundleDependencies": [ | ||
| "bundled-file-dep" | ||
| ], | ||
| "_id": "bundled-file@1.0.0", | ||
| "dist": { | ||
| "integrity": "sha512-1kQd7SfufR6wmrYo6L8J2jZm34WCaJyJj7KoskI+P3S+PuYpZ01rpuH+N15mtjUBcoVkVorPBxaOcSrX0H7ytg==", | ||
| "shasum": "7e59fee2055f735ed039b470f15d95c3612e99b9", | ||
| "tarball": "http://localhost:4873/bundled-file/-/bundled-file-1.0.0.tgz" | ||
| } | ||
| }, | ||
| "2.0.0": { | ||
| "name": "bundled-file", | ||
| "version": "2.0.0", | ||
| "dependencies": { | ||
| "bundled-file-dep": "file:vendor/bundled-file-dep" | ||
| }, | ||
| "_id": "bundled-file@2.0.0", | ||
| "dist": { | ||
| "integrity": "sha512-tFSzHwAOxEKDbBAHK/MY8RQEQ1KdQu6+bJYnW8/lZybGuZG2MoYWvksteDGjsWyXBimCSz7XWjo/ENEU9tsDNg==", | ||
| "shasum": "cd4c6b205128b53321bad299e60d7c6afb1f6c0e", | ||
| "tarball": "http://localhost:4873/bundled-file/-/bundled-file-2.0.0.tgz" | ||
| } | ||
| } | ||
| } | ||
| } |
75 changes: 75 additions & 0 deletions
75
test/cli/install/registry/packages/create-bundled-file-packages.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| #!/usr/bin/env bun | ||
| /** | ||
| * Generates the `bundled-file` fixture used by bun-install-registry.test.ts. | ||
| * | ||
| * Both versions depend on `bundled-file-dep` through a `file:` spec | ||
| * (`file:vendor/bundled-file-dep`) and ship both `vendor/bundled-file-dep/` | ||
| * and a copy under `node_modules/bundled-file-dep/`, the way `npm pack` does | ||
| * for a bundled `file:` dependency. | ||
| * | ||
| * - bundled-file@1.0.0 lists the dependency in `bundleDependencies`. A `file:` | ||
| * resolution has its `bundled: true` marker at a different index in bun.lock | ||
| * than an npm resolution, so an install from the lockfile must still treat | ||
| * the dependency as bundled. | ||
| * - bundled-file@2.0.0 does not bundle it. The install has to link the | ||
| * `file:` dependency over the files the tarball already put in place. | ||
| */ | ||
|
|
||
| import { mkdir, writeFile } from "fs/promises"; | ||
| import { join } from "path"; | ||
|
|
||
| const packagesDir = import.meta.dir; | ||
|
|
||
| const name = "bundled-file"; | ||
| const depName = "bundled-file-dep"; | ||
|
|
||
| const dir = join(packagesDir, name); | ||
| await mkdir(dir, { recursive: true }); | ||
|
|
||
| const depPkgJson = JSON.stringify({ name: depName, version: "1.0.0", main: "index.js" }, null, 2); | ||
| const depIndex = `module.exports = "${depName}";\n`; | ||
|
|
||
| const versions: Record<string, object> = {}; | ||
| let latest = ""; | ||
| for (const [version, bundled] of [ | ||
| ["1.0.0", true], | ||
| ["2.0.0", false], | ||
| ] as const) { | ||
| const pkgJson = { | ||
| name, | ||
| version, | ||
| dependencies: { [depName]: `file:vendor/${depName}` }, | ||
| ...(bundled ? { bundleDependencies: [depName] } : {}), | ||
| }; | ||
|
|
||
| const files: Record<string, string> = { | ||
| "package/package.json": JSON.stringify(pkgJson, null, 2), | ||
| "package/index.js": `module.exports = require("${depName}");\n`, | ||
| [`package/vendor/${depName}/package.json`]: depPkgJson, | ||
| [`package/vendor/${depName}/index.js`]: depIndex, | ||
| [`package/node_modules/${depName}/package.json`]: depPkgJson, | ||
| [`package/node_modules/${depName}/index.js`]: depIndex, | ||
| }; | ||
|
|
||
| const tarball = join(dir, `${name}-${version}.tgz`); | ||
| await Bun.Archive.write(tarball, files, { compress: "gzip" }); | ||
|
|
||
| const bytes = await Bun.file(tarball).bytes(); | ||
| versions[version] = { | ||
| ...pkgJson, | ||
| _id: `${name}@${version}`, | ||
| dist: { | ||
| integrity: `sha512-${Buffer.from(new Bun.CryptoHasher("sha512").update(bytes).digest()).toString("base64")}`, | ||
| shasum: new Bun.CryptoHasher("sha1").update(bytes).digest("hex"), | ||
| tarball: `http://localhost:4873/${name}/-/${name}-${version}.tgz`, | ||
| }, | ||
| }; | ||
| latest = version; | ||
| } | ||
|
|
||
| await writeFile( | ||
| join(dir, "package.json"), | ||
| JSON.stringify({ _id: name, name, "dist-tags": { latest }, versions }, null, 2), | ||
| ); | ||
|
|
||
| console.log("Created bundled-file test packages"); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.