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

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 (44) hide show
  1. package/dist/cjs/index.cjs +1040 -0
  2. package/dist/cjs/locale/en.cjs +97 -0
  3. package/dist/cjs/locale/index.cjs +50 -0
  4. package/dist/cjs/locale/zh.cjs +97 -0
  5. package/dist/cjs/ultramodern-checks/cli/i18n-check.cjs +73 -0
  6. package/dist/cjs/ultramodern-checks/cli/oxlint.cjs +174 -0
  7. package/dist/cjs/ultramodern-checks/cli/workspace-source-check.cjs +179 -0
  8. package/dist/cjs/ultramodern-checks/index.cjs +58 -0
  9. package/dist/cjs/ultramodern-checks/oxlint-plugin.cjs +354 -0
  10. package/dist/cjs/ultramodern-package-source.cjs +133 -0
  11. package/dist/cjs/ultramodern-workspace.cjs +5616 -0
  12. package/dist/esm/index.js +1002 -0
  13. package/dist/esm/locale/en.js +59 -0
  14. package/dist/esm/locale/index.js +9 -0
  15. package/dist/esm/locale/zh.js +59 -0
  16. package/dist/esm/ultramodern-checks/cli/i18n-check.js +26 -0
  17. package/dist/esm/ultramodern-checks/cli/oxlint.js +118 -0
  18. package/dist/esm/ultramodern-checks/cli/workspace-source-check.js +124 -0
  19. package/dist/esm/ultramodern-checks/index.js +3 -0
  20. package/dist/esm/ultramodern-checks/oxlint-plugin.js +316 -0
  21. package/dist/esm/ultramodern-package-source.js +61 -0
  22. package/dist/esm/ultramodern-workspace.js +5554 -0
  23. package/dist/esm-node/index.js +1003 -0
  24. package/dist/esm-node/locale/en.js +60 -0
  25. package/dist/esm-node/locale/index.js +10 -0
  26. package/dist/esm-node/locale/zh.js +60 -0
  27. package/dist/esm-node/ultramodern-checks/cli/i18n-check.js +27 -0
  28. package/dist/esm-node/ultramodern-checks/cli/oxlint.js +119 -0
  29. package/dist/esm-node/ultramodern-checks/cli/workspace-source-check.js +125 -0
  30. package/dist/esm-node/ultramodern-checks/index.js +4 -0
  31. package/dist/esm-node/ultramodern-checks/oxlint-plugin.js +317 -0
  32. package/dist/esm-node/ultramodern-package-source.js +62 -0
  33. package/dist/{index.js → esm-node/ultramodern-workspace.js} +31 -1793
  34. package/dist/types/ultramodern-checks/cli/i18n-check.d.ts +9 -0
  35. package/dist/types/ultramodern-checks/cli/oxlint.d.ts +22 -0
  36. package/dist/types/ultramodern-checks/cli/workspace-source-check.d.ts +8 -0
  37. package/dist/types/ultramodern-checks/index.d.ts +3 -0
  38. package/dist/types/ultramodern-checks/oxlint-plugin.d.ts +63 -0
  39. package/dist/types/ultramodern-package-source.d.ts +2 -2
  40. package/package.json +49 -8
  41. package/template/package.json.handlebars +7 -5
  42. package/template/scripts/check-i18n-strings.mjs +2 -205
  43. package/template/scripts/validate-ultramodern.mjs.handlebars +27 -9
  44. package/template/tests/ultramodern.contract.test.ts.handlebars +19 -0
