Skip to content

Commit d9cdc00

Browse files
committed
修复扫描文件信息异常BUG
修复扫描文件信息失效(jsx)问题,由 ast 转为 re
1 parent 1003ec1 commit d9cdc00

7 files changed

Lines changed: 67 additions & 157 deletions

File tree

.changeset/flat-zoos-join.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@xiaohuohumax/bookmark-script": patch
3+
---
4+
5+
关闭读取 vite.config.js, 修复扫描文件信息失效(jsx)问题

packages/bookmark-script/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
"bookmark-script": "bookmark-script.mjs"
2929
},
3030
"dependencies": {
31-
"@babel/core": "^7.24.0",
32-
"@babel/preset-typescript": "^7.23.3",
3331
"@xiaohuohumax/bookmark": "workspace:^",
3432
"chalk": "^5.3.0",
3533
"mime-types": "^2.1.35",
@@ -42,7 +40,6 @@
4240
},
4341
"devDependencies": {
4442
"@rollup/plugin-json": "^6.1.0",
45-
"@types/babel__core": "^7.20.5",
4643
"@types/mime-types": "^2.1.4",
4744
"@types/progress": "^2.0.7",
4845
"@types/yargs": "^17.0.32",

packages/bookmark-script/src/builder/vite/build.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export async function build(options: BuildScriptOptions): Promise<OutputChunk> {
5555
mode,
5656
envDir,
5757
envPrefix,
58+
configFile: false,
5859
plugins,
5960
resolve: {
6061
alias

packages/bookmark-script/src/cli/babel/index.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

packages/bookmark-script/src/cli/scan.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import chalk from 'chalk';
22

33
import { BookmarkExt, BookmarkFolderExt, BookmarkLinkExt } from '../builder';
4-
import { astScriptCommentBlocks } from './babel';
54

65
import nodePath from 'node:path';
76
import fs from 'node:fs';
87

98
const OPTION_RE = /^(\w+)\s+(.*)$/i;
109
const ENTER_RE = /\r?\n/i;
10+
const COMMENT_BLOCK_RE = /\/\*([\s\S]+?)\*\//ig;
1111

1212
/**
1313
* 依据配置前缀组装配置信息
@@ -68,14 +68,25 @@ function folderFileToBFE(file: string, optionPrefix: string): BookmarkFolderExt
6868
return res;
6969
}
7070

71+
/**
72+
* 通过 re 匹配全部 块注释
73+
* @param file 文件
74+
* @returns
75+
*/
76+
export function reScriptCommentBlocks(file: string): string[] {
77+
const data = fs.readFileSync(file, 'utf-8');
78+
return Array.from(data.matchAll(COMMENT_BLOCK_RE)).map(m => m[1]);
79+
}
80+
7181
/**
7282
* 通过配置前缀获取脚本配置信息
7383
* @param file 脚本文件路径
7484
* @param optionPrefix 配置前缀
7585
* @returns 脚本配置信息
7686
*/
7787
function scriptFileToBLE(file: string, optionPrefix: string): BookmarkLinkExt | void {
78-
const comment = astScriptCommentBlocks(file)[0];
88+
// 只取第一个 块注释
89+
const comment = reScriptCommentBlocks(file)[0];
7990
if (!comment) {
8091
return;
8192
}

packages/bookmark/src/builder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import defineTempleHTML from './index.html?raw';
77
export interface BuildOptions {
88
/**
99
* 是否添加到 个人工具栏文件夹
10+
*
11+
* @default true
1012
*/
1113
personalToolbarFolder?: boolean
1214
}

0 commit comments

Comments
 (0)