vike 0.4.220-commit-5c7810f → 0.4.220-commit-af5c91f
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/api/utils.js +1 -1
- package/dist/cjs/node/plugin/index.js +1 -1
- package/dist/cjs/node/plugin/onLoad.js +1 -1
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +5 -3
- package/dist/cjs/node/plugin/plugins/buildConfig.js +7 -5
- package/dist/cjs/node/plugin/plugins/buildEntry/index.js +2 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -2
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +3 -2
- package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +2 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +10 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +32 -41
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +9 -64
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +281 -313
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +7 -6
- package/dist/cjs/node/plugin/plugins/packageJsonFile.js +2 -2
- package/dist/cjs/node/plugin/plugins/previewConfig.js +4 -3
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +2 -1
- package/dist/cjs/node/plugin/shared/findPageFiles.js +2 -1
- package/dist/cjs/node/plugin/{getOutDirs.js → shared/getOutDirs.js} +24 -27
- package/dist/cjs/node/plugin/{resolveClientEntriesDev.js → shared/resolveClientEntriesDev.js} +5 -8
- package/dist/cjs/{utils → node/plugin/shared}/viteIsSSR.js +2 -2
- package/dist/cjs/node/plugin/utils.js +0 -1
- package/dist/cjs/node/prerender/context.js +8 -3
- package/dist/cjs/node/prerender/resolvePrerenderConfig.js +26 -5
- package/dist/cjs/node/prerender/runPrerender.js +6 -11
- package/dist/cjs/node/prerender/utils.js +1 -2
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +9 -4
- package/dist/cjs/node/runtime/renderPage/getEarlyHints.js +2 -27
- package/dist/cjs/node/runtime/renderPage/isFontFallback.js +29 -0
- package/dist/cjs/node/runtime/utils.js +1 -3
- package/dist/cjs/shared/getPageFiles/fileTypes.js +0 -1
- package/dist/cjs/shared/getPageFiles/getAllPageIdFiles.js +0 -3
- package/dist/cjs/shared/getPageFiles/getPageFileObject.js +0 -5
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +69 -18
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/findFile.js +3 -3
- package/dist/cjs/utils/isDev.js +2 -5
- package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +2 -2
- package/dist/cjs/utils/path.js +48 -0
- package/dist/cjs/utils/requireResolve.js +3 -3
- package/dist/esm/node/api/utils.d.ts +1 -1
- package/dist/esm/node/api/utils.js +1 -1
- package/dist/esm/node/plugin/index.js +1 -1
- package/dist/esm/node/plugin/onLoad.js +1 -1
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +3 -1
- package/dist/esm/node/plugin/plugins/buildConfig.js +3 -1
- package/dist/esm/node/plugin/plugins/buildEntry/index.js +2 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +2 -3
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +2 -1
- package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +9 -7
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +14 -11
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +35 -44
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.d.ts +8 -18
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +10 -65
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +6 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +12 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +8 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +284 -316
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +7 -6
- package/dist/esm/node/plugin/plugins/packageJsonFile.js +1 -1
- package/dist/esm/node/plugin/plugins/previewConfig.js +2 -1
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +2 -1
- package/dist/esm/node/plugin/shared/findPageFiles.js +2 -1
- package/dist/esm/node/plugin/{getOutDirs.js → shared/getOutDirs.js} +2 -5
- package/dist/esm/node/plugin/{resolveClientEntriesDev.js → shared/resolveClientEntriesDev.js} +5 -8
- package/dist/esm/{utils → node/plugin/shared}/viteIsSSR.js +2 -2
- package/dist/esm/node/plugin/utils.d.ts +0 -1
- package/dist/esm/node/plugin/utils.js +0 -1
- package/dist/esm/node/prerender/context.d.ts +2 -0
- package/dist/esm/node/prerender/context.js +8 -3
- package/dist/esm/node/prerender/resolvePrerenderConfig.d.ts +8 -1
- package/dist/esm/node/prerender/resolvePrerenderConfig.js +26 -5
- package/dist/esm/node/prerender/runPrerender.js +7 -12
- package/dist/esm/node/prerender/utils.d.ts +1 -2
- package/dist/esm/node/prerender/utils.js +1 -2
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +9 -4
- package/dist/esm/node/runtime/renderPage/getEarlyHints.js +1 -26
- package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/isFontFallback.d.ts +3 -0
- package/dist/esm/node/runtime/renderPage/isFontFallback.js +27 -0
- package/dist/esm/node/runtime/utils.d.ts +1 -3
- package/dist/esm/node/runtime/utils.js +1 -3
- package/dist/esm/shared/getPageFiles/fileTypes.js +1 -2
- package/dist/esm/shared/getPageFiles/getAllPageIdFiles.js +0 -3
- package/dist/esm/shared/getPageFiles/getPageFileObject.js +0 -5
- package/dist/esm/shared/page-configs/PageConfig.d.ts +0 -1
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +7 -1
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +70 -19
- package/dist/esm/shared/utils.d.ts +0 -1
- package/dist/esm/shared/utils.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/findFile.js +1 -1
- package/dist/esm/utils/isDev.js +3 -6
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +1 -1
- package/dist/esm/utils/path.d.ts +14 -0
- package/dist/esm/utils/path.js +46 -0
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/requireResolve.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/addImportStatement.js +0 -29
- package/dist/cjs/shared/assertPageFilePath.js +0 -11
- package/dist/cjs/utils/path-shim.js +0 -19
- package/dist/cjs/utils/toPosixPath.js +0 -18
- package/dist/esm/node/plugin/plugins/importUserCode/addImportStatement.d.ts +0 -14
- package/dist/esm/node/plugin/plugins/importUserCode/addImportStatement.js +0 -27
- package/dist/esm/shared/assertPageFilePath.d.ts +0 -2
- package/dist/esm/shared/assertPageFilePath.js +0 -9
- package/dist/esm/utils/path-shim.d.ts +0 -2
- package/dist/esm/utils/path-shim.js +0 -17
- package/dist/esm/utils/toPosixPath.d.ts +0 -4
- package/dist/esm/utils/toPosixPath.js +0 -16
- /package/dist/esm/node/plugin/{getOutDirs.d.ts → shared/getOutDirs.d.ts} +0 -0
- /package/dist/esm/node/plugin/{resolveClientEntriesDev.d.ts → shared/resolveClientEntriesDev.d.ts} +0 -0
- /package/dist/esm/{utils → node/plugin/shared}/viteIsSSR.d.ts +0 -0
|
@@ -20,5 +20,5 @@ const onLoad_js_1 = require("./onLoad.js");
|
|
|
20
20
|
(0, onLoad_js_1.onLoad)();
|
|
21
21
|
__exportStar(require("../../utils/assert.js"), exports);
|
|
22
22
|
__exportStar(require("../../utils/getGlobalObject.js"), exports);
|
|
23
|
-
__exportStar(require("../../utils/
|
|
23
|
+
__exportStar(require("../../utils/path.js"), exports);
|
|
24
24
|
__exportStar(require("../../utils/isObject.js"), exports);
|
|
@@ -29,7 +29,7 @@ const envVars_js_1 = require("./plugins/envVars.js");
|
|
|
29
29
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
30
30
|
const fileEnv_js_1 = require("./plugins/fileEnv.js");
|
|
31
31
|
const getPageAssets_js_1 = require("../runtime/renderPage/getPageAssets.js");
|
|
32
|
-
const resolveClientEntriesDev_js_1 = require("./resolveClientEntriesDev.js");
|
|
32
|
+
const resolveClientEntriesDev_js_1 = require("./shared/resolveClientEntriesDev.js");
|
|
33
33
|
const workaroundCssModuleHmr_js_1 = require("./plugins/workaroundCssModuleHmr.js");
|
|
34
34
|
const workaroundVite6HmrRegression_js_1 = require("./plugins/workaroundVite6HmrRegression.js");
|
|
35
35
|
// We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
|
|
@@ -10,7 +10,7 @@ function onLoad() {
|
|
|
10
10
|
(0, assertSetup_js_1.markSetup_vikeVitePlugin)();
|
|
11
11
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
12
12
|
(0, assertNodeVersion_js_1.assertNodeVersion)();
|
|
13
|
-
// package.json#peerDependencies isn't enough as users
|
|
13
|
+
// package.json#peerDependencies isn't enough as users often ignore it
|
|
14
14
|
(0, assertVersion_js_1.assertVersion)('Vite', vite_1.version, '5.1.0');
|
|
15
15
|
// Ensure we don't bloat the server runtime with heavy dependencies such Vite and esbuild
|
|
16
16
|
(0, assertSetup_js_1.assertIsNotProductionRuntime)();
|
|
@@ -18,6 +18,8 @@ const buildConfig_js_1 = require("../buildConfig.js");
|
|
|
18
18
|
const getAssetsDir_js_1 = require("../../shared/getAssetsDir.js");
|
|
19
19
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
20
20
|
const getVikeConfig_js_1 = require("../importUserCode/v1-design/getVikeConfig.js");
|
|
21
|
+
const getOutDirs_js_1 = require("../../shared/getOutDirs.js");
|
|
22
|
+
const viteIsSSR_js_1 = require("../../shared/viteIsSSR.js");
|
|
21
23
|
/**
|
|
22
24
|
* true => use workaround config.build.ssrEmitAssets
|
|
23
25
|
* false => use workaround extractAssets plugin
|
|
@@ -31,7 +33,7 @@ function fixServerAssets_isEnabled() {
|
|
|
31
33
|
}
|
|
32
34
|
/** https://github.com/vikejs/vike/issues/1339 */
|
|
33
35
|
async function fixServerAssets(config) {
|
|
34
|
-
const outDirs = (0,
|
|
36
|
+
const outDirs = (0, getOutDirs_js_1.getOutDirs)(config);
|
|
35
37
|
const clientManifest = await loadManifest(outDirs.outDirClient);
|
|
36
38
|
const serverManifest = await loadManifest(outDirs.outDirServer);
|
|
37
39
|
const { clientManifestMod, serverManifestMod, filesToCopy, filesToRemove } = addServerAssets(clientManifest, serverManifest);
|
|
@@ -47,7 +49,7 @@ async function loadManifest(outDir) {
|
|
|
47
49
|
return manifest;
|
|
48
50
|
}
|
|
49
51
|
async function copyAssets(filesToCopy, filesToRemove, config) {
|
|
50
|
-
const { outDirClient, outDirServer } = (0,
|
|
52
|
+
const { outDirClient, outDirServer } = (0, getOutDirs_js_1.getOutDirs)(config);
|
|
51
53
|
const assetsDir = (0, getAssetsDir_js_1.getAssetsDir)(config);
|
|
52
54
|
const assetsDirServer = path_1.default.posix.join(outDirServer, assetsDir);
|
|
53
55
|
if (!filesToCopy.length && !filesToRemove.length && !(0, fs_2.existsSync)(assetsDirServer))
|
|
@@ -199,7 +201,7 @@ function fixServerAssets_assertCssCodeSplit(config) {
|
|
|
199
201
|
}
|
|
200
202
|
const targets = [];
|
|
201
203
|
function fixServerAssets_assertCssTarget_populate(config) {
|
|
202
|
-
const isServerSide = (0,
|
|
204
|
+
const isServerSide = (0, viteIsSSR_js_1.viteIsSSR)(config);
|
|
203
205
|
(0, utils_js_1.assert)(typeof isServerSide === 'boolean');
|
|
204
206
|
(0, utils_js_1.assert)(config.build.target !== undefined);
|
|
205
207
|
targets.push({ global: config.build.target, css: config.build.cssTarget, isServerSide });
|
|
@@ -20,6 +20,8 @@ const index_js_1 = require("./buildEntry/index.js");
|
|
|
20
20
|
const prependEntriesDir_js_1 = require("../../shared/prependEntriesDir.js");
|
|
21
21
|
const getFilePath_js_1 = require("../shared/getFilePath.js");
|
|
22
22
|
const getConfigValueBuildTime_js_1 = require("../../../shared/page-configs/getConfigValueBuildTime.js");
|
|
23
|
+
const getOutDirs_js_1 = require("../shared/getOutDirs.js");
|
|
24
|
+
const viteIsSSR_js_1 = require("../shared/viteIsSSR.js");
|
|
23
25
|
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
24
26
|
const importMetaUrl = `file://${__filename}`;
|
|
25
27
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
@@ -45,7 +47,7 @@ function buildConfig() {
|
|
|
45
47
|
(0, utils_js_1.assert)(Object.keys(entries).length > 0);
|
|
46
48
|
config.build.rollupOptions.input = (0, utils_js_1.injectRollupInputs)(entries, config);
|
|
47
49
|
addLogHook();
|
|
48
|
-
outDirs = (0,
|
|
50
|
+
outDirs = (0, getOutDirs_js_1.getOutDirs)(config);
|
|
49
51
|
{
|
|
50
52
|
isServerAssetsFixEnabled = (0, fixServerAssets_js_1.fixServerAssets_isEnabled)() && (await (0, getVikeConfig_js_1.isV1Design)(config));
|
|
51
53
|
if (isServerAssetsFixEnabled) {
|
|
@@ -63,10 +65,10 @@ function buildConfig() {
|
|
|
63
65
|
order: 'post',
|
|
64
66
|
handler(config) {
|
|
65
67
|
(0, utils_js_1.onSetupBuild)();
|
|
66
|
-
isSsrBuild = (0,
|
|
68
|
+
isSsrBuild = (0, viteIsSSR_js_1.viteIsSSR)(config);
|
|
67
69
|
return {
|
|
68
70
|
build: {
|
|
69
|
-
outDir: (0,
|
|
71
|
+
outDir: (0, getOutDirs_js_1.resolveOutDir)(config),
|
|
70
72
|
manifest: manifestTempFile,
|
|
71
73
|
copyPublicDir: !isSsrBuild
|
|
72
74
|
}
|
|
@@ -123,7 +125,7 @@ async function getEntries(config) {
|
|
|
123
125
|
// TODO/now: add meta.default
|
|
124
126
|
vikeConfig.global.config.includeAssetsImportedByServer ?? true);
|
|
125
127
|
(0, utils_js_1.assertUsage)(Object.keys(pageFileEntries).length !== 0 || pageConfigs.length !== 0, 'At least one page should be defined, see https://vike.dev/add');
|
|
126
|
-
if ((0,
|
|
128
|
+
if ((0, viteIsSSR_js_1.viteIsSSR)(config)) {
|
|
127
129
|
const pageEntries = getPageEntries(pageConfigs);
|
|
128
130
|
const entries = {
|
|
129
131
|
// buildEntry: resolve('dist/esm/node/buildEntry.js'), // TODO/next-major-release: remove
|
|
@@ -197,7 +199,7 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
197
199
|
// Ensure Rollup creates entries for each page file, see https://github.com/vikejs/vike/issues/350
|
|
198
200
|
// (Otherwise the page files may be missing in the client manifest.json)
|
|
199
201
|
async function getPageFileEntries(config, includeAssetsImportedByServer) {
|
|
200
|
-
const isForClientSide = !(0,
|
|
202
|
+
const isForClientSide = !(0, viteIsSSR_js_1.viteIsSSR)(config);
|
|
201
203
|
const fileTypes = isForClientSide ? ['.page', '.page.client'] : ['.page', '.page.server'];
|
|
202
204
|
if (isForClientSide && includeAssetsImportedByServer) {
|
|
203
205
|
fileTypes.push('.page.server');
|
|
@@ -16,6 +16,7 @@ const importMetaUrl = `file://${__filename}`;
|
|
|
16
16
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
17
17
|
const extractExportNamesPlugin_js_1 = require("../extractExportNamesPlugin.js");
|
|
18
18
|
const globalContext_js_1 = require("../../../runtime/globalContext.js");
|
|
19
|
+
const getOutDirs_js_1 = require("../../shared/getOutDirs.js");
|
|
19
20
|
const ASSETS_MANIFEST = '__VITE_ASSETS_MANIFEST__';
|
|
20
21
|
function buildEntry() {
|
|
21
22
|
let config;
|
|
@@ -100,7 +101,7 @@ function getImportPath(config) {
|
|
|
100
101
|
return 'vike/__internal';
|
|
101
102
|
}
|
|
102
103
|
else {
|
|
103
|
-
const { outDirServer } = (0,
|
|
104
|
+
const { outDirServer } = (0, getOutDirs_js_1.getOutDirs)(config);
|
|
104
105
|
const filePathRelative = path_1.default.posix.relative(outDirServer, filePathAbsolute);
|
|
105
106
|
return filePathRelative;
|
|
106
107
|
}
|
|
@@ -17,7 +17,6 @@ const context_js_1 = require("../../api/context.js");
|
|
|
17
17
|
const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
|
|
18
18
|
const prepareViteApiCall_js_1 = require("../../api/prepareViteApiCall.js");
|
|
19
19
|
const context_js_2 = require("../../prerender/context.js");
|
|
20
|
-
const resolvePrerenderConfig_js_1 = require("../../prerender/resolvePrerenderConfig.js");
|
|
21
20
|
const pluginName = 'vike:commonConfig';
|
|
22
21
|
function commonConfig(vikeVitePluginOptions) {
|
|
23
22
|
return [
|
|
@@ -39,7 +38,7 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
39
38
|
vike: { global: vikeConfig.global },
|
|
40
39
|
// TODO/v1-release: remove https://github.com/vikejs/vike/issues/2122
|
|
41
40
|
configVikePromise: Promise.resolve({
|
|
42
|
-
prerender:
|
|
41
|
+
prerender: (0, context_js_2.isPrerenderEnabled)(vikeConfig)
|
|
43
42
|
})
|
|
44
43
|
};
|
|
45
44
|
}
|
|
@@ -18,6 +18,7 @@ const fixServerAssets_js_1 = require("./buildConfig/fixServerAssets.js");
|
|
|
18
18
|
const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
|
|
19
19
|
const assertV1Design_js_1 = require("../../shared/assertV1Design.js");
|
|
20
20
|
const normalizeId_js_1 = require("../shared/normalizeId.js");
|
|
21
|
+
const viteIsSSR_js_1 = require("../shared/viteIsSSR.js");
|
|
21
22
|
const extractAssetsRE = /(\?|&)extractAssets(?:&|$)/;
|
|
22
23
|
exports.extractAssetsRE = extractAssetsRE;
|
|
23
24
|
const rawRE = /(\?|&)raw(?:&|$)/;
|
|
@@ -47,7 +48,7 @@ function extractAssetsPlugin() {
|
|
|
47
48
|
}
|
|
48
49
|
// TODO/now: add meta.default
|
|
49
50
|
(0, utils_js_1.assert)(vikeConfig.global.config.includeAssetsImportedByServer ?? true);
|
|
50
|
-
(0, utils_js_1.assert)(!(0,
|
|
51
|
+
(0, utils_js_1.assert)(!(0, viteIsSSR_js_1.viteIsSSR_options)(options));
|
|
51
52
|
const importStatements = await (0, parseEsModule_js_1.getImportStatements)(src);
|
|
52
53
|
const moduleNames = getImportedModules(importStatements);
|
|
53
54
|
const code = moduleNames.map((moduleName) => `import '${moduleName}';`).join('\n');
|
|
@@ -64,7 +65,7 @@ function extractAssetsPlugin() {
|
|
|
64
65
|
// - Vite's `vite:resolve` plugin; https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/resolve.ts#L105
|
|
65
66
|
enforce: 'pre',
|
|
66
67
|
async resolveId(source, importer, options) {
|
|
67
|
-
if ((0,
|
|
68
|
+
if ((0, viteIsSSR_js_1.viteIsSSR_options)(options)) {
|
|
68
69
|
// When building for the server, there should never be a `?extractAssets` query
|
|
69
70
|
(0, utils_js_1.assert)(!extractAssetsRE.test(source));
|
|
70
71
|
(0, utils_js_1.assert)(importer === undefined || !extractAssetsRE.test(importer));
|
|
@@ -7,6 +7,7 @@ const utils_js_1 = require("../utils.js");
|
|
|
7
7
|
const parseEsModule_js_1 = require("../shared/parseEsModule.js");
|
|
8
8
|
const rollupSourceMap_js_1 = require("../shared/rollupSourceMap.js");
|
|
9
9
|
const normalizeId_js_1 = require("../shared/normalizeId.js");
|
|
10
|
+
const viteIsSSR_js_1 = require("../shared/viteIsSSR.js");
|
|
10
11
|
const extractExportNamesRE = /(\?|&)extractExportNames(?:&|$)/;
|
|
11
12
|
exports.extractExportNamesRE = extractExportNamesRE;
|
|
12
13
|
const debug = (0, utils_js_1.createDebugger)('vike:extractExportNames');
|
|
@@ -18,7 +19,7 @@ function extractExportNamesPlugin() {
|
|
|
18
19
|
enforce: 'post',
|
|
19
20
|
async transform(src, id, options) {
|
|
20
21
|
id = (0, normalizeId_js_1.normalizeId)(id);
|
|
21
|
-
const isClientSide = !(0,
|
|
22
|
+
const isClientSide = !(0, viteIsSSR_js_1.viteIsSSR_options)(options);
|
|
22
23
|
if (extractExportNamesRE.test(id)) {
|
|
23
24
|
const code = await getExtractExportNamesCode(src, isClientSide, !isDev, id);
|
|
24
25
|
debug('id ' + id, ['result:\n' + code.code.trim(), 'src:\n' + src.trim()]);
|
|
@@ -11,17 +11,17 @@ const fileTypes_js_1 = require("../../../../shared/getPageFiles/fileTypes.js");
|
|
|
11
11
|
const path_1 = __importDefault(require("path"));
|
|
12
12
|
const getVirtualFilePageConfigs_js_1 = require("./v1-design/getVirtualFilePageConfigs.js");
|
|
13
13
|
const getVikeConfig_js_1 = require("./v1-design/getVikeConfig.js");
|
|
14
|
-
const
|
|
14
|
+
const getOutDirs_js_1 = require("../../shared/getOutDirs.js");
|
|
15
|
+
const viteIsSSR_js_1 = require("../../shared/viteIsSSR.js");
|
|
15
16
|
async function getVirtualFileImportUserCode(id, options, vikeConfig, config, isDev) {
|
|
16
17
|
const idParsed = (0, virtualFileImportUserCode_js_1.isVirtualFileIdImportUserCode)(id);
|
|
17
18
|
(0, utils_js_1.assert)(idParsed);
|
|
18
19
|
const { isForClientSide, isClientRouting } = idParsed;
|
|
19
|
-
(0, utils_js_1.assert)(isForClientSide === !(0,
|
|
20
|
-
const
|
|
21
|
-
const code = await getCode(config, vikeConfig, isForClientSide, isClientRouting, isPrerendering, isDev, id);
|
|
20
|
+
(0, utils_js_1.assert)(isForClientSide === !(0, viteIsSSR_js_1.viteIsSSR_options)(options));
|
|
21
|
+
const code = await getCode(config, vikeConfig, isForClientSide, isClientRouting, isDev, id);
|
|
22
22
|
return code;
|
|
23
23
|
}
|
|
24
|
-
async function getCode(config, vikeConfig, isForClientSide, isClientRouting,
|
|
24
|
+
async function getCode(config, vikeConfig, isForClientSide, isClientRouting, isDev, id) {
|
|
25
25
|
const { command } = config;
|
|
26
26
|
(0, utils_js_1.assert)(command === 'serve' || command === 'build');
|
|
27
27
|
const isBuild = command === 'build';
|
|
@@ -30,7 +30,7 @@ async function getCode(config, vikeConfig, isForClientSide, isClientRouting, isP
|
|
|
30
30
|
{
|
|
31
31
|
const globRoots = getGlobRoots(config);
|
|
32
32
|
(0, utils_js_1.debugGlob)('Glob roots: ', globRoots);
|
|
33
|
-
content += await generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, vikeConfig,
|
|
33
|
+
content += await generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, vikeConfig, config, isDev, id);
|
|
34
34
|
}
|
|
35
35
|
(0, utils_js_1.debugGlob)(`Glob imports for ${isForClientSide ? 'client' : 'server'}:\n`, content);
|
|
36
36
|
return content;
|
|
@@ -60,7 +60,7 @@ function determineInjection({ fileType, isForClientSide, isClientRouting, isPrer
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
async function generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, vikeConfig,
|
|
63
|
+
async function generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, vikeConfig, config, isDev, id) {
|
|
64
64
|
let fileContent = `// Generated by https://github.com/vikejs/vike/blob/main/vike/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.ts
|
|
65
65
|
|
|
66
66
|
export const pageFilesLazy = {};
|
|
@@ -75,6 +75,8 @@ ${await (0, getVirtualFilePageConfigs_js_1.getVirtualFilePageConfigs)(isForClien
|
|
|
75
75
|
`;
|
|
76
76
|
// We still use import.meta.glob() when using th V1 design in order to not break the V1 design deprecation warning
|
|
77
77
|
const isV1Design = await (0, getVikeConfig_js_1.isV1Design)(config);
|
|
78
|
+
// Old design => no + files => only to enable pre-rendering is setting `vike({prerender})` in vite.config.js
|
|
79
|
+
const isPrerendering = !!vikeConfig.global.config.prerender;
|
|
78
80
|
fileTypes_js_1.fileTypes
|
|
79
81
|
.filter((fileType) => fileType !== '.css')
|
|
80
82
|
.forEach((fileType) => {
|
|
@@ -170,7 +172,7 @@ function getGlobRoots(config) {
|
|
|
170
172
|
const globRoots = [
|
|
171
173
|
{
|
|
172
174
|
includeDir: '/',
|
|
173
|
-
excludeDir: path_1.default.posix.relative(config.root, (0,
|
|
175
|
+
excludeDir: path_1.default.posix.relative(config.root, (0, getOutDirs_js_1.getOutDirs)(config).outDirRoot)
|
|
174
176
|
}
|
|
175
177
|
];
|
|
176
178
|
return globRoots;
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -4,9 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports.loadPointerImport = loadPointerImport;
|
|
8
8
|
exports.loadValueFile = loadValueFile;
|
|
9
|
-
exports.loadValueFiles = loadValueFiles;
|
|
10
9
|
exports.loadConfigFile = loadConfigFile;
|
|
11
10
|
const utils_js_1 = require("../../../../utils.js");
|
|
12
11
|
const transpileAndExecuteFile_js_1 = require("./transpileAndExecuteFile.js");
|
|
@@ -16,38 +15,36 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
16
15
|
const transformPointerImports_js_1 = require("./transformPointerImports.js");
|
|
17
16
|
const getConfigFileExport_js_1 = require("../getConfigFileExport.js");
|
|
18
17
|
const resolvePointerImport_js_1 = require("./resolvePointerImport.js");
|
|
18
|
+
const getConfigDefinedAt_js_1 = require("../../../../../../shared/page-configs/getConfigDefinedAt.js");
|
|
19
19
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
20
20
|
// Load pointer import
|
|
21
|
-
async function
|
|
22
|
-
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
async function loadPointerImport(pointerImport, userRootDir, configName, configDefinitions, esbuildCache) {
|
|
22
|
+
// The value of `extends` was already loaded and already used: we don't need the value of `extends` anymore
|
|
23
|
+
if (configName === 'extends')
|
|
24
|
+
return;
|
|
25
|
+
const configDef = (0, getVikeConfig_js_1.getConfigDefinitionOptional)(configDefinitions, configName);
|
|
26
|
+
// Only load pointer import if `env.config===true`
|
|
27
|
+
if (!configDef || !shouldBeLoadableAtBuildTime(configDef))
|
|
28
|
+
return;
|
|
29
|
+
const configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAt)('Config', configName, pointerImport.fileExportPath);
|
|
30
|
+
(0, utils_js_1.assertUsage)(pointerImport.fileExportPath.filePathAbsoluteFilesystem, `${configDefinedAt} cannot be defined over an aliased import`);
|
|
31
|
+
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(pointerImport.fileExportPath, userRootDir, false, esbuildCache);
|
|
32
|
+
const fileExportValue = fileExports[pointerImport.fileExportPath.fileExportName];
|
|
33
|
+
pointerImport.fileExportValueLoaded = true;
|
|
34
|
+
(0, utils_js_1.assert)(pointerImport.fileExportValueLoaded);
|
|
35
|
+
pointerImport.fileExportValue = fileExportValue;
|
|
29
36
|
}
|
|
30
37
|
// Load +{configName}.js
|
|
31
|
-
async function loadValueFile(interfaceValueFile, configDefinitions, userRootDir) {
|
|
38
|
+
async function loadValueFile(interfaceValueFile, configDefinitions, userRootDir, esbuildCache) {
|
|
32
39
|
const { configName } = interfaceValueFile;
|
|
33
40
|
const configDef = (0, getVikeConfig_js_1.getConfigDefinitionOptional)(configDefinitions, configName);
|
|
34
|
-
|
|
35
|
-
|
|
41
|
+
// Only load value files with `env.config===true`
|
|
42
|
+
if (!configDef || !shouldBeLoadableAtBuildTime(configDef))
|
|
36
43
|
return;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
await interfaceValueFile.isValueLoaded;
|
|
40
|
-
if (
|
|
41
|
-
// Help TS
|
|
42
|
-
true)
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const { promise, resolve } = (0, utils_js_1.genPromise)();
|
|
46
|
-
interfaceValueFile.isValueLoaded = promise;
|
|
47
|
-
(0, utils_js_1.assert)(interfaceValueFile.isValueLoaded);
|
|
44
|
+
interfaceValueFile.isValueFileLoaded = true;
|
|
45
|
+
(0, utils_js_1.assert)(interfaceValueFile.isValueFileLoaded);
|
|
48
46
|
interfaceValueFile.fileExportsByConfigName = {};
|
|
49
|
-
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(interfaceValueFile.filePath, userRootDir, false);
|
|
50
|
-
resolve();
|
|
47
|
+
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(interfaceValueFile.filePath, userRootDir, false, esbuildCache);
|
|
51
48
|
const { filePathToShowToUser } = interfaceValueFile.filePath;
|
|
52
49
|
(0, assertPlusFileExport_js_1.assertPlusFileExport)(fileExports, filePathToShowToUser, configName);
|
|
53
50
|
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
@@ -55,21 +52,12 @@ async function loadValueFile(interfaceValueFile, configDefinitions, userRootDir)
|
|
|
55
52
|
interfaceValueFile.fileExportsByConfigName[configName_] = configValue;
|
|
56
53
|
});
|
|
57
54
|
}
|
|
58
|
-
async function loadValueFiles(interfaceFiles, configDefinitions, userRootDir) {
|
|
59
|
-
await Promise.all(Object.values(interfaceFiles)
|
|
60
|
-
.flat(1)
|
|
61
|
-
.filter((interfaceFile) => interfaceFile.isValueFile)
|
|
62
|
-
.map(async (interfaceFile) => await loadValueFile(interfaceFile, configDefinitions, userRootDir)));
|
|
63
|
-
}
|
|
64
55
|
// Load +config.js, including all its extends pointer imports
|
|
65
|
-
async function loadConfigFile(configFilePath, userRootDir, visited, isExtensionConfig) {
|
|
56
|
+
async function loadConfigFile(configFilePath, userRootDir, visited, isExtensionConfig, esbuildCache) {
|
|
66
57
|
const { filePathAbsoluteFilesystem } = configFilePath;
|
|
67
58
|
assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem);
|
|
68
|
-
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(configFilePath, userRootDir, isExtensionConfig ? 'is-extension-config' : true);
|
|
69
|
-
const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [
|
|
70
|
-
...visited,
|
|
71
|
-
filePathAbsoluteFilesystem
|
|
72
|
-
]);
|
|
59
|
+
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(configFilePath, userRootDir, isExtensionConfig ? 'is-extension-config' : true, esbuildCache);
|
|
60
|
+
const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [...visited, filePathAbsoluteFilesystem], esbuildCache);
|
|
73
61
|
const configFile = {
|
|
74
62
|
fileExports,
|
|
75
63
|
filePath: configFilePath,
|
|
@@ -85,15 +73,15 @@ function assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem) {
|
|
|
85
73
|
(0, utils_js_1.assert)(loop[0] === filePathAbsoluteFilesystem);
|
|
86
74
|
(0, utils_js_1.assertUsage)(idx === -1, `Infinite extends loop ${[...loop, filePathAbsoluteFilesystem].join('>')}`);
|
|
87
75
|
}
|
|
88
|
-
async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir, visited) {
|
|
76
|
+
async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir, visited, esbuildCache) {
|
|
89
77
|
const { extendsPointerImportData, extendsConfigs } = getExtendsPointerImportData(configFileExports, configFilePath);
|
|
90
78
|
const extendsConfigFiles = [];
|
|
91
79
|
extendsPointerImportData.map((pointerImportData) => {
|
|
92
|
-
const filePath = (0, resolvePointerImport_js_1.
|
|
80
|
+
const filePath = (0, resolvePointerImport_js_1.resolvePointerImportData)(pointerImportData, configFilePath, userRootDir);
|
|
93
81
|
(0, utils_js_1.assert)(filePath.filePathAbsoluteFilesystem);
|
|
94
82
|
extendsConfigFiles.push(filePath);
|
|
95
83
|
});
|
|
96
|
-
const results = await Promise.all(extendsConfigFiles.map(async (configFilePath) => await loadConfigFile(configFilePath, userRootDir, visited, true)));
|
|
84
|
+
const results = await Promise.all(extendsConfigFiles.map(async (configFilePath) => await loadConfigFile(configFilePath, userRootDir, visited, true, esbuildCache)));
|
|
97
85
|
results.forEach((result) => {
|
|
98
86
|
extendsConfigs.push(result.configFile);
|
|
99
87
|
extendsConfigs.push(...result.extendsConfigs);
|
|
@@ -136,3 +124,6 @@ function getExtendsPointerImportData(configFileExports, configFilePath) {
|
|
|
136
124
|
}
|
|
137
125
|
return { extendsPointerImportData, extendsConfigs };
|
|
138
126
|
}
|
|
127
|
+
function shouldBeLoadableAtBuildTime(configDef) {
|
|
128
|
+
return !!configDef.env.config && !configDef._valueIsFilePath;
|
|
129
|
+
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
CHANGED
|
@@ -3,37 +3,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.resolvePointerImportOfConfig = resolvePointerImportOfConfig;
|
|
7
6
|
exports.resolvePointerImport = resolvePointerImport;
|
|
8
|
-
exports.
|
|
9
|
-
exports.resolveConfigEnvWithFileName = resolveConfigEnvWithFileName;
|
|
7
|
+
exports.resolvePointerImportData = resolvePointerImportData;
|
|
10
8
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
11
9
|
const utils_js_1 = require("../../../../utils.js");
|
|
12
10
|
const transformPointerImports_js_1 = require("./transformPointerImports.js");
|
|
13
11
|
const path_1 = __importDefault(require("path"));
|
|
14
12
|
const getFilePath_js_1 = require("../../../../shared/getFilePath.js");
|
|
15
|
-
|
|
16
|
-
function resolvePointerImportOfConfig(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
13
|
+
function resolvePointerImport(configValue, importerFilePath, userRootDir, configName) {
|
|
17
14
|
if (typeof configValue !== 'string')
|
|
18
15
|
return null;
|
|
19
16
|
const pointerImportData = (0, transformPointerImports_js_1.parsePointerImportData)(configValue);
|
|
20
17
|
if (!pointerImportData)
|
|
21
18
|
return null;
|
|
22
|
-
const {
|
|
23
|
-
const filePath =
|
|
19
|
+
const { exportName } = pointerImportData;
|
|
20
|
+
const filePath = resolvePointerImportData(pointerImportData, importerFilePath, userRootDir);
|
|
24
21
|
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
25
|
-
|
|
26
|
-
if (filePath.filePathAbsoluteFilesystem)
|
|
27
|
-
configEnvResolved = resolveConfigEnvWithFileName(configEnv, filePath);
|
|
28
|
-
assertUsageFileEnv(filePath, importPath, configEnvResolved, configName);
|
|
29
|
-
const pointerImport = {
|
|
22
|
+
const fileExportPath = {
|
|
30
23
|
...filePath,
|
|
31
24
|
fileExportName: exportName,
|
|
32
25
|
fileExportPathToShowToUser
|
|
33
26
|
};
|
|
34
|
-
return {
|
|
27
|
+
return { fileExportPath };
|
|
35
28
|
}
|
|
36
|
-
function
|
|
29
|
+
function resolvePointerImportData(pointerImportData, importerFilePath, userRootDir) {
|
|
37
30
|
// `importPath` should be one of the following:
|
|
38
31
|
// - A relative import path
|
|
39
32
|
// - A filesystem absolute path
|
|
@@ -44,7 +37,7 @@ function resolvePointerImport(pointerImportData, importerFilePath, userRootDir)
|
|
|
44
37
|
(0, utils_js_1.assertPosixPath)(importPath);
|
|
45
38
|
if (importPath.startsWith('.') || (0, utils_js_1.isFilePathAbsolute)(importPath)) {
|
|
46
39
|
if (importPath.startsWith('.')) {
|
|
47
|
-
(0, utils_js_1.assertUsage)(
|
|
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.`);
|
|
48
41
|
}
|
|
49
42
|
// Pointer imports are included in virtual files, thus relative imports need to be resolved. (Virtual modules cannot contain relative imports.)
|
|
50
43
|
assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath);
|
|
@@ -100,7 +93,7 @@ function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportD
|
|
|
100
93
|
: `The import ${picocolors_1.default.code(importString)} defined by ${filePathToShowToUser}`;
|
|
101
94
|
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
102
95
|
if (importPath.startsWith('.')) {
|
|
103
|
-
(0, utils_js_1.assert)(
|
|
96
|
+
(0, utils_js_1.assert)((0, utils_js_1.pathIsRelative)(importPath));
|
|
104
97
|
(0, utils_js_1.assertUsage)(false, `${errIntro2} point to an existing file?`);
|
|
105
98
|
}
|
|
106
99
|
else {
|
|
@@ -108,51 +101,3 @@ function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportD
|
|
|
108
101
|
}
|
|
109
102
|
}
|
|
110
103
|
}
|
|
111
|
-
function assertUsageFileEnv(filePath, importPath, configEnvResolved, configName) {
|
|
112
|
-
let key;
|
|
113
|
-
if (filePath.filePathAbsoluteFilesystem) {
|
|
114
|
-
key = filePath.filePathAbsoluteFilesystem;
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
// Path alias
|
|
118
|
-
(0, utils_js_1.assert)(!isRelativeImportPath(importPath));
|
|
119
|
-
key = importPath;
|
|
120
|
-
}
|
|
121
|
-
(0, utils_js_1.assertPosixPath)(key);
|
|
122
|
-
if (!filesEnvMap.has(key)) {
|
|
123
|
-
filesEnvMap.set(key, []);
|
|
124
|
-
}
|
|
125
|
-
const fileEnv = filesEnvMap.get(key);
|
|
126
|
-
fileEnv.push({ configEnvResolved, configName });
|
|
127
|
-
const configDifferentEnv = fileEnv.filter((c) => !(0, utils_js_1.deepEqual)(c.configEnvResolved, configEnvResolved))[0];
|
|
128
|
-
if (configDifferentEnv) {
|
|
129
|
-
(0, utils_js_1.assertUsage)(false, [
|
|
130
|
-
`${key} defines the value of configs living in different environments:`,
|
|
131
|
-
...[configDifferentEnv, { configName, configEnvResolved }].map((c) => ` - config ${picocolors_1.default.code(c.configName)} which value lives in environment ${picocolors_1.default.code(JSON.stringify(c.configEnvResolved))}`),
|
|
132
|
-
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/config#pointer-imports'
|
|
133
|
-
].join('\n'));
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
function clearFilesEnvMap() {
|
|
137
|
-
filesEnvMap.clear();
|
|
138
|
-
}
|
|
139
|
-
function resolveConfigEnvWithFileName(configEnv, filePath) {
|
|
140
|
-
const { fileName } = filePath;
|
|
141
|
-
const configEnvResolved = { ...configEnv };
|
|
142
|
-
if (fileName.includes('.server.')) {
|
|
143
|
-
configEnvResolved.server = true;
|
|
144
|
-
configEnvResolved.client = false;
|
|
145
|
-
}
|
|
146
|
-
else if (fileName.includes('.client.')) {
|
|
147
|
-
configEnvResolved.client = true;
|
|
148
|
-
configEnvResolved.server = false;
|
|
149
|
-
}
|
|
150
|
-
else if (fileName.includes('.shared.')) {
|
|
151
|
-
configEnvResolved.server = true;
|
|
152
|
-
configEnvResolved.client = true;
|
|
153
|
-
}
|
|
154
|
-
return configEnvResolved;
|
|
155
|
-
}
|
|
156
|
-
function isRelativeImportPath(importPath) {
|
|
157
|
-
return importPath.startsWith('./') || importPath.startsWith('../');
|
|
158
|
-
}
|
|
@@ -26,25 +26,31 @@ const debug = (0, utils_js_1.createDebugger)('vike:pointer-imports');
|
|
|
26
26
|
const debugEsbuildResolve = (0, utils_js_1.createDebugger)('vike:esbuild-resolve');
|
|
27
27
|
if (debugEsbuildResolve.isActivated)
|
|
28
28
|
debugEsbuildResolve('esbuild version', esbuild_1.version);
|
|
29
|
-
async function transpileAndExecuteFile(filePath, userRootDir, isConfigFile) {
|
|
29
|
+
async function transpileAndExecuteFile(filePath, userRootDir, isConfigFile, esbuildCache) {
|
|
30
30
|
const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
|
|
31
31
|
const fileExtension = getFileExtension(filePathAbsoluteFilesystem);
|
|
32
|
+
if (esbuildCache[filePathAbsoluteFilesystem]) {
|
|
33
|
+
return await esbuildCache[filePathAbsoluteFilesystem];
|
|
34
|
+
}
|
|
35
|
+
const { promise, resolve } = (0, utils_js_1.genPromise)();
|
|
36
|
+
esbuildCache[filePathAbsoluteFilesystem] = promise;
|
|
32
37
|
(0, utils_js_1.assertUsage)((0, utils_js_1.isPlainJavaScriptFile)(filePathAbsoluteFilesystem), `${filePathToShowToUserResolved} has file extension .${fileExtension} but a config file can only be a JavaScript/TypeScript file`);
|
|
33
38
|
const isHeader = isHeaderFile(filePathAbsoluteFilesystem);
|
|
34
39
|
if (isHeader) {
|
|
35
40
|
(0, utils_js_1.assertWarning)(false, `${picocolors_1.default.cyan('.h.js')} files are deprecated: simply renaming ${filePathToShowToUserResolved} to ${removeHeaderFileExtension(filePathToShowToUserResolved)} is usually enough, although you may occasionally need to use ${picocolors_1.default.cyan("with { type: 'pointer' }")} as explained at https://vike.dev/config#pointer-imports`, { onlyOnce: true });
|
|
36
41
|
}
|
|
42
|
+
let fileExports;
|
|
37
43
|
if (isConfigFile === 'is-extension-config' && !isHeader && fileExtension.endsWith('js')) {
|
|
38
44
|
// This doesn't track dependencies => we should never use this for user land configs
|
|
39
|
-
|
|
40
|
-
return { fileExports };
|
|
45
|
+
fileExports = await executeFile(filePathAbsoluteFilesystem, filePath);
|
|
41
46
|
}
|
|
42
47
|
else {
|
|
43
48
|
const transformImports = isConfigFile && (isHeader ? 'all' : true);
|
|
44
49
|
const code = await transpileFile(filePath, transformImports, userRootDir);
|
|
45
|
-
|
|
46
|
-
return { fileExports };
|
|
50
|
+
fileExports = await executeTranspiledFile(filePath, code);
|
|
47
51
|
}
|
|
52
|
+
resolve({ fileExports });
|
|
53
|
+
return { fileExports };
|
|
48
54
|
}
|
|
49
55
|
async function transpileFile(filePath, transformImports, userRootDir) {
|
|
50
56
|
const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
|