vike 0.4.227-commit-710dcb6 → 0.4.227-commit-77128be
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/build/pluginBuildConfig.js +3 -5
- package/dist/cjs/node/plugin/plugins/build/pluginBuildEntry.js +3 -6
- package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +8 -9
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +1 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +25 -19
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +0 -1
- package/dist/cjs/node/plugin/shared/resolveClientEntriesDev.js +11 -10
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +0 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/findPackageJson.js +2 -2
- package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +1 -1
- package/dist/cjs/utils/isNpmPackage.js +1 -1
- package/dist/cjs/utils/requireResolve.js +25 -25
- package/dist/esm/node/plugin/plugins/build/pluginBuildConfig.js +2 -4
- package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.js +2 -5
- package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.js +7 -8
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +2 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +26 -20
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +0 -1
- package/dist/esm/node/plugin/shared/resolveClientEntriesDev.js +10 -9
- package/dist/esm/node/runtime/renderPage/analyzePage.js +0 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +1 -1
- package/dist/esm/utils/isNpmPackage.js +1 -1
- package/dist/esm/utils/requireResolve.d.ts +7 -5
- package/dist/esm/utils/requireResolve.js +23 -23
- package/package.json +1 -1
|
@@ -9,16 +9,14 @@ const getVikeConfig_js_1 = require("../importUserCode/v1-design/getVikeConfig.js
|
|
|
9
9
|
const findPageFiles_js_1 = require("../../shared/findPageFiles.js");
|
|
10
10
|
const virtualFilePageConfigValuesAll_js_1 = require("../../../shared/virtual-files/virtualFilePageConfigValuesAll.js");
|
|
11
11
|
const extractAssetsQuery_js_1 = require("../../../shared/extractAssetsQuery.js");
|
|
12
|
-
const module_1 = require("module");
|
|
13
12
|
const prependEntriesDir_js_1 = require("../../../shared/prependEntriesDir.js");
|
|
14
13
|
const getFilePath_js_1 = require("../../shared/getFilePath.js");
|
|
15
14
|
const getConfigValueBuildTime_js_1 = require("../../../../shared/page-configs/getConfigValueBuildTime.js");
|
|
16
15
|
const isViteServerBuild_js_1 = require("../../shared/isViteServerBuild.js");
|
|
17
16
|
const getOutDirs_js_1 = require("../../shared/getOutDirs.js");
|
|
18
17
|
const handleAssetsManifest_js_1 = require("./handleAssetsManifest.js");
|
|
19
|
-
// @ts-ignore `file
|
|
20
|
-
const importMetaUrl = `file
|
|
21
|
-
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
18
|
+
// @ts-ignore `file:///${__filename.split('\\').join('/')}` is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
19
|
+
const importMetaUrl = `file:///${__filename.split('\\').join('/')}`;
|
|
22
20
|
const manifestTempFile = '_temp_manifest.json';
|
|
23
21
|
exports.manifestTempFile = manifestTempFile;
|
|
24
22
|
function pluginBuildConfig() {
|
|
@@ -200,7 +198,7 @@ function getEntryFromPageConfig(pageConfig, isForClientSide) {
|
|
|
200
198
|
function resolve(filePath) {
|
|
201
199
|
(0, utils_js_1.assert)(filePath.startsWith('dist/'));
|
|
202
200
|
// [RELATIVE_PATH_FROM_DIST] Current directory: node_modules/vike/dist/esm/node/plugin/plugins/build/
|
|
203
|
-
return
|
|
201
|
+
return (0, utils_js_1.requireResolveNonUserFile)(`../../../../../../${filePath}`, importMetaUrl);
|
|
204
202
|
}
|
|
205
203
|
function addLogHook() {
|
|
206
204
|
const tty = process.stdout.isTTY && !process.env.CI; // Equals https://github.com/vitejs/vite/blob/193d55c7b9cbfec5b79ebfca276d4a721e7de14d/packages/vite/src/node/plugins/reporter.ts#L27
|
|
@@ -10,10 +10,8 @@ const virtualFileImportUserCode_js_1 = require("../../../shared/virtual-files/vi
|
|
|
10
10
|
const utils_js_1 = require("../../utils.js");
|
|
11
11
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
12
12
|
const path_1 = __importDefault(require("path"));
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const importMetaUrl = `file://${__filename.split('\\').join('/')}`;
|
|
16
|
-
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
13
|
+
// @ts-ignore `file:///${__filename.split('\\').join('/')}` is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
14
|
+
const importMetaUrl = `file:///${__filename.split('\\').join('/')}`;
|
|
17
15
|
const extractExportNamesPlugin_js_1 = require("../extractExportNamesPlugin.js");
|
|
18
16
|
const globalContext_js_1 = require("../../../runtime/globalContext.js");
|
|
19
17
|
const getOutDirs_js_1 = require("../../shared/getOutDirs.js");
|
|
@@ -92,9 +90,8 @@ function find_ASSETS_MANIFEST(bundle) {
|
|
|
92
90
|
}
|
|
93
91
|
function getImportPath(config) {
|
|
94
92
|
// We resolve filePathAbsolute even if we don't use it: we use require.resolve() as an assertion that the relative path is correct
|
|
95
|
-
const filePathAbsolute = (0, utils_js_1.toPosixPath)(
|
|
96
93
|
// [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/plugins/pluginBuildEntry/index.js
|
|
97
|
-
|
|
94
|
+
const filePathAbsolute = (0, utils_js_1.requireResolveNonUserFile)(`../../../../../../dist/esm/__internal/index.js`, importMetaUrl);
|
|
98
95
|
if (
|
|
99
96
|
// Let's implement a new config if a user needs the import to be a relative path instead of 'vike/__internal' (AFAIK a relative path is needed only if a framework has npm package 'vike' as direct dependency instead of a peer dependency and if the user of that framework uses pnpm)
|
|
100
97
|
true) {
|
|
@@ -5,15 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.determineFsAllowList = determineFsAllowList;
|
|
7
7
|
const vite_1 = require("vite");
|
|
8
|
-
const
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const utils_js_1 = require("../../utils.js");
|
|
10
|
-
const module_1 = require("module");
|
|
11
|
-
const path_2 = require("path");
|
|
12
10
|
const url_1 = require("url");
|
|
13
|
-
// @ts-ignore `file
|
|
14
|
-
const importMetaUrl = `file
|
|
15
|
-
|
|
16
|
-
const __dirname_ =
|
|
11
|
+
// @ts-ignore `file:///${__filename.split('\\').join('/')}` is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
12
|
+
const importMetaUrl = `file:///${__filename.split('\\').join('/')}`;
|
|
13
|
+
(0, utils_js_1.assertPosixPath)(importMetaUrl);
|
|
14
|
+
const __dirname_ = node_path_1.default.posix.dirname((0, url_1.fileURLToPath)(importMetaUrl));
|
|
15
|
+
(0, utils_js_1.assertPosixPath)(__dirname_);
|
|
17
16
|
async function determineFsAllowList(config) {
|
|
18
17
|
const fsAllow = config.server.fs.allow;
|
|
19
18
|
// fsAllow should already contain searchForWorkspaceRoot()
|
|
@@ -26,9 +25,9 @@ async function determineFsAllowList(config) {
|
|
|
26
25
|
// Add node_modules/vike/
|
|
27
26
|
{
|
|
28
27
|
// [RELATIVE_PATH_FROM_DIST] Current directory: node_modules/vike/dist/esm/node/plugin/plugins/config/
|
|
29
|
-
const vikeRoot =
|
|
28
|
+
const vikeRoot = node_path_1.default.posix.join(__dirname_, '../../../../../../');
|
|
30
29
|
// Assert that `vikeRoot` is indeed pointing to `node_modules/vike/`
|
|
31
|
-
|
|
30
|
+
(0, utils_js_1.requireResolveNonUserFile)(`${vikeRoot}/dist/esm/node/plugin/plugins/devConfig/index.js`, importMetaUrl);
|
|
32
31
|
fsAllow.push(vikeRoot);
|
|
33
32
|
}
|
|
34
33
|
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
CHANGED
|
@@ -77,10 +77,8 @@ function resolveImportPathWithNode(pointerImportData, importerFilePath) {
|
|
|
77
77
|
const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
|
|
78
78
|
(0, utils_js_1.assertPosixPath)(importerFilePathAbsolute);
|
|
79
79
|
const cwd = path_1.default.posix.dirname(importerFilePathAbsolute);
|
|
80
|
-
// We still can't use import.meta.resolve() as of 23.1.0 (November 2024) because `parent` argument requires an experimental flag.
|
|
81
|
-
// - https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment139581675_62272600
|
|
82
80
|
// filePathAbsoluteFilesystem is expected to be null when pointerImportData.importPath is a Vite path alias
|
|
83
|
-
const filePathAbsoluteFilesystem = (0, utils_js_1.
|
|
81
|
+
const filePathAbsoluteFilesystem = (0, utils_js_1.requireResolveOptional)(pointerImportData.importPath, cwd);
|
|
84
82
|
return filePathAbsoluteFilesystem;
|
|
85
83
|
}
|
|
86
84
|
function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath) {
|
|
@@ -16,10 +16,6 @@ const utils_js_1 = require("../../../../utils.js");
|
|
|
16
16
|
const transformPointerImports_js_1 = require("./transformPointerImports.js");
|
|
17
17
|
const source_map_support_1 = __importDefault(require("source-map-support"));
|
|
18
18
|
const getFilePath_js_1 = require("../../../../shared/getFilePath.js");
|
|
19
|
-
const module_1 = require("module");
|
|
20
|
-
// @ts-ignore `file://${__filename.split('\\').join('/')}` is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
21
|
-
const importMetaUrl = `file://${__filename.split('\\').join('/')}`;
|
|
22
|
-
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
23
19
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
24
20
|
installSourceMapSupport();
|
|
25
21
|
const debug = (0, utils_js_1.createDebugger)('vike:pointer-imports');
|
|
@@ -115,8 +111,6 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
115
111
|
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
116
112
|
if (args.kind !== 'import-statement')
|
|
117
113
|
return;
|
|
118
|
-
if (debugEsbuildResolve.isActivated)
|
|
119
|
-
debugEsbuildResolve('args', args);
|
|
120
114
|
// Avoid infinite loop: https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
|
|
121
115
|
const useEsbuildResolver = 'useEsbuildResolver';
|
|
122
116
|
if (args.pluginData?.[useEsbuildResolver])
|
|
@@ -124,17 +118,15 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
124
118
|
const { path, ...opts } = args;
|
|
125
119
|
opts.pluginData = { [useEsbuildResolver]: true };
|
|
126
120
|
let resolved = await build.resolve(path, opts);
|
|
121
|
+
if (debugEsbuildResolve.isActivated)
|
|
122
|
+
debugEsbuildResolve('args', args);
|
|
127
123
|
if (debugEsbuildResolve.isActivated)
|
|
128
124
|
debugEsbuildResolve('resolved', resolved);
|
|
129
125
|
// Temporary workaround for https://github.com/evanw/esbuild/issues/3973
|
|
130
126
|
// - Sitll required for esbuild@0.24.0 (November 2024).
|
|
131
127
|
// - Let's try to remove this workaround again later.
|
|
132
128
|
if (resolved.errors.length > 0) {
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
resolvedWithNode = require_.resolve(path, { paths: [args.resolveDir] });
|
|
136
|
-
}
|
|
137
|
-
catch { }
|
|
129
|
+
const resolvedWithNode = (0, utils_js_1.requireResolveOptional)(path, args.resolveDir);
|
|
138
130
|
if (debugEsbuildResolve.isActivated)
|
|
139
131
|
debugEsbuildResolve('resolvedWithNode', resolvedWithNode);
|
|
140
132
|
if (resolvedWithNode)
|
|
@@ -168,11 +160,25 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
168
160
|
// - vike@0.4.162 started soft-requiring Vike extensions to set the name config.
|
|
169
161
|
// - In practice, it seems like it requires some (non-trivial?) refactoring.
|
|
170
162
|
isVikeExtensionImport;
|
|
171
|
-
// Externalize npm package imports
|
|
172
163
|
(0, utils_js_1.assertPosixPath)(importPathResolved);
|
|
173
|
-
|
|
164
|
+
// `isNpmPkgImport` => `importPathOriginal` is most likely an npm package import, but it can also be a path alias that a) looks like an npm package import and b) resolves outside of `userRootDir`.
|
|
165
|
+
const isNpmPkgImport = (() => {
|
|
166
|
+
if (importPathResolved.includes('/node_modules/')) {
|
|
167
|
+
// 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.
|
|
168
|
+
(0, utils_js_1.assert)((0, utils_js_1.isNpmPackageImport_unreliable)(importPathOriginal));
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
174
171
|
// Linked npm packages
|
|
175
|
-
|
|
172
|
+
if (
|
|
173
|
+
// Assuming path aliases usually resolve inside `userRootDir`.
|
|
174
|
+
// - This isn't always the case: https://github.com/vikejs/vike/issues/2326
|
|
175
|
+
!importPathResolved.startsWith(userRootDir) &&
|
|
176
|
+
// 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.
|
|
177
|
+
(0, utils_js_1.isNpmPackageImport_unreliable)(importPathOriginal)) {
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
return false;
|
|
181
|
+
})();
|
|
176
182
|
const isExternal = isPointerImport ||
|
|
177
183
|
// Performance: npm package imports can be externalized. (We could as well let esbuild transpile /node_modules/ code but it's useless as /node_modules/ code is already built. It would unnecessarily slow down transpilation.)
|
|
178
184
|
isNpmPkgImport;
|
|
@@ -196,19 +202,19 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
196
202
|
filePathAbsoluteFilesystem: importPathResolved,
|
|
197
203
|
userRootDir
|
|
198
204
|
});
|
|
199
|
-
// We assuming that path aliases always resolve inside `userRootDir`.
|
|
200
205
|
if (filePathAbsoluteUserRootDir && !isNpmPkgImport) {
|
|
201
|
-
// `importPathOriginal` is a path alias.
|
|
206
|
+
// `importPathOriginal` is most likely a path alias.
|
|
202
207
|
// - We have to use esbuild's path alias resolution, because:
|
|
203
208
|
// - Vike doesn't resolve path aliases at all.
|
|
204
209
|
// - Node.js doesn't support `tsconfig.js#compilerOptions.paths`.
|
|
205
|
-
// - Esbuild path alias resolution seems
|
|
210
|
+
// - Esbuild path alias resolution seems reliable, e.g. it supports `tsconfig.js#compilerOptions.paths`.
|
|
211
|
+
(0, utils_js_1.assert)(!(0, utils_js_1.isNpmPackageImport_unreliable)(importPathOriginal));
|
|
206
212
|
importPathTranspiled = importPathResolved;
|
|
207
213
|
}
|
|
208
214
|
else {
|
|
209
|
-
// `importPathOriginal` is an npm package import.
|
|
215
|
+
// `importPathOriginal` is most likely an npm package import.
|
|
210
216
|
(0, utils_js_1.assertIsNpmPackageImport)(importPathOriginal);
|
|
211
|
-
// For
|
|
217
|
+
// For improved error messages, let the resolution be handled by Vike or Node.js.
|
|
212
218
|
importPathTranspiled = importPathOriginal;
|
|
213
219
|
}
|
|
214
220
|
}
|
|
@@ -573,7 +573,6 @@ function getConfigValueSource(configName, plusFile, configDef, userRootDir) {
|
|
|
573
573
|
// Defined over pointer import
|
|
574
574
|
(0, utils_js_1.assert)(confVal.valueIsLoaded);
|
|
575
575
|
const pointerImport = (0, resolvePointerImport_js_1.resolvePointerImport)(confVal.value, plusFile.filePath, userRootDir, configName);
|
|
576
|
-
console.log('pointerImport', pointerImport);
|
|
577
576
|
const configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAt)('Config', configName, definedAtFilePath_);
|
|
578
577
|
(0, utils_js_1.assertUsage)(pointerImport, `${configDefinedAt} should be an import`);
|
|
579
578
|
valueFilePath = pointerImport.fileExportPath.filePathAbsoluteVite;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveClientEntriesDev = resolveClientEntriesDev;
|
|
4
4
|
const utils_js_1 = require("../utils.js");
|
|
5
|
-
// @ts-ignore `file
|
|
6
|
-
const importMetaUrl = `file
|
|
5
|
+
// @ts-ignore `file:///${__filename.split('\\').join('/')}` is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
6
|
+
const importMetaUrl = `file:///${__filename.split('\\').join('/')}`;
|
|
7
7
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
8
8
|
async function resolveClientEntriesDev(clientEntry, viteDevServer) {
|
|
9
9
|
let root = viteDevServer.config.root;
|
|
@@ -27,20 +27,21 @@ async function resolveClientEntriesDev(clientEntry, viteDevServer) {
|
|
|
27
27
|
else {
|
|
28
28
|
if (clientEntry.startsWith('@@vike/')) {
|
|
29
29
|
(0, utils_js_1.assert)(clientEntry.endsWith('.js'));
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
catch {
|
|
30
|
+
let filePath_;
|
|
31
|
+
// For Vitest (which doesn't resolve vike to its dist but to its source files)
|
|
32
|
+
// [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/node/plugin/shared/resolveClientEntriesDev.js
|
|
33
|
+
filePath_ = (0, utils_js_1.requireResolveOptionalNonUserFile)(clientEntry.replace('@@vike/dist/esm/client/', '../../../client/').replace('.js', '.ts'), importMetaUrl);
|
|
34
|
+
if (!filePath_) {
|
|
36
35
|
// For users
|
|
37
36
|
// [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/shared/resolveClientEntriesDev.js
|
|
38
|
-
|
|
37
|
+
filePath_ = (0, utils_js_1.requireResolveOptionalNonUserFile)(clientEntry.replace('@@vike/dist/esm/client/', '../../../../../dist/esm/client/'), importMetaUrl);
|
|
39
38
|
}
|
|
39
|
+
(0, utils_js_1.assert)(filePath_);
|
|
40
|
+
filePath = filePath_;
|
|
40
41
|
}
|
|
41
42
|
else {
|
|
42
43
|
(0, utils_js_1.assertIsNpmPackageImport)(clientEntry);
|
|
43
|
-
filePath = (0, utils_js_1.
|
|
44
|
+
filePath = (0, utils_js_1.requireResolve)(clientEntry, root);
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
if (!filePath.startsWith('/')) {
|
|
@@ -15,7 +15,6 @@ async function analyzePage(pageFilesAll, pageConfig, pageId, globalContext) {
|
|
|
15
15
|
clientEntries.push(clientFilePath);
|
|
16
16
|
if (isClientRuntimeLoaded)
|
|
17
17
|
clientEntries.push((0, determineClientEntry_js_1.getVikeClientEntry)(isClientRouting));
|
|
18
|
-
console.log('clientEntries', clientEntries);
|
|
19
18
|
const clientDependencies = [];
|
|
20
19
|
clientDependencies.push({
|
|
21
20
|
id: (0, virtualFilePageConfigValuesAll_js_1.getVirtualFileIdPageConfigValuesAll)(pageConfig.pageId, true),
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.findPackageJson = findPackageJson;
|
|
4
4
|
const findFile_js_1 = require("./findFile.js");
|
|
5
5
|
const module_1 = require("module");
|
|
6
|
-
// @ts-ignore `file
|
|
7
|
-
const importMetaUrl = `file
|
|
6
|
+
// @ts-ignore `file:///${__filename.split('\\').join('/')}` is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
7
|
+
const importMetaUrl = `file:///${__filename.split('\\').join('/')}`;
|
|
8
8
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
9
9
|
function findPackageJson(cwd) {
|
|
10
10
|
const packageJsonPath = (0, findFile_js_1.findFile)('package.json', cwd);
|
|
@@ -24,8 +24,8 @@ function assertFilePathAbsoluteFilesystem(filePath) {
|
|
|
24
24
|
// - For Linux users assertFilePathAbsoluteFilesystem() will erroneously succeed if `p` is a path absolute from the user root dir.
|
|
25
25
|
// - But that's okay because the assertion will eventually fail for Windows users.
|
|
26
26
|
// - On Linux there doesn't seem to be a way to distinguish between an absolute path starting from the filesystem root or starting from the user root directory, see comment at isFilePathAbsoluteFilesystem()
|
|
27
|
-
(0, assert_js_1.assert)(isFilePathAbsoluteFilesystem(filePath));
|
|
28
27
|
(0, path_js_1.assertPosixPath)(filePath);
|
|
28
|
+
(0, assert_js_1.assert)(isFilePathAbsoluteFilesystem(filePath));
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* Whether `filePath` is an absolute file path starting from the filesystem root.
|
|
@@ -10,10 +10,10 @@ const assert_js_1 = require("./assert.js");
|
|
|
10
10
|
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
11
11
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
12
12
|
function isNpmPackageImport(str, { cannotBePathAlias }) {
|
|
13
|
-
// We cannot distinguish path alises that look like npm package imports
|
|
14
13
|
(0, assert_js_1.assert)(cannotBePathAlias);
|
|
15
14
|
return isNpmPackageImport_unreliable(str);
|
|
16
15
|
}
|
|
16
|
+
// We cannot distinguish path aliases that look like npm package imports
|
|
17
17
|
function isNpmPackageImport_unreliable(str) {
|
|
18
18
|
const res = parse(str);
|
|
19
19
|
return res !== null;
|
|
@@ -4,8 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.requireResolve = requireResolve;
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
7
|
+
exports.requireResolveOptional = requireResolveOptional;
|
|
8
|
+
exports.requireResolveNonUserFile = requireResolveNonUserFile;
|
|
9
|
+
exports.requireResolveOptionalNonUserFile = requireResolveOptionalNonUserFile;
|
|
9
10
|
const assert_js_1 = require("./assert.js");
|
|
10
11
|
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
11
12
|
const assertSetup_js_1 = require("./assertSetup.js");
|
|
@@ -13,17 +14,20 @@ const path_js_1 = require("./path.js");
|
|
|
13
14
|
const isScriptFile_js_1 = require("./isScriptFile.js");
|
|
14
15
|
const node_module_1 = require("node:module");
|
|
15
16
|
const node_path_1 = __importDefault(require("node:path"));
|
|
16
|
-
// @ts-ignore `file
|
|
17
|
-
const importMetaUrl = `file
|
|
17
|
+
// @ts-ignore `file:///${__filename.split('\\').join('/')}` is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
18
|
+
const importMetaUrl = `file:///${__filename.split('\\').join('/')}`;
|
|
18
19
|
const require_ = (0, node_module_1.createRequire)(importMetaUrl);
|
|
19
20
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
20
21
|
(0, assertSetup_js_1.assertIsNotProductionRuntime)();
|
|
21
|
-
function requireResolve_(importPath, cwd) {
|
|
22
|
+
function requireResolve_(importPath, cwd, options) {
|
|
22
23
|
(0, path_js_1.assertPosixPath)(cwd);
|
|
23
24
|
(0, path_js_1.assertPosixPath)(importPath);
|
|
24
25
|
cwd = resolveCwd(cwd);
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
let clean = () => { };
|
|
27
|
+
if (!options?.doNotHandleFileExtension) {
|
|
28
|
+
clean = addFileExtensionsToRequireResolve();
|
|
29
|
+
importPath = removeFileExtention(importPath);
|
|
30
|
+
}
|
|
27
31
|
let importedFile;
|
|
28
32
|
try {
|
|
29
33
|
// We still can't use import.meta.resolve() as of 23.1.0 (November 2024) because `parent` argument requires an experimental flag.
|
|
@@ -38,33 +42,29 @@ function requireResolve_(importPath, cwd) {
|
|
|
38
42
|
importedFile = (0, path_js_1.toPosixPath)(importedFile);
|
|
39
43
|
return { importedFile, err: undefined, hasFailed: false };
|
|
40
44
|
}
|
|
41
|
-
function
|
|
45
|
+
function requireResolveOptional(importPath, cwd) {
|
|
42
46
|
const res = requireResolve_(importPath, cwd);
|
|
43
47
|
if (res.hasFailed)
|
|
44
48
|
return null;
|
|
45
49
|
return res.importedFile;
|
|
46
50
|
}
|
|
47
|
-
function
|
|
48
|
-
const res = requireResolve_(importPath, cwd);
|
|
51
|
+
function requireResolveOptionalNonUserFile(importPath, cwd) {
|
|
52
|
+
const res = requireResolve_(importPath, cwd, { doNotHandleFileExtension: true });
|
|
53
|
+
if (res.hasFailed)
|
|
54
|
+
return null;
|
|
55
|
+
return res.importedFile;
|
|
56
|
+
}
|
|
57
|
+
function requireResolveNonUserFile(importPath, cwd) {
|
|
58
|
+
const res = requireResolve_(importPath, cwd, { doNotHandleFileExtension: true });
|
|
49
59
|
if (res.hasFailed)
|
|
50
60
|
throw res.err;
|
|
51
61
|
return res.importedFile;
|
|
52
62
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
let importedFile;
|
|
59
|
-
try {
|
|
60
|
-
importedFile = require_.resolve(importPath, { paths: [cwd] });
|
|
61
|
-
}
|
|
62
|
-
catch (err) {
|
|
63
|
-
console.log('err', err);
|
|
64
|
-
(0, assert_js_1.assert)(false, { cwd, importPath });
|
|
65
|
-
}
|
|
66
|
-
importedFile = (0, path_js_1.toPosixPath)(importedFile);
|
|
67
|
-
return importedFile;
|
|
63
|
+
function requireResolve(importPath, cwd) {
|
|
64
|
+
const res = requireResolve_(importPath, cwd);
|
|
65
|
+
if (res.hasFailed)
|
|
66
|
+
throw res.err;
|
|
67
|
+
return res.importedFile;
|
|
68
68
|
}
|
|
69
69
|
function resolveCwd(cwd) {
|
|
70
70
|
let prefix = 'file://';
|
|
@@ -2,12 +2,11 @@ export { pluginBuildConfig };
|
|
|
2
2
|
export { assertRollupInput };
|
|
3
3
|
export { analyzeClientEntries };
|
|
4
4
|
export { manifestTempFile };
|
|
5
|
-
import { assert, addOnBeforeLogHook, removeFileExtention, unique, assertUsage, injectRollupInputs, normalizeRollupInput, onSetupBuild, assertIsNpmPackageImport } from '../../utils.js';
|
|
5
|
+
import { assert, addOnBeforeLogHook, removeFileExtention, unique, assertUsage, injectRollupInputs, normalizeRollupInput, onSetupBuild, assertIsNpmPackageImport, requireResolveNonUserFile } from '../../utils.js';
|
|
6
6
|
import { getVikeConfig } from '../importUserCode/v1-design/getVikeConfig.js';
|
|
7
7
|
import { findPageFiles } from '../../shared/findPageFiles.js';
|
|
8
8
|
import { getVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
9
9
|
import { extractAssetsAddQuery } from '../../../shared/extractAssetsQuery.js';
|
|
10
|
-
import { createRequire } from 'module';
|
|
11
10
|
import { prependEntriesDir } from '../../../shared/prependEntriesDir.js';
|
|
12
11
|
import { getFilePathResolved } from '../../shared/getFilePath.js';
|
|
13
12
|
import { getConfigValueBuildTime } from '../../../../shared/page-configs/getConfigValueBuildTime.js';
|
|
@@ -16,7 +15,6 @@ import { resolveOutDir } from '../../shared/getOutDirs.js';
|
|
|
16
15
|
import { handleAssetsManifest_assertUsageCssCodeSplit, handleAssetsManifest_getBuildConfig } from './handleAssetsManifest.js';
|
|
17
16
|
// @ts-ignore import.meta.url is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
18
17
|
const importMetaUrl = import.meta.url;
|
|
19
|
-
const require_ = createRequire(importMetaUrl);
|
|
20
18
|
const manifestTempFile = '_temp_manifest.json';
|
|
21
19
|
function pluginBuildConfig() {
|
|
22
20
|
let config;
|
|
@@ -197,7 +195,7 @@ function getEntryFromPageConfig(pageConfig, isForClientSide) {
|
|
|
197
195
|
function resolve(filePath) {
|
|
198
196
|
assert(filePath.startsWith('dist/'));
|
|
199
197
|
// [RELATIVE_PATH_FROM_DIST] Current directory: node_modules/vike/dist/esm/node/plugin/plugins/build/
|
|
200
|
-
return
|
|
198
|
+
return requireResolveNonUserFile(`../../../../../../${filePath}`, importMetaUrl);
|
|
201
199
|
}
|
|
202
200
|
function addLogHook() {
|
|
203
201
|
const tty = process.stdout.isTTY && !process.env.CI; // Equals https://github.com/vitejs/vite/blob/193d55c7b9cbfec5b79ebfca276d4a721e7de14d/packages/vite/src/node/plugins/reporter.ts#L27
|
|
@@ -2,13 +2,11 @@ export { pluginBuildEntry };
|
|
|
2
2
|
export { set_macro_ASSETS_MANIFEST };
|
|
3
3
|
import { serverProductionEntryPlugin } from '@brillout/vite-plugin-server-entry/plugin';
|
|
4
4
|
import { virtualFileIdImportUserCodeServer } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
5
|
-
import { assert, PROJECT_VERSION,
|
|
5
|
+
import { assert, PROJECT_VERSION, requireResolveNonUserFile } from '../../utils.js';
|
|
6
6
|
import fs from 'fs/promises';
|
|
7
7
|
import path from 'path';
|
|
8
|
-
import { createRequire } from 'module';
|
|
9
8
|
// @ts-ignore import.meta.url is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
10
9
|
const importMetaUrl = import.meta.url;
|
|
11
|
-
const require_ = createRequire(importMetaUrl);
|
|
12
10
|
import { isUsingClientRouter } from '../extractExportNamesPlugin.js';
|
|
13
11
|
import { assertBuildInfo, getViteConfigRuntime } from '../../../runtime/globalContext.js';
|
|
14
12
|
import { getOutDirs } from '../../shared/getOutDirs.js';
|
|
@@ -87,9 +85,8 @@ function find_ASSETS_MANIFEST(bundle) {
|
|
|
87
85
|
}
|
|
88
86
|
function getImportPath(config) {
|
|
89
87
|
// We resolve filePathAbsolute even if we don't use it: we use require.resolve() as an assertion that the relative path is correct
|
|
90
|
-
const filePathAbsolute = toPosixPath(
|
|
91
88
|
// [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/plugins/pluginBuildEntry/index.js
|
|
92
|
-
|
|
89
|
+
const filePathAbsolute = requireResolveNonUserFile(`../../../../../../dist/esm/__internal/index.js`, importMetaUrl);
|
|
93
90
|
if (
|
|
94
91
|
// Let's implement a new config if a user needs the import to be a relative path instead of 'vike/__internal' (AFAIK a relative path is needed only if a framework has npm package 'vike' as direct dependency instead of a peer dependency and if the user of that framework uses pnpm)
|
|
95
92
|
true) {
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
export { determineFsAllowList };
|
|
2
2
|
import { searchForWorkspaceRoot } from 'vite';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { assert } from '../../utils.js';
|
|
5
|
-
import { createRequire } from 'module';
|
|
6
|
-
import { dirname } from 'path';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { assert, assertPosixPath, requireResolveNonUserFile } from '../../utils.js';
|
|
7
5
|
import { fileURLToPath } from 'url';
|
|
8
6
|
// @ts-ignore import.meta.url is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
9
7
|
const importMetaUrl = import.meta.url;
|
|
10
|
-
|
|
11
|
-
const __dirname_ = dirname(fileURLToPath(importMetaUrl));
|
|
8
|
+
assertPosixPath(importMetaUrl);
|
|
9
|
+
const __dirname_ = path.posix.dirname(fileURLToPath(importMetaUrl));
|
|
10
|
+
assertPosixPath(__dirname_);
|
|
12
11
|
async function determineFsAllowList(config) {
|
|
13
12
|
const fsAllow = config.server.fs.allow;
|
|
14
13
|
// fsAllow should already contain searchForWorkspaceRoot()
|
|
@@ -21,9 +20,9 @@ async function determineFsAllowList(config) {
|
|
|
21
20
|
// Add node_modules/vike/
|
|
22
21
|
{
|
|
23
22
|
// [RELATIVE_PATH_FROM_DIST] Current directory: node_modules/vike/dist/esm/node/plugin/plugins/config/
|
|
24
|
-
const vikeRoot = path.join(__dirname_, '../../../../../../');
|
|
23
|
+
const vikeRoot = path.posix.join(__dirname_, '../../../../../../');
|
|
25
24
|
// Assert that `vikeRoot` is indeed pointing to `node_modules/vike/`
|
|
26
|
-
|
|
25
|
+
requireResolveNonUserFile(`${vikeRoot}/dist/esm/node/plugin/plugins/devConfig/index.js`, importMetaUrl);
|
|
27
26
|
fsAllow.push(vikeRoot);
|
|
28
27
|
}
|
|
29
28
|
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { resolvePointerImport };
|
|
2
2
|
export { resolvePointerImportData };
|
|
3
3
|
import pc from '@brillout/picocolors';
|
|
4
|
-
import { assert, assertPosixPath, assertUsage, isFilePathAbsolute, pathIsRelative,
|
|
4
|
+
import { assert, assertPosixPath, assertUsage, isFilePathAbsolute, pathIsRelative, requireResolveOptional } from '../../../../utils.js';
|
|
5
5
|
import { parsePointerImportData } from './transformPointerImports.js';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { getFilePathAbsoluteUserRootDir, getFilePathResolved, getFilePathUnresolved } from '../../../../shared/getFilePath.js';
|
|
@@ -72,10 +72,8 @@ function resolveImportPathWithNode(pointerImportData, importerFilePath) {
|
|
|
72
72
|
const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
|
|
73
73
|
assertPosixPath(importerFilePathAbsolute);
|
|
74
74
|
const cwd = path.posix.dirname(importerFilePathAbsolute);
|
|
75
|
-
// We still can't use import.meta.resolve() as of 23.1.0 (November 2024) because `parent` argument requires an experimental flag.
|
|
76
|
-
// - https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment139581675_62272600
|
|
77
75
|
// filePathAbsoluteFilesystem is expected to be null when pointerImportData.importPath is a Vite path alias
|
|
78
|
-
const filePathAbsoluteFilesystem =
|
|
76
|
+
const filePathAbsoluteFilesystem = requireResolveOptional(pointerImportData.importPath, cwd);
|
|
79
77
|
return filePathAbsoluteFilesystem;
|
|
80
78
|
}
|
|
81
79
|
function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath) {
|
|
@@ -7,14 +7,10 @@ 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, assertIsNpmPackageImport, genPromise, isVitest } from '../../../../utils.js';
|
|
10
|
+
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isPlainJavaScriptFile, createDebugger, assertFilePathAbsoluteFilesystem, assertIsNpmPackageImport, genPromise, isVitest, requireResolveOptional, isNpmPackageImport_unreliable } from '../../../../utils.js';
|
|
11
11
|
import { transformPointerImports } from './transformPointerImports.js';
|
|
12
12
|
import sourceMapSupport from 'source-map-support';
|
|
13
13
|
import { getFilePathAbsoluteUserRootDir } from '../../../../shared/getFilePath.js';
|
|
14
|
-
import { createRequire } from 'module';
|
|
15
|
-
// @ts-ignore import.meta.url is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
16
|
-
const importMetaUrl = import.meta.url;
|
|
17
|
-
const require_ = createRequire(importMetaUrl);
|
|
18
14
|
assertIsNotProductionRuntime();
|
|
19
15
|
installSourceMapSupport();
|
|
20
16
|
const debug = createDebugger('vike:pointer-imports');
|
|
@@ -110,8 +106,6 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
110
106
|
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
111
107
|
if (args.kind !== 'import-statement')
|
|
112
108
|
return;
|
|
113
|
-
if (debugEsbuildResolve.isActivated)
|
|
114
|
-
debugEsbuildResolve('args', args);
|
|
115
109
|
// Avoid infinite loop: https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
|
|
116
110
|
const useEsbuildResolver = 'useEsbuildResolver';
|
|
117
111
|
if (args.pluginData?.[useEsbuildResolver])
|
|
@@ -119,17 +113,15 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
119
113
|
const { path, ...opts } = args;
|
|
120
114
|
opts.pluginData = { [useEsbuildResolver]: true };
|
|
121
115
|
let resolved = await build.resolve(path, opts);
|
|
116
|
+
if (debugEsbuildResolve.isActivated)
|
|
117
|
+
debugEsbuildResolve('args', args);
|
|
122
118
|
if (debugEsbuildResolve.isActivated)
|
|
123
119
|
debugEsbuildResolve('resolved', resolved);
|
|
124
120
|
// Temporary workaround for https://github.com/evanw/esbuild/issues/3973
|
|
125
121
|
// - Sitll required for esbuild@0.24.0 (November 2024).
|
|
126
122
|
// - Let's try to remove this workaround again later.
|
|
127
123
|
if (resolved.errors.length > 0) {
|
|
128
|
-
|
|
129
|
-
try {
|
|
130
|
-
resolvedWithNode = require_.resolve(path, { paths: [args.resolveDir] });
|
|
131
|
-
}
|
|
132
|
-
catch { }
|
|
124
|
+
const resolvedWithNode = requireResolveOptional(path, args.resolveDir);
|
|
133
125
|
if (debugEsbuildResolve.isActivated)
|
|
134
126
|
debugEsbuildResolve('resolvedWithNode', resolvedWithNode);
|
|
135
127
|
if (resolvedWithNode)
|
|
@@ -163,11 +155,25 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
163
155
|
// - vike@0.4.162 started soft-requiring Vike extensions to set the name config.
|
|
164
156
|
// - In practice, it seems like it requires some (non-trivial?) refactoring.
|
|
165
157
|
isVikeExtensionImport;
|
|
166
|
-
// Externalize npm package imports
|
|
167
158
|
assertPosixPath(importPathResolved);
|
|
168
|
-
|
|
159
|
+
// `isNpmPkgImport` => `importPathOriginal` is most likely an npm package import, but it can also be a path alias that a) looks like an npm package import and b) resolves outside of `userRootDir`.
|
|
160
|
+
const isNpmPkgImport = (() => {
|
|
161
|
+
if (importPathResolved.includes('/node_modules/')) {
|
|
162
|
+
// 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(isNpmPackageImport_unreliable(importPathOriginal));
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
169
166
|
// Linked npm packages
|
|
170
|
-
|
|
167
|
+
if (
|
|
168
|
+
// Assuming path aliases usually resolve inside `userRootDir`.
|
|
169
|
+
// - This isn't always the case: https://github.com/vikejs/vike/issues/2326
|
|
170
|
+
!importPathResolved.startsWith(userRootDir) &&
|
|
171
|
+
// 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
|
+
isNpmPackageImport_unreliable(importPathOriginal)) {
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
return false;
|
|
176
|
+
})();
|
|
171
177
|
const isExternal = isPointerImport ||
|
|
172
178
|
// Performance: npm package imports can be externalized. (We could as well let esbuild transpile /node_modules/ code but it's useless as /node_modules/ code is already built. It would unnecessarily slow down transpilation.)
|
|
173
179
|
isNpmPkgImport;
|
|
@@ -191,19 +197,19 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
191
197
|
filePathAbsoluteFilesystem: importPathResolved,
|
|
192
198
|
userRootDir
|
|
193
199
|
});
|
|
194
|
-
// We assuming that path aliases always resolve inside `userRootDir`.
|
|
195
200
|
if (filePathAbsoluteUserRootDir && !isNpmPkgImport) {
|
|
196
|
-
// `importPathOriginal` is a path alias.
|
|
201
|
+
// `importPathOriginal` is most likely a path alias.
|
|
197
202
|
// - We have to use esbuild's path alias resolution, because:
|
|
198
203
|
// - Vike doesn't resolve path aliases at all.
|
|
199
204
|
// - Node.js doesn't support `tsconfig.js#compilerOptions.paths`.
|
|
200
|
-
// - Esbuild path alias resolution seems
|
|
205
|
+
// - Esbuild path alias resolution seems reliable, e.g. it supports `tsconfig.js#compilerOptions.paths`.
|
|
206
|
+
assert(!isNpmPackageImport_unreliable(importPathOriginal));
|
|
201
207
|
importPathTranspiled = importPathResolved;
|
|
202
208
|
}
|
|
203
209
|
else {
|
|
204
|
-
// `importPathOriginal` is an npm package import.
|
|
210
|
+
// `importPathOriginal` is most likely an npm package import.
|
|
205
211
|
assertIsNpmPackageImport(importPathOriginal);
|
|
206
|
-
// For
|
|
212
|
+
// For improved error messages, let the resolution be handled by Vike or Node.js.
|
|
207
213
|
importPathTranspiled = importPathOriginal;
|
|
208
214
|
}
|
|
209
215
|
}
|
|
@@ -568,7 +568,6 @@ function getConfigValueSource(configName, plusFile, configDef, userRootDir) {
|
|
|
568
568
|
// Defined over pointer import
|
|
569
569
|
assert(confVal.valueIsLoaded);
|
|
570
570
|
const pointerImport = resolvePointerImport(confVal.value, plusFile.filePath, userRootDir, configName);
|
|
571
|
-
console.log('pointerImport', pointerImport);
|
|
572
571
|
const configDefinedAt = getConfigDefinedAt('Config', configName, definedAtFilePath_);
|
|
573
572
|
assertUsage(pointerImport, `${configDefinedAt} should be an import`);
|
|
574
573
|
valueFilePath = pointerImport.fileExportPath.filePathAbsoluteVite;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { resolveClientEntriesDev };
|
|
2
|
-
import { assert, assertPosixPath, toPosixPath, pathJoin, assertIsNpmPackageImport, assertIsNotProductionRuntime,
|
|
2
|
+
import { assert, assertPosixPath, toPosixPath, pathJoin, assertIsNpmPackageImport, assertIsNotProductionRuntime, requireResolveOptionalNonUserFile, requireResolve } from '../utils.js';
|
|
3
3
|
// @ts-ignore import.meta.url is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
4
4
|
const importMetaUrl = import.meta.url;
|
|
5
5
|
assertIsNotProductionRuntime();
|
|
@@ -25,20 +25,21 @@ async function resolveClientEntriesDev(clientEntry, viteDevServer) {
|
|
|
25
25
|
else {
|
|
26
26
|
if (clientEntry.startsWith('@@vike/')) {
|
|
27
27
|
assert(clientEntry.endsWith('.js'));
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
catch {
|
|
28
|
+
let filePath_;
|
|
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_) {
|
|
34
33
|
// For users
|
|
35
34
|
// [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/shared/resolveClientEntriesDev.js
|
|
36
|
-
|
|
35
|
+
filePath_ = requireResolveOptionalNonUserFile(clientEntry.replace('@@vike/dist/esm/client/', '../../../../../dist/esm/client/'), importMetaUrl);
|
|
37
36
|
}
|
|
37
|
+
assert(filePath_);
|
|
38
|
+
filePath = filePath_;
|
|
38
39
|
}
|
|
39
40
|
else {
|
|
40
41
|
assertIsNpmPackageImport(clientEntry);
|
|
41
|
-
filePath =
|
|
42
|
+
filePath = requireResolve(clientEntry, root);
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
if (!filePath.startsWith('/')) {
|
|
@@ -13,7 +13,6 @@ async function analyzePage(pageFilesAll, pageConfig, pageId, globalContext) {
|
|
|
13
13
|
clientEntries.push(clientFilePath);
|
|
14
14
|
if (isClientRuntimeLoaded)
|
|
15
15
|
clientEntries.push(getVikeClientEntry(isClientRouting));
|
|
16
|
-
console.log('clientEntries', clientEntries);
|
|
17
16
|
const clientDependencies = [];
|
|
18
17
|
clientDependencies.push({
|
|
19
18
|
id: getVirtualFileIdPageConfigValuesAll(pageConfig.pageId, true),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.227-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.227-commit-77128be";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.227-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.227-commit-77128be';
|
|
@@ -19,8 +19,8 @@ function assertFilePathAbsoluteFilesystem(filePath) {
|
|
|
19
19
|
// - For Linux users assertFilePathAbsoluteFilesystem() will erroneously succeed if `p` is a path absolute from the user root dir.
|
|
20
20
|
// - But that's okay because the assertion will eventually fail for Windows users.
|
|
21
21
|
// - On Linux there doesn't seem to be a way to distinguish between an absolute path starting from the filesystem root or starting from the user root directory, see comment at isFilePathAbsoluteFilesystem()
|
|
22
|
-
assert(isFilePathAbsoluteFilesystem(filePath));
|
|
23
22
|
assertPosixPath(filePath);
|
|
23
|
+
assert(isFilePathAbsoluteFilesystem(filePath));
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Whether `filePath` is an absolute file path starting from the filesystem root.
|
|
@@ -14,10 +14,10 @@ import { assert } from './assert.js';
|
|
|
14
14
|
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
15
15
|
assertIsNotBrowser();
|
|
16
16
|
function isNpmPackageImport(str, { cannotBePathAlias }) {
|
|
17
|
-
// We cannot distinguish path alises that look like npm package imports
|
|
18
17
|
assert(cannotBePathAlias);
|
|
19
18
|
return isNpmPackageImport_unreliable(str);
|
|
20
19
|
}
|
|
20
|
+
// We cannot distinguish path aliases that look like npm package imports
|
|
21
21
|
function isNpmPackageImport_unreliable(str) {
|
|
22
22
|
const res = parse(str);
|
|
23
23
|
return res !== null;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { requireResolve };
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
|
|
5
|
-
declare function
|
|
6
|
-
declare function
|
|
2
|
+
export { requireResolveOptional };
|
|
3
|
+
export { requireResolveNonUserFile };
|
|
4
|
+
export { requireResolveOptionalNonUserFile };
|
|
5
|
+
declare function requireResolveOptional(importPath: string, cwd: string): string | null;
|
|
6
|
+
declare function requireResolveOptionalNonUserFile(importPath: string, cwd: string): string | null;
|
|
7
|
+
declare function requireResolveNonUserFile(importPath: string, cwd: string): string;
|
|
8
|
+
declare function requireResolve(importPath: string, cwd: string): string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { requireResolve };
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
2
|
+
export { requireResolveOptional };
|
|
3
|
+
export { requireResolveNonUserFile };
|
|
4
|
+
export { requireResolveOptionalNonUserFile };
|
|
4
5
|
import { assert } from './assert.js';
|
|
5
6
|
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
6
7
|
import { assertIsNotProductionRuntime } from './assertSetup.js';
|
|
@@ -13,12 +14,15 @@ const importMetaUrl = import.meta.url;
|
|
|
13
14
|
const require_ = createRequire(importMetaUrl);
|
|
14
15
|
assertIsNotBrowser();
|
|
15
16
|
assertIsNotProductionRuntime();
|
|
16
|
-
function requireResolve_(importPath, cwd) {
|
|
17
|
+
function requireResolve_(importPath, cwd, options) {
|
|
17
18
|
assertPosixPath(cwd);
|
|
18
19
|
assertPosixPath(importPath);
|
|
19
20
|
cwd = resolveCwd(cwd);
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
let clean = () => { };
|
|
22
|
+
if (!options?.doNotHandleFileExtension) {
|
|
23
|
+
clean = addFileExtensionsToRequireResolve();
|
|
24
|
+
importPath = removeFileExtention(importPath);
|
|
25
|
+
}
|
|
22
26
|
let importedFile;
|
|
23
27
|
try {
|
|
24
28
|
// We still can't use import.meta.resolve() as of 23.1.0 (November 2024) because `parent` argument requires an experimental flag.
|
|
@@ -33,33 +37,29 @@ function requireResolve_(importPath, cwd) {
|
|
|
33
37
|
importedFile = toPosixPath(importedFile);
|
|
34
38
|
return { importedFile, err: undefined, hasFailed: false };
|
|
35
39
|
}
|
|
36
|
-
function
|
|
40
|
+
function requireResolveOptional(importPath, cwd) {
|
|
37
41
|
const res = requireResolve_(importPath, cwd);
|
|
38
42
|
if (res.hasFailed)
|
|
39
43
|
return null;
|
|
40
44
|
return res.importedFile;
|
|
41
45
|
}
|
|
42
|
-
function
|
|
43
|
-
const res = requireResolve_(importPath, cwd);
|
|
46
|
+
function requireResolveOptionalNonUserFile(importPath, cwd) {
|
|
47
|
+
const res = requireResolve_(importPath, cwd, { doNotHandleFileExtension: true });
|
|
48
|
+
if (res.hasFailed)
|
|
49
|
+
return null;
|
|
50
|
+
return res.importedFile;
|
|
51
|
+
}
|
|
52
|
+
function requireResolveNonUserFile(importPath, cwd) {
|
|
53
|
+
const res = requireResolve_(importPath, cwd, { doNotHandleFileExtension: true });
|
|
44
54
|
if (res.hasFailed)
|
|
45
55
|
throw res.err;
|
|
46
56
|
return res.importedFile;
|
|
47
57
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
let importedFile;
|
|
54
|
-
try {
|
|
55
|
-
importedFile = require_.resolve(importPath, { paths: [cwd] });
|
|
56
|
-
}
|
|
57
|
-
catch (err) {
|
|
58
|
-
console.log('err', err);
|
|
59
|
-
assert(false, { cwd, importPath });
|
|
60
|
-
}
|
|
61
|
-
importedFile = toPosixPath(importedFile);
|
|
62
|
-
return importedFile;
|
|
58
|
+
function requireResolve(importPath, cwd) {
|
|
59
|
+
const res = requireResolve_(importPath, cwd);
|
|
60
|
+
if (res.hasFailed)
|
|
61
|
+
throw res.err;
|
|
62
|
+
return res.importedFile;
|
|
63
63
|
}
|
|
64
64
|
function resolveCwd(cwd) {
|
|
65
65
|
let prefix = 'file://';
|