Skip to content
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

feat(module-tools): support autoExtension and shims to improve node esm mode #4831

Merged
merged 3 commits into from
Oct 25, 2023

Conversation

10Derozan
Copy link
Member

@10Derozan 10Derozan commented Oct 20, 2023

Summary

🤖 Generated by Copilot at 35b3016

This pull request adds support for different output file extensions for JavaScript and TypeScript modules based on the module type and format. It also adds some features and options for building bundles with esbuild, such as injecting global variables and shims for compatibility. It updates the build config schema, types, utils and dts modules to reflect the new features and options. It also adds some tests and changesets for the new features.

Details

🤖 Generated by Copilot at 35b3016

  • Add .changeset/orange-garlics-beg.md file to describe the changes in the pull request (link)
  • Add getDefaultOutExtension function to utils/outExtension.ts file to determine the default output file extension based on the format, root and autoExtension options (link)
  • Add shims and autoExtension properties to the build config schema, types, constants and merge functions, and set their default values (link, link, link, link, link, link, link, link)
  • Add dtsExtension property to the GeneratorDtsConfig interface and the generatorDts function, and use it to set the output file extension for the declaration files (link, link, link, link, link, link)
  • Add jsExtension property to the redirect and redirectImport functions, and use it to modify the import name based on the module type and format (link, link, link, link)
  • Add inject and outExtension properties to the esbuild build options, and use them to inject global variables and shims and customize the output file extension for the JavaScript bundles (link)
  • Modify the writeDtsFiles function to write the declaration files directly to the output directory with the correct file extension (link)
  • Add shims/cjs.js and shims/esm.js files to define and export global variables and shims for the CommonJS and ES modules bundles (link, link)
  • Import getDefaultOutExtension function in the build, redirect and esbuild modules, and use it to get the jsExtension and dtsExtension values based on the build config options (link, link, link, link, link, link, link)
  • Import path module in the esbuild and redirect modules, and use it to manipulate file paths and get file extensions (link, link)
  • Add test files for the autoExtension feature with the type-commonjs project type, and use the import function and the path module to test the dynamic import and the output file extension (link, link, link, link, link)

Related Issue

Checklist

  • I have added changeset via pnpm run change.
  • I have updated the documentation.
  • I have added tests to cover my changes.

@changeset-bot
Copy link

changeset-bot bot commented Oct 20, 2023

🦋 Changeset detected

Latest commit: 2cb3d02

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 265 packages
Name Type
@modern-js/module-tools Major
@modern-js/doc-plugin-auto-sidebar Major
@modern-js/plugin-tailwindcss Major
@modern-js/devtools-kit Major
@modern-js/plugin-devtools Major
@modern-js/plugin-module-babel Major
@modern-js/plugin-module-banner Major
@modern-js/plugin-module-import Major
@modern-js/plugin-module-node-polyfill Major
@modern-js/plugin-module-polyfill Major
integration-module-tools Major
@modern-js/core Major
@modern-js/plugin-bff Major
@modern-js/plugin-changeset Major
@modern-js/plugin-data-loader Major
@modern-js/plugin-i18n Major
@modern-js/plugin-lint Major
@modern-js/plugin-proxy Major
@modern-js/plugin-ssg Major
@modern-js/plugin-swc Major
@modern-js/builder-doc Major
@modern-js/main-doc Major
@modern-js/module-tools-docs Major
@modern-js/devtools-client Major
@modern-js/devtools-mount Major
@modern-js/plugin-garfish Major
@modern-js/plugin-router-v5 Major
@modern-js/runtime Major
@modern-js/plugin-testing Major
@modern-js/new-action Major
@modern-js/sandpack-react Major
@modern-js/storybook-generator-next Major
@modern-js-app/eslint-config Major
@modern-js/eslint-config Major
@modern-js/tsconfig Major
@modern-js/babel-plugin-module-resolver Major
@modern-js/bff-core Major
@modern-js/bff-runtime Major
@modern-js/server-core Major
@modern-js/create-request Major
@modern-js/plugin-express Major
@modern-js/plugin-koa Major
@modern-js/plugin-polyfill Major
@modern-js/plugin-server Major
@modern-js/plugin-worker Major
@modern-js/prod-server Major
@modern-js/server Major
@modern-js/server-utils Major
@modern-js/builder-cli Major
@modern-js/builder-rspack-provider Major
@modern-js/builder-shared Major
@modern-js/builder-webpack-provider Major
@modern-js/builder Major
@modern-js/builder-plugin-esbuild Major
@modern-js/builder-plugin-image-compress Major
@modern-js/builder-plugin-node-polyfill Major
@modern-js/builder-plugin-stylus Major
@modern-js/builder-plugin-swc Major
@modern-js/builder-plugin-vue Major
@modern-js/builder-plugin-vue2 Major
@modern-js/app-tools Major
@modern-js/monorepo-tools Major
@modern-js/create Major
@modern-js/e2e Major
@modern-js/node-bundle-require Major
@modern-js/plugin Major
@modern-js/runtime-utils Major
@modern-js/types Major
@modern-js/upgrade Major
@modern-js/utils Major
@modern-js/babel-compiler Major
@modern-js/storybook-builder Major
@modern-js/storybook Major
@scripts/build Major
@scripts/check-changeset Major
@scripts/jest-config Major
@scripts/lint-package-json Major
@scripts/prebundle Major
@scripts/update-codesmith Major
@scripts/update-rsbuild Major
@scripts/update-rspress Major
@scripts/vitest-config Major
tests Major
@integration-test/alias-set Major
api-service-koa Major
app-docmuent Major
integration-asset-prefix Major
async-entry-test Major
tmp Major
bff-express Major
bff-koa Major
integration-builder-plugins Major
integration-clean-dist-path Major
integration-compatibility Major
integration-copy-assets Major
integration-custom-dist-path Major
integration-custom-render Major
integration-custom-template Major
dev-server Major
@integration-test/devtools Major
integration-disable-html Major
esbuild-transform-and-minify Major
esbuild-integration Major
integration-config-async-config-test Major
integration-basic-local-config Major
integration-config-function-params Major
integration-local-config-function Major
integration-load-config Major
main-entry-name Major
alias-js-test Major
alias-ts-test Major
asset-limit-test Major
asset-path-test Major
asset-publicPath-test Major
svgr-test Major
auto-extension-commonjs-test Major
auto-extension-type-module-test Major
auto-external-test Major
banner-footer-test Major
build-type-test Major
copy-test Major
decorator-test Major
global-vars-js-test Major
global-vars-ts-test Major
dts-test Major
esbuild-options-test Major
external-test Major
format-cjs-test Major
format-esm-test Major
format-iife-test Major
format-umd-test Major
entry-test Major
jsx-test Major
metafile-test Major
minify-test Major
platform-test Major
redirect-test Major
data-url-test Major
resolve-false Major
ndoe-protocol-test Major
lib1 Major
lib2 Major
lib3 Major
condition-exports-test Major
js-extensions-test Major
main-fields-test Major
shims-test Major
module-tools-side-effects-test Major
source-dir-test Major
sourcemap-test Major
splitting-test Major
css-test Major
less-test Major
style-test Major
postcss-test Major
sass-test Major
tailwindcss-test Major
target-test Major
transform-import Major
transform-lodash Major
tsconfig-test Major
umdGlobals-test Major
get-module-id-test Major
dev-test Major
build-platform-test Major
build-preset-error-test Major
build-preset-function-test Major
build-preset-test Major
build-preset-string-test Major
plugin-babel Major
plugin-node-polyfill Major
plugin-polyfill Major
nonce Major
routes Major
file-based-router Major
use-loader Major
runtime Major
select-mul-entry-test Major
select-one-entry-test Major
entry Major
server-config Major
server-middleware Major
server-hook-reqeust Major
server-hook-response Major
server-hook-router Major
@integration-test/server-hook-reqeust Major
server-prod Major
@source-code-build/app-ts-loader Major
@source-code-build/app Major
@source-code-build/common Major
@source-code-build/components Major
@source-code-build/utils Major
ssg-fixtures-nested-routes Major
ssg-fixtures-simple Major
ssg-fixtures-web-server Major
ssg Major
ssr-base-json-test Major
ssr-base-test Major
ssr-base-fallback-test Major
init Major
ssr-inline Major
ssr-preload Major
ssr-streaming-test Major
ssr Major
integration-tests-storybook Major
swc-test-decorator-legacy Major
swc-test-decorator Major
swc-minify-css Major
swc-minify-js Major
transform-fail Major
swc-integration Major
integration-tailwindcss-v2 Major
integration-tailwindcss-v3-js-config Major
integration-tailwindcss-v3-merge-config Major
integration-tailwindcss-v3-ts-config Major
integration-tailwindcss-v3 Major
twin-macro-v2 Major
twin-macro-v3 Major
tailwindcss-integration-test Major
tmp-dir Major
@e2e/testing-plugin Major
write-to-dist Major
@e2e/builder-cli-rspack Major
@e2e/builder-cli-vue Major
@e2e/builder-cli-webpack Major
@e2e/webpack-builder-import-antd-v4 Major
@e2e/webpack-builder-import-antd-v5 Major
@e2e/webpack-builder-import-arco Major
@e2e/webpack-builder-test-moment Major
@e2e/builder-remove-prop-types Major
@e2e/webpack-builder-source-map Major
@e2e/builder-vue3 Major
@e2e/builder-vue2 Major
@e2e/builder Major
@e2e/garfish-dashboard-router-v6 Major
@e2e/garfish-dashboard Major
@e2e/garfish-main-router-v6 Major
@e2e/garfish-main Major
@e2e/garfish-table Major
@e2e/garfish Major
@modern-js/generator-common Patch
@modern-js/generator-plugin Patch
@modern-js/generator-utils Patch
@modern-js/bff-generator Patch
@modern-js/dependence-generator Patch
@modern-js/entry-generator Patch
@modern-js/generator-generator Patch
@modern-js/module-generator Patch
@modern-js/module-test-generator Patch
@modern-js/monorepo-generator Patch
@modern-js/mwa-generator Patch
@modern-js/router-v5-generator Patch
@modern-js/rspack-generator Patch
@modern-js/ssg-generator Patch
@modern-js/storybook-generator Patch
@modern-js/test-generator Patch
@modern-js/upgrade-generator Patch
@modern-js/generator-plugin-plugin Patch
@modern-js/base-generator Patch
@modern-js/changeset-generator Patch
@modern-js/packages-generator Patch
@modern-js/repo-generator Patch
@modern-js/server-generator Patch
@modern-js/tailwindcss-generator Patch
@modern-js/generator-cases Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@10Derozan 10Derozan added the enhancement New feature or request label Oct 20, 2023
@10Derozan 10Derozan linked an issue Oct 20, 2023 that may be closed by this pull request
@10Derozan 10Derozan marked this pull request as draft October 20, 2023 10:08
@10Derozan 10Derozan marked this pull request as ready for review October 24, 2023 10:34
chenjiahan
chenjiahan previously approved these changes Oct 24, 2023
@chenjiahan chenjiahan merged commit 44fea2c into main Oct 25, 2023
7 checks passed
@chenjiahan chenjiahan deleted the feat/autoExtension branch October 25, 2023 09:48
This was referenced Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC]: 工具库/ UI 库支持 TypeScript 新增文件后缀
2 participants