vike 0.4.249-commit-d781796 → 0.4.249-commit-4ef7732

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.
@@ -110,13 +110,7 @@ type StaticReplace = {
110
110
  /** Remove target (optional) */
111
111
  remove?: RemoveTarget;
112
112
  };
113
- type TransformInput = {
114
- code: string;
115
- id: string;
116
- env: string;
117
- options: StaticReplace[];
118
- };
119
- declare function applyStaticReplace({ code, id, env, options }: TransformInput): Promise<{
113
+ declare function applyStaticReplace(code: string, staticReplaceList: StaticReplace[], id: string, env: 'server' | 'client'): Promise<{
120
114
  code: string;
121
115
  map: {
122
116
  version: number;
@@ -127,4 +121,4 @@ declare function applyStaticReplace({ code, id, env, options }: TransformInput):
127
121
  mappings: string;
128
122
  file: string;
129
123
  } | null | undefined;
130
- } | null>;
124
+ } | null | undefined>;
@@ -2,19 +2,21 @@ export { applyStaticReplace };
2
2
  import { transformAsync } from '@babel/core';
3
3
  import * as t from '@babel/types';
4
4
  import { parseImportString } from '../../shared/importString.js';
5
- async function applyStaticReplace({ code, id, env, options }) {
6
- // 'server' means "not client" (covers ssr, cloudflare, etc.)
7
- const filteredRules = options.filter((rule) => {
8
- if (!rule.env)
5
+ import assert from 'node:assert';
6
+ // ============================================================================
7
+ // Main transformer
8
+ // ============================================================================
9
+ async function applyStaticReplace(code, staticReplaceList, id, env) {
10
+ assert(staticReplaceList.length > 0);
11
+ const SKIPPED = undefined;
12
+ const NO_CHANGE = null;
13
+ const staticReplaceListFiltered = staticReplaceList.filter((staticReplace) => {
14
+ if (!staticReplace.env)
9
15
  return true;
10
- if (rule.env === 'client')
11
- return env === 'client';
12
- if (rule.env === 'server')
13
- return env !== 'client';
14
- return false;
16
+ return staticReplace.env === env;
15
17
  });
16
- if (filteredRules.length === 0) {
17
- return null;
18
+ if (staticReplaceListFiltered.length === 0) {
19
+ return SKIPPED;
18
20
  }
19
21
  try {
20
22
  const state = {
@@ -26,16 +28,20 @@ async function applyStaticReplace({ code, id, env, options }) {
26
28
  filename: id,
27
29
  ast: true,
28
30
  sourceMaps: true,
29
- plugins: [collectImportsPlugin(state), applyRulesPlugin(state, filteredRules), removeUnreferencedPlugin(state)],
31
+ plugins: [
32
+ collectImportsPlugin(state),
33
+ applyRulesPlugin(state, staticReplaceListFiltered),
34
+ removeUnreferencedPlugin(state),
35
+ ],
30
36
  });
31
37
  if (!result?.code || !state.modified) {
32
- return null;
38
+ return NO_CHANGE;
33
39
  }
34
40
  return { code: result.code, map: result.map };
35
41
  }
36
42
  catch (error) {
37
43
  console.error(`Error transforming ${id}:`, error);
38
- return null;
44
+ return SKIPPED;
39
45
  }
40
46
  }
41
47
  // ============================================================================
@@ -42,17 +42,21 @@ function pluginStaticReplace(vikeConfig) {
42
42
  filter: filterRolldown,
43
43
  async handler(code, id, options) {
44
44
  assert(filterFunction(id, code));
45
+ debug('id', id);
45
46
  const env = isViteServerSide_extraSafe(config, this.environment, options) ? 'server' : 'client';
46
- const result = await applyStaticReplace({
47
- code,
48
- id,
49
- env,
50
- options: staticReplaceList,
51
- });
52
- if (debug.isActivated && result) {
53
- debug('id', id);
54
- debug('before', code);
55
- debug('after', result.code);
47
+ debug('env', env);
48
+ const result = await applyStaticReplace(code, staticReplaceList, id, env);
49
+ if (debug.isActivated) {
50
+ if (result === undefined) {
51
+ debug('Skipped');
52
+ }
53
+ if (result === null) {
54
+ debug('AST parsed, but no modifications');
55
+ }
56
+ if (result) {
57
+ debug('Before:', code);
58
+ debug('After:', result.code);
59
+ }
56
60
  }
57
61
  return result;
58
62
  },
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.249-commit-d781796";
1
+ export declare const PROJECT_VERSION: "0.4.249-commit-4ef7732";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.249-commit-d781796';
2
+ export const PROJECT_VERSION = '0.4.249-commit-4ef7732';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.249-commit-d781796",
3
+ "version": "0.4.249-commit-4ef7732",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {