8000 fix: add preset files and adjustments by jcbsfilho · Pull Request #134 · aziontech/lib · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: add preset files and adjustments #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
"packages/**/dist/**/*",
"cli/**/*",
"packages/unenv-preset/src/polyfills/*",
"packages/bundler/src/polyfills/*"
"packages/bundler/src/polyfills/*",
"packages/presets/src/presets/*"
],
"exports": {
".": {
Expand All @@ -90,6 +91,7 @@
"require": "./packages/presets/dist/index.cjs",
"import": "./packages/presets/dist/index.js"
},
"./presets/preset/*": "./packages/presets/src/presets/*",
"./bundler": {
"require": "./packages/bundler/dist/index.cjs",
"import": "./packages/bundler/dist/index.js"
Expand Down Expand Up @@ -225,13 +227,12 @@
}
},
"dependencies": {
"@edge-runtime/primitives": "^6.0.0",
"@edge-runtime/primitives": "^4.0.5",
"@fastly/http-compute-js": "^1.1.5",
"accepts": "^1.3.8",
"ajv": "^8.17.1",
"ajv-errors": "^3.0.0",
"ajv-keywords": "^5.1.0",
"mathjs": "^13.1.1",
"accepts": "^1.3.8",
"browserify-zlib": "^0.2.0",
"chalk": "^5.3.0",
"cookie": "^1.0.2",
Expand All @@ -242,6 +243,7 @@
"inherits": "^2.0.4",
"ip": "^2.0.1",
"lodash-es": "^4.17.21",
"mathjs": "^13.1.1",
"mime": "^3.0.0",
"mime-types": "^2.1.35",
"pcre-to-regexp": "^1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"src/polyfills/*"
],
"dependencies": {
"@edge-runtime/primitives": "^6.0.0",
"@edge-runtime/primitives": "^4.0.5",
"@fastly/http-compute-js": "^1.1.5",
"@lib/unenv-preset": "*",
"accepts": "^1.3.8",
Expand Down
6 changes: 4 additions & 2 deletions packages/presets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
".": {
"require": "./dist/index.cjs",
"import": "./dist/index.js"
}
},
"./presets/preset/*": "./src/presets/src/*"
},
"author": "aziontech",
"license": "MIT",
"files": [
"dist",
"package.json"
"package.json",
"src/presets/*"
],
"dependencies": {
"cookie": "^1.0.2",
Expand Down
2 changes: 2 additions & 0 deletions packages/presets/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export * from './presets/preact';
export * from './presets/qwik';
export * from './presets/react';
export * from './presets/rustwasm';
export * from './presets/stencil';
export * from './presets/svelte';
export * from './presets/typescript';
export * from './presets/vitepress';
export * from './presets/vue';
export * from './presets/vuepress';
4 changes: 2 additions & 2 deletions packages/presets/src/presets/astro/handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FetchEvent } from 'azion/types';
import { mountSPA } from 'azion/utils/edge';
import { mountMPA } from 'azion/utils/edge';

/**
* Handles the 'fetch' event.
Expand All @@ -8,7 +8,7 @@ import { mountSPA } from 'azion/utils/edge';
*/
async function handler(event: FetchEvent): Promise<Response> {
try {
const myApp = await mountSPA(event.request.url);
const myApp = await mountMPA(event.request.url);
return myApp;
} catch (e) {
return new Response('Not Found', { status: 500 });
Expand Down
5 changes: 2 additions & 3 deletions packages/presets/src/presets/eleventy/prebuild.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { copyDirectory, exec, getPackageManager } from 'azion/utils/node';
import { copyDirectory, exec } from 'azion/utils/node';

/**
* Runs custom prebuild actions for Eleventy
*/
async function prebuild(): Promise<void> {
const packageManager = await getPackageManager();
const newOutDir = '.edge/storage';
const outDir = '_site';

await exec(`${packageManager} exec @11ty/eleventy`, {
await exec(`npx -y @11ty/eleventy`, {
scope: 'Eleventy',
verbose: true,
});
F438 Expand Down
8 changes: 5 additions & 3 deletions packages/presets/src/presets/next/default/prebuild/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { writeFileSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
import { join, resolve } from 'path';

import { feedback, getAbsoluteDirPath } from 'azion/utils/node';
import { getNextProjectConfig } from '../../utils/next.js';
Expand Down Expand Up @@ -109,13 +109,15 @@ async function run(prebuildContext) {

const buildMetadata = { hasIndexFunctions, i18n };

const filePath = resolve(getAbsoluteDirPath(import.meta.url, 'presets'), 'src');

return {
// onEntry
filesToInject: [
// async local storage use
`${getAbsoluteDirPath()}/presets/next/default/handler/async-local-storage.js`,
`${filePath}/presets/next/default/handler/async-local-storage.js`,
// node custom server
`${getAbsoluteDirPath()}/presets/next/node/handler/index.js`,
`${filePath}/presets/next/node/handler/index.js`,
// file to generate Output. It contains functions references to build
outputReferencesFilePath,
],
Expand Down
2 changes: 1 addition & 1 deletion packages/presets/src/presets/next/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async function handlerDefault(event: FetchEvent): Promise<Response> {
}

async function handler(event: FetchEvent): Promise<Response> {
if ((globalThis as any).nextBuildStatic) {
if ((globalThis as any).bundler?.nextBuildStatic) {
return handlerStatic(event);
}
return handlerDefault(event);
Expand Down
4 changes: 2 additions & 2 deletions packages/presets/src/presets/next/node/prebuild/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ async function run(nextVersion, buildContext) {
// INIT FOLDER CUSTOM SERVER
const CUSTOM_SERVER_DIR = 'custom-server';
const CURRENT_VERSION = nextVersion;
const vulcanLibPath = getAbsoluteDirPath();
const customServerPath = join(vulcanLibPath, 'presets', 'next', 'node', CUSTOM_SERVER_DIR, CURRENT_VERSION);
const filePath = path.resolve(getAbsoluteDirPath(import.meta.url, 'presets'), 'src');
const customServerPath = join(filePath, 'presets', 'next', 'node', CUSTOM_SERVER_DIR, CURRENT_VERSION);
const rootDir = process.cwd();
// try version dir
const outPathCustomServer = path.resolve(OUT_DIR_CUSTOM_SERVER, 'custom-server');
Expand Down
4 changes: 2 additions & 2 deletions packages/presets/src/presets/vitepress/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AzionBuildPreset } from 'azion/config';
import config from './config';
import handler from './handler';
import metadata from './metadata';
// import prebuild from './prebuild';
import prebuild from './prebuild';
// import postbuild from './postbuild';

export const vitepress: AzionBuildPreset = { config, metadata, handler };
export const vitepress: AzionBuildPreset = { config, metadata, handler, prebuild };
48 changes: 48 additions & 0 deletions packages/presets/src/presets/vuepress/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { defineConfig } from 'azion/config';

export default defineConfig({
build: {
bundler: 'esbuild',
preset: 'vuepress',
polyfills: false,
},
origin: [
{
name: 'origin-storage-default',
type: 'object_storage',
},
],
rules: {
request: [
{
name: 'Set Storage Origin for All Requests',
match: '^\\/',
behavior: {
setOrigin: {
name: 'origin-storage-default',
type: 'object_storage',
},
},
},
{
name: 'Deliver Static Assets',
match: '.(css|js|ttf|woff|woff2|pdf|svg|jpg|jpeg|gif|bmp|png|ico|mp4|json|xml|html)$',
behavior: {
setOrigin: {
name: 'origin-storage-default',
type: 'object_storage',
},
deliver: true,
},
},

{
name: 'Redirect to index.html',
match: '^\\/',
behavior: {
rewrite: `/index.html`,
},
},
],
},
});
18 changes: 18 additions & 0 deletions packages/presets/src/presets/vuepress/handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { FetchEvent } from 'azion/types';
import { mountMPA } from 'azion/utils/edge';

/**
* Handles the 'fetch' event.
* @param {import('azion/types').FetchEvent} event - The fetch event.
* @returns {Promise<Response>} The response for the request.
*/
async function handler(event: FetchEvent): Promise<Response> {
try {
const myApp = await mountMPA(event.request.url);
return myApp;
} catch (e) {
return new Response('Not Found', { status: 500 });
}
}

export default handler;
7 changes: 7 additions & 0 deletions packages/presets/src/presets/vuepress/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { AzionBuildPreset } from 'azion/config';
import config from './config';
import handler from './handler';
import metadata from './metadata';
import prebuild from './prebuild';

export const vuepress: AzionBuildPreset = { config, metadata, handler, prebuild };
7 changes: 7 additions & 0 deletions packages/presets/src/presets/vuepress/metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { PresetMetadata } from 'azion/config';

const metadata: PresetMetadata = {
name: 'vuepress',
};

export default metadata;
39 changes: 39 additions & 0 deletions packages/presets/src/presets/vuepress/prebuild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { copyDirectory, exec, getPackageManager } from 'azion/utils/node';
import { lstat, rm } from 'fs/promises';

const packageManager = await getPackageManager();

/**
* Check if the project uses the "/docs"
*/
async function docsFolderExists(): Promise<boolean> {
try {
await lstat('docs/');
return true;
} catch (err) {
return false;
}
}

/**
* Runs custom prebuild actions for VitePress
*/
async function prebuild(): Promise<void> {
const newOutDir = '.edge/storage';

// The main folder for VuePress usually is 'docs',
// however the users also might use the root folder
const outDir = (await docsFolderExists()) ? 'docs/.vuepress/dist' : '.vuepress/dist';

await exec(`${packageManager} run docs:build`, {
scope: 'VuePress',
verbose: true,
});

// move files to vulcan default path
copyDirectory(outDir, newOutDir);

rm(outDir, { recursive: true, force: true });
}

export default prebuild;
0