MCPcopy Index your code
hub / github.com/alibaba/lowcode-engine / scan

Function scan

modules/material-parser/src/scan.ts:13–78  ·  view source on GitHub ↗
(
  options: IInternalMaterializeOptions,
)

Source from the content-addressed store, hash-verified

11const log = debug.extend('mat');
12
13export default async function scan(
14 options: IInternalMaterializeOptions,
15): Promise<IMaterialScanModel> {
16 const model: IMaterialScanModel = {
17 pkgName: '',
18 pkgVersion: '',
19 mainFileAbsolutePath: '',
20 mainFilePath: '',
21 };
22 log('options', options);
23 // 入口文件路径
24 const entryFilePath = options.entry;
25 const stats = lstatSync(entryFilePath);
26 if (
27 (options.accesser === 'local' ||
28 (options.accesser === 'online' &&
29 (options as IMaterializeOnlinePackageAndVersionOptions).name &&
30 options.entry)) &&
31 stats.isFile()
32 ) {
33 if (options.accesser === 'online') {
34 model.useEntry = true;
35 }
36 if (isAbsolute(entryFilePath)) {
37 model.mainFilePath = entryFilePath;
38 model.mainFileAbsolutePath = entryFilePath;
39 } else {
40 model.mainFilePath = entryFilePath;
41 model.mainFileAbsolutePath = resolve(entryFilePath);
42 }
43 }
44 const pkgJsonPath = join(options.root, 'package.json');
45 if (await pathExists(pkgJsonPath)) {
46 const pkgJson = await resolvePkgJson(pkgJsonPath);
47 model.pkgName = pkgJson.name;
48 model.pkgVersion = pkgJson.version;
49 if (pkgJson.module) {
50 const moduleFileAbsolutePath = join(options.root, pkgJson.module);
51 if (await pathExists(moduleFileAbsolutePath)) {
52 model.moduleFilePath = pkgJson.module;
53 model.moduleFileAbsolutePath = moduleFileAbsolutePath;
54 }
55 }
56 model.mainFilePath = model.mainFilePath || pkgJson.main || './index.js';
57 model.mainFileAbsolutePath = model.mainFileAbsolutePath || join(entryFilePath, pkgJson.main);
58 const typingsPathCandidates = [
59 pkgJson.typings,
60 pkgJson.types,
61 './index.d.ts',
62 './lib/index.d.ts',
63 ];
64 for (let i = 0; i < typingsPathCandidates.length; i++) {
65 const typingsFilePath = typingsPathCandidates[i];
66 if (!typingsFilePath) continue;
67 const typingsFileAbsolutePath = join(options.root, typingsFilePath);
68 if (await pathExists(typingsFileAbsolutePath)) {
69 model.typingsFileAbsolutePath = typingsFileAbsolutePath;
70 model.typingsFilePath = typingsFilePath;

Callers 1

index.tsFile · 0.85

Calls 1

resolvePkgJsonFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…