@mxpicture/build-api 0.2.22 → 0.2.23

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
@@ -0,0 +1,24 @@
1
+ import { PackageJson } from "../types/types.package.js";
2
+ export declare class Pkg {
3
+ readonly repoRoot: string;
4
+ readonly repoPath: string;
5
+ readonly filePath: string;
6
+ readonly dirPath: string;
7
+ readonly srcPath: string;
8
+ readonly distPath: string;
9
+ readonly repoFilePath: string;
10
+ readonly repoDirPath: string;
11
+ readonly repoSrcPath: string;
12
+ readonly repoDistPath: string;
13
+ protected _content: PackageJson | null;
14
+ protected originalContent: PackageJson | null;
15
+ constructor(repoRoot: string, repoPath: string);
16
+ get content(): PackageJson;
17
+ protected set content(c: PackageJson);
18
+ modified(): boolean;
19
+ read(): Promise<PackageJson>;
20
+ readSync(): PackageJson;
21
+ write(): Promise<void>;
22
+ packageVersions(): Promise<Record<string, string>>;
23
+ protected updateOriginal(content?: PackageJson): void;
24
+ }
@@ -0,0 +1,74 @@
1
+ import { join, relative } from "node:path";
2
+ import { logInfo, logSuccess } from "../logger/Logger.js";
3
+ import { ensurePkgJsonPath, readPackageJson, readPackageJsonSync, writePackageJson, } from "./pkg.fs.js";
4
+ import { jsonClone, jsonEqual } from "../common/common.json.js";
5
+ export class Pkg {
6
+ repoRoot;
7
+ repoPath;
8
+ filePath;
9
+ dirPath;
10
+ srcPath;
11
+ distPath;
12
+ repoFilePath;
13
+ repoDirPath;
14
+ repoSrcPath;
15
+ repoDistPath;
16
+ _content = null;
17
+ originalContent = null;
18
+ constructor(repoRoot, repoPath) {
19
+ this.repoRoot = repoRoot;
20
+ this.repoPath = repoPath;
21
+ this.dirPath = join(repoRoot, repoPath);
22
+ this.filePath = ensurePkgJsonPath(this.dirPath);
23
+ this.srcPath = join(repoRoot, repoPath, "src");
24
+ this.distPath = join(repoRoot, repoPath, "dist");
25
+ this.repoFilePath = relative(repoRoot, this.filePath);
26
+ this.repoDirPath = relative(repoRoot, this.dirPath);
27
+ this.repoSrcPath = relative(repoRoot, this.srcPath);
28
+ this.repoDistPath = relative(repoRoot, this.distPath);
29
+ }
30
+ get content() {
31
+ if (!this._content)
32
+ throw new Error(`Content not loaded. ${this.filePath}`);
33
+ return this._content;
34
+ }
35
+ set content(c) {
36
+ this._content = c;
37
+ }
38
+ modified() {
39
+ return !jsonEqual(this.content, this.originalContent);
40
+ }
41
+ async read() {
42
+ if (!this._content)
43
+ this.updateOriginal((this.content = await readPackageJson(this.filePath)));
44
+ return this.content;
45
+ }
46
+ readSync() {
47
+ if (!this._content)
48
+ this.updateOriginal((this.content = readPackageJsonSync(this.filePath)));
49
+ return this.content;
50
+ }
51
+ async write() {
52
+ if (this.content && this.modified()) {
53
+ await writePackageJson(this.filePath, this.content);
54
+ logSuccess(` ✅ package.json updated ${this.repoFilePath}\n`);
55
+ }
56
+ else {
57
+ logInfo(` ⏭️ No changes in package.json. ${this.repoFilePath}\n`);
58
+ }
59
+ }
60
+ async packageVersions() {
61
+ const pkgJson = await this.read();
62
+ let versions = {};
63
+ if (pkgJson.dependencies)
64
+ versions = { ...versions, ...pkgJson.dependencies };
65
+ if (pkgJson.devDependencies)
66
+ versions = { ...versions, ...pkgJson.devDependencies };
67
+ if (pkgJson.peerDependencies)
68
+ versions = { ...versions, ...pkgJson.peerDependencies };
69
+ return versions;
70
+ }
71
+ updateOriginal(content) {
72
+ this.originalContent = jsonClone(content ?? this.content);
73
+ }
74
+ }
@@ -1,12 +1,11 @@
1
- import { BumpParams, PackageEntry, SyncPkgVersionParams } from "../types/types.package.js";
2
- import { WorkspacePaths } from "../workspace/WorkspacePaths.js";
1
+ import { BumpParams, SyncPkgVersionParams } from "../types/types.package.js";
2
+ import { Pkg } from "./Pkg.js";
3
3
  export declare const runSyncPkgVersion: (params: SyncPkgVersionParams) => Promise<void>;
4
4
  export declare class SyncPkgVersion {
5
- protected readonly paths: WorkspacePaths;
6
5
  protected readonly bump: BumpParams | null;
7
6
  protected readonly noTag: boolean;
8
- constructor(paths: WorkspacePaths, bump: BumpParams | null, noTag: boolean);
7
+ constructor(bump: BumpParams | null, noTag: boolean);
9
8
  run(): Promise<void>;
10
- protected read(): Promise<PackageEntry[]>;
11
- protected write(packages: PackageEntry[]): Promise<void>;
9
+ protected read(): Promise<Pkg[]>;
10
+ protected write(): Promise<void>;
12
11
  }
@@ -1,15 +1,14 @@
1
- import { join } from "node:path";
2
- import { readPackageEntries, readPackageEntryThrow, writePackageEntries, } from "../workspace/workspace.pkg.js";
3
- import { WorkspacePaths } from "../workspace/WorkspacePaths.js";
4
1
  import { bumpVersion, compareVersionsGT, concatVersion, splitVersion, } from "./pkg.common.js";
5
2
  import { verifiedGit } from "../git/git.util.js";
6
- export const runSyncPkgVersion = async (params) => new SyncPkgVersion(WorkspacePaths.instance(params.repoRoot, params.workspacesName), params.noBump ? null : (params.bump ?? { patch: true }), !!params.noTag).run();
3
+ import { initWorkspace, workspace } from "../workspace/Workspace.js";
4
+ export const runSyncPkgVersion = async (params) => {
5
+ initWorkspace(params.repoRoot);
6
+ return new SyncPkgVersion(params.noBump ? null : (params.bump ?? { patch: true }), !!params.noTag).run();
7
+ };
7
8
  export class SyncPkgVersion {
8
- paths;
9
9
  bump;
10
10
  noTag;
11
- constructor(paths, bump, noTag) {
12
- this.paths = paths;
11
+ constructor(bump, noTag) {
13
12
  this.bump = bump;
14
13
  this.noTag = noTag;
15
14
  }
@@ -31,26 +30,22 @@ export class SyncPkgVersion {
31
30
  maxVersion = bumpVersion(maxVersion, this.bump);
32
31
  const newVersion = concatVersion(maxVersion);
33
32
  // set/update
34
- for (const entry of packages) {
33
+ for (const entry of packages)
35
34
  entry.content.version = newVersion;
36
- entry.modified = true;
37
- }
38
- await this.write(packages);
35
+ await this.write();
39
36
  // create tag
40
37
  if (!this.noTag) {
41
- const git = await verifiedGit(this.paths.repoRoot);
38
+ const git = await verifiedGit(workspace().repoRoot);
42
39
  await git.addAnnotatedTag(`v${newVersion}`, `Release v${newVersion}`);
43
40
  await git.pushTags();
44
41
  }
45
42
  }
46
43
  async read() {
47
- const [packages, root] = await Promise.all([
48
- readPackageEntries(this.paths.repoRoot),
49
- readPackageEntryThrow(join(this.paths.repoRoot, "package.json")),
50
- ]);
51
- return [...packages, root];
44
+ const ws = workspace();
45
+ await ws.loadPackages();
46
+ return [ws.mainPackage, ...ws.packages];
52
47
  }
53
- async write(packages) {
54
- await writePackageEntries(packages);
48
+ async write() {
49
+ return workspace().write();
55
50
  }
56
51
  }
@@ -1,16 +1,14 @@
1
- import { WorkspacePaths } from "../workspace/WorkspacePaths.js";
2
- import { PackageEntry, UpdatePackagesParams } from "../types/types.package.js";
1
+ import { PackageJson, UpdatePackagesParams } from "../types/types.package.js";
3
2
  export declare const runUpdatePackages: (params: UpdatePackagesParams) => Promise<void>;
4
3
  export declare class UpdatePackages {
5
- protected readonly paths: WorkspacePaths;
6
4
  protected readonly pattern: string;
7
5
  protected patternWoSlash: string;
8
- constructor(paths: WorkspacePaths, pattern: string);
6
+ constructor(pattern: string);
9
7
  run(): Promise<void>;
10
8
  protected exec(command: string): Promise<string>;
11
9
  protected getPackages(): Promise<Set<string>>;
12
- protected filterPackages(wsPackages: PackageEntry[], results: Set<string>): void;
13
- protected filterPackage(wsPackage: PackageEntry, results: Set<string>): void;
10
+ protected filterPackages(wsPackages: PackageJson[], results: Set<string>): void;
11
+ protected filterPackage(wsPackage: PackageJson, results: Set<string>): void;
14
12
  protected filterPackageDep(deps: Record<string, string> | undefined, results: Set<string>): void;
15
13
  protected updatePackages(packages: Set<string>): Promise<void>;
16
14
  protected deduplicate(): Promise<void>;
@@ -1,15 +1,15 @@
1
- import { WorkspacePaths } from "../workspace/WorkspacePaths.js";
2
- import { readPackageEntries } from "../workspace/workspace.pkg.js";
3
1
  import { logInfo, logSuccess } from "../logger/Logger.js";
4
2
  import { execAsync } from "../common/common.fs.js";
5
3
  import micromatch from "micromatch";
6
- export const runUpdatePackages = async (params) => new UpdatePackages(WorkspacePaths.instance(params.repoRoot, params.workspacesName), params.pattern).run();
4
+ import { initWorkspace, workspace } from "../workspace/Workspace.js";
5
+ export const runUpdatePackages = async (params) => {
6
+ initWorkspace(params.repoRoot);
7
+ return new UpdatePackages(params.pattern).run();
8
+ };
7
9
  export class UpdatePackages {
8
- paths;
9
10
  pattern;
10
11
  patternWoSlash;
11
- constructor(paths, pattern) {
12
- this.paths = paths;
12
+ constructor(pattern) {
13
13
  this.pattern = pattern;
14
14
  this.patternWoSlash = pattern.replaceAll("/", "+");
15
15
  }
@@ -35,7 +35,7 @@ export class UpdatePackages {
35
35
  console.log(`\n▶ ${command}`);
36
36
  try {
37
37
  return (await execAsync(command, {
38
- cwd: this.paths.repoRoot,
38
+ cwd: workspace().repoRoot,
39
39
  encoding: "utf-8",
40
40
  })).stdout;
41
41
  }
@@ -45,9 +45,10 @@ export class UpdatePackages {
45
45
  }
46
46
  }
47
47
  async getPackages() {
48
- const wsPackages = await readPackageEntries(this.paths.repoRoot);
48
+ const ws = workspace();
49
+ const pkgs = await ws.loadPackages();
49
50
  const packageNames = new Set();
50
- this.filterPackages(wsPackages, packageNames);
51
+ this.filterPackages(pkgs.map((p) => p.content), packageNames);
51
52
  return packageNames;
52
53
  }
53
54
  filterPackages(wsPackages, results) {
@@ -55,8 +56,8 @@ export class UpdatePackages {
55
56
  this.filterPackage(wsPackage, results);
56
57
  }
57
58
  filterPackage(wsPackage, results) {
58
- this.filterPackageDep(wsPackage.content.dependencies, results);
59
- this.filterPackageDep(wsPackage.content.devDependencies, results);
59
+ this.filterPackageDep(wsPackage.dependencies, results);
60
+ this.filterPackageDep(wsPackage.devDependencies, results);
60
61
  }
61
62
  filterPackageDep(deps, results) {
62
63
  if (!deps)
@@ -1,3 +1,5 @@
1
+ export * from "./Pkg.js";
1
2
  export * from "./SyncPkgVersion.js";
2
3
  export * from "./UpdatePackages.js";
3
4
  export * from "./pkg.common.js";
5
+ export * from "./pkg.fs.js";
package/dist/pkg/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  // This file is auto-generated. Do not edit manually.
2
+ export * from "./Pkg.js";
2
3
  export * from "./SyncPkgVersion.js";
3
4
  export * from "./UpdatePackages.js";
4
5
  export * from "./pkg.common.js";
6
+ export * from "./pkg.fs.js";
@@ -0,0 +1,5 @@
1
+ import { PackageJson } from "../types/types.package.js";
2
+ export declare const readPackageJson: (dirOrFilepath: string) => Promise<PackageJson>;
3
+ export declare const readPackageJsonSync: (dirOrFilepath: string) => PackageJson;
4
+ export declare const writePackageJson: (jsonPath: string, content: PackageJson) => Promise<void>;
5
+ export declare const ensurePkgJsonPath: (dirOrFilepath: string) => string;
@@ -0,0 +1,11 @@
1
+ import json5 from "json5";
2
+ import { readFile, writeFile } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { formatJsonStringify } from "../format/format.code.js";
5
+ import { readFileSync } from "node:fs";
6
+ export const readPackageJson = async (dirOrFilepath) => json5.parse(await readFile(ensurePkgJsonPath(dirOrFilepath), "utf8"));
7
+ export const readPackageJsonSync = (dirOrFilepath) => json5.parse(readFileSync(ensurePkgJsonPath(dirOrFilepath), "utf8"));
8
+ export const writePackageJson = async (jsonPath, content) => writeFile(jsonPath, await formatJsonStringify(json5.stringify(content)));
9
+ export const ensurePkgJsonPath = (dirOrFilepath) => dirOrFilepath.endsWith("/package.json")
10
+ ? dirOrFilepath
11
+ : join(dirOrFilepath, "package.json");
@@ -1,6 +1,5 @@
1
1
  export * from "./types.barrel.js";
2
2
  export * from "./types.changelog.js";
3
- export * from "./types.changeset.js";
4
3
  export * from "./types.cleanup.js";
5
4
  export * from "./types.code.js";
6
5
  export * from "./types.deps.js";
@@ -1,7 +1,6 @@
1
1
  // This file is auto-generated. Do not edit manually.
2
2
  export * from "./types.barrel.js";
3
3
  export * from "./types.changelog.js";
4
- export * from "./types.changeset.js";
5
4
  export * from "./types.cleanup.js";
6
5
  export * from "./types.code.js";
7
6
  export * from "./types.deps.js";
@@ -1,16 +1,15 @@
1
- import { RunRepoRootWsParams } from "./types.run.js";
1
+ import type { Pkg } from "../pkg/Pkg.js";
2
+ import { RunRepoRootParams } from "./types.run.js";
2
3
  export interface BarrelGroup {
3
4
  dirPath: string;
4
5
  files: string[];
5
- packageDir: string;
6
- packageJsonPath: string;
6
+ pkg: Pkg;
7
7
  }
8
8
  export interface BarrelResult {
9
9
  barrelDirs: string[];
10
- packageDir: string;
11
- packageJsonPath: string;
10
+ pkg: Pkg;
12
11
  }
13
- export interface BarrelParams extends RunRepoRootWsParams {
12
+ export interface BarrelParams extends RunRepoRootParams {
14
13
  excludes?: RegExp[];
15
14
  fileHeader?: string;
16
15
  }
@@ -1,4 +1,4 @@
1
- import { RunRepoRootWsParams } from "./types.run.js";
1
+ import { RunRepoRootParams } from "./types.run.js";
2
2
  export interface ToBeDeleted {
3
3
  name: string;
4
4
  moveSuffix?: string;
@@ -7,6 +7,6 @@ export interface ToCleanup extends ToBeDeleted {
7
7
  path: string;
8
8
  moveTo?: string;
9
9
  }
10
- export interface CleanupParams extends RunRepoRootWsParams {
10
+ export interface CleanupParams extends RunRepoRootParams {
11
11
  toBeDeleted?: ToBeDeleted[];
12
12
  }
@@ -1,4 +1,6 @@
1
- import { MapEntry, PackageEntry } from "./types.package.js";
1
+ import type { Pkg } from "../pkg/Pkg.js";
2
+ import { MapEntry } from "./types.package.js";
3
+ import { RunRepoRootParams } from "./types.run.js";
2
4
  export declare enum DepsProcessMode {
3
5
  fix = "fix",
4
6
  restore = "restore"
@@ -9,7 +11,7 @@ export declare enum DepsReplacementMode {
9
11
  }
10
12
  export interface FixWorkspaceDepsMain {
11
13
  mapEntries: MapEntry[];
12
- consumingPkg: PackageEntry;
14
+ consumingPkg: Pkg;
13
15
  versionMap: Map<string, string>;
14
16
  workspacePackages: Set<string>;
15
17
  }
@@ -17,8 +19,7 @@ export interface FixWorkspaceDepsData extends FixWorkspaceDepsMain {
17
19
  pkg: string;
18
20
  version: string;
19
21
  }
20
- export interface FixWorkspaceDepsParams {
21
- repoRoot: string;
22
+ export interface FixWorkspaceDepsParams extends RunRepoRootParams {
22
23
  mode: DepsProcessMode;
23
24
  replacement: DepsReplacementMode;
24
25
  }
@@ -1,7 +1,7 @@
1
1
  import type { DiffResult } from "simple-git";
2
2
  export interface GitChangedResult {
3
3
  path: string;
4
- sinceCommit: string;
4
+ sinceCommitTag: string;
5
5
  hasChanged: boolean;
6
6
  changedFiles: string[];
7
7
  }
@@ -12,7 +12,7 @@ export interface GitChangedContent {
12
12
  }
13
13
  export interface GitChangedContentsResult {
14
14
  path: string;
15
- sinceCommit: string;
15
+ sinceCommitTag: string;
16
16
  files: GitChangedContent[];
17
17
  }
18
18
  export interface GitCommitHash {
@@ -1,2 +1,2 @@
1
- import { RunPackagesDirParams } from "./types.run.js";
2
- export type NpmPublisherParams = RunPackagesDirParams;
1
+ import { RunRepoRootParams } from "./types.run.js";
2
+ export type NpmPublisherParams = RunRepoRootParams;
@@ -1,4 +1,5 @@
1
- import { RunRepoRootWsParams } from "./types.run.js";
1
+ import type { Pkg } from "../pkg/Pkg.js";
2
+ import { RunRepoRootParams } from "./types.run.js";
2
3
  export interface PackageVersion {
3
4
  major: number;
4
5
  minor: number | null;
@@ -15,16 +16,9 @@ export interface PackageJson {
15
16
  peerDependencies?: Record<string, string>;
16
17
  [key: string]: unknown;
17
18
  }
18
- export interface PackageEntry {
19
- jsonPath: string;
20
- repoPath: string | null;
21
- wsName: string;
22
- content: PackageJson;
23
- modified: boolean;
24
- }
25
19
  export interface MapEntry {
26
- fromPkg: PackageEntry;
27
- toPkg: PackageEntry;
20
+ fromPkg: Pkg;
21
+ toPkg: Pkg;
28
22
  relPath: string;
29
23
  }
30
24
  export interface BumpParams {
@@ -32,11 +26,11 @@ export interface BumpParams {
32
26
  minor?: boolean;
33
27
  patch?: boolean;
34
28
  }
35
- export interface SyncPkgVersionParams extends RunRepoRootWsParams {
29
+ export interface SyncPkgVersionParams extends RunRepoRootParams {
36
30
  bump?: BumpParams;
37
31
  noBump?: boolean;
38
32
  noTag?: boolean;
39
33
  }
40
- export interface UpdatePackagesParams extends RunRepoRootWsParams {
34
+ export interface UpdatePackagesParams extends RunRepoRootParams {
41
35
  pattern: string;
42
36
  }
@@ -1,7 +1,3 @@
1
- export interface RunRepoRootWsParams {
1
+ export interface RunRepoRootParams {
2
2
  repoRoot: string;
3
- workspacesName: string;
4
- }
5
- export interface RunPackagesDirParams {
6
- packagesDir: string;
7
3
  }
@@ -1,3 +1,5 @@
1
1
  import { VSCodeSettings } from "../types/types.vscode.js";
2
2
  export declare const vscodeSettings: (dir?: string) => Promise<VSCodeSettings>;
3
3
  export declare const clangFormatStyle: (cwd: string) => Promise<string>;
4
+ /** @internal test-only */
5
+ export declare const __resetSettings: () => void;
@@ -24,3 +24,7 @@ export const clangFormatStyle = async (cwd) => {
24
24
  throw new Error("C_Cpp.clang_format_style not found in settings.json");
25
25
  return settings["C_Cpp.clang_format_style"];
26
26
  };
27
+ /** @internal test-only */
28
+ export const __resetSettings = () => {
29
+ __settings = null;
30
+ };
@@ -1,3 +1,5 @@
1
1
  import { VSCodeStorage } from "../types/types.vscode.js";
2
2
  export declare const storagePath: () => string;
3
3
  export declare const storage: () => VSCodeStorage;
4
+ /** @internal test-only */
5
+ export declare const __resetStorage: () => void;
@@ -13,3 +13,7 @@ export const storage = () => {
13
13
  throw new Error("VS Code storage.json could not be loaded");
14
14
  return __storage;
15
15
  };
16
+ /** @internal test-only */
17
+ export const __resetStorage = () => {
18
+ __storage = undefined;
19
+ };
@@ -0,0 +1,25 @@
1
+ import { PnpmWorkspace } from "../types/types.workspace.js";
2
+ import { Pkg } from "../pkg/Pkg.js";
3
+ export declare const initWorkspace: (repoRoot: string) => Workspace;
4
+ export declare const workspace: () => Workspace;
5
+ interface WorkspaceData {
6
+ pnpmWs: PnpmWorkspace;
7
+ mainPackage: Pkg;
8
+ packages: Pkg[];
9
+ }
10
+ export declare class Workspace {
11
+ readonly repoRoot: string;
12
+ protected _data: WorkspaceData | null;
13
+ static __init(repoRoot: string): Workspace;
14
+ static __get(): Workspace;
15
+ private constructor();
16
+ get pnpmWs(): PnpmWorkspace;
17
+ get packages(): Pkg[];
18
+ get mainPackage(): Pkg;
19
+ protected set data(c: WorkspaceData);
20
+ protected get data(): WorkspaceData;
21
+ read(): Promise<void>;
22
+ loadPackages(): Promise<Pkg[]>;
23
+ write(): Promise<void>;
24
+ }
25
+ export {};
@@ -0,0 +1,70 @@
1
+ import { readWorkspaceYaml } from "./workspace.common.js";
2
+ import { Pkg } from "../pkg/Pkg.js";
3
+ import { jsonClone } from "../common/common.json.js";
4
+ let __instance = null;
5
+ export const initWorkspace = (repoRoot) => Workspace.__init(repoRoot);
6
+ export const workspace = () => Workspace.__get();
7
+ export class Workspace {
8
+ repoRoot;
9
+ _data = null;
10
+ static __init(repoRoot) {
11
+ return (__instance = new Workspace(repoRoot));
12
+ }
13
+ static __get() {
14
+ if (!__instance)
15
+ throw new Error("Workspace not initialized. initWorkspace()");
16
+ return __instance;
17
+ }
18
+ constructor(repoRoot) {
19
+ this.repoRoot = repoRoot;
20
+ }
21
+ get pnpmWs() {
22
+ return jsonClone(this.data.pnpmWs);
23
+ }
24
+ get packages() {
25
+ return this.data.packages;
26
+ }
27
+ get mainPackage() {
28
+ return this.data.mainPackage;
29
+ }
30
+ set data(c) {
31
+ this._data = c;
32
+ }
33
+ get data() {
34
+ if (!this._data)
35
+ throw new Error(`Data not loaded. ${this.repoRoot}`);
36
+ return this._data;
37
+ }
38
+ async read() {
39
+ if (!this._data) {
40
+ const pnpmWs = await readWorkspaceYaml(this.repoRoot);
41
+ const packages = pnpmWs.packages.map((repoPath) => new Pkg(this.repoRoot, repoPath));
42
+ this.data = {
43
+ pnpmWs,
44
+ packages,
45
+ mainPackage: new Pkg(this.repoRoot, "."),
46
+ };
47
+ }
48
+ }
49
+ async loadPackages() {
50
+ try {
51
+ await this.read();
52
+ await Promise.all([
53
+ this.mainPackage.read(),
54
+ ...this.packages.map((pkg) => pkg.read()),
55
+ ]);
56
+ return this.packages;
57
+ }
58
+ catch {
59
+ return [];
60
+ }
61
+ }
62
+ async write() {
63
+ if (!this._data)
64
+ return;
65
+ await Promise.all([
66
+ this.mainPackage.write(),
67
+ ...this.packages.map((pkg) => pkg.write()),
68
+ ]);
69
+ }
70
+ }
@@ -1,7 +1 @@
1
- export declare class WorkspacePaths {
2
- readonly repoRoot: string;
3
- readonly workspacesDir: string;
4
- static instance(repoRoot: string, workspacesName?: string): WorkspacePaths;
5
- private constructor();
6
- workspaceByPath(path: string): Promise<string | null>;
7
- }
1
+ export {};
@@ -1,30 +1,30 @@
1
- import { stat } from "node:fs/promises";
2
- import { join, relative, sep } from "node:path";
3
- const __instances = {};
4
- export class WorkspacePaths {
5
- repoRoot;
6
- workspacesDir;
7
- static instance(repoRoot, workspacesName = "packages") {
8
- const workspacesDir = join(repoRoot, workspacesName);
9
- if (!__instances[workspacesDir])
10
- __instances[workspacesDir] = new WorkspacePaths(repoRoot, workspacesDir);
11
- return __instances[workspacesDir];
12
- }
13
- constructor(repoRoot, workspacesDir) {
14
- this.repoRoot = repoRoot;
15
- this.workspacesDir = workspacesDir;
16
- }
17
- async workspaceByPath(path) {
18
- try {
19
- const pkgPath = relative(this.workspacesDir, path);
20
- const pkg = pkgPath.split(sep).shift();
21
- if (!pkg)
22
- return null;
23
- const pkgJsonPath = join(this.workspacesDir, pkg, "package.json");
24
- return (await stat(pkgJsonPath)).isFile() ? pkg : null;
25
- }
26
- catch {
27
- return null;
28
- }
29
- }
30
- }
1
+ // import { stat } from "node:fs/promises";
2
+ // import { join, relative, sep } from "node:path";
3
+ export {};
4
+ // const __instances: Record<string, WorkspacePaths> = {};
5
+ // export class WorkspacePaths {
6
+ // public static instance(
7
+ // repoRoot: string,
8
+ // workspacesName: string = "packages",
9
+ // ): WorkspacePaths {
10
+ // const workspacesDir = join(repoRoot, workspacesName);
11
+ // if (!__instances[workspacesDir])
12
+ // __instances[workspacesDir] = new WorkspacePaths(repoRoot, workspacesDir);
13
+ // return __instances[workspacesDir];
14
+ // }
15
+ // private constructor(
16
+ // public readonly repoRoot: string,
17
+ // public readonly workspacesDir: string,
18
+ // ) {}
19
+ // public async workspaceByPath(path: string): Promise<string | null> {
20
+ // try {
21
+ // const pkgPath = relative(this.workspacesDir, path);
22
+ // const pkg = pkgPath.split(sep).shift();
23
+ // if (!pkg) return null;
24
+ // const pkgJsonPath = join(this.workspacesDir, pkg, "package.json");
25
+ // return (await stat(pkgJsonPath)).isFile() ? pkg : null;
26
+ // } catch {
27
+ // return null;
28
+ // }
29
+ // }
30
+ // }
@@ -1,3 +1,3 @@
1
+ export * from "./Workspace.js";
1
2
  export * from "./WorkspacePaths.js";
2
3
  export * from "./workspace.common.js";
3
- export * from "./workspace.pkg.js";