-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[charts] Use vendor to have CJS working out of the box (#13608)
Signed-off-by: Alexandre Fauquette <[email protected]> Co-authored-by: Lukas Tyla <[email protected]>
- Loading branch information
1 parent
af9b360
commit 743779f
Showing
344 changed files
with
21,199 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
name: Vale action | ||
|
||
on: [pull_request] | ||
on: | ||
pull_request: | ||
paths: | ||
- 'docs/data/**.md' | ||
|
||
permissions: {} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
coverage: | ||
ignore: | ||
- 'packages/x-charts-vendor' | ||
- '**/*.test.tsx' | ||
status: | ||
project: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Transform d3 ESM libraries to vendored CommonJS libraries | ||
* | ||
* This produces `lib-vendor/d3-<package name>/src` files that have | ||
* internally consistent references to other d3 packages. It is only meant | ||
* to be used for the CommonJS import path. | ||
*/ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
only: [/node_modules\/(d3-.*|internmap|delaunator|robust-predicates)\/.*\.js/], | ||
plugins: [ | ||
[ | ||
'@babel/transform-modules-commonjs', | ||
{ | ||
strict: false, | ||
allowTopLevelThis: true, | ||
}, | ||
], | ||
[ | ||
'module-resolver', | ||
{ | ||
// Convert all imports for _other_ d3 dependencies to the relative | ||
// path in our vendor package. | ||
resolvePath(sourcePath, currentFile) { | ||
const d3pattern = | ||
/^(?<pkg>(d3-[^\/]+|internmap|delaunator|robust-predicates))(?<path>.*)/; | ||
const match = d3pattern.exec(sourcePath); | ||
if (match) { | ||
// We're assuming a common shape of d3 packages: | ||
// - Only top level imports "d3-<whatever>" | ||
// - With no path components (like "d3-<whatever>/path/to.js") | ||
if (match.groups.path) { | ||
throw new Error(`Unable to process ${sourcePath} import in ${currentFile}`); | ||
} | ||
|
||
// Get Vendor package path. | ||
const vendorPkg = ['delaunator', 'robust-predicates'].includes(match.groups.pkg) | ||
? path.resolve(__dirname, `./lib-vendor/${match.groups.pkg}/index.js`) | ||
: path.resolve(__dirname, `./lib-vendor/${match.groups.pkg}/src/index.js`); | ||
|
||
// Derive relative path to vendor lib to have a file like move from: | ||
// - 'node_modules/d3-interpolate/src/rgb.js' | ||
// - 'lib-vendor/d3-interpolate/src/rgb.js' | ||
// and have an import transform like: | ||
// - `d3-color` | ||
// - `../../d3-color` | ||
const currentFileVendor = currentFile.replace(/^node_modules/, 'lib-vendor'); | ||
const relPathToPkg = path | ||
.relative(path.dirname(currentFileVendor), vendorPkg) | ||
.replace(/\\/g, '/'); | ||
|
||
return relPathToPkg; | ||
} | ||
|
||
return sourcePath; | ||
}, | ||
}, | ||
], | ||
'@babel/plugin-transform-runtime', | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
!/dist | ||
!/es | ||
!/lib | ||
!/lib-vendor | ||
!/src | ||
!/d3-* | ||
!/internmap.js | ||
!LICENSE.txt | ||
!CHANGELOG.md | ||
!README.md | ||
!package.json | ||
*.map | ||
**/*.test.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Charts Vendor | ||
|
||
Vendored dependencies for @mui/x-charts. | ||
|
||
An adaptation of the victory-vendor | ||
|
||
## Background | ||
|
||
D3 has released most of its libraries as ESM-only. This means that consumers in Node.js applications can no longer just `require()` anything with a d3 transitive dependency, including much of @mui/x-charts. | ||
|
||
To help provide an easy path to folks still using CommonJS in their Node.js applications that consume @mui/x-charts, we now provide this package to vendor in various d3-related packages. | ||
|
||
## Main difference with victory-vendor | ||
|
||
Victory is using the `d3-voronoid` which is an archived project. | ||
Our chart library relies on the `d3-delaunay` which is also ESM only and reuse `robust-predicates` which is also ESM only | ||
|
||
## Packages | ||
|
||
We presently provide the following top-level libraries: | ||
|
||
- d3-color | ||
- d3-delaunay | ||
- d3-interpolate | ||
- d3-scale | ||
- d3-shape | ||
- d3-time | ||
- delaunator | ||
- robust-predicate | ||
|
||
This is the total list of top and transitive libraries we vendor: | ||
|
||
- d3-array | ||
- d3-color | ||
- d3-delaunay | ||
- d3-format | ||
- d3-interpolate | ||
- d3-path | ||
- d3-scale | ||
- d3-shape | ||
- d3-time | ||
- d3-time-format | ||
- delaunator | ||
- internmap | ||
- robust-predicates | ||
|
||
## How it works | ||
|
||
We provide two alternate paths and behaviors -- for ESM and CommonJS | ||
|
||
### ESM | ||
|
||
If you do a Node.js import like: | ||
|
||
```js | ||
import { interpolate } from '@mui/x-charts-vendor/d3-interpolate'; | ||
``` | ||
|
||
under the hood it's going to just re-export and pass you through to `node_modules/d3-interpolate`, the **real** ESM library from D3. | ||
|
||
### CommonJS | ||
|
||
If you do a Node.js import like: | ||
|
||
```js | ||
const { interpolate } = require('@mui/x-charts-vendor/d3-interpolate'); | ||
``` | ||
|
||
under the hood, it will go to an alternate path that contains the transpiled version of the underlying d3 library found at `x-charts-vendor/lib-vendor/d3-interpolate/**/*.js`. | ||
This further has internally consistent import references to other `x-charts-vendor/lib-vendor/<pkg-name>` paths. | ||
|
||
Note that for some tooling (like Jest) that doesn't play well with `package.json:exports` routing to this CommonJS path, we **also** output a root file in the form of `x-charts-vendor/d3-interpolate.js`. | ||
|
||
## Licenses | ||
|
||
This project is released under the MIT license, but the vendored in libraries include other licenses (e.g. ISC) that we enumerate in our `package.json:license` field. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
// `x-charts-vendor/d3-color` (TypeScript) | ||
// | ||
// Export the type definitions for this package: | ||
export * from "d3-color"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
// `x-charts-vendor/d3-color` (CommonJS) | ||
// See upstream license: https://github.com/d3/d3-color/blob/main/LICENSE | ||
// | ||
// This file only exists for tooling that doesn't work yet with package.json:exports | ||
// by proxying through the CommonJS version. | ||
module.exports = require("./lib/d3-color"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
// `x-charts-vendor/d3-delaunay` (TypeScript) | ||
// | ||
// Export the type definitions for this package: | ||
export * from "d3-delaunay"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
// `x-charts-vendor/d3-delaunay` (CommonJS) | ||
// See upstream license: https://github.com/d3/d3-delaunay/blob/main/LICENSE | ||
// | ||
// This file only exists for tooling that doesn't work yet with package.json:exports | ||
// by proxying through the CommonJS version. | ||
module.exports = require("./lib/d3-delaunay"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
// `x-charts-vendor/d3-interpolate` (TypeScript) | ||
// | ||
// Export the type definitions for this package: | ||
export * from "d3-interpolate"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
// `x-charts-vendor/d3-interpolate` (CommonJS) | ||
// See upstream license: https://github.com/d3/d3-interpolate/blob/main/LICENSE | ||
// | ||
// This file only exists for tooling that doesn't work yet with package.json:exports | ||
// by proxying through the CommonJS version. | ||
module.exports = require("./lib/d3-interpolate"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
// `x-charts-vendor/d3-scale` (TypeScript) | ||
// | ||
// Export the type definitions for this package: | ||
export * from "d3-scale"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
// `x-charts-vendor/d3-scale` (CommonJS) | ||
// See upstream license: https://github.com/d3/d3-scale/blob/main/LICENSE | ||
// | ||
// This file only exists for tooling that doesn't work yet with package.json:exports | ||
// by proxying through the CommonJS version. | ||
module.exports = require("./lib/d3-scale"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
// `x-charts-vendor/d3-shape` (TypeScript) | ||
// | ||
// Export the type definitions for this package: | ||
export * from "d3-shape"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
// `x-charts-vendor/d3-shape` (CommonJS) | ||
// See upstream license: https://github.com/d3/d3-shape/blob/main/LICENSE | ||
// | ||
// This file only exists for tooling that doesn't work yet with package.json:exports | ||
// by proxying through the CommonJS version. | ||
module.exports = require("./lib/d3-shape"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
// `x-charts-vendor/d3-time` (TypeScript) | ||
// | ||
// Export the type definitions for this package: | ||
export * from "d3-time"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
// `x-charts-vendor/d3-time` (CommonJS) | ||
// See upstream license: https://github.com/d3/d3-time/blob/main/LICENSE | ||
// | ||
// This file only exists for tooling that doesn't work yet with package.json:exports | ||
// by proxying through the CommonJS version. | ||
module.exports = require("./lib/d3-time"); |
Oops, something went wrong.