Skip to content

fix: required amd in umd external object#8369

Merged
LingyuCoder merged 3 commits intomainfrom
fix/external-object-type
Nov 8, 2024
Merged

fix: required amd in umd external object#8369
LingyuCoder merged 3 commits intomainfrom
fix/external-object-type

Conversation

@LingyuCoder
Copy link
Copy Markdown
Contributor

@LingyuCoder LingyuCoder commented Nov 7, 2024

Summary

https://github.com/web-infra-dev/rspack/pull/8286/files#r1831012797

Cause lots of projects use object item of externals when not umd and it can actually work well. For example:

module.exports = {
  output: {
     library: {
       type: "commonjs"
     }
  },
  externalsType: "commonjs",
  externals: {
    // actually same as: `react: "REACT"` or `react: "commonjs REACT"`
    react: {
      commonjs: "REACT"
    }
  }
};

so if we just add a strict object validation to object item of externals, it will be a breaking change to these projects.

The object item of externals should be validate according to the values of output.library.type/output.libraryTarget and externalsType. Only if output.library.type/output.libraryTarget is set to umd and externalsType is not set or also set to umd, the object item in externals should be handle as an umd dependency.

We can add a new ZodType named ZodCrossFieldsOptions to validate the object item in externals. In its _parse method we can get the zod context, and then get its root context through its parent field. Then we can do some checking cross configuration options and make sure that the object item in externals should only be validated when it is really handle as an umd dependency.

But there is a trick in ZodUnion. The parent field is set to null here. Not sure if it is a bug or not. So we need to override the ZodUnion._parse to pass the parent context to children like other ZodType does.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@github-actions github-actions bot added the release: bug fix release: bug related release(mr only) label Nov 7, 2024
@netlify
Copy link
Copy Markdown

netlify bot commented Nov 7, 2024

Deploy Preview for rspack ready!

Name Link
🔨 Latest commit 04d9bb9
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/672dcda376e9e80008ff0ab7
😎 Deploy Preview https://deploy-preview-8369--rspack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: bug fix release: bug related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants