Skip to content

Commit

Permalink
feat(pnp): experimental esm support (#2161)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
merceyz and arcanis authored Oct 20, 2021
1 parent c57f788 commit 8ca7aef
Show file tree
Hide file tree
Showing 28 changed files with 995 additions and 85 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/packages/yarnpkg-pnp/sources/hook.js
/packages/yarnpkg-pnp/sources/esm-loader/built-loader.js

/packages/yarnpkg-libzip/sources/libzipAsync.js
/packages/yarnpkg-libzip/sources/libzipSync.js
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/e2e-svelte-kit-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
on:
schedule:
- cron: '0 */4 * * *'
push:
branches:
- master
pull_request:
paths:
- .github/workflows/e2e-svelte-kit-workflow.yml
- scripts/e2e-setup-ci.sh

name: 'E2E SvelteKit'
jobs:
chore:
name: 'Validating SvelteKit'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@master

- name: 'Install Node'
uses: actions/setup-node@master
with:
node-version: 14.x

- name: 'Build the standard bundle'
run: |
node ./scripts/run-yarn.js build:cli
- name: 'Running the integration test'
run: |
source scripts/e2e-setup-ci.sh
yes | yarn create svelte@next my-app && cd my-app
yarn
yarn build
175 changes: 129 additions & 46 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
28 changes: 28 additions & 0 deletions .yarn/versions/42ed2c88.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
releases:
"@yarnpkg/cli": minor
"@yarnpkg/plugin-pnp": minor
"@yarnpkg/pnp": minor

declined:
- "@yarnpkg/esbuild-plugin-pnp"
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
- "@yarnpkg/nm"
- "@yarnpkg/pnpify"
- "@yarnpkg/sdks"
2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ changesetIgnorePatterns:

enableGlobalCache: false

pnpEnableExperimentalEsm: false

immutablePatterns:
- .pnp.*

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ On top of our classic integration tests, we also run Yarn every day against the
[![](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/>
[![](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/>
[![](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/>
[![](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/>
[![](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/>
</td><td valign="top">

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

0 comments on commit 8ca7aef

Please sign in to comment.