Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@mendix/eslint-config-web-widgets": "workspace:*",
"@mendix/pluggable-widgets-tools": "*",
"@mendix/prettier-config-web-widgets": "workspace:*",
"@mendix/rollup-web-widgets": "workspace:*",
"@mendix/run-e2e": "workspace:*",
"@mendix/widget-plugin-component-kit": "workspace:*",
"@mendix/widget-plugin-hooks": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { withSharedLibs } from "@mendix/rollup-web-widgets/sharedLibs.mjs";

export default args => withSharedLibs(args, args.configDefaultConfig);
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@mendix/eslint-config-web-widgets": "workspace:*",
"@mendix/pluggable-widgets-tools": "*",
"@mendix/prettier-config-web-widgets": "workspace:*",
"@mendix/rollup-web-widgets": "workspace:*",
"@mendix/run-e2e": "workspace:*",
"@mendix/widget-plugin-component-kit": "workspace:*",
"@mendix/widget-plugin-hooks": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { withSharedLibs } from "@mendix/rollup-web-widgets/sharedLibs.mjs";

export default args => withSharedLibs(args, args.configDefaultConfig);
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@mendix/eslint-config-web-widgets": "workspace:*",
"@mendix/pluggable-widgets-tools": "*",
"@mendix/prettier-config-web-widgets": "workspace:*",
"@mendix/rollup-web-widgets": "workspace:*",
"@mendix/run-e2e": "workspace:*",
"@mendix/widget-plugin-component-kit": "workspace:*",
"@mendix/widget-plugin-hooks": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { withSharedLibs } from "@mendix/rollup-web-widgets/sharedLibs.mjs";

export default args => withSharedLibs(args, args.configDefaultConfig);
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@mendix/eslint-config-web-widgets": "workspace:*",
"@mendix/pluggable-widgets-tools": "*",
"@mendix/prettier-config-web-widgets": "workspace:*",
"@mendix/rollup-web-widgets": "workspace:*",
"@mendix/run-e2e": "workspace:*",
"@mendix/widget-plugin-test-utils": "workspace:*"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { withSharedLibs } from "@mendix/rollup-web-widgets/sharedLibs.mjs";

