vaderjs 1.3.3-alpha-122 → 1.3.3-alpha-123
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/package.json +1 -1
- package/vader.js +50 -3
package/package.json
CHANGED
package/vader.js
CHANGED
|
@@ -4,7 +4,11 @@ import { glob, globSync, globStream, globStreamSync, Glob, } from 'glob'
|
|
|
4
4
|
import puppeteer from 'puppeteer';
|
|
5
5
|
import http from 'http'
|
|
6
6
|
import { WebSocketServer } from 'ws'
|
|
7
|
-
import { watch } from "fs";
|
|
7
|
+
import { watch } from "fs";
|
|
8
|
+
import path from 'path'
|
|
9
|
+
let config = await import('file://' + process.cwd() + '/vader.config.js').then((e) => e.default || e)
|
|
10
|
+
console.log(config)
|
|
11
|
+
|
|
8
12
|
let start = Date.now()
|
|
9
13
|
let bundleSize = 0;
|
|
10
14
|
let errorCodes = {
|
|
@@ -891,6 +895,7 @@ async function Build() {
|
|
|
891
895
|
let origin = file.replace(/\\/g, '/');
|
|
892
896
|
let fileName = origin.split('/pages/')[1].split('.jsx')[0].replace('.jsx', '') + '.jsx';
|
|
893
897
|
let isBasePath = fileName === 'index.jsx';
|
|
898
|
+
let isParamRoute = fileName.includes('[') && fileName.includes(']') ? true : false
|
|
894
899
|
|
|
895
900
|
// Extract all dynamic parameters from the file path [param1]/[param2]/[param3
|
|
896
901
|
let aburl = origin.split('/pages')[1].split('.jsx')[0].replace('.jsx', '').split('[').join(':').split(']').join('');
|
|
@@ -941,9 +946,51 @@ async function Build() {
|
|
|
941
946
|
|
|
942
947
|
|
|
943
948
|
obj.compiledPath = process.cwd() + "/dist/pages/" + fileName.replace('.jsx', '.js')
|
|
949
|
+
let providerRedirects = {cloudflare: '_redirect', vercel: 'vercel.json', netlify:'_redirects'}
|
|
950
|
+
switch(true){
|
|
951
|
+
case config && config.host && !config.host['_redirect']:
|
|
952
|
+
let host = config.host.provider
|
|
953
|
+
|
|
954
|
+
let provider = providerRedirects[host]
|
|
955
|
+
if(provider){
|
|
956
|
+
|
|
957
|
+
let redirectFile = fs.existsSync(process.cwd() + '/dist/' + provider) ? fs.readFileSync(process.cwd() + '/dist/' + provider, 'utf8') : ''
|
|
958
|
+
let type = provider === '_redirect' ? 'text/plain' : 'application/json'
|
|
959
|
+
let root = isParamRoute ? obj.url.split('/:')[0] : obj.url
|
|
960
|
+
|
|
961
|
+
switch(true){
|
|
962
|
+
case root === '/':
|
|
963
|
+
break;
|
|
964
|
+
case 'text/plain' && !redirectFile.includes(root):
|
|
965
|
+
|
|
966
|
+
redirectFile += `\n${root}/* ${root} 200`
|
|
967
|
+
fs.writeFileSync(process.cwd() + '/dist/' + provider, redirectFile)
|
|
968
|
+
console.log(`Added ${root}/* ${root} 200 to ${provider}`)
|
|
969
|
+
break;
|
|
970
|
+
case 'application/json' && !redirectFile.includes(root):
|
|
971
|
+
let json = JSON.parse(redirectFile) || {}
|
|
972
|
+
let isVercel = provider === 'vercel.json' ? true : false
|
|
973
|
+
if(isVercel){
|
|
974
|
+
json['rewrites'] = json['rewrites'] || []
|
|
975
|
+
json['rewrites'].push({ "source": `${root}/*`, "destination": `/${root}` })
|
|
976
|
+
}
|
|
977
|
+
fs.writeFileSync(process.cwd() + '/dist/' + provider, JSON.stringify(json))
|
|
978
|
+
console.log(`Added ${root}/* ${root} 200 to ${provider}`)
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
break;
|
|
982
|
+
case config && config.host && config.host['_redirect']:
|
|
983
|
+
let file = config.host['_redirect']
|
|
984
|
+
file = file.split('./').join('')
|
|
985
|
+
let redirectFile = fs.existsSync(process.cwd() + '/' + file) ? fs.readFileSync(process.cwd() + '/' + file, 'utf8') : ''
|
|
986
|
+
fs.writeFileSync(process.cwd() + '/dist/' + file, redirectFile)
|
|
987
|
+
console.log(`Using ${file} for redirects`)
|
|
988
|
+
default:
|
|
989
|
+
break;
|
|
944
990
|
|
|
945
|
-
|
|
946
|
-
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
|
|
947
994
|
globalThis.routes.push({ fileName: fileName, url: obj.url, html: '/' + (isBasePath ? 'index.html' : `${obj.url}/` + 'index.html') })
|
|
948
995
|
|
|
949
996
|
|