vike 0.4.253-commit-3e3975d → 0.4.253-commit-332f31b
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/node/vite/index.js +2 -0
- package/dist/node/vite/plugins/pluginDev/optimizeDeps.js +1 -1
- package/dist/node/vite/plugins/pluginStripPointerImportAttribute.d.ts +4 -0
- package/dist/node/vite/plugins/pluginStripPointerImportAttribute.js +31 -0
- package/dist/node/vite/shared/resolveVikeConfigInternal/crawlPlusFilePaths/ignorePatternsBuiltIn.d.ts +1 -1
- package/dist/node/vite/shared/resolveVikeConfigInternal/crawlPlusFilePaths/ignorePatternsBuiltIn.js +3 -0
- package/dist/node/vite/shared/resolveVikeConfigInternal/getPlusFilesByLocationId.d.ts +2 -0
- package/dist/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.js +3 -22
- package/dist/node/vite/shared/resolveVikeConfigInternal.js +13 -6
- package/dist/shared-server-client/page-configs/loadAndParseVirtualFilePageEntry.js +12 -1
- package/dist/shared-server-client/page-configs/serialize/serializeConfigValues.js +1 -11
- package/dist/types/PageConfig.d.ts +1 -1
- package/dist/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/utils/PROJECT_VERSION.js +1 -1
- package/package.json +1 -1
package/dist/node/vite/index.js
CHANGED
|
@@ -36,6 +36,7 @@ import { pluginModuleBanner } from './plugins/build/pluginModuleBanner.js';
|
|
|
36
36
|
import { pluginReplaceConstantsNonRunnableDev } from './plugins/non-runnable-dev/pluginReplaceConstantsNonRunnableDev.js';
|
|
37
37
|
import { isVikeCliOrApi } from '../../shared-server-node/api-context.js';
|
|
38
38
|
import { pluginViteConfigVikeExtensions } from './plugins/pluginViteConfigVikeExtensions.js';
|
|
39
|
+
import { pluginStripPointerImportAttribute } from './plugins/pluginStripPointerImportAttribute.js';
|
|
39
40
|
import { getVikeConfigInternalEarly, isOnlyResolvingUserConfig } from '../api/resolveViteConfigFromUser.js';
|
|
40
41
|
import './assertEnvVite.js';
|
|
41
42
|
// We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
|
|
@@ -67,6 +68,7 @@ function plugin(vikeVitePluginOptions = {}) {
|
|
|
67
68
|
...pluginReplaceConstantsGlobalThis(),
|
|
68
69
|
...pluginStaticReplace(vikeConfig),
|
|
69
70
|
...pluginNonRunnabeDev(),
|
|
71
|
+
...pluginStripPointerImportAttribute(),
|
|
70
72
|
...(await pluginViteConfigVikeExtensions(vikeConfig)),
|
|
71
73
|
];
|
|
72
74
|
Object.assign(plugin, pluginAddendum);
|
|
@@ -181,7 +181,7 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
181
181
|
};
|
|
182
182
|
const sourcesRelevant = getConfigValueSourcesRelevant(configName, runtimeEnv, pageConfig);
|
|
183
183
|
sourcesRelevant.forEach((configValueSource) => {
|
|
184
|
-
if (!configValueSource.
|
|
184
|
+
if (!configValueSource.valueLoadedViaImport && !configValueSource.valueIsFilePath)
|
|
185
185
|
return;
|
|
186
186
|
const { definedAt } = configValueSource;
|
|
187
187
|
if (definedAt.definedBy)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export { pluginStripPointerImportAttribute };
|
|
2
|
+
import { getMagicString } from '../shared/getMagicString.js';
|
|
3
|
+
import '../assertEnvVite.js';
|
|
4
|
+
// Match `with { type: 'vike-pointer' }` (with optional whitespace variations)
|
|
5
|
+
const runtimeAttrRE = /\bwith\s*\{\s*type\s*:\s*['"]vike-pointer['"]\s*\}/g;
|
|
6
|
+
function pluginStripPointerImportAttribute() {
|
|
7
|
+
return [
|
|
8
|
+
{
|
|
9
|
+
name: 'vike:pluginStripPointerImportAttribute',
|
|
10
|
+
transform: {
|
|
11
|
+
filter: {
|
|
12
|
+
code: {
|
|
13
|
+
include: 'vike-pointer',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
handler(code, id) {
|
|
17
|
+
runtimeAttrRE.lastIndex = 0;
|
|
18
|
+
if (!runtimeAttrRE.test(code))
|
|
19
|
+
return;
|
|
20
|
+
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
21
|
+
runtimeAttrRE.lastIndex = 0;
|
|
22
|
+
let match;
|
|
23
|
+
while ((match = runtimeAttrRE.exec(code)) !== null) {
|
|
24
|
+
magicString.remove(match.index, match.index + match[0].length);
|
|
25
|
+
}
|
|
26
|
+
return getMagicStringResult();
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import '../../../assertEnvVite.js';
|
|
2
|
-
export declare const ignorePatternsBuiltIn: readonly ["**/node_modules/**", "**/ejected/**", "**/*.telefunc.*", "**/.history/**", "**/*.generated.*"];
|
|
2
|
+
export declare const ignorePatternsBuiltIn: readonly ["**/node_modules/**", "**/ejected/**", "**/*.telefunc.*", "**/.history/**", "**/*.generated.*", "**/*.spec.*", "**/*.test.*"];
|
|
@@ -14,6 +14,7 @@ type PlusFileCommon = {
|
|
|
14
14
|
};
|
|
15
15
|
/** +config.js */
|
|
16
16
|
type PlusFileConfig = PlusFileCommon & {
|
|
17
|
+
/** Whether file is `+config.js` or `+{configName}.js` */
|
|
17
18
|
isConfigFile: true;
|
|
18
19
|
fileExportsByConfigName: Record<string, // configName
|
|
19
20
|
unknown>;
|
|
@@ -25,6 +26,7 @@ type PlusFileConfig = PlusFileCommon & {
|
|
|
25
26
|
};
|
|
26
27
|
/** +{configName}.js */
|
|
27
28
|
type PlusFileValue = PlusFileCommon & {
|
|
29
|
+
/** Whether file is `+config.js` or `+{configName}.js` */
|
|
28
30
|
isConfigFile: false;
|
|
29
31
|
configName: string;
|
|
30
32
|
} & ({
|
|
@@ -15,7 +15,7 @@ import { genPromise } from '../../../../utils/genPromise.js';
|
|
|
15
15
|
import { assertFilePathAbsoluteFilesystem } from '../../../../utils/isFilePathAbsoluteFilesystem.js';
|
|
16
16
|
import { isImportPathRelative } from '../../../../utils/isImportPath.js';
|
|
17
17
|
import { isObject } from '../../../../utils/isObject.js';
|
|
18
|
-
import { isPlainScriptFile
|
|
18
|
+
import { isPlainScriptFile } from '../../../../utils/isScriptFile.js';
|
|
19
19
|
import { isVitest } from '../../../../utils/isVitest.js';
|
|
20
20
|
import { assertIsImportPathNpmPackage, isImportPathNpmPackageOrPathAlias } from '../../../../utils/parseNpmPackage.js';
|
|
21
21
|
import { assertPosixPath, toPosixPath } from '../../../../utils/path.js';
|
|
@@ -182,19 +182,10 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
182
182
|
// - assertIsImportPathNpmPackage()
|
|
183
183
|
// - isImportPathNpmPackage(str, { cannotBePathAlias: true })
|
|
184
184
|
assertFilePathAbsoluteFilesystem(importPathResolved);
|
|
185
|
-
// Non-script file (e.g. .svg, .css) => resolve to constant string so that files with
|
|
186
|
-
// `env: { config: true, client: true }` can also be loaded in Node.js
|
|
187
|
-
if (!isScriptFile(importPathResolved)) {
|
|
188
|
-
esbuildCache.vikeConfigDependencies.add(importPathResolved);
|
|
189
|
-
return {
|
|
190
|
-
path: importPathResolved,
|
|
191
|
-
namespace: 'vike-static-file',
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
185
|
// Should be remove this? See comment below.
|
|
195
186
|
const isVikeExtensionImport = (path.startsWith('vike-') && path.endsWith('/config')) || importPathResolved.endsWith('+config.js');
|
|
196
187
|
const isPointerImport = transformImports === 'all' ||
|
|
197
|
-
// .jsx, .
|
|
188
|
+
// .jsx, .vue, .svg, ... => obviously not config code => pointer import
|
|
198
189
|
!isPlainScriptFile(importPathResolved) ||
|
|
199
190
|
// Import of a Vike extension config => make it a pointer import because we want to show nice error messages (that can display whether a config has been set by the user or by a Vike extension).
|
|
200
191
|
// - Should we stop doing this? (And instead let Node.js directly load Vike extensions.)
|
|
@@ -202,9 +193,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
202
193
|
// - vike@0.4.162 started soft-requiring Vike extensions to set the name config.
|
|
203
194
|
// - In practice, it seems like it requires some (non-trivial?) refactoring.
|
|
204
195
|
isVikeExtensionImport ||
|
|
205
|
-
|
|
206
|
-
// mechanism correctly encodes path + export name (import:path:exportName).
|
|
207
|
-
args.with?.['type'] === 'runtime';
|
|
196
|
+
args.with?.['type'] === 'vike-pointer';
|
|
208
197
|
assertPosixPath(importPathResolved);
|
|
209
198
|
// `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`.
|
|
210
199
|
const isNpmPkgImport = (() => {
|
|
@@ -273,14 +262,6 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
273
262
|
pointerImports[importPathTranspiled] = isPointerImport;
|
|
274
263
|
return { external: true, path: importPathTranspiled };
|
|
275
264
|
});
|
|
276
|
-
build.onLoad({ filter: /.*/, namespace: 'vike-static-file' }, (args) => {
|
|
277
|
-
// args.path is an absolute filesystem path; convert to a Vite-compatible path.
|
|
278
|
-
const vitePath = getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem: args.path, userRootDir }) ?? `/@fs${args.path}`;
|
|
279
|
-
return {
|
|
280
|
-
contents: `export default 'STATIC_FILE_NOT_AVAILABLE:${vitePath}'`,
|
|
281
|
-
loader: 'js',
|
|
282
|
-
};
|
|
283
|
-
});
|
|
284
265
|
},
|
|
285
266
|
},
|
|
286
267
|
// Track dependencies
|
|
@@ -513,7 +513,7 @@ function getSourceNonConfigFile(configName, value, definedAt) {
|
|
|
513
513
|
definedAt,
|
|
514
514
|
locationId: '/',
|
|
515
515
|
plusFile: null,
|
|
516
|
-
|
|
516
|
+
valueLoadedViaImport: false,
|
|
517
517
|
valueIsDefinedByPlusValueFile: false,
|
|
518
518
|
};
|
|
519
519
|
return source;
|
|
@@ -667,7 +667,7 @@ function getConfigValueSources(configName, plusFile, configDef, userRootDir) {
|
|
|
667
667
|
value: valueFilePath,
|
|
668
668
|
valueIsFilePath: true,
|
|
669
669
|
configEnv: configDef.env,
|
|
670
|
-
|
|
670
|
+
valueLoadedViaImport: false,
|
|
671
671
|
valueIsDefinedByPlusValueFile: false,
|
|
672
672
|
definedAt: definedAtFilePath,
|
|
673
673
|
};
|
|
@@ -692,7 +692,7 @@ function getConfigValueSources(configName, plusFile, configDef, userRootDir) {
|
|
|
692
692
|
...configValueSourceCommon,
|
|
693
693
|
...value,
|
|
694
694
|
configEnv: resolveConfigEnv(configDef.env, pointerImport.fileExportPath),
|
|
695
|
-
|
|
695
|
+
valueLoadedViaImport: true,
|
|
696
696
|
valueIsDefinedByPlusValueFile: false,
|
|
697
697
|
definedAt: pointerImport.fileExportPath,
|
|
698
698
|
};
|
|
@@ -705,7 +705,7 @@ function getConfigValueSources(configName, plusFile, configDef, userRootDir) {
|
|
|
705
705
|
valueIsLoaded: true,
|
|
706
706
|
value: confVal.value,
|
|
707
707
|
configEnv: configDef.env,
|
|
708
|
-
|
|
708
|
+
valueLoadedViaImport: false,
|
|
709
709
|
valueIsDefinedByPlusValueFile: false,
|
|
710
710
|
definedAt: definedAtFilePath_,
|
|
711
711
|
};
|
|
@@ -719,7 +719,14 @@ function getConfigValueSources(configName, plusFile, configDef, userRootDir) {
|
|
|
719
719
|
...configValueSourceCommon,
|
|
720
720
|
...confVal,
|
|
721
721
|
configEnv: configEnvResolved,
|
|
722
|
-
|
|
722
|
+
valueLoadedViaImport:
|
|
723
|
+
// If +{configName}.js is (also) runtime code => always load it via import (not strictly required, but seems to be a good default)
|
|
724
|
+
!!configEnvResolved.client ||
|
|
725
|
+
!!configEnvResolved.server ||
|
|
726
|
+
// No choice: value isn't loaded at config-time
|
|
727
|
+
!confVal.valueIsLoaded ||
|
|
728
|
+
// No choice: value isn't serializable
|
|
729
|
+
!isJsonValue(confVal.value),
|
|
723
730
|
valueIsDefinedByPlusValueFile: true,
|
|
724
731
|
definedAt: {
|
|
725
732
|
...plusFile.filePath,
|
|
@@ -903,7 +910,7 @@ function applyEffectConfVal(configModFromEffect, sourceEffect, configValueSource
|
|
|
903
910
|
plusFile: sourceEffect.plusFile,
|
|
904
911
|
locationId: sourceEffect.locationId,
|
|
905
912
|
configEnv: configDef.env,
|
|
906
|
-
|
|
913
|
+
valueLoadedViaImport: false,
|
|
907
914
|
valueIsDefinedByPlusValueFile: false,
|
|
908
915
|
valueIsLoaded: true,
|
|
909
916
|
value: configValue,
|
|
@@ -16,7 +16,18 @@ async function loadAndParseVirtualFilePageEntry(pageConfig, isDev) {
|
|
|
16
16
|
// Catch @cloudflare/vite-plugin bug
|
|
17
17
|
assertVirtualFileExports(moduleExports, () => 'configValuesSerialized' in moduleExports, moduleId);
|
|
18
18
|
const virtualFileExportsPageEntry = moduleExports;
|
|
19
|
-
|
|
19
|
+
let configValues;
|
|
20
|
+
try {
|
|
21
|
+
configValues = parseVirtualFileExportsPageEntry(virtualFileExportsPageEntry);
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
if (!(e instanceof ReferenceError))
|
|
25
|
+
throw e;
|
|
26
|
+
// Safari WebKit bug: dynamic import() may resolve before the module body executes,
|
|
27
|
+
// https://github.com/vikejs/vike/issues/3121
|
|
28
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
29
|
+
configValues = parseVirtualFileExportsPageEntry(virtualFileExportsPageEntry);
|
|
30
|
+
}
|
|
20
31
|
Object.assign(pageConfig.configValues, configValues);
|
|
21
32
|
objectAssign(pageConfig, { isPageEntryLoaded: true });
|
|
22
33
|
return pageConfig;
|
|
@@ -16,7 +16,6 @@ import { getConfigValueSourcesRelevant, isRuntimeEnvMatch, } from '../../../node
|
|
|
16
16
|
const stringifyOptions = { forbidReactElements: true };
|
|
17
17
|
const REPLACE_ME_BEFORE = '__VIKE__REPLACE_ME_BEFORE__';
|
|
18
18
|
const REPLACE_ME_AFTER = '__VIKE__REPLACE_ME_AFTER__';
|
|
19
|
-
const STATIC_FILE_NOT_AVAILABLE_PREFIX = 'STATIC_FILE_NOT_AVAILABLE:';
|
|
20
19
|
// This file is never loaded on the client-side but we save it under the vike/shared/ directory in order to collocate it with parsePageConfigsSerialized()
|
|
21
20
|
// - vike/shared/page-configs/serialize/parsePageConfigsSerialized.ts
|
|
22
21
|
// - parsePageConfigsSerialized() is loaded on both the client- and server-side.
|
|
@@ -53,7 +52,7 @@ function serializeConfigValues(pageConfig, importStatements, filesEnv, runtimeEn
|
|
|
53
52
|
}
|
|
54
53
|
function getValueSerializedFromSource(configValueSource, configName, importStatements, filesEnv) {
|
|
55
54
|
let valueData;
|
|
56
|
-
if (configValueSource.valueIsLoaded && !configValueSource.
|
|
55
|
+
if (configValueSource.valueIsLoaded && !configValueSource.valueLoadedViaImport) {
|
|
57
56
|
valueData = getValueSerializedWithJson(configValueSource.value, configName, configValueSource.definedAt, importStatements, filesEnv, configValueSource.configEnv);
|
|
58
57
|
}
|
|
59
58
|
else {
|
|
@@ -142,15 +141,6 @@ function valueToJson(value, configName, definedAtData, importStatements, filesEn
|
|
|
142
141
|
const replacement = [REPLACE_ME_BEFORE, importName, REPLACE_ME_AFTER].join('');
|
|
143
142
|
return { replacement };
|
|
144
143
|
}
|
|
145
|
-
// Handle STATIC_FILE_NOT_AVAILABLE strings: these are generated during config
|
|
146
|
-
// execution when a non-script file (e.g. .svg) or a `with { type: 'runtime' }`
|
|
147
|
-
// import is encountered. They must become runtime imports, not raw strings.
|
|
148
|
-
if (value.startsWith(STATIC_FILE_NOT_AVAILABLE_PREFIX)) {
|
|
149
|
-
const importPath = value.slice(STATIC_FILE_NOT_AVAILABLE_PREFIX.length);
|
|
150
|
-
const { importName } = addImportStatement(importStatements, importPath, 'default', filesEnv, configEnv, configName);
|
|
151
|
-
const replacement = [REPLACE_ME_BEFORE, importName, REPLACE_ME_AFTER].join('');
|
|
152
|
-
return { replacement };
|
|
153
|
-
}
|
|
154
144
|
}
|
|
155
145
|
},
|
|
156
146
|
});
|
|
@@ -98,7 +98,7 @@ type ConfigValueSource = {
|
|
|
98
98
|
plusFile: PlusFile | null;
|
|
99
99
|
locationId: LocationId;
|
|
100
100
|
/** Whether the config value is loaded at runtime, for example config.Page or config.onBeforeRender */
|
|
101
|
-
|
|
101
|
+
valueLoadedViaImport: boolean;
|
|
102
102
|
/** Whether the config value is a file path, this is currently only true for +client */
|
|
103
103
|
valueIsFilePath?: true;
|
|
104
104
|
/** Whether the config value is defined by a +{configName}.js file */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.253-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.253-commit-332f31b";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.253-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.253-commit-332f31b';
|