-
Notifications
You must be signed in to change notification settings - Fork 197
add bun support #1648
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
Merged
add bun support #1648
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
32b8379
Add bun.lock analysis support with JSONC parser
jagonalez 0c19687
Remove workspace-level peerDependencies from bun.lock parser
jagonalez 7476747
Fix alphabetical ordering of Data.Text.Jsonc in spectrometer.cabal
jagonalez 273d4d2
Merge branch 'master' into jg/feat/bun
jagonalez 2074075
Refactor wsPackageNames to use mapMaybe instead of list comprehension
jagonalez e7c7583
Simplify dependency environment inference and add transitive dev dep …
jagonalez 6323f6f
Clarify env inference comment to explain mechanism
jagonalez b0c199d
Use Text IO instead of String IO in BunLockSpec
jagonalez d0c07af
Filter dependency types: only include npm and git packages
jagonalez c726120
Refactor BunLock to use LabeledGrapher for environment merging
jagonalez 61a5ce9
Remove unused lockfileVersion field from BunLockfile
jagonalez be99f59
Revert "Remove unused lockfileVersion field from BunLockfile"
jagonalez 8c46c95
Merge remote-tracking branch 'origin/master' into jg/feat/bun
jagonalez 43cbfe4
Add comment explaining lockfileVersion is kept for debug bundles
jagonalez f52103b
Fix fourmolu formatting in BunLock.hs
jagonalez 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # Bun | ||
|
|
||
| [Bun](https://bun.sh/) is a fast JavaScript runtime and package manager. | ||
| Bun uses a `bun.lock` lockfile in JSONC format (JSON with Comments). | ||
|
|
||
| Reference: https://bun.sh/docs/install/lockfile | ||
|
|
||
| ## Project Discovery | ||
|
|
||
| Find files named `bun.lock` with a corresponding `package.json` file. | ||
|
|
||
| ## Analysis | ||
|
|
||
| Only `bun.lock` is used for analysis. The lockfile is in JSONC format, | ||
| meaning it may contain single-line comments (`//`), block comments (`/* */`), | ||
| and trailing commas. These are stripped before parsing. | ||
|
|
||
| ### Lockfile Structure | ||
|
|
||
| The `bun.lock` file has the following top-level structure: | ||
|
|
||
| ```jsonc | ||
| { | ||
| "lockfileVersion": 1, | ||
| "workspaces": { | ||
| "": { "name": "my-project", "dependencies": {...}, "devDependencies": {...} }, | ||
| "packages/a": { "name": "pkg-a", "dependencies": {...} } | ||
| }, | ||
| "packages": { | ||
| "lodash": ["lodash@4.17.21", "", {}, "sha512-..."], | ||
| "cross-spawn/which": ["which@2.0.2", "", {...}, "sha512-..."] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Workspaces | ||
|
|
||
| Workspace entries are keyed by their relative path from the root, with `""` | ||
| representing the root workspace. Each workspace declares its own | ||
| `dependencies`, `devDependencies`, and `optionalDependencies`. | ||
|
|
||
| ### Packages | ||
|
|
||
| Package keys use a slash-delimited path for nested `node_modules`: | ||
|
|
||
| - `"lodash"` — top-level package | ||
| - `"cross-spawn/which"` — `which` nested under `cross-spawn` | ||
|
|
||
| Package values are variable-length arrays depending on the resolution type: | ||
|
|
||
| - **npm:** `["name@version", "registry", {deps}, "integrity"]` | ||
| - **file:** `["name@file:path", {deps}]` | ||
| - **workspace:** `["name@workspace:path"]` | ||
| - **git:** `["name@git+url", {deps}, "hash", "integrity"]` | ||
|
|
||
| ### Environment Labeling | ||
|
|
||
| - Dependencies declared in `devDependencies` of any workspace are labeled as development dependencies. | ||
| - Dependencies declared in `dependencies` or `optionalDependencies` of any workspace are labeled as production dependencies. | ||
| - Workspace packages themselves (those with `workspace:` resolutions) are excluded from the final dependency graph. | ||
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 |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| # NodeJS Analysis | ||
|
|
||
| The nodejs buildtool ecosystem consists of three major toolchains: the `npm` cli, `pnpm` and `yarn`. | ||
| The nodejs buildtool ecosystem consists of four major toolchains: the `npm` cli, `pnpm`, `yarn`, and `bun`. | ||
|
|
||
| | Strategy | Direct Deps | Transitive Deps | Edges | Container Scanning | | ||
| | ----------------------------- | ------------------ | ------------------ | ------------------ | ------------------ | | ||
| | [yarnlock](yarn.md) | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | ||
| | [npmlock](npm-lockfile.md) | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | ||
| | [pnpmlock](pnpm.md) | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | ||
| | [bunlock](bun.md) | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | | ||
jagonalez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| | [packagejson](packagejson.md) | :white_check_mark: | :x: | :x: | :white_check_mark: | | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| module Data.Text.Jsonc ( | ||
| stripJsonc, | ||
| ) where | ||
|
|
||
| import Data.Functor (($>)) | ||
| import Data.Text (Text) | ||
| import Data.Text qualified as Text | ||
| import Data.Void (Void) | ||
| import Text.Megaparsec ( | ||
| Parsec, | ||
| anySingle, | ||
| eof, | ||
| lookAhead, | ||
| manyTill, | ||
| runParser, | ||
| satisfy, | ||
| takeWhileP, | ||
| try, | ||
| (<|>), | ||
| ) | ||
| import Text.Megaparsec.Char (char, string) | ||
| import Text.Megaparsec.Error (errorBundlePretty) | ||
|
|
||
| type Parser = Parsec Void Text | ||
|
|
||
| -- | Strip JSONC artifacts (single-line comments, block comments, | ||
| -- and trailing commas) from text, producing valid JSON. | ||
| -- | ||
| -- Handles: | ||
| -- | ||
| -- * @\/\/@ single-line comments (to end of line) | ||
| -- * @\/\* ... \*\/@ block comments | ||
| -- * Trailing commas before @}@ or @]@ | ||
| -- | ||
| -- Strings (delimited by @"@) are preserved verbatim, including | ||
| -- any comment-like or comma characters they contain. | ||
| stripJsonc :: Text -> Either String Text | ||
| stripJsonc input = case runParser jsoncParser "jsonc" input of | ||
| Left err -> Left (errorBundlePretty err) | ||
| Right chunks -> Right (Text.concat chunks) | ||
|
|
||
| -- | Parse the entire JSONC input into chunks of valid JSON text. | ||
| jsoncParser :: Parser [Text] | ||
| jsoncParser = manyTill chunk eof | ||
| where | ||
| chunk :: Parser Text | ||
| chunk = | ||
| quotedString | ||
| <|> lineComment | ||
| <|> blockComment | ||
| <|> trailingComma | ||
| <|> plainText | ||
|
|
||
| -- | Parse a JSON string literal, preserving its contents verbatim. | ||
| quotedString :: Parser Text | ||
| quotedString = do | ||
| _ <- char '"' | ||
| contents <- manyTill stringChar (char '"') | ||
| pure $ "\"" <> Text.concat contents <> "\"" | ||
| where | ||
| stringChar :: Parser Text | ||
| stringChar = escapedChar <|> (Text.singleton <$> anySingle) | ||
|
|
||
| escapedChar :: Parser Text | ||
| escapedChar = do | ||
| _ <- char '\\' | ||
| c <- anySingle | ||
| pure $ "\\" <> Text.singleton c | ||
|
|
||
| -- | Parse a @\/\/@ line comment and discard it. | ||
| lineComment :: Parser Text | ||
| lineComment = do | ||
| _ <- try (string "//") | ||
| _ <- takeWhileP Nothing (/= '\n') | ||
| _ <- (char '\n' $> ()) <|> eof | ||
| pure "" | ||
|
|
||
| -- | Parse a @\/\* ... \*\/@ block comment and discard it. | ||
| blockComment :: Parser Text | ||
| blockComment = do | ||
| _ <- try (string "/*") | ||
| _ <- manyTill anySingle (string "*/") | ||
| pure "" | ||
|
|
||
| -- | Parse a trailing comma (comma followed by optional whitespace | ||
| -- then @}@ or @]@) and discard only the comma, preserving whitespace. | ||
| trailingComma :: Parser Text | ||
| trailingComma = do | ||
| _ <- try $ do | ||
| _ <- char ',' | ||
| _ <- lookAhead (takeWhileP Nothing isJsonWhitespace *> satisfy isClosingBracket) | ||
| pure () | ||
| pure "" | ||
| where | ||
| isClosingBracket :: Char -> Bool | ||
| isClosingBracket c = c == '}' || c == ']' | ||
|
|
||
| -- | Parse one or more characters that aren't special | ||
| -- (not a quote, slash, or comma). | ||
| plainText :: Parser Text | ||
| plainText = do | ||
| c <- anySingle | ||
| if c == '/' | ||
| then pure (Text.singleton c) | ||
| else do | ||
| rest <- takeWhileP Nothing (\x -> x /= '"' && x /= '/' && x /= ',') | ||
| pure $ Text.singleton c <> rest | ||
|
|
||
| isJsonWhitespace :: Char -> Bool | ||
| isJsonWhitespace c = c == ' ' || c == '\t' || c == '\n' || c == '\r' |
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
Oops, something went wrong.
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.