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

workspace-tools

Package Overview
Dependencies
Maintainers
2
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

workspace-tools - npm Package Compare versions

Comparing version 0.16.2 to 0.17.0

lib/lockfile/parseNpmLock.d.ts

9

beachball.config.js
module.exports = {
scope: ["!src/__fixtures__/**/*"],
ignorePatterns: [
".github/**",
".prettierrc",
"jest.config.js",
"src/__fixtures__/**",
"src/__tests__/**",
// This prevents dependabot from being blocked by change file requirements for lock file-only changes
"yarn.lock",
],
};

32

CHANGELOG.json

@@ -5,6 +5,36 @@ {

{
"date": "Thu, 03 Jun 2021 20:23:16 GMT",
"date": "Thu, 02 Dec 2021 17:11:04 GMT",
"tag": "workspace-tools_v0.17.0",
"version": "0.17.0",
"comments": {
"minor": [
{
"author": "riacarmin@microsoft.com",
"package": "workspace-tools",
"comment": "Implements NPM workspaces support to parseLockFile utility.",
"commit": "0d9b3bd5c091e238d302f4a6912692e2eda95385"
}
]
}
},
{
"date": "Thu, 21 Oct 2021 20:01:33 GMT",
"tag": "workspace-tools_v0.16.2",
"version": "0.16.2",
"comments": {
"none": [
{
"author": "elcraig@microsoft.com",
"package": "workspace-tools",
"comment": "Update beachball and add ignorePatterns",
"commit": "1aca866df2443581ce221c08b8e783a7054fcd7d"
}
]
}
},
{
"date": "Thu, 03 Jun 2021 20:23:22 GMT",
"tag": "workspace-tools_v0.16.2",
"version": "0.16.2",
"comments": {
"patch": [

@@ -11,0 +41,0 @@ {

# Change Log - workspace-tools
This log was last generated on Thu, 03 Jun 2021 20:23:16 GMT and should not be manually modified.
This log was last generated on Thu, 02 Dec 2021 17:11:04 GMT and should not be manually modified.
<!-- Start content -->
## 0.17.0
Thu, 02 Dec 2021 17:11:04 GMT
### Minor changes
- Implements NPM workspaces support to parseLockFile utility. (riacarmin@microsoft.com)
## 0.16.2
Thu, 03 Jun 2021 20:23:16 GMT
Thu, 03 Jun 2021 20:23:22 GMT

@@ -11,0 +19,0 @@ ### Patches

@@ -5,3 +5,23 @@ "use strict";

const lockfile_1 = require("../lockfile");
const ERROR_MESSAGES = {
NO_LOCK: "You do not have yarn.lock, pnpm-lock.yaml or package-lock.json. Please use one of these package managers.",
UNSUPPORTED: "Your package-lock.json version is not supported: lockfileVersion is 1. You need npm version 7 or above and package-lock version 2 or above. Please, upgrade npm or choose a different package manager.",
};
describe("parseLockFile()", () => {
// General
it("throws if it cannot find lock file", async () => {
const packageRoot = await setupFixture_1.setupFixture("basic-without-lock-file");
await expect(lockfile_1.parseLockFile(packageRoot)).rejects.toThrow(ERROR_MESSAGES.NO_LOCK);
});
// NPM
it("parses package-lock.json file when it is found", async () => {
const packageRoot = await setupFixture_1.setupFixture("monorepo-npm");
const parsedLockeFile = await lockfile_1.parseLockFile(packageRoot);
expect(parsedLockeFile).toHaveProperty("type", "success");
});
it("throws if npm version is unsupported", async () => {
const packageRoot = await setupFixture_1.setupFixture("monorepo-npm-unsupported");
await expect(lockfile_1.parseLockFile(packageRoot)).rejects.toThrow(ERROR_MESSAGES.UNSUPPORTED);
});
// Yarn
it("parses yarn.lock file when it is found", async () => {

@@ -12,6 +32,2 @@ const packageRoot = await setupFixture_1.setupFixture("basic");

});
it("throws if it cannot find a yarn.lock file", async () => {
const packageRoot = await setupFixture_1.setupFixture("basic-without-lock-file");
await expect(lockfile_1.parseLockFile(packageRoot)).rejects.toThrow("You do not have either yarn.lock nor pnpm-lock.yaml. Please use one of these package managers");
});
it("parses combined ranges in yarn.lock", async () => {

@@ -22,3 +38,4 @@ const packageRoot = await setupFixture_1.setupFixture("basic-yarn");

});
it("parses pnpm-lock.yaml properly", async () => {
// PNPM
it("parses pnpm-lock.yaml file when it is found", async () => {
const packageRoot = await setupFixture_1.setupFixture("basic-pnpm");

@@ -25,0 +42,0 @@ const parsedLockeFile = await lockfile_1.parseLockFile(packageRoot);

2

lib/lockfile/index.d.ts

@@ -6,2 +6,2 @@ import { ParsedLock } from "./types";

export { queryLockFile } from "./queryLockFile";
export * from './types';
export * from "./types";

@@ -13,2 +13,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
// NOTE: never place the import of lockfile implementation here, as it slows down the library as a whole
const find_up_1 = __importDefault(require("find-up"));

@@ -20,2 +21,3 @@ const fs_extra_1 = __importDefault(require("fs-extra"));

const parsePnpmLock_1 = require("./parsePnpmLock");
const parseNpmLock_1 = require("./parseNpmLock");
const memoization = {};

@@ -46,3 +48,23 @@ async function parseLockFile(packageRoot) {

}
throw new Error("You do not have either yarn.lock nor pnpm-lock.yaml. Please use one of these package managers");
// Third, try for npm workspaces
let npmLockPath = await find_up_1.default(["package-lock.json"], { cwd: packageRoot });
if (npmLockPath) {
if (memoization[npmLockPath]) {
return memoization[npmLockPath];
}
let npmLockJson;
try {
npmLockJson = fs_extra_1.default.readFileSync(npmLockPath);
}
catch (_a) {
throw new Error("Couldn’t parse package-lock.json.");
}
const npmLock = JSON.parse(npmLockJson.toString());
if (!(npmLock === null || npmLock === void 0 ? void 0 : npmLock.lockfileVersion) || npmLock.lockfileVersion < 2) {
throw new Error(`Your package-lock.json version is not supported: lockfileVersion is ${npmLock.lockfileVersion}. You need npm version 7 or above and package-lock version 2 or above. Please, upgrade npm or choose a different package manager.`);
}
memoization[npmLockPath] = parseNpmLock_1.parseNpmLock(npmLock);
return memoization[npmLockPath];
}
throw new Error("You do not have yarn.lock, pnpm-lock.yaml or package-lock.json. Please use one of these package managers.");
}

@@ -49,0 +71,0 @@ exports.parseLockFile = parseLockFile;

@@ -19,1 +19,32 @@ export declare type Dependencies = {

}
export interface NpmWorkspacesInfo {
version: string;
workspaces: {
packages: string[];
};
}
export interface NpmSymlinkInfo {
resolved: string;
link: boolean;
integrity?: "sha512" | "sha1";
dev?: boolean;
optional?: boolean;
devOptional?: boolean;
dependencies?: {
[key: string]: LockDependency;
};
}
export interface NpmLockFile {
name: string;
version: string;
lockfileVersion?: 1 | 2 | 3;
requires?: boolean;
packages?: {
""?: NpmWorkspacesInfo;
} & {
[key: string]: NpmSymlinkInfo | LockDependency;
};
dependencies?: {
[key: string]: LockDependency;
};
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const implementations_1 = require("./implementations");
const lerna_1 = require("./implementations/lerna");
const npm_1 = require("./implementations/npm");
const pnpm_1 = require("./implementations/pnpm");
const rush_1 = require("./implementations/rush");
const yarn_1 = require("./implementations/yarn");
const rush_1 = require("./implementations/rush");
const npm_1 = require("./implementations/npm");
const lerna_1 = require("./implementations/lerna");
const workspaceGetter = {

@@ -10,0 +10,0 @@ yarn: yarn_1.getYarnWorkspaces,

@@ -13,5 +13,5 @@ "use strict";

function getNpmWorkspaces(cwd) {
const yarnWorkspacesRoot = getNpmWorkspaceRoot(cwd);
return packageJsonWorkspaces_1.getWorkspaceInfoFromWorkspaceRoot(yarnWorkspacesRoot);
const npmWorkspacesRoot = getNpmWorkspaceRoot(cwd);
return packageJsonWorkspaces_1.getWorkspaceInfoFromWorkspaceRoot(npmWorkspacesRoot);
}
exports.getNpmWorkspaces = getNpmWorkspaces;
{
"name": "workspace-tools",
"version": "0.16.2",
"version": "0.17.0",
"license": "MIT",

@@ -40,3 +40,3 @@ "repository": {

"@types/yarnpkg__lockfile": "^1.1.3",
"beachball": "^2.2.0",
"beachball": "^2.17.0",
"jest": "^25.0.0",

@@ -43,0 +43,0 @@ "tmp": "^0.2.1",

@@ -5,6 +5,7 @@ # workspace-tools

- lerna
- npm workspaces
- pnpm workspaces
- rush
- yarn workspaces
- pnpm workspaces
- lerna

@@ -21,3 +22,3 @@ # Environment Variables

Sometimes multiple package manager files are checked in. It is necessary to hint to `workspace-tools` which manager
is used: `yarn`, `pnpm`, `rush`, or `lerna`
is used: `npm`, `yarn`, `pnpm`, `rush`, or `lerna`

@@ -24,0 +25,0 @@ # Contributing

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