Skip to content

Commit

Permalink
fix(gen-rollup-conf): bypass index files in bundled JS (#160)
Browse files Browse the repository at this point in the history
This skips index files traversal in bundled files and requires the final
file directly.
  • Loading branch information
Thomaash authored May 17, 2020
1 parent edfdd17 commit 5bab3f8
Showing 1 changed file with 40 additions and 19 deletions.
59 changes: 40 additions & 19 deletions src/module/generate-rollup-configuration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,41 @@ const validate: (
/**
* Transform ESNext import paths to match the build version being constructed.
*
* @param variant - ESNext or peer build. This is not available for standalone
* as only peer and ESNext have imports.
* @param buildVariant - ESNext or peer build. This is not available for
* standalone as only peer and ESNext have imports.
* @param moduleFormat - What kind of module system to use.
*
* @returns Path overrides for Rollup.
*/
const getPaths = (variant: "esnext" | "peer"): Record<string, string> => ({
"vis-charts/esnext": `vis-charts/${variant}`,
"vis-data/esnext": `vis-data/${variant}`,
"vis-graph3d/esnext": `vis-graph3d/${variant}`,
"vis-network/esnext": `vis-network/${variant}`,
"vis-timeline/esnext": `vis-timeline/${variant}`,
"vis-util/esnext": `vis-util/${variant}`,
"vis-uuid/esnext": `vis-uuid/${variant}`
});
function getPaths(
buildVariant: "esnext" | "peer",
moduleFormat: "esm" | "umd"
): Record<string, string> {
function getPath(
lib:
| "charts"
| "data"
| "graph3d"
| "network"
| "timeline"
| "util"
| "uuid"
): Record<string, string> {
return {
[`vis-${lib}/esnext`]: `vis-${lib}/${buildVariant}/${moduleFormat}/vis-${lib}.js`
};
}

return {
...getPath("charts"),
...getPath("data"),
...getPath("graph3d"),
...getPath("network"),
...getPath("timeline"),
...getPath("util"),
...getPath("uuid")
};
}

const injectCSS = true;
const minimize = true;
Expand Down Expand Up @@ -601,12 +622,12 @@ export function generateRollupConfiguration(
{
...commonOutputESM,
entryFileNames: `peer/esm/${libraryFilename}.js`,
paths: getPaths("peer")
paths: getPaths("peer", "esm")
},
{
...commonOutputUMD,
entryFileNames: `peer/umd/${libraryFilename}.js`,
paths: getPaths("peer")
paths: getPaths("peer", "umd")
}
],
plugins: getPlugins("peer", {
Expand All @@ -621,12 +642,12 @@ export function generateRollupConfiguration(
{
...commonOutputESM,
entryFileNames: `peer/esm/${libraryFilename}.min.js`,
paths: getPaths("peer")
paths: getPaths("peer", "esm")
},
{
...commonOutputUMD,
entryFileNames: `peer/umd/${libraryFilename}.min.js`,
paths: getPaths("peer")
paths: getPaths("peer", "umd")
}
],
plugins: getPlugins("peer", {
Expand All @@ -643,12 +664,12 @@ export function generateRollupConfiguration(
{
...commonOutputESM,
entryFileNames: `esnext/esm/${libraryFilename}.js`,
paths: getPaths("esnext")
paths: getPaths("esnext", "esm")
},
{
...commonOutputUMD,
entryFileNames: `esnext/umd/${libraryFilename}.js`,
paths: getPaths("esnext")
paths: getPaths("esnext", "umd")
}
],
plugins: getPlugins("esnext", {
Expand All @@ -662,12 +683,12 @@ export function generateRollupConfiguration(
{
...commonOutputESM,
entryFileNames: `esnext/esm/${libraryFilename}.min.js`,
paths: getPaths("esnext")
paths: getPaths("esnext", "esm")
},
{
...commonOutputUMD,
entryFileNames: `esnext/umd/${libraryFilename}.min.js`,
paths: getPaths("esnext")
paths: getPaths("esnext", "umd")
}
],
plugins: getPlugins("esnext", {
Expand Down

0 comments on commit 5bab3f8

Please sign in to comment.