@bleedingdev/modern-js-create 3.2.0-ultramodern.21 → 3.2.0-ultramodern.22

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.
@@ -1,83 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
-
4
- const root = process.cwd();
5
- const scanRoots = ['apps'].map((scanRoot) => path.join(root, scanRoot));
6
- const ignoredDirectories = new Set(['.modern', '.modernjs', 'dist', 'node_modules']);
7
- const visibleAttributePattern =
8
- /\s(?:aria-label|alt|placeholder|title)=["']([^"']*[A-Za-z][^"']*)["']/gu;
9
- const jsxTextPattern = />([^<>{}]*[A-Za-z][^<>{}]*)</gu;
10
-
11
- const collectFiles = (directory) => {
12
- if (!fs.existsSync(directory)) {
13
- return [];
14
- }
15
-
16
- const files = [];
17
- for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
18
- if (entry.isDirectory()) {
19
- if (!ignoredDirectories.has(entry.name)) {
20
- files.push(...collectFiles(path.join(directory, entry.name)));
21
- }
22
- continue;
23
- }
24
-
25
- if (entry.isFile() && /\.(jsx|tsx)$/u.test(entry.name) && !entry.name.endsWith('.d.ts')) {
26
- files.push(path.join(directory, entry.name));
27
- }
28
- }
29
- return files;
30
- };
31
-
32
- const lineNumberForIndex = (content, index) => content.slice(0, index).split('\n').length;
33
- const isIgnoredLine = (content, index) => {
34
- const lineStart = content.lastIndexOf('\n', index) + 1;
35
- const lineEnd = content.indexOf('\n', index);
36
- const currentLineEnd = lineEnd === -1 ? content.length : lineEnd;
37
- const previousLineStart = content.lastIndexOf('\n', Math.max(0, lineStart - 2)) + 1;
38
- const nextLineEnd = content.indexOf('\n', currentLineEnd + 1);
39
- const context = content.slice(
40
- previousLineStart,
41
- nextLineEnd === -1 ? content.length : nextLineEnd,
42
- );
43
- return /i18n-ignore/u.test(context);
44
- };
45
-
46
- const violations = [];
47
- for (const filePath of scanRoots.flatMap(collectFiles)) {
48
- const content = fs.readFileSync(filePath, 'utf-8');
49
- for (const match of content.matchAll(visibleAttributePattern)) {
50
- if (!isIgnoredLine(content, match.index ?? 0)) {
51
- violations.push({
52
- filePath,
53
- line: lineNumberForIndex(content, match.index ?? 0),
54
- text: match[1].trim(),
55
- });
56
- }
57
- }
58
-
59
- for (const match of content.matchAll(jsxTextPattern)) {
60
- const text = match[1].replaceAll(/\s+/gu, ' ').trim();
61
- if (text && !isIgnoredLine(content, match.index ?? 0)) {
62
- violations.push({
63
- filePath,
64
- line: lineNumberForIndex(content, match.index ?? 0),
65
- text,
66
- });
67
- }
68
- }
69
- }
70
-
71
- if (violations.length > 0) {
72
- console.error('Hardcoded user-visible JSX strings found. Move copy to locale JSON files.');
73
- for (const violation of violations) {
74
- console.error(
75
- `${path.relative(root, violation.filePath)}:${violation.line} ${JSON.stringify(
76
- violation.text,
77
- )}`,
78
- );
79
- }
80
- process.exit(1);
81
- }
82
-
83
- console.log('No hardcoded user-visible JSX strings found.');