Skip to content

Commit 8ca7aef

Browse files
merceyzarcanis
andauthored
feat(pnp): experimental esm support (#2161)
* feat: esm support * fix: detect module type from any workspace * fix: always treat cjs as commonjs * test: add tests * chore: change loader name * test: exports * fix: use legacy resolve if exports is missing * chore: update config name * feat: enable loader if any package is a module * fix: use `findPnpApi` to get the correct `pnpapi` instance * fix: check if specifier has a pnpapi * ci: add SvelteKit test * ci: add Astro e2e test * fix: pass unknown extensions to the next loader * fix: don't enter ESM mode if main is cjs * fix: handle absolute paths to `_findPath` * chore: let node handle encoding the path to the loader * fix: get pnpapi of absolute path in `_findPath` * Update packages/yarnpkg-pnp/sources/esm-loader/loader.ts Co-authored-by: Maël Nison <[email protected]> * test: add dynamic import tests * test: check named exports from a zip file works * refactor: avoid code generation * test: skip `dynamic import in cjs` test * refactor: cleanup * refactor: rename config and move it to the plugin * fix: support explicitly disabling ESM support * chore: print a warning about experimental esm support * fix: make `isEsmEnabled` private * chore: versions * fix: add types for loader artifact * chore: eslintignore esm loader * chore: lint after merge * chore: update versions * chore: link to the test and upstream issue * refactor: pass conditions directly to `resolve.exports` * ci: set config as env variables * chore: update warning message * refactor: use `changeFilePromise` to update the loader * ci: remove Astro e2e test I've added integration tests that cover the same things * test: add link to issue Co-authored-by: Maël Nison <[email protected]>
1 parent c57f788 commit 8ca7aef

File tree

28 files changed

+995
-85
lines changed

28 files changed

+995
-85
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/packages/yarnpkg-pnp/sources/hook.js
2+
/packages/yarnpkg-pnp/sources/esm-loader/built-loader.js
23

34
/packages/yarnpkg-libzip/sources/libzipAsync.js
45
/packages/yarnpkg-libzip/sources/libzipSync.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
on:
2+
schedule:
3+
- cron: '0 */4 * * *'
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
paths:
9+
- .github/workflows/e2e-svelte-kit-workflow.yml
10+
- scripts/e2e-setup-ci.sh
11+
12+
name: 'E2E SvelteKit'
13+
jobs:
14+
chore:
15+
name: 'Validating SvelteKit'
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@master
20+
21+
- name: 'Install Node'
22+
uses: actions/setup-node@master
23+
with:
24+
node-version: 14.x
25+
26+
- name: 'Build the standard bundle'
27+
run: |
28+
node ./scripts/run-yarn.js build:cli
29+
30+
- name: 'Running the integration test'
31+
run: |
32+
source scripts/e2e-setup-ci.sh
33+
yes | yarn create svelte@next my-app && cd my-app
34+
yarn
35+
yarn build
36+

.pnp.cjs

+129-46
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Binary file not shown.

.yarn/versions/42ed2c88.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
releases:
2+
"@yarnpkg/cli": minor
3+
"@yarnpkg/plugin-pnp": minor
4+
"@yarnpkg/pnp": minor
5+
6+
declined:
7+
- "@yarnpkg/esbuild-plugin-pnp"
8+
- "@yarnpkg/plugin-compat"
9+
- "@yarnpkg/plugin-constraints"
10+
- "@yarnpkg/plugin-dlx"
11+
- "@yarnpkg/plugin-essentials"
12+
- "@yarnpkg/plugin-init"
13+
- "@yarnpkg/plugin-interactive-tools"
14+
- "@yarnpkg/plugin-nm"
15+
- "@yarnpkg/plugin-npm-cli"
16+
- "@yarnpkg/plugin-pack"
17+
- "@yarnpkg/plugin-patch"
18+
- "@yarnpkg/plugin-pnpm"
19+
- "@yarnpkg/plugin-stage"
20+
- "@yarnpkg/plugin-typescript"
21+
- "@yarnpkg/plugin-version"
22+
- "@yarnpkg/plugin-workspace-tools"
23+
- "@yarnpkg/builder"
24+
- "@yarnpkg/core"
25+
- "@yarnpkg/doctor"
26+
- "@yarnpkg/nm"
27+
- "@yarnpkg/pnpify"
28+
- "@yarnpkg/sdks"

.yarnrc.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ changesetIgnorePatterns:
33

44
enableGlobalCache: false
55

6+
pnpEnableExperimentalEsm: false
7+
68
immutablePatterns:
79
- .pnp.*
810

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ On top of our classic integration tests, we also run Yarn every day against the
113113
[![](https://github.com/yarnpkg/berry/workflows/E2E%20Gulp/badge.svg?event=schedule)](https://github.com/yarnpkg/berry/blob/master/.github/workflows/e2e-gulp-workflow.yml)<br/>
114114
[![](https://github.com/yarnpkg/berry/workflows/E2E%20Next/badge.svg?event=schedule)](https://github.com/yarnpkg/berry/blob/master/.github/workflows/e2e-next-workflow.yml)<br/>
115115
[![](https://github.com/yarnpkg/berry/workflows/E2E%20Preact%20CLI/badge.svg?event=schedule)](https://github.com/yarnpkg/berry/blob/master/.github/workflows/e2e-preact-cli-workflow.yml)<br/>
116+
[![](https://github.com/yarnpkg/berry/workflows/E2E%20SvelteKit/badge.svg?event=schedule)](https://github.com/yarnpkg/berry/blob/master/.github/workflows/e2e-svelte-kit-workflow.yml)<br/>
116117
[![](https://github.com/yarnpkg/berry/workflows/E2E%20Vue-CLI/badge.svg?event=schedule)](https://github.com/yarnpkg/berry/blob/master/.github/workflows/e2e-vue-cli-workflow.yml)<br/>
117118
</td><td valign="top">
118119

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log(42);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "no-deps-bins-esm",
3+
"version": "1.0.0",
4+
"type": "module",
5+
"bin": "./index.mjs"
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports.foo = 42;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "no-deps-exports",
3+
"version": "1.0.0"
4+
}

0 commit comments

Comments
 (0)