@bleedingdev/modern-js-code-tools 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.
- package/LICENSE +21 -0
- package/dist/cjs/cli/i18n-check.cjs +73 -0
- package/dist/cjs/cli/oxlint.cjs +174 -0
- package/dist/cjs/cli/workspace-source-check.cjs +179 -0
- package/dist/cjs/index.cjs +58 -0
- package/dist/cjs/oxlint-plugin.cjs +354 -0
- package/dist/esm/cli/i18n-check.js +26 -0
- package/dist/esm/cli/oxlint.js +118 -0
- package/dist/esm/cli/workspace-source-check.js +124 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/oxlint-plugin.js +316 -0
- package/dist/esm-node/cli/i18n-check.js +27 -0
- package/dist/esm-node/cli/oxlint.js +119 -0
- package/dist/esm-node/cli/workspace-source-check.js +125 -0
- package/dist/esm-node/index.js +4 -0
- package/dist/esm-node/oxlint-plugin.js +317 -0
- package/dist/types/cli/i18n-check.d.ts +9 -0
- package/dist/types/cli/oxlint.d.ts +22 -0
- package/dist/types/cli/workspace-source-check.d.ts +8 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/oxlint-plugin.d.ts +63 -0
- package/package.json +80 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present Modern.js
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
SINGLE_APP_I18N_FAILURE: ()=>SINGLE_APP_I18N_FAILURE,
|
|
32
|
+
SINGLE_APP_I18N_SUCCESS: ()=>SINGLE_APP_I18N_SUCCESS,
|
|
33
|
+
main: ()=>main,
|
|
34
|
+
runSingleAppI18nCheck: ()=>runSingleAppI18nCheck
|
|
35
|
+
});
|
|
36
|
+
const external_oxlint_cjs_namespaceObject = require("./oxlint.cjs");
|
|
37
|
+
const SINGLE_APP_I18N_SUCCESS = 'No hardcoded user-visible JSX strings found.';
|
|
38
|
+
const SINGLE_APP_I18N_FAILURE = 'Hardcoded user-visible JSX strings found. Move copy to locale JSON files.';
|
|
39
|
+
const runSingleAppI18nCheck = ({ cwd = process.cwd(), targets = [
|
|
40
|
+
'src'
|
|
41
|
+
] } = {})=>{
|
|
42
|
+
const result = (0, external_oxlint_cjs_namespaceObject.runOxlintRules)({
|
|
43
|
+
cwd,
|
|
44
|
+
targets,
|
|
45
|
+
rules: {
|
|
46
|
+
'ultramodern/no-hardcoded-jsx-text': 'error',
|
|
47
|
+
'ultramodern/no-literal-visible-jsx-attributes': 'error'
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
if (0 === result.exitCode) {
|
|
51
|
+
console.log(SINGLE_APP_I18N_SUCCESS);
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
console.error(SINGLE_APP_I18N_FAILURE);
|
|
55
|
+
(0, external_oxlint_cjs_namespaceObject.printOxlintOutput)(result);
|
|
56
|
+
return result.exitCode;
|
|
57
|
+
};
|
|
58
|
+
const main = ()=>{
|
|
59
|
+
process.exitCode = runSingleAppI18nCheck();
|
|
60
|
+
};
|
|
61
|
+
exports.SINGLE_APP_I18N_FAILURE = __webpack_exports__.SINGLE_APP_I18N_FAILURE;
|
|
62
|
+
exports.SINGLE_APP_I18N_SUCCESS = __webpack_exports__.SINGLE_APP_I18N_SUCCESS;
|
|
63
|
+
exports.main = __webpack_exports__.main;
|
|
64
|
+
exports.runSingleAppI18nCheck = __webpack_exports__.runSingleAppI18nCheck;
|
|
65
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
66
|
+
"SINGLE_APP_I18N_FAILURE",
|
|
67
|
+
"SINGLE_APP_I18N_SUCCESS",
|
|
68
|
+
"main",
|
|
69
|
+
"runSingleAppI18nCheck"
|
|
70
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
71
|
+
Object.defineProperty(exports, '__esModule', {
|
|
72
|
+
value: true
|
|
73
|
+
});
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
|
|
3
|
+
return "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
4
|
+
}();
|
|
5
|
+
var __webpack_require__ = {};
|
|
6
|
+
(()=>{
|
|
7
|
+
__webpack_require__.n = (module)=>{
|
|
8
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
9
|
+
__webpack_require__.d(getter, {
|
|
10
|
+
a: getter
|
|
11
|
+
});
|
|
12
|
+
return getter;
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
17
|
+
var define = (defs, kind)=>{
|
|
18
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
[kind]: defs[key]
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
define(getters, "get");
|
|
24
|
+
define(values, "value");
|
|
25
|
+
};
|
|
26
|
+
})();
|
|
27
|
+
(()=>{
|
|
28
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
29
|
+
})();
|
|
30
|
+
(()=>{
|
|
31
|
+
__webpack_require__.r = (exports1)=>{
|
|
32
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
33
|
+
value: 'Module'
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
36
|
+
value: true
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
var __webpack_exports__ = {};
|
|
41
|
+
__webpack_require__.r(__webpack_exports__);
|
|
42
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
43
|
+
printOxlintOutput: ()=>printOxlintOutput,
|
|
44
|
+
runOxlintRules: ()=>runOxlintRules
|
|
45
|
+
});
|
|
46
|
+
const external_node_child_process_namespaceObject = require("node:child_process");
|
|
47
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
48
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
49
|
+
const external_node_module_namespaceObject = require("node:module");
|
|
50
|
+
const external_node_os_namespaceObject = require("node:os");
|
|
51
|
+
var external_node_os_default = /*#__PURE__*/ __webpack_require__.n(external_node_os_namespaceObject);
|
|
52
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
53
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
54
|
+
const external_node_url_namespaceObject = require("node:url");
|
|
55
|
+
const oxlint_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
|
|
56
|
+
const ignoredDirectories = new Set([
|
|
57
|
+
'.modern',
|
|
58
|
+
'.modernjs',
|
|
59
|
+
'.output',
|
|
60
|
+
'dist',
|
|
61
|
+
'node_modules'
|
|
62
|
+
]);
|
|
63
|
+
const packageNames = new Set([
|
|
64
|
+
'@modern-js/code-tools',
|
|
65
|
+
'@bleedingdev/modern-js-code-tools'
|
|
66
|
+
]);
|
|
67
|
+
const resolveExistingPath = (candidates)=>candidates.find((candidate)=>external_node_fs_default().existsSync(candidate));
|
|
68
|
+
const findPackageRoot = ()=>{
|
|
69
|
+
let directory = external_node_path_default().dirname((0, external_node_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__));
|
|
70
|
+
while(directory !== external_node_path_default().dirname(directory)){
|
|
71
|
+
const packageJsonPath = external_node_path_default().join(directory, 'package.json');
|
|
72
|
+
if (external_node_fs_default().existsSync(packageJsonPath)) try {
|
|
73
|
+
const packageJson = JSON.parse(external_node_fs_default().readFileSync(packageJsonPath, 'utf-8'));
|
|
74
|
+
if (packageNames.has(packageJson.name)) return directory;
|
|
75
|
+
} catch {
|
|
76
|
+
return directory;
|
|
77
|
+
}
|
|
78
|
+
directory = external_node_path_default().dirname(directory);
|
|
79
|
+
}
|
|
80
|
+
throw new Error('Unable to resolve @modern-js/code-tools package root.');
|
|
81
|
+
};
|
|
82
|
+
const resolvePluginPath = ()=>{
|
|
83
|
+
const root = findPackageRoot();
|
|
84
|
+
const sourcePluginPath = external_node_path_default().join(root, 'src/oxlint-plugin.ts');
|
|
85
|
+
const pluginPath = resolveExistingPath([
|
|
86
|
+
external_node_path_default().join(root, 'dist/esm-node/oxlint-plugin.mjs'),
|
|
87
|
+
external_node_path_default().join(root, 'dist/esm-node/oxlint-plugin.js'),
|
|
88
|
+
external_node_path_default().join(root, 'dist/esm/oxlint-plugin.mjs'),
|
|
89
|
+
external_node_path_default().join(root, 'dist/esm/oxlint-plugin.js'),
|
|
90
|
+
external_node_path_default().join(root, 'dist/cjs/oxlint-plugin.js'),
|
|
91
|
+
external_node_path_default().join(root, 'dist/cjs/oxlint-plugin.cjs'),
|
|
92
|
+
sourcePluginPath
|
|
93
|
+
]);
|
|
94
|
+
if (!pluginPath) throw new Error('Unable to resolve @modern-js/code-tools Oxlint plugin.');
|
|
95
|
+
return pluginPath;
|
|
96
|
+
};
|
|
97
|
+
const resolveOxlintBin = ()=>{
|
|
98
|
+
const packageJsonPath = oxlint_require.resolve('oxlint/package.json');
|
|
99
|
+
const packageJson = JSON.parse(external_node_fs_default().readFileSync(packageJsonPath, 'utf-8'));
|
|
100
|
+
const binRelativePath = 'string' == typeof packageJson.bin ? packageJson.bin : packageJson.bin?.oxlint;
|
|
101
|
+
if (!binRelativePath) throw new Error('Unable to resolve oxlint binary.');
|
|
102
|
+
return external_node_path_default().join(external_node_path_default().dirname(packageJsonPath), binRelativePath);
|
|
103
|
+
};
|
|
104
|
+
const existingTargets = (cwd, targets)=>targets.map((target)=>external_node_path_default().resolve(cwd, target)).filter((target)=>external_node_fs_default().existsSync(target));
|
|
105
|
+
const containsLintableSource = (filePath)=>{
|
|
106
|
+
if (!external_node_fs_default().existsSync(filePath)) return false;
|
|
107
|
+
const stats = external_node_fs_default().statSync(filePath);
|
|
108
|
+
if (stats.isFile()) return /\.(?:js|jsx|ts|tsx)$/u.test(filePath) && !filePath.endsWith('.d.ts');
|
|
109
|
+
if (!stats.isDirectory()) return false;
|
|
110
|
+
for (const entry of external_node_fs_default().readdirSync(filePath, {
|
|
111
|
+
withFileTypes: true
|
|
112
|
+
}))if (!(entry.isDirectory() && ignoredDirectories.has(entry.name))) {
|
|
113
|
+
if (containsLintableSource(external_node_path_default().join(filePath, entry.name))) return true;
|
|
114
|
+
}
|
|
115
|
+
return false;
|
|
116
|
+
};
|
|
117
|
+
const runOxlintRules = ({ cwd, targets, rules })=>{
|
|
118
|
+
const resolvedTargets = existingTargets(cwd, targets);
|
|
119
|
+
if (0 === resolvedTargets.length || !resolvedTargets.some((target)=>containsLintableSource(target))) return {
|
|
120
|
+
exitCode: 0,
|
|
121
|
+
stdout: '',
|
|
122
|
+
stderr: ''
|
|
123
|
+
};
|
|
124
|
+
const tempDir = external_node_fs_default().mkdtempSync(external_node_path_default().join(external_node_os_default().tmpdir(), 'ultramodern-oxlint-'));
|
|
125
|
+
const configPath = external_node_path_default().join(tempDir, 'oxlint.config.mjs');
|
|
126
|
+
const pluginPath = resolvePluginPath();
|
|
127
|
+
external_node_fs_default().writeFileSync(configPath, `export default {
|
|
128
|
+
jsPlugins: [${JSON.stringify(pluginPath)}],
|
|
129
|
+
rules: ${JSON.stringify(rules, null, 2)}
|
|
130
|
+
};
|
|
131
|
+
`, 'utf-8');
|
|
132
|
+
try {
|
|
133
|
+
const result = (0, external_node_child_process_namespaceObject.spawnSync)(process.execPath, [
|
|
134
|
+
resolveOxlintBin(),
|
|
135
|
+
...resolvedTargets,
|
|
136
|
+
'--config',
|
|
137
|
+
configPath,
|
|
138
|
+
'--format',
|
|
139
|
+
'unix',
|
|
140
|
+
'--quiet'
|
|
141
|
+
], {
|
|
142
|
+
cwd,
|
|
143
|
+
encoding: 'utf-8',
|
|
144
|
+
stdio: [
|
|
145
|
+
'ignore',
|
|
146
|
+
'pipe',
|
|
147
|
+
'pipe'
|
|
148
|
+
]
|
|
149
|
+
});
|
|
150
|
+
return {
|
|
151
|
+
exitCode: result.status ?? 1,
|
|
152
|
+
stdout: result.stdout ?? '',
|
|
153
|
+
stderr: result.stderr ?? ''
|
|
154
|
+
};
|
|
155
|
+
} finally{
|
|
156
|
+
external_node_fs_default().rmSync(tempDir, {
|
|
157
|
+
recursive: true,
|
|
158
|
+
force: true
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const printOxlintOutput = ({ stdout, stderr })=>{
|
|
163
|
+
if (stdout) process.stdout.write(stdout);
|
|
164
|
+
if (stderr) process.stderr.write(stderr);
|
|
165
|
+
};
|
|
166
|
+
exports.printOxlintOutput = __webpack_exports__.printOxlintOutput;
|
|
167
|
+
exports.runOxlintRules = __webpack_exports__.runOxlintRules;
|
|
168
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
169
|
+
"printOxlintOutput",
|
|
170
|
+
"runOxlintRules"
|
|
171
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
172
|
+
Object.defineProperty(exports, '__esModule', {
|
|
173
|
+
value: true
|
|
174
|
+
});
|
|
@@ -0,0 +1,179 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
});
|