@blankways/ui 0.0.0-stage → 0.2.0-alpha.1
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/README.md +246 -2
- package/dist/cli/cli.options.d.ts +5 -0
- package/dist/cli/cli.options.js +73 -0
- package/dist/cli/cli.registry.d.ts +6 -0
- package/dist/cli/cli.registry.js +37 -0
- package/dist/cli/cli.types.d.ts +33 -0
- package/dist/cli/cli.types.js +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.js +3 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +48 -0
- package/dist/commands/add.command.d.ts +4 -0
- package/dist/commands/add.command.js +49 -0
- package/dist/commands/dev.command.d.ts +3 -0
- package/dist/commands/dev.command.js +76 -0
- package/dist/commands/doctor.command.d.ts +3 -0
- package/dist/commands/doctor.command.js +103 -0
- package/dist/commands/index.d.ts +9 -0
- package/dist/commands/index.js +9 -0
- package/dist/commands/init.command.d.ts +2 -0
- package/dist/commands/init.command.js +43 -0
- package/dist/commands/install.command.d.ts +2 -0
- package/dist/commands/install.command.js +36 -0
- package/dist/commands/list.command.d.ts +2 -0
- package/dist/commands/list.command.js +59 -0
- package/dist/commands/meta.command.d.ts +1 -0
- package/dist/commands/meta.command.js +19 -0
- package/dist/commands/registry.command.d.ts +2 -0
- package/dist/commands/registry.command.js +69 -0
- package/dist/commands/styles.command.d.ts +5 -0
- package/dist/commands/styles.command.js +44 -0
- package/dist/config/config.helpers.d.ts +10 -0
- package/dist/config/config.helpers.js +116 -0
- package/dist/config/framework.helpers.d.ts +3 -0
- package/dist/config/framework.helpers.js +14 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +2 -0
- package/dist/constants/cli.constants.d.ts +20 -0
- package/dist/constants/cli.constants.js +20 -0
- package/dist/constants/framework.constants.d.ts +3 -0
- package/dist/constants/framework.constants.js +2 -0
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.js +2 -0
- package/dist/doctor/checks/barrels.check.d.ts +1 -0
- package/dist/doctor/checks/barrels.check.js +60 -0
- package/dist/doctor/checks/contracts.check.d.ts +1 -0
- package/dist/doctor/checks/contracts.check.js +45 -0
- package/dist/doctor/checks/entries.check.d.ts +1 -0
- package/dist/doctor/checks/entries.check.js +21 -0
- package/dist/doctor/checks/icons.check.d.ts +1 -0
- package/dist/doctor/checks/icons.check.js +60 -0
- package/dist/doctor/checks/imports.check.d.ts +1 -0
- package/dist/doctor/checks/imports.check.js +45 -0
- package/dist/doctor/checks/index.d.ts +10 -0
- package/dist/doctor/checks/index.js +10 -0
- package/dist/doctor/checks/motion.check.d.ts +1 -0
- package/dist/doctor/checks/motion.check.js +66 -0
- package/dist/doctor/checks/namespaces.check.d.ts +1 -0
- package/dist/doctor/checks/namespaces.check.js +76 -0
- package/dist/doctor/checks/peers.check.d.ts +1 -0
- package/dist/doctor/checks/peers.check.js +55 -0
- package/dist/doctor/checks/styles.check.d.ts +1 -0
- package/dist/doctor/checks/styles.check.js +45 -0
- package/dist/doctor/checks/themes.check.d.ts +1 -0
- package/dist/doctor/checks/themes.check.js +42 -0
- package/dist/doctor/doctor.helpers.d.ts +6 -0
- package/dist/doctor/doctor.helpers.js +43 -0
- package/dist/doctor/doctor.registry.d.ts +10 -0
- package/dist/doctor/doctor.registry.js +24 -0
- package/dist/doctor/doctor.types.d.ts +31 -0
- package/dist/doctor/doctor.types.js +1 -0
- package/dist/doctor/index.d.ts +3 -0
- package/dist/doctor/index.js +3 -0
- package/dist/errors/cli-error.d.ts +3 -0
- package/dist/errors/cli-error.js +6 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/helpers/args.helpers.d.ts +6 -0
- package/dist/helpers/args.helpers.js +84 -0
- package/dist/helpers/barrels.helpers.d.ts +15 -0
- package/dist/helpers/barrels.helpers.js +157 -0
- package/dist/helpers/help.helpers.d.ts +1 -0
- package/dist/helpers/help.helpers.js +30 -0
- package/dist/helpers/index.d.ts +5 -0
- package/dist/helpers/index.js +5 -0
- package/dist/helpers/package.helpers.d.ts +2 -0
- package/dist/helpers/package.helpers.js +12 -0
- package/dist/helpers/path.helpers.d.ts +3 -0
- package/dist/helpers/path.helpers.js +15 -0
- package/dist/helpers/styles.helpers.d.ts +21 -0
- package/dist/helpers/styles.helpers.js +164 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +11 -0
- package/dist/registry/index.d.ts +3 -0
- package/dist/registry/index.js +3 -0
- package/dist/registry/lockfile.d.ts +18 -0
- package/dist/registry/lockfile.js +32 -0
- package/dist/registry/registry.helpers.d.ts +12 -0
- package/dist/registry/registry.helpers.js +242 -0
- package/dist/registry/registry.providers.d.ts +13 -0
- package/dist/registry/registry.providers.js +159 -0
- package/dist/registry/registry.service.d.ts +14 -0
- package/dist/registry/registry.service.js +126 -0
- package/dist/types/cli.types.d.ts +6 -0
- package/dist/types/cli.types.js +1 -0
- package/dist/types/config.types.d.ts +70 -0
- package/dist/types/config.types.js +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +3 -0
- package/dist/types/registry.types.d.ts +68 -0
- package/dist/types/registry.types.js +3 -0
- package/dist/ui-api/index.d.ts +16 -0
- package/dist/ui-api/index.js +30 -0
- package/dist/ui-api/ui-api.d.ts +18 -0
- package/dist/ui-api/ui-api.js +194 -0
- package/package.json +37 -3
- package/styles.css +16 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { BASE_STYLE_IMPORT } from '../../constants/index.js';
|
|
4
|
+
import { toDisplayPath } from '../../helpers/path.helpers.js';
|
|
5
|
+
import { getInstalledItems, isFile } from '../doctor.helpers.js';
|
|
6
|
+
import { registerDoctorCheck } from '../doctor.registry.js';
|
|
7
|
+
registerDoctorCheck({
|
|
8
|
+
id: 'barrels',
|
|
9
|
+
async run(context) {
|
|
10
|
+
const problems = [];
|
|
11
|
+
const themesBarrel = join(context.componentsDir, 'themes', 'index.css');
|
|
12
|
+
const runtimesBarrel = join(context.componentsDir, 'runtimes', 'index.ts');
|
|
13
|
+
const installed = await getInstalledItems(context);
|
|
14
|
+
if (!(await isFile(themesBarrel))) {
|
|
15
|
+
problems.push({
|
|
16
|
+
level: 'error',
|
|
17
|
+
message: `${context.displayDir}/themes/index.css is missing. Run "ui install".`
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
const content = await readFile(themesBarrel, 'utf8');
|
|
22
|
+
if (!content.includes(`@import '${BASE_STYLE_IMPORT}';`)) {
|
|
23
|
+
problems.push({
|
|
24
|
+
level: 'error',
|
|
25
|
+
message: `${context.displayDir}/themes/index.css does not import ${BASE_STYLE_IMPORT}`
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
for (const item of installed) {
|
|
29
|
+
for (const file of item.files) {
|
|
30
|
+
if (!file.target.startsWith('themes/') || file.target.endsWith('index.css'))
|
|
31
|
+
continue;
|
|
32
|
+
const name = file.target.slice('themes/'.length);
|
|
33
|
+
if (!content.includes(`@import './${name}';`)) {
|
|
34
|
+
problems.push({
|
|
35
|
+
level: 'warn',
|
|
36
|
+
message: `${context.displayDir}/themes/index.css is missing ${name}`
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const hasRuntimes = installed.some(item => item.files.some(file => file.target.startsWith('runtimes/') && !file.target.endsWith('/index.ts')));
|
|
43
|
+
if (hasRuntimes && !(await isFile(runtimesBarrel))) {
|
|
44
|
+
problems.push({
|
|
45
|
+
level: 'error',
|
|
46
|
+
message: `${context.displayDir}/runtimes/index.ts is missing. Run "ui install".`
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (context.globalCss && (await isFile(context.globalCss))) {
|
|
50
|
+
const css = await readFile(context.globalCss, 'utf8');
|
|
51
|
+
if (!css.includes('themes/index.css')) {
|
|
52
|
+
problems.push({
|
|
53
|
+
level: 'warn',
|
|
54
|
+
message: `${toDisplayPath(context.cwd, context.globalCss)} does not import the themes barrel`
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return { summary: 'generated entry points', problems };
|
|
59
|
+
}
|
|
60
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { registerDoctorCheck } from '../doctor.registry.js';
|
|
2
|
+
const ROOTS = ['components', 'themes', 'runtimes'];
|
|
3
|
+
registerDoctorCheck({
|
|
4
|
+
id: 'contracts',
|
|
5
|
+
async run(context) {
|
|
6
|
+
const problems = [];
|
|
7
|
+
const items = context.items ?? [];
|
|
8
|
+
const providers = context.providers ?? [];
|
|
9
|
+
const ids = new Map();
|
|
10
|
+
for (const provider of providers) {
|
|
11
|
+
const owner = ids.get(provider.id);
|
|
12
|
+
if (owner) {
|
|
13
|
+
problems.push({
|
|
14
|
+
level: 'error',
|
|
15
|
+
message: `Duplicate registry id "${provider.id}" (${owner}, ${provider.specifier})`
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
ids.set(provider.id, provider.specifier);
|
|
19
|
+
}
|
|
20
|
+
const available = new Set(items.map(item => `${item.id}:${item.name}`));
|
|
21
|
+
for (const item of items) {
|
|
22
|
+
const allowed = ROOTS.map(root => `${root}/${item.id}/`);
|
|
23
|
+
for (const file of item.files) {
|
|
24
|
+
if (!allowed.some(prefix => file.target.startsWith(prefix))) {
|
|
25
|
+
problems.push({
|
|
26
|
+
level: 'error',
|
|
27
|
+
message: `${item.id}:${item.name} → ${file.target} escapes its namespace`
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
for (const request of item.requires) {
|
|
32
|
+
if (!available.has(request)) {
|
|
33
|
+
problems.push({
|
|
34
|
+
level: 'error',
|
|
35
|
+
message: `${item.id}:${item.name} requires "${request}" which is not configured`
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
summary: `${items.length} entries, ${providers.length} registries`,
|
|
42
|
+
problems
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CLI_NAME } from '../../constants/index.js';
|
|
2
|
+
import { getInstalledItems } from '../doctor.helpers.js';
|
|
3
|
+
import { registerDoctorCheck } from '../doctor.registry.js';
|
|
4
|
+
registerDoctorCheck({
|
|
5
|
+
id: 'entries',
|
|
6
|
+
async run(context) {
|
|
7
|
+
if (context.files.length === 0) {
|
|
8
|
+
return {
|
|
9
|
+
summary: 'none detected',
|
|
10
|
+
problems: [
|
|
11
|
+
{
|
|
12
|
+
level: 'warn',
|
|
13
|
+
message: `No files found in ${context.displayDir}/. Run "${CLI_NAME} add button" first.`
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const items = await getInstalledItems(context);
|
|
19
|
+
return { summary: `${items.length} detected` };
|
|
20
|
+
}
|
|
21
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { toDisplayPath } from '../../helpers/path.helpers.js';
|
|
3
|
+
import { localNames } from '../doctor.helpers.js';
|
|
4
|
+
import { registerDoctorCheck } from '../doctor.registry.js';
|
|
5
|
+
function parseIconExports(content) {
|
|
6
|
+
const names = new Set();
|
|
7
|
+
const reexport = /export\s*\{([^}]*)\}\s*from\s*['"][^'"]+['"]/g;
|
|
8
|
+
const declaration = /export\s+(?:function|const|class)\s+(\w+)/g;
|
|
9
|
+
for (const match of content.matchAll(reexport)) {
|
|
10
|
+
for (const name of localNames(match[1]))
|
|
11
|
+
names.add(name);
|
|
12
|
+
}
|
|
13
|
+
for (const match of content.matchAll(declaration))
|
|
14
|
+
names.add(match[1]);
|
|
15
|
+
return names;
|
|
16
|
+
}
|
|
17
|
+
function parseIconImports(content) {
|
|
18
|
+
const names = new Set();
|
|
19
|
+
const pattern = /import\s*\{([^}]*)\}\s*from\s*['"][^'"]*\/icons\/[^'"]+['"]/g;
|
|
20
|
+
for (const match of content.matchAll(pattern)) {
|
|
21
|
+
for (const name of localNames(match[1]))
|
|
22
|
+
names.add(name);
|
|
23
|
+
}
|
|
24
|
+
return Array.from(names);
|
|
25
|
+
}
|
|
26
|
+
registerDoctorCheck({
|
|
27
|
+
id: 'icons',
|
|
28
|
+
async run(context) {
|
|
29
|
+
const iconFiles = context.files.filter(file => /[\\/]icons[\\/].*\.tsx?$/.test(file));
|
|
30
|
+
if (iconFiles.length === 0)
|
|
31
|
+
return null;
|
|
32
|
+
const iconFileSet = new Set(iconFiles);
|
|
33
|
+
const exported = new Set();
|
|
34
|
+
for (const file of iconFiles) {
|
|
35
|
+
const content = await readFile(file, 'utf8');
|
|
36
|
+
for (const name of parseIconExports(content))
|
|
37
|
+
exported.add(name);
|
|
38
|
+
}
|
|
39
|
+
let checked = 0;
|
|
40
|
+
const problems = [];
|
|
41
|
+
for (const file of context.sourceFiles) {
|
|
42
|
+
if (iconFileSet.has(file))
|
|
43
|
+
continue;
|
|
44
|
+
const content = await readFile(file, 'utf8');
|
|
45
|
+
for (const name of parseIconImports(content)) {
|
|
46
|
+
checked += 1;
|
|
47
|
+
if (!exported.has(name)) {
|
|
48
|
+
problems.push({
|
|
49
|
+
level: 'error',
|
|
50
|
+
message: `${toDisplayPath(context.cwd, file)} imports "${name}" not exported from any icons module`
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
summary: `${checked} imports checked${problems.length > 0 ? `, ${problems.length} missing` : ''}`,
|
|
57
|
+
problems
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, extname, join, resolve } from 'node:path';
|
|
3
|
+
import { toDisplayPath } from '../../helpers/path.helpers.js';
|
|
4
|
+
import { isFile } from '../doctor.helpers.js';
|
|
5
|
+
import { registerDoctorCheck } from '../doctor.registry.js';
|
|
6
|
+
async function resolveImportTarget(specifier, fromFile) {
|
|
7
|
+
const base = resolve(dirname(fromFile), specifier);
|
|
8
|
+
const candidates = [base];
|
|
9
|
+
if (base.endsWith('.js')) {
|
|
10
|
+
candidates.push(base.replace(/\.js$/, '.ts'), base.replace(/\.js$/, '.tsx'), base.replace(/\.js$/, '.jsx'));
|
|
11
|
+
}
|
|
12
|
+
else if (!extname(base)) {
|
|
13
|
+
candidates.push(`${base}.ts`, `${base}.tsx`, `${base}.js`, join(base, 'index.ts'), join(base, 'index.tsx'));
|
|
14
|
+
}
|
|
15
|
+
for (const candidate of candidates) {
|
|
16
|
+
if (await isFile(candidate))
|
|
17
|
+
return candidate;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
registerDoctorCheck({
|
|
22
|
+
id: 'imports',
|
|
23
|
+
async run(context) {
|
|
24
|
+
let resolved = 0;
|
|
25
|
+
const problems = [];
|
|
26
|
+
for (const file of context.sourceFiles) {
|
|
27
|
+
const content = await readFile(file, 'utf8');
|
|
28
|
+
for (const match of content.matchAll(/from\s+['"](\.{1,2}\/[^'"]+)['"]/g)) {
|
|
29
|
+
if (await resolveImportTarget(match[1], file)) {
|
|
30
|
+
resolved += 1;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
problems.push({
|
|
34
|
+
level: 'error',
|
|
35
|
+
message: `${toDisplayPath(context.cwd, file)} → ${match[1]} (missing)`
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
summary: `${resolved} resolved${problems.length > 0 ? `, ${problems.length} broken` : ''}`,
|
|
42
|
+
problems
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import './contracts.check.js';
|
|
2
|
+
import './namespaces.check.js';
|
|
3
|
+
import './barrels.check.js';
|
|
4
|
+
import './imports.check.js';
|
|
5
|
+
import './icons.check.js';
|
|
6
|
+
import './themes.check.js';
|
|
7
|
+
import './entries.check.js';
|
|
8
|
+
import './styles.check.js';
|
|
9
|
+
import './peers.check.js';
|
|
10
|
+
import './motion.check.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import './contracts.check.js';
|
|
2
|
+
import './namespaces.check.js';
|
|
3
|
+
import './barrels.check.js';
|
|
4
|
+
import './imports.check.js';
|
|
5
|
+
import './icons.check.js';
|
|
6
|
+
import './themes.check.js';
|
|
7
|
+
import './entries.check.js';
|
|
8
|
+
import './styles.check.js';
|
|
9
|
+
import './peers.check.js';
|
|
10
|
+
import './motion.check.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { CLI_NAME } from '../../constants/index.js';
|
|
3
|
+
import { registerDoctorCheck } from '../doctor.registry.js';
|
|
4
|
+
const MOTION_CLASS = /\b(?:motion-(?:color|fade|fade-slow|transform|press|lift|focus|icon-swap|ripple)|reveal-up|stagger-(?:children|words)|stagger-word|surface-enter|popup-enter|backdrop-enter|toast-enter|progress-life|tabs-indicator|sidebar-shell|sidebar-drawer|sidebar-label|sidebar-chevron|sidebar-highlight|shimmer|shake|check-draw)\b/;
|
|
5
|
+
registerDoctorCheck({
|
|
6
|
+
id: 'motion',
|
|
7
|
+
async run(context) {
|
|
8
|
+
const hasMotionStyles = context.files.some(file => /[\\/]themes[\\/].*motion\.css$/.test(file));
|
|
9
|
+
if (hasMotionStyles)
|
|
10
|
+
return null;
|
|
11
|
+
const matches = await Promise.all(context.sourceFiles.map(async (file) => {
|
|
12
|
+
try {
|
|
13
|
+
return MOTION_CLASS.test(await readFile(file, 'utf8'));
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}));
|
|
19
|
+
if (!matches.some(Boolean))
|
|
20
|
+
return null;
|
|
21
|
+
const problems = [
|
|
22
|
+
{
|
|
23
|
+
level: 'warn',
|
|
24
|
+
message: `Motion utilities are in use but ${context.displayDir}/themes/<id>/motion.css is missing. Run "${CLI_NAME} add styles-motion".`,
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
return { summary: 'motion styles missing, 1 issue', problems };
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const FORBIDDEN_IMPORTS = /from\s+['"]((?:motion|framer-motion|motion\/react|@animate-ui\/react(?:\/[^'"]*)?|@base-ui\/react(?:\/[^'"]*)?|radix-ui(?:[^'"]*)?))['"]/;
|
|
31
|
+
const FORBIDDEN_HOOKS = /\b(useInView|useParallax|useReducedMotion|useScrolled)\s*\(/;
|
|
32
|
+
registerDoctorCheck({
|
|
33
|
+
id: 'motion-policy',
|
|
34
|
+
async run(context) {
|
|
35
|
+
const problems = [];
|
|
36
|
+
await Promise.all(context.sourceFiles.map(async (file) => {
|
|
37
|
+
let content;
|
|
38
|
+
try {
|
|
39
|
+
content = await readFile(file, 'utf8');
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const importMatch = content.match(FORBIDDEN_IMPORTS);
|
|
45
|
+
if (importMatch) {
|
|
46
|
+
problems.push({
|
|
47
|
+
level: 'error',
|
|
48
|
+
message: `${file} imports ${importMatch[1]}; animation libraries are not allowed. Use styles-motion utilities instead.`,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const hookMatch = content.match(FORBIDDEN_HOOKS);
|
|
52
|
+
if (hookMatch) {
|
|
53
|
+
problems.push({
|
|
54
|
+
level: 'error',
|
|
55
|
+
message: `${file} calls ${hookMatch[1]}; motion hooks are not allowed. Publish semantic state and animate with CSS.`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
59
|
+
if (problems.length === 0)
|
|
60
|
+
return null;
|
|
61
|
+
return {
|
|
62
|
+
summary: `motion policy violations, ${problems.length} issue${problems.length === 1 ? '' : 's'}`,
|
|
63
|
+
problems: problems.sort((a, b) => a.message.localeCompare(b.message)),
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { join, sep } from 'node:path';
|
|
3
|
+
import { posix } from 'node:path';
|
|
4
|
+
import { toDisplayPath } from '../../helpers/path.helpers.js';
|
|
5
|
+
import { isFile } from '../doctor.helpers.js';
|
|
6
|
+
import { registerDoctorCheck } from '../doctor.registry.js';
|
|
7
|
+
const RELATIVE_IMPORT = /(?:from\s*|import\s*\(\s*|import\s*)['"](\.{1,2}\/[^'"]+)['"]/g;
|
|
8
|
+
function toPosix(path) {
|
|
9
|
+
return path.split(sep).join('/');
|
|
10
|
+
}
|
|
11
|
+
function peerOf(target) {
|
|
12
|
+
return target.split('/')[1] ?? '';
|
|
13
|
+
}
|
|
14
|
+
function ownerOf(items, target) {
|
|
15
|
+
return items.find(item => item.files.some(file => file.target === target));
|
|
16
|
+
}
|
|
17
|
+
async function resolveTarget(specifier, fromTarget, root) {
|
|
18
|
+
const base = posix.normalize(posix.join(posix.dirname(fromTarget), specifier));
|
|
19
|
+
const extension = posix.extname(base);
|
|
20
|
+
const candidates = [base];
|
|
21
|
+
if (extension === '.js' || extension === '.jsx' || extension === '.mjs') {
|
|
22
|
+
const stem = base.slice(0, -extension.length);
|
|
23
|
+
candidates.push(`${stem}.ts`, `${stem}.tsx`, `${stem}.js`, `${stem}.jsx`);
|
|
24
|
+
}
|
|
25
|
+
else if (extension === '') {
|
|
26
|
+
candidates.push(`${base}.ts`, `${base}.tsx`, `${base}.js`, `${base}.jsx`, posix.join(base, 'index.ts'), posix.join(base, 'index.tsx'));
|
|
27
|
+
}
|
|
28
|
+
for (const candidate of candidates) {
|
|
29
|
+
if (await isFile(join(root, ...candidate.split('/'))))
|
|
30
|
+
return candidate;
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
registerDoctorCheck({
|
|
35
|
+
id: 'namespaces',
|
|
36
|
+
async run(context) {
|
|
37
|
+
const problems = [];
|
|
38
|
+
const items = context.items ?? [];
|
|
39
|
+
let checked = 0;
|
|
40
|
+
let crossed = 0;
|
|
41
|
+
for (const file of context.sourceFiles) {
|
|
42
|
+
const target = toPosix(file.slice(context.componentsDir.length + 1));
|
|
43
|
+
if (target.endsWith('/index.ts'))
|
|
44
|
+
continue;
|
|
45
|
+
const owner = ownerOf(items, target);
|
|
46
|
+
if (!owner)
|
|
47
|
+
continue;
|
|
48
|
+
const content = await readFile(file, 'utf8');
|
|
49
|
+
for (const match of content.matchAll(RELATIVE_IMPORT)) {
|
|
50
|
+
const resolved = await resolveTarget(match[1], target, context.componentsDir);
|
|
51
|
+
if (!resolved)
|
|
52
|
+
continue;
|
|
53
|
+
checked += 1;
|
|
54
|
+
const dependency = ownerOf(items, resolved);
|
|
55
|
+
const targetPeer = peerOf(resolved);
|
|
56
|
+
if (!targetPeer || targetPeer === owner.id)
|
|
57
|
+
continue;
|
|
58
|
+
crossed += 1;
|
|
59
|
+
const declared = dependency
|
|
60
|
+
? owner.requires.includes(`${dependency.id}:${dependency.name}`)
|
|
61
|
+
: owner.requires.some(request => request.startsWith(`${targetPeer}:`));
|
|
62
|
+
if (!declared) {
|
|
63
|
+
const expected = dependency ? `${dependency.id}:${dependency.name}` : `${targetPeer}:*`;
|
|
64
|
+
problems.push({
|
|
65
|
+
level: 'error',
|
|
66
|
+
message: `${toDisplayPath(context.cwd, file)} crosses ${targetPeer} without requires "${expected}"`
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
summary: `${checked} imports checked, ${crossed} cross-peer${problems.length > 0 ? `, ${problems.length} undeclared` : ''}`,
|
|
73
|
+
problems
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { getInstalledItems, readJsonFile } from '../doctor.helpers.js';
|
|
3
|
+
import { registerDoctorCheck } from '../doctor.registry.js';
|
|
4
|
+
function parsePeerSpec(spec) {
|
|
5
|
+
const at = spec.startsWith('@') ? spec.indexOf('@', 1) : spec.indexOf('@');
|
|
6
|
+
if (at === -1)
|
|
7
|
+
return { name: spec };
|
|
8
|
+
return { name: spec.slice(0, at), version: spec.slice(at + 1) };
|
|
9
|
+
}
|
|
10
|
+
function normalizeVersion(version) {
|
|
11
|
+
return version.trim().replace(/^[~^]/, '');
|
|
12
|
+
}
|
|
13
|
+
registerDoctorCheck({
|
|
14
|
+
id: 'peers',
|
|
15
|
+
async run(context) {
|
|
16
|
+
const items = await getInstalledItems(context);
|
|
17
|
+
const specs = Array.from(new Set(items.flatMap(item => item.peers))).map(parsePeerSpec);
|
|
18
|
+
let project = {};
|
|
19
|
+
try {
|
|
20
|
+
project = await readJsonFile(join(context.cwd, 'package.json'));
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
project = {};
|
|
24
|
+
}
|
|
25
|
+
const installed = {
|
|
26
|
+
...project.dependencies,
|
|
27
|
+
...project.devDependencies
|
|
28
|
+
};
|
|
29
|
+
const problems = [];
|
|
30
|
+
let satisfied = 0;
|
|
31
|
+
for (const { name, version } of specs) {
|
|
32
|
+
const declared = installed[name];
|
|
33
|
+
const install = `${name}${version ? `@${version}` : ''}`;
|
|
34
|
+
if (typeof declared !== 'string') {
|
|
35
|
+
problems.push({
|
|
36
|
+
level: 'warn',
|
|
37
|
+
message: `${name} is not listed in package.json. Install it with: pnpm add ${install}`
|
|
38
|
+
});
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (version && normalizeVersion(declared) !== version) {
|
|
42
|
+
problems.push({
|
|
43
|
+
level: 'warn',
|
|
44
|
+
message: `${install} is required, but package.json declares ${declared}. Install it with: pnpm add ${install}`
|
|
45
|
+
});
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
satisfied += 1;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
summary: `${satisfied}/${specs.length} satisfied${problems.length > 0 ? ` (${problems.length} pending)` : ''}`,
|
|
52
|
+
problems
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { CLI_NAME } from '../../constants/index.js';
|
|
4
|
+
import { toDisplayPath } from '../../helpers/path.helpers.js';
|
|
5
|
+
import { findGlobalStylesheet } from '../../helpers/styles.helpers.js';
|
|
6
|
+
import { isFile } from '../doctor.helpers.js';
|
|
7
|
+
import { registerDoctorCheck } from '../doctor.registry.js';
|
|
8
|
+
registerDoctorCheck({
|
|
9
|
+
id: 'styles',
|
|
10
|
+
async run(context) {
|
|
11
|
+
const styleFiles = context.files.filter(file => /[\\/]styles[\\/].*\.css$/.test(file));
|
|
12
|
+
if (styleFiles.length === 0)
|
|
13
|
+
return null;
|
|
14
|
+
const barrelPath = join(context.componentsDir, 'styles', 'index.css');
|
|
15
|
+
const problems = [];
|
|
16
|
+
if (!(await isFile(barrelPath))) {
|
|
17
|
+
problems.push({
|
|
18
|
+
level: 'warn',
|
|
19
|
+
message: `${context.displayDir}/styles/index.css is missing. Run "${CLI_NAME} styles link".`
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const globalCss = await findGlobalStylesheet(context.cwd, barrelPath, context.globalCss);
|
|
24
|
+
if (!globalCss) {
|
|
25
|
+
problems.push({
|
|
26
|
+
level: 'warn',
|
|
27
|
+
message: `No global stylesheet found. Use --global-css with "${CLI_NAME} styles link".`
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
const content = await readFile(globalCss, 'utf8');
|
|
32
|
+
if (!/@import\s+['"][^'"]*styles\/index\.css['"]/.test(content)) {
|
|
33
|
+
problems.push({
|
|
34
|
+
level: 'warn',
|
|
35
|
+
message: `${toDisplayPath(context.cwd, globalCss)} does not import ${context.displayDir}/styles/index.css.`
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
summary: `${styleFiles.length} css files${problems.length > 0 ? `, ${problems.length} issues` : ''}`,
|
|
42
|
+
problems
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { getInstalledItems } from '../doctor.helpers.js';
|
|
3
|
+
import { registerDoctorCheck } from '../doctor.registry.js';
|
|
4
|
+
const DECLARED_THEME = /\[data-(?:[\w-]+-)?theme\s*=\s*['"]([^'"]+)['"]\]/g;
|
|
5
|
+
registerDoctorCheck({
|
|
6
|
+
id: 'themes',
|
|
7
|
+
async run(context) {
|
|
8
|
+
const problems = [];
|
|
9
|
+
const declared = new Set((await getInstalledItems(context)).flatMap(item => item.themes));
|
|
10
|
+
const cssThemes = new Set();
|
|
11
|
+
let cssFiles = 0;
|
|
12
|
+
for (const file of context.files) {
|
|
13
|
+
if (!/[\\/]themes[\\/].*\.css$/.test(file) || file.endsWith('index.css'))
|
|
14
|
+
continue;
|
|
15
|
+
cssFiles += 1;
|
|
16
|
+
const content = await readFile(file, 'utf8');
|
|
17
|
+
for (const match of content.matchAll(DECLARED_THEME))
|
|
18
|
+
cssThemes.add(match[1]);
|
|
19
|
+
}
|
|
20
|
+
for (const name of declared) {
|
|
21
|
+
if (!cssThemes.has(name)) {
|
|
22
|
+
problems.push({
|
|
23
|
+
level: 'warn',
|
|
24
|
+
message: `Theme "${name}" is declared but has no CSS block.`
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
for (const name of cssThemes) {
|
|
29
|
+
if (!declared.has(name)) {
|
|
30
|
+
problems.push({
|
|
31
|
+
level: 'warn',
|
|
32
|
+
message: `CSS theme "${name}" is not declared by any registry entry.`
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const names = Array.from(new Set([...declared, ...cssThemes])).sort();
|
|
37
|
+
return {
|
|
38
|
+
summary: `${names.length} themes in ${cssFiles} files (${names.join(', ') || 'none'})${problems.length > 0 ? `, ${problems.length} mismatches` : ''}`,
|
|
39
|
+
problems
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RegistryItem } from '../types/registry.types.js';
|
|
2
|
+
import type { DoctorContext } from './doctor.types.js';
|
|
3
|
+
export declare function isFile(path: string): Promise<boolean>;
|
|
4
|
+
export declare function readJsonFile(path: string): Promise<Record<string, unknown>>;
|
|
5
|
+
export declare function localNames(block: string): string[];
|
|
6
|
+
export declare function getInstalledItems(context: DoctorContext): Promise<RegistryItem[]>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { listRegistryItems } from '../registry/index.js';
|
|
4
|
+
export async function isFile(path) {
|
|
5
|
+
try {
|
|
6
|
+
return (await stat(path)).isFile();
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export async function readJsonFile(path) {
|
|
13
|
+
const content = (await readFile(path, 'utf8')).replace(/^\uFEFF/, '');
|
|
14
|
+
return JSON.parse(content);
|
|
15
|
+
}
|
|
16
|
+
export function localNames(block) {
|
|
17
|
+
return block
|
|
18
|
+
.split(',')
|
|
19
|
+
.map(part => part.trim())
|
|
20
|
+
.filter(Boolean)
|
|
21
|
+
.map(part => part.split(/\s+as\s+/).pop().trim());
|
|
22
|
+
}
|
|
23
|
+
export async function getInstalledItems(context) {
|
|
24
|
+
const installed = [];
|
|
25
|
+
for (const item of await listRegistryItems({
|
|
26
|
+
cwd: context.cwd,
|
|
27
|
+
framework: context.framework,
|
|
28
|
+
registries: context.registries ?? []
|
|
29
|
+
})) {
|
|
30
|
+
if (item.hidden || item.files.length === 0)
|
|
31
|
+
continue;
|
|
32
|
+
let present = true;
|
|
33
|
+
for (const file of item.files) {
|
|
34
|
+
if (!(await isFile(resolve(context.componentsDir, file.target)))) {
|
|
35
|
+
present = false;
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (present)
|
|
40
|
+
installed.push(item);
|
|
41
|
+
}
|
|
42
|
+
return installed;
|
|
43
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DoctorCheck } from './doctor.types.js';
|
|
2
|
+
export type DoctorRegistry = {
|
|
3
|
+
register(check: DoctorCheck): void;
|
|
4
|
+
list(): readonly DoctorCheck[];
|
|
5
|
+
clear(): void;
|
|
6
|
+
};
|
|
7
|
+
export declare function createDoctorRegistry(): DoctorRegistry;
|
|
8
|
+
export declare const doctorRegistry: DoctorRegistry;
|
|
9
|
+
export declare function registerDoctorCheck(check: DoctorCheck): void;
|
|
10
|
+
export declare function getDoctorChecks(): readonly DoctorCheck[];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function createDoctorRegistry() {
|
|
2
|
+
const checks = [];
|
|
3
|
+
return {
|
|
4
|
+
register(check) {
|
|
5
|
+
if (checks.some(item => item.id === check.id)) {
|
|
6
|
+
throw new Error(`Doctor check "${check.id}" is already registered.`);
|
|
7
|
+
}
|
|
8
|
+
checks.push(check);
|
|
9
|
+
},
|
|
10
|
+
list() {
|
|
11
|
+
return [...checks];
|
|
12
|
+
},
|
|
13
|
+
clear() {
|
|
14
|
+
checks.length = 0;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export const doctorRegistry = createDoctorRegistry();
|
|
19
|
+
export function registerDoctorCheck(check) {
|
|
20
|
+
doctorRegistry.register(check);
|
|
21
|
+
}
|
|
22
|
+
export function getDoctorChecks() {
|
|
23
|
+
return doctorRegistry.list();
|
|
24
|
+
}
|