Skip to content

v1.20.0-stage.15 #178

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 3 commits into from
Jun 20, 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
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ const config = {
entry: './src/index.js',
preset: 'react',
polyfills: true,
worker: true,
},
domain: {
name: 'example.com',
Expand Down Expand Up @@ -302,7 +301,6 @@ const config = defineConfig({
},
},
polyfills: true,
worker: true,
extend: (config) => {
// Customize bundler configuration
return {
Expand Down Expand Up @@ -394,7 +392,6 @@ export default defineConfig({
// Other build configurations
entry: './src/index.ts',
polyfills: true,
worker: true,
memoryFS: {
injectionDirs: ['./src/inject'],
removePathPrefix: './src',
Expand Down
2 changes: 0 additions & 2 deletions packages/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>` - 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.

Expand Down Expand Up @@ -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.

Expand Down
4 changes: 0 additions & 4 deletions packages/config/src/configProcessor/helpers/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion packages/config/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ export interface AzionBuild<T extends WebpackConfig | ESBuildConfig | unknown =
bundler?: 'webpack' | 'esbuild';
preset?: PresetInput;
polyfills?: boolean;
worker?: boolean;
extend?: (context: T) => T;
memoryFS?: {
injectionDirs: string[];
Expand Down
59 changes: 39 additions & 20 deletions packages/presets/src/presets/astro/prebuild.ts
Original file line number Diff line number Diff line change
@@ -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<string> {
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<void> {
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(`Error during Astro prebuild: ${error instanceof Error ? error.message : String(error)}`);
}
}

export default prebuild;