workspace-tools 0.25.4 → 0.26.2

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,94 @@
2
2
  "name": "workspace-tools",
3
3
  "entries": [
4
4
  {
5
- "date": "Thu, 04 Aug 2022 08:01:45 GMT",
5
+ "date": "Fri, 12 Aug 2022 01:57:23 GMT",
6
+ "tag": "workspace-tools_v0.26.2",
7
+ "version": "0.26.2",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "elcraig@microsoft.com",
12
+ "package": "workspace-tools",
13
+ "commit": "35fa36c25d7b1b2ef2de4d6318fa69af59b620ce",
14
+ "comment": "Add cleanup functions for addGitObserver"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Mon, 08 Aug 2022 22:44:02 GMT",
21
+ "tag": "workspace-tools_v0.26.1",
22
+ "version": "0.26.1",
23
+ "comments": {
24
+ "patch": [
25
+ {
26
+ "author": "elcraig@microsoft.com",
27
+ "package": "workspace-tools",
28
+ "commit": "fa0d932a0a0ae63ebf16357b9a5ca42412405e95",
29
+ "comment": "Add missing type exports"
30
+ }
31
+ ],
32
+ "none": [
33
+ {
34
+ "author": "email not defined",
35
+ "package": "workspace-tools",
36
+ "commit": "05c206e967548245798da2f8b41ded7415e757e9",
37
+ "comment": "Update devDependency beachball to v2.26.1"
38
+ },
39
+ {
40
+ "author": "email not defined",
41
+ "package": "workspace-tools",
42
+ "commit": "9349737ca68eb1a10bc56c19911a08027fce9f48",
43
+ "comment": "Update devDependency gh-pages to v4"
44
+ },
45
+ {
46
+ "author": "email not defined",
47
+ "package": "workspace-tools",
48
+ "commit": "dbd019cf7c1cafb1b9a503461cc49acce936278f",
49
+ "comment": "Lock file maintenance"
50
+ }
51
+ ]
52
+ }
53
+ },
54
+ {
55
+ "date": "Thu, 04 Aug 2022 21:47:46 GMT",
56
+ "tag": "workspace-tools_v0.26.0",
57
+ "version": "0.26.0",
58
+ "comments": {
59
+ "minor": [
60
+ {
61
+ "author": "elcraig@microsoft.com",
62
+ "package": "workspace-tools",
63
+ "commit": "e74753a50e613d41f62c1e917ceafc2185791e2a",
64
+ "comment": "Use ES2019 output (compatible with Node 14)"
65
+ }
66
+ ],
67
+ "none": [
68
+ {
69
+ "author": "elcraig@microsoft.com",
70
+ "package": "workspace-tools",
71
+ "commit": "286b02b981a5bc532560ee17433ef0501f9414ea",
72
+ "comment": "Use Node 14 in repo and types"
73
+ },
74
+ {
75
+ "author": "renovate@whitesourcesoftware.com",
76
+ "package": "workspace-tools",
77
+ "commit": "5cba374fac27ef530d5f80530d3b925577f7e193",
78
+ "comment": "Lock file maintenance"
79
+ }
80
+ ],
81
+ "patch": [
82
+ {
83
+ "author": "boabdelm@microsoft.com",
84
+ "package": "workspace-tools",
85
+ "commit": "5577a58d537fe41ca2dd8f74ea243da700ca0840",
86
+ "comment": "Gracefully handle not having a package.json at git root"
87
+ }
88
+ ]
89
+ }
90
+ },
91
+ {
92
+ "date": "Thu, 04 Aug 2022 08:01:48 GMT",
6
93
  "tag": "workspace-tools_v0.25.4",
7
94
  "version": "0.25.4",
8
95
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,40 @@
1
1
  # Change Log - workspace-tools
2
2
 
3
- This log was last generated on Thu, 04 Aug 2022 08:01:45 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 12 Aug 2022 01:57:23 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 0.26.2
8
+
9
+ Fri, 12 Aug 2022 01:57:23 GMT
10
+
11
+ ### Patches
12
+
13
+ - Add cleanup functions for addGitObserver (elcraig@microsoft.com)
14
+
15
+ ## 0.26.1
16
+
17
+ Mon, 08 Aug 2022 22:44:02 GMT
18
+
19
+ ### Patches
20
+
21
+ - Add missing type exports (elcraig@microsoft.com)
22
+
23
+ ## 0.26.0
24
+
25
+ Thu, 04 Aug 2022 21:47:46 GMT
26
+
27
+ ### Minor changes
28
+
29
+ - Use ES2019 output (compatible with Node 14) (elcraig@microsoft.com)
30
+
31
+ ### Patches
32
+
33
+ - Gracefully handle not having a package.json at git root (boabdelm@microsoft.com)
34
+
7
35
  ## 0.25.4
8
36
 
9
- Thu, 04 Aug 2022 08:01:45 GMT
37
+ Thu, 04 Aug 2022 08:01:48 GMT
10
38
 
11
39
  ### Patches
12
40
 
@@ -26,7 +26,7 @@ function getDefaultRemote(cwdOrOptions) {
26
26
  packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath, "utf8").trim());
27
27
  }
28
28
  catch (e) {
29
- throw new Error(`Could not read "${packageJsonPath}"`);
29
+ logOrThrow(`Could not read "${packageJsonPath}"`);
30
30
  }
31
31
  const { repository } = packageJson;
32
32
  const repositoryUrl = typeof repository === "string" ? repository : (repository && repository.url) || "";
package/lib/git/git.d.ts CHANGED
@@ -10,12 +10,14 @@ export declare type GitProcessOutput = {
10
10
  success: boolean;
11
11
  };
12
12
  /** Observes the git operations called from `git()` or `gitFailFast()` */
13
- declare type GitObserver = (args: string[], output: GitProcessOutput) => void;
13
+ export declare type GitObserver = (args: string[], output: GitProcessOutput) => void;
14
14
  /**
15
15
  * Adds an observer for the git operations, e.g. for testing
16
- * @param observer
16
+ * @returns a function to remove the observer
17
17
  */
18
- export declare function addGitObserver(observer: GitObserver): void;
18
+ export declare function addGitObserver(observer: GitObserver): () => void;
19
+ /** Clear all git observers */
20
+ export declare function clearGitObservers(): void;
19
21
  /**
20
22
  * Runs git command - use this for read-only commands
21
23
  */
@@ -26,4 +28,3 @@ export declare function git(args: string[], options?: SpawnSyncOptions): GitProc
26
28
  export declare function gitFailFast(args: string[], options?: SpawnSyncOptions & {
27
29
  noExitCode?: boolean;
28
30
  }): void;
29
- export {};
package/lib/git/git.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // Basic git wrappers
4
4
  //
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.gitFailFast = exports.git = exports.addGitObserver = exports.GitError = void 0;
6
+ exports.gitFailFast = exports.git = exports.clearGitObservers = exports.addGitObserver = exports.GitError = void 0;
7
7
  const child_process_1 = require("child_process");
8
8
  class GitError extends Error {
9
9
  constructor(message, originalError) {
@@ -27,17 +27,30 @@ const observers = [];
27
27
  let observing;
28
28
  /**
29
29
  * Adds an observer for the git operations, e.g. for testing
30
- * @param observer
30
+ * @returns a function to remove the observer
31
31
  */
32
32
  function addGitObserver(observer) {
33
33
  observers.push(observer);
34
+ return () => removeGitObserver(observer);
34
35
  }
35
36
  exports.addGitObserver = addGitObserver;
37
+ /** Clear all git observers */
38
+ function clearGitObservers() {
39
+ observers.splice(0, observers.length);
40
+ }
41
+ exports.clearGitObservers = clearGitObservers;
42
+ /** Remove a git observer */
43
+ function removeGitObserver(observer) {
44
+ const index = observers.indexOf(observer);
45
+ if (index > -1) {
46
+ observers.splice(index, 1);
47
+ }
48
+ }
36
49
  /**
37
50
  * Runs git command - use this for read-only commands
38
51
  */
39
52
  function git(args, options) {
40
- const results = (0, child_process_1.spawnSync)("git", args, Object.assign({ maxBuffer: defaultMaxBuffer }, options));
53
+ const results = (0, child_process_1.spawnSync)("git", args, { maxBuffer: defaultMaxBuffer, ...options });
41
54
  const output = {
42
55
  stderr: results.stderr.toString().trimRight(),
43
56
  stdout: results.stdout.toString().trimRight(),
@@ -2,7 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPackageDependencies = void 0;
4
4
  function getPackageDependencies(info, packages, options = { withDevDependencies: true }) {
5
- const deps = Object.assign(Object.assign(Object.assign({}, info.dependencies), (options.withDevDependencies && info.devDependencies)), (options.withPeerDependencies && info.peerDependencies));
5
+ const deps = {
6
+ ...info.dependencies,
7
+ ...(options.withDevDependencies && info.devDependencies),
8
+ ...(options.withPeerDependencies && info.peerDependencies),
9
+ };
6
10
  return Object.keys(packages).filter((pkg) => !!deps[pkg]);
7
11
  }
8
12
  exports.getPackageDependencies = getPackageDependencies;
@@ -72,7 +72,7 @@ function setupPackageJson(cwd, packageJson = {}) {
72
72
  if (fs_extra_1.default.existsSync(pkgJsonPath)) {
73
73
  oldPackageJson = JSON.parse(fs_extra_1.default.readFileSync(pkgJsonPath, "utf-8"));
74
74
  }
75
- fs_extra_1.default.writeFileSync(pkgJsonPath, JSON.stringify(Object.assign(Object.assign({}, oldPackageJson), packageJson), null, 2));
75
+ fs_extra_1.default.writeFileSync(pkgJsonPath, JSON.stringify({ ...oldPackageJson, ...packageJson }, null, 2));
76
76
  }
77
77
  exports.setupPackageJson = setupPackageJson;
78
78
  function setupLocalRemote(cwd, remoteName, fixtureName) {
package/lib/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export * from "./graph/index";
5
5
  export * from "./lockfile";
6
6
  export * from "./paths";
7
7
  export * from "./scope";
8
+ export * from "./types/PackageGraph";
8
9
  export * from "./types/PackageInfo";
9
10
  export * from "./types/WorkspaceInfo";
10
11
  export * from "./workspaces/findWorkspacePath";
package/lib/index.js CHANGED
@@ -17,6 +17,7 @@ __exportStar(require("./graph/index"), exports);
17
17
  __exportStar(require("./lockfile"), exports);
18
18
  __exportStar(require("./paths"), exports);
19
19
  __exportStar(require("./scope"), exports);
20
+ __exportStar(require("./types/PackageGraph"), exports);
20
21
  __exportStar(require("./types/PackageInfo"), exports);
21
22
  __exportStar(require("./types/WorkspaceInfo"), exports);
22
23
  __exportStar(require("./workspaces/findWorkspacePath"), exports);
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.infoFromPackageJson = void 0;
4
4
  function infoFromPackageJson(packageJson, packageJsonPath) {
5
- return Object.assign({ packageJsonPath }, packageJson);
5
+ return {
6
+ packageJsonPath,
7
+ ...packageJson,
8
+ };
6
9
  }
7
10
  exports.infoFromPackageJson = infoFromPackageJson;
@@ -69,7 +69,7 @@ async function parseLockFile(packageRoot) {
69
69
  try {
70
70
  npmLockJson = fs_1.default.readFileSync(npmLockPath, "utf-8");
71
71
  }
72
- catch (_a) {
72
+ catch {
73
73
  throw new Error("Couldn’t parse package-lock.json.");
74
74
  }
75
75
  const npmLock = JSON.parse(npmLockJson.toString());
@@ -1,2 +1,2 @@
1
1
  import { ParsedLock, NpmLockFile } from "./types";
2
- export declare const parseNpmLock: (lock: NpmLockFile) => ParsedLock;
2
+ export declare function parseNpmLock(lock: NpmLockFile): ParsedLock;
@@ -2,21 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseNpmLock = void 0;
4
4
  const nameAtVersion_1 = require("./nameAtVersion");
5
- /**
6
- * formatNpmLock reformats the dependencies object, so the key includes the version, similarly to yarn.lock. For
7
- * example, `"@microsoft/task-scheduler": { }` will become `"@microsoft/task-scheduler@2.7.1": { }`.
8
- */
9
- const formatNpmLock = (previousValue, currentValue) => {
10
- const [key, dependency] = currentValue;
11
- previousValue[(0, nameAtVersion_1.nameAtVersion)(key, dependency.version)] = dependency;
12
- return previousValue;
13
- };
14
- const parseNpmLock = (lock) => {
5
+ function parseNpmLock(lock) {
15
6
  var _a;
16
- const dependencies = Object.entries((_a = lock.dependencies) !== null && _a !== void 0 ? _a : {}).reduce(formatNpmLock, {});
7
+ // Re-format the dependencies object so that the key includes the version, similarly to yarn.lock.
8
+ // For example, `"@microsoft/task-scheduler": { }` will become `"@microsoft/task-scheduler@2.7.1": { }`.
9
+ const dependencies = Object.fromEntries(Object.entries((_a = lock.dependencies) !== null && _a !== void 0 ? _a : {}).map(([key, dep]) => [(0, nameAtVersion_1.nameAtVersion)(key, dep.version), dep]));
17
10
  return {
18
11
  object: dependencies,
19
12
  type: "success",
20
13
  };
21
- };
14
+ }
22
15
  exports.parseNpmLock = parseNpmLock;
package/lib/paths.js CHANGED
@@ -55,7 +55,7 @@ function findProjectRoot(cwd) {
55
55
  try {
56
56
  workspaceRoot = (0, getWorkspaceRoot_1.getWorkspaceRoot)(cwd);
57
57
  }
58
- catch (_a) { }
58
+ catch { }
59
59
  return workspaceRoot || findGitRoot(cwd);
60
60
  }
61
61
  exports.findProjectRoot = findProjectRoot;
@@ -8,7 +8,3 @@ export interface PackageGraph {
8
8
  packages: string[];
9
9
  dependencies: PackageDependency[];
10
10
  }
11
- /** Package graph visitor is called as it visits every package in dependency order */
12
- export interface PackageGraphVisitor {
13
- (pkg: string, dependencies: string[], dependents: string[]): void;
14
- }
@@ -16,7 +16,7 @@ function getWorkspacePackageInfo(workspacePaths) {
16
16
  try {
17
17
  packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath, "utf-8"));
18
18
  }
19
- catch (_a) {
19
+ catch {
20
20
  return returnValue;
21
21
  }
22
22
  return [
@@ -24,7 +24,10 @@ function getWorkspacePackageInfo(workspacePaths) {
24
24
  {
25
25
  name: packageJson.name,
26
26
  path: workspacePath,
27
- packageJson: Object.assign(Object.assign({}, packageJson), { packageJsonPath }),
27
+ packageJson: {
28
+ ...packageJson,
29
+ packageJsonPath,
30
+ },
28
31
  },
29
32
  ];
30
33
  }, []);
@@ -27,7 +27,7 @@ function getLernaWorkspaces(cwd) {
27
27
  const workspaceInfo = (0, getWorkspacePackageInfo_1.getWorkspacePackageInfo)(packagePaths);
28
28
  return workspaceInfo;
29
29
  }
30
- catch (_a) {
30
+ catch {
31
31
  return [];
32
32
  }
33
33
  }
@@ -44,7 +44,7 @@ function getWorkspaceInfoFromWorkspaceRoot(packageJsonWorkspacesRoot) {
44
44
  const workspaceInfo = (0, getWorkspacePackageInfo_1.getWorkspacePackageInfo)(packagePaths);
45
45
  return workspaceInfo;
46
46
  }
47
- catch (_a) {
47
+ catch {
48
48
  return [];
49
49
  }
50
50
  }
@@ -26,7 +26,7 @@ function getPnpmWorkspaces(cwd) {
26
26
  const workspaceInfo = (0, getWorkspacePackageInfo_1.getWorkspacePackageInfo)(packagePaths);
27
27
  return workspaceInfo;
28
28
  }
29
- catch (_a) {
29
+ catch {
30
30
  return [];
31
31
  }
32
32
  }
@@ -25,7 +25,7 @@ function getRushWorkspaces(cwd) {
25
25
  const root = path_1.default.dirname(rushJsonPath);
26
26
  return (0, getWorkspacePackageInfo_1.getWorkspacePackageInfo)(rushConfig.projects.map((project) => path_1.default.join(root, project.projectFolder)));
27
27
  }
28
- catch (_a) {
28
+ catch {
29
29
  return [];
30
30
  }
31
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "workspace-tools",
3
- "version": "0.25.4",
3
+ "version": "0.26.2",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +14,7 @@
14
14
  "scripts": {
15
15
  "build": "tsc",
16
16
  "build:docs": "typedoc src/index.ts",
17
- "release:docs": "typedoc src/index.ts && gh-pages -d docs",
17
+ "release:docs": "yarn build:docs && gh-pages -d docs",
18
18
  "change": "beachball change",
19
19
  "checkchange": "beachball check",
20
20
  "format": "prettier --write .",
@@ -37,12 +37,12 @@
37
37
  "@types/jest": "28.1.6",
38
38
  "@types/jju": "1.4.2",
39
39
  "@types/micromatch": "4.0.2",
40
- "@types/node": "13.13.5",
40
+ "@types/node": "14.18.23",
41
41
  "@types/tmp": "0.2.3",
42
42
  "@types/yarnpkg__lockfile": "1.1.5",
43
- "beachball": "2.26.0",
43
+ "beachball": "2.26.1",
44
44
  "fs-extra": "10.1.0",
45
- "gh-pages": "3.2.3",
45
+ "gh-pages": "4.0.0",
46
46
  "jest": "28.1.3",
47
47
  "prettier": "2.7.1",
48
48
  "tmp": "0.2.1",