vaderjs 1.7.7 → 1.7.8
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/bundler/index.js +113 -98
- package/package.json +1 -1
package/bundler/index.js
CHANGED
|
@@ -15,8 +15,8 @@ let path2 = require("path");
|
|
|
15
15
|
globalThis.Fragment = Fragment;
|
|
16
16
|
globalThis.window = {
|
|
17
17
|
location: {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
hash: "",
|
|
19
|
+
host: "",
|
|
20
20
|
},
|
|
21
21
|
};
|
|
22
22
|
globalThis.Component = Component;
|
|
@@ -35,142 +35,157 @@ globalThis.document = {
|
|
|
35
35
|
};
|
|
36
36
|
try {
|
|
37
37
|
await Bun.build({
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
entrypoints: [process.env.ENTRYPOINT],
|
|
39
|
+
minify: false,
|
|
40
|
+
root: process.cwd() + "/dist/",
|
|
41
|
+
outdir: process.cwd() + "/dist/",
|
|
42
|
+
format: "esm",
|
|
43
|
+
...(process.env.DEV ? { sourcemap: "inline" } : {}),
|
|
44
|
+
packages: "bundle",
|
|
45
|
+
external: ["vaderjs"]
|
|
46
46
|
});
|
|
47
47
|
} catch (error) {
|
|
48
|
-
console.error(error)
|
|
48
|
+
console.error(error)
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
let builtCode = fs.readFileSync(path.join(process.cwd(), 'dist', process.env.filePath), 'utf-8')
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
const handleReplacements = (code) => {
|
|
55
55
|
let lines = code.split('\n')
|
|
56
56
|
let newLines = []
|
|
57
57
|
for (let line of lines) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
58
|
+
let hasImport = line.includes('import')
|
|
59
|
+
if (hasImport && line.includes('vaderjs')) {
|
|
60
|
+
line = line.replace('vaderjs', '/src/vader/index.js')
|
|
61
|
+
}
|
|
62
|
+
if (hasImport && line.includes('.css')) {
|
|
63
|
+
try {
|
|
64
|
+
let isSmallColon = line.includes("'")
|
|
65
|
+
let url = isSmallColon ? line.split("'")[1] : line.split('"')[1]
|
|
66
|
+
// start from "/" not "/app"
|
|
67
|
+
// remvoe all ./ and ../
|
|
68
|
+
url = url.replaceAll('./', '/').replaceAll('../', '/')
|
|
69
|
+
|
|
70
|
+
let p = path.join(process.cwd(), '/', url)
|
|
71
|
+
line = '';
|
|
72
|
+
url = url.replace(process.cwd() + '/app', '')
|
|
73
|
+
url = url.replace(/\\/g, '/')
|
|
74
|
+
if (!bindes.includes(`<link rel="stylesheet" href="${url}">`)) {
|
|
75
|
+
bindes.push(`
|
|
76
76
|
<style>
|
|
77
77
|
${fs.readFileSync(p, 'utf-8')}
|
|
78
78
|
</style>
|
|
79
79
|
`)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (line.toLowerCase().includes('genkey()')) {
|
|
86
|
-
line = line.toLowerCase().replace('genkey()', `this.key = "${crypto.randomUUID()}"`)
|
|
87
|
-
}
|
|
88
|
-
if (!hasImport && line.includes('useFetch')) {
|
|
89
|
-
line = line.replace('useFetch', 'this.useFetch')
|
|
90
|
-
}
|
|
91
|
-
if (!hasImport && line.includes('useState') && line.includes('[')) {
|
|
92
|
-
let key = line.split(',')[0].split('[')[1].replace(' ', '')
|
|
93
|
-
let b4 = line
|
|
94
|
-
b4 = line.replace('useState(', `this.useState('${key}',`)
|
|
95
|
-
line = b4
|
|
96
|
-
}
|
|
97
|
-
if (!hasImport && line.includes('useAsyncState')) {
|
|
98
|
-
let key = line.split(',')[0].split('[')[1].replace(' ', '')
|
|
99
|
-
let b4 = line
|
|
100
|
-
b4 = line.replace('useAsyncState(', `this.useAsyncState('${key}',`)
|
|
101
|
-
line = b4
|
|
102
|
-
}
|
|
103
|
-
if (!hasImport && line.includes('useEffect')) {
|
|
104
|
-
let b4 = line
|
|
105
|
-
b4 = line.replace('useEffect(', `this.useEffect(`)
|
|
106
|
-
line = b4
|
|
107
|
-
}
|
|
108
|
-
if (!hasImport && line.includes('useRef')) {
|
|
109
|
-
let b4 = line
|
|
110
|
-
let key = line.split(' ')[1].split('=')[0]
|
|
111
|
-
b4 = line.replace('useRef(', `this.useRef('${key}',`)
|
|
112
|
-
line = b4
|
|
80
|
+
}
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error(error)
|
|
113
83
|
}
|
|
84
|
+
}
|
|
85
|
+
if (line.toLowerCase().includes('genkey()')) {
|
|
86
|
+
line = line.toLowerCase().replace('genkey()', `this.key = "${crypto.randomUUID()}"`)
|
|
87
|
+
}
|
|
88
|
+
if (!hasImport && line.includes('useFetch')) {
|
|
89
|
+
line = line.replace('useFetch', 'this.useFetch')
|
|
90
|
+
}
|
|
91
|
+
if (!hasImport && line.match(/\buseState\d*\(/) && line.includes('[') && !line.includes("this")) {
|
|
92
|
+
|
|
114
93
|
|
|
115
|
-
|
|
94
|
+
let key = line.split(',')[0].split('[')[1].replace(' ', '');
|
|
95
|
+
|
|
96
|
+
let updatedLine = line.replace(/\buseState\d*\(/, `this.useState('${key}',`);
|
|
97
|
+
|
|
98
|
+
line = updatedLine;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!hasImport && line.match(/\buseAsyncState\d*\(/) && line.includes('[') && !line.includes("this")) {
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
let key = line.split(',')[0].split('[')[1].replace(' ', '');
|
|
105
|
+
|
|
106
|
+
let updatedLine = line.replace(/\buseAsyncState\d*\(/, `this.useAsyncState('${key}',`);
|
|
107
|
+
|
|
108
|
+
line = updatedLine;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (!hasImport && line.match(/\buseEffect\d*\(/) && !line.includes("this")) {
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
let updatedLine = line.replace(/\buseEffect\d*\(/, `this.useEffect(`);
|
|
115
|
+
|
|
116
|
+
line = updatedLine;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!hasImport && line.match(/\buseRef\d*\(/) && !line.includes("this")) {
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
let key = line.split(' ')[1].split('=')[0];
|
|
123
|
+
|
|
124
|
+
let updatedLine = line.replace(/\buseRef\d*\(/, `this.useRef('${key}',`);
|
|
125
|
+
|
|
126
|
+
line = updatedLine;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
newLines.push(line)
|
|
116
131
|
}
|
|
117
132
|
let c = newLines.join('\n')
|
|
118
133
|
return c
|
|
119
|
-
}
|
|
134
|
+
}
|
|
120
135
|
builtCode = handleReplacements(builtCode)
|
|
121
|
-
|
|
136
|
+
|
|
122
137
|
fs.writeFileSync(path.join(process.cwd(), 'dist', process.env.filePath), builtCode)
|
|
123
138
|
|
|
124
|
-
let isClass = function (element) {
|
|
139
|
+
let isClass = function (element) {
|
|
125
140
|
return element && element.toString().startsWith("class");
|
|
126
141
|
};
|
|
127
142
|
const generatePage = async (
|
|
128
143
|
data = { path: process.env.INPUT, route: process.env.OUT }
|
|
129
144
|
) => {
|
|
130
145
|
const { path, route } = data;
|
|
131
|
-
if (path.includes("root.js")) return;
|
|
146
|
+
if (path.includes("root.js")) return;
|
|
132
147
|
let html = await import(path).then((m) => m.default);
|
|
133
|
-
|
|
148
|
+
|
|
134
149
|
let { head } = await import(path).then((m) => m);
|
|
135
150
|
let isFunction = false;
|
|
136
|
-
globalThis.isServer = true;
|
|
137
|
-
if(!html){
|
|
151
|
+
globalThis.isServer = true;
|
|
152
|
+
if (!html) {
|
|
138
153
|
return
|
|
139
154
|
}
|
|
140
|
-
if (isClass(html)
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
155
|
+
if (isClass(html)) {
|
|
156
|
+
html = new html();
|
|
157
|
+
html.Mounted = true;
|
|
158
|
+
html = html.render();
|
|
144
159
|
} else {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
160
|
+
isFunction = true;
|
|
161
|
+
let instance = new Component();
|
|
162
|
+
html = html.bind(instance);
|
|
163
|
+
instance.render = html;
|
|
164
|
+
html = instance.render();
|
|
150
165
|
}
|
|
151
166
|
|
|
152
167
|
let h = document(html);
|
|
153
168
|
if (!fs.existsSync(process.cwd() + "/dist" + path2.dirname(route))) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
169
|
+
fs.mkdirSync(process.cwd() + "/dist" + path2.dirname(route), {
|
|
170
|
+
recursive: true,
|
|
171
|
+
});
|
|
157
172
|
}
|
|
158
173
|
let headHtml = "";
|
|
159
174
|
if (head) {
|
|
160
|
-
|
|
175
|
+
headHtml = document(head());
|
|
161
176
|
}
|
|
162
177
|
|
|
163
178
|
|
|
164
179
|
|
|
165
|
-
if (h.includes("<head>")) {
|
|
166
|
-
|
|
167
|
-
}else{
|
|
180
|
+
if (h.includes("<head>")) {
|
|
181
|
+
h = h.replace("<head>", `<head>${process.env.bindes}`)
|
|
182
|
+
} else {
|
|
168
183
|
h += process.env.bindes
|
|
169
184
|
}
|
|
170
185
|
|
|
171
186
|
await Bun.write(
|
|
172
|
-
|
|
173
|
-
|
|
187
|
+
process.cwd() + "/dist/" + route + "/index.html",
|
|
188
|
+
`<!DOCTYPE html>
|
|
174
189
|
${h}
|
|
175
190
|
<script type="module">
|
|
176
191
|
import c from '${process.env.filePath}'
|
|
@@ -181,18 +196,18 @@ const generatePage = async (
|
|
|
181
196
|
`
|
|
182
197
|
);
|
|
183
198
|
console.log(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
199
|
+
ansiColors.blue(
|
|
200
|
+
`${process.env.filePath.replace(".js", ".jsx")} - ${parseInt(
|
|
201
|
+
process.env.size
|
|
202
|
+
).toFixed(2)}kb`
|
|
203
|
+
)
|
|
189
204
|
);
|
|
190
205
|
process.exit(0);
|
|
191
206
|
};
|
|
192
|
-
|
|
193
|
-
try {
|
|
194
|
-
|
|
195
|
-
|
|
207
|
+
|
|
208
|
+
try {
|
|
209
|
+
if (process.env.isJsx == "true" && process.env.isAppFile == "true") {
|
|
210
|
+
generatePage({ path: process.env.INPUT, route: process.env.OUT })
|
|
196
211
|
}
|
|
197
212
|
} catch (error) {
|
|
198
213
|
console.log(ansiColors.red(error))
|