Skip to content

Commit

Permalink
0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ityuany committed Jul 5, 2024
1 parent f8ea329 commit 6c5189b
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 11 deletions.
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
# source-code-diagnosis

This is a grocery store based on the `Rust` tool class, mainly used for various unique analysis of source code, supporting multi-threading.

## 如何安装

```bash
# pnpm
pnpm i @shined/source-code-diagnosis -D

# npm
npm i @shined/source-code-diagnosis -D

# yarn
yarn add @shined/source-code-diagnosis -D
```

## getUsageOfDangerStrings

Analyze the dangerous strings in the source code, usually used for third-party CDN detection.

```ts
import { getUsageOfDangerStrings } from "@shined/source-code-diagnosis";
import { getDangerStringsUsage } from "@shined/source-code-diagnosis";

let response = getUsageOfDangerStrings(
let response = getDangerStringsUsage(
["bootcss.com", "bootcdn.com", "polyfill.com", "polyfill.io"],
{
cwd: "/Users/Pikachu/project",
concurrency: 1,
}
);
```

## getModuleMemberUsage

Analyze the usage rate of module members, generally used to analyze the number of times the exported members of a third-party package are used.

```ts
const response = getModuleMemberUsage(["antd"], {
cwd: "/Users/Pikachu/project",
});
```
42 changes: 42 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# source-code-diagnosis

这是一个基于 `Rust` 工具类的杂货铺,主要用于对源码进行各种唯独的分析,支持多线程。

## 如何安装

```bash
# pnpm
pnpm i @shined/source-code-diagnosis -D

# npm
npm i @shined/source-code-diagnosis -D

# yarn
yarn add @shined/source-code-diagnosis -D
```

## getUsageOfDangerStrings

分析源码中存在的危险字符串,一般用于第三方 CDN 检测

```ts
import { getDangerStringsUsage } from "@shined/source-code-diagnosis";

let response = getDangerStringsUsage(
["bootcss.com", "bootcdn.com", "polyfill.com", "polyfill.io"],
{
cwd: "/Users/Pikachu/project",
concurrency: 1,
}
);
```

## getModuleMemberUsage

分析模块成员的使用率,一般用于分析一个第三方包的导出成员被使用的次数

```ts
const response = getModuleMemberUsage(["antd"], {
cwd: "/Users/Pikachu/project",
});
```
4 changes: 2 additions & 2 deletions __test__/danger_string/index.spec.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import test from "ava";
import { getUsageOfDangerStrings } from "../../index.js";
import { getDangerStringsUsage } from "../../index.js";
import { fileURLToPath } from "node:url";
import { dirname } from "node:path";

// 获取当前文件的路径
const __filename = fileURLToPath(import.meta.url);

test("getUsageOfDangerStrings", (t) => {
const response = getUsageOfDangerStrings(["bootcss.com", "bootcdn.com", "polyfill.com", "polyfill.io"], {
const response = getDangerStringsUsage(["bootcss.com", "bootcdn.com", "polyfill.com", "polyfill.io"], {
cwd: dirname(__filename),
});
t.snapshot(response.sort((x) => x.filePath));
Expand Down
2 changes: 1 addition & 1 deletion __test__/module_member_usage/index.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { dirname } from "node:path";
// 获取当前文件的路径
const __filename = fileURLToPath(import.meta.url);

test("getUsageOfDangerStrings", (t) => {
test("getModuleMemberUsage", (t) => {
const response = getModuleMemberUsage(["antd"], {
cwd: dirname(__filename),
});
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface DangerStringLocation {
end: number
filePath: string
}
export declare function getUsageOfDangerStrings(dangerStrings: Array<string>, options?: Options | undefined | null): Array<DangerStringLocation>
export declare function getDangerStringsUsage(dangerStrings: Array<string>, options?: Options | undefined | null): Array<DangerStringLocation>
export interface ModuleMemberUsageLocation {
libName: string
memberName: string
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`)
}

const { getUsageOfDangerStrings, getModuleMemberUsage } = nativeBinding
const { getDangerStringsUsage, getModuleMemberUsage } = nativeBinding

module.exports.getUsageOfDangerStrings = getUsageOfDangerStrings
module.exports.getDangerStringsUsage = getDangerStringsUsage
module.exports.getModuleMemberUsage = getModuleMemberUsage
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shined/source-code-diagnosis",
"version": "0.0.3",
"version": "0.0.4",
"main": "index.js",
"types": "index.d.ts",
"napi": {
Expand Down
2 changes: 1 addition & 1 deletion src/danger_string_usage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod danger_string_location;
mod danger_string_visitor;

#[napi]
pub fn get_usage_of_danger_strings(
pub fn get_danger_strings_usage(
danger_strings: Vec<String>,
options: Option<Options>,
) -> Result<Vec<DangerStringLocation>> {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ mod danger_string_usage;
mod module_member_usage;
mod oxc_visitor_processor;

pub use danger_string_usage::get_usage_of_danger_strings;
pub use danger_string_usage::get_danger_strings_usage;
pub use module_member_usage::get_module_member_usage;

0 comments on commit 6c5189b

Please sign in to comment.