Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

get-workspaces

Package Overview
Dependencies
Maintainers
3
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-workspaces - npm Package Compare versions

Comparing version 0.5.2 to 0.6.0

8

CHANGELOG.md
# get-workspaces
## 0.6.0
### Minor Changes
- [`fe0d9192`](https://github.com/atlassian/changesets/commit/fe0d9192544646e1a755202b87dfe850c1c200a3) [#236](https://github.com/atlassian/changesets/pull/236) Thanks [@Andarist](https://github.com/Andarist)! - Added support for finding pnpm workspace packages. It has been added to default queried tools.
* [`fe0d9192`](https://github.com/atlassian/changesets/commit/fe0d9192544646e1a755202b87dfe850c1c200a3) [#236](https://github.com/atlassian/changesets/pull/236) Thanks [@Andarist](https://github.com/Andarist)! - Read also pnpm workspace packages when searching for packages.
## 0.5.2

@@ -4,0 +12,0 @@

2

dist/declarations/src/index.d.ts
import { PackageJSON } from "@changesets/types";
declare type Options = {
cwd?: string;
tools?: Array<"yarn" | "bolt" | "root">;
tools?: Array<"yarn" | "bolt" | "pnpm" | "root">;
};

@@ -6,0 +6,0 @@ export declare type Workspace = {

@@ -10,2 +10,3 @@ 'use strict';

var globby = _interopDefault(require('globby'));
var readYamlFile = _interopDefault(require('read-yaml-file'));

@@ -15,3 +16,3 @@ // This is a modified version of the package-getting in bolt

const cwd = opts.cwd || process.cwd();
const tools = opts.tools || ["yarn", "bolt"]; // We also support root, but don't do it by default
const tools = opts.tools || ["yarn", "bolt", "pnpm"]; // We also support root, but don't do it by default

@@ -29,2 +30,14 @@ const pkg = await fs.readFile(path.join(cwd, "package.json"), "utf-8").then(JSON.parse);

workspaces = pkg.bolt.workspaces;
} else if (tools.includes("pnpm")) {
try {
const manifest = await readYamlFile(path.join(cwd, "pnpm-workspace.yaml"));
if (manifest && manifest.packages) {
workspaces = manifest.packages;
}
} catch (err) {
if (err.code !== "ENOENT") {
throw err;
}
}
}

@@ -31,0 +44,0 @@

@@ -11,9 +11,14 @@ "use strict";

var fs = _interopDefault(require("fs-extra")), path = _interopDefault(require("path")), globby = _interopDefault(require("globby"));
var fs = _interopDefault(require("fs-extra")), path = _interopDefault(require("path")), globby = _interopDefault(require("globby")), readYamlFile = _interopDefault(require("read-yaml-file"));
async function getWorkspaces(opts = {}) {
const cwd = opts.cwd || process.cwd(), tools = opts.tools || [ "yarn", "bolt" ], pkg = await fs.readFile(path.join(cwd, "package.json"), "utf-8").then(JSON.parse);
const cwd = opts.cwd || process.cwd(), tools = opts.tools || [ "yarn", "bolt", "pnpm" ], pkg = await fs.readFile(path.join(cwd, "package.json"), "utf-8").then(JSON.parse);
let workspaces;
if (tools.includes("yarn") && pkg.workspaces ? Array.isArray(pkg.workspaces) ? workspaces = pkg.workspaces : pkg.workspaces.packages && (workspaces = pkg.workspaces.packages) : tools.includes("bolt") && pkg.bolt && pkg.bolt.workspaces && (workspaces = pkg.bolt.workspaces),
!workspaces) return tools.includes("root") ? [ {
if (tools.includes("yarn") && pkg.workspaces) Array.isArray(pkg.workspaces) ? workspaces = pkg.workspaces : pkg.workspaces.packages && (workspaces = pkg.workspaces.packages); else if (tools.includes("bolt") && pkg.bolt && pkg.bolt.workspaces) workspaces = pkg.bolt.workspaces; else if (tools.includes("pnpm")) try {
const manifest = await readYamlFile(path.join(cwd, "pnpm-workspace.yaml"));
manifest && manifest.packages && (workspaces = manifest.packages);
} catch (err) {
if ("ENOENT" !== err.code) throw err;
}
if (!workspaces) return tools.includes("root") ? [ {
config: pkg,

@@ -20,0 +25,0 @@ dir: cwd,

import fs from 'fs-extra';
import path from 'path';
import globby from 'globby';
import readYamlFile from 'read-yaml-file';

@@ -8,3 +9,3 @@ // This is a modified version of the package-getting in bolt

const cwd = opts.cwd || process.cwd();
const tools = opts.tools || ["yarn", "bolt"]; // We also support root, but don't do it by default
const tools = opts.tools || ["yarn", "bolt", "pnpm"]; // We also support root, but don't do it by default

@@ -22,2 +23,14 @@ const pkg = await fs.readFile(path.join(cwd, "package.json"), "utf-8").then(JSON.parse);

workspaces = pkg.bolt.workspaces;
} else if (tools.includes("pnpm")) {
try {
const manifest = await readYamlFile(path.join(cwd, "pnpm-workspace.yaml"));
if (manifest && manifest.packages) {
workspaces = manifest.packages;
}
} catch (err) {
if (err.code !== "ENOENT") {
throw err;
}
}
}

@@ -24,0 +37,0 @@

{
"name": "get-workspaces",
"version": "0.5.2",
"version": "0.6.0",
"description": "Get workspaces for yarn workspaces, bolt workspaces, or the root package for building repo-agnostic tools",

@@ -12,3 +12,4 @@ "main": "dist/get-workspaces.cjs.js",

"fs-extra": "^7.0.1",
"globby": "^9.2.0"
"globby": "^9.2.0",
"read-yaml-file": "^1.1.0"
},

@@ -15,0 +16,0 @@ "devDependencies": {

@@ -36,7 +36,7 @@ # Get Workspaces

The tools supported are `yarn`, `bolt`, and `root`, which returns the root package as a single workspace if passed.
The tools supported are `yarn`, `bolt`, `pnpm` and `root`, which returns the root package as a single workspace if passed.
Tools is an array, so you can try for one type of workspace and then another, so you could do:
```javascript
getWorkspaces({ tools: ["bolt", "yarn", "root"] });
getWorkspaces({ tools: ["bolt", "yarn", "pnpm", "root"] });
```

@@ -32,2 +32,11 @@ import { getFixturePath } from "jest-fixtures";

});
it("should resolve pnpm workspaces if the pnpm option is passed", async () => {
let cwd = await getFixturePath(__dirname, "pnpm-workspace-base");
const workspaces = await getWorkspaces({ cwd, tools: ["pnpm"] });
if (workspaces === null) {
return expect(workspaces).not.toBeNull();
}
expect(workspaces[0].name).toEqual("pnpm-workspace-base-pkg-a");
expect(workspaces[1].name).toEqual("pnpm-workspace-base-pkg-b");
});
it("should resolve main package if root option is passed", async () => {

@@ -60,2 +69,11 @@ let cwd = await getFixturePath(__dirname, "root-only");

});
it("should by default resolve pnpm workspaces if yarn & bolt workspaces are absent", async () => {
let cwd = await getFixturePath(__dirname, "pnpm-workspace-base");
const workspaces = await getWorkspaces({ cwd });
if (workspaces === null) {
return expect(workspaces).not.toBeNull();
}
expect(workspaces[0].name).toEqual("pnpm-workspace-base-pkg-a");
expect(workspaces[1].name).toEqual("pnpm-workspace-base-pkg-b");
});
it("should return an empty array if no workspaces are found", async () => {

@@ -62,0 +80,0 @@ let cwd = await getFixturePath(__dirname, "root-only");

@@ -8,2 +8,3 @@ // This is a modified version of the package-getting in bolt

import globby from "globby";
import readYamlFile from "read-yaml-file";
import { PackageJSON } from "@changesets/types";

@@ -13,3 +14,3 @@

cwd?: string;
tools?: Array<"yarn" | "bolt" | "root">;
tools?: Array<"yarn" | "bolt" | "pnpm" | "root">;
};

@@ -23,3 +24,3 @@

const cwd = opts.cwd || process.cwd();
const tools = opts.tools || ["yarn", "bolt"]; // We also support root, but don't do it by default
const tools = opts.tools || ["yarn", "bolt", "pnpm"]; // We also support root, but don't do it by default

@@ -40,2 +41,15 @@ const pkg = await fs

workspaces = pkg.bolt.workspaces;
} else if (tools.includes("pnpm")) {
try {
const manifest = await readYamlFile<{ packages?: string[] }>(
path.join(cwd, "pnpm-workspace.yaml")
);
if (manifest && manifest.packages) {
workspaces = manifest.packages;
}
} catch (err) {
if (err.code !== "ENOENT") {
throw err;
}
}
}

@@ -42,0 +56,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc