-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat: support workspaces #100
Changes from all commits
52d4de2
3125b96
51606aa
44c2735
f47dc3b
cba9611
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "pnpm-workspace-project", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"type": "module", | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "sub", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "pnpm-workspace-project", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"type": "module", | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": {}, | ||
"private": true, | ||
"workspaces": "sub" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "sub", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* @fileoverview tests for pnpm workspace install packages at root | ||
* @author Wataru Nishimura<[email protected]> | ||
*/ | ||
|
||
import { describe, it, expect, assert, afterEach } from "vitest"; | ||
import { fileURLToPath } from "node:url"; | ||
import { join } from "path"; | ||
import { findPnpmWorkspaceYaml, installSyncSaveDev } from "../lib/utils/npm-utils.js"; | ||
import sinon from "sinon"; | ||
import spawn from "cross-spawn"; | ||
|
||
const __filename = fileURLToPath(import.meta.url); // eslint-disable-line no-underscore-dangle -- commonjs convention | ||
|
||
describe("pnpm workspace install packages at root", () => { | ||
const pnpmWithWorkspaceDir = join(__filename, "../fixtures/pnpm-workspace-project"); | ||
const yarnLegacyWithWorkspaceDir = join(__filename, "../fixtures/yarn-legacy-workspace-project"); | ||
|
||
afterEach(() => { | ||
sinon.verifyAndRestore(); | ||
}); | ||
|
||
/** | ||
* pnpm recognizes whether workspace is enabled by `pnpm-workspace.yaml`. | ||
* This test case tests function to find `pnpm-workspace.yaml`. | ||
*/ | ||
it("find pnpm-workspace.yaml", () => { | ||
const pnpmWorkspaceYaml = findPnpmWorkspaceYaml(pnpmWithWorkspaceDir); | ||
|
||
expect(pnpmWorkspaceYaml).toBeTruthy(); | ||
}); | ||
|
||
/** | ||
* at project root, `pnpm add` needs to be applied "-w" option. | ||
*/ | ||
it("should invoke pnpm with workspace option to install a single desired packages", async () => { | ||
const stub = sinon.stub(spawn, "sync").returns({ stdout: 0 }); | ||
|
||
installSyncSaveDev("desired-package", pnpmWithWorkspaceDir, "pnpm"); | ||
assert(stub.calledOnce); | ||
assert.strictEqual(stub.firstCall.args[0], "pnpm"); | ||
assert.deepStrictEqual(stub.firstCall.args[1], ["add", "-D", "-w", "desired-package"]); | ||
stub.restore(); | ||
}); | ||
|
||
it("should invoke yarn legacy with workspace option to install a single desired packages", async () => { | ||
const stub = sinon.stub(spawn, "sync").returns({ stdout: 0 }); | ||
|
||
installSyncSaveDev("desired-package", yarnLegacyWithWorkspaceDir, "yarn"); | ||
assert(stub.calledOnce); | ||
assert.strictEqual(stub.firstCall.args[0], "yarn"); | ||
assert.deepStrictEqual(stub.firstCall.args[1], ["add", "-D", "-W", "desired-package"]); | ||
Check failure on line 52 in tests/workspace-support.spec.js GitHub Actions / Test (ubuntu-latest, 22.x)tests/workspace-support.spec.js > pnpm workspace install packages at root > should invoke yarn legacy with workspace option to install a single desired packages
Check failure on line 52 in tests/workspace-support.spec.js GitHub Actions / Test (ubuntu-latest, 21.x)tests/workspace-support.spec.js > pnpm workspace install packages at root > should invoke yarn legacy with workspace option to install a single desired packages
Check failure on line 52 in tests/workspace-support.spec.js GitHub Actions / Test (ubuntu-latest, 20.x)tests/workspace-support.spec.js > pnpm workspace install packages at root > should invoke yarn legacy with workspace option to install a single desired packages
Check failure on line 52 in tests/workspace-support.spec.js GitHub Actions / Test (ubuntu-latest, 18.x)tests/workspace-support.spec.js > pnpm workspace install packages at root > should invoke yarn legacy with workspace option to install a single desired packages
Check failure on line 52 in tests/workspace-support.spec.js GitHub Actions / Test (ubuntu-latest, 18.18.0)tests/workspace-support.spec.js > pnpm workspace install packages at root > should invoke yarn legacy with workspace option to install a single desired packages
|
||
}); | ||
|
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can write this as a function(possible
isRootWorkspace()
), something like:it can be evalutated in the constructor, so you can just use it when you need it: