@bemoje/monorepo 1.1.1 → 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.
- package/lib/MonoRepo.cjs +142 -0
- package/lib/MonoRepo.d.cts +10 -0
- package/lib/MonoRepo.d.ts +10 -0
- package/lib/MonoRepo.js +134 -0
- package/lib/code/AbstractCode.cjs +77 -0
- package/lib/code/AbstractCode.d.cts +30 -0
- package/lib/code/AbstractCode.d.ts +30 -0
- package/lib/code/AbstractCode.js +74 -0
- package/lib/code/CodeBlock.cjs +51 -0
- package/lib/code/CodeBlock.d.cts +22 -0
- package/lib/code/CodeBlock.d.ts +22 -0
- package/lib/code/CodeBlock.js +48 -0
- package/lib/code/TsCode.cjs +90 -0
- package/lib/code/TsCode.d.cts +10 -0
- package/lib/code/TsCode.d.ts +10 -0
- package/lib/code/TsCode.js +87 -0
- package/lib/code/imports/ImportKeywords.cjs +42 -0
- package/lib/code/imports/ImportKeywords.d.cts +10 -0
- package/lib/code/imports/ImportKeywords.d.ts +10 -0
- package/lib/code/imports/ImportKeywords.js +39 -0
- package/lib/code/imports/ImportSpecifiers.cjs +98 -0
- package/lib/code/imports/ImportSpecifiers.d.cts +10 -0
- package/lib/code/imports/ImportSpecifiers.d.ts +10 -0
- package/lib/code/imports/ImportSpecifiers.js +95 -0
- package/lib/code/imports/ImportStatement.cjs +89 -0
- package/lib/code/imports/ImportStatement.d.cts +10 -0
- package/lib/code/imports/ImportStatement.d.ts +10 -0
- package/lib/code/imports/ImportStatement.js +86 -0
- package/lib/code/imports/ModuleSpecifier.cjs +77 -0
- package/lib/code/imports/ModuleSpecifier.d.cts +10 -0
- package/lib/code/imports/ModuleSpecifier.d.ts +10 -0
- package/lib/code/imports/ModuleSpecifier.js +74 -0
- package/lib/common/AbstractBase.cjs +77 -0
- package/lib/common/AbstractBase.d.cts +3 -0
- package/lib/common/AbstractBase.d.ts +3 -0
- package/lib/common/AbstractBase.js +74 -0
- package/lib/file/File.cjs +118 -0
- package/lib/file/File.d.cts +10 -0
- package/lib/file/File.d.ts +10 -0
- package/lib/file/File.js +91 -0
- package/lib/file/TestFile.cjs +42 -0
- package/lib/file/TestFile.d.cts +10 -0
- package/lib/file/TestFile.d.ts +10 -0
- package/lib/file/TestFile.js +39 -0
- package/lib/file/TsFile.cjs +46 -0
- package/lib/file/TsFile.d.cts +10 -0
- package/lib/file/TsFile.d.ts +10 -0
- package/lib/file/TsFile.js +43 -0
- package/lib/index.cjs +215 -0
- package/lib/index.d.cts +26 -0
- package/lib/index.d.ts +26 -0
- package/lib/index.js +30 -0
- package/lib/methods/findWorkspacePackageName.cjs +17 -0
- package/lib/methods/findWorkspacePackageName.d.cts +6 -0
- package/lib/methods/findWorkspacePackageName.d.ts +6 -0
- package/lib/methods/findWorkspacePackageName.js +14 -0
- package/lib/methods/getAllImports.cjs +18 -0
- package/lib/methods/getAllImports.d.cts +17 -0
- package/lib/methods/getAllImports.d.ts +17 -0
- package/lib/methods/getAllImports.js +16 -0
- package/lib/methods/getAllWorkspacePackageJsonPaths.cjs +20 -0
- package/lib/methods/getAllWorkspacePackageJsonPaths.d.cts +6 -0
- package/lib/methods/getAllWorkspacePackageJsonPaths.d.ts +6 -0
- package/lib/methods/getAllWorkspacePackageJsonPaths.js +13 -0
- package/lib/methods/getAllWorkspacePackageJsons.cjs +20 -0
- package/lib/methods/getAllWorkspacePackageJsons.d.cts +6 -0
- package/lib/methods/getAllWorkspacePackageJsons.d.ts +6 -0
- package/lib/methods/getAllWorkspacePackageJsons.js +13 -0
- package/lib/methods/getAllWorkspacePackageNames.cjs +15 -0
- package/lib/methods/getAllWorkspacePackageNames.d.cts +6 -0
- package/lib/methods/getAllWorkspacePackageNames.d.ts +6 -0
- package/lib/methods/getAllWorkspacePackageNames.js +12 -0
- package/lib/methods/getAllWorkspacePaths.cjs +23 -0
- package/lib/methods/getAllWorkspacePaths.d.cts +6 -0
- package/lib/methods/getAllWorkspacePaths.d.ts +6 -0
- package/lib/methods/getAllWorkspacePaths.js +16 -0
- package/lib/methods/getImportsRecursively.cjs +176 -0
- package/lib/methods/getImportsRecursively.d.cts +37 -0
- package/lib/methods/getImportsRecursively.d.ts +37 -0
- package/lib/methods/getImportsRecursively.js +168 -0
- package/lib/methods/getRepoPackageJson.cjs +17 -0
- package/lib/methods/getRepoPackageJson.d.cts +6 -0
- package/lib/methods/getRepoPackageJson.d.ts +6 -0
- package/lib/methods/getRepoPackageJson.js +10 -0
- package/lib/methods/getRepoPackageJsonPath.cjs +17 -0
- package/lib/methods/getRepoPackageJsonPath.d.cts +6 -0
- package/lib/methods/getRepoPackageJsonPath.d.ts +6 -0
- package/lib/methods/getRepoPackageJsonPath.js +10 -0
- package/lib/repo/Workspace.cjs +383 -0
- package/lib/repo/Workspace.d.cts +10 -0
- package/lib/repo/Workspace.d.ts +10 -0
- package/lib/repo/Workspace.js +376 -0
- package/lib/util/SemanticExtnamePrefix.cjs +12 -0
- package/lib/util/SemanticExtnamePrefix.d.cts +14 -0
- package/lib/util/SemanticExtnamePrefix.d.ts +14 -0
- package/lib/util/SemanticExtnamePrefix.js +12 -0
- package/lib/util/SemanticExtnamePrefixDescriptions.cjs +12 -0
- package/lib/util/SemanticExtnamePrefixDescriptions.d.cts +15 -0
- package/lib/util/SemanticExtnamePrefixDescriptions.d.ts +15 -0
- package/lib/util/SemanticExtnamePrefixDescriptions.js +12 -0
- package/lib/util/SemanticExtnamePrefixes.cjs +9 -0
- package/lib/util/SemanticExtnamePrefixes.d.cts +97 -0
- package/lib/util/SemanticExtnamePrefixes.d.ts +97 -0
- package/lib/util/SemanticExtnamePrefixes.js +6 -0
- package/lib/util/getRepoRootDirpath.cjs +30 -0
- package/lib/util/getRepoRootDirpath.d.cts +6 -0
- package/lib/util/getRepoRootDirpath.d.ts +6 -0
- package/lib/util/getRepoRootDirpath.js +21 -0
- package/lib/util/getWorkspaceDirpaths.cjs +27 -0
- package/lib/util/getWorkspaceDirpaths.d.cts +6 -0
- package/lib/util/getWorkspaceDirpaths.d.ts +6 -0
- package/lib/util/getWorkspaceDirpaths.js +19 -0
- package/lib/util/hasExtnamePrefix.cjs +18 -0
- package/lib/util/hasExtnamePrefix.d.cts +38 -0
- package/lib/util/hasExtnamePrefix.d.ts +38 -0
- package/lib/util/hasExtnamePrefix.js +11 -0
- package/lib/util/resolveModuleImportPath.cjs +34 -0
- package/lib/util/resolveModuleImportPath.d.cts +8 -0
- package/lib/util/resolveModuleImportPath.d.ts +8 -0
- package/lib/util/resolveModuleImportPath.js +26 -0
- package/lib/util/semverVersionBump.cjs +28 -0
- package/lib/util/semverVersionBump.d.cts +22 -0
- package/lib/util/semverVersionBump.d.ts +22 -0
- package/lib/util/semverVersionBump.js +26 -0
- package/package.json +464 -32
- package/index.d.ts +0 -636
- package/index.mjs +0 -2321
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var getAllWorkspacePaths = require('./getAllWorkspacePaths');
|
|
4
|
+
var upath = require('upath');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var upath__default = /*#__PURE__*/_interopDefault(upath);
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
+
async function getAllWorkspacePackageJsonPaths() {
|
|
13
|
+
const paths = await getAllWorkspacePaths.getAllWorkspacePaths();
|
|
14
|
+
return paths.map((p) => {
|
|
15
|
+
return upath__default.default.join(p, "package.json");
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
__name(getAllWorkspacePackageJsonPaths, "getAllWorkspacePackageJsonPaths");
|
|
19
|
+
|
|
20
|
+
exports.getAllWorkspacePackageJsonPaths = getAllWorkspacePackageJsonPaths;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { __name } from '../chunk-SHUYVCID.js';
|
|
2
|
+
import { getAllWorkspacePaths } from './getAllWorkspacePaths';
|
|
3
|
+
import upath from 'upath';
|
|
4
|
+
|
|
5
|
+
async function getAllWorkspacePackageJsonPaths() {
|
|
6
|
+
const paths = await getAllWorkspacePaths();
|
|
7
|
+
return paths.map((p) => {
|
|
8
|
+
return upath.join(p, "package.json");
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
__name(getAllWorkspacePackageJsonPaths, "getAllWorkspacePackageJsonPaths");
|
|
12
|
+
|
|
13
|
+
export { getAllWorkspacePackageJsonPaths };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs-extra');
|
|
4
|
+
var getAllWorkspacePackageJsonPaths = require('./getAllWorkspacePackageJsonPaths');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
+
async function getAllWorkspacePackageJsons() {
|
|
13
|
+
const paths = await getAllWorkspacePackageJsonPaths.getAllWorkspacePackageJsonPaths();
|
|
14
|
+
return paths.map((p) => {
|
|
15
|
+
return fs__default.default.readJsonSync(p);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
__name(getAllWorkspacePackageJsons, "getAllWorkspacePackageJsons");
|
|
19
|
+
|
|
20
|
+
exports.getAllWorkspacePackageJsons = getAllWorkspacePackageJsons;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { __name } from '../chunk-SHUYVCID.js';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import { getAllWorkspacePackageJsonPaths } from './getAllWorkspacePackageJsonPaths';
|
|
4
|
+
|
|
5
|
+
async function getAllWorkspacePackageJsons() {
|
|
6
|
+
const paths = await getAllWorkspacePackageJsonPaths();
|
|
7
|
+
return paths.map((p) => {
|
|
8
|
+
return fs.readJsonSync(p);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
__name(getAllWorkspacePackageJsons, "getAllWorkspacePackageJsons");
|
|
12
|
+
|
|
13
|
+
export { getAllWorkspacePackageJsons };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var getAllWorkspacePackageJsons = require('./getAllWorkspacePackageJsons');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
async function getAllWorkspacePackageNames() {
|
|
8
|
+
const pkgs = await getAllWorkspacePackageJsons.getAllWorkspacePackageJsons();
|
|
9
|
+
return pkgs.map((p) => {
|
|
10
|
+
return p.name;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
__name(getAllWorkspacePackageNames, "getAllWorkspacePackageNames");
|
|
14
|
+
|
|
15
|
+
exports.getAllWorkspacePackageNames = getAllWorkspacePackageNames;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { __name } from '../chunk-SHUYVCID.js';
|
|
2
|
+
import { getAllWorkspacePackageJsons } from './getAllWorkspacePackageJsons';
|
|
3
|
+
|
|
4
|
+
async function getAllWorkspacePackageNames() {
|
|
5
|
+
const pkgs = await getAllWorkspacePackageJsons();
|
|
6
|
+
return pkgs.map((p) => {
|
|
7
|
+
return p.name;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
__name(getAllWorkspacePackageNames, "getAllWorkspacePackageNames");
|
|
11
|
+
|
|
12
|
+
export { getAllWorkspacePackageNames };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var getRepoPackageJson = require('./getRepoPackageJson');
|
|
4
|
+
var glob = require('glob');
|
|
5
|
+
var upath = require('upath');
|
|
6
|
+
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var upath__default = /*#__PURE__*/_interopDefault(upath);
|
|
10
|
+
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
|
+
async function getAllWorkspacePaths() {
|
|
14
|
+
const pkg = await getRepoPackageJson.getRepoPackageJson();
|
|
15
|
+
return (await Promise.all(pkg.workspaces.map((pattern) => {
|
|
16
|
+
return glob.glob(pattern);
|
|
17
|
+
}))).flat().map((fp) => {
|
|
18
|
+
return upath__default.default.normalizeSafe(fp);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
__name(getAllWorkspacePaths, "getAllWorkspacePaths");
|
|
22
|
+
|
|
23
|
+
exports.getAllWorkspacePaths = getAllWorkspacePaths;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { __name } from '../chunk-SHUYVCID.js';
|
|
2
|
+
import { getRepoPackageJson } from './getRepoPackageJson';
|
|
3
|
+
import { glob } from 'glob';
|
|
4
|
+
import upath from 'upath';
|
|
5
|
+
|
|
6
|
+
async function getAllWorkspacePaths() {
|
|
7
|
+
const pkg = await getRepoPackageJson();
|
|
8
|
+
return (await Promise.all(pkg.workspaces.map((pattern) => {
|
|
9
|
+
return glob(pattern);
|
|
10
|
+
}))).flat().map((fp) => {
|
|
11
|
+
return upath.normalizeSafe(fp);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
__name(getAllWorkspacePaths, "getAllWorkspacePaths");
|
|
15
|
+
|
|
16
|
+
export { getAllWorkspacePaths };
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var mnemonist = require('mnemonist');
|
|
4
|
+
var MonoRepo = require('../MonoRepo');
|
|
5
|
+
var fs = require('fs-extra');
|
|
6
|
+
var getAllWorkspacePackageJsonPaths = require('./getAllWorkspacePackageJsonPaths');
|
|
7
|
+
var getRepoPackageJson = require('./getRepoPackageJson');
|
|
8
|
+
var resolveModuleImportPath = require('../util/resolveModuleImportPath');
|
|
9
|
+
var path = require('@mono/path');
|
|
10
|
+
var upath = require('upath');
|
|
11
|
+
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
|
|
14
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
15
|
+
var upath__default = /*#__PURE__*/_interopDefault(upath);
|
|
16
|
+
|
|
17
|
+
var __defProp = Object.defineProperty;
|
|
18
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
19
|
+
async function getImportsRecursively(entryPoints) {
|
|
20
|
+
const entryPointWsDirpaths = new Set(entryPoints.map((ep) => {
|
|
21
|
+
return ep.split("/").slice(0, 2).join("/");
|
|
22
|
+
}));
|
|
23
|
+
if (entryPointWsDirpaths.size !== 1) {
|
|
24
|
+
throw new Error(`All entry points must be in the same workspace. Got: ${[
|
|
25
|
+
...entryPointWsDirpaths
|
|
26
|
+
].join(", ")}`);
|
|
27
|
+
}
|
|
28
|
+
const wsDirpath = Array.from(entryPointWsDirpaths)[0];
|
|
29
|
+
const rootPkg = await getRepoPackageJson.getRepoPackageJson();
|
|
30
|
+
const allPkgJsonPaths = await getAllWorkspacePackageJsonPaths.getAllWorkspacePackageJsonPaths();
|
|
31
|
+
const allPkgJsons = allPkgJsonPaths.map((p) => {
|
|
32
|
+
return fs__default.default.readJsonSync(p);
|
|
33
|
+
});
|
|
34
|
+
const files = /* @__PURE__ */ new Map();
|
|
35
|
+
const repo = new MonoRepo.MonoRepo();
|
|
36
|
+
repo.workspaces.forEach((ws) => {
|
|
37
|
+
ws.tsFiles.forEach((ts) => {
|
|
38
|
+
if (ts.isSourceFile) {
|
|
39
|
+
const filepath = path.toCwdRelative(ts.path);
|
|
40
|
+
files.set(filepath, ts);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
const wsFilenames = new mnemonist.DefaultMap(() => {
|
|
45
|
+
return new mnemonist.DefaultMap(() => {
|
|
46
|
+
return /* @__PURE__ */ new Set();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
Array.from(files.keys()).forEach((filepath) => {
|
|
50
|
+
return wsFilenames.get(filepath.split("/").slice(0, 2).join("/")).get(upath__default.default.basename(filepath).replace(/\.ts$/, "")).add(filepath);
|
|
51
|
+
});
|
|
52
|
+
const seen = /* @__PURE__ */ new Set();
|
|
53
|
+
const externalsLocal = /* @__PURE__ */ new Set();
|
|
54
|
+
const builtinsLocal = /* @__PURE__ */ new Set();
|
|
55
|
+
const internalsLocal = /* @__PURE__ */ new Set();
|
|
56
|
+
const externalsRecursive = /* @__PURE__ */ new Set();
|
|
57
|
+
const builtinsRecursive = /* @__PURE__ */ new Set();
|
|
58
|
+
const internalsRecursive = /* @__PURE__ */ new Set();
|
|
59
|
+
const sort = /* @__PURE__ */ __name((s) => {
|
|
60
|
+
return Array.from(s).sort();
|
|
61
|
+
}, "sort");
|
|
62
|
+
function recurse(curFilepath, wsDirpath2) {
|
|
63
|
+
if (seen.has(curFilepath)) {
|
|
64
|
+
seen.add(`[CIRCULAR]: ${curFilepath}`);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
seen.add(curFilepath);
|
|
68
|
+
const filepathWsDirpath = curFilepath.split("/").slice(0, 2).join("/");
|
|
69
|
+
const isLocalWorkspace = filepathWsDirpath === wsDirpath2;
|
|
70
|
+
const externals = isLocalWorkspace ? externalsLocal : externalsRecursive;
|
|
71
|
+
const builtins = isLocalWorkspace ? builtinsLocal : builtinsRecursive;
|
|
72
|
+
const internals = isLocalWorkspace ? internalsLocal : internalsRecursive;
|
|
73
|
+
const entryPointFile = files.get(curFilepath);
|
|
74
|
+
const wsName = entryPointFile.parent.name;
|
|
75
|
+
internals.add(wsName);
|
|
76
|
+
for (const i of entryPointFile.tsCode.imports) {
|
|
77
|
+
if (i.module.isBuiltin) {
|
|
78
|
+
builtins.add(i.module.from);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const moduleFrom = i.module.from.startsWith(".") ? i.module.from : i.module.from.split("/").slice(0, i.module.from.startsWith("@") ? 2 : 1).join("/");
|
|
82
|
+
const resolvedModule = resolveModuleImportPath.resolveModuleImportPath(i.parent.parent.path, moduleFrom);
|
|
83
|
+
const resolvedFilepath = resolvedModule?.resolvedFileName;
|
|
84
|
+
if (resolvedFilepath) {
|
|
85
|
+
if (i.module.isRelative) {
|
|
86
|
+
recurse(resolvedFilepath, wsDirpath2);
|
|
87
|
+
} else if (i.module.isRepoScoped && resolvedFilepath.endsWith("src/index.ts")) {
|
|
88
|
+
internals.add(moduleFrom);
|
|
89
|
+
const resolvedWsDirpath = resolvedFilepath.split("/").slice(0, 2).join("/");
|
|
90
|
+
const map = wsFilenames.get(resolvedWsDirpath);
|
|
91
|
+
for (const name of i.specifiers?.importedNamesArray || []) {
|
|
92
|
+
if (map.has(name)) {
|
|
93
|
+
const filepaths = map.get(name);
|
|
94
|
+
for (const filepath of filepaths) {
|
|
95
|
+
const lines = fs__default.default.readFileSync(filepath, "utf-8").split("\n");
|
|
96
|
+
for (const line of lines) {
|
|
97
|
+
if (line.startsWith("export ") && line.includes(` ${name}`)) {
|
|
98
|
+
recurse(filepath, wsDirpath2);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
const depName = moduleFrom;
|
|
106
|
+
const pkgName = resolvedModule?.packageId?.name;
|
|
107
|
+
let version = resolvedModule?.packageId?.version || "";
|
|
108
|
+
version = version ? `^${version}` : "";
|
|
109
|
+
externals.add(`"${pkgName}": "${version}",`);
|
|
110
|
+
if (depName !== pkgName) {
|
|
111
|
+
const found = allPkgJsons.find((p) => {
|
|
112
|
+
return p.dependencies?.[depName] || p.devDependencies?.[depName];
|
|
113
|
+
});
|
|
114
|
+
const depVersion = rootPkg.dependencies?.[depName] || rootPkg.devDependencies?.[depName] || found?.dependencies?.[depName] || found?.devDependencies?.[depName];
|
|
115
|
+
if (depVersion) {
|
|
116
|
+
externals.add(`"${depName}": "${depVersion}",`);
|
|
117
|
+
} else {
|
|
118
|
+
throw new Error(`Could not find version for dependency "${depName}" imported in ${curFilepath}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
throw new Error(`Could not resolve import "${moduleFrom}" in ${curFilepath}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (isLocalWorkspace) {
|
|
127
|
+
internals.delete(wsName);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
__name(recurse, "recurse");
|
|
131
|
+
for (const entryPoint of entryPoints) {
|
|
132
|
+
if (upath__default.default.basename(entryPoint) !== "index.ts") {
|
|
133
|
+
recurse(path.toCwdRelative(entryPoint), wsDirpath);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const code = await fs__default.default.readFile(entryPoint, "utf8");
|
|
137
|
+
const lines = code.split("\n").filter((line) => {
|
|
138
|
+
return line.startsWith("export * from ");
|
|
139
|
+
});
|
|
140
|
+
for (const line of lines) {
|
|
141
|
+
const moduleFrom = line.split("export * from ")[1].slice(1).replaceAll(/["';]+$/g, "");
|
|
142
|
+
const resolvedModule = resolveModuleImportPath.resolveModuleImportPath(entryPoint, moduleFrom);
|
|
143
|
+
const resolvedFilepath = resolvedModule?.resolvedFileName;
|
|
144
|
+
if (!resolvedFilepath) {
|
|
145
|
+
throw new Error(`Could not resolve export "${moduleFrom}" in ${entryPoint}`);
|
|
146
|
+
}
|
|
147
|
+
recurse(path.toCwdRelative(resolvedFilepath), wsDirpath);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
externalsLocal.forEach((v) => {
|
|
151
|
+
return externalsRecursive.add(v);
|
|
152
|
+
});
|
|
153
|
+
builtinsLocal.forEach((v) => {
|
|
154
|
+
return builtinsRecursive.add(v);
|
|
155
|
+
});
|
|
156
|
+
internalsLocal.forEach((v) => {
|
|
157
|
+
return internalsRecursive.add(v);
|
|
158
|
+
});
|
|
159
|
+
const result = {
|
|
160
|
+
filepaths: Array.from(seen),
|
|
161
|
+
recursive: {
|
|
162
|
+
external: sort(externalsRecursive),
|
|
163
|
+
builtin: sort(builtinsRecursive),
|
|
164
|
+
internal: sort(internalsRecursive)
|
|
165
|
+
},
|
|
166
|
+
local: {
|
|
167
|
+
external: sort(externalsLocal),
|
|
168
|
+
builtin: sort(builtinsLocal),
|
|
169
|
+
internal: sort(internalsLocal)
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
__name(getImportsRecursively, "getImportsRecursively");
|
|
175
|
+
|
|
176
|
+
exports.getImportsRecursively = getImportsRecursively;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively retrieves all imports for the given entry points, categorizing them into external, builtin, and internal dependencies.
|
|
3
|
+
*
|
|
4
|
+
* @param entryPoints - An array of entry point file paths to analyze.
|
|
5
|
+
* @returns An object containing the file paths of all imports and categorized dependencies.
|
|
6
|
+
*/
|
|
7
|
+
declare function getImportsRecursively(entryPoints: string[]): Promise<Result>;
|
|
8
|
+
type Result = {
|
|
9
|
+
/**
|
|
10
|
+
* All file paths of the imports found recursively, in discovery order, starting from the entry points, including circular reference stops.
|
|
11
|
+
*/
|
|
12
|
+
filepaths: string[];
|
|
13
|
+
/**
|
|
14
|
+
* All workspace imports found recursively. Includes all `local` imports plus for any other worksapce imports discovered.
|
|
15
|
+
*/
|
|
16
|
+
recursive: {
|
|
17
|
+
/** External dependencies */
|
|
18
|
+
external: string[];
|
|
19
|
+
/** Built-in node dependencies */
|
|
20
|
+
builtin: string[];
|
|
21
|
+
/** Other repo workspaces */
|
|
22
|
+
internal: string[];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Only workspace imports found in the same workspace as the entry points.
|
|
26
|
+
*/
|
|
27
|
+
local: {
|
|
28
|
+
/** External dependencies */
|
|
29
|
+
external: string[];
|
|
30
|
+
/** Built-in node dependencies */
|
|
31
|
+
builtin: string[];
|
|
32
|
+
/** Other repo workspaces */
|
|
33
|
+
internal: string[];
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { getImportsRecursively };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively retrieves all imports for the given entry points, categorizing them into external, builtin, and internal dependencies.
|
|
3
|
+
*
|
|
4
|
+
* @param entryPoints - An array of entry point file paths to analyze.
|
|
5
|
+
* @returns An object containing the file paths of all imports and categorized dependencies.
|
|
6
|
+
*/
|
|
7
|
+
declare function getImportsRecursively(entryPoints: string[]): Promise<Result>;
|
|
8
|
+
type Result = {
|
|
9
|
+
/**
|
|
10
|
+
* All file paths of the imports found recursively, in discovery order, starting from the entry points, including circular reference stops.
|
|
11
|
+
*/
|
|
12
|
+
filepaths: string[];
|
|
13
|
+
/**
|
|
14
|
+
* All workspace imports found recursively. Includes all `local` imports plus for any other worksapce imports discovered.
|
|
15
|
+
*/
|
|
16
|
+
recursive: {
|
|
17
|
+
/** External dependencies */
|
|
18
|
+
external: string[];
|
|
19
|
+
/** Built-in node dependencies */
|
|
20
|
+
builtin: string[];
|
|
21
|
+
/** Other repo workspaces */
|
|
22
|
+
internal: string[];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Only workspace imports found in the same workspace as the entry points.
|
|
26
|
+
*/
|
|
27
|
+
local: {
|
|
28
|
+
/** External dependencies */
|
|
29
|
+
external: string[];
|
|
30
|
+
/** Built-in node dependencies */
|
|
31
|
+
builtin: string[];
|
|
32
|
+
/** Other repo workspaces */
|
|
33
|
+
internal: string[];
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { getImportsRecursively };
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { __name } from '../chunk-SHUYVCID.js';
|
|
2
|
+
import { DefaultMap } from 'mnemonist';
|
|
3
|
+
import { MonoRepo } from '../MonoRepo';
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
import { getAllWorkspacePackageJsonPaths } from './getAllWorkspacePackageJsonPaths';
|
|
6
|
+
import { getRepoPackageJson } from './getRepoPackageJson';
|
|
7
|
+
import { resolveModuleImportPath } from '../util/resolveModuleImportPath';
|
|
8
|
+
import { toCwdRelative } from '@mono/path';
|
|
9
|
+
import upath from 'upath';
|
|
10
|
+
|
|
11
|
+
async function getImportsRecursively(entryPoints) {
|
|
12
|
+
const entryPointWsDirpaths = new Set(entryPoints.map((ep) => {
|
|
13
|
+
return ep.split("/").slice(0, 2).join("/");
|
|
14
|
+
}));
|
|
15
|
+
if (entryPointWsDirpaths.size !== 1) {
|
|
16
|
+
throw new Error(`All entry points must be in the same workspace. Got: ${[
|
|
17
|
+
...entryPointWsDirpaths
|
|
18
|
+
].join(", ")}`);
|
|
19
|
+
}
|
|
20
|
+
const wsDirpath = Array.from(entryPointWsDirpaths)[0];
|
|
21
|
+
const rootPkg = await getRepoPackageJson();
|
|
22
|
+
const allPkgJsonPaths = await getAllWorkspacePackageJsonPaths();
|
|
23
|
+
const allPkgJsons = allPkgJsonPaths.map((p) => {
|
|
24
|
+
return fs.readJsonSync(p);
|
|
25
|
+
});
|
|
26
|
+
const files = /* @__PURE__ */ new Map();
|
|
27
|
+
const repo = new MonoRepo();
|
|
28
|
+
repo.workspaces.forEach((ws) => {
|
|
29
|
+
ws.tsFiles.forEach((ts) => {
|
|
30
|
+
if (ts.isSourceFile) {
|
|
31
|
+
const filepath = toCwdRelative(ts.path);
|
|
32
|
+
files.set(filepath, ts);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
const wsFilenames = new DefaultMap(() => {
|
|
37
|
+
return new DefaultMap(() => {
|
|
38
|
+
return /* @__PURE__ */ new Set();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
Array.from(files.keys()).forEach((filepath) => {
|
|
42
|
+
return wsFilenames.get(filepath.split("/").slice(0, 2).join("/")).get(upath.basename(filepath).replace(/\.ts$/, "")).add(filepath);
|
|
43
|
+
});
|
|
44
|
+
const seen = /* @__PURE__ */ new Set();
|
|
45
|
+
const externalsLocal = /* @__PURE__ */ new Set();
|
|
46
|
+
const builtinsLocal = /* @__PURE__ */ new Set();
|
|
47
|
+
const internalsLocal = /* @__PURE__ */ new Set();
|
|
48
|
+
const externalsRecursive = /* @__PURE__ */ new Set();
|
|
49
|
+
const builtinsRecursive = /* @__PURE__ */ new Set();
|
|
50
|
+
const internalsRecursive = /* @__PURE__ */ new Set();
|
|
51
|
+
const sort = /* @__PURE__ */ __name((s) => {
|
|
52
|
+
return Array.from(s).sort();
|
|
53
|
+
}, "sort");
|
|
54
|
+
function recurse(curFilepath, wsDirpath2) {
|
|
55
|
+
if (seen.has(curFilepath)) {
|
|
56
|
+
seen.add(`[CIRCULAR]: ${curFilepath}`);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
seen.add(curFilepath);
|
|
60
|
+
const filepathWsDirpath = curFilepath.split("/").slice(0, 2).join("/");
|
|
61
|
+
const isLocalWorkspace = filepathWsDirpath === wsDirpath2;
|
|
62
|
+
const externals = isLocalWorkspace ? externalsLocal : externalsRecursive;
|
|
63
|
+
const builtins = isLocalWorkspace ? builtinsLocal : builtinsRecursive;
|
|
64
|
+
const internals = isLocalWorkspace ? internalsLocal : internalsRecursive;
|
|
65
|
+
const entryPointFile = files.get(curFilepath);
|
|
66
|
+
const wsName = entryPointFile.parent.name;
|
|
67
|
+
internals.add(wsName);
|
|
68
|
+
for (const i of entryPointFile.tsCode.imports) {
|
|
69
|
+
if (i.module.isBuiltin) {
|
|
70
|
+
builtins.add(i.module.from);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const moduleFrom = i.module.from.startsWith(".") ? i.module.from : i.module.from.split("/").slice(0, i.module.from.startsWith("@") ? 2 : 1).join("/");
|
|
74
|
+
const resolvedModule = resolveModuleImportPath(i.parent.parent.path, moduleFrom);
|
|
75
|
+
const resolvedFilepath = resolvedModule?.resolvedFileName;
|
|
76
|
+
if (resolvedFilepath) {
|
|
77
|
+
if (i.module.isRelative) {
|
|
78
|
+
recurse(resolvedFilepath, wsDirpath2);
|
|
79
|
+
} else if (i.module.isRepoScoped && resolvedFilepath.endsWith("src/index.ts")) {
|
|
80
|
+
internals.add(moduleFrom);
|
|
81
|
+
const resolvedWsDirpath = resolvedFilepath.split("/").slice(0, 2).join("/");
|
|
82
|
+
const map = wsFilenames.get(resolvedWsDirpath);
|
|
83
|
+
for (const name of i.specifiers?.importedNamesArray || []) {
|
|
84
|
+
if (map.has(name)) {
|
|
85
|
+
const filepaths = map.get(name);
|
|
86
|
+
for (const filepath of filepaths) {
|
|
87
|
+
const lines = fs.readFileSync(filepath, "utf-8").split("\n");
|
|
88
|
+
for (const line of lines) {
|
|
89
|
+
if (line.startsWith("export ") && line.includes(` ${name}`)) {
|
|
90
|
+
recurse(filepath, wsDirpath2);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
const depName = moduleFrom;
|
|
98
|
+
const pkgName = resolvedModule?.packageId?.name;
|
|
99
|
+
let version = resolvedModule?.packageId?.version || "";
|
|
100
|
+
version = version ? `^${version}` : "";
|
|
101
|
+
externals.add(`"${pkgName}": "${version}",`);
|
|
102
|
+
if (depName !== pkgName) {
|
|
103
|
+
const found = allPkgJsons.find((p) => {
|
|
104
|
+
return p.dependencies?.[depName] || p.devDependencies?.[depName];
|
|
105
|
+
});
|
|
106
|
+
const depVersion = rootPkg.dependencies?.[depName] || rootPkg.devDependencies?.[depName] || found?.dependencies?.[depName] || found?.devDependencies?.[depName];
|
|
107
|
+
if (depVersion) {
|
|
108
|
+
externals.add(`"${depName}": "${depVersion}",`);
|
|
109
|
+
} else {
|
|
110
|
+
throw new Error(`Could not find version for dependency "${depName}" imported in ${curFilepath}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
throw new Error(`Could not resolve import "${moduleFrom}" in ${curFilepath}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (isLocalWorkspace) {
|
|
119
|
+
internals.delete(wsName);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
__name(recurse, "recurse");
|
|
123
|
+
for (const entryPoint of entryPoints) {
|
|
124
|
+
if (upath.basename(entryPoint) !== "index.ts") {
|
|
125
|
+
recurse(toCwdRelative(entryPoint), wsDirpath);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const code = await fs.readFile(entryPoint, "utf8");
|
|
129
|
+
const lines = code.split("\n").filter((line) => {
|
|
130
|
+
return line.startsWith("export * from ");
|
|
131
|
+
});
|
|
132
|
+
for (const line of lines) {
|
|
133
|
+
const moduleFrom = line.split("export * from ")[1].slice(1).replaceAll(/["';]+$/g, "");
|
|
134
|
+
const resolvedModule = resolveModuleImportPath(entryPoint, moduleFrom);
|
|
135
|
+
const resolvedFilepath = resolvedModule?.resolvedFileName;
|
|
136
|
+
if (!resolvedFilepath) {
|
|
137
|
+
throw new Error(`Could not resolve export "${moduleFrom}" in ${entryPoint}`);
|
|
138
|
+
}
|
|
139
|
+
recurse(toCwdRelative(resolvedFilepath), wsDirpath);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
externalsLocal.forEach((v) => {
|
|
143
|
+
return externalsRecursive.add(v);
|
|
144
|
+
});
|
|
145
|
+
builtinsLocal.forEach((v) => {
|
|
146
|
+
return builtinsRecursive.add(v);
|
|
147
|
+
});
|
|
148
|
+
internalsLocal.forEach((v) => {
|
|
149
|
+
return internalsRecursive.add(v);
|
|
150
|
+
});
|
|
151
|
+
const result = {
|
|
152
|
+
filepaths: Array.from(seen),
|
|
153
|
+
recursive: {
|
|
154
|
+
external: sort(externalsRecursive),
|
|
155
|
+
builtin: sort(builtinsRecursive),
|
|
156
|
+
internal: sort(internalsRecursive)
|
|
157
|
+
},
|
|
158
|
+
local: {
|
|
159
|
+
external: sort(externalsLocal),
|
|
160
|
+
builtin: sort(builtinsLocal),
|
|
161
|
+
internal: sort(internalsLocal)
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
__name(getImportsRecursively, "getImportsRecursively");
|
|
167
|
+
|
|
168
|
+
export { getImportsRecursively };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs-extra');
|
|
4
|
+
var getRepoPackageJsonPath = require('./getRepoPackageJsonPath');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
+
async function getRepoPackageJson() {
|
|
13
|
+
return await fs__default.default.readJson(getRepoPackageJsonPath.getRepoPackageJsonPath());
|
|
14
|
+
}
|
|
15
|
+
__name(getRepoPackageJson, "getRepoPackageJson");
|
|
16
|
+
|
|
17
|
+
exports.getRepoPackageJson = getRepoPackageJson;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { __name } from '../chunk-SHUYVCID.js';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import { getRepoPackageJsonPath } from './getRepoPackageJsonPath';
|
|
4
|
+
|
|
5
|
+
async function getRepoPackageJson() {
|
|
6
|
+
return await fs.readJson(getRepoPackageJsonPath());
|
|
7
|
+
}
|
|
8
|
+
__name(getRepoPackageJson, "getRepoPackageJson");
|
|
9
|
+
|
|
10
|
+
export { getRepoPackageJson };
|