Skip to content

fix(rollup-plugin): remove default modules #5203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 12, 2025

Conversation

cardoso
Copy link
Contributor

@cardoso cardoso commented Feb 10, 2025

StackBlitz Repro. (The only difference from the playground is using pnpm instead of npm)

This PR proposes removing:

const DEFAULT_MODULES = [
{ npm: '@lwc/engine-dom' },
{ npm: '@lwc/synthetic-shadow' },
{ npm: '@lwc/wire-service' },
];

All tests are passing locally and no breaking changes are intended. If nucleus catches any downstream breakages, this PR can be closed.

Details

There are at least a few drawbacks related to declaring these default modules in advance.

  1. if you don't use synthetic shadow you're still required to have it in your dependency graph, even if you configure disableSyntheticShadowSupport: true and don't import it at all.

  2. If your setup doesn't handle transitive dependencies in the same way the resolve package expects, you're forced to make changes.

  3. The errors thrown when those packages cannot be resolved seem to imply the user declared them in the lwc config:

Error: Invalid LWC configuration in "/home/cardoso/salesforce-lwc-dshanxfr".
Invalid npm module record "{"npm":"@lwc/engine-dom"}",
"@lwc/engine-dom" npm module can't be resolved

The drawbacks stem from using the lwc module resolver to resolve those modules instead of letting the bundler (in this case rollup) handle them. This results in tooling compatibility issues with no apparent benefit.

Does this pull request introduce a breaking change?

  • 😮‍💨 No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

  • 🤞 No, it does not introduce an observable change.

GUS work item

@cardoso cardoso requested a review from a team as a code owner February 10, 2025 14:40
@wjhsf
Copy link
Collaborator

wjhsf commented Feb 10, 2025

/nucleus test

@wjhsf
Copy link
Collaborator

wjhsf commented Feb 10, 2025

When I run the repro:

[!] (plugin rollup-plugin-lwc-compiler) Error: Invalid LWC configuration in "/home/cardoso/salesforce-lwc-dshanxfr". Invalid npm module record "{"npm":"@lwc/engine-dom"}", "@lwc/engine-dom" npm module can't be resolved

🫠

@wjhsf
Copy link
Collaborator

wjhsf commented Feb 10, 2025

I'm not sure I fully understand the context here. Is this correct?

  • DEFAULT_MODULES defines a set of npm packages that the LWC module resolver knows about by default.

  • If the user doesn't specify them in their module config, then the modules can still be resolved.

  • If the user does specify them in their module config, then the modules are resolved just fine.

  • If a user doesn't use the packages and doesn't have them installed, compilation fails.

    • If they do have them installed, do they end up in the bundle? Or do they just need to be installed and bundled as needed.
  • Since they're regular npm packages, then this change removes them from the LWC resolution lookup, and lets rollup handle it instead. Since both module resolution algorithms point to the same file, this should ultimately not be a change to the bundled code, but it eliminates the requirement to have the packages installed.

  • If a user (does/doesn't) have the packages installed, and (does/doesn't) use the packages in their code, what's the behavior (before/after) this change?

@cardoso
Copy link
Contributor Author

cardoso commented Feb 12, 2025

@wjhsf yes that's pretty much it.

If they do have them installed, do they end up in the bundle? Or do they just need to be installed and bundled as needed.

They are installed as needed and get bundled only if used.

Since "lwc" pulls everything as a transitive dependency, they're guaranteed to be installed, but not guaranteed to be hoisted.

  • If using pnpm, they can be added explicitly as dependencies, or the line below can be added to .npmrc:

public-hoist-pattern[]=@lwc*

If someone is already using pnpm with lwc, they're already doing the above or explicit dependencies.

  • In npm/yarn transitive dependencies get hoisted by default, so nothing needs changing.

If a user (does/doesn't) have the packages installed, and (does/doesn't) use the packages in their code, what's the behavior (before/after) this change?

Instead of the error coming from the lwc plugin, it will come from the bundler as a warning or error depending on the setup.

In my opinion, it's a good tradeoff, since what's currently working should keep working without changes.

I'm assuming this based on nucleus + internal assessments.

@wjhsf
Copy link
Collaborator

wjhsf commented Feb 12, 2025

/nucleus test

