@ankhorage/doctor 0.4.0 → 0.5.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 23a5302: Validate canonical `./cli` exports, reject `@ankh/*` workspace aliases and active `ankhorage4` source references, and enforce direct Studio ownership of runtime and drag-and-drop packages.
8
+
3
9
  ## 0.4.0
4
10
 
5
11
  ### Minor Changes
package/README.md CHANGED
@@ -3,9 +3,9 @@
3
3
 
4
4
  # DOCTOR
5
5
 
6
- ![license: MIT](././paradox/badges/license.svg) ![npm: v0.3.0](././paradox/badges/npm.svg) ![runtime: bun](././paradox/badges/runtime.svg) ![typescript: strict](././paradox/badges/typescript.svg) ![eslint: checked](././paradox/badges/eslint.svg) ![prettier: checked](././paradox/badges/prettier.svg) ![build: checked](././paradox/badges/build.svg) ![tests: checked](././paradox/badges/tests.svg) ![docs: paradox](././paradox/badges/docs.svg)
6
+ ![license: MIT](././paradox/badges/license.svg) ![npm: v0.4.0](././paradox/badges/npm.svg) ![runtime: bun](././paradox/badges/runtime.svg) ![typescript: strict](././paradox/badges/typescript.svg) ![eslint: checked](././paradox/badges/eslint.svg) ![prettier: checked](././paradox/badges/prettier.svg) ![build: checked](././paradox/badges/build.svg) ![tests: checked](././paradox/badges/tests.svg) ![docs: paradox](././paradox/badges/docs.svg)
7
7
 
8
- Executable doctor provider and standalone CLI for lightweight repo and package compliance diagnostics.
8
+ Executable doctor provider and standalone CLI for lightweight Ankhorage repo and package compliance diagnostics.
9
9
 
10
10
  ## Usage
11
11
 
