vike 0.4.165-commit-6dfef11 → 0.4.165-commit-8eba585
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/buildConfig/fixServerAssets.js +6 -1
- package/dist/cjs/node/plugin/plugins/buildConfig.js +1 -1
- package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +12 -0
- package/dist/cjs/node/plugin/plugins/config/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -2
- package/dist/cjs/node/plugin/plugins/envVars.js +1 -1
- package/dist/cjs/node/plugin/plugins/fileEnv.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +0 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +53 -24
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +6 -6
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getFilePath.js +90 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +5 -24
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +15 -22
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -20
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +21 -20
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +1 -1
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -0
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +26 -24
- package/dist/cjs/node/runtime/renderPage.js +34 -21
- package/dist/cjs/shared/page-configs/FilePath.js +2 -0
- package/dist/cjs/utils/assert.js +2 -0
- package/dist/cjs/utils/assertSingleInstance.js +6 -5
- package/dist/cjs/utils/assertVersion.js +4 -1
- package/dist/cjs/utils/getFilePathAbsolute.js +11 -11
- package/dist/cjs/utils/getGlobalObject.js +21 -6
- package/dist/cjs/utils/isNpmPackage.js +1 -4
- package/dist/cjs/utils/parseUrl.js +1 -1
- package/dist/cjs/utils/projectInfo.js +1 -4
- package/dist/esm/node/plugin/plugins/baseUrls.js +1 -1
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +6 -1
- package/dist/esm/node/plugin/plugins/buildConfig.js +2 -2
- package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +12 -0
- package/dist/esm/node/plugin/plugins/config/index.js +1 -1
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +3 -3
- package/dist/esm/node/plugin/plugins/envVars.js +2 -2
- package/dist/esm/node/plugin/plugins/fileEnv.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +54 -25
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +6 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getFilePath.d.ts +20 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getFilePath.js +84 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +6 -25
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +15 -22
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -20
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +21 -20
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +2 -2
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +26 -24
- package/dist/esm/node/runtime/renderPage.js +34 -21
- package/dist/esm/shared/page-configs/FilePath.d.ts +52 -0
- package/dist/esm/shared/page-configs/FilePath.js +1 -0
- package/dist/esm/shared/page-configs/PageConfig.d.ts +1 -42
- package/dist/esm/utils/assert.js +2 -0
- package/dist/esm/utils/assertSingleInstance.d.ts +2 -2
- package/dist/esm/utils/assertSingleInstance.js +5 -4
- package/dist/esm/utils/assertVersion.js +4 -1
- package/dist/esm/utils/getFilePathAbsolute.d.ts +4 -4
- package/dist/esm/utils/getFilePathAbsolute.js +10 -10
- package/dist/esm/utils/getGlobalObject.d.ts +6 -1
- package/dist/esm/utils/getGlobalObject.js +22 -6
- package/dist/esm/utils/isNpmPackage.d.ts +0 -6
- package/dist/esm/utils/isNpmPackage.js +5 -3
- package/dist/esm/utils/parseUrl.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -4
- package/package.json +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +0 -33
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +0 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +0 -27
|
@@ -3,7 +3,7 @@ import { normalizePath } from 'vite';
|
|
|
3
3
|
import { getConfigVike } from '../../../shared/getConfigVike.js';
|
|
4
4
|
import { getVirtualFilePageConfigValuesAll } from './v1-design/getVirtualFilePageConfigValuesAll.js';
|
|
5
5
|
import { getVirtualFileImportUserCode } from './getVirtualFileImportUserCode.js';
|
|
6
|
-
import { assert, assertPosixPath,
|
|
6
|
+
import { assert, assertPosixPath, getFilePathAbsoluteUserRootDir, getOutDirs, getVirtualFileId, isDev1, isDev1_onConfigureServer, isVirtualFileId, resolveVirtualFileId } from '../../utils.js';
|
|
7
7
|
import { isVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
8
8
|
import { isVirtualFileIdImportUserCode } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
9
9
|
import { vikeConfigDependencies, reloadVikeConfig, isVikeConfigFile } from './v1-design/getVikeConfig.js';
|
|
@@ -118,7 +118,7 @@ function isVikeConfigModule(filePathAbsoluteFilesystem) {
|
|
|
118
118
|
}
|
|
119
119
|
function reloadConfig(filePath, config, op) {
|
|
120
120
|
{
|
|
121
|
-
const filePathToShowToUser = pc.dim(
|
|
121
|
+
const filePathToShowToUser = pc.dim(getFilePathAbsoluteUserRootDir(filePath, config.root, true));
|
|
122
122
|
const msg = `${op} ${filePathToShowToUser}`;
|
|
123
123
|
logConfigInfo(msg, 'info');
|
|
124
124
|
}
|
|
@@ -58,5 +58,5 @@ type ConfigDefinitionInternal = Omit<ConfigDefinition, 'env'> & {
|
|
|
58
58
|
type ConfigDefinitions = Record<string, ConfigDefinitionInternal>;
|
|
59
59
|
type ConfigDefinitionsBuiltIn = Record<ConfigNameBuiltIn, ConfigDefinitionInternal>;
|
|
60
60
|
declare const configDefinitionsBuiltIn: ConfigDefinitionsBuiltIn;
|
|
61
|
-
type ConfigNameGlobal = 'onPrerenderStart' | 'onBeforeRoute' | 'prerender' | '
|
|
61
|
+
type ConfigNameGlobal = 'onPrerenderStart' | 'onBeforeRoute' | 'prerender' | 'disableAutoFullBuild' | 'includeAssetsImportedByServer' | 'baseAssets' | 'baseServer' | 'redirects' | 'trailingSlash' | 'disableUrlNormalization';
|
|
62
62
|
declare const configDefinitionsBuiltInGlobal: Record<ConfigNameGlobal, ConfigDefinitionInternal>;
|
|
@@ -103,7 +103,6 @@ const configDefinitionsBuiltInGlobal = {
|
|
|
103
103
|
prerender: {
|
|
104
104
|
env: { config: true }
|
|
105
105
|
},
|
|
106
|
-
extensions: { env: { config: true } },
|
|
107
106
|
disableAutoFullBuild: { env: { config: true } },
|
|
108
107
|
includeAssetsImportedByServer: { env: { config: true } },
|
|
109
108
|
baseAssets: { env: { config: true } },
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export { crawlPlusFiles };
|
|
2
|
-
import { assertPosixPath, assert, toPosixPath, assertWarning, scriptFileExtensionList, scriptFileExtensions,
|
|
2
|
+
import { assertPosixPath, assert, toPosixPath, assertWarning, scriptFileExtensionList, scriptFileExtensions, humanizeTime, assertIsSingleModuleInstance, assertIsNotProductionRuntime, isVersionOrAbove } from '../../../../utils.js';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import glob from 'fast-glob';
|
|
5
5
|
import { exec } from 'child_process';
|
|
6
6
|
import { promisify } from 'util';
|
|
7
7
|
import pc from '@brillout/picocolors';
|
|
8
8
|
const execA = promisify(exec);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
assertIsNotProductionRuntime();
|
|
10
|
+
assertIsSingleModuleInstance('crawlPlusFiles.ts');
|
|
11
|
+
let gitIsNotUsable = false;
|
|
12
12
|
async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
13
13
|
assertPosixPath(userRootDir);
|
|
14
14
|
assertPosixPath(outDirAbsoluteFilesystem);
|
|
@@ -43,14 +43,14 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
|
43
43
|
const plusFiles = files.map((p) => {
|
|
44
44
|
p = toPosixPath(p);
|
|
45
45
|
assert(!p.startsWith(userRootDir));
|
|
46
|
-
const
|
|
47
|
-
return {
|
|
46
|
+
const filePathAbsoluteUserRootDir = path.posix.join('/', p);
|
|
47
|
+
return { filePathAbsoluteUserRootDir };
|
|
48
48
|
});
|
|
49
49
|
return plusFiles;
|
|
50
50
|
}
|
|
51
51
|
// Same as fastGlob() but using `$ git ls-files`
|
|
52
52
|
async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
53
|
-
if (
|
|
53
|
+
if (gitIsNotUsable)
|
|
54
54
|
return null;
|
|
55
55
|
const ignoreAsPatterns = getIgnoreAsPatterns(outDirRelativeFromUserRootDir);
|
|
56
56
|
const ignoreAsFilterFn = getIgnoreAsFilterFn(outDirRelativeFromUserRootDir);
|
|
@@ -68,14 +68,14 @@ async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
|
68
68
|
;
|
|
69
69
|
[files, filesDeleted] = await Promise.all([
|
|
70
70
|
// Main command
|
|
71
|
-
|
|
71
|
+
runCmd1(cmd, userRootDir),
|
|
72
72
|
// Get tracked by deleted files
|
|
73
|
-
|
|
73
|
+
runCmd1('git ls-files --deleted', userRootDir)
|
|
74
74
|
]);
|
|
75
75
|
}
|
|
76
76
|
catch (err) {
|
|
77
|
-
if (await
|
|
78
|
-
|
|
77
|
+
if (await isGitNotUsable(userRootDir)) {
|
|
78
|
+
gitIsNotUsable = true;
|
|
79
79
|
return null;
|
|
80
80
|
}
|
|
81
81
|
throw err;
|
|
@@ -119,24 +119,53 @@ function getIgnoreAsFilterFn(outDirRelativeFromUserRootDir) {
|
|
|
119
119
|
!file.includes('.telefunc.') &&
|
|
120
120
|
(outDirRelativeFromUserRootDir === null || !file.startsWith(`${outDirRelativeFromUserRootDir}/`));
|
|
121
121
|
}
|
|
122
|
-
// Whether Git is installed and whether
|
|
123
|
-
async function
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
res = await
|
|
122
|
+
// Whether Git is installed and whether we can use it
|
|
123
|
+
async function isGitNotUsable(userRootDir) {
|
|
124
|
+
// Check Git version
|
|
125
|
+
{
|
|
126
|
+
const res = await runCmd2('git --version', userRootDir);
|
|
127
|
+
if ('err' in res)
|
|
128
|
+
return true;
|
|
129
|
+
let { stdout, stderr } = res;
|
|
130
|
+
assert(stderr === '');
|
|
131
|
+
const prefix = 'git version ';
|
|
132
|
+
assert(stdout.startsWith(prefix));
|
|
133
|
+
const gitVersion = stdout.slice(prefix.length);
|
|
134
|
+
// - Works with Git 2.43.1 but also (most certainly) with earlier versions.
|
|
135
|
+
// - We didn't bother test which is the earliest verision that works.
|
|
136
|
+
// - Git 2.32.0 doesn't seem to work: https://github.com/vikejs/vike/discussions/1549
|
|
137
|
+
// - Maybe it's because of StackBlitz: looking at the release notes, Git 2.32.0 should be working.
|
|
138
|
+
if (!isVersionOrAbove(gitVersion, '2.43.1'))
|
|
139
|
+
return true;
|
|
127
140
|
}
|
|
128
|
-
|
|
129
|
-
|
|
141
|
+
// Is userRootDir inside a Git repository?
|
|
142
|
+
{
|
|
143
|
+
const res = await runCmd2('git rev-parse --is-inside-work-tree', userRootDir);
|
|
144
|
+
if ('err' in res)
|
|
145
|
+
return true;
|
|
146
|
+
let { stdout, stderr } = res;
|
|
147
|
+
assert(stderr === '');
|
|
148
|
+
assert(stdout === 'true');
|
|
149
|
+
return false;
|
|
130
150
|
}
|
|
131
|
-
const { stdout, stderr } = res;
|
|
132
|
-
assert(stderr.toString().trim() === '');
|
|
133
|
-
assert(stdout.toString().trim() === 'true');
|
|
134
|
-
return false;
|
|
135
151
|
}
|
|
136
|
-
async function
|
|
137
|
-
const
|
|
152
|
+
async function runCmd1(cmd, cwd) {
|
|
153
|
+
const { stdout } = await execA(cmd, { cwd });
|
|
138
154
|
/* Not always true: https://github.com/vikejs/vike/issues/1440#issuecomment-1892831303
|
|
139
155
|
assert(res.stderr === '')
|
|
140
156
|
*/
|
|
141
|
-
return
|
|
157
|
+
return stdout.toString().split('\n').filter(Boolean);
|
|
158
|
+
}
|
|
159
|
+
async function runCmd2(cmd, cwd) {
|
|
160
|
+
let res;
|
|
161
|
+
try {
|
|
162
|
+
res = await execA(cmd, { cwd });
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
return { err };
|
|
166
|
+
}
|
|
167
|
+
let { stdout, stderr } = res;
|
|
168
|
+
stdout = stdout.toString().trim();
|
|
169
|
+
stderr = stderr.toString().trim();
|
|
170
|
+
return { stdout, stderr };
|
|
142
171
|
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ type LocationId = string & {
|
|
|
39
39
|
*
|
|
40
40
|
* The value `locationId` is always a user-land path, because Filesystem Routing/Inheritance only applies to the user-land (Vike never uses Filesystem Routing/Inheritance for `node_modules/**`).
|
|
41
41
|
*/
|
|
42
|
-
declare function getLocationId(
|
|
42
|
+
declare function getLocationId(filePathAbsoluteUserRootDir: string): LocationId;
|
|
43
43
|
/** Filesystem Routing: get the URL */
|
|
44
44
|
declare function getFilesystemRouteString(locationId: LocationId): string;
|
|
45
45
|
/**
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js
CHANGED
|
@@ -16,10 +16,10 @@ import { assert, assertPosixPath, higherFirst } from '../../../../utils.js';
|
|
|
16
16
|
*/
|
|
17
17
|
function getLocationId(
|
|
18
18
|
// We always determine `locationId` from a real user-land file: the `locationId` for Vike extensions is the `locationId` of the the user's `+config.js` that extends the Vike extension.
|
|
19
|
-
|
|
20
|
-
assertPosixPath(
|
|
21
|
-
assert(
|
|
22
|
-
const locationId = removeFilename(
|
|
19
|
+
filePathAbsoluteUserRootDir) {
|
|
20
|
+
assertPosixPath(filePathAbsoluteUserRootDir);
|
|
21
|
+
assert(filePathAbsoluteUserRootDir.startsWith('/'));
|
|
22
|
+
const locationId = removeFilename(filePathAbsoluteUserRootDir);
|
|
23
23
|
assertLocationId(locationId);
|
|
24
24
|
return locationId;
|
|
25
25
|
}
|
|
@@ -96,8 +96,8 @@ function removeDirectories(somePath, removeDirs) {
|
|
|
96
96
|
somePath = '/';
|
|
97
97
|
return somePath;
|
|
98
98
|
}
|
|
99
|
-
function removeFilename(
|
|
100
|
-
const filePathParts =
|
|
99
|
+
function removeFilename(filePathAbsoluteUserRootDir) {
|
|
100
|
+
const filePathParts = filePathAbsoluteUserRootDir.split('/');
|
|
101
101
|
{
|
|
102
102
|
const filename = filePathParts.slice(-1)[0];
|
|
103
103
|
assert(filename.includes('.'));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { getFilePathResolved };
|
|
2
|
+
export { getFilePathUnresolved };
|
|
3
|
+
import type { FilePath, FilePathResolved } from '../../../../../../shared/page-configs/FilePath.js';
|
|
4
|
+
declare function getFilePathUnresolved(args: {
|
|
5
|
+
filePathAbsoluteFilesystem: string | null;
|
|
6
|
+
filePathAbsoluteUserRootDir: string | null;
|
|
7
|
+
importPathAbsolute: string | null;
|
|
8
|
+
} & ({
|
|
9
|
+
filePathAbsoluteUserRootDir: string;
|
|
10
|
+
} | {
|
|
11
|
+
importPathAbsolute: string;
|
|
12
|
+
})): FilePath;
|
|
13
|
+
declare function getFilePathResolved(args: {
|
|
14
|
+
userRootDir: string;
|
|
15
|
+
importPathAbsolute: string | null;
|
|
16
|
+
} & ({
|
|
17
|
+
filePathAbsoluteFilesystem: string;
|
|
18
|
+
} | {
|
|
19
|
+
filePathAbsoluteUserRootDir: string;
|
|
20
|
+
})): FilePathResolved;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export { getFilePathResolved };
|
|
2
|
+
export { getFilePathUnresolved };
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { assert, assertPosixPath, hasProp } from '../../../../utils.js';
|
|
5
|
+
function getFilePathUnresolved(args) {
|
|
6
|
+
const { filePathAbsoluteFilesystem, filePathAbsoluteUserRootDir } = args;
|
|
7
|
+
let filePathAbsoluteVite;
|
|
8
|
+
if (args.filePathAbsoluteUserRootDir !== null) {
|
|
9
|
+
filePathAbsoluteVite = args.filePathAbsoluteUserRootDir;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
assert(args.importPathAbsolute !== null); // Help TS
|
|
13
|
+
filePathAbsoluteVite = args.importPathAbsolute;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
...args,
|
|
17
|
+
filePathAbsoluteVite,
|
|
18
|
+
filePathToShowToUser: filePathAbsoluteVite,
|
|
19
|
+
filePathToShowToUserResolved: filePathAbsoluteUserRootDir || filePathAbsoluteFilesystem
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function getFilePathResolved(args) {
|
|
23
|
+
const { userRootDir, importPathAbsolute } = args;
|
|
24
|
+
let filePathAbsoluteFilesystem;
|
|
25
|
+
let filePathAbsoluteUserRootDir;
|
|
26
|
+
if ('filePathAbsoluteFilesystem' in args) {
|
|
27
|
+
filePathAbsoluteFilesystem = args.filePathAbsoluteFilesystem;
|
|
28
|
+
filePathAbsoluteUserRootDir = getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir });
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
filePathAbsoluteUserRootDir = args.filePathAbsoluteUserRootDir;
|
|
32
|
+
filePathAbsoluteFilesystem = getFilePathAbsoluteUserFilesystem({ filePathAbsoluteUserRootDir, userRootDir });
|
|
33
|
+
}
|
|
34
|
+
let filePathResolved;
|
|
35
|
+
const common = {
|
|
36
|
+
filePathAbsoluteUserRootDir,
|
|
37
|
+
filePathAbsoluteFilesystem,
|
|
38
|
+
importPathAbsolute,
|
|
39
|
+
userRootDir
|
|
40
|
+
};
|
|
41
|
+
if (importPathAbsolute) {
|
|
42
|
+
filePathResolved = getFilePathUnresolved({
|
|
43
|
+
...common,
|
|
44
|
+
importPathAbsolute
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
assert(filePathAbsoluteUserRootDir);
|
|
49
|
+
filePathResolved = getFilePathUnresolved({
|
|
50
|
+
...common,
|
|
51
|
+
filePathAbsoluteUserRootDir
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
assert(filePathAbsoluteFilesystem);
|
|
55
|
+
assert(hasProp(filePathResolved, 'filePathAbsoluteFilesystem', 'string'));
|
|
56
|
+
assert(hasProp(filePathResolved, 'filePathToShowToUserResolved', 'string'));
|
|
57
|
+
return filePathResolved;
|
|
58
|
+
}
|
|
59
|
+
function getFilePathAbsoluteUserFilesystem({ filePathAbsoluteUserRootDir, userRootDir }) {
|
|
60
|
+
assertPosixPath(filePathAbsoluteUserRootDir);
|
|
61
|
+
assertPosixPath(userRootDir);
|
|
62
|
+
const filePathAbsoluteFilesystem = path.posix.join(userRootDir, filePathAbsoluteUserRootDir);
|
|
63
|
+
return filePathAbsoluteFilesystem;
|
|
64
|
+
}
|
|
65
|
+
function getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir }) {
|
|
66
|
+
assertPosixPath(filePathAbsoluteFilesystem);
|
|
67
|
+
assertPosixPath(userRootDir);
|
|
68
|
+
let filePathAbsoluteUserRootDir = null;
|
|
69
|
+
if (filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
70
|
+
{
|
|
71
|
+
let filePathAbsoluteUserRootDir1 = filePathAbsoluteFilesystem.slice(userRootDir.length);
|
|
72
|
+
if (!filePathAbsoluteUserRootDir1.startsWith('/'))
|
|
73
|
+
filePathAbsoluteUserRootDir1 = '/' + filePathAbsoluteUserRootDir1;
|
|
74
|
+
filePathAbsoluteUserRootDir = filePathAbsoluteUserRootDir1;
|
|
75
|
+
}
|
|
76
|
+
{
|
|
77
|
+
let filePathAbsoluteUserRootDir2 = path.posix.relative(userRootDir, filePathAbsoluteFilesystem);
|
|
78
|
+
assert(!filePathAbsoluteUserRootDir2.startsWith('.') && !filePathAbsoluteUserRootDir2.startsWith('/'));
|
|
79
|
+
filePathAbsoluteUserRootDir2 = '/' + filePathAbsoluteUserRootDir2;
|
|
80
|
+
assert(filePathAbsoluteFilesystem === filePathAbsoluteUserRootDir2);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return filePathAbsoluteUserRootDir;
|
|
84
|
+
}
|
|
@@ -3,7 +3,7 @@ export { loadValueFile };
|
|
|
3
3
|
export { loadConfigFile };
|
|
4
4
|
export type { ImportedFilesLoaded };
|
|
5
5
|
export type { ConfigFile };
|
|
6
|
-
import type { FilePathResolved } from '../../../../../../shared/page-configs/
|
|
6
|
+
import type { FilePathResolved } from '../../../../../../shared/page-configs/FilePath.js';
|
|
7
7
|
import type { InterfaceValueFile } from '../getVikeConfig.js';
|
|
8
8
|
type ImportedFilesLoaded = Record<string, Promise<Record<string, unknown>>>;
|
|
9
9
|
type ConfigFile = {
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
export { loadImportedFile };
|
|
3
3
|
export { loadValueFile };
|
|
4
4
|
export { loadConfigFile };
|
|
5
|
-
import {
|
|
5
|
+
import { assert, assertUsage, assertWarning, hasProp, assertIsNotProductionRuntime, isNpmPackageImport } from '../../../../utils.js';
|
|
6
6
|
import { transpileAndExecuteFile } from './transpileAndExecuteFile.js';
|
|
7
7
|
import { assertPlusFileExport } from '../../../../../../shared/page-configs/assertPlusFileExport.js';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
9
|
import { parseImportData } from './transformFileImports.js';
|
|
10
10
|
import { getConfigFileExport } from '../getConfigFileExport.js';
|
|
11
11
|
import { assertImportPath, resolveImportPath } from './resolveImportPath.js';
|
|
12
|
+
import { getFilePathResolved } from './getFilePath.js';
|
|
12
13
|
assertIsNotProductionRuntime();
|
|
13
14
|
// Load fake import
|
|
14
15
|
async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
|
|
@@ -58,21 +59,12 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
58
59
|
const extendsImportData = getExtendsImportData(configFileExports, configFilePath);
|
|
59
60
|
const extendsConfigFiles = [];
|
|
60
61
|
extendsImportData.map((importData) => {
|
|
61
|
-
const { importPath:
|
|
62
|
+
const { importPath: importPathAbsolute } = importData;
|
|
62
63
|
const filePathAbsoluteFilesystem = resolveImportPath(importData, configFilePath);
|
|
63
64
|
assertImportPath(filePathAbsoluteFilesystem, importData, configFilePath);
|
|
64
|
-
warnUserLandExtension(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const filePathRelativeToUserRootDir = determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir);
|
|
68
|
-
const filePathAbsoluteVite = filePathRelativeToUserRootDir ?? importPath;
|
|
69
|
-
extendsConfigFiles.push({
|
|
70
|
-
filePathAbsoluteFilesystem,
|
|
71
|
-
filePathAbsoluteVite,
|
|
72
|
-
filePathRelativeToUserRootDir,
|
|
73
|
-
filePathToShowToUser: filePathAbsoluteVite,
|
|
74
|
-
importPathAbsolute: importPath
|
|
75
|
-
});
|
|
65
|
+
warnUserLandExtension(importPathAbsolute, configFilePath);
|
|
66
|
+
const filePath = getFilePathResolved({ filePathAbsoluteFilesystem, userRootDir, importPathAbsolute });
|
|
67
|
+
extendsConfigFiles.push(filePath);
|
|
76
68
|
});
|
|
77
69
|
const extendsConfigs = [];
|
|
78
70
|
await Promise.all(extendsConfigFiles.map(async (configFilePath) => {
|
|
@@ -83,17 +75,6 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
83
75
|
const extendsFilePaths = extendsConfigFiles.map((f) => f.filePathAbsoluteFilesystem);
|
|
84
76
|
return { extendsConfigs, extendsFilePaths };
|
|
85
77
|
}
|
|
86
|
-
function determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir) {
|
|
87
|
-
assertPosixPath(filePathAbsoluteFilesystem);
|
|
88
|
-
assertPosixPath(userRootDir);
|
|
89
|
-
if (!filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
let filePathRelativeToUserRootDir = filePathAbsoluteFilesystem.slice(userRootDir.length);
|
|
93
|
-
if (!filePathRelativeToUserRootDir.startsWith('/'))
|
|
94
|
-
filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir;
|
|
95
|
-
return filePathRelativeToUserRootDir;
|
|
96
|
-
}
|
|
97
78
|
function warnUserLandExtension(importPath, configFilePath) {
|
|
98
79
|
assertWarning(isNpmPackageImport(importPath), `${configFilePath.filePathToShowToUser} uses ${pc.cyan('extends')} to inherit from ${pc.cyan(importPath)} which is a user-land file: this is experimental and may be remove at any time. Reach out to a maintainer if you need this.`, { onlyOnce: true });
|
|
99
80
|
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ export { resolveImport };
|
|
|
2
2
|
export { resolveImportPath };
|
|
3
3
|
export { assertImportPath };
|
|
4
4
|
export { clearFilesEnvMap };
|
|
5
|
-
import type { ConfigEnvInternal, DefinedAtFileFullInfo
|
|
5
|
+
import type { ConfigEnvInternal, DefinedAtFileFullInfo } from '../../../../../../shared/page-configs/PageConfig.js';
|
|
6
6
|
import { type ImportData } from './transformFileImports.js';
|
|
7
|
+
import type { FilePathResolved } from '../../../../../../shared/page-configs/FilePath.js';
|
|
7
8
|
declare function resolveImport(configValue: unknown, importerFilePath: FilePathResolved, userRootDir: string, configEnv: ConfigEnvInternal, configName: string): null | (DefinedAtFileFullInfo & {
|
|
8
9
|
fileExportName: string;
|
|
9
10
|
});
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js
CHANGED
|
@@ -6,6 +6,7 @@ import pc from '@brillout/picocolors';
|
|
|
6
6
|
import { assert, assertPosixPath, assertUsage, deepEqual, requireResolve } from '../../../../utils.js';
|
|
7
7
|
import { parseImportData } from './transformFileImports.js';
|
|
8
8
|
import path from 'path';
|
|
9
|
+
import { getFilePathResolved, getFilePathUnresolved } from './getFilePath.js';
|
|
9
10
|
const filesEnvMap = new Map();
|
|
10
11
|
function resolveImport(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
11
12
|
if (typeof configValue !== 'string')
|
|
@@ -23,14 +24,8 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
|
|
|
23
24
|
// [vite] Internal server error: Failed to resolve import "./onPageTransitionHooks" from "virtual:vike:pageConfigValuesAll:client:/pages/index". Does the file exist?
|
|
24
25
|
// ```
|
|
25
26
|
assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath);
|
|
26
|
-
const
|
|
27
|
-
const filePath = {
|
|
28
|
-
filePathAbsoluteFilesystem,
|
|
29
|
-
filePathRelativeToUserRootDir,
|
|
30
|
-
filePathAbsoluteVite: filePathRelativeToUserRootDir,
|
|
31
|
-
filePathToShowToUser: filePathRelativeToUserRootDir,
|
|
32
|
-
importPathAbsolute: null
|
|
33
|
-
};
|
|
27
|
+
const filePathAbsoluteUserRootDir = resolveImportPath_absoluteUserRootDir(filePathAbsoluteFilesystem, importData, importerFilePath, userRootDir);
|
|
28
|
+
const filePath = getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir, importPathAbsolute: null });
|
|
34
29
|
return {
|
|
35
30
|
...filePath,
|
|
36
31
|
fileExportName: exportName,
|
|
@@ -41,13 +36,11 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
|
|
|
41
36
|
// importPath can be:
|
|
42
37
|
// - an npm package import
|
|
43
38
|
// - a path alias
|
|
44
|
-
const filePath = {
|
|
39
|
+
const filePath = getFilePathUnresolved({
|
|
45
40
|
filePathAbsoluteFilesystem,
|
|
46
|
-
|
|
47
|
-
filePathAbsoluteVite: importPath,
|
|
48
|
-
filePathToShowToUser: importPath,
|
|
41
|
+
filePathAbsoluteUserRootDir: null,
|
|
49
42
|
importPathAbsolute: importPath
|
|
50
|
-
};
|
|
43
|
+
});
|
|
51
44
|
return {
|
|
52
45
|
...filePath,
|
|
53
46
|
fileExportName: exportName,
|
|
@@ -55,11 +48,11 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
|
|
|
55
48
|
};
|
|
56
49
|
}
|
|
57
50
|
}
|
|
58
|
-
function
|
|
51
|
+
function resolveImportPath_absoluteUserRootDir(filePathAbsoluteFilesystem, importData, configFilePath, userRootDir) {
|
|
59
52
|
assertPosixPath(userRootDir);
|
|
60
|
-
let
|
|
53
|
+
let filePathAbsoluteUserRootDir;
|
|
61
54
|
if (filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
62
|
-
|
|
55
|
+
filePathAbsoluteUserRootDir = getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, userRootDir);
|
|
63
56
|
}
|
|
64
57
|
else {
|
|
65
58
|
assertUsage(false, `${configFilePath.filePathToShowToUser} imports from a relative path ${pc.cyan(importData.importPath)} outside of ${userRootDir} which is forbidden: import from a relative path inside ${userRootDir}, or import from a dependency's package.json#exports entry instead`);
|
|
@@ -68,14 +61,14 @@ function resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, imp
|
|
|
68
61
|
// assert(filePathAbsoluteFilesystem.startsWith('/'))
|
|
69
62
|
// filePath = `/@fs${filePathAbsoluteFilesystem}`
|
|
70
63
|
// /*/
|
|
71
|
-
//
|
|
72
|
-
// assert(
|
|
73
|
-
//
|
|
64
|
+
// filePathAbsoluteUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem)
|
|
65
|
+
// assert(filePathAbsoluteUserRootDir.startsWith('../'))
|
|
66
|
+
// filePathAbsoluteUserRootDir = '/' + filePathAbsoluteUserRootDir
|
|
74
67
|
// //*/
|
|
75
68
|
}
|
|
76
|
-
assertPosixPath(
|
|
77
|
-
assert(
|
|
78
|
-
return
|
|
69
|
+
assertPosixPath(filePathAbsoluteUserRootDir);
|
|
70
|
+
assert(filePathAbsoluteUserRootDir.startsWith('/'));
|
|
71
|
+
return filePathAbsoluteUserRootDir;
|
|
79
72
|
}
|
|
80
73
|
function resolveImportPath(importData, importerFilePath) {
|
|
81
74
|
const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
|
|
@@ -3,7 +3,7 @@ export { getConfigBuildErrorFormatted };
|
|
|
3
3
|
export { getConfigExecutionErrorIntroMsg };
|
|
4
4
|
export { isTmpFile };
|
|
5
5
|
import 'source-map-support/register.js';
|
|
6
|
-
import type { FilePathResolved } from '../../../../../../shared/page-configs/
|
|
6
|
+
import type { FilePathResolved } from '../../../../../../shared/page-configs/FilePath.js';
|
|
7
7
|
declare function transpileAndExecuteFile(filePath: FilePathResolved, userRootDir: string, isConfigFile: boolean | 'is-extension-config'): Promise<{
|
|
8
8
|
fileExports: Record<string, unknown>;
|
|
9
9
|
}>;
|
|
@@ -14,13 +14,12 @@ import 'source-map-support/register.js';
|
|
|
14
14
|
assertIsNotProductionRuntime();
|
|
15
15
|
const debug = createDebugger('vike:pointer-imports');
|
|
16
16
|
async function transpileAndExecuteFile(filePath, userRootDir, isConfigFile) {
|
|
17
|
-
const { filePathAbsoluteFilesystem } = filePath;
|
|
17
|
+
const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
|
|
18
18
|
const fileExtension = getFileExtension(filePathAbsoluteFilesystem);
|
|
19
|
-
|
|
20
|
-
assertUsage(isJavaScriptFile(filePathAbsoluteFilesystem), `${filePathToShowToUser2} has file extension .${fileExtension} but a config file can only be a JavaScript/TypeScript file`);
|
|
19
|
+
assertUsage(isJavaScriptFile(filePathAbsoluteFilesystem), `${filePathToShowToUserResolved} has file extension .${fileExtension} but a config file can only be a JavaScript/TypeScript file`);
|
|
21
20
|
const isHeader = isHeaderFile(filePathAbsoluteFilesystem);
|
|
22
21
|
if (isHeader) {
|
|
23
|
-
assertWarning(false, `${pc.cyan('.h.js')} files are deprecated: simply renaming ${
|
|
22
|
+
assertWarning(false, `${pc.cyan('.h.js')} files are deprecated: simply renaming ${filePathToShowToUserResolved} to ${removeHeaderFileExtension(filePathToShowToUserResolved)} is usually enough, although you may occasionally need to use ${pc.cyan("with { type: 'pointer' }")} as explained at https://vike.dev/config#pointer-imports`, { onlyOnce: true });
|
|
24
23
|
}
|
|
25
24
|
if (isConfigFile === 'is-extension-config' && !isHeader && fileExtension.endsWith('js')) {
|
|
26
25
|
// This doesn't track dependencies => we should never use this for user land configs
|
|
@@ -35,28 +34,27 @@ async function transpileAndExecuteFile(filePath, userRootDir, isConfigFile) {
|
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
36
|
async function transpileFile(filePath, transformImports, userRootDir) {
|
|
38
|
-
const
|
|
39
|
-
const { filePathAbsoluteFilesystem } = filePath;
|
|
37
|
+
const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
|
|
40
38
|
assertPosixPath(filePathAbsoluteFilesystem);
|
|
41
39
|
vikeConfigDependencies.add(filePathAbsoluteFilesystem);
|
|
42
40
|
if (debug.isEnabled)
|
|
43
|
-
debug('transpile',
|
|
41
|
+
debug('transpile', filePathToShowToUserResolved);
|
|
44
42
|
let { code, pointerImports } = await transpileWithEsbuild(filePath, userRootDir, transformImports);
|
|
45
43
|
if (debug.isEnabled)
|
|
46
|
-
debug(`code, post esbuild (${
|
|
44
|
+
debug(`code, post esbuild (${filePathToShowToUserResolved})`, code);
|
|
47
45
|
let isImportTransformed = false;
|
|
48
46
|
if (transformImports) {
|
|
49
|
-
const codeMod = transformFileImports(code,
|
|
47
|
+
const codeMod = transformFileImports(code, filePathToShowToUserResolved, pointerImports);
|
|
50
48
|
if (codeMod) {
|
|
51
49
|
code = codeMod;
|
|
52
50
|
isImportTransformed = true;
|
|
53
51
|
if (debug.isEnabled)
|
|
54
|
-
debug(`code, post transformImports() (${
|
|
52
|
+
debug(`code, post transformImports() (${filePathToShowToUserResolved})`, code);
|
|
55
53
|
}
|
|
56
54
|
}
|
|
57
55
|
if (!isImportTransformed) {
|
|
58
56
|
if (debug.isEnabled)
|
|
59
|
-
debug(`code, no transformImports() (${
|
|
57
|
+
debug(`code, no transformImports() (${filePathToShowToUserResolved})`);
|
|
60
58
|
}
|
|
61
59
|
return code;
|
|
62
60
|
}
|
|
@@ -292,19 +290,12 @@ function triggerPrepareStackTrace(err) {
|
|
|
292
290
|
}
|
|
293
291
|
}
|
|
294
292
|
function getErrIntroMsg(operation, filePath) {
|
|
295
|
-
const
|
|
293
|
+
const { filePathToShowToUserResolved } = filePath;
|
|
296
294
|
const msg = [
|
|
297
295
|
// prettier ignore
|
|
298
296
|
pc.red(`Failed to ${operation}`),
|
|
299
|
-
pc.bold(pc.red(
|
|
297
|
+
pc.bold(pc.red(filePathToShowToUserResolved)),
|
|
300
298
|
pc.red(`because:`)
|
|
301
299
|
].join(' ');
|
|
302
300
|
return msg;
|
|
303
301
|
}
|
|
304
|
-
/** `filePath.filePathToShowToUser` may show the import path of a package, use `filePathToShowToUser2` instead always show a file path instead. */
|
|
305
|
-
function getFilePathToShowToUser2(filePath) {
|
|
306
|
-
const { filePathAbsoluteFilesystem, filePathRelativeToUserRootDir } = filePath;
|
|
307
|
-
const filePathToShowToUser2 = filePathRelativeToUserRootDir || filePathAbsoluteFilesystem;
|
|
308
|
-
assert(filePathToShowToUser2);
|
|
309
|
-
return filePathToShowToUser2;
|
|
310
|
-
}
|
|
@@ -5,9 +5,10 @@ export { isVikeConfigFile };
|
|
|
5
5
|
export { isV1Design };
|
|
6
6
|
export type { VikeConfigObject };
|
|
7
7
|
export type { InterfaceValueFile };
|
|
8
|
-
import type { PageConfigGlobalBuildTime, PageConfigBuildTime
|
|
8
|
+
import type { PageConfigGlobalBuildTime, PageConfigBuildTime } from '../../../../../shared/page-configs/PageConfig.js';
|
|
9
9
|
import { type LocationId } from './getVikeConfig/filesystemRouting.js';
|
|
10
10
|
import type { ResolvedConfig } from 'vite';
|
|
11
|
+
import type { FilePathResolved } from '../../../../../shared/page-configs/FilePath.js';
|
|
11
12
|
type InterfaceFileCommons = {
|
|
12
13
|
locationId: LocationId;
|
|
13
14
|
filePath: FilePathResolved;
|
|
@@ -28,6 +29,6 @@ type VikeConfigObject = {
|
|
|
28
29
|
};
|
|
29
30
|
declare const vikeConfigDependencies: Set<string>;
|
|
30
31
|
declare function reloadVikeConfig(userRootDir: string, outDirRoot: string): void;
|
|
31
|
-
declare function getVikeConfig(config: ResolvedConfig, isDev: boolean, tolerateInvalidConfig?:
|
|
32
|
+
declare function getVikeConfig(config: ResolvedConfig, isDev: boolean, tolerateInvalidConfig?: true): Promise<VikeConfigObject>;
|
|
32
33
|
declare function isV1Design(config: ResolvedConfig, isDev: boolean): Promise<boolean>;
|
|
33
34
|
declare function isVikeConfigFile(filePath: string): boolean;
|