Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unplugin-vue-router

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unplugin-vue-router - npm Package Compare versions

Comparing version 0.2.3 to 0.3.0

dist/chunk-6WSG64Q7.mjs

2

dist/esbuild.d.ts
import * as esbuild from 'esbuild';
import { O as Options } from './options-dcd51c9e.js';
import { O as Options } from './options-adeff310.js';
import 'vue-router';

@@ -4,0 +4,0 @@

"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __export = (target, all) => {

@@ -113,2 +130,3 @@ for (var name in all)

function mergeRouteRecordOverride(a, b) {
var _a;
const merged = {};

@@ -127,3 +145,3 @@ const keys = [

} else {
merged[key] = b[key] ?? a[key];
merged[key] = (_a = b[key]) != null ? _a : a[key];
}

@@ -152,3 +170,2 @@ }

}
var __DEV__ = process.env.NODE_ENV !== "production";

@@ -352,7 +369,8 @@ // src/core/treeNodeValue.ts

get path() {
var _a;
return this.value.overrides.path ?? (((_a = this.parent) == null ? void 0 : _a.isRoot()) ? "/" : "") + this.value.pathSegment;
var _a, _b;
return (_b = this.value.overrides.path) != null ? _b : (((_a = this.parent) == null ? void 0 : _a.isRoot()) ? "/" : "") + this.value.pathSegment;
}
get fullPath() {
return this.value.overrides.path ?? this.value.path;
var _a;
return (_a = this.value.overrides.path) != null ? _a : this.value.path;
}

