@bemoje/monorepo 1.0.0 → 1.2.0

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 (128) hide show
  1. package/README.md +99 -0
  2. package/lib/MonoRepo.cjs +142 -0
  3. package/lib/MonoRepo.d.cts +10 -0
  4. package/lib/MonoRepo.d.ts +10 -0
  5. package/lib/MonoRepo.js +134 -0
  6. package/lib/code/AbstractCode.cjs +77 -0
  7. package/lib/code/AbstractCode.d.cts +30 -0
  8. package/lib/code/AbstractCode.d.ts +30 -0
  9. package/lib/code/AbstractCode.js +74 -0
  10. package/lib/code/CodeBlock.cjs +51 -0
  11. package/lib/code/CodeBlock.d.cts +22 -0
  12. package/lib/code/CodeBlock.d.ts +22 -0
  13. package/lib/code/CodeBlock.js +48 -0
  14. package/lib/code/TsCode.cjs +90 -0
  15. package/lib/code/TsCode.d.cts +10 -0
  16. package/lib/code/TsCode.d.ts +10 -0
  17. package/lib/code/TsCode.js +87 -0
  18. package/lib/code/imports/ImportKeywords.cjs +42 -0
  19. package/lib/code/imports/ImportKeywords.d.cts +10 -0
  20. package/lib/code/imports/ImportKeywords.d.ts +10 -0
  21. package/lib/code/imports/ImportKeywords.js +39 -0
  22. package/lib/code/imports/ImportSpecifiers.cjs +98 -0
  23. package/lib/code/imports/ImportSpecifiers.d.cts +10 -0
  24. package/lib/code/imports/ImportSpecifiers.d.ts +10 -0
  25. package/lib/code/imports/ImportSpecifiers.js +95 -0
  26. package/lib/code/imports/ImportStatement.cjs +89 -0
  27. package/lib/code/imports/ImportStatement.d.cts +10 -0
  28. package/lib/code/imports/ImportStatement.d.ts +10 -0
  29. package/lib/code/imports/ImportStatement.js +86 -0
  30. package/lib/code/imports/ModuleSpecifier.cjs +77 -0
  31. package/lib/code/imports/ModuleSpecifier.d.cts +10 -0
  32. package/lib/code/imports/ModuleSpecifier.d.ts +10 -0
  33. package/lib/code/imports/ModuleSpecifier.js +74 -0
  34. package/lib/common/AbstractBase.cjs +77 -0
  35. package/lib/common/AbstractBase.d.cts +3 -0
  36. package/lib/common/AbstractBase.d.ts +3 -0
  37. package/lib/common/AbstractBase.js +74 -0
  38. package/lib/file/File.cjs +118 -0
  39. package/lib/file/File.d.cts +10 -0
  40. package/lib/file/File.d.ts +10 -0
  41. package/lib/file/File.js +91 -0
  42. package/lib/file/TestFile.cjs +42 -0
  43. package/lib/file/TestFile.d.cts +10 -0
  44. package/lib/file/TestFile.d.ts +10 -0
  45. package/lib/file/TestFile.js +39 -0
  46. package/lib/file/TsFile.cjs +46 -0
  47. package/lib/file/TsFile.d.cts +10 -0
  48. package/lib/file/TsFile.d.ts +10 -0
  49. package/lib/file/TsFile.js +43 -0
  50. package/lib/index.cjs +215 -0
  51. package/lib/index.d.cts +26 -0
  52. package/lib/index.d.ts +26 -0
  53. package/lib/index.js +30 -0
  54. package/lib/methods/findWorkspacePackageName.cjs +17 -0
  55. package/lib/methods/findWorkspacePackageName.d.cts +6 -0
  56. package/lib/methods/findWorkspacePackageName.d.ts +6 -0
  57. package/lib/methods/findWorkspacePackageName.js +14 -0
  58. package/lib/methods/getAllImports.cjs +18 -0
  59. package/lib/methods/getAllImports.d.cts +17 -0
  60. package/lib/methods/getAllImports.d.ts +17 -0
  61. package/lib/methods/getAllImports.js +16 -0
  62. package/lib/methods/getAllWorkspacePackageJsonPaths.cjs +20 -0
  63. package/lib/methods/getAllWorkspacePackageJsonPaths.d.cts +6 -0
  64. package/lib/methods/getAllWorkspacePackageJsonPaths.d.ts +6 -0
  65. package/lib/methods/getAllWorkspacePackageJsonPaths.js +13 -0
  66. package/lib/methods/getAllWorkspacePackageJsons.cjs +20 -0
  67. package/lib/methods/getAllWorkspacePackageJsons.d.cts +6 -0
  68. package/lib/methods/getAllWorkspacePackageJsons.d.ts +6 -0
  69. package/lib/methods/getAllWorkspacePackageJsons.js +13 -0
  70. package/lib/methods/getAllWorkspacePackageNames.cjs +15 -0
  71. package/lib/methods/getAllWorkspacePackageNames.d.cts +6 -0
  72. package/lib/methods/getAllWorkspacePackageNames.d.ts +6 -0
  73. package/lib/methods/getAllWorkspacePackageNames.js +12 -0
  74. package/lib/methods/getAllWorkspacePaths.cjs +23 -0
  75. package/lib/methods/getAllWorkspacePaths.d.cts +6 -0
  76. package/lib/methods/getAllWorkspacePaths.d.ts +6 -0
  77. package/lib/methods/getAllWorkspacePaths.js +16 -0
  78. package/lib/methods/getImportsRecursively.cjs +176 -0
  79. package/lib/methods/getImportsRecursively.d.cts +37 -0
  80. package/lib/methods/getImportsRecursively.d.ts +37 -0
  81. package/lib/methods/getImportsRecursively.js +168 -0
  82. package/lib/methods/getRepoPackageJson.cjs +17 -0
  83. package/lib/methods/getRepoPackageJson.d.cts +6 -0
  84. package/lib/methods/getRepoPackageJson.d.ts +6 -0
  85. package/lib/methods/getRepoPackageJson.js +10 -0
  86. package/lib/methods/getRepoPackageJsonPath.cjs +17 -0
  87. package/lib/methods/getRepoPackageJsonPath.d.cts +6 -0
  88. package/lib/methods/getRepoPackageJsonPath.d.ts +6 -0
  89. package/lib/methods/getRepoPackageJsonPath.js +10 -0
  90. package/lib/repo/Workspace.cjs +383 -0
  91. package/lib/repo/Workspace.d.cts +10 -0
  92. package/lib/repo/Workspace.d.ts +10 -0
  93. package/lib/repo/Workspace.js +376 -0
  94. package/lib/util/SemanticExtnamePrefix.cjs +12 -0
  95. package/lib/util/SemanticExtnamePrefix.d.cts +14 -0
  96. package/lib/util/SemanticExtnamePrefix.d.ts +14 -0
  97. package/lib/util/SemanticExtnamePrefix.js +12 -0
  98. package/lib/util/SemanticExtnamePrefixDescriptions.cjs +12 -0
  99. package/lib/util/SemanticExtnamePrefixDescriptions.d.cts +15 -0
  100. package/lib/util/SemanticExtnamePrefixDescriptions.d.ts +15 -0
  101. package/lib/util/SemanticExtnamePrefixDescriptions.js +12 -0
  102. package/lib/util/SemanticExtnamePrefixes.cjs +9 -0
  103. package/lib/util/SemanticExtnamePrefixes.d.cts +97 -0
  104. package/lib/util/SemanticExtnamePrefixes.d.ts +97 -0
  105. package/lib/util/SemanticExtnamePrefixes.js +6 -0
  106. package/lib/util/getRepoRootDirpath.cjs +30 -0
  107. package/lib/util/getRepoRootDirpath.d.cts +6 -0
  108. package/lib/util/getRepoRootDirpath.d.ts +6 -0
  109. package/lib/util/getRepoRootDirpath.js +21 -0
  110. package/lib/util/getWorkspaceDirpaths.cjs +27 -0
  111. package/lib/util/getWorkspaceDirpaths.d.cts +6 -0
  112. package/lib/util/getWorkspaceDirpaths.d.ts +6 -0
  113. package/lib/util/getWorkspaceDirpaths.js +19 -0
  114. package/lib/util/hasExtnamePrefix.cjs +18 -0
  115. package/lib/util/hasExtnamePrefix.d.cts +38 -0
  116. package/lib/util/hasExtnamePrefix.d.ts +38 -0
  117. package/lib/util/hasExtnamePrefix.js +11 -0
  118. package/lib/util/resolveModuleImportPath.cjs +34 -0
  119. package/lib/util/resolveModuleImportPath.d.cts +8 -0
  120. package/lib/util/resolveModuleImportPath.d.ts +8 -0
  121. package/lib/util/resolveModuleImportPath.js +26 -0
  122. package/lib/util/semverVersionBump.cjs +28 -0
  123. package/lib/util/semverVersionBump.d.cts +22 -0
  124. package/lib/util/semverVersionBump.d.ts +22 -0
  125. package/lib/util/semverVersionBump.js +26 -0
  126. package/package.json +464 -32
  127. package/index.d.ts +0 -636
  128. package/index.mjs +0 -2330
