diff --git a/.github/actions/pnpm/action.yml b/.github/actions/pnpm/action.yml new file mode 100644 index 00000000..1e66e72a --- /dev/null +++ b/.github/actions/pnpm/action.yml @@ -0,0 +1,22 @@ +name: Pnpm + +description: Install pnpm + +runs: + using: composite + steps: + - name: Install pnpm + working-directory: fixtures/pnpm8 + run: corepack enable + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 18 + cache-dependency-path: ./fixtures/pnpm8/package.json + cache: pnpm + + - name: pnpm install + working-directory: fixtures/pnpm8 + shell: bash + run: pnpm install diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13b0d0bb..29d87673 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -179,6 +179,6 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - - name: Install Rust - uses: ./.github/actions/rustup + - uses: ./.github/actions/pnpm + - uses: ./.github/actions/rustup - run: cargo test --quiet diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index d59ada11..4d1b4f5f 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -26,6 +26,9 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Pnpm + uses: ./.github/actions/pnpm + - name: Install Rust Toolchain uses: ./.github/actions/rustup with: diff --git a/fixtures/pnpm8/.gitignore b/fixtures/pnpm8/.gitignore new file mode 100644 index 00000000..3c3629e6 --- /dev/null +++ b/fixtures/pnpm8/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/fixtures/pnpm8/package.json b/fixtures/pnpm8/package.json new file mode 100644 index 00000000..df53f01b --- /dev/null +++ b/fixtures/pnpm8/package.json @@ -0,0 +1,12 @@ +{ + "name": "pnpm8", + "version": "1.0.0", + "private": true, + "engines": { + "node": ">=16.0.0" + }, + "packageManager": "pnpm@8.10.5", + "devDependencies": { + "styled-components": "6.1.1" + } +} diff --git a/fixtures/pnpm8/pnpm-lock.yaml b/fixtures/pnpm8/pnpm-lock.yaml new file mode 100644 index 00000000..803e1540 --- /dev/null +++ b/fixtures/pnpm8/pnpm-lock.yaml @@ -0,0 +1,145 @@ +lockfileVersion: '6.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +devDependencies: + styled-components: + specifier: ^6.1.1 + version: 6.1.1(react-dom@18.2.0)(react@18.2.0) + +packages: + + /@emotion/is-prop-valid@1.2.1: + resolution: {integrity: sha512-61Mf7Ufx4aDxx1xlDeOm8aFFigGHE4z+0sKCa+IHCeZKiyP9RLD0Mmx7m8b9/Cf37f7NAvQOOJAbQQGVr5uERw==} + dependencies: + '@emotion/memoize': 0.8.1 + dev: true + + /@emotion/memoize@0.8.1: + resolution: {integrity: sha512-W2P2c/VRW1/1tLox0mVUalvnWXxavmv/Oum2aPsRcoDJuob75FC3Y8FbpfLwUegRcxINtGUMPq0tFCvYNTBXNA==} + dev: true + + /@emotion/unitless@0.8.1: + resolution: {integrity: sha512-KOEGMu6dmJZtpadb476IsZBclKvILjopjUii3V+7MnXIQCYh8W3NgNcgwo21n9LXZX6EDIKvqfjYxXebDwxKmQ==} + dev: true + + /@types/stylis@4.2.4: + resolution: {integrity: sha512-36ZrGJ8fgtBr6nwNnuJ9jXIj+bn/pF6UoqmrQT7+Y99+tFFeHHsoR54+194dHdyhPjgbeoNz3Qru0oRt0l6ASQ==} + dev: true + + /camelize@1.0.1: + resolution: {integrity: sha512-dU+Tx2fsypxTgtLoE36npi3UqcjSSMNYfkqgmoEhtZrraP5VWq0K7FkWVTYa8eMPtnU/G2txVsfdCJTn9uzpuQ==} + dev: true + + /css-color-keywords@1.0.0: + resolution: {integrity: sha512-FyyrDHZKEjXDpNJYvVsV960FiqQyXc/LlYmsxl2BcdMb2WPx0OGRVgTg55rPSyLSNMqP52R9r8geSp7apN3Ofg==} + engines: {node: '>=4'} + dev: true + + /css-to-react-native@3.2.0: + resolution: {integrity: sha512-e8RKaLXMOFii+02mOlqwjbD00KSEKqblnpO9e++1aXS1fPQOpS1YoqdVHBqPjHNoxeF2mimzVqawm2KCbEdtHQ==} + dependencies: + camelize: 1.0.1 + css-color-keywords: 1.0.0 + postcss-value-parser: 4.2.0 + dev: true + + /csstype@3.1.2: + resolution: {integrity: sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==} + dev: true + + /js-tokens@4.0.0: + resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} + dev: true + + /loose-envify@1.4.0: + resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==} + hasBin: true + dependencies: + js-tokens: 4.0.0 + dev: true + + /nanoid@3.3.7: + resolution: {integrity: sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==} + engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} + hasBin: true + dev: true + + /picocolors@1.0.0: + resolution: {integrity: sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==} + dev: true + + /postcss-value-parser@4.2.0: + resolution: {integrity: sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==} + dev: true + + /postcss@8.4.32: + resolution: {integrity: sha512-D/kj5JNu6oo2EIy+XL/26JEDTlIbB8hw85G8StOE6L74RQAVVP5rej6wxCNqyMbR4RkPfqvezVbPw81Ngd6Kcw==} + engines: {node: ^10 || ^12 || >=14} + dependencies: + nanoid: 3.3.7 + picocolors: 1.0.0 + source-map-js: 1.0.2 + dev: true + + /react-dom@18.2.0(react@18.2.0): + resolution: {integrity: sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==} + peerDependencies: + react: ^18.2.0 + dependencies: + loose-envify: 1.4.0 + react: 18.2.0 + scheduler: 0.23.0 + dev: true + + /react@18.2.0: + resolution: {integrity: sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==} + engines: {node: '>=0.10.0'} + dependencies: + loose-envify: 1.4.0 + dev: true + + /scheduler@0.23.0: + resolution: {integrity: sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==} + dependencies: + loose-envify: 1.4.0 + dev: true + + /shallowequal@1.1.0: + resolution: {integrity: sha512-y0m1JoUZSlPAjXVtPPW70aZWfIL/dSP7AFkRnniLCrK/8MDKog3TySTBmckD+RObVxH0v4Tox67+F14PdED2oQ==} + dev: true + + /source-map-js@1.0.2: + resolution: {integrity: sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==} + engines: {node: '>=0.10.0'} + dev: true + + /styled-components@6.1.1(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-cpZZP5RrKRIClBW5Eby4JM1wElLVP4NQrJbJ0h10TidTyJf4SIIwa3zLXOoPb4gJi8MsJ8mjq5mu2IrEhZIAcQ==} + engines: {node: '>= 16'} + peerDependencies: + react: '>= 16.8.0' + react-dom: '>= 16.8.0' + dependencies: + '@emotion/is-prop-valid': 1.2.1 + '@emotion/unitless': 0.8.1 + '@types/stylis': 4.2.4 + css-to-react-native: 3.2.0 + csstype: 3.1.2 + postcss: 8.4.32 + react: 18.2.0 + react-dom: 18.2.0(react@18.2.0) + shallowequal: 1.1.0 + stylis: 4.3.0 + tslib: 2.6.2 + dev: true + + /stylis@4.3.0: + resolution: {integrity: sha512-E87pIogpwUsUwXw7dNyU4QDjdgVMy52m+XEOPEKUn161cCzWjjhPSQhByfd1CcNvrOLnXQ6OnnZDwnJrz/Z4YQ==} + dev: true + + /tslib@2.6.2: + resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} + dev: true diff --git a/tests/resolve_test.rs b/tests/resolve_test.rs index 68a1b3be..9e2afb75 100644 --- a/tests/resolve_test.rs +++ b/tests/resolve_test.rs @@ -7,9 +7,31 @@ fn dir() -> PathBuf { } #[test] -fn chinese_dir() { +fn chinese() { let dir = dir(); let specifier = "./fixtures/misc/中文/中文.js"; let resolution = Resolver::new(ResolveOptions::default()).resolve(&dir, specifier); - assert_eq!(resolution.map(|r| r.into_path_buf()), Ok(dir.join("fixtures/misc/中文/中文.js"))) + assert_eq!(resolution.map(|r| r.into_path_buf()), Ok(dir.join("fixtures/misc/中文/中文.js"))); +} + +#[test] +fn styled_components() { + let dir = dir(); + let path = dir.join("fixtures/pnpm8"); + let specifier = "styled-components"; + + // cjs + let options = + ResolveOptions { alias_fields: vec![vec!["browser".into()]], ..ResolveOptions::default() }; + let resolution = Resolver::new(options).resolve(&path, specifier); + assert_eq!(resolution.map(|r| r.into_path_buf()), Ok(path.join("node_modules/.pnpm/styled-components@6.1.1_react-dom@18.2.0_react@18.2.0/node_modules/styled-components/dist/styled-components.browser.cjs.js"))); + + // esm + let options = ResolveOptions { + alias_fields: vec![vec!["browser".into()]], + main_fields: vec!["module".into()], + ..ResolveOptions::default() + }; + let resolution = Resolver::new(options).resolve(&path, specifier); + assert_eq!(resolution.map(|r| r.into_path_buf()), Ok(path.join("node_modules/.pnpm/styled-components@6.1.1_react-dom@18.2.0_react@18.2.0/node_modules/styled-components/dist/styled-components.browser.esm.js"))); }