workspace-tools 0.16.2 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.json CHANGED
@@ -2,7 +2,37 @@
2
2
  "name": "workspace-tools",
3
3
  "entries": [
4
4
  {
5
- "date": "Thu, 03 Jun 2021 20:23:16 GMT",
5
+ "date": "Thu, 02 Dec 2021 17:11:04 GMT",
6
+ "tag": "workspace-tools_v0.17.0",
7
+ "version": "0.17.0",
8
+ "comments": {
9
+ "minor": [
10
+ {
11
+ "author": "riacarmin@microsoft.com",
12
+ "package": "workspace-tools",
13
+ "comment": "Implements NPM workspaces support to parseLockFile utility.",
14
+ "commit": "0d9b3bd5c091e238d302f4a6912692e2eda95385"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Thu, 21 Oct 2021 20:01:33 GMT",
21
+ "tag": "workspace-tools_v0.16.2",
22
+ "version": "0.16.2",
23
+ "comments": {
24
+ "none": [
25
+ {
26
+ "author": "elcraig@microsoft.com",
27
+ "package": "workspace-tools",
28
+ "comment": "Update beachball and add ignorePatterns",
29
+ "commit": "1aca866df2443581ce221c08b8e783a7054fcd7d"
30
+ }
31
+ ]
32
+ }
33
+ },
34
+ {
35
+ "date": "Thu, 03 Jun 2021 20:23:22 GMT",
6
36
  "tag": "workspace-tools_v0.16.2",
7
37
  "version": "0.16.2",
8
38
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,20 @@
1
1
  # Change Log - workspace-tools
2
2
 
3
- This log was last generated on Thu, 03 Jun 2021 20:23:16 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 02 Dec 2021 17:11:04 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 0.17.0
8
+
9
+ Thu, 02 Dec 2021 17:11:04 GMT
10
+
11
+ ### Minor changes
12
+
13
+ - Implements NPM workspaces support to parseLockFile utility. (riacarmin@microsoft.com)
14
+
7
15
  ## 0.16.2
8
16
 
9
- Thu, 03 Jun 2021 20:23:16 GMT
17
+ Thu, 03 Jun 2021 20:23:22 GMT
10
18
 
11
19
  ### Patches
12
20
 
package/README.md CHANGED
@@ -2,10 +2,11 @@
2
2
 
3
3
  A collection of tools that are useful in a git-controlled monorepo that is managed by one of these software:
4
4
 
5
+ - lerna
6
+ - npm workspaces
7
+ - pnpm workspaces
5
8
  - rush
6
9
  - yarn workspaces
7
- - pnpm workspaces
8
- - lerna
9
10
 
10
11
  # Environment Variables
11
12
 
@@ -17,7 +18,7 @@ default node.js maxBuffer of 1MB)
17
18
  ## PREFERRED_WORKSPACE_MANAGER
18
19
 
19
20
  Sometimes multiple package manager files are checked in. It is necessary to hint to `workspace-tools` which manager
20
- is used: `yarn`, `pnpm`, `rush`, or `lerna`
21
+ is used: `npm`, `yarn`, `pnpm`, `rush`, or `lerna`
21
22
 
22
23
  # Contributing
23
24
 
@@ -1,3 +1,12 @@
1
1
  module.exports = {
2
2
  scope: ["!src/__fixtures__/**/*"],
3
+ ignorePatterns: [
4
+ ".github/**",
5
+ ".prettierrc",
6
+ "jest.config.js",
7
+ "src/__fixtures__/**",
8
+ "src/__tests__/**",
9
+ // This prevents dependabot from being blocked by change file requirements for lock file-only changes
10
+ "yarn.lock",
11
+ ],
3
12
  };
@@ -2,22 +2,39 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const setupFixture_1 = require("../helpers/setupFixture");
4
4
  const lockfile_1 = require("../lockfile");
5
+ const ERROR_MESSAGES = {
6
+ NO_LOCK: "You do not have yarn.lock, pnpm-lock.yaml or package-lock.json. Please use one of these package managers.",
7
+ 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.",
8
+ };
5
9
  describe("parseLockFile()", () => {
10
+ // General
11
+ it("throws if it cannot find lock file", async () => {
12
+ const packageRoot = await setupFixture_1.setupFixture("basic-without-lock-file");
13
+ await expect(lockfile_1.parseLockFile(packageRoot)).rejects.toThrow(ERROR_MESSAGES.NO_LOCK);
14
+ });
15
+ // NPM
16
+ it("parses package-lock.json file when it is found", async () => {
17
+ const packageRoot = await setupFixture_1.setupFixture("monorepo-npm");
18
+ const parsedLockeFile = await lockfile_1.parseLockFile(packageRoot);
19
+ expect(parsedLockeFile).toHaveProperty("type", "success");
20
+ });
21
+ it("throws if npm version is unsupported", async () => {
22
+ const packageRoot = await setupFixture_1.setupFixture("monorepo-npm-unsupported");
23
+ await expect(lockfile_1.parseLockFile(packageRoot)).rejects.toThrow(ERROR_MESSAGES.UNSUPPORTED);
24
+ });
25
+ // Yarn
6
26
  it("parses yarn.lock file when it is found", async () => {
7
27
  const packageRoot = await setupFixture_1.setupFixture("basic");
8
28
  const parsedLockeFile = await lockfile_1.parseLockFile(packageRoot);
9
29
  expect(parsedLockeFile).toHaveProperty("type", "success");
10
30
  });
11
- it("throws if it cannot find a yarn.lock file", async () => {
12
- const packageRoot = await setupFixture_1.setupFixture("basic-without-lock-file");
13
- 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");
14
- });
15
31
  it("parses combined ranges in yarn.lock", async () => {
16
32
  const packageRoot = await setupFixture_1.setupFixture("basic-yarn");
17
33
  const parsedLockeFile = await lockfile_1.parseLockFile(packageRoot);
18
34
  expect(parsedLockeFile.object["@babel/code-frame@^7.0.0"].version).toBe(parsedLockeFile.object["@babel/code-frame@^7.8.3"].version);
19
35
  });
20
- it("parses pnpm-lock.yaml properly", async () => {
36
+ // PNPM
37
+ it("parses pnpm-lock.yaml file when it is found", async () => {
21
38
  const packageRoot = await setupFixture_1.setupFixture("basic-pnpm");
22
39
  const parsedLockeFile = await lockfile_1.parseLockFile(packageRoot);
23
40
  expect(Object.keys(parsedLockeFile.object["yargs@16.2.0"].dependencies)).toContain("cliui");
@@ -3,4 +3,4 @@ import { nameAtVersion } from "./nameAtVersion";
3
3
  export declare function parseLockFile(packageRoot: string): Promise<ParsedLock>;
4
4
  export { nameAtVersion };
5
5
  export { queryLockFile } from "./queryLockFile";
6
- export * from './types';
6
+ export * from "./types";
@@ -10,12 +10,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
10
10
  return result;
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
+ // NOTE: never place the import of lockfile implementation here, as it slows down the library as a whole
13
14
  const find_up_1 = __importDefault(require("find-up"));
14
15
  const fs_extra_1 = __importDefault(require("fs-extra"));
15
16
  const read_yaml_file_1 = __importDefault(require("read-yaml-file"));
16
17
  const nameAtVersion_1 = require("./nameAtVersion");
17
18
  exports.nameAtVersion = nameAtVersion_1.nameAtVersion;
18
19
  const parsePnpmLock_1 = require("./parsePnpmLock");
20
+ const parseNpmLock_1 = require("./parseNpmLock");
19
21
  const memoization = {};
20
22
  async function parseLockFile(packageRoot) {
21
23
  const yarnLockPath = await find_up_1.default(["yarn.lock", "common/config/rush/yarn.lock"], { cwd: packageRoot });
@@ -41,7 +43,27 @@ async function parseLockFile(packageRoot) {
41
43
  memoization[pnpmLockPath] = parsed;
42
44
  return memoization[pnpmLockPath];
43
45
  }
44
- throw new Error("You do not have either yarn.lock nor pnpm-lock.yaml. Please use one of these package managers");
46
+ // Third, try for npm workspaces
47
+ let npmLockPath = await find_up_1.default(["package-lock.json"], { cwd: packageRoot });
48
+ if (npmLockPath) {
49
+ if (memoization[npmLockPath]) {
50
+ return memoization[npmLockPath];
51
+ }
52
+ let npmLockJson;
53
+ try {
54
+ npmLockJson = fs_extra_1.default.readFileSync(npmLockPath);
55
+ }
56
+ catch (_a) {
57
+ throw new Error("Couldn’t parse package-lock.json.");
58
+ }
59
+ const npmLock = JSON.parse(npmLockJson.toString());
60
+ if (!(npmLock === null || npmLock === void 0 ? void 0 : npmLock.lockfileVersion) || npmLock.lockfileVersion < 2) {
61
+ 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.`);
62
+ }
63
+ memoization[npmLockPath] = parseNpmLock_1.parseNpmLock(npmLock);
64
+ return memoization[npmLockPath];
65
+ }
66
+ throw new Error("You do not have yarn.lock, pnpm-lock.yaml or package-lock.json. Please use one of these package managers.");
45
67
  }
46
68
  exports.parseLockFile = parseLockFile;
47
69
  var queryLockFile_1 = require("./queryLockFile");
@@ -0,0 +1,2 @@
1
+ import { ParsedLock, NpmLockFile } from "./types";
2
+ export declare const parseNpmLock: (lock: NpmLockFile) => ParsedLock;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseNpmLock = (lock) => {
4
+ var _a;
5
+ return ({
6
+ object: (_a = lock.dependencies) !== null && _a !== void 0 ? _a : {},
7
+ type: "success",
8
+ });
9
+ };
@@ -16,3 +16,34 @@ export interface PnpmLockFile {
16
16
  [name: string]: any;
17
17
  };
18
18
  }
19
+ export interface NpmWorkspacesInfo {
20
+ version: string;
21
+ workspaces: {
22
+ packages: string[];
23
+ };
24
+ }
25
+ export interface NpmSymlinkInfo {
26
+ resolved: string;
27
+ link: boolean;
28
+ integrity?: "sha512" | "sha1";
29
+ dev?: boolean;
30
+ optional?: boolean;
31
+ devOptional?: boolean;
32
+ dependencies?: {
33
+ [key: string]: LockDependency;
34
+ };
35
+ }
36
+ export interface NpmLockFile {
37
+ name: string;
38
+ version: string;
39
+ lockfileVersion?: 1 | 2 | 3;
40
+ requires?: boolean;
41
+ packages?: {
42
+ ""?: NpmWorkspacesInfo;
43
+ } & {
44
+ [key: string]: NpmSymlinkInfo | LockDependency;
45
+ };
46
+ dependencies?: {
47
+ [key: string]: LockDependency;
48
+ };
49
+ }
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const implementations_1 = require("./implementations");
4
+ const lerna_1 = require("./implementations/lerna");
5
+ const npm_1 = require("./implementations/npm");
4
6
  const pnpm_1 = require("./implementations/pnpm");
5
- const yarn_1 = require("./implementations/yarn");
6
7
  const rush_1 = require("./implementations/rush");
7
- const npm_1 = require("./implementations/npm");
8
- const lerna_1 = require("./implementations/lerna");
8
+ const yarn_1 = require("./implementations/yarn");
9
9
  const workspaceGetter = {
10
10
  yarn: yarn_1.getYarnWorkspaces,
11
11
  pnpm: pnpm_1.getPnpmWorkspaces,
@@ -10,7 +10,7 @@ function getNpmWorkspaceRoot(cwd) {
10
10
  }
11
11
  exports.getNpmWorkspaceRoot = getNpmWorkspaceRoot;
12
12
  function getNpmWorkspaces(cwd) {
13
- const yarnWorkspacesRoot = getNpmWorkspaceRoot(cwd);
14
- return packageJsonWorkspaces_1.getWorkspaceInfoFromWorkspaceRoot(yarnWorkspacesRoot);
13
+ const npmWorkspacesRoot = getNpmWorkspaceRoot(cwd);
14
+ return packageJsonWorkspaces_1.getWorkspaceInfoFromWorkspaceRoot(npmWorkspacesRoot);
15
15
  }
16
16
  exports.getNpmWorkspaces = getNpmWorkspaces;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "workspace-tools",
3
- "version": "0.16.2",
3
+ "version": "0.17.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -37,7 +37,7 @@
37
37
  "@types/node": ">=12.0.0",
38
38
  "@types/tmp": "^0.2.0",
39
39
  "@types/yarnpkg__lockfile": "^1.1.3",
40
- "beachball": "^2.2.0",
40
+ "beachball": "^2.17.0",
41
41
  "jest": "^25.0.0",
42
42
  "tmp": "^0.2.1",
43
43
  "ts-jest": "^25.5.1",