@bleedingdev/modern-js-create 3.2.0-ultramodern.110 → 3.2.0-ultramodern.111

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.
Files changed (35) hide show
  1. package/dist/cjs/index.cjs +2 -0
  2. package/dist/cjs/ultramodern-package-source.cjs +2 -0
  3. package/dist/cjs/ultramodern-workspace.cjs +10 -3
  4. package/dist/esm/index.js +2 -0
  5. package/dist/esm/ultramodern-package-source.js +2 -0
  6. package/dist/esm/ultramodern-workspace.js +10 -3
  7. package/dist/esm-node/index.js +2 -0
  8. package/dist/esm-node/ultramodern-package-source.js +2 -0
  9. package/dist/esm-node/ultramodern-workspace.js +10 -3
  10. package/dist/types/ultramodern-package-source.d.ts +2 -2
  11. package/package.json +4 -29
  12. package/template/package.json.handlebars +1 -0
  13. package/template/scripts/check-i18n-strings.mjs +1 -1
  14. package/template/scripts/validate-ultramodern.mjs.handlebars +3 -2
  15. package/template/tests/ultramodern.contract.test.ts.handlebars +4 -1
  16. package/dist/cjs/ultramodern-checks/cli/i18n-check.cjs +0 -73
  17. package/dist/cjs/ultramodern-checks/cli/oxlint.cjs +0 -174
  18. package/dist/cjs/ultramodern-checks/cli/workspace-source-check.cjs +0 -179
  19. package/dist/cjs/ultramodern-checks/index.cjs +0 -58
  20. package/dist/cjs/ultramodern-checks/oxlint-plugin.cjs +0 -354
  21. package/dist/esm/ultramodern-checks/cli/i18n-check.js +0 -26
  22. package/dist/esm/ultramodern-checks/cli/oxlint.js +0 -118
  23. package/dist/esm/ultramodern-checks/cli/workspace-source-check.js +0 -124
  24. package/dist/esm/ultramodern-checks/index.js +0 -3
  25. package/dist/esm/ultramodern-checks/oxlint-plugin.js +0 -316
  26. package/dist/esm-node/ultramodern-checks/cli/i18n-check.js +0 -27
  27. package/dist/esm-node/ultramodern-checks/cli/oxlint.js +0 -119
  28. package/dist/esm-node/ultramodern-checks/cli/workspace-source-check.js +0 -125
  29. package/dist/esm-node/ultramodern-checks/index.js +0 -4
  30. package/dist/esm-node/ultramodern-checks/oxlint-plugin.js +0 -317
  31. package/dist/types/ultramodern-checks/cli/i18n-check.d.ts +0 -9
  32. package/dist/types/ultramodern-checks/cli/oxlint.d.ts +0 -22
  33. package/dist/types/ultramodern-checks/cli/workspace-source-check.d.ts +0 -8
  34. package/dist/types/ultramodern-checks/index.d.ts +0 -3
  35. package/dist/types/ultramodern-checks/oxlint-plugin.d.ts +0 -63
