edge-functions 5.1.0 → 5.2.0-stage.10

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/README.md CHANGED
@@ -22,8 +22,9 @@ Azion Bundler is a powerful tool designed to build and adapt projects for edge c
22
22
  - [Commands](#commands)
23
23
  - [`build`](#build)
24
24
  - [`dev`](#dev)
25
- - [`store`](#store)
25
+ - [`config`](#config)
26
26
  - [`presets`](#presets)
27
+ - [`store`](#store)
27
28
  - [`manifest`](#manifest)
28
29
  - [Configuration](#configuration)
29
30
  - [Build Process Flow](#build-process-flow)
@@ -111,6 +112,9 @@ See some examples below:
111
112
 
112
113
  The Azion Bundler CLI provides several commands to help you manage your edge applications:
113
114
 
115
+ > ⚠️ \*Deprecation Notice:
116
+ > 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.
117
+
114
118
  ### `build`
115
119
  Builds your project for edge deployment.
116
120
 
@@ -118,11 +122,12 @@ Builds your project for edge deployment.
118
122
  ef build [options]
119
123
 
120
124
  Options:
121
- --entry <string> Code entrypoint (default: ./handler.js or ./handler.ts)
122
- --preset <type> Preset of build target (e.g., vue, next, javascript)
123
- --polyfills Use node polyfills in build (default: true)
124
- --worker Enable worker mode with addEventListener signature (default: false)
125
- --development Build in development mode (default: false)
125
+ -e, --entry <string> Code entrypoint (default: ./handler.js or ./handler.ts)
126
+ -p, --preset <type> Preset of build target (e.g., vue, next, javascript)
127
+ --polyfills Use node polyfills in build (default: true)
128
+ -w, --worker Enable worker mode with addEventListener signature (default: false)
129
+ -d, --dev Build in development mode (default: false)
130
+ -x, --experimental Enable experimental features (default: false)
126
131
  ```
127
132
 
128
133
  ### `dev`
@@ -132,39 +137,70 @@ Starts a local development environment.
132
137
  ef dev [entry] [options]
133
138
 
134
139
  Arguments:
135
- entry Specify the entry file (default: .edge/functions/handler.dev.js)
140
+ entry Specify the entry file (default: .edge/worker.dev.js)
136
141
 
137
142
  Options:
138
- -p, --port <port> Specify the port (default: "3333")
143
+ -p, --port <port> Specify the port (default: "3333")
144
+ -x, --experimental Enable experimental features (default: false)
139
145
  ```
140
146
 
141
- ### `store`
142
- Manages store configuration.
147
+ ### `config`
148
+ Manages Azion configuration settings with CRUD operations.
143
149
 
144
150
  ```shell
145
- ef store <command> [options]
151
+ ef config <command> [options]
146
152
 
147
153
  Commands:
148
- init Initialize store configuration
149
- destroy Remove store configuration
154
+ create Create a new configuration property
155
+ read Read configuration properties
156
+ update Update existing configuration properties
157
+ delete Delete configuration properties
150
158
 
151
159
  Options:
152
- --scope <scope> Project scope (default: "global")
153
- --preset <string> Preset name
154
- --entry <string> Code entrypoint
155
- --bundler <type> Bundler type (webpack/esbuild)
156
- --polyfills Use node polyfills in build
157
- --worker Enable worker mode
160
+ -k, --key <key> Property key (e.g., build.preset or edgeApplications[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
+ $ ef config create -k "build.preset" -v "typescript"
166
+ $ ef config read -k "edgeApplications[0].name"
167
+ $ ef config update -k "build.bundler" -v "esbuild"
168
+ $ ef config delete -k "build.polyfills"
169
+ $ ef config read --all
158
170
  ```
159
171
 
160
172
  ### `presets`
161
- Lists available project presets.
173
+ Manages presets for Azion projects.
162
174
 
163
175
  ```shell
164
- ef presets <command>
176
+ ef presets <command> [preset]
165
177
 
166
178
  Commands:
167
179
  ls List all available presets
180
+ config Get Azion configuration file for a specific preset
181
+
182
+ Arguments:
183
+ preset Preset name (required for config command)
184
+
185
+ Examples:
186
+ $ ef presets ls
187
+ $ ef presets config react
188
+ $ ef presets config next
189
+ ```
190
+
191
+ ### `store`
192
+ Manages store configuration.
193
+
194
+ ```shell
195
+ ef store <command> [options]
196
+
197
+ Commands:
198
+ init Initialize store configuration
199
+ destroy Remove store configuration
200
+
201
+ Options:
202
+ -c, --config <json> Configuration in JSON format
203
+ -s, --scope <scope> Scope of the store (default: global)
168
204
  ```
169
205
 
170
206
  ### `manifest`
@@ -178,13 +214,13 @@ Arguments:
178
214
  (default: "generate")
179
215
 
180
216
  Options:
181
- --entry <path> Path to the input file or configuration file
182
- --output <path> Output file/directory path
217
+ -e, --entry <path> Path to the input file or configuration file
218
+ -o, --output <path> Output file/directory path
183
219
 
184
220
  Examples:
185
- $ ef manifest transform --entry=manifest.json --output=azion.config.js
186
- $ ef manifest generate --entry=azion.config.js --output=.edge
187
- $ ef manifest --entry=azion.config.js --output=.edge
221
+ $ ef manifest transform -e manifest.json -o azion.config.js
222
+ $ ef manifest generate -e azion.config.js -o .edge
223
+ $ ef manifest -e azion.config.js -o .edge
188
224
  ```
189
225
 
190
226
  ## Configuration
@@ -1,37 +1,14 @@
1
- // lib/utils.ts
2
- import { readdirSync, unlinkSync } from "fs";
3
- import { join } from "path";
4
- function removeAzionTempFiles() {
5
- const directory = process.cwd();
6
- const tempFiles = readdirSync(directory).filter(
7
- (file) => file.startsWith("azion-") && (file.endsWith(".temp.js") || file.endsWith(".temp.ts"))
8
- );
9
- tempFiles.forEach((file) => {
10
- const filePath = join(directory, file);
11
- unlinkSync(filePath);
12
- });
13
- }
14
- var debug = {};
15
- Object.keys(console).forEach((method) => {
16
- if (typeof console[method] === "function") {
17
- debug[method] = (...args) => {
18
- if (process.env.DEBUG === "true") {
19
- console[method](...args);
20
- }
21
- };
22
- }
23
- });
24
-
25
1
  // lib/constants.ts
26
- import { join as join2, resolve } from "path";
2
+ import { join, resolve } from "path";
27
3
  import { readFileSync } from "fs";
28
4
  import { getAbsoluteDirPath } from "azion/utils/node";
29
5
  import { tmpdir } from "os";
30
6
  var DIRECTORIES = {
31
7
  OUTPUT_BASE_PATH: ".edge",
32
- OUTPUT_FUNCTIONS_PATH: join2(".edge", "functions"),
33
- OUTPUT_STORAGE_PATH: join2(".edge", "storage"),
34
- OUTPUT_MANIFEST_PATH: join2(".edge", "manifest.json")
8
+ OUTPUT_FUNCTIONS_PATH: join(".edge", "functions"),
9
+ OUTPUT_STORAGE_PATH: join(".edge", "storage"),
10
+ OUTPUT_MANIFEST_PATH: join(".edge", "manifest.json"),
11
+ OUTPUT_ENV_VARS_PATH: join(".edge", ".env")
35
12
  };
36
13
  var BUILD_CONFIG_DEFAULTS = {
37
14
  POLYFILLS: true,
@@ -58,7 +35,7 @@ var BUNDLER = {
58
35
  LIB_DIR: getAbsoluteDirPath(import.meta.url, "bundler"),
59
36
  ARGS_PATH: "azion/args.json",
60
37
  IS_DEBUG: process.env.DEBUG === "true",
61
- TEMP_DIR: (projectID) => join2(tmpdir(), ".azion", projectID),
38
+ TEMP_DIR: (projectID) => join(tmpdir(), ".azion", projectID),
62
39
  get ROOT_PATH() {
63
40
  return resolve(BUNDLER.LIB_DIR, ".");
64
41
  },
@@ -71,17 +48,60 @@ var BUNDLER = {
71
48
  };
72
49
  var DOCS_MESSAGE = `
73
50
 
74
- \u{1F4DA} Need help? Check out our documentation:
51
+ \u{1F4DA} Need help? Check out our documentation:
75
52
  - Azion CLI Documentation: https://www.azion.com/en/documentation/devtools/cli/build/
53
+ - Azion Library on Github: https://github.com/aziontech/lib/tree/main/packages/config/
76
54
  - Azion Bundler on GitHub: https://github.com/aziontech/bundler
77
55
  `;
78
56
 
57
+ // lib/utils.ts
58
+ import { readdirSync, unlinkSync } from "fs";
59
+ import { join as join2 } from "path";
60
+ import { readFile, writeFile, access } from "fs/promises";
61
+ import { constants } from "fs";
62
+ function removeAzionTempFiles() {
63
+ const directory = process.cwd();
64
+ const tempFiles = readdirSync(directory).filter(
65
+ (file) => file.startsWith("azion-") && (file.endsWith(".temp.js") || file.endsWith(".temp.ts"))
66
+ );
67
+ tempFiles.forEach((file) => {
68
+ const filePath = join2(directory, file);
69
+ unlinkSync(filePath);
70
+ });
71
+ }
72
+ var debug = {};
73
+ Object.keys(console).forEach((method) => {
74
+ if (typeof console[method] === "function") {
75
+ debug[method] = (...args) => {
76
+ if (process.env.DEBUG === "true") {
77
+ console[method](...args);
78
+ }
79
+ };
80
+ }
81
+ });
82
+ async function copyEnvVars() {
83
+ const cwd = process.cwd();
84
+ const envPath = join2(cwd, ".env");
85
+ const edgeEnvPath = DIRECTORIES.OUTPUT_ENV_VARS_PATH;
86
+ try {
87
+ const exists = await access(envPath, constants.F_OK).then(() => true).catch(() => false);
88
+ if (exists) {
89
+ const envContent = await readFile(envPath, "utf-8");
90
+ await writeFile(edgeEnvPath, envContent, "utf-8");
91
+ debug.info(`Environment file copied to ${edgeEnvPath}`);
92
+ }
93
+ } catch (error) {
94
+ debug.warn("No .env file found or error copying environment file");
95
+ }
96
+ }
97
+
79
98
  export {
80
- removeAzionTempFiles,
81
- debug,
82
99
  DIRECTORIES,
83
100
  BUILD_CONFIG_DEFAULTS,
84
101
  SUPPORTED_BUNDLERS,
85
102
  BUNDLER,
86
- DOCS_MESSAGE
103
+ DOCS_MESSAGE,
104
+ removeAzionTempFiles,
105
+ debug,
106
+ copyEnvVars
87
107
  };