@bleedingdev/modern-js-code-tools 3.9.0-ultramodern.1 → 3.9.0-ultramodern.10
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/bin/modern-api-check-files.mjs +4 -0
- package/bin/modern-api-check.mjs +4 -0
- package/dist/cjs/cli/microvertical-api-check.cjs +71 -0
- package/dist/cjs/cli/oxlint.cjs +9 -5
- package/dist/cjs/microvertical-api-baseline.cjs +677 -0
- package/dist/cjs/microvertical-api-boundary.cjs +507 -0
- package/dist/cjs/microvertical-api-owner.cjs +217 -0
- package/dist/cjs/oxlint-plugin/rules/strict-effect-api-boundaries.cjs +7 -5
- package/dist/cjs/strict-effect-runtime.cjs +411 -0
- package/dist/esm/cli/microvertical-api-check.js +33 -0
- package/dist/esm/cli/oxlint.js +10 -6
- package/dist/esm/microvertical-api-baseline.js +621 -0
- package/dist/esm/microvertical-api-boundary.js +449 -0
- package/dist/esm/microvertical-api-owner.js +162 -0
- package/dist/esm/oxlint-plugin/rules/strict-effect-api-boundaries.js +7 -5
- package/dist/esm/strict-effect-runtime.js +358 -0
- package/dist/esm-node/cli/microvertical-api-check.js +34 -0
- package/dist/esm-node/cli/oxlint.js +10 -6
- package/dist/esm-node/microvertical-api-baseline.js +622 -0
- package/dist/esm-node/microvertical-api-boundary.js +450 -0
- package/dist/esm-node/microvertical-api-owner.js +163 -0
- package/dist/esm-node/oxlint-plugin/rules/strict-effect-api-boundaries.js +7 -5
- package/dist/esm-node/strict-effect-runtime.js +359 -0
- package/dist/types/cli/microvertical-api-check.d.ts +1 -0
- package/dist/types/microvertical-api-baseline.d.ts +28 -0
- package/dist/types/microvertical-api-boundary.d.ts +32 -0
- package/dist/types/microvertical-api-owner.d.ts +6 -0
- package/dist/types/strict-effect-runtime.d.ts +10 -0
- package/package.json +25 -4
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import node_fs from "node:fs";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import { parse } from "@babel/parser";
|
|
4
|
+
import traverse, { Hub, NodePath } from "@babel/traverse";
|
|
5
|
+
import * as __rspack_external__babel_types_6e8337dd from "@babel/types";
|
|
6
|
+
const edge = '@modern-js/bff-effect/effect-edge';
|
|
7
|
+
const nodeRuntime = '@modern-js/bff-effect/effect';
|
|
8
|
+
const sharedRuntime = /^@[^/]+\/shared-contracts\/server\/effect-bff-runtime$/u;
|
|
9
|
+
const failure = 'Generated API entries must export defineEffectBff(...) or the server-only shared Effect BFF assembly helper with an explicitly composed handler Layer and an unshadowed executable root; entries must implement handlers through HttpApiBuilder.group.';
|
|
10
|
+
const invalidSources = new WeakSet();
|
|
11
|
+
function invalidSource(message) {
|
|
12
|
+
const error = new Error(message);
|
|
13
|
+
invalidSources.add(error);
|
|
14
|
+
return error;
|
|
15
|
+
}
|
|
16
|
+
class SourceValidationHub extends Hub {
|
|
17
|
+
buildError(_node, message) {
|
|
18
|
+
return invalidSource(message);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function createEffectApiImportResolver(filename) {
|
|
22
|
+
const directory = node_fs.realpathSync(node_path.dirname(filename));
|
|
23
|
+
const owner = node_fs.realpathSync(node_path.resolve(directory, '..'));
|
|
24
|
+
const resolve = (from)=>(specifier)=>{
|
|
25
|
+
if (!specifier.startsWith('.')) return;
|
|
26
|
+
const target = node_path.resolve(node_path.dirname(from), specifier);
|
|
27
|
+
if (!target.startsWith(`${owner}${node_path.sep}`)) return;
|
|
28
|
+
for (const candidate of [
|
|
29
|
+
target,
|
|
30
|
+
`${target}.ts`,
|
|
31
|
+
`${target}.mts`
|
|
32
|
+
])try {
|
|
33
|
+
const real = node_fs.realpathSync(candidate);
|
|
34
|
+
if (!real.startsWith(`${owner}${node_path.sep}`) || node_fs.statSync(real).size > 1000000) return;
|
|
35
|
+
return {
|
|
36
|
+
id: real,
|
|
37
|
+
source: node_fs.readFileSync(real, 'utf8'),
|
|
38
|
+
resolveImport: resolve(real)
|
|
39
|
+
};
|
|
40
|
+
} catch {}
|
|
41
|
+
};
|
|
42
|
+
return resolve(node_path.join(directory, node_path.basename(filename)));
|
|
43
|
+
}
|
|
44
|
+
function strictEffectRuntimeTopologyViolation(source, resolveImport) {
|
|
45
|
+
const modules = new Map();
|
|
46
|
+
const owners = new Map();
|
|
47
|
+
const paths = new Map();
|
|
48
|
+
const mutated = new Set();
|
|
49
|
+
const load = (input)=>{
|
|
50
|
+
const existing = modules.get(input.id);
|
|
51
|
+
if (existing) return existing;
|
|
52
|
+
if (modules.size >= 64 || input.source.length > 1000000) throw invalidSource('API source budget exceeded');
|
|
53
|
+
let file;
|
|
54
|
+
try {
|
|
55
|
+
file = parse(input.source, {
|
|
56
|
+
sourceType: 'module',
|
|
57
|
+
sourceFilename: input.id,
|
|
58
|
+
plugins: [
|
|
59
|
+
"typescript"
|
|
60
|
+
]
|
|
61
|
+
});
|
|
62
|
+
} catch (cause) {
|
|
63
|
+
if ('object' == typeof cause && null !== cause && 'code' in cause && 'BABEL_PARSER_SYNTAX_ERROR' === cause.code && 'reasonCode' in cause && 'string' == typeof cause.reasonCode) throw invalidSource('Invalid API syntax');
|
|
64
|
+
throw cause;
|
|
65
|
+
}
|
|
66
|
+
const module = {
|
|
67
|
+
...input,
|
|
68
|
+
file
|
|
69
|
+
};
|
|
70
|
+
modules.set(input.id, module);
|
|
71
|
+
const program = NodePath.get({
|
|
72
|
+
hub: new SourceValidationHub(),
|
|
73
|
+
parentPath: void 0,
|
|
74
|
+
parent: file,
|
|
75
|
+
container: file,
|
|
76
|
+
key: 'program'
|
|
77
|
+
});
|
|
78
|
+
program.setContext();
|
|
79
|
+
traverse(file, {
|
|
80
|
+
enter (nodePath) {
|
|
81
|
+
paths.set(nodePath.node, nodePath);
|
|
82
|
+
owners.set(nodePath.node, module);
|
|
83
|
+
if (nodePath.isAssignmentExpression() || nodePath.isUpdateExpression() || nodePath.isUnaryExpression({
|
|
84
|
+
operator: 'delete'
|
|
85
|
+
})) {
|
|
86
|
+
let target = nodePath.isAssignmentExpression() ? nodePath.node.left : nodePath.node.argument;
|
|
87
|
+
while(__rspack_external__babel_types_6e8337dd.isMemberExpression(target))target = target.object;
|
|
88
|
+
if (__rspack_external__babel_types_6e8337dd.isIdentifier(target)) {
|
|
89
|
+
const binding = nodePath.scope.getBinding(target.name);
|
|
90
|
+
if (binding) mutated.add(binding);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (nodePath.isTSModuleDeclaration() && __rspack_external__babel_types_6e8337dd.isIdentifier(nodePath.node.id)) {
|
|
94
|
+
const binding = nodePath.scope.getBinding(nodePath.node.id.name);
|
|
95
|
+
if (binding) mutated.add(binding);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}, program.scope, void 0, program);
|
|
99
|
+
return module;
|
|
100
|
+
};
|
|
101
|
+
try {
|
|
102
|
+
const entry = load({
|
|
103
|
+
id: '/entry.ts',
|
|
104
|
+
source,
|
|
105
|
+
resolveImport
|
|
106
|
+
});
|
|
107
|
+
const unwrap = (node)=>{
|
|
108
|
+
while(__rspack_external__babel_types_6e8337dd.isParenthesizedExpression(node) || __rspack_external__babel_types_6e8337dd.isTSSatisfiesExpression(node) || __rspack_external__babel_types_6e8337dd.isTSAsExpression(node) || __rspack_external__babel_types_6e8337dd.isTSTypeAssertion(node) || __rspack_external__babel_types_6e8337dd.isTSNonNullExpression(node))node = node.expression;
|
|
109
|
+
return node;
|
|
110
|
+
};
|
|
111
|
+
const binding = (node)=>{
|
|
112
|
+
node = unwrap(node);
|
|
113
|
+
if (!__rspack_external__babel_types_6e8337dd.isIdentifier(node)) return;
|
|
114
|
+
const nodePath = paths.get(node);
|
|
115
|
+
if (!nodePath) throw new Error('Missing API lexical scope');
|
|
116
|
+
const value = nodePath.scope.getBinding(node.name);
|
|
117
|
+
return value?.constant && !mutated.has(value) ? value : void 0;
|
|
118
|
+
};
|
|
119
|
+
const declaration = (node)=>binding(node)?.path.node;
|
|
120
|
+
const imported = (node)=>{
|
|
121
|
+
const value = binding(node);
|
|
122
|
+
const decl = value?.path.node;
|
|
123
|
+
if (!decl || !__rspack_external__babel_types_6e8337dd.isImportSpecifier(decl) && !__rspack_external__babel_types_6e8337dd.isImportNamespaceSpecifier(decl) || __rspack_external__babel_types_6e8337dd.isImportSpecifier(decl) && 'type' === decl.importKind) return;
|
|
124
|
+
const statement = value.path.parent;
|
|
125
|
+
if (!__rspack_external__babel_types_6e8337dd.isImportDeclaration(statement) || 'type' === statement.importKind) return;
|
|
126
|
+
return {
|
|
127
|
+
namespace: __rspack_external__babel_types_6e8337dd.isImportNamespaceSpecifier(decl),
|
|
128
|
+
name: __rspack_external__babel_types_6e8337dd.isImportNamespaceSpecifier(decl) ? '*' : __rspack_external__babel_types_6e8337dd.isIdentifier(decl.imported) ? decl.imported.name : decl.imported.value,
|
|
129
|
+
specifier: statement.source.value
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
const namespaceSources = {
|
|
133
|
+
HttpApi: [
|
|
134
|
+
edge,
|
|
135
|
+
'effect/unstable/httpapi'
|
|
136
|
+
],
|
|
137
|
+
HttpApiBuilder: [
|
|
138
|
+
edge,
|
|
139
|
+
'effect/unstable/httpapi'
|
|
140
|
+
],
|
|
141
|
+
HttpRouter: [
|
|
142
|
+
edge,
|
|
143
|
+
'effect/unstable/http'
|
|
144
|
+
]
|
|
145
|
+
};
|
|
146
|
+
const native = (node, name, sources)=>{
|
|
147
|
+
const value = imported(node);
|
|
148
|
+
if (!value) return false;
|
|
149
|
+
const importedNameMatches = value.namespace ? value.specifier === `effect/${name}` : value.name === name && value.specifier !== `effect/${name}`;
|
|
150
|
+
return importedNameMatches && (sources ?? namespaceSources[name] ?? [
|
|
151
|
+
edge
|
|
152
|
+
]).includes(value.specifier);
|
|
153
|
+
};
|
|
154
|
+
const method = (node, namespace, member, sources)=>{
|
|
155
|
+
node = unwrap(node);
|
|
156
|
+
return __rspack_external__babel_types_6e8337dd.isMemberExpression(node) && !node.computed && __rspack_external__babel_types_6e8337dd.isIdentifier(node.property, {
|
|
157
|
+
name: member
|
|
158
|
+
}) && native(node.object, namespace, sources);
|
|
159
|
+
};
|
|
160
|
+
const initialized = (node)=>{
|
|
161
|
+
const value = binding(node);
|
|
162
|
+
return value?.kind === 'const' && __rspack_external__babel_types_6e8337dd.isVariableDeclarator(value.path.node) ? value.path.node.init ?? void 0 : void 0;
|
|
163
|
+
};
|
|
164
|
+
const moduleFor = (node)=>{
|
|
165
|
+
const value = imported(node);
|
|
166
|
+
if (!value) return;
|
|
167
|
+
const input = owners.get(node)?.resolveImport?.(value.specifier);
|
|
168
|
+
return input ? {
|
|
169
|
+
module: load(input),
|
|
170
|
+
name: value.name
|
|
171
|
+
} : void 0;
|
|
172
|
+
};
|
|
173
|
+
const exported = (module, name)=>{
|
|
174
|
+
for (const statement of module.file.program.body)if (__rspack_external__babel_types_6e8337dd.isExportNamedDeclaration(statement) && 'type' !== statement.exportKind) {
|
|
175
|
+
if (__rspack_external__babel_types_6e8337dd.isVariableDeclaration(statement.declaration)) {
|
|
176
|
+
for (const decl of statement.declaration.declarations)if (__rspack_external__babel_types_6e8337dd.isIdentifier(decl.id, {
|
|
177
|
+
name
|
|
178
|
+
})) return decl.id;
|
|
179
|
+
}
|
|
180
|
+
if (!statement.source) {
|
|
181
|
+
const specifier = statement.specifiers.find((element)=>__rspack_external__babel_types_6e8337dd.isExportSpecifier(element) && 'type' !== element.exportKind && (__rspack_external__babel_types_6e8337dd.isIdentifier(element.exported) ? element.exported.name : element.exported.value) === name);
|
|
182
|
+
if (__rspack_external__babel_types_6e8337dd.isExportSpecifier(specifier)) return specifier.local;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
const externalValue = (node)=>{
|
|
187
|
+
const value = moduleFor(node);
|
|
188
|
+
return value ? exported(value.module, value.name) : void 0;
|
|
189
|
+
};
|
|
190
|
+
const apiIdentity = (node, seen = new Set())=>{
|
|
191
|
+
node = unwrap(node);
|
|
192
|
+
if (seen.has(node)) return;
|
|
193
|
+
seen.add(node);
|
|
194
|
+
const value = imported(node);
|
|
195
|
+
if (value) {
|
|
196
|
+
if (!value.specifier.startsWith('.')) return;
|
|
197
|
+
const module = moduleFor(node);
|
|
198
|
+
const exportedValue = module && exported(module.module, module.name);
|
|
199
|
+
if (exportedValue) return apiIdentity(exportedValue, seen);
|
|
200
|
+
if (module && /(?:^|\/)shared\/(?:api|rpc)\.ts$/u.test(value.specifier)) return `${module.module.id}:import:${value.name}`;
|
|
201
|
+
if (!owners.get(node)?.resolveImport && /(?:^|\/)shared\/(?:api|rpc)\.ts$/u.test(value.specifier)) return `${value.specifier}:${value.name}`;
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const init = initialized(node);
|
|
205
|
+
if (init && __rspack_external__babel_types_6e8337dd.isIdentifier(unwrap(init))) return apiIdentity(init, seen);
|
|
206
|
+
const valueBinding = binding(node);
|
|
207
|
+
return valueBinding ? `${owners.get(valueBinding.path.node)?.id}:${valueBinding.identifier.start}` : void 0;
|
|
208
|
+
};
|
|
209
|
+
const properties = (node)=>{
|
|
210
|
+
node = unwrap(node);
|
|
211
|
+
if (!__rspack_external__babel_types_6e8337dd.isObjectExpression(node)) return;
|
|
212
|
+
const result = new Map();
|
|
213
|
+
for (const prop of node.properties){
|
|
214
|
+
if (!__rspack_external__babel_types_6e8337dd.isObjectProperty(prop) || prop.computed || !__rspack_external__babel_types_6e8337dd.isIdentifier(prop.key) || result.has(prop.key.name)) return;
|
|
215
|
+
result.set(prop.key.name, prop.value);
|
|
216
|
+
}
|
|
217
|
+
return result;
|
|
218
|
+
};
|
|
219
|
+
const active = new Set();
|
|
220
|
+
const guarded = (node, check)=>{
|
|
221
|
+
node = unwrap(node);
|
|
222
|
+
if (active.has(node) || active.size > 128) return false;
|
|
223
|
+
active.add(node);
|
|
224
|
+
try {
|
|
225
|
+
return check(node);
|
|
226
|
+
} finally{
|
|
227
|
+
active.delete(node);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
const layerSources = [
|
|
231
|
+
edge,
|
|
232
|
+
'effect',
|
|
233
|
+
'effect/Layer'
|
|
234
|
+
];
|
|
235
|
+
const returned = (body)=>{
|
|
236
|
+
if (!__rspack_external__babel_types_6e8337dd.isBlockStatement(body)) return body;
|
|
237
|
+
const statements = body.body;
|
|
238
|
+
const last = statements.at(-1);
|
|
239
|
+
return statements.slice(0, -1).every((statement)=>__rspack_external__babel_types_6e8337dd.isVariableDeclaration(statement)) && __rspack_external__babel_types_6e8337dd.isReturnStatement(last) ? last.argument : void 0;
|
|
240
|
+
};
|
|
241
|
+
const pipe = (node, check)=>__rspack_external__babel_types_6e8337dd.isMemberExpression(node.callee) && !node.callee.computed && __rspack_external__babel_types_6e8337dd.isIdentifier(node.callee.property, {
|
|
242
|
+
name: 'pipe'
|
|
243
|
+
}) && check(node.callee.object) && node.arguments.every((argument)=>method(argument, 'Layer', 'orDie', layerSources) || __rspack_external__babel_types_6e8337dd.isCallExpression(argument) && method(argument.callee, 'Layer', 'provide', layerSources) && argument.arguments.length > 0);
|
|
244
|
+
const handled = (node)=>{
|
|
245
|
+
node = unwrap(node);
|
|
246
|
+
if (!__rspack_external__babel_types_6e8337dd.isArrowFunctionExpression(node) && !__rspack_external__babel_types_6e8337dd.isFunctionExpression(node)) return false;
|
|
247
|
+
const parameter = node.params[0];
|
|
248
|
+
if (!__rspack_external__babel_types_6e8337dd.isIdentifier(parameter)) return false;
|
|
249
|
+
const body = returned(node.body);
|
|
250
|
+
const chain = (value, count = 0)=>{
|
|
251
|
+
value = unwrap(value);
|
|
252
|
+
if (__rspack_external__babel_types_6e8337dd.isIdentifier(value)) return count > 0 && declaration(value) === parameter;
|
|
253
|
+
return __rspack_external__babel_types_6e8337dd.isCallExpression(value) && __rspack_external__babel_types_6e8337dd.isMemberExpression(value.callee) && !value.callee.computed && __rspack_external__babel_types_6e8337dd.isIdentifier(value.callee.property) && [
|
|
254
|
+
'handle',
|
|
255
|
+
'handleRaw'
|
|
256
|
+
].includes(value.callee.property.name) && 2 === value.arguments.length && chain(value.callee.object, count + 1);
|
|
257
|
+
};
|
|
258
|
+
return !!body && chain(body);
|
|
259
|
+
};
|
|
260
|
+
const handlers = (node, api)=>guarded(node, (node)=>{
|
|
261
|
+
const init = initialized(node) ?? externalValue(node);
|
|
262
|
+
if (init) return handlers(init, api);
|
|
263
|
+
if (!__rspack_external__babel_types_6e8337dd.isCallExpression(node)) return false;
|
|
264
|
+
if (pipe(node, (value)=>handlers(value, api))) return true;
|
|
265
|
+
if (method(node.callee, 'Layer', 'mergeAll', layerSources)) return node.arguments.length > 0 && node.arguments.every((argument)=>handlers(argument, api));
|
|
266
|
+
return method(node.callee, 'HttpApiBuilder', 'group') && 3 === node.arguments.length && apiIdentity(node.arguments[0]) === api && handled(node.arguments[2]);
|
|
267
|
+
});
|
|
268
|
+
const transport = (node)=>guarded(node, (node)=>{
|
|
269
|
+
const init = initialized(node);
|
|
270
|
+
if (init) return transport(init);
|
|
271
|
+
if (!__rspack_external__babel_types_6e8337dd.isCallExpression(node)) return method(node, 'Layer', 'empty', layerSources);
|
|
272
|
+
return pipe(node, transport) || method(node.callee, 'HttpRouter', 'cors') || method(node.callee, 'Layer', 'mergeAll', layerSources) && node.arguments.length > 0 && node.arguments.every(transport);
|
|
273
|
+
});
|
|
274
|
+
const directLayer = (node, api)=>guarded(node, (node)=>{
|
|
275
|
+
const init = initialized(node);
|
|
276
|
+
if (init) return directLayer(init, api);
|
|
277
|
+
if (!__rspack_external__babel_types_6e8337dd.isCallExpression(node) || !__rspack_external__babel_types_6e8337dd.isMemberExpression(node.callee) || node.callee.computed || !__rspack_external__babel_types_6e8337dd.isIdentifier(node.callee.property, {
|
|
278
|
+
name: 'pipe'
|
|
279
|
+
})) return false;
|
|
280
|
+
const base = unwrap(node.callee.object);
|
|
281
|
+
return __rspack_external__babel_types_6e8337dd.isCallExpression(base) && method(base.callee, 'HttpApiBuilder', 'layer') && 1 === base.arguments.length && apiIdentity(base.arguments[0]) === api && node.arguments.length > 0 && node.arguments.every((argument)=>__rspack_external__babel_types_6e8337dd.isCallExpression(argument) && method(argument.callee, 'Layer', 'provide', layerSources) && 1 === argument.arguments.length && handlers(argument.arguments[0], api));
|
|
282
|
+
});
|
|
283
|
+
const rpc = (values)=>{
|
|
284
|
+
const api = values.get('api');
|
|
285
|
+
const apiLayer = values.get('layer');
|
|
286
|
+
const apiInit = api && (initialized(api) ?? unwrap(api));
|
|
287
|
+
if (!apiInit || !__rspack_external__babel_types_6e8337dd.isCallExpression(apiInit) || !method(apiInit.callee, 'HttpApi', 'make') || 1 !== apiInit.arguments.length || !apiLayer || !transport(apiLayer)) return false;
|
|
288
|
+
const config = values.get('rpc');
|
|
289
|
+
const fields = config && properties(config);
|
|
290
|
+
const route = fields?.get('path');
|
|
291
|
+
const serialization = fields?.get('serialization');
|
|
292
|
+
if (!__rspack_external__babel_types_6e8337dd.isStringLiteral(route, {
|
|
293
|
+
value: '/rpc'
|
|
294
|
+
}) || !__rspack_external__babel_types_6e8337dd.isStringLiteral(serialization, {
|
|
295
|
+
value: 'json'
|
|
296
|
+
})) return false;
|
|
297
|
+
const group = fields?.get('group');
|
|
298
|
+
const layer = fields?.get('layer');
|
|
299
|
+
const value = group && imported(group);
|
|
300
|
+
if (!group || !layer || value?.specifier !== '../shared/rpc.ts') return false;
|
|
301
|
+
const groupValue = externalValue(group);
|
|
302
|
+
const groupInit = groupValue && initialized(groupValue);
|
|
303
|
+
if (!groupInit || !__rspack_external__babel_types_6e8337dd.isCallExpression(groupInit) || !method(groupInit.callee, 'RpcGroup', 'make', [
|
|
304
|
+
'effect/unstable/rpc',
|
|
305
|
+
'@modern-js/bff-effect/effect-client'
|
|
306
|
+
])) return false;
|
|
307
|
+
const layerInit = initialized(layer) ?? unwrap(layer);
|
|
308
|
+
if (!__rspack_external__babel_types_6e8337dd.isCallExpression(layerInit) || !__rspack_external__babel_types_6e8337dd.isMemberExpression(layerInit.callee) || layerInit.callee.computed || !__rspack_external__babel_types_6e8337dd.isIdentifier(layerInit.callee.property, {
|
|
309
|
+
name: 'toLayer'
|
|
310
|
+
}) || apiIdentity(layerInit.callee.object) !== apiIdentity(group) || 1 !== layerInit.arguments.length) return false;
|
|
311
|
+
const implementation = unwrap(layerInit.arguments[0]);
|
|
312
|
+
if (!__rspack_external__babel_types_6e8337dd.isCallExpression(implementation) || !__rspack_external__babel_types_6e8337dd.isMemberExpression(implementation.callee) || implementation.callee.computed || !__rspack_external__babel_types_6e8337dd.isIdentifier(implementation.callee.property, {
|
|
313
|
+
name: 'of'
|
|
314
|
+
}) || apiIdentity(implementation.callee.object) !== apiIdentity(group) || 1 !== implementation.arguments.length) return false;
|
|
315
|
+
const entries = properties(implementation.arguments[0]);
|
|
316
|
+
return !!entries?.size && [
|
|
317
|
+
...entries.values()
|
|
318
|
+
].every((value)=>__rspack_external__babel_types_6e8337dd.isArrowFunctionExpression(value) || __rspack_external__babel_types_6e8337dd.isFunctionExpression(value));
|
|
319
|
+
};
|
|
320
|
+
const runtime = (node)=>guarded(node, (node)=>{
|
|
321
|
+
const init = initialized(node);
|
|
322
|
+
if (init) return runtime(init);
|
|
323
|
+
if (!__rspack_external__babel_types_6e8337dd.isCallExpression(node)) return false;
|
|
324
|
+
const value = imported(node.callee);
|
|
325
|
+
if (value?.name === 'defineEffectBff' && [
|
|
326
|
+
edge,
|
|
327
|
+
nodeRuntime
|
|
328
|
+
].includes(value.specifier) || value?.name === 'assembleEffectBffRuntime' && sharedRuntime.test(value.specifier)) {
|
|
329
|
+
if (1 !== node.arguments.length) return false;
|
|
330
|
+
const values = properties(node.arguments[0]);
|
|
331
|
+
if (!values) return false;
|
|
332
|
+
if ('defineEffectBff' === value.name && values.has('rpc')) return rpc(values);
|
|
333
|
+
const api = values.get('api');
|
|
334
|
+
const apiBinding = api && imported(api);
|
|
335
|
+
if (!api || apiBinding?.specifier !== '../shared/api.ts') return false;
|
|
336
|
+
const identity = apiIdentity(api);
|
|
337
|
+
if (!identity) return false;
|
|
338
|
+
const layer = values.get('defineEffectBff' === value.name ? 'layer' : 'handlers');
|
|
339
|
+
const extra = values.get('transport');
|
|
340
|
+
return void 0 !== layer && ('defineEffectBff' === value.name ? directLayer(layer, identity) : handlers(layer, identity)) && (!extra || transport(extra));
|
|
341
|
+
}
|
|
342
|
+
const decl = declaration(node.callee);
|
|
343
|
+
const factory = decl && __rspack_external__babel_types_6e8337dd.isFunctionDeclaration(decl) ? decl : initialized(node.callee);
|
|
344
|
+
if (!factory || !__rspack_external__babel_types_6e8337dd.isFunctionDeclaration(factory) && !__rspack_external__babel_types_6e8337dd.isArrowFunctionExpression(factory) && !__rspack_external__babel_types_6e8337dd.isFunctionExpression(factory) || !factory.body) return false;
|
|
345
|
+
const result = returned(factory.body);
|
|
346
|
+
return !!result && runtime(result);
|
|
347
|
+
});
|
|
348
|
+
const root = entry.file.program.body.find((statement)=>__rspack_external__babel_types_6e8337dd.isExportDefaultDeclaration(statement));
|
|
349
|
+
return root && runtime(root.declaration) ? void 0 : failure;
|
|
350
|
+
} catch (cause) {
|
|
351
|
+
if ('object' == typeof cause && null !== cause && invalidSources.has(cause)) return failure;
|
|
352
|
+
const message = 'object' == typeof cause && null !== cause && 'message' in cause && 'string' == typeof cause.message ? cause.message : String(cause);
|
|
353
|
+
throw new Error(`Strict Effect API analysis failed: ${message}`, {
|
|
354
|
+
cause
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
export { createEffectApiImportResolver, strictEffectRuntimeTopologyViolation };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { checkMicroVerticalApiBoundaries, checkMicroVerticalApiConsumerFiles } from "../microvertical-api-boundary.js";
|
|
3
|
+
function runMicroVerticalApiCheckCli(args = process.argv.slice(2), filesOnly = false) {
|
|
4
|
+
let workspaceRoot = process.env.ULTRAMODERN_WORKSPACE_ROOT ?? process.cwd();
|
|
5
|
+
let baselinePackageDirectory;
|
|
6
|
+
for(let index = 0; index < args.length; index += 1){
|
|
7
|
+
const argument = args[index];
|
|
8
|
+
if ('--help' === argument || '-h' === argument) {
|
|
9
|
+
console.log(`${filesOnly ? 'modern-api-check-files' : 'modern-api-check'} [--workspace-root <path>] [--baseline-package-directory <path>]\n${filesOnly ? 'Checks consumer files, contracts, package exports and owner identity. Does not analyze runtime topology; run the strict Effect source phase separately.' : 'Checks consumer files, contracts, package exports, owner identity and runtime topology once per API entry.'}\nWorkspace defaults to ULTRAMODERN_WORKSPACE_ROOT then cwd. Exit codes: 0 valid, 1 consumer violation, 2 tool/configuration failure.`);
|
|
10
|
+
return 0;
|
|
11
|
+
}
|
|
12
|
+
if (![
|
|
13
|
+
'--workspace-root',
|
|
14
|
+
'--baseline-package-directory'
|
|
15
|
+
].includes(argument ?? '') || !args[index + 1] || args[index + 1]?.startsWith('--')) {
|
|
16
|
+
console.error(`Invalid argument: ${argument ?? ''}. Use --help.`);
|
|
17
|
+
return 2;
|
|
18
|
+
}
|
|
19
|
+
const value = args[++index];
|
|
20
|
+
if ('--workspace-root' === argument) workspaceRoot = value;
|
|
21
|
+
else baselinePackageDirectory = value;
|
|
22
|
+
}
|
|
23
|
+
const result = (filesOnly ? checkMicroVerticalApiConsumerFiles : checkMicroVerticalApiBoundaries)({
|
|
24
|
+
workspaceRoot,
|
|
25
|
+
baselinePackageDirectory
|
|
26
|
+
});
|
|
27
|
+
for (const diagnostic of result.diagnostics)console.error(`API violation: ${diagnostic}`);
|
|
28
|
+
for (const error of result.toolErrors)console.error(`API tool error: ${error}`);
|
|
29
|
+
if (result.toolErrors.length) return 2;
|
|
30
|
+
if (result.diagnostics.length) return 1;
|
|
31
|
+
console.log(`UltraModern API ${filesOnly ? 'consumer files' : 'boundary'} check passed.`);
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
export { runMicroVerticalApiCheckCli };
|
|
@@ -4,7 +4,7 @@ import node_fs from "node:fs";
|
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import node_os from "node:os";
|
|
6
6
|
import node_path from "node:path";
|
|
7
|
-
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
8
8
|
const oxlint_require = createRequire(import.meta.url);
|
|
9
9
|
const ignoredDirectories = new Set([
|
|
10
10
|
'.modern',
|
|
@@ -74,22 +74,26 @@ const runOxlintRules = ({ cwd, targets, rules })=>{
|
|
|
74
74
|
stdout: '',
|
|
75
75
|
stderr: ''
|
|
76
76
|
};
|
|
77
|
+
const pluginPath = resolvePluginPath();
|
|
77
78
|
const tempDir = node_fs.mkdtempSync(node_path.join(node_os.tmpdir(), 'modern-code-tools-oxlint-'));
|
|
78
79
|
const configPath = node_path.join(tempDir, 'oxlint.config.mjs');
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
const adapterPath = node_path.join(tempDir, 'oxlint-plugin.mjs');
|
|
81
|
+
try {
|
|
82
|
+
node_fs.writeFileSync(adapterPath, `import plugin from ${JSON.stringify(pathToFileURL(pluginPath).href)};
|
|
83
|
+
export default plugin.rules ? plugin : plugin.default;
|
|
84
|
+
`, 'utf-8');
|
|
85
|
+
node_fs.writeFileSync(configPath, `export default {
|
|
86
|
+
jsPlugins: [${JSON.stringify(adapterPath)}],
|
|
82
87
|
rules: ${JSON.stringify(rules, null, 2)}
|
|
83
88
|
};
|
|
84
89
|
`, 'utf-8');
|
|
85
|
-
try {
|
|
86
90
|
const result = spawnSync(process.execPath, [
|
|
87
91
|
resolveOxlintBin(),
|
|
88
92
|
...resolvedTargets,
|
|
89
93
|
'--config',
|
|
90
94
|
configPath,
|
|
91
95
|
'--format',
|
|
92
|
-
'
|
|
96
|
+
'default',
|
|
93
97
|
'--quiet'
|
|
94
98
|
], {
|
|
95
99
|
cwd,
|