export default args => withSharedLibs(args, args.configDefaultConfig);
1 change: 1 addition & 0 deletions packages/pluggableWidgets/datagrid-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@mendix/eslint-config-web-widgets": "workspace:*",
"@mendix/pluggable-widgets-tools": "*",
"@mendix/prettier-config-web-widgets": "workspace:*",
"@mendix/rollup-web-widgets": "workspace:*",
"@mendix/run-e2e": "workspace:*",
"@mendix/widget-plugin-test-utils": "workspace:*"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module.exports = args => {
import { withSharedLibs } from "@mendix/rollup-web-widgets/sharedLibs.mjs";

export default args => {
const [widgetAMD, widgetESM, editorPreview, editorConfig] = args.configDefaultConfig;

// By default "react/jsx-runtime" is marked as external.
// We remove it from external array to make it a normal dependency for editorPreview file.
editorPreview.external = [/^mendix($|\/)/, /^react$/, /^react-dom$/];

return [widgetAMD, widgetESM, editorPreview, editorConfig];
return withSharedLibs(args, [widgetAMD, widgetESM, editorPreview, editorConfig]);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import copyFiles from "@mendix/rollup-web-widgets/copyFiles.mjs";
import { withSharedLibs } from "@mendix/rollup-web-widgets/sharedLibs.mjs";

export default args => {
return copyFiles(args);
return withSharedLibs(args, copyFiles(args));
};
1 change: 1 addition & 0 deletions packages/pluggableWidgets/dropdown-sort-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@mendix/eslint-config-web-widgets": "workspace:*",
"@mendix/pluggable-widgets-tools": "*",
"@mendix/prettier-config-web-widgets": "workspace:*",
"@mendix/rollup-web-widgets": "workspace:*",
"@mendix/run-e2e": "workspace:*",
"@mendix/widget-plugin-test-utils": "workspace:*"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { withSharedLibs } from "@mendix/rollup-web-widgets/sharedLibs.mjs";

export default args => withSharedLibs(args, args.configDefaultConfig);
1 change: 1 addition & 0 deletions packages/pluggableWidgets/file-uploader-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@mendix/eslint-config-web-widgets": "workspace:*",
"@mendix/pluggable-widgets-tools": "*",
"@mendix/prettier-config-web-widgets": "workspace:*",
"@mendix/rollup-web-widgets": "workspace:*",
"@mendix/widget-plugin-platform": "workspace:*",
"@mendix/widget-plugin-test-utils": "workspace:*",
"@rollup/plugin-json": "^6.1.0",
Expand Down
12 changes: 8 additions & 4 deletions packages/pluggableWidgets/file-uploader-web/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import json from "@rollup/plugin-json";
import { withSharedLibs } from "@mendix/rollup-web-widgets/sharedLibs.mjs";

export default args => {
const result = args.configDefaultConfig;
return result.map((config, _index) => {
config.plugins = [...config.plugins, json()];
return config;
});
return withSharedLibs(
args,
result.map((config, _index) => {
config.plugins = [...config.plugins, json()];
return config;
})
);
};
1 change: 1 addition & 0 deletions packages/pluggableWidgets/gallery-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@mendix/eslint-config-web-widgets": "workspace:*",
"@mendix/pluggable-widgets-tools": "*",
"@mendix/prettier-config-web-widgets": "workspace:*",
"@mendix/rollup-web-widgets": "workspace:*",
"@mendix/run-e2e": "workspace:*",
"@mendix/widget-plugin-grid": "workspace:*",
"@mendix/widget-plugin-platform": "workspace:*",
Expand Down
3 changes: 3 additions & 0 deletions packages/pluggableWidgets/gallery-web/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { withSharedLibs } from "@mendix/rollup-web-widgets/sharedLibs.mjs";

export default args => withSharedLibs(args, args.configDefaultConfig);
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import copyFiles from "@mendix/rollup-web-widgets/copyFiles.mjs";
import { withSharedLibs } from "@mendix/rollup-web-widgets/sharedLibs.mjs";

export default args => {
return copyFiles(args);
return withSharedLibs(args, copyFiles(args));
};
3 changes: 2 additions & 1 deletion packages/pluggableWidgets/maps-web/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { cpSync, existsSync, mkdirSync, rmSync, statSync } from "node:fs";
import { fileURLToPath } from "url";
import copyFiles from "@mendix/rollup-web-widgets/copyFiles.mjs";
import { withSharedLibs } from "@mendix/rollup-web-widgets/sharedLibs.mjs";
import url from "@mendix/pluggable-widgets-tools/configs/rollup-plugin-assets.mjs";

// The maps widget package was wrongly named with an uppercase M in the past. We have to keep that
Expand Down Expand Up @@ -94,5 +95,5 @@ export default args => {
// Only the amd bundle extracts a stylesheet.
fixCssAssetPaths(jsConfig);

return result;
return withSharedLibs(args, result);
};
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@mendix/eslint-config-web-widgets": "workspace:*",
"@mendix/pluggable-widgets-tools": "*",
"@mendix/prettier-config-web-widgets": "workspace:*",
"@mendix/rollup-web-widgets": "workspace:*",
"@mendix/widget-plugin-component-kit": "workspace:*",
"@mendix/widget-plugin-grid": "workspace:*",
"@mendix/widget-plugin-platform": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { withSharedLibs } from "@mendix/rollup-web-widgets/sharedLibs.mjs";

export default args => withSharedLibs(args, args.configDefaultConfig);
113 changes: 113 additions & 0 deletions packages/shared/rollup-web-widgets/__tests__/sharedLibs.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import assert from "node:assert/strict";
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { after, describe, it } from "node:test";
import { withSharedLibs } from "../sharedLibs.mjs";

const OUT = join("dist", "tmp", "widgets");
const MOBX_ESM = "shared/mobx/6.12.3/esm/mobx.mjs";
const MOBX_AMD = "shared/mobx/6.12.3/amd/mobx.js";

function widgetConfigs(dir = "com/mendix/widget/web/datagrid") {
return [
{ input: "src/W.tsx", output: { format: "amd", file: join(OUT, dir, "W.js") }, plugins: [] },
{ input: "src/W.tsx", output: { format: "es", file: join(OUT, dir, "W.mjs") }, plugins: [] },
{ input: "src/W.editorPreview.tsx", output: { format: "commonjs", file: join(OUT, "W.editorPreview.js") } },
{ input: "src/W.editorConfig.ts", output: { format: "commonjs", file: join(OUT, "W.editorConfig.js") } }
];
}

const consumerOf = config => config.plugins.find(p => p.name === "mendix-shared-libs");
const pathsFor = config => consumerOf(config).outputOptions(config.output).paths;

describe("withSharedLibs", () => {
it("prepends shared bundles and only changes the runtime entries", () => {
const configs = withSharedLibs({}, widgetConfigs());

assert.equal(configs.length, 6);
assert.match(configs[0].output[0].file, /shared\/mobx\/6\.12\.3\/esm\/mobx\.mjs$/);
assert.match(configs[1].output[0].file, /shared\/mobx-react-lite\/4\.0\.7\/esm\/mobx-react-lite\.mjs$/);
assert.ok(consumerOf(configs[2]) && consumerOf(configs[3]));
assert.equal(configs[4].plugins, undefined);
assert.equal(configs[5].plugins, undefined);
});

it("points widget imports at the shared bundles", () => {
const [, , amd, esm] = withSharedLibs({}, widgetConfigs());

assert.equal(pathsFor(esm).mobx, `../../../${MOBX_ESM}`);
assert.equal(pathsFor(amd).mobx, `../../../${MOBX_AMD}`);
});

it("computes paths from the final output file (maps-web moves it)", () => {
const [, , amd, esm] = withSharedLibs({}, widgetConfigs());
const moved = join(process.cwd(), OUT, "com/mendix/widget/custom/Maps");
esm.output.file = join(moved, "Maps.mjs");
amd.output.file = join(moved, "Maps.js");

assert.equal(pathsFor(esm).mobx, `../../../${MOBX_ESM}`);
assert.equal(pathsFor(amd)["mobx-react-lite"], "../../../shared/mobx-react-lite/4.0.7/amd/mobx-react-lite.js");
});

it("points mobx-react-lite at the shared mobx", () => {
const [, mrl] = withSharedLibs({}, widgetConfigs());

assert.ok(mrl.external.includes("mobx"));
assert.equal(mrl.output[0].paths.mobx, "../../../mobx/6.12.3/esm/mobx.mjs");
assert.equal(mrl.output[1].paths.mobx, "../../../mobx/6.12.3/amd/mobx.js");
});

it("keeps the widget's own externals", () => {
const configs = widgetConfigs();
configs[1].external = [/^react$/];
const esm = withSharedLibs({}, configs)[3];
const { external } = consumerOf(esm).options(esm);

assert.equal(external("mobx", "/src/W.tsx", false), true);
assert.equal(external("react", "/src/W.tsx", false), true);
assert.equal(external("classnames", "/src/W.tsx", false), false);
});

it("rejects unknown libraries and missing shared dependencies", () => {
assert.throws(() => withSharedLibs({}, widgetConfigs(), ["lodash"]), /unknown library "lodash"/);
assert.throws(() => withSharedLibs({}, widgetConfigs(), ["mobx-react-lite"]), /requires "mobx"/);
assert.throws(() => withSharedLibs({}, widgetConfigs().slice(2)), /no widget AMD\/ESM entries/);
});

describe("version check", () => {
const root = mkdtempSync(join(tmpdir(), "shared-libs-"));
after(() => rmSync(root, { recursive: true, force: true }));

function importerWithMobx(version) {
const dir = join(root, version);
mkdirSync(join(dir, "node_modules", "mobx"), { recursive: true });
mkdirSync(join(dir, "src"), { recursive: true });
writeFileSync(
join(dir, "node_modules", "mobx", "package.json"),
JSON.stringify({ name: "mobx", version, main: "index.js" })
);
writeFileSync(join(dir, "node_modules", "mobx", "index.js"), "");
return join(dir, "src", "W.tsx");
}

function build(importer) {
const esm = withSharedLibs({}, widgetConfigs())[3];
const plugin = consumerOf(esm);
plugin.options(esm).external("mobx", importer, false);
plugin.buildEnd.call({
error: message => {
throw new Error(message);
}
});
}

it("fails when a widget resolves another mobx version", () => {
assert.throws(() => build(importerWithMobx("6.13.0")), /resolves to 6\.13\.0 .* shared bundle is 6\.12\.3/);
});

it("passes when the versions match", () => {
assert.doesNotThrow(() => build(importerWithMobx("6.12.3")));
});
});
});
12 changes: 12 additions & 0 deletions packages/shared/rollup-web-widgets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
"type": "git",
"url": "https://github.com/mendix/web-widgets.git"
},
"scripts": {
"test": "node --test \"__tests__/*.spec.mjs\""
},
"dependencies": {
"@rollup/plugin-commonjs": "^29.0.3",
"@rollup/plugin-node-resolve": "^15.3.1",
"@rollup/plugin-replace": "^6.0.2",
"@rollup/plugin-terser": "^0.4.4",
"mobx": "6.12.3",
"mobx-react-lite": "4.0.7",
"rollup-plugin-license": "^3.6.0"
},
"devDependencies": {
"@mendix/pluggable-widgets-tools": "*",
"rollup-plugin-copy": "^3.5.0"
Expand Down
Loading
Loading