vike 0.4.228-commit-4bed128 → 0.4.228-commit-0e9e0f2
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/client/shared/createGetGlobalContext.js +8 -1
- package/dist/cjs/node/plugin/plugins/baseUrls.js +1 -1
- package/dist/cjs/node/plugin/plugins/build/handleAssetsManifest.js +1 -1
- package/dist/cjs/node/plugin/plugins/build/pluginBuildApp.js +1 -1
- package/dist/cjs/node/plugin/plugins/build/pluginBuildConfig.js +3 -10
- package/dist/cjs/node/plugin/plugins/build/pluginBuildEntry.js +1 -4
- package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +1 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +11 -3
- package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +2 -7
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.js → pointerImports.js} +13 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +20 -19
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +14 -10
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -1
- package/dist/cjs/node/plugin/shared/getFilePath.js +2 -2
- package/dist/cjs/node/plugin/shared/resolveClientEntriesDev.js +7 -19
- package/dist/cjs/node/plugin/utils.js +1 -0
- package/dist/cjs/node/prerender/runPrerender.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +11 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +1 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +1 -1
- package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +1 -1
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/cjs/shared/createGlobalContextShared.js +6 -0
- package/dist/cjs/shared/createPageContextShared.js +1 -1
- package/dist/cjs/shared/getPageFiles/fileTypes.js +1 -1
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +3 -7
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/isImportPath.js +21 -0
- package/dist/cjs/utils/objectAssign.js +1 -1
- package/dist/cjs/utils/{isNpmPackage.js → parseNpmPackage.js} +23 -23
- package/dist/cjs/utils/path.js +12 -2
- package/dist/cjs/utils/requireResolve.js +134 -53
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +5 -2
- package/dist/esm/client/client-routing-runtime/globalContext.d.ts +6 -2
- package/dist/esm/client/server-routing-runtime/createPageContextClientSide.d.ts +4 -1
- package/dist/esm/client/server-routing-runtime/globalContext.d.ts +3 -0
- package/dist/esm/client/shared/createGetGlobalContext.d.ts +9 -1
- package/dist/esm/client/shared/createGetGlobalContext.js +8 -1
- package/dist/esm/node/plugin/plugins/baseUrls.js +2 -2
- package/dist/esm/node/plugin/plugins/build/handleAssetsManifest.js +2 -2
- package/dist/esm/node/plugin/plugins/build/pluginBuildApp.js +2 -2
- package/dist/esm/node/plugin/plugins/build/pluginBuildConfig.js +4 -11
- package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.js +2 -5
- package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +2 -2
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/commonConfig.js +12 -4
- package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.js +3 -8
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.d.ts → pointerImports.d.ts} +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.js → pointerImports.js} +14 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +20 -19
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +14 -10
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -1
- package/dist/esm/node/plugin/shared/getFilePath.js +3 -3
- package/dist/esm/node/plugin/shared/resolveClientEntriesDev.js +8 -20
- package/dist/esm/node/plugin/utils.d.ts +1 -0
- package/dist/esm/node/plugin/utils.js +1 -0
- package/dist/esm/node/prerender/runPrerender.d.ts +16 -2
- package/dist/esm/node/prerender/runPrerender.js +2 -2
- package/dist/esm/node/runtime/globalContext.d.ts +32 -2
- package/dist/esm/node/runtime/globalContext.js +11 -1
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +8 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +1 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +16 -2
- package/dist/esm/node/runtime/renderPage.d.ts +8 -1
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/esm/shared/createGlobalContextShared.d.ts +13 -1
- package/dist/esm/shared/createGlobalContextShared.js +6 -0
- package/dist/esm/shared/createPageContextShared.d.ts +1 -1
- package/dist/esm/shared/createPageContextShared.js +1 -1
- package/dist/esm/shared/getPageFiles/fileTypes.js +1 -1
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +3 -7
- package/dist/esm/shared/types.d.ts +8 -2
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/isImportPath.d.ts +4 -0
- package/dist/esm/utils/isImportPath.js +19 -0
- package/dist/esm/utils/objectAssign.js +1 -1
- package/dist/esm/utils/parseNpmPackage.d.ts +17 -0
- package/dist/esm/utils/{isNpmPackage.js → parseNpmPackage.js} +23 -23
- package/dist/esm/utils/path.d.ts +1 -1
- package/dist/esm/utils/path.js +12 -2
- package/dist/esm/utils/requireResolve.d.ts +20 -7
- package/dist/esm/utils/requireResolve.js +134 -53
- package/package.json +3 -3
- package/dist/esm/utils/isNpmPackage.d.ts +0 -17
|
@@ -25,7 +25,7 @@ function determineFileType(filePath) {
|
|
|
25
25
|
const isCSS = filePath.endsWith('.css');
|
|
26
26
|
if (isCSS) {
|
|
27
27
|
/* This assert() is skipped to reduce client-side bundle size
|
|
28
|
-
assert(
|
|
28
|
+
assert(isImportPathNpmPackage(filePath), filePath) // `.css` page files are only supported for npm packages
|
|
29
29
|
*/
|
|
30
30
|
return '.css';
|
|
31
31
|
}
|
|
@@ -8,7 +8,7 @@ exports.getConfigValuesBase = getConfigValuesBase;
|
|
|
8
8
|
exports.isJsonValue = isJsonValue;
|
|
9
9
|
const assertSetup_js_1 = require("../../../utils/assertSetup.js");
|
|
10
10
|
const utils_js_1 = require("../../../node/plugin/utils.js");
|
|
11
|
-
const
|
|
11
|
+
const pointerImports_js_1 = require("../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/pointerImports.js");
|
|
12
12
|
const helpers_js_1 = require("../helpers.js");
|
|
13
13
|
const stringify_1 = require("@brillout/json-serializer/stringify");
|
|
14
14
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
@@ -134,7 +134,7 @@ function valueToJson(value, configName, definedAtData, importStatements, filesEn
|
|
|
134
134
|
// - https://github.com/vikejs/vike-react/pull/113
|
|
135
135
|
replacer(_, value) {
|
|
136
136
|
if (typeof value === 'string') {
|
|
137
|
-
const importData = (0,
|
|
137
|
+
const importData = (0, pointerImports_js_1.parsePointerImportData)(value);
|
|
138
138
|
if (importData) {
|
|
139
139
|
const { importName } = addImportStatement(importStatements, importData.importPath, importData.exportName, filesEnv, configEnv, configName);
|
|
140
140
|
const replacement = [REPLACE_ME_BEFORE, importName, REPLACE_ME_AFTER].join('');
|
|
@@ -269,10 +269,10 @@ function addImportStatement(importStatements, importPath, exportName, filesEnv,
|
|
|
269
269
|
return { importName };
|
|
270
270
|
}
|
|
271
271
|
function assertFileEnv(importPath, configEnv, configName, filesEnv) {
|
|
272
|
+
(0, utils_js_1.assert)(!(0, utils_js_1.isImportPathRelative)(importPath));
|
|
272
273
|
const key = importPath;
|
|
273
274
|
(0, utils_js_1.assert)(key);
|
|
274
275
|
(0, utils_js_1.assertPosixPath)(key);
|
|
275
|
-
(0, utils_js_1.assert)(!isRelativeImportPath(key));
|
|
276
276
|
if (!filesEnv.has(key)) {
|
|
277
277
|
filesEnv.set(key, []);
|
|
278
278
|
}
|
|
@@ -288,7 +288,3 @@ function assertFileEnv(importPath, configEnv, configName, filesEnv) {
|
|
|
288
288
|
].join('\n'));
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
|
-
// TODO/now dedupe
|
|
292
|
-
function isRelativeImportPath(importPath) {
|
|
293
|
-
return importPath.startsWith('./') || importPath.startsWith('../');
|
|
294
|
-
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isImportPath = isImportPath;
|
|
4
|
+
exports.isImportPathRelative = isImportPathRelative;
|
|
5
|
+
const path_js_1 = require("./path.js");
|
|
6
|
+
const assert_js_1 = require("./assert.js");
|
|
7
|
+
const parseNpmPackage_js_1 = require("./parseNpmPackage.js");
|
|
8
|
+
function isImportPath(importPath) {
|
|
9
|
+
return isImportPathRelative(importPath) || (0, parseNpmPackage_js_1.isImportPathNpmPackageOrPathAlias)(importPath);
|
|
10
|
+
}
|
|
11
|
+
// See also `import { pathIsRelative } from './path'`
|
|
12
|
+
function isImportPathRelative(importPath) {
|
|
13
|
+
(0, path_js_1.assertPosixPath)(importPath);
|
|
14
|
+
if (importPath.startsWith('./') || importPath.startsWith('../')) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
(0, assert_js_1.assert)(!importPath.startsWith('.'));
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -9,6 +9,6 @@ function objectAssign(obj, objAddendum, objAddendumCanBePageContextObject) {
|
|
|
9
9
|
if (!objAddendum)
|
|
10
10
|
return;
|
|
11
11
|
if (!objAddendumCanBePageContextObject)
|
|
12
|
-
(0, assert_js_1.assert)(!('
|
|
12
|
+
(0, assert_js_1.assert)(!('isPageContext' in objAddendum));
|
|
13
13
|
Object.defineProperties(obj, Object.getOwnPropertyDescriptors(objAddendum));
|
|
14
14
|
}
|
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
3
|
+
exports.isImportPathNpmPackage = isImportPathNpmPackage;
|
|
4
|
+
exports.isImportPathNpmPackageOrPathAlias = isImportPathNpmPackageOrPathAlias;
|
|
5
|
+
exports.assertIsImportPathNpmPackage = assertIsImportPathNpmPackage;
|
|
6
|
+
exports.isPathAliasRecommended = isPathAliasRecommended;
|
|
7
|
+
exports.parseNpmPackage = parseNpmPackage;
|
|
8
8
|
exports.isDistinguishable = isDistinguishable;
|
|
9
9
|
const assert_js_1 = require("./assert.js");
|
|
10
10
|
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
11
11
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
12
|
-
function
|
|
12
|
+
function isImportPathNpmPackage(str, { cannotBePathAlias }) {
|
|
13
13
|
(0, assert_js_1.assert)(cannotBePathAlias);
|
|
14
|
-
return
|
|
14
|
+
return isImportPathNpmPackageOrPathAlias(str);
|
|
15
15
|
}
|
|
16
16
|
// We cannot distinguish path aliases that look like npm package imports
|
|
17
|
-
function
|
|
18
|
-
const res =
|
|
17
|
+
function isImportPathNpmPackageOrPathAlias(str) {
|
|
18
|
+
const res = parseNpmPackage(str);
|
|
19
19
|
return res !== null;
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
(0, assert_js_1.assert)(
|
|
23
|
-
// If `str` is a path alias that looks like an npm package =>
|
|
21
|
+
function assertIsImportPathNpmPackage(str) {
|
|
22
|
+
(0, assert_js_1.assert)(isImportPathNpmPackage(str, {
|
|
23
|
+
// If `str` is a path alias that looks like an npm package => assertIsImportPathNpmPackage() is erroneous but that's okay because the assertion will eventually fail for some other user using a disambiguated path alias.
|
|
24
24
|
cannotBePathAlias: true
|
|
25
25
|
}), str);
|
|
26
26
|
}
|
|
27
27
|
function isNpmPackageName(str) {
|
|
28
|
-
const res =
|
|
28
|
+
const res = parseNpmPackage(str);
|
|
29
29
|
return res !== null && res.importPath === null;
|
|
30
30
|
}
|
|
31
31
|
function getNpmPackageName(str) {
|
|
32
|
-
const res =
|
|
32
|
+
const res = parseNpmPackage(str);
|
|
33
33
|
if (!res)
|
|
34
34
|
return null;
|
|
35
35
|
return res.pkgName;
|
|
36
36
|
}
|
|
37
37
|
function getNpmPackageImportPath(str) {
|
|
38
|
-
const res =
|
|
38
|
+
const res = parseNpmPackage(str);
|
|
39
39
|
if (!res)
|
|
40
40
|
return null;
|
|
41
41
|
return res.importPath;
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function isPathAliasRecommended(alias) {
|
|
44
44
|
// Cannot be distinguished from npm package names
|
|
45
45
|
if (!isDistinguishable(alias))
|
|
46
46
|
return false;
|
|
@@ -56,14 +56,14 @@ function isValidPathAlias(alias) {
|
|
|
56
56
|
return true;
|
|
57
57
|
}
|
|
58
58
|
function isDistinguishable(alias) {
|
|
59
|
-
return (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
return (parseNpmPackage(alias) === null &&
|
|
60
|
+
parseNpmPackage(`${alias}fake-path`) === null &&
|
|
61
|
+
parseNpmPackage(`${alias}/fake-path`) === null &&
|
|
62
|
+
parseNpmPackage(`${alias}fake/deep/path`) === null &&
|
|
63
|
+
parseNpmPackage(`${alias}/fake/deep/path`) === null &&
|
|
64
64
|
// See note about '-' in ./isNpmPackageName.spec.ts
|
|
65
65
|
// ```ts
|
|
66
|
-
// expect(
|
|
66
|
+
// expect(parseNpmPackage('-')).toBe(null) // actually wrong: https://www.npmjs.com/package/-
|
|
67
67
|
// ```
|
|
68
68
|
!alias.startsWith('-'));
|
|
69
69
|
}
|
|
@@ -71,7 +71,7 @@ function isDistinguishable(alias) {
|
|
|
71
71
|
// - https://www.npmjs.com/package/-
|
|
72
72
|
// The correct logic is complex, see https://github.com/npm/validate-npm-package-name
|
|
73
73
|
// We don't need to be accurate: are there npm packages with weird names that are actually being used?
|
|
74
|
-
function
|
|
74
|
+
function parseNpmPackage(str) {
|
|
75
75
|
if (!str)
|
|
76
76
|
return null;
|
|
77
77
|
let scope = null;
|
package/dist/cjs/utils/path.js
CHANGED
|
@@ -44,6 +44,16 @@ function assertPosixPath(path) {
|
|
|
44
44
|
(0, assert_js_1.assert)(path);
|
|
45
45
|
(0, assert_js_1.assert)(!path.includes('\\'), errMsg(path));
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
// See also `import { isImportPathRelative } from './isImportPath.js'`
|
|
48
|
+
function pathIsRelative(path) {
|
|
49
|
+
assertPosixPath(path);
|
|
50
|
+
if (path.startsWith('./') || path.startsWith('../')) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
/* Not true if `path` starts with a hidden directory (i.e. a directory with a name that starts with `.`)
|
|
55
|
+
assert(!path.startsWith('.'))
|
|
56
|
+
*/
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
49
59
|
}
|
|
@@ -3,10 +3,11 @@ 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.requireResolve = requireResolve;
|
|
7
6
|
exports.requireResolveOptional = requireResolveOptional;
|
|
8
|
-
exports.
|
|
9
|
-
exports.
|
|
7
|
+
exports.requireResolveOptionalDir = requireResolveOptionalDir;
|
|
8
|
+
exports.requireResolveNpmPackage = requireResolveNpmPackage;
|
|
9
|
+
exports.requireResolveVikeDistFile = requireResolveVikeDistFile;
|
|
10
|
+
exports.getVikeNodeModulesRoot = getVikeNodeModulesRoot;
|
|
10
11
|
const assert_js_1 = require("./assert.js");
|
|
11
12
|
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
12
13
|
const assertSetup_js_1 = require("./assertSetup.js");
|
|
@@ -14,68 +15,118 @@ const path_js_1 = require("./path.js");
|
|
|
14
15
|
const isScriptFile_js_1 = require("./isScriptFile.js");
|
|
15
16
|
const node_module_1 = require("node:module");
|
|
16
17
|
const node_path_1 = __importDefault(require("node:path"));
|
|
18
|
+
const parseNpmPackage_js_1 = require("./parseNpmPackage.js");
|
|
19
|
+
const isNullish_js_1 = require("./isNullish.js");
|
|
17
20
|
// @ts-ignore `file:///${__filename.split('\\').join('/')}` is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
18
21
|
const importMetaUrl = `file:///${__filename.split('\\').join('/')}`;
|
|
19
|
-
|
|
22
|
+
(0, path_js_1.assertPosixPath)(importMetaUrl);
|
|
20
23
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
21
24
|
(0, assertSetup_js_1.assertIsNotProductionRuntime)();
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
// - We still can't use import.meta.resolve() as of 23.1.0 (November 2024) because `parent` argument requires an experimental flag.
|
|
26
|
+
// - https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment139581675_62272600
|
|
27
|
+
// - Passing context to createRequire(context) isn't equivalent to passing it to the `paths` argument of require.resolve()
|
|
28
|
+
// - https://github.com/brillout/require-test
|
|
29
|
+
// - In practice, I guess it doesn't make a difference? It just seems to be small Node.js weirdness.
|
|
30
|
+
// - The argument createRequire(argument) seems to be overriden by the `paths` argument require.resolve()
|
|
31
|
+
// - For example, passing an empty array to `paths` kills the argument passed to `createRequire()`
|
|
32
|
+
// - Thus, when `paths` is defined, then the context needs to be passed to both createRequire() as well as the `paths` argument of require.resolve()
|
|
33
|
+
function requireResolve_(importPath, importerFilePath, { userRootDir, doNotHandleFileExtension } = {}) {
|
|
24
34
|
(0, path_js_1.assertPosixPath)(importPath);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
const contexts = importerFilePath
|
|
36
|
+
? [importerFilePath]
|
|
37
|
+
: [userRootDir ? getFakeImporterFile(userRootDir) : importMetaUrl];
|
|
38
|
+
addExtraContextForNpmPackageImport(contexts, { importPath, userRootDir });
|
|
39
|
+
let importPathResolvedFilePath;
|
|
40
|
+
let failure;
|
|
41
|
+
for (const context of contexts) {
|
|
42
|
+
(0, path_js_1.assertPosixPath)(context);
|
|
43
|
+
const require_ = (0, node_module_1.createRequire)(ensureFilePrefix(context));
|
|
44
|
+
if (!doNotHandleFileExtension) {
|
|
45
|
+
addFileExtensionsToRequireResolve(require_);
|
|
46
|
+
importPath = removeFileExtention(importPath);
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
importPathResolvedFilePath = require_.resolve(importPath);
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
/* DEBUG
|
|
53
|
+
console.log('err', err)
|
|
54
|
+
console.log('importPath', importPath)
|
|
55
|
+
console.log('importerFilePath', importerFilePath)
|
|
56
|
+
console.log('context', context)
|
|
57
|
+
console.log('importMetaUrl', importMetaUrl)
|
|
58
|
+
console.log('paths', paths)
|
|
59
|
+
//*/
|
|
60
|
+
failure ?? (failure = { err });
|
|
61
|
+
}
|
|
62
|
+
if (importPathResolvedFilePath)
|
|
63
|
+
break;
|
|
30
64
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// - https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment139581675_62272600
|
|
35
|
-
importedFile = require_.resolve(importPath, { paths: [cwd] });
|
|
65
|
+
if (!importPathResolvedFilePath) {
|
|
66
|
+
(0, assert_js_1.assert)(failure);
|
|
67
|
+
return { importPathResolvedFilePath: undefined, err: failure.err, hasFailed: true };
|
|
36
68
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
69
|
+
else {
|
|
70
|
+
(0, assert_js_1.assert)(importPathResolvedFilePath);
|
|
71
|
+
importPathResolvedFilePath = (0, path_js_1.toPosixPath)(importPathResolvedFilePath);
|
|
72
|
+
return { importPathResolvedFilePath, err: undefined, hasFailed: false };
|
|
40
73
|
}
|
|
41
|
-
clean();
|
|
42
|
-
importedFile = (0, path_js_1.toPosixPath)(importedFile);
|
|
43
|
-
return { importedFile, err: undefined, hasFailed: false };
|
|
44
74
|
}
|
|
45
|
-
function requireResolveOptional(importPath,
|
|
46
|
-
const res = requireResolve_(importPath,
|
|
75
|
+
function requireResolveOptional({ importPath, importerFilePath, userRootDir }) {
|
|
76
|
+
const res = requireResolve_(importPath, importerFilePath, { userRootDir });
|
|
47
77
|
if (res.hasFailed)
|
|
48
78
|
return null;
|
|
49
|
-
return res.
|
|
79
|
+
return res.importPathResolvedFilePath;
|
|
50
80
|
}
|
|
51
|
-
function
|
|
52
|
-
const
|
|
81
|
+
function requireResolveOptionalDir({ importPath, importerDir, userRootDir }) {
|
|
82
|
+
const importerFilePath = getFakeImporterFile(importerDir);
|
|
83
|
+
const res = requireResolve_(importPath, importerFilePath, { userRootDir });
|
|
53
84
|
if (res.hasFailed)
|
|
54
85
|
return null;
|
|
55
|
-
return res.
|
|
56
|
-
}
|
|
57
|
-
function requireResolveNonUserFile(importPath, cwd) {
|
|
58
|
-
const res = requireResolve_(importPath, cwd, { doNotHandleFileExtension: true });
|
|
59
|
-
if (res.hasFailed)
|
|
60
|
-
throw res.err;
|
|
61
|
-
return res.importedFile;
|
|
86
|
+
return res.importPathResolvedFilePath;
|
|
62
87
|
}
|
|
63
|
-
function
|
|
64
|
-
|
|
88
|
+
function requireResolveNpmPackage({ importPathNpmPackage, userRootDir }) {
|
|
89
|
+
(0, parseNpmPackage_js_1.assertIsImportPathNpmPackage)(importPathNpmPackage);
|
|
90
|
+
const importerFilePath = getFakeImporterFile(userRootDir);
|
|
91
|
+
const res = requireResolve_(importPathNpmPackage, importerFilePath, { userRootDir });
|
|
65
92
|
if (res.hasFailed)
|
|
66
93
|
throw res.err;
|
|
67
|
-
return res.
|
|
94
|
+
return res.importPathResolvedFilePath;
|
|
68
95
|
}
|
|
69
|
-
function
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
96
|
+
function requireResolveVikeDistFile(vikeDistFile) {
|
|
97
|
+
const vikeNodeModulesRoot = getVikeNodeModulesRoot();
|
|
98
|
+
(0, path_js_1.assertPosixPath)(vikeNodeModulesRoot);
|
|
99
|
+
(0, path_js_1.assertPosixPath)(vikeDistFile);
|
|
100
|
+
const importPathResolvedFilePath = node_path_1.default.posix.join(vikeNodeModulesRoot, vikeDistFile);
|
|
101
|
+
// Double check
|
|
102
|
+
{
|
|
103
|
+
const res = requireResolve_(importPathResolvedFilePath,
|
|
104
|
+
// No context needed: importPathResolvedFilePath is already resolved and absolute
|
|
105
|
+
null, { doNotHandleFileExtension: true });
|
|
106
|
+
if (res.hasFailed)
|
|
107
|
+
throw res.err;
|
|
108
|
+
(0, assert_js_1.assert)(res.importPathResolvedFilePath === importPathResolvedFilePath);
|
|
76
109
|
}
|
|
77
|
-
|
|
78
|
-
|
|
110
|
+
return importPathResolvedFilePath;
|
|
111
|
+
}
|
|
112
|
+
function addExtraContextForNpmPackageImport(contexts, { importPath, userRootDir }) {
|
|
113
|
+
// We should add extra context only for npm packages, but unfortunately we cannot always disambiguate between npm package imports and path aliases.
|
|
114
|
+
if (!(0, parseNpmPackage_js_1.isImportPathNpmPackageOrPathAlias)(importPath))
|
|
115
|
+
return;
|
|
116
|
+
const userRootDirFakeFile = userRootDir && getFakeImporterFile(userRootDir);
|
|
117
|
+
[
|
|
118
|
+
// Workaround for monorepo resolve issue: https://github.com/vikejs/vike-react/pull/161/commits/dbaa6643e78015ac2797c237552800fef29b72a7
|
|
119
|
+
userRootDirFakeFile,
|
|
120
|
+
// I can't think of a use case where this would be needed, but let's add one extra last chance to sucessfully resolve some complex monorepo setups
|
|
121
|
+
importMetaUrl
|
|
122
|
+
]
|
|
123
|
+
.filter(isNullish_js_1.isNotNullish)
|
|
124
|
+
.forEach((context) => {
|
|
125
|
+
const alreadyHasContext = contexts.includes(context) || contexts.includes(ensureFilePrefix(context));
|
|
126
|
+
if (alreadyHasContext)
|
|
127
|
+
return;
|
|
128
|
+
contexts.push(context);
|
|
129
|
+
});
|
|
79
130
|
}
|
|
80
131
|
function removeFileExtention(importPath) {
|
|
81
132
|
// Skip for Bun: https://github.com/vikejs/vike/issues/2204
|
|
@@ -93,7 +144,7 @@ function removeFileExtention(importPath) {
|
|
|
93
144
|
}
|
|
94
145
|
return importPath;
|
|
95
146
|
}
|
|
96
|
-
function addFileExtensionsToRequireResolve() {
|
|
147
|
+
function addFileExtensionsToRequireResolve(require_) {
|
|
97
148
|
const added = [];
|
|
98
149
|
isScriptFile_js_1.scriptFileExtensionList.forEach((ext) => {
|
|
99
150
|
(0, assert_js_1.assert)(!ext.includes('.'));
|
|
@@ -103,10 +154,40 @@ function addFileExtensionsToRequireResolve() {
|
|
|
103
154
|
added.push(ext);
|
|
104
155
|
}
|
|
105
156
|
});
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return
|
|
157
|
+
}
|
|
158
|
+
function getVikeNodeModulesRoot() {
|
|
159
|
+
// [RELATIVE_PATH_FROM_DIST] Current file: vike/dist/esm/utils/requireResolve.js
|
|
160
|
+
(0, assert_js_1.assert)(importMetaUrl.includes('/dist/esm/') || importMetaUrl.includes('/dist/cjs/'));
|
|
161
|
+
const vikeNodeModulesRoot = node_path_1.default.posix.join(removeFilePrefix(importMetaUrl), '../../../../');
|
|
162
|
+
return vikeNodeModulesRoot;
|
|
163
|
+
}
|
|
164
|
+
function getFakeImporterFile(dirPath) {
|
|
165
|
+
(0, path_js_1.assertPosixPath)(dirPath);
|
|
166
|
+
(0, assert_js_1.assert)(!dirPath.startsWith('file')); // The file:// prefix is bogus when used with path.posix.join()
|
|
167
|
+
const importerFilePath = node_path_1.default.posix.join(dirPath, 'fakeFileForNodeResolve.js');
|
|
168
|
+
return importerFilePath;
|
|
169
|
+
}
|
|
170
|
+
function ensureFilePrefix(filePath) {
|
|
171
|
+
(0, path_js_1.assertPosixPath)(filePath);
|
|
172
|
+
const filePrefix = getFilePrefix();
|
|
173
|
+
if (!filePath.startsWith(filePrefix)) {
|
|
174
|
+
(0, assert_js_1.assert)(!filePath.startsWith('file'));
|
|
175
|
+
filePath = filePrefix + filePath;
|
|
176
|
+
}
|
|
177
|
+
(0, assert_js_1.assert)(filePath.startsWith(filePrefix));
|
|
178
|
+
return filePath;
|
|
179
|
+
}
|
|
180
|
+
function removeFilePrefix(filePath) {
|
|
181
|
+
const filePrefix = getFilePrefix();
|
|
182
|
+
if (filePath.startsWith(filePrefix)) {
|
|
183
|
+
filePath = filePath.slice(filePrefix.length);
|
|
184
|
+
}
|
|
185
|
+
(0, assert_js_1.assert)(!filePath.startsWith('file'));
|
|
186
|
+
return filePath;
|
|
187
|
+
}
|
|
188
|
+
function getFilePrefix() {
|
|
189
|
+
let prefix = 'file://';
|
|
190
|
+
if (process.platform === 'win32')
|
|
191
|
+
prefix += '/';
|
|
192
|
+
return prefix;
|
|
112
193
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { createPageContextClientSide };
|
|
2
2
|
declare function createPageContextClientSide(urlOriginal: string): Promise<{
|
|
3
3
|
globalContext: {
|
|
4
|
+
isGlobalContext: true;
|
|
4
5
|
_virtualFileExports: unknown;
|
|
5
6
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
6
7
|
_pageConfigs: import("../../__internal/index.js").PageConfig[];
|
|
@@ -8,7 +9,9 @@ declare function createPageContextClientSide(urlOriginal: string): Promise<{
|
|
|
8
9
|
_allPageIds: string[];
|
|
9
10
|
config: import("../../types/index.js").ConfigResolved;
|
|
10
11
|
pages: import("../../shared/page-configs/getPageConfigUserFriendly.js").PageConfigsUserFriendly;
|
|
11
|
-
} &
|
|
12
|
+
} & {
|
|
13
|
+
isClientSide: true;
|
|
14
|
+
} & {
|
|
12
15
|
_pageRoutes: import("../../__internal/index.js").PageRoutes;
|
|
13
16
|
_onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
14
17
|
};
|
|
@@ -33,5 +36,5 @@ declare function createPageContextClientSide(urlOriginal: string): Promise<{
|
|
|
33
36
|
_source: import("../../shared/page-configs/getPageConfigUserFriendly.js").Source;
|
|
34
37
|
_sources: import("../../shared/page-configs/getPageConfigUserFriendly.js").Sources;
|
|
35
38
|
_from: import("../../shared/page-configs/getPageConfigUserFriendly.js").From;
|
|
36
|
-
|
|
39
|
+
isPageContext: true;
|
|
37
40
|
}>;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export { getGlobalContext };
|
|
2
2
|
export type { GlobalContextClient };
|
|
3
3
|
import type { GlobalContextSharedPublic } from '../../shared/createGlobalContextShared.js';
|
|
4
|
-
type GlobalContextClient = GlobalContextSharedPublic & Vike.GlobalContext & Vike.GlobalContextClient & {};
|
|
4
|
+
type GlobalContextClient = GlobalContextSharedPublic & Pick<GlobalContextClientInternal, 'isClientSide'> & Vike.GlobalContext & Vike.GlobalContextClient & {};
|
|
5
|
+
type GlobalContextClientInternal = Awaited<ReturnType<typeof getGlobalContext>>;
|
|
5
6
|
declare const getGlobalContext: () => Promise<{
|
|
7
|
+
isGlobalContext: true;
|
|
6
8
|
_virtualFileExports: unknown;
|
|
7
9
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
8
10
|
_pageConfigs: import("../../__internal/index.js").PageConfig[];
|
|
@@ -10,7 +12,9 @@ declare const getGlobalContext: () => Promise<{
|
|
|
10
12
|
_allPageIds: string[];
|
|
11
13
|
config: import("../../types/index.js").ConfigResolved;
|
|
12
14
|
pages: import("../../shared/page-configs/getPageConfigUserFriendly.js").PageConfigsUserFriendly;
|
|
13
|
-
} &
|
|
15
|
+
} & {
|
|
16
|
+
isClientSide: true;
|
|
17
|
+
} & {
|
|
14
18
|
_pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
|
|
15
19
|
_onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
16
20
|
}>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { createPageContextClientSide };
|
|
2
2
|
declare function createPageContextClientSide(): Promise<{
|
|
3
3
|
globalContext: {
|
|
4
|
+
isGlobalContext: true;
|
|
4
5
|
_virtualFileExports: unknown;
|
|
5
6
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
6
7
|
_pageConfigs: import("../../__internal/index.js").PageConfig[];
|
|
@@ -8,6 +9,8 @@ declare function createPageContextClientSide(): Promise<{
|
|
|
8
9
|
_allPageIds: string[];
|
|
9
10
|
config: import("../../types/index.js").ConfigResolved;
|
|
10
11
|
pages: import("../../shared/page-configs/getPageConfigUserFriendly.js").PageConfigsUserFriendly;
|
|
12
|
+
} & {
|
|
13
|
+
isClientSide: true;
|
|
11
14
|
} & object;
|
|
12
15
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
13
16
|
_pageConfigs: import("../../__internal/index.js").PageConfig[];
|
|
@@ -29,5 +32,5 @@ declare function createPageContextClientSide(): Promise<{
|
|
|
29
32
|
_source: import("../../shared/page-configs/getPageConfigUserFriendly.js").Source;
|
|
30
33
|
_sources: import("../../shared/page-configs/getPageConfigUserFriendly.js").Sources;
|
|
31
34
|
_from: import("../../shared/page-configs/getPageConfigUserFriendly.js").From;
|
|
32
|
-
|
|
35
|
+
isPageContext: true;
|
|
33
36
|
}>;
|
|
@@ -3,6 +3,7 @@ export type { GlobalContextClientWithServerRouting };
|
|
|
3
3
|
import type { GlobalContextSharedPublic } from '../../shared/createGlobalContextShared.js';
|
|
4
4
|
type GlobalContextClientWithServerRouting = GlobalContextSharedPublic & Vike.GlobalContext & Vike.GlobalContextClient & {};
|
|
5
5
|
declare const getGlobalContext: () => Promise<{
|
|
6
|
+
isGlobalContext: true;
|
|
6
7
|
_virtualFileExports: unknown;
|
|
7
8
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
8
9
|
_pageConfigs: import("../../__internal/index.js").PageConfig[];
|
|
@@ -10,4 +11,6 @@ declare const getGlobalContext: () => Promise<{
|
|
|
10
11
|
_allPageIds: string[];
|
|
11
12
|
config: import("../../types/index.js").ConfigResolved;
|
|
12
13
|
pages: import("../../shared/page-configs/getPageConfigUserFriendly.js").PageConfigsUserFriendly;
|
|
14
|
+
} & {
|
|
15
|
+
isClientSide: true;
|
|
13
16
|
} & object>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { createGetGlobalContext };
|
|
2
2
|
import { type GlobalContextShared } from '../../shared/createGlobalContextShared.js';
|
|
3
3
|
declare function createGetGlobalContext<GlobalContextAddendum extends object>(virtualFileExports: unknown, isClientRouting: boolean, addGlobalContext?: (globalContext: GlobalContextShared) => Promise<GlobalContextAddendum>): () => Promise<{
|
|
4
|
+
isGlobalContext: true;
|
|
4
5
|
_virtualFileExports: unknown;
|
|
5
6
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
6
7
|
_pageConfigs: import("../../__internal/index.js").PageConfig[];
|
|
@@ -8,4 +9,11 @@ declare function createGetGlobalContext<GlobalContextAddendum extends object>(vi
|
|
|
8
9
|
_allPageIds: string[];
|
|
9
10
|
config: import("../../types/index.js").ConfigResolved;
|
|
10
11
|
pages: import("../../shared/page-configs/getPageConfigUserFriendly.js").PageConfigsUserFriendly;
|
|
11
|
-
} & Awaited<
|
|
12
|
+
} & Awaited<{
|
|
13
|
+
/**
|
|
14
|
+
* Whether the environment is client-side or server-side / pre-rendering.
|
|
15
|
+
*
|
|
16
|
+
* We recommend using `import.meta.env.SSR` instead, see https://vike.dev/globalContext
|
|
17
|
+
*/
|
|
18
|
+
isClientSide: true;
|
|
19
|
+
} & Awaited<GlobalContextAddendum>>>;
|
|
@@ -18,7 +18,14 @@ function createGetGlobalContext(virtualFileExports, isClientRouting, addGlobalCo
|
|
|
18
18
|
}
|
|
19
19
|
// Create
|
|
20
20
|
const globalContext = await createGlobalContextShared(virtualFileExports, globalObject, async (globalContext) => {
|
|
21
|
-
const globalContextAddendum = {
|
|
21
|
+
const globalContextAddendum = {
|
|
22
|
+
/**
|
|
23
|
+
* Whether the environment is client-side or server-side / pre-rendering.
|
|
24
|
+
*
|
|
25
|
+
* We recommend using `import.meta.env.SSR` instead, see https://vike.dev/globalContext
|
|
26
|
+
*/
|
|
27
|
+
isClientSide: true
|
|
28
|
+
};
|
|
22
29
|
objectAssign(globalContextAddendum, getGlobalContextSerializedInHtml());
|
|
23
30
|
objectAssign(globalContextAddendum, await addGlobalContext?.(globalContext));
|
|
24
31
|
return globalContextAddendum;
|
|
@@ -2,7 +2,7 @@ export { baseUrls };
|
|
|
2
2
|
import { resolveBase } from '../../shared/resolveBase.js';
|
|
3
3
|
import { assert } from '../utils.js';
|
|
4
4
|
import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
|
|
5
|
-
import {
|
|
5
|
+
import { getVikeConfigInternal } from './commonConfig.js';
|
|
6
6
|
function baseUrls() {
|
|
7
7
|
let basesResolved;
|
|
8
8
|
return {
|
|
@@ -12,7 +12,7 @@ function baseUrls() {
|
|
|
12
12
|
const isDev = config._isDev;
|
|
13
13
|
assert(typeof isDev === 'boolean');
|
|
14
14
|
const baseViteOriginal = config.base ?? '/__UNSET__'; // '/__UNSET__' because Vite resolves `_baseViteOriginal: null` to `undefined`
|
|
15
|
-
const vike =
|
|
15
|
+
const vike = getVikeConfigInternal(config);
|
|
16
16
|
basesResolved = resolveBase(baseViteOriginal, vike.config.baseServer ?? null, vike.config.baseAssets ?? null);
|
|
17
17
|
// We cannot define these in configResolved() because Vite picks up the env variables before any configResolved() hook is called
|
|
18
18
|
process.env.BASE_SERVER = basesResolved.baseServer;
|
|
@@ -15,7 +15,7 @@ import pc from '@brillout/picocolors';
|
|
|
15
15
|
import { isV1Design } from '../importUserCode/v1-design/getVikeConfig.js';
|
|
16
16
|
import { getOutDirs } from '../../shared/getOutDirs.js';
|
|
17
17
|
import { isViteServerBuild_onlySsrEnv, isViteServerBuild } from '../../shared/isViteServerBuild.js';
|
|
18
|
-
import {
|
|
18
|
+
import { getVikeConfigInternal } from '../commonConfig.js';
|
|
19
19
|
import { set_macro_ASSETS_MANIFEST } from './pluginBuildEntry.js';
|
|
20
20
|
assertIsSingleModuleInstance('build/handleAssetsManifest.ts');
|
|
21
21
|
let assetsJsonFilePath;
|
|
@@ -281,7 +281,7 @@ async function writeManifestFile(manifest, manifestFilePath) {
|
|
|
281
281
|
await fs.writeFile(manifestFilePath, manifestFileContent, 'utf-8');
|
|
282
282
|
}
|
|
283
283
|
function handleAssetsManifest_getBuildConfig(config) {
|
|
284
|
-
const vike =
|
|
284
|
+
const vike = getVikeConfigInternal(config);
|
|
285
285
|
const isFixEnabled = handleAssetsManifest_isFixEnabled(config);
|
|
286
286
|
return {
|
|
287
287
|
// https://github.com/vikejs/vike/issues/1339
|
|
@@ -2,7 +2,7 @@ export { pluginBuildApp };
|
|
|
2
2
|
import { runPrerender_forceExit } from '../../../prerender/runPrerender.js';
|
|
3
3
|
import { resolveOutDir } from '../../shared/getOutDirs.js';
|
|
4
4
|
import { assert } from '../../utils.js';
|
|
5
|
-
import {
|
|
5
|
+
import { getVikeConfigInternal } from '../commonConfig.js';
|
|
6
6
|
import { isPrerenderForceExit } from './pluginAutoFullBuild.js';
|
|
7
7
|
function pluginBuildApp() {
|
|
8
8
|
return [
|
|
@@ -10,7 +10,7 @@ function pluginBuildApp() {
|
|
|
10
10
|
name: 'vike:build:pluginBuildApp',
|
|
11
11
|
apply: 'build',
|
|
12
12
|
config(config) {
|
|
13
|
-
const vike =
|
|
13
|
+
const vike = getVikeConfigInternal(config);
|
|
14
14
|
if (!vike.config.vite6BuilderApp)
|
|
15
15
|
return;
|
|
16
16
|
return {
|