@@ -363,3 +381,3 @@ get name() {

get meta() {
const overrideMeta = { ...this.value.overrides.meta };
const overrideMeta = __spreadValues({}, this.value.overrides.meta);
if (this.value.includeLoaderGuard) {

@@ -555,3 +573,4 @@ overrideMeta._loaderGuard = true;

function parseCustomBlock(block, filePath, options) {
const lang = block.lang ?? options.routeBlockLang;
var _a;
const lang = (_a = block.lang) != null ? _a : options.routeBlockLang;
if (lang === "json5") {

@@ -726,2 +745,4 @@ try {

export const RouterLink: RouterLinkTyped<RouteNamedMap>
// Experimental Data Fetching

@@ -853,2 +874,51 @@

}
function extractDefinePageNameAndPath(sfcCode, id) {
if (!sfcCode.includes(MACRO_DEFINE_PAGE))
return;
const sfc = (0, import_common.parseSFC)(sfcCode, id);
if (!sfc.scriptSetup)
return;
const { script, scriptSetup, scriptCompiled } = sfc;
const definePageNodes = scriptCompiled.scriptSetupAst.map((node) => {
if (node.type === "ExpressionStatement")
node = node.expression;
return (0, import_common.isCallOf)(node, MACRO_DEFINE_PAGE) ? node : null;
}).filter((node) => !!node);
if (!definePageNodes.length) {
return;
} else if (definePageNodes.length > 1) {
throw new SyntaxError(`duplicate definePage() call`);
}
const definePageNode = definePageNodes[0];
const setupOffset = scriptSetup.loc.start.offset;
const routeRecord = definePageNode.arguments[0];
if (routeRecord.type !== "ObjectExpression") {
throw new SyntaxError(
`[${id}]: definePage() expects an object expression as its only argument`
);
}
const routeInfo = {};
for (const prop of routeRecord.properties) {
if (prop.type === "ObjectProperty" && prop.key.type === "Identifier") {
if (prop.key.name === "name") {
if (prop.value.type !== "StringLiteral") {
console.warn(
`[unplugin-vue-router]: route name must be a string literal. Found in "${id}".`
);
} else {
routeInfo.name = prop.value.value;
}
} else if (prop.key.name === "path") {
if (prop.value.type !== "StringLiteral") {
console.warn(
`[unplugin-vue-router]: route path must be a string literal. Found in "${id}".`
);
} else {
routeInfo.path = prop.value.value;
}
}
}
}
return routeInfo;
}
var getIdentifiers = (stmts) => {

@@ -924,7 +994,14 @@ let ids = [];

}
async function writeRouteInfoToNode(node, path) {
const content = await import_fs3.promises.readFile(path, "utf8");
node.hasDefinePage = content.includes("definePage");
const [definedPageNameAndPath, routeBlock] = await Promise.all([
extractDefinePageNameAndPath(content, path),
getRouteBlock(path, options)
]);
node.setCustomRouteBlock(path, __spreadValues(__spreadValues({}, routeBlock), definedPageNameAndPath));
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(path);
}
async function addPage({ filePath: path, routePath }) {
const routeBlock = await getRouteBlock(path, options);
log(`added "${routePath}" for "${path}"`);
if (routeBlock)
log(routeBlock);
const node = routeTree.insert(

@@ -934,7 +1011,4 @@ routePath,

);
node.setCustomRouteBlock(path, routeBlock);
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(path);
await writeRouteInfoToNode(node, path);
routeMap.set(path, node);
const content = await import_fs3.promises.readFile(path, "utf8");
node.hasDefinePage = content.includes("definePage");
}

@@ -948,6 +1022,3 @@ async function updatePage({ filePath: path, routePath }) {

}
const content = await import_fs3.promises.readFile(path, "utf8");
node.hasDefinePage = content.includes("definePage");
node.setCustomRouteBlock(path, await getRouteBlock(path, options));
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(path);
writeRouteInfoToNode(node, path);
}

@@ -1006,3 +1077,3 @@ function removePage({ filePath: path, routePath }) {

async function _writeConfigFiles() {
log("writing");
log("\u{1F4BE} writing...");
logTree(routeTree, log);

@@ -1069,11 +1140,8 @@ if (dts) {

options.routesFolder || DEFAULT_OPTIONS.routesFolder
).map((routeOption) => ({
...routeOption,
).map((routeOption) => __spreadProps(__spreadValues({}, routeOption), {
src: (0, import_pathe3.resolve)(root, routeOption.src)
}));
return {
...DEFAULT_OPTIONS,
...options,
return __spreadProps(__spreadValues(__spreadValues({}, DEFAULT_OPTIONS), options), {
routesFolder
};
});
}

@@ -1080,0 +1148,0 @@

import * as unplugin from 'unplugin';
import { R as ResolvedOptions, S as ServerContext, O as Options } from './options-dcd51c9e.js';
export { O as Options, T as TreeNode, b as TreeNodeValueParam, d as TreeNodeValueStatic, c as createPrefixTree, a as createTreeNodeValue } from './options-dcd51c9e.js';
import { L as LiteralStringUnion } from './defineLoader-24fcbf59.js';
export { b as _DataLoader, D as _DefineLoaderOptions, g as getFileBasedRouteName, a as getPascalCaseRouteName } from './defineLoader-24fcbf59.js';
import { R as ResolvedOptions, S as ServerContext, O as Options } from './options-adeff310.js';
export { T as TreeNode, b as TreeNodeValueParam, d as TreeNodeValueStatic, c as createPrefixTree, a as createTreeNodeValue } from './options-adeff310.js';
import { L as LiteralStringUnion } from './defineLoader-23e4921c.js';
export { b as _DataLoader, D as _DefineLoaderOptions, g as getFileBasedRouteName, a as getPascalCaseRouteName } from './defineLoader-23e4921c.js';
import { RouteParamsRaw, RouteParams, RouteMeta, RouteLocationNormalized, RouteRecordName, RouteLocationNormalizedLoaded, RouteQueryAndHash, RouteLocationOptions, RouteLocation, NavigationGuardNext, NavigationFailure, Router, RouteLocationRaw, RouterLinkProps as RouterLinkProps$1 } from 'vue-router';

@@ -26,3 +26,3 @@ import { Ref, AllowedComponentProps, ComponentCustomProps, VNodeProps, UnwrapRef, VNode, ComputedRef } from 'vue';

}
declare type _RouteMapGeneric = Record<string, RouteRecordInfo>;
type _RouteMapGeneric = Record<string, RouteRecordInfo>;

@@ -33,3 +33,3 @@ interface RouteLocationNormalizedTyped<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>, Name extends keyof RouteMap = keyof RouteMap> extends RouteLocationNormalized {

}
declare type RouteLocationNormalizedTypedList<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>> = {
type RouteLocationNormalizedTypedList<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>> = {
[N in keyof RouteMap]: RouteLocationNormalizedTyped<RouteMap, N>;

@@ -41,3 +41,3 @@ };

}
declare type RouteLocationNormalizedLoadedTypedList<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>> = {
type RouteLocationNormalizedLoadedTypedList<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>> = {
[N in keyof RouteMap]: RouteLocationNormalizedLoadedTyped<RouteMap, N>;

@@ -49,3 +49,3 @@ };

}
declare type RouteLocationAsRelativeTypedList<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>> = {
type RouteLocationAsRelativeTypedList<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>> = {
[N in keyof RouteMap]: RouteLocationAsRelativeTyped<RouteMap, N>;

@@ -56,6 +56,6 @@ };

}
declare type RouteLocationAsPathTypedList<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>> = {
type RouteLocationAsPathTypedList<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>> = {
[N in keyof RouteMap]: RouteLocationAsPathTyped<RouteMap, N>;
};
declare type RouteLocationAsString<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>> = LiteralStringUnion<RouteMap[keyof RouteMap]['path'], string>;
type RouteLocationAsString<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>> = LiteralStringUnion<RouteMap[keyof RouteMap]['path'], string>;
interface RouteLocationTyped<RouteMap extends _RouteMapGeneric, Name extends keyof RouteMap> extends RouteLocation {

@@ -65,3 +65,3 @@ name: Extract<Name, RouteRecordName>;

}
declare type RouteLocationTypedList<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>> = {
type RouteLocationTypedList<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>> = {
[N in keyof RouteMap]: RouteLocationTyped<RouteMap, N>;

@@ -72,7 +72,7 @@ };

}
declare type RouteLocationResolvedTypedList<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>> = {
type RouteLocationResolvedTypedList<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>> = {
[N in keyof RouteMap]: RouteLocationResolvedTyped<RouteMap, N>;
};
declare type NavigationGuardReturn<RouteMap extends _RouteMapGeneric> = void | boolean | RouteLocationAsString<RouteMap> | RouteLocationAsRelativeTypedList<RouteMap>[keyof RouteMap] | RouteLocationAsPathTypedList<RouteMap>[keyof RouteMap];
type NavigationGuardReturn<RouteMap extends _RouteMapGeneric> = void | boolean | RouteLocationAsString<RouteMap> | RouteLocationAsRelativeTypedList<RouteMap>[keyof RouteMap] | RouteLocationAsPathTypedList<RouteMap>[keyof RouteMap];
interface NavigationGuardWithThis<T, RouteMap extends _RouteMapGeneric> {

@@ -140,3 +140,3 @@ (this: T, to: RouteLocationNormalizedTypedList<RouteMap>[keyof RouteMap], from: RouteLocationNormalizedLoadedTypedList<RouteMap>[keyof RouteMap], next: NavigationGuardNext): NavigationGuardReturn<RouteMap> | Promise<NavigationGuardReturn<RouteMap>>;

*/
declare type ParamValueOneOrMore<isRaw extends boolean> = [
type ParamValueOneOrMore<isRaw extends boolean> = [
ParamValue<isRaw>,

@@ -149,3 +149,3 @@ ...ParamValue<isRaw>[]

*/
declare type ParamValueZeroOrMore<isRaw extends boolean> = ParamValue<isRaw>[] | undefined | null;
type ParamValueZeroOrMore<isRaw extends boolean> = ParamValue<isRaw>[] | undefined | null;
/**

@@ -155,3 +155,3 @@ * Utility type for raw and non raw params like :id?

*/
declare type ParamValueZeroOrOne<isRaw extends boolean> = true extends isRaw ? string | number | null | undefined : string;
type ParamValueZeroOrOne<isRaw extends boolean> = true extends isRaw ? string | number | null | undefined : string;
/**

@@ -161,5 +161,5 @@ * Utility type for raw and non raw params like :id

*/
declare type ParamValue<isRaw extends boolean> = true extends isRaw ? string | number : string;
type ParamValue<isRaw extends boolean> = true extends isRaw ? string | number : string;
declare const _default: unplugin.UnpluginInstance<Options | undefined>;
declare const _default: unplugin.UnpluginInstance<Options | undefined, boolean>;

@@ -183,2 +183,2 @@ /**

export { NavigationGuard, ParamValue, ParamValueOneOrMore, ParamValueZeroOrMore, ParamValueZeroOrOne, RouteLocationAsPathTyped, RouteLocationAsPathTypedList, RouteLocationAsRelativeTyped, RouteLocationAsRelativeTypedList, RouteLocationAsString, RouteLocationNormalizedLoadedTyped, RouteLocationNormalizedLoadedTypedList, RouteLocationNormalizedTyped, RouteLocationNormalizedTypedList, RouteLocationResolvedTyped, RouteLocationResolvedTypedList, RouteLocationTyped, RouteLocationTypedList, RouteRecordInfo, RouterLinkTyped, UseLinkFnTyped, VueRouterAutoImports, VueRouterExports, _RouteMapGeneric, _RouterTyped, _UseLinkReturnTyped, createRoutesContext, _default as default };
export { NavigationGuard, Options, ParamValue, ParamValueOneOrMore, ParamValueZeroOrMore, ParamValueZeroOrOne, RouteLocationAsPathTyped, RouteLocationAsPathTypedList, RouteLocationAsRelativeTyped, RouteLocationAsRelativeTypedList, RouteLocationAsString, RouteLocationNormalizedLoadedTyped, RouteLocationNormalizedLoadedTypedList, RouteLocationNormalizedTyped, RouteLocationNormalizedTypedList, RouteLocationResolvedTyped, RouteLocationResolvedTypedList, RouteLocationTyped, RouteLocationTypedList, RouteRecordInfo, RouterLinkTyped, UseLinkFnTyped, VueRouterAutoImports, VueRouterExports, _RouteMapGeneric, _RouterTyped, _UseLinkReturnTyped, createRoutesContext, _default as default };
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __export = (target, all) => {

@@ -140,2 +157,3 @@ for (var name in all)

function mergeRouteRecordOverride(a, b) {
var _a;
const merged = {};

@@ -154,3 +172,3 @@ const keys = [

} else {
merged[key] = b[key] ?? a[key];
merged[key] = (_a = b[key]) != null ? _a : a[key];
}

@@ -179,3 +197,2 @@ }

}
var __DEV__ = process.env.NODE_ENV !== "production";

@@ -379,7 +396,8 @@ // src/core/treeNodeValue.ts

get path() {
var _a;
return this.value.overrides.path ?? (((_a = this.parent) == null ? void 0 : _a.isRoot()) ? "/" : "") + this.value.pathSegment;
var _a, _b;
return (_b = this.value.overrides.path) != null ? _b : (((_a = this.parent) == null ? void 0 : _a.isRoot()) ? "/" : "") + this.value.pathSegment;
}
get fullPath() {
return this.value.overrides.path ?? this.value.path;
var _a;
return (_a = this.value.overrides.path) != null ? _a : this.value.path;
}

@@ -390,3 +408,3 @@ get name() {

get meta() {
const overrideMeta = { ...this.value.overrides.meta };
const overrideMeta = __spreadValues({}, this.value.overrides.meta);
if (this.value.includeLoaderGuard) {

@@ -582,3 +600,4 @@ overrideMeta._loaderGuard = true;

function parseCustomBlock(block, filePath, options) {
const lang = block.lang ?? options.routeBlockLang;
var _a;
const lang = (_a = block.lang) != null ? _a : options.routeBlockLang;
if (lang === "json5") {

@@ -753,2 +772,4 @@ try {

export const RouterLink: RouterLinkTyped<RouteNamedMap>
// Experimental Data Fetching

@@ -880,2 +901,51 @@

}
function extractDefinePageNameAndPath(sfcCode, id) {
if (!sfcCode.includes(MACRO_DEFINE_PAGE))
return;
const sfc = (0, import_common.parseSFC)(sfcCode, id);
if (!sfc.scriptSetup)
return;
const { script, scriptSetup, scriptCompiled } = sfc;
const definePageNodes = scriptCompiled.scriptSetupAst.map((node) => {
if (node.type === "ExpressionStatement")
node = node.expression;
return (0, import_common.isCallOf)(node, MACRO_DEFINE_PAGE) ? node : null;
}).filter((node) => !!node);
if (!definePageNodes.length) {
return;
} else if (definePageNodes.length > 1) {
throw new SyntaxError(`duplicate definePage() call`);
}
const definePageNode = definePageNodes[0];
const setupOffset = scriptSetup.loc.start.offset;
const routeRecord = definePageNode.arguments[0];
if (routeRecord.type !== "ObjectExpression") {
throw new SyntaxError(
`[${id}]: definePage() expects an object expression as its only argument`
);
}
const routeInfo = {};
for (const prop of routeRecord.properties) {
if (prop.type === "ObjectProperty" && prop.key.type === "Identifier") {
if (prop.key.name === "name") {
if (prop.value.type !== "StringLiteral") {
console.warn(
`[unplugin-vue-router]: route name must be a string literal. Found in "${id}".`
);
} else {
routeInfo.name = prop.value.value;
}
} else if (prop.key.name === "path") {
if (prop.value.type !== "StringLiteral") {
console.warn(
`[unplugin-vue-router]: route path must be a string literal. Found in "${id}".`
);
} else {
routeInfo.path = prop.value.value;
}
}
}
}
return routeInfo;
}
var getIdentifiers = (stmts) => {

@@ -951,7 +1021,14 @@ let ids = [];

}
async function writeRouteInfoToNode(node, path) {
const content = await import_fs3.promises.readFile(path, "utf8");
node.hasDefinePage = content.includes("definePage");
const [definedPageNameAndPath, routeBlock] = await Promise.all([
extractDefinePageNameAndPath(content, path),
getRouteBlock(path, options)
]);
node.setCustomRouteBlock(path, __spreadValues(__spreadValues({}, routeBlock), definedPageNameAndPath));
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(path);
}
async function addPage({ filePath: path, routePath }) {
const routeBlock = await getRouteBlock(path, options);
log(`added "${routePath}" for "${path}"`);
if (routeBlock)
log(routeBlock);
const node = routeTree.insert(

@@ -961,7 +1038,4 @@ routePath,

);
node.setCustomRouteBlock(path, routeBlock);
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(path);
await writeRouteInfoToNode(node, path);
routeMap.set(path, node);
const content = await import_fs3.promises.readFile(path, "utf8");
node.hasDefinePage = content.includes("definePage");
}

@@ -975,6 +1049,3 @@ async function updatePage({ filePath: path, routePath }) {

}
const content = await import_fs3.promises.readFile(path, "utf8");
node.hasDefinePage = content.includes("definePage");
node.setCustomRouteBlock(path, await getRouteBlock(path, options));
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(path);
writeRouteInfoToNode(node, path);
}

@@ -1033,3 +1104,3 @@ function removePage({ filePath: path, routePath }) {

async function _writeConfigFiles() {
log("writing");
log("\u{1F4BE} writing...");
logTree(routeTree, log);

@@ -1096,11 +1167,8 @@ if (dts) {

options.routesFolder || DEFAULT_OPTIONS.routesFolder
).map((routeOption) => ({
...routeOption,
).map((routeOption) => __spreadProps(__spreadValues({}, routeOption), {
src: (0, import_pathe3.resolve)(root, routeOption.src)
}));
return {
...DEFAULT_OPTIONS,
...options,
return __spreadProps(__spreadValues(__spreadValues({}, DEFAULT_OPTIONS), options), {
routesFolder
};
});
}

@@ -1212,3 +1280,5 @@

"useRouter",
"defineLoader"
"defineLoader",
"onBeforeRouteUpdate",
"onBeforeRouteLeave"
];

@@ -1215,0 +1285,0 @@ var VueRouterAutoImports = {

@@ -1,2 +0,2 @@

export { D as DEFAULT_OPTIONS, O as Options, R as ResolvedOptions, f as RoutesFolder, e as RoutesFolderOption, S as ServerContext, g as _OptionsImportMode, _ as _RoutesFolder, r as resolveOptions } from './options-dcd51c9e.js';
export { D as DEFAULT_OPTIONS, O as Options, R as ResolvedOptions, f as RoutesFolder, e as RoutesFolderOption, S as ServerContext, g as _OptionsImportMode, _ as _RoutesFolder, r as resolveOptions } from './options-adeff310.js';
import 'vue-router';
"use strict";
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __export = (target, all) => {

@@ -37,3 +54,2 @@ for (var name in all)

}
var __DEV__ = process.env.NODE_ENV !== "production";

@@ -64,11 +80,8 @@ // src/options.ts

options.routesFolder || DEFAULT_OPTIONS.routesFolder
).map((routeOption) => ({
...routeOption,
).map((routeOption) => __spreadProps(__spreadValues({}, routeOption), {
src: (0, import_pathe.resolve)(root, routeOption.src)
}));
return {
...DEFAULT_OPTIONS,
...options,
return __spreadProps(__spreadValues(__spreadValues({}, DEFAULT_OPTIONS), options), {
routesFolder
};
});
}

@@ -75,0 +88,0 @@ // Annotate the CommonJS export names for ESM import in node:

import * as rollup from 'rollup';
import { O as Options } from './options-dcd51c9e.js';
import { O as Options } from './options-adeff310.js';
import 'vue-router';
declare const _default: (options?: Options | undefined) => rollup.Plugin;
declare const _default: (options?: Options | undefined) => rollup.Plugin | rollup.Plugin[];
export { _default as default };
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __export = (target, all) => {

@@ -113,2 +130,3 @@ for (var name in all)

function mergeRouteRecordOverride(a, b) {
var _a;
const merged = {};

@@ -127,3 +145,3 @@ const keys = [

} else {
merged[key] = b[key] ?? a[key];
merged[key] = (_a = b[key]) != null ? _a : a[key];
}

@@ -152,3 +170,2 @@ }

}
var __DEV__ = process.env.NODE_ENV !== "production";

@@ -352,7 +369,8 @@ // src/core/treeNodeValue.ts

get path() {
var _a;
return this.value.overrides.path ?? (((_a = this.parent) == null ? void 0 : _a.isRoot()) ? "/" : "") + this.value.pathSegment;
var _a, _b;
return (_b = this.value.overrides.path) != null ? _b : (((_a = this.parent) == null ? void 0 : _a.isRoot()) ? "/" : "") + this.value.pathSegment;
}
get fullPath() {
return this.value.overrides.path ?? this.value.path;
var _a;
return (_a = this.value.overrides.path) != null ? _a : this.value.path;
}

@@ -363,3 +381,3 @@ get name() {

get meta() {
const overrideMeta = { ...this.value.overrides.meta };
const overrideMeta = __spreadValues({}, this.value.overrides.meta);
if (this.value.includeLoaderGuard) {

@@ -555,3 +573,4 @@ overrideMeta._loaderGuard = true;

function parseCustomBlock(block, filePath, options) {
const lang = block.lang ?? options.routeBlockLang;
var _a;
const lang = (_a = block.lang) != null ? _a : options.routeBlockLang;
if (lang === "json5") {

@@ -726,2 +745,4 @@ try {

export const RouterLink: RouterLinkTyped<RouteNamedMap>
// Experimental Data Fetching

@@ -853,2 +874,51 @@

}
function extractDefinePageNameAndPath(sfcCode, id) {
if (!sfcCode.includes(MACRO_DEFINE_PAGE))
return;
const sfc = (0, import_common.parseSFC)(sfcCode, id);
if (!sfc.scriptSetup)
return;
const { script, scriptSetup, scriptCompiled } = sfc;
const definePageNodes = scriptCompiled.scriptSetupAst.map((node) => {
if (node.type === "ExpressionStatement")
node = node.expression;
return (0, import_common.isCallOf)(node, MACRO_DEFINE_PAGE) ? node : null;
}).filter((node) => !!node);
if (!definePageNodes.length) {
return;
} else if (definePageNodes.length > 1) {
throw new SyntaxError(`duplicate definePage() call`);
}
const definePageNode = definePageNodes[0];
const setupOffset = scriptSetup.loc.start.offset;
const routeRecord = definePageNode.arguments[0];
if (routeRecord.type !== "ObjectExpression") {
throw new SyntaxError(
`[${id}]: definePage() expects an object expression as its only argument`
);
}
const routeInfo = {};
for (const prop of routeRecord.properties) {
if (prop.type === "ObjectProperty" && prop.key.type === "Identifier") {
if (prop.key.name === "name") {
if (prop.value.type !== "StringLiteral") {
console.warn(
`[unplugin-vue-router]: route name must be a string literal. Found in "${id}".`
);
} else {
routeInfo.name = prop.value.value;
}
} else if (prop.key.name === "path") {
if (prop.value.type !== "StringLiteral") {
console.warn(
`[unplugin-vue-router]: route path must be a string literal. Found in "${id}".`
);
} else {
routeInfo.path = prop.value.value;
}
}
}
}
return routeInfo;
}
var getIdentifiers = (stmts) => {

@@ -924,7 +994,14 @@ let ids = [];

}
async function writeRouteInfoToNode(node, path) {
const content = await import_fs3.promises.readFile(path, "utf8");
node.hasDefinePage = content.includes("definePage");
const [definedPageNameAndPath, routeBlock] = await Promise.all([
extractDefinePageNameAndPath(content, path),
getRouteBlock(path, options)
]);
node.setCustomRouteBlock(path, __spreadValues(__spreadValues({}, routeBlock), definedPageNameAndPath));
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(path);
}
async function addPage({ filePath: path, routePath }) {
const routeBlock = await getRouteBlock(path, options);
log(`added "${routePath}" for "${path}"`);
if (routeBlock)
log(routeBlock);
const node = routeTree.insert(

@@ -934,7 +1011,4 @@ routePath,

);
node.setCustomRouteBlock(path, routeBlock);
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(path);
await writeRouteInfoToNode(node, path);
routeMap.set(path, node);
const content = await import_fs3.promises.readFile(path, "utf8");
node.hasDefinePage = content.includes("definePage");
}

@@ -948,6 +1022,3 @@ async function updatePage({ filePath: path, routePath }) {

}
const content = await import_fs3.promises.readFile(path, "utf8");
node.hasDefinePage = content.includes("definePage");
node.setCustomRouteBlock(path, await getRouteBlock(path, options));
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(path);
writeRouteInfoToNode(node, path);
}

@@ -1006,3 +1077,3 @@ function removePage({ filePath: path, routePath }) {

async function _writeConfigFiles() {
log("writing");
log("\u{1F4BE} writing...");
logTree(routeTree, log);

@@ -1069,11 +1140,8 @@ if (dts) {

options.routesFolder || DEFAULT_OPTIONS.routesFolder
).map((routeOption) => ({
...routeOption,
).map((routeOption) => __spreadProps(__spreadValues({}, routeOption), {
src: (0, import_pathe3.resolve)(root, routeOption.src)
}));
return {
...DEFAULT_OPTIONS,
...options,
return __spreadProps(__spreadValues(__spreadValues({}, DEFAULT_OPTIONS), options), {
routesFolder
};
});
}

@@ -1080,0 +1148,0 @@

import { Router, RouteLocationNormalized, RouteRecordRaw } from 'vue-router';
import { b as DataLoader, A as Awaitable } from './defineLoader-24fcbf59.js';
export { b as DataLoader, D as DefineLoaderOptions, d as _defineLoader, s as _stopDataFetchingScope } from './defineLoader-24fcbf59.js';
import './options-dcd51c9e.js';
import { b as DataLoader, A as Awaitable } from './defineLoader-23e4921c.js';
export { D as DefineLoaderOptions, d as _defineLoader, s as _stopDataFetchingScope } from './defineLoader-23e4921c.js';
import './options-adeff310.js';
import 'vue';

@@ -17,3 +17,3 @@

}
declare type NavigationResult = any;
type NavigationResult = any;
interface SetupDataFetchingGuardOptions {

@@ -44,2 +44,2 @@ /**

export { HasDataLoaderMeta as _HasDataLoaderMeta, _definePage, _mergeRouteRecord, setupDataFetchingGuard as _setupDataFetchingGuard };
export { DataLoader, HasDataLoaderMeta as _HasDataLoaderMeta, _definePage, _mergeRouteRecord, setupDataFetchingGuard as _setupDataFetchingGuard };
"use strict";
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __export = (target, all) => {

@@ -39,12 +56,12 @@ for (var name in all)

const { cacheTime } = options;
return !cacheTime || Date.now() - entry.when >= cacheTime || Array.from(entry.loaders).some(
return !cacheTime || Date.now() - entry.when >= cacheTime || Array.from(entry.children).some(
(childEntry) => isCacheExpired(childEntry, options)
);
}
function createDataCacheEntry(options, initialData) {
function createDataLoaderEntry(options, initialData) {
return withinScope(() => ({
pending: (0, import_vue.ref)(false),
error: (0, import_vue.ref)(),
when: Date.now(),
loaders: /* @__PURE__ */ new Set(),
when: initialData === void 0 ? Date.now() : 0,
children: /* @__PURE__ */ new Set(),
data: (0, import_vue.ref)(initialData),

@@ -56,3 +73,3 @@ params: {},

}
function updateDataCacheEntry(entry, data, params, query, hash) {
function updateDataLoaderEntry(entry, data, params, query, hash) {
entry.when = Date.now();

@@ -111,3 +128,7 @@ entry.params = params;

opts = typeof _loaderOrOptions === "object" ? _loaderOrOptions : opts;
const options = { ...DEFAULT_DEFINE_LOADER_OPTIONS, ...opts };
const options = __spreadValues(__spreadValues({}, DEFAULT_DEFINE_LOADER_OPTIONS), opts);
const entries = /* @__PURE__ */ new WeakMap();
let pendingPromise;
let currentNavigation;
const pendingLoad = () => pendingPromise;
const dataLoader = () => {

@@ -117,9 +138,9 @@ let [parentEntry, _router, _route] = getCurrentContext();

const route = _route || (0, import_vue_router.useRoute)();
if (!cache.has(router) || parentEntry) {
if (!entries.has(router) || parentEntry) {
load(route, router, parentEntry);
}
const entry = cache.get(router);
const entry = entries.get(router);
const promise = Promise.resolve(pendingPromise).then(() => dataLoaderResult).finally(() => {
if (parentEntry) {
parentEntry.loaders.add(entry);
parentEntry.children.add(entry);
}

@@ -148,13 +169,9 @@ setCurrentContext(parentEntry && [parentEntry, router, route]);

};
const cache = /* @__PURE__ */ new WeakMap();
let pendingPromise;
let currentNavigation;
const pendingLoad = () => pendingPromise;
function load(route, router, parent, initialRootData) {
const hasCacheEntry = cache.has(router);
const hasCacheEntry = entries.has(router);
const initialData = initialRootData && initialRootData[options.key];
if (!hasCacheEntry) {
cache.set(router, createDataCacheEntry(options, initialData));
entries.set(router, createDataLoaderEntry(options, initialData));
}
const entry = cache.get(router);
const entry = entries.get(router);
if (initialData) {

@@ -181,3 +198,3 @@ entry.when = 0;

if (pendingPromise === thisPromise) {
updateDataCacheEntry(entry, data, params, query, hash);
updateDataLoaderEntry(entry, data, params, query, hash);
}

@@ -198,4 +215,3 @@ }).catch((err) => {

dataLoader._ = {
loader,
cache,
entries,
load,

@@ -208,3 +224,3 @@ options

function shouldFetchAgain(entry, route) {
return !entry.when || !includesParams(route.params, entry.params) || !includesParams(route.query, entry.query) || entry.hash != null && entry.hash !== route.hash || Array.from(entry.loaders).some(
return !entry.when || !includesParams(route.params, entry.params) || !includesParams(route.query, entry.query) || entry.hash != null && entry.hash !== route.hash || Array.from(entry.children).some(
(childEntry) => shouldFetchAgain(childEntry, route)

@@ -222,4 +238,3 @@ );

return [
{
...route,
__spreadProps(__spreadValues({}, route), {
get hash() {

@@ -230,3 +245,3 @@ return hash.v = route.hash;

query
},
}),
paramReads,

@@ -251,7 +266,2 @@ queryReads,

// src/core/utils.ts
var import_scule = require("scule");
var isArray = Array.isArray;
var __DEV__ = process.env.NODE_ENV !== "production";
// src/data-fetching/dataFetchingGuard.ts

@@ -261,3 +271,3 @@ var HasDataLoaderMeta = Symbol();

function setupDataFetchingGuard(router, { initialData } = {}) {
if (__DEV__) {
if (process.env.NODE_ENV !== "production") {
if (ADDED_SYMBOL in router) {

@@ -275,3 +285,3 @@ console.warn(

return Promise.all(
to.matched.flatMap((route) => route.meta[HasDataLoaderMeta]).filter((moduleImport) => moduleImport).map(
to.matched.flatMap((route) => route.meta[HasDataLoaderMeta]).filter(Boolean).map(
(moduleImport) => moduleImport().then((mod) => {

@@ -283,3 +293,3 @@ const loaders = Object.keys(mod).filter((exportName) => isDataLoader(mod[exportName])).map((loaderName) => mod[loaderName]);

options: { key },
cache
entries
} = loader._;

@@ -294,5 +304,5 @@ return loader._.load(

if (key) {
fetchedState[key] = cache.get(router).data.value;
fetchedState[key] = entries.get(router).data.value;
}
} else if (__DEV__ && !key && !isFetched) {
} else if (process.env.NODE_ENV !== "production" && !key && !isFetched) {
}

@@ -299,0 +309,0 @@ });

import * as vite from 'vite';
import { O as Options } from './options-dcd51c9e.js';
import { O as Options } from './options-adeff310.js';
import 'vue-router';
declare const _default: (options?: Options | undefined) => vite.Plugin;
declare const _default: (options?: Options | undefined) => vite.Plugin | vite.Plugin[];
export { _default as default };
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __export = (target, all) => {

@@ -113,2 +130,3 @@ for (var name in all)

function mergeRouteRecordOverride(a, b) {
var _a;
const merged = {};

@@ -127,3 +145,3 @@ const keys = [

} else {
merged[key] = b[key] ?? a[key];
merged[key] = (_a = b[key]) != null ? _a : a[key];
}

@@ -152,3 +170,2 @@ }

}
var __DEV__ = process.env.NODE_ENV !== "production";

@@ -352,7 +369,8 @@ // src/core/treeNodeValue.ts

get path() {
var _a;
return this.value.overrides.path ?? (((_a = this.parent) == null ? void 0 : _a.isRoot()) ? "/" : "") + this.value.pathSegment;
var _a, _b;
return (_b = this.value.overrides.path) != null ? _b : (((_a = this.parent) == null ? void 0 : _a.isRoot()) ? "/" : "") + this.value.pathSegment;
}
get fullPath() {
return this.value.overrides.path ?? this.value.path;
var _a;
return (_a = this.value.overrides.path) != null ? _a : this.value.path;
}

@@ -363,3 +381,3 @@ get name() {

get meta() {
const overrideMeta = { ...this.value.overrides.meta };
const overrideMeta = __spreadValues({}, this.value.overrides.meta);
if (this.value.includeLoaderGuard) {

@@ -555,3 +573,4 @@ overrideMeta._loaderGuard = true;

function parseCustomBlock(block, filePath, options) {
const lang = block.lang ?? options.routeBlockLang;
var _a;
const lang = (_a = block.lang) != null ? _a : options.routeBlockLang;
if (lang === "json5") {

@@ -726,2 +745,4 @@ try {

export const RouterLink: RouterLinkTyped<RouteNamedMap>
// Experimental Data Fetching

@@ -853,2 +874,51 @@

}
function extractDefinePageNameAndPath(sfcCode, id) {
if (!sfcCode.includes(MACRO_DEFINE_PAGE))
return;
const sfc = (0, import_common.parseSFC)(sfcCode, id);
if (!sfc.scriptSetup)
return;
const { script, scriptSetup, scriptCompiled } = sfc;
const definePageNodes = scriptCompiled.scriptSetupAst.map((node) => {
if (node.type === "ExpressionStatement")
node = node.expression;
return (0, import_common.isCallOf)(node, MACRO_DEFINE_PAGE) ? node : null;
}).filter((node) => !!node);
if (!definePageNodes.length) {
return;
} else if (definePageNodes.length > 1) {
throw new SyntaxError(`duplicate definePage() call`);
}
const definePageNode = definePageNodes[0];
const setupOffset = scriptSetup.loc.start.offset;
const routeRecord = definePageNode.arguments[0];
if (routeRecord.type !== "ObjectExpression") {
throw new SyntaxError(
`[${id}]: definePage() expects an object expression as its only argument`
);
}
const routeInfo = {};
for (const prop of routeRecord.properties) {
if (prop.type === "ObjectProperty" && prop.key.type === "Identifier") {
if (prop.key.name === "name") {
if (prop.value.type !== "StringLiteral") {
console.warn(
`[unplugin-vue-router]: route name must be a string literal. Found in "${id}".`
);
} else {
routeInfo.name = prop.value.value;
}
} else if (prop.key.name === "path") {
if (prop.value.type !== "StringLiteral") {
console.warn(
`[unplugin-vue-router]: route path must be a string literal. Found in "${id}".`
);
} else {
routeInfo.path = prop.value.value;
}
}
}
}
return routeInfo;
}
var getIdentifiers = (stmts) => {

@@ -924,7 +994,14 @@ let ids = [];

}
async function writeRouteInfoToNode(node, path) {
const content = await import_fs3.promises.readFile(path, "utf8");
node.hasDefinePage = content.includes("definePage");
const [definedPageNameAndPath, routeBlock] = await Promise.all([
extractDefinePageNameAndPath(content, path),
getRouteBlock(path, options)
]);
node.setCustomRouteBlock(path, __spreadValues(__spreadValues({}, routeBlock), definedPageNameAndPath));
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(path);
}
async function addPage({ filePath: path, routePath }) {
const routeBlock = await getRouteBlock(path, options);
log(`added "${routePath}" for "${path}"`);
if (routeBlock)
log(routeBlock);
const node = routeTree.insert(

@@ -934,7 +1011,4 @@ routePath,

);
node.setCustomRouteBlock(path, routeBlock);
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(path);
await writeRouteInfoToNode(node, path);
routeMap.set(path, node);
const content = await import_fs3.promises.readFile(path, "utf8");
node.hasDefinePage = content.includes("definePage");
}

@@ -948,6 +1022,3 @@ async function updatePage({ filePath: path, routePath }) {

}
const content = await import_fs3.promises.readFile(path, "utf8");
node.hasDefinePage = content.includes("definePage");
node.setCustomRouteBlock(path, await getRouteBlock(path, options));
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(path);
writeRouteInfoToNode(node, path);
}

@@ -1006,3 +1077,3 @@ function removePage({ filePath: path, routePath }) {

async function _writeConfigFiles() {
log("writing");
log("\u{1F4BE} writing...");
logTree(routeTree, log);

@@ -1069,11 +1140,8 @@ if (dts) {

options.routesFolder || DEFAULT_OPTIONS.routesFolder
).map((routeOption) => ({
...routeOption,
).map((routeOption) => __spreadProps(__spreadValues({}, routeOption), {
src: (0, import_pathe3.resolve)(root, routeOption.src)
}));
return {
...DEFAULT_OPTIONS,
...options,
return __spreadProps(__spreadValues(__spreadValues({}, DEFAULT_OPTIONS), options), {
routesFolder
};
});
}

@@ -1080,0 +1148,0 @@

import * as webpack from 'webpack';
import { O as Options } from './options-dcd51c9e.js';
import { O as Options } from './options-adeff310.js';
import 'vue-router';

@@ -4,0 +4,0 @@

"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __export = (target, all) => {

@@ -113,2 +130,3 @@ for (var name in all)

function mergeRouteRecordOverride(a, b) {
var _a;
const merged = {};

@@ -127,3 +145,3 @@ const keys = [

} else {
merged[key] = b[key] ?? a[key];
merged[key] = (_a = b[key]) != null ? _a : a[key];
}

@@ -152,3 +170,2 @@ }

}
var __DEV__ = process.env.NODE_ENV !== "production";

@@ -352,7 +369,8 @@ // src/core/treeNodeValue.ts

get path() {
var _a;
return this.value.overrides.path ?? (((_a = this.parent) == null ? void 0 : _a.isRoot()) ? "/" : "") + this.value.pathSegment;
var _a, _b;
return (_b = this.value.overrides.path) != null ? _b : (((_a = this.parent) == null ? void 0 : _a.isRoot()) ? "/" : "") + this.value.pathSegment;
}
get fullPath() {
return this.value.overrides.path ?? this.value.path;
var _a;
return (_a = this.value.overrides.path) != null ? _a : this.value.path;
}

@@ -363,3 +381,3 @@ get name() {

get meta() {
const overrideMeta = { ...this.value.overrides.meta };
const overrideMeta = __spreadValues({}, this.value.overrides.meta);
if (this.value.includeLoaderGuard) {

@@ -555,3 +573,4 @@ overrideMeta._loaderGuard = true;

function parseCustomBlock(block, filePath, options) {
const lang = block.lang ?? options.routeBlockLang;
var _a;
const lang = (_a = block.lang) != null ? _a : options.routeBlockLang;
if (lang === "json5") {

@@ -726,2 +745,4 @@ try {

export const RouterLink: RouterLinkTyped<RouteNamedMap>
// Experimental Data Fetching

@@ -853,2 +874,51 @@

}
function extractDefinePageNameAndPath(sfcCode, id) {
if (!sfcCode.includes(MACRO_DEFINE_PAGE))
return;
const sfc = (0, import_common.parseSFC)(sfcCode, id);
if (!sfc.scriptSetup)
return;
const { script, scriptSetup, scriptCompiled } = sfc;
const definePageNodes = scriptCompiled.scriptSetupAst.map((node) => {
if (node.type === "ExpressionStatement")
node = node.expression;
return (0, import_common.isCallOf)(node, MACRO_DEFINE_PAGE) ? node : null;
}).filter((node) => !!node);
if (!definePageNodes.length) {
return;
} else if (definePageNodes.length > 1) {
throw new SyntaxError(`duplicate definePage() call`);
}
const definePageNode = definePageNodes[0];
const setupOffset = scriptSetup.loc.start.offset;
const routeRecord = definePageNode.arguments[0];
if (routeRecord.type !== "ObjectExpression") {
throw new SyntaxError(
`[${id}]: definePage() expects an object expression as its only argument`
);
}
const routeInfo = {};
for (const prop of routeRecord.properties) {
if (prop.type === "ObjectProperty" && prop.key.type === "Identifier") {
if (prop.key.name === "name") {
if (prop.value.type !== "StringLiteral") {
console.warn(
`[unplugin-vue-router]: route name must be a string literal. Found in "${id}".`
);
} else {
routeInfo.name = prop.value.value;
}
} else if (prop.key.name === "path") {
if (prop.value.type !== "StringLiteral") {
console.warn(
`[unplugin-vue-router]: route path must be a string literal. Found in "${id}".`
);
} else {
routeInfo.path = prop.value.value;
}
}
}
}
return routeInfo;
}
var getIdentifiers = (stmts) => {

@@ -924,7 +994,14 @@ let ids = [];

}
async function writeRouteInfoToNode(node, path) {
const content = await import_fs3.promises.readFile(path, "utf8");
node.hasDefinePage = content.includes("definePage");
const [definedPageNameAndPath, routeBlock] = await Promise.all([
extractDefinePageNameAndPath(content, path),
getRouteBlock(path, options)
]);
node.setCustomRouteBlock(path, __spreadValues(__spreadValues({}, routeBlock), definedPageNameAndPath));
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(path);
}
async function addPage({ filePath: path, routePath }) {
const routeBlock = await getRouteBlock(path, options);
log(`added "${routePath}" for "${path}"`);
if (routeBlock)
log(routeBlock);
const node = routeTree.insert(

@@ -934,7 +1011,4 @@ routePath,

);
node.setCustomRouteBlock(path, routeBlock);
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(path);
await writeRouteInfoToNode(node, path);
routeMap.set(path, node);
const content = await import_fs3.promises.readFile(path, "utf8");
node.hasDefinePage = content.includes("definePage");
}

@@ -948,6 +1022,3 @@ async function updatePage({ filePath: path, routePath }) {

}
const content = await import_fs3.promises.readFile(path, "utf8");
node.hasDefinePage = content.includes("definePage");
node.setCustomRouteBlock(path, await getRouteBlock(path, options));
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(path);
writeRouteInfoToNode(node, path);
}

@@ -1006,3 +1077,3 @@ function removePage({ filePath: path, routePath }) {

async function _writeConfigFiles() {
log("writing");
log("\u{1F4BE} writing...");
logTree(routeTree, log);

@@ -1069,11 +1140,8 @@ if (dts) {

options.routesFolder || DEFAULT_OPTIONS.routesFolder
).map((routeOption) => ({
...routeOption,
).map((routeOption) => __spreadProps(__spreadValues({}, routeOption), {
src: (0, import_pathe3.resolve)(root, routeOption.src)
}));
return {
...DEFAULT_OPTIONS,
...options,
return __spreadProps(__spreadValues(__spreadValues({}, DEFAULT_OPTIONS), options), {
routesFolder
};
});
}

@@ -1080,0 +1148,0 @@

{
"name": "unplugin-vue-router",
"version": "0.2.3",
"packageManager": "pnpm@7.13.0",
"version": "0.3.0",
"packageManager": "pnpm@7.21.0",
"description": "File based typed routing for Vue Router",

@@ -79,15 +79,15 @@ "keywords": [

"dependencies": {
"@babel/types": "^7.19.3",
"@rollup/pluginutils": "^4.2.1",
"@vue-macros/common": "^0.11.2",
"ast-walker-scope": "^0.2.3",
"@babel/types": "^7.20.7",
"@rollup/pluginutils": "^5.0.2",
"@vue-macros/common": "^0.13.5",
"ast-walker-scope": "^0.3.1",
"chokidar": "^3.5.3",
"fast-glob": "^3.2.12",
"json5": "^2.2.1",
"json5": "^2.2.3",
"local-pkg": "^0.4.2",
"mlly": "^0.5.16",
"pathe": "^0.3.8",
"scule": "^0.3.2",
"unplugin": "^0.9.6",
"yaml": "^2.1.2"
"mlly": "^1.0.0",
"pathe": "^1.0.0",
"scule": "^1.0.0",
"unplugin": "^1.0.1",
"yaml": "^2.2.1"
},

@@ -103,5 +103,5 @@ "peerDependencies": {

"devDependencies": {
"@volar/vue-language-core": "^0.40.13",
"@volar/vue-language-core": "^1.0.19",
"c8": "^7.12.0",
"chalk": "^5.0.1",
"chalk": "^5.2.0",
"conventional-changelog-cli": "^2.2.2",

@@ -111,19 +111,19 @@ "enquirer": "^2.3.6",

"execa": "^6.1.0",
"lint-staged": "^13.0.3",
"minimist": "^1.2.6",
"lint-staged": "^13.1.0",
"minimist": "^1.2.7",
"nodemon": "^2.0.20",
"p-series": "^3.0.0",
"prettier": "^2.7.1",
"prettier": "^2.8.1",
"rimraf": "^3.0.2",
"rollup": "^2.79.1",
"semver": "^7.3.7",
"rollup": "^3.9.0",
"semver": "^7.3.8",
"ts-expect": "^1.3.0",
"tsup": "^6.2.3",
"typescript": "^4.8.4",
"unplugin-auto-import": "^0.11.2",
"vite": "^3.1.4",
"vitest": "^0.23.4",
"vue": "^3.2.40",
"vue-router": "^4.1.5",
"webpack": "^5.74.0",
"tsup": "^6.5.0",
"typescript": "^4.9.4",
"unplugin-auto-import": "^0.12.1",
"vite": "^4.0.3",
"vitest": "^0.26.3",
"vue": "^3.2.45",
"vue-router": "^4.1.6",
"webpack": "^5.75.0",
"yorkie": "^2.0.0"

@@ -130,0 +130,0 @@ },

@@ -184,2 +184,17 @@ # unplugin-vue-router

Note that the `vue-router` preset might export less things than the one exported by `unplugin-vue-router` so you might need to add any other imports you were relying on manually:
```diff
AutoImport({
imports: [
- 'vue-router',
+ VueRouterAutoImports,
+ {
+ // add any other imports you were relying on
+ 'vue-router/auto': ['useLink']
+ },
],
}),
```
Make sure to also check and follow [the TypeScript section](#typescript) below **if you are using TypeScript or have a `jsconfig.json` file**.

@@ -445,9 +460,9 @@

#### `RouterLocationResolved`
#### `RouteLocationResolved`
The `RouterLocationResolved` type exposed by `vue-router/auto` allows passing a generic (which autocomplete) to type a route **whenever checking the name doesn't makes sense because you know the type**. This is useful for cases like `<RouterLink v-slot="{ route }">`:
The `RouteLocationResolved` type exposed by `vue-router/auto` allows passing a generic (which autocomplete) to type a route **whenever checking the name doesn't makes sense because you know the type**. This is useful for cases like `<RouterLink v-slot="{ route }">`:
```vue
<RouterLink v-slot="{ route }">
User {{ (route as RouterLocationResolved<'/users/[id]'>).params.id }}
User {{ (route as RouteLocationResolved<'/users/[id]'>).params.id }}
</RouterLink>

@@ -458,7 +473,7 @@ ```

You have the same equivalents for `RouterLocation`, `RouterLocationNormalized`, and `RouterLocationNormalizedLoaded`. All of them exist in `vue-router` but `vue-router/auto` override them to provide a type safe version of them. In addition to that, you can pass the name of the route as a generic:
You have the same equivalents for `RouteLocation`, `RouteLocationNormalized`, and `RouteLocationNormalizedLoaded`. All of them exist in `vue-router` but `vue-router/auto` override them to provide a type safe version of them. In addition to that, you can pass the name of the route as a generic:
```ts
// these are all valid
let userWithId: RouterLocationNormalizedLoaded<'/users/[id]'> = useRoute()
let userWithId: RouteLocationNormalizedLoaded<'/users/[id]'> = useRoute()
userWithId = useRoute<'/users/[id]'>()

@@ -465,0 +480,0 @@ // 👇 this one is the easiest to write because it autocomplete

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc