vike 0.4.228-commit-8d90991 → 0.4.228-commit-84954ae
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/node/plugin/plugins/baseUrls.js +1 -1
- package/dist/cjs/node/plugin/plugins/build/handleAssetsManifest.js +1 -1
- package/dist/cjs/node/plugin/plugins/build/pluginBuildApp.js +1 -1
- package/dist/cjs/node/plugin/plugins/build/pluginBuildConfig.js +3 -10
- package/dist/cjs/node/plugin/plugins/build/pluginBuildEntry.js +1 -4
- package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +1 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +11 -3
- package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +2 -7
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.js → pointerImports.js} +13 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +20 -19
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +14 -10
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -1
- package/dist/cjs/node/plugin/shared/getFilePath.js +2 -2
- package/dist/cjs/node/plugin/shared/resolveClientEntriesDev.js +7 -19
- package/dist/cjs/node/plugin/utils.js +1 -0
- package/dist/cjs/node/prerender/runPrerender.js +1 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +1 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +1 -1
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/shared/getPageFiles/fileTypes.js +1 -1
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +3 -7
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/isImportPath.js +21 -0
- package/dist/cjs/utils/{isNpmPackage.js → parseNpmPackage.js} +23 -23
- package/dist/cjs/utils/path.js +12 -2
- package/dist/cjs/utils/requireResolve.js +98 -39
- package/dist/esm/client/client-routing-runtime/globalContext.d.ts +1 -1
- package/dist/esm/client/server-routing-runtime/globalContext.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/baseUrls.js +2 -2
- package/dist/esm/node/plugin/plugins/build/handleAssetsManifest.js +2 -2
- package/dist/esm/node/plugin/plugins/build/pluginBuildApp.js +2 -2
- package/dist/esm/node/plugin/plugins/build/pluginBuildConfig.js +4 -11
- package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.js +2 -5
- package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +2 -2
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/commonConfig.js +12 -4
- package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.js +3 -8
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.d.ts → pointerImports.d.ts} +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.js → pointerImports.js} +14 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +20 -19
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +14 -10
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -1
- package/dist/esm/node/plugin/shared/getFilePath.js +3 -3
- package/dist/esm/node/plugin/shared/resolveClientEntriesDev.js +8 -20
- package/dist/esm/node/plugin/utils.d.ts +1 -0
- package/dist/esm/node/plugin/utils.js +1 -0
- package/dist/esm/node/prerender/runPrerender.js +2 -2
- package/dist/esm/node/runtime/globalContext.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/shared/VikeNamespace.d.ts +8 -8
- package/dist/esm/shared/getPageFiles/fileTypes.js +1 -1
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +3 -7
- package/dist/esm/shared/types.d.ts +4 -4
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/isImportPath.d.ts +4 -0
- package/dist/esm/utils/isImportPath.js +19 -0
- package/dist/esm/utils/parseNpmPackage.d.ts +17 -0
- package/dist/esm/utils/{isNpmPackage.js → parseNpmPackage.js} +23 -23
- package/dist/esm/utils/path.d.ts +1 -1
- package/dist/esm/utils/path.js +12 -2
- package/dist/esm/utils/requireResolve.d.ts +20 -7
- package/dist/esm/utils/requireResolve.js +98 -39
- package/package.json +1 -1
- package/dist/esm/utils/isNpmPackage.d.ts +0 -17
|
@@ -14,7 +14,7 @@ function baseUrls() {
|
|
|
14
14
|
const isDev = config._isDev;
|
|
15
15
|
(0, utils_js_1.assert)(typeof isDev === 'boolean');
|
|
16
16
|
const baseViteOriginal = config.base ?? '/__UNSET__'; // '/__UNSET__' because Vite resolves `_baseViteOriginal: null` to `undefined`
|
|
17
|
-
const vike = (0, commonConfig_js_1.
|
|
17
|
+
const vike = (0, commonConfig_js_1.getVikeConfigInternal)(config);
|
|
18
18
|
basesResolved = (0, resolveBase_js_1.resolveBase)(baseViteOriginal, vike.config.baseServer ?? null, vike.config.baseAssets ?? null);
|
|
19
19
|
// We cannot define these in configResolved() because Vite picks up the env variables before any configResolved() hook is called
|
|
20
20
|
process.env.BASE_SERVER = basesResolved.baseServer;
|
|
@@ -286,7 +286,7 @@ async function writeManifestFile(manifest, manifestFilePath) {
|
|
|
286
286
|
await promises_1.default.writeFile(manifestFilePath, manifestFileContent, 'utf-8');
|
|
287
287
|
}
|
|
288
288
|
function handleAssetsManifest_getBuildConfig(config) {
|
|
289
|
-
const vike = (0, commonConfig_js_1.
|
|
289
|
+
const vike = (0, commonConfig_js_1.getVikeConfigInternal)(config);
|
|
290
290
|
const isFixEnabled = handleAssetsManifest_isFixEnabled(config);
|
|
291
291
|
return {
|
|
292
292
|
// https://github.com/vikejs/vike/issues/1339
|
|
@@ -12,7 +12,7 @@ function pluginBuildApp() {
|
|
|
12
12
|
name: 'vike:build:pluginBuildApp',
|
|
13
13
|
apply: 'build',
|
|
14
14
|
config(config) {
|
|
15
|
-
const vike = (0, commonConfig_js_1.
|
|
15
|
+
const vike = (0, commonConfig_js_1.getVikeConfigInternal)(config);
|
|
16
16
|
if (!vike.config.vite6BuilderApp)
|
|
17
17
|
return;
|
|
18
18
|
return {
|
|
@@ -15,8 +15,6 @@ const getConfigValueBuildTime_js_1 = require("../../../../shared/page-configs/ge
|
|
|
15
15
|
const isViteServerBuild_js_1 = require("../../shared/isViteServerBuild.js");
|
|
16
16
|
const getOutDirs_js_1 = require("../../shared/getOutDirs.js");
|
|
17
17
|
const handleAssetsManifest_js_1 = require("./handleAssetsManifest.js");
|
|
18
|
-
// @ts-ignore `file:///${__filename.split('\\').join('/')}` is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
19
|
-
const importMetaUrl = `file:///${__filename.split('\\').join('/')}`;
|
|
20
18
|
const manifestTempFile = '_temp_manifest.json';
|
|
21
19
|
exports.manifestTempFile = manifestTempFile;
|
|
22
20
|
function pluginBuildConfig() {
|
|
@@ -84,8 +82,8 @@ async function getEntries(config) {
|
|
|
84
82
|
...clientEntries,
|
|
85
83
|
...pageFileEntries
|
|
86
84
|
};
|
|
87
|
-
const clientRoutingEntry =
|
|
88
|
-
const serverRoutingEntry =
|
|
85
|
+
const clientRoutingEntry = (0, utils_js_1.requireResolveVikeDistFile)('dist/esm/client/client-routing-runtime/entry.js');
|
|
86
|
+
const serverRoutingEntry = (0, utils_js_1.requireResolveVikeDistFile)('dist/esm/client/server-routing-runtime/entry.js');
|
|
89
87
|
if (hasClientRouting) {
|
|
90
88
|
entries['entries/entry-client-routing'] = clientRoutingEntry;
|
|
91
89
|
}
|
|
@@ -159,7 +157,7 @@ async function getPageFileEntries(config, includeAssetsImportedByServer) {
|
|
|
159
157
|
}
|
|
160
158
|
function getEntryFromClientEntry(clientEntry, config, addExtractAssetsQuery) {
|
|
161
159
|
if (!clientEntry.startsWith('/')) {
|
|
162
|
-
(0, utils_js_1.
|
|
160
|
+
(0, utils_js_1.assertIsImportPathNpmPackage)(clientEntry);
|
|
163
161
|
const entryTarget = clientEntry;
|
|
164
162
|
const entryName = (0, prependEntriesDir_js_1.prependEntriesDir)(clientEntry);
|
|
165
163
|
return { entryName, entryTarget };
|
|
@@ -195,11 +193,6 @@ function getEntryFromPageConfig(pageConfig, isForClientSide) {
|
|
|
195
193
|
(0, utils_js_1.assert)(!entryName.endsWith('/'));
|
|
196
194
|
return { entryName, entryTarget };
|
|
197
195
|
}
|
|
198
|
-
function resolve(filePath) {
|
|
199
|
-
(0, utils_js_1.assert)(filePath.startsWith('dist/'));
|
|
200
|
-
// [RELATIVE_PATH_FROM_DIST] Current directory: node_modules/vike/dist/esm/node/plugin/plugins/build/
|
|
201
|
-
return (0, utils_js_1.requireResolveNonUserFile)(`../../../../../../${filePath}`, importMetaUrl);
|
|
202
|
-
}
|
|
203
196
|
function addLogHook() {
|
|
204
197
|
const tty = process.stdout.isTTY && !process.env.CI; // Equals https://github.com/vitejs/vite/blob/193d55c7b9cbfec5b79ebfca276d4a721e7de14d/packages/vite/src/node/plugins/reporter.ts#L27
|
|
205
198
|
if (!tty)
|
|
@@ -10,8 +10,6 @@ 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
|
-
// @ts-ignore `file:///${__filename.split('\\').join('/')}` is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
14
|
-
const importMetaUrl = `file:///${__filename.split('\\').join('/')}`;
|
|
15
13
|
const extractExportNamesPlugin_js_1 = require("../extractExportNamesPlugin.js");
|
|
16
14
|
const globalContext_js_1 = require("../../../runtime/globalContext.js");
|
|
17
15
|
const getOutDirs_js_1 = require("../../shared/getOutDirs.js");
|
|
@@ -98,8 +96,7 @@ function find_ASSETS_MANIFEST(bundle) {
|
|
|
98
96
|
}
|
|
99
97
|
function getImportPath(config) {
|
|
100
98
|
// We resolve filePathAbsolute even if we don't use it: we use require.resolve() as an assertion that the relative path is correct
|
|
101
|
-
|
|
102
|
-
const filePathAbsolute = (0, utils_js_1.requireResolveNonUserFile)(`../../../../../../dist/esm/__internal/index.js`, importMetaUrl);
|
|
99
|
+
const filePathAbsolute = (0, utils_js_1.requireResolveVikeDistFile)('dist/esm/__internal/index.js');
|
|
103
100
|
if (
|
|
104
101
|
// 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)
|
|
105
102
|
true) {
|
|
@@ -64,7 +64,7 @@ function assertResolveAlias(config) {
|
|
|
64
64
|
// - determineOptimizeDeps()
|
|
65
65
|
// - extractAssets
|
|
66
66
|
// - in general: using un-distinguishable path aliases is asking for trouble
|
|
67
|
-
if (!(0, utils_js_1.
|
|
67
|
+
if (!(0, utils_js_1.isPathAliasRecommended)(find)) {
|
|
68
68
|
if (find.startsWith('@')) {
|
|
69
69
|
const msg = `${errPrefix} defines an invalid resolve.alias ${deprecation}: a path alias cannot start with ${picocolors_1.default.cyan('@')}, ${errSuffix1}`;
|
|
70
70
|
(0, utils_js_1.assertWarning)(false, msg, { onlyOnce: true });
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.commonConfig = commonConfig;
|
|
7
7
|
exports.getVikeConfigPublic = getVikeConfigPublic;
|
|
8
|
+
exports.getVikeConfigInternal = getVikeConfigInternal;
|
|
8
9
|
const utils_js_1 = require("../utils.js");
|
|
9
10
|
const pluginBuildConfig_js_1 = require("./build/pluginBuildConfig.js");
|
|
10
11
|
const require_shim_1 = require("@brillout/require-shim");
|
|
@@ -90,7 +91,7 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
90
91
|
order: 'post',
|
|
91
92
|
handler(configFromUser) {
|
|
92
93
|
let configFromVike = { server: {}, preview: {} };
|
|
93
|
-
const vike =
|
|
94
|
+
const vike = getVikeConfigInternal(configFromUser);
|
|
94
95
|
if (vike.config.port !== undefined) {
|
|
95
96
|
// https://vike.dev/port
|
|
96
97
|
setDefault('port', vike.config.port, configFromUser, configFromVike);
|
|
@@ -157,6 +158,8 @@ function assertSingleInstance(config) {
|
|
|
157
158
|
function assertVikeCliOrApi(config) {
|
|
158
159
|
if ((0, context_js_1.isVikeCliOrApi)())
|
|
159
160
|
return;
|
|
161
|
+
if ((0, utils_js_1.isVitest)())
|
|
162
|
+
return;
|
|
160
163
|
if ((0, isViteCliCall_js_1.isViteCliCall)()) {
|
|
161
164
|
(0, utils_js_1.assertWarning)(false, `Vite's CLI is deprecated ${picocolors_1.default.underline('https://vike.dev/migration/cli')}`, {
|
|
162
165
|
onlyOnce: true
|
|
@@ -196,7 +199,7 @@ function temp_supportOldInterface(config) {
|
|
|
196
199
|
}
|
|
197
200
|
// TODO/soon rename:
|
|
198
201
|
// - `getVikeConfig()` => `resolveVikeConfig()` ?
|
|
199
|
-
// - `
|
|
202
|
+
// - `getVikeConfigInternal()` => `getVikeConfig()`
|
|
200
203
|
// - `VikeConfigPublic` => `VikeConfig` ?
|
|
201
204
|
// - `VikeConfigObject` => `VikeConfigInternal` ?
|
|
202
205
|
/**
|
|
@@ -204,11 +207,16 @@ function temp_supportOldInterface(config) {
|
|
|
204
207
|
*
|
|
205
208
|
* https://vike.dev/getVikeConfig
|
|
206
209
|
*/
|
|
207
|
-
function
|
|
210
|
+
function getVikeConfigInternal(config) {
|
|
208
211
|
const vikeConfig = config._vike;
|
|
209
212
|
(0, utils_js_1.assert)(vikeConfig);
|
|
210
213
|
return vikeConfig;
|
|
211
214
|
}
|
|
215
|
+
function getVikeConfigPublic(config) {
|
|
216
|
+
const vikeConfig = config._vike;
|
|
217
|
+
(0, utils_js_1.assertUsage)(vikeConfig, "getVikeConfig() can only be used when Vite is running with Vike's Vite plugin");
|
|
218
|
+
return vikeConfig;
|
|
219
|
+
}
|
|
212
220
|
// Only emit dist/server/entry.mjs if necessary
|
|
213
221
|
function emitServerEntryOnlyIfNeeded(config) {
|
|
214
222
|
if (config.vitePluginServerEntry?.inject &&
|
|
@@ -23,11 +23,6 @@ async function determineFsAllowList(config) {
|
|
|
23
23
|
// We add it again just to be sure.
|
|
24
24
|
fsAllow.push((0, vite_1.searchForWorkspaceRoot)(process.cwd()));
|
|
25
25
|
// Add node_modules/vike/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const vikeRoot = node_path_1.default.posix.join(__dirname_, '../../../../../../');
|
|
29
|
-
// Assert that `vikeRoot` is indeed pointing to `node_modules/vike/`
|
|
30
|
-
(0, utils_js_1.requireResolveNonUserFile)(`${vikeRoot}/dist/esm/node/plugin/plugins/devConfig/index.js`, importMetaUrl);
|
|
31
|
-
fsAllow.push(vikeRoot);
|
|
32
|
-
}
|
|
26
|
+
const vikeNodeModulesRoot = (0, utils_js_1.getVikeNodeModulesRoot)();
|
|
27
|
+
fsAllow.push(vikeNodeModulesRoot);
|
|
33
28
|
}
|
|
@@ -40,7 +40,7 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
40
40
|
const addInclude = (e) => {
|
|
41
41
|
(0, utils_js_1.assert)(e);
|
|
42
42
|
// Shouldn't be a path alias, as path aliases would need to be added to config.optimizeDeps.entries instead of config.optimizeDeps.include
|
|
43
|
-
(0, utils_js_1.
|
|
43
|
+
(0, utils_js_1.assertIsImportPathNpmPackage)(e);
|
|
44
44
|
include.push(e);
|
|
45
45
|
};
|
|
46
46
|
// V1 design
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -12,7 +12,7 @@ const transpileAndExecuteFile_js_1 = require("./transpileAndExecuteFile.js");
|
|
|
12
12
|
const getVikeConfig_js_1 = require("../getVikeConfig.js");
|
|
13
13
|
const assertPlusFileExport_js_1 = require("../../../../../../shared/page-configs/assertPlusFileExport.js");
|
|
14
14
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
15
|
-
const
|
|
15
|
+
const pointerImports_js_1 = require("./pointerImports.js");
|
|
16
16
|
const getConfigFileExport_js_1 = require("./getConfigFileExport.js");
|
|
17
17
|
const resolvePointerImport_js_1 = require("./resolvePointerImport.js");
|
|
18
18
|
const getConfigDefinedAt_js_1 = require("../../../../../../shared/page-configs/getConfigDefinedAt.js");
|
|
@@ -117,7 +117,7 @@ function getExtendsPointerImportData(configFileExports, configFilePath) {
|
|
|
117
117
|
(0, utils_js_1.assertUsage)(false, wrongUsage);
|
|
118
118
|
}
|
|
119
119
|
extendsPointerImportData.push(...extendList.map((importString) => {
|
|
120
|
-
const pointerImportData = (0,
|
|
120
|
+
const pointerImportData = (0, pointerImports_js_1.parsePointerImportData)(importString);
|
|
121
121
|
(0, utils_js_1.assertUsage)(pointerImportData, wrongUsage);
|
|
122
122
|
return pointerImportData;
|
|
123
123
|
}));
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.transformPointerImports = transformPointerImports;
|
|
7
7
|
exports.parsePointerImportData = parsePointerImportData;
|
|
8
8
|
exports.isPointerImportData = isPointerImportData;
|
|
9
|
+
exports.assertPointerImportPath = assertPointerImportPath;
|
|
9
10
|
// Playground: https://github.com/brillout/acorn-playground
|
|
10
11
|
// Notes about `with { type: 'pointer' }`
|
|
11
12
|
// - It works well with TypeScript: it doesn't complain upon `with { type: 'unknown-to-typescript' }` and go-to-definition & types are preserved: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html#import-attributes
|
|
@@ -149,8 +150,20 @@ function parsePointerImportData(importString) {
|
|
|
149
150
|
(0, utils_js_1.assert)(parts.length >= 2);
|
|
150
151
|
const exportName = parts[parts.length - 1];
|
|
151
152
|
const importPath = parts.slice(0, -1).join(SEP);
|
|
153
|
+
if (importPath.startsWith('.') && !(importPath.startsWith('./') || importPath.startsWith('../'))) {
|
|
154
|
+
(0, utils_js_1.assert)(!importStringWasGenerated);
|
|
155
|
+
(0, utils_js_1.assertUsage)(false, `Invalid relative import path ${picocolors_1.default.code(importPath)} defined by ${picocolors_1.default.code(JSON.stringify(importString))} because it should start with ${picocolors_1.default.code('./')} or ${picocolors_1.default.code('../')}, or use an npm package import instead.`);
|
|
156
|
+
}
|
|
157
|
+
assertPointerImportPath(importPath);
|
|
152
158
|
return { importPath, exportName, importStringWasGenerated, importString };
|
|
153
159
|
}
|
|
160
|
+
// `importPath` is one of the following:
|
|
161
|
+
// - A relative import path
|
|
162
|
+
// - An npm package import
|
|
163
|
+
// - A filesystem absolute path, see transpileWithEsbuild()
|
|
164
|
+
function assertPointerImportPath(importPath) {
|
|
165
|
+
return (0, utils_js_1.isImportPath)(importPath) || (0, utils_js_1.isFilePathAbsolute)(importPath);
|
|
166
|
+
}
|
|
154
167
|
function spliceMany(str, operations) {
|
|
155
168
|
let strMod = '';
|
|
156
169
|
let endPrev;
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
CHANGED
|
@@ -7,13 +7,12 @@ exports.resolvePointerImport = resolvePointerImport;
|
|
|
7
7
|
exports.resolvePointerImportData = resolvePointerImportData;
|
|
8
8
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
9
9
|
const utils_js_1 = require("../../../../utils.js");
|
|
10
|
-
const
|
|
11
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const pointerImports_js_1 = require("./pointerImports.js");
|
|
12
11
|
const getFilePath_js_1 = require("../../../../shared/getFilePath.js");
|
|
13
12
|
function resolvePointerImport(configValue, importerFilePath, userRootDir, configName) {
|
|
14
13
|
if (typeof configValue !== 'string')
|
|
15
14
|
return null;
|
|
16
|
-
const pointerImportData = (0,
|
|
15
|
+
const pointerImportData = (0, pointerImports_js_1.parsePointerImportData)(configValue);
|
|
17
16
|
if (!pointerImportData)
|
|
18
17
|
return null;
|
|
19
18
|
const { exportName } = pointerImportData;
|
|
@@ -27,24 +26,18 @@ function resolvePointerImport(configValue, importerFilePath, userRootDir, config
|
|
|
27
26
|
return { fileExportPath };
|
|
28
27
|
}
|
|
29
28
|
function resolvePointerImportData(pointerImportData, importerFilePath, userRootDir) {
|
|
30
|
-
// `importPath` should be one of the following:
|
|
31
|
-
// - A relative import path
|
|
32
|
-
// - A filesystem absolute path
|
|
33
|
-
// - An npm package import
|
|
34
29
|
const { importPath } = pointerImportData;
|
|
35
|
-
|
|
30
|
+
(0, pointerImports_js_1.assertPointerImportPath)(importPath);
|
|
31
|
+
const filePathAbsoluteFilesystem = resolveImportPathWithNode(pointerImportData, importerFilePath, userRootDir);
|
|
36
32
|
let filePath;
|
|
37
33
|
(0, utils_js_1.assertPosixPath)(importPath);
|
|
38
|
-
if (
|
|
39
|
-
if (importPath.startsWith('.')) {
|
|
40
|
-
(0, utils_js_1.assertUsage)((0, utils_js_1.pathIsRelative)(importPath), `Invalid relative import path ${picocolors_1.default.code(importPath)} defined by ${importerFilePath.filePathToShowToUser} because it should start with ${picocolors_1.default.code('./')} or ${picocolors_1.default.code('../')}, or use an npm package import instead.`);
|
|
41
|
-
}
|
|
34
|
+
if ((0, utils_js_1.isImportPathRelative)(importPath) || (0, utils_js_1.isFilePathAbsolute)(importPath)) {
|
|
42
35
|
// Pointer imports are included in virtual files, thus relative imports need to be resolved. (Virtual modules cannot contain relative imports.)
|
|
43
36
|
assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath);
|
|
44
37
|
// 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
|
|
45
38
|
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.`;
|
|
46
39
|
const filePathAbsoluteUserRootDir = (0, getFilePath_js_1.getFilePathAbsoluteUserRootDir)({ filePathAbsoluteFilesystem, userRootDir });
|
|
47
|
-
if (
|
|
40
|
+
if ((0, utils_js_1.isImportPathRelative)(importPath)) {
|
|
48
41
|
(0, utils_js_1.assertUsage)(filePathAbsoluteUserRootDir, `The relative import ${picocolors_1.default.cyan(importPath)} defined by ${importerFilePath.filePathToShowToUser} resolves to ${filePathAbsoluteFilesystem} ${errSuffix}`);
|
|
49
42
|
}
|
|
50
43
|
else {
|
|
@@ -56,6 +49,7 @@ function resolvePointerImportData(pointerImportData, importerFilePath, userRootD
|
|
|
56
49
|
filePath = (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteUserRootDir, userRootDir });
|
|
57
50
|
}
|
|
58
51
|
else {
|
|
52
|
+
(0, utils_js_1.assert)((0, utils_js_1.isImportPathNpmPackageOrPathAlias)(importPath));
|
|
59
53
|
const importPathAbsolute = importPath;
|
|
60
54
|
if (filePathAbsoluteFilesystem) {
|
|
61
55
|
filePath = (0, getFilePath_js_1.getFilePathResolved)({
|
|
@@ -73,12 +67,20 @@ function resolvePointerImportData(pointerImportData, importerFilePath, userRootD
|
|
|
73
67
|
}
|
|
74
68
|
return filePath;
|
|
75
69
|
}
|
|
76
|
-
function resolveImportPathWithNode(pointerImportData, importerFilePath) {
|
|
70
|
+
function resolveImportPathWithNode(pointerImportData, importerFilePath, userRootDir) {
|
|
77
71
|
const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
|
|
78
72
|
(0, utils_js_1.assertPosixPath)(importerFilePathAbsolute);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
// filePathAbsoluteFilesystem is null when pointerImportData.importPath is a path alias that Node.js doesn't know about
|
|
74
|
+
const filePathAbsoluteFilesystem = (0, utils_js_1.requireResolveOptional)({
|
|
75
|
+
importPath: pointerImportData.importPath,
|
|
76
|
+
importerFile: importerFilePathAbsolute,
|
|
77
|
+
userRootDir
|
|
78
|
+
});
|
|
79
|
+
if (!filePathAbsoluteFilesystem) {
|
|
80
|
+
(0, utils_js_1.assert)(!(0, utils_js_1.isImportPathRelative)(pointerImportData.importPath));
|
|
81
|
+
// Libraries don't use path aliases => filePathAbsoluteFilesystem should be defined
|
|
82
|
+
(0, utils_js_1.assert)(!importerFilePathAbsolute.includes('node_modules'));
|
|
83
|
+
}
|
|
82
84
|
return filePathAbsoluteFilesystem;
|
|
83
85
|
}
|
|
84
86
|
function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath) {
|
|
@@ -90,8 +92,7 @@ function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportD
|
|
|
90
92
|
? `The import path ${importPathString} in ${filePathToShowToUser}`
|
|
91
93
|
: `The import ${picocolors_1.default.code(importString)} defined by ${filePathToShowToUser}`;
|
|
92
94
|
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
93
|
-
if (
|
|
94
|
-
(0, utils_js_1.assert)((0, utils_js_1.pathIsRelative)(importPath));
|
|
95
|
+
if ((0, utils_js_1.isImportPathRelative)(importPath)) {
|
|
95
96
|
(0, utils_js_1.assertUsage)(false, `${errIntro2} point to an existing file?`);
|
|
96
97
|
}
|
|
97
98
|
else {
|
|
@@ -13,7 +13,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
13
13
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
14
14
|
const import_1 = require("@brillout/import");
|
|
15
15
|
const utils_js_1 = require("../../../../utils.js");
|
|
16
|
-
const
|
|
16
|
+
const pointerImports_js_1 = require("./pointerImports.js");
|
|
17
17
|
const source_map_support_1 = __importDefault(require("source-map-support"));
|
|
18
18
|
const getFilePath_js_1 = require("../../../../shared/getFilePath.js");
|
|
19
19
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
@@ -61,7 +61,7 @@ async function transpileFile(filePath, transformImports, userRootDir, esbuildCac
|
|
|
61
61
|
debug(`code, post esbuild (${filePathToShowToUserResolved})`, code);
|
|
62
62
|
let isImportTransformed = false;
|
|
63
63
|
if (transformImports) {
|
|
64
|
-
const codeMod = (0,
|
|
64
|
+
const codeMod = (0, pointerImports_js_1.transformPointerImports)(code, filePathToShowToUserResolved, pointerImports);
|
|
65
65
|
if (codeMod) {
|
|
66
66
|
code = codeMod;
|
|
67
67
|
isImportTransformed = true;
|
|
@@ -126,7 +126,11 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
126
126
|
// - Sitll required for esbuild@0.24.0 (November 2024).
|
|
127
127
|
// - Let's try to remove this workaround again later.
|
|
128
128
|
if (resolved.errors.length > 0) {
|
|
129
|
-
const resolvedWithNode = (0, utils_js_1.
|
|
129
|
+
const resolvedWithNode = (0, utils_js_1.requireResolveOptionalDir)({
|
|
130
|
+
importPath: path,
|
|
131
|
+
importerDir: (0, utils_js_1.toPosixPath)(args.resolveDir),
|
|
132
|
+
userRootDir
|
|
133
|
+
});
|
|
130
134
|
if (debugEsbuildResolve.isActivated)
|
|
131
135
|
debugEsbuildResolve('resolvedWithNode', resolvedWithNode);
|
|
132
136
|
if (resolvedWithNode)
|
|
@@ -146,8 +150,8 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
146
150
|
const importPathOriginal = args.path;
|
|
147
151
|
// Esbuild resolves path aliases.
|
|
148
152
|
// - Enabling us to use:
|
|
149
|
-
// -
|
|
150
|
-
// -
|
|
153
|
+
// - assertIsImportPathNpmPackage()
|
|
154
|
+
// - isImportPathNpmPackage(str, { cannotBePathAlias: true })
|
|
151
155
|
(0, utils_js_1.assertFilePathAbsoluteFilesystem)(importPathResolved);
|
|
152
156
|
// Should be remove this? See comment below.
|
|
153
157
|
const isVikeExtensionImport = (path.startsWith('vike-') && path.endsWith('/config')) || importPathResolved.endsWith('+config.js');
|
|
@@ -165,7 +169,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
165
169
|
const isNpmPkgImport = (() => {
|
|
166
170
|
if (importPathResolved.includes('/node_modules/')) {
|
|
167
171
|
// 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.
|
|
172
|
+
(0, utils_js_1.assert)((0, utils_js_1.isImportPathNpmPackageOrPathAlias)(importPathOriginal));
|
|
169
173
|
return true;
|
|
170
174
|
}
|
|
171
175
|
// Linked npm packages
|
|
@@ -174,7 +178,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
174
178
|
// - This isn't always the case: https://github.com/vikejs/vike/issues/2326
|
|
175
179
|
!importPathResolved.startsWith(userRootDir) &&
|
|
176
180
|
// 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.
|
|
181
|
+
(0, utils_js_1.isImportPathNpmPackageOrPathAlias)(importPathOriginal)) {
|
|
178
182
|
return true;
|
|
179
183
|
}
|
|
180
184
|
return false;
|
|
@@ -191,7 +195,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
191
195
|
}
|
|
192
196
|
let importPathTranspiled;
|
|
193
197
|
(0, utils_js_1.assertPosixPath)(importPathOriginal);
|
|
194
|
-
if (
|
|
198
|
+
if ((0, utils_js_1.isImportPathRelative)(importPathOriginal)) {
|
|
195
199
|
importPathTranspiled = importPathResolved;
|
|
196
200
|
}
|
|
197
201
|
else {
|
|
@@ -208,12 +212,12 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
208
212
|
// - Vike doesn't resolve path aliases at all.
|
|
209
213
|
// - Node.js doesn't support `tsconfig.js#compilerOptions.paths`.
|
|
210
214
|
// - Esbuild path alias resolution seems reliable, e.g. it supports `tsconfig.js#compilerOptions.paths`.
|
|
211
|
-
(0, utils_js_1.assert)(!(0, utils_js_1.
|
|
215
|
+
(0, utils_js_1.assert)(!(0, utils_js_1.isImportPathNpmPackageOrPathAlias)(importPathOriginal));
|
|
212
216
|
importPathTranspiled = importPathResolved;
|
|
213
217
|
}
|
|
214
218
|
else {
|
|
215
219
|
// `importPathOriginal` is most likely an npm package import.
|
|
216
|
-
(0, utils_js_1.
|
|
220
|
+
(0, utils_js_1.assertIsImportPathNpmPackage)(importPathOriginal);
|
|
217
221
|
// For improved error messages, let the resolution be handled by Vike or Node.js.
|
|
218
222
|
importPathTranspiled = importPathOriginal;
|
|
219
223
|
}
|
|
@@ -75,7 +75,7 @@ async function handleReloadSideEffects() {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
// TODO/soon: predominantly use
|
|
78
|
+
// TODO/soon: predominantly use getVikeConfigInternal() instead of getVikeConfig() then maybe refector?
|
|
79
79
|
async function getVikeConfig(config, { doNotRestartViteOnError } = {}) {
|
|
80
80
|
const userRootDir = config.root;
|
|
81
81
|
const vikeVitePluginOptions = config._vikeVitePluginOptions;
|
|
@@ -44,7 +44,7 @@ function getComputedProps(args) {
|
|
|
44
44
|
const importPathAbsolute = args.importPathAbsolute ?? null;
|
|
45
45
|
const { filePathAbsoluteUserRootDir } = args;
|
|
46
46
|
if (importPathAbsolute)
|
|
47
|
-
(0, utils_js_1.
|
|
47
|
+
(0, utils_js_1.assertIsImportPathNpmPackage)(importPathAbsolute);
|
|
48
48
|
return {
|
|
49
49
|
importPathAbsolute,
|
|
50
50
|
filePathAbsoluteUserRootDir,
|
|
@@ -58,7 +58,7 @@ function getComputedProps(args) {
|
|
|
58
58
|
}
|
|
59
59
|
function getComputedPropsImportPathAbsolute(args) {
|
|
60
60
|
const { importPathAbsolute } = args;
|
|
61
|
-
(0, utils_js_1.
|
|
61
|
+
(0, utils_js_1.assertIsImportPathNpmPackage)(importPathAbsolute);
|
|
62
62
|
return {
|
|
63
63
|
filePathAbsoluteUserRootDir: null,
|
|
64
64
|
importPathAbsolute,
|
|
@@ -2,13 +2,11 @@
|
|
|
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:///${__filename.split('\\').join('/')}` is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
6
|
-
const importMetaUrl = `file:///${__filename.split('\\').join('/')}`;
|
|
7
5
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
8
6
|
async function resolveClientEntriesDev(clientEntry, viteDevServer) {
|
|
9
|
-
let
|
|
10
|
-
(0, utils_js_1.assert)(
|
|
11
|
-
|
|
7
|
+
let userRootDir = viteDevServer.config.root;
|
|
8
|
+
(0, utils_js_1.assert)(userRootDir);
|
|
9
|
+
userRootDir = (0, utils_js_1.toPosixPath)(userRootDir);
|
|
12
10
|
// The `?import` suffix is needed for MDX to be transpiled:
|
|
13
11
|
// - Not transpiled: `/pages/markdown.page.mdx`
|
|
14
12
|
// - Transpiled: `/pages/markdown.page.mdx?import`
|
|
@@ -22,26 +20,16 @@ async function resolveClientEntriesDev(clientEntry, viteDevServer) {
|
|
|
22
20
|
(0, utils_js_1.assertPosixPath)(clientEntry);
|
|
23
21
|
let filePath;
|
|
24
22
|
if (clientEntry.startsWith('/')) {
|
|
25
|
-
filePath = (0, utils_js_1.pathJoin)(
|
|
23
|
+
filePath = (0, utils_js_1.pathJoin)(userRootDir, clientEntry);
|
|
26
24
|
}
|
|
27
25
|
else {
|
|
28
26
|
if (clientEntry.startsWith('@@vike/')) {
|
|
29
27
|
(0, utils_js_1.assert)(clientEntry.endsWith('.js'));
|
|
30
|
-
|
|
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_) {
|
|
35
|
-
// For users
|
|
36
|
-
// [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/shared/resolveClientEntriesDev.js
|
|
37
|
-
filePath_ = (0, utils_js_1.requireResolveOptionalNonUserFile)(clientEntry.replace('@@vike/dist/esm/client/', '../../../../../dist/esm/client/'), importMetaUrl);
|
|
38
|
-
}
|
|
39
|
-
(0, utils_js_1.assert)(filePath_);
|
|
40
|
-
filePath = filePath_;
|
|
28
|
+
filePath = (0, utils_js_1.requireResolveVikeDistFile)(`dist/esm/${clientEntry.replace('@@vike/dist/esm/', '')}`);
|
|
41
29
|
}
|
|
42
30
|
else {
|
|
43
|
-
(0, utils_js_1.
|
|
44
|
-
filePath = (0, utils_js_1.
|
|
31
|
+
(0, utils_js_1.assertIsImportPathNpmPackage)(clientEntry);
|
|
32
|
+
filePath = (0, utils_js_1.requireResolveNpmPackage)({ importPathNpmPackage: clientEntry, userRootDir });
|
|
45
33
|
}
|
|
46
34
|
}
|
|
47
35
|
if (!filePath.startsWith('/')) {
|
|
@@ -46,3 +46,4 @@ __exportStar(require("../../utils/isEqualStringList.js"), exports);
|
|
|
46
46
|
__exportStar(require("../../utils/isDocker.js"), exports);
|
|
47
47
|
__exportStar(require("../../utils/isVitest.js"), exports);
|
|
48
48
|
__exportStar(require("../../utils/rollupSourceMap.js"), exports);
|
|
49
|
+
__exportStar(require("../../utils/isImportPath.js"), exports);
|
|
@@ -115,7 +115,7 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
115
115
|
await disableReactStreaming();
|
|
116
116
|
const viteConfig = await (0, vite_1.resolveConfig)(options.viteConfig || {}, 'build', 'production');
|
|
117
117
|
const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(viteConfig);
|
|
118
|
-
const vike = (0, commonConfig_js_1.
|
|
118
|
+
const vike = (0, commonConfig_js_1.getVikeConfigInternal)(viteConfig);
|
|
119
119
|
const { outDirClient, outDirServer } = (0, getOutDirs_js_1.getOutDirs)(viteConfig);
|
|
120
120
|
const { root } = viteConfig;
|
|
121
121
|
const prerenderConfigGlobal = (0, resolvePrerenderConfig_js_1.resolvePrerenderConfigGlobal)(vikeConfig);
|
|
@@ -42,7 +42,7 @@ function getManifestEntry(id, assetsManifest) {
|
|
|
42
42
|
return { manifestEntry, manifestKey };
|
|
43
43
|
}
|
|
44
44
|
// npm package import
|
|
45
|
-
(0, utils_js_1.
|
|
45
|
+
(0, utils_js_1.assertIsImportPathNpmPackage)(id);
|
|
46
46
|
const found = Object.entries(assetsManifest).find(([, e]) => e.name === (0, prependEntriesDir_js_1.prependEntriesDir)(id));
|
|
47
47
|
(0, utils_js_1.assert)(found);
|
|
48
48
|
const [manifestKey, manifestEntry] = found;
|
|
@@ -16,7 +16,7 @@ function retrieveAssetsProd(clientDependencies, assetsManifest, includeAssetsImp
|
|
|
16
16
|
onlyAssets &&
|
|
17
17
|
id.includes('.page.server.') &&
|
|
18
18
|
// 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.
|
|
19
|
-
!(0, utils_js_1.
|
|
19
|
+
!(0, utils_js_1.isImportPathNpmPackage)(id, {
|
|
20
20
|
// I presume Vite already resolves path aliases when Vite sets the module's id
|
|
21
21
|
cannotBePathAlias: true
|
|
22
22
|
})) {
|
|
@@ -50,7 +50,7 @@ __exportStar(require("../../utils/debug.js"), exports);
|
|
|
50
50
|
__exportStar(require("../../utils/urlToFile.js"), exports);
|
|
51
51
|
__exportStar(require("../../utils/getGlobalObject.js"), exports);
|
|
52
52
|
__exportStar(require("../../utils/freezePartial.js"), exports);
|
|
53
|
-
__exportStar(require("../../utils/
|
|
53
|
+
__exportStar(require("../../utils/parseNpmPackage.js"), exports);
|
|
54
54
|
__exportStar(require("../../utils/isNullish.js"), exports);
|
|
55
55
|
__exportStar(require("../../utils/isScriptFile.js"), exports);
|
|
56
56
|
__exportStar(require("../../utils/removeFileExtention.js"), exports);
|
|
@@ -25,7 +25,7 @@ function determineFileType(filePath) {
|
|
|
25
25
|
const isCSS = filePath.endsWith('.css');
|
|
26
26
|
if (isCSS) {
|
|
27
27
|
/* This assert() is skipped to reduce client-side bundle size
|
|
28
|
-
assert(
|
|
28
|
+
assert(isImportPathNpmPackage(filePath), filePath) // `.css` page files are only supported for npm packages
|
|
29
29
|
*/
|
|
30
30
|
return '.css';
|
|
31
31
|
}
|
|
@@ -8,7 +8,7 @@ exports.getConfigValuesBase = getConfigValuesBase;
|
|
|
8
8
|
exports.isJsonValue = isJsonValue;
|
|
9
9
|
const assertSetup_js_1 = require("../../../utils/assertSetup.js");
|
|
10
10
|
const utils_js_1 = require("../../../node/plugin/utils.js");
|
|
11
|
-
const
|
|
11
|
+
const pointerImports_js_1 = require("../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/pointerImports.js");
|
|
12
12
|
const helpers_js_1 = require("../helpers.js");
|
|
13
13
|
const stringify_1 = require("@brillout/json-serializer/stringify");
|
|
14
14
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
@@ -134,7 +134,7 @@ function valueToJson(value, configName, definedAtData, importStatements, filesEn
|
|
|
134
134
|
// - https://github.com/vikejs/vike-react/pull/113
|
|
135
135
|
replacer(_, value) {
|
|
136
136
|
if (typeof value === 'string') {
|
|
137
|
-
const importData = (0,
|
|
137
|
+
const importData = (0, pointerImports_js_1.parsePointerImportData)(value);
|
|
138
138
|
if (importData) {
|
|
139
139
|
const { importName } = addImportStatement(importStatements, importData.importPath, importData.exportName, filesEnv, configEnv, configName);
|
|
140
140
|
const replacement = [REPLACE_ME_BEFORE, importName, REPLACE_ME_AFTER].join('');
|
|
@@ -269,10 +269,10 @@ function addImportStatement(importStatements, importPath, exportName, filesEnv,
|
|
|
269
269
|
return { importName };
|
|
270
270
|
}
|
|
271
271
|
function assertFileEnv(importPath, configEnv, configName, filesEnv) {
|
|
272
|
+
(0, utils_js_1.assert)(!(0, utils_js_1.isImportPathRelative)(importPath));
|
|
272
273
|
const key = importPath;
|
|
273
274
|
(0, utils_js_1.assert)(key);
|
|
274
275
|
(0, utils_js_1.assertPosixPath)(key);
|
|
275
|
-
(0, utils_js_1.assert)(!isRelativeImportPath(key));
|
|
276
276
|
if (!filesEnv.has(key)) {
|
|
277
277
|
filesEnv.set(key, []);
|
|
278
278
|
}
|
|
@@ -288,7 +288,3 @@ function assertFileEnv(importPath, configEnv, configName, filesEnv) {
|
|
|
288
288
|
].join('\n'));
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
|
-
// TODO/now dedupe
|
|
292
|
-
function isRelativeImportPath(importPath) {
|
|
293
|
-
return importPath.startsWith('./') || importPath.startsWith('../');
|
|
294
|
-
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isImportPath = isImportPath;
|
|
4
|
+
exports.isImportPathRelative = isImportPathRelative;
|
|
5
|
+
const path_js_1 = require("./path.js");
|
|
6
|
+
const assert_js_1 = require("./assert.js");
|
|
7
|
+
const parseNpmPackage_js_1 = require("./parseNpmPackage.js");
|
|
8
|
+
function isImportPath(importPath) {
|
|
9
|
+
return isImportPathRelative(importPath) || (0, parseNpmPackage_js_1.isImportPathNpmPackageOrPathAlias)(importPath);
|
|
10
|
+
}
|
|
11
|
+
// See also `import { pathIsRelative } from './path'`
|
|
12
|
+
function isImportPathRelative(importPath) {
|
|
13
|
+
(0, path_js_1.assertPosixPath)(importPath);
|
|
14
|
+
if (importPath.startsWith('./') || importPath.startsWith('../')) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
(0, assert_js_1.assert)(!importPath.startsWith('.'));
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|