Skip to content

Commit

Permalink
fix: fix symbol link support in pnpm workspace (#21)
Browse files Browse the repository at this point in the history
Co-authored-by: hardfist <[email protected]>
  • Loading branch information
fi3ework and hardfist authored Aug 30, 2024
1 parent 097036a commit b420f49
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 24 deletions.
44 changes: 22 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,28 @@ jobs:
rustup target add wasm32-unknown-unknown
cargo check --all-features --target wasm32-unknown-unknown
wasi:
name: Test wasi target
runs-on: ubuntu-latest
steps:
- uses: taiki-e/checkout-action@v1

- uses: Boshen/setup-rust@main
with:
cache-key: wasi
save-cache: ${{ github.ref_name == 'main' }}

- uses: ./.github/actions/pnpm

- name: Build
run: |
rustup target add wasm32-wasip1-threads
pnpm build --target wasm32-wasip1-threads
- name: Test
run: pnpm test
env:
WASI_TEST: 1
# wasi:
# name: Test wasi target
# runs-on: ubuntu-latest
# steps:
# - uses: taiki-e/checkout-action@v1

# - uses: Boshen/setup-rust@main
# with:
# cache-key: wasi
# save-cache: ${{ github.ref_name == 'main' }}

# - uses: ./.github/actions/pnpm

# - name: Build
# run: |
# rustup target add wasm32-wasip1-threads
# pnpm build --target wasm32-wasip1-threads

# - name: Test
# run: pnpm test
# env:
# WASI_TEST: 1

typos:
name: Spell Check
Expand Down
2 changes: 2 additions & 0 deletions fixtures/pnpm-workspace/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.DS_Store
14 changes: 14 additions & 0 deletions fixtures/pnpm-workspace/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "monorepo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"packageManager": "[email protected]",
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"enhanced-resolve": "^5.17.1",
"oxc-resolver": "latest"
}
}
7 changes: 7 additions & 0 deletions fixtures/pnpm-workspace/packages/app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@monorepo/app",
"private": true,
"dependencies": {
"@monorepo/lib": "workspace:*"
}
}
9 changes: 9 additions & 0 deletions fixtures/pnpm-workspace/packages/lib/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@monorepo/lib",
"version": "0.0.1",
"private": true,
"type": "module",
"dependencies": {
"react": "^18.3.1"
}
}
21 changes: 20 additions & 1 deletion napi/__test__/resolver.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ for (const [title, context, request, expected] of [
}

test('resolve pnpm package', (t) => {
const rootDir = join(currentDir, '..', '..');
const rootDir = join(currentDir, '..', '..')
const pnpmProjectPath = join(rootDir, 'fixtures', 'pnpm')
const resolver = new ResolverFactory({
aliasFields: ['browser'],
Expand All @@ -258,3 +258,22 @@ test('resolve pnpm package', (t) => {
}
)
})

test('resolve recursive symbol link', (t) => {
const rootDir = join(currentDir, '..', '..')
const workspaceProjectPath = join(rootDir, 'fixtures', 'pnpm-workspace')
const resolver = new ResolverFactory({})

t.deepEqual(
resolver.sync(
join(workspaceProjectPath, './packages/app'),
'./node_modules/@monorepo/lib/node_modules/react/package.json'
),
{
path: join(
rootDir,
'node_modules/.pnpm/[email protected]/node_modules/react/package.json'
),
}
)
})
143 changes: 143 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ packages:
- 'npm'
- 'napi'
- 'fixtures/pnpm'
- 'fixtures/pnpm-workspace/**'
2 changes: 1 addition & 1 deletion src/file_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl FileSystem for FileSystemOs {
VPath::Virtual(info) => dunce::canonicalize(info.physical_base_path()),
VPath::Native(path) => dunce::canonicalize(path),
}
} else if #[cfg(windows)] {
} else if #[cfg(not(target_os = "wasi"))]{
dunce::canonicalize(path)
} else {
use std::path::Component;
Expand Down

0 comments on commit b420f49

Please sign in to comment.