From 846990f63f4b194e5f9b3e82c687be8f9ede1a65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Narciso?= Date: Wed, 18 Jun 2025 21:51:59 -0300 Subject: [PATCH 1/3] fix(presets): astro prebuild --- .../presets/src/presets/astro/prebuild.ts | 59 ++++++++++++------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/packages/presets/src/presets/astro/prebuild.ts b/packages/presets/src/presets/astro/prebuild.ts index 17633194..16850402 100644 --- a/packages/presets/src/presets/astro/prebuild.ts +++ b/packages/presets/src/presets/astro/prebuild.ts @@ -1,27 +1,46 @@ import { copyDirectory, exec, getPackageManager } from 'azion/utils/node'; -import { readFile } from 'fs/promises'; - -/** - * Runs custom prebuild actions for Astro - */ -async function prebuild() { - const packageManager = await getPackageManager(); - const newOutDir = '.edge/storage'; - let outDir = 'dist'; - - // check if an output path is specified in config file - const configFileContent = await readFile('./astro.config.mjs', 'utf-8'); - const attributeMatch = Array.from(configFileContent.matchAll(/outDir:(.*)\n/g), (match) => match)[0]; - if (attributeMatch) { - outDir = attributeMatch[1].trim(); +import { constants } from 'fs'; +import { access, readFile } from 'fs/promises'; + +const CONFIG_FILES = ['astro.config.ts', 'astro.config.mjs', 'astro.config.js', 'astro.config.cjs'] as const; + +async function getAstroOutDir(): Promise { + for (const configFile of CONFIG_FILES) { + try { + await access(configFile, constants.F_OK); + const configContent = await readFile(configFile, 'utf-8'); + + // Regex supports: outDir: 'path', outDir:"path", outDir: `path` + const outDirMatch = configContent.match(/outDir\s*:\s*['"`]([^'"`]+)['"`]/); + + if (outDirMatch && outDirMatch[1]) { + return outDirMatch[1].trim(); + } + + break; + } catch { + continue; + } } - await exec(`${packageManager} run build`, { - scope: 'Astro', - verbose: true, - }); + return 'dist'; // Default Astro output directory +} + +async function prebuild(): Promise { + try { + const [packageManager, outDir] = await Promise.all([getPackageManager(), getAstroOutDir()]); + + const newOutDir = '.edge/storage'; - copyDirectory(outDir, newOutDir); + await exec(`${packageManager} run build`, { + scope: 'Astro', + verbose: true, + }); + + copyDirectory(outDir, newOutDir); + } catch (error) { + throw new Error(`Erro durante o prebuild do Astro: ${error instanceof Error ? error.message : String(error)}`); + } } export default prebuild; From 8673494eb1cf86de4544a7791db9524866b7ddbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Narciso?= Date: Thu, 19 Jun 2025 18:15:27 -0300 Subject: [PATCH 2/3] fix: rm worker property --- README.md | 3 --- packages/config/README.md | 2 -- packages/config/src/configProcessor/helpers/schema.ts | 4 ---- packages/config/src/types.ts | 1 - 4 files changed, 10 deletions(-) diff --git a/README.md b/README.md index 96a22a48..d5eaf324 100644 --- a/README.md +++ b/README.md @@ -211,7 +211,6 @@ const config = { entry: './src/index.js', preset: 'react', polyfills: true, - worker: true, }, domain: { name: 'example.com', @@ -302,7 +301,6 @@ const config = defineConfig({ }, }, polyfills: true, - worker: true, extend: (config) => { // Customize bundler configuration return { @@ -394,7 +392,6 @@ export default defineConfig({ // Other build configurations entry: './src/index.ts', polyfills: true, - worker: true, memoryFS: { injectionDirs: ['./src/inject'], removePathPrefix: './src', diff --git a/packages/config/README.md b/packages/config/README.md index 49213a8b..a92d5119 100644 --- a/packages/config/README.md +++ b/packages/config/README.md @@ -313,7 +313,6 @@ Type definition for the build configuration. - `preset?: string | AzionBuildPreset` - The preset to be used, can be a string or an AzionBuildPreset object. - `entry?: string | string[] | Record` - The entry file, can be a string, an array of strings, or an object. - `polyfills?: boolean` - Whether to include polyfills. -- `worker?: boolean` - Whether to build a worker. - `extend?: (context: T) => T` - Function to extend the bundler configuration. - `memoryFS?: { injectionDirs: string[], removePathPrefix: string }` - In-memory file system configuration. @@ -371,7 +370,6 @@ Type definition for the build configuration. - `setup: BundlerSetup` - Bundler configuration. - \*`bundler?: 'webpack' | 'esbuild'` - The bundler to be used. - `polyfills?: boolean` - Whether to include polyfills. -- `worker?: boolean` - Whether to build a worker. - `extend?: (context: T) => T` - Function to extend the bundler configuration. - `memoryFS?: { injectionDirs: string[], removePathPrefix: string }` - In-memory file system configuration. diff --git a/packages/config/src/configProcessor/helpers/schema.ts b/packages/config/src/configProcessor/helpers/schema.ts index 4880d56c..cdd292e9 100644 --- a/packages/config/src/configProcessor/helpers/schema.ts +++ b/packages/config/src/configProcessor/helpers/schema.ts @@ -492,10 +492,6 @@ const azionConfigSchema = { type: 'boolean', errorMessage: "The 'build.polyfills' must be a boolean", }, - worker: { - type: 'boolean', - errorMessage: "The 'build.worker' must be a boolean", - }, extend: { instanceof: 'Function', errorMessage: "The 'build.extend' must be a function", diff --git a/packages/config/src/types.ts b/packages/config/src/types.ts index 9095200c..5bfe6ea7 100644 --- a/packages/config/src/types.ts +++ b/packages/config/src/types.ts @@ -321,7 +321,6 @@ export interface AzionBuild T; memoryFS?: { injectionDirs: string[]; From ada2ea5ea5843bba934084c92b101d8b842dd99e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Narciso?= Date: Fri, 20 Jun 2025 15:11:11 -0300 Subject: [PATCH 3/3] chore: fix message lang --- packages/presets/src/presets/astro/prebuild.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/presets/src/presets/astro/prebuild.ts b/packages/presets/src/presets/astro/prebuild.ts index 16850402..798f11eb 100644 --- a/packages/presets/src/presets/astro/prebuild.ts +++ b/packages/presets/src/presets/astro/prebuild.ts @@ -39,7 +39,7 @@ async function prebuild(): Promise { copyDirectory(outDir, newOutDir); } catch (error) { - throw new Error(`Erro durante o prebuild do Astro: ${error instanceof Error ? error.message : String(error)}`); + throw new Error(`Error during Astro prebuild: ${error instanceof Error ? error.message : String(error)}`); } }