@medusajs/admin-bundler 2.6.2-snapshot-20250311083444 → 2.6.2-snapshot-20250311115840

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import * as express_serve_static_core from 'express-serve-static-core';
4
4
  type BundlerOptions = Required<Pick<AdminOptions, "path">> & Pick<AdminOptions, "vite" | "backendUrl" | "storefrontUrl"> & {
5
5
  outDir: string;
6
6
  sources?: string[];
7
+ plugins?: string[];
7
8
  };
8
9
 
9
10
  declare function build(options: BundlerOptions): Promise<void>;
package/dist/index.js CHANGED
@@ -1108,16 +1108,179 @@ __export(src_exports, {
1108
1108
  });
1109
1109
  module.exports = __toCommonJS(src_exports);
1110
1110
 
1111
- // src/lib/config.ts
1111
+ // src/utils/config.ts
1112
1112
  var import_admin_shared = require("@medusajs/admin-shared");
1113
1113
  var import_path = __toESM(require("path"));
1114
+
1115
+ // src/plugins/inject-tailwindcss.ts
1116
+ var import_node_path = __toESM(require("path"));
1117
+ var injectTailwindCSS = (options) => {
1118
+ return {
1119
+ name: "medusa:inject-tailwindcss",
1120
+ config: () => ({
1121
+ css: {
1122
+ postcss: {
1123
+ plugins: [
1124
+ require("tailwindcss")({
1125
+ config: createTailwindConfig(
1126
+ options.entry,
1127
+ options.sources,
1128
+ options.plugins
1129
+ )
1130
+ })
1131
+ ]
1132
+ }
1133
+ }
1134
+ })
1135
+ };
1136
+ };
1137
+ function createTailwindConfig(entry, sources = [], plugins = []) {
1138
+ const root = import_node_path.default.join(entry, "**/*.{js,ts,jsx,tsx}");
1139
+ const html = import_node_path.default.join(entry, "index.html");
1140
+ let dashboard = "";
1141
+ try {
1142
+ dashboard = import_node_path.default.join(
1143
+ import_node_path.default.dirname(require.resolve("@medusajs/dashboard")),
1144
+ "**/*.{js,ts,jsx,tsx}"
1145
+ );
1146
+ } catch (_e) {
1147
+ }
1148
+ let ui = "";
1149
+ try {
1150
+ ui = import_node_path.default.join(
1151
+ import_node_path.default.dirname(require.resolve("@medusajs/ui")),
1152
+ "**/*.{js,ts,jsx,tsx}"
1153
+ );
1154
+ } catch (_e) {
1155
+ }
1156
+ const sourceExtensions = sources.map(
1157
+ (s) => import_node_path.default.join(s, "**/*.{js,ts,jsx,tsx}")
1158
+ );
1159
+ const pluginExtensions = [];
1160
+ for (const plugin2 of plugins) {
1161
+ try {
1162
+ const pluginPath = import_node_path.default.join(
1163
+ import_node_path.default.dirname(require.resolve(plugin2)),
1164
+ "**/*.{js,ts,jsx,tsx}"
1165
+ );
1166
+ pluginExtensions.push(pluginPath);
1167
+ } catch (_e) {
1168
+ }
1169
+ }
1170
+ const config = {
1171
+ presets: [require_dist()],
1172
+ content: [
1173
+ html,
1174
+ root,
1175
+ dashboard,
1176
+ ui,
1177
+ ...sourceExtensions,
1178
+ ...pluginExtensions
1179
+ ],
1180
+ darkMode: "class"
1181
+ };
1182
+ return config;
1183
+ }
1184
+
1185
+ // src/utils/write-static-files.ts
1186
+ var import_promises = require("fs/promises");
1187
+ var import_node_path2 = require("path");
1188
+ var import_outdent = __toESM(require("outdent"));
1189
+ async function writeStaticFiles(plugins) {
1190
+ const outDir = (0, import_node_path2.join)(process.cwd(), ".medusa/client");
1191
+ await (0, import_promises.mkdir)(outDir, { recursive: true });
1192
+ const promises = [
1193
+ writeCSSFile(outDir),
1194
+ writeEntryFile(outDir, plugins),
1195
+ writeHTMLFile(outDir)
1196
+ ];
1197
+ await Promise.all(promises);
1198
+ }
1199
+ async function writeCSSFile(outDir) {
1200
+ const css = import_outdent.default`
1201
+ @import "@medusajs/dashboard/css";
1202
+
1203
+ @tailwind base;
1204
+ @tailwind components;
1205
+ @tailwind utilities;
1206
+ `;
1207
+ await (0, import_promises.writeFile)((0, import_node_path2.join)(outDir, "index.css"), css);
1208
+ }
1209
+ function getPluginName(index) {
1210
+ return `plugin${index}`;
1211
+ }
1212
+ async function writeEntryFile(outDir, plugins) {
1213
+ const entry = import_outdent.default`
1214
+ import App from "@medusajs/dashboard";
1215
+ import React from "react";
1216
+ import ReactDOM from "react-dom/client";
1217
+ import "./index.css";
1218
+
1219
+ ${plugins?.map((plugin2, idx) => `import ${getPluginName(idx)} from "${plugin2}"`).join("\n")}
1220
+
1221
+ let root = null
1222
+
1223
+ if (!root) {
1224
+ root = ReactDOM.createRoot(document.getElementById("medusa"))
1225
+ }
1226
+
1227
+
1228
+ root.render(
1229
+ <React.StrictMode>
1230
+ <App plugins={[${plugins?.map((_, idx) => getPluginName(idx)).join(", ")}]} />
1231
+ </React.StrictMode>
1232
+ )
1233
+
1234
+
1235
+ if (import.meta.hot) {
1236
+ import.meta.hot.accept()
1237
+ }
1238
+ `;
1239
+ await (0, import_promises.writeFile)((0, import_node_path2.join)(outDir, "entry.jsx"), entry);
1240
+ }
1241
+ async function writeHTMLFile(outDir) {
1242
+ const html = import_outdent.default`
1243
+ <!DOCTYPE html>
1244
+ <html>
1245
+ <head>
1246
+ <meta
1247
+ http-equiv="Content-Type"
1248
+ content="text/html; charset=UTF-8"
1249
+ />
1250
+ <meta
1251
+ name="viewport"
1252
+ content="width=device-width, initial-scale=1, user-scalable=no"
1253
+ />
1254
+ <link rel="icon" href="data:," data-placeholder-favicon />
1255
+ </head>
1256
+
1257
+ <body>
1258
+ <div id="medusa"></div>
1259
+ <script type="module" src="./entry.jsx"></script>
1260
+ </body>
1261
+ </html>
1262
+ `;
1263
+ await (0, import_promises.writeFile)((0, import_node_path2.join)(outDir, "index.html"), html);
1264
+ }
1265
+
1266
+ // src/plugins/write-static-files.ts
1267
+ var writeStaticFiles2 = (options) => {
1268
+ return {
1269
+ name: "medusa:write-static-files",
1270
+ buildStart: async (ctx) => {
1271
+ await writeStaticFiles(options.plugins);
1272
+ }
1273
+ };
1274
+ };
1275
+
1276
+ // src/utils/config.ts
1114
1277
  async function getViteConfig(options) {
1115
1278
  const { searchForWorkspaceRoot, mergeConfig } = await import("vite");
1116
1279
  const { default: react } = await import("@vitejs/plugin-react");
1117
1280
  const { default: medusa } = await import("@medusajs/admin-vite-plugin");
1118
1281
  const getPort = await import("get-port");
1119
1282
  const hmrPort = await getPort.default();
1120
- const root = import_path.default.resolve(__dirname, "./");
1283
+ const root = import_path.default.resolve(process.cwd(), ".medusa/client");
1121
1284
  const backendUrl = options.backendUrl ?? "";
1122
1285
  const storefrontUrl = options.storefrontUrl ?? "";
1123
1286
  const baseConfig = {
@@ -1153,16 +1316,15 @@ async function getViteConfig(options) {
1153
1316
  port: hmrPort
1154
1317
  }
1155
1318
  },
1156
- css: {
1157
- postcss: {
1158
- plugins: [
1159
- require("tailwindcss")({
1160
- config: createTailwindConfig(root, options.sources)
1161
- })
1162
- ]
1163
- }
1164
- },
1165
1319
  plugins: [
1320
+ writeStaticFiles2({
1321
+ plugins: options.plugins
1322
+ }),
1323
+ injectTailwindCSS({
1324
+ entry: root,
1325
+ sources: options.sources,
1326
+ plugins: options.plugins
1327
+ }),
1166
1328
  react(),
1167
1329
  medusa({
1168
1330
  sources: options.sources
@@ -1175,35 +1337,8 @@ async function getViteConfig(options) {
1175
1337
  }
1176
1338
  return baseConfig;
1177
1339
  }
1178
- function createTailwindConfig(entry, sources = []) {
1179
- const root = import_path.default.join(entry, "**/*.{js,ts,jsx,tsx}");
1180
- const html = import_path.default.join(entry, "index.html");
1181
- let dashboard = "";
1182
- try {
1183
- dashboard = import_path.default.join(
1184
- import_path.default.dirname(require.resolve("@medusajs/dashboard")),
1185
- "**/*.{js,ts,jsx,tsx}"
1186
- );
1187
- } catch (_e) {
1188
- }
1189
- let ui = "";
1190
- try {
1191
- ui = import_path.default.join(
1192
- import_path.default.dirname(require.resolve("@medusajs/ui")),
1193
- "**/*.{js,ts,jsx,tsx}"
1194
- );
1195
- } catch (_e) {
1196
- }
1197
- const extensions = sources.map((s) => import_path.default.join(s, "**/*.{js,ts,jsx,tsx}"));
1198
- const config = {
1199
- presets: [require_dist()],
1200
- content: [html, root, dashboard, ui, ...extensions],
1201
- darkMode: "class"
1202
- };
1203
- return config;
1204
- }
1205
1340
 
1206
- // src/lib/build.ts
1341
+ // src/commands/build.ts
1207
1342
  async function build(options) {
1208
1343
  const vite = await import("vite");
1209
1344
  const viteConfig = await getViteConfig(options);
@@ -1214,7 +1349,7 @@ async function build(options) {
1214
1349
  await vite.build(vite.mergeConfig(viteConfig, buildConfig));
1215
1350
  }
1216
1351
 
1217
- // src/lib/develop.ts
1352
+ // src/commands/develop.ts
1218
1353
  var import_express = __toESM(require("express"));
1219
1354
  var import_fs = __toESM(require("fs"));
1220
1355
  var import_path2 = __toESM(require("path"));
@@ -1285,24 +1420,30 @@ async function develop(options) {
1285
1420
  return router;
1286
1421
  }
1287
1422
 
1288
- // src/lib/plugin.ts
1423
+ // src/commands/plugin.ts
1289
1424
  var import_fs2 = require("fs");
1290
- var import_promises = require("fs/promises");
1291
- var import_glob = require("glob");
1425
+ var import_node_module = require("module");
1292
1426
  var import_path3 = __toESM(require("path"));
1427
+
1428
+ // src/plugins/clear-plugin-build.ts
1429
+ var import_promises2 = require("fs/promises");
1430
+ var import_node_path3 = __toESM(require("path"));
1431
+ var clearPluginBuild = (options) => ({
1432
+ name: "medusa:clear-plugin-build",
1433
+ buildStart: async () => {
1434
+ const adminDir = import_node_path3.default.join(options.outDir, "admin");
1435
+ try {
1436
+ await (0, import_promises2.rm)(adminDir, { recursive: true, force: true });
1437
+ } catch (e) {
1438
+ }
1439
+ }
1440
+ });
1441
+
1442
+ // src/commands/plugin.ts
1293
1443
  async function plugin(options) {
1294
1444
  const vite = await import("vite");
1295
1445
  const react = (await import("@vitejs/plugin-react")).default;
1296
- const { nodeResolve } = await import("@rollup/plugin-node-resolve");
1297
- const entries = await (0, import_glob.glob)(`${options.root}/src/admin/**/*.{ts,tsx,js,jsx}`);
1298
- if (entries.length === 0) {
1299
- return;
1300
- }
1301
- const entryPoints = entries.reduce((acc, entry) => {
1302
- const outPath = entry.replace(/^src\//, "").replace(/\.(ts|tsx|js|jsx)$/, "");
1303
- acc[outPath] = import_path3.default.resolve(options.root, entry);
1304
- return acc;
1305
- }, {});
1446
+ const medusa = (await import("@medusajs/admin-vite-plugin")).default;
1306
1447
  const pkg = JSON.parse(
1307
1448
  (0, import_fs2.readFileSync)(import_path3.default.resolve(options.root, "package.json"), "utf-8")
1308
1449
  );
@@ -1311,51 +1452,62 @@ async function plugin(options) {
1311
1452
  ...Object.keys(pkg.peerDependencies || {}),
1312
1453
  ...Object.keys(pkg.devDependencies || {}),
1313
1454
  "react",
1314
- "react-dom",
1315
1455
  "react/jsx-runtime",
1316
1456
  "react-router-dom",
1457
+ "@medusajs/js-sdk",
1317
1458
  "@medusajs/admin-sdk",
1318
1459
  "@tanstack/react-query"
1319
1460
  ]);
1461
+ const outDir = import_path3.default.resolve(options.root, options.outDir, "src/admin");
1462
+ const entryPoint = import_path3.default.resolve(
1463
+ options.root,
1464
+ "src/admin/__admin-extensions__.js"
1465
+ );
1320
1466
  const originalNodeEnv = process.env.NODE_ENV;
1321
1467
  process.env.NODE_ENV = "production";
1322
1468
  const pluginConfig = {
1323
1469
  build: {
1324
1470
  lib: {
1325
- entry: entryPoints,
1326
- formats: ["es"]
1471
+ entry: entryPoint,
1472
+ formats: ["es", "cjs"],
1473
+ fileName: "index"
1327
1474
  },
1328
1475
  emptyOutDir: false,
1329
1476
  minify: false,
1330
- outDir: import_path3.default.resolve(options.root, options.outDir),
1477
+ outDir,
1331
1478
  rollupOptions: {
1332
- plugins: [nodeResolve()],
1333
- external: [...external, /node_modules/],
1479
+ external: (id, importer) => {
1480
+ if (!importer) {
1481
+ const idParts2 = id.split("/");
1482
+ const name2 = idParts2[0]?.startsWith("@") ? `${idParts2[0]}/${idParts2[1]}` : idParts2[0];
1483
+ const builtinModulesWithNodePrefix = [
1484
+ ...import_node_module.builtinModules,
1485
+ ...import_node_module.builtinModules.map((modName) => `node:${modName}`)
1486
+ ];
1487
+ return Boolean(
1488
+ name2 && external.has(name2) || name2 && builtinModulesWithNodePrefix.includes(name2)
1489
+ );
1490
+ }
1491
+ const idParts = id.split("/");
1492
+ const name = idParts[0]?.startsWith("@") ? `${idParts[0]}/${idParts[1]}` : idParts[0];
1493
+ return Boolean(name && external.has(name));
1494
+ },
1334
1495
  output: {
1335
- globals: {
1336
- react: "React",
1337
- "react-dom": "React-dom",
1338
- "react/jsx-runtime": "react/jsx-runtime"
1339
- },
1340
- preserveModules: true,
1341
- entryFileNames: (chunkInfo) => {
1342
- return `${chunkInfo.name.replace(`${options.root}/`, "")}.js`;
1496
+ preserveModules: false,
1497
+ interop: "auto",
1498
+ chunkFileNames: () => {
1499
+ return `_chunks/[name]-[hash]`;
1343
1500
  }
1344
1501
  }
1345
1502
  }
1346
1503
  },
1347
1504
  plugins: [
1348
1505
  react(),
1349
- {
1350
- name: "clear-admin-plugin",
1351
- buildStart: async () => {
1352
- const adminDir = import_path3.default.join(options.root, options.outDir, "admin");
1353
- try {
1354
- await (0, import_promises.rm)(adminDir, { recursive: true, force: true });
1355
- } catch (e) {
1356
- }
1357
- }
1358
- }
1506
+ medusa({
1507
+ pluginMode: true,
1508
+ sources: [import_path3.default.resolve(options.root, "src/admin")]
1509
+ }),
1510
+ clearPluginBuild({ outDir })
1359
1511
  ],
1360
1512
  logLevel: "silent",
1361
1513
  clearScreen: false
@@ -1364,7 +1516,7 @@ async function plugin(options) {
1364
1516
  process.env.NODE_ENV = originalNodeEnv;
1365
1517
  }
1366
1518
 
1367
- // src/lib/serve.ts
1519
+ // src/commands/serve.ts
1368
1520
  var import_compression = __toESM(require("compression"));
1369
1521
  var import_express2 = require("express");
1370
1522
  var import_fs3 = __toESM(require("fs"));
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@medusajs/admin-bundler",
3
- "version": "2.6.2-snapshot-20250311083444",
3
+ "version": "2.6.2-snapshot-20250311115840",
4
4
  "description": "Bundler for the Medusa admin dashboard.",
5
5
  "author": "Kasper Kristensen <kasper@medusajs.com>",
6
6
  "scripts": {
7
- "build": "tsup && copyfiles -f ./src/index.html ./src/entry.tsx ./src/index.css ./dist"
7
+ "build": "tsup"
8
8
  },
9
9
  "main": "./dist/index.js",
10
10
  "types": "./dist/index.d.ts",
@@ -18,30 +18,26 @@
18
18
  "package.json"
19
19
  ],
20
20
  "devDependencies": {
21
- "@medusajs/types": "2.6.2-snapshot-20250311083444",
21
+ "@medusajs/types": "2.6.2-snapshot-20250311115840",
22
22
  "@types/compression": "^1.7.5",
23
- "copyfiles": "^2.4.1",
24
23
  "express": "^4.21.0",
25
24
  "tsup": "^8.0.1",
26
25
  "typescript": "^5.3.3"
27
26
  },
28
27
  "dependencies": {
29
- "@medusajs/admin-shared": "2.6.2-snapshot-20250311083444",
30
- "@medusajs/admin-vite-plugin": "2.6.2-snapshot-20250311083444",
31
- "@medusajs/dashboard": "2.6.2-snapshot-20250311083444",
32
- "@rollup/plugin-node-resolve": "^16.0.0",
28
+ "@medusajs/admin-shared": "2.6.2-snapshot-20250311115840",
29
+ "@medusajs/admin-vite-plugin": "2.6.2-snapshot-20250311115840",
30
+ "@medusajs/dashboard": "2.6.2-snapshot-20250311115840",
33
31
  "@vitejs/plugin-react": "^4.2.1",
34
32
  "autoprefixer": "^10.4.16",
35
33
  "compression": "^1.7.4",
36
34
  "express": "^4.21.0",
37
35
  "get-port": "^5.1.1",
38
36
  "glob": "^10.3.10",
37
+ "outdent": "^0.8.0",
39
38
  "postcss": "^8.4.32",
40
39
  "tailwindcss": "^3.3.6",
41
40
  "vite": "^5.4.14"
42
41
  },
43
- "peerDependencies": {
44
- "react-dom": "^18.0.0"
45
- },
46
42
  "packageManager": "yarn@3.2.1"
47
43
  }
package/dist/entry.tsx DELETED
@@ -1,15 +0,0 @@
1
- import App from "@medusajs/dashboard";
2
- import React from "react";
3
- import ReactDOM from "react-dom/client";
4
- import "./index.css";
5
-
6
- ReactDOM.createRoot(document.getElementById("medusa")!).render(
7
- <React.StrictMode>
8
- <App />
9
- </React.StrictMode>
10
- )
11
-
12
-
13
- if (import.meta.hot) {
14
- import.meta.hot.accept()
15
- }
package/dist/index.css DELETED
@@ -1,5 +0,0 @@
1
- @import "@medusajs/dashboard/css";
2
-
3
- @tailwind base;
4
- @tailwind components;
5
- @tailwind utilities;
package/dist/index.html DELETED
@@ -1,16 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5
- <meta
6
- name="viewport"
7
- content="width=device-width, initial-scale=1, user-scalable=no"
8
- />
9
- <link rel="icon" href="data:," data-placeholder-favicon />
10
- </head>
11
-
12
- <body>
13
- <div id="medusa"></div>
14
- <script type="module" src="./entry.tsx"></script>
15
- </body>
16
- </html>