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.
- package/dist/node/vite/plugins/pluginStaticReplace/applyStaticReplace.d.ts +2 -8
- package/dist/node/vite/plugins/pluginStaticReplace/applyStaticReplace.js +20 -14
- package/dist/node/vite/plugins/pluginStaticReplace.js +14 -10
- package/dist/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/utils/PROJECT_VERSION.js +1 -1
- package/package.json +1 -1
|
@@ -110,13 +110,7 @@ type StaticReplace = {
|
|
|
110
110
|
/** Remove target (optional) */
|
|
111
111
|
remove?: RemoveTarget;
|
|
112
112
|
};
|
|
113
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
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 (
|
|
17
|
-
return
|
|
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: [
|
|
31
|
+
plugins: [
|
|
32
|
+
collectImportsPlugin(state),
|
|
33
|
+
applyRulesPlugin(state, staticReplaceListFiltered),
|
|
34
|
+
removeUnreferencedPlugin(state),
|
|
35
|
+
],
|
|
30
36
|
});
|
|
31
37
|
if (!result?.code || !state.modified) {
|
|
32
|
-
return
|
|
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
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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-
|
|
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-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.249-commit-4ef7732';
|