@wjhsf wjhsf merged commit 1e7642b into salesforce:master Feb 12, 2025
11 checks passed
jhefferman-sfdc added a commit that referenced this pull request Feb 18, 2025
* wip: wip

* build(deps-dev): bump prettier from 3.4.2 to 3.5.0 in the prettier group (#5204)

Bumps the prettier group with 1 update: [prettier](https://github.com/prettier/prettier).


Updates `prettier` from 3.4.2 to 3.5.0
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md)
- [Commits](prettier/prettier@3.4.2...3.5.0)

---
updated-dependencies:
- dependency-name: prettier
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: prettier
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump the theoretically-non-breaking group with 20 updates (#5205)

* build(deps): bump the theoretically-non-breaking group with 20 updates

Bumps the theoretically-non-breaking group with 20 updates:

| Package | From | To |
| --- | --- | --- |
| [@eslint/js](https://github.com/eslint/eslint/tree/HEAD/packages/js) | `9.19.0` | `9.20.0` |
| [@nx/js](https://github.com/nrwl/nx/tree/HEAD/packages/js) | `20.3.3` | `20.4.2` |
| [@swc/core](https://github.com/swc-project/swc) | `1.10.12` | `1.10.15` |
| [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) | `22.13.0` | `22.13.1` |
| [@vitest/eslint-plugin](https://github.com/vitest-dev/eslint-plugin-vitest) | `1.1.25` | `1.1.27` |
| [eslint](https://github.com/eslint/eslint) | `9.19.0` | `9.20.0` |
| [nx](https://github.com/nrwl/nx/tree/HEAD/packages/nx) | `20.3.3` | `20.4.2` |
| [rollup](https://github.com/rollup/rollup) | `4.34.1` | `4.34.6` |
| [terser](https://github.com/terser/terser) | `5.37.0` | `5.38.1` |
| [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/typescript-eslint) | `8.22.0` | `8.23.0` |
| [@babel/core](https://github.com/babel/babel/tree/HEAD/packages/babel-core) | `7.26.7` | `7.26.8` |
| [@babel/plugin-transform-async-generator-functions](https://github.com/babel/babel/tree/HEAD/packages/babel-plugin-transform-async-generator-functions) | `7.25.9` | `7.26.8` |
| [@wdio/cli](https://github.com/webdriverio/webdriverio/tree/HEAD/packages/wdio-cli) | `9.7.2` | `9.8.0` |
| [@wdio/local-runner](https://github.com/webdriverio/webdriverio/tree/HEAD/packages/wdio-local-runner) | `9.7.2` | `9.8.0` |
| [@wdio/mocha-framework](https://github.com/webdriverio/webdriverio/tree/HEAD/packages/wdio-mocha-framework) | `9.7.2` | `9.7.3` |
| [@wdio/sauce-service](https://github.com/webdriverio/webdriverio/tree/HEAD/packages/wdio-sauce-service) | `9.7.2` | `9.8.0` |
| [@wdio/spec-reporter](https://github.com/webdriverio/webdriverio/tree/HEAD/packages/wdio-spec-reporter) | `9.6.3` | `9.8.0` |
| [webdriverio](https://github.com/webdriverio/webdriverio/tree/HEAD/packages/webdriverio) | `9.7.2` | `9.8.0` |
| [@babel/types](https://github.com/babel/babel/tree/HEAD/packages/babel-types) | `7.26.7` | `7.26.8` |
| [postcss-selector-parser](https://github.com/postcss/postcss-selector-parser) | `7.0.0` | `7.1.0` |


Updates `@eslint/js` from 9.19.0 to 9.20.0
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/commits/v9.20.0/packages/js)

Updates `@nx/js` from 20.3.3 to 20.4.2
- [Release notes](https://github.com/nrwl/nx/releases)
- [Commits](https://github.com/nrwl/nx/commits/20.4.2/packages/js)

Updates `@swc/core` from 1.10.12 to 1.10.15
- [Release notes](https://github.com/swc-project/swc/releases)
- [Changelog](https://github.com/swc-project/swc/blob/main/CHANGELOG.md)
- [Commits](swc-project/swc@v1.10.12...v1.10.15)

Updates `@types/node` from 22.13.0 to 22.13.1
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Updates `@vitest/eslint-plugin` from 1.1.25 to 1.1.27
- [Release notes](https://github.com/vitest-dev/eslint-plugin-vitest/releases)
- [Commits](vitest-dev/eslint-plugin-vitest@v1.1.25...v1.1.27)

Updates `eslint` from 9.19.0 to 9.20.0
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](eslint/eslint@v9.19.0...v9.20.0)

Updates `nx` from 20.3.3 to 20.4.2
- [Release notes](https://github.com/nrwl/nx/releases)
- [Commits](https://github.com/nrwl/nx/commits/20.4.2/packages/nx)

Updates `rollup` from 4.34.1 to 4.34.6
- [Release notes](https://github.com/rollup/rollup/releases)
- [Changelog](https://github.com/rollup/rollup/blob/master/CHANGELOG.md)
- [Commits](rollup/rollup@v4.34.1...v4.34.6)

Updates `terser` from 5.37.0 to 5.38.1
- [Changelog](https://github.com/terser/terser/blob/master/CHANGELOG.md)
- [Commits](terser/terser@v5.37.0...v5.38.1)

Updates `typescript-eslint` from 8.22.0 to 8.23.0
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/typescript-eslint/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.23.0/packages/typescript-eslint)

Updates `@babel/core` from 7.26.7 to 7.26.8
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.26.8/packages/babel-core)

Updates `@babel/plugin-transform-async-generator-functions` from 7.25.9 to 7.26.8
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.26.8/packages/babel-plugin-transform-async-generator-functions)

Updates `@wdio/cli` from 9.7.2 to 9.8.0
- [Release notes](https://github.com/webdriverio/webdriverio/releases)
- [Changelog](https://github.com/webdriverio/webdriverio/blob/main/CHANGELOG.md)
- [Commits](https://github.com/webdriverio/webdriverio/commits/v9.8.0/packages/wdio-cli)

Updates `@wdio/local-runner` from 9.7.2 to 9.8.0
- [Release notes](https://github.com/webdriverio/webdriverio/releases)
- [Changelog](https://github.com/webdriverio/webdriverio/blob/main/CHANGELOG.md)
- [Commits](https://github.com/webdriverio/webdriverio/commits/v9.8.0/packages/wdio-local-runner)

Updates `@wdio/mocha-framework` from 9.7.2 to 9.7.3
- [Release notes](https://github.com/webdriverio/webdriverio/releases)
- [Changelog](https://github.com/webdriverio/webdriverio/blob/main/CHANGELOG.md)
- [Commits](https://github.com/webdriverio/webdriverio/commits/v9.7.3/packages/wdio-mocha-framework)

Updates `@wdio/sauce-service` from 9.7.2 to 9.8.0
- [Release notes](https://github.com/webdriverio/webdriverio/releases)
- [Changelog](https://github.com/webdriverio/webdriverio/blob/main/CHANGELOG.md)
- [Commits](https://github.com/webdriverio/webdriverio/commits/v9.8.0/packages/wdio-sauce-service)

Updates `@wdio/spec-reporter` from 9.6.3 to 9.8.0
- [Release notes](https://github.com/webdriverio/webdriverio/releases)
- [Changelog](https://github.com/webdriverio/webdriverio/blob/main/CHANGELOG.md)
- [Commits](https://github.com/webdriverio/webdriverio/commits/v9.8.0/packages/wdio-spec-reporter)

Updates `webdriverio` from 9.7.2 to 9.8.0
- [Release notes](https://github.com/webdriverio/webdriverio/releases)
- [Changelog](https://github.com/webdriverio/webdriverio/blob/main/CHANGELOG.md)
- [Commits](https://github.com/webdriverio/webdriverio/commits/v9.8.0/packages/webdriverio)

Updates `@babel/types` from 7.26.7 to 7.26.8
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.26.8/packages/babel-types)

Updates `postcss-selector-parser` from 7.0.0 to 7.1.0
- [Release notes](https://github.com/postcss/postcss-selector-parser/releases)
- [Changelog](https://github.com/postcss/postcss-selector-parser/blob/master/CHANGELOG.md)
- [Commits](postcss/postcss-selector-parser@v7.0.0...v7.1.0)

---
updated-dependencies:
- dependency-name: "@eslint/js"
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: theoretically-non-breaking
- dependency-name: "@nx/js"
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: theoretically-non-breaking
- dependency-name: "@swc/core"
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: theoretically-non-breaking
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: theoretically-non-breaking
- dependency-name: "@vitest/eslint-plugin"
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: theoretically-non-breaking
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: theoretically-non-breaking
- dependency-name: nx
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: theoretically-non-breaking
- dependency-name: rollup
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: theoretically-non-breaking
- dependency-name: terser
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: theoretically-non-breaking
- dependency-name: typescript-eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: theoretically-non-breaking
- dependency-name: "@babel/core"
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: theoretically-non-breaking
- dependency-name: "@babel/plugin-transform-async-generator-functions"
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: theoretically-non-breaking
- dependency-name: "@wdio/cli"
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: theoretically-non-breaking
- dependency-name: "@wdio/local-runner"
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: theoretically-non-breaking
- dependency-name: "@wdio/mocha-framework"
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: theoretically-non-breaking
- dependency-name: "@wdio/sauce-service"
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: theoretically-non-breaking
- dependency-name: "@wdio/spec-reporter"
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: theoretically-non-breaking
- dependency-name: webdriverio
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: theoretically-non-breaking
- dependency-name: "@babel/types"
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: theoretically-non-breaking
- dependency-name: postcss-selector-parser
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: theoretically-non-breaking
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore: downgrade nx

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Will Harney <wharney@salesforce.com>

* chore: bump nx (#5207)

* chore: bump nx

last time dependabot tried, nx caused issues

* chore(nx): downgrade to 20.4.0

* chore: add logging to see why tree shaking is weird on CI

* chore: un-exclude LWC

it doesn't have build/dev scripts, so won't get picked up

and recent bug in NX causes --exclude=lwc to exclude all packages

* chore: revert test change to scripts

* fix(ssr): make internals non-configurable (#5208)

* fix(ssr): make internals non-configurable

* test(ssr): add check that internals are safe

* chore: remove rogue file

* chore: use correct file extension for test output

* fix: provide template prop on LightningElement in SSRv2 (#5212)

* chore: release v8.13.2 (#5213)

* fix(rollup-plugin): remove default modules (#5203)

* build(deps): bump koa from 2.15.3 to 2.15.4 (#5220)

Bumps [koa](https://github.com/koajs/koa) from 2.15.3 to 2.15.4.
- [Release notes](https://github.com/koajs/koa/releases)
- [Changelog](https://github.com/koajs/koa/blob/2.15.4/History.md)
- [Commits](koajs/koa@2.15.3...2.15.4)

---
updated-dependencies:
- dependency-name: koa
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat(ssr): add LWC version comment to end of compiled template (#5218)

* chore: rename ephemeral placeholder variable (#5210)

* chore: don't use custom test timeout for fixtures (#5221)

* test(engine-server): clean up fixture tests (#5219)

* test(engine-server): remove `feature` feature

it's unused

* chore: remove feature from types

* chore(tests): remove unused exports from tests

* chore: rename x/test modules to x/static

* chore: use static x-test for root fixture component

tag name (x-test) may not match directory name of root component

* chore: remove tag name that is no longer used

* refactor(test): destructure!

* chore: `fixture-test` feels better than `x-test` to make it more clear it's special

* chore: reintroduce locker logic (#5217)

* chore: reintroduce locker logic

* Update packages/@lwc/integration-karma/test/component/LightningElement/index.spec.js

Co-authored-by: Will Harney <62956339+wjhsf@users.noreply.github.com>

* Update packages/@lwc/engine-core/src/framework/invoker.ts

Co-authored-by: Will Harney <62956339+wjhsf@users.noreply.github.com>

---------

Co-authored-by: Will Harney <62956339+wjhsf@users.noreply.github.com>

* test(fixtures): eradicate `index.js` (#5222)

* refactor: create rollup plugin for virtual modules

* test(fixtures): refactor fixture config defs to individual files

they're not actually shared

* test(fixtures): update to use config.json instead of index.js

* chore: eradicate index.js

* chore: fix file extension

* chore: oops forgot this part

* chore: release v8.13.3 (#5223)

* chore: release v8.13.4

* chore: release v8.13.3

* fix: corrections, v1/2 pathing, expected failures

* chore: variable rename

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Dale Bustad <dbustad@salesforce.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Will Harney <wharney@salesforce.com>
Co-authored-by: Will Harney <62956339+wjhsf@users.noreply.github.com>
Co-authored-by: Matheus Cardoso <matheus@cardo.so>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy