@medusajs/admin-vite-plugin 2.19.0 → 2.19.1-preview-20260813160157
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.js +184 -100
- package/dist/index.mjs +185 -100
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -35,7 +35,7 @@ __export(index_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(index_exports);
|
|
36
36
|
|
|
37
37
|
// src/plugin.ts
|
|
38
|
-
var
|
|
38
|
+
var import_promises17 = require("fs/promises");
|
|
39
39
|
var import_node_path = __toESM(require("path"));
|
|
40
40
|
|
|
41
41
|
// src/cell-renderers/generate-cell-renderer-hash.ts
|
|
@@ -83,12 +83,12 @@ function generateModule(code) {
|
|
|
83
83
|
var VALID_FILE_EXTENSIONS = [".tsx", ".jsx", ".js", ".ts"];
|
|
84
84
|
async function crawl(dir, file, depth) {
|
|
85
85
|
const dirDepth = dir.split(import_path.default.sep).length;
|
|
86
|
-
const crawler = new import_fdir.fdir().withBasePath().exclude((dirName) => dirName.startsWith("_")).filter((
|
|
87
|
-
return VALID_FILE_EXTENSIONS.some((ext) =>
|
|
86
|
+
const crawler = new import_fdir.fdir().withBasePath().exclude((dirName) => dirName.startsWith("_")).filter((path6) => {
|
|
87
|
+
return VALID_FILE_EXTENSIONS.some((ext) => path6.endsWith(ext));
|
|
88
88
|
});
|
|
89
89
|
if (file) {
|
|
90
|
-
crawler.filter((
|
|
91
|
-
return VALID_FILE_EXTENSIONS.some((ext) =>
|
|
90
|
+
crawler.filter((path6) => {
|
|
91
|
+
return VALID_FILE_EXTENSIONS.some((ext) => path6.endsWith(file + ext));
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
if (depth) {
|
|
@@ -105,15 +105,15 @@ async function crawl(dir, file, depth) {
|
|
|
105
105
|
}
|
|
106
106
|
return crawler.crawl(dir).withPromise();
|
|
107
107
|
}
|
|
108
|
-
function getConfigObjectProperties(
|
|
109
|
-
if ((0, import_types.isVariableDeclarator)(
|
|
110
|
-
const configDeclaration = (0, import_types.isIdentifier)(
|
|
108
|
+
function getConfigObjectProperties(path6) {
|
|
109
|
+
if ((0, import_types.isVariableDeclarator)(path6.node)) {
|
|
110
|
+
const configDeclaration = (0, import_types.isIdentifier)(path6.node.id, { name: "config" }) ? path6.node : null;
|
|
111
111
|
if (configDeclaration && (0, import_types.isCallExpression)(configDeclaration.init) && configDeclaration.init.arguments.length > 0 && (0, import_types.isObjectExpression)(configDeclaration.init.arguments[0])) {
|
|
112
112
|
return configDeclaration.init.arguments[0].properties;
|
|
113
113
|
}
|
|
114
114
|
return null;
|
|
115
115
|
}
|
|
116
|
-
const declaration =
|
|
116
|
+
const declaration = path6.node.declaration;
|
|
117
117
|
if ((0, import_types.isVariableDeclaration)(declaration)) {
|
|
118
118
|
const configDeclaration = declaration.declarations.find(
|
|
119
119
|
(d) => (0, import_types.isVariableDeclarator)(d) && (0, import_types.isIdentifier)(d.id, { name: "config" })
|
|
@@ -130,13 +130,13 @@ async function hasDefaultExport(ast) {
|
|
|
130
130
|
ExportDefaultDeclaration() {
|
|
131
131
|
hasDefaultExport2 = true;
|
|
132
132
|
},
|
|
133
|
-
AssignmentExpression(
|
|
134
|
-
if (
|
|
133
|
+
AssignmentExpression(path6) {
|
|
134
|
+
if (path6.node.left.type === "MemberExpression" && path6.node.left.object.type === "Identifier" && path6.node.left.object.name === "exports" && path6.node.left.property.type === "Identifier" && path6.node.left.property.name === "default") {
|
|
135
135
|
hasDefaultExport2 = true;
|
|
136
136
|
}
|
|
137
137
|
},
|
|
138
|
-
ExportNamedDeclaration(
|
|
139
|
-
const specifiers =
|
|
138
|
+
ExportNamedDeclaration(path6) {
|
|
139
|
+
const specifiers = path6.node.specifiers;
|
|
140
140
|
if (specifiers?.some(
|
|
141
141
|
(s) => s.type === "ExportSpecifier" && s.exported.type === "Identifier" && s.exported.name === "default"
|
|
142
142
|
)) {
|
|
@@ -222,8 +222,8 @@ var logger = {
|
|
|
222
222
|
|
|
223
223
|
// src/custom-fields/helpers.ts
|
|
224
224
|
var import_admin_shared = require("@medusajs/admin-shared");
|
|
225
|
-
function getModel(
|
|
226
|
-
const configArgument = getConfigArgument(
|
|
225
|
+
function getModel(path6, file) {
|
|
226
|
+
const configArgument = getConfigArgument(path6);
|
|
227
227
|
if (!configArgument) {
|
|
228
228
|
return null;
|
|
229
229
|
}
|
|
@@ -257,23 +257,23 @@ function getModel(path5, file) {
|
|
|
257
257
|
}
|
|
258
258
|
return model;
|
|
259
259
|
}
|
|
260
|
-
function getConfigArgument(
|
|
261
|
-
if (!(0, import_types.isCallExpression)(
|
|
260
|
+
function getConfigArgument(path6) {
|
|
261
|
+
if (!(0, import_types.isCallExpression)(path6.node.declaration)) {
|
|
262
262
|
return null;
|
|
263
263
|
}
|
|
264
|
-
if (!(0, import_types.isIdentifier)(
|
|
264
|
+
if (!(0, import_types.isIdentifier)(path6.node.declaration.callee, {
|
|
265
265
|
name: "unstable_defineCustomFieldsConfig"
|
|
266
266
|
})) {
|
|
267
267
|
return null;
|
|
268
268
|
}
|
|
269
|
-
const configArgument =
|
|
269
|
+
const configArgument = path6.node.declaration.arguments[0];
|
|
270
270
|
if (!(0, import_types.isObjectExpression)(configArgument)) {
|
|
271
271
|
return null;
|
|
272
272
|
}
|
|
273
273
|
return configArgument;
|
|
274
274
|
}
|
|
275
|
-
function validateLink(
|
|
276
|
-
const configArgument = getConfigArgument(
|
|
275
|
+
function validateLink(path6, file) {
|
|
276
|
+
const configArgument = getConfigArgument(path6);
|
|
277
277
|
if (!configArgument) {
|
|
278
278
|
return false;
|
|
279
279
|
}
|
|
@@ -363,14 +363,14 @@ async function parseDisplayFile(file, index) {
|
|
|
363
363
|
let hasLink = false;
|
|
364
364
|
try {
|
|
365
365
|
traverse(ast, {
|
|
366
|
-
ExportDefaultDeclaration(
|
|
367
|
-
const _model = getModel(
|
|
366
|
+
ExportDefaultDeclaration(path6) {
|
|
367
|
+
const _model = getModel(path6, file);
|
|
368
368
|
if (!_model) {
|
|
369
369
|
return;
|
|
370
370
|
}
|
|
371
371
|
model = _model;
|
|
372
|
-
displays = getDisplays(
|
|
373
|
-
hasLink = validateLink(
|
|
372
|
+
displays = getDisplays(path6, model, index, file);
|
|
373
|
+
hasLink = validateLink(path6, file);
|
|
374
374
|
}
|
|
375
375
|
});
|
|
376
376
|
} catch (err) {
|
|
@@ -394,8 +394,8 @@ async function parseDisplayFile(file, index) {
|
|
|
394
394
|
displays
|
|
395
395
|
};
|
|
396
396
|
}
|
|
397
|
-
function getDisplays(
|
|
398
|
-
const configArgument = getConfigArgument(
|
|
397
|
+
function getDisplays(path6, model, index, file) {
|
|
398
|
+
const configArgument = getConfigArgument(path6);
|
|
399
399
|
if (!configArgument) {
|
|
400
400
|
return null;
|
|
401
401
|
}
|
|
@@ -471,8 +471,8 @@ function generateCustomFieldConfigName(index) {
|
|
|
471
471
|
return `CustomFieldConfig${index}`;
|
|
472
472
|
}
|
|
473
473
|
function generateImport(file, index) {
|
|
474
|
-
const
|
|
475
|
-
return `import ${generateCustomFieldConfigName(index)} from "${
|
|
474
|
+
const path6 = normalizePath(file);
|
|
475
|
+
return `import ${generateCustomFieldConfigName(index)} from "${path6}"`;
|
|
476
476
|
}
|
|
477
477
|
|
|
478
478
|
// src/custom-fields/generate-custom-field-forms.ts
|
|
@@ -592,15 +592,15 @@ async function parseFile(file, index) {
|
|
|
592
592
|
let hasLink = false;
|
|
593
593
|
try {
|
|
594
594
|
traverse(ast, {
|
|
595
|
-
ExportDefaultDeclaration(
|
|
596
|
-
const _model = getModel(
|
|
595
|
+
ExportDefaultDeclaration(path6) {
|
|
596
|
+
const _model = getModel(path6, file);
|
|
597
597
|
if (!_model) {
|
|
598
598
|
return;
|
|
599
599
|
}
|
|
600
600
|
model = _model;
|
|
601
|
-
hasLink = validateLink(
|
|
602
|
-
configs = getConfigs(
|
|
603
|
-
forms = getForms(
|
|
601
|
+
hasLink = validateLink(path6, file);
|
|
602
|
+
configs = getConfigs(path6, model, index, file);
|
|
603
|
+
forms = getForms(path6, model, index, file);
|
|
604
604
|
}
|
|
605
605
|
});
|
|
606
606
|
} catch (err) {
|
|
@@ -629,11 +629,11 @@ function generateCustomFieldConfigName2(index) {
|
|
|
629
629
|
return `CustomFieldConfig${index}`;
|
|
630
630
|
}
|
|
631
631
|
function generateImport2(file, index) {
|
|
632
|
-
const
|
|
633
|
-
return `import ${generateCustomFieldConfigName2(index)} from "${
|
|
632
|
+
const path6 = normalizePath(file);
|
|
633
|
+
return `import ${generateCustomFieldConfigName2(index)} from "${path6}"`;
|
|
634
634
|
}
|
|
635
|
-
function getForms(
|
|
636
|
-
const formArray = getFormsArgument(
|
|
635
|
+
function getForms(path6, model, index, file) {
|
|
636
|
+
const formArray = getFormsArgument(path6, file);
|
|
637
637
|
if (!formArray) {
|
|
638
638
|
return null;
|
|
639
639
|
}
|
|
@@ -797,8 +797,8 @@ function getFormFieldSectionValue(exists, fileIndex, formIndex, fieldKey, value)
|
|
|
797
797
|
function getFormEntryFieldPath(model, zone, tab) {
|
|
798
798
|
return `${model}.${zone}.${tab ? `${tab}.` : ""}$field`;
|
|
799
799
|
}
|
|
800
|
-
function getConfigs(
|
|
801
|
-
const formArray = getFormsArgument(
|
|
800
|
+
function getConfigs(path6, model, index, file) {
|
|
801
|
+
const formArray = getFormsArgument(path6, file);
|
|
802
802
|
if (!formArray) {
|
|
803
803
|
logger.warn(`'forms' property is missing.`, { file });
|
|
804
804
|
return null;
|
|
@@ -917,8 +917,8 @@ function getFormFieldValue(fileIndex, formIndex, fieldKey, value) {
|
|
|
917
917
|
function getFormEntryConfigPath(model, zone) {
|
|
918
918
|
return `${model}.${zone}.$config`;
|
|
919
919
|
}
|
|
920
|
-
function getFormsArgument(
|
|
921
|
-
const configArgument = getConfigArgument(
|
|
920
|
+
function getFormsArgument(path6, file) {
|
|
921
|
+
const configArgument = getConfigArgument(path6);
|
|
922
922
|
if (!configArgument) {
|
|
923
923
|
return null;
|
|
924
924
|
}
|
|
@@ -979,8 +979,8 @@ async function getCustomFieldContents(file) {
|
|
|
979
979
|
let displayContent = null;
|
|
980
980
|
try {
|
|
981
981
|
traverse(ast, {
|
|
982
|
-
ExportDefaultDeclaration(
|
|
983
|
-
const configArgument = getConfigArgument(
|
|
982
|
+
ExportDefaultDeclaration(path6) {
|
|
983
|
+
const configArgument = getConfigArgument(path6);
|
|
984
984
|
if (!configArgument) {
|
|
985
985
|
return;
|
|
986
986
|
}
|
|
@@ -1074,13 +1074,13 @@ async function parseFile2(file, index) {
|
|
|
1074
1074
|
let model = null;
|
|
1075
1075
|
try {
|
|
1076
1076
|
traverse(ast, {
|
|
1077
|
-
ExportDefaultDeclaration(
|
|
1078
|
-
const _model = getModel(
|
|
1077
|
+
ExportDefaultDeclaration(path6) {
|
|
1078
|
+
const _model = getModel(path6, file);
|
|
1079
1079
|
if (!_model) {
|
|
1080
1080
|
return;
|
|
1081
1081
|
}
|
|
1082
1082
|
model = _model;
|
|
1083
|
-
link = getLink(
|
|
1083
|
+
link = getLink(path6, index, file);
|
|
1084
1084
|
}
|
|
1085
1085
|
});
|
|
1086
1086
|
} catch (err) {
|
|
@@ -1103,11 +1103,11 @@ function generateCustomFieldConfigName3(index) {
|
|
|
1103
1103
|
return `CustomFieldConfig${index}`;
|
|
1104
1104
|
}
|
|
1105
1105
|
function generateImport3(file, index) {
|
|
1106
|
-
const
|
|
1107
|
-
return `import ${generateCustomFieldConfigName3(index)} from "${
|
|
1106
|
+
const path6 = normalizePath(file);
|
|
1107
|
+
return `import ${generateCustomFieldConfigName3(index)} from "${path6}"`;
|
|
1108
1108
|
}
|
|
1109
|
-
function getLink(
|
|
1110
|
-
const configArgument = getConfigArgument(
|
|
1109
|
+
function getLink(path6, index, file) {
|
|
1110
|
+
const configArgument = getConfigArgument(path6);
|
|
1111
1111
|
if (!configArgument) {
|
|
1112
1112
|
return null;
|
|
1113
1113
|
}
|
|
@@ -1246,11 +1246,11 @@ async function parseFile3(file, index) {
|
|
|
1246
1246
|
function hasConfigExport(ast) {
|
|
1247
1247
|
let found = false;
|
|
1248
1248
|
traverse(ast, {
|
|
1249
|
-
ExportNamedDeclaration(
|
|
1249
|
+
ExportNamedDeclaration(path6) {
|
|
1250
1250
|
if (found) {
|
|
1251
1251
|
return;
|
|
1252
1252
|
}
|
|
1253
|
-
if (getConfigObjectProperties(
|
|
1253
|
+
if (getConfigObjectProperties(path6)) {
|
|
1254
1254
|
found = true;
|
|
1255
1255
|
}
|
|
1256
1256
|
}
|
|
@@ -1258,8 +1258,8 @@ function hasConfigExport(ast) {
|
|
|
1258
1258
|
return found;
|
|
1259
1259
|
}
|
|
1260
1260
|
function generateImport4(file, componentName, configName) {
|
|
1261
|
-
const
|
|
1262
|
-
return `import ${componentName}, { config as ${configName} } from "${
|
|
1261
|
+
const path6 = normalizePath(file);
|
|
1262
|
+
return `import ${componentName}, { config as ${configName} } from "${path6}"`;
|
|
1263
1263
|
}
|
|
1264
1264
|
|
|
1265
1265
|
// src/layouts/generate-layout-hash.ts
|
|
@@ -1307,11 +1307,11 @@ function generateCode4(results) {
|
|
|
1307
1307
|
`;
|
|
1308
1308
|
}
|
|
1309
1309
|
function formatMenuItem(route) {
|
|
1310
|
-
const { label, icon, path:
|
|
1310
|
+
const { label, icon, path: path6, nested, rank, translationNs } = route;
|
|
1311
1311
|
return `{
|
|
1312
1312
|
label: ${label},
|
|
1313
1313
|
icon: ${icon || "undefined"},
|
|
1314
|
-
path: "${
|
|
1314
|
+
path: "${path6}",
|
|
1315
1315
|
nested: ${nested ? `"${nested}"` : "undefined"},
|
|
1316
1316
|
rank: ${rank !== void 0 ? rank : "undefined"},
|
|
1317
1317
|
translationNs: ${translationNs ? `${translationNs}` : "undefined"}
|
|
@@ -1347,8 +1347,8 @@ async function parseFile4(file, index) {
|
|
|
1347
1347
|
};
|
|
1348
1348
|
}
|
|
1349
1349
|
function generateImport5(file, index) {
|
|
1350
|
-
const
|
|
1351
|
-
return `import { config as ${generateRouteConfigName(index)} } from "${
|
|
1350
|
+
const path6 = normalizePath(file);
|
|
1351
|
+
return `import { config as ${generateRouteConfigName(index)} } from "${path6}"`;
|
|
1352
1352
|
}
|
|
1353
1353
|
function generateMenuItem(config, file, index) {
|
|
1354
1354
|
const configName = generateRouteConfigName(index);
|
|
@@ -1381,11 +1381,11 @@ async function getRouteConfig(file) {
|
|
|
1381
1381
|
* For bundled files, the config will not be a named export,
|
|
1382
1382
|
* but instead a variable declaration.
|
|
1383
1383
|
*/
|
|
1384
|
-
VariableDeclarator(
|
|
1384
|
+
VariableDeclarator(path6) {
|
|
1385
1385
|
if (configFound) {
|
|
1386
1386
|
return;
|
|
1387
1387
|
}
|
|
1388
|
-
const properties = getConfigObjectProperties(
|
|
1388
|
+
const properties = getConfigObjectProperties(path6);
|
|
1389
1389
|
if (!properties) {
|
|
1390
1390
|
return;
|
|
1391
1391
|
}
|
|
@@ -1397,11 +1397,11 @@ async function getRouteConfig(file) {
|
|
|
1397
1397
|
/**
|
|
1398
1398
|
* For unbundled files, the `config` will always be a named export.
|
|
1399
1399
|
*/
|
|
1400
|
-
ExportNamedDeclaration(
|
|
1400
|
+
ExportNamedDeclaration(path6) {
|
|
1401
1401
|
if (configFound) {
|
|
1402
1402
|
return;
|
|
1403
1403
|
}
|
|
1404
|
-
const properties = getConfigObjectProperties(
|
|
1404
|
+
const properties = getConfigObjectProperties(path6);
|
|
1405
1405
|
if (!properties) {
|
|
1406
1406
|
return;
|
|
1407
1407
|
}
|
|
@@ -1506,13 +1506,13 @@ async function getRouteContents(file) {
|
|
|
1506
1506
|
let configContent = null;
|
|
1507
1507
|
try {
|
|
1508
1508
|
traverse(ast, {
|
|
1509
|
-
ExportDefaultDeclaration(
|
|
1510
|
-
defaultExportContent = code.slice(
|
|
1509
|
+
ExportDefaultDeclaration(path6) {
|
|
1510
|
+
defaultExportContent = code.slice(path6.node.start, path6.node.end);
|
|
1511
1511
|
},
|
|
1512
|
-
ExportNamedDeclaration(
|
|
1513
|
-
const properties = getConfigObjectProperties(
|
|
1512
|
+
ExportNamedDeclaration(path6) {
|
|
1513
|
+
const properties = getConfigObjectProperties(path6);
|
|
1514
1514
|
if (properties) {
|
|
1515
|
-
configContent = code.slice(
|
|
1515
|
+
configContent = code.slice(path6.node.start, path6.node.end);
|
|
1516
1516
|
}
|
|
1517
1517
|
}
|
|
1518
1518
|
});
|
|
@@ -1692,8 +1692,8 @@ async function hasNamedExports(ast, file) {
|
|
|
1692
1692
|
let hasConfig = false;
|
|
1693
1693
|
try {
|
|
1694
1694
|
traverse(ast, {
|
|
1695
|
-
ExportNamedDeclaration(
|
|
1696
|
-
const declaration =
|
|
1695
|
+
ExportNamedDeclaration(path6) {
|
|
1696
|
+
const declaration = path6.node.declaration;
|
|
1697
1697
|
if (declaration?.type === "VariableDeclaration") {
|
|
1698
1698
|
declaration.declarations.forEach((decl) => {
|
|
1699
1699
|
if (decl.id.type === "Identifier" && decl.id.name === "handle") {
|
|
@@ -1721,6 +1721,44 @@ async function hasNamedExports(ast, file) {
|
|
|
1721
1721
|
return { hasHandle, hasLoader, hasConfig };
|
|
1722
1722
|
}
|
|
1723
1723
|
|
|
1724
|
+
// src/search-entities/constants.ts
|
|
1725
|
+
var SEARCH_ENTITY_FILES = [
|
|
1726
|
+
"search-entities.tsx",
|
|
1727
|
+
"search-entities.ts"
|
|
1728
|
+
];
|
|
1729
|
+
|
|
1730
|
+
// src/search-entities/find-search-entity-file.ts
|
|
1731
|
+
var import_promises12 = __toESM(require("fs/promises"));
|
|
1732
|
+
var import_path3 = __toESM(require("path"));
|
|
1733
|
+
async function findSearchEntityFile(source) {
|
|
1734
|
+
for (const fileName of SEARCH_ENTITY_FILES) {
|
|
1735
|
+
const filePath = import_path3.default.join(source, fileName);
|
|
1736
|
+
try {
|
|
1737
|
+
await import_promises12.default.access(filePath);
|
|
1738
|
+
return filePath;
|
|
1739
|
+
} catch {
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
return null;
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
// src/search-entities/generate-search-entity-hash.ts
|
|
1746
|
+
var import_promises13 = __toESM(require("fs/promises"));
|
|
1747
|
+
async function generateSearchEntityHash(sources) {
|
|
1748
|
+
const contents = [];
|
|
1749
|
+
for (const source of sources) {
|
|
1750
|
+
const searchEntitiesPath = await findSearchEntityFile(source);
|
|
1751
|
+
if (!searchEntitiesPath) {
|
|
1752
|
+
continue;
|
|
1753
|
+
}
|
|
1754
|
+
try {
|
|
1755
|
+
contents.push(await import_promises13.default.readFile(searchEntitiesPath, "utf-8"));
|
|
1756
|
+
} catch {
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
return generateHash(contents.join(""));
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1724
1762
|
// src/virtual-modules/generate-virtual-display-module.ts
|
|
1725
1763
|
var import_outdent6 = require("outdent");
|
|
1726
1764
|
async function generateVirtualDisplayModule(sources, pluginMode = false) {
|
|
@@ -1800,7 +1838,7 @@ async function generateVirtualRouteModule(sources, pluginMode = false) {
|
|
|
1800
1838
|
var import_outdent13 = __toESM(require("outdent"));
|
|
1801
1839
|
|
|
1802
1840
|
// src/widgets/generate-widget-hash.ts
|
|
1803
|
-
var
|
|
1841
|
+
var import_promises14 = __toESM(require("fs/promises"));
|
|
1804
1842
|
|
|
1805
1843
|
// src/widgets/helpers.ts
|
|
1806
1844
|
async function getWidgetFilesFromSources(sources) {
|
|
@@ -1817,7 +1855,7 @@ async function generateWidgetHash(sources) {
|
|
|
1817
1855
|
return generateHash(totalContent);
|
|
1818
1856
|
}
|
|
1819
1857
|
async function getWidgetContents(file) {
|
|
1820
|
-
const code = await
|
|
1858
|
+
const code = await import_promises14.default.readFile(file, "utf-8");
|
|
1821
1859
|
let ast;
|
|
1822
1860
|
try {
|
|
1823
1861
|
ast = (0, import_parser.parse)(code, getParserOptions(file));
|
|
@@ -1834,14 +1872,14 @@ async function getWidgetContents(file) {
|
|
|
1834
1872
|
let configContent = null;
|
|
1835
1873
|
let defaultExportContent = null;
|
|
1836
1874
|
traverse(ast, {
|
|
1837
|
-
ExportNamedDeclaration(
|
|
1838
|
-
const properties = getConfigObjectProperties(
|
|
1875
|
+
ExportNamedDeclaration(path6) {
|
|
1876
|
+
const properties = getConfigObjectProperties(path6);
|
|
1839
1877
|
if (properties) {
|
|
1840
|
-
configContent = code.slice(
|
|
1878
|
+
configContent = code.slice(path6.node.start, path6.node.end);
|
|
1841
1879
|
}
|
|
1842
1880
|
},
|
|
1843
|
-
ExportDefaultDeclaration(
|
|
1844
|
-
defaultExportContent = code.slice(
|
|
1881
|
+
ExportDefaultDeclaration(path6) {
|
|
1882
|
+
defaultExportContent = code.slice(path6.node.start, path6.node.end);
|
|
1845
1883
|
}
|
|
1846
1884
|
});
|
|
1847
1885
|
return { config: configContent, defaultExport: defaultExportContent };
|
|
@@ -1849,7 +1887,7 @@ async function getWidgetContents(file) {
|
|
|
1849
1887
|
|
|
1850
1888
|
// src/widgets/generate-widgets.ts
|
|
1851
1889
|
var import_admin_shared5 = require("@medusajs/admin-shared");
|
|
1852
|
-
var
|
|
1890
|
+
var import_promises15 = __toESM(require("fs/promises"));
|
|
1853
1891
|
var import_outdent12 = __toESM(require("outdent"));
|
|
1854
1892
|
async function generateWidgets(sources) {
|
|
1855
1893
|
const files = await getWidgetFilesFromSources(sources);
|
|
@@ -1893,7 +1931,7 @@ function getWidgetId(idOverride, file) {
|
|
|
1893
1931
|
return `Widget-${generateHash(relative).slice(0, 4)}`;
|
|
1894
1932
|
}
|
|
1895
1933
|
async function parseFile6(file, index) {
|
|
1896
|
-
const code = await
|
|
1934
|
+
const code = await import_promises15.default.readFile(file, "utf-8");
|
|
1897
1935
|
let ast;
|
|
1898
1936
|
try {
|
|
1899
1937
|
ast = (0, import_parser.parse)(code, getParserOptions(file));
|
|
@@ -1954,10 +1992,10 @@ function generateWidgetConfigName(index) {
|
|
|
1954
1992
|
return `WidgetConfig${index}`;
|
|
1955
1993
|
}
|
|
1956
1994
|
function generateImport6(file, index) {
|
|
1957
|
-
const
|
|
1995
|
+
const path6 = normalizePath(file);
|
|
1958
1996
|
return `import ${generateWidgetComponentName(
|
|
1959
1997
|
index
|
|
1960
|
-
)}, { config as ${generateWidgetConfigName(index)} } from "${
|
|
1998
|
+
)}, { config as ${generateWidgetConfigName(index)} } from "${path6}"`;
|
|
1961
1999
|
}
|
|
1962
2000
|
function generateWidget(zone, index, widgetId) {
|
|
1963
2001
|
return {
|
|
@@ -1969,11 +2007,11 @@ function generateWidget(zone, index, widgetId) {
|
|
|
1969
2007
|
function getWidgetIdOverride(ast) {
|
|
1970
2008
|
let id = null;
|
|
1971
2009
|
let found = false;
|
|
1972
|
-
const readId = (
|
|
2010
|
+
const readId = (path6) => {
|
|
1973
2011
|
if (found) {
|
|
1974
2012
|
return;
|
|
1975
2013
|
}
|
|
1976
|
-
const properties = getConfigObjectProperties(
|
|
2014
|
+
const properties = getConfigObjectProperties(path6);
|
|
1977
2015
|
if (!properties) {
|
|
1978
2016
|
return;
|
|
1979
2017
|
}
|
|
@@ -2002,12 +2040,12 @@ async function getWidgetZone(ast, file) {
|
|
|
2002
2040
|
* not be a named export. Instead we look for a `VariableDeclaration` named
|
|
2003
2041
|
* `config` and extract the `zone` property from it.
|
|
2004
2042
|
*/
|
|
2005
|
-
VariableDeclarator(
|
|
2043
|
+
VariableDeclarator(path6) {
|
|
2006
2044
|
if (zoneFound) {
|
|
2007
2045
|
return;
|
|
2008
2046
|
}
|
|
2009
|
-
if (
|
|
2010
|
-
const arg =
|
|
2047
|
+
if (path6.node.id.type === "Identifier" && path6.node.id.name === "config" && path6.node.init?.type === "CallExpression") {
|
|
2048
|
+
const arg = path6.node.init.arguments[0];
|
|
2011
2049
|
if (arg?.type === "ObjectExpression") {
|
|
2012
2050
|
const zoneProperty = arg.properties.find(
|
|
2013
2051
|
(p) => p.type === "ObjectProperty" && p.key.name === "zone"
|
|
@@ -2022,11 +2060,11 @@ async function getWidgetZone(ast, file) {
|
|
|
2022
2060
|
/**
|
|
2023
2061
|
* For unbundled files, the `config` will always be a named export.
|
|
2024
2062
|
*/
|
|
2025
|
-
ExportNamedDeclaration(
|
|
2063
|
+
ExportNamedDeclaration(path6) {
|
|
2026
2064
|
if (zoneFound) {
|
|
2027
2065
|
return;
|
|
2028
2066
|
}
|
|
2029
|
-
const declaration =
|
|
2067
|
+
const declaration = path6.node.declaration;
|
|
2030
2068
|
if (declaration?.type === "VariableDeclaration" && declaration.declarations[0]?.type === "VariableDeclarator" && declaration.declarations[0].id.type === "Identifier" && declaration.declarations[0].id.name === "config" && declaration.declarations[0].init?.type === "CallExpression") {
|
|
2031
2069
|
const arg = declaration.declarations[0].init.arguments[0];
|
|
2032
2070
|
if (arg?.type === "ObjectExpression") {
|
|
@@ -2103,14 +2141,14 @@ async function generateVirtualI18nModule(sources, pluginMode = false) {
|
|
|
2103
2141
|
|
|
2104
2142
|
// src/virtual-modules/generate-virtual-cell-renderer-module.ts
|
|
2105
2143
|
var import_outdent15 = __toESM(require("outdent"));
|
|
2106
|
-
var
|
|
2107
|
-
var
|
|
2144
|
+
var import_promises16 = __toESM(require("fs/promises"));
|
|
2145
|
+
var import_path4 = __toESM(require("path"));
|
|
2108
2146
|
async function generateVirtualCellRendererModule(sources, pluginMode = false) {
|
|
2109
2147
|
const imports = [];
|
|
2110
2148
|
for (const source of sources) {
|
|
2111
|
-
const cellRenderersPath =
|
|
2149
|
+
const cellRenderersPath = import_path4.default.join(source, "cell-renderers.tsx");
|
|
2112
2150
|
try {
|
|
2113
|
-
await
|
|
2151
|
+
await import_promises16.default.access(cellRenderersPath);
|
|
2114
2152
|
imports.push(`import "${cellRenderersPath}"`);
|
|
2115
2153
|
} catch {
|
|
2116
2154
|
}
|
|
@@ -2123,6 +2161,24 @@ async function generateVirtualCellRendererModule(sources, pluginMode = false) {
|
|
|
2123
2161
|
return generateModule(code);
|
|
2124
2162
|
}
|
|
2125
2163
|
|
|
2164
|
+
// src/virtual-modules/generate-virtual-search-entity-module.ts
|
|
2165
|
+
var import_outdent16 = __toESM(require("outdent"));
|
|
2166
|
+
async function generateVirtualSearchEntityModule(sources, pluginMode = false) {
|
|
2167
|
+
const imports = [];
|
|
2168
|
+
for (const source of sources) {
|
|
2169
|
+
const searchEntitiesPath = await findSearchEntityFile(source);
|
|
2170
|
+
if (searchEntitiesPath) {
|
|
2171
|
+
imports.push(`import "${normalizePath(searchEntitiesPath)}"`);
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
const code = import_outdent16.default`
|
|
2175
|
+
${imports.join("\n")}
|
|
2176
|
+
|
|
2177
|
+
${pluginMode ? `const searchEntityModule = {}` : `export default {}`}
|
|
2178
|
+
`;
|
|
2179
|
+
return generateModule(code);
|
|
2180
|
+
}
|
|
2181
|
+
|
|
2126
2182
|
// src/vmod.ts
|
|
2127
2183
|
var import_admin_shared6 = require("@medusajs/admin-shared");
|
|
2128
2184
|
var RESOLVED_LINK_VIRTUAL_MODULE = `\0${import_admin_shared6.LINK_VIRTUAL_MODULE}`;
|
|
@@ -2134,6 +2190,7 @@ var RESOLVED_WIDGET_VIRTUAL_MODULE = `\0${import_admin_shared6.WIDGET_VIRTUAL_MO
|
|
|
2134
2190
|
var RESOLVED_I18N_VIRTUAL_MODULE = `\0${import_admin_shared6.I18N_VIRTUAL_MODULE}`;
|
|
2135
2191
|
var RESOLVED_CELL_RENDERER_VIRTUAL_MODULE = `\0${import_admin_shared6.CELL_RENDERER_VIRTUAL_MODULE}`;
|
|
2136
2192
|
var RESOLVED_LAYOUT_VIRTUAL_MODULE = `\0${import_admin_shared6.LAYOUT_VIRTUAL_MODULE}`;
|
|
2193
|
+
var RESOLVED_SEARCH_ENTITY_VIRTUAL_MODULE = `\0${import_admin_shared6.SEARCH_ENTITY_VIRTUAL_MODULE}`;
|
|
2137
2194
|
var VIRTUAL_MODULES = [
|
|
2138
2195
|
import_admin_shared6.LINK_VIRTUAL_MODULE,
|
|
2139
2196
|
import_admin_shared6.FORM_VIRTUAL_MODULE,
|
|
@@ -2143,7 +2200,8 @@ var VIRTUAL_MODULES = [
|
|
|
2143
2200
|
import_admin_shared6.WIDGET_VIRTUAL_MODULE,
|
|
2144
2201
|
import_admin_shared6.I18N_VIRTUAL_MODULE,
|
|
2145
2202
|
import_admin_shared6.CELL_RENDERER_VIRTUAL_MODULE,
|
|
2146
|
-
import_admin_shared6.LAYOUT_VIRTUAL_MODULE
|
|
2203
|
+
import_admin_shared6.LAYOUT_VIRTUAL_MODULE,
|
|
2204
|
+
import_admin_shared6.SEARCH_ENTITY_VIRTUAL_MODULE
|
|
2147
2205
|
];
|
|
2148
2206
|
var RESOLVED_VIRTUAL_MODULES = [
|
|
2149
2207
|
RESOLVED_LINK_VIRTUAL_MODULE,
|
|
@@ -2154,7 +2212,8 @@ var RESOLVED_VIRTUAL_MODULES = [
|
|
|
2154
2212
|
RESOLVED_WIDGET_VIRTUAL_MODULE,
|
|
2155
2213
|
RESOLVED_I18N_VIRTUAL_MODULE,
|
|
2156
2214
|
RESOLVED_CELL_RENDERER_VIRTUAL_MODULE,
|
|
2157
|
-
RESOLVED_LAYOUT_VIRTUAL_MODULE
|
|
2215
|
+
RESOLVED_LAYOUT_VIRTUAL_MODULE,
|
|
2216
|
+
RESOLVED_SEARCH_ENTITY_VIRTUAL_MODULE
|
|
2158
2217
|
];
|
|
2159
2218
|
function resolveVirtualId(id) {
|
|
2160
2219
|
return `\0${id}`;
|
|
@@ -2176,7 +2235,8 @@ var resolvedVirtualModuleIds = {
|
|
|
2176
2235
|
widget: RESOLVED_WIDGET_VIRTUAL_MODULE,
|
|
2177
2236
|
i18n: RESOLVED_I18N_VIRTUAL_MODULE,
|
|
2178
2237
|
cellRenderer: RESOLVED_CELL_RENDERER_VIRTUAL_MODULE,
|
|
2179
|
-
layout: RESOLVED_LAYOUT_VIRTUAL_MODULE
|
|
2238
|
+
layout: RESOLVED_LAYOUT_VIRTUAL_MODULE,
|
|
2239
|
+
searchEntity: RESOLVED_SEARCH_ENTITY_VIRTUAL_MODULE
|
|
2180
2240
|
};
|
|
2181
2241
|
var virtualModuleIds = {
|
|
2182
2242
|
link: import_admin_shared6.LINK_VIRTUAL_MODULE,
|
|
@@ -2187,7 +2247,8 @@ var virtualModuleIds = {
|
|
|
2187
2247
|
widget: import_admin_shared6.WIDGET_VIRTUAL_MODULE,
|
|
2188
2248
|
i18n: import_admin_shared6.I18N_VIRTUAL_MODULE,
|
|
2189
2249
|
cellRenderer: import_admin_shared6.CELL_RENDERER_VIRTUAL_MODULE,
|
|
2190
|
-
layout: import_admin_shared6.LAYOUT_VIRTUAL_MODULE
|
|
2250
|
+
layout: import_admin_shared6.LAYOUT_VIRTUAL_MODULE,
|
|
2251
|
+
searchEntity: import_admin_shared6.SEARCH_ENTITY_VIRTUAL_MODULE
|
|
2191
2252
|
};
|
|
2192
2253
|
var vmod = {
|
|
2193
2254
|
resolved: resolvedVirtualModuleIds,
|
|
@@ -2237,6 +2298,7 @@ var medusaVitePlugin = (options) => {
|
|
|
2237
2298
|
const i18nModule = await generateVirtualI18nModule(sources, true);
|
|
2238
2299
|
const cellRendererModule = await generateVirtualCellRendererModule(sources, true);
|
|
2239
2300
|
const layoutModule = await generateVirtualLayoutModule(sources, true);
|
|
2301
|
+
const searchEntityModule = await generateVirtualSearchEntityModule(sources, true);
|
|
2240
2302
|
return `
|
|
2241
2303
|
// Auto-generated index file for Medusa Admin UI extensions
|
|
2242
2304
|
${widgetModule.code}
|
|
@@ -2247,6 +2309,7 @@ var medusaVitePlugin = (options) => {
|
|
|
2247
2309
|
${i18nModule.code}
|
|
2248
2310
|
${cellRendererModule.code}
|
|
2249
2311
|
${layoutModule.code}
|
|
2312
|
+
${searchEntityModule.code}
|
|
2250
2313
|
|
|
2251
2314
|
const plugin = {
|
|
2252
2315
|
widgetModule,
|
|
@@ -2256,7 +2319,8 @@ var medusaVitePlugin = (options) => {
|
|
|
2256
2319
|
displayModule,
|
|
2257
2320
|
i18nModule,
|
|
2258
2321
|
cellRendererModule,
|
|
2259
|
-
layoutModule
|
|
2322
|
+
layoutModule,
|
|
2323
|
+
searchEntityModule
|
|
2260
2324
|
}
|
|
2261
2325
|
|
|
2262
2326
|
export default plugin
|
|
@@ -2273,7 +2337,7 @@ var medusaVitePlugin = (options) => {
|
|
|
2273
2337
|
switch (mode) {
|
|
2274
2338
|
case "plugin" /* PLUGIN */: {
|
|
2275
2339
|
const code = await generatePluginEntryModule(_sources);
|
|
2276
|
-
await (0,
|
|
2340
|
+
await (0, import_promises17.writeFile)(pluginEntryFile, code, "utf-8");
|
|
2277
2341
|
break;
|
|
2278
2342
|
}
|
|
2279
2343
|
case "application" /* APPLICATION */: {
|
|
@@ -2285,7 +2349,7 @@ var medusaVitePlugin = (options) => {
|
|
|
2285
2349
|
switch (mode) {
|
|
2286
2350
|
case "plugin" /* PLUGIN */: {
|
|
2287
2351
|
try {
|
|
2288
|
-
await (0,
|
|
2352
|
+
await (0, import_promises17.rm)(pluginEntryFile, { force: true });
|
|
2289
2353
|
} catch (error) {
|
|
2290
2354
|
}
|
|
2291
2355
|
break;
|
|
@@ -2377,6 +2441,11 @@ var loadConfigs = {
|
|
|
2377
2441
|
hashGenerator: async (sources) => generateLayoutHash(sources),
|
|
2378
2442
|
moduleGenerator: async (sources) => generateVirtualLayoutModule(sources),
|
|
2379
2443
|
hashKey: vmod.virtual.layout
|
|
2444
|
+
},
|
|
2445
|
+
[vmod.resolved.searchEntity]: {
|
|
2446
|
+
hashGenerator: async (sources) => generateSearchEntityHash(sources),
|
|
2447
|
+
moduleGenerator: async (sources) => generateVirtualSearchEntityModule(sources),
|
|
2448
|
+
hashKey: vmod.virtual.searchEntity
|
|
2380
2449
|
}
|
|
2381
2450
|
};
|
|
2382
2451
|
var watcherConfigs = [
|
|
@@ -2468,7 +2537,22 @@ var watcherConfigs = [
|
|
|
2468
2537
|
hashKey: "layoutConfigHash"
|
|
2469
2538
|
}
|
|
2470
2539
|
]
|
|
2471
|
-
}
|
|
2540
|
+
},
|
|
2541
|
+
...SEARCH_ENTITY_FILES.map(
|
|
2542
|
+
(subdirectory) => ({
|
|
2543
|
+
subdirectory,
|
|
2544
|
+
hashGenerator: async (sources) => ({
|
|
2545
|
+
searchEntityHash: await generateSearchEntityHash(sources)
|
|
2546
|
+
}),
|
|
2547
|
+
modules: [
|
|
2548
|
+
{
|
|
2549
|
+
virtualModule: vmod.virtual.searchEntity,
|
|
2550
|
+
resolvedModule: vmod.resolved.searchEntity,
|
|
2551
|
+
hashKey: "searchEntityHash"
|
|
2552
|
+
}
|
|
2553
|
+
]
|
|
2554
|
+
})
|
|
2555
|
+
)
|
|
2472
2556
|
];
|
|
2473
2557
|
|
|
2474
2558
|
// src/index.ts
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/plugin.ts
|
|
2
2
|
import { rm, writeFile } from "fs/promises";
|
|
3
|
-
import
|
|
3
|
+
import path5 from "path";
|
|
4
4
|
|
|
5
5
|
// src/cell-renderers/generate-cell-renderer-hash.ts
|
|
6
6
|
import fs from "fs/promises";
|
|
@@ -62,12 +62,12 @@ function generateModule(code) {
|
|
|
62
62
|
var VALID_FILE_EXTENSIONS = [".tsx", ".jsx", ".js", ".ts"];
|
|
63
63
|
async function crawl(dir, file, depth) {
|
|
64
64
|
const dirDepth = dir.split(path.sep).length;
|
|
65
|
-
const crawler = new fdir().withBasePath().exclude((dirName) => dirName.startsWith("_")).filter((
|
|
66
|
-
return VALID_FILE_EXTENSIONS.some((ext) =>
|
|
65
|
+
const crawler = new fdir().withBasePath().exclude((dirName) => dirName.startsWith("_")).filter((path6) => {
|
|
66
|
+
return VALID_FILE_EXTENSIONS.some((ext) => path6.endsWith(ext));
|
|
67
67
|
});
|
|
68
68
|
if (file) {
|
|
69
|
-
crawler.filter((
|
|
70
|
-
return VALID_FILE_EXTENSIONS.some((ext) =>
|
|
69
|
+
crawler.filter((path6) => {
|
|
70
|
+
return VALID_FILE_EXTENSIONS.some((ext) => path6.endsWith(file + ext));
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
if (depth) {
|
|
@@ -84,15 +84,15 @@ async function crawl(dir, file, depth) {
|
|
|
84
84
|
}
|
|
85
85
|
return crawler.crawl(dir).withPromise();
|
|
86
86
|
}
|
|
87
|
-
function getConfigObjectProperties(
|
|
88
|
-
if (isVariableDeclarator(
|
|
89
|
-
const configDeclaration = isIdentifier(
|
|
87
|
+
function getConfigObjectProperties(path6) {
|
|
88
|
+
if (isVariableDeclarator(path6.node)) {
|
|
89
|
+
const configDeclaration = isIdentifier(path6.node.id, { name: "config" }) ? path6.node : null;
|
|
90
90
|
if (configDeclaration && isCallExpression(configDeclaration.init) && configDeclaration.init.arguments.length > 0 && isObjectExpression(configDeclaration.init.arguments[0])) {
|
|
91
91
|
return configDeclaration.init.arguments[0].properties;
|
|
92
92
|
}
|
|
93
93
|
return null;
|
|
94
94
|
}
|
|
95
|
-
const declaration =
|
|
95
|
+
const declaration = path6.node.declaration;
|
|
96
96
|
if (isVariableDeclaration(declaration)) {
|
|
97
97
|
const configDeclaration = declaration.declarations.find(
|
|
98
98
|
(d) => isVariableDeclarator(d) && isIdentifier(d.id, { name: "config" })
|
|
@@ -109,13 +109,13 @@ async function hasDefaultExport(ast) {
|
|
|
109
109
|
ExportDefaultDeclaration() {
|
|
110
110
|
hasDefaultExport2 = true;
|
|
111
111
|
},
|
|
112
|
-
AssignmentExpression(
|
|
113
|
-
if (
|
|
112
|
+
AssignmentExpression(path6) {
|
|
113
|
+
if (path6.node.left.type === "MemberExpression" && path6.node.left.object.type === "Identifier" && path6.node.left.object.name === "exports" && path6.node.left.property.type === "Identifier" && path6.node.left.property.name === "default") {
|
|
114
114
|
hasDefaultExport2 = true;
|
|
115
115
|
}
|
|
116
116
|
},
|
|
117
|
-
ExportNamedDeclaration(
|
|
118
|
-
const specifiers =
|
|
117
|
+
ExportNamedDeclaration(path6) {
|
|
118
|
+
const specifiers = path6.node.specifiers;
|
|
119
119
|
if (specifiers?.some(
|
|
120
120
|
(s) => s.type === "ExportSpecifier" && s.exported.type === "Identifier" && s.exported.name === "default"
|
|
121
121
|
)) {
|
|
@@ -206,8 +206,8 @@ var logger = {
|
|
|
206
206
|
import {
|
|
207
207
|
isValidCustomFieldModel
|
|
208
208
|
} from "@medusajs/admin-shared";
|
|
209
|
-
function getModel(
|
|
210
|
-
const configArgument = getConfigArgument(
|
|
209
|
+
function getModel(path6, file) {
|
|
210
|
+
const configArgument = getConfigArgument(path6);
|
|
211
211
|
if (!configArgument) {
|
|
212
212
|
return null;
|
|
213
213
|
}
|
|
@@ -241,23 +241,23 @@ function getModel(path5, file) {
|
|
|
241
241
|
}
|
|
242
242
|
return model;
|
|
243
243
|
}
|
|
244
|
-
function getConfigArgument(
|
|
245
|
-
if (!isCallExpression(
|
|
244
|
+
function getConfigArgument(path6) {
|
|
245
|
+
if (!isCallExpression(path6.node.declaration)) {
|
|
246
246
|
return null;
|
|
247
247
|
}
|
|
248
|
-
if (!isIdentifier(
|
|
248
|
+
if (!isIdentifier(path6.node.declaration.callee, {
|
|
249
249
|
name: "unstable_defineCustomFieldsConfig"
|
|
250
250
|
})) {
|
|
251
251
|
return null;
|
|
252
252
|
}
|
|
253
|
-
const configArgument =
|
|
253
|
+
const configArgument = path6.node.declaration.arguments[0];
|
|
254
254
|
if (!isObjectExpression(configArgument)) {
|
|
255
255
|
return null;
|
|
256
256
|
}
|
|
257
257
|
return configArgument;
|
|
258
258
|
}
|
|
259
|
-
function validateLink(
|
|
260
|
-
const configArgument = getConfigArgument(
|
|
259
|
+
function validateLink(path6, file) {
|
|
260
|
+
const configArgument = getConfigArgument(path6);
|
|
261
261
|
if (!configArgument) {
|
|
262
262
|
return false;
|
|
263
263
|
}
|
|
@@ -347,14 +347,14 @@ async function parseDisplayFile(file, index) {
|
|
|
347
347
|
let hasLink = false;
|
|
348
348
|
try {
|
|
349
349
|
traverse(ast, {
|
|
350
|
-
ExportDefaultDeclaration(
|
|
351
|
-
const _model = getModel(
|
|
350
|
+
ExportDefaultDeclaration(path6) {
|
|
351
|
+
const _model = getModel(path6, file);
|
|
352
352
|
if (!_model) {
|
|
353
353
|
return;
|
|
354
354
|
}
|
|
355
355
|
model = _model;
|
|
356
|
-
displays = getDisplays(
|
|
357
|
-
hasLink = validateLink(
|
|
356
|
+
displays = getDisplays(path6, model, index, file);
|
|
357
|
+
hasLink = validateLink(path6, file);
|
|
358
358
|
}
|
|
359
359
|
});
|
|
360
360
|
} catch (err) {
|
|
@@ -378,8 +378,8 @@ async function parseDisplayFile(file, index) {
|
|
|
378
378
|
displays
|
|
379
379
|
};
|
|
380
380
|
}
|
|
381
|
-
function getDisplays(
|
|
382
|
-
const configArgument = getConfigArgument(
|
|
381
|
+
function getDisplays(path6, model, index, file) {
|
|
382
|
+
const configArgument = getConfigArgument(path6);
|
|
383
383
|
if (!configArgument) {
|
|
384
384
|
return null;
|
|
385
385
|
}
|
|
@@ -455,8 +455,8 @@ function generateCustomFieldConfigName(index) {
|
|
|
455
455
|
return `CustomFieldConfig${index}`;
|
|
456
456
|
}
|
|
457
457
|
function generateImport(file, index) {
|
|
458
|
-
const
|
|
459
|
-
return `import ${generateCustomFieldConfigName(index)} from "${
|
|
458
|
+
const path6 = normalizePath(file);
|
|
459
|
+
return `import ${generateCustomFieldConfigName(index)} from "${path6}"`;
|
|
460
460
|
}
|
|
461
461
|
|
|
462
462
|
// src/custom-fields/generate-custom-field-forms.ts
|
|
@@ -581,15 +581,15 @@ async function parseFile(file, index) {
|
|
|
581
581
|
let hasLink = false;
|
|
582
582
|
try {
|
|
583
583
|
traverse(ast, {
|
|
584
|
-
ExportDefaultDeclaration(
|
|
585
|
-
const _model = getModel(
|
|
584
|
+
ExportDefaultDeclaration(path6) {
|
|
585
|
+
const _model = getModel(path6, file);
|
|
586
586
|
if (!_model) {
|
|
587
587
|
return;
|
|
588
588
|
}
|
|
589
589
|
model = _model;
|
|
590
|
-
hasLink = validateLink(
|
|
591
|
-
configs = getConfigs(
|
|
592
|
-
forms = getForms(
|
|
590
|
+
hasLink = validateLink(path6, file);
|
|
591
|
+
configs = getConfigs(path6, model, index, file);
|
|
592
|
+
forms = getForms(path6, model, index, file);
|
|
593
593
|
}
|
|
594
594
|
});
|
|
595
595
|
} catch (err) {
|
|
@@ -618,11 +618,11 @@ function generateCustomFieldConfigName2(index) {
|
|
|
618
618
|
return `CustomFieldConfig${index}`;
|
|
619
619
|
}
|
|
620
620
|
function generateImport2(file, index) {
|
|
621
|
-
const
|
|
622
|
-
return `import ${generateCustomFieldConfigName2(index)} from "${
|
|
621
|
+
const path6 = normalizePath(file);
|
|
622
|
+
return `import ${generateCustomFieldConfigName2(index)} from "${path6}"`;
|
|
623
623
|
}
|
|
624
|
-
function getForms(
|
|
625
|
-
const formArray = getFormsArgument(
|
|
624
|
+
function getForms(path6, model, index, file) {
|
|
625
|
+
const formArray = getFormsArgument(path6, file);
|
|
626
626
|
if (!formArray) {
|
|
627
627
|
return null;
|
|
628
628
|
}
|
|
@@ -786,8 +786,8 @@ function getFormFieldSectionValue(exists, fileIndex, formIndex, fieldKey, value)
|
|
|
786
786
|
function getFormEntryFieldPath(model, zone, tab) {
|
|
787
787
|
return `${model}.${zone}.${tab ? `${tab}.` : ""}$field`;
|
|
788
788
|
}
|
|
789
|
-
function getConfigs(
|
|
790
|
-
const formArray = getFormsArgument(
|
|
789
|
+
function getConfigs(path6, model, index, file) {
|
|
790
|
+
const formArray = getFormsArgument(path6, file);
|
|
791
791
|
if (!formArray) {
|
|
792
792
|
logger.warn(`'forms' property is missing.`, { file });
|
|
793
793
|
return null;
|
|
@@ -906,8 +906,8 @@ function getFormFieldValue(fileIndex, formIndex, fieldKey, value) {
|
|
|
906
906
|
function getFormEntryConfigPath(model, zone) {
|
|
907
907
|
return `${model}.${zone}.$config`;
|
|
908
908
|
}
|
|
909
|
-
function getFormsArgument(
|
|
910
|
-
const configArgument = getConfigArgument(
|
|
909
|
+
function getFormsArgument(path6, file) {
|
|
910
|
+
const configArgument = getConfigArgument(path6);
|
|
911
911
|
if (!configArgument) {
|
|
912
912
|
return null;
|
|
913
913
|
}
|
|
@@ -968,8 +968,8 @@ async function getCustomFieldContents(file) {
|
|
|
968
968
|
let displayContent = null;
|
|
969
969
|
try {
|
|
970
970
|
traverse(ast, {
|
|
971
|
-
ExportDefaultDeclaration(
|
|
972
|
-
const configArgument = getConfigArgument(
|
|
971
|
+
ExportDefaultDeclaration(path6) {
|
|
972
|
+
const configArgument = getConfigArgument(path6);
|
|
973
973
|
if (!configArgument) {
|
|
974
974
|
return;
|
|
975
975
|
}
|
|
@@ -1063,13 +1063,13 @@ async function parseFile2(file, index) {
|
|
|
1063
1063
|
let model = null;
|
|
1064
1064
|
try {
|
|
1065
1065
|
traverse(ast, {
|
|
1066
|
-
ExportDefaultDeclaration(
|
|
1067
|
-
const _model = getModel(
|
|
1066
|
+
ExportDefaultDeclaration(path6) {
|
|
1067
|
+
const _model = getModel(path6, file);
|
|
1068
1068
|
if (!_model) {
|
|
1069
1069
|
return;
|
|
1070
1070
|
}
|
|
1071
1071
|
model = _model;
|
|
1072
|
-
link = getLink(
|
|
1072
|
+
link = getLink(path6, index, file);
|
|
1073
1073
|
}
|
|
1074
1074
|
});
|
|
1075
1075
|
} catch (err) {
|
|
@@ -1092,11 +1092,11 @@ function generateCustomFieldConfigName3(index) {
|
|
|
1092
1092
|
return `CustomFieldConfig${index}`;
|
|
1093
1093
|
}
|
|
1094
1094
|
function generateImport3(file, index) {
|
|
1095
|
-
const
|
|
1096
|
-
return `import ${generateCustomFieldConfigName3(index)} from "${
|
|
1095
|
+
const path6 = normalizePath(file);
|
|
1096
|
+
return `import ${generateCustomFieldConfigName3(index)} from "${path6}"`;
|
|
1097
1097
|
}
|
|
1098
|
-
function getLink(
|
|
1099
|
-
const configArgument = getConfigArgument(
|
|
1098
|
+
function getLink(path6, index, file) {
|
|
1099
|
+
const configArgument = getConfigArgument(path6);
|
|
1100
1100
|
if (!configArgument) {
|
|
1101
1101
|
return null;
|
|
1102
1102
|
}
|
|
@@ -1235,11 +1235,11 @@ async function parseFile3(file, index) {
|
|
|
1235
1235
|
function hasConfigExport(ast) {
|
|
1236
1236
|
let found = false;
|
|
1237
1237
|
traverse(ast, {
|
|
1238
|
-
ExportNamedDeclaration(
|
|
1238
|
+
ExportNamedDeclaration(path6) {
|
|
1239
1239
|
if (found) {
|
|
1240
1240
|
return;
|
|
1241
1241
|
}
|
|
1242
|
-
if (getConfigObjectProperties(
|
|
1242
|
+
if (getConfigObjectProperties(path6)) {
|
|
1243
1243
|
found = true;
|
|
1244
1244
|
}
|
|
1245
1245
|
}
|
|
@@ -1247,8 +1247,8 @@ function hasConfigExport(ast) {
|
|
|
1247
1247
|
return found;
|
|
1248
1248
|
}
|
|
1249
1249
|
function generateImport4(file, componentName, configName) {
|
|
1250
|
-
const
|
|
1251
|
-
return `import ${componentName}, { config as ${configName} } from "${
|
|
1250
|
+
const path6 = normalizePath(file);
|
|
1251
|
+
return `import ${componentName}, { config as ${configName} } from "${path6}"`;
|
|
1252
1252
|
}
|
|
1253
1253
|
|
|
1254
1254
|
// src/layouts/generate-layout-hash.ts
|
|
@@ -1298,11 +1298,11 @@ function generateCode4(results) {
|
|
|
1298
1298
|
`;
|
|
1299
1299
|
}
|
|
1300
1300
|
function formatMenuItem(route) {
|
|
1301
|
-
const { label, icon, path:
|
|
1301
|
+
const { label, icon, path: path6, nested, rank, translationNs } = route;
|
|
1302
1302
|
return `{
|
|
1303
1303
|
label: ${label},
|
|
1304
1304
|
icon: ${icon || "undefined"},
|
|
1305
|
-
path: "${
|
|
1305
|
+
path: "${path6}",
|
|
1306
1306
|
nested: ${nested ? `"${nested}"` : "undefined"},
|
|
1307
1307
|
rank: ${rank !== void 0 ? rank : "undefined"},
|
|
1308
1308
|
translationNs: ${translationNs ? `${translationNs}` : "undefined"}
|
|
@@ -1338,8 +1338,8 @@ async function parseFile4(file, index) {
|
|
|
1338
1338
|
};
|
|
1339
1339
|
}
|
|
1340
1340
|
function generateImport5(file, index) {
|
|
1341
|
-
const
|
|
1342
|
-
return `import { config as ${generateRouteConfigName(index)} } from "${
|
|
1341
|
+
const path6 = normalizePath(file);
|
|
1342
|
+
return `import { config as ${generateRouteConfigName(index)} } from "${path6}"`;
|
|
1343
1343
|
}
|
|
1344
1344
|
function generateMenuItem(config, file, index) {
|
|
1345
1345
|
const configName = generateRouteConfigName(index);
|
|
@@ -1372,11 +1372,11 @@ async function getRouteConfig(file) {
|
|
|
1372
1372
|
* For bundled files, the config will not be a named export,
|
|
1373
1373
|
* but instead a variable declaration.
|
|
1374
1374
|
*/
|
|
1375
|
-
VariableDeclarator(
|
|
1375
|
+
VariableDeclarator(path6) {
|
|
1376
1376
|
if (configFound) {
|
|
1377
1377
|
return;
|
|
1378
1378
|
}
|
|
1379
|
-
const properties = getConfigObjectProperties(
|
|
1379
|
+
const properties = getConfigObjectProperties(path6);
|
|
1380
1380
|
if (!properties) {
|
|
1381
1381
|
return;
|
|
1382
1382
|
}
|
|
@@ -1388,11 +1388,11 @@ async function getRouteConfig(file) {
|
|
|
1388
1388
|
/**
|
|
1389
1389
|
* For unbundled files, the `config` will always be a named export.
|
|
1390
1390
|
*/
|
|
1391
|
-
ExportNamedDeclaration(
|
|
1391
|
+
ExportNamedDeclaration(path6) {
|
|
1392
1392
|
if (configFound) {
|
|
1393
1393
|
return;
|
|
1394
1394
|
}
|
|
1395
|
-
const properties = getConfigObjectProperties(
|
|
1395
|
+
const properties = getConfigObjectProperties(path6);
|
|
1396
1396
|
if (!properties) {
|
|
1397
1397
|
return;
|
|
1398
1398
|
}
|
|
@@ -1497,13 +1497,13 @@ async function getRouteContents(file) {
|
|
|
1497
1497
|
let configContent = null;
|
|
1498
1498
|
try {
|
|
1499
1499
|
traverse(ast, {
|
|
1500
|
-
ExportDefaultDeclaration(
|
|
1501
|
-
defaultExportContent = code.slice(
|
|
1500
|
+
ExportDefaultDeclaration(path6) {
|
|
1501
|
+
defaultExportContent = code.slice(path6.node.start, path6.node.end);
|
|
1502
1502
|
},
|
|
1503
|
-
ExportNamedDeclaration(
|
|
1504
|
-
const properties = getConfigObjectProperties(
|
|
1503
|
+
ExportNamedDeclaration(path6) {
|
|
1504
|
+
const properties = getConfigObjectProperties(path6);
|
|
1505
1505
|
if (properties) {
|
|
1506
|
-
configContent = code.slice(
|
|
1506
|
+
configContent = code.slice(path6.node.start, path6.node.end);
|
|
1507
1507
|
}
|
|
1508
1508
|
}
|
|
1509
1509
|
});
|
|
@@ -1683,8 +1683,8 @@ async function hasNamedExports(ast, file) {
|
|
|
1683
1683
|
let hasConfig = false;
|
|
1684
1684
|
try {
|
|
1685
1685
|
traverse(ast, {
|
|
1686
|
-
ExportNamedDeclaration(
|
|
1687
|
-
const declaration =
|
|
1686
|
+
ExportNamedDeclaration(path6) {
|
|
1687
|
+
const declaration = path6.node.declaration;
|
|
1688
1688
|
if (declaration?.type === "VariableDeclaration") {
|
|
1689
1689
|
declaration.declarations.forEach((decl) => {
|
|
1690
1690
|
if (decl.id.type === "Identifier" && decl.id.name === "handle") {
|
|
@@ -1712,6 +1712,44 @@ async function hasNamedExports(ast, file) {
|
|
|
1712
1712
|
return { hasHandle, hasLoader, hasConfig };
|
|
1713
1713
|
}
|
|
1714
1714
|
|
|
1715
|
+
// src/search-entities/constants.ts
|
|
1716
|
+
var SEARCH_ENTITY_FILES = [
|
|
1717
|
+
"search-entities.tsx",
|
|
1718
|
+
"search-entities.ts"
|
|
1719
|
+
];
|
|
1720
|
+
|
|
1721
|
+
// src/search-entities/find-search-entity-file.ts
|
|
1722
|
+
import fs12 from "fs/promises";
|
|
1723
|
+
import path3 from "path";
|
|
1724
|
+
async function findSearchEntityFile(source) {
|
|
1725
|
+
for (const fileName of SEARCH_ENTITY_FILES) {
|
|
1726
|
+
const filePath = path3.join(source, fileName);
|
|
1727
|
+
try {
|
|
1728
|
+
await fs12.access(filePath);
|
|
1729
|
+
return filePath;
|
|
1730
|
+
} catch {
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
return null;
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1736
|
+
// src/search-entities/generate-search-entity-hash.ts
|
|
1737
|
+
import fs13 from "fs/promises";
|
|
1738
|
+
async function generateSearchEntityHash(sources) {
|
|
1739
|
+
const contents = [];
|
|
1740
|
+
for (const source of sources) {
|
|
1741
|
+
const searchEntitiesPath = await findSearchEntityFile(source);
|
|
1742
|
+
if (!searchEntitiesPath) {
|
|
1743
|
+
continue;
|
|
1744
|
+
}
|
|
1745
|
+
try {
|
|
1746
|
+
contents.push(await fs13.readFile(searchEntitiesPath, "utf-8"));
|
|
1747
|
+
} catch {
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
return generateHash(contents.join(""));
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1715
1753
|
// src/virtual-modules/generate-virtual-display-module.ts
|
|
1716
1754
|
import { outdent as outdent6 } from "outdent";
|
|
1717
1755
|
async function generateVirtualDisplayModule(sources, pluginMode = false) {
|
|
@@ -1791,7 +1829,7 @@ async function generateVirtualRouteModule(sources, pluginMode = false) {
|
|
|
1791
1829
|
import outdent13 from "outdent";
|
|
1792
1830
|
|
|
1793
1831
|
// src/widgets/generate-widget-hash.ts
|
|
1794
|
-
import
|
|
1832
|
+
import fs14 from "fs/promises";
|
|
1795
1833
|
|
|
1796
1834
|
// src/widgets/helpers.ts
|
|
1797
1835
|
async function getWidgetFilesFromSources(sources) {
|
|
@@ -1808,7 +1846,7 @@ async function generateWidgetHash(sources) {
|
|
|
1808
1846
|
return generateHash(totalContent);
|
|
1809
1847
|
}
|
|
1810
1848
|
async function getWidgetContents(file) {
|
|
1811
|
-
const code = await
|
|
1849
|
+
const code = await fs14.readFile(file, "utf-8");
|
|
1812
1850
|
let ast;
|
|
1813
1851
|
try {
|
|
1814
1852
|
ast = parse(code, getParserOptions(file));
|
|
@@ -1825,14 +1863,14 @@ async function getWidgetContents(file) {
|
|
|
1825
1863
|
let configContent = null;
|
|
1826
1864
|
let defaultExportContent = null;
|
|
1827
1865
|
traverse(ast, {
|
|
1828
|
-
ExportNamedDeclaration(
|
|
1829
|
-
const properties = getConfigObjectProperties(
|
|
1866
|
+
ExportNamedDeclaration(path6) {
|
|
1867
|
+
const properties = getConfigObjectProperties(path6);
|
|
1830
1868
|
if (properties) {
|
|
1831
|
-
configContent = code.slice(
|
|
1869
|
+
configContent = code.slice(path6.node.start, path6.node.end);
|
|
1832
1870
|
}
|
|
1833
1871
|
},
|
|
1834
|
-
ExportDefaultDeclaration(
|
|
1835
|
-
defaultExportContent = code.slice(
|
|
1872
|
+
ExportDefaultDeclaration(path6) {
|
|
1873
|
+
defaultExportContent = code.slice(path6.node.start, path6.node.end);
|
|
1836
1874
|
}
|
|
1837
1875
|
});
|
|
1838
1876
|
return { config: configContent, defaultExport: defaultExportContent };
|
|
@@ -1840,7 +1878,7 @@ async function getWidgetContents(file) {
|
|
|
1840
1878
|
|
|
1841
1879
|
// src/widgets/generate-widgets.ts
|
|
1842
1880
|
import { isValidInjectionZone } from "@medusajs/admin-shared";
|
|
1843
|
-
import
|
|
1881
|
+
import fs15 from "fs/promises";
|
|
1844
1882
|
import outdent12 from "outdent";
|
|
1845
1883
|
async function generateWidgets(sources) {
|
|
1846
1884
|
const files = await getWidgetFilesFromSources(sources);
|
|
@@ -1884,7 +1922,7 @@ function getWidgetId(idOverride, file) {
|
|
|
1884
1922
|
return `Widget-${generateHash(relative).slice(0, 4)}`;
|
|
1885
1923
|
}
|
|
1886
1924
|
async function parseFile6(file, index) {
|
|
1887
|
-
const code = await
|
|
1925
|
+
const code = await fs15.readFile(file, "utf-8");
|
|
1888
1926
|
let ast;
|
|
1889
1927
|
try {
|
|
1890
1928
|
ast = parse(code, getParserOptions(file));
|
|
@@ -1945,10 +1983,10 @@ function generateWidgetConfigName(index) {
|
|
|
1945
1983
|
return `WidgetConfig${index}`;
|
|
1946
1984
|
}
|
|
1947
1985
|
function generateImport6(file, index) {
|
|
1948
|
-
const
|
|
1986
|
+
const path6 = normalizePath(file);
|
|
1949
1987
|
return `import ${generateWidgetComponentName(
|
|
1950
1988
|
index
|
|
1951
|
-
)}, { config as ${generateWidgetConfigName(index)} } from "${
|
|
1989
|
+
)}, { config as ${generateWidgetConfigName(index)} } from "${path6}"`;
|
|
1952
1990
|
}
|
|
1953
1991
|
function generateWidget(zone, index, widgetId) {
|
|
1954
1992
|
return {
|
|
@@ -1960,11 +1998,11 @@ function generateWidget(zone, index, widgetId) {
|
|
|
1960
1998
|
function getWidgetIdOverride(ast) {
|
|
1961
1999
|
let id = null;
|
|
1962
2000
|
let found = false;
|
|
1963
|
-
const readId = (
|
|
2001
|
+
const readId = (path6) => {
|
|
1964
2002
|
if (found) {
|
|
1965
2003
|
return;
|
|
1966
2004
|
}
|
|
1967
|
-
const properties = getConfigObjectProperties(
|
|
2005
|
+
const properties = getConfigObjectProperties(path6);
|
|
1968
2006
|
if (!properties) {
|
|
1969
2007
|
return;
|
|
1970
2008
|
}
|
|
@@ -1993,12 +2031,12 @@ async function getWidgetZone(ast, file) {
|
|
|
1993
2031
|
* not be a named export. Instead we look for a `VariableDeclaration` named
|
|
1994
2032
|
* `config` and extract the `zone` property from it.
|
|
1995
2033
|
*/
|
|
1996
|
-
VariableDeclarator(
|
|
2034
|
+
VariableDeclarator(path6) {
|
|
1997
2035
|
if (zoneFound) {
|
|
1998
2036
|
return;
|
|
1999
2037
|
}
|
|
2000
|
-
if (
|
|
2001
|
-
const arg =
|
|
2038
|
+
if (path6.node.id.type === "Identifier" && path6.node.id.name === "config" && path6.node.init?.type === "CallExpression") {
|
|
2039
|
+
const arg = path6.node.init.arguments[0];
|
|
2002
2040
|
if (arg?.type === "ObjectExpression") {
|
|
2003
2041
|
const zoneProperty = arg.properties.find(
|
|
2004
2042
|
(p) => p.type === "ObjectProperty" && p.key.name === "zone"
|
|
@@ -2013,11 +2051,11 @@ async function getWidgetZone(ast, file) {
|
|
|
2013
2051
|
/**
|
|
2014
2052
|
* For unbundled files, the `config` will always be a named export.
|
|
2015
2053
|
*/
|
|
2016
|
-
ExportNamedDeclaration(
|
|
2054
|
+
ExportNamedDeclaration(path6) {
|
|
2017
2055
|
if (zoneFound) {
|
|
2018
2056
|
return;
|
|
2019
2057
|
}
|
|
2020
|
-
const declaration =
|
|
2058
|
+
const declaration = path6.node.declaration;
|
|
2021
2059
|
if (declaration?.type === "VariableDeclaration" && declaration.declarations[0]?.type === "VariableDeclarator" && declaration.declarations[0].id.type === "Identifier" && declaration.declarations[0].id.name === "config" && declaration.declarations[0].init?.type === "CallExpression") {
|
|
2022
2060
|
const arg = declaration.declarations[0].init.arguments[0];
|
|
2023
2061
|
if (arg?.type === "ObjectExpression") {
|
|
@@ -2094,14 +2132,14 @@ async function generateVirtualI18nModule(sources, pluginMode = false) {
|
|
|
2094
2132
|
|
|
2095
2133
|
// src/virtual-modules/generate-virtual-cell-renderer-module.ts
|
|
2096
2134
|
import outdent15 from "outdent";
|
|
2097
|
-
import
|
|
2098
|
-
import
|
|
2135
|
+
import fs16 from "fs/promises";
|
|
2136
|
+
import path4 from "path";
|
|
2099
2137
|
async function generateVirtualCellRendererModule(sources, pluginMode = false) {
|
|
2100
2138
|
const imports = [];
|
|
2101
2139
|
for (const source of sources) {
|
|
2102
|
-
const cellRenderersPath =
|
|
2140
|
+
const cellRenderersPath = path4.join(source, "cell-renderers.tsx");
|
|
2103
2141
|
try {
|
|
2104
|
-
await
|
|
2142
|
+
await fs16.access(cellRenderersPath);
|
|
2105
2143
|
imports.push(`import "${cellRenderersPath}"`);
|
|
2106
2144
|
} catch {
|
|
2107
2145
|
}
|
|
@@ -2114,6 +2152,24 @@ async function generateVirtualCellRendererModule(sources, pluginMode = false) {
|
|
|
2114
2152
|
return generateModule(code);
|
|
2115
2153
|
}
|
|
2116
2154
|
|
|
2155
|
+
// src/virtual-modules/generate-virtual-search-entity-module.ts
|
|
2156
|
+
import outdent16 from "outdent";
|
|
2157
|
+
async function generateVirtualSearchEntityModule(sources, pluginMode = false) {
|
|
2158
|
+
const imports = [];
|
|
2159
|
+
for (const source of sources) {
|
|
2160
|
+
const searchEntitiesPath = await findSearchEntityFile(source);
|
|
2161
|
+
if (searchEntitiesPath) {
|
|
2162
|
+
imports.push(`import "${normalizePath(searchEntitiesPath)}"`);
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
const code = outdent16`
|
|
2166
|
+
${imports.join("\n")}
|
|
2167
|
+
|
|
2168
|
+
${pluginMode ? `const searchEntityModule = {}` : `export default {}`}
|
|
2169
|
+
`;
|
|
2170
|
+
return generateModule(code);
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2117
2173
|
// src/vmod.ts
|
|
2118
2174
|
import {
|
|
2119
2175
|
CELL_RENDERER_VIRTUAL_MODULE,
|
|
@@ -2124,6 +2180,7 @@ import {
|
|
|
2124
2180
|
LINK_VIRTUAL_MODULE,
|
|
2125
2181
|
MENU_ITEM_VIRTUAL_MODULE,
|
|
2126
2182
|
ROUTE_VIRTUAL_MODULE,
|
|
2183
|
+
SEARCH_ENTITY_VIRTUAL_MODULE,
|
|
2127
2184
|
WIDGET_VIRTUAL_MODULE
|
|
2128
2185
|
} from "@medusajs/admin-shared";
|
|
2129
2186
|
var RESOLVED_LINK_VIRTUAL_MODULE = `\0${LINK_VIRTUAL_MODULE}`;
|
|
@@ -2135,6 +2192,7 @@ var RESOLVED_WIDGET_VIRTUAL_MODULE = `\0${WIDGET_VIRTUAL_MODULE}`;
|
|
|
2135
2192
|
var RESOLVED_I18N_VIRTUAL_MODULE = `\0${I18N_VIRTUAL_MODULE}`;
|
|
2136
2193
|
var RESOLVED_CELL_RENDERER_VIRTUAL_MODULE = `\0${CELL_RENDERER_VIRTUAL_MODULE}`;
|
|
2137
2194
|
var RESOLVED_LAYOUT_VIRTUAL_MODULE = `\0${LAYOUT_VIRTUAL_MODULE}`;
|
|
2195
|
+
var RESOLVED_SEARCH_ENTITY_VIRTUAL_MODULE = `\0${SEARCH_ENTITY_VIRTUAL_MODULE}`;
|
|
2138
2196
|
var VIRTUAL_MODULES = [
|
|
2139
2197
|
LINK_VIRTUAL_MODULE,
|
|
2140
2198
|
FORM_VIRTUAL_MODULE,
|
|
@@ -2144,7 +2202,8 @@ var VIRTUAL_MODULES = [
|
|
|
2144
2202
|
WIDGET_VIRTUAL_MODULE,
|
|
2145
2203
|
I18N_VIRTUAL_MODULE,
|
|
2146
2204
|
CELL_RENDERER_VIRTUAL_MODULE,
|
|
2147
|
-
LAYOUT_VIRTUAL_MODULE
|
|
2205
|
+
LAYOUT_VIRTUAL_MODULE,
|
|
2206
|
+
SEARCH_ENTITY_VIRTUAL_MODULE
|
|
2148
2207
|
];
|
|
2149
2208
|
var RESOLVED_VIRTUAL_MODULES = [
|
|
2150
2209
|
RESOLVED_LINK_VIRTUAL_MODULE,
|
|
@@ -2155,7 +2214,8 @@ var RESOLVED_VIRTUAL_MODULES = [
|
|
|
2155
2214
|
RESOLVED_WIDGET_VIRTUAL_MODULE,
|
|
2156
2215
|
RESOLVED_I18N_VIRTUAL_MODULE,
|
|
2157
2216
|
RESOLVED_CELL_RENDERER_VIRTUAL_MODULE,
|
|
2158
|
-
RESOLVED_LAYOUT_VIRTUAL_MODULE
|
|
2217
|
+
RESOLVED_LAYOUT_VIRTUAL_MODULE,
|
|
2218
|
+
RESOLVED_SEARCH_ENTITY_VIRTUAL_MODULE
|
|
2159
2219
|
];
|
|
2160
2220
|
function resolveVirtualId(id) {
|
|
2161
2221
|
return `\0${id}`;
|
|
@@ -2177,7 +2237,8 @@ var resolvedVirtualModuleIds = {
|
|
|
2177
2237
|
widget: RESOLVED_WIDGET_VIRTUAL_MODULE,
|
|
2178
2238
|
i18n: RESOLVED_I18N_VIRTUAL_MODULE,
|
|
2179
2239
|
cellRenderer: RESOLVED_CELL_RENDERER_VIRTUAL_MODULE,
|
|
2180
|
-
layout: RESOLVED_LAYOUT_VIRTUAL_MODULE
|
|
2240
|
+
layout: RESOLVED_LAYOUT_VIRTUAL_MODULE,
|
|
2241
|
+
searchEntity: RESOLVED_SEARCH_ENTITY_VIRTUAL_MODULE
|
|
2181
2242
|
};
|
|
2182
2243
|
var virtualModuleIds = {
|
|
2183
2244
|
link: LINK_VIRTUAL_MODULE,
|
|
@@ -2188,7 +2249,8 @@ var virtualModuleIds = {
|
|
|
2188
2249
|
widget: WIDGET_VIRTUAL_MODULE,
|
|
2189
2250
|
i18n: I18N_VIRTUAL_MODULE,
|
|
2190
2251
|
cellRenderer: CELL_RENDERER_VIRTUAL_MODULE,
|
|
2191
|
-
layout: LAYOUT_VIRTUAL_MODULE
|
|
2252
|
+
layout: LAYOUT_VIRTUAL_MODULE,
|
|
2253
|
+
searchEntity: SEARCH_ENTITY_VIRTUAL_MODULE
|
|
2192
2254
|
};
|
|
2193
2255
|
var vmod = {
|
|
2194
2256
|
resolved: resolvedVirtualModuleIds,
|
|
@@ -2203,7 +2265,7 @@ var medusaVitePlugin = (options) => {
|
|
|
2203
2265
|
let watcher;
|
|
2204
2266
|
function isFileInSources(file) {
|
|
2205
2267
|
for (const source of _sources) {
|
|
2206
|
-
if (file.startsWith(
|
|
2268
|
+
if (file.startsWith(path5.resolve(source))) {
|
|
2207
2269
|
return true;
|
|
2208
2270
|
}
|
|
2209
2271
|
}
|
|
@@ -2238,6 +2300,7 @@ var medusaVitePlugin = (options) => {
|
|
|
2238
2300
|
const i18nModule = await generateVirtualI18nModule(sources, true);
|
|
2239
2301
|
const cellRendererModule = await generateVirtualCellRendererModule(sources, true);
|
|
2240
2302
|
const layoutModule = await generateVirtualLayoutModule(sources, true);
|
|
2303
|
+
const searchEntityModule = await generateVirtualSearchEntityModule(sources, true);
|
|
2241
2304
|
return `
|
|
2242
2305
|
// Auto-generated index file for Medusa Admin UI extensions
|
|
2243
2306
|
${widgetModule.code}
|
|
@@ -2248,6 +2311,7 @@ var medusaVitePlugin = (options) => {
|
|
|
2248
2311
|
${i18nModule.code}
|
|
2249
2312
|
${cellRendererModule.code}
|
|
2250
2313
|
${layoutModule.code}
|
|
2314
|
+
${searchEntityModule.code}
|
|
2251
2315
|
|
|
2252
2316
|
const plugin = {
|
|
2253
2317
|
widgetModule,
|
|
@@ -2257,13 +2321,14 @@ var medusaVitePlugin = (options) => {
|
|
|
2257
2321
|
displayModule,
|
|
2258
2322
|
i18nModule,
|
|
2259
2323
|
cellRendererModule,
|
|
2260
|
-
layoutModule
|
|
2324
|
+
layoutModule,
|
|
2325
|
+
searchEntityModule
|
|
2261
2326
|
}
|
|
2262
2327
|
|
|
2263
2328
|
export default plugin
|
|
2264
2329
|
`;
|
|
2265
2330
|
}
|
|
2266
|
-
const pluginEntryFile =
|
|
2331
|
+
const pluginEntryFile = path5.resolve(
|
|
2267
2332
|
process.cwd(),
|
|
2268
2333
|
"src/admin/__admin-extensions__.js"
|
|
2269
2334
|
);
|
|
@@ -2378,6 +2443,11 @@ var loadConfigs = {
|
|
|
2378
2443
|
hashGenerator: async (sources) => generateLayoutHash(sources),
|
|
2379
2444
|
moduleGenerator: async (sources) => generateVirtualLayoutModule(sources),
|
|
2380
2445
|
hashKey: vmod.virtual.layout
|
|
2446
|
+
},
|
|
2447
|
+
[vmod.resolved.searchEntity]: {
|
|
2448
|
+
hashGenerator: async (sources) => generateSearchEntityHash(sources),
|
|
2449
|
+
moduleGenerator: async (sources) => generateVirtualSearchEntityModule(sources),
|
|
2450
|
+
hashKey: vmod.virtual.searchEntity
|
|
2381
2451
|
}
|
|
2382
2452
|
};
|
|
2383
2453
|
var watcherConfigs = [
|
|
@@ -2469,7 +2539,22 @@ var watcherConfigs = [
|
|
|
2469
2539
|
hashKey: "layoutConfigHash"
|
|
2470
2540
|
}
|
|
2471
2541
|
]
|
|
2472
|
-
}
|
|
2542
|
+
},
|
|
2543
|
+
...SEARCH_ENTITY_FILES.map(
|
|
2544
|
+
(subdirectory) => ({
|
|
2545
|
+
subdirectory,
|
|
2546
|
+
hashGenerator: async (sources) => ({
|
|
2547
|
+
searchEntityHash: await generateSearchEntityHash(sources)
|
|
2548
|
+
}),
|
|
2549
|
+
modules: [
|
|
2550
|
+
{
|
|
2551
|
+
virtualModule: vmod.virtual.searchEntity,
|
|
2552
|
+
resolvedModule: vmod.resolved.searchEntity,
|
|
2553
|
+
hashKey: "searchEntityHash"
|
|
2554
|
+
}
|
|
2555
|
+
]
|
|
2556
|
+
})
|
|
2557
|
+
)
|
|
2473
2558
|
];
|
|
2474
2559
|
|
|
2475
2560
|
// src/index.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medusajs/admin-vite-plugin",
|
|
3
|
-
"version": "2.19.
|
|
3
|
+
"version": "2.19.1-preview-20260813160157",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@babel/parser": "7.25.6",
|
|
40
40
|
"@babel/traverse": "7.25.6",
|
|
41
41
|
"@babel/types": "7.25.6",
|
|
42
|
-
"@medusajs/admin-shared": "2.19.
|
|
42
|
+
"@medusajs/admin-shared": "2.19.1-preview-20260813160157",
|
|
43
43
|
"fdir": "6.1.1",
|
|
44
44
|
"magic-string": "0.30.5",
|
|
45
45
|
"outdent": "^0.8.0",
|