@@ -1,179 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.n = (module)=>{
5
- var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
- __webpack_require__.d(getter, {
7
- a: getter
8
- });
9
- return getter;
10
- };
11
- })();
12
- (()=>{
13
- __webpack_require__.d = (exports1, getters, values)=>{
14
- var define = (defs, kind)=>{
15
- for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
- enumerable: true,
17
- [kind]: defs[key]
18
- });
19
- };
20
- define(getters, "get");
21
- define(values, "value");
22
- };
23
- })();
24
- (()=>{
25
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
- })();
27
- (()=>{
28
- __webpack_require__.r = (exports1)=>{
29
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
- value: 'Module'
31
- });
32
- Object.defineProperty(exports1, '__esModule', {
33
- value: true
34
- });
35
- };
36
- })();
37
- var __webpack_exports__ = {};
38
- __webpack_require__.r(__webpack_exports__);
39
- __webpack_require__.d(__webpack_exports__, {
40
- WORKSPACE_SOURCE_SUCCESS: ()=>WORKSPACE_SOURCE_SUCCESS,
41
- main: ()=>main,
42
- runWorkspaceSourceCheck: ()=>runWorkspaceSourceCheck
43
- });
44
- const external_node_fs_namespaceObject = require("node:fs");
45
- var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
46
- const external_node_path_namespaceObject = require("node:path");
47
- var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
48
- const external_oxlint_cjs_namespaceObject = require("./oxlint.cjs");
49
- const WORKSPACE_SOURCE_SUCCESS = 'UltraModern i18n and boundary guardrails validated';
50
- const ignoredDirectories = new Set([
51
- '.modern',
52
- '.modernjs',
53
- '.output',
54
- 'dist',
55
- 'node_modules'
56
- ]);
57
- const normalizePath = (filePath)=>filePath.replaceAll('\\', '/');
58
- const relativePath = (root, filePath)=>normalizePath(external_node_path_default().relative(root, filePath));
59
- const walk = (directory, files = [])=>{
60
- if (!external_node_fs_default().existsSync(directory)) return files;
61
- for (const entry of external_node_fs_default().readdirSync(directory, {
62
- withFileTypes: true
63
- })){
64
- if (entry.isDirectory() && ignoredDirectories.has(entry.name)) continue;
65
- const entryPath = external_node_path_default().join(directory, entry.name);
66
- if (entry.isDirectory()) {
67
- walk(entryPath, files);
68
- continue;
69
- }
70
- if (entry.isFile()) files.push(entryPath);
71
- }
72
- return files;
73
- };
74
- const isSourceFile = (filePath)=>/\.(?:ts|tsx|js|jsx)$/u.test(filePath);
75
- const isLocaleJson = (root, filePath)=>/\/locales\/(?:en|cs)\/[^/]+\.json$/u.test(`/${relativePath(root, filePath)}`);
76
- const readText = (filePath)=>external_node_fs_default().readFileSync(filePath, 'utf-8');
77
- const checkRuntimeResources = (root, filePath, text)=>{
78
- const relative = relativePath(root, filePath);
79
- if (!relative.endsWith('/src/modern.runtime.ts')) return;
80
- const importsLocaleResources = /import\s+csResource\s+from\s+['"]\.\.\/locales\/cs\/[^'"]+\.json['"]/u.test(text) && /import\s+enResource\s+from\s+['"]\.\.\/locales\/en\/[^'"]+\.json['"]/u.test(text);
81
- if (!importsLocaleResources || !/initOptions\s*:\s*\{[\s\S]*?\bresources\s*,/u.test(text)) throw new Error(`${relative} must register locale JSON resources in modern.runtime.ts so Worker SSR and hydration use the same first-render translations.`);
82
- };
83
- const visitLocaleKeys = (value, visitor, pathParts = [])=>{
84
- if (!value || 'object' != typeof value || Array.isArray(value)) return;
85
- for (const [key, child] of Object.entries(value)){
86
- const nextPath = [
87
- ...pathParts,
88
- key
89
- ];
90
- visitor(key, child, nextPath);
91
- visitLocaleKeys(child, visitor, nextPath);
92
- }
93
- };
94
- const checkPluralResources = (root, filePath, json)=>{
95
- const relative = relativePath(root, filePath);
96
- const language = relative.split('/locales/')[1]?.split('/')[0];
97
- const requiredSuffixes = 'cs' === language ? [
98
- 'one',
99
- 'few',
100
- 'many',
101
- 'other'
102
- ] : [
103
- 'one',
104
- 'other'
105
- ];
106
- const groups = new Map();
107
- visitLocaleKeys(json, (key, value, pathParts)=>{
108
- if ('string' != typeof value || !value.includes('{{count}}')) return;
109
- const suffixMatch = key.match(/^(.*)_(one|few|many|other)$/u);
110
- if (!suffixMatch) throw new Error(`${relative} key ${pathParts.join('.')} contains {{count}} but is not plural-suffixed.`);
111
- const [, base = '', suffix = ''] = suffixMatch;
112
- const parentPath = pathParts.slice(0, -1).join('.');
113
- const groupKey = `${parentPath}.${base}`;
114
- const existing = groups.get(groupKey) ?? new Set();
115
- existing.add(suffix);
116
- groups.set(groupKey, existing);
117
- });
118
- for (const [group, suffixes] of groups)for (const suffix of requiredSuffixes)if (!suffixes.has(suffix)) throw new Error(`${relative} plural group ${group} is missing _${suffix}.`);
119
- };
120
- const runRuntimeAndLocaleResourceChecks = (root, sourceRoots)=>{
121
- const files = sourceRoots.flatMap((sourceRoot)=>walk(external_node_path_default().join(root, sourceRoot)));
122
- for (const filePath of files.filter(isSourceFile))checkRuntimeResources(root, filePath, readText(filePath));
123
- for (const filePath of files.filter((filePath)=>isLocaleJson(root, filePath)))checkPluralResources(root, filePath, JSON.parse(readText(filePath)));
124
- };
125
- const runWorkspaceSourceCheck = ({ cwd = process.cwd(), sourceRoots = [
126
- 'apps',
127
- 'verticals'
128
- ] } = {})=>{
129
- const oxlintResult = (0, external_oxlint_cjs_namespaceObject.runOxlintRules)({
130
- cwd,
131
- targets: sourceRoots,
132
- rules: {
133
- 'ultramodern/no-legacy-mf-boundary-attributes': 'error',
134
- 'ultramodern/no-literal-visible-jsx-attributes': [
135
- 'error',
136
- {
137
- visibleAttributes: [
138
- 'aria-label',
139
- "aria-description",
140
- "aria-roledescription",
141
- 'aria-valuetext',
142
- 'alt',
143
- 'label',
144
- 'placeholder',
145
- 'title'
146
- ]
147
- }
148
- ],
149
- 'ultramodern/no-manual-locale-copy-branching': 'error',
150
- 'ultramodern/no-split-translation-keys': 'error'
151
- }
152
- });
153
- if (0 !== oxlintResult.exitCode) {
154
- (0, external_oxlint_cjs_namespaceObject.printOxlintOutput)(oxlintResult);
155
- return oxlintResult.exitCode;
156
- }
157
- try {
158
- runRuntimeAndLocaleResourceChecks(cwd, sourceRoots);
159
- } catch (error) {
160
- console.error(error instanceof Error ? error.message : 'UltraModern workspace source checks failed.');
161
- return 1;
162
- }
163
- console.log(WORKSPACE_SOURCE_SUCCESS);
164
- return 0;
165
- };
166
- const main = ()=>{
167
- process.exitCode = runWorkspaceSourceCheck();
168
- };
169
- exports.WORKSPACE_SOURCE_SUCCESS = __webpack_exports__.WORKSPACE_SOURCE_SUCCESS;
170
- exports.main = __webpack_exports__.main;
171
- exports.runWorkspaceSourceCheck = __webpack_exports__.runWorkspaceSourceCheck;
172
- for(var __rspack_i in __webpack_exports__)if (-1 === [
173
- "WORKSPACE_SOURCE_SUCCESS",
174
- "main",
175
- "runWorkspaceSourceCheck"
176
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
177
- Object.defineProperty(exports, '__esModule', {
178
- value: true
179
- });
@@ -1,58 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.n = (module)=>{
5
- var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
- __webpack_require__.d(getter, {
7
- a: getter
8
- });
9
- return getter;
10
- };
11
- })();
12
- (()=>{
13
- __webpack_require__.d = (exports1, getters, values)=>{
14
- var define = (defs, kind)=>{
15
- for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
- enumerable: true,
17
- [kind]: defs[key]
18
- });
19
- };
20
- define(getters, "get");
21
- define(values, "value");
22
- };
23
- })();
24
- (()=>{
25
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
- })();
27
- (()=>{
28
- __webpack_require__.r = (exports1)=>{
29
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
- value: 'Module'
31
- });
32
- Object.defineProperty(exports1, '__esModule', {
33
- value: true
34
- });
35
- };
36
- })();
37
- var __webpack_exports__ = {};
38
- __webpack_require__.r(__webpack_exports__);
39
- __webpack_require__.d(__webpack_exports__, {
40
- oxlintPlugin: ()=>external_oxlint_plugin_cjs_default(),
41
- runSingleAppI18nCheck: ()=>i18n_check_cjs_namespaceObject.runSingleAppI18nCheck,
42
- runWorkspaceSourceCheck: ()=>workspace_source_check_cjs_namespaceObject.runWorkspaceSourceCheck
43
- });
44
- const i18n_check_cjs_namespaceObject = require("./cli/i18n-check.cjs");
45
- const workspace_source_check_cjs_namespaceObject = require("./cli/workspace-source-check.cjs");
46
- const external_oxlint_plugin_cjs_namespaceObject = require("./oxlint-plugin.cjs");
47
- var external_oxlint_plugin_cjs_default = /*#__PURE__*/ __webpack_require__.n(external_oxlint_plugin_cjs_namespaceObject);
48
- exports.oxlintPlugin = __webpack_exports__.oxlintPlugin;
49
- exports.runSingleAppI18nCheck = __webpack_exports__.runSingleAppI18nCheck;
50
- exports.runWorkspaceSourceCheck = __webpack_exports__.runWorkspaceSourceCheck;
51
- for(var __rspack_i in __webpack_exports__)if (-1 === [
52
- "oxlintPlugin",
53
- "runSingleAppI18nCheck",
54
- "runWorkspaceSourceCheck"
55
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
56
- Object.defineProperty(exports, '__esModule', {
57
- value: true
58
- });
@@ -1,354 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (exports1, getters, values)=>{
5
- var define = (defs, kind)=>{
6
- for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
- enumerable: true,
8
- [kind]: defs[key]
9
- });
10
- };
11
- define(getters, "get");
12
- define(values, "value");
13
- };
14
- })();
15
- (()=>{
16
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
- })();
18
- (()=>{
19
- __webpack_require__.r = (exports1)=>{
20
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
- value: 'Module'
22
- });
23
- Object.defineProperty(exports1, '__esModule', {
24
- value: true
25
- });
26
- };
27
- })();
28
- var __webpack_exports__ = {};
29
- __webpack_require__.r(__webpack_exports__);
30
- const commonOptionsSchema = {
31
- type: 'object',
32
- properties: {
33
- allowElements: {
34
- type: 'array',
35
- items: {
36
- type: 'string'
37
- }
38
- },
39
- ignoreCommentPattern: {
40
- type: 'string'
41
- }
42
- },
43
- additionalProperties: false
44
- };
45
- const attributeOptionsSchema = {
46
- type: 'object',
47
- properties: {
48
- ...commonOptionsSchema.properties,
49
- visibleAttributes: {
50
- type: 'array',
51
- items: {
52
- type: 'string'
53
- }
54
- }
55
- },
56
- additionalProperties: false
57
- };
58
- const translationOptionsSchema = {
59
- type: 'object',
60
- properties: {
61
- translationFunctions: {
62
- type: 'array',
63
- items: {
64
- type: 'string'
65
- }
66
- }
67
- },
68
- additionalProperties: false
69
- };
70
- const DEFAULT_VISIBLE_ATTRIBUTES = [
71
- 'aria-label',
72
- "aria-description",
73
- "aria-roledescription",
74
- 'aria-valuetext',
75
- 'alt',
76
- 'placeholder',
77
- 'title'
78
- ];
79
- const DEFAULT_ALLOWED_ELEMENTS = [
80
- 'code',
81
- 'kbd',
82
- 'samp'
83
- ];
84
- const DEFAULT_TRANSLATION_FUNCTIONS = [
85
- 't'
86
- ];
87
- const DEFAULT_IGNORE_COMMENT_PATTERN = 'i18n-ignore';
88
- const LETTER_PATTERN = /\p{L}/u;
89
- const SPLIT_TRANSLATION_KEY_PATTERN = /\.(?:prefix|suffix|before|after)$/u;
90
- const isRecord = (value)=>Boolean(value) && 'object' == typeof value && !Array.isArray(value);
91
- const asStringArray = (value, fallback)=>Array.isArray(value) && value.every((item)=>'string' == typeof item) ? value : fallback;
92
- const getCommonRuleOption = (context, defaults)=>{
93
- const options = context.options?.[0];
94
- if (!isRecord(options)) return defaults;
95
- return {
96
- allowElements: asStringArray(options.allowElements, defaults.allowElements),
97
- ignoreCommentPattern: 'string' == typeof options.ignoreCommentPattern ? options.ignoreCommentPattern : defaults.ignoreCommentPattern
98
- };
99
- };
100
- const getAttributeRuleOption = (context, defaults)=>{
101
- const options = context.options?.[0];
102
- const commonOptions = getCommonRuleOption(context, defaults);
103
- return {
104
- ...commonOptions,
105
- visibleAttributes: isRecord(options) ? asStringArray(options.visibleAttributes, defaults.visibleAttributes) : defaults.visibleAttributes
106
- };
107
- };
108
- const getSplitTranslationKeyRuleOption = (context, defaults)=>{
109
- const options = context.options?.[0];
110
- if (!isRecord(options)) return defaults;
111
- return {
112
- translationFunctions: asStringArray(options.translationFunctions, defaults.translationFunctions)
113
- };
114
- };
115
- const normalizeVisibleText = (value)=>value.replaceAll(/\s+/gu, ' ').trim();
116
- const hasLetters = (value)=>LETTER_PATTERN.test(value);
117
- const getNodeName = (node)=>{
118
- if (!node) return;
119
- if ('string' == typeof node.name) return node.name;
120
- if ('JSXIdentifier' === node.type && isRecord(node.name) && 'string' == typeof node.name.name) return node.name.name;
121
- if ('JSXIdentifier' === node.type && 'string' == typeof node.name) return node.name;
122
- if (('JSXMemberExpression' === node.type || 'MemberExpression' === node.type) && isRecord(node.property) && true !== node.computed) {
123
- const objectName = getNodeName(node.object);
124
- const propertyName = getNodeName(node.property);
125
- return objectName && propertyName ? `${objectName}.${propertyName}` : propertyName;
126
- }
127
- };
128
- const getJsxElementName = (node)=>{
129
- if (node?.type !== 'JSXElement') return;
130
- return getNodeName(node.openingElement?.name);
131
- };
132
- const hasAllowedElementAncestor = (node, allowedElements)=>{
133
- let current = node;
134
- while(current){
135
- const elementName = getJsxElementName(current);
136
- if (elementName && allowedElements.has(elementName)) return true;
137
- current = current.parent;
138
- }
139
- return false;
140
- };
141
- const getTemplateLiteralValue = (node)=>{
142
- if ('TemplateLiteral' !== node.type || (node.expressions?.length ?? 0) > 0) return;
143
- const quasi = node.quasis?.[0];
144
- if (!isRecord(quasi?.value)) return;
145
- const cooked = quasi.value.cooked;
146
- const raw = quasi.value.raw;
147
- return 'string' == typeof cooked ? cooked : 'string' == typeof raw ? raw : void 0;
148
- };
149
- const getStringLiteralValue = (node)=>{
150
- if (!node) return;
151
- if (('Literal' === node.type || 'StringLiteral' === node.type) && 'string' == typeof node.value) return node.value;
152
- return getTemplateLiteralValue(node);
153
- };
154
- const expressionStringValue = (node)=>getStringLiteralValue(node?.type === 'JSXExpressionContainer' ? node.expression : node);
155
- const getLine = (node)=>node.loc?.start?.line;
156
- const hasIgnoreComment = (node, context, pattern)=>{
157
- const sourceCode = context.getSourceCode?.();
158
- const nodeLine = getLine(node);
159
- if (!sourceCode?.getAllComments || void 0 === nodeLine) return false;
160
- return sourceCode.getAllComments().some((comment)=>{
161
- const commentValue = String(comment.value ?? '');
162
- if (!pattern.test(commentValue)) return false;
163
- const startLine = comment.loc?.start?.line;
164
- const endLine = comment.loc?.end?.line ?? startLine;
165
- return void 0 !== startLine && void 0 !== endLine && startLine <= nodeLine + 1 && endLine >= nodeLine - 1;
166
- });
167
- };
168
- const getIgnorePattern = (options)=>new RegExp(options.ignoreCommentPattern, 'u');
169
- const reportVisibleText = (context, node, text)=>{
170
- context.report({
171
- node,
172
- message: `Move user-visible JSX text to locale resources: ${JSON.stringify(text)}`
173
- });
174
- };
175
- const createNoHardcodedJsxTextRule = ()=>({
176
- meta: {
177
- type: 'problem',
178
- docs: {
179
- description: 'Disallow literal user-visible text in JSX children in UltraModern generated apps.'
180
- },
181
- schema: [
182
- commonOptionsSchema
183
- ]
184
- },
185
- create (context) {
186
- const options = getCommonRuleOption(context, {
187
- allowElements: DEFAULT_ALLOWED_ELEMENTS,
188
- ignoreCommentPattern: DEFAULT_IGNORE_COMMENT_PATTERN
189
- });
190
- const allowedElements = new Set(options.allowElements);
191
- const ignorePattern = getIgnorePattern(options);
192
- const shouldSkipNode = (node)=>hasAllowedElementAncestor(node, allowedElements) || hasIgnoreComment(node, context, ignorePattern);
193
- return {
194
- JSXText (node) {
195
- const text = normalizeVisibleText(String(node.value ?? ''));
196
- if (!text || !hasLetters(text) || shouldSkipNode(node)) return;
197
- reportVisibleText(context, node, text);
198
- },
199
- JSXExpressionContainer (node) {
200
- if (node.parent?.type !== 'JSXElement' && node.parent?.type !== 'JSXFragment') return;
201
- const text = normalizeVisibleText(expressionStringValue(node.expression) ?? '');
202
- if (!text || !hasLetters(text) || shouldSkipNode(node)) return;
203
- reportVisibleText(context, node, text);
204
- }
205
- };
206
- }
207
- });
208
- const createNoLiteralVisibleJsxAttributesRule = ()=>({
209
- meta: {
210
- type: 'problem',
211
- docs: {
212
- description: 'Disallow literal user-visible JSX attribute text in UltraModern generated apps.'
213
- },
214
- schema: [
215
- attributeOptionsSchema
216
- ]
217
- },
218
- create (context) {
219
- const options = getAttributeRuleOption(context, {
220
- allowElements: DEFAULT_ALLOWED_ELEMENTS,
221
- ignoreCommentPattern: DEFAULT_IGNORE_COMMENT_PATTERN,
222
- visibleAttributes: DEFAULT_VISIBLE_ATTRIBUTES
223
- });
224
- const visibleAttributes = new Set(options.visibleAttributes);
225
- const ignorePattern = getIgnorePattern(options);
226
- return {
227
- JSXAttribute (node) {
228
- const attributeName = getNodeName(node.name);
229
- if (!attributeName || !visibleAttributes.has(attributeName)) return;
230
- const text = normalizeVisibleText(expressionStringValue(node.value) ?? '');
231
- if (!text || !hasLetters(text) || hasIgnoreComment(node, context, ignorePattern)) return;
232
- context.report({
233
- node,
234
- message: `Move literal ${attributeName} copy to locale resources: ${JSON.stringify(text)}`
235
- });
236
- }
237
- };
238
- }
239
- });
240
- const getSourceText = (context, node)=>context.getSourceCode?.().getText?.(node) ?? '';
241
- const looksLikeLocaleTest = (context, node)=>{
242
- const text = getSourceText(context, node);
243
- return /\b(?:language|locale|lng|currentLanguage)\b/u.test(text) && /(?:={2,3}|!==?)/u.test(text) && /['"][a-z]{2}(?:-[A-Za-z0-9]+)?['"]/u.test(text);
244
- };
245
- const isAllowedBranchLiteral = (text)=>new Set([
246
- 'page',
247
- 'undefined',
248
- 'null',
249
- 'true',
250
- 'false'
251
- ]).has(text);
252
- const createNoManualLocaleCopyBranchingRule = ()=>({
253
- meta: {
254
- type: 'problem',
255
- docs: {
256
- description: 'Disallow manual locale conditionals that choose user-visible copy.'
257
- },
258
- schema: []
259
- },
260
- create (context) {
261
- const reportBranch = (node, text)=>{
262
- context.report({
263
- node,
264
- message: `Move locale-specific copy branch to i18n resources: ${JSON.stringify(normalizeVisibleText(text))}`
265
- });
266
- };
267
- return {
268
- ConditionalExpression (node) {
269
- if (!node.test || !looksLikeLocaleTest(context, node.test)) return;
270
- for (const branch of [
271
- node.consequent,
272
- node.alternate
273
- ]){
274
- const text = expressionStringValue(branch);
275
- if (text && hasLetters(text) && !isAllowedBranchLiteral(text.trim())) reportBranch(branch, text);
276
- }
277
- }
278
- };
279
- }
280
- });
281
- const getCallExpressionName = (node)=>getNodeName(node);
282
- const createNoSplitTranslationKeysRule = ()=>({
283
- meta: {
284
- type: 'problem',
285
- docs: {
286
- description: 'Disallow split phrase translation key suffixes such as .prefix and .suffix.'
287
- },
288
- schema: [
289
- translationOptionsSchema
290
- ]
291
- },
292
- create (context) {
293
- const options = getSplitTranslationKeyRuleOption(context, {
294
- translationFunctions: DEFAULT_TRANSLATION_FUNCTIONS
295
- });
296
- const translationFunctions = new Set(options.translationFunctions);
297
- return {
298
- CallExpression (node) {
299
- const calleeName = getCallExpressionName(node.callee);
300
- if (!calleeName || !translationFunctions.has(calleeName)) return;
301
- const key = expressionStringValue(node.arguments?.[0]);
302
- if (!key || !SPLIT_TRANSLATION_KEY_PATTERN.test(key)) return;
303
- context.report({
304
- node,
305
- message: 'Keep translator-owned phrases whole instead of using split translation keys.'
306
- });
307
- }
308
- };
309
- }
310
- });
311
- const createNoLegacyMfBoundaryAttributesRule = ()=>({
312
- meta: {
313
- type: 'problem',
314
- docs: {
315
- description: 'Disallow legacy Module Federation boundary attributes in generated UltraModern workspaces.'
316
- },
317
- schema: []
318
- },
319
- create (context) {
320
- return {
321
- JSXAttribute (node) {
322
- const attributeName = getNodeName(node.name);
323
- if ('data-mf-boundary' !== attributeName && 'data-mf-remote' !== attributeName && 'data-mf-expose' !== attributeName) return;
324
- context.report({
325
- node,
326
- message: 'Use data-modern-boundary-id and data-modern-mf-expose instead of legacy data-mf-* boundary attributes.'
327
- });
328
- }
329
- };
330
- }
331
- });
332
- const plugin = {
333
- meta: {
334
- name: 'ultramodern'
335
- },
336
- rules: {
337
- 'no-hardcoded-jsx-text': createNoHardcodedJsxTextRule(),
338
- 'no-legacy-mf-boundary-attributes': createNoLegacyMfBoundaryAttributesRule(),
339
- 'no-literal-visible-jsx-attributes': createNoLiteralVisibleJsxAttributesRule(),
340
- 'no-manual-locale-copy-branching': createNoManualLocaleCopyBranchingRule(),
341
- 'no-split-translation-keys': createNoSplitTranslationKeysRule()
342
- }
343
- };
344
- const __rspack_default_export = plugin;
345
- __webpack_require__.d(__webpack_exports__, {}, {
346
- default: __rspack_default_export
347
- });
348
- exports["default"] = __webpack_exports__["default"];
349
- for(var __rspack_i in __webpack_exports__)if (-1 === [
350
- "default"
351
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
352
- Object.defineProperty(exports, '__esModule', {
353
- value: true
354
- });
@@ -1,26 +0,0 @@
1
- import { printOxlintOutput, runOxlintRules } from "./oxlint.js";
2
- const SINGLE_APP_I18N_SUCCESS = 'No hardcoded user-visible JSX strings found.';
3
- const SINGLE_APP_I18N_FAILURE = 'Hardcoded user-visible JSX strings found. Move copy to locale JSON files.';
4
- const runSingleAppI18nCheck = ({ cwd = process.cwd(), targets = [
5
- 'src'
6
- ] } = {})=>{
7
- const result = runOxlintRules({
8
- cwd,
9
- targets,
10
- rules: {
11
- 'ultramodern/no-hardcoded-jsx-text': 'error',
12
- 'ultramodern/no-literal-visible-jsx-attributes': 'error'
13
- }
14
- });
15
- if (0 === result.exitCode) {
16
- console.log(SINGLE_APP_I18N_SUCCESS);
17
- return 0;
18
- }
19
- console.error(SINGLE_APP_I18N_FAILURE);
20
- printOxlintOutput(result);
21
- return result.exitCode;
22
- };
23
- const main = ()=>{
24
- process.exitCode = runSingleAppI18nCheck();
25
- };
26
- export { SINGLE_APP_I18N_FAILURE, SINGLE_APP_I18N_SUCCESS, main, runSingleAppI18nCheck };