@@ -1 +1 @@
1
- {"version":3,"file":"cliLayoutAnalysis.d.ts","sourceRoot":"","sources":["../src/cliLayoutAnalysis.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EAC1B,MAAM,eAAe,CAAC;AAMvB,wBAAsB,gCAAgC,CACpD,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,oBAAoB,CAAC,CAkB/B"}
1
+ {"version":3,"file":"cliLayoutAnalysis.d.ts","sourceRoot":"","sources":["../src/cliLayoutAnalysis.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EAC1B,MAAM,eAAe,CAAC;AAsDvB,wBAAsB,gCAAgC,CACpD,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,oBAAoB,CAAC,CA6B/B"}
@@ -3,55 +3,319 @@ import path from 'node:path';
3
3
  import { analyzeDoctorTarget, } from './analysis.js';
4
4
  const LEGACY_ROOT_CLI_SOURCE = path.join('src', 'cli.ts');
5
5
  const CANONICAL_CLI_INDEX_SOURCE = path.join('src', 'cli', 'index.ts');
6
+ const ACTIVE_SOURCE_ROOTS = ['src', 'app', 'apps', 'packages', 'scripts'];
7
+ const ACTIVE_SOURCE_EXTENSIONS = new Set([
8
+ '.cjs',
9
+ '.cts',
10
+ '.js',
11
+ '.jsx',
12
+ '.mjs',
13
+ '.mts',
14
+ '.ts',
15
+ '.tsx',
16
+ ]);
17
+ const IGNORED_SOURCE_DIRECTORIES = new Set([
18
+ '.expo',
19
+ '.git',
20
+ '.next',
21
+ '__fixtures__',
22
+ '__tests__',
23
+ 'build',
24
+ 'coverage',
25
+ 'dist',
26
+ 'docs',
27
+ 'fixtures',
28
+ 'node_modules',
29
+ 'paradox',
30
+ 'test',
31
+ 'tests',
32
+ ]);
33
+ const COMPATIBILITY_PACKAGE_PREFIX = '@ankh/';
34
+ const STUDIO_PACKAGE_NAME = '@ankhorage/studio';
35
+ const STUDIO_DND_PACKAGE_NAME = '@ankhorage/react-native-reanimated-dnd-web';
36
+ const STUDIO_RUNTIME_PACKAGE_NAME = '@ankhorage/runtime';
37
+ const DEPENDENCY_FIELD_NAMES = [
38
+ 'dependencies',
39
+ 'devDependencies',
40
+ 'optionalDependencies',
41
+ 'peerDependencies',
42
+ ];
6
43
  export async function analyzeDoctorTargetWithCliLayout(request) {
7
44
  const result = await analyzeDoctorTarget(request);
8
45
  if (!result.hasPackageJson) {
9
46
  return result;
10
47
  }
11
- const cliDiagnostics = await analyzeCliLayout(result.targetPath, result.profile);
12
- if (cliDiagnostics.length === 0) {
48
+ const packageJsonPath = path.join(result.targetPath, 'package.json');
49
+ const packageJson = await readPackageJson(packageJsonPath);
50
+ if (packageJson === null) {
13
51
  return result;
14
52
  }
15
- const diagnostics = [...result.diagnostics, ...cliDiagnostics];
53
+ const architectureDiagnostics = await analyzeTargetArchitecture({
54
+ packageJson,
55
+ packageJsonPath,
56
+ profile: result.profile,
57
+ targetPath: result.targetPath,
58
+ });
59
+ if (architectureDiagnostics.length === 0) {
60
+ return result;
61
+ }
62
+ const diagnostics = [...result.diagnostics, ...architectureDiagnostics];
16
63
  return {
17
64
  ...result,
18
65
  diagnostics,
19
66
  fixPlan: result.fixPlan === null ? null : { ...result.fixPlan, diagnostics },
20
67
  };
21
68
  }
22
- async function analyzeCliLayout(targetPath, profile) {
69
+ async function analyzeTargetArchitecture(request) {
23
70
  const diagnostics = [];
24
- const legacyRootCliPath = path.join(targetPath, LEGACY_ROOT_CLI_SOURCE);
25
- const canonicalCliIndexPath = path.join(targetPath, CANONICAL_CLI_INDEX_SOURCE);
71
+ const legacyRootCliPath = path.join(request.targetPath, LEGACY_ROOT_CLI_SOURCE);
72
+ const canonicalCliIndexPath = path.join(request.targetPath, CANONICAL_CLI_INDEX_SOURCE);
73
+ const exportsField = isRecord(request.packageJson.exports) ? request.packageJson.exports : null;
74
+ const cliCapable = hasAnkhProvider(request.packageJson) ||
75
+ exportsField?.['./cli'] !== undefined ||
76
+ (await pathExists(canonicalCliIndexPath));
26
77
  if (await pathExists(legacyRootCliPath)) {
27
78
  diagnostics.push({
28
79
  code: 'field-invalid',
29
80
  message: 'Package CLI code must live under src/cli/; root src/cli.ts is not allowed.',
30
81
  path: legacyRootCliPath,
31
- profile,
82
+ profile: request.profile,
32
83
  ruleId: 'package.cli.root-file.disallowed',
33
84
  severity: 'error',
34
85
  });
35
86
  }
36
- const packageJson = await readPackageJson(path.join(targetPath, 'package.json'));
37
- if (packageJson !== null &&
38
- exposesCliProvider(packageJson) &&
39
- !(await pathExists(canonicalCliIndexPath))) {
87
+ if (cliCapable && !(await pathExists(canonicalCliIndexPath))) {
40
88
  diagnostics.push({
41
89
  code: 'missing-path',
42
90
  message: 'CLI-capable packages must expose their provider from src/cli/index.ts.',
43
91
  path: canonicalCliIndexPath,
44
- profile,
92
+ profile: request.profile,
45
93
  ruleId: 'package.cli.index.required',
46
94
  severity: 'error',
47
95
  });
48
96
  }
97
+ if (cliCapable && exportsField?.['./cli'] === undefined) {
98
+ diagnostics.push({
99
+ code: 'field-missing',
100
+ message: 'CLI-capable packages must export "./cli" from package.json and point it at the owning src/cli/index.ts build output.',
101
+ path: request.packageJsonPath,
102
+ profile: request.profile,
103
+ ruleId: 'package.cli.export.required',
104
+ severity: 'error',
105
+ });
106
+ }
107
+ const dependencyEntries = collectDependencyEntries(request.packageJson);
108
+ diagnostics.push(...validateDependencyArchitecture({
109
+ dependencyEntries,
110
+ packageJsonPath: request.packageJsonPath,
111
+ profile: request.profile,
112
+ }));
113
+ const activeSourceImports = await collectActiveSourceImports(request.targetPath);
114
+ diagnostics.push(...validateActiveSourceImports({
115
+ activeSourceImports,
116
+ profile: request.profile,
117
+ }));
118
+ if (request.packageJson.name === STUDIO_PACKAGE_NAME) {
119
+ diagnostics.push(...validateStudioOwnership({
120
+ activeSourceImports,
121
+ dependencyEntries,
122
+ packageJsonPath: request.packageJsonPath,
123
+ profile: request.profile,
124
+ }));
125
+ }
126
+ return diagnostics;
127
+ }
128
+ function validateDependencyArchitecture(request) {
129
+ const diagnostics = [];
130
+ for (const dependency of request.dependencyEntries) {
131
+ if (dependency.packageName.startsWith(COMPATIBILITY_PACKAGE_PREFIX)) {
132
+ diagnostics.push({
133
+ code: 'field-invalid',
134
+ message: `Dependency "${dependency.packageName}" in package.json.${dependency.fieldName} is an old ankhorage4 workspace alias. Depend on "${toOwningPackageSpecifier(dependency.packageName)}" directly.`,
135
+ path: request.packageJsonPath,
136
+ profile: request.profile,
137
+ ruleId: 'package.dependencies.ankh-workspace-alias.disallowed',
138
+ severity: 'error',
139
+ });
140
+ }
141
+ if (dependency.packageName.includes('ankhorage4') ||
142
+ dependency.version.includes('ankhorage4')) {
143
+ diagnostics.push({
144
+ code: 'field-invalid',
145
+ message: `Dependency "${dependency.packageName}" references ankhorage4 as active source. Depend on the extracted owning @ankhorage/* package instead.`,
146
+ path: request.packageJsonPath,
147
+ profile: request.profile,
148
+ ruleId: 'package.dependencies.ankhorage4-source.disallowed',
149
+ severity: 'error',
150
+ });
151
+ }
152
+ }
153
+ return diagnostics;
154
+ }
155
+ function validateActiveSourceImports(request) {
156
+ const diagnostics = [];
157
+ for (const sourceImport of request.activeSourceImports) {
158
+ if (sourceImport.specifier.startsWith(COMPATIBILITY_PACKAGE_PREFIX)) {
159
+ diagnostics.push({
160
+ code: 'field-invalid',
161
+ message: `Import "${sourceImport.specifier}" is an old ankhorage4 compatibility boundary. Import "${toOwningPackageSpecifier(sourceImport.specifier)}" directly from the owning package.`,
162
+ path: sourceImport.filePath,
163
+ profile: request.profile,
164
+ ruleId: 'package.imports.ankh-workspace-alias.disallowed',
165
+ severity: 'error',
166
+ });
167
+ }
168
+ if (sourceImport.specifier.includes('ankhorage4')) {
169
+ diagnostics.push({
170
+ code: 'field-invalid',
171
+ message: `Import "${sourceImport.specifier}" references ankhorage4 as active source. Import the extracted owning @ankhorage/* package instead.`,
172
+ path: sourceImport.filePath,
173
+ profile: request.profile,
174
+ ruleId: 'package.imports.ankhorage4-source.disallowed',
175
+ severity: 'error',
176
+ });
177
+ }
178
+ }
49
179
  return diagnostics;
50
180
  }
51
- function exposesCliProvider(packageJson) {
181
+ function validateStudioOwnership(request) {
182
+ const diagnostics = [];
183
+ const directDependencies = new Set(request.dependencyEntries
184
+ .filter((dependency) => dependency.fieldName === 'dependencies')
185
+ .map((dependency) => dependency.packageName));
186
+ const importedSpecifiers = request.activeSourceImports.map((sourceImport) => sourceImport.specifier);
187
+ if (!directDependencies.has(STUDIO_DND_PACKAGE_NAME)) {
188
+ diagnostics.push({
189
+ code: 'missing-dependency',
190
+ message: `@ankhorage/studio must depend directly on "${STUDIO_DND_PACKAGE_NAME}" for Studio drag-and-drop ownership.`,
191
+ path: request.packageJsonPath,
192
+ profile: request.profile,
193
+ ruleId: 'studio.dependencies.dnd.required',
194
+ severity: 'error',
195
+ });
196
+ }
197
+ if (!directDependencies.has(STUDIO_RUNTIME_PACKAGE_NAME)) {
198
+ diagnostics.push({
199
+ code: 'missing-dependency',
200
+ message: `@ankhorage/studio must depend directly on "${STUDIO_RUNTIME_PACKAGE_NAME}" for runtime ownership.`,
201
+ path: request.packageJsonPath,
202
+ profile: request.profile,
203
+ ruleId: 'studio.dependencies.runtime.required',
204
+ severity: 'error',
205
+ });
206
+ }
207
+ if (!importedSpecifiers.some((specifier) => isPackageImport(specifier, STUDIO_DND_PACKAGE_NAME))) {
208
+ diagnostics.push({
209
+ code: 'field-missing',
210
+ message: `@ankhorage/studio must import "${STUDIO_DND_PACKAGE_NAME}" directly from its Studio DnD boundary.`,
211
+ path: request.packageJsonPath,
212
+ profile: request.profile,
213
+ ruleId: 'studio.imports.dnd.required',
214
+ severity: 'error',
215
+ });
216
+ }
217
+ if (!importedSpecifiers.some((specifier) => isPackageImport(specifier, STUDIO_RUNTIME_PACKAGE_NAME))) {
218
+ diagnostics.push({
219
+ code: 'field-missing',
220
+ message: `@ankhorage/studio must import "${STUDIO_RUNTIME_PACKAGE_NAME}" directly from the owning runtime package.`,
221
+ path: request.packageJsonPath,
222
+ profile: request.profile,
223
+ ruleId: 'studio.imports.runtime.required',
224
+ severity: 'error',
225
+ });
226
+ }
227
+ return diagnostics;
228
+ }
229
+ async function collectActiveSourceImports(targetPath) {
230
+ const imports = [];
231
+ for (const sourceRoot of ACTIVE_SOURCE_ROOTS) {
232
+ const sourceRootPath = path.join(targetPath, sourceRoot);
233
+ if (!(await pathExists(sourceRootPath))) {
234
+ continue;
235
+ }
236
+ for (const filePath of await listActiveSourceFiles(sourceRootPath)) {
237
+ const source = await fs.readFile(filePath, 'utf8');
238
+ for (const specifier of extractImportSpecifiers(source)) {
239
+ imports.push({ filePath, specifier });
240
+ }
241
+ }
242
+ }
243
+ return imports;
244
+ }
245
+ async function listActiveSourceFiles(rootPath) {
246
+ const files = [];
247
+ await visit(rootPath);
248
+ return files.sort((left, right) => left.localeCompare(right));
249
+ async function visit(currentPath) {
250
+ const entries = await fs.readdir(currentPath, { withFileTypes: true });
251
+ for (const entry of entries) {
252
+ if (entry.isDirectory()) {
253
+ if (!IGNORED_SOURCE_DIRECTORIES.has(entry.name)) {
254
+ await visit(path.join(currentPath, entry.name));
255
+ }
256
+ continue;
257
+ }
258
+ if (!entry.isFile()) {
259
+ continue;
260
+ }
261
+ const filePath = path.join(currentPath, entry.name);
262
+ if (isActiveSourceFile(filePath)) {
263
+ files.push(filePath);
264
+ }
265
+ }
266
+ }
267
+ }
268
+ function isActiveSourceFile(filePath) {
269
+ if (!ACTIVE_SOURCE_EXTENSIONS.has(path.extname(filePath))) {
270
+ return false;
271
+ }
272
+ return !/(?:^|\.)(?:spec|test)\.[cm]?[jt]sx?$/.test(path.basename(filePath));
273
+ }
274
+ function extractImportSpecifiers(source) {
275
+ const specifiers = new Set();
276
+ const patterns = [
277
+ /\b(?:import|export)\s+(?:type\s+)?(?:[^;]*?\sfrom\s*)?['"]([^'"]+)['"]/g,
278
+ /\b(?:import|require)\s*\(\s*['"]([^'"]+)['"]\s*\)/g,
279
+ ];
280
+ for (const pattern of patterns) {
281
+ for (const match of source.matchAll(pattern)) {
282
+ const [, specifier] = match;
283
+ if (specifier !== undefined) {
284
+ specifiers.add(specifier);
285
+ }
286
+ }
287
+ }
288
+ return [...specifiers].sort((left, right) => left.localeCompare(right));
289
+ }
290
+ function collectDependencyEntries(packageJson) {
291
+ const entries = [];
292
+ for (const fieldName of DEPENDENCY_FIELD_NAMES) {
293
+ const dependencies = isRecord(packageJson[fieldName]) ? packageJson[fieldName] : null;
294
+ if (dependencies === null) {
295
+ continue;
296
+ }
297
+ for (const [packageName, version] of Object.entries(dependencies)) {
298
+ if (isNonEmptyString(version)) {
299
+ entries.push({ fieldName, packageName, version });
300
+ }
301
+ }
302
+ }
303
+ return entries.sort((left, right) => {
304
+ const fieldComparison = left.fieldName.localeCompare(right.fieldName);
305
+ return fieldComparison !== 0
306
+ ? fieldComparison
307
+ : left.packageName.localeCompare(right.packageName);
308
+ });
309
+ }
310
+ function hasAnkhProvider(packageJson) {
52
311
  const ankh = isRecord(packageJson.ankh) ? packageJson.ankh : null;
53
- const exportsField = isRecord(packageJson.exports) ? packageJson.exports : null;
54
- return isNonEmptyString(ankh?.provider) || exportsField?.['./cli'] !== undefined;
312
+ return isNonEmptyString(ankh?.provider);
313
+ }
314
+ function isPackageImport(specifier, packageName) {
315
+ return specifier === packageName || specifier.startsWith(`${packageName}/`);
316
+ }
317
+ function toOwningPackageSpecifier(specifier) {
318
+ return `@ankhorage/${specifier.slice(COMPATIBILITY_PACKAGE_PREFIX.length)}`;
55
319
  }
56
320
  async function readPackageJson(packageJsonPath) {
57
321
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"cliLayoutAnalysis.js","sourceRoot":"","sources":["../src/cliLayoutAnalysis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACL,mBAAmB,GAGpB,MAAM,eAAe,CAAC;AAGvB,MAAM,sBAAsB,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AAC1D,MAAM,0BAA0B,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,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C,UAAkB;IAC1C,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc;IACtC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;AAC9D,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["import { promises as fs } from 'node:fs';\nimport path from 'node:path';\n\nimport {\n analyzeDoctorTarget,\n type DoctorAnalysisRequest,\n type DoctorAnalysisResult,\n} from './analysis.js';\nimport type { DoctorDiagnostic, DoctorPolicyProfile } from './diagnostics.js';\n\nconst LEGACY_ROOT_CLI_SOURCE = path.join('src', 'cli.ts');\nconst CANONICAL_CLI_INDEX_SOURCE = path.join('src', 'cli', 'index.ts');\n\nexport async function analyzeDoctorTargetWithCliLayout(\n request: DoctorAnalysisRequest,\n): Promise<DoctorAnalysisResult> {\n const result = await analyzeDoctorTarget(request);\n if (!result.hasPackageJson) {\n return result;\n }\n\n const cliDiagnostics = await analyzeCliLayout(result.targetPath, result.profile);\n if (cliDiagnostics.length === 0) {\n return result;\n }\n\n const diagnostics = [...result.diagnostics, ...cliDiagnostics];\n\n return {\n ...result,\n diagnostics,\n fixPlan: result.fixPlan === null ? null : { ...result.fixPlan, diagnostics },\n };\n}\n\nasync function analyzeCliLayout(\n targetPath: string,\n profile: DoctorPolicyProfile,\n): Promise<DoctorDiagnostic[]> {\n const diagnostics: DoctorDiagnostic[] = [];\n const legacyRootCliPath = path.join(targetPath, LEGACY_ROOT_CLI_SOURCE);\n const canonicalCliIndexPath = path.join(targetPath, CANONICAL_CLI_INDEX_SOURCE);\n\n if (await pathExists(legacyRootCliPath)) {\n diagnostics.push({\n code: 'field-invalid',\n message: 'Package CLI code must live under src/cli/; root src/cli.ts is not allowed.',\n path: legacyRootCliPath,\n profile,\n ruleId: 'package.cli.root-file.disallowed',\n severity: 'error',\n });\n }\n\n const packageJson = await readPackageJson(path.join(targetPath, 'package.json'));\n if (\n packageJson !== null &&\n exposesCliProvider(packageJson) &&\n !(await pathExists(canonicalCliIndexPath))\n ) {\n diagnostics.push({\n code: 'missing-path',\n message: 'CLI-capable packages must expose their provider from src/cli/index.ts.',\n path: canonicalCliIndexPath,\n profile,\n ruleId: 'package.cli.index.required',\n severity: 'error',\n });\n }\n\n return diagnostics;\n}\n\nfunction exposesCliProvider(packageJson: Record<string, unknown>): boolean {\n const ankh = isRecord(packageJson.ankh) ? packageJson.ankh : null;\n const exportsField = isRecord(packageJson.exports) ? packageJson.exports : null;\n\n return isNonEmptyString(ankh?.provider) || exportsField?.['./cli'] !== undefined;\n}\n\nasync function readPackageJson(packageJsonPath: string): Promise<Record<string, unknown> | null> {\n try {\n const parsed: unknown = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));\n return isRecord(parsed) ? parsed : null;\n } catch {\n return null;\n }\n}\n\nasync function pathExists(targetPath: string): Promise<boolean> {\n try {\n await fs.access(targetPath);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === 'string' && value.trim().length > 0;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n"]}
1
+ {"version":3,"file":"cliLayoutAnalysis.js","sourceRoot":"","sources":["../src/cliLayoutAnalysis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACL,mBA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AC,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc;IACtC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;AAC9D,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["import { promises as fs } from 'node:fs';\nimport path from 'node:path';\n\nimport {\n analyzeDoctorTarget,\n type DoctorAnalysisRequest,\n type DoctorAnalysisResult,\n} from './analysis.js';\nimport type { DoctorDiagnostic, DoctorPolicyProfile } from './diagnostics.js';\n\nconst LEGACY_ROOT_CLI_SOURCE = path.join('src', 'cli.ts');\nconst CANONICAL_CLI_INDEX_SOURCE = path.join('src', 'cli', 'index.ts');\nconst ACTIVE_SOURCE_ROOTS = ['src', 'app', 'apps', 'packages', 'scripts'] as const;\nconst ACTIVE_SOURCE_EXTENSIONS = new Set([\n '.cjs',\n '.cts',\n '.js',\n '.jsx',\n '.mjs',\n '.mts',\n '.ts',\n '.tsx',\n]);\nconst IGNORED_SOURCE_DIRECTORIES = new Set([\n '.expo',\n '.git',\n '.next',\n '__fixtures__',\n '__tests__',\n 'build',\n 'coverage',\n 'dist',\n 'docs',\n 'fixtures',\n 'node_modules',\n 'paradox',\n 'test',\n 'tests',\n]);\nconst COMPATIBILITY_PACKAGE_PREFIX = '@ankh/';\nconst STUDIO_PACKAGE_NAME = '@ankhorage/studio';\nconst STUDIO_DND_PACKAGE_NAME = '@ankhorage/react-native-reanimated-dnd-web';\nconst STUDIO_RUNTIME_PACKAGE_NAME = '@ankhorage/runtime';\nconst DEPENDENCY_FIELD_NAMES = [\n 'dependencies',\n 'devDependencies',\n 'optionalDependencies',\n 'peerDependencies',\n] as const;\n\ninterface ActiveSourceImport {\n readonly filePath: string;\n readonly specifier: string;\n}\n\ninterface DependencyEntry {\n readonly fieldName: (typeof DEPENDENCY_FIELD_NAMES)[number];\n readonly packageName: string;\n readonly version: string;\n}\n\nexport async function analyzeDoctorTargetWithCliLayout(\n request: DoctorAnalysisRequest,\n): Promise<DoctorAnalysisResult> {\n const result = await analyzeDoctorTarget(request);\n if (!result.hasPackageJson) {\n return result;\n }\n\n const packageJsonPath = path.join(result.targetPath, 'package.json');\n const packageJson = await readPackageJson(packageJsonPath);\n if (packageJson === null) {\n return result;\n }\n\n const architectureDiagnostics = await analyzeTargetArchitecture({\n packageJson,\n packageJsonPath,\n profile: result.profile,\n targetPath: result.targetPath,\n });\n if (architectureDiagnostics.length === 0) {\n return result;\n }\n\n const diagnostics = [...result.diagnostics, ...architectureDiagnostics];\n\n return {\n ...result,\n diagnostics,\n fixPlan: result.fixPlan === null ? null : { ...result.fixPlan, diagnostics },\n };\n}\n\nasync function analyzeTargetArchitecture(request: {\n readonly packageJson: Record<string, unknown>;\n readonly packageJsonPath: string;\n readonly profile: DoctorPolicyProfile;\n readonly targetPath: string;\n}): Promise<DoctorDiagnostic[]> {\n const diagnostics: DoctorDiagnostic[] = [];\n const legacyRootCliPath = path.join(request.targetPath, LEGACY_ROOT_CLI_SOURCE);\n const canonicalCliIndexPath = path.join(request.targetPath, CANONICAL_CLI_INDEX_SOURCE);\n const exportsField = isRecord(request.packageJson.exports) ? request.packageJson.exports : null;\n const cliCapable =\n hasAnkhProvider(request.packageJson) ||\n exportsField?.['./cli'] !== undefined ||\n (await pathExists(canonicalCliIndexPath));\n\n if (await pathExists(legacyRootCliPath)) {\n diagnostics.push({\n code: 'field-invalid',\n message: 'Package CLI code must live under src/cli/; root src/cli.ts is not allowed.',\n path: legacyRootCliPath,\n profile: request.profile,\n ruleId: 'package.cli.root-file.disallowed',\n severity: 'error',\n });\n }\n\n if (cliCapable && !(await pathExists(canonicalCliIndexPath))) {\n diagnostics.push({\n code: 'missing-path',\n message: 'CLI-capable packages must expose their provider from src/cli/index.ts.',\n path: canonicalCliIndexPath,\n profile: request.profile,\n ruleId: 'package.cli.index.required',\n severity: 'error',\n });\n }\n\n if (cliCapable && exportsField?.['./cli'] === undefined) {\n diagnostics.push({\n code: 'field-missing',\n message:\n 'CLI-capable packages must export \"./cli\" from package.json and point it at the owning src/cli/index.ts build output.',\n path: request.packageJsonPath,\n profile: request.profile,\n ruleId: 'package.cli.export.required',\n severity: 'error',\n });\n }\n\n const dependencyEntries = collectDependencyEntries(request.packageJson);\n diagnostics.push(\n ...validateDependencyArchitecture({\n dependencyEntries,\n packageJsonPath: request.packageJsonPath,\n profile: request.profile,\n }),\n );\n\n const activeSourceImports = await collectActiveSourceImports(request.targetPath);\n diagnostics.push(\n ...validateActiveSourceImports({\n activeSourceImports,\n profile: request.profile,\n }),\n );\n\n if (request.packageJson.name === STUDIO_PACKAGE_NAME) {\n diagnostics.push(\n ...validateStudioOwnership({\n activeSourceImports,\n dependencyEntries,\n packageJsonPath: request.packageJsonPath,\n profile: request.profile,\n }),\n );\n }\n\n return diagnostics;\n}\n\nfunction validateDependencyArchitecture(request: {\n readonly dependencyEntries: readonly DependencyEntry[];\n readonly packageJsonPath: string;\n readonly profile: DoctorPolicyProfile;\n}): DoctorDiagnostic[] {\n const diagnostics: DoctorDiagnostic[] = [];\n\n for (const dependency of request.dependencyEntries) {\n if (dependency.packageName.startsWith(COMPATIBILITY_PACKAGE_PREFIX)) {\n diagnostics.push({\n code: 'field-invalid',\n message: `Dependency \"${dependency.packageName}\" in package.json.${dependency.fieldName} is an old ankhorage4 workspace alias. Depend on \"${toOwningPackageSpecifier(dependency.packageName)}\" directly.`,\n path: request.packageJsonPath,\n profile: request.profile,\n ruleId: 'package.dependencies.ankh-workspace-alias.disallowed',\n severity: 'error',\n });\n }\n\n if (\n dependency.packageName.includes('ankhorage4') ||\n dependency.version.includes('ankhorage4')\n ) {\n diagnostics.push({\n code: 'field-invalid',\n message: `Dependency \"${dependency.packageName}\" references ankhorage4 as active source. Depend on the extracted owning @ankhorage/* package instead.`,\n path: request.packageJsonPath,\n profile: request.profile,\n ruleId: 'package.dependencies.ankhorage4-source.disallowed',\n severity: 'error',\n });\n }\n }\n\n return diagnostics;\n}\n\nfunction validateActiveSourceImports(request: {\n readonly activeSourceImports: readonly ActiveSourceImport[];\n readonly profile: DoctorPolicyProfile;\n}): DoctorDiagnostic[] {\n const diagnostics: DoctorDiagnostic[] = [];\n\n for (const sourceImport of request.activeSourceImports) {\n if (sourceImport.specifier.startsWith(COMPATIBILITY_PACKAGE_PREFIX)) {\n diagnostics.push({\n code: 'field-invalid',\n message: `Import \"${sourceImport.specifier}\" is an old ankhorage4 compatibility boundary. Import \"${toOwningPackageSpecifier(sourceImport.specifier)}\" directly from the owning package.`,\n path: sourceImport.filePath,\n profile: request.profile,\n ruleId: 'package.imports.ankh-workspace-alias.disallowed',\n severity: 'error',\n });\n }\n\n if (sourceImport.specifier.includes('ankhorage4')) {\n diagnostics.push({\n code: 'field-invalid',\n message: `Import \"${sourceImport.specifier}\" references ankhorage4 as active source. Import the extracted owning @ankhorage/* package instead.`,\n path: sourceImport.filePath,\n profile: request.profile,\n ruleId: 'package.imports.ankhorage4-source.disallowed',\n severity: 'error',\n });\n }\n }\n\n return diagnostics;\n}\n\nfunction validateStudioOwnership(request: {\n readonly activeSourceImports: readonly ActiveSourceImport[];\n readonly dependencyEntries: readonly DependencyEntry[];\n readonly packageJsonPath: string;\n readonly profile: DoctorPolicyProfile;\n}): DoctorDiagnostic[] {\n const diagnostics: DoctorDiagnostic[] = [];\n const directDependencies = new Set(\n request.dependencyEntries\n .filter((dependency) => dependency.fieldName === 'dependencies')\n .map((dependency) => dependency.packageName),\n );\n const importedSpecifiers = request.activeSourceImports.map(\n (sourceImport) => sourceImport.specifier,\n );\n\n if (!directDependencies.has(STUDIO_DND_PACKAGE_NAME)) {\n diagnostics.push({\n code: 'missing-dependency',\n message: `@ankhorage/studio must depend directly on \"${STUDIO_DND_PACKAGE_NAME}\" for Studio drag-and-drop ownership.`,\n path: request.packageJsonPath,\n profile: request.profile,\n ruleId: 'studio.dependencies.dnd.required',\n severity: 'error',\n });\n }\n\n if (!directDependencies.has(STUDIO_RUNTIME_PACKAGE_NAME)) {\n diagnostics.push({\n code: 'missing-dependency',\n message: `@ankhorage/studio must depend directly on \"${STUDIO_RUNTIME_PACKAGE_NAME}\" for runtime ownership.`,\n path: request.packageJsonPath,\n profile: request.profile,\n ruleId: 'studio.dependencies.runtime.required',\n severity: 'error',\n });\n }\n\n if (\n !importedSpecifiers.some((specifier) => isPackageImport(specifier, STUDIO_DND_PACKAGE_NAME))\n ) {\n diagnostics.push({\n code: 'field-missing',\n message: `@ankhorage/studio must import \"${STUDIO_DND_PACKAGE_NAME}\" directly from its Studio DnD boundary.`,\n path: request.packageJsonPath,\n profile: request.profile,\n ruleId: 'studio.imports.dnd.required',\n severity: 'error',\n });\n }\n\n if (\n !importedSpecifiers.some((specifier) => isPackageImport(specifier, STUDIO_RUNTIME_PACKAGE_NAME))\n ) {\n diagnostics.push({\n code: 'field-missing',\n message: `@ankhorage/studio must import \"${STUDIO_RUNTIME_PACKAGE_NAME}\" directly from the owning runtime package.`,\n path: request.packageJsonPath,\n profile: request.profile,\n ruleId: 'studio.imports.runtime.required',\n severity: 'error',\n });\n }\n\n return diagnostics;\n}\n\nasync function collectActiveSourceImports(targetPath: string): Promise<ActiveSourceImport[]> {\n const imports: ActiveSourceImport[] = [];\n\n for (const sourceRoot of ACTIVE_SOURCE_ROOTS) {\n const sourceRootPath = path.join(targetPath, sourceRoot);\n if (!(await pathExists(sourceRootPath))) {\n continue;\n }\n\n for (const filePath of await listActiveSourceFiles(sourceRootPath)) {\n const source = await fs.readFile(filePath, 'utf8');\n for (const specifier of extractImportSpecifiers(source)) {\n imports.push({ filePath, specifier });\n }\n }\n }\n\n return imports;\n}\n\nasync function listActiveSourceFiles(rootPath: string): Promise<string[]> {\n const files: string[] = [];\n await visit(rootPath);\n return files.sort((left, right) => left.localeCompare(right));\n\n async function visit(currentPath: string): Promise<void> {\n const entries = await fs.readdir(currentPath, { withFileTypes: true });\n\n for (const entry of entries) {\n if (entry.isDirectory()) {\n if (!IGNORED_SOURCE_DIRECTORIES.has(entry.name)) {\n await visit(path.join(currentPath, entry.name));\n }\n continue;\n }\n\n if (!entry.isFile()) {\n continue;\n }\n\n const filePath = path.join(currentPath, entry.name);\n if (isActiveSourceFile(filePath)) {\n files.push(filePath);\n }\n }\n }\n}\n\nfunction isActiveSourceFile(filePath: string): boolean {\n if (!ACTIVE_SOURCE_EXTENSIONS.has(path.extname(filePath))) {\n return false;\n }\n\n return !/(?:^|\\.)(?:spec|test)\\.[cm]?[jt]sx?$/.test(path.basename(filePath));\n}\n\nfunction extractImportSpecifiers(source: string): string[] {\n const specifiers = new Set<string>();\n const patterns = [\n /\\b(?:import|export)\\s+(?:type\\s+)?(?:[^;]*?\\sfrom\\s*)?['\"]([^'\"]+)['\"]/g,\n /\\b(?:import|require)\\s*\\(\\s*['\"]([^'\"]+)['\"]\\s*\\)/g,\n ];\n\n for (const pattern of patterns) {\n for (const match of source.matchAll(pattern)) {\n const [, specifier] = match;\n if (specifier !== undefined) {\n specifiers.add(specifier);\n }\n }\n }\n\n return [...specifiers].sort((left, right) => left.localeCompare(right));\n}\n\nfunction collectDependencyEntries(packageJson: Record<string, unknown>): DependencyEntry[] {\n const entries: DependencyEntry[] = [];\n\n for (const fieldName of DEPENDENCY_FIELD_NAMES) {\n const dependencies = isRecord(packageJson[fieldName]) ? packageJson[fieldName] : null;\n if (dependencies === null) {\n continue;\n }\n\n for (const [packageName, version] of Object.entries(dependencies)) {\n if (isNonEmptyString(version)) {\n entries.push({ fieldName, packageName, version });\n }\n }\n }\n\n return entries.sort((left, right) => {\n const fieldComparison = left.fieldName.localeCompare(right.fieldName);\n return fieldComparison !== 0\n ? fieldComparison\n : left.packageName.localeCompare(right.packageName);\n });\n}\n\nfunction hasAnkhProvider(packageJson: Record<string, unknown>): boolean {\n const ankh = isRecord(packageJson.ankh) ? packageJson.ankh : null;\n return isNonEmptyString(ankh?.provider);\n}\n\nfunction isPackageImport(specifier: string, packageName: string): boolean {\n return specifier === packageName || specifier.startsWith(`${packageName}/`);\n}\n\nfunction toOwningPackageSpecifier(specifier: string): string {\n return `@ankhorage/${specifier.slice(COMPATIBILITY_PACKAGE_PREFIX.length)}`;\n}\n\nasync function readPackageJson(packageJsonPath: string): Promise<Record<string, unknown> | null> {\n try {\n const parsed: unknown = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));\n return isRecord(parsed) ? parsed : null;\n } catch {\n return null;\n }\n}\n\nasync function pathExists(targetPath: string): Promise<boolean> {\n try {\n await fs.access(targetPath);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === 'string' && value.trim().length > 0;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  export type DoctorDiagnosticCode = 'field-invalid' | 'field-missing' | 'invalid-ankh-metadata' | 'invalid-package-json' | 'missing-dependency' | 'missing-path' | 'missing-script' | 'provider-source-import-failed' | 'provider-source-missing' | 'target-not-directory' | 'target-not-found' | 'unsupported-target';
2
2
  export type DoctorDiagnosticSeverity = 'error' | 'warning';
3
3
  export type DoctorPolicyProfile = 'integration-monorepo' | 'public-package' | 'unknown';
4
- export type DoctorRuleId = 'integration.package.ankh.disallowed' | 'integration.package.private.required' | 'integration.package.workspaces.required' | 'package.ankh.capabilities.match-provider' | 'package.ankh.present.valid-shape' | 'package.ankh.provider-path.required' | 'package.ankh.required-for-provider' | 'package.cli.index.required' | 'package.cli.root-file.disallowed' | 'package.dependencies.changesets.required' | 'package.dependencies.devtools.required' | 'package.dependencies.paradox.required' | 'package.dependencies.types-bun.required' | 'package.dependencies.types-node.required' | 'package.dependencies.typescript.required' | 'package.json.bugs.required' | 'package.json.description.required' | 'package.json.exports.required' | 'package.json.files.required' | 'package.json.homepage.required' | 'package.json.keywords.required' | 'package.json.license.required' | 'package.json.name.required' | 'package.json.package-manager.bun' | 'package.json.package-manager.required' | 'package.json.private.public-package-disallowed' | 'package.json.publish-config.public' | 'package.json.publish-config.required' | 'package.json.repository.required' | 'package.json.type.module' | 'package.json.type.required' | 'package.json.version.required' | 'package.scripts.build.required' | 'package.scripts.changeset-status.required' | 'package.scripts.changeset.required' | 'package.scripts.docs.required' | 'package.scripts.format-check.required' | 'package.scripts.format.required' | 'package.scripts.knip.required' | 'package.scripts.lint-fix.required' | 'package.scripts.lint.required' | 'package.scripts.test.required' | 'package.scripts.typecheck.required' | 'package.scripts.version-packages.required' | 'provider.commands.match-capabilities' | 'provider.commands.match-handlers' | 'provider.source.importable' | 'provider.source.required' | 'repo.changelog.required' | 'repo.changeset.required' | 'repo.license.required' | 'repo.readme.required' | 'repo.workflows.required' | 'target.package-json.required' | 'target.path.directory' | 'target.path.exists' | 'target.profile.supported' | 'target.repo-markers.required';
4
+ export type DoctorRuleId = 'integration.package.ankh.disallowed' | 'integration.package.private.required' | 'integration.package.workspaces.required' | 'package.ankh.capabilities.match-provider' | 'package.ankh.present.valid-shape' | 'package.ankh.provider-path.required' | 'package.ankh.required-for-provider' | 'package.cli.export.required' | 'package.cli.index.required' | 'package.cli.root-file.disallowed' | 'package.dependencies.ankh-workspace-alias.disallowed' | 'package.dependencies.ankhorage4-source.disallowed' | 'package.dependencies.changesets.required' | 'package.dependencies.devtools.required' | 'package.dependencies.paradox.required' | 'package.dependencies.types-bun.required' | 'package.dependencies.types-node.required' | 'package.dependencies.typescript.required' | 'package.imports.ankh-workspace-alias.disallowed' | 'package.imports.ankhorage4-source.disallowed' | 'package.json.bugs.required' | 'package.json.description.required' | 'package.json.exports.required' | 'package.json.files.required' | 'package.json.homepage.required' | 'package.json.keywords.required' | 'package.json.license.required' | 'package.json.name.required' | 'package.json.package-manager.bun' | 'package.json.package-manager.required' | 'package.json.private.public-package-disallowed' | 'package.json.publish-config.public' | 'package.json.publish-config.required' | 'package.json.repository.required' | 'package.json.type.module' | 'package.json.type.required' | 'package.json.version.required' | 'package.scripts.build.required' | 'package.scripts.changeset-status.required' | 'package.scripts.changeset.required' | 'package.scripts.docs.required' | 'package.scripts.format-check.required' | 'package.scripts.format.required' | 'package.scripts.knip.required' | 'package.scripts.lint-fix.required' | 'package.scripts.lint.required' | 'package.scripts.test.required' | 'package.scripts.typecheck.required' | 'package.scripts.version-packages.required' | 'provider.commands.match-capabilities' | 'provider.commands.match-handlers' | 'provider.source.importable' | 'provider.source.required' | 'repo.changelog.required' | 'repo.changeset.required' | 'repo.license.required' | 'repo.readme.required' | 'repo.workflows.required' | 'studio.dependencies.dnd.required' | 'studio.dependencies.runtime.required' | 'studio.imports.dnd.required' | 'studio.imports.runtime.required' | 'target.package-json.required' | 'target.path.directory' | 'target.path.exists' | 'target.profile.supported' | 'target.repo-markers.required';
5
5
  export interface DoctorDiagnostic {
6
6
  readonly code: DoctorDiagnosticCode;
7
7
  readonly message: string;
@@ -1 +1 @@
1
- {"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAC5B,eAAe,GACf,eAAe,GACf,uBAAuB,GACvB,sBAAsB,GACtB,oBAAoB,GACpB,cAAc,GACd,gBAAgB,GAChB,+BAA+B,GAC/B,yBAAyB,GACzB,sBAAsB,GACtB,kBAAkB,GAClB,oBAAoB,CAAC;AAEzB,MAAM,MAAM,wBAAwB,GAAG,OAAO,GAAG,SAAS,CAAC;AAC3D,MAAM,MAAM,mBAAmB,GAAG,sBAAsB,GAAG,gBAAgB,GAAG,SAAS,CAAC;AACxF,MAAM,MAAM,YAAY,GACpB,qCAAqC,GACrC,sCAAsC,GACtC,yCAAyC,GACzC,0CAA0C,GAC1C,kC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,4BAA4B,GAC5B,0BAA0B,GAC1B,yBAAyB,GACzB,yBAAyB,GACzB,uBAAuB,GACvB,sBAAsB,GACtB,yBAAyB,GACzB,kCAAkC,GAClC,sCAAsC,GACtC,6BAA6B,GAC7B,iCAAiC,GACjC,8BAA8B,GAC9B,uBAAuB,GACvB,oBAAoB,GACpB,0BAA0B,GAC1B,8BAA8B,CAAC;AAEnC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,wBAAwB,CAAC;CAC7C;AAED,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,SAAS,gBAAgB,EAAE,GAAG,MAAM,CAEtF;AAED,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,SAAS,gBAAgB,EAAE,GAAG,MAAM,CAExF"}
@@ -1 +1 @@
1
- {"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAqFA,MAAM,UAAU,qBAAqB,CAAC,WAAwC;IAC5E,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,MAAM,CAAC;AACpF,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,WAAwC;IAC9E,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,MAAM,CAAC;AACtF,CAAC","sourcesContent":["export type DoctorDiagnosticCode =\n | 'field-invalid'\n | 'field-missing'\n | 'invalid-ankh-metadata'\n | 'invalid-package-json'\n | 'missing-dependency'\n | 'missing-path'\n | 'missing-script'\n | 'provider-source-import-failed'\n | 'provider-source-missing'\n | 'target-not-directory'\n | 'target-not-found'\n | 'unsupported-target';\n\nexport type DoctorDiagnosticSeverity = 'error' | 'warning';\nexport type DoctorPolicyProfile = 'integration-monorepo' | 'public-package' | 'unknown';\nexport type DoctorRuleId =\n | 'integration.package.ankh.disallowed'\n | 'integration.package.private.required'\n | 'integration.package.workspaces.required'\n | 'package.ankh.capabilities.match-provider'\n | 'package.ankh.present.valid-shape'\n | 'package.ankh.provider-path.required'\n | 'package.ankh.required-for-provider'\n | 'package.cli.index.required'\n | 'package.cli.root-file.disallowed'\n | 'package.dependencies.changesets.required'\n | 'package.dependencies.devtools.required'\n | 'package.dependencies.paradox.required'\n | 'package.dependencies.types-bun.required'\n | 'package.dependencies.types-node.required'\n | 'package.dependencies.typescript.required'\n | 'package.json.bugs.required'\n | 'package.json.description.required'\n | 'package.json.exports.required'\n | 'package.json.files.required'\n | 'package.json.homepage.required'\n | 'package.json.keywords.required'\n | 'package.json.license.required'\n | 'package.json.name.required'\n | 'package.json.package-manager.bun'\n | 'package.json.package-manager.required'\n | 'package.json.private.public-package-disallowed'\n | 'package.json.publish-config.public'\n | 'package.json.publish-config.required'\n | 'package.json.repository.required'\n | 'package.json.type.module'\n | 'package.json.type.required'\n | 'package.json.version.required'\n | 'package.scripts.build.required'\n | 'package.scripts.changeset-status.required'\n | 'package.scripts.changeset.required'\n | 'package.scripts.docs.required'\n | 'package.scripts.format-check.required'\n | 'package.scripts.format.required'\n | 'package.scripts.knip.required'\n | 'package.scripts.lint-fix.required'\n | 'package.scripts.lint.required'\n | 'package.scripts.test.required'\n | 'package.scripts.typecheck.required'\n | 'package.scripts.version-packages.required'\n | 'provider.commands.match-capabilities'\n | 'provider.commands.match-handlers'\n | 'provider.source.importable'\n | 'provider.source.required'\n | 'repo.changelog.required'\n | 'repo.changeset.required'\n | 'repo.license.required'\n | 'repo.readme.required'\n | 'repo.workflows.required'\n | 'target.package-json.required'\n | 'target.path.directory'\n | 'target.path.exists'\n | 'target.profile.supported'\n | 'target.repo-markers.required';\n\nexport interface DoctorDiagnostic {\n readonly code: DoctorDiagnosticCode;\n readonly message: string;\n readonly path: string;\n readonly profile: DoctorPolicyProfile;\n readonly ruleId: DoctorRuleId;\n readonly severity: DoctorDiagnosticSeverity;\n}\n\nexport function countErrorDiagnostics(diagnostics: readonly DoctorDiagnostic[]): number {\n return diagnostics.filter((diagnostic) => diagnostic.severity === 'error').length;\n}\n\nexport function countWarningDiagnostics(diagnostics: readonly DoctorDiagnostic[]): number {\n return diagnostics.filter((diagnostic) => diagnostic.severity === 'warning').length;\n}\n"]}
1
+ {"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AA8FA,MAAM,UAAU,qBAAqB,CAAC,WAAwC;IAC5E,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,MAAM,CAAC;AACpF,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,WAAwC;IAC9E,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,MAAM,CAAC;AACtF,CAAC","sourcesContent":["export type DoctorDiagnosticCode =\n | 'field-invalid'\n | 'field-missing'\n | 'invalid-ankh-metadata'\n | 'invalid-package-json'\n | 'missing-dependency'\n | 'missing-path'\n | 'missing-script'\n | 'provider-source-import-failed'\n | 'provider-source-missing'\n | 'target-not-directory'\n | 'target-not-found'\n | 'unsupported-target';\n\nexport type DoctorDiagnosticSeverity = 'error' | 'warning';\nexport type DoctorPolicyProfile = 'integration-monorepo' | 'public-package' | 'unknown';\nexport type DoctorRuleId =\n | 'integration.package.ankh.disallowed'\n | 'integration.package.private.required'\n | 'integration.package.workspaces.required'\n | 'package.ankh.capabilities.match-provider'\n | 'package.ankh.present.valid-shape'\n | 'package.ankh.provider-path.required'\n | 'package.ankh.required-for-provider'\n | 'package.cli.export.required'\n | 'package.cli.index.required'\n | 'package.cli.root-file.disallowed'\n | 'package.dependencies.ankh-workspace-alias.disallowed'\n | 'package.dependencies.ankhorage4-source.disallowed'\n | 'package.dependencies.changesets.required'\n | 'package.dependencies.devtools.required'\n | 'package.dependencies.paradox.required'\n | 'package.dependencies.types-bun.required'\n | 'package.dependencies.types-node.required'\n | 'package.dependencies.typescript.required'\n | 'package.imports.ankh-workspace-alias.disallowed'\n | 'package.imports.ankhorage4-source.disallowed'\n | 'package.json.bugs.required'\n | 'package.json.description.required'\n | 'package.json.exports.required'\n | 'package.json.files.required'\n | 'package.json.homepage.required'\n | 'package.json.keywords.required'\n | 'package.json.license.required'\n | 'package.json.name.required'\n | 'package.json.package-manager.bun'\n | 'package.json.package-manager.required'\n | 'package.json.private.public-package-disallowed'\n | 'package.json.publish-config.public'\n | 'package.json.publish-config.required'\n | 'package.json.repository.required'\n | 'package.json.type.module'\n | 'package.json.type.required'\n | 'package.json.version.required'\n | 'package.scripts.build.required'\n | 'package.scripts.changeset-status.required'\n | 'package.scripts.changeset.required'\n | 'package.scripts.docs.required'\n | 'package.scripts.format-check.required'\n | 'package.scripts.format.required'\n | 'package.scripts.knip.required'\n | 'package.scripts.lint-fix.required'\n | 'package.scripts.lint.required'\n | 'package.scripts.test.required'\n | 'package.scripts.typecheck.required'\n | 'package.scripts.version-packages.required'\n | 'provider.commands.match-capabilities'\n | 'provider.commands.match-handlers'\n | 'provider.source.importable'\n | 'provider.source.required'\n | 'repo.changelog.required'\n | 'repo.changeset.required'\n | 'repo.license.required'\n | 'repo.readme.required'\n | 'repo.workflows.required'\n | 'studio.dependencies.dnd.required'\n | 'studio.dependencies.runtime.required'\n | 'studio.imports.dnd.required'\n | 'studio.imports.runtime.required'\n | 'target.package-json.required'\n | 'target.path.directory'\n | 'target.path.exists'\n | 'target.profile.supported'\n | 'target.repo-markers.required';\n\nexport interface DoctorDiagnostic {\n readonly code: DoctorDiagnosticCode;\n readonly message: string;\n readonly path: string;\n readonly profile: DoctorPolicyProfile;\n readonly ruleId: DoctorRuleId;\n readonly severity: DoctorDiagnosticSeverity;\n}\n\nexport function countErrorDiagnostics(diagnostics: readonly DoctorDiagnostic[]): number {\n return diagnostics.filter((diagnostic) => diagnostic.severity === 'error').length;\n}\n\nexport function countWarningDiagnostics(diagnostics: readonly DoctorDiagnostic[]): number {\n return diagnostics.filter((diagnostic) => diagnostic.severity === 'warning').length;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ankhorage/doctor",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Executable Ankh provider and standalone CLI for lightweight repo and package compliance diagnostics.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -10,6 +10,54 @@ import type { DoctorDiagnostic, DoctorPolicyProfile } from './diagnostics.js';
10
10
 
11
11
  const LEGACY_ROOT_CLI_SOURCE = path.join('src', 'cli.ts');
12
12
  const CANONICAL_CLI_INDEX_SOURCE = path.join('src', 'cli', 'index.ts');
13
+ const ACTIVE_SOURCE_ROOTS = ['src', 'app', 'apps', 'packages', 'scripts'] as const;
14
+ const ACTIVE_SOURCE_EXTENSIONS = new Set([
15
+ '.cjs',
16
+ '.cts',
17
+ '.js',
18
+ '.jsx',
19
+ '.mjs',
20
+ '.mts',
21
+ '.ts',
22
+ '.tsx',
23
+ ]);
24
+ const IGNORED_SOURCE_DIRECTORIES = new Set([
25
+ '.expo',
26
+ '.git',
27
+ '.next',
28
+ '__fixtures__',
29
+ '__tests__',
30
+ 'build',
31
+ 'coverage',
32
+ 'dist',
33
+ 'docs',
34
+ 'fixtures',
35
+ 'node_modules',
36
+ 'paradox',
37
+ 'test',
38
+ 'tests',
39
+ ]);
40
+ const COMPATIBILITY_PACKAGE_PREFIX = '@ankh/';
41
+ const STUDIO_PACKAGE_NAME = '@ankhorage/studio';
42
+ const STUDIO_DND_PACKAGE_NAME = '@ankhorage/react-native-reanimated-dnd-web';
43
+ const STUDIO_RUNTIME_PACKAGE_NAME = '@ankhorage/runtime';
44
+ const DEPENDENCY_FIELD_NAMES = [
45
+ 'dependencies',
46
+ 'devDependencies',
47
+ 'optionalDependencies',
48
+ 'peerDependencies',
49
+ ] as const;
50
+
51
+ interface ActiveSourceImport {
52
+ readonly filePath: string;
53
+ readonly specifier: string;
54
+ }
55
+
56
+ interface DependencyEntry {
57
+ readonly fieldName: (typeof DEPENDENCY_FIELD_NAMES)[number];
58
+ readonly packageName: string;
59
+ readonly version: string;
60
+ }
13
61
 
14
62
  export async function analyzeDoctorTargetWithCliLayout(
15
63
  request: DoctorAnalysisRequest,
@@ -19,12 +67,23 @@ export async function analyzeDoctorTargetWithCliLayout(
19
67
  return result;
20
68
  }
21
69
 
22
- const cliDiagnostics = await analyzeCliLayout(result.targetPath, result.profile);
23
- if (cliDiagnostics.length === 0) {
70
+ const packageJsonPath = path.join(result.targetPath, 'package.json');
71
+ const packageJson = await readPackageJson(packageJsonPath);
72
+ if (packageJson === null) {
73
+ return result;
74
+ }
75
+
76
+ const architectureDiagnostics = await analyzeTargetArchitecture({
77
+ packageJson,
78
+ packageJsonPath,
79
+ profile: result.profile,
80
+ targetPath: result.targetPath,
81
+ });
82
+ if (architectureDiagnostics.length === 0) {
24
83
  return result;
25
84
  }
26
85
 
27
- const diagnostics = [...result.diagnostics, ...cliDiagnostics];
86
+ const diagnostics = [...result.diagnostics, ...architectureDiagnostics];
28
87
 
29
88
  return {
30
89
  ...result,
@@ -33,49 +92,333 @@ export async function analyzeDoctorTargetWithCliLayout(
33
92
  };
34
93
  }
35
94
 
36
- async function analyzeCliLayout(
37
- targetPath: string,
38
- profile: DoctorPolicyProfile,
39
- ): Promise<DoctorDiagnostic[]> {
95
+ async function analyzeTargetArchitecture(request: {
96
+ readonly packageJson: Record<string, unknown>;
97
+ readonly packageJsonPath: string;
98
+ readonly profile: DoctorPolicyProfile;
99
+ readonly targetPath: string;
100
+ }): Promise<DoctorDiagnostic[]> {
40
101
  const diagnostics: DoctorDiagnostic[] = [];
41
- const legacyRootCliPath = path.join(targetPath, LEGACY_ROOT_CLI_SOURCE);
42
- const canonicalCliIndexPath = path.join(targetPath, CANONICAL_CLI_INDEX_SOURCE);
102
+ const legacyRootCliPath = path.join(request.targetPath, LEGACY_ROOT_CLI_SOURCE);
103
+ const canonicalCliIndexPath = path.join(request.targetPath, CANONICAL_CLI_INDEX_SOURCE);
104
+ const exportsField = isRecord(request.packageJson.exports) ? request.packageJson.exports : null;
105
+ const cliCapable =
106
+ hasAnkhProvider(request.packageJson) ||
107
+ exportsField?.['./cli'] !== undefined ||
108
+ (await pathExists(canonicalCliIndexPath));
43
109
 
44
110
  if (await pathExists(legacyRootCliPath)) {
45
111
  diagnostics.push({
46
112
  code: 'field-invalid',
47
113
  message: 'Package CLI code must live under src/cli/; root src/cli.ts is not allowed.',
48
114
  path: legacyRootCliPath,
49
- profile,
115
+ profile: request.profile,
50
116
  ruleId: 'package.cli.root-file.disallowed',
51
117
  severity: 'error',
52
118
  });
53
119
  }
54
120
 
55
- const packageJson = await readPackageJson(path.join(targetPath, 'package.json'));
56
- if (
57
- packageJson !== null &&
58
- exposesCliProvider(packageJson) &&
59
- !(await pathExists(canonicalCliIndexPath))
60
- ) {
121
+ if (cliCapable && !(await pathExists(canonicalCliIndexPath))) {
61
122
  diagnostics.push({
62
123
  code: 'missing-path',
63
124
  message: 'CLI-capable packages must expose their provider from src/cli/index.ts.',
64
125
  path: canonicalCliIndexPath,
65
- profile,
126
+ profile: request.profile,
66
127
  ruleId: 'package.cli.index.required',
67
128
  severity: 'error',
68
129
  });
69
130
  }
70
131
 
132
+ if (cliCapable && exportsField?.['./cli'] === undefined) {
133
+ diagnostics.push({
134
+ code: 'field-missing',
135
+ message:
136
+ 'CLI-capable packages must export "./cli" from package.json and point it at the owning src/cli/index.ts build output.',
137
+ path: request.packageJsonPath,
138
+ profile: request.profile,
139
+ ruleId: 'package.cli.export.required',
140
+ severity: 'error',
141
+ });
142
+ }
143
+
144
+ const dependencyEntries = collectDependencyEntries(request.packageJson);
145
+ diagnostics.push(
146
+ ...validateDependencyArchitecture({
147
+ dependencyEntries,
148
+ packageJsonPath: request.packageJsonPath,
149
+ profile: request.profile,
150
+ }),
151
+ );
152
+
153
+ const activeSourceImports = await collectActiveSourceImports(request.targetPath);
154
+ diagnostics.push(
155
+ ...validateActiveSourceImports({
156
+ activeSourceImports,
157
+ profile: request.profile,
158
+ }),
159
+ );
160
+
161
+ if (request.packageJson.name === STUDIO_PACKAGE_NAME) {
162
+ diagnostics.push(
163
+ ...validateStudioOwnership({
164
+ activeSourceImports,
165
+ dependencyEntries,
166
+ packageJsonPath: request.packageJsonPath,
167
+ profile: request.profile,
168
+ }),
169
+ );
170
+ }
171
+
172
+ return diagnostics;
173
+ }
174
+
175
+ function validateDependencyArchitecture(request: {
176
+ readonly dependencyEntries: readonly DependencyEntry[];
177
+ readonly packageJsonPath: string;
178
+ readonly profile: DoctorPolicyProfile;
179
+ }): DoctorDiagnostic[] {
180
+ const diagnostics: DoctorDiagnostic[] = [];
181
+
182
+ for (const dependency of request.dependencyEntries) {
183
+ if (dependency.packageName.startsWith(COMPATIBILITY_PACKAGE_PREFIX)) {
184
+ diagnostics.push({
185
+ code: 'field-invalid',
186
+ message: `Dependency "${dependency.packageName}" in package.json.${dependency.fieldName} is an old ankhorage4 workspace alias. Depend on "${toOwningPackageSpecifier(dependency.packageName)}" directly.`,
187
+ path: request.packageJsonPath,
188
+ profile: request.profile,
189
+ ruleId: 'package.dependencies.ankh-workspace-alias.disallowed',
190
+ severity: 'error',
191
+ });
192
+ }
193
+
194
+ if (
195
+ dependency.packageName.includes('ankhorage4') ||
196
+ dependency.version.includes('ankhorage4')
197
+ ) {
198
+ diagnostics.push({
199
+ code: 'field-invalid',
200
+ message: `Dependency "${dependency.packageName}" references ankhorage4 as active source. Depend on the extracted owning @ankhorage/* package instead.`,
201
+ path: request.packageJsonPath,
202
+ profile: request.profile,
203
+ ruleId: 'package.dependencies.ankhorage4-source.disallowed',
204
+ severity: 'error',
205
+ });
206
+ }
207
+ }
208
+
209
+ return diagnostics;
210
+ }
211
+
212
+ function validateActiveSourceImports(request: {
213
+ readonly activeSourceImports: readonly ActiveSourceImport[];
214
+ readonly profile: DoctorPolicyProfile;
215
+ }): DoctorDiagnostic[] {
216
+ const diagnostics: DoctorDiagnostic[] = [];
217
+
218
+ for (const sourceImport of request.activeSourceImports) {
219
+ if (sourceImport.specifier.startsWith(COMPATIBILITY_PACKAGE_PREFIX)) {
220
+ diagnostics.push({
221
+ code: 'field-invalid',
222
+ message: `Import "${sourceImport.specifier}" is an old ankhorage4 compatibility boundary. Import "${toOwningPackageSpecifier(sourceImport.specifier)}" directly from the owning package.`,
223
+ path: sourceImport.filePath,
224
+ profile: request.profile,
225
+ ruleId: 'package.imports.ankh-workspace-alias.disallowed',
226
+ severity: 'error',
227
+ });
228
+ }
229
+
230
+ if (sourceImport.specifier.includes('ankhorage4')) {
231
+ diagnostics.push({
232
+ code: 'field-invalid',
233
+ message: `Import "${sourceImport.specifier}" references ankhorage4 as active source. Import the extracted owning @ankhorage/* package instead.`,
234
+ path: sourceImport.filePath,
235
+ profile: request.profile,
236
+ ruleId: 'package.imports.ankhorage4-source.disallowed',
237
+ severity: 'error',
238
+ });
239
+ }
240
+ }
241
+
71
242
  return diagnostics;
72
243
  }
73
244
 
74
- function exposesCliProvider(packageJson: Record<string, unknown>): boolean {
245
+ function validateStudioOwnership(request: {
246
+ readonly activeSourceImports: readonly ActiveSourceImport[];
247
+ readonly dependencyEntries: readonly DependencyEntry[];
248
+ readonly packageJsonPath: string;
249
+ readonly profile: DoctorPolicyProfile;
250
+ }): DoctorDiagnostic[] {
251
+ const diagnostics: DoctorDiagnostic[] = [];
252
+ const directDependencies = new Set(
253
+ request.dependencyEntries
254
+ .filter((dependency) => dependency.fieldName === 'dependencies')
255
+ .map((dependency) => dependency.packageName),
256
+ );
257
+ const importedSpecifiers = request.activeSourceImports.map(
258
+ (sourceImport) => sourceImport.specifier,
259
+ );
260
+
261
+ if (!directDependencies.has(STUDIO_DND_PACKAGE_NAME)) {
262
+ diagnostics.push({
263
+ code: 'missing-dependency',
264
+ message: `@ankhorage/studio must depend directly on "${STUDIO_DND_PACKAGE_NAME}" for Studio drag-and-drop ownership.`,
265
+ path: request.packageJsonPath,
266
+ profile: request.profile,
267
+ ruleId: 'studio.dependencies.dnd.required',
268
+ severity: 'error',
269
+ });
270
+ }
271
+
272
+ if (!directDependencies.has(STUDIO_RUNTIME_PACKAGE_NAME)) {
273
+ diagnostics.push({
274
+ code: 'missing-dependency',
275
+ message: `@ankhorage/studio must depend directly on "${STUDIO_RUNTIME_PACKAGE_NAME}" for runtime ownership.`,
276
+ path: request.packageJsonPath,
277
+ profile: request.profile,
278
+ ruleId: 'studio.dependencies.runtime.required',
279
+ severity: 'error',
280
+ });
281
+ }
282
+
283
+ if (
284
+ !importedSpecifiers.some((specifier) => isPackageImport(specifier, STUDIO_DND_PACKAGE_NAME))
285
+ ) {
286
+ diagnostics.push({
287
+ code: 'field-missing',
288
+ message: `@ankhorage/studio must import "${STUDIO_DND_PACKAGE_NAME}" directly from its Studio DnD boundary.`,
289
+ path: request.packageJsonPath,
290
+ profile: request.profile,
291
+ ruleId: 'studio.imports.dnd.required',
292
+ severity: 'error',
293
+ });
294
+ }
295
+
296
+ if (
297
+ !importedSpecifiers.some((specifier) => isPackageImport(specifier, STUDIO_RUNTIME_PACKAGE_NAME))
298
+ ) {
299
+ diagnostics.push({
300
+ code: 'field-missing',
301
+ message: `@ankhorage/studio must import "${STUDIO_RUNTIME_PACKAGE_NAME}" directly from the owning runtime package.`,
302
+ path: request.packageJsonPath,
303
+ profile: request.profile,
304
+ ruleId: 'studio.imports.runtime.required',
305
+ severity: 'error',
306
+ });
307
+ }
308
+
309
+ return diagnostics;
310
+ }
311
+
312
+ async function collectActiveSourceImports(targetPath: string): Promise<ActiveSourceImport[]> {
313
+ const imports: ActiveSourceImport[] = [];
314
+
315
+ for (const sourceRoot of ACTIVE_SOURCE_ROOTS) {
316
+ const sourceRootPath = path.join(targetPath, sourceRoot);
317
+ if (!(await pathExists(sourceRootPath))) {
318
+ continue;
319
+ }
320
+
321
+ for (const filePath of await listActiveSourceFiles(sourceRootPath)) {
322
+ const source = await fs.readFile(filePath, 'utf8');
323
+ for (const specifier of extractImportSpecifiers(source)) {
324
+ imports.push({ filePath, specifier });
325
+ }
326
+ }
327
+ }
328
+
329
+ return imports;
330
+ }
331
+
332
+ async function listActiveSourceFiles(rootPath: string): Promise<string[]> {
333
+ const files: string[] = [];
334
+ await visit(rootPath);
335
+ return files.sort((left, right) => left.localeCompare(right));
336
+
337
+ async function visit(currentPath: string): Promise<void> {
338
+ const entries = await fs.readdir(currentPath, { withFileTypes: true });
339
+
340
+ for (const entry of entries) {
341
+ if (entry.isDirectory()) {
342
+ if (!IGNORED_SOURCE_DIRECTORIES.has(entry.name)) {
343
+ await visit(path.join(currentPath, entry.name));
344
+ }
345
+ continue;
346
+ }
347
+
348
+ if (!entry.isFile()) {
349
+ continue;
350
+ }
351
+
352
+ const filePath = path.join(currentPath, entry.name);
353
+ if (isActiveSourceFile(filePath)) {
354
+ files.push(filePath);
355
+ }
356
+ }
357
+ }
358
+ }
359
+
360
+ function isActiveSourceFile(filePath: string): boolean {
361
+ if (!ACTIVE_SOURCE_EXTENSIONS.has(path.extname(filePath))) {
362
+ return false;
363
+ }
364
+
365
+ return !/(?:^|\.)(?:spec|test)\.[cm]?[jt]sx?$/.test(path.basename(filePath));
366
+ }
367
+
368
+ function extractImportSpecifiers(source: string): string[] {
369
+ const specifiers = new Set<string>();
370
+ const patterns = [
371
+ /\b(?:import|export)\s+(?:type\s+)?(?:[^;]*?\sfrom\s*)?['"]([^'"]+)['"]/g,
372
+ /\b(?:import|require)\s*\(\s*['"]([^'"]+)['"]\s*\)/g,
373
+ ];
374
+
375
+ for (const pattern of patterns) {
376
+ for (const match of source.matchAll(pattern)) {
377
+ const [, specifier] = match;
378
+ if (specifier !== undefined) {
379
+ specifiers.add(specifier);
380
+ }
381
+ }
382
+ }
383
+
384
+ return [...specifiers].sort((left, right) => left.localeCompare(right));
385
+ }
386
+
387
+ function collectDependencyEntries(packageJson: Record<string, unknown>): DependencyEntry[] {
388
+ const entries: DependencyEntry[] = [];
389
+
390
+ for (const fieldName of DEPENDENCY_FIELD_NAMES) {
391
+ const dependencies = isRecord(packageJson[fieldName]) ? packageJson[fieldName] : null;
392
+ if (dependencies === null) {
393
+ continue;
394
+ }
395
+
396
+ for (const [packageName, version] of Object.entries(dependencies)) {
397
+ if (isNonEmptyString(version)) {
398
+ entries.push({ fieldName, packageName, version });
399
+ }
400
+ }
401
+ }
402
+
403
+ return entries.sort((left, right) => {
404
+ const fieldComparison = left.fieldName.localeCompare(right.fieldName);
405
+ return fieldComparison !== 0
406
+ ? fieldComparison
407
+ : left.packageName.localeCompare(right.packageName);
408
+ });
409
+ }
410
+
411
+ function hasAnkhProvider(packageJson: Record<string, unknown>): boolean {
75
412
  const ankh = isRecord(packageJson.ankh) ? packageJson.ankh : null;
76
- const exportsField = isRecord(packageJson.exports) ? packageJson.exports : null;
413
+ return isNonEmptyString(ankh?.provider);
414
+ }
415
+
416
+ function isPackageImport(specifier: string, packageName: string): boolean {
417
+ return specifier === packageName || specifier.startsWith(`${packageName}/`);
418
+ }
77
419
 
78
- return isNonEmptyString(ankh?.provider) || exportsField?.['./cli'] !== undefined;
420
+ function toOwningPackageSpecifier(specifier: string): string {
421
+ return `@ankhorage/${specifier.slice(COMPATIBILITY_PACKAGE_PREFIX.length)}`;
79
422
  }
80
423
 
81
424
  async function readPackageJson(packageJsonPath: string): Promise<Record<string, unknown> | null> {
@@ -22,14 +22,19 @@ export type DoctorRuleId =
22
22
  | 'package.ankh.present.valid-shape'
23
23
  | 'package.ankh.provider-path.required'
24
24
  | 'package.ankh.required-for-provider'
25
+ | 'package.cli.export.required'
25
26
  | 'package.cli.index.required'
26
27
  | 'package.cli.root-file.disallowed'
28
+ | 'package.dependencies.ankh-workspace-alias.disallowed'
29
+ | 'package.dependencies.ankhorage4-source.disallowed'
27
30
  | 'package.dependencies.changesets.required'
28
31
  | 'package.dependencies.devtools.required'
29
32
  | 'package.dependencies.paradox.required'
30
33
  | 'package.dependencies.types-bun.required'
31
34
  | 'package.dependencies.types-node.required'
32
35
  | 'package.dependencies.typescript.required'
36
+ | 'package.imports.ankh-workspace-alias.disallowed'
37
+ | 'package.imports.ankhorage4-source.disallowed'
33
38
  | 'package.json.bugs.required'
34
39
  | 'package.json.description.required'
35
40
  | 'package.json.exports.required'
@@ -68,6 +73,10 @@ export type DoctorRuleId =
68
73
  | 'repo.license.required'
69
74
  | 'repo.readme.required'
70
75
  | 'repo.workflows.required'
76
+ | 'studio.dependencies.dnd.required'
77
+ | 'studio.dependencies.runtime.required'
78
+ | 'studio.imports.dnd.required'
79
+ | 'studio.imports.runtime.required'
71
80
  | 'target.package-json.required'
72
81
  | 'target.path.directory'
73
82
  | 'target.path.exists'