@mxpicture/build-api 0.2.22 → 0.2.24

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 (58) hide show
  1. package/dist/barrel/Barrel.d.ts +3 -4
  2. package/dist/barrel/Barrel.js +27 -28
  3. package/dist/changes/Changes.d.ts +6 -0
  4. package/dist/changes/Changes.js +15 -0
  5. package/dist/changes/index.d.ts +1 -0
  6. package/dist/changes/index.js +2 -0
  7. package/dist/cleanup/Cleanup.d.ts +1 -4
  8. package/dist/cleanup/Cleanup.js +11 -15
  9. package/dist/common/common.json.d.ts +2 -0
  10. package/dist/common/common.json.js +3 -0
  11. package/dist/common/index.d.ts +1 -0
  12. package/dist/common/index.js +1 -0
  13. package/dist/deps/FixWorkspaceDeps.d.ts +6 -5
  14. package/dist/deps/FixWorkspaceDeps.js +31 -26
  15. package/dist/git/GitChanges.d.ts +8 -5
  16. package/dist/git/GitChanges.js +22 -17
  17. package/dist/git/git.util.d.ts +4 -0
  18. package/dist/git/git.util.js +6 -0
  19. package/dist/npmPublish/NpmPublisher.d.ts +3 -3
  20. package/dist/npmPublish/NpmPublisher.js +12 -17
  21. package/dist/osInfo/osInfo.common.d.ts +2 -0
  22. package/dist/osInfo/osInfo.common.js +4 -0
  23. package/dist/pkg/Pkg.d.ts +24 -0
  24. package/dist/pkg/Pkg.js +74 -0
  25. package/dist/pkg/SyncPkgVersion.d.ts +5 -6
  26. package/dist/pkg/SyncPkgVersion.js +14 -19
  27. package/dist/pkg/UpdatePackages.d.ts +4 -6
  28. package/dist/pkg/UpdatePackages.js +12 -11
  29. package/dist/pkg/index.d.ts +2 -0
  30. package/dist/pkg/index.js +2 -0
  31. package/dist/pkg/pkg.fs.d.ts +5 -0
  32. package/dist/pkg/pkg.fs.js +11 -0
  33. package/dist/types/index.d.ts +0 -1
  34. package/dist/types/index.js +0 -1
  35. package/dist/types/types.barrel.d.ts +5 -6
  36. package/dist/types/types.cleanup.d.ts +2 -2
  37. package/dist/types/types.deps.d.ts +5 -4
  38. package/dist/types/types.git.d.ts +2 -2
  39. package/dist/types/types.npm.d.ts +2 -2
  40. package/dist/types/types.package.d.ts +6 -12
  41. package/dist/types/types.run.d.ts +1 -5
  42. package/dist/vscode/vscode.settings.d.ts +2 -0
  43. package/dist/vscode/vscode.settings.js +4 -0
  44. package/dist/vscode/vscode.storage.d.ts +2 -0
  45. package/dist/vscode/vscode.storage.js +4 -0
  46. package/dist/workspace/Workspace.d.ts +25 -0
  47. package/dist/workspace/Workspace.js +70 -0
  48. package/dist/workspace/WorkspacePaths.d.ts +1 -7
  49. package/dist/workspace/WorkspacePaths.js +30 -30
  50. package/dist/workspace/index.d.ts +1 -1
  51. package/dist/workspace/index.js +1 -1
  52. package/dist/workspace/workspace.common.d.ts +2 -0
  53. package/dist/workspace/workspace.common.js +4 -0
  54. package/package.json +4 -4
  55. package/dist/types/types.changeset.d.ts +0 -2
  56. package/dist/types/types.changeset.js +0 -1
  57. package/dist/workspace/workspace.pkg.d.ts +0 -15
  58. package/dist/workspace/workspace.pkg.js +0 -123
@@ -1,17 +1,16 @@
1
1
  import { BarrelGroup, BarrelParams, BarrelResult } from "../types/types.barrel.js";
2
- import { WorkspacePaths } from "../workspace/WorkspacePaths.js";
2
+ import { Pkg } from "../pkg/Pkg.js";
3
3
  export declare const DEFAULT_EXCLUDED_PATTERNS: RegExp[];
4
4
  export declare const DEFAULT_HEADER = "// This file is auto-generated. Do not edit manually.\n";
5
5
  export declare const runBarrel: (params: BarrelParams) => Promise<void>;