@@ -0,0 +1,376 @@
1
+ import { __name } from '../chunk-SHUYVCID.js';
2
+ import { AbstractBase } from '../common/AbstractBase';
3
+ import { Inspector, Parenting } from '@mono/composition';
4
+ import { SemanticExtnamePrefix } from '../util/SemanticExtnamePrefix';
5
+ import { TestFile } from '../file/TestFile';
6
+ import { TsFile } from '../file/TsFile';
7
+ import { difference, union } from 'es-toolkit/array';
8
+ import { exec } from 'child_process';
9
+ import { hasExtnamePrefix } from '../util/hasExtnamePrefix';
10
+ import { hasParentDirname } from '@mono/path';
11
+ import { lazyProp } from '@mono/decorators';
12
+ import path from 'upath';
13
+ import { promisify } from 'util';
14
+ import { readJsonSync } from 'fs-extra/esm';
15
+ import { resolveModuleImportPath } from '../util/resolveModuleImportPath';
16
+ import { uniq } from 'es-toolkit';
17
+ import { walkDirectory } from '@mono/fs';
18
+
19
+ function _ts_decorate(decorators, target, key, desc) {
20
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
21
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
22
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
23
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
24
+ }
25
+ __name(_ts_decorate, "_ts_decorate");
26
+ function _ts_metadata(k, v) {
27
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
28
+ }
29
+ __name(_ts_metadata, "_ts_metadata");
30
+ class Workspace extends AbstractBase {
31
+ static {
32
+ __name(this, "Workspace");
33
+ }
34
+ static inspector = Inspector.compose(Workspace, {
35
+ keys: [
36
+ "name",
37
+ "tsFiles",
38
+ "testFiles"
39
+ ]
40
+ });
41
+ /**
42
+ * The workspace's origin directory name, eg. 'libs', 'apps', etc.
43
+ */
44
+ origin;
45
+ /**
46
+ * The workspace's root directory path.
47
+ */
48
+ path;
49
+ constructor(parent, dirpath) {
50
+ super(parent);
51
+ this.path = path.normalize(dirpath);
52
+ this.origin = path.basename(path.dirname(this.path));
53
+ }
54
+ /**
55
+ * The workspace's package.json filepath.
56
+ */
57
+ get packageJsonPath() {
58
+ return path.join(this.path, "package.json");
59
+ }
60
+ /**
61
+ * The workspace's package.json file as an object.
62
+ */
63
+ get packageJson() {
64
+ return readJsonSync(this.packageJsonPath);
65
+ }
66
+ /**
67
+ * The workspace's name from the package.json file.
68
+ */
69
+ get name() {
70
+ if (!this.packageJson.name) {
71
+ throw new Error(`Workspace package.json missing 'name' field: ${this.packageJsonPath}`);
72
+ }
73
+ return this.packageJson.name;
74
+ }
75
+ /**
76
+ * Reads the workspace's package.json file and returns the 'dependencies' field as a sorted array of strings.
77
+ */
78
+ get installedDependencies() {
79
+ const deps = this.packageJson.dependencies ?? {};
80
+ return Object.keys(deps).sort();
81
+ }
82
+ /**
83
+ * Reads the workspace's package.json file and returns the 'devDependencies' field as a sorted array of strings.
84
+ */
85
+ get installedDevDependencies() {
86
+ const deps = this.packageJson.devDependencies ?? {};
87
+ return Object.keys(deps).sort();
88
+ }
89
+ /**
90
+ * Get all unique file-level dependencies of the workspace, including transitive dependencies through other local workspaces.
91
+ *
92
+ * This method recursively traverses the dependency graph of the workspace, collecting all unique dependencies. It distinguishes between internal dependencies (other local workspaces) and external dependencies (npm packages).
93
+ *
94
+ * @returns An object containing two arrays: `internal` for internal workspace dependencies and `external` for npm package dependencies.
95
+ */
96
+ get importedDependenciesRecursive() {
97
+ const repo = this.parent;
98
+ const wsNames = new Set(repo.workspaces.map((w) => {
99
+ return w.name;
100
+ }));
101
+ const allDeps = recurse(this.tsFiles.filter((f) => {
102
+ return f.isSourceFile;
103
+ }));
104
+ const internal = [
105
+ ...allDeps
106
+ ].filter((d) => {
107
+ return wsNames.has(d);
108
+ }).sort();
109
+ const external = [
110
+ ...allDeps
111
+ ].filter((d) => {
112
+ return !wsNames.has(d);
113
+ }).sort();
114
+ function recurse(files, allDeps2 = /* @__PURE__ */ new Set(), visited = /* @__PURE__ */ new Set(), depth = 0) {
115
+ for (const file of files) {
116
+ if (visited.has(file.path)) {
117
+ continue;
118
+ }
119
+ visited.add(file.path);
120
+ for (const dep of file.dependencies) {
121
+ allDeps2.add(dep);
122
+ const depWs = repo.workspaces.find((w) => {
123
+ return w.name === dep;
124
+ });
125
+ if (depWs) {
126
+ recurse(depWs.tsFiles.filter((f) => {
127
+ return f.isSourceFile;
128
+ }), allDeps2, visited, depth + 1).forEach((d) => {
129
+ return allDeps2.add(d);
130
+ });
131
+ }
132
+ }
133
+ }
134
+ return allDeps2;
135
+ }
136
+ __name(recurse, "recurse");
137
+ return {
138
+ internal,
139
+ external
140
+ };
141
+ }
142
+ /**
143
+ * Get the source files in the workspace's 'src' directory.
144
+ * Test files are not included.
145
+ */
146
+ get tsFiles() {
147
+ return walkDirectory(this.path, {
148
+ stats: true,
149
+ only: "files",
150
+ filter: /* @__PURE__ */ __name((_dirpath, basename) => {
151
+ if (basename === "node_modules") {
152
+ return false;
153
+ }
154
+ if (basename === "coverage") {
155
+ return false;
156
+ }
157
+ if (basename.startsWith(".")) {
158
+ return false;
159
+ }
160
+ return true;
161
+ }, "filter")
162
+ }).filter(([fspath]) => {
163
+ return hasParentDirname(fspath, "src") && !hasExtnamePrefix(fspath);
164
+ }).map(([fspath]) => {
165
+ return new TsFile(this, fspath);
166
+ });
167
+ }
168
+ /**
169
+ * Get the test files in the workspace's 'src' directory.
170
+ */
171
+ get testFiles() {
172
+ return walkDirectory(this.path, {
173
+ stats: true,
174
+ only: "files",
175
+ filter: /* @__PURE__ */ __name((_dirpath, basename) => {
176
+ if (basename === "node_modules") {
177
+ return false;
178
+ }
179
+ if (basename === "coverage") {
180
+ return false;
181
+ }
182
+ if (basename.startsWith(".")) {
183
+ return false;
184
+ }
185
+ return true;
186
+ }, "filter")
187
+ }).filter(([fspath]) => {
188
+ return hasParentDirname(fspath, "src") && !hasExtnamePrefix(fspath, SemanticExtnamePrefix.test);
189
+ }).map(([fspath]) => {
190
+ return new TestFile(this, fspath);
191
+ });
192
+ }
193
+ get files() {
194
+ return [
195
+ ...this.tsFiles,
196
+ ...this.testFiles
197
+ ];
198
+ }
199
+ /**
200
+ * Get imported non-relative dependencies for each source file in the workspace, grouped by file.
201
+ */
202
+ get importedDependenciesByFile() {
203
+ return new Map(this.tsFiles.map((file) => {
204
+ return [
205
+ path.relative(process.cwd(), file.path),
206
+ file.dependencies
207
+ ];
208
+ }));
209
+ }
210
+ /**
211
+ * Get imported non-relative dependencies for each test file in the workspace, grouped by file.
212
+ */
213
+ get importedTestDependenciesByFile() {
214
+ return new Map(this.testFiles.map((file) => {
215
+ return [
216
+ path.relative(process.cwd(), file.path),
217
+ file.dependencies
218
+ ];
219
+ }));
220
+ }
221
+ /**
222
+ * Get imported non-relative dependencies for each source file in the workspace in a flat array.
223
+ */
224
+ get importedDependencies() {
225
+ return uniq(Array.from(this.importedDependenciesByFile.values()).flat());
226
+ }
227
+ /**
228
+ * Get imported non-relative dependencies for each test file in the workspace in a flat array.
229
+ */
230
+ get importedTestDependencies() {
231
+ return uniq(Array.from(this.importedTestDependenciesByFile.values()).flat());
232
+ }
233
+ /**
234
+ * Get dependencies that are imported but not listed in the workspace's package.json under 'dependencies'.
235
+ */
236
+ get missingDependencies() {
237
+ return difference(this.importedDependencies, this.installedDependencies).filter((dep) => {
238
+ return !this.parent.packageJson.dependencies?.[dep];
239
+ }).filter((dep) => {
240
+ return !this.parent.tsconfigBasePaths?.[dep];
241
+ });
242
+ }
243
+ /**
244
+ * Get dependencies that are imported but not listed in the workspace's package.json under 'devDependencies'.
245
+ */
246
+ get missingDevDependencies() {
247
+ return difference(this.importedTestDependencies, union(this.installedDependencies, this.installedDevDependencies)).filter((dep) => {
248
+ return !this.parent.packageJson.devDependencies?.[dep];
249
+ }).filter((dep) => {
250
+ return !this.parent.packageJson.dependencies?.[dep];
251
+ }).filter((dep) => {
252
+ return !this.parent.tsconfigBasePaths?.[dep];
253
+ });
254
+ }
255
+ /**
256
+ * Get dependencies that are listed in the workspace's package.json but not imported in any source file (excl. test files).
257
+ */
258
+ get unusedDependencies() {
259
+ return difference(this.installedDependencies, this.importedDependencies);
260
+ }
261
+ /**
262
+ *
263
+ */
264
+ get incorrectlyImportedRepoWorkspaces() {
265
+ const results = [];
266
+ for (const file of this.files) {
267
+ for (const imp of file.tsCode.imports) {
268
+ if (imp.module.from === this.name) {
269
+ const resolvedFileName = resolveModuleImportPath(file.path, imp.module.from)?.resolvedFileName;
270
+ if (resolvedFileName) {
271
+ results.push({
272
+ filepath: file.path,
273
+ replaceValue: imp.module.from,
274
+ withValue: resolvedFileName.endsWith("index.ts") ? `./${imp.specifiers?.importedNamesArray[0]}` : `./${path.relative(path.dirname(file.path), resolvedFileName)}`
275
+ });
276
+ }
277
+ }
278
+ }
279
+ }
280
+ return results;
281
+ }
282
+ /**
283
+ * Returns an object with found dependency problems for the workspace or undefined if no problems were found.
284
+ * @see WorkspaceDependencyProblems
285
+ */
286
+ get dependencyProblems() {
287
+ const result = {
288
+ origin: this.origin,
289
+ workspace: this.name,
290
+ unused: this.unusedDependencies,
291
+ missing: this.missingDependencies,
292
+ missingDev: this.missingDevDependencies,
293
+ imports: this.incorrectlyImportedRepoWorkspaces
294
+ };
295
+ if (!result.unused.length && !result.missing.length && !result.missingDev.length) {
296
+ return void 0;
297
+ }
298
+ for (const [key, value] of Object.entries(result)) {
299
+ if (!value.length) {
300
+ delete result[key];
301
+ }
302
+ }
303
+ return result;
304
+ }
305
+ async depcheck() {
306
+ try {
307
+ const rootPkg = this.parent.packageJson;
308
+ const dependencies = rootPkg.dependencies || {};
309
+ const devDependencies = rootPkg.devDependencies || {};
310
+ const ignores = Object.keys({
311
+ ...devDependencies,
312
+ ...dependencies
313
+ }).concat("@mono/*");
314
+ const ignoresFlag = `--ignores "${ignores.join(",")}"`;
315
+ const cmd = `yarn depcheck ${this.path} ${ignoresFlag} --json`;
316
+ const execPromise = promisify(exec);
317
+ const res = await execPromise(cmd);
318
+ return JSON.parse(res.stdout.toString());
319
+ } catch (error) {
320
+ const res = error;
321
+ if (res.stdout) {
322
+ return JSON.parse(res.stdout.toString());
323
+ }
324
+ console.error(error);
325
+ return {
326
+ dependencies: [],
327
+ devDependencies: [],
328
+ using: {},
329
+ missing: {},
330
+ invalidFiles: {},
331
+ invalidDirs: {}
332
+ };
333
+ }
334
+ }
335
+ /**
336
+ * Returns the workspace's cwd-relative path.
337
+ */
338
+ toString() {
339
+ return path.relative(process.cwd(), this.path);
340
+ }
341
+ }
342
+ _ts_decorate([
343
+ lazyProp(1e3),
344
+ _ts_metadata("design:type", typeof PackageJson === "undefined" ? Object : PackageJson),
345
+ _ts_metadata("design:paramtypes", [])
346
+ ], Workspace.prototype, "packageJson", null);
347
+ _ts_decorate([
348
+ lazyProp(5e3),
349
+ _ts_metadata("design:type", Array),
350
+ _ts_metadata("design:paramtypes", [])
351
+ ], Workspace.prototype, "tsFiles", null);
352
+ _ts_decorate([
353
+ lazyProp(5e3),
354
+ _ts_metadata("design:type", Array),
355
+ _ts_metadata("design:paramtypes", [])
356
+ ], Workspace.prototype, "testFiles", null);
357
+ _ts_decorate([
358
+ lazyProp(1e3),
359
+ _ts_metadata("design:type", typeof Map === "undefined" ? Object : Map),
360
+ _ts_metadata("design:paramtypes", [])
361
+ ], Workspace.prototype, "importedDependenciesByFile", null);
362
+ _ts_decorate([
363
+ lazyProp(1e3),
364
+ _ts_metadata("design:type", typeof Map === "undefined" ? Object : Map),
365
+ _ts_metadata("design:paramtypes", [])
366
+ ], Workspace.prototype, "importedTestDependenciesByFile", null);
367
+ Workspace = _ts_decorate([
368
+ Parenting.compose,
369
+ _ts_metadata("design:type", Function),
370
+ _ts_metadata("design:paramtypes", [
371
+ typeof P === "undefined" ? Object : P,
372
+ String
373
+ ])
374
+ ], Workspace);
375
+
376
+ export { Workspace };
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ const SemanticExtnamePrefix = {
4
+ d: "d",
5
+ test: "test",
6
+ examples: "examples",
7
+ benchmark: "benchmark",
8
+ temp: "temp",
9
+ wip: "wip"
10
+ };
11
+
12
+ exports.SemanticExtnamePrefix = SemanticExtnamePrefix;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Constants for semantic filename prefixes used to categorize files by their purpose.
3
+ */
4
+ type SemanticExtnamePrefix = (typeof SemanticExtnamePrefix)[keyof typeof SemanticExtnamePrefix];
5
+ declare const SemanticExtnamePrefix: {
6
+ readonly d: "d";
7
+ readonly test: "test";
8
+ readonly examples: "examples";
9
+ readonly benchmark: "benchmark";
10
+ readonly temp: "temp";
11
+ readonly wip: "wip";
12
+ };
13
+
14
+ export { SemanticExtnamePrefix };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Constants for semantic filename prefixes used to categorize files by their purpose.
3
+ */
4
+ type SemanticExtnamePrefix = (typeof SemanticExtnamePrefix)[keyof typeof SemanticExtnamePrefix];
5
+ declare const SemanticExtnamePrefix: {
6
+ readonly d: "d";
7
+ readonly test: "test";
8
+ readonly examples: "examples";
9
+ readonly benchmark: "benchmark";
10
+ readonly temp: "temp";
11
+ readonly wip: "wip";
12
+ };
13
+
14
+ export { SemanticExtnamePrefix };
@@ -0,0 +1,12 @@
1
+ import '../chunk-SHUYVCID.js';
2
+
3
+ const SemanticExtnamePrefix = {
4
+ d: "d",
5
+ test: "test",
6
+ examples: "examples",
7
+ benchmark: "benchmark",
8
+ temp: "temp",
9
+ wip: "wip"
10
+ };
11
+
12
+ export { SemanticExtnamePrefix };
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ const SemanticExtnamePrefixDescriptions = {
4
+ d: "declarations",
5
+ test: "vitest test suite",
6
+ examples: "contains working and tested example usage code. Included in git, but ignored by most repo tools",
7
+ benchmark: "benchmark files, included in git, but ignored by most repo tools.",
8
+ temp: "temporary files, ignored by git, build, tests, etc.",
9
+ wip: "work in progress, ignored by git, build, tests, etc."
10
+ };
11
+
12
+ exports.SemanticExtnamePrefixDescriptions = SemanticExtnamePrefixDescriptions;
@@ -0,0 +1,15 @@
1
+ import { SemanticExtnamePrefix } from './SemanticExtnamePrefix.cjs';
2
+
3
+ /**
4
+ * A record mapping semantic extname prefixes to their descriptions.
5
+ *
6
+ * - `d`: Declaration files
7
+ * - `test`: Vitest test suite files
8
+ * - `examples`: Files containing working and tested example usage code (included in git, but ignored by most repo tools)
9
+ * - `benchmark`: Benchmark files (included in git, but ignored by most repo tools)
10
+ * - `temp`: Temporary files (ignored by git, build, tests, etc.)
11
+ * - `wip`: Work in progress files (ignored by git, build, tests, etc.)
12
+ */
13
+ declare const SemanticExtnamePrefixDescriptions: Record<SemanticExtnamePrefix, string>;
14
+
15
+ export { SemanticExtnamePrefixDescriptions };
@@ -0,0 +1,15 @@
1
+ import { SemanticExtnamePrefix } from './SemanticExtnamePrefix.js';
2
+
3
+ /**
4
+ * A record mapping semantic extname prefixes to their descriptions.
5
+ *
6
+ * - `d`: Declaration files
7
+ * - `test`: Vitest test suite files
8
+ * - `examples`: Files containing working and tested example usage code (included in git, but ignored by most repo tools)
9
+ * - `benchmark`: Benchmark files (included in git, but ignored by most repo tools)
10
+ * - `temp`: Temporary files (ignored by git, build, tests, etc.)
11
+ * - `wip`: Work in progress files (ignored by git, build, tests, etc.)
12
+ */
13
+ declare const SemanticExtnamePrefixDescriptions: Record<SemanticExtnamePrefix, string>;
14
+
15
+ export { SemanticExtnamePrefixDescriptions };
@@ -0,0 +1,12 @@
1
+ import '../chunk-SHUYVCID.js';
2
+
3
+ const SemanticExtnamePrefixDescriptions = {
4
+ d: "declarations",
5
+ test: "vitest test suite",
6
+ examples: "contains working and tested example usage code. Included in git, but ignored by most repo tools",
7
+ benchmark: "benchmark files, included in git, but ignored by most repo tools.",
8
+ temp: "temporary files, ignored by git, build, tests, etc.",
9
+ wip: "work in progress, ignored by git, build, tests, etc."
10
+ };
11
+
12
+ export { SemanticExtnamePrefixDescriptions };
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ var SemanticExtnamePrefix = require('./SemanticExtnamePrefix');
4
+
5
+ var SemanticExtnamePrefixes_default = Object.values(SemanticExtnamePrefix.SemanticExtnamePrefix);
6
+
7
+ module.exports = SemanticExtnamePrefixes_default;
8
+
9
+ module.exports = exports.default;
@@ -0,0 +1,97 @@
1
+ import { SemanticExtnamePrefix } from './SemanticExtnamePrefix.cjs';
2
+ import { I as IsNever } from '../is-never.d-CgQ1j0-8.cjs';
3
+
4
+ /**
5
+ Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
6
+
7
+ Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
8
+
9
+ @example
10
+ ```
11
+ import type {UnionToIntersection} from 'type-fest';
12
+
13
+ type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
14
+
15
+ type Intersection = UnionToIntersection<Union>;
16
+ //=> {the(): void} & {great(arg: string): void} & {escape: boolean}
17
+ ```
18
+
19
+ @category Type
20
+ */
21
+ type UnionToIntersection<Union> = (
22
+ // `extends unknown` is always going to be the case and is used to convert the
23
+ // `Union` into a [distributive conditional
24
+ // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
25
+ Union extends unknown
26
+ // The union type is used as the only argument to a function since the union
27
+ // of function arguments is an intersection.
28
+ ? (distributedUnion: Union) => void
29
+ // This won't happen.
30
+ : never
31
+ // Infer the `Intersection` type since TypeScript represents the positional
32
+ // arguments of unions of functions as an intersection of the union.
33
+ ) extends ((mergedIntersection: infer Intersection) => void)
34
+ // The `& Union` is to ensure result of `UnionToIntersection<A | B>` is always assignable to `A | B`
35
+ ? Intersection & Union
36
+ : never;
37
+
38
+ /**
39
+ Returns the last element of a union type.
40
+
41
+ @example
42
+ ```
43
+ type Last = LastOfUnion<1 | 2 | 3>;
44
+ //=> 3
45
+ ```
46
+ */
47
+ type LastOfUnion<T> =
48
+ UnionToIntersection<T extends any ? () => T : never> extends () => (infer R)
49
+ ? R
50
+ : never;
51
+
52
+ /**
53
+ Convert a union type into an unordered tuple type of its elements.
54
+
55
+ "Unordered" means the elements of the tuple are not guaranteed to be in the same order as in the union type. The arrangement can appear random and may change at any time.
56
+
57
+ This can be useful when you have objects with a finite set of keys and want a type defining only the allowed keys, but do not want to repeat yourself.
58
+
59
+ @example
60
+ ```
61
+ import type {UnionToTuple} from 'type-fest';
62
+
63
+ type Numbers = 1 | 2 | 3;
64
+ type NumbersTuple = UnionToTuple<Numbers>;
65
+ //=> [1, 2, 3]
66
+ ```
67
+
68
+ @example
69
+ ```
70
+ import type {UnionToTuple} from 'type-fest';
71
+
72
+ const pets = {
73
+ dog: '🐶',
74
+ cat: '🐱',
75
+ snake: '🐍',
76
+ };
77
+
78
+ type Pet = keyof typeof pets;
79
+ //=> 'dog' | 'cat' | 'snake'
80
+
81
+ const petList = Object.keys(pets) as UnionToTuple<Pet>;
82
+ //=> ['dog', 'cat', 'snake']
83
+ ```
84
+
85
+ @category Array
86
+ */
87
+ type UnionToTuple<T, L = LastOfUnion<T>> =
88
+ IsNever<T> extends false
89
+ ? [...UnionToTuple<Exclude<T, L>>, L]
90
+ : [];
91
+
92
+ /**
93
+ * Array of all semantic extension prefixes used to categorize files by their purpose.
94
+ */
95
+ declare const _default: UnionToTuple<SemanticExtnamePrefix>;
96
+
97
+ export = _default;