vike 0.4.228-commit-4bed128 → 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/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/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/getPageFiles/fileTypes.js +1 -1
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +3 -7
- package/dist/esm/shared/types.d.ts +1 -1
- 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
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);
|
|
@@ -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';
|
|
@@ -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
|
-
}
|
|
@@ -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
|
+
};
|
|
@@ -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, importerFile, userRootDir }: {
|
|
7
|
+
importPath: string;
|
|
8
|
+
importerFile: 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;
|