6
6
  export declare class Barrel {
7
- protected readonly paths: WorkspacePaths;
8
7
  protected readonly excludes: RegExp[];
9
8
  protected readonly fileHeader: string;
10
- constructor(paths: WorkspacePaths, excludes: RegExp[], fileHeader: string);
9
+ constructor(excludes: RegExp[], fileHeader: string);
11
10
  run(): Promise<void>;
12
11
  protected isExcluded(fileName: string): boolean;
13
12
  protected persistBarrel(group: BarrelGroup): Promise<BarrelGroup>;
14
- protected updatePackageExports(packageDir: string, packageJsonPath: string, exports: Record<string, string>): Promise<void>;
13
+ protected updatePackageExports(pkg: Pkg, exports: Record<string, string>): Promise<void>;
15
14
  protected hasExportsChanged(a: Record<string, string> | undefined, b: Record<string, string> | undefined): boolean;
16
15
  protected extractExports(result: BarrelResult): Record<string, string>;
17
16
  }
@@ -1,12 +1,12 @@
1
1
  import { basename, dirname, join, relative } from "node:path";
2
2
  import { readdir, rm, writeFile } from "node:fs/promises";
3
3
  import { logInfo, logSuccess } from "../logger/Logger.js";
4
- import { WorkspacePaths } from "../workspace/WorkspacePaths.js";
5
- import { readPackageJsonThrow, writePackageJson, } from "../workspace/workspace.pkg.js";
4
+ import { initWorkspace, workspace } from "../workspace/Workspace.js";
6
5
  // /** File patterns to exclude from barrel exports */
