vike 0.4.249-commit-ec50591 → 0.4.249-commit-d781796

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.
@@ -11,6 +11,7 @@ const constantsIsClientSide = [
11
11
  ];
12
12
  // - See https://vike.dev/pageContext#narrowing-down
13
13
  // - We cannot use [`define`](https://vite.dev/config/shared-options.html#define) because of https://github.com/rolldown/rolldown/issues/4300
14
+ // filterRolldown
14
15
  const skipNodeModules = '/node_modules/';
15
16
  const skipIrrelevant = 'Context.isClientSide';
16
17
  assert(constantsIsClientSide.every((constant) => constant.endsWith(skipIrrelevant)));
@@ -110,14 +110,21 @@ type StaticReplace = {
110
110
  /** Remove target (optional) */
111
111
  remove?: RemoveTarget;
112
112
  };
113
- type TransformResult = {
114
- code: string;
115
- map: any;
116
- } | null;
117
113
  type TransformInput = {
118
114
  code: string;
119
115
  id: string;
120
116
  env: string;
121
117
  options: StaticReplace[];
122
118
  };
123
- declare function applyStaticReplace({ code, id, env, options }: TransformInput): Promise<TransformResult>;
119
+ declare function applyStaticReplace({ code, id, env, options }: TransformInput): Promise<{
120
+ code: string;
121
+ map: {
122
+ version: number;
123
+ sources: string[];
124
+ names: string[];
125
+ sourceRoot?: string | undefined;
126
+ sourcesContent?: string[] | undefined;
127
+ mappings: string;
128
+ file: string;
129
+ } | null | undefined;
130
+ } | null>;
@@ -6,8 +6,4 @@ import type { StaticReplace } from './applyStaticReplace.js';
6
6
  * except for call.match.function array which is OR logic.
7
7
  * Between staticReplace entries it's OR logic.
8
8
  */
9
- declare function buildFilterRolldown(staticReplaceList: StaticReplace[]): {
10
- code: {
11
- include: RegExp;
12
- };
13
- } | null;
9
+ declare function buildFilterRolldown(staticReplaceList: StaticReplace[]): RegExp | null;
@@ -61,12 +61,7 @@ function buildFilterRolldown(staticReplaceList) {
61
61
  if (rulePatterns.length === 0)
62
62
  return null;
63
63
  // Create a regex that matches if any rule pattern matches (OR between staticReplace entries)
64
- const regex = new RegExp(rulePatterns.join('|'));
65
- return {
66
- code: {
67
- include: regex,
68
- },
69
- };
64
+ return new RegExp(rulePatterns.join('|'), 's');
70
65
  }
71
66
  /**
72
67
  * Extract import strings from function patterns
@@ -1,15 +1,34 @@
1
1
  export { pluginStaticReplace };
2
- import { assert } from '../utils.js';
2
+ import { assert, createDebug } from '../utils.js';
3
3
  import { isViteServerSide_extraSafe } from '../shared/isViteServerSide.js';
4
4
  import { applyStaticReplace } from './pluginStaticReplace/applyStaticReplace.js';
5
5
  import { buildFilterRolldown } from './pluginStaticReplace/buildFilterRolldown.js';
6
+ const debug = createDebug('vike:staticReplace');
6
7
  function pluginStaticReplace(vikeConfig) {
7
8
  let config;
9
+ // staticReplaceList
8
10
  const staticReplaceList = getStaticReplaceList(vikeConfig);
9
11
  if (staticReplaceList.length === 0)
10
12
  return [];
11
- const filterRolldown = buildFilterRolldown(staticReplaceList);
12
- assert(filterRolldown);
13
+ // filterRolldown
14
+ const skipNodeModules = '/node_modules/';
15
+ const include = buildFilterRolldown(staticReplaceList);
16
+ assert(include);
17
+ const filterRolldown = {
18
+ id: {
19
+ exclude: `**${skipNodeModules}**`,
20
+ },
21
+ code: {
22
+ include,
23
+ },
24
+ };
25
+ const filterFunction = (id, code) => {
26
+ if (id.includes(skipNodeModules))
27
+ return false;
28
+ if (!include.test(code))
29
+ return false;
30
+ return true;
31
+ };
13
32
  return [
14
33
  {
15
34
  name: 'vike:pluginStaticReplace',
@@ -20,13 +39,9 @@ function pluginStaticReplace(vikeConfig) {
20
39
  },
21
40
  },
22
41
  transform: {
23
- filter: {
24
- code: {
25
- include: filterRolldown.code.include,
26
- exclude: /node_modules/,
27
- },
28
- },
42
+ filter: filterRolldown,
29
43
  async handler(code, id, options) {
44
+ assert(filterFunction(id, code));
30
45
  const env = isViteServerSide_extraSafe(config, this.environment, options) ? 'server' : 'client';
31
46
  const result = await applyStaticReplace({
32
47
  code,
@@ -34,6 +49,11 @@ function pluginStaticReplace(vikeConfig) {
34
49
  env,
35
50
  options: staticReplaceList,
36
51
  });
52
+ if (debug.isActivated && result) {
53
+ debug('id', id);
54
+ debug('before', code);
55
+ debug('after', result.code);
56
+ }
37
57
  return result;
38
58
  },
39
59
  },
@@ -273,6 +273,7 @@ const configDefinitionsBuiltIn = {
273
273
  staticReplace: {
274
274
  env: { config: true },
275
275
  cumulative: true,
276
+ global: true,
276
277
  /* TODO
277
278
  vite: true,
278
279
  */
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.249-commit-ec50591";
1
+ export declare const PROJECT_VERSION: "0.4.249-commit-d781796";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.249-commit-ec50591';
2
+ export const PROJECT_VERSION = '0.4.249-commit-d781796';
@@ -2,7 +2,7 @@ export { createDebug };
2
2
  export { isDebug };
3
3
  export { isDebugError };
4
4
  export { debug };
5
- declare const flags: ["vike", "vike:crawl", "vike:file-change", "vike:error", "vike:esbuild-resolve", "vike:pluginExtractAssets", "vike:pluginExtractExportNames", "vike:glob", "vike:globalContext", "vike:log", "vike:optimizeDeps", "vike:outDir", "vike:pageFiles", "vike:pointer-imports", "vike:requireResolve", "vike:routing", "vike:setup", "vike:stream", "vike:virtualFiles", "vike:vite-rpc"];
5
+ declare const flags: ["vike", "vike:crawl", "vike:file-change", "vike:error", "vike:esbuild-resolve", "vike:pluginExtractAssets", "vike:pluginExtractExportNames", "vike:glob", "vike:globalContext", "vike:log", "vike:optimizeDeps", "vike:outDir", "vike:pageFiles", "vike:pointer-imports", "vike:requireResolve", "vike:routing", "vike:setup", "vike:staticReplace", "vike:stream", "vike:virtualFiles", "vike:vite-rpc"];
6
6
  type Flag = (typeof flags)[number];
7
7
  type Options = {
8
8
  serialization?: {
@@ -27,6 +27,7 @@ const flags = [
27
27
  'vike:requireResolve',
28
28
  'vike:routing',
29
29
  'vike:setup',
30
+ 'vike:staticReplace',
30
31
  'vike:stream',
31
32
  'vike:virtualFiles',
32
33
  'vike:vite-rpc',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.249-commit-ec50591",
3
+ "version": "0.4.249-commit-d781796",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {