@monorepolint/utils 0.5.0-alpha.97 → 0.5.0-beta.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.
Files changed (79) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/package.json +43 -20
  3. package/src/AggregateTiming.ts +1 -2
  4. package/src/CachingHost.ts +9 -7
  5. package/src/Host.ts +1 -1
  6. package/src/PackageJson.ts +2 -1
  7. package/src/SimpleHost.ts +3 -4
  8. package/src/Table.ts +1 -2
  9. package/src/Timing.ts +1 -2
  10. package/src/__tests__/CachingHost.spec.ts +5 -5
  11. package/src/findWorkspaceDir.ts +11 -3
  12. package/src/getPackageNameToDir.ts +4 -5
  13. package/src/getWorkspacePackageDirs.ts +32 -15
  14. package/src/index.ts +13 -13
  15. package/src/matchesAnyGlob.ts +9 -8
  16. package/src/mutateJson.ts +2 -3
  17. package/tsconfig.json +7 -2
  18. package/lib/AggregateTiming.d.ts +0 -15
  19. package/lib/AggregateTiming.d.ts.map +0 -1
  20. package/lib/AggregateTiming.js +0 -70
  21. package/lib/AggregateTiming.js.map +0 -1
  22. package/lib/CachingHost.d.ts +0 -39
  23. package/lib/CachingHost.d.ts.map +0 -1
  24. package/lib/CachingHost.js +0 -366
  25. package/lib/CachingHost.js.map +0 -1
  26. package/lib/Host.d.ts +0 -38
  27. package/lib/Host.d.ts.map +0 -1
  28. package/lib/Host.js +0 -9
  29. package/lib/Host.js.map +0 -1
  30. package/lib/PackageJson.d.ts +0 -19
  31. package/lib/PackageJson.d.ts.map +0 -1
  32. package/lib/PackageJson.js +0 -9
  33. package/lib/PackageJson.js.map +0 -1
  34. package/lib/SimpleHost.d.ts +0 -35
  35. package/lib/SimpleHost.d.ts.map +0 -1
  36. package/lib/SimpleHost.js +0 -56
  37. package/lib/SimpleHost.js.map +0 -1
  38. package/lib/Table.d.ts +0 -53
  39. package/lib/Table.d.ts.map +0 -1
  40. package/lib/Table.js +0 -234
  41. package/lib/Table.js.map +0 -1
  42. package/lib/Timing.d.ts +0 -9
  43. package/lib/Timing.d.ts.map +0 -1
  44. package/lib/Timing.js +0 -57
  45. package/lib/Timing.js.map +0 -1
  46. package/lib/__tests__/CachingHost.spec.d.ts +0 -8
  47. package/lib/__tests__/CachingHost.spec.d.ts.map +0 -1
  48. package/lib/__tests__/CachingHost.spec.js +0 -178
  49. package/lib/__tests__/CachingHost.spec.js.map +0 -1
  50. package/lib/findWorkspaceDir.d.ts +0 -9
  51. package/lib/findWorkspaceDir.d.ts.map +0 -1
  52. package/lib/findWorkspaceDir.js +0 -34
  53. package/lib/findWorkspaceDir.js.map +0 -1
  54. package/lib/getPackageNameToDir.d.ts +0 -14
  55. package/lib/getPackageNameToDir.d.ts.map +0 -1
  56. package/lib/getPackageNameToDir.js +0 -31
  57. package/lib/getPackageNameToDir.js.map +0 -1
  58. package/lib/getWorkspacePackageDirs.d.ts +0 -9
  59. package/lib/getWorkspacePackageDirs.d.ts.map +0 -1
  60. package/lib/getWorkspacePackageDirs.js +0 -46
  61. package/lib/getWorkspacePackageDirs.js.map +0 -1
  62. package/lib/index.d.ts +0 -20
  63. package/lib/index.d.ts.map +0 -1
  64. package/lib/index.js +0 -32
  65. package/lib/index.js.map +0 -1
  66. package/lib/matchesAnyGlob.d.ts +0 -17
  67. package/lib/matchesAnyGlob.d.ts.map +0 -1
  68. package/lib/matchesAnyGlob.js +0 -131
  69. package/lib/matchesAnyGlob.js.map +0 -1
  70. package/lib/mutateJson.d.ts +0 -9
  71. package/lib/mutateJson.d.ts.map +0 -1
  72. package/lib/mutateJson.js +0 -16
  73. package/lib/mutateJson.js.map +0 -1
  74. package/lib/nanosecondsToSanity.d.ts +0 -8
  75. package/lib/nanosecondsToSanity.d.ts.map +0 -1
  76. package/lib/nanosecondsToSanity.js +0 -14
  77. package/lib/nanosecondsToSanity.js.map +0 -1
  78. package/tsconfig.tsbuildinfo +0 -1
  79. /package/{jest.config.js → jest.config.cjs} +0 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @monorepolint/utils
