@mark1russell7/boundaries 0.0.0-stage → 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mark Russell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,109 @@
1
- # Temporary Holding Version
1
+ # @mark1russell7/boundaries
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ This package gives the import boundaries of a pnpm workspace as a [dependency-cruiser](https://github.com/sverweij/dependency-cruiser) configuration. Each package is a unit. Another package imports it only through an entry of its `package.json`.
4
+
5
+ ## Rules
6
+
7
+ | Rule | It fails when |
8
+ |---|---|
9
+ | `relative-import-out-of-<package>` | A relative import (`../../b/src/x.js`) goes into the folder of a different package. |
10
+ | `deep-import-into-<package>` | An import gets to a file of a package that is not an entry of its `package.json` (`exports`, `main`, `module`, `types` or `bin`). |
11
+ | `not-a-declared-export` | An import of a workspace package does not resolve. The path is not in its `exports`, or the package is not built. |
12
+ | `unknown-workspace-package` | An import in a scope of the workspace (for example `@x/typo`) does not resolve, and the name is not a workspace package or a declared dependency. |
13
+ | `import-of-the-app-<package>` | A package imports an app. An app is a leaf of the graph. This rule is only on with the option `apps`. |
14
+
15
+ A type-only import is a boundary too. Tests, fixtures and declaration files are not part of a boundary.
16
+
17
+ The rule `import-of-the-app-<package>` examines only the path of an import that resolves. When the name of an app does not resolve, `not-a-declared-export` finds the import.
18
+
19
+ The scopes of `unknown-workspace-package` are the scopes of the workspace package names. For example, the packages `@x/a` and `@x/b` give the scope `@x`. A declared dependency is a name in a dependency field (`dependencies`, `devDependencies`, `peerDependencies` or `optionalDependencies`) of the root `package.json` or of a workspace package.
20
+
21
+ ## Use
22
+
23
+ Install the package, `dependency-cruiser` and, for TypeScript 7 or for source with no TypeScript compiler, `@swc/core`:
24
+
25
+ ```sh
26
+ pnpm add -D @mark1russell7/boundaries dependency-cruiser @swc/core
27
+ ```
28
+
29
+ Since pnpm 11, the install fails with `ERR_PNPM_IGNORED_BUILDS` when a package has an install script that `allowBuilds` does not name. `@swc/core` has an install script. That script only examines the native package, and pnpm installs the native package as an optional dependency. Thus disallow the script in `pnpm-workspace.yaml` before the install:
30
+
31
+ ```yaml
32
+ allowBuilds:
33
+ "@swc/core": false
34
+ ```
35
+
36
+ The option `--allow-build='!@swc/core'` of `pnpm add` writes the same setting.
37
+
38
+ Write `.dependency-cruiser.mjs` at the root of the repository:
39
+
40
+ ```js
41
+ import { boundaries } from "@mark1russell7/boundaries";
42
+
43
+ export default boundaries(import.meta.dirname);
44
+ ```
45
+
46
+ Add the script `"check:boundaries": "depcruise --config .dependency-cruiser.mjs packages"`. The shared CI of the template starts `check:boundaries` after `build` (`CI.md`).
47
+
48
+ ## Options
49
+
50
+ `boundaries(root, options)` reads the packages of `pnpm-workspace.yaml`. These options change it:
51
+
52
+ | Option | Default | What it sets |
53
+ |---|---|---|
54
+ | `packages` | the `packages` list of `pnpm-workspace.yaml` | The globs of the package folders. |
55
+ | `apps` | none | The apps. `"private"` makes each private package an app. |
56
+ | `reference` | none | A text before each comment, for example the name of the decision record. The rules of `forbidden` get it too, when their comment does not start with it. |
57
+ | `scopes` | the scopes of the workspace package names | The scopes of `unknown-workspace-package`. A list replaces the scopes. `{ add: ["@y"], remove: ["@x"] }` changes them. `[]` turns off the rule. |
58
+ | `buildFolders` | `["dist", "build"]` | The build folders of each package. The analysis does not follow them. `[]` follows them. |
59
+ | `forbidden` | none | More rules of the repository, after the rules of the boundaries. |
60
+ | `options` | the default options | More options of dependency-cruiser. They replace the default options that have the same key. |
61
+
62
+ An example with the rules of a repository:
63
+
64
+ ```js
65
+ const { boundaries } = require("@mark1russell7/boundaries");
66
+
67
+ module.exports = boundaries(__dirname, {
68
+ apps: "private",
69
+ reference: "Invariant I9 of ARCHITECTURE.md.",
70
+ forbidden: [
71
+ {
72
+ name: "transport-imports-server",
73
+ severity: "error",
74
+ comment: "A transport does not import the server.",
75
+ from: { path: "^packages/client/src/adapters/" },
76
+ to: { path: "^packages/server/" },
77
+ },
78
+ ],
79
+ });
80
+ ```
81
+
82
+ ## The default options
83
+
84
+ - `doNotFollow`: `node_modules` and the build folders of each package (`buildFolders`). An import of a different package stops at its entry, for example `packages/b/dist/index.js`. The analysis does not go into the imports of that built file. It also does not start from the files of a build folder.
85
+ - `enhancedResolveOptions.conditionNames`: `["import", "node", "default"]`, as Node resolves an ESM import. An entry that is only for `require` does not resolve.
86
+ - `exclude`: tests, fixtures, declaration files and `node_modules`.
87
+
88
+ To change a default option, give the option in `options`. For example, `options: { enhancedResolveOptions: { exportsFields: ["exports"], conditionNames: ["import", "require", "node", "default"], mainFields: ["module", "main"] } }` also resolves the entries for `require`.
89
+
90
+ ## The parser
91
+
92
+ dependency-cruiser reads TypeScript with the TypeScript compiler of the repository only for TypeScript 2 to 6. With TypeScript 7, or with no TypeScript, `boundaries()` sets the parser `swc` when `@swc/core` is installed. Without `@swc/core`, dependency-cruiser reads only JavaScript. For a check of built JavaScript, set `buildFolders: []`.
93
+
94
+ ## Changes in 0.2.0
95
+
96
+ These changes can give different results than 0.1.0:
97
+
98
+ - The analysis does not follow the build folders (`dist/` and `build/`) of the packages.
99
+ - The resolution does not use the condition `require`.
100
+ - The new rule `unknown-workspace-package` finds an import of an unknown name in a scope of the workspace.
101
+ - The rules of `forbidden` get the text of `reference`.
102
+
103
+ ## Other exports
104
+
105
+ - `boundaryRules(packages, options)` gives only the rules, for a list of packages.
106
+ - `workspacePackages(root, globs)` gives the packages of the workspace, their entries and their declared dependencies.
107
+ - `workspaceScopes(packages, scopes)` gives the scopes of `unknown-workspace-package`.
108
+ - `declaredDependencies(manifest)` gives the names in the dependency fields of a `package.json`.
109
+ - `defaultOptions(root, { packages, buildFolders })`, `doNotFollowPaths(packages, buildFolders)` and `parserOptions(root)` give the default options.
@@ -0,0 +1,345 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let node_fs = require("node:fs");
3
+ let node_module = require("node:module");
4
+ let node_path = require("node:path");
5
+ // src/index.ts
6
+ /**
7
+ * The import boundaries of a workspace, as a dependency-cruiser configuration. Each package is a
8
+ * unit. Another package imports it only through an entry of its package.json (`exports`, `main`,
9
+ * `module`, `types`, `bin`). A relative path or a deep path into its folder is not an entry.
10
+ *
11
+ * A repository uses it from its `.dependency-cruiser.cjs`:
12
+ *
13
+ * ```js
14
+ * const { boundaries } = require("@mark1russell7/boundaries");
15
+ * module.exports = boundaries(__dirname, { apps: "private" });
16
+ * ```
17
+ */
18
+ const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
19
+ /** The default build folders of a package. */
20
+ const BUILD_FOLDERS = ["dist", "build"];
21
+ const DEPENDENCY_FIELDS = [
22
+ "dependencies",
23
+ "devDependencies",
24
+ "peerDependencies",
25
+ "optionalDependencies"
26
+ ];
27
+ /** The names of the dependencies of a package.json, from each dependency field. */
28
+ function declaredDependencies(manifest) {
29
+ const names = /* @__PURE__ */ new Set();
30
+ for (const field of DEPENDENCY_FIELDS) {
31
+ const value = manifest[field];
32
+ if (value && typeof value === "object" && !Array.isArray(value)) for (const name of Object.keys(value)) names.add(name);
33
+ }
34
+ return [...names].sort();
35
+ }
36
+ /** The scopes of the package names, for example "@x" for "@x/a", changed by the option `scopes`. A name with no scope gives no scope. */
37
+ function workspaceScopes(packages, opts = {}) {
38
+ const normal = (scope) => (scope.startsWith("@") ? scope : `@${scope}`).replace(/\/$/, "");
39
+ if (Array.isArray(opts)) return [...new Set(opts.map(normal))].sort();
40
+ const scopes = new Set(packages.filter((p) => p.name.startsWith("@") && p.name.includes("/")).map((p) => p.name.slice(0, p.name.indexOf("/"))));
41
+ for (const scope of opts.add ?? []) scopes.add(normal(scope));
42
+ for (const scope of opts.remove ?? []) scopes.delete(normal(scope));
43
+ return [...scopes].sort();
44
+ }
45
+ /** The `packages` list of a pnpm-workspace.yaml file. It reads only that list, with no YAML library. */
46
+ function workspaceGlobs(yaml) {
47
+ const globs = [];
48
+ let inList = false;
49
+ for (const raw of yaml.split(/\r?\n/)) {
50
+ const hash = raw.indexOf(" #");
51
+ const line = (hash === -1 ? raw : raw.slice(0, hash)).trimEnd();
52
+ const trimmed = line.trimStart();
53
+ if (trimmed === "" || trimmed.startsWith("#")) continue;
54
+ if (/^packages\s*:/.test(line)) {
55
+ inList = true;
56
+ continue;
57
+ }
58
+ if (!inList) continue;
59
+ if (trimmed === line) break;
60
+ if (!trimmed.startsWith("-")) continue;
61
+ const item = trimmed.slice(1).trim().replace(/^["']/, "").replace(/["']$/, "");
62
+ if (item) globs.push(item);
63
+ }
64
+ return globs;
65
+ }
66
+ function isDir(path) {
67
+ try {
68
+ return (0, node_fs.statSync)(path).isDirectory();
69
+ } catch {
70
+ return false;
71
+ }
72
+ }
73
+ /** The folders that a glob of pnpm-workspace.yaml gives: "a/b", "a/*" and "a/**". */
74
+ function expand(root, glob) {
75
+ const clean = glob.replace(/^\.\//, "").replace(/\/$/, "");
76
+ const star = clean.indexOf("*");
77
+ if (star === -1) return isDir((0, node_path.join)(root, clean)) ? [clean] : [];
78
+ const base = clean.slice(0, star).replace(/\/$/, "");
79
+ const recursive = clean.slice(star).startsWith("**");
80
+ const found = [];
81
+ const walk = (dir, depth) => {
82
+ let entries;
83
+ try {
84
+ entries = (0, node_fs.readdirSync)((0, node_path.join)(root, dir), { withFileTypes: true });
85
+ } catch {
86
+ return;
87
+ }
88
+ for (const entry of entries) {
89
+ if (!entry.isDirectory() || entry.name === "node_modules" || entry.name.startsWith(".")) continue;
90
+ const child = dir === "" ? entry.name : `${dir}/${entry.name}`;
91
+ found.push(child);
92
+ if (recursive && depth < 6) walk(child, depth + 1);
93
+ }
94
+ };
95
+ walk(base, 0);
96
+ return found;
97
+ }
98
+ /** The leaf strings of an `exports` value, with their subpath keys. */
99
+ function exportTargets(value, out = []) {
100
+ if (typeof value === "string") out.push(value);
101
+ else if (Array.isArray(value)) for (const item of value) exportTargets(item, out);
102
+ else if (value && typeof value === "object") for (const item of Object.values(value)) exportTargets(item, out);
103
+ return out;
104
+ }
105
+ /**
106
+ * The RegExp source of an entry target of a package. The extension can change, because
107
+ * dependency-cruiser resolves "./x.js" to the source file x.ts, and "*" of a subpath pattern matches
108
+ * each path.
109
+ */
110
+ function entryPattern(dir, target) {
111
+ return `^${node_path.posix.normalize(node_path.posix.join(dir, target.replace(/^\.\//, ""))).replace(/\.d\.[cm]?ts$|\.[cm]?[jt]sx?$/, "").split("*").map(escape).join(".*")}(${EXTENSIONS})?$`;
112
+ }
113
+ const EXTENSIONS = [
114
+ ".js",
115
+ ".mjs",
116
+ ".cjs",
117
+ ".jsx",
118
+ ".ts",
119
+ ".mts",
120
+ ".cts",
121
+ ".tsx",
122
+ ".d.ts",
123
+ ".d.mts",
124
+ ".d.cts"
125
+ ].map(escape).join("|");
126
+ /** The entries of a package.json: the files that other packages can import. */
127
+ function packageEntries(dir, manifest) {
128
+ const targets = exportTargets(manifest["exports"]);
129
+ for (const field of [
130
+ "main",
131
+ "module",
132
+ "types",
133
+ "typings"
134
+ ]) {
135
+ const value = manifest[field];
136
+ if (typeof value === "string") targets.push(value);
137
+ }
138
+ if (typeof manifest["bin"] === "string") targets.push(manifest["bin"]);
139
+ else if (manifest["bin"] && typeof manifest["bin"] === "object") targets.push(...exportTargets(manifest["bin"]));
140
+ if (targets.length === 0 && manifest["exports"] === void 0) targets.push("./index.js");
141
+ return [...new Set(targets.filter((t) => !t.endsWith(".json") || t === "./package.json").map((t) => entryPattern(dir, t)))];
142
+ }
143
+ /** The packages of the workspace in the folder `root`. */
144
+ function workspacePackages(root, globs) {
145
+ let list = globs;
146
+ if (!list) {
147
+ try {
148
+ list = workspaceGlobs((0, node_fs.readFileSync)((0, node_path.join)(root, "pnpm-workspace.yaml"), "utf8"));
149
+ } catch {
150
+ list = [];
151
+ }
152
+ if (list.length === 0) list = ["packages/*"];
153
+ }
154
+ const excluded = list.filter((g) => g.startsWith("!")).flatMap((g) => expand(root, g.slice(1)));
155
+ const dirs = [...new Set(list.filter((g) => !g.startsWith("!")).flatMap((g) => expand(root, g)))].filter((d) => !excluded.includes(d));
156
+ const found = [];
157
+ for (const dir of dirs.sort()) {
158
+ let manifest;
159
+ try {
160
+ manifest = JSON.parse((0, node_fs.readFileSync)((0, node_path.join)(root, dir, "package.json"), "utf8"));
161
+ } catch {
162
+ continue;
163
+ }
164
+ if (typeof manifest["name"] !== "string") continue;
165
+ found.push({
166
+ name: manifest["name"],
167
+ dir,
168
+ private: manifest["private"] === true,
169
+ entries: packageEntries(dir, manifest),
170
+ dependencies: declaredDependencies(manifest)
171
+ });
172
+ }
173
+ return found;
174
+ }
175
+ /** The rules of the boundaries for a list of packages. `boundaries()` reads the list from the workspace. */
176
+ function boundaryRules(packages, opts = {}) {
177
+ const why = (text) => opts.reference ? `${opts.reference} ${text}` : text;
178
+ const anyPackage = packages.map((p) => `^${escape(p.dir)}/`);
179
+ const rules = [];
180
+ for (const pkg of packages) {
181
+ const own = `^${escape(pkg.dir)}/`;
182
+ const others = anyPackage.filter((path) => path !== own);
183
+ if (others.length > 0) rules.push({
184
+ name: `relative-import-out-of-${slug(pkg.name)}`,
185
+ severity: "error",
186
+ comment: why(`A relative import leaves the package ${pkg.name}. Import the other package by its name, through an entry of its package.json.`),
187
+ from: { path: own },
188
+ to: {
189
+ path: others,
190
+ pathNot: own,
191
+ dependencyTypes: ["local"]
192
+ }
193
+ });
194
+ rules.push({
195
+ name: `deep-import-into-${slug(pkg.name)}`,
196
+ severity: "error",
197
+ comment: why(`An import reaches into the folder of ${pkg.name} at a file that is not an entry of its package.json (exports, main, module, types or bin). Import an entry, or add the file to the exports of ${pkg.name}.`),
198
+ from: { pathNot: own },
199
+ to: pkg.entries.length > 0 ? {
200
+ path: own,
201
+ pathNot: pkg.entries
202
+ } : { path: own }
203
+ });
204
+ }
205
+ const names = packages.map((p) => escape(p.name));
206
+ if (names.length > 0) rules.push({
207
+ name: "not-a-declared-export",
208
+ severity: "error",
209
+ comment: why("An import of a package of this workspace does not resolve. The path is not an entry of its exports, or the package is not built."),
210
+ from: {},
211
+ to: {
212
+ path: `^(${names.join("|")})(/|$)`,
213
+ couldNotResolve: true
214
+ }
215
+ });
216
+ const scopes = workspaceScopes(packages, opts.scopes);
217
+ if (scopes.length > 0) {
218
+ const inScope = (name) => scopes.some((scope) => name.startsWith(`${scope}/`));
219
+ const declared = [...packages.flatMap((p) => p.dependencies ?? []), ...opts.dependencies ?? []];
220
+ const known = [...new Set([...packages.map((p) => p.name), ...declared].filter(inScope))].sort().map(escape);
221
+ rules.push({
222
+ name: "unknown-workspace-package",
223
+ severity: "error",
224
+ comment: why(`An import names a package of the scope ${scopes.join(", ")}, but the import does not resolve. The name is not a package of this workspace and not a declared dependency. Correct the name, or add the package.`),
225
+ from: {},
226
+ to: {
227
+ path: `^(${scopes.map(escape).join("|")})/`,
228
+ ...known.length > 0 ? { pathNot: `^(${known.join("|")})(/|$)` } : {},
229
+ couldNotResolve: true
230
+ }
231
+ });
232
+ }
233
+ const apps = opts.apps === "private" ? packages.filter((p) => p.private) : packages.filter((p) => (opts.apps ?? []).includes(p.name));
234
+ for (const app of apps) rules.push({
235
+ name: `import-of-the-app-${slug(app.name)}`,
236
+ severity: "error",
237
+ comment: why(`A package imports the app ${app.name}. An app is a leaf: no other package imports it. Move the shared code to a library package.`),
238
+ from: { pathNot: `^${escape(app.dir)}/` },
239
+ to: { path: `^${escape(app.dir)}/` }
240
+ });
241
+ return rules;
242
+ }
243
+ const slug = (name) => name.replace(/^@/, "").replace(/[^A-Za-z0-9]+/g, "-");
244
+ /**
245
+ * The parser of the TypeScript source. dependency-cruiser reads TypeScript with the TypeScript
246
+ * compiler of the repository only for TypeScript 2 to 6. With TypeScript 7 or no TypeScript, it reads
247
+ * TypeScript with swc when @swc/core is installed. Else it reads only JavaScript (acorn): that is
248
+ * enough for a check of built JavaScript.
249
+ */
250
+ function parserOptions(root) {
251
+ if (!root) return {};
252
+ const require$1 = (0, node_module.createRequire)((0, node_path.join)(root, "package.json"));
253
+ try {
254
+ const { version } = require$1("typescript/package.json");
255
+ if (Number(version.split(".")[0]) < 7) return { tsPreCompilationDeps: true };
256
+ } catch {}
257
+ for (const from of [require$1, (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)]) try {
258
+ from.resolve("@swc/core");
259
+ return { parser: "swc" };
260
+ } catch {}
261
+ return {};
262
+ }
263
+ /** The RegExp sources of the paths that the analysis does not follow: node_modules and the build folders of each package. */
264
+ function doNotFollowPaths(packages, buildFolders = BUILD_FOLDERS) {
265
+ const paths = ["(^|/)node_modules/"];
266
+ const dirs = packages.map((p) => p.dir).filter((dir) => dir !== "" && dir !== ".");
267
+ const folders = buildFolders.map((folder) => folder.replace(/^\.\//, "").replace(/\/$/, "")).filter((folder) => folder !== "");
268
+ if (dirs.length > 0 && folders.length > 0) paths.push(`^(${dirs.map(escape).join("|")})/(${folders.map(escape).join("|")})/`);
269
+ return paths;
270
+ }
271
+ /**
272
+ * The default options: the source of the packages, with type-only imports, resolved as Node resolves
273
+ * an ESM import. There is no `includeOnly`, because it also removes the imports that do not resolve,
274
+ * and the rule not-a-declared-export needs them. The analysis does not follow node_modules and the
275
+ * build folders of the packages: an import of a package stops at its entry. The "types" condition is
276
+ * not used: it resolves to a declaration file, and the analysis excludes declaration files, so a deep
277
+ * import does not show. The `require` condition is not used: an ESM import does not resolve to an
278
+ * entry that is only for `require`.
279
+ */
280
+ function defaultOptions(root, input = {}) {
281
+ const packages = input.packages ?? (root ? workspacePackages(root) : []);
282
+ return {
283
+ ...parserOptions(root),
284
+ exclude: { path: [
285
+ "(^|/)node_modules/",
286
+ "\\.(test|spec|e2e)\\.[cm]?[jt]sx?$",
287
+ "\\.d\\.[cm]?ts$",
288
+ "/(test|tests|e2e|__tests__|fixtures)/"
289
+ ] },
290
+ doNotFollow: { path: doNotFollowPaths(packages, input.buildFolders) },
291
+ enhancedResolveOptions: {
292
+ exportsFields: ["exports"],
293
+ conditionNames: [
294
+ "import",
295
+ "node",
296
+ "default"
297
+ ],
298
+ mainFields: ["module", "main"]
299
+ },
300
+ skipAnalysisNotInRules: true
301
+ };
302
+ }
303
+ /** A rule with the reference before its comment, when the comment does not start with it. */
304
+ function withReference(rule, reference) {
305
+ if (!reference || rule.comment?.startsWith(reference)) return rule;
306
+ return {
307
+ ...rule,
308
+ comment: rule.comment ? `${reference} ${rule.comment}` : reference
309
+ };
310
+ }
311
+ /** The dependency-cruiser configuration of the boundaries for the workspace in the folder `root`. */
312
+ function boundaries(root, opts = {}) {
313
+ const packages = workspacePackages(root, opts.packages);
314
+ let rootManifest = {};
315
+ try {
316
+ rootManifest = JSON.parse((0, node_fs.readFileSync)((0, node_path.join)(root, "package.json"), "utf8"));
317
+ } catch {}
318
+ const options = {
319
+ ...defaultOptions(root, {
320
+ packages,
321
+ ...opts.buildFolders ? { buildFolders: opts.buildFolders } : {}
322
+ }),
323
+ ...opts.options
324
+ };
325
+ return {
326
+ forbidden: [...boundaryRules(packages, {
327
+ ...opts,
328
+ dependencies: declaredDependencies(rootManifest)
329
+ }), ...(opts.forbidden ?? []).map((rule) => withReference(rule, opts.reference))],
330
+ options
331
+ };
332
+ }
333
+ exports.boundaries = boundaries;
334
+ exports.boundaryRules = boundaryRules;
335
+ exports.declaredDependencies = declaredDependencies;
336
+ exports.defaultOptions = defaultOptions;
337
+ exports.doNotFollowPaths = doNotFollowPaths;
338
+ exports.entryPattern = entryPattern;
339
+ exports.packageEntries = packageEntries;
340
+ exports.parserOptions = parserOptions;
341
+ exports.workspaceGlobs = workspaceGlobs;
342
+ exports.workspacePackages = workspacePackages;
343
+ exports.workspaceScopes = workspaceScopes;
344
+
345
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["statSync","join","readdirSync","posix","readFileSync","require","createRequire"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * The import boundaries of a workspace, as a dependency-cruiser configuration. Each package is a\n * unit. Another package imports it only through an entry of its package.json (`exports`, `main`,\n * `module`, `types`, `bin`). A relative path or a deep path into its folder is not an entry.\n *\n * A repository uses it from its `.dependency-cruiser.cjs`:\n *\n * ```js\n * const { boundaries } = require(\"@mark1russell7/boundaries\");\n * module.exports = boundaries(__dirname, { apps: \"private\" });\n * ```\n */\nimport { readdirSync, readFileSync, statSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { join, posix } from \"node:path\";\n\n/** A rule of dependency-cruiser (the `forbidden` list). The package does not depend on the types of dependency-cruiser. */\nexport interface Rule {\n name: string;\n severity: \"error\" | \"warn\" | \"info\" | \"ignore\";\n comment?: string;\n from: Record<string, unknown>;\n to: Record<string, unknown>;\n}\n\n/** A dependency-cruiser configuration. */\nexport interface Config {\n forbidden: Rule[];\n options: Record<string, unknown>;\n}\n\n/** A package of the workspace. */\nexport interface WorkspacePackage {\n /** The name in package.json. */\n name: string;\n /** The folder, relative to the root, with \"/\". */\n dir: string;\n private: boolean;\n /** RegExp sources of the files that other packages can import. */\n entries: string[];\n /** The names of the dependencies in package.json: dependencies, devDependencies, peerDependencies and optionalDependencies. */\n dependencies?: string[];\n}\n\n/**\n * The scopes of the rule unknown-workspace-package. A list replaces the scopes of the workspace\n * packages. `add` and `remove` change that list. An empty list turns off the rule.\n */\nexport type ScopeOptions = string[] | { add?: string[]; remove?: string[] };\n\nexport interface BoundaryOptions {\n /**\n * Globs of the package folders, for example `[\"packages/*\"]`. The default is the `packages` list of\n * pnpm-workspace.yaml, or `[\"packages/*\"]` when the file does not exist.\n */\n packages?: string[];\n /** The apps: the leaves of the graph, which no other package imports. \"private\" means each private package. */\n apps?: \"private\" | string[];\n /** A text before each comment, for example the decision record of the rules. The comments of `forbidden` get it too. */\n reference?: string;\n /**\n * The scopes (for example \"@x\") in which an import that does not resolve must name a workspace\n * package or a declared dependency. The default is the scopes of the workspace package names.\n */\n scopes?: ScopeOptions;\n /**\n * The build folders of each package, for example `[\"dist\", \"build\"]` (the default). The analysis\n * does not follow the imports of their files, and it does not start from them.\n */\n buildFolders?: string[];\n /** More rules, after the rules of the boundaries. */\n forbidden?: Rule[];\n /** More options of dependency-cruiser. They replace the default options with the same key. */\n options?: Record<string, unknown>;\n}\n\nconst escape = (text: string): string => text.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\n/** The default build folders of a package. */\nconst BUILD_FOLDERS = [\"dist\", \"build\"];\n\nconst DEPENDENCY_FIELDS = [\"dependencies\", \"devDependencies\", \"peerDependencies\", \"optionalDependencies\"];\n\n/** The names of the dependencies of a package.json, from each dependency field. */\nexport function declaredDependencies(manifest: Record<string, unknown>): string[] {\n const names = new Set<string>();\n for (const field of DEPENDENCY_FIELDS) {\n const value = manifest[field];\n if (value && typeof value === \"object\" && !Array.isArray(value)) for (const name of Object.keys(value)) names.add(name);\n }\n return [...names].sort();\n}\n\n/** The scopes of the package names, for example \"@x\" for \"@x/a\", changed by the option `scopes`. A name with no scope gives no scope. */\nexport function workspaceScopes(packages: Pick<WorkspacePackage, \"name\">[], opts: ScopeOptions = {}): string[] {\n const normal = (scope: string): string => (scope.startsWith(\"@\") ? scope : `@${scope}`).replace(/\\/$/, \"\");\n if (Array.isArray(opts)) return [...new Set(opts.map(normal))].sort();\n const scopes = new Set(packages.filter((p) => p.name.startsWith(\"@\") && p.name.includes(\"/\")).map((p) => p.name.slice(0, p.name.indexOf(\"/\"))));\n for (const scope of opts.add ?? []) scopes.add(normal(scope));\n for (const scope of opts.remove ?? []) scopes.delete(normal(scope));\n return [...scopes].sort();\n}\n\n/** The `packages` list of a pnpm-workspace.yaml file. It reads only that list, with no YAML library. */\nexport function workspaceGlobs(yaml: string): string[] {\n const globs: string[] = [];\n let inList = false;\n // String operations, not one large RegExp: a RegExp with nested whitespace groups can be slow on some input.\n for (const raw of yaml.split(/\\r?\\n/)) {\n const hash = raw.indexOf(\" #\");\n const line = (hash === -1 ? raw : raw.slice(0, hash)).trimEnd();\n const trimmed = line.trimStart();\n if (trimmed === \"\" || trimmed.startsWith(\"#\")) continue;\n if (/^packages\\s*:/.test(line)) {\n inList = true;\n continue;\n }\n if (!inList) continue;\n if (trimmed === line) break;\n if (!trimmed.startsWith(\"-\")) continue;\n const item = trimmed.slice(1).trim().replace(/^[\"']/, \"\").replace(/[\"']$/, \"\");\n if (item) globs.push(item);\n }\n return globs;\n}\n\nfunction isDir(path: string): boolean {\n try {\n return statSync(path).isDirectory();\n } catch {\n return false;\n }\n}\n\n/** The folders that a glob of pnpm-workspace.yaml gives: \"a/b\", \"a/*\" and \"a/**\". */\nfunction expand(root: string, glob: string): string[] {\n const clean = glob.replace(/^\\.\\//, \"\").replace(/\\/$/, \"\");\n const star = clean.indexOf(\"*\");\n if (star === -1) return isDir(join(root, clean)) ? [clean] : [];\n const base = clean.slice(0, star).replace(/\\/$/, \"\");\n const recursive = clean.slice(star).startsWith(\"**\");\n const found: string[] = [];\n const walk = (dir: string, depth: number): void => {\n let entries;\n try {\n entries = readdirSync(join(root, dir), { withFileTypes: true });\n } catch {\n return;\n }\n for (const entry of entries) {\n if (!entry.isDirectory() || entry.name === \"node_modules\" || entry.name.startsWith(\".\")) continue;\n const child = dir === \"\" ? entry.name : `${dir}/${entry.name}`;\n found.push(child);\n if (recursive && depth < 6) walk(child, depth + 1);\n }\n };\n walk(base, 0);\n return found;\n}\n\n/** The leaf strings of an `exports` value, with their subpath keys. */\nfunction exportTargets(value: unknown, out: string[] = []): string[] {\n if (typeof value === \"string\") out.push(value);\n else if (Array.isArray(value)) for (const item of value) exportTargets(item, out);\n else if (value && typeof value === \"object\") for (const item of Object.values(value)) exportTargets(item, out);\n return out;\n}\n\n/**\n * The RegExp source of an entry target of a package. The extension can change, because\n * dependency-cruiser resolves \"./x.js\" to the source file x.ts, and \"*\" of a subpath pattern matches\n * each path.\n */\nexport function entryPattern(dir: string, target: string): string {\n const path = posix.normalize(posix.join(dir, target.replace(/^\\.\\//, \"\")));\n const stem = path.replace(/\\.d\\.[cm]?ts$|\\.[cm]?[jt]sx?$/, \"\");\n const source = stem.split(\"*\").map(escape).join(\".*\");\n // A flat list, because dependency-cruiser refuses a RegExp with nested quantifiers (safe-regex).\n return `^${source}(${EXTENSIONS})?$`;\n}\n\nconst EXTENSIONS = [\".js\", \".mjs\", \".cjs\", \".jsx\", \".ts\", \".mts\", \".cts\", \".tsx\", \".d.ts\", \".d.mts\", \".d.cts\"].map(escape).join(\"|\");\n\n/** The entries of a package.json: the files that other packages can import. */\nexport function packageEntries(dir: string, manifest: Record<string, unknown>): string[] {\n const targets = exportTargets(manifest[\"exports\"]);\n for (const field of [\"main\", \"module\", \"types\", \"typings\"]) {\n const value = manifest[field];\n if (typeof value === \"string\") targets.push(value);\n }\n if (typeof manifest[\"bin\"] === \"string\") targets.push(manifest[\"bin\"]);\n else if (manifest[\"bin\"] && typeof manifest[\"bin\"] === \"object\") targets.push(...exportTargets(manifest[\"bin\"]));\n // With no entry field, Node resolves the package to index.js.\n if (targets.length === 0 && manifest[\"exports\"] === undefined) targets.push(\"./index.js\");\n return [...new Set(targets.filter((t) => !t.endsWith(\".json\") || t === \"./package.json\").map((t) => entryPattern(dir, t)))];\n}\n\n/** The packages of the workspace in the folder `root`. */\nexport function workspacePackages(root: string, globs?: string[]): WorkspacePackage[] {\n let list = globs;\n if (!list) {\n try {\n list = workspaceGlobs(readFileSync(join(root, \"pnpm-workspace.yaml\"), \"utf8\"));\n } catch {\n list = [];\n }\n if (list.length === 0) list = [\"packages/*\"];\n }\n const excluded = list.filter((g) => g.startsWith(\"!\")).flatMap((g) => expand(root, g.slice(1)));\n const dirs = [...new Set(list.filter((g) => !g.startsWith(\"!\")).flatMap((g) => expand(root, g)))].filter((d) => !excluded.includes(d));\n const found: WorkspacePackage[] = [];\n for (const dir of dirs.sort()) {\n let manifest: Record<string, unknown>;\n try {\n manifest = JSON.parse(readFileSync(join(root, dir, \"package.json\"), \"utf8\")) as Record<string, unknown>;\n } catch {\n continue;\n }\n if (typeof manifest[\"name\"] !== \"string\") continue;\n found.push({\n name: manifest[\"name\"],\n dir,\n private: manifest[\"private\"] === true,\n entries: packageEntries(dir, manifest),\n dependencies: declaredDependencies(manifest),\n });\n }\n return found;\n}\n\n/** The options of `boundaryRules()`. */\nexport interface RuleOptions extends Pick<BoundaryOptions, \"apps\" | \"reference\" | \"scopes\"> {\n /** More declared dependencies, for example the dependencies of the root package.json. */\n dependencies?: string[];\n}\n\n/** The rules of the boundaries for a list of packages. `boundaries()` reads the list from the workspace. */\nexport function boundaryRules(packages: WorkspacePackage[], opts: RuleOptions = {}): Rule[] {\n const why = (text: string): string => (opts.reference ? `${opts.reference} ${text}` : text);\n const anyPackage = packages.map((p) => `^${escape(p.dir)}/`);\n const rules: Rule[] = [];\n for (const pkg of packages) {\n const own = `^${escape(pkg.dir)}/`;\n const others = anyPackage.filter((path) => path !== own);\n if (others.length > 0) {\n rules.push({\n name: `relative-import-out-of-${slug(pkg.name)}`,\n severity: \"error\",\n comment: why(`A relative import leaves the package ${pkg.name}. Import the other package by its name, through an entry of its package.json.`),\n from: { path: own },\n to: { path: others, pathNot: own, dependencyTypes: [\"local\"] },\n });\n }\n rules.push({\n name: `deep-import-into-${slug(pkg.name)}`,\n severity: \"error\",\n comment: why(\n `An import reaches into the folder of ${pkg.name} at a file that is not an entry of its package.json (exports, main, module, types or bin). Import an entry, or add the file to the exports of ${pkg.name}.`,\n ),\n from: { pathNot: own },\n to: pkg.entries.length > 0 ? { path: own, pathNot: pkg.entries } : { path: own },\n });\n }\n const names = packages.map((p) => escape(p.name));\n if (names.length > 0) {\n rules.push({\n name: \"not-a-declared-export\",\n severity: \"error\",\n comment: why(\"An import of a package of this workspace does not resolve. The path is not an entry of its exports, or the package is not built.\"),\n from: {},\n to: { path: `^(${names.join(\"|\")})(/|$)`, couldNotResolve: true },\n });\n }\n const scopes = workspaceScopes(packages, opts.scopes);\n if (scopes.length > 0) {\n const inScope = (name: string): boolean => scopes.some((scope) => name.startsWith(`${scope}/`));\n const declared = [...packages.flatMap((p) => p.dependencies ?? []), ...(opts.dependencies ?? [])];\n const known = [...new Set([...packages.map((p) => p.name), ...declared].filter(inScope))].sort().map(escape);\n rules.push({\n name: \"unknown-workspace-package\",\n severity: \"error\",\n comment: why(\n `An import names a package of the scope ${scopes.join(\", \")}, but the import does not resolve. The name is not a package of this workspace and not a declared dependency. Correct the name, or add the package.`,\n ),\n from: {},\n to: { path: `^(${scopes.map(escape).join(\"|\")})/`, ...(known.length > 0 ? { pathNot: `^(${known.join(\"|\")})(/|$)` } : {}), couldNotResolve: true },\n });\n }\n const apps =\n opts.apps === \"private\" ? packages.filter((p) => p.private) : packages.filter((p) => (opts.apps ?? []).includes(p.name));\n for (const app of apps) {\n rules.push({\n name: `import-of-the-app-${slug(app.name)}`,\n severity: \"error\",\n comment: why(`A package imports the app ${app.name}. An app is a leaf: no other package imports it. Move the shared code to a library package.`),\n from: { pathNot: `^${escape(app.dir)}/` },\n to: { path: `^${escape(app.dir)}/` },\n });\n }\n return rules;\n}\n\nconst slug = (name: string): string => name.replace(/^@/, \"\").replace(/[^A-Za-z0-9]+/g, \"-\");\n\n/**\n * The parser of the TypeScript source. dependency-cruiser reads TypeScript with the TypeScript\n * compiler of the repository only for TypeScript 2 to 6. With TypeScript 7 or no TypeScript, it reads\n * TypeScript with swc when @swc/core is installed. Else it reads only JavaScript (acorn): that is\n * enough for a check of built JavaScript.\n */\nexport function parserOptions(root?: string): Record<string, unknown> {\n if (!root) return {};\n const require = createRequire(join(root, \"package.json\"));\n try {\n const { version } = require(\"typescript/package.json\") as { version: string };\n // A type-only import is a boundary too. This option needs the TypeScript compiler.\n if (Number(version.split(\".\")[0]) < 7) return { tsPreCompilationDeps: true };\n } catch {\n // No TypeScript in the repository\n }\n // @swc/core from the repository, or next to this package (a peer dependency)\n for (const from of [require, createRequire(import.meta.url)]) {\n try {\n from.resolve(\"@swc/core\");\n return { parser: \"swc\" };\n } catch {\n // Not there\n }\n }\n return {};\n}\n\n/** The options of `defaultOptions()`. */\nexport interface DefaultOptionsInput {\n /** The packages of the workspace. The default is `workspacePackages(root)`. */\n packages?: WorkspacePackage[];\n /** The build folders of each package. The default is `[\"dist\", \"build\"]`. */\n buildFolders?: string[];\n}\n\n/** The RegExp sources of the paths that the analysis does not follow: node_modules and the build folders of each package. */\nexport function doNotFollowPaths(packages: Pick<WorkspacePackage, \"dir\">[], buildFolders: string[] = BUILD_FOLDERS): string[] {\n const paths = [\"(^|/)node_modules/\"];\n const dirs = packages.map((p) => p.dir).filter((dir) => dir !== \"\" && dir !== \".\");\n const folders = buildFolders.map((folder) => folder.replace(/^\\.\\//, \"\").replace(/\\/$/, \"\")).filter((folder) => folder !== \"\");\n if (dirs.length > 0 && folders.length > 0) paths.push(`^(${dirs.map(escape).join(\"|\")})/(${folders.map(escape).join(\"|\")})/`);\n return paths;\n}\n\n/**\n * The default options: the source of the packages, with type-only imports, resolved as Node resolves\n * an ESM import. There is no `includeOnly`, because it also removes the imports that do not resolve,\n * and the rule not-a-declared-export needs them. The analysis does not follow node_modules and the\n * build folders of the packages: an import of a package stops at its entry. The \"types\" condition is\n * not used: it resolves to a declaration file, and the analysis excludes declaration files, so a deep\n * import does not show. The `require` condition is not used: an ESM import does not resolve to an\n * entry that is only for `require`.\n */\nexport function defaultOptions(root?: string, input: DefaultOptionsInput = {}): Record<string, unknown> {\n const packages = input.packages ?? (root ? workspacePackages(root) : []);\n return {\n ...parserOptions(root),\n exclude: {\n path: [\"(^|/)node_modules/\", \"\\\\.(test|spec|e2e)\\\\.[cm]?[jt]sx?$\", \"\\\\.d\\\\.[cm]?ts$\", \"/(test|tests|e2e|__tests__|fixtures)/\"],\n },\n doNotFollow: { path: doNotFollowPaths(packages, input.buildFolders) },\n enhancedResolveOptions: {\n exportsFields: [\"exports\"],\n conditionNames: [\"import\", \"node\", \"default\"],\n mainFields: [\"module\", \"main\"],\n },\n skipAnalysisNotInRules: true,\n };\n}\n\n/** A rule with the reference before its comment, when the comment does not start with it. */\nfunction withReference(rule: Rule, reference?: string): Rule {\n if (!reference || rule.comment?.startsWith(reference)) return rule;\n return { ...rule, comment: rule.comment ? `${reference} ${rule.comment}` : reference };\n}\n\n/** The dependency-cruiser configuration of the boundaries for the workspace in the folder `root`. */\nexport function boundaries(root: string, opts: BoundaryOptions = {}): Config {\n const packages = workspacePackages(root, opts.packages);\n let rootManifest: Record<string, unknown> = {};\n try {\n rootManifest = JSON.parse(readFileSync(join(root, \"package.json\"), \"utf8\")) as Record<string, unknown>;\n } catch {\n // No package.json at the root\n }\n const options = { ...defaultOptions(root, { packages, ...(opts.buildFolders ? { buildFolders: opts.buildFolders } : {}) }), ...opts.options };\n const rules = boundaryRules(packages, { ...opts, dependencies: declaredDependencies(rootManifest) });\n return {\n forbidden: [...rules, ...(opts.forbidden ?? []).map((rule) => withReference(rule, opts.reference))],\n options,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA4E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AAG,KAAK,SAAS,cAAc,MAAM,KAAK,SAAS,CAAC,CAAC;EAClG;CACF;AACF"}
@@ -0,0 +1,110 @@
1
+ /** A rule of dependency-cruiser (the `forbidden` list). The package does not depend on the types of dependency-cruiser. */
2
+ export interface Rule {
3
+ name: string;
4
+ severity: "error" | "warn" | "info" | "ignore";
5
+ comment?: string;
6
+ from: Record<string, unknown>;
7
+ to: Record<string, unknown>;
8
+ }
9
+ /** A dependency-cruiser configuration. */
10
+ export interface Config {
11
+ forbidden: Rule[];
12
+ options: Record<string, unknown>;
13
+ }
14
+ /** A package of the workspace. */
15
+ export interface WorkspacePackage {
16
+ /** The name in package.json. */
17
+ name: string;
18
+ /** The folder, relative to the root, with "/". */
19
+ dir: string;
20
+ private: boolean;
21
+ /** RegExp sources of the files that other packages can import. */
22
+ entries: string[];
23
+ /** The names of the dependencies in package.json: dependencies, devDependencies, peerDependencies and optionalDependencies. */
24
+ dependencies?: string[];
25
+ }
26
+ /**
27
+ * The scopes of the rule unknown-workspace-package. A list replaces the scopes of the workspace
28
+ * packages. `add` and `remove` change that list. An empty list turns off the rule.
29
+ */
30
+ export type ScopeOptions = string[] | {
31
+ add?: string[];
32
+ remove?: string[];
33
+ };
34
+ export interface BoundaryOptions {
35
+ /**
36
+ * Globs of the package folders, for example `["packages/*"]`. The default is the `packages` list of
37
+ * pnpm-workspace.yaml, or `["packages/*"]` when the file does not exist.
38
+ */
39
+ packages?: string[];
40
+ /** The apps: the leaves of the graph, which no other package imports. "private" means each private package. */
41
+ apps?: "private" | string[];
42
+ /** A text before each comment, for example the decision record of the rules. The comments of `forbidden` get it too. */
43
+ reference?: string;
44
+ /**
45
+ * The scopes (for example "@x") in which an import that does not resolve must name a workspace
46
+ * package or a declared dependency. The default is the scopes of the workspace package names.
47
+ */
48
+ scopes?: ScopeOptions;
49
+ /**
50
+ * The build folders of each package, for example `["dist", "build"]` (the default). The analysis
51
+ * does not follow the imports of their files, and it does not start from them.
52
+ */
53
+ buildFolders?: string[];
54
+ /** More rules, after the rules of the boundaries. */
55
+ forbidden?: Rule[];
56
+ /** More options of dependency-cruiser. They replace the default options with the same key. */
57
+ options?: Record<string, unknown>;
58
+ }
59
+ /** The names of the dependencies of a package.json, from each dependency field. */
60
+ export declare function declaredDependencies(manifest: Record<string, unknown>): string[];
61
+ /** The scopes of the package names, for example "@x" for "@x/a", changed by the option `scopes`. A name with no scope gives no scope. */
62
+ export declare function workspaceScopes(packages: Pick<WorkspacePackage, "name">[], opts?: ScopeOptions): string[];
63
+ /** The `packages` list of a pnpm-workspace.yaml file. It reads only that list, with no YAML library. */
64
+ export declare function workspaceGlobs(yaml: string): string[];
65
+ /**
66
+ * The RegExp source of an entry target of a package. The extension can change, because
67
+ * dependency-cruiser resolves "./x.js" to the source file x.ts, and "*" of a subpath pattern matches
68
+ * each path.
69
+ */
70
+ export declare function entryPattern(dir: string, target: string): string;
71
+ /** The entries of a package.json: the files that other packages can import. */
72
+ export declare function packageEntries(dir: string, manifest: Record<string, unknown>): string[];
73
+ /** The packages of the workspace in the folder `root`. */
74
+ export declare function workspacePackages(root: string, globs?: string[]): WorkspacePackage[];
75
+ /** The options of `boundaryRules()`. */
76
+ export interface RuleOptions extends Pick<BoundaryOptions, "apps" | "reference" | "scopes"> {
77
+ /** More declared dependencies, for example the dependencies of the root package.json. */
78
+ dependencies?: string[];
79
+ }
80
+ /** The rules of the boundaries for a list of packages. `boundaries()` reads the list from the workspace. */
81
+ export declare function boundaryRules(packages: WorkspacePackage[], opts?: RuleOptions): Rule[];
82
+ /**
83
+ * The parser of the TypeScript source. dependency-cruiser reads TypeScript with the TypeScript
84
+ * compiler of the repository only for TypeScript 2 to 6. With TypeScript 7 or no TypeScript, it reads
85
+ * TypeScript with swc when @swc/core is installed. Else it reads only JavaScript (acorn): that is
86
+ * enough for a check of built JavaScript.
87
+ */
88
+ export declare function parserOptions(root?: string): Record<string, unknown>;
89
+ /** The options of `defaultOptions()`. */
90
+ export interface DefaultOptionsInput {
91
+ /** The packages of the workspace. The default is `workspacePackages(root)`. */
92
+ packages?: WorkspacePackage[];
93
+ /** The build folders of each package. The default is `["dist", "build"]`. */
94
+ buildFolders?: string[];
95
+ }
96
+ /** The RegExp sources of the paths that the analysis does not follow: node_modules and the build folders of each package. */
97
+ export declare function doNotFollowPaths(packages: Pick<WorkspacePackage, "dir">[], buildFolders?: string[]): string[];
98
+ /**
99
+ * The default options: the source of the packages, with type-only imports, resolved as Node resolves
100
+ * an ESM import. There is no `includeOnly`, because it also removes the imports that do not resolve,
101
+ * and the rule not-a-declared-export needs them. The analysis does not follow node_modules and the
102
+ * build folders of the packages: an import of a package stops at its entry. The "types" condition is
103
+ * not used: it resolves to a declaration file, and the analysis excludes declaration files, so a deep
104
+ * import does not show. The `require` condition is not used: an ESM import does not resolve to an
105
+ * entry that is only for `require`.
106
+ */
107
+ export declare function defaultOptions(root?: string, input?: DefaultOptionsInput): Record<string, unknown>;
108
+ /** The dependency-cruiser configuration of the boundaries for the workspace in the folder `root`. */
109
+ export declare function boundaries(root: string, opts?: BoundaryOptions): Config;
110
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";iBAiBiB;EACf;EACA;EACA;EACA,MAAM;EACN,IAAI;;;iBAIW;EACf,WAAW;EACX,SAAS;;;iBAIM;;EAEf;;EAEA;EACA;;EAEA;;EAEA;;;;;;YAOU;EAA4B;EAAgB;;iBAEvC;;;;;EAKf;;EAEA;;EAEA;;;;;EAKA,SAAS;;;;;EAKT;;EAEA,YAAY;;EAEZ,UAAU;;;wBAWI,qBAAqB,UAAU;;wBAU/B,gBAAgB,UAAU,KAAK,6BAA6B,OAAM;;wBAUlE,eAAe;;;;;;wBAqEf,aAAa,aAAa;;wBAW1B,eAAe,aAAa,UAAU;;wBActC,kBAAkB,cAAc,mBAAmB;;iBAiClD,oBAAoB,KAAK;;EAExC;;;wBAIc,cAAc,UAAU,oBAAoB,OAAM,cAAmB;;;;;;;wBAyErE,cAAc,gBAAgB;;iBAuB7B;;EAEf,WAAW;;EAEX;;;wBAIc,iBAAiB,UAAU,KAAK,4BAA4B;;;;;;;;;;wBAiB5D,eAAe,eAAe,QAAO,sBAA2B;;wBAwBhE,WAAW,cAAc,OAAM,kBAAuB"}
@@ -0,0 +1,110 @@
1
+ /** A rule of dependency-cruiser (the `forbidden` list). The package does not depend on the types of dependency-cruiser. */
2
+ export interface Rule {
3
+ name: string;
4
+ severity: "error" | "warn" | "info" | "ignore";
5
+ comment?: string;
6
+ from: Record<string, unknown>;
7
+ to: Record<string, unknown>;
8
+ }
9
+ /** A dependency-cruiser configuration. */
10
+ export interface Config {
11
+ forbidden: Rule[];
12
+ options: Record<string, unknown>;
13
+ }
14
+ /** A package of the workspace. */
15
+ export interface WorkspacePackage {
16
+ /** The name in package.json. */
17
+ name: string;
18
+ /** The folder, relative to the root, with "/". */
19
+ dir: string;
20
+ private: boolean;
21
+ /** RegExp sources of the files that other packages can import. */
22
+ entries: string[];
23
+ /** The names of the dependencies in package.json: dependencies, devDependencies, peerDependencies and optionalDependencies. */
24
+ dependencies?: string[];
25
+ }
26
+ /**
27
+ * The scopes of the rule unknown-workspace-package. A list replaces the scopes of the workspace
28
+ * packages. `add` and `remove` change that list. An empty list turns off the rule.
29
+ */
30
+ export type ScopeOptions = string[] | {
31
+ add?: string[];
32
+ remove?: string[];
33
+ };
34
+ export interface BoundaryOptions {
35
+ /**
36
+ * Globs of the package folders, for example `["packages/*"]`. The default is the `packages` list of
37
+ * pnpm-workspace.yaml, or `["packages/*"]` when the file does not exist.
38
+ */
39
+ packages?: string[];
40
+ /** The apps: the leaves of the graph, which no other package imports. "private" means each private package. */
41
+ apps?: "private" | string[];
42
+ /** A text before each comment, for example the decision record of the rules. The comments of `forbidden` get it too. */
43
+ reference?: string;
44
+ /**
45
+ * The scopes (for example "@x") in which an import that does not resolve must name a workspace
46
+ * package or a declared dependency. The default is the scopes of the workspace package names.
47
+ */
48
+ scopes?: ScopeOptions;
49
+ /**
50
+ * The build folders of each package, for example `["dist", "build"]` (the default). The analysis
51
+ * does not follow the imports of their files, and it does not start from them.
52
+ */
53
+ buildFolders?: string[];
54
+ /** More rules, after the rules of the boundaries. */
55
+ forbidden?: Rule[];
56
+ /** More options of dependency-cruiser. They replace the default options with the same key. */
57
+ options?: Record<string, unknown>;
58
+ }
59
+ /** The names of the dependencies of a package.json, from each dependency field. */
60
+ export declare function declaredDependencies(manifest: Record<string, unknown>): string[];
61
+ /** The scopes of the package names, for example "@x" for "@x/a", changed by the option `scopes`. A name with no scope gives no scope. */
62
+ export declare function workspaceScopes(packages: Pick<WorkspacePackage, "name">[], opts?: ScopeOptions): string[];
63
+ /** The `packages` list of a pnpm-workspace.yaml file. It reads only that list, with no YAML library. */
64
+ export declare function workspaceGlobs(yaml: string): string[];
65
+ /**
66
+ * The RegExp source of an entry target of a package. The extension can change, because
67
+ * dependency-cruiser resolves "./x.js" to the source file x.ts, and "*" of a subpath pattern matches
68
+ * each path.
69
+ */
70
+ export declare function entryPattern(dir: string, target: string): string;
71
+ /** The entries of a package.json: the files that other packages can import. */
72
+ export declare function packageEntries(dir: string, manifest: Record<string, unknown>): string[];
73
+ /** The packages of the workspace in the folder `root`. */
74
+ export declare function workspacePackages(root: string, globs?: string[]): WorkspacePackage[];
75
+ /** The options of `boundaryRules()`. */
76
+ export interface RuleOptions extends Pick<BoundaryOptions, "apps" | "reference" | "scopes"> {
77
+ /** More declared dependencies, for example the dependencies of the root package.json. */
78
+ dependencies?: string[];
79
+ }
80
+ /** The rules of the boundaries for a list of packages. `boundaries()` reads the list from the workspace. */
81
+ export declare function boundaryRules(packages: WorkspacePackage[], opts?: RuleOptions): Rule[];
82
+ /**
83
+ * The parser of the TypeScript source. dependency-cruiser reads TypeScript with the TypeScript
84
+ * compiler of the repository only for TypeScript 2 to 6. With TypeScript 7 or no TypeScript, it reads
85
+ * TypeScript with swc when @swc/core is installed. Else it reads only JavaScript (acorn): that is
86
+ * enough for a check of built JavaScript.
87
+ */
88
+ export declare function parserOptions(root?: string): Record<string, unknown>;
89
+ /** The options of `defaultOptions()`. */
90
+ export interface DefaultOptionsInput {
91
+ /** The packages of the workspace. The default is `workspacePackages(root)`. */
92
+ packages?: WorkspacePackage[];
93
+ /** The build folders of each package. The default is `["dist", "build"]`. */
94
+ buildFolders?: string[];
95
+ }
96
+ /** The RegExp sources of the paths that the analysis does not follow: node_modules and the build folders of each package. */
97
+ export declare function doNotFollowPaths(packages: Pick<WorkspacePackage, "dir">[], buildFolders?: string[]): string[];
98
+ /**
99
+ * The default options: the source of the packages, with type-only imports, resolved as Node resolves
100
+ * an ESM import. There is no `includeOnly`, because it also removes the imports that do not resolve,
101
+ * and the rule not-a-declared-export needs them. The analysis does not follow node_modules and the
102
+ * build folders of the packages: an import of a package stops at its entry. The "types" condition is
103
+ * not used: it resolves to a declaration file, and the analysis excludes declaration files, so a deep
104
+ * import does not show. The `require` condition is not used: an ESM import does not resolve to an
105
+ * entry that is only for `require`.
106
+ */
107
+ export declare function defaultOptions(root?: string, input?: DefaultOptionsInput): Record<string, unknown>;
108
+ /** The dependency-cruiser configuration of the boundaries for the workspace in the folder `root`. */
109
+ export declare function boundaries(root: string, opts?: BoundaryOptions): Config;
110
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";iBAiBiB;EACf;EACA;EACA;EACA,MAAM;EACN,IAAI;;;iBAIW;EACf,WAAW;EACX,SAAS;;;iBAIM;;EAEf;;EAEA;EACA;;EAEA;;EAEA;;;;;;YAOU;EAA4B;EAAgB;;iBAEvC;;;;;EAKf;;EAEA;;EAEA;;;;;EAKA,SAAS;;;;;EAKT;;EAEA,YAAY;;EAEZ,UAAU;;;wBAWI,qBAAqB,UAAU;;wBAU/B,gBAAgB,UAAU,KAAK,6BAA6B,OAAM;;wBAUlE,eAAe;;;;;;wBAqEf,aAAa,aAAa;;wBAW1B,eAAe,aAAa,UAAU;;wBActC,kBAAkB,cAAc,mBAAmB;;iBAiClD,oBAAoB,KAAK;;EAExC;;;wBAIc,cAAc,UAAU,oBAAoB,OAAM,cAAmB;;;;;;;wBAyErE,cAAc,gBAAgB;;iBAuB7B;;EAEf,WAAW;;EAEX;;;wBAIc,iBAAiB,UAAU,KAAK,4BAA4B;;;;;;;;;;wBAiB5D,eAAe,eAAe,QAAO,sBAA2B;;wBAwBhE,WAAW,cAAc,OAAM,kBAAuB"}
package/build/index.js ADDED
@@ -0,0 +1,334 @@
1
+ import { createRequire } from "node:module";
2
+ import { readFileSync, readdirSync, statSync } from "node:fs";
3
+ import { join, posix } from "node:path";
4
+ // src/index.ts
5
+ /**
6
+ * The import boundaries of a workspace, as a dependency-cruiser configuration. Each package is a
7
+ * unit. Another package imports it only through an entry of its package.json (`exports`, `main`,
8
+ * `module`, `types`, `bin`). A relative path or a deep path into its folder is not an entry.
9
+ *
10
+ * A repository uses it from its `.dependency-cruiser.cjs`:
11
+ *
12
+ * ```js
13
+ * const { boundaries } = require("@mark1russell7/boundaries");
14
+ * module.exports = boundaries(__dirname, { apps: "private" });
15
+ * ```
16
+ */
17
+ const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
18
+ /** The default build folders of a package. */
19
+ const BUILD_FOLDERS = ["dist", "build"];
20
+ const DEPENDENCY_FIELDS = [
21
+ "dependencies",
22
+ "devDependencies",
23
+ "peerDependencies",
24
+ "optionalDependencies"
25
+ ];
26
+ /** The names of the dependencies of a package.json, from each dependency field. */
27
+ function declaredDependencies(manifest) {
28
+ const names = /* @__PURE__ */ new Set();
29
+ for (const field of DEPENDENCY_FIELDS) {
30
+ const value = manifest[field];
31
+ if (value && typeof value === "object" && !Array.isArray(value)) for (const name of Object.keys(value)) names.add(name);
32
+ }
33
+ return [...names].sort();
34
+ }
35
+ /** The scopes of the package names, for example "@x" for "@x/a", changed by the option `scopes`. A name with no scope gives no scope. */
36
+ function workspaceScopes(packages, opts = {}) {
37
+ const normal = (scope) => (scope.startsWith("@") ? scope : `@${scope}`).replace(/\/$/, "");
38
+ if (Array.isArray(opts)) return [...new Set(opts.map(normal))].sort();
39
+ const scopes = new Set(packages.filter((p) => p.name.startsWith("@") && p.name.includes("/")).map((p) => p.name.slice(0, p.name.indexOf("/"))));
40
+ for (const scope of opts.add ?? []) scopes.add(normal(scope));
41
+ for (const scope of opts.remove ?? []) scopes.delete(normal(scope));
42
+ return [...scopes].sort();
43
+ }
44
+ /** The `packages` list of a pnpm-workspace.yaml file. It reads only that list, with no YAML library. */
45
+ function workspaceGlobs(yaml) {
46
+ const globs = [];
47
+ let inList = false;
48
+ for (const raw of yaml.split(/\r?\n/)) {
49
+ const hash = raw.indexOf(" #");
50
+ const line = (hash === -1 ? raw : raw.slice(0, hash)).trimEnd();
51
+ const trimmed = line.trimStart();
52
+ if (trimmed === "" || trimmed.startsWith("#")) continue;
53
+ if (/^packages\s*:/.test(line)) {
54
+ inList = true;
55
+ continue;
56
+ }
57
+ if (!inList) continue;
58
+ if (trimmed === line) break;
59
+ if (!trimmed.startsWith("-")) continue;
60
+ const item = trimmed.slice(1).trim().replace(/^["']/, "").replace(/["']$/, "");
61
+ if (item) globs.push(item);
62
+ }
63
+ return globs;
64
+ }
65
+ function isDir(path) {
66
+ try {
67
+ return statSync(path).isDirectory();
68
+ } catch {
69
+ return false;
70
+ }
71
+ }
72
+ /** The folders that a glob of pnpm-workspace.yaml gives: "a/b", "a/*" and "a/**". */
73
+ function expand(root, glob) {
74
+ const clean = glob.replace(/^\.\//, "").replace(/\/$/, "");
75
+ const star = clean.indexOf("*");
76
+ if (star === -1) return isDir(join(root, clean)) ? [clean] : [];
77
+ const base = clean.slice(0, star).replace(/\/$/, "");
78
+ const recursive = clean.slice(star).startsWith("**");
79
+ const found = [];
80
+ const walk = (dir, depth) => {
81
+ let entries;
82
+ try {
83
+ entries = readdirSync(join(root, dir), { withFileTypes: true });
84
+ } catch {
85
+ return;
86
+ }
87
+ for (const entry of entries) {
88
+ if (!entry.isDirectory() || entry.name === "node_modules" || entry.name.startsWith(".")) continue;
89
+ const child = dir === "" ? entry.name : `${dir}/${entry.name}`;
90
+ found.push(child);
91
+ if (recursive && depth < 6) walk(child, depth + 1);
92
+ }
93
+ };
94
+ walk(base, 0);
95
+ return found;
96
+ }
97
+ /** The leaf strings of an `exports` value, with their subpath keys. */
98
+ function exportTargets(value, out = []) {
99
+ if (typeof value === "string") out.push(value);
100
+ else if (Array.isArray(value)) for (const item of value) exportTargets(item, out);
101
+ else if (value && typeof value === "object") for (const item of Object.values(value)) exportTargets(item, out);
102
+ return out;
103
+ }
104
+ /**
105
+ * The RegExp source of an entry target of a package. The extension can change, because
106
+ * dependency-cruiser resolves "./x.js" to the source file x.ts, and "*" of a subpath pattern matches
107
+ * each path.
108
+ */
109
+ function entryPattern(dir, target) {
110
+ return `^${posix.normalize(posix.join(dir, target.replace(/^\.\//, ""))).replace(/\.d\.[cm]?ts$|\.[cm]?[jt]sx?$/, "").split("*").map(escape).join(".*")}(${EXTENSIONS})?$`;
111
+ }
112
+ const EXTENSIONS = [
113
+ ".js",
114
+ ".mjs",
115
+ ".cjs",
116
+ ".jsx",
117
+ ".ts",
118
+ ".mts",
119
+ ".cts",
120
+ ".tsx",
121
+ ".d.ts",
122
+ ".d.mts",
123
+ ".d.cts"
124
+ ].map(escape).join("|");
125
+ /** The entries of a package.json: the files that other packages can import. */
126
+ function packageEntries(dir, manifest) {
127
+ const targets = exportTargets(manifest["exports"]);
128
+ for (const field of [
129
+ "main",
130
+ "module",
131
+ "types",
132
+ "typings"
133
+ ]) {
134
+ const value = manifest[field];
135
+ if (typeof value === "string") targets.push(value);
136
+ }
137
+ if (typeof manifest["bin"] === "string") targets.push(manifest["bin"]);
138
+ else if (manifest["bin"] && typeof manifest["bin"] === "object") targets.push(...exportTargets(manifest["bin"]));
139
+ if (targets.length === 0 && manifest["exports"] === void 0) targets.push("./index.js");
140
+ return [...new Set(targets.filter((t) => !t.endsWith(".json") || t === "./package.json").map((t) => entryPattern(dir, t)))];
141
+ }
142
+ /** The packages of the workspace in the folder `root`. */
143
+ function workspacePackages(root, globs) {
144
+ let list = globs;
145
+ if (!list) {
146
+ try {
147
+ list = workspaceGlobs(readFileSync(join(root, "pnpm-workspace.yaml"), "utf8"));
148
+ } catch {
149
+ list = [];
150
+ }
151
+ if (list.length === 0) list = ["packages/*"];
152
+ }
153
+ const excluded = list.filter((g) => g.startsWith("!")).flatMap((g) => expand(root, g.slice(1)));
154
+ const dirs = [...new Set(list.filter((g) => !g.startsWith("!")).flatMap((g) => expand(root, g)))].filter((d) => !excluded.includes(d));
155
+ const found = [];
156
+ for (const dir of dirs.sort()) {
157
+ let manifest;
158
+ try {
159
+ manifest = JSON.parse(readFileSync(join(root, dir, "package.json"), "utf8"));
160
+ } catch {
161
+ continue;
162
+ }
163
+ if (typeof manifest["name"] !== "string") continue;
164
+ found.push({
165
+ name: manifest["name"],
166
+ dir,
167
+ private: manifest["private"] === true,
168
+ entries: packageEntries(dir, manifest),
169
+ dependencies: declaredDependencies(manifest)
170
+ });
171
+ }
172
+ return found;
173
+ }
174
+ /** The rules of the boundaries for a list of packages. `boundaries()` reads the list from the workspace. */
175
+ function boundaryRules(packages, opts = {}) {
176
+ const why = (text) => opts.reference ? `${opts.reference} ${text}` : text;
177
+ const anyPackage = packages.map((p) => `^${escape(p.dir)}/`);
178
+ const rules = [];
179
+ for (const pkg of packages) {
180
+ const own = `^${escape(pkg.dir)}/`;
181
+ const others = anyPackage.filter((path) => path !== own);
182
+ if (others.length > 0) rules.push({
183
+ name: `relative-import-out-of-${slug(pkg.name)}`,
184
+ severity: "error",
185
+ comment: why(`A relative import leaves the package ${pkg.name}. Import the other package by its name, through an entry of its package.json.`),
186
+ from: { path: own },
187
+ to: {
188
+ path: others,
189
+ pathNot: own,
190
+ dependencyTypes: ["local"]
191
+ }
192
+ });
193
+ rules.push({
194
+ name: `deep-import-into-${slug(pkg.name)}`,
195
+ severity: "error",
196
+ comment: why(`An import reaches into the folder of ${pkg.name} at a file that is not an entry of its package.json (exports, main, module, types or bin). Import an entry, or add the file to the exports of ${pkg.name}.`),
197
+ from: { pathNot: own },
198
+ to: pkg.entries.length > 0 ? {
199
+ path: own,
200
+ pathNot: pkg.entries
201
+ } : { path: own }
202
+ });
203
+ }
204
+ const names = packages.map((p) => escape(p.name));
205
+ if (names.length > 0) rules.push({
206
+ name: "not-a-declared-export",
207
+ severity: "error",
208
+ comment: why("An import of a package of this workspace does not resolve. The path is not an entry of its exports, or the package is not built."),
209
+ from: {},
210
+ to: {
211
+ path: `^(${names.join("|")})(/|$)`,
212
+ couldNotResolve: true
213
+ }
214
+ });
215
+ const scopes = workspaceScopes(packages, opts.scopes);
216
+ if (scopes.length > 0) {
217
+ const inScope = (name) => scopes.some((scope) => name.startsWith(`${scope}/`));
218
+ const declared = [...packages.flatMap((p) => p.dependencies ?? []), ...opts.dependencies ?? []];
219
+ const known = [...new Set([...packages.map((p) => p.name), ...declared].filter(inScope))].sort().map(escape);
220
+ rules.push({
221
+ name: "unknown-workspace-package",
222
+ severity: "error",
223
+ comment: why(`An import names a package of the scope ${scopes.join(", ")}, but the import does not resolve. The name is not a package of this workspace and not a declared dependency. Correct the name, or add the package.`),
224
+ from: {},
225
+ to: {
226
+ path: `^(${scopes.map(escape).join("|")})/`,
227
+ ...known.length > 0 ? { pathNot: `^(${known.join("|")})(/|$)` } : {},
228
+ couldNotResolve: true
229
+ }
230
+ });
231
+ }
232
+ const apps = opts.apps === "private" ? packages.filter((p) => p.private) : packages.filter((p) => (opts.apps ?? []).includes(p.name));
233
+ for (const app of apps) rules.push({
234
+ name: `import-of-the-app-${slug(app.name)}`,
235
+ severity: "error",
236
+ comment: why(`A package imports the app ${app.name}. An app is a leaf: no other package imports it. Move the shared code to a library package.`),
237
+ from: { pathNot: `^${escape(app.dir)}/` },
238
+ to: { path: `^${escape(app.dir)}/` }
239
+ });
240
+ return rules;
241
+ }
242
+ const slug = (name) => name.replace(/^@/, "").replace(/[^A-Za-z0-9]+/g, "-");
243
+ /**
244
+ * The parser of the TypeScript source. dependency-cruiser reads TypeScript with the TypeScript
245
+ * compiler of the repository only for TypeScript 2 to 6. With TypeScript 7 or no TypeScript, it reads
246
+ * TypeScript with swc when @swc/core is installed. Else it reads only JavaScript (acorn): that is
247
+ * enough for a check of built JavaScript.
248
+ */
249
+ function parserOptions(root) {
250
+ if (!root) return {};
251
+ const require = createRequire(join(root, "package.json"));
252
+ try {
253
+ const { version } = require("typescript/package.json");
254
+ if (Number(version.split(".")[0]) < 7) return { tsPreCompilationDeps: true };
255
+ } catch {}
256
+ for (const from of [require, createRequire(import.meta.url)]) try {
257
+ from.resolve("@swc/core");
258
+ return { parser: "swc" };
259
+ } catch {}
260
+ return {};
261
+ }
262
+ /** The RegExp sources of the paths that the analysis does not follow: node_modules and the build folders of each package. */
263
+ function doNotFollowPaths(packages, buildFolders = BUILD_FOLDERS) {
264
+ const paths = ["(^|/)node_modules/"];
265
+ const dirs = packages.map((p) => p.dir).filter((dir) => dir !== "" && dir !== ".");
266
+ const folders = buildFolders.map((folder) => folder.replace(/^\.\//, "").replace(/\/$/, "")).filter((folder) => folder !== "");
267
+ if (dirs.length > 0 && folders.length > 0) paths.push(`^(${dirs.map(escape).join("|")})/(${folders.map(escape).join("|")})/`);
268
+ return paths;
269
+ }
270
+ /**
271
+ * The default options: the source of the packages, with type-only imports, resolved as Node resolves
272
+ * an ESM import. There is no `includeOnly`, because it also removes the imports that do not resolve,
273
+ * and the rule not-a-declared-export needs them. The analysis does not follow node_modules and the
274
+ * build folders of the packages: an import of a package stops at its entry. The "types" condition is
275
+ * not used: it resolves to a declaration file, and the analysis excludes declaration files, so a deep
276
+ * import does not show. The `require` condition is not used: an ESM import does not resolve to an
277
+ * entry that is only for `require`.
278
+ */
279
+ function defaultOptions(root, input = {}) {
280
+ const packages = input.packages ?? (root ? workspacePackages(root) : []);
281
+ return {
282
+ ...parserOptions(root),
283
+ exclude: { path: [
284
+ "(^|/)node_modules/",
285
+ "\\.(test|spec|e2e)\\.[cm]?[jt]sx?$",
286
+ "\\.d\\.[cm]?ts$",
287
+ "/(test|tests|e2e|__tests__|fixtures)/"
288
+ ] },
289
+ doNotFollow: { path: doNotFollowPaths(packages, input.buildFolders) },
290
+ enhancedResolveOptions: {
291
+ exportsFields: ["exports"],
292
+ conditionNames: [
293
+ "import",
294
+ "node",
295
+ "default"
296
+ ],
297
+ mainFields: ["module", "main"]
298
+ },
299
+ skipAnalysisNotInRules: true
300
+ };
301
+ }
302
+ /** A rule with the reference before its comment, when the comment does not start with it. */
303
+ function withReference(rule, reference) {
304
+ if (!reference || rule.comment?.startsWith(reference)) return rule;
305
+ return {
306
+ ...rule,
307
+ comment: rule.comment ? `${reference} ${rule.comment}` : reference
308
+ };
309
+ }
310
+ /** The dependency-cruiser configuration of the boundaries for the workspace in the folder `root`. */
311
+ function boundaries(root, opts = {}) {
312
+ const packages = workspacePackages(root, opts.packages);
313
+ let rootManifest = {};
314
+ try {
315
+ rootManifest = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
316
+ } catch {}
317
+ const options = {
318
+ ...defaultOptions(root, {
319
+ packages,
320
+ ...opts.buildFolders ? { buildFolders: opts.buildFolders } : {}
321
+ }),
322
+ ...opts.options
323
+ };
324
+ return {
325
+ forbidden: [...boundaryRules(packages, {
326
+ ...opts,
327
+ dependencies: declaredDependencies(rootManifest)
328
+ }), ...(opts.forbidden ?? []).map((rule) => withReference(rule, opts.reference))],
329
+ options
330
+ };
331
+ }
332
+ export { boundaries, boundaryRules, declaredDependencies, defaultOptions, doNotFollowPaths, entryPattern, packageEntries, parserOptions, workspaceGlobs, workspacePackages, workspaceScopes };
333
+
334
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * The import boundaries of a workspace, as a dependency-cruiser configuration. Each package is a\n * unit. Another package imports it only through an entry of its package.json (`exports`, `main`,\n * `module`, `types`, `bin`). A relative path or a deep path into its folder is not an entry.\n *\n * A repository uses it from its `.dependency-cruiser.cjs`:\n *\n * ```js\n * const { boundaries } = require(\"@mark1russell7/boundaries\");\n * module.exports = boundaries(__dirname, { apps: \"private\" });\n * ```\n */\nimport { readdirSync, readFileSync, statSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { join, posix } from \"node:path\";\n\n/** A rule of dependency-cruiser (the `forbidden` list). The package does not depend on the types of dependency-cruiser. */\nexport interface Rule {\n name: string;\n severity: \"error\" | \"warn\" | \"info\" | \"ignore\";\n comment?: string;\n from: Record<string, unknown>;\n to: Record<string, unknown>;\n}\n\n/** A dependency-cruiser configuration. */\nexport interface Config {\n forbidden: Rule[];\n options: Record<string, unknown>;\n}\n\n/** A package of the workspace. */\nexport interface WorkspacePackage {\n /** The name in package.json. */\n name: string;\n /** The folder, relative to the root, with \"/\". */\n dir: string;\n private: boolean;\n /** RegExp sources of the files that other packages can import. */\n entries: string[];\n /** The names of the dependencies in package.json: dependencies, devDependencies, peerDependencies and optionalDependencies. */\n dependencies?: string[];\n}\n\n/**\n * The scopes of the rule unknown-workspace-package. A list replaces the scopes of the workspace\n * packages. `add` and `remove` change that list. An empty list turns off the rule.\n */\nexport type ScopeOptions = string[] | { add?: string[]; remove?: string[] };\n\nexport interface BoundaryOptions {\n /**\n * Globs of the package folders, for example `[\"packages/*\"]`. The default is the `packages` list of\n * pnpm-workspace.yaml, or `[\"packages/*\"]` when the file does not exist.\n */\n packages?: string[];\n /** The apps: the leaves of the graph, which no other package imports. \"private\" means each private package. */\n apps?: \"private\" | string[];\n /** A text before each comment, for example the decision record of the rules. The comments of `forbidden` get it too. */\n reference?: string;\n /**\n * The scopes (for example \"@x\") in which an import that does not resolve must name a workspace\n * package or a declared dependency. The default is the scopes of the workspace package names.\n */\n scopes?: ScopeOptions;\n /**\n * The build folders of each package, for example `[\"dist\", \"build\"]` (the default). The analysis\n * does not follow the imports of their files, and it does not start from them.\n */\n buildFolders?: string[];\n /** More rules, after the rules of the boundaries. */\n forbidden?: Rule[];\n /** More options of dependency-cruiser. They replace the default options with the same key. */\n options?: Record<string, unknown>;\n}\n\nconst escape = (text: string): string => text.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\n/** The default build folders of a package. */\nconst BUILD_FOLDERS = [\"dist\", \"build\"];\n\nconst DEPENDENCY_FIELDS = [\"dependencies\", \"devDependencies\", \"peerDependencies\", \"optionalDependencies\"];\n\n/** The names of the dependencies of a package.json, from each dependency field. */\nexport function declaredDependencies(manifest: Record<string, unknown>): string[] {\n const names = new Set<string>();\n for (const field of DEPENDENCY_FIELDS) {\n const value = manifest[field];\n if (value && typeof value === \"object\" && !Array.isArray(value)) for (const name of Object.keys(value)) names.add(name);\n }\n return [...names].sort();\n}\n\n/** The scopes of the package names, for example \"@x\" for \"@x/a\", changed by the option `scopes`. A name with no scope gives no scope. */\nexport function workspaceScopes(packages: Pick<WorkspacePackage, \"name\">[], opts: ScopeOptions = {}): string[] {\n const normal = (scope: string): string => (scope.startsWith(\"@\") ? scope : `@${scope}`).replace(/\\/$/, \"\");\n if (Array.isArray(opts)) return [...new Set(opts.map(normal))].sort();\n const scopes = new Set(packages.filter((p) => p.name.startsWith(\"@\") && p.name.includes(\"/\")).map((p) => p.name.slice(0, p.name.indexOf(\"/\"))));\n for (const scope of opts.add ?? []) scopes.add(normal(scope));\n for (const scope of opts.remove ?? []) scopes.delete(normal(scope));\n return [...scopes].sort();\n}\n\n/** The `packages` list of a pnpm-workspace.yaml file. It reads only that list, with no YAML library. */\nexport function workspaceGlobs(yaml: string): string[] {\n const globs: string[] = [];\n let inList = false;\n // String operations, not one large RegExp: a RegExp with nested whitespace groups can be slow on some input.\n for (const raw of yaml.split(/\\r?\\n/)) {\n const hash = raw.indexOf(\" #\");\n const line = (hash === -1 ? raw : raw.slice(0, hash)).trimEnd();\n const trimmed = line.trimStart();\n if (trimmed === \"\" || trimmed.startsWith(\"#\")) continue;\n if (/^packages\\s*:/.test(line)) {\n inList = true;\n continue;\n }\n if (!inList) continue;\n if (trimmed === line) break;\n if (!trimmed.startsWith(\"-\")) continue;\n const item = trimmed.slice(1).trim().replace(/^[\"']/, \"\").replace(/[\"']$/, \"\");\n if (item) globs.push(item);\n }\n return globs;\n}\n\nfunction isDir(path: string): boolean {\n try {\n return statSync(path).isDirectory();\n } catch {\n return false;\n }\n}\n\n/** The folders that a glob of pnpm-workspace.yaml gives: \"a/b\", \"a/*\" and \"a/**\". */\nfunction expand(root: string, glob: string): string[] {\n const clean = glob.replace(/^\\.\\//, \"\").replace(/\\/$/, \"\");\n const star = clean.indexOf(\"*\");\n if (star === -1) return isDir(join(root, clean)) ? [clean] : [];\n const base = clean.slice(0, star).replace(/\\/$/, \"\");\n const recursive = clean.slice(star).startsWith(\"**\");\n const found: string[] = [];\n const walk = (dir: string, depth: number): void => {\n let entries;\n try {\n entries = readdirSync(join(root, dir), { withFileTypes: true });\n } catch {\n return;\n }\n for (const entry of entries) {\n if (!entry.isDirectory() || entry.name === \"node_modules\" || entry.name.startsWith(\".\")) continue;\n const child = dir === \"\" ? entry.name : `${dir}/${entry.name}`;\n found.push(child);\n if (recursive && depth < 6) walk(child, depth + 1);\n }\n };\n walk(base, 0);\n return found;\n}\n\n/** The leaf strings of an `exports` value, with their subpath keys. */\nfunction exportTargets(value: unknown, out: string[] = []): string[] {\n if (typeof value === \"string\") out.push(value);\n else if (Array.isArray(value)) for (const item of value) exportTargets(item, out);\n else if (value && typeof value === \"object\") for (const item of Object.values(value)) exportTargets(item, out);\n return out;\n}\n\n/**\n * The RegExp source of an entry target of a package. The extension can change, because\n * dependency-cruiser resolves \"./x.js\" to the source file x.ts, and \"*\" of a subpath pattern matches\n * each path.\n */\nexport function entryPattern(dir: string, target: string): string {\n const path = posix.normalize(posix.join(dir, target.replace(/^\\.\\//, \"\")));\n const stem = path.replace(/\\.d\\.[cm]?ts$|\\.[cm]?[jt]sx?$/, \"\");\n const source = stem.split(\"*\").map(escape).join(\".*\");\n // A flat list, because dependency-cruiser refuses a RegExp with nested quantifiers (safe-regex).\n return `^${source}(${EXTENSIONS})?$`;\n}\n\nconst EXTENSIONS = [\".js\", \".mjs\", \".cjs\", \".jsx\", \".ts\", \".mts\", \".cts\", \".tsx\", \".d.ts\", \".d.mts\", \".d.cts\"].map(escape).join(\"|\");\n\n/** The entries of a package.json: the files that other packages can import. */\nexport function packageEntries(dir: string, manifest: Record<string, unknown>): string[] {\n const targets = exportTargets(manifest[\"exports\"]);\n for (const field of [\"main\", \"module\", \"types\", \"typings\"]) {\n const value = manifest[field];\n if (typeof value === \"string\") targets.push(value);\n }\n if (typeof manifest[\"bin\"] === \"string\") targets.push(manifest[\"bin\"]);\n else if (manifest[\"bin\"] && typeof manifest[\"bin\"] === \"object\") targets.push(...exportTargets(manifest[\"bin\"]));\n // With no entry field, Node resolves the package to index.js.\n if (targets.length === 0 && manifest[\"exports\"] === undefined) targets.push(\"./index.js\");\n return [...new Set(targets.filter((t) => !t.endsWith(\".json\") || t === \"./package.json\").map((t) => entryPattern(dir, t)))];\n}\n\n/** The packages of the workspace in the folder `root`. */\nexport function workspacePackages(root: string, globs?: string[]): WorkspacePackage[] {\n let list = globs;\n if (!list) {\n try {\n list = workspaceGlobs(readFileSync(join(root, \"pnpm-workspace.yaml\"), \"utf8\"));\n } catch {\n list = [];\n }\n if (list.length === 0) list = [\"packages/*\"];\n }\n const excluded = list.filter((g) => g.startsWith(\"!\")).flatMap((g) => expand(root, g.slice(1)));\n const dirs = [...new Set(list.filter((g) => !g.startsWith(\"!\")).flatMap((g) => expand(root, g)))].filter((d) => !excluded.includes(d));\n const found: WorkspacePackage[] = [];\n for (const dir of dirs.sort()) {\n let manifest: Record<string, unknown>;\n try {\n manifest = JSON.parse(readFileSync(join(root, dir, \"package.json\"), \"utf8\")) as Record<string, unknown>;\n } catch {\n continue;\n }\n if (typeof manifest[\"name\"] !== \"string\") continue;\n found.push({\n name: manifest[\"name\"],\n dir,\n private: manifest[\"private\"] === true,\n entries: packageEntries(dir, manifest),\n dependencies: declaredDependencies(manifest),\n });\n }\n return found;\n}\n\n/** The options of `boundaryRules()`. */\nexport interface RuleOptions extends Pick<BoundaryOptions, \"apps\" | \"reference\" | \"scopes\"> {\n /** More declared dependencies, for example the dependencies of the root package.json. */\n dependencies?: string[];\n}\n\n/** The rules of the boundaries for a list of packages. `boundaries()` reads the list from the workspace. */\nexport function boundaryRules(packages: WorkspacePackage[], opts: RuleOptions = {}): Rule[] {\n const why = (text: string): string => (opts.reference ? `${opts.reference} ${text}` : text);\n const anyPackage = packages.map((p) => `^${escape(p.dir)}/`);\n const rules: Rule[] = [];\n for (const pkg of packages) {\n const own = `^${escape(pkg.dir)}/`;\n const others = anyPackage.filter((path) => path !== own);\n if (others.length > 0) {\n rules.push({\n name: `relative-import-out-of-${slug(pkg.name)}`,\n severity: \"error\",\n comment: why(`A relative import leaves the package ${pkg.name}. Import the other package by its name, through an entry of its package.json.`),\n from: { path: own },\n to: { path: others, pathNot: own, dependencyTypes: [\"local\"] },\n });\n }\n rules.push({\n name: `deep-import-into-${slug(pkg.name)}`,\n severity: \"error\",\n comment: why(\n `An import reaches into the folder of ${pkg.name} at a file that is not an entry of its package.json (exports, main, module, types or bin). Import an entry, or add the file to the exports of ${pkg.name}.`,\n ),\n from: { pathNot: own },\n to: pkg.entries.length > 0 ? { path: own, pathNot: pkg.entries } : { path: own },\n });\n }\n const names = packages.map((p) => escape(p.name));\n if (names.length > 0) {\n rules.push({\n name: \"not-a-declared-export\",\n severity: \"error\",\n comment: why(\"An import of a package of this workspace does not resolve. The path is not an entry of its exports, or the package is not built.\"),\n from: {},\n to: { path: `^(${names.join(\"|\")})(/|$)`, couldNotResolve: true },\n });\n }\n const scopes = workspaceScopes(packages, opts.scopes);\n if (scopes.length > 0) {\n const inScope = (name: string): boolean => scopes.some((scope) => name.startsWith(`${scope}/`));\n const declared = [...packages.flatMap((p) => p.dependencies ?? []), ...(opts.dependencies ?? [])];\n const known = [...new Set([...packages.map((p) => p.name), ...declared].filter(inScope))].sort().map(escape);\n rules.push({\n name: \"unknown-workspace-package\",\n severity: \"error\",\n comment: why(\n `An import names a package of the scope ${scopes.join(\", \")}, but the import does not resolve. The name is not a package of this workspace and not a declared dependency. Correct the name, or add the package.`,\n ),\n from: {},\n to: { path: `^(${scopes.map(escape).join(\"|\")})/`, ...(known.length > 0 ? { pathNot: `^(${known.join(\"|\")})(/|$)` } : {}), couldNotResolve: true },\n });\n }\n const apps =\n opts.apps === \"private\" ? packages.filter((p) => p.private) : packages.filter((p) => (opts.apps ?? []).includes(p.name));\n for (const app of apps) {\n rules.push({\n name: `import-of-the-app-${slug(app.name)}`,\n severity: \"error\",\n comment: why(`A package imports the app ${app.name}. An app is a leaf: no other package imports it. Move the shared code to a library package.`),\n from: { pathNot: `^${escape(app.dir)}/` },\n to: { path: `^${escape(app.dir)}/` },\n });\n }\n return rules;\n}\n\nconst slug = (name: string): string => name.replace(/^@/, \"\").replace(/[^A-Za-z0-9]+/g, \"-\");\n\n/**\n * The parser of the TypeScript source. dependency-cruiser reads TypeScript with the TypeScript\n * compiler of the repository only for TypeScript 2 to 6. With TypeScript 7 or no TypeScript, it reads\n * TypeScript with swc when @swc/core is installed. Else it reads only JavaScript (acorn): that is\n * enough for a check of built JavaScript.\n */\nexport function parserOptions(root?: string): Record<string, unknown> {\n if (!root) return {};\n const require = createRequire(join(root, \"package.json\"));\n try {\n const { version } = require(\"typescript/package.json\") as { version: string };\n // A type-only import is a boundary too. This option needs the TypeScript compiler.\n if (Number(version.split(\".\")[0]) < 7) return { tsPreCompilationDeps: true };\n } catch {\n // No TypeScript in the repository\n }\n // @swc/core from the repository, or next to this package (a peer dependency)\n for (const from of [require, createRequire(import.meta.url)]) {\n try {\n from.resolve(\"@swc/core\");\n return { parser: \"swc\" };\n } catch {\n // Not there\n }\n }\n return {};\n}\n\n/** The options of `defaultOptions()`. */\nexport interface DefaultOptionsInput {\n /** The packages of the workspace. The default is `workspacePackages(root)`. */\n packages?: WorkspacePackage[];\n /** The build folders of each package. The default is `[\"dist\", \"build\"]`. */\n buildFolders?: string[];\n}\n\n/** The RegExp sources of the paths that the analysis does not follow: node_modules and the build folders of each package. */\nexport function doNotFollowPaths(packages: Pick<WorkspacePackage, \"dir\">[], buildFolders: string[] = BUILD_FOLDERS): string[] {\n const paths = [\"(^|/)node_modules/\"];\n const dirs = packages.map((p) => p.dir).filter((dir) => dir !== \"\" && dir !== \".\");\n const folders = buildFolders.map((folder) => folder.replace(/^\\.\\//, \"\").replace(/\\/$/, \"\")).filter((folder) => folder !== \"\");\n if (dirs.length > 0 && folders.length > 0) paths.push(`^(${dirs.map(escape).join(\"|\")})/(${folders.map(escape).join(\"|\")})/`);\n return paths;\n}\n\n/**\n * The default options: the source of the packages, with type-only imports, resolved as Node resolves\n * an ESM import. There is no `includeOnly`, because it also removes the imports that do not resolve,\n * and the rule not-a-declared-export needs them. The analysis does not follow node_modules and the\n * build folders of the packages: an import of a package stops at its entry. The \"types\" condition is\n * not used: it resolves to a declaration file, and the analysis excludes declaration files, so a deep\n * import does not show. The `require` condition is not used: an ESM import does not resolve to an\n * entry that is only for `require`.\n */\nexport function defaultOptions(root?: string, input: DefaultOptionsInput = {}): Record<string, unknown> {\n const packages = input.packages ?? (root ? workspacePackages(root) : []);\n return {\n ...parserOptions(root),\n exclude: {\n path: [\"(^|/)node_modules/\", \"\\\\.(test|spec|e2e)\\\\.[cm]?[jt]sx?$\", \"\\\\.d\\\\.[cm]?ts$\", \"/(test|tests|e2e|__tests__|fixtures)/\"],\n },\n doNotFollow: { path: doNotFollowPaths(packages, input.buildFolders) },\n enhancedResolveOptions: {\n exportsFields: [\"exports\"],\n conditionNames: [\"import\", \"node\", \"default\"],\n mainFields: [\"module\", \"main\"],\n },\n skipAnalysisNotInRules: true,\n };\n}\n\n/** A rule with the reference before its comment, when the comment does not start with it. */\nfunction withReference(rule: Rule, reference?: string): Rule {\n if (!reference || rule.comment?.startsWith(reference)) return rule;\n return { ...rule, comment: rule.comment ? `${reference} ${rule.comment}` : reference };\n}\n\n/** The dependency-cruiser configuration of the boundaries for the workspace in the folder `root`. */\nexport function boundaries(root: string, opts: BoundaryOptions = {}): Config {\n const packages = workspacePackages(root, opts.packages);\n let rootManifest: Record<string, unknown> = {};\n try {\n rootManifest = JSON.parse(readFileSync(join(root, \"package.json\"), \"utf8\")) as Record<string, unknown>;\n } catch {\n // No package.json at the root\n }\n const options = { ...defaultOptions(root, { packages, ...(opts.buildFolders ? { buildFolders: opts.buildFolders } : {}) }), ...opts.options };\n const rules = boundaryRules(packages, { ...opts, dependencies: declaredDependencies(rootManifest) });\n return {\n forbidden: [...rules, ...(opts.forbidden ?? []).map((rule) => withReference(rule, opts.reference))],\n options,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA4EA,MAAM,UAAU,SAAyB,KAAK,QAAQ,uBAAuB,MAAM;;AAGnF,MAAM,gBAAgB,CAAC,QAAQ,OAAO;AAEtC,MAAM,oBAAoB;CAAC;CAAgB;CAAmB;CAAoB;AAAsB;;AAGxG,SAAgB,qBAAqB,UAA6C;CAChF,MAAM,wBAAQ,IAAI,IAAY;CAC9B,KAAK,MAAM,SAAS,mBAAmB;EACrC,MAAM,QAAQ,SAAS;EACvB,IAAI,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,GAAG,KAAK,MAAM,QAAQ,OAAO,KAAK,KAAK,GAAG,MAAM,IAAI,IAAI;CACxH;CACA,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,KAAK;AACzB;;AAGA,SAAgB,gBAAgB,UAA4C,OAAqB,CAAC,GAAa;CAC7G,MAAM,UAAU,WAA2B,MAAM,WAAW,GAAG,IAAI,QAAQ,IAAI,QAAA,CAAS,QAAQ,OAAO,EAAE;CACzG,IAAI,MAAM,QAAQ,IAAI,GAAG,OAAO,CAAC,GAAG,IAAI,IAAI,KAAK,IAAI,MAAM,CAAC,CAAC,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,CAAC;EAAG,GAAG,KAAK;CAAQ;CAE5I,OAAO;EACL,WAAW,CAAC,GAFA,cAAc,UAAU;GAAE,GAAG;GAAM,cAAc,qBAAqB,YAAY;EAAE,CAE7E,GAAG,IAAI,KAAK,aAAa,CAAC,EAAA,CAAG,KAAK,SAAS,cAAc,MAAM,KAAK,SAAS,CAAC,CAAC;EAClG;CACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,79 @@
1
1
  {
2
+ "$schema": "https://json.schemastore.org/package",
2
3
  "name": "@mark1russell7/boundaries",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
4
+ "version": "0.2.0",
5
+ "description": "The import boundaries of a pnpm workspace as a dependency-cruiser configuration: each package is imported only through the entries of its package.json.",
6
+ "keywords": [
7
+ "dependency-cruiser",
8
+ "monorepo",
9
+ "pnpm",
10
+ "workspace",
11
+ "architecture",
12
+ "boundaries",
13
+ "exports",
14
+ "lint"
15
+ ],
16
+ "homepage": "https://github.com/mark1russell7/template/tree/main/packages/boundaries#readme",
17
+ "bugs": {
18
+ "url": "https://github.com/mark1russell7/template/issues"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/mark1russell7/template.git",
23
+ "directory": "packages/boundaries"
24
+ },
25
+ "license": "MIT",
26
+ "author": "Mark Russell (https://github.com/mark1russell7)",
27
+ "type": "module",
28
+ "main": "./build/index.js",
29
+ "files": [
30
+ "build"
31
+ ],
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "engines": {
36
+ "node": ">=22"
37
+ },
38
+ "peerDependencies": {
39
+ "dependency-cruiser": "^17.0.0 || ^18.0.0",
40
+ "@swc/core": "^1.10.0"
41
+ },
42
+ "peerDependenciesMeta": {
43
+ "dependency-cruiser": {
44
+ "optional": true
45
+ },
46
+ "@swc/core": {
47
+ "optional": true
48
+ }
49
+ },
50
+ "devDependencies": {
51
+ "@mark1russell7/cue": "^1.0.2",
52
+ "@types/node": "^26.6.4",
53
+ "typescript": "^7.0.2",
54
+ "vitest": "^5.0.3",
55
+ "dependency-cruiser": "^18.7.0",
56
+ "tsdown": "^0.23.1",
57
+ "@swc/core": "^1.15.0"
58
+ },
59
+ "scripts": {
60
+ "build": "tsdown",
61
+ "test": "vitest run",
62
+ "test:watch": "vitest",
63
+ "typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.test.json"
64
+ },
65
+ "types": "./build/index.d.ts",
66
+ "exports": {
67
+ ".": {
68
+ "import": {
69
+ "types": "./build/index.d.ts",
70
+ "default": "./build/index.js"
71
+ },
72
+ "require": {
73
+ "types": "./build/index.d.cts",
74
+ "default": "./build/index.cjs"
75
+ }
76
+ },
77
+ "./package.json": "./package.json"
78
+ }
6
79
  }