vike 0.4.160 → 0.4.161-commit-ba539a4
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/cli/bin.js +5 -0
- package/dist/cjs/node/client/router.js +4 -2
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +148 -0
- package/dist/cjs/node/plugin/plugins/buildConfig.js +61 -35
- package/dist/cjs/node/plugin/plugins/commonConfig.js +5 -13
- package/dist/cjs/node/plugin/plugins/config/stemUtils.js +1 -1
- package/dist/cjs/node/plugin/plugins/distFileNames.js +9 -1
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +7 -2
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +4 -7
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +28 -46
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.js → loadFileAtConfigTime.js} +5 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +33 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.js → transformFileImports.js} +7 -7
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +21 -27
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +155 -111
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -1
- package/dist/cjs/node/plugin/utils.js +3 -2
- package/dist/cjs/node/prerender/runPrerender.js +12 -5
- package/dist/cjs/node/runtime/globalContext.js +7 -4
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/cjs/node/runtime/html/renderHtml.js +1 -1
- package/dist/cjs/node/runtime/html/stream.js +2 -2
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +39 -39
- package/dist/cjs/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +0 -5
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +8 -7
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +15 -19
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +81 -43
- package/dist/cjs/node/runtime/renderPage/loggerProd.js +3 -3
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/node/shared/{getClientEntryFilePath.js → getClientEntry.js} +3 -3
- package/dist/cjs/node/shared/prependEntriesDir.js +13 -0
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +53 -26
- package/dist/cjs/shared/route/executeGuardHook.js +3 -2
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/utils/assertNodeVersion.js +2 -2
- package/dist/cjs/utils/{findUserPackageJsonPath.js → findFile.js} +11 -8
- package/dist/cjs/utils/isVersionOrAbove.js +29 -0
- package/dist/cjs/utils/nodeEnv.js +23 -1
- package/dist/cjs/utils/objectKeys.js +19 -3
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/sorter.js +62 -1
- package/dist/esm/client/client-routing-runtime/index.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/index.js +1 -1
- package/dist/esm/node/cli/bin.js +3 -1
- package/dist/esm/node/client/router.d.ts +2 -0
- package/dist/esm/node/client/router.js +3 -1
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +2 -2
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.d.ts +13 -0
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +142 -0
- package/dist/esm/node/plugin/plugins/buildConfig.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/buildConfig.js +60 -34
- package/dist/esm/node/plugin/plugins/commonConfig.js +6 -14
- package/dist/esm/node/plugin/plugins/config/stemUtils.js +2 -2
- package/dist/esm/node/plugin/plugins/distFileNames.js +9 -1
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +8 -3
- package/dist/esm/node/plugin/plugins/importBuild/index.d.ts +6 -1
- package/dist/esm/node/plugin/plugins/importBuild/index.js +4 -7
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +39 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +29 -47
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.js → loadFileAtConfigTime.js} +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +27 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.d.ts → transformFileImports.d.ts} +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.js → transformFileImports.js} +6 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +20 -26
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +4 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +153 -109
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -1
- package/dist/esm/node/plugin/utils.d.ts +3 -2
- package/dist/esm/node/plugin/utils.js +3 -2
- package/dist/esm/node/prerender/runPrerender.js +13 -6
- package/dist/esm/node/runtime/globalContext.js +8 -5
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/esm/node/runtime/html/renderHtml.js +1 -1
- package/dist/esm/node/runtime/html/stream.js +2 -2
- package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.d.ts +6 -5
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +39 -39
- package/dist/esm/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +0 -5
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +8 -7
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +16 -20
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/esm/node/runtime/renderPage/logErrorHint.d.ts +8 -0
- package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +80 -42
- package/dist/esm/node/runtime/renderPage/loggerProd.js +3 -3
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/node/shared/ViteManifest.d.ts +1 -0
- package/dist/esm/node/shared/getClientEntry.d.ts +3 -0
- package/dist/esm/node/shared/{getClientEntryFilePath.js → getClientEntry.js} +2 -2
- package/dist/esm/node/shared/prependEntriesDir.d.ts +2 -0
- package/dist/esm/node/shared/prependEntriesDir.js +10 -0
- package/dist/esm/shared/page-configs/Config.d.ts +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +2 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +53 -26
- package/dist/esm/shared/route/executeGuardHook.js +3 -2
- package/dist/esm/shared/utils.d.ts +0 -1
- package/dist/esm/shared/utils.js +0 -1
- package/dist/esm/utils/assertNodeVersion.js +2 -2
- package/dist/esm/utils/findFile.d.ts +3 -0
- package/dist/esm/utils/findFile.js +21 -0
- package/dist/esm/utils/getOutDirs.d.ts +1 -0
- package/dist/esm/utils/isVersionOrAbove.d.ts +2 -0
- package/dist/esm/utils/isVersionOrAbove.js +26 -0
- package/dist/esm/utils/nodeEnv.d.ts +4 -0
- package/dist/esm/utils/nodeEnv.js +19 -0
- package/dist/esm/utils/objectKeys.d.ts +10 -1
- package/dist/esm/utils/objectKeys.js +20 -3
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/sorter.d.ts +59 -0
- package/dist/esm/utils/sorter.js +61 -0
- package/package.json +2 -2
- package/dist/cjs/utils/objectEntries.js +0 -8
- package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError.d.ts +0 -13
- package/dist/esm/node/shared/getClientEntryFilePath.d.ts +0 -3
- package/dist/esm/utils/findUserPackageJsonPath.d.ts +0 -2
- package/dist/esm/utils/findUserPackageJsonPath.js +0 -18
- package/dist/esm/utils/objectEntries.d.ts +0 -4
- package/dist/esm/utils/objectEntries.js +0 -5
- /package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
- /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.d.ts → loadFileAtConfigTime.d.ts} +0 -0
- /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.d.ts +0 -0
- /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
|
@@ -2,41 +2,68 @@ export { parseConfigValuesImported };
|
|
|
2
2
|
import { assert } from '../../utils.js';
|
|
3
3
|
import { assertPlusFileExport } from '../assertPlusFileExport.js';
|
|
4
4
|
function parseConfigValuesImported(configValuesImported) {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
definedAt: {
|
|
10
|
-
// importPath cannot be relative to the current file, since the current file is a virtual file
|
|
11
|
-
filePathToShowToUser: importPath,
|
|
12
|
-
fileExportPathToShowToUser: [configName, 'default'].includes(exportName)
|
|
13
|
-
? []
|
|
14
|
-
: // Side-effect config
|
|
15
|
-
[exportName]
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
assertIsNotNull(value, configName, importPath);
|
|
19
|
-
};
|
|
20
|
-
configValuesImported.forEach((configValueLoaded) => {
|
|
5
|
+
const configValuesUnmerged = {};
|
|
6
|
+
configValuesImported
|
|
7
|
+
.filter((c) => c.configName !== 'client')
|
|
8
|
+
.forEach((configValueLoaded) => {
|
|
21
9
|
if (configValueLoaded.isValueFile) {
|
|
22
10
|
const { exportValues, importPath, configName } = configValueLoaded;
|
|
23
|
-
|
|
24
|
-
assertPlusFileExport(exportValues, importPath, configName);
|
|
25
|
-
}
|
|
11
|
+
assertPlusFileExport(exportValues, importPath, configName);
|
|
26
12
|
Object.entries(exportValues).forEach(([exportName, exportValue]) => {
|
|
27
13
|
const isSideExport = exportName !== 'default'; // .md files may have "side-exports" such as `export { frontmatter }`
|
|
28
14
|
const configName = isSideExport ? exportName : configValueLoaded.configName;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
configValuesUnmerged[configName] ?? (configValuesUnmerged[configName] = []);
|
|
16
|
+
configValuesUnmerged[configName].push({
|
|
17
|
+
value: exportValue,
|
|
18
|
+
importPath,
|
|
19
|
+
exportName,
|
|
20
|
+
isSideExport
|
|
21
|
+
});
|
|
35
22
|
});
|
|
36
23
|
}
|
|
37
24
|
else {
|
|
38
25
|
const { configName, importPath, exportValue, exportName } = configValueLoaded;
|
|
39
|
-
|
|
26
|
+
configValuesUnmerged[configName] ?? (configValuesUnmerged[configName] = []);
|
|
27
|
+
configValuesUnmerged[configName].push({
|
|
28
|
+
value: exportValue,
|
|
29
|
+
importPath,
|
|
30
|
+
exportName,
|
|
31
|
+
isSideExport: false
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
const configValues = {};
|
|
36
|
+
Object.entries(configValuesUnmerged).forEach(([configName, values]) => {
|
|
37
|
+
const valuesWithoutSideExports = values.filter((v) => !v.isSideExport);
|
|
38
|
+
const isCumulative = valuesWithoutSideExports.length > 1;
|
|
39
|
+
const noSideExports = valuesWithoutSideExports.length === values.length;
|
|
40
|
+
if (isCumulative) {
|
|
41
|
+
// Vike currently doesn't support side exports for cumulative configs
|
|
42
|
+
assert(noSideExports);
|
|
43
|
+
// TODO: implement
|
|
44
|
+
assert(false);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const val = valuesWithoutSideExports[0] ??
|
|
48
|
+
// We can't avoid side-export conflicts upstream. (We cannot know about side-exports at build-time.)
|
|
49
|
+
// Side-exports have lower precedence.
|
|
50
|
+
values[0];
|
|
51
|
+
assert(val);
|
|
52
|
+
const { value, importPath, exportName } = val;
|
|
53
|
+
configValues[configName] = {
|
|
54
|
+
value,
|
|
55
|
+
definedAt: {
|
|
56
|
+
// importPath cannot be relative to the current file, since the current file is a virtual file
|
|
57
|
+
filePathToShowToUser: importPath,
|
|
58
|
+
fileExportPathToShowToUser: [configName, 'default'].includes(exportName)
|
|
59
|
+
? []
|
|
60
|
+
: [
|
|
61
|
+
// Side-export
|
|
62
|
+
exportName
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
assertIsNotNull(value, configName, importPath);
|
|
40
67
|
}
|
|
41
68
|
});
|
|
42
69
|
return configValues;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { executeGuardHook };
|
|
2
2
|
import { getHook, getHookTimeoutDefault } from '../hooks/getHook.js';
|
|
3
3
|
import { assert, assertUsage, executeHook, isCallable } from './utils.js';
|
|
4
|
+
const errIntro = 'The guard() hook defined by';
|
|
4
5
|
async function executeGuardHook(pageContext, prepareForUserConsumption) {
|
|
5
6
|
let hook;
|
|
6
7
|
if (pageContext._pageFilesAll.length > 0) {
|
|
@@ -20,7 +21,7 @@ async function executeGuardHook(pageContext, prepareForUserConsumption) {
|
|
|
20
21
|
if (res)
|
|
21
22
|
pageContextForUserConsumption = res;
|
|
22
23
|
const hookResult = await executeHook(() => guard(pageContextForUserConsumption), hook);
|
|
23
|
-
assertUsage(hookResult === undefined,
|
|
24
|
+
assertUsage(hookResult === undefined, `${errIntro} ${hook.hookFilePath} returns a value, but guard() shouldn't return any value`);
|
|
24
25
|
}
|
|
25
26
|
function findPageGuard(pageId, pageFilesAll) {
|
|
26
27
|
const pageRouteFile = pageFilesAll.find((p) => p.pageId === pageId && p.fileType === '.page.route');
|
|
@@ -33,6 +34,6 @@ function findPageGuard(pageId, pageFilesAll) {
|
|
|
33
34
|
return null;
|
|
34
35
|
const hookFilePath = filePath;
|
|
35
36
|
const hookTimeout = getHookTimeoutDefault('guard');
|
|
36
|
-
assertUsage(isCallable(hookFn),
|
|
37
|
+
assertUsage(isCallable(hookFn), `${errIntro} ${hookFilePath} should be a function`);
|
|
37
38
|
return { hookFn, hookName: 'guard', hookFilePath, hookTimeout };
|
|
38
39
|
}
|
|
@@ -18,6 +18,5 @@ export * from '../utils/projectInfo.js';
|
|
|
18
18
|
export * from '../utils/isPropertyGetter.js';
|
|
19
19
|
export * from '../utils/isPromise.js';
|
|
20
20
|
export * from '../utils/checkType.js';
|
|
21
|
-
export * from '../utils/objectEntries.js';
|
|
22
21
|
export * from '../utils/getValuePrintable.js';
|
|
23
22
|
export * from '../utils/escapeRegex.js';
|
package/dist/esm/shared/utils.js
CHANGED
|
@@ -22,6 +22,5 @@ export * from '../utils/projectInfo.js';
|
|
|
22
22
|
export * from '../utils/isPropertyGetter.js';
|
|
23
23
|
export * from '../utils/isPromise.js';
|
|
24
24
|
export * from '../utils/checkType.js';
|
|
25
|
-
export * from '../utils/objectEntries.js';
|
|
26
25
|
export * from '../utils/getValuePrintable.js';
|
|
27
26
|
export * from '../utils/escapeRegex.js';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { assertNodeVersion };
|
|
2
2
|
import { assertUsage } from './assert.js';
|
|
3
3
|
import { isNodeJS } from './isNodeJS.js';
|
|
4
|
+
import { isVersionOrAbove } from './isVersionOrAbove.js';
|
|
4
5
|
// package.json#engines.node isn't enough as users can ignore it
|
|
5
6
|
function assertNodeVersion() {
|
|
6
7
|
if (!isNodeJS())
|
|
7
8
|
return;
|
|
8
9
|
const version = process.versions.node;
|
|
9
|
-
|
|
10
|
-
assertUsage(major >= 16, `Node.js ${version} isn't supported, use Node.js >=16.0.0 instead.`);
|
|
10
|
+
assertUsage(isVersionOrAbove(version, '16.0.0'), `Node.js ${version} isn't supported, use Node.js >=16.0.0 instead.`);
|
|
11
11
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { findFile };
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
function findFile(arg, cwd) {
|
|
5
|
+
const filenames = Array.isArray(arg) ? arg : [arg];
|
|
6
|
+
let dir = cwd;
|
|
7
|
+
while (true) {
|
|
8
|
+
for (const filename of filenames) {
|
|
9
|
+
const configFilePath = path.join(dir, `./${filename}`);
|
|
10
|
+
if (fs.existsSync(configFilePath)) {
|
|
11
|
+
// return toPosixPath(configFilePath)
|
|
12
|
+
return configFilePath;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const dirPrevious = dir;
|
|
16
|
+
dir = path.dirname(dir);
|
|
17
|
+
if (dir === dirPrevious) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export { isVersionOrAbove };
|
|
2
|
+
import { assert } from './assert.js';
|
|
3
|
+
function isVersionOrAbove(versionActual, versionExpected) {
|
|
4
|
+
const p1 = parseVersion(versionActual);
|
|
5
|
+
const p2 = parseVersion(versionExpected);
|
|
6
|
+
// major
|
|
7
|
+
if (p1[0] !== p2[0])
|
|
8
|
+
return p1[0] > p2[0];
|
|
9
|
+
// minor
|
|
10
|
+
if (p1[1] !== p2[1])
|
|
11
|
+
return p1[1] > p2[1];
|
|
12
|
+
// patch
|
|
13
|
+
if (p1[2] !== p2[2])
|
|
14
|
+
return p1[2] > p2[2];
|
|
15
|
+
// Same version
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
function parseVersion(version) {
|
|
19
|
+
// Remove pre-release tag
|
|
20
|
+
version = version.split('-')[0];
|
|
21
|
+
// major.minor.patch
|
|
22
|
+
const partsStr = version.split('.');
|
|
23
|
+
assert(partsStr.length === 3);
|
|
24
|
+
const parts = partsStr.map((s) => parseInt(s, 10));
|
|
25
|
+
return parts;
|
|
26
|
+
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export { getNodeEnv };
|
|
2
2
|
export { setNodeEnvToProduction };
|
|
3
3
|
export { isNodeEnvDev };
|
|
4
|
+
export { getNodeEnvDesc };
|
|
5
|
+
export { assertNodeEnvIsNotDev };
|
|
4
6
|
declare function getNodeEnv(): null | undefined | string;
|
|
5
7
|
declare function setNodeEnvToProduction(): void | undefined;
|
|
6
8
|
declare function isNodeEnvDev(): boolean;
|
|
9
|
+
declare function getNodeEnvDesc(): `environment is set to be a ${string} environment by process.env.NODE_ENV === ${string}`;
|
|
10
|
+
declare function assertNodeEnvIsNotDev(operation: 'building' | 'pre-rendering'): void;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export { getNodeEnv };
|
|
2
2
|
export { setNodeEnvToProduction };
|
|
3
3
|
export { isNodeEnvDev };
|
|
4
|
+
export { getNodeEnvDesc };
|
|
5
|
+
export { assertNodeEnvIsNotDev };
|
|
6
|
+
import pc from '@brillout/picocolors';
|
|
7
|
+
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
8
|
+
import { assertUsage } from './assert.js';
|
|
9
|
+
assertIsNotBrowser();
|
|
4
10
|
function getNodeEnv() {
|
|
5
11
|
if (typeof process === 'undefined')
|
|
6
12
|
return null;
|
|
@@ -21,3 +27,16 @@ function isNodeEnvDev() {
|
|
|
21
27
|
// That's quite aggressive, let's see if some user complains
|
|
22
28
|
return false;
|
|
23
29
|
}
|
|
30
|
+
function getNodeEnvDesc() {
|
|
31
|
+
const nodeEnv = getNodeEnv();
|
|
32
|
+
const isDev = isNodeEnvDev();
|
|
33
|
+
const nodeEnvDesc = `environment is set to be a ${(isDev ? 'development' : 'production')} environment by ${pc.cyan(`process.env.NODE_ENV === ${JSON.stringify(nodeEnv)}`)}`;
|
|
34
|
+
return nodeEnvDesc;
|
|
35
|
+
}
|
|
36
|
+
function assertNodeEnvIsNotDev(operation) {
|
|
37
|
+
const isDev = isNodeEnvDev();
|
|
38
|
+
if (!isDev)
|
|
39
|
+
return;
|
|
40
|
+
const nodeEnvDesc = getNodeEnvDesc();
|
|
41
|
+
assertUsage(false, `The ${nodeEnvDesc} which is forbidden upon ${operation}, see https://vike.dev/NODE_ENV`);
|
|
42
|
+
}
|
|
@@ -1,2 +1,11 @@
|
|
|
1
|
+
export { objectEntries };
|
|
2
|
+
export { objectFromEntries };
|
|
3
|
+
export { objectKeys };
|
|
4
|
+
type ValueOf<T> = T[keyof T];
|
|
5
|
+
type Entries<T> = [keyof T, ValueOf<T>][];
|
|
6
|
+
/** Same as Object.entries() but with type inference */
|
|
7
|
+
declare function objectEntries<T extends object>(obj: T): Entries<T>;
|
|
8
|
+
/** Same as Object.fromEntries() but with type inference */
|
|
9
|
+
declare function objectFromEntries<T extends [PropertyKey, unknown][]>(arr: T): Record<T[number][0], T[number][1]>;
|
|
1
10
|
/** Same as Object.keys() but with type inference */
|
|
2
|
-
|
|
11
|
+
declare function objectKeys<T extends object>(obj: T): (keyof T)[];
|
|
@@ -1,6 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
1
|
+
export { objectEntries };
|
|
2
|
+
export { objectFromEntries };
|
|
3
|
+
export { objectKeys };
|
|
4
|
+
// https://stackoverflow.com/questions/60141960/typescript-key-value-relation-preserving-object-entries-type/75337277#75337277
|
|
5
|
+
/** Same as Object.entries() but with type inference */
|
|
6
|
+
function objectEntries(obj) {
|
|
7
|
+
return Object.entries(obj);
|
|
8
|
+
}
|
|
9
|
+
/** Same as Object.fromEntries() but with type inference */
|
|
10
|
+
function objectFromEntries(arr) {
|
|
11
|
+
return Object.fromEntries(arr);
|
|
4
12
|
}
|
|
5
13
|
// https://stackoverflow.com/questions/52856496/typescript-object-keys-return-string
|
|
6
14
|
// https://github.com/sindresorhus/ts-extras/blob/main/source/object-keys.ts
|
|
15
|
+
/** Same as Object.keys() but with type inference */
|
|
16
|
+
function objectKeys(obj) {
|
|
17
|
+
return Object.keys(obj);
|
|
18
|
+
}
|
|
19
|
+
/*
|
|
20
|
+
function objectKeys2<T extends Record<string, unknown>>(obj: T): Array<keyof T> {
|
|
21
|
+
return Object.keys(obj)
|
|
22
|
+
}
|
|
23
|
+
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
|
-
declare const PROJECT_VERSION: "0.4.
|
|
3
|
+
declare const PROJECT_VERSION: "0.4.161-commit-ba539a4";
|
|
4
4
|
declare const projectInfo: {
|
|
5
5
|
projectName: "Vike";
|
|
6
|
-
projectVersion: "0.4.
|
|
6
|
+
projectVersion: "0.4.161-commit-ba539a4";
|
|
7
7
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
3
|
import { onProjectInfo } from './assertSingleInstance.js';
|
|
4
|
-
const PROJECT_VERSION = '0.4.
|
|
4
|
+
const PROJECT_VERSION = '0.4.161-commit-ba539a4';
|
|
5
5
|
const projectInfo = {
|
|
6
6
|
projectName: 'Vike',
|
|
7
7
|
projectVersion: PROJECT_VERSION
|
|
@@ -2,7 +2,66 @@ export { higherFirst };
|
|
|
2
2
|
export { lowerFirst };
|
|
3
3
|
export { makeFirst };
|
|
4
4
|
export { makeLast };
|
|
5
|
+
export { reverse };
|
|
6
|
+
/**
|
|
7
|
+
* ```js
|
|
8
|
+
* let arr = [
|
|
9
|
+
* { price: 10 },
|
|
10
|
+
* { price: 1000 },
|
|
11
|
+
* { price: 100 }
|
|
12
|
+
* ]
|
|
13
|
+
* arr = arr.sort(higherFirst(el => el.price))
|
|
14
|
+
* isEqual(arr, [
|
|
15
|
+
* { price: 1000 },
|
|
16
|
+
* { price: 100 },
|
|
17
|
+
* { price: 10 }
|
|
18
|
+
* ])
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
5
21
|
declare function higherFirst<T>(getValue: (element: T) => number): (element1: T, element2: T) => 0 | 1 | -1;
|
|
22
|
+
/**
|
|
23
|
+
* ```js
|
|
24
|
+
* let arr = [
|
|
25
|
+
* { price: 10 },
|
|
26
|
+
* { price: 1000 },
|
|
27
|
+
* { price: 100 }
|
|
28
|
+
* ]
|
|
29
|
+
* arr = arr.sort(lowerFirst(el => el.price))
|
|
30
|
+
* isEqual(arr, [
|
|
31
|
+
* { price: 10 },
|
|
32
|
+
* { price: 100 },
|
|
33
|
+
* { price: 1000 }
|
|
34
|
+
* ])
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
6
37
|
declare function lowerFirst<T>(getValue: (element: T) => number): (element1: T, element2: T) => 0 | 1 | -1;
|
|
38
|
+
/**
|
|
39
|
+
* ```js
|
|
40
|
+
* let arr = [
|
|
41
|
+
* { name: 'iphone', isRocket: false },
|
|
42
|
+
* { name: 'starship', isRocket: true }
|
|
43
|
+
* ]
|
|
44
|
+
* arr = arr.sort(makeFirst(el => el.isRocket))
|
|
45
|
+
* isEqual(arr, [
|
|
46
|
+
* { name: 'starship', isRocket: true },
|
|
47
|
+
* { name: 'iphone', isRocket: false }
|
|
48
|
+
* ])
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
7
51
|
declare function makeFirst<T>(getValue: (element: T) => boolean | null): (element1: T, element2: T) => 0 | 1 | -1;
|
|
52
|
+
/**
|
|
53
|
+
* ```js
|
|
54
|
+
* let arr = [
|
|
55
|
+
* { name: 'starship', isRocket: true },
|
|
56
|
+
* { name: 'iphone', isRocket: false }
|
|
57
|
+
* ]
|
|
58
|
+
* arr = arr.sort(makeLast(el => el.isRocket))
|
|
59
|
+
* isEqual(arr, [
|
|
60
|
+
* { name: 'iphone', isRocket: false },
|
|
61
|
+
* { name: 'starship', isRocket: true }
|
|
62
|
+
* ])
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
8
65
|
declare function makeLast<T>(getValue: (element: T) => boolean | null): (element1: T, element2: T) => 0 | 1 | -1;
|
|
66
|
+
/** Reverse order result. */
|
|
67
|
+
declare function reverse(sortKey: 0 | 1 | -1): 0 | 1 | -1;
|
package/dist/esm/utils/sorter.js
CHANGED
|
@@ -3,9 +3,25 @@ export { higherFirst };
|
|
|
3
3
|
export { lowerFirst };
|
|
4
4
|
export { makeFirst };
|
|
5
5
|
export { makeLast };
|
|
6
|
+
export { reverse };
|
|
6
7
|
// -1 => element1 first (i.e. `indexOf(element1) < indexOf(element2)`)
|
|
7
8
|
// +1 => element2 first (i.e. `indexOf(element2) < indexOf(element1)`)
|
|
8
9
|
// 0 => keep original order of element1 and element2
|
|
10
|
+
/**
|
|
11
|
+
* ```js
|
|
12
|
+
* let arr = [
|
|
13
|
+
* { price: 10 },
|
|
14
|
+
* { price: 1000 },
|
|
15
|
+
* { price: 100 }
|
|
16
|
+
* ]
|
|
17
|
+
* arr = arr.sort(higherFirst(el => el.price))
|
|
18
|
+
* isEqual(arr, [
|
|
19
|
+
* { price: 1000 },
|
|
20
|
+
* { price: 100 },
|
|
21
|
+
* { price: 10 }
|
|
22
|
+
* ])
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
9
25
|
function higherFirst(getValue) {
|
|
10
26
|
return (element1, element2) => {
|
|
11
27
|
const val1 = getValue(element1);
|
|
@@ -16,6 +32,21 @@ function higherFirst(getValue) {
|
|
|
16
32
|
return val1 > val2 ? -1 : 1;
|
|
17
33
|
};
|
|
18
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* ```js
|
|
37
|
+
* let arr = [
|
|
38
|
+
* { price: 10 },
|
|
39
|
+
* { price: 1000 },
|
|
40
|
+
* { price: 100 }
|
|
41
|
+
* ]
|
|
42
|
+
* arr = arr.sort(lowerFirst(el => el.price))
|
|
43
|
+
* isEqual(arr, [
|
|
44
|
+
* { price: 10 },
|
|
45
|
+
* { price: 100 },
|
|
46
|
+
* { price: 1000 }
|
|
47
|
+
* ])
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
19
50
|
function lowerFirst(getValue) {
|
|
20
51
|
return (element1, element2) => {
|
|
21
52
|
const val1 = getValue(element1);
|
|
@@ -26,6 +57,19 @@ function lowerFirst(getValue) {
|
|
|
26
57
|
return val1 < val2 ? -1 : 1;
|
|
27
58
|
};
|
|
28
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* ```js
|
|
62
|
+
* let arr = [
|
|
63
|
+
* { name: 'iphone', isRocket: false },
|
|
64
|
+
* { name: 'starship', isRocket: true }
|
|
65
|
+
* ]
|
|
66
|
+
* arr = arr.sort(makeFirst(el => el.isRocket))
|
|
67
|
+
* isEqual(arr, [
|
|
68
|
+
* { name: 'starship', isRocket: true },
|
|
69
|
+
* { name: 'iphone', isRocket: false }
|
|
70
|
+
* ])
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
29
73
|
function makeFirst(getValue) {
|
|
30
74
|
return (element1, element2) => {
|
|
31
75
|
const val1 = getValue(element1);
|
|
@@ -44,6 +88,19 @@ function makeFirst(getValue) {
|
|
|
44
88
|
assert(false);
|
|
45
89
|
};
|
|
46
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* ```js
|
|
93
|
+
* let arr = [
|
|
94
|
+
* { name: 'starship', isRocket: true },
|
|
95
|
+
* { name: 'iphone', isRocket: false }
|
|
96
|
+
* ]
|
|
97
|
+
* arr = arr.sort(makeLast(el => el.isRocket))
|
|
98
|
+
* isEqual(arr, [
|
|
99
|
+
* { name: 'iphone', isRocket: false },
|
|
100
|
+
* { name: 'starship', isRocket: true }
|
|
101
|
+
* ])
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
47
104
|
function makeLast(getValue) {
|
|
48
105
|
return makeFirst((element) => {
|
|
49
106
|
const val = getValue(element);
|
|
@@ -55,3 +112,7 @@ function makeLast(getValue) {
|
|
|
55
112
|
}
|
|
56
113
|
});
|
|
57
114
|
}
|
|
115
|
+
/** Reverse order result. */
|
|
116
|
+
function reverse(sortKey) {
|
|
117
|
+
return (-1 * sortKey);
|
|
118
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.161-commit-ba539a4",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "tsc --watch",
|
|
6
6
|
"build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
|
|
@@ -189,7 +189,7 @@
|
|
|
189
189
|
"@types/source-map-support": "^0.5.10",
|
|
190
190
|
"rimraf": "^5.0.5",
|
|
191
191
|
"typescript": "^5.3.3",
|
|
192
|
-
"vite": "
|
|
192
|
+
"vite": "npm:@brillout/vite@5.1.0-commit-3dc7abd"
|
|
193
193
|
},
|
|
194
194
|
"engines": {
|
|
195
195
|
"node": ">=16.0.0"
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.objectEntries = void 0;
|
|
4
|
-
// Same as `Object.entries()` but with type inference
|
|
5
|
-
function objectEntries(obj) {
|
|
6
|
-
return Object.entries(obj);
|
|
7
|
-
}
|
|
8
|
-
exports.objectEntries = objectEntries;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export { logHintForCjsEsmError };
|
|
2
|
-
export { isCjsEsmError };
|
|
3
|
-
export { isReactInvalidComponentError };
|
|
4
|
-
export { getHint };
|
|
5
|
-
declare function logHintForCjsEsmError(error: unknown): void;
|
|
6
|
-
declare function getHint(error: unknown): null | string;
|
|
7
|
-
declare function isReactInvalidComponentError(error: unknown): boolean;
|
|
8
|
-
/**
|
|
9
|
-
* `false` -> noop
|
|
10
|
-
* `true` -> generic message
|
|
11
|
-
* `'some-npm-package'` -> add some-npm-package to `ssr.noExternal`
|
|
12
|
-
*/
|
|
13
|
-
declare function isCjsEsmError(error: unknown): boolean | string[];
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export { findUserPackageJsonPath };
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
function findUserPackageJsonPath(userDir) {
|
|
5
|
-
let dir = userDir;
|
|
6
|
-
while (true) {
|
|
7
|
-
const configFilePath = path.join(dir, './package.json');
|
|
8
|
-
if (fs.existsSync(configFilePath)) {
|
|
9
|
-
// return toPosixPath(configFilePath)
|
|
10
|
-
return configFilePath;
|
|
11
|
-
}
|
|
12
|
-
const dirPrevious = dir;
|
|
13
|
-
dir = path.dirname(dir);
|
|
14
|
-
if (dir === dirPrevious) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
File without changes
|
|
File without changes
|
/package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.d.ts
RENAMED
|
File without changes
|
|
File without changes
|