-
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.
Noviny/enforce internal dev dep range (#24)
* up is not down * fix things * Update .changeset/cyan-cups-push.md Co-Authored-By: Mitchell Hamilton <[email protected]> * Update .changeset/cyan-cups-push.md Co-Authored-By: Mitchell Hamilton <[email protected]> * Update README.md Co-Authored-By: Mitchell Hamilton <[email protected]> * Update .changeset/cyan-cups-push.md Co-Authored-By: Mitchell Hamilton <[email protected]> * updated messaging * Update .changeset/cyan-cups-push.md
- Loading branch information
Showing
11 changed files
with
254 additions
and
22 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
"@manypkg/cli": minor | ||
--- | ||
|
||
Add new check: INTERNAL_DEV_DEP_NOT_STAR | ||
|
||
This check moves internal devDependencies between packages to be `*` - so in a case where I had a package sunshine, which depends on internal package 'sun': | ||
|
||
```json | ||
{ | ||
"name": "sunshine", | ||
"version": "1.0.0", | ||
"devDependencies": { | ||
"sun": "^1.0.0" | ||
} | ||
} | ||
``` | ||
|
||
we will now have: | ||
|
||
```json | ||
{ | ||
"name": "sunshine", | ||
"version": "1.0.0", | ||
"devDependencies": { | ||
"sun": "*" | ||
} | ||
} | ||
``` | ||
|
||
This is because all internal dependencies are always linked if the version of the internal dependency is within the specified range(which is already enforced by Manypkg), and devDependencies are only relevant in local installs. Having set versions here caused packages to be patched when one of their devDependencies left the range, which was not strictly necessary. |
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
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,43 @@ | ||
import { makeCheck, Workspace } from "./utils"; | ||
|
||
export type ErrorType = { | ||
type: "INTERNAL_DEV_DEP_NOT_STAR"; | ||
workspace: Workspace; | ||
dependencyWorkspace: Workspace; | ||
}; | ||
|
||
export default makeCheck<ErrorType>({ | ||
validate: (workspace, allWorkspaces) => { | ||
let errors: ErrorType[] = []; | ||
let deps = workspace.config.devDependencies; | ||
if (deps) { | ||
for (let depName in deps) { | ||
let range = deps[depName]; | ||
let dependencyWorkspace = allWorkspaces.get(depName); | ||
if (dependencyWorkspace !== undefined && range !== "*") { | ||
errors.push({ | ||
type: "INTERNAL_DEV_DEP_NOT_STAR", | ||
workspace, | ||
dependencyWorkspace | ||
}); | ||
} | ||
} | ||
} | ||
|
||
return errors; | ||
}, | ||
fix: error => { | ||
let deps = error.workspace.config.devDependencies; | ||
if (deps && deps[error.dependencyWorkspace.name]) { | ||
deps[error.dependencyWorkspace.name] = "*"; | ||
} | ||
return { requiresInstall: true }; | ||
}, | ||
print: error => | ||
`${error.workspace.name} has a dependency on ${ | ||
error.dependencyWorkspace.name | ||
} as a devDependency, but has the version listed as ${ | ||
error.workspace.config.devDependencies![error.dependencyWorkspace.name] | ||
}. Please update the dependency to be "*"`, | ||
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
66 changes: 66 additions & 0 deletions
66
packages/cli/src/checks/__tests__/INTERNAL_DEV_DEP_NOT_STAR.ts
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,66 @@ | ||
import makeCheck, { ErrorType } from "../INTERNAL_DEV_DEP_NOT_STAR"; | ||
import { Workspace } from "get-workspaces"; | ||
|
||
let getFakeWS = ( | ||
name: string = "pkg-1", | ||
version: string = "1.0.0" | ||
): Workspace => { | ||
return { | ||
name, | ||
dir: `some/fake/dir/${name}`, | ||
config: { | ||
name, | ||
version | ||
} | ||
}; | ||
}; | ||
|
||
let getWS = (): Map<string, Workspace> => { | ||
let ws = new Map(); | ||
ws.set("pkg-1", getFakeWS()); | ||
return ws; | ||
}; | ||
|
||
describe("internal dev ep is not star", () => { | ||
it("should not error if internal version is *", () => { | ||
let ws = getWS(); | ||
let dependsOnOne = getFakeWS("depends-on-one"); | ||
dependsOnOne.config.devDependencies = { | ||
"pkg-1": "*" | ||
}; | ||
ws.set("depends-on-one", dependsOnOne); | ||
let errors = makeCheck.validate(dependsOnOne, ws); | ||
expect(errors.length).toEqual(0); | ||
}); | ||
it("should error if internal version is not *", () => { | ||
let ws = getWS(); | ||
let dependsOnOne = getFakeWS("depends-on-one"); | ||
dependsOnOne.config.devDependencies = { | ||
"pkg-1": "^1.0.0" | ||
}; | ||
ws.set("depends-on-one", dependsOnOne); | ||
let errors = makeCheck.validate(dependsOnOne, ws); | ||
expect(errors[0]).toMatchObject({ | ||
type: "INTERNAL_DEV_DEP_NOT_STAR", | ||
workspace: dependsOnOne, | ||
dependencyWorkspace: ws.get("pkg-1") | ||
}); | ||
expect(errors.length).toEqual(1); | ||
}); | ||
it("should fix an incompatible version", () => { | ||
let workspace = getFakeWS("depends-on-one"); | ||
workspace.config.devDependencies = { | ||
"pkg-1": "^1.0.0" | ||
}; | ||
let error: ErrorType = { | ||
type: "INTERNAL_DEV_DEP_NOT_STAR", | ||
workspace, | ||
dependencyWorkspace: getFakeWS() | ||
}; | ||
let result = makeCheck.fix!(error); | ||
expect(result).toMatchObject({ requiresInstall: true }); | ||
expect(error.workspace.config.devDependencies).toMatchObject({ | ||
"pkg-1": "*" | ||
}); | ||
}); | ||
}); |
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,85 @@ | ||
import makeCheck, { ErrorType } from "../INTERNAL_MISMATCH"; | ||
import { Workspace } from "get-workspaces"; | ||
|
||
let getFakeWS = ( | ||
name: string = "pkg-1", | ||
version: string = "1.0.0" | ||
): Workspace => { | ||
return { | ||
name, | ||
dir: `some/fake/dir/${name}`, | ||
config: { | ||
name, | ||
version | ||
} | ||
}; | ||
}; | ||
|
||
let getWS = (): Map<string, Workspace> => { | ||
let ws = new Map(); | ||
ws.set("pkg-1", getFakeWS()); | ||
return ws; | ||
}; | ||
|
||
describe("internal mismatch", () => { | ||
it("should not error if internal version is compatible", () => { | ||
let ws = getWS(); | ||
let dependsOnOne = getFakeWS("depends-on-one"); | ||
dependsOnOne.config.dependencies = { | ||
"pkg-1": "^1.0.0" | ||
}; | ||
ws.set("depends-on-one", dependsOnOne); | ||
let errors = makeCheck.validate(dependsOnOne, ws); | ||
expect(errors.length).toEqual(0); | ||
}); | ||
it("should error if internal version is not compatible", () => { | ||
let ws = getWS(); | ||
let dependsOnOne = getFakeWS("depends-on-one"); | ||
dependsOnOne.config.dependencies = { | ||
"pkg-1": "^0.1.0" | ||
}; | ||
ws.set("depends-on-one", dependsOnOne); | ||
let errors = makeCheck.validate(dependsOnOne, ws); | ||
expect(errors[0]).toMatchObject({ | ||
type: "INTERNAL_MISMATCH", | ||
dependencyWorkspace: ws.get("pkg-1"), | ||
workspace: dependsOnOne, | ||
dependencyRange: "^0.1.0" | ||
}); | ||
expect(errors.length).toEqual(1); | ||
}); | ||
it("should fix an incompatible version", () => { | ||
let workspace = getFakeWS("depends-on-one"); | ||
workspace.config.dependencies = { | ||
"pkg-1": "^0.1.0" | ||
}; | ||
|
||
let error: ErrorType = { | ||
type: "INTERNAL_MISMATCH", | ||
workspace, | ||
dependencyWorkspace: getFakeWS(), | ||
dependencyRange: "^0.1.0" | ||
}; | ||
|
||
let fixed = makeCheck.fix!(error); | ||
expect(fixed).toMatchObject({ requiresInstall: true }); | ||
expect(workspace.config.dependencies).toMatchObject({ "pkg-1": "^1.0.0" }); | ||
}); | ||
it("should not check dev dependencies", () => { | ||
// This is handled by INTERNAL_DEV_DEP_NOT_STAR | ||
let ws = getWS(); | ||
let dependsOnOne = getFakeWS("depends-on-one"); | ||
dependsOnOne.config.devDependencies = { | ||
"pkg-1": "^0.1.0" | ||
}; | ||
ws.set("depends-on-one", dependsOnOne); | ||
let errors = makeCheck.validate(dependsOnOne, ws); | ||
expect(errors.length).toEqual(0); | ||
}); | ||
// NB this is the same as dependency right now, but I added it for completeness | ||
describe.skip("peerDependency", () => { | ||
it("should not error if internal version is compatible", () => {}); | ||
it("should error if internal version is not compatible", () => {}); | ||
it("should fix an incompatible version", () => {}); | ||
}); | ||
}); |
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