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
|
@@ -26,6 +26,12 @@ type GlobalContext = GlobalContextServer | GlobalContextClient;
|
|
|
26
26
|
type PageContextWithServerRouting<Data = unknown> = PageContextClientWithServerRouting<Data> | PageContextServer<Data>;
|
|
27
27
|
type PageContextClientWithServerRouting<Data = unknown> = PageContextBuiltInClientWithServerRouting<Data> & Vike.PageContext & Vike.PageContextClient;
|
|
28
28
|
type PageContextBuiltInCommon<Data> = {
|
|
29
|
+
/**
|
|
30
|
+
* Useful for distinguishing `pageContext` from other objects and narrowing down TypeScript unions.
|
|
31
|
+
*
|
|
32
|
+
* https://vike.dev/pageContext#typescript
|
|
33
|
+
*/
|
|
34
|
+
isPageContext: true;
|
|
29
35
|
/** The `export { Page }` of your `.page.js` file.
|
|
30
36
|
*
|
|
31
37
|
* https://vike.dev/Page
|
|
@@ -139,9 +145,9 @@ type PageContextBuiltInCommon<Data> = {
|
|
|
139
145
|
};
|
|
140
146
|
type PageContextBuiltInServer<Data> = PageContextBuiltInCommon<Data> & PageContextUrlServer & {
|
|
141
147
|
/**
|
|
142
|
-
* Whether the page is being rendered on the client-side
|
|
148
|
+
* Whether the page is being rendered on the client-side or server-side / pre-rendered.
|
|
143
149
|
*
|
|
144
|
-
*
|
|
150
|
+
* We recommend using `import.meta.env.SSR` instead, see https://vike.dev/pageContext
|
|
145
151
|
*/
|
|
146
152
|
isClientSide: false;
|
|
147
153
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.228-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.228-commit-0e9e0f2";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.228-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.228-commit-0e9e0f2';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { isImportPath };
|
|
2
|
+
export { isImportPathRelative };
|
|
3
|
+
import { assertPosixPath } from './path.js';
|
|
4
|
+
import { assert } from './assert.js';
|
|
5
|
+
import { isImportPathNpmPackageOrPathAlias } from './parseNpmPackage.js';
|
|
6
|
+
function isImportPath(importPath) {
|
|
7
|
+
return isImportPathRelative(importPath) || isImportPathNpmPackageOrPathAlias(importPath);
|
|
8
|
+
}
|
|
9
|
+
// See also `import { pathIsRelative } from './path'`
|
|
10
|
+
function isImportPathRelative(importPath) {
|
|
11
|
+
assertPosixPath(importPath);
|
|
12
|
+
if (importPath.startsWith('./') || importPath.startsWith('../')) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
assert(!importPath.startsWith('.'));
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -7,6 +7,6 @@ function objectAssign(obj, objAddendum, objAddendumCanBePageContextObject) {
|
|
|
7
7
|
if (!objAddendum)
|
|
8
8
|
return;
|
|
9
9
|
if (!objAddendumCanBePageContextObject)
|
|
10
|
-
assert(!('
|
|
10
|
+
assert(!('isPageContext' in objAddendum));
|
|
11
11
|
Object.defineProperties(obj, Object.getOwnPropertyDescriptors(objAddendum));
|
|
12
12
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { isImportPathNpmPackage };
|
|
2
|
+
export { isImportPathNpmPackageOrPathAlias };
|
|
3
|
+
export { assertIsImportPathNpmPackage };
|
|
4
|
+
export { isPathAliasRecommended };
|
|
5
|
+
export { parseNpmPackage };
|
|
6
|
+
export { isDistinguishable };
|
|
7
|
+
declare function isImportPathNpmPackage(str: string, { cannotBePathAlias }: {
|
|
8
|
+
cannotBePathAlias: true;
|
|
9
|
+
}): boolean;
|
|
10
|
+
declare function isImportPathNpmPackageOrPathAlias(str: string): boolean;
|
|
11
|
+
declare function assertIsImportPathNpmPackage(str: string): void;
|
|
12
|
+
declare function isPathAliasRecommended(alias: string): boolean;
|
|
13
|
+
declare function isDistinguishable(alias: string): boolean;
|
|
14
|
+
declare function parseNpmPackage(str: string | undefined): null | {
|
|
15
|
+
pkgName: string;
|
|
16
|
+
importPath: null | string;
|
|
17
|
+
};
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
1
|
+
export { isImportPathNpmPackage };
|
|
2
|
+
export { isImportPathNpmPackageOrPathAlias };
|
|
3
|
+
export { assertIsImportPathNpmPackage };
|
|
4
|
+
export { isPathAliasRecommended };
|
|
5
5
|
/* Currently not used
|
|
6
6
|
export { isNpmPackageName }
|
|
7
7
|
export { getNpmPackageName }
|
|
8
8
|
export { getNpmPackageImportPath }
|
|
9
9
|
*/
|
|
10
10
|
// For ./isNpmPackage.spec.ts
|
|
11
|
-
export {
|
|
11
|
+
export { parseNpmPackage };
|
|
12
12
|
export { isDistinguishable };
|
|
13
13
|
import { assert } from './assert.js';
|
|
14
14
|
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
15
15
|
assertIsNotBrowser();
|
|
16
|
-
function
|
|
16
|
+
function isImportPathNpmPackage(str, { cannotBePathAlias }) {
|
|
17
17
|
assert(cannotBePathAlias);
|
|
18
|
-
return
|
|
18
|
+
return isImportPathNpmPackageOrPathAlias(str);
|
|
19
19
|
}
|
|
20
20
|
// We cannot distinguish path aliases that look like npm package imports
|
|
21
|
-
function
|
|
22
|
-
const res =
|
|
21
|
+
function isImportPathNpmPackageOrPathAlias(str) {
|
|
22
|
+
const res = parseNpmPackage(str);
|
|
23
23
|
return res !== null;
|
|
24
24
|
}
|
|
25
|
-
function
|
|
26
|
-
assert(
|
|
27
|
-
// If `str` is a path alias that looks like an npm package =>
|
|
25
|
+
function assertIsImportPathNpmPackage(str) {
|
|
26
|
+
assert(isImportPathNpmPackage(str, {
|
|
27
|
+
// 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.
|
|
28
28
|
cannotBePathAlias: true
|
|
29
29
|
}), str);
|
|
30
30
|
}
|
|
31
31
|
function isNpmPackageName(str) {
|
|
32
|
-
const res =
|
|
32
|
+
const res = parseNpmPackage(str);
|
|
33
33
|
return res !== null && res.importPath === null;
|
|
34
34
|
}
|
|
35
35
|
function getNpmPackageName(str) {
|
|
36
|
-
const res =
|
|
36
|
+
const res = parseNpmPackage(str);
|
|
37
37
|
if (!res)
|
|
38
38
|
return null;
|
|
39
39
|
return res.pkgName;
|
|
40
40
|
}
|
|
41
41
|
function getNpmPackageImportPath(str) {
|
|
42
|
-
const res =
|
|
42
|
+
const res = parseNpmPackage(str);
|
|
43
43
|
if (!res)
|
|
44
44
|
return null;
|
|
45
45
|
return res.importPath;
|
|
46
46
|
}
|
|
47
|
-
function
|
|
47
|
+
function isPathAliasRecommended(alias) {
|
|
48
48
|
// Cannot be distinguished from npm package names
|
|
49
49
|
if (!isDistinguishable(alias))
|
|
50
50
|
return false;
|
|
@@ -60,14 +60,14 @@ function isValidPathAlias(alias) {
|
|
|
60
60
|
return true;
|
|
61
61
|
}
|
|
62
62
|
function isDistinguishable(alias) {
|
|
63
|
-
return (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
return (parseNpmPackage(alias) === null &&
|
|
64
|
+
parseNpmPackage(`${alias}fake-path`) === null &&
|
|
65
|
+
parseNpmPackage(`${alias}/fake-path`) === null &&
|
|
66
|
+
parseNpmPackage(`${alias}fake/deep/path`) === null &&
|
|
67
|
+
parseNpmPackage(`${alias}/fake/deep/path`) === null &&
|
|
68
68
|
// See note about '-' in ./isNpmPackageName.spec.ts
|
|
69
69
|
// ```ts
|
|
70
|
-
// expect(
|
|
70
|
+
// expect(parseNpmPackage('-')).toBe(null) // actually wrong: https://www.npmjs.com/package/-
|
|
71
71
|
// ```
|
|
72
72
|
!alias.startsWith('-'));
|
|
73
73
|
}
|
|
@@ -75,7 +75,7 @@ function isDistinguishable(alias) {
|
|
|
75
75
|
// - https://www.npmjs.com/package/-
|
|
76
76
|
// The correct logic is complex, see https://github.com/npm/validate-npm-package-name
|
|
77
77
|
// We don't need to be accurate: are there npm packages with weird names that are actually being used?
|
|
78
|
-
function
|
|
78
|
+
function parseNpmPackage(str) {
|
|
79
79
|
if (!str)
|
|
80
80
|
return null;
|
|
81
81
|
let scope = null;
|
package/dist/esm/utils/path.d.ts
CHANGED
|
@@ -11,4 +11,4 @@ declare function pathJoin(path1: string, path2: string): string;
|
|
|
11
11
|
/**********************/
|
|
12
12
|
declare function toPosixPath(path: string): string;
|
|
13
13
|
declare function assertPosixPath(path: string): void;
|
|
14
|
-
declare function pathIsRelative(
|
|
14
|
+
declare function pathIsRelative(path: string): boolean;
|
package/dist/esm/utils/path.js
CHANGED
|
@@ -42,6 +42,16 @@ function assertPosixPath(path) {
|
|
|
42
42
|
assert(path);
|
|
43
43
|
assert(!path.includes('\\'), errMsg(path));
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
// See also `import { isImportPathRelative } from './isImportPath.js'`
|
|
46
|
+
function pathIsRelative(path) {
|
|
47
|
+
assertPosixPath(path);
|
|
48
|
+
if (path.startsWith('./') || path.startsWith('../')) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
/* Not true if `path` starts with a hidden directory (i.e. a directory with a name that starts with `.`)
|
|
53
|
+
assert(!path.startsWith('.'))
|
|
54
|
+
*/
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
47
57
|
}
|
|
@@ -1,8 +1,21 @@
|
|
|
1
|
-
export { requireResolve };
|
|
2
1
|
export { requireResolveOptional };
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
declare function
|
|
8
|
-
|
|
2
|
+
export { requireResolveOptionalDir };
|
|
3
|
+
export { requireResolveNpmPackage };
|
|
4
|
+
export { requireResolveVikeDistFile };
|
|
5
|
+
export { getVikeNodeModulesRoot };
|
|
6
|
+
declare function requireResolveOptional({ importPath, importerFilePath, userRootDir }: {
|
|
7
|
+
importPath: string;
|
|
8
|
+
importerFilePath: string;
|
|
9
|
+
userRootDir: string;
|
|
10
|
+
}): string | null;
|
|
11
|
+
declare function requireResolveOptionalDir({ importPath, importerDir, userRootDir }: {
|
|
12
|
+
importPath: string;
|
|
13
|
+
importerDir: string;
|
|
14
|
+
userRootDir: string;
|
|
15
|
+
}): string | null;
|
|
16
|
+
declare function requireResolveNpmPackage({ importPathNpmPackage, userRootDir }: {
|
|
17
|
+
importPathNpmPackage: string;
|
|
18
|
+
userRootDir: string;
|
|
19
|
+
}): string;
|
|
20
|
+
declare function requireResolveVikeDistFile(vikeDistFile: `dist/esm/${string}`): string;
|
|
21
|
+
declare function getVikeNodeModulesRoot(): string;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { requireResolve };
|
|
2
1
|
export { requireResolveOptional };
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
2
|
+
export { requireResolveOptionalDir };
|
|
3
|
+
export { requireResolveNpmPackage };
|
|
4
|
+
export { requireResolveVikeDistFile };
|
|
5
|
+
export { getVikeNodeModulesRoot };
|
|
5
6
|
import { assert } from './assert.js';
|
|
6
7
|
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
7
8
|
import { assertIsNotProductionRuntime } from './assertSetup.js';
|
|
@@ -9,68 +10,118 @@ import { assertPosixPath, toPosixPath } from './path.js';
|
|
|
9
10
|
import { scriptFileExtensionList } from './isScriptFile.js';
|
|
10
11
|
import { createRequire } from 'node:module';
|
|
11
12
|
import path from 'node:path';
|
|
13
|
+
import { assertIsImportPathNpmPackage, isImportPathNpmPackageOrPathAlias } from './parseNpmPackage.js';
|
|
14
|
+
import { isNotNullish } from './isNullish.js';
|
|
12
15
|
// @ts-ignore import.meta.url is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
13
16
|
const importMetaUrl = import.meta.url;
|
|
14
|
-
|
|
17
|
+
assertPosixPath(importMetaUrl);
|
|
15
18
|
assertIsNotBrowser();
|
|
16
19
|
assertIsNotProductionRuntime();
|
|
17
|
-
|
|
18
|
-
|
|
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 } = {}) {
|
|
19
29
|
assertPosixPath(importPath);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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;
|
|
25
59
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// - https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment139581675_62272600
|
|
30
|
-
importedFile = require_.resolve(importPath, { paths: [cwd] });
|
|
60
|
+
if (!importPathResolvedFilePath) {
|
|
61
|
+
assert(failure);
|
|
62
|
+
return { importPathResolvedFilePath: undefined, err: failure.err, hasFailed: true };
|
|
31
63
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
64
|
+
else {
|
|
65
|
+
assert(importPathResolvedFilePath);
|
|
66
|
+
importPathResolvedFilePath = toPosixPath(importPathResolvedFilePath);
|
|
67
|
+
return { importPathResolvedFilePath, err: undefined, hasFailed: false };
|
|
35
68
|
}
|
|
36
|
-
clean();
|
|
37
|
-
importedFile = toPosixPath(importedFile);
|
|
38
|
-
return { importedFile, err: undefined, hasFailed: false };
|
|
39
69
|
}
|
|
40
|
-
function requireResolveOptional(importPath,
|
|
41
|
-
const res = requireResolve_(importPath,
|
|
70
|
+
function requireResolveOptional({ importPath, importerFilePath, userRootDir }) {
|
|
71
|
+
const res = requireResolve_(importPath, importerFilePath, { userRootDir });
|
|
42
72
|
if (res.hasFailed)
|
|
43
73
|
return null;
|
|
44
|
-
return res.
|
|
74
|
+
return res.importPathResolvedFilePath;
|
|
45
75
|
}
|
|
46
|
-
function
|
|
47
|
-
const
|
|
76
|
+
function requireResolveOptionalDir({ importPath, importerDir, userRootDir }) {
|
|
77
|
+
const importerFilePath = getFakeImporterFile(importerDir);
|
|
78
|
+
const res = requireResolve_(importPath, importerFilePath, { userRootDir });
|
|
48
79
|
if (res.hasFailed)
|
|
49
80
|
return null;
|
|
50
|
-
return res.
|
|
51
|
-
}
|
|
52
|
-
function requireResolveNonUserFile(importPath, cwd) {
|
|
53
|
-
const res = requireResolve_(importPath, cwd, { doNotHandleFileExtension: true });
|
|
54
|
-
if (res.hasFailed)
|
|
55
|
-
throw res.err;
|
|
56
|
-
return res.importedFile;
|
|
81
|
+
return res.importPathResolvedFilePath;
|
|
57
82
|
}
|
|
58
|
-
function
|
|
59
|
-
|
|
83
|
+
function requireResolveNpmPackage({ importPathNpmPackage, userRootDir }) {
|
|
84
|
+
assertIsImportPathNpmPackage(importPathNpmPackage);
|
|
85
|
+
const importerFilePath = getFakeImporterFile(userRootDir);
|
|
86
|
+
const res = requireResolve_(importPathNpmPackage, importerFilePath, { userRootDir });
|
|
60
87
|
if (res.hasFailed)
|
|
61
88
|
throw res.err;
|
|
62
|
-
return res.
|
|
89
|
+
return res.importPathResolvedFilePath;
|
|
63
90
|
}
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
91
|
+
function requireResolveVikeDistFile(vikeDistFile) {
|
|
92
|
+
const vikeNodeModulesRoot = getVikeNodeModulesRoot();
|
|
93
|
+
assertPosixPath(vikeNodeModulesRoot);
|
|
94
|
+
assertPosixPath(vikeDistFile);
|
|
95
|
+
const importPathResolvedFilePath = path.posix.join(vikeNodeModulesRoot, vikeDistFile);
|
|
96
|
+
// Double check
|
|
97
|
+
{
|
|
98
|
+
const res = requireResolve_(importPathResolvedFilePath,
|
|
99
|
+
// No context needed: importPathResolvedFilePath is already resolved and absolute
|
|
100
|
+
null, { doNotHandleFileExtension: true });
|
|
101
|
+
if (res.hasFailed)
|
|
102
|
+
throw res.err;
|
|
103
|
+
assert(res.importPathResolvedFilePath === importPathResolvedFilePath);
|
|
71
104
|
}
|
|
72
|
-
|
|
73
|
-
|
|
105
|
+
return importPathResolvedFilePath;
|
|
106
|
+
}
|
|
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
|
+
[
|
|
113
|
+
// Workaround for monorepo resolve issue: https://github.com/vikejs/vike-react/pull/161/commits/dbaa6643e78015ac2797c237552800fef29b72a7
|
|
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
|
+
});
|
|
74
125
|
}
|
|
75
126
|
function removeFileExtention(importPath) {
|
|
76
127
|
// Skip for Bun: https://github.com/vikejs/vike/issues/2204
|
|
@@ -88,7 +139,7 @@ function removeFileExtention(importPath) {
|
|
|
88
139
|
}
|
|
89
140
|
return importPath;
|
|
90
141
|
}
|
|
91
|
-
function addFileExtensionsToRequireResolve() {
|
|
142
|
+
function addFileExtensionsToRequireResolve(require_) {
|
|
92
143
|
const added = [];
|
|
93
144
|
scriptFileExtensionList.forEach((ext) => {
|
|
94
145
|
assert(!ext.includes('.'));
|
|
@@ -98,10 +149,40 @@ function addFileExtensionsToRequireResolve() {
|
|
|
98
149
|
added.push(ext);
|
|
99
150
|
}
|
|
100
151
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return
|
|
152
|
+
}
|
|
153
|
+
function getVikeNodeModulesRoot() {
|
|
154
|
+
// [RELATIVE_PATH_FROM_DIST] Current file: vike/dist/esm/utils/requireResolve.js
|
|
155
|
+
assert(importMetaUrl.includes('/dist/esm/') || importMetaUrl.includes('/dist/cjs/'));
|
|
156
|
+
const vikeNodeModulesRoot = path.posix.join(removeFilePrefix(importMetaUrl), '../../../../');
|
|
157
|
+
return vikeNodeModulesRoot;
|
|
158
|
+
}
|
|
159
|
+
function getFakeImporterFile(dirPath) {
|
|
160
|
+
assertPosixPath(dirPath);
|
|
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;
|
|
164
|
+
}
|
|
165
|
+
function ensureFilePrefix(filePath) {
|
|
166
|
+
assertPosixPath(filePath);
|
|
167
|
+
const filePrefix = getFilePrefix();
|
|
168
|
+
if (!filePath.startsWith(filePrefix)) {
|
|
169
|
+
assert(!filePath.startsWith('file'));
|
|
170
|
+
filePath = filePrefix + filePath;
|
|
171
|
+
}
|
|
172
|
+
assert(filePath.startsWith(filePrefix));
|
|
173
|
+
return filePath;
|
|
174
|
+
}
|
|
175
|
+
function removeFilePrefix(filePath) {
|
|
176
|
+
const filePrefix = getFilePrefix();
|
|
177
|
+
if (filePath.startsWith(filePrefix)) {
|
|
178
|
+
filePath = filePath.slice(filePrefix.length);
|
|
179
|
+
}
|
|
180
|
+
assert(!filePath.startsWith('file'));
|
|
181
|
+
return filePath;
|
|
182
|
+
}
|
|
183
|
+
function getFilePrefix() {
|
|
184
|
+
let prefix = 'file://';
|
|
185
|
+
if (process.platform === 'win32')
|
|
186
|
+
prefix += '/';
|
|
187
|
+
return prefix;
|
|
107
188
|
}
|
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",
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export { isNpmPackageImport };
|
|
2
|
-
export { isNpmPackageImport_unreliable };
|
|
3
|
-
export { assertIsNpmPackageImport };
|
|
4
|
-
export { isValidPathAlias };
|
|
5
|
-
export { parse };
|
|
6
|
-
export { isDistinguishable };
|
|
7
|
-
declare function isNpmPackageImport(str: string, { cannotBePathAlias }: {
|
|
8
|
-
cannotBePathAlias: true;
|
|
9
|
-
}): boolean;
|
|
10
|
-
declare function isNpmPackageImport_unreliable(str: string): boolean;
|
|
11
|
-
declare function assertIsNpmPackageImport(str: string): void;
|
|
12
|
-
declare function isValidPathAlias(alias: string): boolean;
|
|
13
|
-
declare function isDistinguishable(alias: string): boolean;
|
|
14
|
-
declare function parse(str: string | undefined): null | {
|
|
15
|
-
pkgName: string;
|
|
16
|
-
importPath: null | string;
|
|
17
|
-
};
|