unplugin-vue-router
Advanced tools
Comparing version 0.6.4 to 0.7.0
import * as esbuild from 'esbuild'; | ||
import { O as Options } from './options-56006a88.js'; | ||
import { O as Options } from './options-8dbadba3.js'; | ||
import 'vue-router'; | ||
@@ -4,0 +4,0 @@ |
@@ -12,2 +12,7 @@ "use strict"; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __knownSymbol = (name, symbol) => { | ||
if (symbol = Symbol[name]) | ||
return symbol; | ||
throw Error("Symbol." + name + " is not defined"); | ||
}; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
@@ -47,2 +52,39 @@ var __spreadValues = (a, b) => { | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var __await = function(promise, isYieldStar) { | ||
this[0] = promise; | ||
this[1] = isYieldStar; | ||
}; | ||
var __yieldStar = (value) => { | ||
var obj = value[__knownSymbol("asyncIterator")]; | ||
var isAwait = false; | ||
var method; | ||
var it = {}; | ||
if (obj == null) { | ||
obj = value[__knownSymbol("iterator")](); | ||
method = (k) => it[k] = (x) => obj[k](x); | ||
} else { | ||
obj = obj.call(value); | ||
method = (k) => it[k] = (v) => { | ||
if (isAwait) { | ||
isAwait = false; | ||
if (k === "throw") | ||
throw v; | ||
return v; | ||
} | ||
isAwait = true; | ||
return { | ||
done: false, | ||
value: new __await(new Promise((resolve4) => { | ||
var x = obj[k](v); | ||
if (!(x instanceof Object)) | ||
throw TypeError("Object expected"); | ||
resolve4(x); | ||
}), 1) | ||
}; | ||
}; | ||
} | ||
return it[__knownSymbol("iterator")] = () => it, method("next"), "throw" in obj ? method("throw") : it.throw = (x) => { | ||
throw x; | ||
}, "return" in obj && method("return"), it; | ||
}; | ||
@@ -185,7 +227,7 @@ // src/esbuild.ts | ||
function asRoutePath({ src, path = "" }, filePath) { | ||
return ( | ||
return typeof path === "string" ? ( | ||
// add the path prefix if any | ||
path + // remove the absolute path to the pages folder | ||
filePath.slice(src.length + 1) | ||
); | ||
) : path(filePath); | ||
} | ||
@@ -256,2 +298,3 @@ function appendExtensionListToPattern(filePatterns, extensions) { | ||
this._overrides = /* @__PURE__ */ new Map(); | ||
// TODO: cache the overrides generation | ||
/** | ||
@@ -270,6 +313,13 @@ * Should we add the loader guard to the route record. | ||
this.subSegments = subSegments; | ||
const parentPath = parent == null ? void 0 : parent.path; | ||
this.path = // both the root record and the index record have a path of / | ||
(!parentPath || parentPath === "/") && this.pathSegment === "" ? "/" : joinPath((parent == null ? void 0 : parent.path) || "", this.pathSegment); | ||
this.parent = parent; | ||
} | ||
/** | ||
* fullPath of the node based on parent nodes | ||
*/ | ||
get path() { | ||
var _a, _b; | ||
const parentPath = (_a = this.parent) == null ? void 0 : _a.path; | ||
const pathSegment = (_b = this.overrides.path) != null ? _b : this.pathSegment; | ||
return (!parentPath || parentPath === "/") && pathSegment === "" ? "/" : joinPath(parentPath || "", pathSegment); | ||
} | ||
toString() { | ||
@@ -294,4 +344,4 @@ return this.pathSegment || "<index>"; | ||
} | ||
setOverride(path, routeBlock) { | ||
this._overrides.set(path, routeBlock || {}); | ||
setOverride(filePath, routeBlock) { | ||
this._overrides.set(filePath, routeBlock || {}); | ||
} | ||
@@ -301,3 +351,3 @@ /** | ||
* | ||
* @param key - key to remove from the override | ||
* @param key - key to remove from the override, e.g. path, name, etc | ||
*/ | ||
@@ -309,9 +359,29 @@ removeOverride(key) { | ||
} | ||
mergeOverride(path, routeBlock) { | ||
const existing = this._overrides.get(path) || {}; | ||
this._overrides.set(path, mergeRouteRecordOverride(existing, routeBlock)); | ||
/** | ||
* Add an override to the current node by merging with the existing values. | ||
* | ||
* @param filePath - The file path to add to the override | ||
* @param routeBlock - The route block to add to the override | ||
*/ | ||
mergeOverride(filePath, routeBlock) { | ||
const existing = this._overrides.get(filePath) || {}; | ||
this._overrides.set( | ||
filePath, | ||
mergeRouteRecordOverride(existing, routeBlock) | ||
); | ||
} | ||
/** | ||
* Add an override to the current node using the special file path `@@edits` that makes this added at build time. | ||
* | ||
* @param routeBlock - The route block to add to the override | ||
*/ | ||
addEditOverride(routeBlock) { | ||
return this.mergeOverride(EDITS_OVERRIDE_NAME, routeBlock); | ||
} | ||
/** | ||
* Set a specific value in the _edits_ override. | ||
* | ||
* @param key - key to set in the override, e.g. path, name, etc | ||
* @param value - value to set in the override | ||
*/ | ||
setEditOverride(key, value) { | ||
@@ -536,4 +606,11 @@ if (!this._overrides.has(EDITS_OVERRIDE_NAME)) { | ||
// src/core/tree.ts | ||
var TreeNode = class { | ||
constructor(options, filePath, parent) { | ||
var TreeNode = class _TreeNode { | ||
/** | ||
* Creates a new tree node. | ||
* | ||
* @param options - TreeNodeOptions shared by all nodes | ||
* @param pathSegment - path segment of this node e.g. `users` or `:id` | ||
* @param parent | ||
*/ | ||
constructor(options, pathSegment, parent) { | ||
/** | ||
@@ -550,3 +627,3 @@ * children of the node | ||
this.value = createTreeNodeValue( | ||
filePath, | ||
pathSegment, | ||
parent == null ? void 0 : parent.value, | ||
@@ -569,3 +646,3 @@ options.treeNodeOptions || options.pathParser | ||
if (!this.children.has(segment)) { | ||
this.children.set(segment, new TreeNode(this.options, segment, this)); | ||
this.children.set(segment, new _TreeNode(this.options, segment, this)); | ||
} | ||
@@ -582,3 +659,4 @@ const child = this.children.get(segment); | ||
/** | ||
* Adds a path to the tree. `path` cannot start with a `/`. | ||
* Adds a path that has already been parsed to the tree. `path` cannot start with a `/`. This method is similar to | ||
* `insert` but the path argument should be already parsed. e.g. `users/:id` for a file named `users/[id].vue`. | ||
* | ||
@@ -590,3 +668,3 @@ * @param path - path segment to insert, already parsed (e.g. users/:id) | ||
const isComponent = true; | ||
const node = new TreeNode( | ||
const node = new _TreeNode( | ||
__spreadProps(__spreadValues({}, this.options), { | ||
@@ -607,4 +685,11 @@ // force the format to raw | ||
} | ||
setCustomRouteBlock(path, routeBlock) { | ||
this.value.setOverride(path, routeBlock); | ||
/** | ||
* Saves a custom route block for a specific file path. The file path is used as a key. Some special file paths will | ||
* have a lower or higher priority. | ||
* | ||
* @param filePath - file path where the custom block is located | ||
* @param routeBlock - custom block to set | ||
*/ | ||
setCustomRouteBlock(filePath, routeBlock) { | ||
this.value.setOverride(filePath, routeBlock); | ||
} | ||
@@ -730,2 +815,7 @@ getSortedChildren() { | ||
} | ||
/** | ||
* Returns the tree node of the given file path. | ||
* | ||
* @param filePath - file path of the tree node to get | ||
*/ | ||
getChild(filePath) { | ||
@@ -735,4 +825,5 @@ return this.map.get(filePath); | ||
/** | ||
* Removes the tree node of the given file path. | ||
* | ||
* @param filePath - | ||
* @param filePath - file path of the tree node to remove | ||
*/ | ||
@@ -746,5 +837,2 @@ removeChild(filePath) { | ||
}; | ||
function createPrefixTree(options) { | ||
return new PrefixTree(options); | ||
} | ||
function splitFilePath(filePath, options) { | ||
@@ -969,11 +1057,14 @@ const slashPos = filePath.indexOf("/"); | ||
var RoutesFolderWatcher = class { | ||
constructor(routesFolder, options) { | ||
this.src = routesFolder.src; | ||
this.pathPrefix = routesFolder.path || ""; | ||
this.options = options; | ||
this.watcher = import_chokidar.default.watch(this.src, { | ||
constructor(folderOptions) { | ||
this.src = folderOptions.src; | ||
this.path = folderOptions.path; | ||
this.exclude = folderOptions.exclude; | ||
this.extensions = folderOptions.extensions; | ||
this.filePatterns = folderOptions.filePatterns; | ||
this.watcher = import_chokidar.default.watch(folderOptions.pattern, { | ||
cwd: this.src, | ||
ignoreInitial: true, | ||
// disableGlobbing: true, | ||
ignorePermissionErrors: true, | ||
ignored: options.exclude | ||
ignored: this.exclude | ||
// useFsEvents: true, | ||
@@ -985,14 +1076,9 @@ // TODO: allow user options | ||
this.watcher.on(event, (filePath) => { | ||
filePath = (0, import_pathe.normalize)(filePath); | ||
if (this.options.extensions.every( | ||
(extension) => !filePath.endsWith(extension) | ||
)) { | ||
if (this.extensions.every((extension) => !filePath.endsWith(extension))) { | ||
return; | ||
} | ||
filePath = (0, import_pathe.resolve)(this.src, filePath); | ||
handler({ | ||
filePath, | ||
routePath: asRoutePath( | ||
{ src: this.src, path: this.pathPrefix }, | ||
filePath | ||
) | ||
routePath: asRoutePath({ src: this.src, path: this.path }, filePath) | ||
}); | ||
@@ -1006,2 +1092,36 @@ }); | ||
}; | ||
function resolveFolderOptions(globalOptions, folderOptions) { | ||
const extensions = overrideOption( | ||
globalOptions.extensions, | ||
folderOptions.extensions | ||
); | ||
const filePatterns = overrideOption( | ||
globalOptions.filePatterns, | ||
folderOptions.filePatterns | ||
); | ||
return { | ||
src: folderOptions.src, | ||
pattern: appendExtensionListToPattern( | ||
filePatterns, | ||
// also override the extensions if the folder has a custom extensions | ||
extensions | ||
), | ||
path: folderOptions.path || "", | ||
extensions, | ||
filePatterns, | ||
exclude: overrideOption(globalOptions.exclude, folderOptions.exclude).map( | ||
(p) => p.startsWith("**") ? p : (0, import_pathe.resolve)(p) | ||
) | ||
}; | ||
} | ||
function overrideOption(existing, newValue) { | ||
const asArray = typeof existing === "string" ? [existing] : existing; | ||
if (typeof newValue === "function") { | ||
return newValue(asArray); | ||
} | ||
if (typeof newValue !== "undefined") { | ||
return typeof newValue === "string" ? [newValue] : newValue; | ||
} | ||
return asArray; | ||
} | ||
@@ -1321,3 +1441,3 @@ // src/codegen/generateDTS.ts | ||
// src/core/extendRoutes.ts | ||
var EditableTreeNode = class { | ||
var EditableTreeNode = class _EditableTreeNode { | ||
// private _parent?: EditableTreeNode | ||
@@ -1348,3 +1468,3 @@ constructor(node) { | ||
const node = this.node.insertParsedPath(path, filePath); | ||
const editable = new EditableTreeNode(node); | ||
const editable = new _EditableTreeNode(node); | ||
if (addBackLeadingSlash) { | ||
@@ -1359,3 +1479,3 @@ editable.path = "/" + node.path; | ||
get parent() { | ||
return this.node.parent && new EditableTreeNode(this.node.parent); | ||
return this.node.parent && new _EditableTreeNode(this.node.parent); | ||
} | ||
@@ -1462,3 +1582,3 @@ /** | ||
return [...this.node.children.values()].map( | ||
(node) => new EditableTreeNode(node) | ||
(node) => new _EditableTreeNode(node) | ||
); | ||
@@ -1480,7 +1600,7 @@ } | ||
for (const [_name, child] of this.node.children) { | ||
yield* new EditableTreeNode(child).traverseDFS(); | ||
yield* __yieldStar(new _EditableTreeNode(child).traverseDFS()); | ||
} | ||
} | ||
*[Symbol.iterator]() { | ||
yield* this.traverseBFS(); | ||
yield* __yieldStar(this.traverseBFS()); | ||
} | ||
@@ -1499,6 +1619,6 @@ /** | ||
for (const [_name, child] of this.node.children) { | ||
yield new EditableTreeNode(child); | ||
yield new _EditableTreeNode(child); | ||
} | ||
for (const [_name, child] of this.node.children) { | ||
yield* new EditableTreeNode(child).traverseBFS(); | ||
yield* __yieldStar(new _EditableTreeNode(child).traverseBFS()); | ||
} | ||
@@ -1512,3 +1632,3 @@ } | ||
const dts = preferDTS === false ? false : preferDTS === true ? (0, import_pathe2.resolve)(root, "typed-router.d.ts") : (0, import_pathe2.resolve)(root, preferDTS); | ||
const routeTree = createPrefixTree(options); | ||
const routeTree = new PrefixTree(options); | ||
const editableRoutes = new EditableTreeNode(routeTree); | ||
@@ -1531,24 +1651,21 @@ function log(...args) { | ||
} | ||
const globalPattern = appendExtensionListToPattern( | ||
options.filePatterns, | ||
options.extensions | ||
); | ||
await Promise.all( | ||
routesFolder.map((folder) => { | ||
routesFolder.map((folder) => resolveFolderOptions(options, folder)).map((folder) => { | ||
if (startWatchers) { | ||
watchers.push(setupWatcher(new RoutesFolderWatcher(folder, options))); | ||
watchers.push(setupWatcher(new RoutesFolderWatcher(folder))); | ||
} | ||
const pattern = folder.filePatterns ? appendExtensionListToPattern( | ||
folder.filePatterns, | ||
// also override the extensions if the folder has a custom extensions | ||
folder.extensions || options.extensions | ||
) : globalPattern; | ||
return (0, import_fast_glob.default)(pattern, { | ||
const ignorePattern = folder.exclude.map( | ||
(f) => ( | ||
// if it starts with ** then it will work as expected | ||
f.startsWith("**") ? f : (0, import_pathe2.relative)(folder.src, f) | ||
) | ||
); | ||
return (0, import_fast_glob.default)(folder.pattern, { | ||
cwd: folder.src, | ||
// TODO: do they return the symbolic link path or the original file? | ||
// followSymbolicLinks: false, | ||
ignore: folder.exclude || options.exclude | ||
}).then((files) => files.map((file) => (0, import_pathe2.resolve)(folder.src, file))).then( | ||
ignore: ignorePattern | ||
}).then( | ||
(files) => Promise.all( | ||
files.map( | ||
files.map((file) => (0, import_pathe2.resolve)(folder.src, file)).map( | ||
(file) => addPage({ | ||
@@ -1568,11 +1685,11 @@ routePath: asRoutePath(folder, file), | ||
} | ||
async function writeRouteInfoToNode(node, path) { | ||
const content = await import_fs3.promises.readFile(path, "utf8"); | ||
async function writeRouteInfoToNode(node, filePath) { | ||
const content = await import_fs3.promises.readFile(filePath, "utf8"); | ||
node.hasDefinePage = content.includes("definePage"); | ||
const [definedPageNameAndPath, routeBlock] = await Promise.all([ | ||
extractDefinePageNameAndPath(content, path), | ||
getRouteBlock(path, options) | ||
extractDefinePageNameAndPath(content, filePath), | ||
getRouteBlock(filePath, options) | ||
]); | ||
node.setCustomRouteBlock(path, __spreadValues(__spreadValues({}, routeBlock), definedPageNameAndPath)); | ||
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(path); | ||
node.setCustomRouteBlock(filePath, __spreadValues(__spreadValues({}, routeBlock), definedPageNameAndPath)); | ||
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(filePath); | ||
} | ||
@@ -1847,3 +1964,1 @@ async function addPage({ filePath, routePath }, triggerExtendRoute = false) { | ||
var esbuild_default = src_default.esbuild; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = {}); |
import * as unplugin from 'unplugin'; | ||
import { R as ResolvedOptions, S as ServerContext, O as Options } from './options-56006a88.js'; | ||
export { D as DEFAULT_OPTIONS, E as EditableTreeNode, T as TreeNode, d as TreeNodeValueParam, e as TreeNodeValueStatic, c as createPrefixTree, b as createTreeNodeValue, g as getFileBasedRouteName, a as getPascalCaseRouteName } from './options-56006a88.js'; | ||
export { N as NavigationGuard, P as ParamValue, r as ParamValueOneOrMore, s as ParamValueZeroOrMore, t as ParamValueZeroOrOne, c as RouteLocationAsPathTyped, d as RouteLocationAsPathTypedList, a as RouteLocationAsRelativeTyped, b as RouteLocationAsRelativeTypedList, e as RouteLocationAsString, l as RouteLocationNormalizedLoadedTyped, m as RouteLocationNormalizedLoadedTypedList, j as RouteLocationNormalizedTyped, k as RouteLocationNormalizedTypedList, h as RouteLocationResolvedTyped, i as RouteLocationResolvedTypedList, f as RouteLocationTyped, g as RouteLocationTypedList, R as RouteRecordInfo, q as RouterLinkPropsTyped, o as RouterLinkTyped, U as UseLinkFnTyped, _ as _RouteMapGeneric, n as _RouterTyped, p as _UseLinkReturnTyped } from './generateRouteParams-16302a62.js'; | ||
import { R as ResolvedOptions, S as ServerContext, O as Options } from './options-8dbadba3.js'; | ||
export { D as DEFAULT_OPTIONS, E as EditableTreeNode, T as TreeNode, d as TreeNodeValueParam, e as TreeNodeValueStatic, c as createPrefixTree, b as createTreeNodeValue, g as getFileBasedRouteName, a as getPascalCaseRouteName } from './options-8dbadba3.js'; | ||
export { NavigationGuard, ParamValue, ParamValueOneOrMore, ParamValueZeroOrMore, ParamValueZeroOrOne, RouteLocationAsPathTyped, RouteLocationAsPathTypedList, RouteLocationAsRelativeTyped, RouteLocationAsRelativeTypedList, RouteLocationAsString, RouteLocationNormalizedLoadedTyped, RouteLocationNormalizedLoadedTypedList, RouteLocationNormalizedTyped, RouteLocationNormalizedTypedList, RouteLocationResolvedTyped, RouteLocationResolvedTypedList, RouteLocationTyped, RouteLocationTypedList, RouteRecordInfo, RouterLinkPropsTyped, RouterLinkTyped, UseLinkFnTyped, _RouteMapGeneric, _RouterTyped, _UseLinkReturnTyped } from './types.js'; | ||
export { a as _DataLoader, D as _DefineLoaderOptions } from './defineLoader-bde635fd.js'; | ||
@@ -6,0 +6,0 @@ import 'vue-router'; |
@@ -12,2 +12,7 @@ "use strict"; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __knownSymbol = (name, symbol) => { | ||
if (symbol = Symbol[name]) | ||
return symbol; | ||
throw Error("Symbol." + name + " is not defined"); | ||
}; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
@@ -47,2 +52,39 @@ var __spreadValues = (a, b) => { | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var __await = function(promise, isYieldStar) { | ||
this[0] = promise; | ||
this[1] = isYieldStar; | ||
}; | ||
var __yieldStar = (value) => { | ||
var obj = value[__knownSymbol("asyncIterator")]; | ||
var isAwait = false; | ||
var method; | ||
var it = {}; | ||
if (obj == null) { | ||
obj = value[__knownSymbol("iterator")](); | ||
method = (k) => it[k] = (x) => obj[k](x); | ||
} else { | ||
obj = obj.call(value); | ||
method = (k) => it[k] = (v) => { | ||
if (isAwait) { | ||
isAwait = false; | ||
if (k === "throw") | ||
throw v; | ||
return v; | ||
} | ||
isAwait = true; | ||
return { | ||
done: false, | ||
value: new __await(new Promise((resolve4) => { | ||
var x = obj[k](v); | ||
if (!(x instanceof Object)) | ||
throw TypeError("Object expected"); | ||
resolve4(x); | ||
}), 1) | ||
}; | ||
}; | ||
} | ||
return it[__knownSymbol("iterator")] = () => it, method("next"), "throw" in obj ? method("throw") : it.throw = (x) => { | ||
throw x; | ||
}, "return" in obj && method("return"), it; | ||
}; | ||
@@ -211,7 +253,7 @@ // src/index.ts | ||
function asRoutePath({ src, path = "" }, filePath) { | ||
return ( | ||
return typeof path === "string" ? ( | ||
// add the path prefix if any | ||
path + // remove the absolute path to the pages folder | ||
filePath.slice(src.length + 1) | ||
); | ||
) : path(filePath); | ||
} | ||
@@ -282,2 +324,3 @@ function appendExtensionListToPattern(filePatterns, extensions) { | ||
this._overrides = /* @__PURE__ */ new Map(); | ||
// TODO: cache the overrides generation | ||
/** | ||
@@ -296,6 +339,13 @@ * Should we add the loader guard to the route record. | ||
this.subSegments = subSegments; | ||
const parentPath = parent == null ? void 0 : parent.path; | ||
this.path = // both the root record and the index record have a path of / | ||
(!parentPath || parentPath === "/") && this.pathSegment === "" ? "/" : joinPath((parent == null ? void 0 : parent.path) || "", this.pathSegment); | ||
this.parent = parent; | ||
} | ||
/** | ||
* fullPath of the node based on parent nodes | ||
*/ | ||
get path() { | ||
var _a, _b; | ||
const parentPath = (_a = this.parent) == null ? void 0 : _a.path; | ||
const pathSegment = (_b = this.overrides.path) != null ? _b : this.pathSegment; | ||
return (!parentPath || parentPath === "/") && pathSegment === "" ? "/" : joinPath(parentPath || "", pathSegment); | ||
} | ||
toString() { | ||
@@ -320,4 +370,4 @@ return this.pathSegment || "<index>"; | ||
} | ||
setOverride(path, routeBlock) { | ||
this._overrides.set(path, routeBlock || {}); | ||
setOverride(filePath, routeBlock) { | ||
this._overrides.set(filePath, routeBlock || {}); | ||
} | ||
@@ -327,3 +377,3 @@ /** | ||
* | ||
* @param key - key to remove from the override | ||
* @param key - key to remove from the override, e.g. path, name, etc | ||
*/ | ||
@@ -335,9 +385,29 @@ removeOverride(key) { | ||
} | ||
mergeOverride(path, routeBlock) { | ||
const existing = this._overrides.get(path) || {}; | ||
this._overrides.set(path, mergeRouteRecordOverride(existing, routeBlock)); | ||
/** | ||
* Add an override to the current node by merging with the existing values. | ||
* | ||
* @param filePath - The file path to add to the override | ||
* @param routeBlock - The route block to add to the override | ||
*/ | ||
mergeOverride(filePath, routeBlock) { | ||
const existing = this._overrides.get(filePath) || {}; | ||
this._overrides.set( | ||
filePath, | ||
mergeRouteRecordOverride(existing, routeBlock) | ||
); | ||
} | ||
/** | ||
* Add an override to the current node using the special file path `@@edits` that makes this added at build time. | ||
* | ||
* @param routeBlock - The route block to add to the override | ||
*/ | ||
addEditOverride(routeBlock) { | ||
return this.mergeOverride(EDITS_OVERRIDE_NAME, routeBlock); | ||
} | ||
/** | ||
* Set a specific value in the _edits_ override. | ||
* | ||
* @param key - key to set in the override, e.g. path, name, etc | ||
* @param value - value to set in the override | ||
*/ | ||
setEditOverride(key, value) { | ||
@@ -562,4 +632,11 @@ if (!this._overrides.has(EDITS_OVERRIDE_NAME)) { | ||
// src/core/tree.ts | ||
var TreeNode = class { | ||
constructor(options, filePath, parent) { | ||
var TreeNode = class _TreeNode { | ||
/** | ||
* Creates a new tree node. | ||
* | ||
* @param options - TreeNodeOptions shared by all nodes | ||
* @param pathSegment - path segment of this node e.g. `users` or `:id` | ||
* @param parent | ||
*/ | ||
constructor(options, pathSegment, parent) { | ||
/** | ||
@@ -576,3 +653,3 @@ * children of the node | ||
this.value = createTreeNodeValue( | ||
filePath, | ||
pathSegment, | ||
parent == null ? void 0 : parent.value, | ||
@@ -595,3 +672,3 @@ options.treeNodeOptions || options.pathParser | ||
if (!this.children.has(segment)) { | ||
this.children.set(segment, new TreeNode(this.options, segment, this)); | ||
this.children.set(segment, new _TreeNode(this.options, segment, this)); | ||
} | ||
@@ -608,3 +685,4 @@ const child = this.children.get(segment); | ||
/** | ||
* Adds a path to the tree. `path` cannot start with a `/`. | ||
* Adds a path that has already been parsed to the tree. `path` cannot start with a `/`. This method is similar to | ||
* `insert` but the path argument should be already parsed. e.g. `users/:id` for a file named `users/[id].vue`. | ||
* | ||
@@ -616,3 +694,3 @@ * @param path - path segment to insert, already parsed (e.g. users/:id) | ||
const isComponent = true; | ||
const node = new TreeNode( | ||
const node = new _TreeNode( | ||
__spreadProps(__spreadValues({}, this.options), { | ||
@@ -633,4 +711,11 @@ // force the format to raw | ||
} | ||
setCustomRouteBlock(path, routeBlock) { | ||
this.value.setOverride(path, routeBlock); | ||
/** | ||
* Saves a custom route block for a specific file path. The file path is used as a key. Some special file paths will | ||
* have a lower or higher priority. | ||
* | ||
* @param filePath - file path where the custom block is located | ||
* @param routeBlock - custom block to set | ||
*/ | ||
setCustomRouteBlock(filePath, routeBlock) { | ||
this.value.setOverride(filePath, routeBlock); | ||
} | ||
@@ -756,2 +841,7 @@ getSortedChildren() { | ||
} | ||
/** | ||
* Returns the tree node of the given file path. | ||
* | ||
* @param filePath - file path of the tree node to get | ||
*/ | ||
getChild(filePath) { | ||
@@ -761,4 +851,5 @@ return this.map.get(filePath); | ||
/** | ||
* Removes the tree node of the given file path. | ||
* | ||
* @param filePath - | ||
* @param filePath - file path of the tree node to remove | ||
*/ | ||
@@ -994,11 +1085,14 @@ removeChild(filePath) { | ||
var RoutesFolderWatcher = class { | ||
constructor(routesFolder, options) { | ||
this.src = routesFolder.src; | ||
this.pathPrefix = routesFolder.path || ""; | ||
this.options = options; | ||
this.watcher = import_chokidar.default.watch(this.src, { | ||
constructor(folderOptions) { | ||
this.src = folderOptions.src; | ||
this.path = folderOptions.path; | ||
this.exclude = folderOptions.exclude; | ||
this.extensions = folderOptions.extensions; | ||
this.filePatterns = folderOptions.filePatterns; | ||
this.watcher = import_chokidar.default.watch(folderOptions.pattern, { | ||
cwd: this.src, | ||
ignoreInitial: true, | ||
// disableGlobbing: true, | ||
ignorePermissionErrors: true, | ||
ignored: options.exclude | ||
ignored: this.exclude | ||
// useFsEvents: true, | ||
@@ -1010,14 +1104,9 @@ // TODO: allow user options | ||
this.watcher.on(event, (filePath) => { | ||
filePath = (0, import_pathe.normalize)(filePath); | ||
if (this.options.extensions.every( | ||
(extension) => !filePath.endsWith(extension) | ||
)) { | ||
if (this.extensions.every((extension) => !filePath.endsWith(extension))) { | ||
return; | ||
} | ||
filePath = (0, import_pathe.resolve)(this.src, filePath); | ||
handler({ | ||
filePath, | ||
routePath: asRoutePath( | ||
{ src: this.src, path: this.pathPrefix }, | ||
filePath | ||
) | ||
routePath: asRoutePath({ src: this.src, path: this.path }, filePath) | ||
}); | ||
@@ -1031,2 +1120,36 @@ }); | ||
}; | ||
function resolveFolderOptions(globalOptions, folderOptions) { | ||
const extensions = overrideOption( | ||
globalOptions.extensions, | ||
folderOptions.extensions | ||
); | ||
const filePatterns = overrideOption( | ||
globalOptions.filePatterns, | ||
folderOptions.filePatterns | ||
); | ||
return { | ||
src: folderOptions.src, | ||
pattern: appendExtensionListToPattern( | ||
filePatterns, | ||
// also override the extensions if the folder has a custom extensions | ||
extensions | ||
), | ||
path: folderOptions.path || "", | ||
extensions, | ||
filePatterns, | ||
exclude: overrideOption(globalOptions.exclude, folderOptions.exclude).map( | ||
(p) => p.startsWith("**") ? p : (0, import_pathe.resolve)(p) | ||
) | ||
}; | ||
} | ||
function overrideOption(existing, newValue) { | ||
const asArray = typeof existing === "string" ? [existing] : existing; | ||
if (typeof newValue === "function") { | ||
return newValue(asArray); | ||
} | ||
if (typeof newValue !== "undefined") { | ||
return typeof newValue === "string" ? [newValue] : newValue; | ||
} | ||
return asArray; | ||
} | ||
@@ -1346,3 +1469,3 @@ // src/codegen/generateDTS.ts | ||
// src/core/extendRoutes.ts | ||
var EditableTreeNode = class { | ||
var EditableTreeNode = class _EditableTreeNode { | ||
// private _parent?: EditableTreeNode | ||
@@ -1373,3 +1496,3 @@ constructor(node) { | ||
const node = this.node.insertParsedPath(path, filePath); | ||
const editable = new EditableTreeNode(node); | ||
const editable = new _EditableTreeNode(node); | ||
if (addBackLeadingSlash) { | ||
@@ -1384,3 +1507,3 @@ editable.path = "/" + node.path; | ||
get parent() { | ||
return this.node.parent && new EditableTreeNode(this.node.parent); | ||
return this.node.parent && new _EditableTreeNode(this.node.parent); | ||
} | ||
@@ -1487,3 +1610,3 @@ /** | ||
return [...this.node.children.values()].map( | ||
(node) => new EditableTreeNode(node) | ||
(node) => new _EditableTreeNode(node) | ||
); | ||
@@ -1505,7 +1628,7 @@ } | ||
for (const [_name, child] of this.node.children) { | ||
yield* new EditableTreeNode(child).traverseDFS(); | ||
yield* __yieldStar(new _EditableTreeNode(child).traverseDFS()); | ||
} | ||
} | ||
*[Symbol.iterator]() { | ||
yield* this.traverseBFS(); | ||
yield* __yieldStar(this.traverseBFS()); | ||
} | ||
@@ -1524,6 +1647,6 @@ /** | ||
for (const [_name, child] of this.node.children) { | ||
yield new EditableTreeNode(child); | ||
yield new _EditableTreeNode(child); | ||
} | ||
for (const [_name, child] of this.node.children) { | ||
yield* new EditableTreeNode(child).traverseBFS(); | ||
yield* __yieldStar(new _EditableTreeNode(child).traverseBFS()); | ||
} | ||
@@ -1537,3 +1660,3 @@ } | ||
const dts = preferDTS === false ? false : preferDTS === true ? (0, import_pathe2.resolve)(root, "typed-router.d.ts") : (0, import_pathe2.resolve)(root, preferDTS); | ||
const routeTree = createPrefixTree(options); | ||
const routeTree = new PrefixTree(options); | ||
const editableRoutes = new EditableTreeNode(routeTree); | ||
@@ -1556,24 +1679,21 @@ function log(...args) { | ||
} | ||
const globalPattern = appendExtensionListToPattern( | ||
options.filePatterns, | ||
options.extensions | ||
); | ||
await Promise.all( | ||
routesFolder.map((folder) => { | ||
routesFolder.map((folder) => resolveFolderOptions(options, folder)).map((folder) => { | ||
if (startWatchers) { | ||
watchers.push(setupWatcher(new RoutesFolderWatcher(folder, options))); | ||
watchers.push(setupWatcher(new RoutesFolderWatcher(folder))); | ||
} | ||
const pattern = folder.filePatterns ? appendExtensionListToPattern( | ||
folder.filePatterns, | ||
// also override the extensions if the folder has a custom extensions | ||
folder.extensions || options.extensions | ||
) : globalPattern; | ||
return (0, import_fast_glob.default)(pattern, { | ||
const ignorePattern = folder.exclude.map( | ||
(f) => ( | ||
// if it starts with ** then it will work as expected | ||
f.startsWith("**") ? f : (0, import_pathe2.relative)(folder.src, f) | ||
) | ||
); | ||
return (0, import_fast_glob.default)(folder.pattern, { | ||
cwd: folder.src, | ||
// TODO: do they return the symbolic link path or the original file? | ||
// followSymbolicLinks: false, | ||
ignore: folder.exclude || options.exclude | ||
}).then((files) => files.map((file) => (0, import_pathe2.resolve)(folder.src, file))).then( | ||
ignore: ignorePattern | ||
}).then( | ||
(files) => Promise.all( | ||
files.map( | ||
files.map((file) => (0, import_pathe2.resolve)(folder.src, file)).map( | ||
(file) => addPage({ | ||
@@ -1593,11 +1713,11 @@ routePath: asRoutePath(folder, file), | ||
} | ||
async function writeRouteInfoToNode(node, path) { | ||
const content = await import_fs3.promises.readFile(path, "utf8"); | ||
async function writeRouteInfoToNode(node, filePath) { | ||
const content = await import_fs3.promises.readFile(filePath, "utf8"); | ||
node.hasDefinePage = content.includes("definePage"); | ||
const [definedPageNameAndPath, routeBlock] = await Promise.all([ | ||
extractDefinePageNameAndPath(content, path), | ||
getRouteBlock(path, options) | ||
extractDefinePageNameAndPath(content, filePath), | ||
getRouteBlock(filePath, options) | ||
]); | ||
node.setCustomRouteBlock(path, __spreadValues(__spreadValues({}, routeBlock), definedPageNameAndPath)); | ||
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(path); | ||
node.setCustomRouteBlock(filePath, __spreadValues(__spreadValues({}, routeBlock), definedPageNameAndPath)); | ||
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(filePath); | ||
} | ||
@@ -1604,0 +1724,0 @@ async function addPage({ filePath, routePath }, triggerExtendRoute = false) { |
@@ -1,2 +0,2 @@ | ||
export { D as DEFAULT_OPTIONS, O as Options, R as ResolvedOptions, h as RoutesFolder, f as RoutesFolderOption, S as ServerContext, i as _OptionsImportMode, _ as _RoutesFolder, r as resolveOptions } from './options-56006a88.js'; | ||
export { D as DEFAULT_OPTIONS, O as Options, R as ResolvedOptions, j as RoutesFolder, f as RoutesFolderOption, h as RoutesFolderOptionResolved, S as ServerContext, k as _OptionsImportMode, _ as _OverridableOption, i as _RoutesFolder, r as resolveOptions } from './options-8dbadba3.js'; | ||
import 'vue-router'; |
import * as rollup from 'rollup'; | ||
import { O as Options } from './options-56006a88.js'; | ||
import { O as Options } from './options-8dbadba3.js'; | ||
import 'vue-router'; | ||
declare const _default: (options?: Options | undefined) => rollup.Plugin | rollup.Plugin[]; | ||
declare const _default: (options?: Options | undefined) => rollup.Plugin<any> | rollup.Plugin<any>[]; | ||
export { _default as default }; |
@@ -12,2 +12,7 @@ "use strict"; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __knownSymbol = (name, symbol) => { | ||
if (symbol = Symbol[name]) | ||
return symbol; | ||
throw Error("Symbol." + name + " is not defined"); | ||
}; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
@@ -47,2 +52,39 @@ var __spreadValues = (a, b) => { | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var __await = function(promise, isYieldStar) { | ||
this[0] = promise; | ||
this[1] = isYieldStar; | ||
}; | ||
var __yieldStar = (value) => { | ||
var obj = value[__knownSymbol("asyncIterator")]; | ||
var isAwait = false; | ||
var method; | ||
var it = {}; | ||
if (obj == null) { | ||
obj = value[__knownSymbol("iterator")](); | ||
method = (k) => it[k] = (x) => obj[k](x); | ||
} else { | ||
obj = obj.call(value); | ||
method = (k) => it[k] = (v) => { | ||
if (isAwait) { | ||
isAwait = false; | ||
if (k === "throw") | ||
throw v; | ||
return v; | ||
} | ||
isAwait = true; | ||
return { | ||
done: false, | ||
value: new __await(new Promise((resolve4) => { | ||
var x = obj[k](v); | ||
if (!(x instanceof Object)) | ||
throw TypeError("Object expected"); | ||
resolve4(x); | ||
}), 1) | ||
}; | ||
}; | ||
} | ||
return it[__knownSymbol("iterator")] = () => it, method("next"), "throw" in obj ? method("throw") : it.throw = (x) => { | ||
throw x; | ||
}, "return" in obj && method("return"), it; | ||
}; | ||
@@ -185,7 +227,7 @@ // src/rollup.ts | ||
function asRoutePath({ src, path = "" }, filePath) { | ||
return ( | ||
return typeof path === "string" ? ( | ||
// add the path prefix if any | ||
path + // remove the absolute path to the pages folder | ||
filePath.slice(src.length + 1) | ||
); | ||
) : path(filePath); | ||
} | ||
@@ -256,2 +298,3 @@ function appendExtensionListToPattern(filePatterns, extensions) { | ||
this._overrides = /* @__PURE__ */ new Map(); | ||
// TODO: cache the overrides generation | ||
/** | ||
@@ -270,6 +313,13 @@ * Should we add the loader guard to the route record. | ||
this.subSegments = subSegments; | ||
const parentPath = parent == null ? void 0 : parent.path; | ||
this.path = // both the root record and the index record have a path of / | ||
(!parentPath || parentPath === "/") && this.pathSegment === "" ? "/" : joinPath((parent == null ? void 0 : parent.path) || "", this.pathSegment); | ||
this.parent = parent; | ||
} | ||
/** | ||
* fullPath of the node based on parent nodes | ||
*/ | ||
get path() { | ||
var _a, _b; | ||
const parentPath = (_a = this.parent) == null ? void 0 : _a.path; | ||
const pathSegment = (_b = this.overrides.path) != null ? _b : this.pathSegment; | ||
return (!parentPath || parentPath === "/") && pathSegment === "" ? "/" : joinPath(parentPath || "", pathSegment); | ||
} | ||
toString() { | ||
@@ -294,4 +344,4 @@ return this.pathSegment || "<index>"; | ||
} | ||
setOverride(path, routeBlock) { | ||
this._overrides.set(path, routeBlock || {}); | ||
setOverride(filePath, routeBlock) { | ||
this._overrides.set(filePath, routeBlock || {}); | ||
} | ||
@@ -301,3 +351,3 @@ /** | ||
* | ||
* @param key - key to remove from the override | ||
* @param key - key to remove from the override, e.g. path, name, etc | ||
*/ | ||
@@ -309,9 +359,29 @@ removeOverride(key) { | ||
} | ||
mergeOverride(path, routeBlock) { | ||
const existing = this._overrides.get(path) || {}; | ||
this._overrides.set(path, mergeRouteRecordOverride(existing, routeBlock)); | ||
/** | ||
* Add an override to the current node by merging with the existing values. | ||
* | ||
* @param filePath - The file path to add to the override | ||
* @param routeBlock - The route block to add to the override | ||
*/ | ||
mergeOverride(filePath, routeBlock) { | ||
const existing = this._overrides.get(filePath) || {}; | ||
this._overrides.set( | ||
filePath, | ||
mergeRouteRecordOverride(existing, routeBlock) | ||
); | ||
} | ||
/** | ||
* Add an override to the current node using the special file path `@@edits` that makes this added at build time. | ||
* | ||
* @param routeBlock - The route block to add to the override | ||
*/ | ||
addEditOverride(routeBlock) { | ||
return this.mergeOverride(EDITS_OVERRIDE_NAME, routeBlock); | ||
} | ||
/** | ||
* Set a specific value in the _edits_ override. | ||
* | ||
* @param key - key to set in the override, e.g. path, name, etc | ||
* @param value - value to set in the override | ||
*/ | ||
setEditOverride(key, value) { | ||
@@ -536,4 +606,11 @@ if (!this._overrides.has(EDITS_OVERRIDE_NAME)) { | ||
// src/core/tree.ts | ||
var TreeNode = class { | ||
constructor(options, filePath, parent) { | ||
var TreeNode = class _TreeNode { | ||
/** | ||
* Creates a new tree node. | ||
* | ||
* @param options - TreeNodeOptions shared by all nodes | ||
* @param pathSegment - path segment of this node e.g. `users` or `:id` | ||
* @param parent | ||
*/ | ||
constructor(options, pathSegment, parent) { | ||
/** | ||
@@ -550,3 +627,3 @@ * children of the node | ||
this.value = createTreeNodeValue( | ||
filePath, | ||
pathSegment, | ||
parent == null ? void 0 : parent.value, | ||
@@ -569,3 +646,3 @@ options.treeNodeOptions || options.pathParser | ||
if (!this.children.has(segment)) { | ||
this.children.set(segment, new TreeNode(this.options, segment, this)); | ||
this.children.set(segment, new _TreeNode(this.options, segment, this)); | ||
} | ||
@@ -582,3 +659,4 @@ const child = this.children.get(segment); | ||
/** | ||
* Adds a path to the tree. `path` cannot start with a `/`. | ||
* Adds a path that has already been parsed to the tree. `path` cannot start with a `/`. This method is similar to | ||
* `insert` but the path argument should be already parsed. e.g. `users/:id` for a file named `users/[id].vue`. | ||
* | ||
@@ -590,3 +668,3 @@ * @param path - path segment to insert, already parsed (e.g. users/:id) | ||
const isComponent = true; | ||
const node = new TreeNode( | ||
const node = new _TreeNode( | ||
__spreadProps(__spreadValues({}, this.options), { | ||
@@ -607,4 +685,11 @@ // force the format to raw | ||
} | ||
setCustomRouteBlock(path, routeBlock) { | ||
this.value.setOverride(path, routeBlock); | ||
/** | ||
* Saves a custom route block for a specific file path. The file path is used as a key. Some special file paths will | ||
* have a lower or higher priority. | ||
* | ||
* @param filePath - file path where the custom block is located | ||
* @param routeBlock - custom block to set | ||
*/ | ||
setCustomRouteBlock(filePath, routeBlock) { | ||
this.value.setOverride(filePath, routeBlock); | ||
} | ||
@@ -730,2 +815,7 @@ getSortedChildren() { | ||
} | ||
/** | ||
* Returns the tree node of the given file path. | ||
* | ||
* @param filePath - file path of the tree node to get | ||
*/ | ||
getChild(filePath) { | ||
@@ -735,4 +825,5 @@ return this.map.get(filePath); | ||
/** | ||
* Removes the tree node of the given file path. | ||
* | ||
* @param filePath - | ||
* @param filePath - file path of the tree node to remove | ||
*/ | ||
@@ -746,5 +837,2 @@ removeChild(filePath) { | ||
}; | ||
function createPrefixTree(options) { | ||
return new PrefixTree(options); | ||
} | ||
function splitFilePath(filePath, options) { | ||
@@ -969,11 +1057,14 @@ const slashPos = filePath.indexOf("/"); | ||
var RoutesFolderWatcher = class { | ||
constructor(routesFolder, options) { | ||
this.src = routesFolder.src; | ||
this.pathPrefix = routesFolder.path || ""; | ||
this.options = options; | ||
this.watcher = import_chokidar.default.watch(this.src, { | ||
constructor(folderOptions) { | ||
this.src = folderOptions.src; | ||
this.path = folderOptions.path; | ||
this.exclude = folderOptions.exclude; | ||
this.extensions = folderOptions.extensions; | ||
this.filePatterns = folderOptions.filePatterns; | ||
this.watcher = import_chokidar.default.watch(folderOptions.pattern, { | ||
cwd: this.src, | ||
ignoreInitial: true, | ||
// disableGlobbing: true, | ||
ignorePermissionErrors: true, | ||
ignored: options.exclude | ||
ignored: this.exclude | ||
// useFsEvents: true, | ||
@@ -985,14 +1076,9 @@ // TODO: allow user options | ||
this.watcher.on(event, (filePath) => { | ||
filePath = (0, import_pathe.normalize)(filePath); | ||
if (this.options.extensions.every( | ||
(extension) => !filePath.endsWith(extension) | ||
)) { | ||
if (this.extensions.every((extension) => !filePath.endsWith(extension))) { | ||
return; | ||
} | ||
filePath = (0, import_pathe.resolve)(this.src, filePath); | ||
handler({ | ||
filePath, | ||
routePath: asRoutePath( | ||
{ src: this.src, path: this.pathPrefix }, | ||
filePath | ||
) | ||
routePath: asRoutePath({ src: this.src, path: this.path }, filePath) | ||
}); | ||
@@ -1006,2 +1092,36 @@ }); | ||
}; | ||
function resolveFolderOptions(globalOptions, folderOptions) { | ||
const extensions = overrideOption( | ||
globalOptions.extensions, | ||
folderOptions.extensions | ||
); | ||
const filePatterns = overrideOption( | ||
globalOptions.filePatterns, | ||
folderOptions.filePatterns | ||
); | ||
return { | ||
src: folderOptions.src, | ||
pattern: appendExtensionListToPattern( | ||
filePatterns, | ||
// also override the extensions if the folder has a custom extensions | ||
extensions | ||
), | ||
path: folderOptions.path || "", | ||
extensions, | ||
filePatterns, | ||
exclude: overrideOption(globalOptions.exclude, folderOptions.exclude).map( | ||
(p) => p.startsWith("**") ? p : (0, import_pathe.resolve)(p) | ||
) | ||
}; | ||
} | ||
function overrideOption(existing, newValue) { | ||
const asArray = typeof existing === "string" ? [existing] : existing; | ||
if (typeof newValue === "function") { | ||
return newValue(asArray); | ||
} | ||
if (typeof newValue !== "undefined") { | ||
return typeof newValue === "string" ? [newValue] : newValue; | ||
} | ||
return asArray; | ||
} | ||
@@ -1321,3 +1441,3 @@ // src/codegen/generateDTS.ts | ||
// src/core/extendRoutes.ts | ||
var EditableTreeNode = class { | ||
var EditableTreeNode = class _EditableTreeNode { | ||
// private _parent?: EditableTreeNode | ||
@@ -1348,3 +1468,3 @@ constructor(node) { | ||
const node = this.node.insertParsedPath(path, filePath); | ||
const editable = new EditableTreeNode(node); | ||
const editable = new _EditableTreeNode(node); | ||
if (addBackLeadingSlash) { | ||
@@ -1359,3 +1479,3 @@ editable.path = "/" + node.path; | ||
get parent() { | ||
return this.node.parent && new EditableTreeNode(this.node.parent); | ||
return this.node.parent && new _EditableTreeNode(this.node.parent); | ||
} | ||
@@ -1462,3 +1582,3 @@ /** | ||
return [...this.node.children.values()].map( | ||
(node) => new EditableTreeNode(node) | ||
(node) => new _EditableTreeNode(node) | ||
); | ||
@@ -1480,7 +1600,7 @@ } | ||
for (const [_name, child] of this.node.children) { | ||
yield* new EditableTreeNode(child).traverseDFS(); | ||
yield* __yieldStar(new _EditableTreeNode(child).traverseDFS()); | ||
} | ||
} | ||
*[Symbol.iterator]() { | ||
yield* this.traverseBFS(); | ||
yield* __yieldStar(this.traverseBFS()); | ||
} | ||
@@ -1499,6 +1619,6 @@ /** | ||
for (const [_name, child] of this.node.children) { | ||
yield new EditableTreeNode(child); | ||
yield new _EditableTreeNode(child); | ||
} | ||
for (const [_name, child] of this.node.children) { | ||
yield* new EditableTreeNode(child).traverseBFS(); | ||
yield* __yieldStar(new _EditableTreeNode(child).traverseBFS()); | ||
} | ||
@@ -1512,3 +1632,3 @@ } | ||
const dts = preferDTS === false ? false : preferDTS === true ? (0, import_pathe2.resolve)(root, "typed-router.d.ts") : (0, import_pathe2.resolve)(root, preferDTS); | ||
const routeTree = createPrefixTree(options); | ||
const routeTree = new PrefixTree(options); | ||
const editableRoutes = new EditableTreeNode(routeTree); | ||
@@ -1531,24 +1651,21 @@ function log(...args) { | ||
} | ||
const globalPattern = appendExtensionListToPattern( | ||
options.filePatterns, | ||
options.extensions | ||
); | ||
await Promise.all( | ||
routesFolder.map((folder) => { | ||
routesFolder.map((folder) => resolveFolderOptions(options, folder)).map((folder) => { | ||
if (startWatchers) { | ||
watchers.push(setupWatcher(new RoutesFolderWatcher(folder, options))); | ||
watchers.push(setupWatcher(new RoutesFolderWatcher(folder))); | ||
} | ||
const pattern = folder.filePatterns ? appendExtensionListToPattern( | ||
folder.filePatterns, | ||
// also override the extensions if the folder has a custom extensions | ||
folder.extensions || options.extensions | ||
) : globalPattern; | ||
return (0, import_fast_glob.default)(pattern, { | ||
const ignorePattern = folder.exclude.map( | ||
(f) => ( | ||
// if it starts with ** then it will work as expected | ||
f.startsWith("**") ? f : (0, import_pathe2.relative)(folder.src, f) | ||
) | ||
); | ||
return (0, import_fast_glob.default)(folder.pattern, { | ||
cwd: folder.src, | ||
// TODO: do they return the symbolic link path or the original file? | ||
// followSymbolicLinks: false, | ||
ignore: folder.exclude || options.exclude | ||
}).then((files) => files.map((file) => (0, import_pathe2.resolve)(folder.src, file))).then( | ||
ignore: ignorePattern | ||
}).then( | ||
(files) => Promise.all( | ||
files.map( | ||
files.map((file) => (0, import_pathe2.resolve)(folder.src, file)).map( | ||
(file) => addPage({ | ||
@@ -1568,11 +1685,11 @@ routePath: asRoutePath(folder, file), | ||
} | ||
async function writeRouteInfoToNode(node, path) { | ||
const content = await import_fs3.promises.readFile(path, "utf8"); | ||
async function writeRouteInfoToNode(node, filePath) { | ||
const content = await import_fs3.promises.readFile(filePath, "utf8"); | ||
node.hasDefinePage = content.includes("definePage"); | ||
const [definedPageNameAndPath, routeBlock] = await Promise.all([ | ||
extractDefinePageNameAndPath(content, path), | ||
getRouteBlock(path, options) | ||
extractDefinePageNameAndPath(content, filePath), | ||
getRouteBlock(filePath, options) | ||
]); | ||
node.setCustomRouteBlock(path, __spreadValues(__spreadValues({}, routeBlock), definedPageNameAndPath)); | ||
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(path); | ||
node.setCustomRouteBlock(filePath, __spreadValues(__spreadValues({}, routeBlock), definedPageNameAndPath)); | ||
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(filePath); | ||
} | ||
@@ -1847,3 +1964,1 @@ async function addPage({ filePath, routePath }, triggerExtendRoute = false) { | ||
var rollup_default = src_default.rollup; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = {}); |
import { Router, RouteLocationNormalized, RouteRecordRaw } from 'vue-router'; | ||
import { a as DataLoader } from './defineLoader-bde635fd.js'; | ||
export { D as DefineLoaderOptions, d as _defineLoader, s as _stopDataFetchingScope } from './defineLoader-bde635fd.js'; | ||
import { A as Awaitable } from './options-56006a88.js'; | ||
import { A as Awaitable } from './options-8dbadba3.js'; | ||
import 'vue'; | ||
@@ -6,0 +6,0 @@ |
@@ -1,5 +0,141 @@ | ||
export { O as Options, T as TreeNode, d as TreeNodeValueParam, e as TreeNodeValueStatic } from './options-56006a88.js'; | ||
export { N as NavigationGuard, P as ParamValue, r as ParamValueOneOrMore, s as ParamValueZeroOrMore, t as ParamValueZeroOrOne, c as RouteLocationAsPathTyped, d as RouteLocationAsPathTypedList, a as RouteLocationAsRelativeTyped, b as RouteLocationAsRelativeTypedList, e as RouteLocationAsString, l as RouteLocationNormalizedLoadedTyped, m as RouteLocationNormalizedLoadedTypedList, j as RouteLocationNormalizedTyped, k as RouteLocationNormalizedTypedList, h as RouteLocationResolvedTyped, i as RouteLocationResolvedTypedList, f as RouteLocationTyped, g as RouteLocationTypedList, R as RouteRecordInfo, q as RouterLinkPropsTyped, o as RouterLinkTyped, U as UseLinkFnTyped, _ as _RouteMapGeneric, n as _RouterTyped, p as _UseLinkReturnTyped } from './generateRouteParams-16302a62.js'; | ||
import { L as LiteralStringUnion } from './options-8dbadba3.js'; | ||
export { O as Options, T as TreeNode, d as TreeNodeValueParam, e as TreeNodeValueStatic } from './options-8dbadba3.js'; | ||
import { RouteParamsRaw, RouteParams, RouteMeta, RouteLocationNormalized, RouteRecordName, RouteLocationNormalizedLoaded, RouteQueryAndHash, RouteLocationOptions, RouteLocation, NavigationGuardNext, NavigationFailure, Router, RouterLinkProps, RouteLocationRaw } from 'vue-router'; | ||
import { Ref, AllowedComponentProps, ComponentCustomProps, VNodeProps, UnwrapRef, VNode, ComputedRef } from 'vue'; | ||
export { a as _DataLoader, D as _DefineLoaderOptions } from './defineLoader-bde635fd.js'; | ||
import 'vue-router'; | ||
import 'vue'; | ||
interface RouteRecordInfo<Name extends string = string, Path extends string = string, ParamsRaw extends RouteParamsRaw = RouteParamsRaw, Params extends RouteParams = RouteParams, Meta extends RouteMeta = RouteMeta> { | ||
name: Name; | ||
path: Path; | ||
paramsRaw: ParamsRaw; | ||
params: Params; | ||
meta: Meta; | ||
} | ||
type _RouteMapGeneric = Record<string, RouteRecordInfo>; | ||
interface RouteLocationNormalizedTyped<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>, Name extends keyof RouteMap = keyof RouteMap> extends RouteLocationNormalized { | ||
name: Extract<Name, RouteRecordName>; | ||
params: RouteMap[Name]['params']; | ||
} | ||
type RouteLocationNormalizedTypedList<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>> = { | ||
[N in keyof RouteMap]: RouteLocationNormalizedTyped<RouteMap, N>; | ||
}; | ||
interface RouteLocationNormalizedLoadedTyped<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>, Name extends keyof RouteMap = keyof RouteMap> extends RouteLocationNormalizedLoaded { | ||
name: Extract<Name, RouteRecordName>; | ||
params: RouteMap[Name]['params']; | ||
} | ||
type RouteLocationNormalizedLoadedTypedList<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>> = { | ||
[N in keyof RouteMap]: RouteLocationNormalizedLoadedTyped<RouteMap, N>; | ||
}; | ||
interface RouteLocationAsRelativeTyped<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>, Name extends keyof RouteMap = keyof RouteMap> extends RouteQueryAndHash, RouteLocationOptions { | ||
name?: Name; | ||
params?: RouteMap[Name]['paramsRaw']; | ||
} | ||
type RouteLocationAsRelativeTypedList<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>> = { | ||
[N in keyof RouteMap]: RouteLocationAsRelativeTyped<RouteMap, N>; | ||
}; | ||
interface RouteLocationAsPathTyped<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>, Name extends keyof RouteMap = keyof RouteMap> extends RouteQueryAndHash, RouteLocationOptions { | ||
path: LiteralStringUnion<RouteMap[Name]['path']>; | ||
} | ||
type RouteLocationAsPathTypedList<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>> = { | ||
[N in keyof RouteMap]: RouteLocationAsPathTyped<RouteMap, N>; | ||
}; | ||
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 { | ||
name: Extract<Name, RouteRecordName>; | ||
params: RouteMap[Name]['params']; | ||
} | ||
type RouteLocationTypedList<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>> = { | ||
[N in keyof RouteMap]: RouteLocationTyped<RouteMap, N>; | ||
}; | ||
interface RouteLocationResolvedTyped<RouteMap extends _RouteMapGeneric, Name extends keyof RouteMap> extends RouteLocationTyped<RouteMap, Name> { | ||
href: string; | ||
} | ||
type RouteLocationResolvedTypedList<RouteMap extends _RouteMapGeneric = Record<string, RouteRecordInfo>> = { | ||
[N in keyof RouteMap]: RouteLocationResolvedTyped<RouteMap, N>; | ||
}; | ||
type NavigationGuardReturn<RouteMap extends _RouteMapGeneric> = void | boolean | RouteLocationAsString<RouteMap> | RouteLocationAsRelativeTypedList<RouteMap>[keyof RouteMap] | RouteLocationAsPathTypedList<RouteMap>[keyof RouteMap]; | ||
interface NavigationGuardWithThis<T, RouteMap extends _RouteMapGeneric> { | ||
(this: T, to: RouteLocationNormalizedTypedList<RouteMap>[keyof RouteMap], from: RouteLocationNormalizedLoadedTypedList<RouteMap>[keyof RouteMap], next: NavigationGuardNext): NavigationGuardReturn<RouteMap> | Promise<NavigationGuardReturn<RouteMap>>; | ||
} | ||
interface NavigationGuard<RouteMap extends _RouteMapGeneric> { | ||
(to: RouteLocationNormalizedTypedList<RouteMap>[keyof RouteMap], from: RouteLocationNormalizedLoadedTypedList<RouteMap>[keyof RouteMap], next: NavigationGuardNext): NavigationGuardReturn<RouteMap> | Promise<NavigationGuardReturn<RouteMap>>; | ||
} | ||
interface NavigationHookAfter<RouteMap extends _RouteMapGeneric = _RouteMapGeneric> { | ||
(to: RouteLocationNormalizedTypedList<RouteMap>[keyof RouteMap], from: RouteLocationNormalizedLoadedTypedList<RouteMap>[keyof RouteMap], failure?: NavigationFailure | void): any; | ||
} | ||
interface _RouterTyped<RouteMap extends _RouteMapGeneric = _RouteMapGeneric> extends Omit<Router, 'resolve' | 'push' | 'replace' | 'beforeEach' | 'beforeResolve' | 'afterEach'> { | ||
currentRoute: Ref<RouteLocationNormalizedLoadedTypedList<RouteMap>[keyof RouteMap]>; | ||
push<Name extends keyof RouteMap = keyof RouteMap>(to: RouteLocationAsString<RouteMap> | RouteLocationAsRelativeTyped<RouteMap, Name> | RouteLocationAsPathTyped<RouteMap, Name>): ReturnType<Router['push']>; | ||
replace<Name extends keyof RouteMap = keyof RouteMap>(to: RouteLocationAsString<RouteMap> | RouteLocationAsRelativeTyped<RouteMap, Name> | RouteLocationAsPathTyped<RouteMap, Name>): ReturnType<Router['replace']>; | ||
resolve<Name extends keyof RouteMap = keyof RouteMap>(to: RouteLocationAsString<RouteMap> | RouteLocationAsRelativeTyped<RouteMap, Name> | RouteLocationAsPathTyped<RouteMap, Name>, currentLocation?: RouteLocationNormalizedLoaded): RouteLocationResolvedTypedList<RouteMap>[Name]; | ||
beforeEach(guard: NavigationGuardWithThis<undefined, RouteMap>): ReturnType<Router['beforeEach']>; | ||
beforeResolve(guard: NavigationGuardWithThis<undefined, RouteMap>): ReturnType<Router['beforeEach']>; | ||
afterEach(guard: NavigationHookAfter<RouteMap>): ReturnType<Router['beforeEach']>; | ||
} | ||
/** | ||
* Typed version of `RouterLinkProps`. | ||
*/ | ||
interface RouterLinkPropsTyped<RouteMap extends _RouteMapGeneric, Name extends keyof RouteMap = keyof RouteMap> extends Omit<RouterLinkProps, 'to'> { | ||
to: RouteLocationAsString<RouteMap> | RouteLocationAsRelativeTypedList<RouteMap>[Name] | RouteLocationAsPathTypedList<RouteMap>[Name]; | ||
} | ||
/** | ||
* Typed version of `<RouterLink>` component. | ||
*/ | ||
interface RouterLinkTyped<RouteMap extends _RouteMapGeneric> { | ||
new (): { | ||
$props: AllowedComponentProps & ComponentCustomProps & VNodeProps & RouterLinkPropsTyped<RouteMap>; | ||
$slots: { | ||
default: (arg: UnwrapRef<_UseLinkReturnTyped<RouteMap>>) => VNode[]; | ||
}; | ||
}; | ||
} | ||
/** | ||
* Return type of `useLink()`. Should be exposed by the router instead. | ||
* @internal | ||
*/ | ||
interface _UseLinkReturnTyped<RouteMap extends _RouteMapGeneric, Name extends keyof RouteMap = keyof RouteMap> { | ||
route: ComputedRef<RouteLocationResolvedTypedList<RouteMap>[Name]>; | ||
href: ComputedRef<string>; | ||
isActive: ComputedRef<boolean>; | ||
isExactActive: ComputedRef<boolean>; | ||
navigate(e?: MouseEvent): Promise<void | NavigationFailure>; | ||
} | ||
/** | ||
* Typed version of `useLink()`. | ||
*/ | ||
interface UseLinkFnTyped<RouteMap extends _RouteMapGeneric> { | ||
<Name extends keyof RouteMap = keyof RouteMap>(props: { | ||
to: RouteLocationAsString<RouteMap> | RouteLocationAsRelativeTyped<RouteMap, Name> | RouteLocationAsPathTyped<RouteMap, Name> | Ref<RouteLocationRaw>; | ||
replace?: boolean | undefined | Ref<boolean | undefined>; | ||
}): _UseLinkReturnTyped<RouteMap, Name>; | ||
} | ||
/** | ||
* Utility type for raw and non raw params like :id+ | ||
* | ||
*/ | ||
type ParamValueOneOrMore<isRaw extends boolean> = [ | ||
ParamValue<isRaw>, | ||
...ParamValue<isRaw>[] | ||
]; | ||
/** | ||
* Utility type for raw and non raw params like :id* | ||
* | ||
*/ | ||
type ParamValueZeroOrMore<isRaw extends boolean> = ParamValue<isRaw>[] | undefined | null; | ||
/** | ||
* Utility type for raw and non raw params like :id? | ||
* | ||
*/ | ||
type ParamValueZeroOrOne<isRaw extends boolean> = true extends isRaw ? string | number | null | undefined : string; | ||
/** | ||
* Utility type for raw and non raw params like :id | ||
* | ||
*/ | ||
type ParamValue<isRaw extends boolean> = true extends isRaw ? string | number : string; | ||
export { NavigationGuard, ParamValue, ParamValueOneOrMore, ParamValueZeroOrMore, ParamValueZeroOrOne, RouteLocationAsPathTyped, RouteLocationAsPathTypedList, RouteLocationAsRelativeTyped, RouteLocationAsRelativeTypedList, RouteLocationAsString, RouteLocationNormalizedLoadedTyped, RouteLocationNormalizedLoadedTypedList, RouteLocationNormalizedTyped, RouteLocationNormalizedTypedList, RouteLocationResolvedTyped, RouteLocationResolvedTypedList, RouteLocationTyped, RouteLocationTypedList, RouteRecordInfo, RouterLinkPropsTyped, RouterLinkTyped, UseLinkFnTyped, _RouteMapGeneric, _RouterTyped, _UseLinkReturnTyped }; |
import * as vite from 'vite'; | ||
import { O as Options } from './options-56006a88.js'; | ||
import { O as Options } from './options-8dbadba3.js'; | ||
import 'vue-router'; | ||
@@ -4,0 +4,0 @@ |
253
dist/vite.js
@@ -12,2 +12,7 @@ "use strict"; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __knownSymbol = (name, symbol) => { | ||
if (symbol = Symbol[name]) | ||
return symbol; | ||
throw Error("Symbol." + name + " is not defined"); | ||
}; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
@@ -47,2 +52,39 @@ var __spreadValues = (a, b) => { | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var __await = function(promise, isYieldStar) { | ||
this[0] = promise; | ||
this[1] = isYieldStar; | ||
}; | ||
var __yieldStar = (value) => { | ||
var obj = value[__knownSymbol("asyncIterator")]; | ||
var isAwait = false; | ||
var method; | ||
var it = {}; | ||
if (obj == null) { | ||
obj = value[__knownSymbol("iterator")](); | ||
method = (k) => it[k] = (x) => obj[k](x); | ||
} else { | ||
obj = obj.call(value); | ||
method = (k) => it[k] = (v) => { | ||
if (isAwait) { | ||
isAwait = false; | ||
if (k === "throw") | ||
throw v; | ||
return v; | ||
} | ||
isAwait = true; | ||
return { | ||
done: false, | ||
value: new __await(new Promise((resolve4) => { | ||
var x = obj[k](v); | ||
if (!(x instanceof Object)) | ||
throw TypeError("Object expected"); | ||
resolve4(x); | ||
}), 1) | ||
}; | ||
}; | ||
} | ||
return it[__knownSymbol("iterator")] = () => it, method("next"), "throw" in obj ? method("throw") : it.throw = (x) => { | ||
throw x; | ||
}, "return" in obj && method("return"), it; | ||
}; | ||
@@ -185,7 +227,7 @@ // src/vite.ts | ||
function asRoutePath({ src, path = "" }, filePath) { | ||
return ( | ||
return typeof path === "string" ? ( | ||
// add the path prefix if any | ||
path + // remove the absolute path to the pages folder | ||
filePath.slice(src.length + 1) | ||
); | ||
) : path(filePath); | ||
} | ||
@@ -256,2 +298,3 @@ function appendExtensionListToPattern(filePatterns, extensions) { | ||
this._overrides = /* @__PURE__ */ new Map(); | ||
// TODO: cache the overrides generation | ||
/** | ||
@@ -270,6 +313,13 @@ * Should we add the loader guard to the route record. | ||
this.subSegments = subSegments; | ||
const parentPath = parent == null ? void 0 : parent.path; | ||
this.path = // both the root record and the index record have a path of / | ||
(!parentPath || parentPath === "/") && this.pathSegment === "" ? "/" : joinPath((parent == null ? void 0 : parent.path) || "", this.pathSegment); | ||
this.parent = parent; | ||
} | ||
/** | ||
* fullPath of the node based on parent nodes | ||
*/ | ||
get path() { | ||
var _a, _b; | ||
const parentPath = (_a = this.parent) == null ? void 0 : _a.path; | ||
const pathSegment = (_b = this.overrides.path) != null ? _b : this.pathSegment; | ||
return (!parentPath || parentPath === "/") && pathSegment === "" ? "/" : joinPath(parentPath || "", pathSegment); | ||
} | ||
toString() { | ||
@@ -294,4 +344,4 @@ return this.pathSegment || "<index>"; | ||
} | ||
setOverride(path, routeBlock) { | ||
this._overrides.set(path, routeBlock || {}); | ||
setOverride(filePath, routeBlock) { | ||
this._overrides.set(filePath, routeBlock || {}); | ||
} | ||
@@ -301,3 +351,3 @@ /** | ||
* | ||
* @param key - key to remove from the override | ||
* @param key - key to remove from the override, e.g. path, name, etc | ||
*/ | ||
@@ -309,9 +359,29 @@ removeOverride(key) { | ||
} | ||
mergeOverride(path, routeBlock) { | ||
const existing = this._overrides.get(path) || {}; | ||
this._overrides.set(path, mergeRouteRecordOverride(existing, routeBlock)); | ||
/** | ||
* Add an override to the current node by merging with the existing values. | ||
* | ||
* @param filePath - The file path to add to the override | ||
* @param routeBlock - The route block to add to the override | ||
*/ | ||
mergeOverride(filePath, routeBlock) { | ||
const existing = this._overrides.get(filePath) || {}; | ||
this._overrides.set( | ||
filePath, | ||
mergeRouteRecordOverride(existing, routeBlock) | ||
); | ||
} | ||
/** | ||
* Add an override to the current node using the special file path `@@edits` that makes this added at build time. | ||
* | ||
* @param routeBlock - The route block to add to the override | ||
*/ | ||
addEditOverride(routeBlock) { | ||
return this.mergeOverride(EDITS_OVERRIDE_NAME, routeBlock); | ||
} | ||
/** | ||
* Set a specific value in the _edits_ override. | ||
* | ||
* @param key - key to set in the override, e.g. path, name, etc | ||
* @param value - value to set in the override | ||
*/ | ||
setEditOverride(key, value) { | ||
@@ -536,4 +606,11 @@ if (!this._overrides.has(EDITS_OVERRIDE_NAME)) { | ||
// src/core/tree.ts | ||
var TreeNode = class { | ||
constructor(options, filePath, parent) { | ||
var TreeNode = class _TreeNode { | ||
/** | ||
* Creates a new tree node. | ||
* | ||
* @param options - TreeNodeOptions shared by all nodes | ||
* @param pathSegment - path segment of this node e.g. `users` or `:id` | ||
* @param parent | ||
*/ | ||
constructor(options, pathSegment, parent) { | ||
/** | ||
@@ -550,3 +627,3 @@ * children of the node | ||
this.value = createTreeNodeValue( | ||
filePath, | ||
pathSegment, | ||
parent == null ? void 0 : parent.value, | ||
@@ -569,3 +646,3 @@ options.treeNodeOptions || options.pathParser | ||
if (!this.children.has(segment)) { | ||
this.children.set(segment, new TreeNode(this.options, segment, this)); | ||
this.children.set(segment, new _TreeNode(this.options, segment, this)); | ||
} | ||
@@ -582,3 +659,4 @@ const child = this.children.get(segment); | ||
/** | ||
* Adds a path to the tree. `path` cannot start with a `/`. | ||
* Adds a path that has already been parsed to the tree. `path` cannot start with a `/`. This method is similar to | ||
* `insert` but the path argument should be already parsed. e.g. `users/:id` for a file named `users/[id].vue`. | ||
* | ||
@@ -590,3 +668,3 @@ * @param path - path segment to insert, already parsed (e.g. users/:id) | ||
const isComponent = true; | ||
const node = new TreeNode( | ||
const node = new _TreeNode( | ||
__spreadProps(__spreadValues({}, this.options), { | ||
@@ -607,4 +685,11 @@ // force the format to raw | ||
} | ||
setCustomRouteBlock(path, routeBlock) { | ||
this.value.setOverride(path, routeBlock); | ||
/** | ||
* Saves a custom route block for a specific file path. The file path is used as a key. Some special file paths will | ||
* have a lower or higher priority. | ||
* | ||
* @param filePath - file path where the custom block is located | ||
* @param routeBlock - custom block to set | ||
*/ | ||
setCustomRouteBlock(filePath, routeBlock) { | ||
this.value.setOverride(filePath, routeBlock); | ||
} | ||
@@ -730,2 +815,7 @@ getSortedChildren() { | ||
} | ||
/** | ||
* Returns the tree node of the given file path. | ||
* | ||
* @param filePath - file path of the tree node to get | ||
*/ | ||
getChild(filePath) { | ||
@@ -735,4 +825,5 @@ return this.map.get(filePath); | ||
/** | ||
* Removes the tree node of the given file path. | ||
* | ||
* @param filePath - | ||
* @param filePath - file path of the tree node to remove | ||
*/ | ||
@@ -746,5 +837,2 @@ removeChild(filePath) { | ||
}; | ||
function createPrefixTree(options) { | ||
return new PrefixTree(options); | ||
} | ||
function splitFilePath(filePath, options) { | ||
@@ -969,11 +1057,14 @@ const slashPos = filePath.indexOf("/"); | ||
var RoutesFolderWatcher = class { | ||
constructor(routesFolder, options) { | ||
this.src = routesFolder.src; | ||
this.pathPrefix = routesFolder.path || ""; | ||
this.options = options; | ||
this.watcher = import_chokidar.default.watch(this.src, { | ||
constructor(folderOptions) { | ||
this.src = folderOptions.src; | ||
this.path = folderOptions.path; | ||
this.exclude = folderOptions.exclude; | ||
this.extensions = folderOptions.extensions; | ||
this.filePatterns = folderOptions.filePatterns; | ||
this.watcher = import_chokidar.default.watch(folderOptions.pattern, { | ||
cwd: this.src, | ||
ignoreInitial: true, | ||
// disableGlobbing: true, | ||
ignorePermissionErrors: true, | ||
ignored: options.exclude | ||
ignored: this.exclude | ||
// useFsEvents: true, | ||
@@ -985,14 +1076,9 @@ // TODO: allow user options | ||
this.watcher.on(event, (filePath) => { | ||
filePath = (0, import_pathe.normalize)(filePath); | ||
if (this.options.extensions.every( | ||
(extension) => !filePath.endsWith(extension) | ||
)) { | ||
if (this.extensions.every((extension) => !filePath.endsWith(extension))) { | ||
return; | ||
} | ||
filePath = (0, import_pathe.resolve)(this.src, filePath); | ||
handler({ | ||
filePath, | ||
routePath: asRoutePath( | ||
{ src: this.src, path: this.pathPrefix }, | ||
filePath | ||
) | ||
routePath: asRoutePath({ src: this.src, path: this.path }, filePath) | ||
}); | ||
@@ -1006,2 +1092,36 @@ }); | ||
}; | ||
function resolveFolderOptions(globalOptions, folderOptions) { | ||
const extensions = overrideOption( | ||
globalOptions.extensions, | ||
folderOptions.extensions | ||
); | ||
const filePatterns = overrideOption( | ||
globalOptions.filePatterns, | ||
folderOptions.filePatterns | ||
); | ||
return { | ||
src: folderOptions.src, | ||
pattern: appendExtensionListToPattern( | ||
filePatterns, | ||
// also override the extensions if the folder has a custom extensions | ||
extensions | ||
), | ||
path: folderOptions.path || "", | ||
extensions, | ||
filePatterns, | ||
exclude: overrideOption(globalOptions.exclude, folderOptions.exclude).map( | ||
(p) => p.startsWith("**") ? p : (0, import_pathe.resolve)(p) | ||
) | ||
}; | ||
} | ||
function overrideOption(existing, newValue) { | ||
const asArray = typeof existing === "string" ? [existing] : existing; | ||
if (typeof newValue === "function") { | ||
return newValue(asArray); | ||
} | ||
if (typeof newValue !== "undefined") { | ||
return typeof newValue === "string" ? [newValue] : newValue; | ||
} | ||
return asArray; | ||
} | ||
@@ -1321,3 +1441,3 @@ // src/codegen/generateDTS.ts | ||
// src/core/extendRoutes.ts | ||
var EditableTreeNode = class { | ||
var EditableTreeNode = class _EditableTreeNode { | ||
// private _parent?: EditableTreeNode | ||
@@ -1348,3 +1468,3 @@ constructor(node) { | ||
const node = this.node.insertParsedPath(path, filePath); | ||
const editable = new EditableTreeNode(node); | ||
const editable = new _EditableTreeNode(node); | ||
if (addBackLeadingSlash) { | ||
@@ -1359,3 +1479,3 @@ editable.path = "/" + node.path; | ||
get parent() { | ||
return this.node.parent && new EditableTreeNode(this.node.parent); | ||
return this.node.parent && new _EditableTreeNode(this.node.parent); | ||
} | ||
@@ -1462,3 +1582,3 @@ /** | ||
return [...this.node.children.values()].map( | ||
(node) => new EditableTreeNode(node) | ||
(node) => new _EditableTreeNode(node) | ||
); | ||
@@ -1480,7 +1600,7 @@ } | ||
for (const [_name, child] of this.node.children) { | ||
yield* new EditableTreeNode(child).traverseDFS(); | ||
yield* __yieldStar(new _EditableTreeNode(child).traverseDFS()); | ||
} | ||
} | ||
*[Symbol.iterator]() { | ||
yield* this.traverseBFS(); | ||
yield* __yieldStar(this.traverseBFS()); | ||
} | ||
@@ -1499,6 +1619,6 @@ /** | ||
for (const [_name, child] of this.node.children) { | ||
yield new EditableTreeNode(child); | ||
yield new _EditableTreeNode(child); | ||
} | ||
for (const [_name, child] of this.node.children) { | ||
yield* new EditableTreeNode(child).traverseBFS(); | ||
yield* __yieldStar(new _EditableTreeNode(child).traverseBFS()); | ||
} | ||
@@ -1512,3 +1632,3 @@ } | ||
const dts = preferDTS === false ? false : preferDTS === true ? (0, import_pathe2.resolve)(root, "typed-router.d.ts") : (0, import_pathe2.resolve)(root, preferDTS); | ||
const routeTree = createPrefixTree(options); | ||
const routeTree = new PrefixTree(options); | ||
const editableRoutes = new EditableTreeNode(routeTree); | ||
@@ -1531,24 +1651,21 @@ function log(...args) { | ||
} | ||
const globalPattern = appendExtensionListToPattern( | ||
options.filePatterns, | ||
options.extensions | ||
); | ||
await Promise.all( | ||
routesFolder.map((folder) => { | ||
routesFolder.map((folder) => resolveFolderOptions(options, folder)).map((folder) => { | ||
if (startWatchers) { | ||
watchers.push(setupWatcher(new RoutesFolderWatcher(folder, options))); | ||
watchers.push(setupWatcher(new RoutesFolderWatcher(folder))); | ||
} | ||
const pattern = folder.filePatterns ? appendExtensionListToPattern( | ||
folder.filePatterns, | ||
// also override the extensions if the folder has a custom extensions | ||
folder.extensions || options.extensions | ||
) : globalPattern; | ||
return (0, import_fast_glob.default)(pattern, { | ||
const ignorePattern = folder.exclude.map( | ||
(f) => ( | ||
// if it starts with ** then it will work as expected | ||
f.startsWith("**") ? f : (0, import_pathe2.relative)(folder.src, f) | ||
) | ||
); | ||
return (0, import_fast_glob.default)(folder.pattern, { | ||
cwd: folder.src, | ||
// TODO: do they return the symbolic link path or the original file? | ||
// followSymbolicLinks: false, | ||
ignore: folder.exclude || options.exclude | ||
}).then((files) => files.map((file) => (0, import_pathe2.resolve)(folder.src, file))).then( | ||
ignore: ignorePattern | ||
}).then( | ||
(files) => Promise.all( | ||
files.map( | ||
files.map((file) => (0, import_pathe2.resolve)(folder.src, file)).map( | ||
(file) => addPage({ | ||
@@ -1568,11 +1685,11 @@ routePath: asRoutePath(folder, file), | ||
} | ||
async function writeRouteInfoToNode(node, path) { | ||
const content = await import_fs3.promises.readFile(path, "utf8"); | ||
async function writeRouteInfoToNode(node, filePath) { | ||
const content = await import_fs3.promises.readFile(filePath, "utf8"); | ||
node.hasDefinePage = content.includes("definePage"); | ||
const [definedPageNameAndPath, routeBlock] = await Promise.all([ | ||
extractDefinePageNameAndPath(content, path), | ||
getRouteBlock(path, options) | ||
extractDefinePageNameAndPath(content, filePath), | ||
getRouteBlock(filePath, options) | ||
]); | ||
node.setCustomRouteBlock(path, __spreadValues(__spreadValues({}, routeBlock), definedPageNameAndPath)); | ||
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(path); | ||
node.setCustomRouteBlock(filePath, __spreadValues(__spreadValues({}, routeBlock), definedPageNameAndPath)); | ||
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(filePath); | ||
} | ||
@@ -1847,3 +1964,1 @@ async function addPage({ filePath, routePath }, triggerExtendRoute = false) { | ||
var vite_default = src_default.vite; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = {}); |
import * as webpack from 'webpack'; | ||
import { O as Options } from './options-56006a88.js'; | ||
import { O as Options } from './options-8dbadba3.js'; | ||
import 'vue-router'; | ||
@@ -4,0 +4,0 @@ |
@@ -12,2 +12,7 @@ "use strict"; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __knownSymbol = (name, symbol) => { | ||
if (symbol = Symbol[name]) | ||
return symbol; | ||
throw Error("Symbol." + name + " is not defined"); | ||
}; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
@@ -47,2 +52,39 @@ var __spreadValues = (a, b) => { | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var __await = function(promise, isYieldStar) { | ||
this[0] = promise; | ||
this[1] = isYieldStar; | ||
}; | ||
var __yieldStar = (value) => { | ||
var obj = value[__knownSymbol("asyncIterator")]; | ||
var isAwait = false; | ||
var method; | ||
var it = {}; | ||
if (obj == null) { | ||
obj = value[__knownSymbol("iterator")](); | ||
method = (k) => it[k] = (x) => obj[k](x); | ||
} else { | ||
obj = obj.call(value); | ||
method = (k) => it[k] = (v) => { | ||
if (isAwait) { | ||
isAwait = false; | ||
if (k === "throw") | ||
throw v; | ||
return v; | ||
} | ||
isAwait = true; | ||
return { | ||
done: false, | ||
value: new __await(new Promise((resolve4) => { | ||
var x = obj[k](v); | ||
if (!(x instanceof Object)) | ||
throw TypeError("Object expected"); | ||
resolve4(x); | ||
}), 1) | ||
}; | ||
}; | ||
} | ||
return it[__knownSymbol("iterator")] = () => it, method("next"), "throw" in obj ? method("throw") : it.throw = (x) => { | ||
throw x; | ||
}, "return" in obj && method("return"), it; | ||
}; | ||
@@ -185,7 +227,7 @@ // src/webpack.ts | ||
function asRoutePath({ src, path = "" }, filePath) { | ||
return ( | ||
return typeof path === "string" ? ( | ||
// add the path prefix if any | ||
path + // remove the absolute path to the pages folder | ||
filePath.slice(src.length + 1) | ||
); | ||
) : path(filePath); | ||
} | ||
@@ -256,2 +298,3 @@ function appendExtensionListToPattern(filePatterns, extensions) { | ||
this._overrides = /* @__PURE__ */ new Map(); | ||
// TODO: cache the overrides generation | ||
/** | ||
@@ -270,6 +313,13 @@ * Should we add the loader guard to the route record. | ||
this.subSegments = subSegments; | ||
const parentPath = parent == null ? void 0 : parent.path; | ||
this.path = // both the root record and the index record have a path of / | ||
(!parentPath || parentPath === "/") && this.pathSegment === "" ? "/" : joinPath((parent == null ? void 0 : parent.path) || "", this.pathSegment); | ||
this.parent = parent; | ||
} | ||
/** | ||
* fullPath of the node based on parent nodes | ||
*/ | ||
get path() { | ||
var _a, _b; | ||
const parentPath = (_a = this.parent) == null ? void 0 : _a.path; | ||
const pathSegment = (_b = this.overrides.path) != null ? _b : this.pathSegment; | ||
return (!parentPath || parentPath === "/") && pathSegment === "" ? "/" : joinPath(parentPath || "", pathSegment); | ||
} | ||
toString() { | ||
@@ -294,4 +344,4 @@ return this.pathSegment || "<index>"; | ||
} | ||
setOverride(path, routeBlock) { | ||
this._overrides.set(path, routeBlock || {}); | ||
setOverride(filePath, routeBlock) { | ||
this._overrides.set(filePath, routeBlock || {}); | ||
} | ||
@@ -301,3 +351,3 @@ /** | ||
* | ||
* @param key - key to remove from the override | ||
* @param key - key to remove from the override, e.g. path, name, etc | ||
*/ | ||
@@ -309,9 +359,29 @@ removeOverride(key) { | ||
} | ||
mergeOverride(path, routeBlock) { | ||
const existing = this._overrides.get(path) || {}; | ||
this._overrides.set(path, mergeRouteRecordOverride(existing, routeBlock)); | ||
/** | ||
* Add an override to the current node by merging with the existing values. | ||
* | ||
* @param filePath - The file path to add to the override | ||
* @param routeBlock - The route block to add to the override | ||
*/ | ||
mergeOverride(filePath, routeBlock) { | ||
const existing = this._overrides.get(filePath) || {}; | ||
this._overrides.set( | ||
filePath, | ||
mergeRouteRecordOverride(existing, routeBlock) | ||
); | ||
} | ||
/** | ||
* Add an override to the current node using the special file path `@@edits` that makes this added at build time. | ||
* | ||
* @param routeBlock - The route block to add to the override | ||
*/ | ||
addEditOverride(routeBlock) { | ||
return this.mergeOverride(EDITS_OVERRIDE_NAME, routeBlock); | ||
} | ||
/** | ||
* Set a specific value in the _edits_ override. | ||
* | ||
* @param key - key to set in the override, e.g. path, name, etc | ||
* @param value - value to set in the override | ||
*/ | ||
setEditOverride(key, value) { | ||
@@ -536,4 +606,11 @@ if (!this._overrides.has(EDITS_OVERRIDE_NAME)) { | ||
// src/core/tree.ts | ||
var TreeNode = class { | ||
constructor(options, filePath, parent) { | ||
var TreeNode = class _TreeNode { | ||
/** | ||
* Creates a new tree node. | ||
* | ||
* @param options - TreeNodeOptions shared by all nodes | ||
* @param pathSegment - path segment of this node e.g. `users` or `:id` | ||
* @param parent | ||
*/ | ||
constructor(options, pathSegment, parent) { | ||
/** | ||
@@ -550,3 +627,3 @@ * children of the node | ||
this.value = createTreeNodeValue( | ||
filePath, | ||
pathSegment, | ||
parent == null ? void 0 : parent.value, | ||
@@ -569,3 +646,3 @@ options.treeNodeOptions || options.pathParser | ||
if (!this.children.has(segment)) { | ||
this.children.set(segment, new TreeNode(this.options, segment, this)); | ||
this.children.set(segment, new _TreeNode(this.options, segment, this)); | ||
} | ||
@@ -582,3 +659,4 @@ const child = this.children.get(segment); | ||
/** | ||
* Adds a path to the tree. `path` cannot start with a `/`. | ||
* Adds a path that has already been parsed to the tree. `path` cannot start with a `/`. This method is similar to | ||
* `insert` but the path argument should be already parsed. e.g. `users/:id` for a file named `users/[id].vue`. | ||
* | ||
@@ -590,3 +668,3 @@ * @param path - path segment to insert, already parsed (e.g. users/:id) | ||
const isComponent = true; | ||
const node = new TreeNode( | ||
const node = new _TreeNode( | ||
__spreadProps(__spreadValues({}, this.options), { | ||
@@ -607,4 +685,11 @@ // force the format to raw | ||
} | ||
setCustomRouteBlock(path, routeBlock) { | ||
this.value.setOverride(path, routeBlock); | ||
/** | ||
* Saves a custom route block for a specific file path. The file path is used as a key. Some special file paths will | ||
* have a lower or higher priority. | ||
* | ||
* @param filePath - file path where the custom block is located | ||
* @param routeBlock - custom block to set | ||
*/ | ||
setCustomRouteBlock(filePath, routeBlock) { | ||
this.value.setOverride(filePath, routeBlock); | ||
} | ||
@@ -730,2 +815,7 @@ getSortedChildren() { | ||
} | ||
/** | ||
* Returns the tree node of the given file path. | ||
* | ||
* @param filePath - file path of the tree node to get | ||
*/ | ||
getChild(filePath) { | ||
@@ -735,4 +825,5 @@ return this.map.get(filePath); | ||
/** | ||
* Removes the tree node of the given file path. | ||
* | ||
* @param filePath - | ||
* @param filePath - file path of the tree node to remove | ||
*/ | ||
@@ -746,5 +837,2 @@ removeChild(filePath) { | ||
}; | ||
function createPrefixTree(options) { | ||
return new PrefixTree(options); | ||
} | ||
function splitFilePath(filePath, options) { | ||
@@ -969,11 +1057,14 @@ const slashPos = filePath.indexOf("/"); | ||
var RoutesFolderWatcher = class { | ||
constructor(routesFolder, options) { | ||
this.src = routesFolder.src; | ||
this.pathPrefix = routesFolder.path || ""; | ||
this.options = options; | ||
this.watcher = import_chokidar.default.watch(this.src, { | ||
constructor(folderOptions) { | ||
this.src = folderOptions.src; | ||
this.path = folderOptions.path; | ||
this.exclude = folderOptions.exclude; | ||
this.extensions = folderOptions.extensions; | ||
this.filePatterns = folderOptions.filePatterns; | ||
this.watcher = import_chokidar.default.watch(folderOptions.pattern, { | ||
cwd: this.src, | ||
ignoreInitial: true, | ||
// disableGlobbing: true, | ||
ignorePermissionErrors: true, | ||
ignored: options.exclude | ||
ignored: this.exclude | ||
// useFsEvents: true, | ||
@@ -985,14 +1076,9 @@ // TODO: allow user options | ||
this.watcher.on(event, (filePath) => { | ||
filePath = (0, import_pathe.normalize)(filePath); | ||
if (this.options.extensions.every( | ||
(extension) => !filePath.endsWith(extension) | ||
)) { | ||
if (this.extensions.every((extension) => !filePath.endsWith(extension))) { | ||
return; | ||
} | ||
filePath = (0, import_pathe.resolve)(this.src, filePath); | ||
handler({ | ||
filePath, | ||
routePath: asRoutePath( | ||
{ src: this.src, path: this.pathPrefix }, | ||
filePath | ||
) | ||
routePath: asRoutePath({ src: this.src, path: this.path }, filePath) | ||
}); | ||
@@ -1006,2 +1092,36 @@ }); | ||
}; | ||
function resolveFolderOptions(globalOptions, folderOptions) { | ||
const extensions = overrideOption( | ||
globalOptions.extensions, | ||
folderOptions.extensions | ||
); | ||
const filePatterns = overrideOption( | ||
globalOptions.filePatterns, | ||
folderOptions.filePatterns | ||
); | ||
return { | ||
src: folderOptions.src, | ||
pattern: appendExtensionListToPattern( | ||
filePatterns, | ||
// also override the extensions if the folder has a custom extensions | ||
extensions | ||
), | ||
path: folderOptions.path || "", | ||
extensions, | ||
filePatterns, | ||
exclude: overrideOption(globalOptions.exclude, folderOptions.exclude).map( | ||
(p) => p.startsWith("**") ? p : (0, import_pathe.resolve)(p) | ||
) | ||
}; | ||
} | ||
function overrideOption(existing, newValue) { | ||
const asArray = typeof existing === "string" ? [existing] : existing; | ||
if (typeof newValue === "function") { | ||
return newValue(asArray); | ||
} | ||
if (typeof newValue !== "undefined") { | ||
return typeof newValue === "string" ? [newValue] : newValue; | ||
} | ||
return asArray; | ||
} | ||
@@ -1321,3 +1441,3 @@ // src/codegen/generateDTS.ts | ||
// src/core/extendRoutes.ts | ||
var EditableTreeNode = class { | ||
var EditableTreeNode = class _EditableTreeNode { | ||
// private _parent?: EditableTreeNode | ||
@@ -1348,3 +1468,3 @@ constructor(node) { | ||
const node = this.node.insertParsedPath(path, filePath); | ||
const editable = new EditableTreeNode(node); | ||
const editable = new _EditableTreeNode(node); | ||
if (addBackLeadingSlash) { | ||
@@ -1359,3 +1479,3 @@ editable.path = "/" + node.path; | ||
get parent() { | ||
return this.node.parent && new EditableTreeNode(this.node.parent); | ||
return this.node.parent && new _EditableTreeNode(this.node.parent); | ||
} | ||
@@ -1462,3 +1582,3 @@ /** | ||
return [...this.node.children.values()].map( | ||
(node) => new EditableTreeNode(node) | ||
(node) => new _EditableTreeNode(node) | ||
); | ||
@@ -1480,7 +1600,7 @@ } | ||
for (const [_name, child] of this.node.children) { | ||
yield* new EditableTreeNode(child).traverseDFS(); | ||
yield* __yieldStar(new _EditableTreeNode(child).traverseDFS()); | ||
} | ||
} | ||
*[Symbol.iterator]() { | ||
yield* this.traverseBFS(); | ||
yield* __yieldStar(this.traverseBFS()); | ||
} | ||
@@ -1499,6 +1619,6 @@ /** | ||
for (const [_name, child] of this.node.children) { | ||
yield new EditableTreeNode(child); | ||
yield new _EditableTreeNode(child); | ||
} | ||
for (const [_name, child] of this.node.children) { | ||
yield* new EditableTreeNode(child).traverseBFS(); | ||
yield* __yieldStar(new _EditableTreeNode(child).traverseBFS()); | ||
} | ||
@@ -1512,3 +1632,3 @@ } | ||
const dts = preferDTS === false ? false : preferDTS === true ? (0, import_pathe2.resolve)(root, "typed-router.d.ts") : (0, import_pathe2.resolve)(root, preferDTS); | ||
const routeTree = createPrefixTree(options); | ||
const routeTree = new PrefixTree(options); | ||
const editableRoutes = new EditableTreeNode(routeTree); | ||
@@ -1531,24 +1651,21 @@ function log(...args) { | ||
} | ||
const globalPattern = appendExtensionListToPattern( | ||
options.filePatterns, | ||
options.extensions | ||
); | ||
await Promise.all( | ||
routesFolder.map((folder) => { | ||
routesFolder.map((folder) => resolveFolderOptions(options, folder)).map((folder) => { | ||
if (startWatchers) { | ||
watchers.push(setupWatcher(new RoutesFolderWatcher(folder, options))); | ||
watchers.push(setupWatcher(new RoutesFolderWatcher(folder))); | ||
} | ||
const pattern = folder.filePatterns ? appendExtensionListToPattern( | ||
folder.filePatterns, | ||
// also override the extensions if the folder has a custom extensions | ||
folder.extensions || options.extensions | ||
) : globalPattern; | ||
return (0, import_fast_glob.default)(pattern, { | ||
const ignorePattern = folder.exclude.map( | ||
(f) => ( | ||
// if it starts with ** then it will work as expected | ||
f.startsWith("**") ? f : (0, import_pathe2.relative)(folder.src, f) | ||
) | ||
); | ||
return (0, import_fast_glob.default)(folder.pattern, { | ||
cwd: folder.src, | ||
// TODO: do they return the symbolic link path or the original file? | ||
// followSymbolicLinks: false, | ||
ignore: folder.exclude || options.exclude | ||
}).then((files) => files.map((file) => (0, import_pathe2.resolve)(folder.src, file))).then( | ||
ignore: ignorePattern | ||
}).then( | ||
(files) => Promise.all( | ||
files.map( | ||
files.map((file) => (0, import_pathe2.resolve)(folder.src, file)).map( | ||
(file) => addPage({ | ||
@@ -1568,11 +1685,11 @@ routePath: asRoutePath(folder, file), | ||
} | ||
async function writeRouteInfoToNode(node, path) { | ||
const content = await import_fs3.promises.readFile(path, "utf8"); | ||
async function writeRouteInfoToNode(node, filePath) { | ||
const content = await import_fs3.promises.readFile(filePath, "utf8"); | ||
node.hasDefinePage = content.includes("definePage"); | ||
const [definedPageNameAndPath, routeBlock] = await Promise.all([ | ||
extractDefinePageNameAndPath(content, path), | ||
getRouteBlock(path, options) | ||
extractDefinePageNameAndPath(content, filePath), | ||
getRouteBlock(filePath, options) | ||
]); | ||
node.setCustomRouteBlock(path, __spreadValues(__spreadValues({}, routeBlock), definedPageNameAndPath)); | ||
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(path); | ||
node.setCustomRouteBlock(filePath, __spreadValues(__spreadValues({}, routeBlock), definedPageNameAndPath)); | ||
node.value.includeLoaderGuard = options.dataFetching && await hasNamedExports(filePath); | ||
} | ||
@@ -1847,3 +1964,1 @@ async function addPage({ filePath, routePath }, triggerExtendRoute = false) { | ||
var webpack_default = src_default.webpack; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = {}); |
{ | ||
"name": "unplugin-vue-router", | ||
"version": "0.6.4", | ||
"packageManager": "pnpm@8.4.0", | ||
"version": "0.7.0", | ||
"packageManager": "pnpm@8.7.6", | ||
"description": "File based typed routing for Vue Router", | ||
@@ -94,15 +94,15 @@ "keywords": [ | ||
"dependencies": { | ||
"@babel/types": "^7.21.5", | ||
"@rollup/pluginutils": "^5.0.2", | ||
"@vue-macros/common": "^1.3.1", | ||
"ast-walker-scope": "^0.4.1", | ||
"@babel/types": "^7.22.19", | ||
"@rollup/pluginutils": "^5.0.4", | ||
"@vue-macros/common": "^1.8.0", | ||
"ast-walker-scope": "^0.5.0", | ||
"chokidar": "^3.5.3", | ||
"fast-glob": "^3.2.12", | ||
"fast-glob": "^3.3.1", | ||
"json5": "^2.2.3", | ||
"local-pkg": "^0.4.3", | ||
"mlly": "^1.2.0", | ||
"pathe": "^1.1.0", | ||
"mlly": "^1.4.2", | ||
"pathe": "^1.1.1", | ||
"scule": "^1.0.0", | ||
"unplugin": "^1.3.1", | ||
"yaml": "^2.2.2" | ||
"unplugin": "^1.5.0", | ||
"yaml": "^2.3.2" | ||
}, | ||
@@ -118,10 +118,12 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@volar/vue-language-core": "^1.6.4", | ||
"c8": "^7.13.0", | ||
"chalk": "^5.2.0", | ||
"@vitest/coverage-v8": "^0.34.4", | ||
"@volar/vue-language-core": "^1.6.5", | ||
"@vue/test-utils": "^2.4.1", | ||
"chalk": "^5.3.0", | ||
"conventional-changelog-cli": "^2.2.2", | ||
"enquirer": "^2.3.6", | ||
"esno": "^0.16.3", | ||
"execa": "^7.1.1", | ||
"lint-staged": "^13.2.2", | ||
"enquirer": "^2.4.1", | ||
"esno": "^0.17.0", | ||
"execa": "^7.2.0", | ||
"happy-dom": "^12.1.2", | ||
"lint-staged": "^13.3.0", | ||
"minimist": "^1.2.8", | ||
@@ -131,15 +133,16 @@ "nodemon": "^2.0.22", | ||
"prettier": "^2.8.8", | ||
"rimraf": "^5.0.0", | ||
"rollup": "^3.21.5", | ||
"semver": "^7.5.0", | ||
"rimraf": "^5.0.1", | ||
"rollup": "^3.29.2", | ||
"semver": "^7.5.4", | ||
"ts-expect": "^1.3.0", | ||
"tsup": "^6.7.0", | ||
"typescript": "^5.0.4", | ||
"unplugin-auto-import": "^0.15.3", | ||
"vite": "^4.3.5", | ||
"vite-plugin-vue-markdown": "^0.23.4", | ||
"vitest": "^0.31.0", | ||
"vue": "^3.2.47", | ||
"vue-router": "^4.1.6", | ||
"webpack": "^5.82.0", | ||
"tsup": "^7.2.0", | ||
"typescript": "^5.2.2", | ||
"unplugin-auto-import": "^0.16.6", | ||
"vite": "^4.4.9", | ||
"vite-plugin-vue-markdown": "^0.23.8", | ||
"vitest": "^0.34.4", | ||
"vue": "^3.3.4", | ||
"vue-router": "^4.2.4", | ||
"vue-router-mock": "^1.0.0", | ||
"webpack": "^5.88.2", | ||
"yorkie": "^2.0.0" | ||
@@ -146,0 +149,0 @@ }, |
@@ -137,5 +137,3 @@ # unplugin-vue-router | ||
{ | ||
"typescript.preferences.autoImportFileExcludePatterns": [ | ||
"vue-router" | ||
] | ||
"typescript.preferences.autoImportFileExcludePatterns": ["vue-router"] | ||
} | ||
@@ -226,6 +224,9 @@ ``` | ||
// Folder(s) to scan for vue components and generate routes. Can be a string, or | ||
// an object, or an array of those. | ||
// an object, or an array of those. Each option allows to override global options. | ||
// like exclude, extensions, etc. | ||
routesFolder: 'src/pages', | ||
// allowed extensions to be considered as routes | ||
// allowed extensions for components to be considered as pages | ||
// can also be a suffix: e.g. `.page.vue` will match `home.page.vue` | ||
// but remove it from the route path | ||
extensions: ['.vue'], | ||
@@ -236,5 +237,3 @@ | ||
// e.g. ['**/__*/**/*'] will exclude all files within folders starting with `__` | ||
// e.g. ['*.component.vue'] will exclude components ending with `.component.vue` | ||
// note you can exclude patterns with a leading `!`: | ||
// '!__not-ignored', -> __not-ignored will still be used as a page | ||
// e.g. ['**/*.component.vue'] will exclude components ending with `.component.vue` | ||
exclude: [], | ||
@@ -527,2 +526,4 @@ | ||
<script setup> | ||
import { definePage } from 'vue-router/auto' | ||
definePage({ | ||
@@ -529,0 +530,0 @@ name: 'my-own-name', |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
485457
51
13304
601
29
+ Addedast-kit@0.9.5(transitive)
+ Addedast-walker-scope@0.5.0(transitive)
- Removedast-walker-scope@0.4.2(transitive)
Updated@babel/types@^7.22.19
Updated@rollup/pluginutils@^5.0.4
Updated@vue-macros/common@^1.8.0
Updatedast-walker-scope@^0.5.0
Updatedfast-glob@^3.3.1
Updatedmlly@^1.4.2
Updatedpathe@^1.1.1
Updatedunplugin@^1.5.0
Updatedyaml@^2.3.2