vike 0.4.142-commit-acfc159 → 0.4.143-commit-f03b42d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/node/plugin/index.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +4 -5
- package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -6
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/generateEagerImport.js +19 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +103 -95
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +37 -27
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +50 -80
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +12 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.js +25 -25
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +19 -16
- package/dist/cjs/node/plugin/shared/{getConfigValueSource.js → getConfigValueSourcesRelevant.js} +1 -12
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +1 -1
- package/dist/cjs/node/plugin/utils.js +1 -2
- package/dist/cjs/node/prerender/runPrerender.js +13 -16
- package/dist/cjs/node/runtime/html/stream.js +4 -1
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/cjs/node/runtime/renderPage/loadPageFilesServerSide.js +2 -2
- package/dist/cjs/node/shared/virtual-files/virtualFilePageConfigValuesAll.js +1 -1
- package/dist/cjs/shared/error-page.js +1 -1
- package/dist/cjs/shared/getPageFiles/assertPageConfigs.js +13 -13
- package/dist/cjs/shared/getPageFiles/getExports.js +3 -3
- package/dist/cjs/shared/getPageFiles/parseGlobResults.js +9 -43
- package/dist/cjs/shared/getPageFiles/parsePageConfigsSerialized.js +62 -0
- package/dist/cjs/shared/page-configs/assertExports.js +60 -0
- package/dist/cjs/shared/page-configs/loadConfigValues.js +18 -0
- package/dist/cjs/shared/page-configs/parseConfigValuesImported.js +50 -0
- package/dist/cjs/shared/page-configs/utils.js +1 -1
- package/dist/cjs/shared/route/loadPageRoutes.js +11 -13
- package/dist/cjs/shared/route/resolvePrecedence.js +32 -11
- package/dist/cjs/shared/route/resolveRedirects.js +1 -1
- package/dist/cjs/shared/route/resolveRouteFunction.js +1 -0
- package/dist/cjs/shared/route/resolveRouteString.js +99 -43
- package/dist/cjs/shared/utils.js +1 -1
- package/dist/cjs/types/defineConfig.js +7 -0
- package/dist/cjs/types/index.js +3 -0
- package/dist/cjs/utils/objectAssign.js +3 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/{resolve.js → requireResolve.js} +3 -3
- package/dist/esm/__internal/index.d.ts +3 -3
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageContext.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageId.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/prefetch.js +3 -1
- package/dist/esm/client/client-routing-runtime/useClientRouter.js +2 -2
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +1 -1
- package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +2 -2
- package/dist/esm/client/shared/loadPageFilesClientSide.d.ts +2 -2
- package/dist/esm/client/shared/loadPageFilesClientSide.js +2 -2
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
- package/dist/esm/node/plugin/index.js +3 -2
- package/dist/esm/node/plugin/plugins/buildConfig.js +4 -5
- package/dist/esm/node/plugin/plugins/commonConfig.js +1 -6
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.d.ts +13 -2
- package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.js +19 -8
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +8 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +104 -96
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +35 -25
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +49 -79
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +10 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.d.ts +18 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.js +25 -25
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +19 -16
- package/dist/esm/node/plugin/shared/{getConfigValueSource.d.ts → getConfigValueSourcesRelevant.d.ts} +0 -2
- package/dist/esm/node/plugin/shared/{getConfigValueSource.js → getConfigValueSourcesRelevant.js} +0 -11
- package/dist/esm/node/plugin/shared/loggerNotProd.js +2 -2
- package/dist/esm/node/plugin/utils.d.ts +1 -2
- package/dist/esm/node/plugin/utils.js +1 -2
- package/dist/esm/node/prerender/runPrerender.js +13 -16
- package/dist/esm/node/runtime/html/injectAssets.d.ts +2 -2
- package/dist/esm/node/runtime/html/serializePageContextClientSide.d.ts +2 -2
- package/dist/esm/node/runtime/html/stream.js +4 -1
- package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/debugPageFiles.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.js +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +13 -13
- package/dist/esm/node/shared/getClientEntryFilePath.d.ts +2 -2
- package/dist/esm/node/shared/virtual-files/virtualFilePageConfigValuesAll.js +1 -1
- package/dist/esm/shared/addIs404ToPageProps.d.ts +2 -2
- package/dist/esm/shared/error-page.d.ts +3 -3
- package/dist/esm/shared/error-page.js +1 -1
- package/dist/esm/shared/getPageFiles/analyzeClientSide.d.ts +2 -2
- package/dist/esm/shared/getPageFiles/assertPageConfigs.d.ts +5 -5
- package/dist/esm/shared/getPageFiles/assertPageConfigs.js +12 -12
- package/dist/esm/shared/getPageFiles/getExports.d.ts +2 -2
- package/dist/esm/shared/getPageFiles/getExports.js +1 -1
- package/dist/esm/shared/getPageFiles/parseGlobResults.d.ts +3 -3
- package/dist/esm/shared/getPageFiles/parseGlobResults.js +9 -43
- package/dist/esm/shared/getPageFiles/parsePageConfigsSerialized.d.ts +6 -0
- package/dist/esm/shared/getPageFiles/parsePageConfigsSerialized.js +59 -0
- package/dist/esm/shared/getPageFiles/setPageFiles.d.ts +3 -3
- package/dist/esm/shared/page-configs/Config.d.ts +200 -11
- package/dist/esm/shared/page-configs/PageConfig.d.ts +59 -39
- package/dist/esm/shared/page-configs/assertExports.d.ts +6 -0
- package/dist/esm/shared/page-configs/assertExports.js +54 -0
- package/dist/esm/shared/page-configs/findPageConfig.d.ts +2 -2
- package/dist/esm/shared/page-configs/loadConfigValues.d.ts +3 -0
- package/dist/esm/shared/page-configs/loadConfigValues.js +15 -0
- package/dist/esm/shared/page-configs/parseConfigValuesImported.d.ts +3 -0
- package/dist/esm/shared/page-configs/parseConfigValuesImported.js +44 -0
- package/dist/esm/shared/page-configs/utils.d.ts +3 -2
- package/dist/esm/shared/page-configs/utils.js +1 -1
- package/dist/esm/shared/route/executeGuardHook.d.ts +2 -2
- package/dist/esm/shared/route/index.d.ts +3 -3
- package/dist/esm/shared/route/loadPageRoutes.d.ts +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +11 -13
- package/dist/esm/shared/route/resolvePrecedence.js +33 -12
- package/dist/esm/shared/route/resolveRedirects.js +1 -1
- package/dist/esm/shared/route/resolveRouteFunction.js +1 -0
- package/dist/esm/shared/route/resolveRouteString.d.ts +21 -4
- package/dist/esm/shared/route/resolveRouteString.js +98 -42
- package/dist/esm/shared/types.d.ts +7 -6
- package/dist/esm/shared/utils.d.ts +1 -1
- package/dist/esm/shared/utils.js +1 -1
- package/dist/esm/types/defineConfig.d.ts +3 -0
- package/dist/esm/types/defineConfig.js +4 -0
- package/dist/esm/types/index.d.ts +2 -1
- package/dist/esm/types/index.js +1 -1
- package/dist/esm/utils/objectAssign.js +3 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/requireResolve.d.ts +2 -0
- package/dist/esm/utils/{resolve.js → requireResolve.js} +2 -2
- package/package.json +3 -3
- package/dist/cjs/shared/page-configs/loadPageCode.js +0 -63
- package/dist/cjs/utils/assertDefaultExport.js +0 -53
- package/dist/esm/shared/page-configs/loadPageCode.d.ts +0 -3
- package/dist/esm/shared/page-configs/loadPageCode.js +0 -57
- package/dist/esm/utils/assertDefaultExport.d.ts +0 -8
- package/dist/esm/utils/assertDefaultExport.js +0 -47
- package/dist/esm/utils/resolve.d.ts +0 -2
- /package/dist/cjs/shared/getPageFiles/{assertExports.js → assert_exports_old_design.js} +0 -0
- /package/dist/esm/shared/getPageFiles/{assertExports.d.ts → assert_exports_old_design.d.ts} +0 -0
- /package/dist/esm/shared/getPageFiles/{assertExports.js → assert_exports_old_design.js} +0 -0
|
@@ -137,19 +137,17 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
137
137
|
function getGlobalHooks(pageFilesAll, pageConfigs, pageConfigGlobal) {
|
|
138
138
|
// V1 Design
|
|
139
139
|
if (pageConfigs.length > 0) {
|
|
140
|
-
if (pageConfigGlobal.onBeforeRoute) {
|
|
141
|
-
const hookFn = pageConfigGlobal.onBeforeRoute
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return { onBeforeRouteHook, filesystemRoots: null };
|
|
152
|
-
}
|
|
140
|
+
if (pageConfigGlobal.configValues.onBeforeRoute?.value) {
|
|
141
|
+
const { value: hookFn, definedAtInfo } = pageConfigGlobal.configValues.onBeforeRoute;
|
|
142
|
+
// config.onBeforeRoute isn't a computed nor a cumulative config => definedAtInfo should always be defined
|
|
143
|
+
assert(definedAtInfo);
|
|
144
|
+
const hookFilePath = definedAtInfo.filePath;
|
|
145
|
+
assertUsage(isCallable(hookFn), `The hook onBeforeRoute() defined by ${hookFilePath} should be a function.`);
|
|
146
|
+
const onBeforeRouteHook = {
|
|
147
|
+
hookFilePath: hookFilePath,
|
|
148
|
+
onBeforeRoute: hookFn
|
|
149
|
+
};
|
|
150
|
+
return { onBeforeRouteHook, filesystemRoots: null };
|
|
153
151
|
}
|
|
154
152
|
return { onBeforeRouteHook: null, filesystemRoots: null };
|
|
155
153
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { resolvePrecendence };
|
|
2
2
|
// export type { RouteMatch }
|
|
3
3
|
import { analyzeRouteString } from './resolveRouteString.js';
|
|
4
|
-
import { higherFirst } from './utils.js';
|
|
4
|
+
import { higherFirst, lowerFirst } from './utils.js';
|
|
5
5
|
import { makeFirst } from './utils.js';
|
|
6
6
|
import { isStaticRouteString } from './resolveRouteString.js';
|
|
7
7
|
// See https://vike.dev/route-function#precedence
|
|
@@ -32,37 +32,58 @@ function sortMatches(routeMatch1, routeMatch2) {
|
|
|
32
32
|
if (!routeMatch1.routeString) {
|
|
33
33
|
return 0;
|
|
34
34
|
}
|
|
35
|
+
/* DEBUG
|
|
36
|
+
console.log('routeMatch1.routeString', routeMatch1.routeString)
|
|
37
|
+
console.log('routeMatch2.routeString', routeMatch2.routeString)
|
|
38
|
+
console.log('parseRouteString(routeMatch1.routeString)', parseRouteString(routeMatch1.routeString))
|
|
39
|
+
console.log('parseRouteString(routeMatch2.routeString)', parseRouteString(routeMatch2.routeString))
|
|
40
|
+
//*/
|
|
35
41
|
// Return route with highest number of static path segments at beginning first
|
|
36
42
|
{
|
|
37
|
-
const getValue = (routeString) => analyzeRouteString(routeString).
|
|
43
|
+
const getValue = (routeString) => analyzeRouteString(routeString).numberOfStaticPartsBeginning;
|
|
38
44
|
const result = higherFirst(getValue)(routeMatch1.routeString, routeMatch2.routeString);
|
|
39
45
|
if (result !== 0) {
|
|
46
|
+
/* DEBUG
|
|
47
|
+
console.log('analyzeRouteString(routeMatch1.routeString).numberOfStaticPartsBeginning', getValue(routeMatch1.routeString))
|
|
48
|
+
console.log('analyzeRouteString(routeMatch2.routeString).numberOfStaticPartsBeginning', getValue(routeMatch2.routeString))
|
|
49
|
+
//*/
|
|
40
50
|
return result;
|
|
41
51
|
}
|
|
42
52
|
}
|
|
43
53
|
// Return route with highest number of static path segments in total first
|
|
44
54
|
{
|
|
45
|
-
const getValue = (routeString) => analyzeRouteString(routeString).
|
|
55
|
+
const getValue = (routeString) => analyzeRouteString(routeString).numberOfStaticParts;
|
|
46
56
|
const result = higherFirst(getValue)(routeMatch1.routeString, routeMatch2.routeString);
|
|
47
57
|
if (result !== 0) {
|
|
58
|
+
/* DEBUG
|
|
59
|
+
console.log('analyzeRouteString(routeMatch1.routeString).numberOfStaticParts', getValue(routeMatch1.routeString))
|
|
60
|
+
console.log('analyzeRouteString(routeMatch2.routeString).numberOfStaticParts', getValue(routeMatch2.routeString))
|
|
61
|
+
//*/
|
|
48
62
|
return result;
|
|
49
63
|
}
|
|
50
64
|
}
|
|
51
|
-
// Return route with
|
|
65
|
+
// Return route with least amount of globs first
|
|
52
66
|
{
|
|
53
|
-
const getValue = (routeString) => analyzeRouteString(routeString).
|
|
54
|
-
const result =
|
|
67
|
+
const getValue = (routeString) => analyzeRouteString(routeString).numberOfGlobs;
|
|
68
|
+
const result = lowerFirst(getValue)(routeMatch1.routeString, routeMatch2.routeString);
|
|
55
69
|
if (result !== 0) {
|
|
70
|
+
/* DEBUG
|
|
71
|
+
console.log('analyzeRouteString(routeMatch1.routeString).numberOfGlobs', getValue(routeMatch1.routeString))
|
|
72
|
+
console.log('analyzeRouteString(routeMatch2.routeString).numberOfGlobs', getValue(routeMatch2.routeString))
|
|
73
|
+
//*/
|
|
56
74
|
return result;
|
|
57
75
|
}
|
|
58
76
|
}
|
|
59
|
-
// Return
|
|
77
|
+
// Return route with highest number of parameters first
|
|
60
78
|
{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
79
|
+
const getValue = (routeString) => analyzeRouteString(routeString).numberOfParams;
|
|
80
|
+
const result = higherFirst(getValue)(routeMatch1.routeString, routeMatch2.routeString);
|
|
81
|
+
if (result !== 0) {
|
|
82
|
+
/* DEBUG
|
|
83
|
+
console.log('analyzeRouteString(routeMatch1.routeString).numberOfParams', getValue(routeMatch1.routeString))
|
|
84
|
+
console.log('analyzeRouteString(routeMatch2.routeString).numberOfParams', getValue(routeMatch2.routeString))
|
|
85
|
+
//*/
|
|
86
|
+
return result;
|
|
66
87
|
}
|
|
67
88
|
}
|
|
68
89
|
return 0;
|
|
@@ -7,7 +7,7 @@ import { assertRouteString, resolveRouteString } from './resolveRouteString.js';
|
|
|
7
7
|
import pc from '@brillout/picocolors';
|
|
8
8
|
assertIsNotBrowser(); // Don't bloat the client
|
|
9
9
|
// TODO/v1-release: update
|
|
10
|
-
const configSrc = '[vite.config.js >
|
|
10
|
+
const configSrc = '[vite.config.js > vike({ redirects })]';
|
|
11
11
|
function resolveRedirects(redirects, urlPathname) {
|
|
12
12
|
for (const [urlSource, urlTarget] of Object.entries(redirects)) {
|
|
13
13
|
const urlResolved = resolveRouteStringRedirect(urlSource, urlTarget, urlPathname);
|
|
@@ -20,6 +20,7 @@ async function resolveRouteFunction(routeFunction, pageContext, routeDefinedAt)
|
|
|
20
20
|
result = {};
|
|
21
21
|
}
|
|
22
22
|
assertUsage(isPlainObject(result), `The Route Function ${routeDefinedAt} should return a boolean or a plain JavaScript object (but it's ${pc.cyan(`typeof result === ${JSON.stringify(typeof result)}`)} instead)`);
|
|
23
|
+
// AFAICT this return interface is superfluous. Should we soft-deprecate it and remove it?
|
|
23
24
|
if ('match' in result) {
|
|
24
25
|
const { match } = result;
|
|
25
26
|
assertUsage(typeof match === 'boolean', `The ${pc.cyan('match')} value returned by the Route Function ${routeDefinedAt} should be a boolean.`);
|
|
@@ -3,15 +3,32 @@ export { getUrlFromRouteString };
|
|
|
3
3
|
export { isStaticRouteString };
|
|
4
4
|
export { analyzeRouteString };
|
|
5
5
|
export { assertRouteString };
|
|
6
|
+
export { parseRouteString };
|
|
6
7
|
declare function assertRouteString(routeString: string, errPrefix?: `${string}Invalid` | `${string}invalid`): void;
|
|
7
8
|
declare function resolveRouteString(routeString: string, urlPathname: string): null | {
|
|
8
9
|
routeParams: Record<string, string>;
|
|
9
10
|
};
|
|
11
|
+
type Segment = {
|
|
12
|
+
glob: true;
|
|
13
|
+
/** Make route /a/* match URL /a */
|
|
14
|
+
isLastDir?: true;
|
|
15
|
+
static?: undefined;
|
|
16
|
+
param?: undefined;
|
|
17
|
+
} | {
|
|
18
|
+
glob?: undefined;
|
|
19
|
+
static: string;
|
|
20
|
+
param?: undefined;
|
|
21
|
+
} | {
|
|
22
|
+
glob?: undefined;
|
|
23
|
+
static?: undefined;
|
|
24
|
+
param: string;
|
|
25
|
+
};
|
|
26
|
+
declare function parseRouteString(routeString: string): Segment[];
|
|
10
27
|
declare function getUrlFromRouteString(routeString: string): null | string;
|
|
11
28
|
declare function analyzeRouteString(routeString: string): {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
29
|
+
numberOfStaticPartsBeginning: number;
|
|
30
|
+
numberOfStaticParts: number;
|
|
31
|
+
numberOfParams: number;
|
|
32
|
+
numberOfGlobs: number;
|
|
16
33
|
};
|
|
17
34
|
declare function isStaticRouteString(routeString: string): boolean;
|
|
@@ -3,48 +3,109 @@ export { getUrlFromRouteString };
|
|
|
3
3
|
export { isStaticRouteString };
|
|
4
4
|
export { analyzeRouteString };
|
|
5
5
|
export { assertRouteString };
|
|
6
|
-
|
|
6
|
+
export { parseRouteString };
|
|
7
|
+
import { assertWarning, isBrowser, escapeRegex } from '../utils.js';
|
|
7
8
|
import { assert, assertUsage } from './utils.js';
|
|
8
9
|
import pc from '@brillout/picocolors';
|
|
9
10
|
const PARAM_TOKEN_NEW = '@';
|
|
10
11
|
// TODO/v1-release: remove
|
|
11
12
|
const PARAM_TOKEN_OLD = ':';
|
|
12
13
|
function assertRouteString(routeString, errPrefix = 'Invalid') {
|
|
13
|
-
|
|
14
|
-
assertUsage(routeString !== '', `${
|
|
15
|
-
assertUsage(
|
|
14
|
+
let errPrefix2 = `${errPrefix} Route String ${highlight(routeString)}`;
|
|
15
|
+
assertUsage(routeString !== '', `${errPrefix2} (empty string): set it to ${highlight('/')} instead`);
|
|
16
|
+
assertUsage(['/', '*'].includes(routeString[0]), `${errPrefix2}: it should start with ${highlight('/')} or ${highlight('*')}`);
|
|
17
|
+
assertUsage(!routeString.includes('**'), `${errPrefix2}: set it to ${highlight(routeString.split('**').join('*'))} instead`);
|
|
16
18
|
}
|
|
17
19
|
function resolveRouteString(routeString, urlPathname) {
|
|
18
20
|
assertRouteString(routeString);
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (routeString === '*') {
|
|
25
|
-
routeString = '/*';
|
|
26
|
-
}
|
|
27
|
-
for (let i = 0; i < Math.max(routeSegments.length, urlSegments.length); i++) {
|
|
28
|
-
const routeSegment = routeSegments[i];
|
|
29
|
-
const urlSegment = urlSegments[i];
|
|
30
|
-
if (routeSegment === '*') {
|
|
31
|
-
routeParams['*'] = urlSegments.slice(Math.max(1, i)).join('/');
|
|
32
|
-
return { routeParams };
|
|
21
|
+
const segments = parseRouteString(routeString);
|
|
22
|
+
const routeRegexStrInner = segments
|
|
23
|
+
.map((segment) => {
|
|
24
|
+
if (segment.param) {
|
|
25
|
+
return '[^/]+';
|
|
33
26
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
if (segment.glob) {
|
|
28
|
+
if (segment.isLastDir) {
|
|
29
|
+
return '|/.*';
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return '.*';
|
|
38
33
|
}
|
|
39
|
-
|
|
34
|
+
}
|
|
35
|
+
// segment.static
|
|
36
|
+
return escapeRegex(segment.static);
|
|
37
|
+
})
|
|
38
|
+
.map((s) => `(${s})`)
|
|
39
|
+
.join('');
|
|
40
|
+
const routeRegex = new RegExp(`^${routeRegexStrInner}/?$`);
|
|
41
|
+
const routeRegexMatch = urlPathname.match(routeRegex);
|
|
42
|
+
/* DEBUG
|
|
43
|
+
console.log()
|
|
44
|
+
console.log('routeString', routeString)
|
|
45
|
+
console.log('urlPathname', urlPathname)
|
|
46
|
+
console.log('routeSegments', segments)
|
|
47
|
+
console.log('routeRegex', routeRegex)
|
|
48
|
+
console.log('routeRegexMatch', routeRegexMatch)
|
|
49
|
+
//*/
|
|
50
|
+
if (!routeRegexMatch)
|
|
51
|
+
return null;
|
|
52
|
+
const routeParams = {};
|
|
53
|
+
const [_, ...segmentsValue] = routeRegexMatch;
|
|
54
|
+
let globIdx = 0;
|
|
55
|
+
const hasMultipleGlobs = segments.filter((segment) => segment.glob).length > 1;
|
|
56
|
+
segments.forEach((segment, i) => {
|
|
57
|
+
let val = segmentsValue[i];
|
|
58
|
+
if (segment.param) {
|
|
59
|
+
routeParams[segment.param] = val;
|
|
60
|
+
}
|
|
61
|
+
if (segment.glob) {
|
|
62
|
+
const param = `*${hasMultipleGlobs ? ++globIdx : ''}`;
|
|
63
|
+
if (segment.isLastDir)
|
|
64
|
+
val = val.slice(1);
|
|
65
|
+
routeParams[param] = val;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return { routeParams };
|
|
69
|
+
}
|
|
70
|
+
function parseRouteString(routeString) {
|
|
71
|
+
const segments = [];
|
|
72
|
+
const pushStatic = (s) => {
|
|
73
|
+
const segmentLast = segments[segments.length - 1];
|
|
74
|
+
if (segmentLast?.static) {
|
|
75
|
+
segmentLast.static += s;
|
|
40
76
|
}
|
|
41
77
|
else {
|
|
42
|
-
|
|
43
|
-
|
|
78
|
+
segments.push({ static: s });
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const parts = routeString.split('/');
|
|
82
|
+
parts.forEach((s, i) => {
|
|
83
|
+
const isFirst = i === 0;
|
|
84
|
+
const isLast = i === parts.length - 1;
|
|
85
|
+
if (isParam(s)) {
|
|
86
|
+
assertWarning(!s.startsWith(PARAM_TOKEN_OLD), `Outdated Route String ${highlight(routeString)}, use ${highlight(routeString.split(PARAM_TOKEN_OLD).join(PARAM_TOKEN_NEW))} instead`, { onlyOnce: true });
|
|
87
|
+
if (!isFirst)
|
|
88
|
+
pushStatic('/');
|
|
89
|
+
segments.push({ param: s.slice(1) });
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
if (s === '*' && isLast && routeString !== '*' && routeString !== '/*') {
|
|
93
|
+
segments.push({ glob: true, isLastDir: true });
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
if (!isFirst)
|
|
97
|
+
pushStatic('/');
|
|
98
|
+
s.split('*').forEach((s, i) => {
|
|
99
|
+
if (i !== 0)
|
|
100
|
+
segments.push({ glob: true });
|
|
101
|
+
if (s !== '') {
|
|
102
|
+
pushStatic(s);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
44
105
|
}
|
|
45
106
|
}
|
|
46
|
-
}
|
|
47
|
-
return
|
|
107
|
+
});
|
|
108
|
+
return segments;
|
|
48
109
|
}
|
|
49
110
|
function getUrlFromRouteString(routeString) {
|
|
50
111
|
assert(routeString.startsWith('/'));
|
|
@@ -54,24 +115,19 @@ function getUrlFromRouteString(routeString) {
|
|
|
54
115
|
}
|
|
55
116
|
return null;
|
|
56
117
|
}
|
|
57
|
-
function assertGlob(routeString) {
|
|
58
|
-
const numberOfGlobChars = routeString.split('*').length - 1;
|
|
59
|
-
assertUsage(numberOfGlobChars <= 1, `Invalid Route String ${highlight(routeString)}: Route Strings aren't allowed to contain more than one glob ${highlight('*')} (use a Route Function instead)`);
|
|
60
|
-
assertUsage(numberOfGlobChars === 0 || (numberOfGlobChars === 1 && routeString.endsWith('*')), `Invalid Route String ${highlight(routeString)}: make sure it ends with ${highlight('*')} or use a Route Function`);
|
|
61
|
-
}
|
|
62
118
|
function analyzeRouteString(routeString) {
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
119
|
+
const segments = parseRouteString(routeString);
|
|
120
|
+
const countStaticParts = (s) => s?.split('/').filter(Boolean).length || 0;
|
|
121
|
+
let numberOfStaticPartsBeginning = 0;
|
|
122
|
+
for (const segment of segments) {
|
|
123
|
+
if (!segment.static)
|
|
67
124
|
break;
|
|
68
|
-
|
|
69
|
-
numberOfStaticSegmentsBeginning++;
|
|
125
|
+
numberOfStaticPartsBeginning += countStaticParts(segment.static);
|
|
70
126
|
}
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
return {
|
|
127
|
+
const numberOfStaticParts = segments.map((s) => countStaticParts(s.static)).reduce((sum, a) => sum + a, 0);
|
|
128
|
+
const numberOfParams = segments.filter((s) => s.param).length;
|
|
129
|
+
const numberOfGlobs = segments.filter((s) => s.glob).length;
|
|
130
|
+
return { numberOfStaticPartsBeginning, numberOfStaticParts, numberOfParams, numberOfGlobs };
|
|
75
131
|
}
|
|
76
132
|
function isParam(routeSegment) {
|
|
77
133
|
return routeSegment.startsWith(PARAM_TOKEN_NEW) || routeSegment.startsWith(PARAM_TOKEN_OLD);
|
|
@@ -12,12 +12,10 @@ import type { ConfigEntries, ExportsAll } from './getPageFiles/getExports.js';
|
|
|
12
12
|
import type { Config } from './page-configs/Config.js';
|
|
13
13
|
import type { PageContextConfig } from './page-configs/Config/PageContextConfig.js';
|
|
14
14
|
import type { AbortStatusCode } from './route/abort.js';
|
|
15
|
-
type PageContext = PageContextWithClientRouting;
|
|
16
|
-
type PageContextClient = PageContextClientWithClientRouting;
|
|
17
|
-
type PageContextWithClientRouting = PageContextClientWithClientRouting | PageContextServer;
|
|
18
|
-
type PageContextWithServerRouting = PageContextClientWithServerRouting | PageContextServer;
|
|
19
15
|
type PageContextServer = PageContextBuiltInServer & Vike.PageContext;
|
|
20
|
-
type
|
|
16
|
+
type PageContext = PageContextClient | PageContextServer;
|
|
17
|
+
type PageContextClient = PageContextBuiltInClientWithClientRouting & Vike.PageContext;
|
|
18
|
+
type PageContextWithServerRouting = PageContextClientWithServerRouting | PageContextServer;
|
|
21
19
|
type PageContextClientWithServerRouting = PageContextBuiltInClientWithServerRouting & Vike.PageContext;
|
|
22
20
|
/** Built-in `pageContext` properties set by vike.
|
|
23
21
|
*
|
|
@@ -57,7 +55,10 @@ type PageContextBuiltInCommon<Page = [never]> = {
|
|
|
57
55
|
* https://vike.dev/exports
|
|
58
56
|
*/
|
|
59
57
|
exportsAll: ExportsAll;
|
|
60
|
-
/** The URL
|
|
58
|
+
/** The URL you provided to Vike when calling `renderPage({ urlOriginal })` in your server middleware.
|
|
59
|
+
*
|
|
60
|
+
* https://vike.dev/renderPage
|
|
61
|
+
*/
|
|
61
62
|
urlOriginal: string;
|
|
62
63
|
/** If an error occurs, whether the error is a `404 Page Not Found`.
|
|
63
64
|
*
|
|
@@ -18,6 +18,6 @@ export * from '../utils/projectInfo.js';
|
|
|
18
18
|
export * from '../utils/hasPropertyGetter.js';
|
|
19
19
|
export * from '../utils/isPromise.js';
|
|
20
20
|
export * from '../utils/checkType.js';
|
|
21
|
-
export * from '../utils/assertDefaultExport.js';
|
|
22
21
|
export * from '../utils/objectEntries.js';
|
|
23
22
|
export * from '../utils/getValuePrintable.js';
|
|
23
|
+
export * from '../utils/escapeRegex.js';
|
package/dist/esm/shared/utils.js
CHANGED
|
@@ -22,6 +22,6 @@ export * from '../utils/projectInfo.js';
|
|
|
22
22
|
export * from '../utils/hasPropertyGetter.js';
|
|
23
23
|
export * from '../utils/isPromise.js';
|
|
24
24
|
export * from '../utils/checkType.js';
|
|
25
|
-
export * from '../utils/assertDefaultExport.js';
|
|
26
25
|
export * from '../utils/objectEntries.js';
|
|
27
26
|
export * from '../utils/getValuePrintable.js';
|
|
27
|
+
export * from '../utils/escapeRegex.js';
|
|
@@ -6,11 +6,12 @@ export type { PageContextClientWithServerRouting } from '../shared/types.js';
|
|
|
6
6
|
export type { PageContextBuiltInServer } from '../shared/types.js';
|
|
7
7
|
export type { PageContextBuiltInClientWithClientRouting } from '../shared/types.js';
|
|
8
8
|
export type { PageContextBuiltInClientWithServerRouting } from '../shared/types.js';
|
|
9
|
-
export type { Config, ConfigMeta as Meta } from '../shared/page-configs/Config.js';
|
|
9
|
+
export type { Config, ConfigMeta as Meta, GuardAsync, GuardSync, OnBeforePrerenderStartAsync, OnBeforePrerenderStartSync, OnBeforeRenderAsync, OnBeforeRenderSync, OnBeforeRouteAsync, OnBeforeRouteSync, OnHydrationEndAsync, OnHydrationEndSync, OnPageTransitionEndAsync, OnPageTransitionEndSync, OnPageTransitionStartAsync, OnPageTransitionStartSync, OnPrerenderStartAsync, OnPrerenderStartSync, OnRenderClientAsync, OnRenderClientSync, OnRenderHtmlAsync, OnRenderHtmlSync, RouteAsync, RouteSync } from '../shared/page-configs/Config.js';
|
|
10
10
|
export type { ConfigEnv } from '../shared/page-configs/PageConfig.js';
|
|
11
11
|
export type { ConfigDefinition, ConfigEffect } from '../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js';
|
|
12
12
|
export type { ConfigEntries } from '../shared/getPageFiles/getExports.js';
|
|
13
13
|
export type { InjectFilterEntry } from '../node/runtime/html/injectAssets/getHtmlTags.js';
|
|
14
|
+
export { defineConfig } from './defineConfig.js';
|
|
14
15
|
import type { ConfigEnv } from '../shared/page-configs/PageConfig.js';
|
|
15
16
|
/** @deprecated Replace:
|
|
16
17
|
* `import type { Env } from 'vike/types'`
|
package/dist/esm/types/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export { defineConfig } from './defineConfig.js';
|
|
@@ -3,5 +3,7 @@ export { objectAssign };
|
|
|
3
3
|
// - With type inference
|
|
4
4
|
// - Preserves property descriptors, which we need for preserving the getters added by addUrlComputedProps()
|
|
5
5
|
function objectAssign(obj, objAddendum) {
|
|
6
|
-
|
|
6
|
+
if (objAddendum) {
|
|
7
|
+
Object.defineProperties(obj, Object.getOwnPropertyDescriptors(objAddendum));
|
|
8
|
+
}
|
|
7
9
|
}
|
|
@@ -5,7 +5,7 @@ type ProjectVersion = typeof projectInfo.projectVersion;
|
|
|
5
5
|
type ProjectTag = `[${PackageName}]` | `[${PackageName}@${ProjectVersion}]`;
|
|
6
6
|
declare const projectInfo: {
|
|
7
7
|
projectName: "Vike";
|
|
8
|
-
projectVersion: "0.4.
|
|
8
|
+
projectVersion: "0.4.143-commit-f03b42d";
|
|
9
9
|
npmPackageName: "vike";
|
|
10
10
|
githubRepository: "https://github.com/vikejs/vike";
|
|
11
11
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
import { onProjectInfo } from './assertSingleInstance.js';
|
|
3
|
-
const PROJECT_VERSION = '0.4.
|
|
3
|
+
const PROJECT_VERSION = '0.4.143-commit-f03b42d';
|
|
4
4
|
const projectInfo = {
|
|
5
5
|
projectName: 'Vike',
|
|
6
6
|
projectVersion: PROJECT_VERSION,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { requireResolve };
|
|
2
2
|
import { assert } from './assert.js';
|
|
3
3
|
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
4
4
|
import { assertIsNotProductionRuntime } from './assertIsNotProductionRuntime.js';
|
|
@@ -10,7 +10,7 @@ const importMetaUrl = import.meta.url;
|
|
|
10
10
|
const require_ = createRequire(importMetaUrl);
|
|
11
11
|
assertIsNotBrowser();
|
|
12
12
|
assertIsNotProductionRuntime();
|
|
13
|
-
function
|
|
13
|
+
function requireResolve(importPath, cwd) {
|
|
14
14
|
assertPosixPath(cwd);
|
|
15
15
|
const clean = addFileExtensionsToRequireResolve();
|
|
16
16
|
importPath = removeFileExtention(importPath);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.143-commit-f03b42d",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "tsc --watch",
|
|
6
6
|
"build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@brillout/json-serializer": "^0.5.6",
|
|
17
17
|
"@brillout/picocolors": "^1.0.9",
|
|
18
18
|
"@brillout/require-shim": "^0.1.2",
|
|
19
|
-
"@brillout/vite-plugin-import-build": "^0.2.
|
|
19
|
+
"@brillout/vite-plugin-import-build": "^0.2.20",
|
|
20
20
|
"acorn": "^8.8.2",
|
|
21
21
|
"cac": "^6.7.14",
|
|
22
22
|
"es-module-lexer": "^1.3.0",
|
|
@@ -163,7 +163,7 @@
|
|
|
163
163
|
},
|
|
164
164
|
"devDependencies": {
|
|
165
165
|
"@brillout/part-regex": "^0.1.2",
|
|
166
|
-
"@brillout/release-me": "^0.1.
|
|
166
|
+
"@brillout/release-me": "^0.1.8",
|
|
167
167
|
"@types/estree": "^1.0.0",
|
|
168
168
|
"@types/jest": "^27.4.1",
|
|
169
169
|
"@types/node": "^20.1.0",
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.loadPageCode = void 0;
|
|
7
|
-
const utils_js_1 = require("../utils.js");
|
|
8
|
-
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
9
|
-
async function loadPageCode(pageConfig, isDev) {
|
|
10
|
-
if (pageConfig.isLoaded &&
|
|
11
|
-
// We don't need to cache in dev, since Vite already caches the virtual module
|
|
12
|
-
!isDev) {
|
|
13
|
-
return pageConfig;
|
|
14
|
-
}
|
|
15
|
-
const codeFiles = await pageConfig.loadConfigValuesAll();
|
|
16
|
-
// TODO: remove?
|
|
17
|
-
// pageConfig.configValuesOld = pageConfig.configValuesOld.filter((val) => !val.definedByCodeFile)
|
|
18
|
-
const addConfigValue = (configName, value, filePath, exportName) => {
|
|
19
|
-
/* TODO
|
|
20
|
-
assert(!isAlreadyDefined(val.configName), val.configName) // Conflicts are resolved upstream
|
|
21
|
-
*/
|
|
22
|
-
pageConfig.configValues[configName] = {
|
|
23
|
-
value,
|
|
24
|
-
definedAtInfo: {
|
|
25
|
-
filePath,
|
|
26
|
-
fileExportPath: [exportName]
|
|
27
|
-
}
|
|
28
|
-
/* TODO: remove?
|
|
29
|
-
definedByCodeFile: true
|
|
30
|
-
*/
|
|
31
|
-
};
|
|
32
|
-
assertIsNotNull(value, configName, filePath);
|
|
33
|
-
};
|
|
34
|
-
codeFiles.forEach((codeFile) => {
|
|
35
|
-
if (codeFile.isPlusFile) {
|
|
36
|
-
const { importFileExports, importFilePath } = codeFile;
|
|
37
|
-
if (codeFile.configName !== 'client') {
|
|
38
|
-
(0, utils_js_1.assertDefaultExportUnknown)(importFileExports, importFilePath);
|
|
39
|
-
}
|
|
40
|
-
Object.entries(importFileExports).forEach(([exportName, exportValue]) => {
|
|
41
|
-
const isSideExport = exportName !== 'default'; // .md files may have "side-exports" such as `export { frontmatter }`
|
|
42
|
-
const configName = isSideExport ? exportName : codeFile.configName;
|
|
43
|
-
if (isSideExport && configName in pageConfig.configValues) {
|
|
44
|
-
// We can't avoid side-export conflicts upstream. (Because we cannot know about side-exports upstream at build-time.)
|
|
45
|
-
// Side-exports have the lowest priority.
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
addConfigValue(configName, exportValue, importFilePath, exportName);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
const { configName, importFilePath, importFileExportValue, importFileExportName } = codeFile;
|
|
53
|
-
addConfigValue(configName, importFileExportValue, importFilePath, importFileExportName);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
(0, utils_js_1.objectAssign)(pageConfig, { isLoaded: true });
|
|
57
|
-
return pageConfig;
|
|
58
|
-
}
|
|
59
|
-
exports.loadPageCode = loadPageCode;
|
|
60
|
-
function assertIsNotNull(configValue, configName, importFilePath) {
|
|
61
|
-
(0, utils_js_1.assert)(!importFilePath.includes('+config.'));
|
|
62
|
-
(0, utils_js_1.assertUsage)(configValue !== null, `Set ${picocolors_1.default.cyan(configName)} to ${picocolors_1.default.cyan('null')} in a +config.h.js file instead of ${importFilePath}`);
|
|
63
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.assertDefaultExportObject = exports.assertDefaultExportUnknown = void 0;
|
|
7
|
-
const assert_js_1 = require("./assert.js");
|
|
8
|
-
const isObject_js_1 = require("./isObject.js");
|
|
9
|
-
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
10
|
-
const IGNORE = [
|
|
11
|
-
// vite-plugin-solid adds `export { $$registrations }`
|
|
12
|
-
'$$registrations',
|
|
13
|
-
// @vitejs/plugin-vue adds `export { _rerender_only }`
|
|
14
|
-
'_rerender_only'
|
|
15
|
-
];
|
|
16
|
-
// support `export { frontmatter }` in .mdx files
|
|
17
|
-
const FILES_WITH_SIDE_EXPORTS = ['.md', '.mdx'];
|
|
18
|
-
function assertDefaultExportUnknown(fileExports, filePath) {
|
|
19
|
-
assertSingleDefaultExport(fileExports, filePath, true);
|
|
20
|
-
}
|
|
21
|
-
exports.assertDefaultExportUnknown = assertDefaultExportUnknown;
|
|
22
|
-
function assertDefaultExportObject(fileExports, filePath) {
|
|
23
|
-
assertSingleDefaultExport(fileExports, filePath, false);
|
|
24
|
-
const exportDefault = fileExports.default;
|
|
25
|
-
(0, assert_js_1.assertUsage)((0, isObject_js_1.isObject)(exportDefault), `The ${picocolors_1.default.cyan('export default')} of ${filePath} should be an object (but it's ${picocolors_1.default.cyan(`typeof exportDefault === ${JSON.stringify(typeof exportDefault)}`)} instead)`);
|
|
26
|
-
}
|
|
27
|
-
exports.assertDefaultExportObject = assertDefaultExportObject;
|
|
28
|
-
function assertSingleDefaultExport(fileExports, filePath, defaultExportValueIsUnknown) {
|
|
29
|
-
const exportsAll = Object.keys(fileExports);
|
|
30
|
-
const exportsRelevant = exportsAll.filter((exportName) => !IGNORE.includes(exportName));
|
|
31
|
-
const exportsInvalid = exportsRelevant.filter((e) => e !== 'default');
|
|
32
|
-
const exportsHasDefault = exportsRelevant.includes('default');
|
|
33
|
-
if (exportsInvalid.length === 0) {
|
|
34
|
-
if (exportsHasDefault) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
(0, assert_js_1.assert)(exportsRelevant.length === 0);
|
|
39
|
-
(0, assert_js_1.assertUsage)(false, `${filePath} doesn't export any value, but it should have a ${picocolors_1.default.cyan('export default')} instead`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
else if (!FILES_WITH_SIDE_EXPORTS.some((ext) => filePath.endsWith(ext))) {
|
|
43
|
-
if (defaultExportValueIsUnknown) {
|
|
44
|
-
exportsInvalid.forEach((exportInvalid) => {
|
|
45
|
-
(0, assert_js_1.assertWarning)(exportsInvalid.length === 0, `${filePath} should only have a default export: move ${picocolors_1.default.cyan(`export { ${exportInvalid} }`)} to +config.h.js or its own +${exportsInvalid}.js`, { onlyOnce: true });
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
const exportsInvalidStr = exportsInvalid.join(', ');
|
|
50
|
-
(0, assert_js_1.assertWarning)(exportsInvalid.length === 0, `${filePath} replace ${picocolors_1.default.cyan(`export { ${exportsInvalidStr} }`)} with ${picocolors_1.default.cyan(`export default { ${exportsInvalidStr} }`)}`, { onlyOnce: true });
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|