@immense/vue-pom-generator 1.0.55 → 1.0.57
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/RELEASE_NOTES.md +14 -12
- package/dist/index.cjs +163 -93
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +163 -93
- package/dist/index.mjs.map +1 -1
- package/dist/router-introspection.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1224,6 +1224,12 @@ function nodeHandlerAttributeInfo(node) {
|
|
|
1224
1224
|
const n = node2;
|
|
1225
1225
|
return typeof n.callee === "object" && n.callee !== null && Array.isArray(n.arguments);
|
|
1226
1226
|
};
|
|
1227
|
+
const isAwaitExpressionNode = (node2) => {
|
|
1228
|
+
if (!isNodeType(node2, "AwaitExpression"))
|
|
1229
|
+
return false;
|
|
1230
|
+
const n = node2;
|
|
1231
|
+
return typeof n.argument === "object" && n.argument !== null;
|
|
1232
|
+
};
|
|
1227
1233
|
const isAssignmentExpressionNode = (node2) => {
|
|
1228
1234
|
if (!isNodeType(node2, "AssignmentExpression"))
|
|
1229
1235
|
return false;
|
|
@@ -1430,14 +1436,15 @@ function nodeHandlerAttributeInfo(node) {
|
|
|
1430
1436
|
if (isArrowFunctionExpressionNode(expr)) {
|
|
1431
1437
|
const body = expr.body;
|
|
1432
1438
|
const tryFromCallExpression = (call) => {
|
|
1433
|
-
|
|
1439
|
+
const resolvedCall = isAwaitExpressionNode(call) ? call.argument : call;
|
|
1440
|
+
if (!isCallExpressionNode(resolvedCall)) {
|
|
1434
1441
|
return null;
|
|
1435
1442
|
}
|
|
1436
|
-
const name = getLastIdentifierFromMemberChain(
|
|
1443
|
+
const name = getLastIdentifierFromMemberChain(resolvedCall.callee);
|
|
1437
1444
|
if (!name) {
|
|
1438
1445
|
return null;
|
|
1439
1446
|
}
|
|
1440
|
-
const suffix = getStableSuffixFromCall(
|
|
1447
|
+
const suffix = getStableSuffixFromCall(resolvedCall);
|
|
1441
1448
|
const semanticNameHint = suffix ? `${toPascalCase(name)}${suffix}` : toPascalCase(name);
|
|
1442
1449
|
return semanticNameHint;
|
|
1443
1450
|
};
|
|
@@ -3109,6 +3116,56 @@ function createRouterIntrospectionVueStubPlugin(options) {
|
|
|
3109
3116
|
}
|
|
3110
3117
|
};
|
|
3111
3118
|
}
|
|
3119
|
+
function snapshotGlobalValue(name) {
|
|
3120
|
+
const g = globalThis;
|
|
3121
|
+
return {
|
|
3122
|
+
descriptor: Object.getOwnPropertyDescriptor(globalThis, name),
|
|
3123
|
+
value: g[name]
|
|
3124
|
+
};
|
|
3125
|
+
}
|
|
3126
|
+
function setTemporaryGlobal(name, value, snapshots) {
|
|
3127
|
+
if (!snapshots.has(name))
|
|
3128
|
+
snapshots.set(name, snapshotGlobalValue(name));
|
|
3129
|
+
const snapshot = snapshots.get(name);
|
|
3130
|
+
if (!snapshot)
|
|
3131
|
+
return false;
|
|
3132
|
+
if (!snapshot.descriptor || snapshot.descriptor.configurable) {
|
|
3133
|
+
Object.defineProperty(globalThis, name, {
|
|
3134
|
+
configurable: true,
|
|
3135
|
+
enumerable: snapshot.descriptor?.enumerable ?? true,
|
|
3136
|
+
writable: true,
|
|
3137
|
+
value
|
|
3138
|
+
});
|
|
3139
|
+
return true;
|
|
3140
|
+
}
|
|
3141
|
+
if ("writable" in snapshot.descriptor && snapshot.descriptor.writable) {
|
|
3142
|
+
Reflect.set(globalThis, name, value);
|
|
3143
|
+
return true;
|
|
3144
|
+
}
|
|
3145
|
+
if (snapshot.descriptor.set) {
|
|
3146
|
+
snapshot.descriptor.set.call(globalThis, value);
|
|
3147
|
+
return true;
|
|
3148
|
+
}
|
|
3149
|
+
return false;
|
|
3150
|
+
}
|
|
3151
|
+
function restoreTemporaryGlobals(snapshots) {
|
|
3152
|
+
for (const [name, snapshot] of Array.from(snapshots.entries()).reverse()) {
|
|
3153
|
+
const { descriptor, value } = snapshot;
|
|
3154
|
+
if (!descriptor) {
|
|
3155
|
+
Reflect.deleteProperty(globalThis, name);
|
|
3156
|
+
continue;
|
|
3157
|
+
}
|
|
3158
|
+
if (descriptor.configurable) {
|
|
3159
|
+
Object.defineProperty(globalThis, name, descriptor);
|
|
3160
|
+
continue;
|
|
3161
|
+
}
|
|
3162
|
+
if ("writable" in descriptor && descriptor.writable) {
|
|
3163
|
+
Reflect.set(globalThis, name, value);
|
|
3164
|
+
continue;
|
|
3165
|
+
}
|
|
3166
|
+
descriptor.set?.call(globalThis, value);
|
|
3167
|
+
}
|
|
3168
|
+
}
|
|
3112
3169
|
const PARAM_TOKEN_PREFIX = "__VUE_TESTID_PARAM__";
|
|
3113
3170
|
function getParamToken(name) {
|
|
3114
3171
|
return `${PARAM_TOKEN_PREFIX}${name}__`;
|
|
@@ -3457,12 +3514,18 @@ function createMinimalLocation() {
|
|
|
3457
3514
|
ancestorOrigins: { length: 0, contains: () => false, item: () => null, [Symbol.iterator]: [][Symbol.iterator] }
|
|
3458
3515
|
};
|
|
3459
3516
|
}
|
|
3460
|
-
|
|
3517
|
+
function ensureDomShim() {
|
|
3461
3518
|
const g = globalThis;
|
|
3462
3519
|
if (typeof document !== "undefined" && typeof window !== "undefined")
|
|
3463
|
-
return
|
|
3520
|
+
return () => {
|
|
3521
|
+
};
|
|
3464
3522
|
const minimalDoc = createMinimalDocument();
|
|
3465
3523
|
const minimalLocation = createMinimalLocation();
|
|
3524
|
+
const snapshots = /* @__PURE__ */ new Map();
|
|
3525
|
+
const setGlobal = (name, value) => {
|
|
3526
|
+
if (!setTemporaryGlobal(name, value, snapshots))
|
|
3527
|
+
debugLog(`could not temporarily install global ${name}`);
|
|
3528
|
+
};
|
|
3466
3529
|
const win = {
|
|
3467
3530
|
document: minimalDoc,
|
|
3468
3531
|
location: minimalLocation,
|
|
@@ -3507,17 +3570,17 @@ async function ensureDomShim() {
|
|
|
3507
3570
|
queueMicrotask,
|
|
3508
3571
|
performance: globalThis.performance
|
|
3509
3572
|
};
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3573
|
+
setGlobal("window", win);
|
|
3574
|
+
setGlobal("document", minimalDoc);
|
|
3575
|
+
setGlobal("location", minimalLocation);
|
|
3513
3576
|
if (!g.self)
|
|
3514
|
-
|
|
3577
|
+
setGlobal("self", win);
|
|
3515
3578
|
if (!g.navigator)
|
|
3516
|
-
|
|
3579
|
+
setGlobal("navigator", win.navigator);
|
|
3517
3580
|
if (!g.history)
|
|
3518
|
-
|
|
3581
|
+
setGlobal("history", win.history);
|
|
3519
3582
|
if (!g.MutationObserver) {
|
|
3520
|
-
|
|
3583
|
+
setGlobal("MutationObserver", class {
|
|
3521
3584
|
disconnect() {
|
|
3522
3585
|
}
|
|
3523
3586
|
observe() {
|
|
@@ -3525,20 +3588,20 @@ async function ensureDomShim() {
|
|
|
3525
3588
|
takeRecords() {
|
|
3526
3589
|
return [];
|
|
3527
3590
|
}
|
|
3528
|
-
};
|
|
3591
|
+
});
|
|
3529
3592
|
}
|
|
3530
3593
|
if (!g.ResizeObserver) {
|
|
3531
|
-
|
|
3594
|
+
setGlobal("ResizeObserver", class {
|
|
3532
3595
|
disconnect() {
|
|
3533
3596
|
}
|
|
3534
3597
|
observe() {
|
|
3535
3598
|
}
|
|
3536
3599
|
unobserve() {
|
|
3537
3600
|
}
|
|
3538
|
-
};
|
|
3601
|
+
});
|
|
3539
3602
|
}
|
|
3540
3603
|
if (!g.IntersectionObserver) {
|
|
3541
|
-
|
|
3604
|
+
setGlobal("IntersectionObserver", class {
|
|
3542
3605
|
disconnect() {
|
|
3543
3606
|
}
|
|
3544
3607
|
observe() {
|
|
@@ -3548,10 +3611,10 @@ async function ensureDomShim() {
|
|
|
3548
3611
|
takeRecords() {
|
|
3549
3612
|
return [];
|
|
3550
3613
|
}
|
|
3551
|
-
};
|
|
3614
|
+
});
|
|
3552
3615
|
}
|
|
3553
3616
|
if (!g.requestIdleCallback) {
|
|
3554
|
-
|
|
3617
|
+
setGlobal("requestIdleCallback", (cb) => setTimeout(() => cb({ didTimeout: false, timeRemaining: () => 0 }), 1));
|
|
3555
3618
|
}
|
|
3556
3619
|
if (!g.localStorage || !g.sessionStorage) {
|
|
3557
3620
|
const storageFactory = () => {
|
|
@@ -3574,12 +3637,15 @@ async function ensureDomShim() {
|
|
|
3574
3637
|
};
|
|
3575
3638
|
};
|
|
3576
3639
|
if (!g.localStorage)
|
|
3577
|
-
|
|
3640
|
+
setGlobal("localStorage", storageFactory());
|
|
3578
3641
|
if (!g.sessionStorage)
|
|
3579
|
-
|
|
3642
|
+
setGlobal("sessionStorage", storageFactory());
|
|
3580
3643
|
}
|
|
3581
3644
|
if (!g.requestAnimationFrame)
|
|
3582
|
-
|
|
3645
|
+
setGlobal("requestAnimationFrame", (cb) => setTimeout(() => cb(Date.now()), 16));
|
|
3646
|
+
return () => {
|
|
3647
|
+
restoreTemporaryGlobals(snapshots);
|
|
3648
|
+
};
|
|
3583
3649
|
}
|
|
3584
3650
|
function unwrapNuxtPageSegment(segment, prefix, suffix) {
|
|
3585
3651
|
if (!segment.startsWith(prefix) || !segment.endsWith(suffix))
|
|
@@ -3697,85 +3763,89 @@ async function parseRouterFileFromCwd(routerEntryPath, options = {}) {
|
|
|
3697
3763
|
}
|
|
3698
3764
|
const cwd = path.dirname(routerEntry);
|
|
3699
3765
|
const moduleShims = normalizeRouterIntrospectionModuleShims(options.moduleShims);
|
|
3700
|
-
|
|
3701
|
-
debugLog(`parseRouterFileFromCwd cwd=${cwd}`);
|
|
3702
|
-
const vite = await import("vite");
|
|
3703
|
-
const server = await vite.createServer({
|
|
3704
|
-
root: cwd,
|
|
3705
|
-
configFile: false,
|
|
3706
|
-
logLevel: "error",
|
|
3707
|
-
// This server is created only to SSR-load the router module. Disable HMR/WebSocket
|
|
3708
|
-
// to avoid port conflicts in dev/test environments.
|
|
3709
|
-
server: { middlewareMode: true, hmr: false, ws: false },
|
|
3710
|
-
appType: "custom",
|
|
3711
|
-
// IMPORTANT:
|
|
3712
|
-
// This internal, short-lived Vite server exists only to `ssrLoadModule()` the router entry.
|
|
3713
|
-
// We close it immediately after reading routes.
|
|
3714
|
-
//
|
|
3715
|
-
// Vite's dependency optimizer (vite:dep-scan / optimizeDeps) runs asynchronously and can
|
|
3716
|
-
// still have pending resolve requests when we call `server.close()`, which surfaces as:
|
|
3717
|
-
// "The server is being restarted or closed. Request is outdated [plugin vite:dep-scan]"
|
|
3718
|
-
//
|
|
3719
|
-
// Disable optimizeDeps entirely for this internal server to avoid that race.
|
|
3720
|
-
optimizeDeps: {
|
|
3721
|
-
disabled: true
|
|
3722
|
-
},
|
|
3723
|
-
resolve: {
|
|
3724
|
-
alias: {
|
|
3725
|
-
"@": cwd
|
|
3726
|
-
}
|
|
3727
|
-
},
|
|
3728
|
-
// Important: Do NOT include @vitejs/plugin-vue here.
|
|
3729
|
-
// We stub all `.vue` imports ourselves, and including the Vue plugin would attempt to parse
|
|
3730
|
-
// those stubbed modules as real SFCs (and fail).
|
|
3731
|
-
plugins: [createRouterIntrospectionVueStubPlugin({ routerEntryAbs: routerEntry, moduleShims })]
|
|
3732
|
-
});
|
|
3766
|
+
const restoreDomShim = ensureDomShim();
|
|
3733
3767
|
try {
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
const
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3768
|
+
debugLog(`parseRouterFileFromCwd cwd=${cwd}`);
|
|
3769
|
+
const vite = await import("vite");
|
|
3770
|
+
const server = await vite.createServer({
|
|
3771
|
+
root: cwd,
|
|
3772
|
+
configFile: false,
|
|
3773
|
+
logLevel: "error",
|
|
3774
|
+
// This server is created only to SSR-load the router module. Disable HMR/WebSocket
|
|
3775
|
+
// to avoid port conflicts in dev/test environments.
|
|
3776
|
+
server: { middlewareMode: true, hmr: false, ws: false },
|
|
3777
|
+
appType: "custom",
|
|
3778
|
+
// IMPORTANT:
|
|
3779
|
+
// This internal, short-lived Vite server exists only to `ssrLoadModule()` the router entry.
|
|
3780
|
+
// We close it immediately after reading routes.
|
|
3781
|
+
//
|
|
3782
|
+
// Vite's dependency optimizer (vite:dep-scan / optimizeDeps) runs asynchronously and can
|
|
3783
|
+
// still have pending resolve requests when we call `server.close()`, which surfaces as:
|
|
3784
|
+
// "The server is being restarted or closed. Request is outdated [plugin vite:dep-scan]"
|
|
3785
|
+
//
|
|
3786
|
+
// Disable optimizeDeps entirely for this internal server to avoid that race.
|
|
3787
|
+
optimizeDeps: {
|
|
3788
|
+
disabled: true
|
|
3789
|
+
},
|
|
3790
|
+
resolve: {
|
|
3791
|
+
alias: {
|
|
3792
|
+
"@": cwd
|
|
3793
|
+
}
|
|
3794
|
+
},
|
|
3795
|
+
// Important: Do NOT include @vitejs/plugin-vue here.
|
|
3796
|
+
// We stub all `.vue` imports ourselves, and including the Vue plugin would attempt to parse
|
|
3797
|
+
// those stubbed modules as real SFCs (and fail).
|
|
3798
|
+
plugins: [createRouterIntrospectionVueStubPlugin({ routerEntryAbs: routerEntry, moduleShims })]
|
|
3799
|
+
});
|
|
3743
3800
|
try {
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
for (const r of router.getRoutes()) {
|
|
3752
|
-
const componentInfo = await getComponentInfoFromRouteRecord(r, { rootDir: cwd });
|
|
3753
|
-
const componentName = resolveIntrospectedComponentName(componentInfo, options.componentNaming);
|
|
3754
|
-
if (!componentName)
|
|
3755
|
-
continue;
|
|
3756
|
-
if (typeof r.path === "string" && r.path.length) {
|
|
3757
|
-
routePathMap.set(r.path, componentName);
|
|
3801
|
+
const moduleId = pathToFileURL(routerEntry).href;
|
|
3802
|
+
debugLog(`ssrLoadModule(${moduleId}) start`);
|
|
3803
|
+
const mod = await server.ssrLoadModule(moduleId);
|
|
3804
|
+
debugLog(`ssrLoadModule(${moduleId}) done; hasDefault=${typeof mod?.default === "function"}`);
|
|
3805
|
+
const makeRouter = mod?.default;
|
|
3806
|
+
if (typeof makeRouter !== "function") {
|
|
3807
|
+
throw new TypeError(`[vue-pom-generator] ${routerEntry} must export a default router factory function (export default makeRouter).`);
|
|
3758
3808
|
}
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3809
|
+
let router;
|
|
3810
|
+
try {
|
|
3811
|
+
router = makeRouter();
|
|
3812
|
+
} catch (err) {
|
|
3813
|
+
throw new Error(`[vue-pom-generator] makeRouter() invocation failed: ${String(err)}`);
|
|
3762
3814
|
}
|
|
3763
|
-
const
|
|
3764
|
-
const
|
|
3765
|
-
const
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3815
|
+
const routeNameMap = /* @__PURE__ */ new Map();
|
|
3816
|
+
const routePathMap = /* @__PURE__ */ new Map();
|
|
3817
|
+
const routeMetaEntries = [];
|
|
3818
|
+
for (const r of router.getRoutes()) {
|
|
3819
|
+
const componentInfo = await getComponentInfoFromRouteRecord(r, { rootDir: cwd });
|
|
3820
|
+
const componentName = resolveIntrospectedComponentName(componentInfo, options.componentNaming);
|
|
3821
|
+
if (!componentName)
|
|
3822
|
+
continue;
|
|
3823
|
+
if (typeof r.path === "string" && r.path.length) {
|
|
3824
|
+
routePathMap.set(r.path, componentName);
|
|
3825
|
+
}
|
|
3826
|
+
if (typeof r.name === "string" && r.name.length) {
|
|
3827
|
+
const key = toPascalCase(r.name);
|
|
3828
|
+
routeNameMap.set(key, componentName);
|
|
3829
|
+
}
|
|
3830
|
+
const { paramKeys, queryKeys } = getRoutePropsKeys(r);
|
|
3831
|
+
const paramsMeta = getRouteParamMeta(router, r, paramKeys);
|
|
3832
|
+
const pathTemplate = buildRouteTemplate(router, r, paramsMeta.map((p) => p.name));
|
|
3833
|
+
if (typeof pathTemplate === "string" && pathTemplate.length) {
|
|
3834
|
+
routeMetaEntries.push({
|
|
3835
|
+
componentName,
|
|
3836
|
+
pathTemplate,
|
|
3837
|
+
params: paramsMeta,
|
|
3838
|
+
query: queryKeys
|
|
3839
|
+
});
|
|
3840
|
+
}
|
|
3773
3841
|
}
|
|
3842
|
+
return { routeNameMap, routePathMap, routeMetaEntries };
|
|
3843
|
+
} finally {
|
|
3844
|
+
debugLog("closing internal vite server");
|
|
3845
|
+
await server.close();
|
|
3774
3846
|
}
|
|
3775
|
-
return { routeNameMap, routePathMap, routeMetaEntries };
|
|
3776
3847
|
} finally {
|
|
3777
|
-
|
|
3778
|
-
await server.close();
|
|
3848
|
+
restoreDomShim();
|
|
3779
3849
|
}
|
|
3780
3850
|
});
|
|
3781
3851
|
}
|