@nadicodeai/ui 12.1.105 → 12.1.107

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.
@@ -58,6 +58,7 @@ import { tableCellInsetOwner } from "./rules/table-cell-inset-owner.js";
58
58
  import { tabsSelectionIsControlled } from "./rules/tabs-selection-is-controlled.js";
59
59
  import { tooltipOnlyArrow } from "./rules/tooltip-only-arrow.js";
60
60
  import { tooltipTriggerAccessibleName } from "./rules/tooltip-trigger-accessible-name.js";
61
+ import { workspaceDeclaresImports } from "./rules/workspace-declares-imports.js";
61
62
  import { strictDesignSystemSelectors } from "./strict-design-system.js";
62
63
 
63
64
  /**
@@ -202,6 +203,7 @@ const plugin = {
202
203
  "tabs-selection-is-controlled": tabsSelectionIsControlled,
203
204
  "tooltip-only-arrow": tooltipOnlyArrow,
204
205
  "tooltip-trigger-accessible-name": tooltipTriggerAccessibleName,
206
+ "workspace-declares-imports": workspaceDeclaresImports,
205
207
  },
206
208
  };
207
209
 
@@ -0,0 +1,163 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { builtinModules } from "node:module";
3
+ import { dirname, join, relative, sep } from "node:path";
4
+
5
+ const DEPENDENCY_FIELDS = [
6
+ "dependencies",
7
+ "devDependencies",
8
+ "peerDependencies",
9
+ "optionalDependencies",
10
+ ];
11
+
12
+ const BUILTINS = new Set(builtinModules);
13
+
14
+ export const DECLARED_DEPENDENCIES_SETTING = "nadicodeai/declared-dependencies";
15
+
16
+ const manifests = new Map();
17
+ const scopes = new Map();
18
+
19
+ function readManifest(directory) {
20
+ const path = join(directory, "package.json");
21
+ return existsSync(path) ? JSON.parse(readFileSync(path, "utf8")) : undefined;
22
+ }
23
+
24
+ function manifestIn(directory) {
25
+ if (!manifests.has(directory)) manifests.set(directory, readManifest(directory));
26
+ return manifests.get(directory);
27
+ }
28
+
29
+ function declaredBy(manifest) {
30
+ return new Set(DEPENDENCY_FIELDS.flatMap((field) => Object.keys(manifest[field] ?? {})));
31
+ }
32
+
33
+ function sortedNames(manifest) {
34
+ return [...declaredBy(manifest)].sort();
35
+ }
36
+
37
+ export function declaredDependencies(rootDirectory) {
38
+ const root = readManifest(rootDirectory);
39
+ const workspaces = {};
40
+ for (const path of [...workspacePaths(root)].sort()) {
41
+ const manifest = readManifest(join(rootDirectory, path));
42
+ if (manifest !== undefined) {
43
+ workspaces[path] = { name: manifest.name, declared: sortedNames(manifest) };
44
+ }
45
+ }
46
+ return { root: sortedNames(root), workspaces };
47
+ }
48
+
49
+ function workspacePaths(manifest) {
50
+ const list = Array.isArray(manifest.workspaces)
51
+ ? manifest.workspaces
52
+ : (manifest.workspaces?.packages ?? []);
53
+ return new Set(list.map((path) => path.replace(/\/$/, "")));
54
+ }
55
+
56
+ function computeScope(directory) {
57
+ const candidates = [];
58
+ for (let current = directory; ; current = dirname(current)) {
59
+ const manifest = manifestIn(current);
60
+ if (manifest?.workspaces !== undefined) {
61
+ const listed = workspacePaths(manifest);
62
+ const workspace = candidates.find((candidate) =>
63
+ listed.has(relative(current, candidate).split(sep).join("/")),
64
+ );
65
+ if (workspace === undefined) return undefined;
66
+ const own = manifestIn(workspace);
67
+ const path = relative(current, workspace).split(sep).join("/");
68
+ return {
69
+ workspacePath: path,
70
+ workspaceName: own.name ?? path,
71
+ ownName: own.name,
72
+ rootDeclared: declaredBy(manifest),
73
+ workspaceDeclared: declaredBy(own),
74
+ };
75
+ }
76
+ if (manifest !== undefined) candidates.push(current);
77
+ if (dirname(current) === current) return undefined;
78
+ }
79
+ }
80
+
81
+ function scopeOf(directory) {
82
+ if (!scopes.has(directory)) scopes.set(directory, computeScope(directory));
83
+ return scopes.get(directory);
84
+ }
85
+
86
+ function declaredNamesOf(scope, given) {
87
+ const entry = given?.workspaces?.[scope.workspacePath];
88
+ if (entry === undefined || !Array.isArray(given.root)) return scope;
89
+ return {
90
+ ownName: entry.name,
91
+ workspaceName: entry.name ?? scope.workspacePath,
92
+ rootDeclared: new Set(given.root),
93
+ workspaceDeclared: new Set(entry.declared),
94
+ };
95
+ }
96
+
97
+ function packageNameOf(specifier) {
98
+ if (specifier.startsWith(".") || specifier.startsWith("/") || specifier.startsWith("node:")) {
99
+ return undefined;
100
+ }
101
+ const [first, second = ""] = specifier.split("/");
102
+ const name = first.startsWith("@") ? `${first}/${second}` : first;
103
+ return BUILTINS.has(name) ? undefined : name;
104
+ }
105
+
106
+ function specifierOf(node) {
107
+ // oxlint-disable-next-line anti-slop/no-runtime-typeof -- ESTree types Literal.value as string | number | boolean | RegExp | bigint | null; only typeof picks the string.
108
+ return node?.type === "Literal" && typeof node.value === "string" ? node.value : undefined;
109
+ }
110
+
111
+ export const workspaceDeclaresImports = {
112
+ meta: {
113
+ type: "problem",
114
+ docs: {
115
+ description:
116
+ "Require a workspace to declare each package it imports that the root package.json declares",
117
+ },
118
+ schema: [],
119
+ messages: {
120
+ undeclared:
121
+ '"{{name}}" is declared by the root package.json but not by {{workspace}}. Declare it in the workspace that imports it, so a root bump is attributed to that workspace.',
122
+ },
123
+ },
124
+ create(context) {
125
+ const found = scopeOf(dirname(context.filename));
126
+ if (found === undefined) return {};
127
+ const scope = declaredNamesOf(found, context.settings[DECLARED_DEPENDENCIES_SETTING]);
128
+
129
+ function check(source) {
130
+ const specifier = specifierOf(source);
131
+ if (specifier === undefined) return;
132
+ const name = packageNameOf(specifier);
133
+ if (
134
+ name === undefined ||
135
+ name === scope.ownName ||
136
+ !scope.rootDeclared.has(name) ||
137
+ scope.workspaceDeclared.has(name)
138
+ ) {
139
+ return;
140
+ }
141
+ context.report({
142
+ node: source,
143
+ messageId: "undeclared",
144
+ data: { name, workspace: scope.workspaceName },
145
+ });
146
+ }
147
+
148
+ return {
149
+ ImportDeclaration: (node) => check(node.source),
150
+ ExportNamedDeclaration: (node) => check(node.source),
151
+ ExportAllDeclaration: (node) => check(node.source),
152
+ ImportExpression: (node) => check(node.source),
153
+ TSExternalModuleReference: (node) => check(node.expression),
154
+ TSImportType: (node) =>
155
+ check(node.argument?.type === "TSLiteralType" ? node.argument.literal : node.argument),
156
+ CallExpression: (node) => {
157
+ if (node.callee.type === "Identifier" && node.callee.name === "require") {
158
+ check(node.arguments[0]);
159
+ }
160
+ },
161
+ };
162
+ },
163
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nadicodeai/ui",
3
- "version": "12.1.105",
3
+ "version": "12.1.107",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -80,7 +80,7 @@
80
80
  "@base-ui/react": "^1.9.0",
81
81
  "@iconify-icons/logos": "^2.0.2",
82
82
  "@iconify/react": "^6.0.2",
83
- "@nadicodeai/design-system": "12.1.105",
83
+ "@nadicodeai/design-system": "12.1.107",
84
84
  "@tanstack/react-table": "^9.2.8",
85
85
  "class-variance-authority": "^0.7.1",
86
86
  "clsx": "^2.1.1",
@@ -124,8 +124,8 @@
124
124
  "eslint": "^9.39.4",
125
125
  "jsdom": "^30.1.2",
126
126
  "postcss": "^8.5.29",
127
- "react": "19.3.0",
128
- "react-dom": "19.3.0",
127
+ "react": "19.3.1",
128
+ "react-dom": "19.3.1",
129
129
  "shadcn": "4.21.0",
130
130
  "tailwindcss": "^4.3.3",
131
131
  "typescript": "^6",