-
Notifications
You must be signed in to change notification settings - Fork 1
fix: 兼容低版本 Node 启动预检 #31
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 1 commit
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,21 @@ | ||||||||||||||||||||||
| import assert from 'node:assert/strict'; | ||||||||||||||||||||||
| import { readFileSync } from 'node:fs'; | ||||||||||||||||||||||
| import test from 'node:test'; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| test('preflight can be parsed by older Node before showing the version guard', () => { | ||||||||||||||||||||||
| const source = readFileSync(new URL('../dist/lib/preflight.js', import.meta.url), 'utf8'); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| assert.doesNotMatch(source, /\?\?/, 'preflight must not use nullish coalescing before the Node version guard runs'); | ||||||||||||||||||||||
| assert.doesNotMatch(source, /\?\./, 'preflight must not use optional chaining before the Node version guard runs'); | ||||||||||||||||||||||
| assert.doesNotMatch(source, /from 'node:/, 'preflight must not use node: imports before the Node version guard runs'); | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| test('cli defers application imports until after preflight runs', () => { | ||||||||||||||||||||||
| const source = readFileSync(new URL('../dist/cli.js', import.meta.url), 'utf8'); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| assert.match(source, /import '\.\/lib\/preflight\.js';/); | ||||||||||||||||||||||
| assert.doesNotMatch(source, /import \{ createProgram \} from '\.\/lib\/command\.js';/); | ||||||||||||||||||||||
| assert.doesNotMatch(source, /import \{ logger \} from '\.\/utils\/logger\.js';/); | ||||||||||||||||||||||
| assert.match(source, /import\('\.\/lib\/command\.js'\)/); | ||||||||||||||||||||||
| assert.match(source, /import\('\.\/utils\/logger\.js'\)/); | ||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 【P2 兼容性与测试漏洞风险】 建议使用支持单双引号的正则表达式,使测试更加健壮。
Suggested change
|
||||||||||||||||||||||
| }); | ||||||||||||||||||||||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
【P2 兼容性与测试漏洞风险】
当前测试中使用硬编码的单引号
from 'node:来匹配node:协议导入。如果 TypeScript 编译器、格式化工具(如 Prettier)或未来的构建流程将生成的 JS 代码中的单引号转换为双引号(例如from "node:fs"),此断言将无法匹配,从而导致测试静默通过(即无法检测出引入了node:导入的回归问题)。建议将正则表达式修改为同时支持单引号和双引号,以提高测试的健壮性。