]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
refactor: flatten src folder
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 24 Apr 2020 16:22:15 +0000 (18:22 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 24 Apr 2020 16:22:15 +0000 (18:22 +0200)
24 files changed:
.github/contributing.md
__tests__/RouterLink.spec.ts
__tests__/RouterView.spec.ts
__tests__/encoding.spec.ts
__tests__/guards/guardToPromiseFn.spec.ts [moved from __tests__/guards/navigationGuards.spec.ts with 100% similarity]
__tests__/location.spec.ts
__tests__/mount.ts
__tests__/parseQuery.spec.ts
__tests__/stringifyQuery.spec.ts
__tests__/urlEncoding.spec.ts
src/RouterLink.ts [moved from src/components/Link.ts with 95% similarity]
src/RouterView.ts [moved from src/components/View.ts with 96% similarity]
src/encoding.ts [moved from src/utils/encoding.ts with 100% similarity]
src/history/html5.ts
src/index.ts
src/injectionSymbols.ts [moved from src/utils/injectionSymbols.ts with 82% similarity]
src/install.ts
src/location.ts [moved from src/utils/location.ts with 98% similarity]
src/navigationGuards.ts
src/query.ts [moved from src/utils/query.ts with 98% similarity]
src/router.ts
src/types/index.ts
src/useApi.ts
src/utils/index.ts

index b213e7483526e8d70f7d3533545b0907cefe8b1e..c2ed3d7d2aea1a80fbf195b83cb8ad907ff96798 100644 (file)
@@ -34,7 +34,7 @@ Hi! I'm really excited that you are interested in contributing to Vue Router. Be
 
 - Make sure tests pass!
 
-- Commit messages must follow the [commit message convention](./commit-convention.md) so that changelogs can be automatically generated. Commit messages are automatically validated before commit (by invoking [Git Hooks](https://git-scm.com/docs/githooks) via [yorkie](https://github.com/yyx990803/yorkie)).
+- Commit messages must follow the [commit message convention](./commit-convention.md) so that the changelog can be automatically generated. Commit messages are automatically validated before commit (by invoking [Git Hooks](https://git-scm.com/docs/githooks) via [yorkie](https://github.com/yyx990803/yorkie)).
 
 - No need to worry about code style as long as you have installed the dev dependencies - modified files are automatically formatted with Prettier on commit (by invoking [Git Hooks](https://git-scm.com/docs/githooks) via [yorkie](https://github.com/yyx990803/yorkie)).
 
@@ -90,11 +90,13 @@ $ yarn jest --watch
 
 Vue Router source code can be found in the `src` directory:
 
-- `src/components`: RouterLink and RouterView components.
 - `src/history`: history implementations that are instantiable with `create*History()`. This folder contains code related to using the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API).
-- `src/matcher`: RouteMatcher implementation. Contains the code that transforms paths like `/users/:id` into regexes and handle the transformation of locations like `{ name: 'UserDetail', params: { id: '2' } }` to strings. It contains path ranking logic and the part of dynamic routing that concerns matching urls in the right order.
-- `src/utils`: contains util functions that are used accross other sections of the router but are not contained by them.
+- `src/matcher`: RouteMatcher implementation. Contains the code that transforms paths like `/users/:id` into regexps and handle the transformation of locations like `{ name: 'UserDetail', params: { id: '2' } }` to strings. It contains path ranking logic and the part of dynamic routing that concerns matching urls in the right order.
+- `src/utils`: contains small utility functions that are used across other sections of the router but are not contained by them.
 - `src/router`: contains the router creation, navigation execution, using the matcher, the history implementation. It runs navigation guards.
+- `src/location`: helpers related to route location and urls
+- `src/encoding`: helpers related to url encoding
+- `src/errors`: different internal and external errors with their messages
 - `src/index`: contains all public API as exports.
 - `src/types`: contains global types that are used across multiple sections of the router.
 
index 5afdf43dd06f6660cfcc0483a854464686e7d5df..5eab0e97b5b406c0a1320b2a3c0aeededb90d974 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * @jest-environment jsdom
  */
-import { RouterLink } from '../src/components/Link'
+import { RouterLink } from '../src/RouterLink'
 import {
   START_LOCATION_NORMALIZED,
   RouteQueryAndHash,
@@ -12,7 +12,7 @@ import { createMemoryHistory } from '../src'
 import { mount, createMockedRoute } from './mount'
 import { nextTick } from 'vue'
 import { RouteRecordNormalized } from '../src/matcher/types'
-import { routerKey } from '../src/utils/injectionSymbols'
+import { routerKey } from '../src/injectionSymbols'
 
 const records = {
   home: {} as RouteRecordNormalized,
index d150a49890349e084810ba18d1e153e7c057bf8f..08a53a661e7984f4802412e644b93953c898a045 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * @jest-environment jsdom
  */
-import { RouterView } from '../src/components/View'
+import { RouterView } from '../src/RouterView'
 import { components, RouteLocationNormalizedLoose } from './utils'
 import { START_LOCATION_NORMALIZED } from '../src/types'
 import { markRaw } from 'vue'
index 19883e179de880304d77fad18d7c4fd775096380..f1e41a38b40f38d07322ec80d863cc27d7164f2b 100644 (file)
@@ -3,7 +3,7 @@ import {
   encodeParam,
   encodeQueryProperty,
   // decode,
-} from '../src/utils/encoding'
+} from '../src/encoding'
 
 describe('Encoding', () => {
   // all ascii chars with a non ascii char at the beginning
index 07222f32770451c68968c3574d200e6850984c4b..252f39bb874191a527dee543df1e2d54b6e9d420 100644 (file)
@@ -1,11 +1,11 @@
 import { normalizeHistoryLocation as normalizeLocation } from '../src/history/common'
-import { parseQuery, stringifyQuery } from '../src/utils/query'
+import { parseQuery, stringifyQuery } from '../src/query'
 import {
   parseURL as originalParseURL,
   stringifyURL as originalStringifyURL,
   stripBase,
   isSameLocationObject,
-} from '../src/utils/location'
+} from '../src/location'
 
 describe('parseURL', () => {
   let parseURL = originalParseURL.bind(null, parseQuery)
index 5d6a6c4b2cc8f3ed56e7913af486a2beeeffa1e9..ce4061d1fd3be390f5b5f2afd6d3b061bfb29898 100644 (file)
@@ -17,7 +17,7 @@ import {
 import { compile } from '@vue/compiler-dom'
 import * as runtimeDom from '@vue/runtime-dom'
 import { RouteLocationNormalizedLoose } from './utils'
-import { routeLocationKey } from '../src/utils/injectionSymbols'
+import { routeLocationKey } from '../src/injectionSymbols'
 
 export interface MountOptions {
   propsData: Record<string, any>
index 5fc772c405de39ab32580e20cda62370ca18832b..49909616ccb1ee59ec5b2b7a4a93884abe97efac 100644 (file)
@@ -1,4 +1,4 @@
-import { parseQuery } from '../src/utils/query'
+import { parseQuery } from '../src/query'
 import { mockWarn } from 'jest-mock-warn'
 
 describe('parseQuery', () => {
index 647db4dd6475ec354ce4d4f8d57e494560f62a20..038e07d49cf4bfee0dd6c7602055b200f9b00867 100644 (file)
@@ -1,4 +1,4 @@
-import { stringifyQuery } from '../src/utils/query'
+import { stringifyQuery } from '../src/query'
 import { mockWarn } from 'jest-mock-warn'
 
 describe('stringifyQuery', () => {
index 085a6989d43391aefdc4736b03eec3d3d6d0a854..abf1bccdb65f48dac41356a3473fefc147d11528 100644 (file)
@@ -2,7 +2,7 @@ import { createRouter as newRouter } from '../src/router'
 import { components } from './utils'
 import { RouteRecordRaw } from '../src/types'
 import { createMemoryHistory } from '../src'
-import * as encoding from '../src/utils/encoding'
+import * as encoding from '../src/encoding'
 
 jest.mock('../src/utils/encoding')
 
similarity index 95%
rename from src/components/Link.ts
rename to src/RouterLink.ts
index 08a98efe59e0f214413f085c40b03b47f4fff7da..b093820baeaddfe06449fe27bfc405cbecd1bef3 100644 (file)
@@ -8,10 +8,10 @@ import {
   unref,
   Component,
 } from 'vue'
-import { RouteLocationRaw, VueUseOptions, RouteLocation } from '../types'
-import { isSameLocationObject, isSameRouteRecord } from '../utils/location'
-import { routerKey, routeLocationKey } from '../utils/injectionSymbols'
-import { RouteRecord } from '../matcher/types'
+import { RouteLocationRaw, VueUseOptions, RouteLocation } from './types'
+import { isSameLocationObject, isSameRouteRecord } from './location'
+import { routerKey, routeLocationKey } from './injectionSymbols'
+import { RouteRecord } from './matcher/types'
 
 interface LinkProps {
   to: RouteLocationRaw
similarity index 96%
rename from src/components/View.ts
rename to src/RouterView.ts
index 4d29de11d36abc05a11afa72f461b04a3af21def..d622ed410cc637e3afddf4c740e2fccbdc221e37 100644 (file)
@@ -9,12 +9,12 @@ import {
   ComponentPublicInstance,
   Component,
 } from 'vue'
-import { RouteLocationNormalizedLoaded } from '../types'
+import { RouteLocationNormalizedLoaded } from './types'
 import {
   matchedRouteKey,
   viewDepthKey,
   routeLocationKey,
-} from '../utils/injectionSymbols'
+} from './injectionSymbols'
 
 export const RouterView = (defineComponent({
   name: 'RouterView',
similarity index 100%
rename from src/utils/encoding.ts
rename to src/encoding.ts
index bf523732f1cfebd7b5e25147031a8b81dc51b94b..0a8b8a1432c82e427383f3543a0991ff8d63cc9f 100644 (file)
@@ -15,7 +15,7 @@ import {
   ScrollPositionCoordinates,
 } from '../scrollBehavior'
 import { warn } from 'vue'
-import { stripBase } from '../utils/location'
+import { stripBase } from '../location'
 
 type PopStateListener = (this: Window, ev: PopStateEvent) => any
 
index 9dd78ee9f17f526f2757d49a6847b8dc9da952f3..8a3e46d1a30bd42f679da5a91400213776d8452d 100644 (file)
@@ -8,7 +8,7 @@ export {
   stringifyQuery,
   LocationQueryRaw,
   LocationQueryValue,
-} from './utils/query'
+} from './query'
 
 export { RouterHistory } from './history/common'
 
@@ -38,8 +38,8 @@ export {
 export { NavigationFailureType, NavigationFailure } from './errors'
 
 export { onBeforeRouteLeave } from './navigationGuards'
-export { RouterLink, useLink } from './components/Link'
-export { RouterView } from './components/View'
+export { RouterLink, useLink } from './RouterLink'
+export { RouterView } from './RouterView'
 
 export { createWebHistory, createMemoryHistory, createWebHashHistory }
 
similarity index 82%
rename from src/utils/injectionSymbols.ts
rename to src/injectionSymbols.ts
index 7247804ce342f604fe7b3beadd622f4bf60452be..cac3b0f7fca9cd64fb88057b81ace065aae39ee5 100644 (file)
@@ -1,7 +1,7 @@
 import { InjectionKey, ComputedRef } from 'vue'
-import { RouteLocationNormalizedLoaded } from '../types'
-import { Router } from '../router'
-import { RouteRecordNormalized } from '../matcher/types'
+import { RouteLocationNormalizedLoaded } from './types'
+import { Router } from './router'
+import { RouteRecordNormalized } from './matcher/types'
 
 export const hasSymbol =
   typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol'
index 1617cebdcfbdb467812fa23c5e6057e7bf6892ed..d95df979b1fc830863843f00c29d5eacba46547e 100644 (file)
@@ -1,7 +1,7 @@
 import { App, ComputedRef, reactive } from 'vue'
 import { Router } from './router'
-import { RouterLink } from './components/Link'
-import { RouterView } from './components/View'
+import { RouterLink } from './RouterLink'
+import { RouterView } from './RouterView'
 import { isBrowser } from './utils'
 import {
   START_LOCATION_NORMALIZED,
@@ -9,7 +9,7 @@ import {
   NavigationGuardWithThis,
   NavigationGuard,
 } from './types'
-import { routerKey, routeLocationKey } from './utils/injectionSymbols'
+import { routerKey, routeLocationKey } from './injectionSymbols'
 
 declare module '@vue/runtime-core' {
   interface ComponentCustomOptions {
similarity index 98%
rename from src/utils/location.ts
rename to src/location.ts
index 84f5f98a9d8daa921da3dbacb3a7d3ea6cb87ec4..a0b9dc7c879f39fafcdda3c92a96016bd72de059 100644 (file)
@@ -3,8 +3,8 @@ import {
   RouteLocation,
   RouteLocationNormalized,
   RouteParamValue,
-} from '../types'
-import { RouteRecord } from '../matcher/types'
+} from './types'
+import { RouteRecord } from './matcher/types'
 
 /**
  * Location object returned by {@link `parseURL`}.
index 57348eca49fcfc1b7c6ab3554ffe314f52f08296..156840a0f3c1fe42410bfaedaf2635f3556384d7 100644 (file)
@@ -18,7 +18,7 @@ import {
 } from './errors'
 import { ComponentPublicInstance } from 'vue'
 import { inject, getCurrentInstance, warn } from 'vue'
-import { matchedRouteKey } from './utils/injectionSymbols'
+import { matchedRouteKey } from './injectionSymbols'
 import { RouteRecordNormalized } from './matcher/types'
 import { isESModule } from './utils'
 
@@ -111,7 +111,10 @@ export function extractComponentsGuards(
         )
         guards.push(async () => {
           const resolved = await componentPromise
-          if (!resolved) throw new Error('TODO: error while fetching')
+          if (!resolved)
+            throw new Error(
+              `Couldn't resolve component "${name}" for the following record with path "${record.path}"`
+            )
           const resolvedComponent = isESModule(resolved)
             ? resolved.default
             : resolved
similarity index 98%
rename from src/utils/query.ts
rename to src/query.ts
index 2d8c053a3677c25641b85bb96991f82d2fc0c51d..512cd35da13e8e7999c734ba9ffa72ae575d82f7 100644 (file)
@@ -1,4 +1,4 @@
-import { decode, encodeQueryProperty } from '../utils/encoding'
+import { decode, encodeQueryProperty } from './encoding'
 
 /**
  * Possible values in normalized {@link LocationQuery}
index 8d1373401cb8e3a47047cbdd2bfb329aacf2619a..68226e194474664c6ac3344a52cb0da991f6e478 100644 (file)
@@ -33,15 +33,15 @@ import {
 } from './errors'
 import { applyToParams, isBrowser } from './utils'
 import { useCallbacks } from './utils/callbacks'
-import { encodeParam, decode } from './utils/encoding'
+import { encodeParam, decode } from './encoding'
 import {
   normalizeQuery,
   parseQuery as originalParseQuery,
   stringifyQuery as originalStringifyQuery,
-} from './utils/query'
+} from './query'
 import { ref, Ref, markRaw, nextTick, App, warn } from 'vue'
 import { RouteRecord, RouteRecordNormalized } from './matcher/types'
-import { parseURL, stringifyURL, isSameRouteLocation } from './utils/location'
+import { parseURL, stringifyURL, isSameRouteLocation } from './location'
 import { extractComponentsGuards, guardToPromiseFn } from './navigationGuards'
 import { applyRouterPlugin } from './install'
 
index a8eb7f7d5860cc7d07b9cd4668b94ad2b052ee28..3943a79166254348849ae45d005c9fd2503ab87f 100644 (file)
@@ -1,4 +1,4 @@
-import { LocationQuery, LocationQueryRaw } from '../utils/query'
+import { LocationQuery, LocationQueryRaw } from '../query'
 import { PathParserOptions } from '../matcher/pathParserRanker'
 import { markRaw, Ref, ComputedRef, ComponentOptions } from 'vue'
 import { RouteRecord, RouteRecordNormalized } from '../matcher/types'
index 8d4b90d4682edda9d6d16982a153dd5dd77d75b6..ad00e759d0bd57e610d7591369962f4802613698 100644 (file)
@@ -1,5 +1,5 @@
 import { inject } from 'vue'
-import { routerKey, routeLocationKey } from './utils/injectionSymbols'
+import { routerKey, routeLocationKey } from './injectionSymbols'
 import { Router } from './router'
 import { RouteLocationNormalizedLoaded } from './types'
 
index 139e3f567522a408f9763c03154bdd82f9db392c..9b074d02c9aabe44566f7c02015faec0ee9125b4 100644 (file)
@@ -1,5 +1,5 @@
 import { RouteParams, RouteComponent } from '../types'
-import { hasSymbol } from './injectionSymbols'
+import { hasSymbol } from '../injectionSymbols'
 
 export * from './env'