vike 0.4.165 → 0.4.166
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 +1 -1
- package/dist/cjs/node/plugin/plugins/baseUrls.js +1 -1
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +6 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +68 -58
- package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +12 -0
- package/dist/cjs/node/plugin/plugins/config/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -2
- package/dist/cjs/node/plugin/plugins/envVars.js +1 -1
- package/dist/cjs/node/plugin/plugins/fileEnv.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +0 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +53 -24
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +6 -6
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +5 -24
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +15 -22
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -20
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +21 -20
- package/dist/cjs/node/plugin/shared/getFilePath.js +88 -0
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +1 -1
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -0
- package/dist/cjs/node/runtime/html/injectAssets/injectHtmlTags.js +1 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +26 -24
- package/dist/cjs/node/runtime/renderPage/logErrorHint.js +5 -0
- package/dist/cjs/node/runtime/renderPage.js +34 -21
- package/dist/cjs/shared/page-configs/FilePath.js +2 -0
- package/dist/cjs/utils/assert.js +2 -0
- package/dist/cjs/utils/assertSingleInstance.js +6 -5
- package/dist/cjs/utils/assertVersion.js +4 -1
- package/dist/cjs/utils/getFilePathAbsolute.js +11 -11
- package/dist/cjs/utils/getGlobalObject.js +21 -6
- package/dist/cjs/utils/isNpmPackage.js +1 -4
- package/dist/cjs/utils/parseUrl.js +8 -1
- package/dist/cjs/utils/projectInfo.js +1 -4
- package/dist/esm/client/client-routing-runtime/history.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/history.js +5 -5
- package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +1 -1
- package/dist/esm/node/plugin/index.js +1 -1
- package/dist/esm/node/plugin/plugins/baseUrls.js +1 -1
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +6 -2
- package/dist/esm/node/plugin/plugins/buildConfig.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/buildConfig.js +69 -59
- package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +12 -0
- package/dist/esm/node/plugin/plugins/config/index.js +1 -1
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +3 -3
- package/dist/esm/node/plugin/plugins/envVars.js +2 -2
- package/dist/esm/node/plugin/plugins/fileEnv.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +54 -25
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +6 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +6 -25
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +15 -22
- 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 +11 -20
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +21 -20
- package/dist/esm/node/plugin/shared/getFilePath.d.ts +20 -0
- package/dist/esm/node/plugin/shared/getFilePath.js +82 -0
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +2 -2
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -0
- package/dist/esm/node/runtime/html/injectAssets/injectHtmlTags.js +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +26 -24
- package/dist/esm/node/runtime/renderPage/logErrorHint.js +2 -0
- package/dist/esm/node/runtime/renderPage.js +34 -21
- package/dist/esm/shared/page-configs/Config/PageContextConfig.d.ts +1 -1
- package/dist/esm/shared/page-configs/FilePath.d.ts +52 -0
- package/dist/esm/shared/page-configs/FilePath.js +1 -0
- package/dist/esm/shared/page-configs/PageConfig.d.ts +1 -42
- package/dist/esm/utils/assert.js +2 -0
- package/dist/esm/utils/assertSingleInstance.d.ts +2 -2
- package/dist/esm/utils/assertSingleInstance.js +5 -4
- package/dist/esm/utils/assertVersion.js +4 -1
- package/dist/esm/utils/getFilePathAbsolute.d.ts +4 -4
- package/dist/esm/utils/getFilePathAbsolute.js +10 -10
- package/dist/esm/utils/getGlobalObject.d.ts +6 -1
- package/dist/esm/utils/getGlobalObject.js +22 -6
- package/dist/esm/utils/isNpmPackage.d.ts +0 -6
- package/dist/esm/utils/isNpmPackage.js +5 -3
- package/dist/esm/utils/parseUrl.js +8 -1
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -4
- package/package.json +26 -14
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +0 -33
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +0 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +0 -27
|
@@ -16,13 +16,12 @@ require("source-map-support/register.js");
|
|
|
16
16
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
17
17
|
const debug = (0, utils_js_1.createDebugger)('vike:pointer-imports');
|
|
18
18
|
async function transpileAndExecuteFile(filePath, userRootDir, isConfigFile) {
|
|
19
|
-
const { filePathAbsoluteFilesystem } = filePath;
|
|
19
|
+
const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
|
|
20
20
|
const fileExtension = getFileExtension(filePathAbsoluteFilesystem);
|
|
21
|
-
|
|
22
|
-
(0, utils_js_1.assertUsage)((0, utils_js_1.isJavaScriptFile)(filePathAbsoluteFilesystem), `${filePathToShowToUser2} has file extension .${fileExtension} but a config file can only be a JavaScript/TypeScript file`);
|
|
21
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.isJavaScriptFile)(filePathAbsoluteFilesystem), `${filePathToShowToUserResolved} has file extension .${fileExtension} but a config file can only be a JavaScript/TypeScript file`);
|
|
23
22
|
const isHeader = isHeaderFile(filePathAbsoluteFilesystem);
|
|
24
23
|
if (isHeader) {
|
|
25
|
-
(0, utils_js_1.assertWarning)(false, `${picocolors_1.default.cyan('.h.js')} files are deprecated: simply renaming ${
|
|
24
|
+
(0, utils_js_1.assertWarning)(false, `${picocolors_1.default.cyan('.h.js')} files are deprecated: simply renaming ${filePathToShowToUserResolved} to ${removeHeaderFileExtension(filePathToShowToUserResolved)} is usually enough, although you may occasionally need to use ${picocolors_1.default.cyan("with { type: 'pointer' }")} as explained at https://vike.dev/config#pointer-imports`, { onlyOnce: true });
|
|
26
25
|
}
|
|
27
26
|
if (isConfigFile === 'is-extension-config' && !isHeader && fileExtension.endsWith('js')) {
|
|
28
27
|
// This doesn't track dependencies => we should never use this for user land configs
|
|
@@ -38,28 +37,27 @@ async function transpileAndExecuteFile(filePath, userRootDir, isConfigFile) {
|
|
|
38
37
|
}
|
|
39
38
|
exports.transpileAndExecuteFile = transpileAndExecuteFile;
|
|
40
39
|
async function transpileFile(filePath, transformImports, userRootDir) {
|
|
41
|
-
const
|
|
42
|
-
const { filePathAbsoluteFilesystem } = filePath;
|
|
40
|
+
const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
|
|
43
41
|
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
44
42
|
getVikeConfig_js_1.vikeConfigDependencies.add(filePathAbsoluteFilesystem);
|
|
45
43
|
if (debug.isEnabled)
|
|
46
|
-
debug('transpile',
|
|
44
|
+
debug('transpile', filePathToShowToUserResolved);
|
|
47
45
|
let { code, pointerImports } = await transpileWithEsbuild(filePath, userRootDir, transformImports);
|
|
48
46
|
if (debug.isEnabled)
|
|
49
|
-
debug(`code, post esbuild (${
|
|
47
|
+
debug(`code, post esbuild (${filePathToShowToUserResolved})`, code);
|
|
50
48
|
let isImportTransformed = false;
|
|
51
49
|
if (transformImports) {
|
|
52
|
-
const codeMod = (0, transformFileImports_js_1.transformFileImports)(code,
|
|
50
|
+
const codeMod = (0, transformFileImports_js_1.transformFileImports)(code, filePathToShowToUserResolved, pointerImports);
|
|
53
51
|
if (codeMod) {
|
|
54
52
|
code = codeMod;
|
|
55
53
|
isImportTransformed = true;
|
|
56
54
|
if (debug.isEnabled)
|
|
57
|
-
debug(`code, post transformImports() (${
|
|
55
|
+
debug(`code, post transformImports() (${filePathToShowToUserResolved})`, code);
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
58
|
if (!isImportTransformed) {
|
|
61
59
|
if (debug.isEnabled)
|
|
62
|
-
debug(`code, no transformImports() (${
|
|
60
|
+
debug(`code, no transformImports() (${filePathToShowToUserResolved})`);
|
|
63
61
|
}
|
|
64
62
|
return code;
|
|
65
63
|
}
|
|
@@ -298,19 +296,12 @@ function triggerPrepareStackTrace(err) {
|
|
|
298
296
|
}
|
|
299
297
|
}
|
|
300
298
|
function getErrIntroMsg(operation, filePath) {
|
|
301
|
-
const
|
|
299
|
+
const { filePathToShowToUserResolved } = filePath;
|
|
302
300
|
const msg = [
|
|
303
301
|
// prettier ignore
|
|
304
302
|
picocolors_1.default.red(`Failed to ${operation}`),
|
|
305
|
-
picocolors_1.default.bold(picocolors_1.default.red(
|
|
303
|
+
picocolors_1.default.bold(picocolors_1.default.red(filePathToShowToUserResolved)),
|
|
306
304
|
picocolors_1.default.red(`because:`)
|
|
307
305
|
].join(' ');
|
|
308
306
|
return msg;
|
|
309
307
|
}
|
|
310
|
-
/** `filePath.filePathToShowToUser` may show the import path of a package, use `filePathToShowToUser2` instead always show a file path instead. */
|
|
311
|
-
function getFilePathToShowToUser2(filePath) {
|
|
312
|
-
const { filePathAbsoluteFilesystem, filePathRelativeToUserRootDir } = filePath;
|
|
313
|
-
const filePathToShowToUser2 = filePathRelativeToUserRootDir || filePathAbsoluteFilesystem;
|
|
314
|
-
(0, utils_js_1.assert)(filePathToShowToUser2);
|
|
315
|
-
return filePathToShowToUser2;
|
|
316
|
-
}
|
|
@@ -20,7 +20,7 @@ const crawlPlusFiles_js_1 = require("./getVikeConfig/crawlPlusFiles.js");
|
|
|
20
20
|
const getConfigFileExport_js_1 = require("./getConfigFileExport.js");
|
|
21
21
|
const loadFileAtConfigTime_js_1 = require("./getVikeConfig/loadFileAtConfigTime.js");
|
|
22
22
|
const resolveImportPath_js_1 = require("./getVikeConfig/resolveImportPath.js");
|
|
23
|
-
const
|
|
23
|
+
const getFilePath_js_1 = require("../../../shared/getFilePath.js");
|
|
24
24
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
25
25
|
let devServerIsCorrupt = false;
|
|
26
26
|
let wasConfigInvalid = null;
|
|
@@ -65,7 +65,7 @@ async function handleReloadSideEffects() {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
async function getVikeConfig(config, isDev, tolerateInvalidConfig
|
|
68
|
+
async function getVikeConfig(config, isDev, tolerateInvalidConfig) {
|
|
69
69
|
const { outDirRoot } = (0, utils_js_1.getOutDirs)(config);
|
|
70
70
|
const userRootDir = config.root;
|
|
71
71
|
if (!vikeConfigPromise) {
|
|
@@ -97,11 +97,11 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev) {
|
|
|
97
97
|
await Promise.all([
|
|
98
98
|
// Config files
|
|
99
99
|
...configFiles.map(async (filePath) => {
|
|
100
|
-
const {
|
|
101
|
-
(0, utils_js_1.assert)(
|
|
100
|
+
const { filePathAbsoluteUserRootDir } = filePath;
|
|
101
|
+
(0, utils_js_1.assert)(filePathAbsoluteUserRootDir);
|
|
102
102
|
const { configFile, extendsConfigs } = await (0, loadFileAtConfigTime_js_1.loadConfigFile)(filePath, userRootDir, [], false);
|
|
103
|
-
(0, utils_js_1.assert)(filePath.
|
|
104
|
-
const locationId = (0, filesystemRouting_js_1.getLocationId)(
|
|
103
|
+
(0, utils_js_1.assert)(filePath.filePathAbsoluteUserRootDir);
|
|
104
|
+
const locationId = (0, filesystemRouting_js_1.getLocationId)(filePathAbsoluteUserRootDir);
|
|
105
105
|
const interfaceFile = getInterfaceFileFromConfigFile(configFile, false, locationId);
|
|
106
106
|
interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
|
|
107
107
|
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
@@ -150,11 +150,11 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev) {
|
|
|
150
150
|
}),
|
|
151
151
|
// Value files
|
|
152
152
|
...valueFiles.map(async (filePath) => {
|
|
153
|
-
const {
|
|
154
|
-
(0, utils_js_1.assert)(
|
|
155
|
-
const configName = getConfigName(
|
|
153
|
+
const { filePathAbsoluteUserRootDir } = filePath;
|
|
154
|
+
(0, utils_js_1.assert)(filePathAbsoluteUserRootDir);
|
|
155
|
+
const configName = getConfigName(filePathAbsoluteUserRootDir);
|
|
156
156
|
(0, utils_js_1.assert)(configName);
|
|
157
|
-
const locationId = (0, filesystemRouting_js_1.getLocationId)(
|
|
157
|
+
const locationId = (0, filesystemRouting_js_1.getLocationId)(filePathAbsoluteUserRootDir);
|
|
158
158
|
const interfaceFile = {
|
|
159
159
|
locationId,
|
|
160
160
|
filePath,
|
|
@@ -353,9 +353,9 @@ async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importe
|
|
|
353
353
|
const interfaceFilesGlobalPaths = [];
|
|
354
354
|
(0, utils_js_1.objectEntries)(interfaceFilesGlobal).forEach(([locationId, interfaceFiles]) => {
|
|
355
355
|
(0, utils_js_1.assert)((0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds));
|
|
356
|
-
interfaceFiles.forEach(({ filePath: {
|
|
357
|
-
if (
|
|
358
|
-
interfaceFilesGlobalPaths.push(
|
|
356
|
+
interfaceFiles.forEach(({ filePath: { filePathAbsoluteUserRootDir } }) => {
|
|
357
|
+
if (filePathAbsoluteUserRootDir) {
|
|
358
|
+
interfaceFilesGlobalPaths.push(filePathAbsoluteUserRootDir);
|
|
359
359
|
}
|
|
360
360
|
});
|
|
361
361
|
});
|
|
@@ -464,10 +464,10 @@ async function resolveConfigValueSources(configName, configDef, interfaceFilesRe
|
|
|
464
464
|
}
|
|
465
465
|
function makeOrderDeterministic(interfaceFile1, interfaceFile2) {
|
|
466
466
|
return (0, utils_js_1.lowerFirst)((interfaceFile) => {
|
|
467
|
-
const {
|
|
467
|
+
const { filePathAbsoluteUserRootDir } = interfaceFile.filePath;
|
|
468
468
|
(0, utils_js_1.assert)(isInterfaceFileUserLand(interfaceFile));
|
|
469
|
-
(0, utils_js_1.assert)(
|
|
470
|
-
return
|
|
469
|
+
(0, utils_js_1.assert)(filePathAbsoluteUserRootDir);
|
|
470
|
+
return filePathAbsoluteUserRootDir.length;
|
|
471
471
|
})(interfaceFile1, interfaceFile2);
|
|
472
472
|
}
|
|
473
473
|
function warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden, configName) {
|
|
@@ -541,6 +541,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
541
541
|
configName !== 'extends') {
|
|
542
542
|
if (import_.filePathAbsoluteFilesystem) {
|
|
543
543
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(import_, 'filePathAbsoluteFilesystem', 'string')); // Help TS
|
|
544
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(import_, 'filePathToShowToUserResolved', 'string')); // Help TS
|
|
544
545
|
const fileExport = await (0, loadFileAtConfigTime_js_1.loadImportedFile)(import_, userRootDir, importedFilesLoaded);
|
|
545
546
|
configValueSource.value = fileExport;
|
|
546
547
|
}
|
|
@@ -744,7 +745,7 @@ function getComputed(configValueSources, configDefinitions) {
|
|
|
744
745
|
}
|
|
745
746
|
async function findPlusFiles(userRootDir, outDirRoot, isDev) {
|
|
746
747
|
const files = await (0, crawlPlusFiles_js_1.crawlPlusFiles)(userRootDir, outDirRoot, isDev);
|
|
747
|
-
const plusFiles = files.map(({
|
|
748
|
+
const plusFiles = files.map(({ filePathAbsoluteUserRootDir }) => (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteUserRootDir, userRootDir, importPathAbsolute: null }));
|
|
748
749
|
return plusFiles;
|
|
749
750
|
}
|
|
750
751
|
function getConfigName(filePath) {
|
|
@@ -834,9 +835,9 @@ function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName)
|
|
|
834
835
|
const configDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, configFilesystemRoutingRoot);
|
|
835
836
|
(0, utils_js_1.assertUsage)(typeof value === 'string', `${configDefinedAt} should be a string`);
|
|
836
837
|
(0, utils_js_1.assertUsage)(value.startsWith('/'), `${configDefinedAt} is ${picocolors_1.default.cyan(value)} but it should start with a leading slash ${picocolors_1.default.cyan('/')}`);
|
|
837
|
-
const {
|
|
838
|
-
(0, utils_js_1.assert)(
|
|
839
|
-
const before = (0, filesystemRouting_js_1.getFilesystemRouteString)((0, filesystemRouting_js_1.getLocationId)(
|
|
838
|
+
const { filePathAbsoluteUserRootDir } = configFilesystemRoutingRoot.definedAt;
|
|
839
|
+
(0, utils_js_1.assert)(filePathAbsoluteUserRootDir);
|
|
840
|
+
const before = (0, filesystemRouting_js_1.getFilesystemRouteString)((0, filesystemRouting_js_1.getLocationId)(filePathAbsoluteUserRootDir));
|
|
840
841
|
const after = value;
|
|
841
842
|
const filesystemRoutingRootEffect = { before, after };
|
|
842
843
|
return { filesystemRoutingRootEffect, filesystemRoutingRootDefinedAt: configDefinedAt };
|
|
@@ -0,0 +1,88 @@
|
|
|
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.getFilePathUnresolved = exports.getFilePathResolved = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const utils_js_1 = require("../utils.js");
|
|
9
|
+
function getFilePathUnresolved(args) {
|
|
10
|
+
const { filePathAbsoluteFilesystem, filePathAbsoluteUserRootDir } = args;
|
|
11
|
+
let filePathAbsoluteVite;
|
|
12
|
+
if (args.filePathAbsoluteUserRootDir !== null) {
|
|
13
|
+
filePathAbsoluteVite = args.filePathAbsoluteUserRootDir;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
(0, utils_js_1.assert)(args.importPathAbsolute !== null); // Help TS
|
|
17
|
+
filePathAbsoluteVite = args.importPathAbsolute;
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
...args,
|
|
21
|
+
filePathAbsoluteVite,
|
|
22
|
+
filePathToShowToUser: filePathAbsoluteVite,
|
|
23
|
+
filePathToShowToUserResolved: filePathAbsoluteUserRootDir || filePathAbsoluteFilesystem
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
exports.getFilePathUnresolved = getFilePathUnresolved;
|
|
27
|
+
function getFilePathResolved(args) {
|
|
28
|
+
const { userRootDir, importPathAbsolute } = args;
|
|
29
|
+
let filePathAbsoluteFilesystem;
|
|
30
|
+
let filePathAbsoluteUserRootDir;
|
|
31
|
+
if ('filePathAbsoluteFilesystem' in args) {
|
|
32
|
+
filePathAbsoluteFilesystem = args.filePathAbsoluteFilesystem;
|
|
33
|
+
filePathAbsoluteUserRootDir = getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir });
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
filePathAbsoluteUserRootDir = args.filePathAbsoluteUserRootDir;
|
|
37
|
+
filePathAbsoluteFilesystem = getFilePathAbsoluteUserFilesystem({ filePathAbsoluteUserRootDir, userRootDir });
|
|
38
|
+
}
|
|
39
|
+
let filePathResolved;
|
|
40
|
+
const common = {
|
|
41
|
+
filePathAbsoluteUserRootDir,
|
|
42
|
+
filePathAbsoluteFilesystem,
|
|
43
|
+
importPathAbsolute,
|
|
44
|
+
userRootDir
|
|
45
|
+
};
|
|
46
|
+
if (importPathAbsolute) {
|
|
47
|
+
filePathResolved = getFilePathUnresolved({
|
|
48
|
+
...common,
|
|
49
|
+
importPathAbsolute
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
(0, utils_js_1.assert)(filePathAbsoluteUserRootDir);
|
|
54
|
+
filePathResolved = getFilePathUnresolved({
|
|
55
|
+
...common,
|
|
56
|
+
filePathAbsoluteUserRootDir
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
(0, utils_js_1.assert)(filePathAbsoluteFilesystem);
|
|
60
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(filePathResolved, 'filePathAbsoluteFilesystem', 'string'));
|
|
61
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(filePathResolved, 'filePathToShowToUserResolved', 'string'));
|
|
62
|
+
return filePathResolved;
|
|
63
|
+
}
|
|
64
|
+
exports.getFilePathResolved = getFilePathResolved;
|
|
65
|
+
function getFilePathAbsoluteUserFilesystem({ filePathAbsoluteUserRootDir, userRootDir }) {
|
|
66
|
+
(0, utils_js_1.assertPosixPath)(filePathAbsoluteUserRootDir);
|
|
67
|
+
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
68
|
+
const filePathAbsoluteFilesystem = path_1.default.posix.join(userRootDir, filePathAbsoluteUserRootDir);
|
|
69
|
+
return filePathAbsoluteFilesystem;
|
|
70
|
+
}
|
|
71
|
+
function getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir }) {
|
|
72
|
+
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
73
|
+
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
74
|
+
const filePathRelative = path_1.default.posix.relative(userRootDir, filePathAbsoluteFilesystem);
|
|
75
|
+
if (!filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
76
|
+
(0, utils_js_1.assert)(filePathRelative.startsWith('../'));
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
(0, utils_js_1.assert)(!filePathRelative.startsWith('.') && !filePathRelative.startsWith('/'));
|
|
80
|
+
const filePathAbsoluteUserRootDir = `/${filePathRelative}`;
|
|
81
|
+
{
|
|
82
|
+
let check = filePathAbsoluteFilesystem.slice(userRootDir.length);
|
|
83
|
+
if (!check.startsWith('/'))
|
|
84
|
+
check = '/' + check;
|
|
85
|
+
(0, utils_js_1.assert)(filePathAbsoluteUserRootDir === check);
|
|
86
|
+
}
|
|
87
|
+
return filePathAbsoluteUserRootDir;
|
|
88
|
+
}
|
|
@@ -48,7 +48,7 @@ function getPrettyErrorWithCodeSnippet(err, userRootDir) {
|
|
|
48
48
|
let { id, frame } = err;
|
|
49
49
|
const msgFirstLine = [
|
|
50
50
|
picocolors_1.default.red('Failed to transpile'),
|
|
51
|
-
picocolors_1.default.bold(picocolors_1.default.red((0, utils_js_1.
|
|
51
|
+
picocolors_1.default.bold(picocolors_1.default.red((0, utils_js_1.getFilePathAbsoluteUserRootDir)(normalizeId(id), userRootDir))),
|
|
52
52
|
picocolors_1.default.red('because:')
|
|
53
53
|
].join(' ');
|
|
54
54
|
const errMsg = getPrettyErrMessage(err);
|
|
@@ -144,6 +144,7 @@ async function mergeScriptEntries(pageAssets, isProduction) {
|
|
|
144
144
|
function getPageContextJsonScriptTag(pageContext) {
|
|
145
145
|
const pageContextSerialized = (0, sanitizeJson_js_1.sanitizeJson)((0, serializePageContextClientSide_js_1.serializePageContextClientSide)(pageContext));
|
|
146
146
|
const htmlTag = `<script id="vike_pageContext" type="application/json">${pageContextSerialized}</script>`;
|
|
147
|
+
// Used by contra.com https://github.com/gajus
|
|
147
148
|
// @ts-expect-error
|
|
148
149
|
pageContext._pageContextHtmlTag = htmlTag;
|
|
149
150
|
return htmlTag;
|
|
@@ -95,7 +95,7 @@ function injectBreakLines(htmlFragment, before, after) {
|
|
|
95
95
|
const whitespaceExtra = paddingParent ? ' ' : '';
|
|
96
96
|
const whitespace = `${paddingParent}${whitespaceExtra}`;
|
|
97
97
|
const padding = `\n${whitespace}`;
|
|
98
|
-
htmlFragment = htmlFragment.
|
|
98
|
+
htmlFragment = htmlFragment.replace(/<[^\/]/g, (match) => `${padding}${match}`);
|
|
99
99
|
if (isBlankLine) {
|
|
100
100
|
(0, utils_js_1.assert)(htmlFragment.startsWith(padding), { htmlFragment });
|
|
101
101
|
htmlFragment = whitespaceExtra + htmlFragment.slice(padding.length);
|
|
@@ -50,35 +50,37 @@ function getManifestEntry(id, assetsManifest) {
|
|
|
50
50
|
const [manifestKey, manifestEntry] = found;
|
|
51
51
|
return { manifestEntry, manifestKey };
|
|
52
52
|
}
|
|
53
|
+
/* Can we remove this?
|
|
53
54
|
// extensions[number].pageConfigsSrcDir
|
|
54
55
|
if (id.startsWith('/node_modules/') || id.startsWith('/../')) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
{
|
|
67
|
-
(0, utils_js_1.assert)(manifestKeyEnd.startsWith('/'), debugInfo);
|
|
68
|
-
const dirS = manifestKeyEnd.split('/');
|
|
69
|
-
(0, utils_js_1.assert)(dirS[0] === '', debugInfo);
|
|
70
|
-
manifestKeyEnd = '/' + dirS.slice(2).join('/');
|
|
71
|
-
(0, utils_js_1.assert)(manifestKeyEnd.startsWith('/'), debugInfo);
|
|
56
|
+
let manifestKeyEnd = id.split('/node_modules/').slice(-1)[0]
|
|
57
|
+
assert(manifestKeyEnd, debugInfo)
|
|
58
|
+
assert(!manifestKeyEnd.startsWith('/'), debugInfo)
|
|
59
|
+
manifestKeyEnd = '/' + manifestKeyEnd
|
|
60
|
+
{
|
|
61
|
+
const { manifestEntry, manifestKey } = findEntryWithKeyEnd(manifestKeyEnd, assetsManifest, id)
|
|
62
|
+
if (manifestEntry) {
|
|
63
|
+
assert(manifestKey, debugInfo)
|
|
64
|
+
return { manifestEntry, manifestKey }
|
|
72
65
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
66
|
+
}
|
|
67
|
+
{
|
|
68
|
+
assert(manifestKeyEnd.startsWith('/'), debugInfo)
|
|
69
|
+
const dirS = manifestKeyEnd.split('/')
|
|
70
|
+
assert(dirS[0] === '', debugInfo)
|
|
71
|
+
manifestKeyEnd = '/' + dirS.slice(2).join('/')
|
|
72
|
+
assert(manifestKeyEnd.startsWith('/'), debugInfo)
|
|
73
|
+
}
|
|
74
|
+
{
|
|
75
|
+
const { manifestEntry, manifestKey } = findEntryWithKeyEnd(manifestKeyEnd, assetsManifest, id)
|
|
76
|
+
if (manifestEntry) {
|
|
77
|
+
assert(manifestKey, debugInfo)
|
|
78
|
+
return { manifestEntry, manifestKey }
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
}
|
|
81
|
+
assert(false, debugInfo)
|
|
81
82
|
}
|
|
83
|
+
*/
|
|
82
84
|
(0, utils_js_1.assert)(false, debugInfo);
|
|
83
85
|
}
|
|
84
86
|
exports.getManifestEntry = getManifestEntry;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.getHint = exports.isKnownError = exports.isCjsEsmError = exports.logErrorHint = void 0;
|
|
4
7
|
const utils_js_1 = require("../utils.js");
|
|
8
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
5
9
|
const knownErrors = [
|
|
6
10
|
{
|
|
7
11
|
errMsg: 'jsxDEV is not a function',
|
|
@@ -44,6 +48,7 @@ function getHint(error) {
|
|
|
44
48
|
exports.getHint = getHint;
|
|
45
49
|
function logHint(hint) {
|
|
46
50
|
hint = (0, utils_js_1.formatHintLog)(hint);
|
|
51
|
+
hint = picocolors_1.default.bold(hint);
|
|
47
52
|
console.error(hint);
|
|
48
53
|
}
|
|
49
54
|
function isKnownError(error) {
|
|
@@ -57,7 +57,7 @@ exports.renderPage = renderPage;
|
|
|
57
57
|
async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
58
58
|
// Invalid config
|
|
59
59
|
const handleInvalidConfig = () => {
|
|
60
|
-
(0, loggerRuntime_js_1.logRuntimeInfo)?.(picocolors_1.default.bold(picocolors_1.default.red(
|
|
60
|
+
(0, loggerRuntime_js_1.logRuntimeInfo)?.(picocolors_1.default.bold(picocolors_1.default.red('Error while loading a Vike config file, see error above.')), httpRequestId, 'error');
|
|
61
61
|
const pageContextHttpResponseNull = getPageContextHttpResponseNull(pageContextInit);
|
|
62
62
|
return pageContextHttpResponseNull;
|
|
63
63
|
};
|
|
@@ -209,29 +209,42 @@ function getRequestInfoMessage(urlOriginal) {
|
|
|
209
209
|
}
|
|
210
210
|
function logHttpResponse(urlOriginal, httpRequestId, pageContextReturn) {
|
|
211
211
|
const statusCode = pageContextReturn.httpResponse?.statusCode ?? null;
|
|
212
|
+
let msg;
|
|
213
|
+
let isNominal;
|
|
212
214
|
{
|
|
213
|
-
// If URL doesn't include Base URL
|
|
214
215
|
const { errorWhileRendering } = pageContextReturn;
|
|
215
|
-
const isSkipped = statusCode === null &&
|
|
216
|
-
if (isSkipped)
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
216
|
+
const isSkipped = statusCode === null && !errorWhileRendering;
|
|
217
|
+
if (isSkipped) {
|
|
218
|
+
// - URL doesn't include Base URL
|
|
219
|
+
// - Can we abort earlier so that `logHttpResponse()` and `logHttpRequest()` aren't even called?
|
|
220
|
+
// - Error loading a Vike config file
|
|
221
|
+
// - We should show `HTTP response ${urlOriginal} ERR` instead.
|
|
222
|
+
// - Maybe we can/should make the error available at pageContext.errorWhileRendering
|
|
223
|
+
(0, utils_js_1.assert)(errorWhileRendering === null || errorWhileRendering === undefined);
|
|
224
|
+
msg = `HTTP response ${picocolors_1.default.bold(urlOriginal)} ${picocolors_1.default.dim('null')}`;
|
|
225
|
+
// Erroneous value (it shoud sometimes be `false`) but it's fine as it doesn't seem to have much of an impact.
|
|
226
|
+
isNominal = true;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
const isSuccess = statusCode !== null && statusCode >= 200 && statusCode <= 399;
|
|
230
|
+
isNominal = isSuccess || statusCode === 404;
|
|
231
|
+
const color = (s) => picocolors_1.default.bold(isSuccess ? picocolors_1.default.green(String(s)) : picocolors_1.default.red(String(s)));
|
|
232
|
+
const isRedirect = statusCode && 300 <= statusCode && statusCode <= 399;
|
|
233
|
+
const type = isRedirect ? 'redirect' : 'response';
|
|
234
|
+
if (isRedirect) {
|
|
235
|
+
(0, utils_js_1.assert)(pageContextReturn.httpResponse);
|
|
236
|
+
const headerRedirect = pageContextReturn.httpResponse.headers
|
|
237
|
+
.slice()
|
|
238
|
+
.reverse()
|
|
239
|
+
.find((header) => header[0] === 'Location');
|
|
240
|
+
(0, utils_js_1.assert)(headerRedirect);
|
|
241
|
+
const urlRedirect = headerRedirect[1];
|
|
242
|
+
urlOriginal = urlRedirect;
|
|
243
|
+
}
|
|
244
|
+
msg = `HTTP ${type} ${picocolors_1.default.bold(urlOriginal)} ${color(statusCode ?? 'ERR')}`;
|
|
245
|
+
}
|
|
233
246
|
}
|
|
234
|
-
(0, loggerRuntime_js_1.logRuntimeInfo)?.(
|
|
247
|
+
(0, loggerRuntime_js_1.logRuntimeInfo)?.(msg, httpRequestId, isNominal ? 'info' : 'error');
|
|
235
248
|
}
|
|
236
249
|
function getPageContextHttpResponseNullWithError(err, pageContextInit) {
|
|
237
250
|
const pageContextHttpResponseNull = {};
|
package/dist/cjs/utils/assert.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.isBug = exports.overwriteAssertProductionLogger = exports.getAssertErrMsg = exports.addOnBeforeLogHook = exports.getProjectError = exports.assertInfo = exports.assertWarning = exports.assertUsage = exports.assert = void 0;
|
|
7
|
+
const assertSingleInstance_js_1 = require("./assertSingleInstance.js");
|
|
7
8
|
const createErrorWithCleanStackTrace_js_1 = require("./createErrorWithCleanStackTrace.js");
|
|
8
9
|
const getGlobalObject_js_1 = require("./getGlobalObject.js");
|
|
9
10
|
const isObject_js_1 = require("./isObject.js");
|
|
@@ -22,6 +23,7 @@ const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('utils/assert.ts'
|
|
|
22
23
|
},
|
|
23
24
|
showStackTraceList: new WeakSet()
|
|
24
25
|
});
|
|
26
|
+
(0, assertSingleInstance_js_1.onAssertModuleLoad)();
|
|
25
27
|
const projectTag = `[vike]`;
|
|
26
28
|
const projectTagWithVersion = `[vike@${projectInfo_js_1.projectInfo.projectVersion}]`;
|
|
27
29
|
const numberOfStackTraceLinesToRemove = 2;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.onAssertModuleLoad = exports.onClientEntry_ClientRouting = exports.onClientEntry_ServerRouting = void 0;
|
|
4
4
|
// - Throw error if there are two different versions of vike loaded
|
|
5
5
|
// - Show warning if entry of Client Routing and entry of Server Routing are both loaded
|
|
6
6
|
// - Show warning if vike is loaded twice
|
|
7
7
|
const unique_js_1 = require("./unique.js");
|
|
8
8
|
const getGlobalObject_js_1 = require("./getGlobalObject.js");
|
|
9
|
+
const projectInfo_js_1 = require("./projectInfo.js");
|
|
9
10
|
/* Use original assertUsage() & assertWarning() after all CJS is removed from node_modules/vike/dist/
|
|
10
11
|
import { assertUsage, assertWarning } from './assert.js'
|
|
11
12
|
*/
|
|
@@ -60,12 +61,12 @@ function onClientEntry_ClientRouting(isProduction) {
|
|
|
60
61
|
assertSingleInstance();
|
|
61
62
|
}
|
|
62
63
|
exports.onClientEntry_ClientRouting = onClientEntry_ClientRouting;
|
|
63
|
-
// Called by utils/
|
|
64
|
-
function
|
|
65
|
-
globalObject.instances.push(projectVersion);
|
|
64
|
+
// Called by utils/assert.ts which is (most certainly) loaded by all entries. That way we don't have to call a callback for every entry. (There are a lot of entries: `client/router/`, `client/`, `node/runtime/`, `node/plugin/`, `node/cli`.)
|
|
65
|
+
function onAssertModuleLoad() {
|
|
66
|
+
globalObject.instances.push(projectInfo_js_1.projectInfo.projectVersion);
|
|
66
67
|
assertSingleInstance();
|
|
67
68
|
}
|
|
68
|
-
exports.
|
|
69
|
+
exports.onAssertModuleLoad = onAssertModuleLoad;
|
|
69
70
|
function assertUsage(condition, errorMessage) {
|
|
70
71
|
if (condition) {
|
|
71
72
|
return;
|
|
@@ -25,9 +25,12 @@ exports.isVersionOrAbove = isVersionOrAbove;
|
|
|
25
25
|
function parseVersion(version) {
|
|
26
26
|
// Remove pre-release tag
|
|
27
27
|
version = version.split('-')[0];
|
|
28
|
+
let partsStr = version.split('.');
|
|
29
|
+
// Git seems to be using a fourth number: https://github.com/git/git/tree/master/Documentation/RelNotes
|
|
30
|
+
partsStr = partsStr.slice(0, 3);
|
|
28
31
|
// major.minor.patch
|
|
29
|
-
const partsStr = version.split('.');
|
|
30
32
|
(0, assert_js_1.assert)(partsStr.length === 3);
|
|
33
|
+
(0, assert_js_1.assert)(partsStr.every((s) => s.length > 0));
|
|
31
34
|
const parts = partsStr.map((s) => parseInt(s, 10));
|
|
32
35
|
return parts;
|
|
33
36
|
}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getFilePathAbsoluteUserRootDir = exports.getFilePathAbsoluteFilesystem = void 0;
|
|
7
7
|
const filesystemPathHandling_js_1 = require("./filesystemPathHandling.js");
|
|
8
8
|
const assert_js_1 = require("./assert.js");
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
@@ -18,7 +18,7 @@ const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
|
18
18
|
// Vite handles paths such as /pages/index.page.js which are relative to `config.root`.
|
|
19
19
|
// Make them absolute starting from the filesystem root.
|
|
20
20
|
// Also resolve plus files living in npm packages such as restack/renderer/+onRenderHtml.js
|
|
21
|
-
function
|
|
21
|
+
function getFilePathAbsoluteFilesystem(filePath, config) {
|
|
22
22
|
(0, filesystemPathHandling_js_1.assertPosixPath)(filePath);
|
|
23
23
|
if (filePath.startsWith('/@fs/')) {
|
|
24
24
|
return filePath;
|
|
@@ -46,25 +46,25 @@ function getFilePathAbsolute(filePath, config) {
|
|
|
46
46
|
(0, assertPathIsFilesystemAbsolute_js_1.assertPathIsFilesystemAbsolute)(filePathAbsoluteFilesystem);
|
|
47
47
|
return filePathAbsoluteFilesystem;
|
|
48
48
|
}
|
|
49
|
-
exports.
|
|
50
|
-
function
|
|
49
|
+
exports.getFilePathAbsoluteFilesystem = getFilePathAbsoluteFilesystem;
|
|
50
|
+
function getFilePathAbsoluteUserRootDir(filePathAbsoluteFilesystem, userRootDir, alwaysRelative = false) {
|
|
51
51
|
(0, filesystemPathHandling_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
52
52
|
(0, filesystemPathHandling_js_1.assertPosixPath)(userRootDir);
|
|
53
|
-
let
|
|
53
|
+
let filePathAbsoluteUserRootDir = path_1.default.posix.relative(userRootDir, filePathAbsoluteFilesystem);
|
|
54
54
|
if (filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
55
|
-
(0, assert_js_1.assert)(!
|
|
55
|
+
(0, assert_js_1.assert)(!filePathAbsoluteUserRootDir.startsWith('.') && !filePathAbsoluteUserRootDir.startsWith('/'),
|
|
56
56
|
// Surprinsingly, this assertion seem to fail sometimes: https://github.com/vikejs/vike/issues/1139
|
|
57
|
-
{
|
|
58
|
-
|
|
59
|
-
return
|
|
57
|
+
{ filePathAbsoluteUserRootDir, filePathAbsoluteFilesystem, userRootDir });
|
|
58
|
+
filePathAbsoluteUserRootDir = `/${filePathAbsoluteUserRootDir}`;
|
|
59
|
+
return filePathAbsoluteUserRootDir;
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
62
|
if (alwaysRelative) {
|
|
63
|
-
return
|
|
63
|
+
return filePathAbsoluteUserRootDir;
|
|
64
64
|
}
|
|
65
65
|
else {
|
|
66
66
|
return filePathAbsoluteFilesystem;
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
exports.
|
|
70
|
+
exports.getFilePathAbsoluteUserRootDir = getFilePathAbsoluteUserRootDir;
|
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getGlobalObject = void 0;
|
|
3
|
+
exports.assertIsSingleModuleInstance = exports.getGlobalObject = void 0;
|
|
4
|
+
const assert_js_1 = require("./assert.js");
|
|
5
|
+
const projectInfo_js_1 = require("./projectInfo.js");
|
|
6
|
+
const projectKey = `_${projectInfo_js_1.projectInfo.projectName.toLowerCase()}`;
|
|
7
|
+
/** Share information across module instances. */
|
|
4
8
|
function getGlobalObject(
|
|
5
|
-
// We use the filename as key
|
|
9
|
+
// We use the filename (or file path) as key. There should be only one getGlobalObject() usage per file. Thus the key should be unique, assuming the filename (or file path) is unique.
|
|
6
10
|
key, defaultValue) {
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const globalObject = (globalObjectsAll[key] = globalObjectsAll[key] || defaultValue);
|
|
11
|
+
const globalObjects = getGlobalObjects();
|
|
12
|
+
const globalObject = (globalObjects[key] = globalObjects[key] || defaultValue);
|
|
10
13
|
return globalObject;
|
|
11
14
|
}
|
|
12
15
|
exports.getGlobalObject = getGlobalObject;
|
|
13
|
-
|
|
16
|
+
/** Assert that the module is instantiated only once. */
|
|
17
|
+
function assertIsSingleModuleInstance(
|
|
18
|
+
// We use the filename (or file path) as key.
|
|
19
|
+
key) {
|
|
20
|
+
const globalObjects = getGlobalObjects();
|
|
21
|
+
(0, assert_js_1.assert)(!(key in globalObjects));
|
|
22
|
+
}
|
|
23
|
+
exports.assertIsSingleModuleInstance = assertIsSingleModuleInstance;
|
|
24
|
+
function getGlobalObjects() {
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
const globalObjects = (globalThis[projectKey] = globalThis[projectKey] || {});
|
|
27
|
+
return globalObjects;
|
|
28
|
+
}
|