2
+
3
+ ## 0.5.0-beta.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 45fb496: I failed to take good notes over the last few years. Sorry.
package/package.json CHANGED
@@ -1,37 +1,60 @@
1
1
  {
2
2
  "name": "@monorepolint/utils",
3
- "version": "0.5.0-alpha.97+b462dc0",
3
+ "version": "0.5.0-beta.0",
4
4
  "author": "Eric L Anderson (https://github.com/ericanderson)",
5
5
  "contributors": [
6
6
  "Mac Lockard (https://github.com/maclockard)"
7
7
  ],
8
8
  "url": "https://github.com/monorepolint/monorepolint",
9
9
  "license": "MIT",
10
- "main": "lib/index.js",
11
- "typings": "lib/index.d.ts",
12
- "scripts": {
13
- "clean": "rm -rf build lib node_modules *.tgz tsconfig.tsbuildinfo",
14
- "compile:typescript": "../../node_modules/.bin/tsc",
15
- "lint": "../../node_modules/.bin/tslint --config ../../tslint.json --project .",
16
- "lint:typescript": "../../node_modules/.bin/tslint --config ../../tslint.json --project .",
17
- "test": "../../node_modules/.bin/jest --colors --passWithNoTests",
18
- "test:watch": "../../node_modules/.bin/jest --colors --passWithNoTests --watch"
10
+ "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./build/types/index.d.ts",
14
+ "import": "./build/js/index.js"
15
+ },
16
+ "./*": {
17
+ "types": "./build/types/public/*.d.ts",
18
+ "import": "./build/js/public/*.js"
19
+ }
20
+ },
21
+ "engines": {
22
+ "node": ">=18"
19
23
  },
20
24
  "dependencies": {
21
- "@pnpm/find-workspace-dir": "^3.0.3",
22
- "@pnpm/find-workspace-packages": "^3.1.42",
23
- "@pnpm/logger": "^4.0.0",
24
- "glob": "^7.1.3",
25
+ "find-packages": "^10.0.4",
26
+ "find-up": "^7.0.0",
27
+ "glob": "^10.3.12",
25
28
  "micromatch": "^4.0.5",
26
- "tslib": "^2.3.1"
29
+ "read-yaml-file": "^2.1.0",
30
+ "tslib": "^2.6.2"
27
31
  },
28
32
  "devDependencies": {
29
- "@types/glob": "^7.1.1",
30
- "@types/micromatch": "^2.3.31",
31
- "@types/node": "^14.0.12"
33
+ "@jest/globals": "^29.7.0",
34
+ "@types/glob": "^8.1.0",
35
+ "@types/jest": "^29.5.12",
36
+ "@types/micromatch": "^4.0.7",
37
+ "@types/node": "^18.18.14",
38
+ "@typescript-eslint/eslint-plugin": "^7.7.1",
39
+ "@typescript-eslint/parser": "^7.7.1",
40
+ "eslint": "^9.1.1",
41
+ "jest": "^29.7.0",
42
+ "prettier": "^3.2.5",
43
+ "ts-jest": "^29.1.2",
44
+ "tslib": "^2.6.2",
45
+ "tsup": "^8.0.2",
46
+ "typescript": "^5.4.5"
32
47
  },
33
48
  "publishConfig": {
34
49
  "access": "public"
35
50
  },
36
- "gitHead": "b462dc0b8b337b9bd2e6733934bb3c0f9781cb92"
37
- }
51
+ "gitHead": "74320e31cfce7555aece7a98d71d01d2f329be0f",
52
+ "scripts": {
53
+ "clean": "rm -rf build dist lib node_modules *.tgz tsconfig.tsbuildinfo",
54
+ "compile-typescript": "tsc --build",
55
+ "lint": "eslint .",
56
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest --colors --passWithNoTests",
57
+ "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --colors --passWithNoTests --watch",
58
+ "transpile-typescript": "tsup --config ../../tsup.config.cjs"
59
+ }
60
+ }
@@ -6,8 +6,7 @@
6
6
  */
