@hanseltime/esm-interop-tools 1.0.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 (64) hide show
  1. package/README.md +115 -0
  2. package/dist/bin/get-esm-packages.js +17 -0
  3. package/dist/bin/get-esm-packages.js.map +1 -0
  4. package/dist/cjs/bin/get-esm-packages.js +73 -0
  5. package/dist/cjs/bin/get-esm-packages.js.map +1 -0
  6. package/dist/cjs/index.js +21 -0
  7. package/dist/cjs/index.js.map +1 -0
  8. package/dist/cjs/operations/getESMPackages.js +105 -0
  9. package/dist/cjs/operations/getESMPackages.js.map +1 -0
  10. package/dist/cjs/operations/index.js +21 -0
  11. package/dist/cjs/operations/index.js.map +1 -0
  12. package/dist/cjs/operations/jest.js +52 -0
  13. package/dist/cjs/operations/jest.js.map +1 -0
  14. package/dist/cjs/packageGraphs/Graph.js +130 -0
  15. package/dist/cjs/packageGraphs/Graph.js.map +1 -0
  16. package/dist/cjs/packageGraphs/PackageGraph.js +42 -0
  17. package/dist/cjs/packageGraphs/PackageGraph.js.map +1 -0
  18. package/dist/cjs/packageGraphs/getYarnInfoPackageGraph.js +128 -0
  19. package/dist/cjs/packageGraphs/getYarnInfoPackageGraph.js.map +1 -0
  20. package/dist/cjs/packageGraphs/index.js +23 -0
  21. package/dist/cjs/packageGraphs/index.js.map +1 -0
  22. package/dist/cjs/packageGraphs/types.js +6 -0
  23. package/dist/cjs/packageGraphs/types.js.map +1 -0
  24. package/dist/esm/bin/get-esm-packages.mjs +86 -0
  25. package/dist/esm/bin/get-esm-packages.mjs.map +1 -0
  26. package/dist/esm/index.mjs +4 -0
  27. package/dist/esm/index.mjs.map +1 -0
  28. package/dist/esm/operations/getESMPackages.mjs +118 -0
  29. package/dist/esm/operations/getESMPackages.mjs.map +1 -0
  30. package/dist/esm/operations/index.mjs +4 -0
  31. package/dist/esm/operations/index.mjs.map +1 -0
  32. package/dist/esm/operations/jest.mjs +45 -0
  33. package/dist/esm/operations/jest.mjs.map +1 -0
  34. package/dist/esm/packageGraphs/Graph.mjs +173 -0
  35. package/dist/esm/packageGraphs/Graph.mjs.map +1 -0
  36. package/dist/esm/packageGraphs/PackageGraph.mjs +28 -0
  37. package/dist/esm/packageGraphs/PackageGraph.mjs.map +1 -0
  38. package/dist/esm/packageGraphs/getYarnInfoPackageGraph.mjs +142 -0
  39. package/dist/esm/packageGraphs/getYarnInfoPackageGraph.mjs.map +1 -0
  40. package/dist/esm/packageGraphs/index.mjs +6 -0
  41. package/dist/esm/packageGraphs/index.mjs.map +1 -0
  42. package/dist/esm/packageGraphs/types.mjs +8 -0
  43. package/dist/esm/packageGraphs/types.mjs.map +1 -0
  44. package/dist/types/bin/get-esm-packages.d.ts +2 -0
  45. package/dist/types/bin/get-esm-packages.d.ts.map +1 -0
  46. package/dist/types/index.d.ts +3 -0
  47. package/dist/types/index.d.ts.map +1 -0
  48. package/dist/types/operations/getESMPackages.d.ts +8 -0
  49. package/dist/types/operations/getESMPackages.d.ts.map +1 -0
  50. package/dist/types/operations/index.d.ts +3 -0
  51. package/dist/types/operations/index.d.ts.map +1 -0
  52. package/dist/types/operations/jest.d.ts +40 -0
  53. package/dist/types/operations/jest.d.ts.map +1 -0
  54. package/dist/types/packageGraphs/Graph.d.ts +72 -0
  55. package/dist/types/packageGraphs/Graph.d.ts.map +1 -0
  56. package/dist/types/packageGraphs/PackageGraph.d.ts +19 -0
  57. package/dist/types/packageGraphs/PackageGraph.d.ts.map +1 -0
  58. package/dist/types/packageGraphs/getYarnInfoPackageGraph.d.ts +9 -0
  59. package/dist/types/packageGraphs/getYarnInfoPackageGraph.d.ts.map +1 -0
  60. package/dist/types/packageGraphs/index.d.ts +5 -0
  61. package/dist/types/packageGraphs/index.d.ts.map +1 -0
  62. package/dist/types/packageGraphs/types.d.ts +9 -0
  63. package/dist/types/packageGraphs/types.d.ts.map +1 -0
  64. package/package.json +64 -0