@@ -0,0 +1,316 @@
1
+ const commonOptionsSchema = {
2
+ type: 'object',
3
+ properties: {
4
+ allowElements: {
5
+ type: 'array',
6
+ items: {
7
+ type: 'string'
8
+ }
9
+ },
10
+ ignoreCommentPattern: {
11
+ type: 'string'
12
+ }
13
+ },
14
+ additionalProperties: false
15
+ };
16
+ const attributeOptionsSchema = {
17
+ type: 'object',
18
+ properties: {
19
+ ...commonOptionsSchema.properties,
20
+ visibleAttributes: {
21
+ type: 'array',
22
+ items: {
23
+ type: 'string'
24
+ }
25
+ }
26
+ },
27
+ additionalProperties: false
28
+ };
29
+ const translationOptionsSchema = {
30
+ type: 'object',
31
+ properties: {
32
+ translationFunctions: {
33
+ type: 'array',
34
+ items: {
35
+ type: 'string'
36
+ }
37
+ }
38
+ },
39
+ additionalProperties: false
40
+ };
41
+ const DEFAULT_VISIBLE_ATTRIBUTES = [
42
+ 'aria-label',
43
+ "aria-description",
44
+ "aria-roledescription",
45
+ 'aria-valuetext',
46
+ 'alt',
47
+ 'placeholder',
48
+ 'title'
49
+ ];
50
+ const DEFAULT_ALLOWED_ELEMENTS = [
51
+ 'code',
52
+ 'kbd',
53
+ 'samp'
54
+ ];
55
+ const DEFAULT_TRANSLATION_FUNCTIONS = [
56
+ 't'
57
+ ];
58
+ const DEFAULT_IGNORE_COMMENT_PATTERN = 'i18n-ignore';
59
+ const LETTER_PATTERN = /\p{L}/u;
60
+ const SPLIT_TRANSLATION_KEY_PATTERN = /\.(?:prefix|suffix|before|after)$/u;
61
+ const isRecord = (value)=>Boolean(value) && 'object' == typeof value && !Array.isArray(value);
62
+ const asStringArray = (value, fallback)=>Array.isArray(value) && value.every((item)=>'string' == typeof item) ? value : fallback;
63
+ const getCommonRuleOption = (context, defaults)=>{
64
+ const options = context.options?.[0];
65
+ if (!isRecord(options)) return defaults;
66
+ return {
67
+ allowElements: asStringArray(options.allowElements, defaults.allowElements),
68
+ ignoreCommentPattern: 'string' == typeof options.ignoreCommentPattern ? options.ignoreCommentPattern : defaults.ignoreCommentPattern
69
+ };
70
+ };
71
+ const getAttributeRuleOption = (context, defaults)=>{
72
+ const options = context.options?.[0];
73
+ const commonOptions = getCommonRuleOption(context, defaults);
74
+ return {
75
+ ...commonOptions,
76
+ visibleAttributes: isRecord(options) ? asStringArray(options.visibleAttributes, defaults.visibleAttributes) : defaults.visibleAttributes
77
+ };
78
+ };
79
+ const getSplitTranslationKeyRuleOption = (context, defaults)=>{
80
+ const options = context.options?.[0];
81
+ if (!isRecord(options)) return defaults;
82
+ return {
83
+ translationFunctions: asStringArray(options.translationFunctions, defaults.translationFunctions)
84
+ };
85
+ };
86
+ const normalizeVisibleText = (value)=>value.replaceAll(/\s+/gu, ' ').trim();
87
+ const hasLetters = (value)=>LETTER_PATTERN.test(value);
88
+ const getNodeName = (node)=>{
89
+ if (!node) return;
90
+ if ('string' == typeof node.name) return node.name;
91
+ if ('JSXIdentifier' === node.type && isRecord(node.name) && 'string' == typeof node.name.name) return node.name.name;
92
+ if ('JSXIdentifier' === node.type && 'string' == typeof node.name) return node.name;
93
+ if (('JSXMemberExpression' === node.type || 'MemberExpression' === node.type) && isRecord(node.property) && true !== node.computed) {
94
+ const objectName = getNodeName(node.object);
95
+ const propertyName = getNodeName(node.property);
96
+ return objectName && propertyName ? `${objectName}.${propertyName}` : propertyName;
97
+ }
98
+ };
99
+ const getJsxElementName = (node)=>{
100
+ if (node?.type !== 'JSXElement') return;
101
+ return getNodeName(node.openingElement?.name);
102
+ };
103
+ const hasAllowedElementAncestor = (node, allowedElements)=>{
104
+ let current = node;
105
+ while(current){
106
+ const elementName = getJsxElementName(current);
107
+ if (elementName && allowedElements.has(elementName)) return true;
108
+ current = current.parent;
109
+ }
110
+ return false;
111
+ };
112
+ const getTemplateLiteralValue = (node)=>{
113
+ if ('TemplateLiteral' !== node.type || (node.expressions?.length ?? 0) > 0) return;
114
+ const quasi = node.quasis?.[0];
115
+ if (!isRecord(quasi?.value)) return;
116
+ const cooked = quasi.value.cooked;
117
+ const raw = quasi.value.raw;
118
+ return 'string' == typeof cooked ? cooked : 'string' == typeof raw ? raw : void 0;
119
+ };
120
+ const getStringLiteralValue = (node)=>{
121
+ if (!node) return;
122
+ if (('Literal' === node.type || 'StringLiteral' === node.type) && 'string' == typeof node.value) return node.value;
123
+ return getTemplateLiteralValue(node);
124
+ };
125
+ const expressionStringValue = (node)=>getStringLiteralValue(node?.type === 'JSXExpressionContainer' ? node.expression : node);
126
+ const getLine = (node)=>node.loc?.start?.line;
127
+ const hasIgnoreComment = (node, context, pattern)=>{
128
+ const sourceCode = context.getSourceCode?.();
129
+ const nodeLine = getLine(node);
130
+ if (!sourceCode?.getAllComments || void 0 === nodeLine) return false;
131
+ return sourceCode.getAllComments().some((comment)=>{
132
+ const commentValue = String(comment.value ?? '');
133
+ if (!pattern.test(commentValue)) return false;
134
+ const startLine = comment.loc?.start?.line;
135
+ const endLine = comment.loc?.end?.line ?? startLine;
136
+ return void 0 !== startLine && void 0 !== endLine && startLine <= nodeLine + 1 && endLine >= nodeLine - 1;
137
+ });
138
+ };
139
+ const getIgnorePattern = (options)=>new RegExp(options.ignoreCommentPattern, 'u');
140
+ const reportVisibleText = (context, node, text)=>{
141
+ context.report({
142
+ node,
143
+ message: `Move user-visible JSX text to locale resources: ${JSON.stringify(text)}`
144
+ });
145
+ };
146
+ const createNoHardcodedJsxTextRule = ()=>({
147
+ meta: {
148
+ type: 'problem',
149
+ docs: {
150
+ description: 'Disallow literal user-visible text in JSX children in UltraModern generated apps.'
151
+ },
152
+ schema: [
153
+ commonOptionsSchema
154
+ ]
155
+ },
156
+ create (context) {
157
+ const options = getCommonRuleOption(context, {
158
+ allowElements: DEFAULT_ALLOWED_ELEMENTS,
159
+ ignoreCommentPattern: DEFAULT_IGNORE_COMMENT_PATTERN
160
+ });
161
+ const allowedElements = new Set(options.allowElements);
162
+ const ignorePattern = getIgnorePattern(options);
163
+ const shouldSkipNode = (node)=>hasAllowedElementAncestor(node, allowedElements) || hasIgnoreComment(node, context, ignorePattern);
164
+ return {
165
+ JSXText (node) {
166
+ const text = normalizeVisibleText(String(node.value ?? ''));
167
+ if (!text || !hasLetters(text) || shouldSkipNode(node)) return;
168
+ reportVisibleText(context, node, text);
169
+ },
170
+ JSXExpressionContainer (node) {
171
+ if (node.parent?.type !== 'JSXElement' && node.parent?.type !== 'JSXFragment') return;
172
+ const text = normalizeVisibleText(expressionStringValue(node.expression) ?? '');
173
+ if (!text || !hasLetters(text) || shouldSkipNode(node)) return;
174
+ reportVisibleText(context, node, text);
175
+ }
176
+ };
177
+ }
178
+ });
179
+ const createNoLiteralVisibleJsxAttributesRule = ()=>({
180
+ meta: {
181
+ type: 'problem',
182
+ docs: {
183
+ description: 'Disallow literal user-visible JSX attribute text in UltraModern generated apps.'
184
+ },
185
+ schema: [
186
+ attributeOptionsSchema
187
+ ]
188
+ },
189
+ create (context) {
190
+ const options = getAttributeRuleOption(context, {
191
+ allowElements: DEFAULT_ALLOWED_ELEMENTS,
192
+ ignoreCommentPattern: DEFAULT_IGNORE_COMMENT_PATTERN,
193
+ visibleAttributes: DEFAULT_VISIBLE_ATTRIBUTES
194
+ });
195
+ const visibleAttributes = new Set(options.visibleAttributes);
196
+ const ignorePattern = getIgnorePattern(options);
197
+ return {
198
+ JSXAttribute (node) {
199
+ const attributeName = getNodeName(node.name);
200
+ if (!attributeName || !visibleAttributes.has(attributeName)) return;
201
+ const text = normalizeVisibleText(expressionStringValue(node.value) ?? '');
202
+ if (!text || !hasLetters(text) || hasIgnoreComment(node, context, ignorePattern)) return;
203
+ context.report({
204
+ node,
205
+ message: `Move literal ${attributeName} copy to locale resources: ${JSON.stringify(text)}`
206
+ });
207
+ }
208
+ };
209
+ }
210
+ });
211
+ const getSourceText = (context, node)=>context.getSourceCode?.().getText?.(node) ?? '';
212
+ const looksLikeLocaleTest = (context, node)=>{
213
+ const text = getSourceText(context, node);
214
+ 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);
215
+ };
216
+ const isAllowedBranchLiteral = (text)=>new Set([
217
+ 'page',
218
+ 'undefined',
219
+ 'null',
220
+ 'true',
221
+ 'false'
222
+ ]).has(text);
223
+ const createNoManualLocaleCopyBranchingRule = ()=>({
224
+ meta: {
225
+ type: 'problem',
226
+ docs: {
227
+ description: 'Disallow manual locale conditionals that choose user-visible copy.'
228
+ },
229
+ schema: []
230
+ },
231
+ create (context) {
232
+ const reportBranch = (node, text)=>{
233
+ context.report({
234
+ node,
235
+ message: `Move locale-specific copy branch to i18n resources: ${JSON.stringify(normalizeVisibleText(text))}`
236
+ });
237
+ };
238
+ return {
239
+ ConditionalExpression (node) {
240
+ if (!node.test || !looksLikeLocaleTest(context, node.test)) return;
241
+ for (const branch of [
242
+ node.consequent,
243
+ node.alternate
244
+ ]){
245
+ const text = expressionStringValue(branch);
246
+ if (text && hasLetters(text) && !isAllowedBranchLiteral(text.trim())) reportBranch(branch, text);
247
+ }
248
+ }
249
+ };
250
+ }
251
+ });
252
+ const getCallExpressionName = (node)=>getNodeName(node);
253
+ const createNoSplitTranslationKeysRule = ()=>({
254
+ meta: {
255
+ type: 'problem',
256
+ docs: {
257
+ description: 'Disallow split phrase translation key suffixes such as .prefix and .suffix.'
258
+ },
259
+ schema: [
260
+ translationOptionsSchema
261
+ ]
262
+ },
263
+ create (context) {
264
+ const options = getSplitTranslationKeyRuleOption(context, {
265
+ translationFunctions: DEFAULT_TRANSLATION_FUNCTIONS
266
+ });
267
+ const translationFunctions = new Set(options.translationFunctions);
268
+ return {
269
+ CallExpression (node) {
270
+ const calleeName = getCallExpressionName(node.callee);
271
+ if (!calleeName || !translationFunctions.has(calleeName)) return;
272
+ const key = expressionStringValue(node.arguments?.[0]);
273
+ if (!key || !SPLIT_TRANSLATION_KEY_PATTERN.test(key)) return;
274
+ context.report({
275
+ node,
276
+ message: 'Keep translator-owned phrases whole instead of using split translation keys.'
277
+ });
278
+ }
279
+ };
280
+ }
281
+ });
282
+ const createNoLegacyMfBoundaryAttributesRule = ()=>({
283
+ meta: {
284
+ type: 'problem',
285
+ docs: {
286
+ description: 'Disallow legacy Module Federation boundary attributes in generated UltraModern workspaces.'
287
+ },
288
+ schema: []
289
+ },
290
+ create (context) {
291
+ return {
292
+ JSXAttribute (node) {
293
+ const attributeName = getNodeName(node.name);
294
+ if ('data-mf-boundary' !== attributeName && 'data-mf-remote' !== attributeName && 'data-mf-expose' !== attributeName) return;
295
+ context.report({
296
+ node,
297
+ message: 'Use data-modern-boundary-id and data-modern-mf-expose instead of legacy data-mf-* boundary attributes.'
298
+ });
299
+ }
300
+ };
301
+ }
302
+ });
303
+ const oxlint_plugin_plugin = {
304
+ meta: {
305
+ name: 'ultramodern'
306
+ },
307
+ rules: {
308
+ 'no-hardcoded-jsx-text': createNoHardcodedJsxTextRule(),
309
+ 'no-legacy-mf-boundary-attributes': createNoLegacyMfBoundaryAttributesRule(),
310
+ 'no-literal-visible-jsx-attributes': createNoLiteralVisibleJsxAttributesRule(),
311
+ 'no-manual-locale-copy-branching': createNoManualLocaleCopyBranchingRule(),
312
+ 'no-split-translation-keys': createNoSplitTranslationKeysRule()
313
+ }
314
+ };
315
+ const oxlint_plugin = oxlint_plugin_plugin;
316
+ export default oxlint_plugin;
@@ -0,0 +1,61 @@
1
+ const WORKSPACE_PACKAGE_VERSION = 'workspace:*';
2
+ const BLEEDINGDEV_CREATE_PACKAGE = '@bleedingdev/modern-js-create';
3
+ const BLEEDINGDEV_PACKAGE_SCOPE = 'bleedingdev';
4
+ const BLEEDINGDEV_PACKAGE_NAME_PREFIX = 'modern-js-';
5
+ const BLEEDINGDEV_FRAMEWORK_VERSION_ENV = 'MODERN_CREATE_ULTRAMODERN_FRAMEWORK_VERSION';
6
+ const ULTRAMODERN_SINGLE_APP_MODERN_PACKAGES = [
7
+ '@modern-js/create',
8
+ '@modern-js/runtime',
9
+ '@modern-js/app-tools',
10
+ '@modern-js/tsconfig',
11
+ '@modern-js/plugin-i18n',
12
+ '@modern-js/plugin-tanstack',
13
+ '@modern-js/plugin-bff',
14
+ '@modern-js/adapter-rstest'
15
+ ];
16
+ const ULTRAMODERN_WORKSPACE_MODERN_PACKAGES = [
17
+ '@modern-js/create',
18
+ '@modern-js/app-tools',
19
+ '@modern-js/plugin-bff',
20
+ '@modern-js/plugin-i18n',
21
+ '@modern-js/plugin-tanstack',
22
+ '@modern-js/runtime'
23
+ ];
24
+ function modernPackageVersion(packageSource) {
25
+ return 'install' === packageSource.strategy ? packageSource.modernPackageVersion : WORKSPACE_PACKAGE_VERSION;
26
+ }
27
+ function modernAliasPackageName(packageName, packageSource) {
28
+ if (!packageSource.aliasScope) return packageName;
29
+ const scope = packageSource.aliasScope.replace(/^@/, '');
30
+ const unscopedName = packageName.split('/').at(-1);
31
+ return `@${scope}/${packageSource.aliasPackageNamePrefix ?? ''}${unscopedName}`;
32
+ }
33
+ function modernPackageSpecifier(packageName, packageSource) {
34
+ if ('install' !== packageSource.strategy) return WORKSPACE_PACKAGE_VERSION;
35
+ if (!packageSource.aliasScope) return packageSource.modernPackageVersion;
36
+ return `npm:${modernAliasPackageName(packageName, packageSource)}@${packageSource.modernPackageVersion}`;
37
+ }
38
+ function modernPackageAliases(packageNames, packageSource) {
39
+ if (!packageSource.aliasScope) return;
40
+ return Object.fromEntries(packageNames.map((packageName)=>[
41
+ packageName,
42
+ modernAliasPackageName(packageName, packageSource)
43
+ ]));
44
+ }
45
+ function createModernPackagesMetadata(packageNames, packageSource, options = {}) {
46
+ const includeAliases = options.includeAliases ?? Boolean(packageSource.aliasScope);
47
+ const aliases = includeAliases ? modernPackageAliases(packageNames, packageSource) : void 0;
48
+ return {
49
+ packages: [
50
+ ...packageNames
51
+ ],
52
+ specifier: modernPackageVersion(packageSource),
53
+ ...packageSource.registry ? {
54
+ registry: packageSource.registry
55
+ } : {},
56
+ ...aliases ? {
57
+ aliases
58
+ } : {}
59
+ };
60
+ }
61
+ export { BLEEDINGDEV_CREATE_PACKAGE, BLEEDINGDEV_FRAMEWORK_VERSION_ENV, BLEEDINGDEV_PACKAGE_NAME_PREFIX, BLEEDINGDEV_PACKAGE_SCOPE, ULTRAMODERN_SINGLE_APP_MODERN_PACKAGES, ULTRAMODERN_WORKSPACE_MODERN_PACKAGES, WORKSPACE_PACKAGE_VERSION, createModernPackagesMetadata, modernAliasPackageName, modernPackageAliases, modernPackageSpecifier, modernPackageVersion };