7
7
  // tslint:disable:no-console
8
8
 
9
- import { Table } from "./Table";
10
-
9
+ import { Table } from "./Table.js";
11
10
  export class AggregateTiming {
12
11
  #data = new Map<string, { count: number; total: bigint }>();
13
12
  #last: { count: number; total: bigint } | undefined;
@@ -5,9 +5,9 @@
5
5
  *
6
6
  */
7
7
 
8
- import * as realFs from "fs";
9
- import { Host } from "./Host";
10
- import * as path from "path";
8
+ import * as realFs from "node:fs";
9
+ import { Host } from "./Host.js";
10
+ import * as path from "node:path";
11
11
 
12
12
  function assertNoTombstone(node: Node): asserts node is Node & { tombstone?: false } {
13
13
  if (node.tombstone) {
@@ -129,11 +129,11 @@ export class CachingHost implements Host {
129
129
  #replaceNode(node: DirNode, newNode: Omit<DirTombstoneNode, "fullPath" | "parent" | "dir">): DirTombstoneNode;
130
130
  #replaceNode(node: Node, partialNewNode: Omit<Node, "fullPath" | "parent">): Node {
131
131
  if (!node.parent) throw new Error("Cannot replace root node");
132
- const newNode = {
132
+ const newNode: Node = {
133
133
  ...partialNewNode,
134
134
  fullPath: node.fullPath,
135
135
  parent: node.parent,
136
- dir: (node as any).dir,
136
+ dir: (node as DirNode).dir,
137
137
  } as Node;
138
138
  node.parent.dir.set(path.basename(node.fullPath), newNode);
139
139
  return newNode;
@@ -238,7 +238,9 @@ export class CachingHost implements Host {
238
238
  assertType(linkedNode, "dir");
239
239
  curNode = linkedNode;
240
240
  }
241
- curNode = curNode.dir.get(part) ?? this.#stubify(path.join(curNode.fullPath, part), curNode as any);
241
+ assertType(curNode, "dir");
242
+ assertNoTombstone(curNode);
243
+ curNode = curNode.dir.get(part) ?? this.#stubify(path.join(curNode.fullPath, part), curNode);
242
244
  curPath = path.join(curPath, part);
243
245
  }
244
246
  } catch (e) {
@@ -480,7 +482,7 @@ export class CachingHost implements Host {
480
482
  }
481
483
 
482
484
  flush() {
483
- const promises: Promise<any>[] = [];
485
+ const promises: Promise<unknown>[] = [];
484
486
  for (const rootNode of this.#trees.values()) {
485
487
  promises.push(this.#flushDirNode(rootNode));
486
488
  }
package/src/Host.ts CHANGED
@@ -9,7 +9,7 @@ export interface Host {
9
9
  /**
10
10
  * Reads and parses a json file.
11
11
  */
12
- readJson(filename: string): any;
12
+ readJson(filename: string): unknown;
13
13
 
14
14
  /**
15
15
  * Writes a json file.
@@ -11,11 +11,12 @@ export interface PackageJson {
11
11
  dependencies?: Record<string, string>;
12
12
  devDependencies?: Record<string, string>;
13
13
  peerDependencies?: Record<string, string>;
14
+ optionalDependencies?: Record<string, string>;
14
15
  workspaces?:
15
16
  | {
16
17
  packages?: string[];
17
18
  nohoist?: string[];
18
19
  }
19
20
  | string[];
20
- [otherKey: string]: any;
21
+ [otherKey: string]: unknown;
21
22
  }
package/src/SimpleHost.ts CHANGED
@@ -7,8 +7,7 @@
7
7
 
8
8
  import * as realFs from "fs";
9
9
 
10
- import { Host } from "./Host";
11
-
10
+ import { Host } from "./Host.js";
12
11
  export class SimpleHost implements Host {
13
12
  constructor(private fs: typeof realFs = realFs) {}
14
13
  mkdir(directoryPath: string, opts?: { recursive: boolean }): void {
@@ -24,7 +23,7 @@ export class SimpleHost implements Host {
24
23
 
25
24
  writeFile(path: string, buffer: Buffer): void;
26
25
  writeFile(path: string, body: string, opts: { encoding: BufferEncoding }): void;
27
- writeFile(path: any, body: any, opts?: { encoding: BufferEncoding }): any {
26
+ writeFile(path: string, body: string | Buffer, opts?: { encoding: BufferEncoding }): void {
28
27
  if (opts) {
29
28
  this.fs.writeFileSync(path, body, { encoding: opts.encoding });
30
29
  } else {
@@ -34,7 +33,7 @@ export class SimpleHost implements Host {
34
33
  readFile(path: string, opts?: undefined): Buffer;
35
34
  readFile(path: string, opts: { encoding: BufferEncoding }): string;
36
35
  readFile(path: string, opts: { asJson: true }): object;
37
- readFile(path: any, opts?: { encoding?: BufferEncoding; asJson?: boolean }): string | object | Buffer {
36
+ readFile(path: string, opts?: { encoding?: BufferEncoding; asJson?: boolean }): string | object | Buffer {
38
37
  if (opts?.asJson) {
39
38
  return JSON.parse(this.fs.readFileSync(path, "utf-8"));
40
39
  }
package/src/Table.ts CHANGED
@@ -5,8 +5,7 @@
5
5
  *
6
6
  */
7
7
  // tslint:disable:no-console
8
- import { nanosecondsToSanity } from "./nanosecondsToSanity";
9
-
8
+ import { nanosecondsToSanity } from "./nanosecondsToSanity.js";
10
9
  type HeaderFooterHelper<HB, FB, H, F> = (HB extends true ? { header: H } : { header?: H }) &
11
10
  (FB extends true ? { footer: F } : { footer?: F });
12
11
 
package/src/Timing.ts CHANGED
@@ -5,8 +5,7 @@
5
5
  *
6
6
  */
7
7
  // tslint:disable:no-console
8
- import { Table } from "./Table";
9
-
8
+ import { Table } from "./Table.js";
10
9
  export class Timing {
11
10
  #starts: Array<{ name?: string; start: bigint }> = [];
12
11
  constructor(private title: string) {
@@ -4,11 +4,11 @@
4
4
  * Licensed under the MIT license. See LICENSE file in the project root for details.
5
5
  *
6
6
  */
7
-
8
- import { CachingHost } from "../CachingHost";
9
- import * as realfs from "fs";
10
- import * as path from "path";
11
- import * as os from "os";
7
+ import { describe, expect, it, beforeEach } from "@jest/globals";
8
+ import { CachingHost } from "../CachingHost.js";
9
+ import * as realfs from "node:fs";
10
+ import * as path from "node:path";
11
+ import * as os from "node:os";
12
12
 
13
13
  interface TestCase<T> {
14
14
  getFs: () => T;
@@ -6,9 +6,17 @@
6
6
  */
7
7
 
8
8
  import * as path from "path";
9
- import { Host } from "./Host";
10
- import { PackageJson } from "./PackageJson";
11
- import findPnpmWorkspaceDir from "@pnpm/find-workspace-dir";
9
+ import { Host } from "./Host.js";
10
+ import { PackageJson } from "./PackageJson.js";
11
+ import * as fs from "fs";
12
+ import { findUp } from "find-up";
13
+
14
+ export async function findPnpmWorkspaceDir(cwd: string) {
15
+ const workspaceManifestLocation = await findUp("pnpm-workspace.yaml", {
16
+ cwd: await fs.promises.realpath(cwd),
17
+ });
18
+ return workspaceManifestLocation && path.dirname(workspaceManifestLocation);
19
+ }
12
20
 
13
21
  export async function findWorkspaceDir(
14
22
  host: Pick<Host, "readJson" | "exists">,
@@ -6,17 +6,16 @@
6
6
  */
7
7
 
8
8
  import { join as pathJoin } from "path";
9
- import { getWorkspacePackageDirs } from "./getWorkspacePackageDirs";
10
- import { Host } from "./Host";
11
- import { PackageJson } from "./PackageJson";
12
-
9
+ import { getWorkspacePackageDirs } from "./getWorkspacePackageDirs.js";
10
+ import { Host } from "./Host.js";
11
+ import { PackageJson } from "./PackageJson.js";
13
12
  /**
14
13
  * returns a map of package names to their directories in the workspace.
15
14
  * if `resolvePaths` is true, the returned directory names are absolute paths
16
15
  * resolved against the `workspaceDir`.
17
16
  */
18
17
  export async function getPackageNameToDir(
19
- host: Pick<Host, "readJson">,
18
+ host: Pick<Host, "readJson" | "exists">,
20
19
  workspaceDir: string,
21
20
  resolvePaths: boolean = false
22
21
  ) {
@@ -6,42 +6,59 @@
6
6
  */
7
7
 
8
8
  import { existsSync } from "fs";
9
- import glob from "glob";
10
- import { join as pathJoin, resolve as pathResolve } from "path";
11
- import { Host } from "./Host";
12
- import { PackageJson } from "./PackageJson";
13
- import findPNPMWorkspacePackages from "@pnpm/find-workspace-packages";
9
+ import * as glob from "glob";
10
+ import * as path from "node:path";
11
+ import * as fs from "node:fs";
12
+ import { Host } from "./Host.js";
13
+ import { PackageJson } from "./PackageJson.js";
14
+ import * as readYamlFile from "read-yaml-file";
15
+ import { findPackages } from "find-packages";
16
+
17
+ async function findPNPMWorkspacePackages(workspaceRoot: string) {
18
+ workspaceRoot = fs.realpathSync(workspaceRoot);
19
+ const workspaceManifest = await readYamlFile.default<{ packages?: string[] }>(
20
+ path.join(workspaceRoot, "pnpm-workspace.yaml")
21
+ );
22
+
23
+ return findPackages(workspaceRoot, {
24
+ ignore: ["**/node_modules/**", "**/bower_components/**"],
25
+ includeRoot: true,
26
+ patterns: workspaceManifest.packages,
27
+ });
28
+ }
14
29
 
15
30
  export async function getWorkspacePackageDirs(
16
- host: Pick<Host, "readJson">,
31
+ host: Pick<Host, "readJson" | "exists">,
17
32
  workspaceDir: string,
18
33
  resolvePaths: boolean = false
19
34
  ) {
20
- const ret: string[] = [];
35
+ const packageJson = host.readJson(path.join(workspaceDir, "package.json")) as PackageJson;
21
36
 
22
- const packageJson: PackageJson = host.readJson(pathJoin(workspaceDir, "package.json"));
23
-
24
- if (packageJson.workspaces === undefined) {
25
- // We may be in a monorepo that uses PNPM and may not define workspaces in the root package.json
37
+ const isPnpmWorkspace = host.exists(path.join(workspaceDir, "pnpm-workspace.yaml"));
38
+ if (isPnpmWorkspace) {
26
39
  const workspacePackages = await findPNPMWorkspacePackages(workspaceDir);
27
40
  if (workspacePackages.length === 0) {
28
41
  throw new Error("Invalid workspaceDir: " + workspaceDir);
29
42
  }
30
- ret.push(...workspacePackages.map((project) => project.dir));
31
- return ret;
43
+ return workspacePackages.map((project) => project.dir).filter((d) => d !== workspaceDir);
44
+ }
45
+
46
+ if (!packageJson.workspaces) {
47
+ throw new Error("Unsupported! Monorepo is not backed by either pnpm nor yarn workspaces.");
32
48
  }
33
49
 
50
+ const ret: string[] = [];
34
51
  const packageGlobs = Array.isArray(packageJson.workspaces)
35
52
  ? packageJson.workspaces
36
53
  : packageJson.workspaces.packages || [];
37
54
 
38
55
  for (const pattern of packageGlobs) {
39
56
  for (const packagePath of glob.sync(pattern, { cwd: workspaceDir })) {
40
- const packageJsonPath = pathJoin(workspaceDir, packagePath, "package.json");
57
+ const packageJsonPath = path.join(workspaceDir, packagePath, "package.json");
41
58
 
42
59
  if (existsSync(packageJsonPath)) {
43
60
  if (resolvePaths === true) {
44
- ret.push(pathResolve(pathJoin(workspaceDir, packagePath)));
61
+ ret.push(path.resolve(path.join(workspaceDir, packagePath)));
45
62
  } else {
46
63
  ret.push(packagePath);
47
64
  }
package/src/index.ts CHANGED
@@ -5,16 +5,16 @@
5
5
  *
6
6
  */
7
7
 
8
- export { getWorkspacePackageDirs } from "./getWorkspacePackageDirs";
9
- export { mutateJson } from "./mutateJson";
10
- export { PackageJson } from "./PackageJson";
11
- export { findWorkspaceDir } from "./findWorkspaceDir";
12
- export { getPackageNameToDir } from "./getPackageNameToDir";
13
- export { Host } from "./Host";
14
- export { SimpleHost } from "./SimpleHost";
15
- export { CachingHost } from "./CachingHost";
16
- export { matchesAnyGlob } from "./matchesAnyGlob";
17
- export { nanosecondsToSanity } from "./nanosecondsToSanity";
18
- export { AggregateTiming } from "./AggregateTiming";
19
- export { Timing } from "./Timing";
20
- export { Table } from "./Table";
8
+ export { getWorkspacePackageDirs } from "./getWorkspacePackageDirs.js";
9
+ export { mutateJson } from "./mutateJson.js";
10
+ export { PackageJson } from "./PackageJson.js";
11
+ export { findWorkspaceDir } from "./findWorkspaceDir.js";
12
+ export { getPackageNameToDir } from "./getPackageNameToDir.js";
13
+ export { Host } from "./Host.js";
14
+ export { SimpleHost } from "./SimpleHost.js";
15
+ export { CachingHost } from "./CachingHost.js";
16
+ export { matchesAnyGlob } from "./matchesAnyGlob.js";
17
+ export { nanosecondsToSanity } from "./nanosecondsToSanity.js";
18
+ export { AggregateTiming } from "./AggregateTiming.js";
19
+ export { Timing } from "./Timing.js";
20
+ export { Table } from "./Table.js";
@@ -5,10 +5,9 @@
5
5
  *
6
6
  */
7
7
 
8
- import { makeRe } from "micromatch";
9
- import { nanosecondsToSanity } from "./nanosecondsToSanity";
10
- import { Table } from "./Table";
11
-
8
+ import micromatch from "micromatch";
9
+ import { nanosecondsToSanity } from "./nanosecondsToSanity.js";
10
+ import { Table } from "./Table.js";
12
11
  // This file requires a LOT of caching to be performant. We have three layers to avoid work.
13
12
 
14
13
  /**
@@ -65,9 +64,10 @@ export const matchesAnyGlob: MatchesAnyGlob = function matchesAnyGlobFunc(needle
65
64
  // N.B. true/false/undefined
66
65
  result = patternCache.get(needle); // only thing different from the inline is we need to reuse `result`
67
66
  if (result === undefined) {
68
- let regexp = compiledGlobCache.get(pattern);
67
+ let regexp: RegExp | undefined | false = compiledGlobCache.get(pattern);
69
68
  if (regexp === undefined) {
70
- regexp = makeRe(pattern);
69
+ regexp = micromatch.makeRe(pattern);
70
+ // if (regexp === false) throw new Error("bad glob");
71
71
  compiledGlobCache.set(pattern, regexp);
72
72
  }
73
73
 
@@ -127,9 +127,10 @@ export function needleInPattern(needle: string, pattern: string) {
127
127
  // N.B. true/false/undefined
128
128
  let result = patternCache.get(needle);
129
129
  if (result === undefined) {
130
- let regexp = compiledGlobCache.get(pattern);
130
+ let regexp: RegExp | undefined | false = compiledGlobCache.get(pattern);
131
131
  if (regexp === undefined) {
132
- regexp = makeRe(pattern);
132
+ regexp = micromatch.makeRe(pattern);
133
+ // if (regexp === false) throw new Error("bad glob");
133
134
  compiledGlobCache.set(pattern, regexp);
134
135
  }
135
136
 
package/src/mutateJson.ts CHANGED
@@ -5,10 +5,9 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Host } from "./Host";
9
-
8
+ import { Host } from "./Host.js";
10
9
  export function mutateJson<T extends object>(path: string, host: Host, mutator: (f: T) => T) {
11
- let file: T = host.readJson(path);
10
+ let file = host.readJson(path) as T;
12
11
  file = mutator(file);
13
12
  host.writeJson(path, file);
14
13
  }
package/tsconfig.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "extends": "../../tsconfig.base.json",
3
3
  "compilerOptions": {
4
- "outDir": "./lib",
5
- "rootDir": "./src"
4
+ "outDir": "./build/js",
5
+ "rootDir": "./src",
6
+ "declarationDir": "./build/types",
7
+ "tsBuildInfoFile": "./build/tsconfig.tsbuildinfo"
6
8
  },
9
+ "include": [
10
+ "src"
11
+ ],
7
12
  "references": []
8
13
  }
@@ -1,15 +0,0 @@
1
- /*!
2
- * Copyright 2022 Palantir Technologies, Inc.
3
- *
4
- * Licensed under the MIT license. See LICENSE file in the project root for details.
5
- *
6
- */
7
- export declare class AggregateTiming {
8
- #private;
9
- private title;
10
- constructor(title: string);
11
- start(name: string): void;
12
- stop(): void;
13
- printResults(): void;
14
- }
15
- //# sourceMappingURL=AggregateTiming.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AggregateTiming.d.ts","sourceRoot":"","sources":["../src/AggregateTiming.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,qBAAa,eAAe;;IAId,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,MAAM;IAE1B,KAAK,CAAC,IAAI,EAAE,MAAM;IAiBlB,IAAI;IAQJ,YAAY;CA6BpB"}
@@ -1,70 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright 2022 Palantir Technologies, Inc.
4
- *
5
- * Licensed under the MIT license. See LICENSE file in the project root for details.
6
- *
7
- */
8
- // tslint:disable:no-console
9
- var _AggregateTiming_data, _AggregateTiming_last;
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.AggregateTiming = void 0;
12
- const tslib_1 = require("tslib");
13
- const Table_1 = require("./Table");
14
- class AggregateTiming {
15
- constructor(title) {
16
- this.title = title;
17
- _AggregateTiming_data.set(this, new Map());
18
- _AggregateTiming_last.set(this, void 0);
19
- }
20
- start(name) {
21
- const time = process.hrtime.bigint();
22
- if (tslib_1.__classPrivateFieldGet(this, _AggregateTiming_last, "f")) {
23
- tslib_1.__classPrivateFieldGet(this, _AggregateTiming_last, "f").total += time;
24
- }
25
- let data = tslib_1.__classPrivateFieldGet(this, _AggregateTiming_data, "f").get(name);
26
- if (data === undefined) {
27
- data = { count: 1, total: -time };
28
- tslib_1.__classPrivateFieldGet(this, _AggregateTiming_data, "f").set(name, data);
29
- }
30
- else {
31
- data.total -= time;
32
- data.count++;
33
- }
34
- tslib_1.__classPrivateFieldSet(this, _AggregateTiming_last, data, "f");
35
- }
36
- stop() {
37
- const time = process.hrtime.bigint();
38
- if (tslib_1.__classPrivateFieldGet(this, _AggregateTiming_last, "f")) {
39
- tslib_1.__classPrivateFieldGet(this, _AggregateTiming_last, "f").total += time;
40
- tslib_1.__classPrivateFieldSet(this, _AggregateTiming_last, undefined, "f");
41
- }
42
- }
43
- printResults() {
44
- const table = new Table_1.Table({
45
- sortColumn: -1,
46
- showFooter: true,
47
- showHeader: true,
48
- title: this.title,
49
- columns: [
50
- {
51
- header: "Duration",
52
- type: "bigint",
53
- renderAs: "nanoseconds",
54
- footer: { aggregate: "sum" },
55
- },
56
- { header: "Task", type: "string", alignment: "left", footer: "TOTAL" },
57
- { header: "Count", type: "bigint", footer: { aggregate: "sum" } },
58
- { header: "Avg", type: "bigint", footer: { aggregate: "average" } },
59
- ],
60
- });
61
- for (const [name, value] of tslib_1.__classPrivateFieldGet(this, _AggregateTiming_data, "f")) {
62
- table.addRow(value.total, name, BigInt(value.count), // fixme this can be a number later
63
- value.total / BigInt(value.count));
64
- }
65
- table.print();
66
- }
67
- }
68
- exports.AggregateTiming = AggregateTiming;
69
- _AggregateTiming_data = new WeakMap(), _AggregateTiming_last = new WeakMap();
70
- //# sourceMappingURL=AggregateTiming.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AggregateTiming.js","sourceRoot":"","sources":["../src/AggregateTiming.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;AACH,4BAA4B;;;;;AAE5B,mCAAgC;AAEhC,MAAa,eAAe;IAI1B,YAAoB,KAAa;QAAb,UAAK,GAAL,KAAK,CAAQ;QAHjC,gCAAQ,IAAI,GAAG,EAA4C,EAAC;QAC5D,wCAAoD;IAEhB,CAAC;IAE9B,KAAK,CAAC,IAAY;QACvB,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACrC,IAAI,+BAAA,IAAI,6BAAM,EAAE;YACd,+BAAA,IAAI,6BAAM,CAAC,KAAK,IAAI,IAAI,CAAC;SAC1B;QAED,IAAI,IAAI,GAAG,+BAAA,IAAI,6BAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,IAAI,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;YAClC,+BAAA,IAAI,6BAAM,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SAC5B;aAAM;YACL,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC;YACnB,IAAI,CAAC,KAAK,EAAE,CAAC;SACd;QACD,+BAAA,IAAI,yBAAS,IAAI,MAAA,CAAC;IACpB,CAAC;IAEM,IAAI;QACT,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACrC,IAAI,+BAAA,IAAI,6BAAM,EAAE;YACd,+BAAA,IAAI,6BAAM,CAAC,KAAK,IAAI,IAAI,CAAC;YACzB,+BAAA,IAAI,yBAAS,SAAS,MAAA,CAAC;SACxB;IACH,CAAC;IAEM,YAAY;QACjB,MAAM,KAAK,GAAG,IAAI,aAAK,CAAmC;YACxD,UAAU,EAAE,CAAC,CAAC;YACd,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,IAAI;YAChB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,OAAO,EAAE;gBACP;oBACE,MAAM,EAAE,UAAU;oBAClB,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,aAAa;oBACvB,MAAM,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE;iBAC7B;gBACD,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE;gBACtE,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE;gBACjE,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE;aACpE;SACF,CAAC,CAAC;QAEH,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,+BAAA,IAAI,6BAAM,EAAE;YACtC,KAAK,CAAC,MAAM,CACV,KAAK,CAAC,KAAK,EACX,IAAI,EACJ,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,mCAAmC;YACxD,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAClC,CAAC;SACH;QACD,KAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;CACF;AA5DD,0CA4DC"}
@@ -1,39 +0,0 @@
1
- /*!
2
- * Copyright 2022 Palantir Technologies, Inc.
3
- *
4
- * Licensed under the MIT license. See LICENSE file in the project root for details.
5
- *
6
- */
7
- /// <reference types="node" />
8
- /// <reference types="graceful-fs" />
9
- import * as realFs from "fs";
10
- import { Host } from "./Host";
11
- export declare class CachingHost implements Host {
12
- #private;
13
- private fs;
14
- constructor(fs?: Pick<typeof realFs, "existsSync" | "lstatSync" | "mkdirSync" | "promises" | "readdirSync" | "readFileSync" | "readlinkSync" | "realpathSync" | "rmdirSync" | "statSync" | "unlinkSync" | "writeFileSync">);
15
- mkdir(filePath: string, opts?: {
16
- recursive: boolean;
17
- }): void;
18
- rmdir(directoryPath: string): void;
19
- exists(filePath: string): boolean;
20
- readFile(filePath: string, opts?: undefined): Buffer;
21
- readFile(filePath: string, opts: {
22
- encoding: BufferEncoding;
23
- }): string;
24
- readFile(filePath: string, opts: {
25
- asJson: true;
26
- }): object;
27
- writeFile(filePath: string, buffer: Buffer): void;
28
- writeFile(filePath: string, body: string, opts: {
29
- encoding: BufferEncoding;
30
- }): void;
31
- writeFile(filePath: string, body: string, opts: {
32
- encoding: BufferEncoding;
33
- }): void;
34
- deleteFile(filePath: string): void;
35
- readJson(filePath: string): object;
36
- writeJson(filePath: string, o: object): void;
37
- flush(): Promise<any[]>;
38
- }
39
- //# sourceMappingURL=CachingHost.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CachingHost.d.ts","sourceRoot":"","sources":["../src/CachingHost.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;;AAEH,OAAO,KAAK,MAAM,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAsF9B,qBAAa,WAAY,YAAW,IAAI;;IAKpC,OAAO,CAAC,EAAE;gBAAF,EAAE,GAAE,IAAI,CACd,OAAO,MAAM,EACX,YAAY,GACZ,WAAW,GACX,WAAW,GACX,UAAU,GACV,aAAa,GACb,cAAc,GACd,cAAc,GACd,cAAc,GACd,WAAW,GACX,UAAU,GACV,YAAY,GACZ,eAAe,CACT;IA2JZ,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,GAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAyB,GAAG,IAAI;IAqClF,KAAK,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI;IAqBlC,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAKjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,MAAM;IACpD,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE;QAAE,QAAQ,EAAE,cAAc,CAAA;KAAE,GAAG,MAAM;IACtE,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE;QAAE,MAAM,EAAE,IAAI,CAAA;KAAE,GAAG,MAAM;IA8B1D,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IACjD,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE;QAAE,QAAQ,EAAE,cAAc,CAAA;KAAE,GAAG,IAAI;IACnF,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE;QAAE,QAAQ,EAAE,cAAc,CAAA;KAAE,GAAG,IAAI;IAgCnF,UAAU,CAAC,QAAQ,EAAE,MAAM;IAY3B,QAAQ,CAAC,QAAQ,EAAE,MAAM;IAIzB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI;IAoE5C,KAAK;CAON"}