edge-functions 4.6.1 → 4.7.0
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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [4.7.0](https://github.com/aziontech/bundler/compare/v4.6.1...v4.7.0) (2025-02-10)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* new preset for preact ssg ([#433](https://github.com/aziontech/bundler/issues/433)) ([83fbd18](https://github.com/aziontech/bundler/commit/83fbd183a123f6f692644ef99b6a1e52cdba9f70))
|
|
7
|
+
|
|
1
8
|
### [4.6.1](https://github.com/aziontech/bundler/compare/v4.6.0...v4.6.1) (2025-02-10)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { mountSPA } from 'azion/utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Handles the 'fetch' event.
|
|
5
|
+
* @param {import('azion/types').FetchEvent} event - The fetch event.
|
|
6
|
+
* @returns {Promise<Response>} The response for the request.
|
|
7
|
+
*/
|
|
8
|
+
async function handler(event) {
|
|
9
|
+
try {
|
|
10
|
+
const myApp = await mountSPA(event.request.url);
|
|
11
|
+
return myApp;
|
|
12
|
+
} catch (e) {
|
|
13
|
+
return new Response('Not Found', { status: 404 });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default handler;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { exec, getPackageManager, copyDirectory } from '#utils';
|
|
2
|
+
import { lstat, readFile, rm } from 'fs/promises';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
|
|
5
|
+
const packageManager = await getPackageManager();
|
|
6
|
+
const edgeStorageDir = '.edge/storage';
|
|
7
|
+
const defaultViteOutDir = 'dist';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Check if the vite.config file exists.
|
|
11
|
+
* @returns {boolean} True if the file exists, false otherwise.
|
|
12
|
+
*/
|
|
13
|
+
async function viteConfigExists() {
|
|
14
|
+
const files = ['./vite.config.js', './vite.config.ts'];
|
|
15
|
+
const checks = files.map(async (file) => {
|
|
16
|
+
try {
|
|
17
|
+
await lstat(file);
|
|
18
|
+
return true;
|
|
19
|
+
} catch (err) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const results = await Promise.all(checks);
|
|
25
|
+
return results.includes(true);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Read vite.config build output
|
|
30
|
+
* @returns {object} The parsed configuration object or null if the file doesn't exist.
|
|
31
|
+
*/
|
|
32
|
+
async function readViteBuildOutput() {
|
|
33
|
+
try {
|
|
34
|
+
const isTypescript = await lstat('./vite.config.ts').then(
|
|
35
|
+
() => true,
|
|
36
|
+
() => false,
|
|
37
|
+
);
|
|
38
|
+
const pathConfigFile = join(
|
|
39
|
+
process.cwd(),
|
|
40
|
+
isTypescript ? 'vite.config.ts' : 'vite.config.js',
|
|
41
|
+
);
|
|
42
|
+
const configFileContent = await readFile(pathConfigFile, 'utf-8');
|
|
43
|
+
const defineConfig = configFileContent.match(/defineConfig\(([\s\S]*)\)/);
|
|
44
|
+
if (!defineConfig) {
|
|
45
|
+
throw new Error('defineConfig not found');
|
|
46
|
+
}
|
|
47
|
+
const buildConfig = defineConfig[1].match(/build: *({[\s\S]*?}),/);
|
|
48
|
+
// eslint-disable-next-line no-eval
|
|
49
|
+
const buildConfigObject = eval(`(${buildConfig[1]})`);
|
|
50
|
+
return Promise.resolve({ build: buildConfigObject });
|
|
51
|
+
} catch (err) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Runs custom prebuild actions
|
|
58
|
+
*/
|
|
59
|
+
async function prebuild() {
|
|
60
|
+
const npmArgsForward = packageManager === 'npm' ? '--' : '';
|
|
61
|
+
|
|
62
|
+
let outDir = defaultViteOutDir;
|
|
63
|
+
const destPath = edgeStorageDir;
|
|
64
|
+
|
|
65
|
+
const isViteProject = await viteConfigExists();
|
|
66
|
+
|
|
67
|
+
if (isViteProject) {
|
|
68
|
+
await exec(`${packageManager} run build ${npmArgsForward}`, 'Preact', true);
|
|
69
|
+
|
|
70
|
+
const config = await readViteBuildOutput();
|
|
71
|
+
|
|
72
|
+
if (config?.build?.outDir) {
|
|
73
|
+
outDir = config.build.outDir;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
copyDirectory(outDir, destPath);
|
|
77
|
+
rm(outDir, { recursive: true, force: true });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!isViteProject) {
|
|
81
|
+
await exec(
|
|
82
|
+
`BUILD_PATH="./.edge/storage" ${packageManager} run build`,
|
|
83
|
+
'React',
|
|
84
|
+
true,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export default prebuild;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "edge-functions",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.7.0",
|
|
5
5
|
"description": "Tool to launch and build JavaScript/Frameworks. This tool automates polyfills for Edge Computing and assists in creating Workers, notably for the Azion platform.",
|
|
6
6
|
"main": "lib/main.js",
|
|
7
7
|
"bin": {
|