7
6
  export const DEFAULT_EXCLUDED_PATTERNS = [
8
7
  /\.test\.ts$/,
9
8
  /\.spec\.ts$/,
9
+ /(^|\/)__tests__(\/|$)/,
10
10
  /\.d\.ts$/,
11
11
  /index\.ts$/,
12
12
  /(.+\/|^)src\/(.+\/|)scripts?\/.+\.m?ts$/,
@@ -14,28 +14,28 @@ export const DEFAULT_EXCLUDED_PATTERNS = [
14
14
  ];
15
15
  // /** Header comment added to every generated barrel file */
16
16
  export const DEFAULT_HEADER = "// This file is auto-generated. Do not edit manually.\n";
17
- export const runBarrel = async (params) => new Barrel(WorkspacePaths.instance(params.repoRoot, params.workspacesName), params.excludes ?? DEFAULT_EXCLUDED_PATTERNS, params.fileHeader ?? DEFAULT_HEADER).run();
17
+ export const runBarrel = async (params) => {
18
+ initWorkspace(params.repoRoot);
19
+ return new Barrel(params.excludes ?? DEFAULT_EXCLUDED_PATTERNS, params.fileHeader ?? DEFAULT_HEADER).run();
20
+ };
18
21
  export class Barrel {
19
- paths;
20
22
  excludes;
21
23
  fileHeader;
22
- constructor(paths, excludes, fileHeader) {
23
- this.paths = paths;
24
+ constructor(excludes, fileHeader) {
24
25
  this.excludes = excludes;
25
26
  this.fileHeader = fileHeader;
26
27
  }
27
28
  async run() {
28
- const packageDirs = (await readdir(this.paths.workspacesDir)).map((p) => join(this.paths.workspacesDir, p));
29
+ const ws = workspace();
30
+ await ws.read();
29
31
  const promises = [];
30
- for (const packageDir of packageDirs) {
32
+ for (const pkg of ws.packages) {
31
33
  try {
32
- const srcDirPath = join(packageDir, "src");
33
- const packageJsonPath = join(packageDir, "package.json");
34
- const items = (await readdir(srcDirPath, { recursive: true })).sort();
34
+ const items = (await readdir(pkg.srcPath, { recursive: true })).sort();
35
35
  let currentGroup;
36
36
  for (const item of items) {
37
37
  const filename = basename(item);
38
- const dirPath = join(srcDirPath, dirname(item));
38
+ const dirPath = join(pkg.srcPath, dirname(item));
39
39
  const filePath = join(dirPath, filename);
40
40
  if (dirPath !== currentGroup?.dirPath) {
41
41
  if (currentGroup)
@@ -43,8 +43,7 @@ export class Barrel {
43
43
  currentGroup = {
44
44
  dirPath,
45
45
  files: [],
46
- packageDir,
47
- packageJsonPath,
46
+ pkg,
48
47
  };
49
48
  }
50
49
  if (this.isExcluded(filePath) ||
@@ -62,18 +61,17 @@ export class Barrel {
62
61
  const barrelGroups = (await Promise.all(promises)).filter((prom) => prom.files.length > 0);
63
62
  const results = [];
64
63
  for (const barrelGroup of barrelGroups) {
65
- let found = results.find((res) => barrelGroup.packageDir === res.packageDir);
64
+ let found = results.find((res) => barrelGroup.dirPath === res.pkg.dirPath);
66
65
  if (!found) {
67
66
  found = {
68
67
  barrelDirs: [],
69
- packageDir: barrelGroup.packageDir,
70
- packageJsonPath: barrelGroup.packageJsonPath,
68
+ pkg: barrelGroup.pkg,
71
69
  };
72
70
  results.push(found);
73
71
  }
74
72
  found.barrelDirs.push(barrelGroup.dirPath);
75
73
  }
76
- await Promise.all(results.map(async (res) => this.updatePackageExports(res.packageDir, res.packageJsonPath, this.extractExports(res))));
74
+ await Promise.all(results.map(async (res) => this.updatePackageExports(res.pkg, this.extractExports(res))));
77
75
  }
78
76
  isExcluded(fileName) {
79
77
  return this.excludes.some((pattern) => pattern.test(fileName));
@@ -92,18 +90,19 @@ export class Barrel {
92
90
  await writeFile(barrelPath, content);
93
91
  return group;
94
92
  }
95
- async updatePackageExports(packageDir, packageJsonPath, exports) {
93
+ async updatePackageExports(pkg, exports) {
96
94
  try {
97
- const pkgName = relative(this.paths.workspacesDir, packageDir);
98
- logInfo(`šŸ“¦ updating ${pkgName} package.json ...`);
99
- const pkg = await readPackageJsonThrow(packageJsonPath);
100
- if (!this.hasExportsChanged(exports, pkg.exports)) {
101
- logInfo(`🧹 No changes in ${pkgName}, nothing to do`);
95
+ // const pkgName = relative(this.paths.workspacesDir, packageDir);
96
+ // // const pkgs = await workspace().loadPackages();
97
+ logInfo(`šŸ“¦ updating ${pkg.repoDirPath} package.json ...`);
98
+ // const pkg = await readPackageJsonThrow(packageJsonPath);
99
+ if (!this.hasExportsChanged(exports, pkg.content.exports)) {
100
+ logInfo(`🧹 No changes in ${pkg.repoDirPath}, nothing to do`);
102
101
  return;
103
102
  }
104
- pkg.exports = { ...exports };
105
- await writePackageJson(packageJsonPath, pkg);
106
- logSuccess(`āœ… ${pkgName} update successful`);
103
+ pkg.content.exports = { ...exports };
104
+ await pkg.write();
105
+ logSuccess(`āœ… ${pkg.repoDirPath} update successful`);
107
106
  }
108
107
  catch (error) {
109
108
  logInfo(error);
@@ -129,7 +128,7 @@ export class Barrel {
129
128
  extractExports(result) {
130
129
  const record = {};
131
130
  for (const barrelDir of result.barrelDirs) {
132
- const ex = relative(join(result.packageDir, "src"), barrelDir);
131
+ const ex = relative(join(result.pkg.srcPath, "src"), barrelDir);
133
132
  record[`./${ex}`] = `./dist/${ex}/index.js`;
134
133
  }
135
134
  record["./package.json"] = "./package.json";
@@ -0,0 +1,6 @@
1
+ import { GitChangedContent } from "../types/types.git.js";
2
+ export declare class Changes {
3
+ readonly rootDir: string;
4
+ constructor(rootDir: string);
5
+ protected readFiles(): Promise<GitChangedContent[]>;
6
+ }
@@ -0,0 +1,15 @@
1
+ import { lastCommitHash, lastTag } from "../git/git.util.js";
2
+ import { GitChangesTag } from "../git/GitChanges.js";
3
+ export class Changes {
4
+ rootDir;
5
+ constructor(rootDir) {
6
+ this.rootDir = rootDir;
7
+ }
8
+ async readFiles() {
9
+ const commitTag = (await lastTag(this.rootDir)) ?? (await lastCommitHash(this.rootDir));
10
+ if (!commitTag)
11
+ throw new Error("No last commit or tag found");
12
+ const gitc = new GitChangesTag(this.rootDir, commitTag);
13
+ return (await gitc.readChangedFiles()).files;
14
+ }
15
+ }
@@ -0,0 +1 @@
1
+ export * from "./Changes.js";
@@ -0,0 +1,2 @@
1
+ // This file is auto-generated. Do not edit manually.
2
+ export * from "./Changes.js";
@@ -1,15 +1,12 @@
1
1
  import { CleanupParams, ToBeDeleted, ToCleanup } from "../types/types.cleanup.js";
2
- import { WorkspacePaths } from "../workspace/WorkspacePaths.js";
3
2
  export declare const runCleanup: (params: CleanupParams) => Promise<void>;
4
3
  export declare class Cleanup {
5
- protected readonly paths: WorkspacePaths;
6
4
  protected readonly toBeDeleted: ToBeDeleted[];
7
- constructor(paths: WorkspacePaths, toBeDeleted: ToBeDeleted[]);
5
+ constructor(toBeDeleted: ToBeDeleted[]);
8
6
  run(): Promise<void>;
9
7
  read(): Promise<ToCleanup[]>;
10
8
  cleanup(toCleanups: ToCleanup[]): Promise<void>;
11
9
  cleanupSingle(toCleanup: ToCleanup): Promise<void>;
12
- protected readDir(dir: string): Promise<ToCleanup[]>;
13
10
  protected buildRemovePaths(basePath: string): ToCleanup[];
14
11
  protected move(toCleanup: ToCleanup): Promise<void>;
15
12
  protected remove(toCleanup: ToCleanup): Promise<void>;
@@ -1,7 +1,7 @@
1
- import { readdir, rename, rm } from "node:fs/promises";
1
+ import { rename, rm } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
- import { WorkspacePaths } from "../workspace/WorkspacePaths.js";
4
3
  import { logError, logInfo, logSuccess } from "../logger/Logger.js";
4
+ import { initWorkspace, workspace } from "../workspace/Workspace.js";
5
5
  // moveSuffix: e.g. mv node_modules node_modules_tmp && rm -rf node_modules_tmp (async)
6
6
  const DEFAULT_TO_BE_DELETED = [
7
7
  { name: "node_modules", moveSuffix: "_tmp" },
@@ -9,12 +9,13 @@ const DEFAULT_TO_BE_DELETED = [
9
9
  { name: "tsconfig.tsbuildinfo" },
10
10
  { name: ".tsbuildinfo" },
11
11
  ];
12
- export const runCleanup = async (params) => new Cleanup(WorkspacePaths.instance(params.repoRoot, params.workspacesName), params.toBeDeleted ?? DEFAULT_TO_BE_DELETED).run();
12
+ export const runCleanup = async (params) => {
13
+ initWorkspace(params.repoRoot);
14
+ return new Cleanup(params.toBeDeleted ?? DEFAULT_TO_BE_DELETED).run();
15
+ };
13
16
  export class Cleanup {
14
- paths;
15
17
  toBeDeleted;
16
- constructor(paths, toBeDeleted) {
17
- this.paths = paths;
18
+ constructor(toBeDeleted) {
18
19
  this.toBeDeleted = toBeDeleted;
19
20
  }
20
21
  async run() {
@@ -22,9 +23,10 @@ export class Cleanup {
22
23
  return this.cleanup(items);
23
24
  }
24
25
  async read() {
25
- const dirs = await readdir(this.paths.workspacesDir);
26
- const toCleanupsTmp = await Promise.all(dirs.map((dir) => this.readDir(dir)));
27
- const toCleanups = this.buildRemovePaths(this.paths.repoRoot);
26
+ const ws = workspace();
27
+ await ws.read();
28
+ const toCleanupsTmp = ws.packages.map((pkg) => this.buildRemovePaths(pkg.dirPath));
29
+ const toCleanups = this.buildRemovePaths(workspace().repoRoot);
28
30
  for (const tmp of toCleanupsTmp)
29
31
  toCleanups.push(...tmp);
30
32
  return toCleanups;
@@ -53,12 +55,6 @@ export class Cleanup {
53
55
  logError(`āŒ Removing ${toCleanup.name} failed ${error}`);
54
56
  }
55
57
  }
56
- async readDir(dir) {
57
- const packgeDir = join(this.paths.workspacesDir, dir);
58
- if (!(await this.paths.workspaceByPath(packgeDir)))
59
- return [];
60
- return this.buildRemovePaths(packgeDir);
61
- }
62
58
  buildRemovePaths(basePath) {
63
59
  return this.toBeDeleted.map((d) => {
64
60
  const path = join(basePath, d.name);
@@ -0,0 +1,2 @@
1
+ export declare const jsonEqual: <T>(a: T, b: T) => boolean;
2
+ export declare const jsonClone: <T>(value: T) => T;
@@ -0,0 +1,3 @@
1
+ import { isDeepStrictEqual } from "node:util";
2
+ export const jsonEqual = (a, b) => isDeepStrictEqual(a, b);
3
+ export const jsonClone = (value) => structuredClone(value);
@@ -1 +1,2 @@
1
1
  export * from "./common.fs.js";
2
+ export * from "./common.json.js";
@@ -1,2 +1,3 @@
1
1
  // This file is auto-generated. Do not edit manually.
2
2
  export * from "./common.fs.js";
3
+ export * from "./common.json.js";
@@ -1,19 +1,20 @@
1
+ import { Pkg } from "../pkg/Pkg.js";
1
2
  import { DepsProcessMode, DepsReplacementMode, FixWorkspaceDepsData, FixWorkspaceDepsMain, FixWorkspaceDepsParams } from "../types/types.deps.js";
3
+ import { MapEntry } from "../types/types.package.js";
2
4
  export declare const runFixDeps: (p: FixWorkspaceDepsParams) => Promise<void>;
3
5
  export declare const instanceFixDeps: (p: {
4
- repoRoot: string;
5
6
  mode: DepsProcessMode;
6
7
  replacement: DepsReplacementMode;
7
8
  }) => FixWorkspaceDepsVersion | FixWorkspaceDepsFile;
8
9
  export declare abstract class IFixWorkspaceDeps {
9
- readonly repoRoot: string;
10
10
  readonly mode: DepsProcessMode;
11
- constructor(repoRoot: string, mode: DepsProcessMode);
11
+ constructor(mode: DepsProcessMode);
12
12
  protected abstract fixVersion(p: FixWorkspaceDepsData): string | null;
13
13
  protected abstract restoreVersion(p: FixWorkspaceDepsData): string | null;
14
14
  run(): Promise<void>;
15
- protected handleDependencies(deps: Record<string, string> | undefined, p: FixWorkspaceDepsMain): boolean;
16
- protected runSingle(p: FixWorkspaceDepsMain): boolean;
15
+ protected handleDependencies(deps: Record<string, string> | undefined, p: FixWorkspaceDepsMain): void;
16
+ protected runSingle(p: FixWorkspaceDepsMain): void;
17
+ protected buildMapEntries(pkgs: Pkg[]): MapEntry[];
17
18
  }
18
19
  export declare class FixWorkspaceDepsVersion extends IFixWorkspaceDeps {
19
20
  protected fixVersion(p: FixWorkspaceDepsData): string | null;
@@ -1,15 +1,17 @@
1
+ import { relative } from "path";
1
2
  import { logError, logInfo, logSuccess } from "../logger/Logger.js";
2
3
  import { DepsReplacementMode, } from "../types/types.deps.js";
3
- import { buildMapEntries, readPackageEntries, writePackageEntries, } from "../workspace/workspace.pkg.js";
4
- export const runFixDeps = async (p) => instanceFixDeps(p).run();
4
+ import { initWorkspace, workspace } from "../workspace/Workspace.js";
5
+ export const runFixDeps = async (p) => {
6
+ initWorkspace(p.repoRoot);
7
+ return instanceFixDeps(p).run();
8
+ };
5
9
  export const instanceFixDeps = (p) => p.replacement === DepsReplacementMode.version
6
- ? new FixWorkspaceDepsVersion(p.repoRoot, p.mode)
7
- : new FixWorkspaceDepsFile(p.repoRoot, p.mode);
10
+ ? new FixWorkspaceDepsVersion(p.mode)
11
+ : new FixWorkspaceDepsFile(p.mode);
8
12
  export class IFixWorkspaceDeps {
9
- repoRoot;
10
13
  mode;
11
- constructor(repoRoot, mode) {
12
- this.repoRoot = repoRoot;
14
+ constructor(mode) {
13
15
  this.mode = mode;
14
16
  }
15
17
  async run() {
@@ -17,8 +19,9 @@ export class IFixWorkspaceDeps {
17
19
  logInfo("šŸ”§ Fixing workspace dependencies...\n");
18
20
  else
19
21
  logInfo("šŸ”§ Restoring workspace dependencies...\n");
20
- const pkgs = await readPackageEntries(this.repoRoot);
21
- const mapEntries = buildMapEntries(pkgs);
22
+ const ws = workspace();
23
+ const pkgs = await ws.loadPackages();
24
+ const mapEntries = this.buildMapEntries(pkgs);
22
25
  const versionMap = new Map();
23
26
  const workspacePackages = new Set();
24
27
  for (const pkg of pkgs) {
@@ -32,7 +35,7 @@ export class IFixWorkspaceDeps {
32
35
  for (const consumingPkg of pkgs) {
33
36
  logInfo(`šŸ“¦ Processing ${consumingPkg.content.name}...`);
34
37
  try {
35
- consumingPkg.modified = this.runSingle({
38
+ this.runSingle({
36
39
  consumingPkg,
37
40
  mapEntries,
38
41
  versionMap,
@@ -44,7 +47,7 @@ export class IFixWorkspaceDeps {
44
47
  throw err;
45
48
  }
46
49
  }
47
- await writePackageEntries(pkgs);
50
+ await ws.write();
48
51
  if (this.mode === "fix")
49
52
  logSuccess("āœ… Done fixing workspace dependencies!");
50
53
  else
@@ -53,31 +56,33 @@ export class IFixWorkspaceDeps {
53
56
  // Replace workspace:* with file:...
54
57
  handleDependencies(deps, p) {
55
58
  if (!deps)
56
- return false;
59
+ return;
57
60
  const handler = this.mode === "fix" ? this.fixVersion : this.restoreVersion;
58
- let modified = false;
59
61
  for (const [name, version] of Object.entries(deps)) {
60
62
  const newVersion = handler({ ...p, pkg: name, version });
61
63
  if (!newVersion)
62
64
  continue;
63
65
  logInfo(` āœ“ Replaced ${name}: ${version} → ${newVersion}`);
64
66
  deps[name] = newVersion;
65
- modified = true;
66
67
  }
67
- return modified;
68
68
  }
69
69
  runSingle(p) {
70
- let modified = false;
71
- modified =
72
- this.handleDependencies(p.consumingPkg.content.dependencies, p) ||
73
- modified;
74
- modified =
75
- this.handleDependencies(p.consumingPkg.content.devDependencies, p) ||
76
- modified;
77
- modified =
78
- this.handleDependencies(p.consumingPkg.content.peerDependencies, p) ||
79
- modified;
80
- return modified;
70
+ this.handleDependencies(p.consumingPkg.content.dependencies, p);
71
+ this.handleDependencies(p.consumingPkg.content.devDependencies, p);
72
+ this.handleDependencies(p.consumingPkg.content.peerDependencies, p);
73
+ }
74
+ // Build a map of package names to their versions
75
+ buildMapEntries(pkgs) {
76
+ const versionEntries = [];
77
+ for (const fromPkg of pkgs)
78
+ for (const toPkg of pkgs)
79
+ if (fromPkg.content.name !== toPkg.content.name)
80
+ versionEntries.push({
81
+ fromPkg,
82
+ toPkg,
83
+ relPath: relative(fromPkg.filePath, toPkg.filePath),
84
+ });
85
+ return versionEntries;
81
86
  }
82
87
  }
83
88
  export class FixWorkspaceDepsVersion extends IFixWorkspaceDeps {
@@ -1,16 +1,16 @@
1
1
  import { GitChangedResult, GitChangedContentsResult } from "../types/types.git.js";
2
2
  export declare class GitChanges {
3
3
  readonly rootDir: string;
4
- protected _sinceCommit: string | null;
4
+ protected _sinceCommitTag: string | null;
5
5
  constructor(rootDir: string);
6
- set sinceCommit(sinceCommit: string);
7
- get sinceCommit(): string;
6
+ set sinceCommitTag(sinceCommitTag: string);
7
+ get sinceCommitTag(): string;
8
8
  /**
9
9
  * Checks if a specific file or directory has been changed since a given git commit.
10
10
  * Includes both committed and uncommitted changes (staged + unstaged).
11
11
  *
12
12
  * @param target - Relative path to the file or directory to check.
13
- * @param sinceCommit - The git commit hash (or ref like a tag/branch) to compare against.
13
+ * @param sinceCommitTag - The git commit hash (or ref like a tag/branch) to compare against.
14
14
  * @returns A result object indicating whether changes were detected.
15
15
  */
16
16
  hasChanged(path: string): Promise<GitChangedResult>;
@@ -22,7 +22,7 @@ export declare class GitChanges {
22
22
  * Deleted files are excluded from the result since they no longer exist on disk.
23
23
  *
24
24
  * @param target - Relative path to the file or directory to check.
25
- * @param sinceCommit - The git commit hash (or ref like a tag/branch) to compare against.
25
+ * @param sinceCommitTag - The git commit hash (or ref like a tag/branch) to compare against.
26
26
  * @param cwd - The working directory of the git repository (defaults to process.cwd()).
27
27
  * @returns A result object containing the current content of each changed file.
28
28
  */
@@ -31,3 +31,6 @@ export declare class GitChanges {
31
31
  export declare class GitChangesCommit extends GitChanges {
32
32
  constructor(rootDir: string, sinceCommit: string);
33
33
  }
34
+ export declare class GitChangesTag extends GitChangesCommit {
35
+ constructor(rootDir: string, sinceTag: string);
36
+ }
@@ -4,39 +4,39 @@ import { resolve } from "node:path";
4
4
  import { verifiedGit } from "./git.util.js";
5
5
  export class GitChanges {
6
6
  rootDir;
7
- _sinceCommit = null;
7
+ _sinceCommitTag = null;
8
8
  constructor(rootDir) {
9
9
  this.rootDir = rootDir;
10
10
  }
11
- set sinceCommit(sinceCommit) {
12
- this._sinceCommit = sinceCommit;
11
+ set sinceCommitTag(sinceCommitTag) {
12
+ this._sinceCommitTag = sinceCommitTag;
13
13
  }
14
- get sinceCommit() {
15
- if (!this._sinceCommit)
14
+ get sinceCommitTag() {
15
+ if (!this._sinceCommitTag)
16
16
  throw new Error("SinceCommit missing");
17
- return this._sinceCommit;
17
+ return this._sinceCommitTag;
18
18
  }
19
19
  /**
20
20
  * Checks if a specific file or directory has been changed since a given git commit.
21
21
  * Includes both committed and uncommitted changes (staged + unstaged).
22
22
  *
23
23
  * @param target - Relative path to the file or directory to check.
24
- * @param sinceCommit - The git commit hash (or ref like a tag/branch) to compare against.
24
+ * @param sinceCommitTag - The git commit hash (or ref like a tag/branch) to compare against.
25
25
  * @returns A result object indicating whether changes were detected.
26
26
  */
27
27
  async hasChanged(path) {
28
- const sinceCommit = this.sinceCommit;
28
+ const sinceCommitTag = this.sinceCommitTag;
29
29
  const resolvedTarget = resolve(this.rootDir, path);
30
30
  if (!existsSync(resolvedTarget)) {
31
31
  throw new Error(`Target path does not exist: ${resolvedTarget}`);
32
32
  }
33
- const git = await verifiedGit(this.rootDir, sinceCommit);
33
+ const git = await verifiedGit(this.rootDir, sinceCommitTag);
34
34
  // Compare commit to working directory (includes uncommitted changes)
35
- const diff = await git.diffSummary([sinceCommit, "--", path]);
35
+ const diff = await git.diffSummary([sinceCommitTag, "--", path]);
36
36
  const changedFiles = diff.files.map((file) => file.file);
37
37
  return {
38
38
  path,
39
- sinceCommit,
39
+ sinceCommitTag,
40
40
  hasChanged: changedFiles.length > 0,
41
41
  changedFiles,
42
42
  };
@@ -49,15 +49,15 @@ export class GitChanges {
49
49
  * Deleted files are excluded from the result since they no longer exist on disk.
50
50
  *
51
51
  * @param target - Relative path to the file or directory to check.
52
- * @param sinceCommit - The git commit hash (or ref like a tag/branch) to compare against.
52
+ * @param sinceCommitTag - The git commit hash (or ref like a tag/branch) to compare against.
53
53
  * @param cwd - The working directory of the git repository (defaults to process.cwd()).
54
54
  * @returns A result object containing the current content of each changed file.
55
55
  */
56
56
  async readChangedFiles(readContent) {
57
- const sinceCommit = this.sinceCommit;
58
- const git = await verifiedGit(this.rootDir, sinceCommit);
57
+ const sinceCommitTag = this.sinceCommitTag;
58
+ const git = await verifiedGit(this.rootDir, sinceCommitTag);
59
59
  // Compare commit to working directory (includes uncommitted changes)
60
- const diff = await git.diffSummary([sinceCommit, "--", this.rootDir]);
60
+ const diff = await git.diffSummary([sinceCommitTag, "--", this.rootDir]);
61
61
  const files = [];
62
62
  for (const entry of diff.files) {
63
63
  const repoFilePath = entry.file;
@@ -72,7 +72,7 @@ export class GitChanges {
72
72
  }
73
73
  return {
74
74
  path: this.rootDir,
75
- sinceCommit,
75
+ sinceCommitTag,
76
76
  files,
77
77
  };
78
78
  }
@@ -80,6 +80,11 @@ export class GitChanges {
80
80
  export class GitChangesCommit extends GitChanges {
81
81
  constructor(rootDir, sinceCommit) {
82
82
  super(rootDir);
83
- this.sinceCommit = sinceCommit;
83
+ this.sinceCommitTag = sinceCommit;
84
+ }
85
+ }
86
+ export class GitChangesTag extends GitChangesCommit {
87
+ constructor(rootDir, sinceTag) {
88
+ super(rootDir, sinceTag);
84
89
  }
85
90
  }
@@ -5,6 +5,10 @@ import { GitCommitHash } from "../types/types.git.js";
5
5
  * and the commit ref is valid.
6
6
  */
7
7
  export declare const verifiedGit: (rootDir: string, commitRef?: string) => Promise<SimpleGit>;
8
+ export declare const lastTag: (rootDir: string) => Promise<string | null>;
9
+ export declare const tags: (rootDir: string) => Promise<string[]>;
8
10
  export declare const lastCommitHash: (rootDir: string) => Promise<string | null>;
9
11
  export declare const commitHashs: (rootDir: string) => Promise<GitCommitHash[]>;
10
12
  export declare const ensureCommitRef: (ref: string, fallback: string, rootDir: string) => Promise<string>;
13
+ /** @internal test-only */
14
+ export declare const __resetGitEntries: () => void;
@@ -25,6 +25,8 @@ const verifyGit = async (git, rootDir, commitRef) => {
25
25
  }
26
26
  return { git, rootDir, commitRef };
27
27
  };
28
+ export const lastTag = async (rootDir) => (await (await verifiedGit(rootDir)).tags()).latest ?? null;
29
+ export const tags = async (rootDir) => (await (await verifiedGit(rootDir)).tags()).all;
28
30
  export const lastCommitHash = async (rootDir) => (await (await verifiedGit(rootDir)).log()).latest?.hash ?? null;
29
31
  export const commitHashs = async (rootDir) => (await (await verifiedGit(rootDir)).log()).all.map((a) => ({
30
32
  date: a.date,
@@ -41,3 +43,7 @@ export const ensureCommitRef = async (ref, fallback, rootDir) => {
41
43
  return fallback;
42
44
  }
43
45
  };
46
+ /** @internal test-only */
47
+ export const __resetGitEntries = () => {
48
+ __entries.length = 0;
49
+ };
@@ -1,8 +1,8 @@
1
1
  import { NpmPublisherParams } from "../types/types.npm.js";
2
+ import { Pkg } from "../pkg/Pkg.js";
2
3
  export declare const runNpmPublisher: (params: NpmPublisherParams) => Promise<void>;
3
4
  export declare class NpmPublisher {
4
- protected readonly packagesDir: string;
5
- constructor(packagesDir: string);
5
+ constructor();
6
6
  run(): Promise<void>;
7
- protected runPackage(dir: string): Promise<void>;
7
+ protected runPackage(pkg: Pkg): Promise<void>;
8
8
  }
@@ -1,19 +1,15 @@
1
- import { readdir } from "node:fs/promises";
2
- import { join } from "node:path";
3
1
  import { logError, logInfo, logSuccess } from "../logger/Logger.js";
4
2
  import { execAsync } from "../common/common.fs.js";
5
- import { readPackageJson } from "../workspace/workspace.pkg.js";
6
- export const runNpmPublisher = async (params) => new NpmPublisher(params.packagesDir).run();
3
+ import { initWorkspace, workspace } from "../workspace/Workspace.js";
4
+ export const runNpmPublisher = async (params) => {
5
+ initWorkspace(params.repoRoot);
6
+ return new NpmPublisher().run();
7
+ };
7
8
  export class NpmPublisher {
8
- packagesDir;
9
- constructor(packagesDir) {
10
- this.packagesDir = packagesDir;
11
- }
9
+ constructor() { }
12
10
  async run() {
13
- const packageDirs = (await readdir(this.packagesDir, { withFileTypes: true }))
14
- .filter((d) => d.isDirectory())
15
- .map((d) => join(this.packagesDir, d.name));
16
- const results = await Promise.allSettled(packageDirs.map((d) => this.runPackage(d)));
11
+ const pkgs = await workspace().loadPackages();
12
+ const results = await Promise.allSettled(pkgs.map((d) => this.runPackage(d)));
17
13
  const failures = results.filter((r) => r.status === "rejected");
18
14
  if (failures.length > 0) {
19
15
  logError(`\nāŒ ${failures.length} package(s) failed to publish:`);
@@ -23,11 +19,10 @@ export class NpmPublisher {
23
19
  process.exit(1);
24
20
  }
25
21
  }
26
- async runPackage(dir) {
27
- const pkg = await readPackageJson(join(dir, "package.json"));
28
- if (!pkg || pkg.private)
22
+ async runPackage(pkg) {
23
+ if (pkg.content.private)
29
24
  return;
30
- const { name, version } = pkg;
25
+ const { name, version } = pkg.content;
31
26
  logInfo(`šŸ“¦ Publishing ${name}@${version} ... (${new Date().toISOString()})`);
32
27
  // Check if this exact version is already published
33
28
  try {
@@ -43,7 +38,7 @@ export class NpmPublisher {
43
38
  }
44
39
  try {
45
40
  await execAsync("npm publish --access public", {
46
- cwd: dir,
41
+ cwd: pkg.dirPath,
47
42
  });
48
43
  logSuccess(`āœ… ${name}@${version} published successfully (${new Date().toISOString()}).`);
49
44
  }
@@ -2,3 +2,5 @@ import { OSInfo } from "../types/types.os.js";
2
2
  export declare const osInfo: () => OSInfo;
3
3
  export declare const defaultInfo: () => OSInfo;
4
4
  export declare const wslInfo: () => OSInfo;
5
+ /** @internal test-only */
6
+ export declare const __resetOsInfo: () => void;
@@ -54,3 +54,7 @@ export const wslInfo = () => {
54
54
  isWSL: true,
55
55
  };
56
56
  };
57
+ /** @internal test-only */
58
+ export const __resetOsInfo = () => {
59
+ __info = null;
60
+ };