-
Notifications
You must be signed in to change notification settings - Fork 205
Pnpm: scope analysis to individual workspace members (ANE-3125) #1763
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
Draft
spatten
wants to merge
10
commits into
master
Choose a base branch
from
ane-3125-pnpm-workspace-targets
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
408bfb7
Pnpm: scope analysis to individual workspace members (ANE-3125)
spatten 6c0ebac
Document the target filter field in the .fossa.yml schema
spatten 3e3c78e
Fill in the changelog PR links and close the docs gaps around build t…
spatten 52a8772
Keep an unnamed workspace root's dependencies in yarn and npm v1 anal…
spatten 3e85476
Require a named workspace root for build targets, and say so
spatten 3bedca2
Document the root-name requirement, the warning, and the list-targets…
spatten f4ea10f
Log the unnamed-root warning instead of raising it as a diagnostic
spatten d99a34f
Test link-following edge cases and the package.json workspace-referen…
spatten 4d8d2c2
Move the package.json fallback fix and the target-field docs to their…
spatten adb36f8
Bind the scoped selection once and warn with `when`
spatten 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
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,105 @@ | ||
| {-# LANGUAGE TemplateHaskell #-} | ||
|
|
||
| -- | End-to-end coverage for target-level dependency scoping of pnpm workspaces: | ||
| -- discovery over a vendored workspace fixture, then analysis per selected build | ||
| -- target. | ||
| module Analysis.PnpmWorkspaceSpec (spec) where | ||
|
|
||
| import Analysis.FixtureUtils (FixtureEnvironment (LocalEnvironment), testRunner, withResult) | ||
| import App.Fossa.Analyze.Types (AnalyzeProject (analyzeProject)) | ||
| import App.Types (Mode (NonStrict)) | ||
| import Control.Carrier.Debug (ignoreDebug) | ||
| import Control.Carrier.Reader (runReader) | ||
| import Data.Set (Set) | ||
| import Data.Set qualified as Set | ||
| import Data.Set.NonEmpty qualified as NonEmptySet | ||
| import Data.Text (Text) | ||
| import DepTypes (Dependency (dependencyName)) | ||
| import Graphing (Graphing) | ||
| import Graphing qualified | ||
| import Path (Dir, Path, Rel, mkRelDir, (</>)) | ||
| import Path.IO qualified as PIO | ||
| import Test.Hspec (Spec, beforeAll, describe, it, shouldBe, shouldSatisfy) | ||
| import Types ( | ||
| BuildTarget (BuildTarget), | ||
| DependencyResults (dependencyGraph), | ||
| DiscoveredProject (projectBuildTargets, projectData, projectType), | ||
| DiscoveredProjectType (PnpmProjectType), | ||
| FoundTargets (FoundTargets, ProjectWithoutTargets), | ||
| ) | ||
|
|
||
| import Strategy.Node qualified as Node | ||
|
|
||
| fixtureDir :: Path Rel Dir | ||
| fixtureDir = $(mkRelDir "test/Node/testdata/pnpm-workspaces/") | ||
|
|
||
| -- | Every package in the fixture, the root included, is named in its | ||
| -- package.json. A workspace root without a @name@ yields no build targets. | ||
| allTargetNames :: [Text] | ||
| allTargetNames = | ||
| [ "@fossa-test/workspace" | ||
| , "@fossa-test/browser" | ||
| , "@fossa-test/server" | ||
| , "@fossa-test/shared" | ||
| ] | ||
|
|
||
| data FixtureGraphs = FixtureGraphs | ||
| { discoveredTargets :: FoundTargets | ||
| , wholeGraph :: Graphing Dependency | ||
| , rootGraph :: Graphing Dependency | ||
| , browserGraph :: Graphing Dependency | ||
| , serverGraph :: Graphing Dependency | ||
| , sharedGraph :: Graphing Dependency | ||
| } | ||
|
|
||
| mkTargets :: [Text] -> FoundTargets | ||
| mkTargets = maybe ProjectWithoutTargets FoundTargets . NonEmptySet.nonEmpty . Set.fromList . map BuildTarget | ||
|
|
||
| depNames :: Graphing Dependency -> Set Text | ||
| depNames = Set.fromList . map dependencyName . Graphing.vertexList | ||
|
|
||
| analyzeFixture :: IO FixtureGraphs | ||
| analyzeFixture = do | ||
| currentDir <- PIO.getCurrentDir | ||
| let scanDir = currentDir </> fixtureDir | ||
| discovered <- testRunner (Node.discover scanDir) LocalEnvironment | ||
| withResult discovered $ \_ projects -> case projects of | ||
| [project] -> do | ||
| projectType project `shouldBe` PnpmProjectType | ||
| let analyzeWith targets = do | ||
| analyzed <- testRunner (ignoreDebug $ runReader NonStrict $ analyzeProject targets (projectData project)) LocalEnvironment | ||
| withResult analyzed $ \_ depResults -> pure (dependencyGraph depResults) | ||
| FixtureGraphs (projectBuildTargets project) | ||
| <$> analyzeWith (projectBuildTargets project) | ||
| <*> analyzeWith (mkTargets ["@fossa-test/workspace"]) | ||
| <*> analyzeWith (mkTargets ["@fossa-test/browser"]) | ||
| <*> analyzeWith (mkTargets ["@fossa-test/server"]) | ||
| <*> analyzeWith (mkTargets ["@fossa-test/shared"]) | ||
| projects' -> fail ("expected exactly one discovered project, got " <> show (length projects')) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| spec :: Spec | ||
| spec = beforeAll analyzeFixture $ | ||
| describe "pnpm workspace" $ do | ||
| it "should expose the root and each workspace member as build targets" $ \fixture -> | ||
| discoveredTargets fixture `shouldBe` mkTargets allTargetNames | ||
|
|
||
| it "should report only the selected member's dependencies" $ \fixture -> do | ||
| -- left-pad reaches browser through a catalog: specifier; is-odd belongs | ||
| -- only to server, and colorjs only to the root. | ||
| depNames (browserGraph fixture) `shouldSatisfy` Set.member "left-pad" | ||
| depNames (browserGraph fixture) `shouldSatisfy` (\names -> not (any (`Set.member` names) ["is-odd", "is-number", "colorjs"])) | ||
|
|
||
| depNames (serverGraph fixture) `shouldBe` Set.fromList ["is-odd", "is-number"] | ||
| depNames (rootGraph fixture) `shouldBe` Set.fromList ["colorjs"] | ||
|
|
||
| it "should follow a workspace link into the sibling it names" $ \fixture -> do | ||
| -- browser depends on the shared member via `version: link:../shared`. | ||
| -- Its dependencies, and their transitives, belong in browser's result; | ||
| -- the workspace package itself is not a reportable dependency. | ||
| depNames (browserGraph fixture) `shouldBe` Set.fromList ["left-pad", "uri-js", "punycode"] | ||
| depNames (sharedGraph fixture) `shouldBe` Set.fromList ["uri-js", "punycode"] | ||
|
|
||
| it "should analyze the whole workspace when all targets are selected" $ \fixture -> do | ||
| depNames (wholeGraph fixture) `shouldBe` Set.fromList ["colorjs", "left-pad", "is-odd", "is-number", "uri-js", "punycode"] | ||
| [rootGraph fixture, browserGraph fixture, serverGraph fixture, sharedGraph fixture] | ||
| `shouldSatisfy` all ((`Set.isSubsetOf` depNames (wholeGraph fixture)) . depNames) | ||
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.