@mxpicture/build-api 0.2.25 → 0.2.26

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.
@@ -19,8 +19,8 @@ export class IFixWorkspaceDeps {
19
19
  logInfo("🔧 Fixing workspace dependencies...\n");
20
20
  else
21
21
  logInfo("🔧 Restoring workspace dependencies...\n");
22
- const ws = workspace();
23
- const pkgs = await ws.loadPackages();
22
+ const ws = await workspace().read();
23
+ const pkgs = ws.packages;
24
24
  const mapEntries = this.buildMapEntries(pkgs);
25
25
  const versionMap = new Map();
26
26
  const workspacePackages = new Set();
@@ -8,7 +8,7 @@ export const runNpmPublisher = async (params) => {
8
8
  export class NpmPublisher {
9
9
  constructor() { }
10
10
  async run() {
11
- const pkgs = await workspace().loadPackages();
11
+ const pkgs = (await workspace().read()).packages;
12
12
  const results = await Promise.allSettled(pkgs.map((d) => this.runPackage(d)));
13
13
  const failures = results.filter((r) => r.status === "rejected");
14
14
  if (failures.length > 0) {
@@ -41,9 +41,8 @@ export class SyncPkgVersion {
41
41
  }
42
42
  }
43
43
  async read() {
44
- const ws = workspace();
45
- await ws.loadPackages();
46
- return [ws.mainPackage, ...ws.packages];
44
+ const ws = await workspace().read();
45
+ return [ws.rootPackage, ...ws.packages];
47
46
  }
48
47
  async write() {
49
48
  return workspace().write();
@@ -45,8 +45,7 @@ export class UpdatePackages {
45
45
  }
46
46
  }
47
47
  async getPackages() {
48
- const ws = workspace();
49
- const pkgs = await ws.loadPackages();
48
+ const pkgs = (await workspace().read()).packages;
50
49
  const packageNames = new Set();
51
50
  this.filterPackages(pkgs.map((p) => p.content), packageNames);
52
51
  return packageNames;
@@ -4,7 +4,7 @@ export declare const initWorkspace: (repoRoot: string) => Workspace;
4
4
  export declare const workspace: () => Workspace;
5
5
  interface WorkspaceData {
6
6
  pnpmWs: PnpmWorkspace;
7
- mainPackage: Pkg;
7
+ rootPackage: Pkg;
8
8
  packages: Pkg[];
9
9
  }
10
10
  export declare class Workspace {
@@ -15,11 +15,10 @@ export declare class Workspace {
15
15
  private constructor();
16
16
  get pnpmWs(): PnpmWorkspace;
17
17
  get packages(): Pkg[];
18
- get mainPackage(): Pkg;
18
+ get rootPackage(): Pkg;
19
19
  protected set data(c: WorkspaceData);
20
20
  protected get data(): WorkspaceData;
21
- read(): Promise<void>;
22
- loadPackages(): Promise<Pkg[]>;
21
+ read(): Promise<Workspace>;
23
22
  write(): Promise<void>;
24
23
  }
25
24
  export {};
@@ -24,8 +24,8 @@ export class Workspace {
24
24
  get packages() {
25
25
  return this.data.packages;
26
26
  }
27
- get mainPackage() {
28
- return this.data.mainPackage;
27
+ get rootPackage() {
28
+ return this.data.rootPackage;
29
29
  }
30
30
  set data(c) {
31
31
  this._data = c;
@@ -36,34 +36,27 @@ export class Workspace {
36
36
  return this._data;
37
37
  }
38
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
- }
39
+ if (this._data)
40
+ return this;
41
+ const pnpmWs = await readWorkspaceYaml(this.repoRoot);
42
+ const rootPackage = new Pkg(this.repoRoot, ".");
43
+ const packages = pnpmWs.packages.map((repoPath) => new Pkg(this.repoRoot, repoPath));
44
+ await Promise.all([
45
+ rootPackage.read(),
46
+ ...packages.map((pkg) => pkg.read()),
47
+ ]);
48
+ this.data = {
49
+ pnpmWs,
50
+ packages,
51
+ rootPackage,
52
+ };
53
+ return this;
61
54
  }
62
55
  async write() {
63
56
  if (!this._data)
64
57
  return;
65
58
  await Promise.all([
66
- this.mainPackage.write(),
59
+ this.rootPackage.write(),
67
60
  ...this.packages.map((pkg) => pkg.write()),
68
61
  ]);
69
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mxpicture/build-api",
3
- "version": "0.2.25",
3
+ "version": "0.2.26",
4
4
  "description": "Build utilities API",
5
5
  "type": "module",
6
6
  "author": "MXPicture",