This commit is contained in:
wkj 2024-11-06 14:28:27 +08:00
parent 9c2a6a488f
commit 45e78466dd
1 changed files with 56 additions and 55 deletions

View File

@ -1,12 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerIgnoredForeignKeyMap = registerIgnoredForeignKeyMap;
exports.registerFreeEntities = registerFreeEntities;
exports.registerIgnoredRelationPathMap = registerIgnoredRelationPathMap;
exports.registerFixedDestinationPathMap = registerFixedDestinationPathMap;
exports.registerDeducedRelationMap = registerDeducedRelationMap;
exports.analyzeEntities = analyzeEntities;
exports.buildSchema = buildSchema;
exports.buildSchema = exports.analyzeEntities = exports.registerDeducedRelationMap = exports.registerFixedDestinationPathMap = exports.registerIgnoredRelationPathMap = exports.registerFreeEntities = exports.registerIgnoredForeignKeyMap = void 0;
const tslib_1 = require("tslib");
const path_1 = tslib_1.__importDefault(require("path"));
const assert_1 = tslib_1.__importDefault(require("assert"));
@ -579,54 +573,54 @@ function analyzeImportDeclaration(node, referencedSchemas, additionalImports, fi
* @param filename
* @returns
*/
// function getImportedFilePath(path: string, fileSpecifierPath: string, filename: string) {
// let importedFilepath = '';
// const getExistedFileName = () => {
// if (existsSync(`${importedFilepath}.ts`)) {
// return `${importedFilepath}.ts`;
// }
// else if (existsSync(`${importedFilepath}.d.ts`)) {
// return `${importedFilepath}.d.ts`;
// }
// return '';
// };
// if (fileSpecifierPath.startsWith('.')) {
// importedFilepath = PathLib.join(path, fileSpecifierPath);
// const importedFilename = getExistedFileName();
// assert(importedFilename, `「${filename}」中import路径${fileSpecifierPath}找不到对应的声明`);
// return importedFilename;
// }
// else {
// const cwd = process.cwd();
// const fileSpecifierPaths = fileSpecifierPath.split('/');
// const moduleName = fileSpecifierPaths[0] || fileSpecifierPaths[1];
// assert(moduleName);
// // 从path向外找package.json -> node_modules直至找到fileSpecifier
// const paths = path.split('/');
// for (let iter = paths.length; iter >= 0; iter--) {
// const paths2 = paths.slice(0, iter);
// const pkgJsonPath = PathLib.join(cwd, ...paths2, 'package.json');
// if (existsSync(pkgJsonPath)) {
// const pkgJson = require(pkgJsonPath);
// if (pkgJson.dependencies?.hasOwnProperty(moduleName)) {
// const dependentPath = pkgJson.dependencies[moduleName] as string;
// if (dependentPath.trimStart().startsWith('file:')) {
// const dependentFilePath = dependentPath.trimStart().slice(5);
// importedFilepath = PathLib.join(pkgJsonPath, '..', dependentFilePath, ...(fileSpecifierPaths[0] ? fileSpecifierPaths.slice(1) : (fileSpecifierPaths.slice(2))));
// }
// else {
// importedFilepath = PathLib.join(pkgJsonPath, '..', 'node_modules', fileSpecifierPath);
// }
// const importedFilename = getExistedFileName();
// if (importedFilename) {
// return importedFilename;
// }
// }
// }
// }
// }
// assert(false, `「${filename}」中import路径${fileSpecifierPath}找不到对应的声明`);
// }
function getImportedFilePath(path, fileSpecifierPath, filename) {
let importedFilepath = '';
const getExistedFileName = () => {
if ((0, fs_1.existsSync)(`${importedFilepath}.ts`)) {
return `${importedFilepath}.ts`;
}
else if ((0, fs_1.existsSync)(`${importedFilepath}.d.ts`)) {
return `${importedFilepath}.d.ts`;
}
return '';
};
if (fileSpecifierPath.startsWith('.')) {
importedFilepath = path_1.default.join(path, fileSpecifierPath);
const importedFilename = getExistedFileName();
(0, assert_1.default)(importedFilename, `${filename}」中import路径${fileSpecifierPath}找不到对应的声明`);
return importedFilename;
}
else {
const cwd = process.cwd();
const fileSpecifierPaths = fileSpecifierPath.split('/');
const moduleName = fileSpecifierPaths[0] || fileSpecifierPaths[1];
(0, assert_1.default)(moduleName);
// 从path向外找package.json -> node_modules直至找到fileSpecifier
const paths = path.split('/');
for (let iter = paths.length; iter >= 0; iter--) {
const paths2 = paths.slice(0, iter);
const pkgJsonPath = path_1.default.join(cwd, ...paths2, 'package.json');
if ((0, fs_1.existsSync)(pkgJsonPath)) {
const pkgJson = require(pkgJsonPath);
if (pkgJson.dependencies?.hasOwnProperty(moduleName)) {
const dependentPath = pkgJson.dependencies[moduleName];
if (dependentPath.trimStart().startsWith('file:')) {
const dependentFilePath = dependentPath.trimStart().slice(5);
importedFilepath = path_1.default.join(pkgJsonPath, '..', dependentFilePath, ...(fileSpecifierPaths[0] ? fileSpecifierPaths.slice(1) : (fileSpecifierPaths.slice(2))));
}
else {
importedFilepath = path_1.default.join(pkgJsonPath, '..', 'node_modules', fileSpecifierPath);
}
const importedFilename = getExistedFileName();
if (importedFilename) {
return importedFilename;
}
}
}
}
}
(0, assert_1.default)(false, `${filename}」中import路径${fileSpecifierPath}找不到对应的声明`);
}
function analyzeSchemaDefinition(node, moduleName, filename, path, program, referencedSchemas, schemaAttrs, enumAttributes, importAttrFrom, relativePath) {
let hasEntityAttr = false;
let hasEntityIdAttr = false;
@ -3738,6 +3732,7 @@ let FIXED_FOR_ALL_DESTINATION_PATH_ENTITIES = [];
function registerIgnoredForeignKeyMap(map) {
IGNORED_FOREIGN_KEY_MAP = map;
}
exports.registerIgnoredForeignKeyMap = registerIgnoredForeignKeyMap;
/**
* 此函数不再使用
* @param map
@ -3747,6 +3742,7 @@ function registerFreeEntities(selectFreeEntities = [], createFreeEntities = [],
CREATE_FREE_ENTITIES = createFreeEntities;
UPDATE_FREE_ENTITIES = updateFreeEntities;
}
exports.registerFreeEntities = registerFreeEntities;
/**
* 此函数不再使用
* @param map
@ -3756,6 +3752,7 @@ function registerIgnoredRelationPathMap(map) {
IGNORED_RELATION_PATH_MAP[(0, string_1.firstLetterUpperCase)(k)] = map[k];
}
}
exports.registerIgnoredRelationPathMap = registerIgnoredRelationPathMap;
/**
* 很多路径虽然最后指向同一对象但不能封掉封了会导致查询的时候找不到对应的路径path
* @param map
@ -3773,6 +3770,7 @@ function registerFixedDestinationPathMap(map) {
}
}
}
exports.registerFixedDestinationPathMap = registerFixedDestinationPathMap;
/**
* 此函数不再使用
* @param map
@ -3791,6 +3789,7 @@ function registerDeducedRelationMap(map) {
DEDUCED_RELATION_MAP[entity] = map[k];
}
}
exports.registerDeducedRelationMap = registerDeducedRelationMap;
/**
* 输出所有和User相关的对象的后继
* 此函数不再使用
@ -4273,6 +4272,7 @@ function analyzeEntities(inputDir, relativePath) {
analyzeInModi();
uniqRelationships();
}
exports.analyzeEntities = analyzeEntities;
function buildSchema(outputDir) {
addReverseRelationship();
// setRelationEntities();
@ -4291,3 +4291,4 @@ function buildSchema(outputDir) {
outputPackageJson(outputDir);
}
}
exports.buildSchema = buildSchema;