edge-functions 1.0.0 → 1.3.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/.eslintrc.json +60 -15
- package/.github/workflows/major.yml +1 -1
- package/.github/workflows/minor.yml +1 -2
- package/README.md +36 -0
- package/aliases.js +1 -1
- package/docs/overview.md +4 -3
- package/docs/presets.md +18 -6
- package/examples/angular-static/package.json +0 -1
- package/examples/simple-js-esm/main.js +13 -8
- package/examples/simple-js-esm-node/index.js +45 -0
- package/examples/simple-ts-esm/main.ts +24 -0
- package/examples/simple-ts-esm/messages.ts +11 -0
- package/examples/simple-ts-esm/package.json +9 -0
- package/examples/simple-ts-esm/tsconfig.json +109 -0
- package/examples/simple-ts-esm/yarn.lock +8 -0
- package/examples/vue-vite-static/README.md +29 -0
- package/examples/vue-vite-static/index.html +13 -0
- package/examples/vue-vite-static/package.json +18 -0
- package/examples/vue-vite-static/public/favicon.ico +0 -0
- package/examples/vue-vite-static/src/App.vue +85 -0
- package/examples/vue-vite-static/src/assets/base.css +73 -0
- package/examples/vue-vite-static/src/assets/logo.svg +1 -0
- package/examples/vue-vite-static/src/assets/main.css +35 -0
- package/examples/vue-vite-static/src/components/HelloWorld.vue +44 -0
- package/examples/vue-vite-static/src/components/TheWelcome.vue +86 -0
- package/examples/vue-vite-static/src/components/WelcomeItem.vue +86 -0
- package/examples/vue-vite-static/src/components/icons/IconCommunity.vue +7 -0
- package/examples/vue-vite-static/src/components/icons/IconDocumentation.vue +7 -0
- package/examples/vue-vite-static/src/components/icons/IconEcosystem.vue +7 -0
- package/examples/vue-vite-static/src/components/icons/IconSupport.vue +7 -0
- package/examples/vue-vite-static/src/components/icons/IconTooling.vue +19 -0
- package/examples/vue-vite-static/src/main.js +11 -0
- package/examples/vue-vite-static/src/router/index.js +23 -0
- package/examples/vue-vite-static/src/views/AboutView.vue +15 -0
- package/examples/vue-vite-static/src/views/HomeView.vue +9 -0
- package/examples/vue-vite-static/vite.config.js +16 -0
- package/jsconfig.json +1 -1
- package/lib/build/bundlers/esbuild/esbuild.config.js +12 -0
- package/lib/build/bundlers/esbuild/index.js +46 -0
- package/lib/build/bundlers/esbuild/plugins/node-polyfills/index.js +147 -0
- package/lib/build/bundlers/esbuild/plugins/node-polyfills/node-polyfills-paths.js +124 -0
- package/lib/build/bundlers/index.js +2 -2
- package/lib/build/bundlers/webpack/index.js +16 -7
- package/lib/build/bundlers/webpack/webpack.config.js +5 -25
- package/lib/build/dispatcher/dispatcher.js +116 -66
- package/lib/constants/framework-initializer.constants.js +51 -0
- package/lib/constants/index.js +4 -1
- package/lib/constants/messages/build.messages.js +2 -0
- package/lib/constants/messages/env.messages.js +5 -3
- package/lib/constants/messages/global.messages.js +4 -1
- package/lib/env/polyfills/FetchEvent.polyfills.js +13 -0
- package/lib/env/polyfills/fetch.polyfills.js +39 -0
- package/lib/env/polyfills/index.js +4 -0
- package/lib/env/runtime.env.js +57 -63
- package/lib/env/server.env.js +32 -76
- package/lib/main.js +234 -90
- package/lib/notations/namespaces.js +5 -0
- package/lib/platform/actions/core/auth.actions.js +1 -1
- package/lib/platform/actions/core/propagation.actions.js +8 -5
- package/lib/platform/actions/core/storage.actions.js +1 -1
- package/lib/platform/actions/function/showFunctionLogs.actions.js +71 -92
- package/lib/platform/edgehooks/debugRequest/debugRequest.hooks.js +28 -0
- package/lib/platform/edgehooks/debugRequest/index.js +3 -0
- package/lib/platform/edgehooks/index.js +4 -1
- package/lib/polyfills/FetchEvent.polyfills.js +13 -0
- package/lib/polyfills/fetch.polyfills.js +39 -0
- package/lib/polyfills/index.js +4 -0
- package/lib/presets/custom/angular/deliver/config.js +2 -4
- package/lib/presets/custom/angular/deliver/handler.js +12 -5
- package/lib/presets/custom/angular/deliver/prebuild.js +8 -11
- package/lib/presets/custom/astro/deliver/config.js +2 -4
- package/lib/presets/custom/astro/deliver/handler.js +14 -7
- package/lib/presets/custom/astro/deliver/prebuild.js +18 -21
- package/lib/presets/custom/hexo/deliver/config.js +2 -4
- package/lib/presets/custom/hexo/deliver/handler.js +13 -6
- package/lib/presets/custom/hexo/deliver/prebuild.js +18 -21
- package/lib/presets/custom/next/deliver/config.js +2 -6
- package/lib/presets/custom/next/deliver/handler.js +14 -7
- package/lib/presets/custom/next/deliver/prebuild.js +37 -40
- package/lib/presets/custom/react/deliver/config.js +2 -4
- package/lib/presets/custom/react/deliver/handler.js +10 -3
- package/lib/presets/custom/react/deliver/prebuild.js +4 -7
- package/lib/presets/custom/vue/deliver/config.js +2 -4
- package/lib/presets/custom/vue/deliver/handler.js +10 -3
- package/lib/presets/custom/vue/deliver/prebuild.js +66 -10
- package/lib/presets/default/html/deliver/config.js +1 -4
- package/lib/presets/default/html/deliver/handler.js +14 -7
- package/lib/presets/default/html/deliver/prebuild.js +3 -2
- package/lib/presets/default/javascript/compute/config.js +2 -5
- package/lib/presets/default/javascript/compute/handler.js +15 -4
- package/lib/presets/default/javascript/compute/prebuild.js +2 -1
- package/lib/presets/default/typescript/compute/config.js +10 -0
- package/lib/presets/default/typescript/compute/handler.js +16 -0
- package/lib/presets/default/typescript/compute/prebuild.js +7 -0
- package/lib/providers/azion/worker.js +6 -2
- package/lib/utils/exec/exec.utils.js +34 -23
- package/lib/utils/feedback/feedback.utils.js +6 -2
- package/lib/utils/getAbsoluteLibDirPath/getAbsoluteLibDirPath.utils.js +11 -2
- package/lib/utils/getVulcanBuildId/getVulcanBuildId.utils.js +1 -1
- package/lib/utils/index.js +4 -2
- package/lib/utils/overrideStaticOutputPath/overrideStaticOutputPath.utils.js +2 -2
- package/lib/utils/presets/index.js +3 -0
- package/lib/utils/presets/presets.utils.js +169 -0
- package/lib/utils/spinner/index.js +3 -0
- package/lib/utils/spinner/spinner.utils.js +32 -0
- package/package.json +17 -4
- package/examples/hexo-static/yarn.lock +0 -1625
- package/lib/build/polyfills/index.js +0 -0
- package/lib/utils/getPresetsList/getPresetsList.utils.js +0 -50
- package/lib/utils/getPresetsList/index.js +0 -3
- /package/lib/utils/{getPresetsList/getPresetsList.utils.test.js → presets/presets.utils.test.js} +0 -0
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import debugRequest from './debugRequest/debugRequest.hooks.js';
|
|
1
2
|
import mountSPA from './mountSPA/mountSPA.hooks.js';
|
|
2
3
|
import mountSSG from './mountSSG/mountSSG.hooks.js';
|
|
3
4
|
import ErrorHTML from './ErrorHTML/ErrorHTML.hooks.js';
|
|
4
5
|
|
|
5
|
-
export {
|
|
6
|
+
export {
|
|
7
|
+
debugRequest, mountSPA, mountSSG, ErrorHTML,
|
|
8
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import primitives from '@edge-runtime/primitives';
|
|
2
|
+
import { feedback } from '#utils';
|
|
3
|
+
|
|
4
|
+
class FetchEventPolyfill extends primitives.FetchEvent {
|
|
5
|
+
constructor(request) {
|
|
6
|
+
super(request);
|
|
7
|
+
this.console = {
|
|
8
|
+
log: (log) => feedback.server.log(log),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default FetchEventPolyfill;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { join } from 'path';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
|
+
import mime from 'mime-types';
|
|
4
|
+
import { EdgeRuntime } from 'edge-runtime';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A custom fetch implementation that adds an additional path to the URL if it starts with 'file://'.
|
|
8
|
+
* This function is used to simulate the local edge environment. When a 'file://' request is made,
|
|
9
|
+
* it behaves as if the request is made from within the edge itself. In this case, an additional
|
|
10
|
+
* '.edge/storage' folder is appended to the URL to represent the edge environment.
|
|
11
|
+
* @param {EdgeRuntime} context - VMContext
|
|
12
|
+
* @param {URL} url - The URL to fetch.
|
|
13
|
+
* @param {object} [options] - The fetch options.
|
|
14
|
+
* @returns {Promise<Response>} A Promise that resolves to the Response object.
|
|
15
|
+
*/
|
|
16
|
+
async function fetchPolyfill(context, url, options) {
|
|
17
|
+
const {
|
|
18
|
+
URL, Headers, Response,
|
|
19
|
+
} = context;
|
|
20
|
+
|
|
21
|
+
const urlOBJ = new URL(url);
|
|
22
|
+
if (urlOBJ.href.startsWith('file://')) {
|
|
23
|
+
// url pathname = /VERSION_ID/filePath
|
|
24
|
+
const file = url.pathname.slice(15);
|
|
25
|
+
const filePath = join(process.cwd(), '.edge', 'storage', file);
|
|
26
|
+
const fileContent = readFileSync(filePath);
|
|
27
|
+
const contentType = mime.lookup(filePath) || 'application/octet-stream';
|
|
28
|
+
|
|
29
|
+
const headers = new Headers();
|
|
30
|
+
headers.append('Content-Type', contentType);
|
|
31
|
+
|
|
32
|
+
const response = new Response(fileContent, { headers, ...options });
|
|
33
|
+
return response;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return fetch(url, options);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default fetchPolyfill;
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { mountSPA, ErrorHTML } from '#edge';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Handles the 'fetch' event.
|
|
5
|
+
* @param {FetchEvent} event - The fetch event.
|
|
6
|
+
* @returns {Promise<Response>} The response for the request.
|
|
7
|
+
*/
|
|
8
|
+
async function handle(event) {
|
|
9
|
+
try {
|
|
10
|
+
const myApp = await mountSPA(event.request.url, AZION_VERSION_ID);
|
|
11
|
+
return myApp;
|
|
12
|
+
} catch (e) {
|
|
13
|
+
return ErrorHTML('404');
|
|
14
|
+
}
|
|
8
15
|
}
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import { exec,
|
|
1
|
+
import { exec, getPackageManager } from '#utils';
|
|
2
2
|
|
|
3
3
|
const packageManager = await getPackageManager();
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Runs custom prebuild actions
|
|
7
|
+
* @param {object} buildContext - info about the build
|
|
7
8
|
*/
|
|
8
|
-
async function prebuild() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
await exec(`${packageManager} run build ${npmArgsForward} --output-path=.edge/statics`, 'Angular', true);
|
|
15
|
-
} catch (error) {
|
|
16
|
-
feedback.prebuild.error(error);
|
|
17
|
-
}
|
|
9
|
+
async function prebuild(buildContext) {
|
|
10
|
+
// This is because npm interprets arguments passed directly
|
|
11
|
+
// after the script as options for npm itself, not the script itself.
|
|
12
|
+
const npmArgsForward = packageManager === 'npm' ? '--' : '';
|
|
13
|
+
// support npm, yarn, pnpm
|
|
14
|
+
await exec(`${packageManager} run build ${npmArgsForward} --output-path=.edge/storage`, 'Angular', true);
|
|
18
15
|
}
|
|
19
16
|
|
|
20
17
|
export default prebuild;
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import { mountSSG, ErrorHTML } from
|
|
1
|
+
import { mountSSG, ErrorHTML } from '#edge';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Handles the 'fetch' event.
|
|
5
|
+
* @param {FetchEvent} event - The fetch event.
|
|
6
|
+
* @returns {Promise<Response>} The response for the request.
|
|
7
|
+
*/
|
|
8
|
+
async function handle(event) {
|
|
9
|
+
try {
|
|
10
|
+
const myApp = await mountSSG(event.request.url, AZION_VERSION_ID);
|
|
11
|
+
return myApp;
|
|
12
|
+
} catch (error) {
|
|
13
|
+
return ErrorHTML('404');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -7,31 +7,28 @@ const packageManager = await getPackageManager();
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Runs custom prebuild actions
|
|
10
|
+
* @param {object} buildContext - info about the build
|
|
10
11
|
*/
|
|
11
|
-
async function prebuild() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let outDir = 'dist';
|
|
12
|
+
async function prebuild(buildContext) {
|
|
13
|
+
const newOutDir = '.edge/storage';
|
|
14
|
+
let outDir = 'dist';
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
// check if an output path is specified in config file
|
|
17
|
+
const configFileContent = await readFile('./astro.config.mjs', 'utf-8');
|
|
18
|
+
const attributeMatch = Array.from(
|
|
19
|
+
configFileContent.matchAll(/outDir:(.*)\n/g),
|
|
20
|
+
(match) => match,
|
|
21
|
+
)[0];
|
|
22
|
+
if (attributeMatch) {
|
|
23
|
+
// get the specified value in config
|
|
24
|
+
outDir = attributeMatch[1].trim();
|
|
25
|
+
}
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
await exec(`${packageManager} run build`, 'Astro', true);
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
} catch (error) {
|
|
33
|
-
feedback.prebuild.error(error);
|
|
34
|
-
}
|
|
29
|
+
// move files to vulcan default path
|
|
30
|
+
copyDirectory(outDir, newOutDir);
|
|
31
|
+
rm(outDir, { recursive: true, force: true });
|
|
35
32
|
}
|
|
36
33
|
|
|
37
34
|
export default prebuild;
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import { mountSSG, ErrorHTML } from
|
|
1
|
+
import { mountSSG, ErrorHTML } from '#edge';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Handles the 'fetch' event.
|
|
5
|
+
* @param {FetchEvent} event - The fetch event.
|
|
6
|
+
* @returns {Promise<Response>} The response for the request.
|
|
7
|
+
*/
|
|
8
|
+
async function handle(event) {
|
|
9
|
+
try {
|
|
10
|
+
const myApp = await mountSSG(event.request.url, AZION_VERSION_ID);
|
|
11
|
+
return myApp;
|
|
12
|
+
} catch (e) {
|
|
13
|
+
return ErrorHTML('404');
|
|
14
|
+
}
|
|
8
15
|
}
|
|
@@ -7,31 +7,28 @@ const packageManager = await getPackageManager();
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Runs custom prebuild actions
|
|
10
|
+
* @param {object} buildContext - info about the build
|
|
10
11
|
*/
|
|
11
|
-
async function prebuild() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let outDir = 'public';
|
|
12
|
+
async function prebuild(buildContext) {
|
|
13
|
+
const newOutDir = '.edge/storage';
|
|
14
|
+
let outDir = 'public';
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
// check if an output path is specified in config file
|
|
17
|
+
const configFileContent = await readFile('./_config.yml', 'utf-8');
|
|
18
|
+
const attributeMatch = Array.from(
|
|
19
|
+
configFileContent.matchAll(/public_dir:(.*)\n/g),
|
|
20
|
+
(match) => match,
|
|
21
|
+
)[0];
|
|
22
|
+
if (attributeMatch) {
|
|
23
|
+
// get the specified value in config
|
|
24
|
+
outDir = attributeMatch[1].trim().replace(/["']/g, '');
|
|
25
|
+
}
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
await exec(`${packageManager} hexo generate`, 'Hexo', true);
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
} catch (error) {
|
|
33
|
-
feedback.prebuild.error(error);
|
|
34
|
-
}
|
|
29
|
+
// move files to vulcan default path
|
|
30
|
+
copyDirectory(outDir, newOutDir);
|
|
31
|
+
rm(outDir, { recursive: true, force: true });
|
|
35
32
|
}
|
|
36
33
|
|
|
37
34
|
export default prebuild;
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import { mountSSG } from
|
|
1
|
+
import { mountSSG } from '#edge';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Handles the 'fetch' event.
|
|
5
|
+
* @param {FetchEvent} event - The fetch event.
|
|
6
|
+
* @returns {Promise<Response>} The response for the request.
|
|
7
|
+
*/
|
|
8
|
+
async function handle(event) {
|
|
9
|
+
try {
|
|
10
|
+
const myApp = await mountSSG(event.request.url, AZION_VERSION_ID);
|
|
11
|
+
return myApp;
|
|
12
|
+
} catch (e) {
|
|
13
|
+
const notFoundError = new URL(`${AZION_VERSION_ID}/404.html`, 'file://');
|
|
14
|
+
return fetch(notFoundError);
|
|
15
|
+
}
|
|
9
16
|
}
|
|
@@ -26,11 +26,11 @@ const packageManager = await getPackageManager();
|
|
|
26
26
|
* @param {string} directory - The root directory to start moving files.
|
|
27
27
|
* @example
|
|
28
28
|
* // Before:
|
|
29
|
-
* // Root directory: '/path/to/project/.edge/
|
|
29
|
+
* // Root directory: '/path/to/project/.edge/storage'
|
|
30
30
|
* // Files in the directory: ['home.html', 'about.html', 'contact.html', 'styles.css']
|
|
31
31
|
*
|
|
32
|
-
* // After calling moveFiles('/path/to/project/.edge/
|
|
33
|
-
* // Root directory: '/path/to/project/.edge/
|
|
32
|
+
* // After calling moveFiles('/path/to/project/.edge/storage'):
|
|
33
|
+
* // Root directory: '/path/to/project/.edge/storage'
|
|
34
34
|
* // Files in the directory: ['styles.css']
|
|
35
35
|
* // Subdirectory 'home':
|
|
36
36
|
* // - index.html (previously home.html)
|
|
@@ -139,55 +139,52 @@ function validateStaticSiteMode(nextConfig) {
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
/**
|
|
142
|
-
* Runs custom prebuild actions
|
|
142
|
+
* Runs custom prebuild actions
|
|
143
|
+
* @param {object} buildContext - info about the build
|
|
143
144
|
*/
|
|
144
|
-
async function prebuild() {
|
|
145
|
-
|
|
146
|
-
feedback.prebuild.info('Starting Next.js static build process...');
|
|
145
|
+
async function prebuild(buildContext) {
|
|
146
|
+
feedback.prebuild.info('Starting Next.js static build process...');
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
const nextVersion = getPackageVersion('next');
|
|
149
|
+
feedback.prebuild.info('Detected Next.js version:', nextVersion);
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
const staticsOutputDir = '.edge/storage';
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
if (isANewerVersion(nextVersion)) {
|
|
154
|
+
const nextConfig = await getNextConfig();
|
|
155
155
|
|
|
156
|
-
|
|
156
|
+
validateStaticSiteMode(nextConfig);
|
|
157
157
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
158
|
+
// check if an output path is specified in config file
|
|
159
|
+
let outDir = 'out';
|
|
160
|
+
const configFileContent = await readFile('./next.config.js', 'utf-8');
|
|
161
|
+
const attributeMatch = Array.from(
|
|
162
|
+
configFileContent.matchAll(/distDir:(.*),/g),
|
|
163
|
+
(match) => match,
|
|
164
|
+
)[0];
|
|
165
|
+
if (attributeMatch) {
|
|
166
|
+
// get the specified value in config
|
|
167
|
+
outDir = attributeMatch[1].trim().replace(/["']/g, '');
|
|
168
|
+
}
|
|
169
169
|
|
|
170
|
-
|
|
170
|
+
await exec(`${packageManager} run build`, `Next ${nextVersion}`, true);
|
|
171
171
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
// move files to vulcan default path
|
|
173
|
+
copyDirectory(outDir, staticsOutputDir);
|
|
174
|
+
rm(outDir, { recursive: true, force: true });
|
|
175
175
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
176
|
+
feedback.prebuild.info('Adapting Next.js build output...');
|
|
177
|
+
await moveFiles(`${process.cwd()}/${staticsOutputDir}`);
|
|
178
|
+
} else {
|
|
179
|
+
await exec(`${packageManager} run build`, `Next ${nextVersion}`, true);
|
|
180
180
|
|
|
181
|
-
|
|
181
|
+
await exec(`npx next export -o ${staticsOutputDir}`, `Next ${nextVersion}`, true);
|
|
182
182
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
feedback.prebuild.success('Next.js build adaptation completed successfully.');
|
|
188
|
-
} catch (error) {
|
|
189
|
-
feedback.prebuild.error('Error occurred during Next.js build adaptation:', error);
|
|
183
|
+
feedback.prebuild.info('Adapting Next.js build output...');
|
|
184
|
+
await moveFiles(`${process.cwd()}/${staticsOutputDir}`);
|
|
190
185
|
}
|
|
186
|
+
|
|
187
|
+
feedback.prebuild.success('Next.js build adaptation completed successfully.');
|
|
191
188
|
}
|
|
192
189
|
|
|
193
190
|
export default prebuild;
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import { mountSPA, ErrorHTML } from
|
|
1
|
+
import { mountSPA, ErrorHTML } from '#edge';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Handles the 'fetch' event.
|
|
5
|
+
* @param {FetchEvent} event - The fetch event.
|
|
6
|
+
* @returns {Promise<Response>} The response for the request.
|
|
7
|
+
*/
|
|
8
|
+
async function handle(event) {
|
|
3
9
|
try {
|
|
4
|
-
const myApp = await mountSPA(event.request.url,
|
|
10
|
+
const myApp = await mountSPA(event.request.url, AZION_VERSION_ID);
|
|
5
11
|
return myApp;
|
|
6
12
|
} catch (e) {
|
|
7
|
-
return ErrorHTML(
|
|
13
|
+
return ErrorHTML('404');
|
|
8
14
|
}
|
|
15
|
+
}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { exec,
|
|
1
|
+
import { exec, getPackageManager } from '#utils';
|
|
2
2
|
|
|
3
3
|
const packageManager = await getPackageManager();
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Runs custom prebuild actions
|
|
7
|
+
* @param {object} buildContext - info about the build
|
|
7
8
|
*/
|
|
8
|
-
async function prebuild() {
|
|
9
|
-
|
|
10
|
-
await exec(`BUILD_PATH="./.edge/statics" ${packageManager} run build`, 'React', true);
|
|
11
|
-
} catch (error) {
|
|
12
|
-
feedback.prebuild.error(error);
|
|
13
|
-
}
|
|
9
|
+
async function prebuild(buildContext) {
|
|
10
|
+
await exec(`BUILD_PATH="./.edge/storage" ${packageManager} run build`, 'React', true);
|
|
14
11
|
}
|
|
15
12
|
|
|
16
13
|
export default prebuild;
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import { mountSPA, ErrorHTML } from
|
|
1
|
+
import { mountSPA, ErrorHTML } from '#edge';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Handles the 'fetch' event.
|
|
5
|
+
* @param {FetchEvent} event - The fetch event.
|
|
6
|
+
* @returns {Promise<Response>} The response for the request.
|
|
7
|
+
*/
|
|
8
|
+
async function handle(event) {
|
|
3
9
|
try {
|
|
4
|
-
const myApp = await mountSPA(event.request.url,
|
|
10
|
+
const myApp = await mountSPA(event.request.url, AZION_VERSION_ID);
|
|
5
11
|
return myApp;
|
|
6
12
|
} catch (e) {
|
|
7
|
-
return ErrorHTML(
|
|
13
|
+
return ErrorHTML('404');
|
|
8
14
|
}
|
|
15
|
+
}
|
|
@@ -1,19 +1,75 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
exec, getPackageManager, copyDirectory,
|
|
3
|
+
} from '#utils';
|
|
4
|
+
import { lstat, readFile, rm } from 'fs/promises';
|
|
5
|
+
import { join } from 'path';
|
|
2
6
|
|
|
3
7
|
const packageManager = await getPackageManager();
|
|
8
|
+
const edgeStorageDir = '.edge/storage';
|
|
9
|
+
const defaultViteOutDir = 'dist';
|
|
4
10
|
|
|
5
11
|
/**
|
|
6
|
-
*
|
|
12
|
+
* Check if the vite.config.js file exists.
|
|
13
|
+
* @returns {boolean} True if the file exists, false otherwise.
|
|
7
14
|
*/
|
|
8
|
-
async function
|
|
15
|
+
async function viteConfigExists() {
|
|
9
16
|
try {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
await lstat('./vite.config.js');
|
|
18
|
+
return true;
|
|
19
|
+
} catch (err) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Read and parse the vite.config.js file.
|
|
26
|
+
* @returns {object} The parsed configuration object or null if the file doesn't exist.
|
|
27
|
+
*/
|
|
28
|
+
async function readViteConfig() {
|
|
29
|
+
try {
|
|
30
|
+
const configFileContent = await readFile('./vite.config.js', 'utf-8');
|
|
31
|
+
return JSON.parse(configFileContent.replace(/^module.exports = /, ''));
|
|
32
|
+
} catch (err) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Runs custom prebuild actions.
|
|
39
|
+
*/
|
|
40
|
+
async function prebuild() {
|
|
41
|
+
const npmArgsForward = packageManager === 'npm' ? '--' : '';
|
|
42
|
+
|
|
43
|
+
let outDir = defaultViteOutDir;
|
|
44
|
+
let destPath = edgeStorageDir;
|
|
45
|
+
|
|
46
|
+
const isViteProject = await viteConfigExists();
|
|
47
|
+
|
|
48
|
+
if (isViteProject) {
|
|
49
|
+
await exec(
|
|
50
|
+
`${packageManager} run build ${npmArgsForward}`,
|
|
51
|
+
'Vue/Vite',
|
|
52
|
+
true,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const config = await readViteConfig();
|
|
56
|
+
|
|
57
|
+
if (config?.build?.outDir) {
|
|
58
|
+
outDir = config.build.outDir;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const srcPath = join('.', outDir);
|
|
62
|
+
destPath = join(edgeStorageDir);
|
|
63
|
+
copyDirectory(outDir, srcPath);
|
|
64
|
+
rm(outDir, { recursive: true, force: true });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!isViteProject) {
|
|
68
|
+
await exec(
|
|
69
|
+
`${packageManager} run build ${npmArgsForward} --dest ${destPath}`,
|
|
70
|
+
'Vue',
|
|
71
|
+
true,
|
|
72
|
+
);
|
|
17
73
|
}
|
|
18
74
|
}
|
|
19
75
|
|