vike 0.4.228-commit-8d90991 → 0.4.228-commit-84954ae
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/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/renderPage/getPageAssets/getManifestEntry.js +1 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +1 -1
- package/dist/cjs/node/runtime/utils.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/{isNpmPackage.js → parseNpmPackage.js} +23 -23
- package/dist/cjs/utils/path.js +12 -2
- package/dist/cjs/utils/requireResolve.js +98 -39
- package/dist/esm/client/client-routing-runtime/globalContext.d.ts +1 -1
- package/dist/esm/client/server-routing-runtime/globalContext.d.ts +1 -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.js +2 -2
- package/dist/esm/node/runtime/globalContext.d.ts +2 -2
- 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/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/shared/VikeNamespace.d.ts +8 -8
- 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 +4 -4
- 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/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 +98 -39
- package/package.json +1 -1
- package/dist/esm/utils/isNpmPackage.d.ts +0 -17
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { transformPointerImports };
|
|
2
2
|
export { parsePointerImportData };
|
|
3
3
|
export { isPointerImportData };
|
|
4
|
+
export { assertPointerImportPath };
|
|
4
5
|
// Playground: https://github.com/brillout/acorn-playground
|
|
5
6
|
// Notes about `with { type: 'pointer' }`
|
|
6
7
|
// - It works well with TypeScript: it doesn't complain upon `with { type: 'unknown-to-typescript' }` and go-to-definition & types are preserved: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html#import-attributes
|
|
@@ -17,7 +18,7 @@ export { isPointerImportData };
|
|
|
17
18
|
// - Esbuild removes comments: https://github.com/evanw/esbuild/issues/1439#issuecomment-877656182
|
|
18
19
|
// - Using source maps to track these magic comments is brittle (source maps can easily break)
|
|
19
20
|
import { parse } from 'acorn';
|
|
20
|
-
import { assert, assertUsage, assertWarning, styleFileRE } from '../../../../utils.js';
|
|
21
|
+
import { assert, assertUsage, assertWarning, isFilePathAbsolute, isImportPath, styleFileRE } from '../../../../utils.js';
|
|
21
22
|
import pc from '@brillout/picocolors';
|
|
22
23
|
function transformPointerImports(code, filePathToShowToUser2, pointerImports,
|
|
23
24
|
// For ./transformPointerImports.spec.ts
|
|
@@ -144,8 +145,20 @@ function parsePointerImportData(importString) {
|
|
|
144
145
|
assert(parts.length >= 2);
|
|
145
146
|
const exportName = parts[parts.length - 1];
|
|
146
147
|
const importPath = parts.slice(0, -1).join(SEP);
|
|
148
|
+
if (importPath.startsWith('.') && !(importPath.startsWith('./') || importPath.startsWith('../'))) {
|
|
149
|
+
assert(!importStringWasGenerated);
|
|
150
|
+
assertUsage(false, `Invalid relative import path ${pc.code(importPath)} defined by ${pc.code(JSON.stringify(importString))} because it should start with ${pc.code('./')} or ${pc.code('../')}, or use an npm package import instead.`);
|
|
151
|
+
}
|
|
152
|
+
assertPointerImportPath(importPath);
|
|
147
153
|
return { importPath, exportName, importStringWasGenerated, importString };
|
|
148
154
|
}
|
|
155
|
+
// `importPath` is one of the following:
|
|
156
|
+
// - A relative import path
|
|
157
|
+
// - An npm package import
|
|
158
|
+
// - A filesystem absolute path, see transpileWithEsbuild()
|
|
159
|
+
function assertPointerImportPath(importPath) {
|
|
160
|
+
return isImportPath(importPath) || isFilePathAbsolute(importPath);
|
|
161
|
+
}
|
|
149
162
|
function spliceMany(str, operations) {
|
|
150
163
|
let strMod = '';
|
|
151
164
|
let endPrev;
|
|
@@ -2,7 +2,7 @@ export { resolvePointerImport };
|
|
|
2
2
|
export { resolvePointerImportData };
|
|
3
3
|
export type { PointerImport };
|
|
4
4
|
import type { DefinedAtFilePath } from '../../../../../../shared/page-configs/PageConfig.js';
|
|
5
|
-
import { type PointerImportData } from './
|
|
5
|
+
import { type PointerImportData } from './pointerImports.js';
|
|
6
6
|
import type { FilePath, FilePathResolved } from '../../../../../../shared/page-configs/FilePath.js';
|
|
7
7
|
type PointerImport = {
|
|
8
8
|
fileExportPath: FileExportPath;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export { resolvePointerImport };
|
|
2
2
|
export { resolvePointerImportData };
|
|
3
3
|
import pc from '@brillout/picocolors';
|
|
4
|
-
import { assert, assertPosixPath, assertUsage, isFilePathAbsolute,
|
|
5
|
-
import { parsePointerImportData } from './
|
|
6
|
-
import path from 'path';
|
|
4
|
+
import { assert, assertPosixPath, assertUsage, isFilePathAbsolute, isImportPathRelative, isImportPathNpmPackageOrPathAlias, requireResolveOptional } from '../../../../utils.js';
|
|
5
|
+
import { assertPointerImportPath, parsePointerImportData } from './pointerImports.js';
|
|
7
6
|
import { getFilePathAbsoluteUserRootDir, getFilePathResolved, getFilePathUnresolved } from '../../../../shared/getFilePath.js';
|
|
8
7
|
function resolvePointerImport(configValue, importerFilePath, userRootDir, configName) {
|
|
9
8
|
if (typeof configValue !== 'string')
|
|
@@ -22,24 +21,18 @@ function resolvePointerImport(configValue, importerFilePath, userRootDir, config
|
|
|
22
21
|
return { fileExportPath };
|
|
23
22
|
}
|
|
24
23
|
function resolvePointerImportData(pointerImportData, importerFilePath, userRootDir) {
|
|
25
|
-
// `importPath` should be one of the following:
|
|
26
|
-
// - A relative import path
|
|
27
|
-
// - A filesystem absolute path
|
|
28
|
-
// - An npm package import
|
|
29
24
|
const { importPath } = pointerImportData;
|
|
30
|
-
|
|
25
|
+
assertPointerImportPath(importPath);
|
|
26
|
+
const filePathAbsoluteFilesystem = resolveImportPathWithNode(pointerImportData, importerFilePath, userRootDir);
|
|
31
27
|
let filePath;
|
|
32
28
|
assertPosixPath(importPath);
|
|
33
|
-
if (importPath
|
|
34
|
-
if (importPath.startsWith('.')) {
|
|
35
|
-
assertUsage(pathIsRelative(importPath), `Invalid relative import path ${pc.code(importPath)} defined by ${importerFilePath.filePathToShowToUser} because it should start with ${pc.code('./')} or ${pc.code('../')}, or use an npm package import instead.`);
|
|
36
|
-
}
|
|
29
|
+
if (isImportPathRelative(importPath) || isFilePathAbsolute(importPath)) {
|
|
37
30
|
// Pointer imports are included in virtual files, thus relative imports need to be resolved. (Virtual modules cannot contain relative imports.)
|
|
38
31
|
assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath);
|
|
39
32
|
// Pointer imports are included in virtual files, and we need filePathAbsoluteUserRootDir because we didn't find a way to have filesystem absolute import paths in virtual files: https://gist.github.com/brillout/2315231c9a8164f950c64b4b4a7bbd39
|
|
40
33
|
const errSuffix = `outside of the ${userRootDir} directory which is forbidden: make sure your import paths resolve inside the ${userRootDir} directory, or import from an npm package.`;
|
|
41
34
|
const filePathAbsoluteUserRootDir = getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir });
|
|
42
|
-
if (importPath
|
|
35
|
+
if (isImportPathRelative(importPath)) {
|
|
43
36
|
assertUsage(filePathAbsoluteUserRootDir, `The relative import ${pc.cyan(importPath)} defined by ${importerFilePath.filePathToShowToUser} resolves to ${filePathAbsoluteFilesystem} ${errSuffix}`);
|
|
44
37
|
}
|
|
45
38
|
else {
|
|
@@ -51,6 +44,7 @@ function resolvePointerImportData(pointerImportData, importerFilePath, userRootD
|
|
|
51
44
|
filePath = getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir });
|
|
52
45
|
}
|
|
53
46
|
else {
|
|
47
|
+
assert(isImportPathNpmPackageOrPathAlias(importPath));
|
|
54
48
|
const importPathAbsolute = importPath;
|
|
55
49
|
if (filePathAbsoluteFilesystem) {
|
|
56
50
|
filePath = getFilePathResolved({
|
|
@@ -68,12 +62,20 @@ function resolvePointerImportData(pointerImportData, importerFilePath, userRootD
|
|
|
68
62
|
}
|
|
69
63
|
return filePath;
|
|
70
64
|
}
|
|
71
|
-
function resolveImportPathWithNode(pointerImportData, importerFilePath) {
|
|
65
|
+
function resolveImportPathWithNode(pointerImportData, importerFilePath, userRootDir) {
|
|
72
66
|
const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
|
|
73
67
|
assertPosixPath(importerFilePathAbsolute);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
68
|
+
// filePathAbsoluteFilesystem is null when pointerImportData.importPath is a path alias that Node.js doesn't know about
|
|
69
|
+
const filePathAbsoluteFilesystem = requireResolveOptional({
|
|
70
|
+
importPath: pointerImportData.importPath,
|
|
71
|
+
importerFile: importerFilePathAbsolute,
|
|
72
|
+
userRootDir
|
|
73
|
+
});
|
|
74
|
+
if (!filePathAbsoluteFilesystem) {
|
|
75
|
+
assert(!isImportPathRelative(pointerImportData.importPath));
|
|
76
|
+
// Libraries don't use path aliases => filePathAbsoluteFilesystem should be defined
|
|
77
|
+
assert(!importerFilePathAbsolute.includes('node_modules'));
|
|
78
|
+
}
|
|
77
79
|
return filePathAbsoluteFilesystem;
|
|
78
80
|
}
|
|
79
81
|
function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath) {
|
|
@@ -85,8 +87,7 @@ function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportD
|
|
|
85
87
|
? `The import path ${importPathString} in ${filePathToShowToUser}`
|
|
86
88
|
: `The import ${pc.code(importString)} defined by ${filePathToShowToUser}`;
|
|
87
89
|
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
88
|
-
if (importPath
|
|
89
|
-
assert(pathIsRelative(importPath));
|
|
90
|
+
if (isImportPathRelative(importPath)) {
|
|
90
91
|
assertUsage(false, `${errIntro2} point to an existing file?`);
|
|
91
92
|
}
|
|
92
93
|
else {
|
|
@@ -7,8 +7,8 @@ import fs from 'fs';
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
9
|
import { import_ } from '@brillout/import';
|
|
10
|
-
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isPlainJavaScriptFile, createDebugger, assertFilePathAbsoluteFilesystem,
|
|
11
|
-
import { transformPointerImports } from './
|
|
10
|
+
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isPlainJavaScriptFile, createDebugger, assertFilePathAbsoluteFilesystem, assertIsImportPathNpmPackage, genPromise, isVitest, isImportPathNpmPackageOrPathAlias, isImportPathRelative, requireResolveOptionalDir } from '../../../../utils.js';
|
|
11
|
+
import { transformPointerImports } from './pointerImports.js';
|
|
12
12
|
import sourceMapSupport from 'source-map-support';
|
|
13
13
|
import { getFilePathAbsoluteUserRootDir } from '../../../../shared/getFilePath.js';
|
|
14
14
|
assertIsNotProductionRuntime();
|
|
@@ -121,7 +121,11 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
121
121
|
// - Sitll required for esbuild@0.24.0 (November 2024).
|
|
122
122
|
// - Let's try to remove this workaround again later.
|
|
123
123
|
if (resolved.errors.length > 0) {
|
|
124
|
-
const resolvedWithNode =
|
|
124
|
+
const resolvedWithNode = requireResolveOptionalDir({
|
|
125
|
+
importPath: path,
|
|
126
|
+
importerDir: toPosixPath(args.resolveDir),
|
|
127
|
+
userRootDir
|
|
128
|
+
});
|
|
125
129
|
if (debugEsbuildResolve.isActivated)
|
|
126
130
|
debugEsbuildResolve('resolvedWithNode', resolvedWithNode);
|
|
127
131
|
if (resolvedWithNode)
|
|
@@ -141,8 +145,8 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
141
145
|
const importPathOriginal = args.path;
|
|
142
146
|
// Esbuild resolves path aliases.
|
|
143
147
|
// - Enabling us to use:
|
|
144
|
-
// -
|
|
145
|
-
// -
|
|
148
|
+
// - assertIsImportPathNpmPackage()
|
|
149
|
+
// - isImportPathNpmPackage(str, { cannotBePathAlias: true })
|
|
146
150
|
assertFilePathAbsoluteFilesystem(importPathResolved);
|
|
147
151
|
// Should be remove this? See comment below.
|
|
148
152
|
const isVikeExtensionImport = (path.startsWith('vike-') && path.endsWith('/config')) || importPathResolved.endsWith('+config.js');
|
|
@@ -160,7 +164,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
160
164
|
const isNpmPkgImport = (() => {
|
|
161
165
|
if (importPathResolved.includes('/node_modules/')) {
|
|
162
166
|
// So far I can't think of a use case where this assertion would fail, but let's eventually remove it to avoid artificially restricting the user.
|
|
163
|
-
assert(
|
|
167
|
+
assert(isImportPathNpmPackageOrPathAlias(importPathOriginal));
|
|
164
168
|
return true;
|
|
165
169
|
}
|
|
166
170
|
// Linked npm packages
|
|
@@ -169,7 +173,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
169
173
|
// - This isn't always the case: https://github.com/vikejs/vike/issues/2326
|
|
170
174
|
!importPathResolved.startsWith(userRootDir) &&
|
|
171
175
|
// False positive if `importPathOriginal` is a path alias that a) looks like an npm package import and b) resolves outside of `userRootDir` => we then we wrongfully assume that `importPathOriginal` is an npm package import.
|
|
172
|
-
|
|
176
|
+
isImportPathNpmPackageOrPathAlias(importPathOriginal)) {
|
|
173
177
|
return true;
|
|
174
178
|
}
|
|
175
179
|
return false;
|
|
@@ -186,7 +190,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
186
190
|
}
|
|
187
191
|
let importPathTranspiled;
|
|
188
192
|
assertPosixPath(importPathOriginal);
|
|
189
|
-
if (
|
|
193
|
+
if (isImportPathRelative(importPathOriginal)) {
|
|
190
194
|
importPathTranspiled = importPathResolved;
|
|
191
195
|
}
|
|
192
196
|
else {
|
|
@@ -203,12 +207,12 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
203
207
|
// - Vike doesn't resolve path aliases at all.
|
|
204
208
|
// - Node.js doesn't support `tsconfig.js#compilerOptions.paths`.
|
|
205
209
|
// - Esbuild path alias resolution seems reliable, e.g. it supports `tsconfig.js#compilerOptions.paths`.
|
|
206
|
-
assert(!
|
|
210
|
+
assert(!isImportPathNpmPackageOrPathAlias(importPathOriginal));
|
|
207
211
|
importPathTranspiled = importPathResolved;
|
|
208
212
|
}
|
|
209
213
|
else {
|
|
210
214
|
// `importPathOriginal` is most likely an npm package import.
|
|
211
|
-
|
|
215
|
+
assertIsImportPathNpmPackage(importPathOriginal);
|
|
212
216
|
// For improved error messages, let the resolution be handled by Vike or Node.js.
|
|
213
217
|
importPathTranspiled = importPathOriginal;
|
|
214
218
|
}
|
|
@@ -70,7 +70,7 @@ async function handleReloadSideEffects() {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
// TODO/soon: predominantly use
|
|
73
|
+
// TODO/soon: predominantly use getVikeConfigInternal() instead of getVikeConfig() then maybe refector?
|
|
74
74
|
async function getVikeConfig(config, { doNotRestartViteOnError } = {}) {
|
|
75
75
|
const userRootDir = config.root;
|
|
76
76
|
const vikeVitePluginOptions = config._vikeVitePluginOptions;
|
|
@@ -7,7 +7,7 @@ export { getModuleFilePathRelative };
|
|
|
7
7
|
export { cleanFilePathUnkown };
|
|
8
8
|
export { assertModuleId };
|
|
9
9
|
import path from 'path';
|
|
10
|
-
import { assert,
|
|
10
|
+
import { assert, assertIsImportPathNpmPackage, assertFilePathAbsoluteFilesystem, assertPosixPath, toPosixPath } from '../utils.js';
|
|
11
11
|
function getFilePathResolved(args) {
|
|
12
12
|
const { userRootDir } = args;
|
|
13
13
|
let filePathAbsoluteFilesystem;
|
|
@@ -39,7 +39,7 @@ function getComputedProps(args) {
|
|
|
39
39
|
const importPathAbsolute = args.importPathAbsolute ?? null;
|
|
40
40
|
const { filePathAbsoluteUserRootDir } = args;
|
|
41
41
|
if (importPathAbsolute)
|
|
42
|
-
|
|
42
|
+
assertIsImportPathNpmPackage(importPathAbsolute);
|
|
43
43
|
return {
|
|
44
44
|
importPathAbsolute,
|
|
45
45
|
filePathAbsoluteUserRootDir,
|
|
@@ -53,7 +53,7 @@ function getComputedProps(args) {
|
|
|
53
53
|
}
|
|
54
54
|
function getComputedPropsImportPathAbsolute(args) {
|
|
55
55
|
const { importPathAbsolute } = args;
|
|
56
|
-
|
|
56
|
+
assertIsImportPathNpmPackage(importPathAbsolute);
|
|
57
57
|
return {
|
|
58
58
|
filePathAbsoluteUserRootDir: null,
|
|
59
59
|
importPathAbsolute,
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
export { resolveClientEntriesDev };
|
|
2
|
-
import { assert, assertPosixPath, toPosixPath, pathJoin,
|
|
3
|
-
// @ts-ignore import.meta.url is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
4
|
-
const importMetaUrl = import.meta.url;
|
|
2
|
+
import { assert, assertPosixPath, toPosixPath, pathJoin, assertIsImportPathNpmPackage, assertIsNotProductionRuntime, requireResolveNpmPackage, requireResolveVikeDistFile } from '../utils.js';
|
|
5
3
|
assertIsNotProductionRuntime();
|
|
6
4
|
async function resolveClientEntriesDev(clientEntry, viteDevServer) {
|
|
7
|
-
let
|
|
8
|
-
assert(
|
|
9
|
-
|
|
5
|
+
let userRootDir = viteDevServer.config.root;
|
|
6
|
+
assert(userRootDir);
|
|
7
|
+
userRootDir = toPosixPath(userRootDir);
|
|
10
8
|
// The `?import` suffix is needed for MDX to be transpiled:
|
|
11
9
|
// - Not transpiled: `/pages/markdown.page.mdx`
|
|
12
10
|
// - Transpiled: `/pages/markdown.page.mdx?import`
|
|
@@ -20,26 +18,16 @@ async function resolveClientEntriesDev(clientEntry, viteDevServer) {
|
|
|
20
18
|
assertPosixPath(clientEntry);
|
|
21
19
|
let filePath;
|
|
22
20
|
if (clientEntry.startsWith('/')) {
|
|
23
|
-
filePath = pathJoin(
|
|
21
|
+
filePath = pathJoin(userRootDir, clientEntry);
|
|
24
22
|
}
|
|
25
23
|
else {
|
|
26
24
|
if (clientEntry.startsWith('@@vike/')) {
|
|
27
25
|
assert(clientEntry.endsWith('.js'));
|
|
28
|
-
|
|
29
|
-
// For Vitest (which doesn't resolve vike to its dist but to its source files)
|
|
30
|
-
// [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/node/plugin/shared/resolveClientEntriesDev.js
|
|
31
|
-
filePath_ = requireResolveOptionalNonUserFile(clientEntry.replace('@@vike/dist/esm/client/', '../../../client/').replace('.js', '.ts'), importMetaUrl);
|
|
32
|
-
if (!filePath_) {
|
|
33
|
-
// For users
|
|
34
|
-
// [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/shared/resolveClientEntriesDev.js
|
|
35
|
-
filePath_ = requireResolveOptionalNonUserFile(clientEntry.replace('@@vike/dist/esm/client/', '../../../../../dist/esm/client/'), importMetaUrl);
|
|
36
|
-
}
|
|
37
|
-
assert(filePath_);
|
|
38
|
-
filePath = filePath_;
|
|
26
|
+
filePath = requireResolveVikeDistFile(`dist/esm/${clientEntry.replace('@@vike/dist/esm/', '')}`);
|
|
39
27
|
}
|
|
40
28
|
else {
|
|
41
|
-
|
|
42
|
-
filePath =
|
|
29
|
+
assertIsImportPathNpmPackage(clientEntry);
|
|
30
|
+
filePath = requireResolveNpmPackage({ importPathNpmPackage: clientEntry, userRootDir });
|
|
43
31
|
}
|
|
44
32
|
}
|
|
45
33
|
if (!filePath.startsWith('/')) {
|
|
@@ -30,7 +30,7 @@ import { resolvePrerenderConfigGlobal, resolvePrerenderConfigLocal } from './res
|
|
|
30
30
|
import { getOutDirs } from '../plugin/shared/getOutDirs.js';
|
|
31
31
|
import { isVikeCli } from '../cli/context.js';
|
|
32
32
|
import { isViteCliCall } from '../plugin/shared/isViteCliCall.js';
|
|
33
|
-
import {
|
|
33
|
+
import { getVikeConfigInternal } from '../plugin/plugins/commonConfig.js';
|
|
34
34
|
import fs from 'node:fs';
|
|
35
35
|
async function runPrerenderFromAPI(options = {}) {
|
|
36
36
|
return await runPrerender(options, 'prerender()');
|
|
@@ -77,7 +77,7 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
77
77
|
await disableReactStreaming();
|
|
78
78
|
const viteConfig = await resolveConfig(options.viteConfig || {}, 'build', 'production');
|
|
79
79
|
const vikeConfig = await getVikeConfig(viteConfig);
|
|
80
|
-
const vike =
|
|
80
|
+
const vike = getVikeConfigInternal(viteConfig);
|
|
81
81
|
const { outDirClient, outDirServer } = getOutDirs(viteConfig);
|
|
82
82
|
const { root } = viteConfig;
|
|
83
83
|
const prerenderConfigGlobal = resolvePrerenderConfigGlobal(vikeConfig);
|
|
@@ -21,7 +21,7 @@ export type { GlobalContextServer };
|
|
|
21
21
|
import type { ViteManifest } from '../shared/ViteManifest.js';
|
|
22
22
|
import type { ResolvedConfig, ViteDevServer } from 'vite';
|
|
23
23
|
import type { ViteConfigRuntime } from '../plugin/shared/getViteConfigRuntime.js';
|
|
24
|
-
type GlobalContextServer = ReturnType<typeof makePublic> & Vike.GlobalContext;
|
|
24
|
+
type GlobalContextServer = ReturnType<typeof makePublic> & Vike.GlobalContext & Vike.GlobalContextServer;
|
|
25
25
|
type GlobalContextServerInternal = Awaited<ReturnType<typeof setGlobalContext>>;
|
|
26
26
|
declare function getGlobalContextInternal(): Promise<{
|
|
27
27
|
globalContext: (Record<string, unknown> & {
|
|
@@ -223,7 +223,7 @@ declare function getGlobalContextInternal(): Promise<{
|
|
|
223
223
|
_allPageIds: string[];
|
|
224
224
|
config: import("../../types/index.js").ConfigResolved;
|
|
225
225
|
pages: import("../../shared/page-configs/getPageConfigUserFriendly.js").PageConfigsUserFriendly;
|
|
226
|
-
}), "pages" | "viteConfig" | "viteConfigRuntime" | "assetsManifest" | "baseServer" | "baseAssets" | "config"> & Vike.GlobalContext;
|
|
226
|
+
}), "pages" | "viteConfig" | "viteConfigRuntime" | "assetsManifest" | "baseServer" | "baseAssets" | "config"> & Vike.GlobalContext & Vike.GlobalContextServer;
|
|
227
227
|
}>;
|
|
228
228
|
/**
|
|
229
229
|
* Get runtime information about your app.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getManifestEntry };
|
|
2
|
-
import { assert, slice,
|
|
2
|
+
import { assert, slice, assertIsImportPathNpmPackage } from '../../utils.js';
|
|
3
3
|
import { isVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
4
4
|
import { prependEntriesDir } from '../../../shared/prependEntriesDir.js';
|
|
5
5
|
function getManifestEntry(id, assetsManifest) {
|
|
@@ -40,7 +40,7 @@ function getManifestEntry(id, assetsManifest) {
|
|
|
40
40
|
return { manifestEntry, manifestKey };
|
|
41
41
|
}
|
|
42
42
|
// npm package import
|
|
43
|
-
|
|
43
|
+
assertIsImportPathNpmPackage(id);
|
|
44
44
|
const found = Object.entries(assetsManifest).find(([, e]) => e.name === prependEntriesDir(id));
|
|
45
45
|
assert(found);
|
|
46
46
|
const [manifestKey, manifestEntry] = found;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { retrieveAssetsProd };
|
|
2
|
-
import { assert,
|
|
2
|
+
import { assert, isImportPathNpmPackage } from '../../utils.js';
|
|
3
3
|
import { getManifestEntry } from './getManifestEntry.js';
|
|
4
4
|
import { extractAssetsAddQuery } from '../../../shared/extractAssetsQuery.js';
|
|
5
5
|
function retrieveAssetsProd(clientDependencies, assetsManifest, includeAssetsImportedByServer) {
|
|
@@ -14,7 +14,7 @@ function retrieveAssetsProd(clientDependencies, assetsManifest, includeAssetsImp
|
|
|
14
14
|
onlyAssets &&
|
|
15
15
|
id.includes('.page.server.') &&
|
|
16
16
|
// We assume that all npm packages have already built their files: bundlers (Rollup, esbuild, tsup, ...) extract the CSS out of JavaScript => we can assume JavaScript to not import any CSS/assets.
|
|
17
|
-
!
|
|
17
|
+
!isImportPathNpmPackage(id, {
|
|
18
18
|
// I presume Vite already resolves path aliases when Vite sets the module's id
|
|
19
19
|
cannotBePathAlias: true
|
|
20
20
|
})) {
|
|
@@ -30,7 +30,7 @@ export * from '../../utils/debug.js';
|
|
|
30
30
|
export * from '../../utils/urlToFile.js';
|
|
31
31
|
export * from '../../utils/getGlobalObject.js';
|
|
32
32
|
export * from '../../utils/freezePartial.js';
|
|
33
|
-
export * from '../../utils/
|
|
33
|
+
export * from '../../utils/parseNpmPackage.js';
|
|
34
34
|
export * from '../../utils/isNullish.js';
|
|
35
35
|
export * from '../../utils/isScriptFile.js';
|
|
36
36
|
export * from '../../utils/removeFileExtention.js';
|
|
@@ -34,7 +34,7 @@ export * from '../../utils/debug.js';
|
|
|
34
34
|
export * from '../../utils/urlToFile.js';
|
|
35
35
|
export * from '../../utils/getGlobalObject.js';
|
|
36
36
|
export * from '../../utils/freezePartial.js';
|
|
37
|
-
export * from '../../utils/
|
|
37
|
+
export * from '../../utils/parseNpmPackage.js';
|
|
38
38
|
export * from '../../utils/isNullish.js';
|
|
39
39
|
export * from '../../utils/isScriptFile.js';
|
|
40
40
|
export * from '../../utils/removeFileExtention.js';
|
|
@@ -9,6 +9,14 @@ declare global {
|
|
|
9
9
|
*/
|
|
10
10
|
interface Config {
|
|
11
11
|
}
|
|
12
|
+
/** Refine the `pageContext.config` type.
|
|
13
|
+
*
|
|
14
|
+
* It's used for cumulative configs: the `pageContext.config[configName]` type is an `array` whereas `Config[configName]` isn't.
|
|
15
|
+
*
|
|
16
|
+
* https://vike.dev/meta#typescript
|
|
17
|
+
*/
|
|
18
|
+
interface ConfigResolved {
|
|
19
|
+
}
|
|
12
20
|
/** Extend the `PageContext` type (`import type { PageContext } from 'vike/types'`).
|
|
13
21
|
*
|
|
14
22
|
* https://vike.dev/pageContext#typescript
|
|
@@ -27,14 +35,6 @@ declare global {
|
|
|
27
35
|
*/
|
|
28
36
|
interface PageContextServer {
|
|
29
37
|
}
|
|
30
|
-
/** Refine the `pageContext.config` type.
|
|
31
|
-
*
|
|
32
|
-
* It's used for cumulative configs: the `pageContext.config[configName]` type is an `array` whereas `Config[configName]` isn't.
|
|
33
|
-
*
|
|
34
|
-
* https://vike.dev/meta#typescript
|
|
35
|
-
*/
|
|
36
|
-
interface ConfigResolved {
|
|
37
|
-
}
|
|
38
38
|
/** Extend the `GlobalContext` type (`import type { GlobalContext } from 'vike/types'`).
|
|
39
39
|
*
|
|
40
40
|
* https://vike.dev/globalContext#typescript
|
|
@@ -22,7 +22,7 @@ function determineFileType(filePath) {
|
|
|
22
22
|
const isCSS = filePath.endsWith('.css');
|
|
23
23
|
if (isCSS) {
|
|
24
24
|
/* This assert() is skipped to reduce client-side bundle size
|
|
25
|
-
assert(
|
|
25
|
+
assert(isImportPathNpmPackage(filePath), filePath) // `.css` page files are only supported for npm packages
|
|
26
26
|
*/
|
|
27
27
|
return '.css';
|
|
28
28
|
}
|
|
@@ -2,8 +2,8 @@ export { serializeConfigValues };
|
|
|
2
2
|
export { getConfigValuesBase };
|
|
3
3
|
export { isJsonValue };
|
|
4
4
|
import { assertIsNotProductionRuntime } from '../../../utils/assertSetup.js';
|
|
5
|
-
import { assert, assertPosixPath, assertUsage, deepEqual, getPropAccessNotation } from '../../../node/plugin/utils.js';
|
|
6
|
-
import { parsePointerImportData } from '../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/
|
|
5
|
+
import { assert, assertPosixPath, assertUsage, deepEqual, getPropAccessNotation, isImportPathRelative } from '../../../node/plugin/utils.js';
|
|
6
|
+
import { parsePointerImportData } from '../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/pointerImports.js';
|
|
7
7
|
import { getConfigValueFilePathToShowToUser } from '../helpers.js';
|
|
8
8
|
import { stringify } from '@brillout/json-serializer/stringify';
|
|
9
9
|
import pc from '@brillout/picocolors';
|
|
@@ -264,10 +264,10 @@ function addImportStatement(importStatements, importPath, exportName, filesEnv,
|
|
|
264
264
|
return { importName };
|
|
265
265
|
}
|
|
266
266
|
function assertFileEnv(importPath, configEnv, configName, filesEnv) {
|
|
267
|
+
assert(!isImportPathRelative(importPath));
|
|
267
268
|
const key = importPath;
|
|
268
269
|
assert(key);
|
|
269
270
|
assertPosixPath(key);
|
|
270
|
-
assert(!isRelativeImportPath(key));
|
|
271
271
|
if (!filesEnv.has(key)) {
|
|
272
272
|
filesEnv.set(key, []);
|
|
273
273
|
}
|
|
@@ -283,7 +283,3 @@ function assertFileEnv(importPath, configEnv, configName, filesEnv) {
|
|
|
283
283
|
].join('\n'));
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
|
-
// TODO/now dedupe
|
|
287
|
-
function isRelativeImportPath(importPath) {
|
|
288
|
-
return importPath.startsWith('./') || importPath.startsWith('../');
|
|
289
|
-
}
|
|
@@ -19,12 +19,12 @@ import type { AbortStatusCode } from './route/abort.js';
|
|
|
19
19
|
import type { GlobalContextServer } from '../node/runtime/globalContext.js';
|
|
20
20
|
import type { GlobalContextClient } from '../client/client-routing-runtime/globalContext.js';
|
|
21
21
|
import type { GlobalContextClientWithServerRouting } from '../client/server-routing-runtime/globalContext.js';
|
|
22
|
-
type PageContextServer<Data = unknown> = PageContextBuiltInServer<Data> & Vike.PageContext;
|
|
22
|
+
type PageContextServer<Data = unknown> = PageContextBuiltInServer<Data> & Vike.PageContext & Vike.PageContextServer;
|
|
23
23
|
type PageContext<Data = unknown> = PageContextClient<Data> | PageContextServer<Data>;
|
|
24
|
-
type PageContextClient<Data = unknown> = PageContextBuiltInClientWithClientRouting<Data> & Vike.PageContext;
|
|
24
|
+
type PageContextClient<Data = unknown> = PageContextBuiltInClientWithClientRouting<Data> & Vike.PageContext & Vike.PageContextClient;
|
|
25
25
|
type GlobalContext = GlobalContextServer | GlobalContextClient;
|
|
26
26
|
type PageContextWithServerRouting<Data = unknown> = PageContextClientWithServerRouting<Data> | PageContextServer<Data>;
|
|
27
|
-
type PageContextClientWithServerRouting<Data = unknown> = PageContextBuiltInClientWithServerRouting<Data> & Vike.PageContext;
|
|
27
|
+
type PageContextClientWithServerRouting<Data = unknown> = PageContextBuiltInClientWithServerRouting<Data> & Vike.PageContext & Vike.PageContextClient;
|
|
28
28
|
type PageContextBuiltInCommon<Data> = {
|
|
29
29
|
/** The `export { Page }` of your `.page.js` file.
|
|
30
30
|
*
|
|
@@ -139,7 +139,7 @@ type PageContextBuiltInCommon<Data> = {
|
|
|
139
139
|
};
|
|
140
140
|
type PageContextBuiltInServer<Data> = PageContextBuiltInCommon<Data> & PageContextUrlServer & {
|
|
141
141
|
/**
|
|
142
|
-
* Whether the page is being rendered on the client-
|
|
142
|
+
* Whether the page is being rendered on the client- or server-side / pre-rendered.
|
|
143
143
|
*
|
|
144
144
|
* In order to save client-side KBs, we recommend using `import.meta.env.SSR` whenever possible instead, see https://vike.dev/pageContext
|
|
145
145
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.228-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.228-commit-84954ae";
|
|
@@ -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-84954ae';
|
|
@@ -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
|
+
}
|
|
@@ -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
|
+
};
|