@bemoje/monorepo 1.2.2 → 1.2.3

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.
package/README.md CHANGED
@@ -2,15 +2,49 @@
2
2
 
3
3
  Monorepo workspace management, package discovery, and TypeScript code processing utilities.
4
4
 
5
- [![TypeScript](https://img.shields.io/badge/TypeScript-5-blue)](https://www.typescriptlang.org/)
6
- [![Module](https://img.shields.io/badge/Module-ESM-yellow)](https://nodejs.org/api/esm.html)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5-blue)](https://www.typescriptlang.org/) [![Module](https://img.shields.io/badge/Module-ESM-yellow)](https://nodejs.org/api/esm.html)
6
+
7
+ ## Exports
8
+
9
+ <!-- EXPORTS_START -->
10
+
11
+ - **AbstractBase**: Abstract base class that provides common functionality for monorepo management including parenting and inspection capabilities.
12
+ - **AbstractCode**: Abstract base class for representing code structures in the monorepo with inspection and preview capabilities.
13
+ - **CodeBlock**: Represents a block of code within a larger code structure, defined by an index range.
14
+ - **File**: Represents a file in a workspace with various utility methods to check file types and read contents.
15
+ - **ImportKeywords**: Represents the imported keywords/specifiers in an import statement.
16
+ - **ImportSpecifiers**: Represents and analyzes import specifiers in TypeScript/JavaScript code. This class parses and categorizes different types of import statements such as default imports, named imports, namespace imports, mixed imports, and side effect imports. It provides methods to retrieve specific parts of import statements and to manipulate them.
17
+ - **ImportStatement**: Represents an import statement in TypeScript code with parsing and manipulation capabilities.
18
+ - **ModuleSpecifier**: Represents a module specifier in an import statement. Module specifiers are the strings that indicate where to import from, such as './path/to/file', '
19
+ - **MonoRepo**: Represents a monorepo with workspace management, TypeScript configuration, and dependency analysis capabilities.
20
+ - **SemanticExtnamePrefix**: Constants for semantic filename prefixes used to categorize files by their purpose.
21
+ - **SemanticExtnamePrefixDescriptions**
22
+ - **TestFile**: Represents a test file in the monorepo with TypeScript code analysis capabilities.
23
+ - **TsCode**: Represents TypeScript code with import parsing and manipulation capabilities.
24
+ - **TsFile**: Represents a TypeScript file in the monorepo with code analysis and dependency tracking capabilities.
25
+ - **Workspace**: Represents a workspace within a monorepo, providing functionality to analyze and manage workspace dependencies. A workspace is a directory containing a package.json file and typically source code files. This class provides methods and properties for analyzing: - Source and test files in the workspace - Dependencies declared in package.json - Dependencies imported in source and test files - Missing, unused, and incorrectly imported dependencies
26
+ - **findWorkspacePackageName**: Finds the full package name for a workspace given a partial name.
27
+ - **getAllImports**: Retrieves all import statements from TypeScript source files across all workspaces in the monorepo.
28
+ - **getAllWorkspacePackageJsonPaths**: Gets all workspace package.json file paths.
29
+ - **getAllWorkspacePackageJsons**: Gets all workspace package.json contents.
30
+ - **getAllWorkspacePackageNames**: Gets all workspace package names.
31
+ - **getAllWorkspacePaths**: Returns an array of all workspace directory paths.
32
+ - **getImportsRecursively**: Recursively retrieves all imports for the given entry points, categorizing them into external, builtin, and internal dependencies.
33
+ - **getRepoPackageJson**: Reads the repository's root package.json file.
34
+ - **getRepoPackageJsonPath**: Gets the absolute path to the repository's package.json file.
35
+ - **getRepoRootDirpath**: Get the root directory path of the monorepo by finding the package.json with workspaces configuration.
36
+ - **getWorkspaceDirpaths**: Get all workspace directory paths by reading the workspace patterns from the root package.json.
37
+ - **hasExtnamePrefix**.
38
+ - **resolveModuleImportPath**
39
+ - **semverVersionBump** of a given version string or array based on the specified level. The function supports 'major', 'minor', and 'patch' levels.
40
+
41
+ <!-- EXPORTS_END -->
7
42
 
8
43
  ## Usage
9
44
 
10
45
  ### Managing the Repository & Workspaces
11
46
 
12
- The `MonoRepo` class allows structured, automated tasks against packages and workspaces in a typical monorepo
13
- environment (e.g. yarn, npm, pnpm workspaces).
47
+ The `MonoRepo` class allows structured, automated tasks against packages and workspaces in a typical monorepo environment (e.g. yarn, npm, pnpm workspaces).
14
48
 
15
49
  ```ts
16
50
  import { MonoRepo } from '@mono/monorepo'
@@ -41,59 +75,3 @@ const imports = tsFile.imports
41
75
  // Use utility functions independently of classes
42
76
  const packageName = findWorkspacePackageName('libs/my-feature')
43
77
  ```
44
-
45
- ## API Reference
46
-
47
- ### Core Repository
48
-
49
- | Export | Description |
50
- | -------------- | ---------------------------------------------------------- |
51
- | `MonoRepo` | Central class governing the structure of an open monorepo |
52
- | `Workspace` | Model structure for an individual project/package |
53
- | `AbstractBase` | Foundational primitive used for components mapping classes |
54
-
55
- ### Code & Imports Parsing
56
-
57
- | Export | Description |
58
- | ------------------ | ---------------------------------------------------------- |
59
- | `AbstractCode` | Model providing baseline AST context matching |
60
- | `TsCode` | Encapsulates structural elements found in Typescript code |
61
- | `CodeBlock` | Abstraction representing code blocks and nested structures |
62
- | `ImportStatement` | Comprehensive model for evaluating module imports |
63
- | `ImportKeywords` | Parsed model mapping distinct words injected |
64
- | `ImportSpecifiers` | Parsed model resolving named exports inside imports |
65
- | `ModuleSpecifier` | Model resolving targeted module representations |
66
-
67
- ### File Operations
68
-
69
- | Export | Description |
70
- | ---------- | ---------------------------------------------------------- |
71
- | `File` | Generic cross-platform file wrapper providing baseline IO |
72
- | `TsFile` | File abstraction built specifically for `.ts` processing |
73
- | `TestFile` | Standard test-execution tracking class wrapping code types |
74
-
75
- ### Discovery Methods
76
-
77
- | Export | Description |
78
- | --------------------------------- | --------------------------------------------------------- |
79
- | `getRepoRootDirpath` | Find the repository's root execution configuration index |
80
- | `getRepoPackageJsonPath` | Absolute path to root `package.json` |
81
- | `getRepoPackageJson` | Full structurally parsed data for root `package.json` |
82
- | `getWorkspaceDirpaths` | Retrieve array of directories containing active packages |
83
- | `getAllWorkspacePaths` | Return specific mapped configurations of standard domains |
84
- | `getAllWorkspacePackageJsonPaths` | Array returning strictly active `package.json` paths |
85
- | `getAllWorkspacePackageJsons` | Extract parsing configuration objects for children pkgs |
86
- | `getAllWorkspacePackageNames` | Map name attributes found from all workspace directories |
87
- | `findWorkspacePackageName` | Discover closest named active project bound to child path |
88
-
89
- ### Utilities
90
-
91
- | Export | Description |
92
- | ----------------------------------- | ---------------------------------------------------------- |
93
- | `getAllImports` | Collect import arrays across scopes / boundaries |
94
- | `resolveModuleImportPath` | Convert abstract module statements into absolute locations |
95
- | `semverVersionBump` | Upgrade semantics targeting specific boundaries semver |
96
- | `hasExtnamePrefix` | Matching abstraction targeting specific semantic models |
97
- | `SemanticExtnamePrefix` | Types identifying standard TS suffix standards (`.test`) |
98
- | `SemanticExtnamePrefixes` | Array evaluation tracking suffixes expected across modules |
99
- | `SemanticExtnamePrefixDescriptions` | Readable text models matching semantic prefix usages |
package/lib/index.cjs CHANGED
@@ -2158,7 +2158,9 @@ exports.MonoRepo = class _MonoRepo extends exports.AbstractBase {
2158
2158
  if (!this.packageJson.workspaces) {
2159
2159
  throw new Error(`MonoRepo package.json missing 'workspaces' field: ${this.packageJsonPath}`);
2160
2160
  }
2161
- return this.packageJson.workspaces.map((workspacePath) => {
2161
+ return this.packageJson.workspaces.filter((ws) => {
2162
+ return ws !== ".";
2163
+ }).map((workspacePath) => {
2162
2164
  return path2__default.default.join(this.path, workspacePath.replace(/\*$/, ""));
2163
2165
  });
2164
2166
  }
@@ -2221,7 +2223,9 @@ async function getRepoPackageJson() {
2221
2223
  __name(getRepoPackageJson, "getRepoPackageJson");
2222
2224
  async function getAllWorkspacePaths() {
2223
2225
  const pkg = await getRepoPackageJson();
2224
- return (await Promise.all(pkg.workspaces.map((pattern) => {
2226
+ return (await Promise.all(pkg.workspaces.filter((ws) => {
2227
+ return ws !== ".";
2228
+ }).map((pattern) => {
2225
2229
  return glob.glob(pattern);
2226
2230
  }))).flat().map((fp) => {
2227
2231
  return path2__default.default.normalizeSafe(fp);
@@ -2333,6 +2337,9 @@ async function getImportsRecursively(entryPoints) {
2333
2337
  const builtins = isLocalWorkspace ? builtinsLocal : builtinsRecursive;
2334
2338
  const internals = isLocalWorkspace ? internalsLocal : internalsRecursive;
2335
2339
  const entryPointFile = files.get(curFilepath);
2340
+ if (!entryPointFile) {
2341
+ return;
2342
+ }
2336
2343
  const wsName = entryPointFile.parent.name;
2337
2344
  internals.add(wsName);
2338
2345
  for (const i of entryPointFile.tsCode.imports) {
@@ -2450,7 +2457,9 @@ function getWorkspaceDirpaths() {
2450
2457
  if (!pkg.workspaces) {
2451
2458
  throw new Error(`No workspaces found in package.json at ${rootDirpath}`);
2452
2459
  }
2453
- return pkg.workspaces.flatMap((workspace) => {
2460
+ return pkg.workspaces.filter((ws) => {
2461
+ return ws !== ".";
2462
+ }).flatMap((workspace) => {
2454
2463
  return glob.globSync(workspace);
2455
2464
  }).map(path2__default.default.normalizeSafe);
2456
2465
  }
package/lib/index.js CHANGED
@@ -2144,7 +2144,9 @@ var MonoRepo = class _MonoRepo extends AbstractBase {
2144
2144
  if (!this.packageJson.workspaces) {
2145
2145
  throw new Error(`MonoRepo package.json missing 'workspaces' field: ${this.packageJsonPath}`);
2146
2146
  }
2147
- return this.packageJson.workspaces.map((workspacePath) => {
2147
+ return this.packageJson.workspaces.filter((ws) => {
2148
+ return ws !== ".";
2149
+ }).map((workspacePath) => {
2148
2150
  return path2.join(this.path, workspacePath.replace(/\*$/, ""));
2149
2151
  });
2150
2152
  }
@@ -2207,7 +2209,9 @@ async function getRepoPackageJson() {
2207
2209
  __name(getRepoPackageJson, "getRepoPackageJson");
2208
2210
  async function getAllWorkspacePaths() {
2209
2211
  const pkg = await getRepoPackageJson();
2210
- return (await Promise.all(pkg.workspaces.map((pattern) => {
2212
+ return (await Promise.all(pkg.workspaces.filter((ws) => {
2213
+ return ws !== ".";
2214
+ }).map((pattern) => {
2211
2215
  return glob(pattern);
2212
2216
  }))).flat().map((fp) => {
2213
2217
  return path2.normalizeSafe(fp);
@@ -2319,6 +2323,9 @@ async function getImportsRecursively(entryPoints) {
2319
2323
  const builtins = isLocalWorkspace ? builtinsLocal : builtinsRecursive;
2320
2324
  const internals = isLocalWorkspace ? internalsLocal : internalsRecursive;
2321
2325
  const entryPointFile = files.get(curFilepath);
2326
+ if (!entryPointFile) {
2327
+ return;
2328
+ }
2322
2329
  const wsName = entryPointFile.parent.name;
2323
2330
  internals.add(wsName);
2324
2331
  for (const i of entryPointFile.tsCode.imports) {
@@ -2436,7 +2443,9 @@ function getWorkspaceDirpaths() {
2436
2443
  if (!pkg.workspaces) {
2437
2444
  throw new Error(`No workspaces found in package.json at ${rootDirpath}`);
2438
2445
  }
2439
- return pkg.workspaces.flatMap((workspace) => {
2446
+ return pkg.workspaces.filter((ws) => {
2447
+ return ws !== ".";
2448
+ }).flatMap((workspace) => {
2440
2449
  return globSync(workspace);
2441
2450
  }).map(path2.normalizeSafe);
2442
2451
  }
package/package.json CHANGED
@@ -1,9 +1,24 @@
1
1
  {
2
2
  "name": "@bemoje/monorepo",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "Monorepo workspace management, package discovery, and TypeScript code processing utilities.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "dependencies": {
11
+ "ansi-colors": "^4.1.3",
12
+ "es-toolkit": "^1.45.1",
13
+ "fs-extra": "^11.3.4",
14
+ "glob": "^11.1.0",
15
+ "mnemonist": "^0.40.3",
16
+ "onetime": "^7.0.0",
17
+ "upath": "^2.0.1",
18
+ "depcheck": "^1.4.7",
19
+ "typescript": "^5.5.4",
20
+ "@types/fs-extra": "^11.0.4"
21
+ },
7
22
  "keywords": [
8
23
  "monorepo",
9
24
  "workspace",
@@ -33,297 +48,7 @@
33
48
  "default": "./lib/index.cjs"
34
49
  }
35
50
  },
36
- "./MonoRepo": {
37
- "import": {
38
- "types": "./lib/index.d.ts",
39
- "default": "./lib/index.js"
40
- },
41
- "require": {
42
- "types": "./lib/index.d.cts",
43
- "default": "./lib/index.cjs"
44
- }
45
- },
46
- "./AbstractCode": {
47
- "import": {
48
- "types": "./lib/index.d.ts",
49
- "default": "./lib/index.js"
50
- },
51
- "require": {
52
- "types": "./lib/index.d.cts",
53
- "default": "./lib/index.cjs"
54
- }
55
- },
56
- "./CodeBlock": {
57
- "import": {
58
- "types": "./lib/index.d.ts",
59
- "default": "./lib/index.js"
60
- },
61
- "require": {
62
- "types": "./lib/index.d.cts",
63
- "default": "./lib/index.cjs"
64
- }
65
- },
66
- "./TsCode": {
67
- "import": {
68
- "types": "./lib/index.d.ts",
69
- "default": "./lib/index.js"
70
- },
71
- "require": {
72
- "types": "./lib/index.d.cts",
73
- "default": "./lib/index.cjs"
74
- }
75
- },
76
- "./ImportKeywords": {
77
- "import": {
78
- "types": "./lib/index.d.ts",
79
- "default": "./lib/index.js"
80
- },
81
- "require": {
82
- "types": "./lib/index.d.cts",
83
- "default": "./lib/index.cjs"
84
- }
85
- },
86
- "./ImportSpecifiers": {
87
- "import": {
88
- "types": "./lib/index.d.ts",
89
- "default": "./lib/index.js"
90
- },
91
- "require": {
92
- "types": "./lib/index.d.cts",
93
- "default": "./lib/index.cjs"
94
- }
95
- },
96
- "./ImportStatement": {
97
- "import": {
98
- "types": "./lib/index.d.ts",
99
- "default": "./lib/index.js"
100
- },
101
- "require": {
102
- "types": "./lib/index.d.cts",
103
- "default": "./lib/index.cjs"
104
- }
105
- },
106
- "./ModuleSpecifier": {
107
- "import": {
108
- "types": "./lib/index.d.ts",
109
- "default": "./lib/index.js"
110
- },
111
- "require": {
112
- "types": "./lib/index.d.cts",
113
- "default": "./lib/index.cjs"
114
- }
115
- },
116
- "./AbstractBase": {
117
- "import": {
118
- "types": "./lib/index.d.ts",
119
- "default": "./lib/index.js"
120
- },
121
- "require": {
122
- "types": "./lib/index.d.cts",
123
- "default": "./lib/index.cjs"
124
- }
125
- },
126
- "./File": {
127
- "import": {
128
- "types": "./lib/index.d.ts",
129
- "default": "./lib/index.js"
130
- },
131
- "require": {
132
- "types": "./lib/index.d.cts",
133
- "default": "./lib/index.cjs"
134
- }
135
- },
136
- "./TestFile": {
137
- "import": {
138
- "types": "./lib/index.d.ts",
139
- "default": "./lib/index.js"
140
- },
141
- "require": {
142
- "types": "./lib/index.d.cts",
143
- "default": "./lib/index.cjs"
144
- }
145
- },
146
- "./TsFile": {
147
- "import": {
148
- "types": "./lib/index.d.ts",
149
- "default": "./lib/index.js"
150
- },
151
- "require": {
152
- "types": "./lib/index.d.cts",
153
- "default": "./lib/index.cjs"
154
- }
155
- },
156
- "./findWorkspacePackageName": {
157
- "import": {
158
- "types": "./lib/index.d.ts",
159
- "default": "./lib/index.js"
160
- },
161
- "require": {
162
- "types": "./lib/index.d.cts",
163
- "default": "./lib/index.cjs"
164
- }
165
- },
166
- "./getAllImports": {
167
- "import": {
168
- "types": "./lib/index.d.ts",
169
- "default": "./lib/index.js"
170
- },
171
- "require": {
172
- "types": "./lib/index.d.cts",
173
- "default": "./lib/index.cjs"
174
- }
175
- },
176
- "./getAllWorkspacePackageJsonPaths": {
177
- "import": {
178
- "types": "./lib/index.d.ts",
179
- "default": "./lib/index.js"
180
- },
181
- "require": {
182
- "types": "./lib/index.d.cts",
183
- "default": "./lib/index.cjs"
184
- }
185
- },
186
- "./getAllWorkspacePackageJsons": {
187
- "import": {
188
- "types": "./lib/index.d.ts",
189
- "default": "./lib/index.js"
190
- },
191
- "require": {
192
- "types": "./lib/index.d.cts",
193
- "default": "./lib/index.cjs"
194
- }
195
- },
196
- "./getAllWorkspacePackageNames": {
197
- "import": {
198
- "types": "./lib/index.d.ts",
199
- "default": "./lib/index.js"
200
- },
201
- "require": {
202
- "types": "./lib/index.d.cts",
203
- "default": "./lib/index.cjs"
204
- }
205
- },
206
- "./getAllWorkspacePaths": {
207
- "import": {
208
- "types": "./lib/index.d.ts",
209
- "default": "./lib/index.js"
210
- },
211
- "require": {
212
- "types": "./lib/index.d.cts",
213
- "default": "./lib/index.cjs"
214
- }
215
- },
216
- "./getImportsRecursively": {
217
- "import": {
218
- "types": "./lib/index.d.ts",
219
- "default": "./lib/index.js"
220
- },
221
- "require": {
222
- "types": "./lib/index.d.cts",
223
- "default": "./lib/index.cjs"
224
- }
225
- },
226
- "./getRepoPackageJson": {
227
- "import": {
228
- "types": "./lib/index.d.ts",
229
- "default": "./lib/index.js"
230
- },
231
- "require": {
232
- "types": "./lib/index.d.cts",
233
- "default": "./lib/index.cjs"
234
- }
235
- },
236
- "./getRepoPackageJsonPath": {
237
- "import": {
238
- "types": "./lib/index.d.ts",
239
- "default": "./lib/index.js"
240
- },
241
- "require": {
242
- "types": "./lib/index.d.cts",
243
- "default": "./lib/index.cjs"
244
- }
245
- },
246
- "./Workspace": {
247
- "import": {
248
- "types": "./lib/index.d.ts",
249
- "default": "./lib/index.js"
250
- },
251
- "require": {
252
- "types": "./lib/index.d.cts",
253
- "default": "./lib/index.cjs"
254
- }
255
- },
256
- "./SemanticExtnamePrefix": {
257
- "import": {
258
- "types": "./lib/index.d.ts",
259
- "default": "./lib/index.js"
260
- },
261
- "require": {
262
- "types": "./lib/index.d.cts",
263
- "default": "./lib/index.cjs"
264
- }
265
- },
266
- "./SemanticExtnamePrefixDescriptions": {
267
- "import": {
268
- "types": "./lib/index.d.ts",
269
- "default": "./lib/index.js"
270
- },
271
- "require": {
272
- "types": "./lib/index.d.cts",
273
- "default": "./lib/index.cjs"
274
- }
275
- },
276
- "./SemanticExtnamePrefixes": {
277
- "import": {
278
- "types": "./lib/index.d.ts",
279
- "default": "./lib/index.js"
280
- },
281
- "require": {
282
- "types": "./lib/index.d.cts",
283
- "default": "./lib/index.cjs"
284
- }
285
- },
286
- "./getRepoRootDirpath": {
287
- "import": {
288
- "types": "./lib/index.d.ts",
289
- "default": "./lib/index.js"
290
- },
291
- "require": {
292
- "types": "./lib/index.d.cts",
293
- "default": "./lib/index.cjs"
294
- }
295
- },
296
- "./getWorkspaceDirpaths": {
297
- "import": {
298
- "types": "./lib/index.d.ts",
299
- "default": "./lib/index.js"
300
- },
301
- "require": {
302
- "types": "./lib/index.d.cts",
303
- "default": "./lib/index.cjs"
304
- }
305
- },
306
- "./hasExtnamePrefix": {
307
- "import": {
308
- "types": "./lib/index.d.ts",
309
- "default": "./lib/index.js"
310
- },
311
- "require": {
312
- "types": "./lib/index.d.cts",
313
- "default": "./lib/index.cjs"
314
- }
315
- },
316
- "./resolveModuleImportPath": {
317
- "import": {
318
- "types": "./lib/index.d.ts",
319
- "default": "./lib/index.js"
320
- },
321
- "require": {
322
- "types": "./lib/index.d.cts",
323
- "default": "./lib/index.cjs"
324
- }
325
- },
326
- "./semverVersionBump": {
51
+ "./*": {
327
52
  "import": {
328
53
  "types": "./lib/index.d.ts",
329
54
  "default": "./lib/index.js"
@@ -334,30 +59,15 @@
334
59
  }
335
60
  }
336
61
  },
337
- "dependencies": {
338
- "ansi-colors": "^4.1.3",
339
- "es-toolkit": "^1.45.1",
340
- "fs-extra": "^11.3.4",
341
- "glob": "^11.1.0",
342
- "mnemonist": "^0.40.3",
343
- "onetime": "^7.0.0",
344
- "upath": "^2.0.1",
345
- "depcheck": "^1.4.7",
346
- "typescript": "^5.5.4",
347
- "@types/fs-extra": "^11.0.4"
348
- },
349
- "publishConfig": {
350
- "access": "public"
62
+ "repository": {
63
+ "type": "git",
64
+ "url": "git+https://github.com/bemoje/mono.git",
65
+ "directory": "libs/monorepo"
351
66
  },
352
- "license": "MIT",
353
67
  "author": {
354
68
  "name": "Benjamin Møller Jensen",
355
69
  "email": "bemoje@bemoje.net",
356
70
  "url": "https://github.com/bemoje/"
357
71
  },
358
- "repository": {
359
- "type": "git",
360
- "url": "git+https://github.com/bemoje/mono.git",
361
- "directory": "libs/monorepo"
362
- }
72
+ "license": "MIT"
363
73
  }