@medusajs/admin-vite-plugin 2.6.0-snapshot-20250221153919 → 3.0.0-preview-20250211091350
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 +20 -103
- package/dist/index.mjs +20 -103
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1354,25 +1354,9 @@ function generateCode4(results) {
|
|
|
1354
1354
|
`;
|
|
1355
1355
|
}
|
|
1356
1356
|
function formatRoute(route) {
|
|
1357
|
-
|
|
1357
|
+
return `{
|
|
1358
1358
|
Component: ${route.Component},
|
|
1359
|
-
path: "${route.path}"
|
|
1360
|
-
if (route.handle) {
|
|
1361
|
-
base += `,
|
|
1362
|
-
handle: ${route.handle}`;
|
|
1363
|
-
}
|
|
1364
|
-
if (route.loader) {
|
|
1365
|
-
base += `,
|
|
1366
|
-
loader: ${route.loader}`;
|
|
1367
|
-
}
|
|
1368
|
-
if (route.children?.length) {
|
|
1369
|
-
return `${base},
|
|
1370
|
-
children: [
|
|
1371
|
-
${route.children.map((child) => formatRoute(child)).join(",\n ")}
|
|
1372
|
-
]
|
|
1373
|
-
}`;
|
|
1374
|
-
}
|
|
1375
|
-
return `${base}
|
|
1359
|
+
path: "${route.path}",
|
|
1376
1360
|
}`;
|
|
1377
1361
|
}
|
|
1378
1362
|
async function getFilesFromSources7(sources) {
|
|
@@ -1387,29 +1371,21 @@ async function getRouteResults(files) {
|
|
|
1387
1371
|
const results = (await Promise.all(files.map(parseFile4))).filter(
|
|
1388
1372
|
(result) => result !== null
|
|
1389
1373
|
);
|
|
1390
|
-
|
|
1391
|
-
results.forEach((result) => {
|
|
1392
|
-
const routePath = result.route.path;
|
|
1393
|
-
const isParallel = routePath.includes("/@");
|
|
1394
|
-
if (isParallel) {
|
|
1395
|
-
const parentPath = routePath.split("/@")[0];
|
|
1396
|
-
const parent = routeMap.get(parentPath);
|
|
1397
|
-
if (parent) {
|
|
1398
|
-
parent.route.children = parent.route.children || [];
|
|
1399
|
-
const finalRoute = {
|
|
1400
|
-
...result.route,
|
|
1401
|
-
path: result.route.path.replace("@", "")
|
|
1402
|
-
};
|
|
1403
|
-
parent.route.children.push(finalRoute);
|
|
1404
|
-
parent.imports.push(...result.imports);
|
|
1405
|
-
}
|
|
1406
|
-
} else {
|
|
1407
|
-
routeMap.set(routePath, result);
|
|
1408
|
-
}
|
|
1409
|
-
});
|
|
1410
|
-
return Array.from(routeMap.values());
|
|
1374
|
+
return results;
|
|
1411
1375
|
}
|
|
1412
1376
|
async function parseFile4(file, index) {
|
|
1377
|
+
if (!await isValidRouteFile(file)) {
|
|
1378
|
+
return null;
|
|
1379
|
+
}
|
|
1380
|
+
const routePath = getRoute(file);
|
|
1381
|
+
const imports = generateImports(file, index);
|
|
1382
|
+
const route = generateRoute(routePath, index);
|
|
1383
|
+
return {
|
|
1384
|
+
imports,
|
|
1385
|
+
route
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
async function isValidRouteFile(file) {
|
|
1413
1389
|
const code = await import_promises7.default.readFile(file, "utf-8");
|
|
1414
1390
|
let ast = null;
|
|
1415
1391
|
try {
|
|
@@ -1419,21 +1395,8 @@ async function parseFile4(file, index) {
|
|
|
1419
1395
|
file,
|
|
1420
1396
|
error: e
|
|
1421
1397
|
});
|
|
1422
|
-
return
|
|
1423
|
-
}
|
|
1424
|
-
if (!await isValidRouteFile(ast, file)) {
|
|
1425
|
-
return null;
|
|
1398
|
+
return false;
|
|
1426
1399
|
}
|
|
1427
|
-
const { hasHandle, hasLoader } = await hasNamedExports(ast, file);
|
|
1428
|
-
const routePath = getRoute(file);
|
|
1429
|
-
const imports = generateImports(file, index, hasHandle, hasLoader);
|
|
1430
|
-
const route = generateRoute(routePath, index, hasHandle, hasLoader);
|
|
1431
|
-
return {
|
|
1432
|
-
imports,
|
|
1433
|
-
route
|
|
1434
|
-
};
|
|
1435
|
-
}
|
|
1436
|
-
async function isValidRouteFile(ast, file) {
|
|
1437
1400
|
try {
|
|
1438
1401
|
return await hasDefaultExport(ast);
|
|
1439
1402
|
} catch (e) {
|
|
@@ -1444,68 +1407,22 @@ ${e}`
|
|
|
1444
1407
|
return false;
|
|
1445
1408
|
}
|
|
1446
1409
|
}
|
|
1447
|
-
function generateImports(file, index
|
|
1410
|
+
function generateImports(file, index) {
|
|
1448
1411
|
const imports = [];
|
|
1449
1412
|
const route = generateRouteComponentName(index);
|
|
1450
1413
|
const importPath = normalizePath(file);
|
|
1451
|
-
|
|
1452
|
-
imports.push(`import ${route} from "${importPath}"`);
|
|
1453
|
-
} else {
|
|
1454
|
-
const namedImports = [
|
|
1455
|
-
hasHandle && `handle as ${generateHandleName(index)}`,
|
|
1456
|
-
hasLoader && `loader as ${generateLoaderName(index)}`
|
|
1457
|
-
].filter(Boolean).join(", ");
|
|
1458
|
-
imports.push(`import ${route}, { ${namedImports} } from "${importPath}"`);
|
|
1459
|
-
}
|
|
1414
|
+
imports.push(`import ${route} from "${importPath}"`);
|
|
1460
1415
|
return imports;
|
|
1461
1416
|
}
|
|
1462
|
-
function generateRoute(route, index
|
|
1417
|
+
function generateRoute(route, index) {
|
|
1463
1418
|
return {
|
|
1464
1419
|
Component: generateRouteComponentName(index),
|
|
1465
|
-
path: route
|
|
1466
|
-
handle: hasHandle ? generateHandleName(index) : void 0,
|
|
1467
|
-
loader: hasLoader ? generateLoaderName(index) : void 0
|
|
1420
|
+
path: route
|
|
1468
1421
|
};
|
|
1469
1422
|
}
|
|
1470
1423
|
function generateRouteComponentName(index) {
|
|
1471
1424
|
return `RouteComponent${index}`;
|
|
1472
1425
|
}
|
|
1473
|
-
function generateHandleName(index) {
|
|
1474
|
-
return `handle${index}`;
|
|
1475
|
-
}
|
|
1476
|
-
function generateLoaderName(index) {
|
|
1477
|
-
return `loader${index}`;
|
|
1478
|
-
}
|
|
1479
|
-
async function hasNamedExports(ast, file) {
|
|
1480
|
-
let hasHandle = false;
|
|
1481
|
-
let hasLoader = false;
|
|
1482
|
-
try {
|
|
1483
|
-
traverse(ast, {
|
|
1484
|
-
ExportNamedDeclaration(path3) {
|
|
1485
|
-
const declaration = path3.node.declaration;
|
|
1486
|
-
if (declaration?.type === "VariableDeclaration") {
|
|
1487
|
-
declaration.declarations.forEach((decl) => {
|
|
1488
|
-
if (decl.id.type === "Identifier" && decl.id.name === "handle") {
|
|
1489
|
-
hasHandle = true;
|
|
1490
|
-
}
|
|
1491
|
-
if (decl.id.type === "Identifier" && decl.id.name === "loader") {
|
|
1492
|
-
hasLoader = true;
|
|
1493
|
-
}
|
|
1494
|
-
});
|
|
1495
|
-
}
|
|
1496
|
-
if (declaration?.type === "FunctionDeclaration" && declaration.id?.name === "loader") {
|
|
1497
|
-
hasLoader = true;
|
|
1498
|
-
}
|
|
1499
|
-
}
|
|
1500
|
-
});
|
|
1501
|
-
} catch (e) {
|
|
1502
|
-
logger.error("An error occurred while checking for named exports.", {
|
|
1503
|
-
file,
|
|
1504
|
-
error: e
|
|
1505
|
-
});
|
|
1506
|
-
}
|
|
1507
|
-
return { hasHandle, hasLoader };
|
|
1508
|
-
}
|
|
1509
1426
|
|
|
1510
1427
|
// src/virtual-modules/generate-virtual-display-module.ts
|
|
1511
1428
|
var import_outdent4 = require("outdent");
|
package/dist/index.mjs
CHANGED
|
@@ -1344,25 +1344,9 @@ function generateCode4(results) {
|
|
|
1344
1344
|
`;
|
|
1345
1345
|
}
|
|
1346
1346
|
function formatRoute(route) {
|
|
1347
|
-
|
|
1347
|
+
return `{
|
|
1348
1348
|
Component: ${route.Component},
|
|
1349
|
-
path: "${route.path}"
|
|
1350
|
-
if (route.handle) {
|
|
1351
|
-
base += `,
|
|
1352
|
-
handle: ${route.handle}`;
|
|
1353
|
-
}
|
|
1354
|
-
if (route.loader) {
|
|
1355
|
-
base += `,
|
|
1356
|
-
loader: ${route.loader}`;
|
|
1357
|
-
}
|
|
1358
|
-
if (route.children?.length) {
|
|
1359
|
-
return `${base},
|
|
1360
|
-
children: [
|
|
1361
|
-
${route.children.map((child) => formatRoute(child)).join(",\n ")}
|
|
1362
|
-
]
|
|
1363
|
-
}`;
|
|
1364
|
-
}
|
|
1365
|
-
return `${base}
|
|
1349
|
+
path: "${route.path}",
|
|
1366
1350
|
}`;
|
|
1367
1351
|
}
|
|
1368
1352
|
async function getFilesFromSources7(sources) {
|
|
@@ -1377,29 +1361,21 @@ async function getRouteResults(files) {
|
|
|
1377
1361
|
const results = (await Promise.all(files.map(parseFile4))).filter(
|
|
1378
1362
|
(result) => result !== null
|
|
1379
1363
|
);
|
|
1380
|
-
|
|
1381
|
-
results.forEach((result) => {
|
|
1382
|
-
const routePath = result.route.path;
|
|
1383
|
-
const isParallel = routePath.includes("/@");
|
|
1384
|
-
if (isParallel) {
|
|
1385
|
-
const parentPath = routePath.split("/@")[0];
|
|
1386
|
-
const parent = routeMap.get(parentPath);
|
|
1387
|
-
if (parent) {
|
|
1388
|
-
parent.route.children = parent.route.children || [];
|
|
1389
|
-
const finalRoute = {
|
|
1390
|
-
...result.route,
|
|
1391
|
-
path: result.route.path.replace("@", "")
|
|
1392
|
-
};
|
|
1393
|
-
parent.route.children.push(finalRoute);
|
|
1394
|
-
parent.imports.push(...result.imports);
|
|
1395
|
-
}
|
|
1396
|
-
} else {
|
|
1397
|
-
routeMap.set(routePath, result);
|
|
1398
|
-
}
|
|
1399
|
-
});
|
|
1400
|
-
return Array.from(routeMap.values());
|
|
1364
|
+
return results;
|
|
1401
1365
|
}
|
|
1402
1366
|
async function parseFile4(file, index) {
|
|
1367
|
+
if (!await isValidRouteFile(file)) {
|
|
1368
|
+
return null;
|
|
1369
|
+
}
|
|
1370
|
+
const routePath = getRoute(file);
|
|
1371
|
+
const imports = generateImports(file, index);
|
|
1372
|
+
const route = generateRoute(routePath, index);
|
|
1373
|
+
return {
|
|
1374
|
+
imports,
|
|
1375
|
+
route
|
|
1376
|
+
};
|
|
1377
|
+
}
|
|
1378
|
+
async function isValidRouteFile(file) {
|
|
1403
1379
|
const code = await fs7.readFile(file, "utf-8");
|
|
1404
1380
|
let ast = null;
|
|
1405
1381
|
try {
|
|
@@ -1409,21 +1385,8 @@ async function parseFile4(file, index) {
|
|
|
1409
1385
|
file,
|
|
1410
1386
|
error: e
|
|
1411
1387
|
});
|
|
1412
|
-
return
|
|
1413
|
-
}
|
|
1414
|
-
if (!await isValidRouteFile(ast, file)) {
|
|
1415
|
-
return null;
|
|
1388
|
+
return false;
|
|
1416
1389
|
}
|
|
1417
|
-
const { hasHandle, hasLoader } = await hasNamedExports(ast, file);
|
|
1418
|
-
const routePath = getRoute(file);
|
|
1419
|
-
const imports = generateImports(file, index, hasHandle, hasLoader);
|
|
1420
|
-
const route = generateRoute(routePath, index, hasHandle, hasLoader);
|
|
1421
|
-
return {
|
|
1422
|
-
imports,
|
|
1423
|
-
route
|
|
1424
|
-
};
|
|
1425
|
-
}
|
|
1426
|
-
async function isValidRouteFile(ast, file) {
|
|
1427
1390
|
try {
|
|
1428
1391
|
return await hasDefaultExport(ast);
|
|
1429
1392
|
} catch (e) {
|
|
@@ -1434,68 +1397,22 @@ ${e}`
|
|
|
1434
1397
|
return false;
|
|
1435
1398
|
}
|
|
1436
1399
|
}
|
|
1437
|
-
function generateImports(file, index
|
|
1400
|
+
function generateImports(file, index) {
|
|
1438
1401
|
const imports = [];
|
|
1439
1402
|
const route = generateRouteComponentName(index);
|
|
1440
1403
|
const importPath = normalizePath(file);
|
|
1441
|
-
|
|
1442
|
-
imports.push(`import ${route} from "${importPath}"`);
|
|
1443
|
-
} else {
|
|
1444
|
-
const namedImports = [
|
|
1445
|
-
hasHandle && `handle as ${generateHandleName(index)}`,
|
|
1446
|
-
hasLoader && `loader as ${generateLoaderName(index)}`
|
|
1447
|
-
].filter(Boolean).join(", ");
|
|
1448
|
-
imports.push(`import ${route}, { ${namedImports} } from "${importPath}"`);
|
|
1449
|
-
}
|
|
1404
|
+
imports.push(`import ${route} from "${importPath}"`);
|
|
1450
1405
|
return imports;
|
|
1451
1406
|
}
|
|
1452
|
-
function generateRoute(route, index
|
|
1407
|
+
function generateRoute(route, index) {
|
|
1453
1408
|
return {
|
|
1454
1409
|
Component: generateRouteComponentName(index),
|
|
1455
|
-
path: route
|
|
1456
|
-
handle: hasHandle ? generateHandleName(index) : void 0,
|
|
1457
|
-
loader: hasLoader ? generateLoaderName(index) : void 0
|
|
1410
|
+
path: route
|
|
1458
1411
|
};
|
|
1459
1412
|
}
|
|
1460
1413
|
function generateRouteComponentName(index) {
|
|
1461
1414
|
return `RouteComponent${index}`;
|
|
1462
1415
|
}
|
|
1463
|
-
function generateHandleName(index) {
|
|
1464
|
-
return `handle${index}`;
|
|
1465
|
-
}
|
|
1466
|
-
function generateLoaderName(index) {
|
|
1467
|
-
return `loader${index}`;
|
|
1468
|
-
}
|
|
1469
|
-
async function hasNamedExports(ast, file) {
|
|
1470
|
-
let hasHandle = false;
|
|
1471
|
-
let hasLoader = false;
|
|
1472
|
-
try {
|
|
1473
|
-
traverse(ast, {
|
|
1474
|
-
ExportNamedDeclaration(path3) {
|
|
1475
|
-
const declaration = path3.node.declaration;
|
|
1476
|
-
if (declaration?.type === "VariableDeclaration") {
|
|
1477
|
-
declaration.declarations.forEach((decl) => {
|
|
1478
|
-
if (decl.id.type === "Identifier" && decl.id.name === "handle") {
|
|
1479
|
-
hasHandle = true;
|
|
1480
|
-
}
|
|
1481
|
-
if (decl.id.type === "Identifier" && decl.id.name === "loader") {
|
|
1482
|
-
hasLoader = true;
|
|
1483
|
-
}
|
|
1484
|
-
});
|
|
1485
|
-
}
|
|
1486
|
-
if (declaration?.type === "FunctionDeclaration" && declaration.id?.name === "loader") {
|
|
1487
|
-
hasLoader = true;
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
});
|
|
1491
|
-
} catch (e) {
|
|
1492
|
-
logger.error("An error occurred while checking for named exports.", {
|
|
1493
|
-
file,
|
|
1494
|
-
error: e
|
|
1495
|
-
});
|
|
1496
|
-
}
|
|
1497
|
-
return { hasHandle, hasLoader };
|
|
1498
|
-
}
|
|
1499
1416
|
|
|
1500
1417
|
// src/virtual-modules/generate-virtual-display-module.ts
|
|
1501
1418
|
import { outdent as outdent4 } from "outdent";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medusajs/admin-vite-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-preview-20250211091350",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"@types/node": "^20.10.4",
|
|
31
31
|
"tsup": "8.0.1",
|
|
32
32
|
"typescript": "5.3.3",
|
|
33
|
-
"vite": "^5.
|
|
34
|
-
"vitest": "^
|
|
33
|
+
"vite": "^5.2.11",
|
|
34
|
+
"vitest": "^2.1.9"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"vite": "^5.0.0"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@babel/parser": "7.25.6",
|
|
41
41
|
"@babel/traverse": "7.25.6",
|
|
42
42
|
"@babel/types": "7.25.6",
|
|
43
|
-
"@medusajs/admin-shared": "
|
|
43
|
+
"@medusajs/admin-shared": "3.0.0-preview-20250211091350",
|
|
44
44
|
"chokidar": "3.5.3",
|
|
45
45
|
"fdir": "6.1.1",
|
|
46
46
|
"magic-string": "0.30.5",
|