-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 添加 Node.js SDK 的构建和测试支持,更新文档,移除过时的测试文件 #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| { | ||
| "name": "source_map_parser_node", | ||
| "collaborators": [ | ||
| "MasonChow <masonchat@foxmail.com>" | ||
| ], | ||
| "description": "A WebAssembly package for source_map_parser", | ||
| "version": "0.2.1", | ||
| "license": "MIT", | ||
| "type": "module", | ||
| "files": [ | ||
| "dist/", | ||
| "README.md", | ||
| "LICENSE" | ||
| ], | ||
| "types": "dist/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "import": "./dist/index.es.js" | ||
| }, | ||
| "./wasm": "./pkg/source_map_parser_node_bg.wasm", | ||
| "./raw": { | ||
| "types": "./pkg/source_map_parser_node.d.ts", | ||
| "import": "./pkg/source_map_parser_node.js" | ||
| } | ||
| }, | ||
| "scripts": { | ||
| "build:lib": "vite build", | ||
| "build": "bash ../../scripts/build-wasm-node.sh && vite build", | ||
| "pretest": "pnpm run build:lib", | ||
| "test": "pnpm pretest && vitest --run", | ||
| "test:coverage": "vitest --coverage", | ||
| "deploy": "pnpm run build && npm publish" | ||
| }, | ||
| "devDependencies": { | ||
| "@vitest/coverage-v8": "^2.0.5", | ||
| "@vitest/ui": "^2.0.5", | ||
| "typescript": "^5.5.4", | ||
| "vite": "^5.4.0", | ||
| "vite-plugin-top-level-await": "^1.6.0", | ||
| "vite-plugin-wasm": "^3.5.0", | ||
| "vitest": "^2.0.5" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // 高级入口:对 pkg 目录下 wasm 绑定做一层稳定封装 | ||
| // 目标:库模式构建 (Vite) 输出到 dist,并在使用端自动完成 wasm 初始化。 | ||
| // 注意:保持对原始 API 的命名导出,不修改 wasm 生成的函数签名。 | ||
|
|
||
| // 直接引用已经生成的绑定代码。 | ||
| // Vite 在构建时会处理对 .wasm 的静态导入(需保留插件或默认支持)。 | ||
| import * as lowLevel from '../pkg/source_map_parser_node.js'; | ||
|
|
||
| // 再导出所有低层 API,保持向后兼容。 | ||
| export * from '../pkg/source_map_parser_node.js'; | ||
|
|
||
| // 提供一个可显式调用的 init(幂等),方便在某些 SSR/自定义加载场景中手动控制。 | ||
| let _inited = false; | ||
| export async function init(): Promise<void> { | ||
| if (_inited) return; | ||
| // 这里实际上只要执行过绑定文件的顶层代码就已经初始化, | ||
| // 但为了语义化,仍然提供一个 Promise 接口,未来可在此扩展(例如自定义 wasm fetch)。 | ||
| _inited = true; | ||
| } | ||
|
|
||
| // 提供一个辅助方法,对常见用例进行包装示例(非必须,可选增强)。 | ||
| export async function mapErrorStackWithResolver(options: { | ||
| errorStack: string; | ||
| resolveSourceMap: (filePath: string) => string | undefined | null; | ||
| formatter?: (filePath: string) => string; | ||
| onError?: (rawLine: string, message: string) => void; | ||
| }): Promise<any> { | ||
| await init(); | ||
| const { errorStack, resolveSourceMap, formatter, onError } = options; | ||
| return lowLevel.generate_token_by_stack_raw( | ||
| errorStack, | ||
| formatter ?? null, | ||
| (p: string) => resolveSourceMap(p) ?? null, | ||
| onError ?? null | ||
| ); | ||
| } | ||
|
|
||
| // 默认导出整体 API(含原始导出与封装方法)。 | ||
| export default { | ||
| init, | ||
| mapErrorStackWithResolver, | ||
| ...lowLevel, | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.