@@ -0,0 +1,142 @@
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _async_to_generator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ import { execSync } from "child_process";
31
+ import { PackageGraph } from "./PackageGraph";
32
+ import { existsSync, readFileSync } from "fs";
33
+ import { dirname, join } from "path";
34
+ /**
35
+ * Gets the first package.json that can be found
36
+ */ function getRootPackageJson(start, curDir) {
37
+ const dir = curDir !== null && curDir !== void 0 ? curDir : start;
38
+ const testPath = join(dir, "package.json");
39
+ if (existsSync(testPath)) {
40
+ return testPath;
41
+ }
42
+ const oneUp = dirname(dir);
43
+ if (!oneUp) {
44
+ throw new Error(`Could not find package.json traveling up from start dir at ${start}`);
45
+ }
46
+ return getRootPackageJson(start, oneUp);
47
+ }
48
+ /**
49
+ * Retrieves the dependencies for a package in a PackageGraph
50
+ * @param pkgDir - the directory where the top-level package is
51
+ * @param recurse - get all the packages through all immediate dependencies
52
+ * @returns
53
+ */ export function getYarnInfoPackageGraph(pkgDir, recurse) {
54
+ return _getYarnInfoPackageGraph.apply(this, arguments);
55
+ }
56
+ function _getYarnInfoPackageGraph() {
57
+ _getYarnInfoPackageGraph = _async_to_generator(function*(pkgDir, recurse) {
58
+ const query = execSync(`yarn info ${recurse ? "-R" : ""} --json`, {
59
+ cwd: pkgDir,
60
+ stdio: "pipe"
61
+ });
62
+ // Get the current package name so we can determine the root
63
+ const rootPkgJsonPath = getRootPackageJson(pkgDir);
64
+ let rootPkgName = "";
65
+ try {
66
+ rootPkgName = JSON.parse(readFileSync(rootPkgJsonPath).toString()).name;
67
+ } catch (e) {
68
+ console.error("Error retrieving root package name!");
69
+ throw e;
70
+ }
71
+ const packageGraph = new PackageGraph(pkgDir);
72
+ // Since the info shows multiple versions we keep a dedup set of the serialized key to avoid longer times
73
+ const dedupSet = new Set();
74
+ return query.toString().split("\n").reduce((pkgGraph, q)=>{
75
+ // Make sure we have an actual value
76
+ if (q.trim()) {
77
+ const pkgInfo = JSON.parse(q);
78
+ const { name, version, isPatch } = parsePackage(pkgInfo.value);
79
+ const nameKey = packageGraph.keySerializer({
80
+ name,
81
+ version
82
+ });
83
+ if (!dedupSet.has(nameKey)) {
84
+ dedupSet.add(nameKey);
85
+ // List of package names as dependencies
86
+ let deps;
87
+ if (recurse) {
88
+ var _pkgInfo_children_Dependencies, _pkgInfo_children;
89
+ var _pkgInfo_children_Dependencies_map;
90
+ deps = (_pkgInfo_children_Dependencies_map = (_pkgInfo_children = pkgInfo.children) === null || _pkgInfo_children === void 0 ? void 0 : (_pkgInfo_children_Dependencies = _pkgInfo_children.Dependencies) === null || _pkgInfo_children_Dependencies === void 0 ? void 0 : _pkgInfo_children_Dependencies.map((deps)=>{
91
+ const info = parsePackage(deps.locator);
92
+ return {
93
+ name: info.name,
94
+ version: info.version
95
+ };
96
+ })) !== null && _pkgInfo_children_Dependencies_map !== void 0 ? _pkgInfo_children_Dependencies_map : [];
97
+ } else {
98
+ // We don't actually set up the dependencies because that would make the graph incomplete
99
+ deps = [];
100
+ }
101
+ packageGraph.addDownstreamNode({
102
+ self: {
103
+ name,
104
+ version
105
+ },
106
+ value: {
107
+ name,
108
+ version,
109
+ isPatch,
110
+ isRoot: name === rootPkgName
111
+ },
112
+ to: deps !== null && deps !== void 0 ? deps : []
113
+ });
114
+ }
115
+ }
116
+ return pkgGraph;
117
+ }, packageGraph);
118
+ });
119
+ return _getYarnInfoPackageGraph.apply(this, arguments);
120
+ }
121
+ function parsePackage(pkgAndVersion) {
122
+ const versionIdx = pkgAndVersion.indexOf("@", 1);
123
+ if (versionIdx < 0) {
124
+ throw new Error(`could not find version from name: ${pkgAndVersion}`);
125
+ }
126
+ let version = pkgAndVersion.substring(versionIdx + 1);
127
+ // Parse out virtual versions since those are just file directors used by yarn
128
+ if (version.startsWith("virtual:")) {
129
+ const hashIdx = version.lastIndexOf("#");
130
+ if (hashIdx < 1) {
131
+ throw new Error(`could not find the expected # for virtual locator information`);
132
+ }
133
+ version = version.substring(hashIdx + 1);
134
+ }
135
+ return {
136
+ name: pkgAndVersion.substring(0, versionIdx),
137
+ version,
138
+ isPatch: version.includes("patch")
139
+ };
140
+ }
141
+
142
+ //# sourceMappingURL=getYarnInfoPackageGraph.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/packageGraphs/getYarnInfoPackageGraph.ts"],"sourcesContent":["import { execSync } from \"child_process\";\nimport { PackageGraph, PackageInfoKey } from \"./PackageGraph\";\nimport { existsSync, readFileSync } from \"fs\";\nimport { dirname, join } from \"path\";\n\n/**\n * Gets the first package.json that can be found\n */\nfunction getRootPackageJson(start: string, curDir?: string) {\n\tconst dir = curDir ?? start;\n\tconst testPath = join(dir, \"package.json\");\n\tif (existsSync(testPath)) {\n\t\treturn testPath;\n\t}\n\tconst oneUp = dirname(dir);\n\n\tif (!oneUp) {\n\t\tthrow new Error(\n\t\t\t`Could not find package.json traveling up from start dir at ${start}`,\n\t\t);\n\t}\n\treturn getRootPackageJson(start, oneUp);\n}\n\n/**\n * Retrieves the dependencies for a package in a PackageGraph\n * @param pkgDir - the directory where the top-level package is\n * @param recurse - get all the packages through all immediate dependencies\n * @returns\n */\nexport async function getYarnInfoPackageGraph(\n\tpkgDir: string,\n\trecurse: boolean,\n): Promise<PackageGraph> {\n\tconst query = execSync(`yarn info ${recurse ? \"-R\" : \"\"} --json`, {\n\t\tcwd: pkgDir,\n\t\tstdio: \"pipe\",\n\t});\n\n\t// Get the current package name so we can determine the root\n\tconst rootPkgJsonPath = getRootPackageJson(pkgDir);\n\tlet rootPkgName = \"\";\n\ttry {\n\t\trootPkgName = JSON.parse(readFileSync(rootPkgJsonPath).toString()).name;\n\t} catch (e) {\n\t\tconsole.error(\"Error retrieving root package name!\");\n\t\tthrow e;\n\t}\n\n\tconst packageGraph = new PackageGraph(pkgDir);\n\t// Since the info shows multiple versions we keep a dedup set of the serialized key to avoid longer times\n\tconst dedupSet = new Set<string>();\n\n\treturn query\n\t\t.toString()\n\t\t.split(\"\\n\")\n\t\t.reduce((pkgGraph, q) => {\n\t\t\t// Make sure we have an actual value\n\t\t\tif (q.trim()) {\n\t\t\t\tconst pkgInfo = JSON.parse(q) as YamlInfoDeps;\n\t\t\t\tconst { name, version, isPatch } = parsePackage(pkgInfo.value);\n\t\t\t\tconst nameKey = packageGraph.keySerializer({\n\t\t\t\t\tname,\n\t\t\t\t\tversion,\n\t\t\t\t});\n\t\t\t\tif (!dedupSet.has(nameKey)) {\n\t\t\t\t\tdedupSet.add(nameKey);\n\t\t\t\t\t// List of package names as dependencies\n\t\t\t\t\tlet deps: PackageInfoKey[];\n\t\t\t\t\tif (recurse) {\n\t\t\t\t\t\tdeps =\n\t\t\t\t\t\t\tpkgInfo.children?.Dependencies?.map((deps) => {\n\t\t\t\t\t\t\t\tconst info = parsePackage(deps.locator);\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tname: info.name,\n\t\t\t\t\t\t\t\t\tversion: info.version,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}) ?? [];\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// We don't actually set up the dependencies because that would make the graph incomplete\n\t\t\t\t\t\tdeps = [];\n\t\t\t\t\t}\n\t\t\t\t\tpackageGraph.addDownstreamNode({\n\t\t\t\t\t\tself: {\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\tversion,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\tversion,\n\t\t\t\t\t\t\tisPatch,\n\t\t\t\t\t\t\tisRoot: name === rootPkgName,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tto: deps ?? [],\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn pkgGraph;\n\t\t}, packageGraph);\n}\n\nfunction parsePackage(pkgAndVersion: string): {\n\tname: string;\n\tversion: string;\n\tisPatch: boolean;\n} {\n\tconst versionIdx = pkgAndVersion.indexOf(\"@\", 1);\n\tif (versionIdx < 0) {\n\t\tthrow new Error(`could not find version from name: ${pkgAndVersion}`);\n\t}\n\tlet version = pkgAndVersion.substring(versionIdx + 1);\n\t// Parse out virtual versions since those are just file directors used by yarn\n\tif (version.startsWith(\"virtual:\")) {\n\t\tconst hashIdx = version.lastIndexOf(\"#\");\n\t\tif (hashIdx < 1) {\n\t\t\tthrow new Error(\n\t\t\t\t`could not find the expected # for virtual locator information`,\n\t\t\t);\n\t\t}\n\t\tversion = version.substring(hashIdx + 1);\n\t}\n\treturn {\n\t\tname: pkgAndVersion.substring(0, versionIdx),\n\t\tversion,\n\t\tisPatch: version.includes(\"patch\"),\n\t};\n}\n\ninterface YamlInfoDeps {\n\tvalue: string;\n\tchildren?: {\n\t\tInstances: number;\n\t\tVersion: string;\n\t\tDependencies?: {\n\t\t\tdescriptor: string;\n\t\t\tlocator: string;\n\t\t}[];\n\t};\n}\n"],"names":["execSync","PackageGraph","existsSync","readFileSync","dirname","join","getRootPackageJson","start","curDir","dir","testPath","oneUp","Error","getYarnInfoPackageGraph","pkgDir","recurse","query","cwd","stdio","rootPkgJsonPath","rootPkgName","JSON","parse","toString","name","e","console","error","packageGraph","dedupSet","Set","split","reduce","pkgGraph","q","trim","pkgInfo","version","isPatch","parsePackage","value","nameKey","keySerializer","has","add","deps","children","Dependencies","map","info","locator","addDownstreamNode","self","isRoot","to","pkgAndVersion","versionIdx","indexOf","substring","starts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ChB,MAAM,IAAIhD,MACT,CAAC,6DAA6D,CAAC;QAEjE;QACAyB,UAAUA,QAAQqB,SAAS,CAACE,UAAU;IACvC;IACA,OAAO;QACNpC,MAAM+B,cAAcG,SAAS,CAAC,GAAGF;QACjCnB;QACAC,SAASD,QAAQyB,QAAQ,CAAC;IAC3B;AACD"}
@@ -0,0 +1,6 @@
1
+ export * from "./types";
2
+ export * from "./Graph";
3
+ export * from "./PackageGraph";
4
+ export * from "./getYarnInfoPackageGraph";
5
+
6
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/packageGraphs/index.ts"],"sourcesContent":["export * from \"./types\";\nexport * from \"./Graph\";\nexport * from \"./PackageGraph\";\nexport * from \"./getYarnInfoPackageGraph\";\n"],"names":[],"mappings":"AAAA,cAAc,UAAU;AACxB,cAAc,UAAU;AACxB,cAAc,iBAAiB;AAC/B,cAAc,4BAA4B"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * A function that should return a Package Graph for the current package in the working directory
3
+ *
4
+ * @param pkgDir - the directory where the top-level package is
5
+ * @param recurse - if we should get all dependencies of the direct dependencies as well
6
+ */ export { };
7
+
8
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/packageGraphs/types.ts"],"sourcesContent":["import { PackageGraph } from \"./PackageGraph\";\n\n/**\n * A function that should return a Package Graph for the current package in the working directory\n *\n * @param pkgDir - the directory where the top-level package is\n * @param recurse - if we should get all dependencies of the direct dependencies as well\n */\nexport type GetPackagesGraphFn = (recurse: boolean) => Promise<PackageGraph>;\n"],"names":[],"mappings":"AAEA;;;;;CAKC,GACD,WAA6E"}
@@ -0,0 +1,2 @@
1
+ export declare function writeESMModuleOutput(packages: string[], file: string): void;
2
+ //# sourceMappingURL=get-esm-packages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-esm-packages.d.ts","sourceRoot":"","sources":["../../../src/bin/get-esm-packages.ts"],"names":[],"mappings":"AA6EA,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,QAYpE"}
@@ -0,0 +1,3 @@
1
+ export * from "./operations";
2
+ export * from "./packageGraphs";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { PackageGraph } from "../packageGraphs";
2
+ /**
3
+ * Returns the esm packages from a PackageGraph - Assumes we can read package.json (may not work with yarn plug'n'play)
4
+ * @param pkgGraph
5
+ * @returns
6
+ */
7
+ export declare function getESMPackages(pkgGraph: PackageGraph): Promise<string[]>;
8
+ //# sourceMappingURL=getESMPackages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getESMPackages.d.ts","sourceRoot":"","sources":["../../../src/operations/getESMPackages.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,YAAY,EAIZ,MAAM,kBAAkB,CAAC;AAiD1B;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,QAAQ,EAAE,YAAY,qBAgE1D"}
@@ -0,0 +1,3 @@
1
+ export * from "./getESMPackages";
2
+ export * from "./jest";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/operations/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,QAAQ,CAAC"}
@@ -0,0 +1,40 @@
1
+ export interface EsmPackagesFile {
2
+ description: string;
3
+ /**
4
+ * Package names that are esm modules
5
+ */
6
+ packages: string[];
7
+ }
8
+ /**
9
+ * You can use this function to get get a transformIgnore pattern for jest that excludes node_modules
10
+ * from a file where we have written all esm files that were detected.
11
+ *
12
+ * This is specifically designed for a "post-install" script that scans on install and overwrites the file
13
+ * if there are new esm module types - thereby reducing the cost of tests to just a file read instead of a
14
+ * tree scan.
15
+ *
16
+ * @param options
17
+ * @returns
18
+ */
19
+ export declare function getJestNodeModulesTransformIgnore(options: {
20
+ /**
21
+ * The file location where we have written the esm module info to
22
+ *
23
+ * default (esm-modules.json)
24
+ */
25
+ file: string;
26
+ /**
27
+ * Extra packages for an exception for node modules
28
+ */
29
+ extraExceptions?: string[];
30
+ }): string;
31
+ /**
32
+ * Given a set of package names, this constructs a node_modules ignore string that exempts the
33
+ * targeted modules from jest transform.
34
+ *
35
+ * It should be used with the transformIgnore configuration.
36
+ * @param packageExceptions
37
+ * @returns
38
+ */
39
+ export declare function createNodeModulesTransformIgnore(packageExceptions: string[]): string;
40
+ //# sourceMappingURL=jest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jest.d.ts","sourceRoot":"","sources":["../../../src/operations/jest.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iCAAiC,CAAC,OAAO,EAAE;IAC1D;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B,UAMA;AAmBD;;;;;;;GAOG;AACH,wBAAgB,gCAAgC,CAAC,iBAAiB,EAAE,MAAM,EAAE,UAE3E"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Describes a node in a graph that has a value of a specific type
3
+ * and then points to values of others nodes
4
+ */
5
+ export interface Node<T, NodeKey> {
6
+ self: NodeKey;
7
+ from: NodeKey[];
8
+ to: NodeKey[];
9
+ value: T;
10
+ }
11
+ /**
12
+ * A node that we only know where it goes to at the moment
13
+ */
14
+ export interface DownstreamNode<T, NodeKey> {
15
+ self: NodeKey;
16
+ value: T;
17
+ to: NodeKey[];
18
+ }
19
+ /**
20
+ * If using a compound node key, then we require a node key serializer to get a base string out of it
21
+ */
22
+ type NodeKeySerializer<T> = T extends string ? undefined : (t: T) => string;
23
+ /**
24
+ * Mnimal "graph" class that takes in a bunch of nodes and then allows you to visit them in a particular order.
25
+ *
26
+ * The value of the node <T> is used as the unique node key for referencing other nodes.
27
+ */
28
+ export declare class Graph<T, NodeKey, NKSerializer extends NodeKeySerializer<NodeKey> = NodeKeySerializer<NodeKey>> {
29
+ readonly map: Map<string, Node<T | undefined, NodeKey>>;
30
+ private readonly noFrom;
31
+ readonly keySerializer: NKSerializer;
32
+ /**
33
+ *
34
+ * @param keySerializer - if the graph has a compound key, then you must supply a function that converts a compound key to a string
35
+ */
36
+ constructor(keySerializer: NKSerializer);
37
+ private getNodeKeyStr;
38
+ addDownstreamNode(node: DownstreamNode<T, NodeKey>): void;
39
+ validate(): void;
40
+ /**
41
+ *
42
+ * @param visit
43
+ * @param firstArrivalOnly - if set to true, we are saying that we do not care about from where we get to the node, just the first arrival matters
44
+ * This will depend on your visit function, since the visit function can pass parent -> child info that may change based on the node
45
+ * it is coming from
46
+ */
47
+ topDownVisitAsync<R>(visit: VisitFunction<Node<T, NodeKey>, R>, firstArrivalOnly?: boolean): Promise<void>;
48
+ /**
49
+ *
50
+ * @param nodeKey - the key that we used to retrieve this node
51
+ * @param node - the node itself
52
+ * @param visit - the visit function
53
+ * @param guestBook - This is used to track if we have already visited the node - note this means we don't expect the visit function to change results
54
+ * regardless of the node that we come from
55
+ * @param prevResult - the result of the last node that got here
56
+ * @returns
57
+ */
58
+ visitDownNodeAsync<R>(node: Node<T, NodeKey>, visit: VisitFunction<Node<T, NodeKey>, R>, guestBook?: Set<string>, prevResult?: R): Promise<void>;
59
+ }
60
+ type StopVisiting = boolean;
61
+ /**
62
+ * This function will be called for each visit while traversing along the "to" nodes. You can return
63
+ * a result from the visit function that will be provided to any of the "to" visitors as the previous result.
64
+ *
65
+ * Additionally, if you return a boolean value in the second tuple, it can stop any further downstream visits from this
66
+ * particular visitor function. (Keep in mind that a visitor can only stop further travel from itself, so if there are
67
+ * multiple visits from multiple nodes each visitor will need to stop further travel. If you do use a guestbook, in a
68
+ * visiting function, that would stop travel fromm the visitor function that first calls stop.)
69
+ */
70
+ type VisitFunction<Node, R> = (currentNode: Node, previousResult?: R) => Promise<[R, StopVisiting]>;
71
+ export {};
72
+ //# sourceMappingURL=Graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Graph.d.ts","sourceRoot":"","sources":["../../../src/packageGraphs/Graph.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,WAAW,IAAI,CAAC,CAAC,EAAE,OAAO;IAC/B,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,EAAE,EAAE,OAAO,EAAE,CAAC;IACd,KAAK,EAAE,CAAC,CAAC;CACT;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,EAAE,OAAO;IACzC,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,CAAC,CAAC;IACT,EAAE,EAAE,OAAO,EAAE,CAAC;CACd;AAED;;GAEG;AACH,KAAK,iBAAiB,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG,SAAS,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,CAAC;AAE5E;;;;GAIG;AACH,qBAAa,KAAK,CACjB,CAAC,EACD,OAAO,EACP,YAAY,SAAS,iBAAiB,CAAC,OAAO,CAAC,GAAG,iBAAiB,CAAC,OAAO,CAAC;IAG5E,QAAQ,CAAC,GAAG,4CAAmD;IAC/D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAC5C,QAAQ,CAAC,aAAa,EAAE,YAAY,CAAC;IAErC;;;OAGG;gBACS,aAAa,EAAE,YAAY;IAIvC,OAAO,CAAC,aAAa;IAMrB,iBAAiB,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,EAAE,OAAO,CAAC;IA0ClD,QAAQ;IAcR;;;;;;OAMG;IACG,iBAAiB,CAAC,CAAC,EACxB,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,EACzC,gBAAgB,CAAC,EAAE,OAAO;IAS3B;;;;;;;;;OASG;IACG,kBAAkB,CAAC,CAAC,EACzB,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,EACtB,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,EACzC,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EACvB,UAAU,CAAC,EAAE,CAAC;CAsBf;AAED,KAAK,YAAY,GAAG,OAAO,CAAC;AAE5B;;;;;;;;GAQG;AACH,KAAK,aAAa,CAAC,IAAI,EAAE,CAAC,IAAI,CAC7B,WAAW,EAAE,IAAI,EACjB,cAAc,CAAC,EAAE,CAAC,KACd,OAAO,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { Graph } from "./Graph";
2
+ export interface PackageInfo {
3
+ name: string;
4
+ version: string;
5
+ isPatch: boolean;
6
+ isRoot: boolean;
7
+ }
8
+ export interface PackageInfoKey {
9
+ name: string;
10
+ version: string;
11
+ }
12
+ /**
13
+ * A graph of package names and their dependencies
14
+ */
15
+ export declare class PackageGraph extends Graph<PackageInfo, PackageInfoKey> {
16
+ readonly pkgDir: string;
17
+ constructor(pkgDir: string);
18
+ }
19
+ //# sourceMappingURL=PackageGraph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PackageGraph.d.ts","sourceRoot":"","sources":["../../../src/packageGraphs/PackageGraph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAEhB,OAAO,EAAE,OAAO,CAAC;IAEjB,MAAM,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK,CAAC,WAAW,EAAE,cAAc,CAAC;IACnE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBACZ,MAAM,EAAE,MAAM;CAQ1B"}
@@ -0,0 +1,9 @@
1
+ import { PackageGraph } from "./PackageGraph";
2
+ /**
3
+ * Retrieves the dependencies for a package in a PackageGraph
4
+ * @param pkgDir - the directory where the top-level package is
5
+ * @param recurse - get all the packages through all immediate dependencies
6
+ * @returns
7
+ */
8
+ export declare function getYarnInfoPackageGraph(pkgDir: string, recurse: boolean): Promise<PackageGraph>;
9
+ //# sourceMappingURL=getYarnInfoPackageGraph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getYarnInfoPackageGraph.d.ts","sourceRoot":"","sources":["../../../src/packageGraphs/getYarnInfoPackageGraph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAkB,MAAM,gBAAgB,CAAC;AAuB9D;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC5C,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,YAAY,CAAC,CAkEvB"}
@@ -0,0 +1,5 @@
1
+ export * from "./types";
2
+ export * from "./Graph";
3
+ export * from "./PackageGraph";
4
+ export * from "./getYarnInfoPackageGraph";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packageGraphs/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { PackageGraph } from "./PackageGraph";
2
+ /**
3
+ * A function that should return a Package Graph for the current package in the working directory
4
+ *
5
+ * @param pkgDir - the directory where the top-level package is
6
+ * @param recurse - if we should get all dependencies of the direct dependencies as well
7
+ */
8
+ export type GetPackagesGraphFn = (recurse: boolean) => Promise<PackageGraph>;
9
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/packageGraphs/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@hanseltime/esm-interop-tools",
3
+ "main": "dist/cjs/index.js",
4
+ "types": "dist/types/index.d.ts",
5
+ "bin": {
6
+ "get-esm-packages": "dist/bin/get-esm-packages.js"
7
+ },
8
+ "exports": {
9
+ ".": {
10
+ "require": "./dist/cjs/index.js",
11
+ "import": "./dist/esm/index.mjs",
12
+ "types": "./dist/types/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build:esm": "tswc -- src -d dist/esm --config-file .esm.swcrc --strip-leading-paths --out-file-extension mjs",
21
+ "build:cjs": "tswc -- src -d dist/cjs --config-file .cjs.swcrc --strip-leading-paths",
22
+ "build:bin": "rspack build",
23
+ "build:types": "tsc",
24
+ "build": "yarn build:types && yarn build:esm && yarn build:cjs && yarn build:bin",
25
+ "lint": "biome lint",
26
+ "format": "biome format",
27
+ "test": "jest --passWithNoTests",
28
+ "ts-run": "./bin/ts-run.sh",
29
+ "release": "yarn semantic-release",
30
+ "get-esm-packages": "yarn ts-run src/bin/get-esm-packages.ts"
31
+ },
32
+ "devDependencies": {
33
+ "@biomejs/biome": "1.9.4",
34
+ "@commitlint/config-angular": "^19.6.0",
35
+ "@hanseltime/swc-plugin-node-globals-inject": "^1.0.0",
36
+ "@rspack/cli": "^1.1.6",
37
+ "@rspack/core": "^1.1.6",
38
+ "@semantic-release/changelog": "^6.0.3",
39
+ "@semantic-release/git": "^10.0.1",
40
+ "@swc/cli": "^0.5.2",
41
+ "@swc/core": "^1.10.1",
42
+ "@types/jest": "^29.5.14",
43
+ "@types/node": "^18",
44
+ "commitlint": "^19.6.1",
45
+ "husky": "^9.1.7",
46
+ "jest": "^29.7.0",
47
+ "jest-chain-transform": "^0.0.8",
48
+ "semantic-release": "^24.2.0",
49
+ "ts-jest": "^29.2.5",
50
+ "ts-node": "^10.9.2",
51
+ "tswc": "^1.4.0",
52
+ "tsx": "^4.19.2",
53
+ "typescript": "^5.0.0"
54
+ },
55
+ "dependencies": {
56
+ "commander": "^12.1.0",
57
+ "resolve-package-path": "^4.0.3"
58
+ },
59
+ "publishConfig": {
60
+ "access": "public"
61
+ },
62
+ "packageManager": "yarn@4.5.3",
63
+ "version": "1.0.0"
64
+ }