@jay-framework/plugin-validator 0.23.1 → 0.24.1
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/dist/index.js +97 -0
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1995,6 +1995,96 @@ async function validatePackageJson(context, result) {
|
|
|
1995
1995
|
});
|
|
1996
1996
|
}
|
|
1997
1997
|
}
|
|
1998
|
+
function isBareFunctionExport(exportName, context) {
|
|
1999
|
+
const sourcePath = resolveExportSourceFile(exportName, context);
|
|
2000
|
+
if (!sourcePath) return false;
|
|
2001
|
+
let sourceCode;
|
|
2002
|
+
try {
|
|
2003
|
+
sourceCode = fs.readFileSync(sourcePath, "utf-8");
|
|
2004
|
+
} catch {
|
|
2005
|
+
return false;
|
|
2006
|
+
}
|
|
2007
|
+
const sourceFile = ts.createSourceFile(
|
|
2008
|
+
sourcePath,
|
|
2009
|
+
sourceCode,
|
|
2010
|
+
ts.ScriptTarget.Latest,
|
|
2011
|
+
true,
|
|
2012
|
+
ts.ScriptKind.TS
|
|
2013
|
+
);
|
|
2014
|
+
for (const statement of sourceFile.statements) {
|
|
2015
|
+
if (ts.isFunctionDeclaration(statement) && hasExportModifier(statement) && statement.name?.text === exportName) {
|
|
2016
|
+
return true;
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
return false;
|
|
2020
|
+
}
|
|
2021
|
+
function resolveModulePathWithJsToTs(basePath) {
|
|
2022
|
+
const result = resolveModulePath(basePath);
|
|
2023
|
+
if (result) return result;
|
|
2024
|
+
if (basePath.endsWith(".js")) {
|
|
2025
|
+
return resolveModulePath(basePath.slice(0, -3) + ".ts");
|
|
2026
|
+
}
|
|
2027
|
+
return void 0;
|
|
2028
|
+
}
|
|
2029
|
+
function resolveExportSourceFile(exportName, context) {
|
|
2030
|
+
const modulePath = context.manifest.module || "index";
|
|
2031
|
+
const entryBase = path.join(context.pluginPath, modulePath);
|
|
2032
|
+
const libEntryBase = path.join(context.pluginPath, "lib", modulePath);
|
|
2033
|
+
const sourceEntry = resolveModulePath(entryBase) || resolveModulePath(libEntryBase);
|
|
2034
|
+
if (!sourceEntry || !sourceEntry.endsWith(".ts")) return void 0;
|
|
2035
|
+
return followExportChain(exportName, sourceEntry);
|
|
2036
|
+
}
|
|
2037
|
+
function followExportChain(exportName, filePath) {
|
|
2038
|
+
let sourceCode;
|
|
2039
|
+
try {
|
|
2040
|
+
sourceCode = fs.readFileSync(filePath, "utf-8");
|
|
2041
|
+
} catch {
|
|
2042
|
+
return void 0;
|
|
2043
|
+
}
|
|
2044
|
+
const sourceFile = ts.createSourceFile(
|
|
2045
|
+
filePath,
|
|
2046
|
+
sourceCode,
|
|
2047
|
+
ts.ScriptTarget.Latest,
|
|
2048
|
+
true,
|
|
2049
|
+
ts.ScriptKind.TS
|
|
2050
|
+
);
|
|
2051
|
+
const starReexportModules = [];
|
|
2052
|
+
for (const statement of sourceFile.statements) {
|
|
2053
|
+
if (ts.isExportDeclaration(statement) && statement.moduleSpecifier) {
|
|
2054
|
+
if (!ts.isStringLiteral(statement.moduleSpecifier)) continue;
|
|
2055
|
+
const moduleSpec = statement.moduleSpecifier.text;
|
|
2056
|
+
if (!statement.exportClause) {
|
|
2057
|
+
starReexportModules.push(moduleSpec);
|
|
2058
|
+
continue;
|
|
2059
|
+
}
|
|
2060
|
+
if (ts.isNamedExports(statement.exportClause)) {
|
|
2061
|
+
for (const element of statement.exportClause.elements) {
|
|
2062
|
+
if (element.name.text === exportName) {
|
|
2063
|
+
const resolvedBase = path.resolve(path.dirname(filePath), moduleSpec);
|
|
2064
|
+
return resolveModulePathWithJsToTs(resolvedBase);
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
if (ts.isFunctionDeclaration(statement) && hasExportModifier(statement)) {
|
|
2070
|
+
if (statement.name?.text === exportName) return filePath;
|
|
2071
|
+
}
|
|
2072
|
+
if (ts.isVariableStatement(statement) && hasExportModifier(statement)) {
|
|
2073
|
+
for (const decl of statement.declarationList.declarations) {
|
|
2074
|
+
if (ts.isIdentifier(decl.name) && decl.name.text === exportName) return filePath;
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
for (const moduleSpec of starReexportModules) {
|
|
2079
|
+
if (!moduleSpec.startsWith(".")) continue;
|
|
2080
|
+
const resolvedBase = path.resolve(path.dirname(filePath), moduleSpec);
|
|
2081
|
+
const resolved = resolveModulePathWithJsToTs(resolvedBase);
|
|
2082
|
+
if (!resolved) continue;
|
|
2083
|
+
const found = followExportChain(exportName, resolved);
|
|
2084
|
+
if (found) return found;
|
|
2085
|
+
}
|
|
2086
|
+
return void 0;
|
|
2087
|
+
}
|
|
1998
2088
|
async function validateDynamicContracts(context, result) {
|
|
1999
2089
|
const { dynamic_contracts } = context.manifest;
|
|
2000
2090
|
if (!dynamic_contracts) return;
|
|
@@ -2021,6 +2111,13 @@ async function validateDynamicContracts(context, result) {
|
|
|
2021
2111
|
suggestion: `Create generator file at ${generatorPath}.ts`
|
|
2022
2112
|
});
|
|
2023
2113
|
}
|
|
2114
|
+
} else if (isBareFunctionExport(config.generator, context)) {
|
|
2115
|
+
result.errors.push({
|
|
2116
|
+
type: "export-mismatch",
|
|
2117
|
+
message: `Generator "${config.generator}" for ${prefix} is a bare function — it must be a DynamicContractGenerator object`,
|
|
2118
|
+
location: "plugin.yaml dynamic_contracts",
|
|
2119
|
+
suggestion: `Use makeContractGenerator().generateWith(...) from @jay-framework/fullstack-component instead of exporting a plain function`
|
|
2120
|
+
});
|
|
2024
2121
|
}
|
|
2025
2122
|
}
|
|
2026
2123
|
if (config.component) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/plugin-validator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"description": "Validation tool for Jay Stack plugins",
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"test:watch": "vitest"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@jay-framework/compiler-jay-html": "^0.
|
|
29
|
-
"@jay-framework/compiler-shared": "^0.
|
|
30
|
-
"@jay-framework/typescript-bridge": "^0.
|
|
28
|
+
"@jay-framework/compiler-jay-html": "^0.24.1",
|
|
29
|
+
"@jay-framework/compiler-shared": "^0.24.1",
|
|
30
|
+
"@jay-framework/typescript-bridge": "^0.24.1",
|
|
31
31
|
"chalk": "^4.1.2",
|
|
32
32
|
"yaml": "^2.3.4"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@jay-framework/dev-environment": "^0.
|
|
35
|
+
"@jay-framework/dev-environment": "^0.24.1",
|
|
36
36
|
"@types/node": "^22.15.21",
|
|
37
37
|
"rimraf": "^5.0.5",
|
|
38
38
|
"tsup": "^8.0.1",
|