[RFC]: Bringing `resolve` Dependency In-House
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 5/5
- 預估耗時
- 一週以上
- 新手友好度
- 35/100
- Issue 類型
- 重構
- 描述清晰度
- 基本清楚
- 活躍度
- 冷清
- 技術堆疊
- javascript, node.js
研究方向
先檢視提議的 @stdlib/utils/resolve 結構,接著檢查列出的 resolve 使用者,尤其是 modules/pkg-deps 及其 test/test.walk_file.js。在變更相依性之前先執行現有的使用者測試,然後加入套件測試並遷移列出的 import。完成的標準是回歸測試通過,且移除 resolve 及其傳遞相依性;手動驗證仍標記為 TODO。
由索引模型根據 Issue 內容生成。
描述
Replace resolve Dependency with In-House @stdlib/utils/resolve
Replace the external resolve npm dependency with a new stdlib-native package. This eliminates resolve and its 3 transitive dependencies (is-core-module, path-parse, supports-preserve-symlinks-flag) from the supply chain — removing 4 third-party packages total.
Background
The resolve package implements Node.js's require.resolve() algorithm with configurable basedir and paths options.
Only these features are used:
| Feature | Used? |
|---|---|
resolve(id, {basedir}, cb) (async) |
✅ 5 files |
resolve.sync(id, {basedir}) |
✅ 7 files |
resolve.sync(id, {basedir, paths}) |
✅ 1 file |
All other options (packageFilter, pathFilter, extensions, moduleDirectory, etc.) |
❌ |
Proposed Changes
New Package: @stdlib/utils/resolve
Folder Structure
lib/node_modules/@stdlib/utils/resolve/
├── README.md
├── package.json
│
├── lib/
│ ├── index.js # Entry point: exports async + .sync
│ ├── main.js # Async resolve( id, opts, clbk )
│ ├── sync.js # Sync resolve( id, opts ) → string
│ ├── validate.js # Options validation
│ ├── defaults.js # Default options (basedir, extensions)
│ ├── resolve_path.js # Core sync resolution algorithm
│ ├── async_resolve_path.js # Core async resolution algorithm
│ └── is_core_module.js # Built-in module check via module.builtinModules
│
├── docs/
│ ├── repl.txt
│ └── types/
│ ├── index.d.ts
│ └── test.ts
│
├── benchmark/
│ └── benchmark.js # Performance benchmarks (sync vs async)
│
├── examples/
│ └── index.js # Usage examples
│
└── test/
├── test.js # Main export tests
├── test.sync.js # Sync API tests
├── test.async.js # Async API tests
├── test.validate.js # Options validation tests
├── test.is_core_module.js # Core module detection tests
└── fixtures/
├── node_modules/
│ └── mock-pkg/
│ ├── package.json # { "main": "./lib/index.js" }
│ └── lib/
│ └── index.js
├── index.js # Mock directory index
├── foo.js # Mock module
└── foo.json # Mock JSON module
Key Implementation Details
lib/index.js — Entry point matching the resolve package's API shape:
var resolve = require( './main.js' ); // async
var sync = require( './sync.js' ); // sync
resolve.sync = sync;
module.exports = resolve;
lib/resolve_path.js— Core Node.js resolution algorithm:
- If
idis a core module → returnid - If
idstarts with./or../or/→ resolve as file, then as directory - Otherwise → walk
node_modulesdirectories upward frombasedir; ifpathsoption given, also search those - File resolution: try exact path →
.js→.json→.node - Directory resolution: read
package.jsonmainfield → fallback toindex.js→index.json→index.node
lib/is_core_module.js — Zero-dependency replacement for is-core-module:
var builtinModules = require( 'module' ).builtinModules;
function isCoreModule( id ) {
return builtinModules.indexOf( id ) !== -1;
}
Internal dependencies only — no third-party packages:
path(Node.js built-in)fs(Node.js built-in)module(Node.js built-in)@stdlib/assert/is-string(input validation)@stdlib/assert/is-plain-object(options validation)@stdlib/assert/has-own-property(options checking)@stdlib/error/tools/fmtprodmsg(error formatting)
Consumer Migration (13 files)
Each migration is a 1-line require swap. The API shape is identical.
Sync consumers (8 files) — require( 'resolve' ).sync → require( '@stdlib/utils/resolve' ).sync:
| # | File |
|---|---|
| 1 | eslint/require-file-extensions/lib/main.js |
| 2 | modules/pkg-deps/lib/walk_file.sync.js |
| 3 | pkgs/browser-compatible/lib/resolve.sync.js |
| 4 | pkgs/entry-points/lib/resolve.sync.js |
| 5 | pkgs/browser-entry-points/lib/resolve.sync.js |
| 6 | utils/library-manifest/lib/main.js |
| 7 | repl/help/scripts/build.js |
Async consumers (6 files) — require( 'resolve' ) → require( '@stdlib/utils/resolve' ):
| # | File |
|---|---|
| 8 | modules/pkg-deps/lib/walk_file.js |
| 9 | modules/pkg-deps/test/test.walk_file.js (also update proxyquire mock key) |
| 10 | pkgs/browser-compatible/lib/resolve.js |
| 11 | pkgs/entry-points/lib/resolve.js |
| 12 | pkgs/browser-entry-points/lib/resolve.js |
| 13 | lint/namespace-aliases/lib/resolve.js |
Dependency Removal
npm uninstall resolve
Verification Plan
Automated Tests
stdlib uses make test:
- Run new package tests using stdlib's test infrastructure:
make EXAMPLES_FILTER=".*/utils/resolve/.*"" examples
make BENCHMARKS_FILTER=".*/utils/resolve/.*"" benchmark
make TESTS_FILTER=". */utils/resolve/.*"" test
- Run consumer regression tests (pkg-deps has the most extensive test suite):
make TESTS_FILTER=". */_tools/modules/pkg-deps/.*"" test
Manual Verification
{TODO}
- 主要語言
- JavaScript
- 星號
- 6k
- 分支
- 1.3k
- 平均合併
- 1 天 21 小時
- 30 天內合併 PR
- 224
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
stdlib-js/stdlib 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
stdlib-js/stdlib#16655 · 1 則留言 ·
維護者通常 1 天內回覆
-
Fix JavaScript lint errors可能已有人在做 @protestershankar 於 5 天前認領。 未關閉Good First Issue
難度 2/5 1-3 小時 新手友好度 82/100
stdlib-js/stdlib#16563 · 3 則留言 ·
維護者通常 1 天內回覆
-
Fix C lint errors可能已有人在做 @raus7n 於 14 天前認領。 未關閉Good First Issue
難度 1/5 1 小時以內 新手友好度 82/100
stdlib-js/stdlib#16454 · 1 則留言 ·
維護者通常 1 天內回覆
-
Fix JavaScript lint errors可能已有人在做 @Devansh-18155 於 39 天前認領。 未關閉Good First Issue
難度 1/5 1 小時以內 新手友好度 82/100
stdlib-js/stdlib#15970 · 1 則留言 ·
維護者通常 1 天內回覆
-
Fix JavaScript lint errors可能已有人在做 @lb1192176991-lab 於 44 天前認領。 未關閉Good First Issue
難度 1/5 1 小時以內 新手友好度 90/100
stdlib-js/stdlib#15831 · 2 則留言 ·
維護者通常 1 天內回覆
相似的 Issue
-
難度 1/5 1 小時以內 新手友好度 69/100
維護者通常 1 天內回覆
-
automation chore ci-cd consistency developer-experience difficulty: easy discoverability documentation enhancement github-actions good first issue help wanted hygiene priority: P3 seo shell yaml
難度 1/5 1 小時以內 新手友好度 76/100
-
bug
難度 2/5 1-3 小時 新手友好度 84/100
swc-project/swc-next-issues#394 ·
-
難度 1/5 1-3 小時 新手友好度 88/100
githubnext/gh-aw-workshop#5790 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
adobe/helix-tools-website#480 ·
維護者通常 1 天內回覆