Skip to content

NXT-20982: Upgrade chalk to v6 and support webpack 5.112 - #168

Open
hong6316 wants to merge 6 commits into
developfrom
feature/NXT-20982
Open

hong6316 wants to merge 6 commits into
developfrom
feature/NXT-20982

Conversation

@hong6316

Copy link
Copy Markdown
Contributor

Checklist

  • I have read and understand the contribution guide
  • A CHANGELOG entry is included
  • I have run automated testing and it is passed
  • Documentation was added or is not needed
  • This is an API breaking change

Issue Resolved / Feature Added

Upgrades chalk to v6 and makes the DLL/prerender plugins compatible with
webpack 5.112, which relocated several internal modules that the framework
plugins require directly.

Resolution

  • chalk 5 → 6: no code change needed; all usages already use the ESM-friendly
    dynamic import('chalk') / new Chalk() patterns.
  • import-fresh: removed the dependency. import-fresh 4 is ESM-only and
    exposes an asynchronous, module-loader-hook based importer, which is
    incompatible with the synchronous prerender path in vdom-server-render
    (invoked inside webpack’s synchronous chunkAsset hook). The small,
    CommonJS-only "uncached require" behavior it provided is inlined instead, so
    render() stays synchronous and PrerenderPlugin is unchanged.
  • webpack 5.112 internal relocations fixed in the DLL plugins:
    • RuntimeGlobals: moved to lib/runtime/ — now uses the public API
      require('webpack').RuntimeGlobals.
    • ExternalsPlugin: moved to lib/externals/ — now uses the public API
      require('webpack').ExternalsPlugin.
    • DelegatedSourceDependency: moved from lib/dependencies/ to lib/dll/ —
      now required from the correct path. (Targets webpack 5.112.)

Additional Considerations

Verified the DLL/prerender plugins and their require chains
(EnactFrameworkPlugin, EnactFrameworkRefPlugin, mixins/framework.js,
mixins/externals.js, index.js) load under webpack 5.112.2, with lint passing.
Exercised end-to-end via the Enact CLI framework/isomorphic/screenshot/ui jobs
through the companion @enact/cli PR.

Links

NXT-20982

Comments

Enact-DCO-1.0-Signed-off-by: Taeyoung Hong (taeyoung.hong@lge.com)

…d require

- chalk ^5.6.2 -> ^6.0.1. No code change needed: all usages already use the
  ESM-compatible dynamic import('chalk') / new Chalk() patterns.

- Remove the import-fresh dependency. import-fresh 4 is ESM-only and exposes an
  asynchronous, module-loader-hook based importer, which is incompatible with
  the synchronous prerender path in vdom-server-render (invoked inside webpack's
  synchronous chunkAsset SyncHook). Inline the small, CommonJS-only behavior the
  code relied on (resolve, drop from require.cache incl. parent linkage, require
  again) so render() stays synchronous and PrerenderPlugin is unchanged.
webpack 5.112 relocated RuntimeGlobals from webpack/lib/RuntimeGlobals to
webpack/lib/runtime/RuntimeGlobals, so the deep require broke framework builds
('Cannot find module webpack/lib/RuntimeGlobals') on webpack >= 5.112. Switch
to the public API (require('webpack').RuntimeGlobals), which resolves across
webpack 5 versions. The other deep webpack/lib requires in the dll plugins
(DllEntryPlugin, DllModule, Delegated*, ExternalsPlugin) still exist in 5.112
and are left unchanged.
webpack 5.112 moved internal modules, breaking the external-framework build
('Cannot find module webpack/lib/dependencies/DelegatedSourceDependency'):
- ExternalsPlugin: use the public API require('webpack').ExternalsPlugin
  (its internal path moved to lib/externals/).
- DelegatedSourceDependency: moved from lib/dependencies/ to lib/dll/. It has
  no public API, so resolve it tolerantly across both locations.
- DelegatedModule: wrapped with the same tolerant resolver for robustness.
Keeps compatibility with both older (5.109) and newer (5.112+) webpack 5.
Drop the webpack 5.109 compatibility fallback and target webpack 5.112 directly:
- DelegatedSourceDependency / DelegatedModule: require from lib/dll/ directly.
- ExternalsPlugin / RuntimeGlobals: use the public webpack API.
chalk 6 ships a conditional `exports` map that eslint-import-resolver-node
(via eslint-plugin-import) cannot resolve, so the dynamic `import('chalk')`
calls produced false `import/no-unresolved` errors and failed the CI lint
(run with --max-warnings 0). Ignore `chalk` in the import/no-unresolved rule;
the import resolves correctly at runtime.
Comment thread package.json
},
"peerDependencies": {
"html-webpack-plugin": ">=5.0.0",
"webpack": ">=5.0.0"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should update this, since webpack 5.112 has breaking changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants