@longzai-intelligence-dependencies/scanner 0.0.0-stage → 0.0.8

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/README.md CHANGED
@@ -1,3 +1,21 @@
1
- # Temporary Holding Version
1
+ # @longzai-intelligence-dependencies/scanner
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Longzai Intelligence 生态清单文件全树扫描共享包,以单次目录树遍历同时发现 npm 清单、rust 清单与鸿蒙清单,供 version 与 changelog 等域工具经 npm 版本依赖消费。
4
+
5
+ ## 能力
6
+
7
+ - 多生态单遍扫描:三类清单 pattern 合并为一次 `tinyglobby` 数组调用,目录树只下探一遍,`ecosystems` 选项可门控参与扫描的生态集合
8
+ - 容错扫描适配器:目录读取失败按错误码降级为空结果并按路径去重告警,可容忍错误码为 `ENAMETOOLONG`、`EACCES`、`EPERM`、`ENOENT`
9
+ - 默认忽略集:覆盖依赖目录与构建产物目录,并显式排除 `.lzi` 与 `.git` 工具链状态目录,`resolveScanIgnorePaths` 提供默认集与追加条目的合并
10
+ - 只做文件发现:生态语义解析如 rust workspace 识别与鸿蒙 entry 排除留在各域内,按清单文件名把发现结果归入所属生态并解析为绝对路径
11
+
12
+ ## 用法
13
+
14
+ ```ts
15
+ import { createTolerantScanFs, scanEcosystemFiles } from '@longzai-intelligence-dependencies/scanner';
16
+
17
+ const scanFs = createTolerantScanFs((dir, code) => {
18
+ console.warn(`跳过无法读取的目录 ${dir},错误码 ${code}`);
19
+ });
20
+ const result = await scanEcosystemFiles(rootDir, { ecosystems: ['npm'], scanFs });
21
+ ```
@@ -0,0 +1,111 @@
1
+ import "./rolldown-runtime-BqT_7tdF.js";
2
+ import { FileSystemAdapter } from "tinyglobby";
3
+ //#region src/utils/ecosystem-scan.utils.d.ts
4
+ /**
5
+ * 受扫描支持的生态
6
+ */
7
+ type ScanEcosystem = 'npm' | 'rust' | 'harmony';
8
+ /**
9
+ * 全部受支持的生态,即缺省扫描范围
10
+ */
11
+ declare const ALL_SCAN_ECOSYSTEMS: ScanEcosystem[];
12
+ /**
13
+ * 多生态扫描的发现结果
14
+ */
15
+ type EcosystemScanResult = {
16
+ /**
17
+ * npm 清单文件绝对路径列表,按路径排序
18
+ */
19
+ npm: string[];
20
+ /**
21
+ * rust 清单文件绝对路径列表,按路径排序
22
+ */
23
+ rust: string[];
24
+ /**
25
+ * 鸿蒙清单文件绝对路径列表,按路径排序
26
+ */
27
+ harmony: string[];
28
+ };
29
+ /**
30
+ * 多生态扫描选项
31
+ */
32
+ type ScanEcosystemFilesOptions = {
33
+ /**
34
+ * 参与扫描的生态集合,纯 npm 仓库可只声明 npm 以收窄遍历 pattern
35
+ *
36
+ * @default ALL_SCAN_ECOSYSTEMS
37
+ */
38
+ ecosystems?: ScanEcosystem[];
39
+ /**
40
+ * 完整的忽略路径列表,传入即整体取代默认忽略集,调用方需要追加条目时
41
+ * 先经 `resolveScanIgnorePaths` 合并再传入
42
+ *
43
+ * @default DEFAULT_SCAN_IGNORE
44
+ */
45
+ ignore?: string[];
46
+ /**
47
+ * 注入的文件系统适配器,目录读取失败的降级与告警由适配器承担,
48
+ * 适配器实例应在一次命令运行内复用以共享去重记录
49
+ */
50
+ scanFs?: FileSystemAdapter;
51
+ };
52
+ /**
53
+ * 单次遍历发现多生态的清单文件
54
+ *
55
+ * 三类清单 pattern 合并为一次 tinyglobby 数组调用,目录树只下探一遍,
56
+ * 与逐 pattern 独立发起 glob 相比,遍历成本从按生态计次收敛为一次
57
+ *
58
+ * @param rootDir - 扫描根目录,须为绝对路径
59
+ * @param options - 扫描选项
60
+ * @returns 按生态归类的清单文件绝对路径列表
61
+ */
62
+ declare const scanEcosystemFiles: (rootDir: string, options?: ScanEcosystemFilesOptions) => Promise<EcosystemScanResult>;
63
+ //#endregion
64
+ //#region src/utils/scan-ignore.utils.d.ts
65
+ /**
66
+ * 扫描默认忽略路径
67
+ */
68
+ /**
69
+ * 默认忽略的路径 glob,相对扫描根
70
+ *
71
+ * 覆盖各生态的依赖目录与构建产物目录,并显式排除工具链状态目录:
72
+ *
73
+ * - node_modules / oh_modules:npm 与鸿蒙依赖
74
+ * - target:rust 构建产物
75
+ * - dist / build / out:通用构建产物目录
76
+ * - coverage:测试覆盖率产物,内含的 package.json 不应参与扫描
77
+ * - .turbo:turbo 缓存
78
+ * - .lzi:lzi 工具链状态目录,聚合配置与运行凭据所在
79
+ * - .git:版本库元数据目录,此前依赖 glob 对点目录的跳过行为隐式排除,这里改为显式声明
80
+ */
81
+ declare const DEFAULT_SCAN_IGNORE: string[];
82
+ /**
83
+ * 合并默认忽略路径与调用方追加的忽略路径
84
+ *
85
+ * 追加列表缺省或为空时仅使用默认列表,行为与各域此前的忽略合并口径一致
86
+ *
87
+ * @param extraIgnore - 调用方追加的忽略路径
88
+ * @returns 合并后的忽略路径列表
89
+ */
90
+ declare const resolveScanIgnorePaths: (extraIgnore?: string[]) => string[];
91
+ //#endregion
92
+ //#region src/utils/tolerant-scan-fs.utils.d.ts
93
+ /**
94
+ * 目录读取失败被降级跳过时的一次性告警回调
95
+ *
96
+ * @param dir - 读取失败的目录路径
97
+ * @param code - 失败错误码,如 `EACCES`
98
+ */
99
+ type ScanSkipHandler = (dir: string, code: string) => void;
100
+ /**
101
+ * 创建容错扫描文件系统适配器
102
+ *
103
+ * 同一错误码与路径组合只告警一次,适配器实例应在一次命令运行内复用,
104
+ * 让多轮扫描共享去重记录
105
+ *
106
+ * @param onSkip - 目录读取失败被降级跳过时的告警回调
107
+ * @returns 可注入 tinyglobby `fs` 选项的适配器
108
+ */
109
+ declare const createTolerantScanFs: (onSkip: ScanSkipHandler) => FileSystemAdapter;
110
+ //#endregion
111
+ export { ALL_SCAN_ECOSYSTEMS, DEFAULT_SCAN_IGNORE, type EcosystemScanResult, type ScanEcosystem, type ScanEcosystemFilesOptions, type ScanSkipHandler, createTolerantScanFs, resolveScanIgnorePaths, scanEcosystemFiles };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import"./rolldown-runtime-BqT_7tdF.js";import{resolve as e}from"node:path";import{glob as t}from"tinyglobby";import*as n from"node:fs/promises";const r=[`**/node_modules/**`,`**/oh_modules/**`,`**/target/**`,`**/dist/**`,`**/build/**`,`**/out/**`,`**/coverage/**`,`**/.turbo/**`,`**/.lzi/**`,`**/.git/**`],i=e=>!e||e.length===0?r:[...r,...e],a=[`npm`,`rust`,`harmony`],o={npm:`**/package.json`,rust:`**/Cargo.toml`,harmony:`**/oh-package.json5`},s={"package.json":`npm`,"Cargo.toml":`rust`,"oh-package.json5":`harmony`},c=async(n,i)=>{let c=[...new Set(i?.ecosystems??a)].map(e=>o[e]),l=await t(c,{cwd:n,ignore:i?.ignore??r,onlyFiles:!0,dot:!1,fs:i?.scanFs}),u={npm:[],rust:[],harmony:[]};for(let t of l){let r=t.split(`/`).pop()??``,i=s[r];i!==void 0&&u[i].push(e(n,t))}return u.npm.sort(),u.rust.sort(),u.harmony.sort(),u},l=/* @__PURE__ */ new Set([`ENAMETOOLONG`,`EACCES`,`EPERM`,`ENOENT`]),u=e=>typeof e==`function`,d=e=>!(typeof e!=`object`||!e||`encoding`in e&&e.encoding!==void 0&&e.encoding!==null&&typeof e.encoding!=`string`||`withFileTypes`in e&&e.withFileTypes!==void 0&&typeof e.withFileTypes!=`boolean`||`recursive`in e&&e.recursive!==void 0&&typeof e.recursive!=`boolean`),f=e=>typeof e!=`object`||!e||!(`code`in e)?!1:typeof e.code==`string`,p=e=>{let t=/* @__PURE__ */ new Set,r=(n,r)=>{let i=`${r}:${n}`;t.has(i)||(t.add(i),e(n,r))},i=e=>{if(f(e))return l.has(e.code)?e.code:void 0};return{readdir:Object.assign((e,t,a)=>{let o=u(t)?t:u(a)?a:void 0,s=u(t)?void 0:t;if(o===void 0)throw Error(`readdir 调用缺少回调参数`);let c=t=>{let n=i(t);n===void 0?o(t,[]):(r(String(e),n),o(null,[]))};try{let t=s===void 0?n.readdir(e):d(s)?s.withFileTypes===!0?n.readdir(e,{encoding:s.encoding,withFileTypes:!0,recursive:s.recursive}):n.readdir(e,{encoding:s.encoding,recursive:s.recursive}):void 0;if(t===void 0)throw Error(`readdir 调用的选项形态不受支持`);t.then(e=>{o(null,e)},e=>{c(e)})}catch(e){c(e)}},{__promisify__:n.readdir})}};export{a as ALL_SCAN_ECOSYSTEMS,r as DEFAULT_SCAN_IGNORE,p as createTolerantScanFs,i as resolveScanIgnorePaths,c as scanEcosystemFiles};
@@ -0,0 +1 @@
1
+ import"node:module";export{};
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-dependencies/scanner",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.8",
4
+ "description": "Longzai Intelligence 生态清单文件全树扫描共享包",
5
+ "keywords": [
6
+ "dependencies",
7
+ "longzai-intelligence",
8
+ "scanner",
9
+ "tinyglobby"
10
+ ],
11
+ "license": "UNLICENSED",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "type": "module",
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ }
23
+ },
24
+ "scripts": {
25
+ "build": "lzi-builder",
26
+ "build:prod": "NODE_ENV=production bun run build",
27
+ "prepublishOnly": "bun run build:prod",
28
+ "typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
29
+ "typecheck:app": "lzi-tsgo typecheck tsconfig/app.json",
30
+ "typecheck:node": "lzi-tsgo typecheck tsconfig/node.json",
31
+ "typecheck:test": "lzi-tsgo typecheck tsconfig/test.json",
32
+ "lint": "oxlint && oxfmt --check",
33
+ "lint:fix": "oxlint --fix && oxfmt",
34
+ "test": "bun test",
35
+ "test:watch": "bun test --watch",
36
+ "test:coverage": "bun test --coverage",
37
+ "clean": "lzi-dev-cli clean"
38
+ },
39
+ "dependencies": {
40
+ "tinyglobby": "^0.2.17"
41
+ }
42
+ }