vike 0.4.228-commit-84954ae → 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/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +11 -1
- package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.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/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/objectAssign.js +1 -1
- package/dist/cjs/utils/requireResolve.js +85 -63
- 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/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +1 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +16 -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/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/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/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/objectAssign.js +1 -1
- package/dist/esm/utils/requireResolve.d.ts +2 -2
- package/dist/esm/utils/requireResolve.js +85 -63
- package/package.json +3 -3
|
@@ -11,93 +11,117 @@ import { scriptFileExtensionList } from './isScriptFile.js';
|
|
|
11
11
|
import { createRequire } from 'node:module';
|
|
12
12
|
import path from 'node:path';
|
|
13
13
|
import { assertIsImportPathNpmPackage, isImportPathNpmPackageOrPathAlias } from './parseNpmPackage.js';
|
|
14
|
+
import { isNotNullish } from './isNullish.js';
|
|
14
15
|
// @ts-ignore import.meta.url is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
15
16
|
const importMetaUrl = import.meta.url;
|
|
17
|
+
assertPosixPath(importMetaUrl);
|
|
16
18
|
assertIsNotBrowser();
|
|
17
19
|
assertIsNotProductionRuntime();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
// - We still can't use import.meta.resolve() as of 23.1.0 (November 2024) because `parent` argument requires an experimental flag.
|
|
21
|
+
// - https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment139581675_62272600
|
|
22
|
+
// - Passing context to createRequire(context) isn't equivalent to passing it to the `paths` argument of require.resolve()
|
|
23
|
+
// - https://github.com/brillout/require-test
|
|
24
|
+
// - In practice, I guess it doesn't make a difference? It just seems to be small Node.js weirdness.
|
|
25
|
+
// - The argument createRequire(argument) seems to be overriden by the `paths` argument require.resolve()
|
|
26
|
+
// - For example, passing an empty array to `paths` kills the argument passed to `createRequire()`
|
|
27
|
+
// - Thus, when `paths` is defined, then the context needs to be passed to both createRequire() as well as the `paths` argument of require.resolve()
|
|
28
|
+
function requireResolve_(importPath, importerFilePath, { userRootDir, doNotHandleFileExtension } = {}) {
|
|
20
29
|
assertPosixPath(importPath);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
const contexts = importerFilePath
|
|
31
|
+
? [importerFilePath]
|
|
32
|
+
: [userRootDir ? getFakeImporterFile(userRootDir) : importMetaUrl];
|
|
33
|
+
addExtraContextForNpmPackageImport(contexts, { importPath, userRootDir });
|
|
34
|
+
let importPathResolvedFilePath;
|
|
35
|
+
let failure;
|
|
36
|
+
for (const context of contexts) {
|
|
37
|
+
assertPosixPath(context);
|
|
38
|
+
const require_ = createRequire(ensureFilePrefix(context));
|
|
39
|
+
if (!doNotHandleFileExtension) {
|
|
40
|
+
addFileExtensionsToRequireResolve(require_);
|
|
41
|
+
importPath = removeFileExtention(importPath);
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
importPathResolvedFilePath = require_.resolve(importPath);
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
/* DEBUG
|
|
48
|
+
console.log('err', err)
|
|
49
|
+
console.log('importPath', importPath)
|
|
50
|
+
console.log('importerFilePath', importerFilePath)
|
|
51
|
+
console.log('context', context)
|
|
52
|
+
console.log('importMetaUrl', importMetaUrl)
|
|
53
|
+
console.log('paths', paths)
|
|
54
|
+
//*/
|
|
55
|
+
failure ?? (failure = { err });
|
|
56
|
+
}
|
|
57
|
+
if (importPathResolvedFilePath)
|
|
58
|
+
break;
|
|
28
59
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
:
|
|
32
|
-
// Seems like `importerPath` gets overriden by the `paths` argument, so we add it to `paths`. (For example, passing an empty array to `paths` kills the argument passed to `createRequire()`.)
|
|
33
|
-
toDirPath(importerFile),
|
|
34
|
-
...(options?.paths || [])
|
|
35
|
-
];
|
|
36
|
-
let importedFile;
|
|
37
|
-
try {
|
|
38
|
-
// We still can't use import.meta.resolve() as of 23.1.0 (November 2024) because `parent` argument requires an experimental flag.
|
|
39
|
-
// - https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment139581675_62272600
|
|
40
|
-
importedFile = require_.resolve(importPath, { paths });
|
|
60
|
+
if (!importPathResolvedFilePath) {
|
|
61
|
+
assert(failure);
|
|
62
|
+
return { importPathResolvedFilePath: undefined, err: failure.err, hasFailed: true };
|
|
41
63
|
}
|
|
42
|
-
|
|
43
|
-
|
|
64
|
+
else {
|
|
65
|
+
assert(importPathResolvedFilePath);
|
|
66
|
+
importPathResolvedFilePath = toPosixPath(importPathResolvedFilePath);
|
|
67
|
+
return { importPathResolvedFilePath, err: undefined, hasFailed: false };
|
|
44
68
|
}
|
|
45
|
-
importedFile = toPosixPath(importedFile);
|
|
46
|
-
return { importedFile, err: undefined, hasFailed: false };
|
|
47
69
|
}
|
|
48
|
-
function requireResolveOptional({ importPath,
|
|
49
|
-
const
|
|
50
|
-
const res = requireResolve_(importPath, importerFile, { paths });
|
|
70
|
+
function requireResolveOptional({ importPath, importerFilePath, userRootDir }) {
|
|
71
|
+
const res = requireResolve_(importPath, importerFilePath, { userRootDir });
|
|
51
72
|
if (res.hasFailed)
|
|
52
73
|
return null;
|
|
53
|
-
return res.
|
|
74
|
+
return res.importPathResolvedFilePath;
|
|
54
75
|
}
|
|
55
76
|
function requireResolveOptionalDir({ importPath, importerDir, userRootDir }) {
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const res = requireResolve_(importPath, importerFile, { paths });
|
|
77
|
+
const importerFilePath = getFakeImporterFile(importerDir);
|
|
78
|
+
const res = requireResolve_(importPath, importerFilePath, { userRootDir });
|
|
59
79
|
if (res.hasFailed)
|
|
60
80
|
return null;
|
|
61
|
-
return res.
|
|
81
|
+
return res.importPathResolvedFilePath;
|
|
62
82
|
}
|
|
63
83
|
function requireResolveNpmPackage({ importPathNpmPackage, userRootDir }) {
|
|
64
84
|
assertIsImportPathNpmPackage(importPathNpmPackage);
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const res = requireResolve_(importPathNpmPackage, importerFile, { paths });
|
|
85
|
+
const importerFilePath = getFakeImporterFile(userRootDir);
|
|
86
|
+
const res = requireResolve_(importPathNpmPackage, importerFilePath, { userRootDir });
|
|
68
87
|
if (res.hasFailed)
|
|
69
88
|
throw res.err;
|
|
70
|
-
return res.
|
|
89
|
+
return res.importPathResolvedFilePath;
|
|
71
90
|
}
|
|
72
91
|
function requireResolveVikeDistFile(vikeDistFile) {
|
|
73
92
|
const vikeNodeModulesRoot = getVikeNodeModulesRoot();
|
|
74
93
|
assertPosixPath(vikeNodeModulesRoot);
|
|
75
94
|
assertPosixPath(vikeDistFile);
|
|
76
|
-
const
|
|
95
|
+
const importPathResolvedFilePath = path.posix.join(vikeNodeModulesRoot, vikeDistFile);
|
|
77
96
|
// Double check
|
|
78
97
|
{
|
|
79
|
-
const res = requireResolve_(
|
|
80
|
-
//
|
|
81
|
-
|
|
98
|
+
const res = requireResolve_(importPathResolvedFilePath,
|
|
99
|
+
// No context needed: importPathResolvedFilePath is already resolved and absolute
|
|
100
|
+
null, { doNotHandleFileExtension: true });
|
|
82
101
|
if (res.hasFailed)
|
|
83
102
|
throw res.err;
|
|
84
|
-
assert(res.
|
|
103
|
+
assert(res.importPathResolvedFilePath === importPathResolvedFilePath);
|
|
85
104
|
}
|
|
86
|
-
return
|
|
105
|
+
return importPathResolvedFilePath;
|
|
87
106
|
}
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const paths = [
|
|
107
|
+
function addExtraContextForNpmPackageImport(contexts, { importPath, userRootDir }) {
|
|
108
|
+
// We should add extra context only for npm packages, but unfortunately we cannot always disambiguate between npm package imports and path aliases.
|
|
109
|
+
if (!isImportPathNpmPackageOrPathAlias(importPath))
|
|
110
|
+
return;
|
|
111
|
+
const userRootDirFakeFile = userRootDir && getFakeImporterFile(userRootDir);
|
|
112
|
+
[
|
|
95
113
|
// Workaround for monorepo resolve issue: https://github.com/vikejs/vike-react/pull/161/commits/dbaa6643e78015ac2797c237552800fef29b72a7
|
|
96
|
-
|
|
97
|
-
// I can't think of a use case where this would be needed, but let's add
|
|
98
|
-
|
|
99
|
-
]
|
|
100
|
-
|
|
114
|
+
userRootDirFakeFile,
|
|
115
|
+
// 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
|
|
116
|
+
importMetaUrl
|
|
117
|
+
]
|
|
118
|
+
.filter(isNotNullish)
|
|
119
|
+
.forEach((context) => {
|
|
120
|
+
const alreadyHasContext = contexts.includes(context) || contexts.includes(ensureFilePrefix(context));
|
|
121
|
+
if (alreadyHasContext)
|
|
122
|
+
return;
|
|
123
|
+
contexts.push(context);
|
|
124
|
+
});
|
|
101
125
|
}
|
|
102
126
|
function removeFileExtention(importPath) {
|
|
103
127
|
// Skip for Bun: https://github.com/vikejs/vike/issues/2204
|
|
@@ -132,16 +156,14 @@ function getVikeNodeModulesRoot() {
|
|
|
132
156
|
const vikeNodeModulesRoot = path.posix.join(removeFilePrefix(importMetaUrl), '../../../../');
|
|
133
157
|
return vikeNodeModulesRoot;
|
|
134
158
|
}
|
|
135
|
-
function
|
|
136
|
-
return path.posix.dirname(removeFilePrefix(filePath));
|
|
137
|
-
}
|
|
138
|
-
function getFakeFilePath(dirPath) {
|
|
159
|
+
function getFakeImporterFile(dirPath) {
|
|
139
160
|
assertPosixPath(dirPath);
|
|
140
|
-
assert(!dirPath.startsWith('file')); // The file:// prefix is bogus with path.join
|
|
141
|
-
const
|
|
142
|
-
return
|
|
161
|
+
assert(!dirPath.startsWith('file')); // The file:// prefix is bogus when used with path.posix.join()
|
|
162
|
+
const importerFilePath = path.posix.join(dirPath, 'fakeFileForNodeResolve.js');
|
|
163
|
+
return importerFilePath;
|
|
143
164
|
}
|
|
144
|
-
function
|
|
165
|
+
function ensureFilePrefix(filePath) {
|
|
166
|
+
assertPosixPath(filePath);
|
|
145
167
|
const filePrefix = getFilePrefix();
|
|
146
168
|
if (!filePath.startsWith(filePrefix)) {
|
|
147
169
|
assert(!filePath.startsWith('file'));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.228-commit-
|
|
3
|
+
"version": "0.4.228-commit-0e9e0f2",
|
|
4
4
|
"repository": "https://github.com/vikejs/vike",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./server": {
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"@brillout/json-serializer": "^0.5.15",
|
|
124
124
|
"@brillout/picocolors": "^1.0.26",
|
|
125
125
|
"@brillout/require-shim": "^0.1.2",
|
|
126
|
-
"@brillout/vite-plugin-server-entry": "^0.7.
|
|
126
|
+
"@brillout/vite-plugin-server-entry": "^0.7.8",
|
|
127
127
|
"acorn": "^8.0.0",
|
|
128
128
|
"cac": "^6.0.0",
|
|
129
129
|
"es-module-lexer": "^1.0.0",
|
|
@@ -256,7 +256,7 @@
|
|
|
256
256
|
"react-streaming": "^0.3.47",
|
|
257
257
|
"rimraf": "^5.0.5",
|
|
258
258
|
"typescript": "^5.8.3",
|
|
259
|
-
"vite": "^6.2
|
|
259
|
+
"vite": "^6.3.2"
|
|
260
260
|
},
|
|
261
261
|
"scripts": {
|
|
262
262
|
"dev": "tsc --watch",
|