vike 0.4.249-commit-92f1383 → 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,14 +110,15 @@ type StaticReplace = {
110
110
  /** Remove target (optional) */
111
111
  remove?: RemoveTarget;
112
112
  };
113
- type TransformResult = {
113
+ declare function applyStaticReplace(code: string, staticReplaceList: StaticReplace[], id: string, env: 'server' | 'client'): Promise<{
114
114
  code: string;
115
- map: any;
116
- } | null;
117
- type TransformInput = {
118
- code: string;
119
- id: string;
120
- env: string;
121
- options: StaticReplace[];
122
- };
123
- declare function applyStaticReplace({ code, id, env, options }: TransformInput): Promise<TransformResult>;
115
+ map: {
116
+ version: number;
117
+ sources: string[];
118
+ names: string[];
119
+ sourceRoot?: string | undefined;
120
+ sourcesContent?: string[] | undefined;
121
+ mappings: string;
122
+ file: string;
123
+ } | null | undefined;
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
  // ============================================================================
@@ -1,8 +1,9 @@
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;
8
9
  // staticReplaceList
@@ -41,13 +42,22 @@ function pluginStaticReplace(vikeConfig) {
41
42
  filter: filterRolldown,
42
43
  async handler(code, id, options) {
43
44
  assert(filterFunction(id, code));
45
+ debug('id', id);
44
46
  const env = isViteServerSide_extraSafe(config, this.environment, options) ? 'server' : 'client';
45
- const result = await applyStaticReplace({
46
- code,
47
- id,
48
- env,
49
- options: staticReplaceList,
50
- });
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
+ }
60
+ }
51
61
  return result;
52
62
  },
53
63
  },
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.249-commit-92f1383";
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-92f1383';
2
+ export const PROJECT_VERSION = '0.4.249-commit-4ef7732';
@@ -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-92f1383",
3
+ "version": "0.4.249-commit-4ef7732",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {