-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow dependecies to use the
workspace:
protocol and add `"workspac…
…eProtocol": "require"` config option (#204)
- Loading branch information
Showing
9 changed files
with
140 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/config@0.2.1/schema.json", | ||
"$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json", | ||
"changelog": [ | ||
"@changesets/changelog-github", | ||
{ "repo": "Thinkmill/manypkg" } | ||
], | ||
"commit": false, | ||
"linked": [], | ||
"access": "public" | ||
"access": "public", | ||
"baseBranch": "main" | ||
} |
This file contains 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,5 @@ | ||
--- | ||
"@manypkg/cli": patch | ||
--- | ||
|
||
Allow dependecies to use the `workspace:` protocol and support adding `"workspaceProtocol": "require"` to the `manypkg` config to require it. |
This file contains 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 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 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,46 @@ | ||
import { makeCheck, NORMAL_DEPENDENCY_TYPES } from "./utils"; | ||
import { Package } from "@manypkg/get-packages"; | ||
|
||
export type ErrorType = { | ||
type: "WORKSPACE_REQUIRED"; | ||
workspace: Package; | ||
depType: typeof NORMAL_DEPENDENCY_TYPES[number]; | ||
depName: string; | ||
}; | ||
|
||
export default makeCheck<ErrorType>({ | ||
validate: (workspace, allWorkspaces, root, opts) => { | ||
if (opts.workspaceProtocol !== "require") return []; | ||
let errors: ErrorType[] = []; | ||
for (let depType of NORMAL_DEPENDENCY_TYPES) { | ||
let deps = workspace.packageJson[depType]; | ||
if (deps) { | ||
for (let depName in deps) { | ||
if ( | ||
allWorkspaces.has(depName) && | ||
!deps[depName].startsWith("workspace:") | ||
) { | ||
errors.push({ | ||
type: "WORKSPACE_REQUIRED", | ||
workspace, | ||
depName, | ||
depType, | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return errors; | ||
}, | ||
fix: (error) => { | ||
let deps = error.workspace.packageJson[error.depType]; | ||
if (deps && deps[error.depName]) { | ||
deps[error.depName] = "workspace:^"; | ||
} | ||
return { requiresInstall: true }; | ||
}, | ||
print: (error) => | ||
`${error.workspace.packageJson.name} has a dependency on ${error.depName} without using the workspace: protocol but this project requires using the workspace: protocol, please change it to workspace:^ or etc.`, | ||
type: "all", | ||
}); |
This file contains 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 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,54 @@ | ||
import { getWS, getFakeWS, getRootWS } from "../../test-helpers"; | ||
import makeCheck from "../WORKSPACE_REQUIRED"; | ||
let rootWorkspace = getRootWS(); | ||
|
||
test("should not error if not using workspaceProtocol: require", () => { | ||
let ws = getWS(); | ||
let dependsOnOne = getFakeWS("depends-on-one"); | ||
dependsOnOne.packageJson.dependencies = { | ||
"pkg-1": "^1.0.0", | ||
}; | ||
ws.set("depends-on-one", dependsOnOne); | ||
let errors = makeCheck.validate(dependsOnOne, ws, rootWorkspace, {}); | ||
expect(errors.length).toEqual(0); | ||
}); | ||
|
||
test("should error if using workspaceProtocol: require", () => { | ||
let ws = getWS(); | ||
let dependsOnOne = getFakeWS("depends-on-one"); | ||
dependsOnOne.packageJson.dependencies = { | ||
"pkg-1": "^1.0.0", | ||
}; | ||
ws.set("depends-on-one", dependsOnOne); | ||
let errors = makeCheck.validate(dependsOnOne, ws, rootWorkspace, { | ||
workspaceProtocol: "require", | ||
}); | ||
expect(errors).toEqual([ | ||
{ | ||
type: "WORKSPACE_REQUIRED", | ||
workspace: dependsOnOne, | ||
depName: "pkg-1", | ||
depType: "dependencies", | ||
}, | ||
]); | ||
}); | ||
|
||
test("should fix if using workspaceProtocol: require", () => { | ||
let ws = getWS(); | ||
let dependsOnOne = getFakeWS("depends-on-one"); | ||
dependsOnOne.packageJson.dependencies = { | ||
"pkg-1": "^1.0.0", | ||
}; | ||
ws.set("depends-on-one", dependsOnOne); | ||
const errors = makeCheck.validate(dependsOnOne, ws, rootWorkspace, { | ||
workspaceProtocol: "require", | ||
}); | ||
expect(errors).toHaveLength(1); | ||
const result = makeCheck.fix(errors[0], { | ||
workspaceProtocol: "require", | ||
}); | ||
expect(dependsOnOne.packageJson.dependencies).toEqual({ | ||
"pkg-1": "workspace:^", | ||
}); | ||
expect(result).toEqual({ requiresInstall: true }); | ||
}); |
This file contains 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 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