Skip to content

Commit

Permalink
feat: support yarn PnP out of box, propagate PnP runtime (#98)
Browse files Browse the repository at this point in the history
Co-authored-by: JounQin <admin@1stg.me>
  • Loading branch information
Noah and JounQin committed Aug 10, 2022
1 parent 59af559 commit 4fe6aef
Show file tree
Hide file tree
Showing 12 changed files with 10,666 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-comics-smell.md
@@ -0,0 +1,5 @@
---
"synckit": patch
---

feat: support yarn PnP out of box, propagate PnP runtime
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -96,6 +96,7 @@
"deasync": "^0.1.27",
"esbuild-register": "^3.3.3",
"esbuild-runner": "^2.2.1",
"execa": "^6.1.0",
"jest": "^28.1.3",
"patch-package": "^6.4.7",
"sync-threads": "^1.0.1",
Expand Down
17 changes: 17 additions & 0 deletions src/index.ts
Expand Up @@ -42,6 +42,7 @@ const {
SYNCKIT_TIMEOUT,
SYNCKIT_EXEC_ARGV,
SYNCKIT_TS_RUNNER,
NODE_OPTIONS,
} = process.env

export const DEFAULT_BUFFER_SIZE = SYNCKIT_BUFFER_SIZE
Expand Down Expand Up @@ -209,6 +210,22 @@ const setupTsRunner = (
}
}

/* istanbul ignore if -- https://github.com/facebook/jest/issues/5274 */
if (process.versions.pnp) {
const nodeOptions = NODE_OPTIONS?.split(/\s+/)
const pnpApiPath = cjsRequire.resolve('pnpapi')
if (
!nodeOptions?.some(
(option, index) =>
['-r', '--require'].includes(option) &&
pnpApiPath === cjsRequire.resolve(nodeOptions[index + 1]),
) &&
!execArgv.includes(pnpApiPath)
) {
execArgv = ['-r', pnpApiPath, ...execArgv]
}
}

return {
ext,
isTs,
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/yarn-pnp.spec.ts
@@ -0,0 +1,11 @@
import { resolve } from 'node:path'

import { execaNode } from 'execa'

test('yarn-pnp', async () => {
const { stdout } = await execaNode('index.js', [], {
nodeOptions: ['-r', './.pnp.cjs'],
cwd: resolve('test/fixtures/yarn-pnp'),
})
expect(stdout).toBe([1, 2, 5].join(' '))
})

0 comments on commit 4fe6aef

Please sign in to comment.