@nasl/cli 0.2.2 → 0.3.0
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/bin/nasl.mjs +591 -127
- package/dist/bin/nasl.mjs.map +1 -1
- package/dist/bin/naslc.mjs +322 -59
- package/dist/bin/naslc.mjs.map +1 -1
- package/dist/index.mjs +11683 -11254
- package/dist/index.mjs.map +1 -1
- package/out/apis/compileApi.d.ts.map +1 -1
- package/out/apis/compileApi.js +3 -2
- package/out/apis/compileApi.js.map +1 -1
- package/out/apis/dependencyApi.d.ts +29 -0
- package/out/apis/dependencyApi.d.ts.map +1 -0
- package/out/apis/dependencyApi.js +17 -0
- package/out/apis/dependencyApi.js.map +1 -0
- package/out/apis/index.d.ts +1 -0
- package/out/apis/index.d.ts.map +1 -1
- package/out/apis/index.js +1 -0
- package/out/apis/index.js.map +1 -1
- package/out/apis/openapi.d.ts +12 -0
- package/out/apis/openapi.d.ts.map +1 -1
- package/out/apis/openapi.js +15 -0
- package/out/apis/openapi.js.map +1 -1
- package/out/apis/transformApi.d.ts.map +1 -1
- package/out/apis/transformApi.js +2 -0
- package/out/apis/transformApi.js.map +1 -1
- package/out/bin/nasl.js +38 -2
- package/out/bin/nasl.js.map +1 -1
- package/out/commands/check.d.ts.map +1 -1
- package/out/commands/check.js +10 -1
- package/out/commands/check.js.map +1 -1
- package/out/commands/compile.d.ts.map +1 -1
- package/out/commands/compile.js +3 -2
- package/out/commands/compile.js.map +1 -1
- package/out/commands/dep.d.ts +4 -2
- package/out/commands/dep.d.ts.map +1 -1
- package/out/commands/dep.js +44 -2
- package/out/commands/dep.js.map +1 -1
- package/out/commands/index.d.ts +1 -0
- package/out/commands/index.d.ts.map +1 -1
- package/out/commands/index.js +1 -0
- package/out/commands/index.js.map +1 -1
- package/out/commands/install.d.ts +9 -0
- package/out/commands/install.d.ts.map +1 -0
- package/out/commands/install.js +123 -0
- package/out/commands/install.js.map +1 -0
- package/out/commands/transform.d.ts.map +1 -1
- package/out/commands/transform.js +3 -2
- package/out/commands/transform.js.map +1 -1
- package/out/constants/nasl-file-types.d.ts.map +1 -1
- package/out/constants/nasl-file-types.js +21 -0
- package/out/constants/nasl-file-types.js.map +1 -1
- package/out/services/compose.d.ts +8 -0
- package/out/services/compose.d.ts.map +1 -1
- package/out/services/compose.js +31 -1
- package/out/services/compose.js.map +1 -1
- package/out/services/resolve.d.ts +18 -0
- package/out/services/resolve.d.ts.map +1 -1
- package/out/services/resolve.js +208 -9
- package/out/services/resolve.js.map +1 -1
- package/out/types/api.d.ts +4 -0
- package/out/types/api.d.ts.map +1 -1
- package/out/types/config.d.ts +2 -0
- package/out/types/config.d.ts.map +1 -1
- package/out/types/config.js +1 -0
- package/out/types/config.js.map +1 -1
- package/out/utils/config.d.ts.map +1 -1
- package/out/utils/config.js +2 -0
- package/out/utils/config.js.map +1 -1
- package/out/utils/errorMapper.d.ts +14 -0
- package/out/utils/errorMapper.d.ts.map +1 -0
- package/out/utils/errorMapper.js +60 -0
- package/out/utils/errorMapper.js.map +1 -0
- package/package.json +1 -1
package/dist/bin/naslc.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
#!/usr/bin/env node
|
|
3
2
|
import require$$0$1, { EventEmitter } from 'events';
|
|
4
3
|
import require$$1 from 'child_process';
|
|
5
|
-
import * as
|
|
6
|
-
import
|
|
4
|
+
import * as path$1 from 'path';
|
|
5
|
+
import path__default, { join } from 'path';
|
|
7
6
|
import require$$0$2, { promises } from 'fs';
|
|
8
7
|
import require$$4 from 'process';
|
|
9
8
|
import require$$0$5 from 'os';
|
|
@@ -1166,7 +1165,7 @@ function requireCommand () {
|
|
|
1166
1165
|
hasRequiredCommand = 1;
|
|
1167
1166
|
const EventEmitter = require$$0$1.EventEmitter;
|
|
1168
1167
|
const childProcess = require$$1;
|
|
1169
|
-
const path =
|
|
1168
|
+
const path = path__default;
|
|
1170
1169
|
const fs = require$$0$2;
|
|
1171
1170
|
const process = require$$4;
|
|
1172
1171
|
|
|
@@ -4576,7 +4575,7 @@ var hasRequiredUtils$5;
|
|
|
4576
4575
|
function requireUtils$5 () {
|
|
4577
4576
|
if (hasRequiredUtils$5) return utils$7;
|
|
4578
4577
|
hasRequiredUtils$5 = 1;
|
|
4579
|
-
const path =
|
|
4578
|
+
const path = path__default;
|
|
4580
4579
|
|
|
4581
4580
|
// https://github.com/nodejs/node/issues/8987
|
|
4582
4581
|
// https://github.com/libuv/libuv/pull/1088
|
|
@@ -4722,7 +4721,7 @@ function requireStat () {
|
|
|
4722
4721
|
hasRequiredStat = 1;
|
|
4723
4722
|
|
|
4724
4723
|
const fs = /*@__PURE__*/ requireFs$4();
|
|
4725
|
-
const path =
|
|
4724
|
+
const path = path__default;
|
|
4726
4725
|
const u = requireUniversalify().fromPromise;
|
|
4727
4726
|
|
|
4728
4727
|
function getStats (src, dest, opts) {
|
|
@@ -4926,7 +4925,7 @@ function requireCopy$1 () {
|
|
|
4926
4925
|
hasRequiredCopy$1 = 1;
|
|
4927
4926
|
|
|
4928
4927
|
const fs = /*@__PURE__*/ requireFs$4();
|
|
4929
|
-
const path =
|
|
4928
|
+
const path = path__default;
|
|
4930
4929
|
const { mkdirs } = /*@__PURE__*/ requireMkdirs();
|
|
4931
4930
|
const { pathExists } = /*@__PURE__*/ requirePathExists();
|
|
4932
4931
|
const { utimesMillis } = /*@__PURE__*/ requireUtimes();
|
|
@@ -5109,7 +5108,7 @@ function requireCopySync () {
|
|
|
5109
5108
|
hasRequiredCopySync = 1;
|
|
5110
5109
|
|
|
5111
5110
|
const fs = requireGracefulFs();
|
|
5112
|
-
const path =
|
|
5111
|
+
const path = path__default;
|
|
5113
5112
|
const mkdirsSync = /*@__PURE__*/ requireMkdirs().mkdirsSync;
|
|
5114
5113
|
const utimesMillisSync = /*@__PURE__*/ requireUtimes().utimesMillisSync;
|
|
5115
5114
|
const stat = /*@__PURE__*/ requireStat();
|
|
@@ -5329,7 +5328,7 @@ function requireEmpty () {
|
|
|
5329
5328
|
|
|
5330
5329
|
const u = requireUniversalify().fromPromise;
|
|
5331
5330
|
const fs = /*@__PURE__*/ requireFs$4();
|
|
5332
|
-
const path =
|
|
5331
|
+
const path = path__default;
|
|
5333
5332
|
const mkdir = /*@__PURE__*/ requireMkdirs();
|
|
5334
5333
|
const remove = /*@__PURE__*/ requireRemove();
|
|
5335
5334
|
|
|
@@ -5375,7 +5374,7 @@ function requireFile () {
|
|
|
5375
5374
|
hasRequiredFile = 1;
|
|
5376
5375
|
|
|
5377
5376
|
const u = requireUniversalify().fromPromise;
|
|
5378
|
-
const path =
|
|
5377
|
+
const path = path__default;
|
|
5379
5378
|
const fs = /*@__PURE__*/ requireFs$4();
|
|
5380
5379
|
const mkdir = /*@__PURE__*/ requireMkdirs();
|
|
5381
5380
|
|
|
@@ -5449,7 +5448,7 @@ function requireLink () {
|
|
|
5449
5448
|
hasRequiredLink = 1;
|
|
5450
5449
|
|
|
5451
5450
|
const u = requireUniversalify().fromPromise;
|
|
5452
|
-
const path =
|
|
5451
|
+
const path = path__default;
|
|
5453
5452
|
const fs = /*@__PURE__*/ requireFs$4();
|
|
5454
5453
|
const mkdir = /*@__PURE__*/ requireMkdirs();
|
|
5455
5454
|
const { pathExists } = /*@__PURE__*/ requirePathExists();
|
|
@@ -5520,7 +5519,7 @@ function requireSymlinkPaths () {
|
|
|
5520
5519
|
if (hasRequiredSymlinkPaths) return symlinkPaths_1;
|
|
5521
5520
|
hasRequiredSymlinkPaths = 1;
|
|
5522
5521
|
|
|
5523
|
-
const path =
|
|
5522
|
+
const path = path__default;
|
|
5524
5523
|
const fs = /*@__PURE__*/ requireFs$4();
|
|
5525
5524
|
const { pathExists } = /*@__PURE__*/ requirePathExists();
|
|
5526
5525
|
|
|
@@ -5672,7 +5671,7 @@ function requireSymlink () {
|
|
|
5672
5671
|
hasRequiredSymlink = 1;
|
|
5673
5672
|
|
|
5674
5673
|
const u = requireUniversalify().fromPromise;
|
|
5675
|
-
const path =
|
|
5674
|
+
const path = path__default;
|
|
5676
5675
|
const fs = /*@__PURE__*/ requireFs$4();
|
|
5677
5676
|
|
|
5678
5677
|
const { mkdirs, mkdirsSync } = /*@__PURE__*/ requireMkdirs();
|
|
@@ -5918,7 +5917,7 @@ function requireOutputFile () {
|
|
|
5918
5917
|
|
|
5919
5918
|
const u = requireUniversalify().fromPromise;
|
|
5920
5919
|
const fs = /*@__PURE__*/ requireFs$4();
|
|
5921
|
-
const path =
|
|
5920
|
+
const path = path__default;
|
|
5922
5921
|
const mkdir = /*@__PURE__*/ requireMkdirs();
|
|
5923
5922
|
const pathExists = /*@__PURE__*/ requirePathExists().pathExists;
|
|
5924
5923
|
|
|
@@ -6020,7 +6019,7 @@ function requireMove$1 () {
|
|
|
6020
6019
|
hasRequiredMove$1 = 1;
|
|
6021
6020
|
|
|
6022
6021
|
const fs = /*@__PURE__*/ requireFs$4();
|
|
6023
|
-
const path =
|
|
6022
|
+
const path = path__default;
|
|
6024
6023
|
const { copy } = /*@__PURE__*/ requireCopy();
|
|
6025
6024
|
const { remove } = /*@__PURE__*/ requireRemove();
|
|
6026
6025
|
const { mkdirp } = /*@__PURE__*/ requireMkdirs();
|
|
@@ -6087,7 +6086,7 @@ function requireMoveSync () {
|
|
|
6087
6086
|
hasRequiredMoveSync = 1;
|
|
6088
6087
|
|
|
6089
6088
|
const fs = requireGracefulFs();
|
|
6090
|
-
const path =
|
|
6089
|
+
const path = path__default;
|
|
6091
6090
|
const copySync = /*@__PURE__*/ requireCopy().copySync;
|
|
6092
6091
|
const removeSync = /*@__PURE__*/ requireRemove().removeSync;
|
|
6093
6092
|
const mkdirpSync = /*@__PURE__*/ requireMkdirs().mkdirpSync;
|
|
@@ -8204,16 +8203,16 @@ class BaseLogger {
|
|
|
8204
8203
|
}
|
|
8205
8204
|
debugToFile(topic, ...args) {
|
|
8206
8205
|
if (process.env.DEBUG_TO_FILE) {
|
|
8207
|
-
const baseDir =
|
|
8206
|
+
const baseDir = path$1.join(process.cwd(), '.nasl');
|
|
8208
8207
|
const currentHour = dayjs().format('YYYYMMDD_HH');
|
|
8209
8208
|
const prevHour = dayjs().subtract(1, 'hour').format('YYYYMMDD_HH');
|
|
8210
8209
|
let subdir = `${topic}_${currentHour}`;
|
|
8211
8210
|
const prevSubdir = `${topic}_${prevHour}`;
|
|
8212
8211
|
// 判断如果有上一个小时的 subdir,则自己汇聚到上一个小时的 subdir 中
|
|
8213
|
-
if (libExports.existsSync(
|
|
8212
|
+
if (libExports.existsSync(path$1.join(baseDir, prevSubdir)))
|
|
8214
8213
|
subdir = prevSubdir;
|
|
8215
8214
|
const fileName = `${topic}_${dayjs().format('YYYYMMDD_HHmmss')}.log`;
|
|
8216
|
-
const filePath =
|
|
8215
|
+
const filePath = path$1.join(baseDir, subdir, fileName);
|
|
8217
8216
|
libExports.outputFileSync(filePath, args.join(' '));
|
|
8218
8217
|
}
|
|
8219
8218
|
}
|
|
@@ -8278,11 +8277,11 @@ function findConfigDir(startDir = process.cwd()) {
|
|
|
8278
8277
|
let currentDir = startDir;
|
|
8279
8278
|
// eslint-disable-next-line no-constant-condition
|
|
8280
8279
|
while (true) {
|
|
8281
|
-
const configPath =
|
|
8280
|
+
const configPath = path$1.join(currentDir, CONFIG_FILE_NAME);
|
|
8282
8281
|
if (libExports.existsSync(configPath)) {
|
|
8283
8282
|
return currentDir;
|
|
8284
8283
|
}
|
|
8285
|
-
const parentDir =
|
|
8284
|
+
const parentDir = path$1.dirname(currentDir);
|
|
8286
8285
|
// 已经到达根目录
|
|
8287
8286
|
if (parentDir === currentDir) {
|
|
8288
8287
|
return null;
|
|
@@ -8299,7 +8298,7 @@ function loadConfig(configDir) {
|
|
|
8299
8298
|
defaultLogger.error(`未找到配置文件 ${CONFIG_FILE_NAME},请先运行 nasl-init 初始化配置`);
|
|
8300
8299
|
return defaultLogger.exit(1);
|
|
8301
8300
|
}
|
|
8302
|
-
const configPath =
|
|
8301
|
+
const configPath = path$1.join(dir, CONFIG_FILE_NAME);
|
|
8303
8302
|
try {
|
|
8304
8303
|
const content = libExports.readFileSync(configPath, 'utf-8');
|
|
8305
8304
|
const config = JSON.parse(content);
|
|
@@ -8330,6 +8329,8 @@ function loadConfig(configDir) {
|
|
|
8330
8329
|
config.OPENAPI_AK = process.env.LCAP_OPENAPI_AK;
|
|
8331
8330
|
if (process.env.LCAP_OPENAPI_SK)
|
|
8332
8331
|
config.OPENAPI_SK = process.env.LCAP_OPENAPI_SK;
|
|
8332
|
+
if (process.env.LCAP_TENANT_NAME)
|
|
8333
|
+
config.tenantName = process.env.LCAP_TENANT_NAME;
|
|
8333
8334
|
// 如果启用了 OpenAPI,验证必需的 AK 和 SK
|
|
8334
8335
|
if (config.useOPENAPI) {
|
|
8335
8336
|
if (!config.OPENAPI_AK || !config.OPENAPI_SK) {
|
|
@@ -8376,7 +8377,7 @@ function readFileWithLog(filePath, logger) {
|
|
|
8376
8377
|
*/
|
|
8377
8378
|
function writeFileWithLog(filePath, content, logger) {
|
|
8378
8379
|
try {
|
|
8379
|
-
const dir =
|
|
8380
|
+
const dir = path$1.dirname(filePath);
|
|
8380
8381
|
libExports.ensureDirSync(dir);
|
|
8381
8382
|
libExports.writeFileSync(filePath, content, 'utf-8');
|
|
8382
8383
|
}
|
|
@@ -20362,7 +20363,7 @@ function requireMimeTypes () {
|
|
|
20362
20363
|
*/
|
|
20363
20364
|
|
|
20364
20365
|
var db = requireMimeDb();
|
|
20365
|
-
var extname =
|
|
20366
|
+
var extname = path__default.extname;
|
|
20366
20367
|
|
|
20367
20368
|
/**
|
|
20368
20369
|
* Module variables.
|
|
@@ -22103,7 +22104,7 @@ function requireForm_data () {
|
|
|
22103
22104
|
|
|
22104
22105
|
var CombinedStream = requireCombined_stream();
|
|
22105
22106
|
var util = require$$0$4;
|
|
22106
|
-
var path =
|
|
22107
|
+
var path = path__default;
|
|
22107
22108
|
var http = require$$3;
|
|
22108
22109
|
var https = require$$4$1;
|
|
22109
22110
|
var parseUrl = require$$0$6.parse;
|
|
@@ -29047,6 +29048,20 @@ async function generateCompleteHeaders(options) {
|
|
|
29047
29048
|
}
|
|
29048
29049
|
return headers;
|
|
29049
29050
|
}
|
|
29051
|
+
/**
|
|
29052
|
+
* 构建请求 headers
|
|
29053
|
+
* 如果 ServerOptions.useOPENAPI 为 true, 意味着接口内部是走的集群,反之则需要走 openapi 调用(本地或者server的场景,透传options相关配置)
|
|
29054
|
+
*/
|
|
29055
|
+
function buildNaslHeaders(options) {
|
|
29056
|
+
return {
|
|
29057
|
+
'Content-Type': 'text/plain',
|
|
29058
|
+
'X-Server-Base-URL': options.serverBaseURL,
|
|
29059
|
+
...(options.OPENAPI_AK && { 'X-OPENAPI-AK': options.OPENAPI_AK }),
|
|
29060
|
+
...(options.OPENAPI_SK && { 'X-OPENAPI-SK': options.OPENAPI_SK }),
|
|
29061
|
+
...(options.tenantName && { 'X-Tenant-Name': options.tenantName }),
|
|
29062
|
+
...(options.useOPENAPI !== undefined && { 'X-Use-OPENAPI': String(!options.useOPENAPI) }),
|
|
29063
|
+
};
|
|
29064
|
+
}
|
|
29050
29065
|
|
|
29051
29066
|
/**
|
|
29052
29067
|
* 创建 Axios 实例
|
|
@@ -29094,7 +29109,7 @@ async function compileApi(fullNaturalTS, options) {
|
|
|
29094
29109
|
// 示例实现:
|
|
29095
29110
|
const axios = await createAxios(options);
|
|
29096
29111
|
const res = await axios.post(`/compile/tsx?ideVersion=${options.ideVersion}&needAnnotation=true`, fullNaturalTS, {
|
|
29097
|
-
headers:
|
|
29112
|
+
headers: buildNaslHeaders(options),
|
|
29098
29113
|
});
|
|
29099
29114
|
const data = res.data;
|
|
29100
29115
|
const { bundle } = data.result;
|
|
@@ -29198,7 +29213,10 @@ function validateNormalFile(file, nameFromPath, namespace, errors) {
|
|
|
29198
29213
|
function composeToString(files) {
|
|
29199
29214
|
files.sort((a, b) => sorter(a.path, b.path));
|
|
29200
29215
|
const errors = [];
|
|
29216
|
+
let currentLine = 1;
|
|
29201
29217
|
const result = files.map((file) => {
|
|
29218
|
+
// 记录这个文件的开始行号
|
|
29219
|
+
file.startLine = currentLine;
|
|
29202
29220
|
const arr = file.path.split('.');
|
|
29203
29221
|
const ext = arr.pop();
|
|
29204
29222
|
const nameFromPath = arr.pop();
|
|
@@ -29224,7 +29242,14 @@ function composeToString(files) {
|
|
|
29224
29242
|
else if (isThemeCss) {
|
|
29225
29243
|
content = ` $theme\`${content}\`;`;
|
|
29226
29244
|
}
|
|
29227
|
-
|
|
29245
|
+
const fileContent = `namespace ${namespace} {\n${content}\n}\n`;
|
|
29246
|
+
// 计算这个文件占用的行数(末尾 \n 导致 split 多一个空元素,减 1 得到实际行数)
|
|
29247
|
+
const lineCount = fileContent.split('\n').length - 1;
|
|
29248
|
+
// 记录这个文件的结束行号
|
|
29249
|
+
file.endLine = currentLine + lineCount - 1;
|
|
29250
|
+
// +1 是 join('\n') 在文件之间插入的换行符
|
|
29251
|
+
currentLine = file.endLine + 2;
|
|
29252
|
+
return fileContent;
|
|
29228
29253
|
})
|
|
29229
29254
|
.join('\n');
|
|
29230
29255
|
if (errors.length > 0) {
|
|
@@ -29232,6 +29257,25 @@ function composeToString(files) {
|
|
|
29232
29257
|
}
|
|
29233
29258
|
return result;
|
|
29234
29259
|
}
|
|
29260
|
+
/**
|
|
29261
|
+
* 将依赖信息拼接到 fullNaturalTS 顶部
|
|
29262
|
+
* @param fullNaturalTS 组合后的 NASL 代码
|
|
29263
|
+
* @param dependencies mergedDependencies 对象或 JSON 字符串
|
|
29264
|
+
* @returns 拼接后的完整内容
|
|
29265
|
+
*/
|
|
29266
|
+
function prependDependencies(fullNaturalTS, dependencies) {
|
|
29267
|
+
if (!dependencies)
|
|
29268
|
+
return fullNaturalTS;
|
|
29269
|
+
const jsonStr = JSON.stringify(dependencies, null, 2);
|
|
29270
|
+
const header = `/*
|
|
29271
|
+
-----------app.dependencies.json7xdhjutehm.start
|
|
29272
|
+
${jsonStr}
|
|
29273
|
+
-----------app.dependencies.json7xdhjutehm.end
|
|
29274
|
+
*/
|
|
29275
|
+
|
|
29276
|
+
`;
|
|
29277
|
+
return header + fullNaturalTS;
|
|
29278
|
+
}
|
|
29235
29279
|
|
|
29236
29280
|
var globby$1 = {exports: {}};
|
|
29237
29281
|
|
|
@@ -29489,7 +29533,7 @@ function requirePath () {
|
|
|
29489
29533
|
Object.defineProperty(path, "__esModule", { value: true });
|
|
29490
29534
|
path.convertPosixPathToPattern = path.convertWindowsPathToPattern = path.convertPathToPattern = path.escapePosixPath = path.escapeWindowsPath = path.escape = path.removeLeadingDotSegment = path.makeAbsolute = path.unixify = void 0;
|
|
29491
29535
|
const os = require$$0$5;
|
|
29492
|
-
const path$1 =
|
|
29536
|
+
const path$1 = path__default;
|
|
29493
29537
|
const IS_WINDOWS_PLATFORM = os.platform() === 'win32';
|
|
29494
29538
|
const LEADING_DOT_SEGMENT_CHARACTERS_COUNT = 2; // ./ or .\\
|
|
29495
29539
|
/**
|
|
@@ -29754,7 +29798,7 @@ function requireGlobParent () {
|
|
|
29754
29798
|
hasRequiredGlobParent = 1;
|
|
29755
29799
|
|
|
29756
29800
|
var isGlob = requireIsGlob();
|
|
29757
|
-
var pathPosixDirname =
|
|
29801
|
+
var pathPosixDirname = path__default.posix.dirname;
|
|
29758
29802
|
var isWin32 = require$$0$5.platform() === 'win32';
|
|
29759
29803
|
|
|
29760
29804
|
var slash = '/';
|
|
@@ -31326,7 +31370,7 @@ function requireConstants$1 () {
|
|
|
31326
31370
|
if (hasRequiredConstants$1) return constants$1;
|
|
31327
31371
|
hasRequiredConstants$1 = 1;
|
|
31328
31372
|
|
|
31329
|
-
const path =
|
|
31373
|
+
const path = path__default;
|
|
31330
31374
|
const WIN_SLASH = '\\\\/';
|
|
31331
31375
|
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
31332
31376
|
|
|
@@ -31513,7 +31557,7 @@ function requireUtils$2 () {
|
|
|
31513
31557
|
hasRequiredUtils$2 = 1;
|
|
31514
31558
|
(function (exports$1) {
|
|
31515
31559
|
|
|
31516
|
-
const path =
|
|
31560
|
+
const path = path__default;
|
|
31517
31561
|
const win32 = process.platform === 'win32';
|
|
31518
31562
|
const {
|
|
31519
31563
|
REGEX_BACKSLASH,
|
|
@@ -33084,7 +33128,7 @@ function requirePicomatch$1 () {
|
|
|
33084
33128
|
if (hasRequiredPicomatch$1) return picomatch_1;
|
|
33085
33129
|
hasRequiredPicomatch$1 = 1;
|
|
33086
33130
|
|
|
33087
|
-
const path =
|
|
33131
|
+
const path = path__default;
|
|
33088
33132
|
const scan = requireScan();
|
|
33089
33133
|
const parse = requireParse();
|
|
33090
33134
|
const utils = requireUtils$2();
|
|
@@ -33927,7 +33971,7 @@ function requirePattern () {
|
|
|
33927
33971
|
hasRequiredPattern = 1;
|
|
33928
33972
|
Object.defineProperty(pattern, "__esModule", { value: true });
|
|
33929
33973
|
pattern.isAbsolute = pattern.partitionAbsoluteAndRelative = pattern.removeDuplicateSlashes = pattern.matchAny = pattern.convertPatternsToRe = pattern.makeRe = pattern.getPatternParts = pattern.expandBraceExpansion = pattern.expandPatternsWithBraceExpansion = pattern.isAffectDepthOfReadingPattern = pattern.endsWithSlashGlobStar = pattern.hasGlobStar = pattern.getBaseDirectory = pattern.isPatternRelatedToParentDirectory = pattern.getPatternsOutsideCurrentDirectory = pattern.getPatternsInsideCurrentDirectory = pattern.getPositivePatterns = pattern.getNegativePatterns = pattern.isPositivePattern = pattern.isNegativePattern = pattern.convertToNegativePattern = pattern.convertToPositivePattern = pattern.isDynamicPattern = pattern.isStaticPattern = void 0;
|
|
33930
|
-
const path =
|
|
33974
|
+
const path = path__default;
|
|
33931
33975
|
const globParent = requireGlobParent();
|
|
33932
33976
|
const micromatch = requireMicromatch();
|
|
33933
33977
|
const GLOBSTAR = '**';
|
|
@@ -34881,7 +34925,7 @@ function requireSettings$2 () {
|
|
|
34881
34925
|
if (hasRequiredSettings$2) return settings$2;
|
|
34882
34926
|
hasRequiredSettings$2 = 1;
|
|
34883
34927
|
Object.defineProperty(settings$2, "__esModule", { value: true });
|
|
34884
|
-
const path =
|
|
34928
|
+
const path = path__default;
|
|
34885
34929
|
const fsStat = requireOut$3();
|
|
34886
34930
|
const fs = requireFs();
|
|
34887
34931
|
class Settings {
|
|
@@ -35643,7 +35687,7 @@ function requireSettings$1 () {
|
|
|
35643
35687
|
if (hasRequiredSettings$1) return settings$1;
|
|
35644
35688
|
hasRequiredSettings$1 = 1;
|
|
35645
35689
|
Object.defineProperty(settings$1, "__esModule", { value: true });
|
|
35646
|
-
const path =
|
|
35690
|
+
const path = path__default;
|
|
35647
35691
|
const fsScandir = requireOut$2();
|
|
35648
35692
|
class Settings {
|
|
35649
35693
|
constructor(_options = {}) {
|
|
@@ -35719,7 +35763,7 @@ function requireReader () {
|
|
|
35719
35763
|
if (hasRequiredReader) return reader;
|
|
35720
35764
|
hasRequiredReader = 1;
|
|
35721
35765
|
Object.defineProperty(reader, "__esModule", { value: true });
|
|
35722
|
-
const path =
|
|
35766
|
+
const path = path__default;
|
|
35723
35767
|
const fsStat = requireOut$3();
|
|
35724
35768
|
const utils = requireUtils$1();
|
|
35725
35769
|
class Reader {
|
|
@@ -36192,7 +36236,7 @@ function requireProvider () {
|
|
|
36192
36236
|
if (hasRequiredProvider) return provider;
|
|
36193
36237
|
hasRequiredProvider = 1;
|
|
36194
36238
|
Object.defineProperty(provider, "__esModule", { value: true });
|
|
36195
|
-
const path =
|
|
36239
|
+
const path = path__default;
|
|
36196
36240
|
const deep_1 = requireDeep();
|
|
36197
36241
|
const entry_1 = requireEntry$1();
|
|
36198
36242
|
const error_1 = requireError();
|
|
@@ -36632,7 +36676,7 @@ var hasRequiredDirGlob;
|
|
|
36632
36676
|
function requireDirGlob () {
|
|
36633
36677
|
if (hasRequiredDirGlob) return dirGlob.exports;
|
|
36634
36678
|
hasRequiredDirGlob = 1;
|
|
36635
|
-
const path =
|
|
36679
|
+
const path = path__default;
|
|
36636
36680
|
const pathType = requirePathType();
|
|
36637
36681
|
|
|
36638
36682
|
const getExtensions = extensions => extensions.length > 1 ? `{${extensions.join(',')}}` : extensions[0];
|
|
@@ -37382,7 +37426,7 @@ function requireGitignore () {
|
|
|
37382
37426
|
hasRequiredGitignore = 1;
|
|
37383
37427
|
const {promisify} = require$$0$4;
|
|
37384
37428
|
const fs = require$$0$2;
|
|
37385
|
-
const path =
|
|
37429
|
+
const path = path__default;
|
|
37386
37430
|
const fastGlob = requireOut();
|
|
37387
37431
|
const gitIgnore = requireIgnore();
|
|
37388
37432
|
const slash = requireSlash();
|
|
@@ -37814,6 +37858,27 @@ const NASL_FILE_TYPES = [
|
|
|
37814
37858
|
codeRefPattern: 'extensions\\.\\w+(?:\\.\\w+)*',
|
|
37815
37859
|
extension: 'ts',
|
|
37816
37860
|
},
|
|
37861
|
+
{
|
|
37862
|
+
name: 'apis',
|
|
37863
|
+
description: 'API',
|
|
37864
|
+
fileNamePattern: 'apis\\.\\w+\\.ts',
|
|
37865
|
+
codeRefPattern: 'apis\\.\\w+(?:\\.\\w+)*',
|
|
37866
|
+
extension: 'ts',
|
|
37867
|
+
},
|
|
37868
|
+
{
|
|
37869
|
+
name: 'connectors',
|
|
37870
|
+
description: '连接器',
|
|
37871
|
+
fileNamePattern: 'connectors\\.\\w+\\.ts',
|
|
37872
|
+
codeRefPattern: 'connectors\\.\\w+(?:\\.\\w+)*',
|
|
37873
|
+
extension: 'ts',
|
|
37874
|
+
},
|
|
37875
|
+
{
|
|
37876
|
+
name: 'uilibs',
|
|
37877
|
+
description: 'UI 库',
|
|
37878
|
+
fileNamePattern: 'uilibs\\.\\w+\\.ts',
|
|
37879
|
+
codeRefPattern: 'uilibs\\.\\w+(?:\\.\\w+)*',
|
|
37880
|
+
extension: 'ts',
|
|
37881
|
+
},
|
|
37817
37882
|
];
|
|
37818
37883
|
/**
|
|
37819
37884
|
* 获取用于验证文件名的正则表达式数组
|
|
@@ -37846,10 +37911,15 @@ const codeRefPatterns = getCodeRefPatterns();
|
|
|
37846
37911
|
*/
|
|
37847
37912
|
function isKnownFileType(filePath) {
|
|
37848
37913
|
// 提取文件名
|
|
37849
|
-
const fileName =
|
|
37914
|
+
const fileName = path$1.basename(filePath);
|
|
37850
37915
|
return fileNamePatterns.some((pattern) => pattern.test(fileName));
|
|
37851
37916
|
}
|
|
37852
37917
|
|
|
37918
|
+
/** 这些前缀的依赖不再向下递归查找 */
|
|
37919
|
+
const EXTERNAL_DEP_PREFIXES = ['extensions.', 'connectors.', 'apis.', 'uilibs.'];
|
|
37920
|
+
function shouldSkipDependencyTraversal(depPath) {
|
|
37921
|
+
return EXTERNAL_DEP_PREFIXES.some((prefix) => depPath.startsWith(prefix));
|
|
37922
|
+
}
|
|
37853
37923
|
/**
|
|
37854
37924
|
* 扫描目录下的所有 NASL 文件
|
|
37855
37925
|
*/
|
|
@@ -37915,6 +37985,15 @@ function extractDeps(content) {
|
|
|
37915
37985
|
if (/^extensions\.\w+\./.test(dep)) {
|
|
37916
37986
|
dep = dep.replace(/^(extensions\.\w+)\..+$/, '$1');
|
|
37917
37987
|
}
|
|
37988
|
+
if (/^apis\.\w+\./.test(dep)) {
|
|
37989
|
+
dep = dep.replace(/^(apis\.\w+)\..+$/, '$1');
|
|
37990
|
+
}
|
|
37991
|
+
if (/^connectors\.\w+\./.test(dep)) {
|
|
37992
|
+
dep = dep.replace(/^(connectors\.\w+)\..+$/, '$1');
|
|
37993
|
+
}
|
|
37994
|
+
if (/^uilibs\.\w+\./.test(dep)) {
|
|
37995
|
+
dep = dep.replace(/^(uilibs\.\w+)\..+$/, '$1');
|
|
37996
|
+
}
|
|
37918
37997
|
// 跳过不合法的实体引用(实体后还有字段的情况)
|
|
37919
37998
|
if (/app\.dataSources\.\w+\.entities\.\w+\.\w+$/.test(dep)) {
|
|
37920
37999
|
continue;
|
|
@@ -37926,6 +38005,152 @@ function extractDeps(content) {
|
|
|
37926
38005
|
}
|
|
37927
38006
|
return Array.from(deps);
|
|
37928
38007
|
}
|
|
38008
|
+
/**
|
|
38009
|
+
* 从文件内容中提取外部依赖引用(extensions/connectors/apis/uilibs)
|
|
38010
|
+
* 用于构建 externalDependencies
|
|
38011
|
+
*/
|
|
38012
|
+
function extractExternalRefs(content) {
|
|
38013
|
+
const refs = {
|
|
38014
|
+
extensions: new Set(),
|
|
38015
|
+
connectors: new Set(),
|
|
38016
|
+
uilibs: new Set(),
|
|
38017
|
+
apis: new Map(),
|
|
38018
|
+
};
|
|
38019
|
+
const processedContent = content
|
|
38020
|
+
.replace(/\/\/.*$/gm, '')
|
|
38021
|
+
.replace(/\/\*[\s\S]*?\*\//g, '')
|
|
38022
|
+
.replace(/'(?:[^'\\]|\\.)*'/g, '')
|
|
38023
|
+
.replace(/"(?:[^"\\]|\\.)*"/g, '');
|
|
38024
|
+
// extensions.xxx, connectors.xxx, uilibs.xxx
|
|
38025
|
+
for (const m of processedContent.matchAll(/\b(extensions|connectors|uilibs)\.(\w+)/g)) {
|
|
38026
|
+
const [, kind, name] = m;
|
|
38027
|
+
if (kind === 'extensions')
|
|
38028
|
+
refs.extensions.add(name);
|
|
38029
|
+
else if (kind === 'connectors')
|
|
38030
|
+
refs.connectors.add(name);
|
|
38031
|
+
else
|
|
38032
|
+
refs.uilibs.add(name);
|
|
38033
|
+
}
|
|
38034
|
+
// apis.xxx.interfaces.yyy
|
|
38035
|
+
for (const m of processedContent.matchAll(/\bapis\.(\w+)\.interfaces\.(\w+)/g)) {
|
|
38036
|
+
const [, apiName, ifaceName] = m;
|
|
38037
|
+
if (!refs.apis.has(apiName))
|
|
38038
|
+
refs.apis.set(apiName, new Set());
|
|
38039
|
+
refs.apis.get(apiName).add(ifaceName);
|
|
38040
|
+
}
|
|
38041
|
+
return refs;
|
|
38042
|
+
}
|
|
38043
|
+
function mergeExternalRefs(into, from) {
|
|
38044
|
+
from.extensions.forEach((x) => into.extensions.add(x));
|
|
38045
|
+
from.connectors.forEach((x) => into.connectors.add(x));
|
|
38046
|
+
from.uilibs.forEach((x) => into.uilibs.add(x));
|
|
38047
|
+
from.apis.forEach((interfaces, apiName) => {
|
|
38048
|
+
if (!into.apis.has(apiName))
|
|
38049
|
+
into.apis.set(apiName, new Set());
|
|
38050
|
+
interfaces.forEach((i) => into.apis.get(apiName).add(i));
|
|
38051
|
+
});
|
|
38052
|
+
}
|
|
38053
|
+
/**
|
|
38054
|
+
* 加载 app.dependencies.json(不存在则返回空对象)
|
|
38055
|
+
*/
|
|
38056
|
+
function loadAppDependencies(srcDir) {
|
|
38057
|
+
const p = path$1.join(srcDir, 'app.dependencies.json');
|
|
38058
|
+
if (!libExports.existsSync(p))
|
|
38059
|
+
return {};
|
|
38060
|
+
try {
|
|
38061
|
+
return libExports.readJsonSync(p);
|
|
38062
|
+
}
|
|
38063
|
+
catch {
|
|
38064
|
+
return {};
|
|
38065
|
+
}
|
|
38066
|
+
}
|
|
38067
|
+
/**
|
|
38068
|
+
* 加载并合并 app.dependencies.json 与 potential.dependencies.json
|
|
38069
|
+
* 用于版本号查找:先查 app,再查 potential
|
|
38070
|
+
*/
|
|
38071
|
+
function loadMergedDependencies(srcDir) {
|
|
38072
|
+
const load = (file) => {
|
|
38073
|
+
const p = path$1.join(srcDir, file);
|
|
38074
|
+
if (!libExports.existsSync(p))
|
|
38075
|
+
return null;
|
|
38076
|
+
try {
|
|
38077
|
+
return libExports.readJsonSync(p);
|
|
38078
|
+
}
|
|
38079
|
+
catch {
|
|
38080
|
+
return null;
|
|
38081
|
+
}
|
|
38082
|
+
};
|
|
38083
|
+
const app = load('app.dependencies.json') ?? {};
|
|
38084
|
+
const potential = load('potential.dependencies.json') ?? {};
|
|
38085
|
+
const merged = {};
|
|
38086
|
+
for (const key of ['extensions', 'uilibs', 'connectors', 'apis']) {
|
|
38087
|
+
merged[key] = { ...(potential[key] ?? {}), ...(app[key] ?? {}) };
|
|
38088
|
+
}
|
|
38089
|
+
return merged;
|
|
38090
|
+
}
|
|
38091
|
+
/**
|
|
38092
|
+
* 将 externalDependencies 补充到 app.dependencies.json(只增不减)
|
|
38093
|
+
*/
|
|
38094
|
+
function mergeDependenciesIntoApp(existing, incoming) {
|
|
38095
|
+
const result = {};
|
|
38096
|
+
for (const key of ['extensions', 'uilibs', 'connectors']) {
|
|
38097
|
+
const existingRecord = existing[key] ?? {};
|
|
38098
|
+
const incomingRecord = incoming[key] ?? {};
|
|
38099
|
+
result[key] = { ...incomingRecord, ...existingRecord };
|
|
38100
|
+
}
|
|
38101
|
+
result.apis = {};
|
|
38102
|
+
if (existing.apis || incoming.apis) {
|
|
38103
|
+
const allApiNames = new Set([...Object.keys(existing.apis ?? {}), ...Object.keys(incoming.apis ?? {})]);
|
|
38104
|
+
for (const apiName of allApiNames) {
|
|
38105
|
+
const existingInterfaces = existing.apis?.[apiName] ?? [];
|
|
38106
|
+
const incomingInterfaces = incoming.apis?.[apiName] ?? [];
|
|
38107
|
+
result.apis[apiName] = [...new Set([...existingInterfaces, ...incomingInterfaces])].sort();
|
|
38108
|
+
}
|
|
38109
|
+
}
|
|
38110
|
+
return result;
|
|
38111
|
+
}
|
|
38112
|
+
/**
|
|
38113
|
+
* 根据收集的外部引用和版本配置,构建 DependenciesJSON
|
|
38114
|
+
* extensions/connectors/uilibs 需要版本号,apis 只需 interfaces 数组
|
|
38115
|
+
*/
|
|
38116
|
+
function buildExternalDependencies(refs, mergedDeps, logger) {
|
|
38117
|
+
const result = {};
|
|
38118
|
+
const errors = [];
|
|
38119
|
+
for (const name of refs.extensions) {
|
|
38120
|
+
const ver = mergedDeps.extensions?.[name];
|
|
38121
|
+
if (!ver) {
|
|
38122
|
+
errors.push(`extensions.${name} 未在 app.dependencies.json 或 potential.dependencies.json 中找到版本号`);
|
|
38123
|
+
}
|
|
38124
|
+
else {
|
|
38125
|
+
(result.extensions ?? (result.extensions = {}))[name] = ver;
|
|
38126
|
+
}
|
|
38127
|
+
}
|
|
38128
|
+
for (const name of refs.connectors) {
|
|
38129
|
+
const ver = mergedDeps.connectors?.[name];
|
|
38130
|
+
if (!ver) {
|
|
38131
|
+
errors.push(`connectors.${name} 未在 app.dependencies.json 或 potential.dependencies.json 中找到版本号`);
|
|
38132
|
+
}
|
|
38133
|
+
else {
|
|
38134
|
+
(result.connectors ?? (result.connectors = {}))[name] = ver;
|
|
38135
|
+
}
|
|
38136
|
+
}
|
|
38137
|
+
for (const name of refs.uilibs) {
|
|
38138
|
+
const ver = mergedDeps.uilibs?.[name];
|
|
38139
|
+
if (!ver) {
|
|
38140
|
+
errors.push(`uilibs.${name} 未在 app.dependencies.json 或 potential.dependencies.json 中找到版本号`);
|
|
38141
|
+
}
|
|
38142
|
+
else {
|
|
38143
|
+
(result.uilibs ?? (result.uilibs = {}))[name] = ver;
|
|
38144
|
+
}
|
|
38145
|
+
}
|
|
38146
|
+
// result.uilibs = mergedDeps.uilibs; // 临时先都加上去
|
|
38147
|
+
refs.apis.forEach((interfaces, apiName) => {
|
|
38148
|
+
(result.apis ?? (result.apis = {}))[apiName] = Array.from(interfaces).sort();
|
|
38149
|
+
});
|
|
38150
|
+
if (errors.length > 0)
|
|
38151
|
+
throw new Error(errors.join('\n'));
|
|
38152
|
+
return result;
|
|
38153
|
+
}
|
|
37929
38154
|
/**
|
|
37930
38155
|
* 提取页面文件的签名,移除函数体
|
|
37931
38156
|
* @param content 页面文件内容
|
|
@@ -37948,7 +38173,7 @@ function replaceViewAsSignature(content, hasSubViews = false) {
|
|
|
37948
38173
|
* @returns 文件信息和新发现的依赖文件列表
|
|
37949
38174
|
*/
|
|
37950
38175
|
function processFileDeps(pathRelativeToSrc, srcDir, matchedFileSet, processedFileMap, depNotFoundList, logger, verbose) {
|
|
37951
|
-
const absoluteFilePath =
|
|
38176
|
+
const absoluteFilePath = path$1.join(srcDir, pathRelativeToSrc);
|
|
37952
38177
|
const fileInfo = { path: pathRelativeToSrc, content: '' };
|
|
37953
38178
|
try {
|
|
37954
38179
|
fileInfo.content = readFileWithLog(absoluteFilePath, logger);
|
|
@@ -37978,7 +38203,9 @@ function processFileDeps(pathRelativeToSrc, srcDir, matchedFileSet, processedFil
|
|
|
37978
38203
|
}
|
|
37979
38204
|
processedFileMap.set(pathRelativeToSrc, fileInfo);
|
|
37980
38205
|
// 提取依赖
|
|
37981
|
-
|
|
38206
|
+
// extensions/connectors/apis/uilibs 作为叶子节点,不再向下递归查找依赖
|
|
38207
|
+
const isExternalDep = shouldSkipDependencyTraversal(pathRelativeToSrc);
|
|
38208
|
+
const deps = isExternalDep ? [] : extractDeps(fileInfo.content);
|
|
37982
38209
|
// 查找依赖文件
|
|
37983
38210
|
if (isView) {
|
|
37984
38211
|
const pathArr = pathRelativeToSrc.split('.');
|
|
@@ -37993,24 +38220,30 @@ function processFileDeps(pathRelativeToSrc, srcDir, matchedFileSet, processedFil
|
|
|
37993
38220
|
} while (true);
|
|
37994
38221
|
}
|
|
37995
38222
|
if (verbose || process.env.DEBUG) {
|
|
37996
|
-
console.log(`${isEntryFile ? chalk.magenta('[Entry]') : chalk.green('[ Dep ]')} ${pathRelativeToSrc}${deps.map((dep) => `\n├── ${dep}`).join('')}`);
|
|
38223
|
+
console.log(`${isEntryFile ? chalk.magenta('[Entry]') : isExternalDep ? chalk.blue('[ External Dep ]') : chalk.green('[ Dep ]')} ${pathRelativeToSrc}${deps.map((dep) => `\n├── ${dep}`).join('')}`);
|
|
37997
38224
|
}
|
|
37998
38225
|
return {
|
|
37999
38226
|
fileInfo,
|
|
38000
38227
|
newDeps: deps.filter((dep) => !processedFileMap.has(dep)),
|
|
38228
|
+
isExternalDep,
|
|
38001
38229
|
};
|
|
38002
38230
|
}
|
|
38003
38231
|
/**
|
|
38004
38232
|
* 收集入口文件及其依赖
|
|
38005
38233
|
* @param patterns 入口文件的 glob 模式数组
|
|
38006
38234
|
* @param srcDir 源代码目录绝对路径
|
|
38007
|
-
* @
|
|
38008
|
-
* @returns 文件信息列表
|
|
38235
|
+
* @returns 文件信息列表和外部依赖引用
|
|
38009
38236
|
*/
|
|
38010
38237
|
async function collectDeps(patterns, projectRoot, srcDir, logger, verbose) {
|
|
38011
38238
|
const processedFileMap = new Map(); // 已处理的文件(相对路径)
|
|
38012
38239
|
const filesToProcess = []; // 待处理的文件队列
|
|
38013
38240
|
const result = [];
|
|
38241
|
+
const externalRefs = {
|
|
38242
|
+
extensions: new Set(),
|
|
38243
|
+
connectors: new Set(),
|
|
38244
|
+
uilibs: new Set(),
|
|
38245
|
+
apis: new Map(),
|
|
38246
|
+
};
|
|
38014
38247
|
// 1. 使用 glob 匹配入口文件
|
|
38015
38248
|
logger.newLine();
|
|
38016
38249
|
logger.info(`匹配入口文件: ${patterns.join(', ')}`);
|
|
@@ -38020,15 +38253,15 @@ async function collectDeps(patterns, projectRoot, srcDir, logger, verbose) {
|
|
|
38020
38253
|
throw new Error('未找到匹配的入口文件');
|
|
38021
38254
|
}
|
|
38022
38255
|
logger.info(`找到 ${matchedFiles.length} 个入口文件`);
|
|
38023
|
-
const absoluteSrcDir =
|
|
38256
|
+
const absoluteSrcDir = path$1.resolve(srcDir);
|
|
38024
38257
|
const matchedFileSet = new Set();
|
|
38025
38258
|
matchedFiles.forEach((pathRelativeToRoot) => {
|
|
38026
38259
|
// 统一使用相对于 src 的路径
|
|
38027
|
-
const absoluteFilePath =
|
|
38260
|
+
const absoluteFilePath = path$1.resolve(projectRoot, pathRelativeToRoot);
|
|
38028
38261
|
// 判断 file 是否超出 srcDir 目录(支持相对路径和绝对路径)
|
|
38029
38262
|
if (!absoluteFilePath.startsWith(absoluteSrcDir))
|
|
38030
38263
|
throw new Error(`入口文件 ${absoluteFilePath} 超出了源代码目录 ${srcDir}`);
|
|
38031
|
-
const pathRelativeToSrc =
|
|
38264
|
+
const pathRelativeToSrc = path$1.relative(srcDir, absoluteFilePath);
|
|
38032
38265
|
filesToProcess.push(pathRelativeToSrc);
|
|
38033
38266
|
matchedFileSet.add(pathRelativeToSrc);
|
|
38034
38267
|
});
|
|
@@ -38046,8 +38279,9 @@ async function collectDeps(patterns, projectRoot, srcDir, logger, verbose) {
|
|
|
38046
38279
|
continue;
|
|
38047
38280
|
}
|
|
38048
38281
|
try {
|
|
38049
|
-
const { fileInfo, newDeps } = processFileDeps(pathRelativeToSrc, srcDir, matchedFileSet, processedFileMap, depNotFoundList, logger, verbose);
|
|
38050
|
-
result.push(fileInfo);
|
|
38282
|
+
const { fileInfo, newDeps, isExternalDep } = processFileDeps(pathRelativeToSrc, srcDir, matchedFileSet, processedFileMap, depNotFoundList, logger, verbose);
|
|
38283
|
+
!isExternalDep && result.push(fileInfo);
|
|
38284
|
+
mergeExternalRefs(externalRefs, extractExternalRefs(fileInfo.content));
|
|
38051
38285
|
filesToProcess.push(...newDeps);
|
|
38052
38286
|
}
|
|
38053
38287
|
catch (error) {
|
|
@@ -38069,7 +38303,7 @@ ${depNotFoundList.map((dep) => `- ${dep}\n`).join('')}
|
|
|
38069
38303
|
}
|
|
38070
38304
|
if (errorMessage)
|
|
38071
38305
|
throw new Error(errorMessage);
|
|
38072
|
-
return result;
|
|
38306
|
+
return { files: result, externalRefs };
|
|
38073
38307
|
}
|
|
38074
38308
|
/**
|
|
38075
38309
|
* 解析需要处理的文件(包含配置加载和目录设置)
|
|
@@ -38077,12 +38311,13 @@ ${depNotFoundList.map((dep) => `- ${dep}\n`).join('')}
|
|
|
38077
38311
|
* @returns 文件信息、配置和目录信息
|
|
38078
38312
|
*/
|
|
38079
38313
|
async function resolveNASLFiles(entry, logger, depMode, verbose) {
|
|
38314
|
+
depMode = true; // !!ensure depMode is true
|
|
38080
38315
|
// 加载配置
|
|
38081
38316
|
const config = loadConfig();
|
|
38082
38317
|
const projectRoot = getProjectRoot();
|
|
38083
38318
|
logger.info(`项目根目录: ${projectRoot}`);
|
|
38084
38319
|
logger.info(`源代码目录: ${config.srcDir}`);
|
|
38085
|
-
const srcDir =
|
|
38320
|
+
const srcDir = path$1.join(projectRoot, config.srcDir);
|
|
38086
38321
|
// 收集需要处理的文件
|
|
38087
38322
|
let collectedFiles = [];
|
|
38088
38323
|
if (Array.isArray(entry) && !entry.length) {
|
|
@@ -38091,8 +38326,12 @@ async function resolveNASLFiles(entry, logger, depMode, verbose) {
|
|
|
38091
38326
|
config,
|
|
38092
38327
|
projectRoot,
|
|
38093
38328
|
srcDir,
|
|
38329
|
+
externalDependencies: undefined,
|
|
38094
38330
|
};
|
|
38095
38331
|
}
|
|
38332
|
+
let externalRefs = null;
|
|
38333
|
+
if (!entry && depMode)
|
|
38334
|
+
entry = 'src/**/app.*.{ts,tsx,css}';
|
|
38096
38335
|
if (entry) {
|
|
38097
38336
|
// 检查入口路径是否在源代码目录外面
|
|
38098
38337
|
// if (entry.startsWith('..')) throw new Error('入口路径不能在源代码目录外面');
|
|
@@ -38100,7 +38339,9 @@ async function resolveNASLFiles(entry, logger, depMode, verbose) {
|
|
|
38100
38339
|
// 具体路径也转换为 glob 模式统一处理
|
|
38101
38340
|
// 使用依赖分析收集文件
|
|
38102
38341
|
try {
|
|
38103
|
-
|
|
38342
|
+
const { files, externalRefs: refs } = await collectDeps(Array.isArray(entry) ? entry : [entry], projectRoot, srcDir, logger, depMode || verbose);
|
|
38343
|
+
collectedFiles = files;
|
|
38344
|
+
externalRefs = refs;
|
|
38104
38345
|
}
|
|
38105
38346
|
catch (error) {
|
|
38106
38347
|
logger.error(`依赖分析失败:\n${error.message}`);
|
|
@@ -38114,13 +38355,21 @@ async function resolveNASLFiles(entry, logger, depMode, verbose) {
|
|
|
38114
38355
|
filePaths.sort(sorter);
|
|
38115
38356
|
collectedFiles = filePaths.map((filePath) => ({
|
|
38116
38357
|
path: filePath,
|
|
38117
|
-
content: readFileWithLog(
|
|
38358
|
+
content: readFileWithLog(path$1.join(srcDir, filePath), logger),
|
|
38118
38359
|
}));
|
|
38119
38360
|
if (collectedFiles.length === 0) {
|
|
38120
38361
|
logger.warn('未找到 NASL 文件');
|
|
38121
38362
|
logger.exit(1);
|
|
38122
38363
|
}
|
|
38123
38364
|
logger.info(`找到 ${collectedFiles.length} 个 NASL 文件`);
|
|
38365
|
+
// 全量扫描时也从文件中提取外部依赖引用
|
|
38366
|
+
externalRefs = {
|
|
38367
|
+
extensions: new Set(),
|
|
38368
|
+
connectors: new Set(),
|
|
38369
|
+
uilibs: new Set(),
|
|
38370
|
+
apis: new Map(),
|
|
38371
|
+
};
|
|
38372
|
+
collectedFiles.forEach((f) => mergeExternalRefs(externalRefs, extractExternalRefs(f.content)));
|
|
38124
38373
|
}
|
|
38125
38374
|
// 统一过滤掉不支持的文件类型
|
|
38126
38375
|
const filteredFiles = [];
|
|
@@ -38132,11 +38381,24 @@ async function resolveNASLFiles(entry, logger, depMode, verbose) {
|
|
|
38132
38381
|
logger.warn(`跳过不支持的文件类型: ${file.path}`);
|
|
38133
38382
|
}
|
|
38134
38383
|
});
|
|
38384
|
+
// 从分析中构建 externalDependencies(版本号从 app.dependencies.json / potential.dependencies.json 获取)
|
|
38385
|
+
let externalDependencies;
|
|
38386
|
+
let mergedDependencies;
|
|
38387
|
+
if (externalRefs && (externalRefs.extensions.size > 0 || externalRefs.connectors.size > 0 || externalRefs.uilibs.size > 0 || externalRefs.apis.size > 0)) {
|
|
38388
|
+
const mergedDeps = loadMergedDependencies(srcDir);
|
|
38389
|
+
externalDependencies = buildExternalDependencies(externalRefs, mergedDeps);
|
|
38390
|
+
const appDeps = loadAppDependencies(srcDir);
|
|
38391
|
+
mergedDependencies = mergeDependenciesIntoApp(appDeps, externalDependencies);
|
|
38392
|
+
logger.debug('已从分析构建 externalDependencies', externalDependencies);
|
|
38393
|
+
logger.debug('已从分析构建 mergedDependencies', mergedDependencies);
|
|
38394
|
+
}
|
|
38135
38395
|
return {
|
|
38136
38396
|
collectedFiles: filteredFiles,
|
|
38137
38397
|
config,
|
|
38138
38398
|
projectRoot,
|
|
38139
38399
|
srcDir,
|
|
38400
|
+
externalDependencies,
|
|
38401
|
+
mergedDependencies,
|
|
38140
38402
|
};
|
|
38141
38403
|
}
|
|
38142
38404
|
|
|
@@ -38147,19 +38409,20 @@ async function compile(entry, options) {
|
|
|
38147
38409
|
const logger = options?.logger || defaultLogger;
|
|
38148
38410
|
logger.info('开始编译 NASL 代码...');
|
|
38149
38411
|
// 收集需要编译的文件
|
|
38150
|
-
const { collectedFiles, config, projectRoot } = await resolveNASLFiles(entry, logger, false, options?.verbose);
|
|
38412
|
+
const { collectedFiles, config, projectRoot, mergedDependencies } = await resolveNASLFiles(entry, logger, false, options?.verbose);
|
|
38151
38413
|
logger.info(`输出目录: ${config.outDir}`);
|
|
38152
|
-
const outDir =
|
|
38414
|
+
const outDir = path$1.join(projectRoot, config.outDir);
|
|
38153
38415
|
// 调用编译 API
|
|
38154
38416
|
logger.newLine();
|
|
38155
38417
|
logger.info('正在调用编译服务...');
|
|
38156
38418
|
try {
|
|
38157
|
-
|
|
38419
|
+
let fullNaturalTS = composeToString(collectedFiles);
|
|
38420
|
+
fullNaturalTS = prependDependencies(fullNaturalTS, mergedDependencies);
|
|
38158
38421
|
const outputFiles = await compileApi(fullNaturalTS, config);
|
|
38159
38422
|
logger.success('编译成功!');
|
|
38160
38423
|
// 写入输出文件
|
|
38161
38424
|
for (const file of outputFiles) {
|
|
38162
|
-
const outputPath =
|
|
38425
|
+
const outputPath = path$1.join(outDir, file.path);
|
|
38163
38426
|
writeFileWithLog(outputPath, file.content, logger);
|
|
38164
38427
|
}
|
|
38165
38428
|
logger.info(`输出 ${outputFiles.length} 个文件`);
|
|
@@ -38182,7 +38445,7 @@ async function tryCompile(entry, options) {
|
|
|
38182
38445
|
}
|
|
38183
38446
|
}
|
|
38184
38447
|
|
|
38185
|
-
var version = "0.
|
|
38448
|
+
var version = "0.3.0";
|
|
38186
38449
|
var pkg = {
|
|
38187
38450
|
version: version};
|
|
38188
38451
|
|