@aziontech/bundler 1.0.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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Azion Technologies
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,413 @@
1
+ <p align="center">
2
+ <img src="assets/logo.png" alt="Azion Bundler Logo" width="200"/>
3
+ </p>
4
+
5
+ # Azion Bundler - Built for Builders of the Edge
6
+
7
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.md)
8
+ [![GitHub Stars](https://img.shields.io/github/stars/aziontech/bundler.svg)](https://github.com/aziontech/bundler/stargazers)
9
+
10
+ Azion Bundler is a powerful tool designed to build and adapt projects for edge computing. It handles module resolution and applies necessary polyfills through [unjs/unenv](https://github.com/unjs/unenv) while providing an abstraction layer over popular bundlers like esbuild and webpack. The tool includes a local development environment for testing and debugging, and processes Infrastructure as Code (IaC) through its manifest system.
11
+
12
+ ## Table of Contents
13
+
14
+ - [Azion Bundler - Built for Builders of the Edge](#azion-bundler---built-for-builders-of-the-edge)
15
+ - [Table of Contents](#table-of-contents)
16
+ - [Quick Installation](#quick-installation)
17
+ - [Getting Started for Development](#getting-started-for-development)
18
+ - [Using](#using)
19
+ - [Commands](#commands)
20
+ - [`build`](#build)
21
+ - [`dev`](#dev)
22
+ - [`config`](#config)
23
+ - [`presets`](#presets)
24
+ - [`store`](#store)
25
+ - [`manifest`](#manifest)
26
+ - [Configuration](#configuration)
27
+ - [Build Process Flow](#build-process-flow)
28
+ - [Documentation](#documentation)
29
+ - [Supported Features](#supported-features)
30
+ - [Contributing](#contributing)
31
+ - [License](#license)
32
+
33
+ ## Quick Installation
34
+
35
+ For those who just want to use Azion Bundler in their project without contributing to the development, you can install it directly from npm.
36
+
37
+ ```shell
38
+ npm install @aziontech/bundler
39
+ ```
40
+
41
+ or if you prefer yarn:
42
+
43
+ ```shell
44
+ yarn add @aziontech/bundler
45
+ ```
46
+
47
+ ## Getting Started for Development
48
+
49
+ Follow these steps to start using Azion Bundler:
50
+
51
+ 1. Clone the repository: Clone the Azion Bundler repository from GitHub to your local machine.
52
+
53
+ ```shell
54
+ git clone https://github.com/aziontech/bundler.git
55
+ ```
56
+
57
+ 2. Installation: Navigate to the cloned Azion Bundler directory and install the required dependencies.
58
+
59
+ ```shell
60
+ cd bundler
61
+ pnpm install
62
+ ```
63
+
64
+ 3. Install the Azion Bundler CLI globally, which allows you to use it as a command-line tool from anywhere in your system.
65
+
66
+ ```shell
67
+ pnpm install -g
68
+ ```
69
+
70
+ This command sets up the necessary project structure and configuration files for Azion Bundler.
71
+
72
+ 4. Start developing: Once the project is set up, you can start developing your JavaScript applications or frameworks using the power of Bundler.
73
+
74
+ ## Using
75
+
76
+ See some examples below:
77
+
78
+ - Build a JavaScript/Node project (back-end)
79
+
80
+ ```shell
81
+ azbundler build
82
+ ```
83
+
84
+ - Build a TypeScript/Node (back-end)
85
+
86
+ ```shell
87
+ azbundler build --preset typescript
88
+ ```
89
+
90
+ - Build a Next.js project
91
+
92
+ ```shell
93
+ azbundler build --preset next
94
+ ```
95
+
96
+ - Build Astro.js project
97
+
98
+ ```shell
99
+ azbundler build --preset astro
100
+ ```
101
+
102
+ - Test your project locally (after build)
103
+
104
+ ```shell
105
+ azbundler dev
106
+ ```
107
+
108
+ ## Commands
109
+
110
+ The Azion Bundler CLI provides several commands to help you manage your edge applications:
111
+
112
+ > ⚠️ \*Deprecation Notice:
113
+ > Support for the webpack bundler will be discontinued in future releases. While it is still available for now, new features, fixes, and improvements will be focused exclusively on esbuild. We recommend migrating to esbuild as soon as possible to ensure compatibility and better performance in upcoming versions.
114
+
115
+ ### `build`
116
+
117
+ Builds your project for edge deployment.
118
+
119
+ ```shell
120
+ azbundler build [options]
121
+
122
+ Options:
123
+ -e, --entry <string> Code entrypoint (default: ./handler.js or ./handler.ts)
124
+ -p, --preset <type> Preset of build target (e.g., vue, next, javascript)
125
+ --polyfills Use node polyfills in build (default: true)
126
+ -w, --worker Enable worker mode with addEventListener signature (default: false)
127
+ -d, --dev Build in development mode (default: false)
128
+ -x, --experimental Enable experimental features (default: false)
129
+ ```
130
+
131
+ ### `dev`
132
+
133
+ Starts a local development environment.
134
+
135
+ ```shell
136
+ azbundler dev [entry] [options]
137
+
138
+ Arguments:
139
+ entry Specify the entry file (default: .edge/worker.dev.js)
140
+
141
+ Options:
142
+ -p, --port <port> Specify the port (default: "3333")
143
+ -x, --experimental Enable experimental features (default: false)
144
+ ```
145
+
146
+ ### `config`
147
+
148
+ Manages Azion configuration settings with CRUD operations.
149
+
150
+ ```shell
151
+ azbundler config <command> [options]
152
+
153
+ Commands:
154
+ create Create a new configuration property
155
+ read Read configuration properties
156
+ update Update existing configuration properties
157
+ delete Delete configuration properties
158
+
159
+ Options:
160
+ -k, --key <key> Property key (e.g., build.preset or applications[0].name)
161
+ -v, --value <value> Value to be set (for create/update commands)
162
+ -a, --all Read or delete entire configuration (for read/delete commands)
163
+
164
+ Examples:
165
+ $ azbundler config create -k "build.preset" -v "typescript"
166
+ $ azbundler config read -k "applications[0].name"
167
+ $ azbundler config update -k "build.bundler" -v "esbuild"
168
+ $ azbundler config delete -k "build.polyfills"
169
+ $ azbundler config read --all
170
+ ```
171
+
172
+ ### `presets`
173
+
174
+ Manages presets for Azion projects.
175
+
176
+ ```shell
177
+ azbundler presets <command> [preset]
178
+
179
+ Commands:
180
+ ls List all available presets
181
+ config Get Azion configuration file for a specific preset
182
+
183
+ Arguments:
184
+ preset Preset name (required for config command)
185
+
186
+ Examples:
187
+ $ azbundler presets ls
188
+ $ azbundler presets config react
189
+ $ azbundler presets config next
190
+ ```
191
+
192
+ ### `store`
193
+
194
+ Manages store configuration.
195
+
196
+ ```shell
197
+ azbundler store <command> [options]
198
+
199
+ Commands:
200
+ init Initialize store configuration
201
+ destroy Remove store configuration
202
+
203
+ Options:
204
+ -c, --config <json> Configuration in JSON format
205
+ -s, --scope <scope> Scope of the store (default: global)
206
+ ```
207
+
208
+ ### `manifest`
209
+
210
+ Manages manifest files for Azion.
211
+
212
+ ```shell
213
+ azbundler manifest [action] [options]
214
+
215
+ Arguments:
216
+ action Action to perform: "transform" (JSON to JS) or "generate" (config to manifest)
217
+ (default: "generate")
218
+
219
+ Options:
220
+ -e, --entry <path> Path to the input file or configuration file
221
+ -o, --output <path> Output file/directory path
222
+
223
+ Examples:
224
+ $ azbundler manifest transform -e manifest.json -o azion.config.js
225
+ $ azbundler manifest generate -e azion.config.js -o .edge
226
+ $ azbundler manifest -e azion.config.js -o .edge
227
+ ```
228
+
229
+ ## Configuration
230
+
231
+ The configuration file (`azion.config.js` or `azion.config.ts`) offers a robust configuration system for Bundler. With Azion Bundler, you can extend configurations and leverage pre-configured framework presets for immediate use. The tool empowers users to create their own automations and extensions, making it highly customizable for specific project needs.
232
+
233
+ As the JavaScript engine powering the [Azion CLI](https://github.com/aziontech/azion), it seamlessly integrates with [Azion Libraries](https://github.com/aziontech/lib) to read presets and pre-configured bundler settings from `@aziontech/builder` and framework presets from `@aziontech/presets`. The bundler follows a modular architecture with specialized modules like `@build`, `@prebuild`, and `@postbuild` through the `build` command.
234
+
235
+ The configuration is divided into two main areas:
236
+
237
+ - The `build` property manages all bundler-related settings, including entry points, presets, and build configurations
238
+ - Other properties (like domain, origin, cache, rules) are related to Azion CDN and Edge Computing platform settings
239
+
240
+ While these hooks are pre-configured in framework presets, you can customize them in your `azion.config.ts` to fit your specific needs. You can either create your own configuration from scratch or extend existing presets. Here's an example of extending the Next.js preset:
241
+
242
+ ```typescript
243
+ import { defineConfig } from '@aziontech/config';
244
+ import type { AzionPrebuildResult, AzionConfig } from '@aziontech/config';
245
+ import { emscripten } from '@aziontech/presets';
246
+
247
+ export default defineConfig({
248
+ build: {
249
+ extend: (config) => {
250
+ config.define = {
251
+ ...config.define,
252
+ 'global.customFeature': 'JSON.stringify(true)',
253
+ 'process.env.CUSTOM_VAR': 'JSON.stringify("value")',
254
+ };
255
+ return config;
256
+ },
257
+ preset: {
258
+ ...emscripten,
259
+ prebuild: async (config: AzionConfig, ctx: BuildContext): Promise<AzionPrebuildResult> => {
260
+ // Your custom prebuild logic here
261
+ const result = await doSomething();
262
+ return {
263
+ ...result,
264
+ };
265
+ },
266
+ },
267
+ },
268
+ });
269
+ ```
270
+
271
+ ## Build Process Flow
272
+
273
+ 1. **Config Validation**
274
+ - Validates user configuration using `validateConfig`
275
+ - Ensures configuration schema compliance
276
+ - Early error detection and user feedback
277
+
278
+ 2. **Dependencies Check**
279
+ - Verifies required dependencies are installed
280
+ - Validates build environment requirements
281
+
282
+ 3. **Preset Resolution** (`@modules/preset`)
283
+ - Resolves preset from string name or custom module
284
+ - Loads built-in presets from @aziontech/presets
285
+ - Validates preset interface and metadata
286
+
287
+ 4. **Build Config Setup** (`@modules/config`)
288
+ - Resolves configuration priorities in the following order:
289
+ 1. CLI arguments (highest priority)
290
+ 2. User config file (`azion.config.js`)
291
+ 3. Preset defaults (lowest priority)
292
+ - Sets up bundler configuration
293
+ - Configures build options and extensions
294
+
295
+ 5. **Prebuild Phase** (`@modules/prebuild`)
296
+ - Executes preset's prebuild hooks
297
+ - Prepares build environment and dependencies
298
+ - Framework-specific build preparations
299
+
300
+ 6. **Handler Resolution** (`@modules/handler`)
301
+ - Resolves entry point/handler from CLI args, preset, or user config
302
+ - Validates file existence and accessibility
303
+ - Supports multiple entry points
304
+
305
+ 7. **Worker Setup** (`@modules/worker`)
306
+ - Processes handler files and converts to worker-compatible format
307
+ - Detects handler patterns (ES Modules, Service Worker, Legacy)
308
+ - Generates appropriate wrappers for development/production
309
+ - Creates temporary worker files for bundling
310
+
311
+ 8. **Core Build** (`@modules/core`)
312
+ - Processes bundler configuration (esbuild/webpack)
313
+ - Handles file imports and dependencies
314
+ - Applies polyfills and transformations
315
+ - Generates optimized output
316
+
317
+ 9. **Cleanup**
318
+ - Removes temporary files created during build
319
+ - Cleans up intermediate build artifacts
320
+
321
+ 10. **Postbuild Phase** (`@modules/postbuild`)
322
+ - Executes preset's postbuild hooks
323
+ - Post-processing optimizations
324
+ - Asset finalization
325
+
326
+ 11. **Bindings Setup** (`@modules/bindings`) [Future]
327
+ - Configures Azion platform bindings
328
+ - Sets up edge functions connections
329
+ - _Currently in development_
330
+
331
+ 12. **Storage Setup** (`@modules/storage`) [Future]
332
+ - Configures edge storage connections
333
+ - Sets up data persistence layers
334
+ - _Currently in development_
335
+
336
+ 13. **Environment Setup** (`@modules/environment`)
337
+ - Creates initial `azion.config.js` from preset if none exists
338
+ - Merges configurations (user config takes precedence over preset defaults)
339
+ - Stores build settings locally for development and subsequent builds
340
+
341
+ 14. **Environment Variables**
342
+ - Copies and processes environment variables
343
+ - Sets up runtime environment context
344
+
345
+ ## Documentation
346
+
347
+ - [Handler Patterns](docs/handler-patterns.md)
348
+ - [Node.js APIs](docs/nodejs-apis.md)
349
+ - [Nextjs](docs/nextjs.md)
350
+ - [Rust/Wasm example](https://github.com/aziontech/bundler-examples/tree/main/examples/rust-wasm-yew-ssr/)
351
+ - [Emscripten/Wasm example](https://github.com/aziontech/bundler-examples/tree/main/examples/emscripten-wasm/)
352
+ - [Env vars example](https://github.com/aziontech/bundler-examples/tree/main/examples/javascript/simple-js-env-vars)
353
+ - [Storage example](https://github.com/aziontech/bundler-examples/tree/main/examples/javascript/simple-js-esm-storage)
354
+ - [Firewall example](https://github.com/aziontech/bundler-examples/tree/main/examples/javascript/simple-js-firewall-event)
355
+
356
+ ## Supported Features
357
+
358
+ E2E tests run daily in the [Bundler Examples](https://github.com/aziontech/bundler-examples/tree/main/examples) to ensure that the presets and frameworks continue to work correctly.
359
+
360
+ Table:
361
+ | Test | Status |
362
+ | ------------------------------------ | ------ |
363
+ | Next 14 2 15 Middleware | ⚠️ |
364
+ | Next 13 5 6 I18n | ⚠️ |
365
+ | Next 12 3 4 I18n | ⚠️ |
366
+ | Hexo Static | ⚠️ |
367
+ | Next 13 5 6 Middleware | ⚠️ |
368
+ | Next 12 3 4 Middleware | ⚠️ |
369
+ | Next Node Pages 12 3 1 | ⚠️ |
370
+ | Next 13 5 6 Config | ⚠️ |
371
+ | Next 12 3 4 Config | ⚠️ |
372
+ | Html | ⚠️ |
373
+ | Next Static | ⚠️ |
374
+ | Gatsby Static | ⚠️ |
375
+ | Next Node Pages 12 3 1 Fs | ⚠️ |
376
+ | Sveltekit Static | ⚠️ |
377
+ | Vue Vite Static | ⚠️ |
378
+ | Sveltekit Ssr | ⚠️ |
379
+ | Next 12 Static | ⚠️ |
380
+ | Hugo | ⚠️ |
381
+ | Astro Static | ⚠️ |
382
+ | Qwik Static | ⚠️ |
383
+ | Simple Js Env Vars | ⚠️ |
384
+ | Eleventy Static | ⚠️ |
385
+ | Opennext Ssr | ⚠️ |
386
+ | Simple Js Network List | ⚠️ |
387
+ | Angular Static | ⚠️ |
388
+ | React Static | ⚠️ |
389
+ | Svelte Static | ⚠️ |
390
+ | Stencil Static | ⚠️ |
391
+ | Vitepress Static | ⚠️ |
392
+ | Preact Static | ⚠️ |
393
+ | Vuepress Static | ⚠️ |
394
+ | Nuxt Static | ⚠️ |
395
+ | Docusaurus Static | ⚠️ |
396
+ | Simple Js Firewall Event | ⚠️ |
397
+ | Nuxt Ssr | ⚠️ |
398
+ | Simple Js Network List With Firewall | ⚠️ |
399
+ | Jekyll Static | ⚠️ |
400
+ | Simple Js Esm Worker | ⚠️ |
401
+ | Simple Js Esm Node | ⚠️ |
402
+ | Simple Ts Esm | ⚠️ |
403
+ | Simple Js Esm | ⚠️ |
404
+
405
+ Last test run date: 04/09/26 01:48:55 PM
406
+
407
+ ## Contributing
408
+
409
+ Check the [Contributing doc](CONTRIBUTING.md).
410
+
411
+ ## License
412
+
413
+ [MIT](LICENSE.md)