Skip to content

Commit

Permalink
feat: pnpm workspaces support (#3284)
Browse files Browse the repository at this point in the history
  • Loading branch information
fahslaj committed Aug 31, 2022
1 parent 1d6a6f5 commit 1b18dbe
Show file tree
Hide file tree
Showing 54 changed files with 1,711 additions and 354 deletions.
4 changes: 4 additions & 0 deletions .github/actions/install-node-and-dependencies/action.yml
Expand Up @@ -31,3 +31,7 @@ runs:
- name: Install dependencies
run: npm ci
shell: bash

- name: Install pnpm
run: npm install -g pnpm
shell: bash
7 changes: 7 additions & 0 deletions commands/add/__tests__/__fixtures__/pnpm/lerna.json
@@ -0,0 +1,7 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useNx": false,
"useWorkspaces": true,
"version": "1.0.0",
"npmClient": "pnpm"
}
10 changes: 10 additions & 0 deletions commands/add/__tests__/__fixtures__/pnpm/package.json
@@ -0,0 +1,10 @@
{
"name": "root",
"private": true,
"workspaces": [
"packages/*"
],
"devDependencies": {
"lerna": "^5.3.0"
}
}
@@ -0,0 +1,8 @@
{
"name": "package-1",
"version": "1.0.0",
"scripts": {
"fail": "exit 1",
"my-script": "echo package-1"
}
}
@@ -0,0 +1,11 @@
{
"name": "package-2",
"version": "1.0.0",
"scripts": {
"fail": "exit 1",
"my-script": "echo package-2"
},
"dependencies": {
"package-1": "^1.0.0"
}
}
2 changes: 2 additions & 0 deletions commands/add/__tests__/__fixtures__/pnpm/pnpm-workspace.yaml
@@ -0,0 +1,2 @@
packages:
- "packages/*"
9 changes: 9 additions & 0 deletions commands/add/__tests__/add-command.test.js
Expand Up @@ -44,6 +44,15 @@ describe("AddCommand", () => {
await expect(command).rejects.toThrow(/Requested package has no version:/);
});

it("should throw when using pnpm", async () => {
const testDir = await initFixture("pnpm");
const command = lernaAdd(testDir)("@test/package-1");

await expect(command).rejects.toThrow(
"Add is not supported when using `pnpm` workspaces. Use `pnpm` directly to add dependencies to packages: https://pnpm.io/cli/add"
);
});

it("should reference remote dependencies", async () => {
const testDir = await initFixture("basic");

Expand Down
7 changes: 7 additions & 0 deletions commands/add/index.js
Expand Up @@ -36,6 +36,13 @@ class AddCommand extends Command {
}

initialize() {
if (this.options.npmClient === "pnpm") {
throw new ValidationError(
"EPNPMNOTSUPPORTED",
"Add is not supported when using `pnpm` workspaces. Use `pnpm` directly to add dependencies to packages: https://pnpm.io/cli/add"
);
}

this.spec = npa(this.options.pkg);
this.dirs = new Set(this.options.globs.map((fp) => path.resolve(this.project.rootPath, fp)));
this.selfSatisfied = this.packageSatisfied();
Expand Down
7 changes: 7 additions & 0 deletions commands/bootstrap/__tests__/__fixtures__/pnpm/lerna.json
@@ -0,0 +1,7 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useNx": true,
"useWorkspaces": true,
"version": "1.0.0",
"npmClient": "pnpm"
}
10 changes: 10 additions & 0 deletions commands/bootstrap/__tests__/__fixtures__/pnpm/package.json
@@ -0,0 +1,10 @@
{
"name": "root",
"private": true,
"workspaces": [
"packages/*"
],
"devDependencies": {
"lerna": "^5.3.0"
}
}
@@ -0,0 +1,2 @@
packages:
- "packages/*"
11 changes: 11 additions & 0 deletions commands/bootstrap/__tests__/bootstrap-command.test.js
Expand Up @@ -138,6 +138,17 @@ describe("BootstrapCommand", () => {
});
});

describe("with pnpm", () => {
it("should throw validation error", async () => {
const testDir = await initFixture("pnpm");
const command = lernaBootstrap(testDir)();

await expect(command).rejects.toThrow(
"Bootstrapping with pnpm is not supported. Use pnpm directly to manage dependencies: https://pnpm.io/cli/install"
);
});
});

describe("with hoisting", () => {
it("should hoist", async () => {
const testDir = await initFixture("basic");
Expand Down
7 changes: 7 additions & 0 deletions commands/bootstrap/index.js
Expand Up @@ -38,6 +38,13 @@ class BootstrapCommand extends Command {
initialize() {
const { registry, npmClient = "npm", npmClientArgs = [], mutex, hoist, nohoist } = this.options;

if (npmClient === "pnpm") {
throw new ValidationError(
"EWORKSPACES",
"Bootstrapping with pnpm is not supported. Use pnpm directly to manage dependencies: https://pnpm.io/cli/install"
);
}

if (npmClient === "yarn" && hoist) {
throw new ValidationError(
"EWORKSPACES",
Expand Down
7 changes: 7 additions & 0 deletions commands/link/__tests__/__fixtures__/pnpm/lerna.json
@@ -0,0 +1,7 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useNx": true,
"useWorkspaces": true,
"version": "1.0.0",
"npmClient": "pnpm"
}
10 changes: 10 additions & 0 deletions commands/link/__tests__/__fixtures__/pnpm/package.json
@@ -0,0 +1,10 @@
{
"name": "root",
"private": true,
"workspaces": [
"packages/*"
],
"devDependencies": {
"lerna": "^5.3.0"
}
}
2 changes: 2 additions & 0 deletions commands/link/__tests__/__fixtures__/pnpm/pnpm-workspace.yaml
@@ -0,0 +1,2 @@
packages:
- "packages/*"

0 comments on commit 1b18dbe

Please sign in to comment.