vaderjs 1.7.5 → 1.7.6
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 +61 -16
- package/main.js +31 -36
- package/package.json +1 -1
package/bundler/index.js
CHANGED
|
@@ -41,36 +41,80 @@ try {
|
|
|
41
41
|
outdir: process.cwd() + "/dist/",
|
|
42
42
|
format: "esm",
|
|
43
43
|
...(process.env.DEV ? { sourcemap: "inline" } : {}),
|
|
44
|
-
packages: "bundle",
|
|
45
|
-
external: ['*.jsx', '*.js', '*.ts']
|
|
44
|
+
packages: "bundle",
|
|
46
45
|
});
|
|
47
46
|
} catch (error) {
|
|
48
47
|
console.error(error)
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
let builtCode = fs.readFileSync(path.join(process.cwd(), 'dist', process.env.filePath), 'utf-8')
|
|
52
50
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
let
|
|
51
|
+
let builtCode = fs.readFileSync(path.join(process.cwd(), 'dist', process.env.filePath), 'utf-8')
|
|
52
|
+
const handleReplacements = (code) => {
|
|
53
|
+
let lines = code.split('\n')
|
|
54
|
+
let newLines = []
|
|
56
55
|
for (let line of lines) {
|
|
57
56
|
let hasImport = line.includes('import')
|
|
58
|
-
|
|
57
|
+
|
|
58
|
+
if (hasImport && line.includes('.css')) {
|
|
59
59
|
try {
|
|
60
|
-
let
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
let isSmallColon = line.includes("'")
|
|
61
|
+
let url = isSmallColon ? line.split("'")[1] : line.split('"')[1]
|
|
62
|
+
// start from "/" not "/app"
|
|
63
|
+
// remvoe all ./ and ../
|
|
64
|
+
url = url.replaceAll('./', '/').replaceAll('../', '/')
|
|
65
|
+
|
|
66
|
+
let p = path.join(process.cwd(), '/', url)
|
|
67
|
+
line = '';
|
|
68
|
+
url = url.replace(process.cwd() + '/app', '')
|
|
69
|
+
url = url.replace(/\\/g, '/')
|
|
70
|
+
if (!bindes.includes(`<link rel="stylesheet" href="${url}">`)) {
|
|
71
|
+
bindes.push(`
|
|
72
|
+
<style>
|
|
73
|
+
${fs.readFileSync(p, 'utf-8')}
|
|
74
|
+
</style>
|
|
75
|
+
`)
|
|
76
|
+
}
|
|
64
77
|
} catch (error) {
|
|
65
|
-
|
|
78
|
+
console.error(error)
|
|
66
79
|
}
|
|
67
|
-
} else {
|
|
68
|
-
newLines.push(line)
|
|
69
80
|
}
|
|
81
|
+
if (line.toLowerCase().includes('genkey()')) {
|
|
82
|
+
line = line.toLowerCase().replace('genkey()', `this.key = "${crypto.randomUUID()}"`)
|
|
83
|
+
}
|
|
84
|
+
if (!hasImport && line.includes('useFetch')) {
|
|
85
|
+
line = line.replace('useFetch', 'this.useFetch')
|
|
86
|
+
}
|
|
87
|
+
if (!hasImport && line.includes('useState') && line.includes('[')) {
|
|
88
|
+
let key = line.split(',')[0].split('[')[1].replace(' ', '')
|
|
89
|
+
let b4 = line
|
|
90
|
+
b4 = line.replace('useState(', `this.useState('${key}',`)
|
|
91
|
+
line = b4
|
|
92
|
+
}
|
|
93
|
+
if (!hasImport && line.includes('useAsyncState')) {
|
|
94
|
+
let key = line.split(',')[0].split('[')[1].replace(' ', '')
|
|
95
|
+
let b4 = line
|
|
96
|
+
b4 = line.replace('useAsyncState(', `this.useAsyncState('${key}',`)
|
|
97
|
+
line = b4
|
|
98
|
+
}
|
|
99
|
+
if (!hasImport && line.includes('useEffect')) {
|
|
100
|
+
let b4 = line
|
|
101
|
+
b4 = line.replace('useEffect(', `this.useEffect(`)
|
|
102
|
+
line = b4
|
|
103
|
+
}
|
|
104
|
+
if (!hasImport && line.includes('useRef')) {
|
|
105
|
+
let b4 = line
|
|
106
|
+
let key = line.split(' ')[1].split('=')[0]
|
|
107
|
+
b4 = line.replace('useRef(', `this.useRef('${key}',`)
|
|
108
|
+
line = b4
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
newLines.push(line)
|
|
70
112
|
}
|
|
71
|
-
|
|
113
|
+
let c = newLines.join('\n')
|
|
114
|
+
return c
|
|
72
115
|
}
|
|
73
116
|
builtCode = handleReplacements(builtCode)
|
|
117
|
+
|
|
74
118
|
fs.writeFileSync(path.join(process.cwd(), 'dist', process.env.filePath), builtCode)
|
|
75
119
|
|
|
76
120
|
let isClass = function (element) {
|
|
@@ -140,7 +184,8 @@ const generatePage = async (
|
|
|
140
184
|
)
|
|
141
185
|
);
|
|
142
186
|
process.exit(0);
|
|
143
|
-
};
|
|
187
|
+
};
|
|
188
|
+
console.log(process.env.isJsx, process.env.isAppFile == "true" )
|
|
144
189
|
try {
|
|
145
190
|
if (process.env.isJsx == "true" && process.env.isAppFile == "true" ) {
|
|
146
191
|
generatePage({ path: process.env.INPUT, route: process.env.OUT })
|
package/main.js
CHANGED
|
@@ -200,8 +200,7 @@ async function generateApp() {
|
|
|
200
200
|
Object.keys(routes.routes).forEach(async (route) => {
|
|
201
201
|
|
|
202
202
|
let r = routes.routes[route]
|
|
203
|
-
let code = await Bun.file(r).text()
|
|
204
|
-
code = handleReplacements(code)
|
|
203
|
+
let code = await Bun.file(r).text()
|
|
205
204
|
let size = code.length / 1024
|
|
206
205
|
r = r.replace(process.cwd().replace(/\\/g, '/') + '/app', '')
|
|
207
206
|
var beforeR = r
|
|
@@ -229,39 +228,35 @@ async function generateApp() {
|
|
|
229
228
|
loader: 'ts',
|
|
230
229
|
}).transformSync(await Bun.file(require.resolve('vaderjs')).text()))
|
|
231
230
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
reject()
|
|
259
|
-
}
|
|
231
|
+
Bun.spawn({
|
|
232
|
+
cmd: ['bun', 'run', './dev/bundler.js'],
|
|
233
|
+
cwd: process.cwd(),
|
|
234
|
+
stdout: 'inherit',
|
|
235
|
+
env: {
|
|
236
|
+
ENTRYPOINT: path.join(process.cwd() + '/dist/' + path.dirname(r) + '/' + path.basename(r)),
|
|
237
|
+
ROOT: process.cwd() + '/app/',
|
|
238
|
+
OUT: path.dirname(r),
|
|
239
|
+
file: process.cwd() + '/dist/' + path.dirname(r) + '/' + path.basename(r),
|
|
240
|
+
DEV: mode === 'development',
|
|
241
|
+
size,
|
|
242
|
+
bindes: bindes.join('\n'),
|
|
243
|
+
isTs: beforeR.endsWith(".tsx"),
|
|
244
|
+
filePath: r,
|
|
245
|
+
|
|
246
|
+
isJsx: beforeR.endsWith('.tsx') || beforeR.endsWith(".jsx") ,
|
|
247
|
+
isAppFile: true,
|
|
248
|
+
INPUT: `../app/${beforeR}`,
|
|
249
|
+
},
|
|
250
|
+
onExit({ exitCode: code }) {
|
|
251
|
+
if (code === 0) {
|
|
252
|
+
bindes = []
|
|
253
|
+
console.log(`Built ${r} in ${Date.now() - start}ms`)
|
|
254
|
+
resolve()
|
|
255
|
+
} else {
|
|
256
|
+
reject()
|
|
260
257
|
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
}
|
|
258
|
+
}
|
|
259
|
+
})
|
|
265
260
|
|
|
266
261
|
})
|
|
267
262
|
|
|
@@ -396,9 +391,9 @@ function handleFiles() {
|
|
|
396
391
|
}
|
|
397
392
|
globalThis.clients = []
|
|
398
393
|
|
|
399
|
-
if (mode === 'development') {
|
|
400
|
-
await generateApp()
|
|
394
|
+
if (mode === 'development') {
|
|
401
395
|
await handleFiles()
|
|
396
|
+
await generateApp()
|
|
402
397
|
const watcher = fs.watch(path.join(process.cwd() + '/'), { recursive: true })
|
|
403
398
|
let isBuilding = false; // Flag to track build status
|
|
404
399
|
|