Giter VIP home page Giter VIP logo

father-plugin's People

Contributors

peachscript avatar zombiej avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

apades

father-plugin's Issues

Automatic ESM/CJS redirection

Not sure that it is the good place for this issue, but it's a global issue for all react-component modules and it's linked to the build.

If we agree that an ESM should always use ESM version of RC modules and that a CJS module should always use CJS version, then package.json of all RC modules should be improved with this patch:

-  "main": "./lib/index",
-  "module": "./es/index",
+  "exports": {
+    ".": {
+      "types": {
+        "import": "./es/index.d.ts",
+        "default": "./lib/index.d.ts"
+      },
+      "import": "./es/index.js",
+      "default": "./lib/index.js"
+    },
+    "./*": {
+      "types": {
+        "import": "./es/*",
+        "require": "./lib/*"
+      },
+      "import": "./es/*",
+      "require": "./lib/*"
+    }
+  },

It will fix an issue faced in some modules build to ESM and CJS (such as antd and all RC modules) since path of imports must be fixed (replacing /lib/ with /es/) during the build process (which is complex and not always done, an example here node_modules/antd/es/form/index.d.ts with import type { Rule, RuleObject, RuleRender } from 'rc-field-form/lib/interface';).
It would make babelPluginImportLib2Es of father-plugin useless since Node/TS/bundlers would automatically add the right es or lib prefix when importing/requiring a file of an other RC module from source or es or lib folder. Note that, for this to work, files in es folder should be considered as ESM (files should use .mjs extension or a package.json with "type": "module" should be added to es folder) which is not the case today (bug!). There is a pending PR to fix this bug in father: umijs/father#742

It should be possible to make this change in a backward-compatible manner with this alternative patch which will block access to es from a CJS module and lib from an ESM module:

-  "main": "./lib/index",
-  "module": "./es/index",
+  "exports": {
+    ".": {
+      "types": {
+        "import": "./es/index.d.ts",
+        "default": "./lib/index.d.ts"
+      },
+      "import": "./es/index.js",
+      "default": "./lib/index.js"
+    },
+    "./es/*": {
+      "types": {
+        "import": "./es/*"
+      },
+      "import": "./es/*"
+    },
+    "./lib/*": {
+      "types": {
+        "require": "./lib/*"
+      },
+      "require": "./lib/*"
+    },
+    "./*": {
+      "types": {
+        "import": "./es/*",
+        "require": "./lib/*"
+      },
+      "import": "./es/*",
+      "require": "./lib/*"
+    },
+  },

Or if we want to be 100% backward-compatible (what I don't recommend because it allows a misuse of RC module) we can keep access to wrong paths with:

-  "main": "./lib/index",
-  "module": "./es/index",
+  "exports": {
+    ".": {
+      "types": {
+        "import": "./es/index.d.ts",
+        "default": "./lib/index.d.ts"
+      },
+      "import": "./es/index.js",
+      "default": "./lib/index.js"
+    },
+    "./es/*": {
+      "types": {
+        "import": "./es/*",
+        "require": "./es/*"
+      },
+      "import": "./es/*",
+      "require": "./es/*"
+    },
+    "./lib/*": {
+      "types": {
+        "import": "./lib/*",
+        "require": "./lib/*"
+      },
+      "import": "./lib/*",
+      "require": "./lib/*"
+    },
+    "./*": {
+      "types": {
+        "import": "./es/*",
+        "require": "./lib/*"
+      },
+      "import": "./es/*",
+      "require": "./lib/*"
+    },
+  },

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.