@intlify/vue-router-bridge
Advanced tools
Comparing version 0.1.0-2e90b5a to 0.1.0-63b1fb5
@@ -1,9 +0,113 @@ | ||
import type { RouteLocationNormalizedLoaded, Router } from 'vue-router' | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import type { RouteLocationNormalizedLoaded, Router, RouteRecord, RouteMeta, NavigationGuard } from 'vue-router' | ||
/** | ||
* shim vue-router@3 typings | ||
*/ | ||
declare const VueRouter: any | ||
declare type RouterMode = 'hash' | 'history' | 'abstract' | ||
declare type Dictionary<T> = { [key: string]: T } | ||
declare interface Location { | ||
name?: string | ||
path?: string | ||
hash?: string | ||
query?: Dictionary<string | (string | null)[] | null | undefined> | ||
params?: Dictionary<string> | ||
append?: boolean | ||
replace?: boolean | ||
} | ||
declare type RawLocation = string | Location | ||
declare interface Route { | ||
path: string | ||
name?: string | null | ||
hash: string | ||
query: Dictionary<string | (string | null)[]> | ||
params: Dictionary<string> | ||
fullPath: string | ||
matched: RouteRecord[] | ||
redirectedFrom?: string | ||
meta?: RouteMeta | ||
} | ||
declare type RedirectOption = RawLocation | ((to: Route) => RawLocation) | ||
declare interface PathToRegexpOptions { | ||
sensitive?: boolean | ||
strict?: boolean | ||
end?: boolean | ||
} | ||
declare type Component = any // emulate Vue Component (v2) | ||
declare type RoutePropsFunction = (route: Route) => Record<string, anu> | ||
declare interface _RouteConfigBase { | ||
path: string | ||
name?: string | ||
children?: RouteConfig[] | ||
redirect?: RedirectOption | ||
alias?: string | string[] | ||
meta?: RouteMeta | ||
beforeEnter?: NavigationGuard | ||
caseSensitive?: boolean | ||
pathToRegexpOptions?: PathToRegexpOptions | ||
} | ||
declare interface RouteConfigSingleView extends _RouteConfigBase { | ||
component?: Component | ||
props?: boolean | Rect | RoutePropsFunction | ||
} | ||
declare interface RouteConfigMultipleViews extends _RouteConfigBase { | ||
components?: Dictionary<Component> | ||
props?: Dictionary<boolean | Record<string, any> | RoutePropsFunction> | ||
} | ||
declare type RouteConfig = RouteConfigSingleView | RouteConfigMultipleViews | ||
declare interface RouteRecordPublic { | ||
path: string | ||
components: Dictionary<Component> | ||
instances: Dictionary<Vue> | ||
name?: string | ||
redirect?: RedirectOption | ||
meta: any | ||
beforeEnter?: (route: Route, redirect: (location: RawLocation) => void, next: () => void) => any | ||
props: | ||
| boolean | ||
| Record<string, any> | ||
| RoutePropsFunction | ||
| Dictionary<boolean | Record<string, any> | RoutePropsFunction> | ||
} | ||
/** | ||
* Returns the router instance. Equivalent to using `$router` inside templates. | ||
*/ | ||
declare function useRouter<T = Router>(): T | ||
/** | ||
* Returns the current route location. Equivalent to using `$route` inside templates. | ||
*/ | ||
declare function useRoute<T = RouteLocationNormalizedLoaded>(): T | ||
/** | ||
* Wheter the current vue-router version is 3 | ||
*/ | ||
declare const isVueRouter3: boolean | ||
/** | ||
* Wheter the current vue-router version is 4 | ||
*/ | ||
declare const isVueRouter4: boolean | ||
export { useRouter, useRoute, isVueRouter3, isVueRouter4 } | ||
// export vue-router@4 typings | ||
export * from 'vue-router' | ||
export { | ||
useRouter, | ||
useRoute, | ||
isVueRouter3, | ||
isVueRouter4, | ||
RouterMode, | ||
RawLocation, | ||
RedirectOption, | ||
RouteConfig, | ||
RouteRecordPublic, | ||
Location, | ||
Route | ||
} | ||
// export dummy VueRouter class | ||
export default VueRouter | ||
/* eslint-enable @typescript-eslint/no-explicit-any */ |
@@ -0,12 +1,112 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import VueRouter from 'vue-router' | ||
import type { ComputedRef } from '@vue/composition-api' | ||
import type { Route } from 'vue-router' | ||
import type { Route, RouterOptions } from 'vue-router' | ||
/** | ||
* shim vue-router@4 typings | ||
*/ | ||
declare type Router = any | ||
declare type RouterHistory = any | ||
declare type RouteRecordRaw = any | ||
declare type PathParserOptions = any | ||
declare type RouterMatcher = any | ||
/** | ||
* Creates a Router instance that can be used by a Vue app. | ||
* | ||
* @param options - {@link RouterOptions} | ||
*/ | ||
declare function createRouter(options: RouterOptions): Router | ||
/** | ||
* Creates a in-memory based history. The main purpose of this history is to handle SSR. It starts in a special location that is nowhere. | ||
* It's up to the user to replace that location with the starter location by either calling `router.push` or `router.replace`. | ||
* | ||
* @param base - Base applied to all urls, defaults to '/' | ||
* @returns a history object that can be passed to the router constructor | ||
*/ | ||
declare function createMemoryHistory(base?: string): RouterHistory | ||
/** | ||
* Creates a Router Matcher. | ||
* | ||
* @internal | ||
* @param routes - array of initial routes | ||
* @param globalOptions - global route options | ||
*/ | ||
declare function createRouterMatcher(routes: RouteRecordRaw[], globalOptions: PathParserOptions): RouterMatcher | ||
/** | ||
* Creates a hash history. Useful for web applications with no host (e.g. | ||
* `file://`) or when configuring a server to handle any URL is not possible. | ||
* | ||
* @param base - optional base to provide. Defaults to `location.pathname + | ||
* location.search` If there is a `<base>` tag in the `head`, its value will be | ||
* ignored in favor of this parameter **but note it affects all the | ||
* history.pushState() calls**, meaning that if you use a `<base>` tag, it's | ||
* `href` value **has to match this parameter** (ignoring anything after the | ||
* `#`). | ||
* | ||
* @example | ||
* ```js | ||
* // at https://example.com/folder | ||
* createWebHashHistory() // gives a url of `https://example.com/folder#` | ||
* createWebHashHistory('/folder/') // gives a url of `https://example.com/folder/#` | ||
* // if the `#` is provided in the base, it won't be added by `createWebHashHistory` | ||
* createWebHashHistory('/folder/#/app/') // gives a url of `https://example.com/folder/#/app/` | ||
* // you should avoid doing this because it changes the original url and breaks copying urls | ||
* createWebHashHistory('/other-folder/') // gives a url of `https://example.com/other-folder/#` | ||
* | ||
* // at file:///usr/etc/folder/index.html | ||
* // for locations with no `host`, the base is ignored | ||
* createWebHashHistory('/iAmIgnored') // gives a url of `file:///usr/etc/folder/index.html#` | ||
* ``` | ||
*/ | ||
declare function createWebHashHistory(base?: string): RouterHistory | ||
/** | ||
* Creates an HTML5 history. Most common history for single page applications. | ||
* | ||
* @param base - | ||
*/ | ||
declare function createWebHistory(base?: string): RouterHistory | ||
/** | ||
* Returns the router instance. Equivalent to using `$router` inside templates. | ||
*/ | ||
declare function useRouter<T = VueRouter>(): T | ||
/** | ||
* Returns the current route location. Equivalent to using `$route` inside templates. | ||
*/ | ||
declare function useRoute<T = ComputedRef<Route>>(): T | ||
/** | ||
* Wheter the current vue-router version is 3 | ||
*/ | ||
declare const isVueRouter3: boolean | ||
/** | ||
* Wheter the current vue-router version is 4 | ||
*/ | ||
declare const isVueRouter4: boolean | ||
export { useRouter, useRoute, isVueRouter3, isVueRouter4 } | ||
// export vue-router@4 typings | ||
export * from 'vue-router' | ||
export { | ||
useRouter, | ||
useRoute, | ||
isVueRouter3, | ||
isVueRouter4, | ||
createRouter, | ||
createMemoryHistory, | ||
createRouterMatcher, | ||
createWebHashHistory, | ||
createWebHistory | ||
} | ||
export default VueRouter | ||
/* eslint-enable @typescript-eslint/no-explicit-any */ |
@@ -1,9 +0,113 @@ | ||
import type { RouteLocationNormalizedLoaded, Router } from 'vue-router' | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import type { RouteLocationNormalizedLoaded, Router, RouteRecord, RouteMeta, NavigationGuard } from 'vue-router' | ||
/** | ||
* shim vue-router@3 typings | ||
*/ | ||
declare const VueRouter: any | ||
declare type RouterMode = 'hash' | 'history' | 'abstract' | ||
declare type Dictionary<T> = { [key: string]: T } | ||
declare interface Location { | ||
name?: string | ||
path?: string | ||
hash?: string | ||
query?: Dictionary<string | (string | null)[] | null | undefined> | ||
params?: Dictionary<string> | ||
append?: boolean | ||
replace?: boolean | ||
} | ||
declare type RawLocation = string | Location | ||
declare interface Route { | ||
path: string | ||
name?: string | null | ||
hash: string | ||
query: Dictionary<string | (string | null)[]> | ||
params: Dictionary<string> | ||
fullPath: string | ||
matched: RouteRecord[] | ||
redirectedFrom?: string | ||
meta?: RouteMeta | ||
} | ||
declare type RedirectOption = RawLocation | ((to: Route) => RawLocation) | ||
declare interface PathToRegexpOptions { | ||
sensitive?: boolean | ||
strict?: boolean | ||
end?: boolean | ||
} | ||
declare type Component = any // emulate Vue Component (v2) | ||
declare type RoutePropsFunction = (route: Route) => Record<string, anu> | ||
declare interface _RouteConfigBase { | ||
path: string | ||
name?: string | ||
children?: RouteConfig[] | ||
redirect?: RedirectOption | ||
alias?: string | string[] | ||
meta?: RouteMeta | ||
beforeEnter?: NavigationGuard | ||
caseSensitive?: boolean | ||
pathToRegexpOptions?: PathToRegexpOptions | ||
} | ||
declare interface RouteConfigSingleView extends _RouteConfigBase { | ||
component?: Component | ||
props?: boolean | Rect | RoutePropsFunction | ||
} | ||
declare interface RouteConfigMultipleViews extends _RouteConfigBase { | ||
components?: Dictionary<Component> | ||
props?: Dictionary<boolean | Record<string, any> | RoutePropsFunction> | ||
} | ||
declare type RouteConfig = RouteConfigSingleView | RouteConfigMultipleViews | ||
declare interface RouteRecordPublic { | ||
path: string | ||
components: Dictionary<Component> | ||
instances: Dictionary<Vue> | ||
name?: string | ||
redirect?: RedirectOption | ||
meta: any | ||
beforeEnter?: (route: Route, redirect: (location: RawLocation) => void, next: () => void) => any | ||
props: | ||
| boolean | ||
| Record<string, any> | ||
| RoutePropsFunction | ||
| Dictionary<boolean | Record<string, any> | RoutePropsFunction> | ||
} | ||
/** | ||
* Returns the router instance. Equivalent to using `$router` inside templates. | ||
*/ | ||
declare function useRouter<T = Router>(): T | ||
/** | ||
* Returns the current route location. Equivalent to using `$route` inside templates. | ||
*/ | ||
declare function useRoute<T = RouteLocationNormalizedLoaded>(): T | ||
/** | ||
* Wheter the current vue-router version is 3 | ||
*/ | ||
declare const isVueRouter3: boolean | ||
/** | ||
* Wheter the current vue-router version is 4 | ||
*/ | ||
declare const isVueRouter4: boolean | ||
export { useRouter, useRoute, isVueRouter3, isVueRouter4 } | ||
// export vue-router@4 typings | ||
export * from 'vue-router' | ||
export { | ||
useRouter, | ||
useRoute, | ||
isVueRouter3, | ||
isVueRouter4, | ||
RouterMode, | ||
RawLocation, | ||
RedirectOption, | ||
RouteConfig, | ||
RouteRecordPublic, | ||
Location, | ||
Route | ||
} | ||
// export dummy VueRouter class | ||
export default VueRouter | ||
/* eslint-enable @typescript-eslint/no-explicit-any */ |
{ | ||
"name": "@intlify/vue-router-bridge", | ||
"version": "0.1.0-2e90b5a", | ||
"version": "0.1.0-63b1fb5", | ||
"description": "Vue Router bridging for Vue 2 & Vue 3", | ||
@@ -5,0 +5,0 @@ "peerDependencies": { |
@@ -22,7 +22,9 @@ const fs = require('fs') // eslint-disable-line @typescript-eslint/no-var-requires | ||
function copy(name, version, router) { | ||
function copy(name, version, router, esm = false) { | ||
const src = path.join(dir, `v${version}`, name) | ||
const dest = path.join(dir, name) | ||
let content = fs.readFileSync(src, 'utf-8') | ||
content = content.replace(/'router'/g, `'${router}'`) | ||
content = esm | ||
? content.replace(/from 'vue-router'/g, `from '${router}'`) | ||
: content.replace(/require\('vue-router'\)/g, `require('${router}')`) | ||
try { | ||
@@ -34,2 +36,11 @@ fs.unlinkSync(dest) | ||
function checkVueRouter(pkg) { | ||
const router = loadModule(pkg) | ||
if (!router) { | ||
warn('Vue Router plugin is not found. Please run "npm install vue-router" to install.') | ||
return false | ||
} | ||
return true | ||
} | ||
function checkVCA() { | ||
@@ -46,2 +57,5 @@ const VCA = loadModule('@vue/composition-api') | ||
router = router || 'vue-router' | ||
if (!checkVueRouter(router)) { | ||
return | ||
} | ||
if (version === 3 && !checkVCA()) { | ||
@@ -51,4 +65,4 @@ return | ||
copy('index.cjs', version, router) | ||
copy('index.mjs', version, router) | ||
copy('index.d.ts', version, router) | ||
copy('index.mjs', version, router, true) | ||
copy('index.d.ts', version, router, true) | ||
} | ||
@@ -55,0 +69,0 @@ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
21674
495
1