@mxpicture/build-api 0.2.8 → 0.2.9

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.
@@ -1,11 +1,13 @@
1
- import { BarrelGroup, BarrelResult } from "../types/types.barrel.js";
1
+ import { BarrelGroup, BarrelParams, BarrelResult } from "../types/types.barrel.js";
2
+ import { WorkspacePaths } from "../workspace/WorkspacePaths.js";
2
3
  export declare const DEFAULT_EXCLUDED_PATTERNS: RegExp[];
3
4
  export declare const DEFAULT_HEADER = "// This file is auto-generated. Do not edit manually.\n";
5
+ export declare const runBarrel: (params: BarrelParams) => Promise<void>;
4
6
  export declare class Barrel {
5
- readonly packagesDir: string;
7
+ protected readonly paths: WorkspacePaths;
6
8
  protected readonly excludes: RegExp[];
7
9
  protected readonly fileHeader: string;
8
- constructor(packagesDir: string, excludes?: RegExp[], fileHeader?: string);
10
+ constructor(paths: WorkspacePaths, excludes: RegExp[], fileHeader: string);
9
11
  run(): Promise<void>;
10
12
  protected isExcluded(fileName: string): boolean;
11
13
  protected persistBarrel(group: BarrelGroup): Promise<BarrelGroup>;
@@ -2,6 +2,7 @@ import { basename, dirname, join, relative } from "node:path";
2
2
  import { readdir, rm, writeFile } from "node:fs/promises";
3
3
  import { Pkg } from "../pkg/Pkg.js";
4
4
  import { logInfo, logSuccess } from "../logger/Logger.js";
5
+ import { WorkspacePaths } from "../workspace/WorkspacePaths.js";
5
6
  // /** File patterns to exclude from barrel exports */
6
7
  export const DEFAULT_EXCLUDED_PATTERNS = [
7
8
  /\.test\.ts$/,
@@ -13,17 +14,18 @@ export const DEFAULT_EXCLUDED_PATTERNS = [
13
14
  ];
14
15
  // /** Header comment added to every generated barrel file */
15
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();
16
18
  export class Barrel {
17
- packagesDir;
19
+ paths;
18
20
  excludes;
19
21
  fileHeader;
20
- constructor(packagesDir, excludes, fileHeader) {
21
- this.packagesDir = packagesDir;
22
- this.excludes = excludes ?? DEFAULT_EXCLUDED_PATTERNS;
23
- this.fileHeader = fileHeader ?? DEFAULT_HEADER;
22
+ constructor(paths, excludes, fileHeader) {
23
+ this.paths = paths;
24
+ this.excludes = excludes;
25
+ this.fileHeader = fileHeader;
24
26
  }
25
27
  async run() {
26
- const packageDirs = (await readdir(this.packagesDir)).map((p) => join(this.packagesDir, p));
28
+ const packageDirs = (await readdir(this.paths.workspacesDir)).map((p) => join(this.paths.workspacesDir, p));
27
29
  const promises = [];
28
30
  for (const packageDir of packageDirs) {
29
31
  try {
@@ -93,7 +95,7 @@ export class Barrel {
93
95
  async updatePackageExports(packageDir, packageJsonPath, exports) {
94
96
  try {
95
97
  const pkgJson = new Pkg(packageJsonPath);
96
- const pkgName = relative(this.packagesDir, packageDir);
98
+ const pkgName = relative(this.paths.workspacesDir, packageDir);
97
99
  logInfo(`📦 updating ${pkgName} package.json ...`);
98
100
  const pkg = await pkgJson.readJson();
99
101
  if (!this.hasExportsChanged(exports, pkg.exports)) {
@@ -9,3 +9,9 @@ export interface BarrelResult {
9
9
  packageDir: string;
10
10
  packageJsonPath: string;
11
11
  }
12
+ export interface BarrelParams {
13
+ repoRoot: string;
14
+ workspacesName?: string;
15
+ excludes?: RegExp[];
16
+ fileHeader?: string;
17
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mxpicture/build-api",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "Build utilities API",
5
5
  "type": "module",
6
6
  "author": "MXPicture",