edge-functions 3.2.1 → 3.3.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.
Files changed (192) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +46 -48
  3. package/aliases.js +0 -1
  4. package/lib/build/bundlers/base.bundlers.js +2 -17
  5. package/lib/build/bundlers/esbuild/esbuild.bundlers.js +6 -7
  6. package/lib/build/bundlers/esbuild/esbuild.bundlers.test.js +6 -12
  7. package/lib/build/bundlers/polyfills/polyfills-manager.js +7 -1
  8. package/lib/build/bundlers/polyfills/polyfills-manager.test.js +1 -0
  9. package/lib/build/bundlers/webpack/webpack.bundlers.js +7 -8
  10. package/lib/build/bundlers/webpack/webpack.bundlers.test.js +6 -12
  11. package/lib/build/dispatcher/dispatcher.js +53 -128
  12. package/lib/build/dispatcher/dispatcher.test.js +5 -6
  13. package/lib/build/dispatcher/helpers/helpers.js +0 -62
  14. package/lib/commands/build.commands.js +28 -44
  15. package/lib/commands/init.commands.js +6 -8
  16. package/lib/commands/presets.commands.js +6 -28
  17. package/lib/constants/index.js +1 -2
  18. package/lib/constants/messages/build.messages.js +7 -7
  19. package/lib/env/env.test.js +138 -105
  20. package/lib/env/polyfills/azion/storage/context/storage.context.js +1 -1
  21. package/lib/env/server.env.js +4 -4
  22. package/lib/env/vulcan.env.js +153 -27
  23. package/lib/main.js +54 -17
  24. package/lib/presets/{eleventy/deliver → angular}/config.js +1 -1
  25. package/lib/presets/{vue/deliver → angular}/handler.js +3 -3
  26. package/lib/presets/angular/{deliver/prebuild.js → prebuild.js} +1 -15
  27. package/lib/presets/{docusaurus/deliver → astro}/config.js +1 -1
  28. package/lib/presets/astro/handler.js +17 -0
  29. package/lib/presets/{angular/deliver → docusaurus}/config.js +1 -1
  30. package/lib/presets/docusaurus/handler.js +17 -0
  31. package/lib/presets/{astro/deliver → eleventy}/config.js +1 -1
  32. package/lib/presets/eleventy/handler.js +17 -0
  33. package/lib/presets/emscripten/{compute/config.js → config.js} +1 -1
  34. package/lib/presets/emscripten/{compute/handler.js → handler.js} +2 -2
  35. package/lib/presets/emscripten/{compute/prebuild.js → prebuild.js} +1 -1
  36. package/lib/presets/gatsby/config.js +10 -0
  37. package/lib/presets/gatsby/handler.js +17 -0
  38. package/lib/presets/hexo/config.js +10 -0
  39. package/lib/presets/hexo/handler.js +17 -0
  40. package/lib/presets/html/config.js +10 -0
  41. package/lib/presets/html/handler.js +17 -0
  42. package/lib/presets/hugo/config.js +10 -0
  43. package/lib/presets/hugo/handler.js +17 -0
  44. package/lib/presets/javascript/{compute/config.js → config.js} +1 -1
  45. package/lib/presets/javascript/{compute/handler.js → handler.js} +2 -3
  46. package/lib/presets/jekyll/config.js +10 -0
  47. package/lib/presets/jekyll/handler.js +17 -0
  48. package/lib/presets/next/{compute/config.js → config.js} +1 -1
  49. package/lib/presets/next/{compute/default → default}/prebuild/index.js +2 -2
  50. package/lib/presets/next/{compute/default → default}/prebuild/mapping/index.js +2 -2
  51. package/lib/presets/next/{compute/handler.js → handler.js} +13 -5
  52. package/lib/presets/next/{compute/node → node}/custom-server/12.3.x/server/config.js +1 -1
  53. package/lib/presets/next/{compute/node → node}/handler/index.js +2 -2
  54. package/lib/presets/next/{compute/node → node}/prebuild/index.js +0 -1
  55. package/lib/presets/next/{compute/prebuild.js → prebuild.js} +20 -1
  56. package/lib/presets/next/static/handler.js +17 -0
  57. package/lib/presets/next/{deliver → static}/prebuild.js +6 -0
  58. package/lib/presets/react/config.js +10 -0
  59. package/lib/presets/{angular/deliver → react}/handler.js +3 -4
  60. package/lib/presets/rustwasm/{compute/config.js → config.js} +1 -1
  61. package/lib/presets/rustwasm/{compute/handler.js → handler.js} +1 -1
  62. package/lib/presets/svelte/config.js +10 -0
  63. package/lib/presets/svelte/handler.js +17 -0
  64. package/lib/presets/typescript/{compute/config.js → config.js} +1 -1
  65. package/lib/presets/typescript/{compute/handler.js → handler.js} +1 -2
  66. package/lib/presets/vitepress/config.js +10 -0
  67. package/lib/presets/vitepress/handler.js +17 -0
  68. package/lib/presets/vue/config.js +10 -0
  69. package/lib/presets/{react/deliver → vue}/handler.js +4 -4
  70. package/lib/utils/exec/exec.utils.js +2 -2
  71. package/lib/utils/feedback/feedback.utils.js +17 -13
  72. package/lib/utils/generateManifest/generateManifest.utils.js +3 -61
  73. package/lib/utils/presets/presets.utils.js +8 -30
  74. package/lib/utils/presets/presets.utils.test.js +9 -83
  75. package/package.json +7 -7
  76. package/lib/constants/azion-edges.constants.js +0 -98
  77. package/lib/env/edgehooks/ErrorHTML/ErrorHTML.hooks.js +0 -104
  78. package/lib/env/edgehooks/ErrorHTML/index.js +0 -3
  79. package/lib/env/edgehooks/debugRequest/debugRequest.hooks.js +0 -28
  80. package/lib/env/edgehooks/debugRequest/index.js +0 -3
  81. package/lib/env/edgehooks/index.js +0 -6
  82. package/lib/env/edgehooks/mountSPA/index.js +0 -3
  83. package/lib/env/edgehooks/mountSPA/mountSPA.hooks.js +0 -56
  84. package/lib/env/edgehooks/mountSPA/mountSPA.hooks.test.js +0 -36
  85. package/lib/env/edgehooks/mountSSG/index.js +0 -3
  86. package/lib/env/edgehooks/mountSSG/mountSSG.hooks.js +0 -64
  87. package/lib/env/edgehooks/mountSSG/mountSSG.hooks.test.js +0 -36
  88. package/lib/presets/astro/deliver/handler.js +0 -16
  89. package/lib/presets/docusaurus/deliver/handler.js +0 -16
  90. package/lib/presets/eleventy/deliver/handler.js +0 -16
  91. package/lib/presets/gatsby/deliver/config.js +0 -10
  92. package/lib/presets/gatsby/deliver/handler.js +0 -16
  93. package/lib/presets/hexo/deliver/config.js +0 -10
  94. package/lib/presets/hexo/deliver/handler.js +0 -16
  95. package/lib/presets/html/deliver/config.js +0 -10
  96. package/lib/presets/html/deliver/handler.js +0 -17
  97. package/lib/presets/hugo/deliver/config.js +0 -10
  98. package/lib/presets/hugo/deliver/handler.js +0 -16
  99. package/lib/presets/jekyll/deliver/config.js +0 -10
  100. package/lib/presets/jekyll/deliver/handler.js +0 -16
  101. package/lib/presets/next/deliver/config.js +0 -10
  102. package/lib/presets/next/deliver/handler.js +0 -17
  103. package/lib/presets/react/deliver/config.js +0 -10
  104. package/lib/presets/svelte/deliver/config.js +0 -10
  105. package/lib/presets/svelte/deliver/handler.js +0 -16
  106. package/lib/presets/vitepress/deliver/azion.config.js +0 -50
  107. package/lib/presets/vitepress/deliver/config.js +0 -10
  108. package/lib/presets/vitepress/deliver/handler.js +0 -16
  109. package/lib/presets/vue/deliver/config.js +0 -10
  110. package/lib/utils/generateManifest/generateManifest.utils.test.js +0 -2225
  111. package/lib/utils/generateManifest/helpers/azion.config.example.js +0 -322
  112. package/lib/utils/generateManifest/helpers/behaviors.js +0 -216
  113. package/lib/utils/generateManifest/helpers/convertLegacyConfig.js +0 -72
  114. package/lib/utils/generateManifest/helpers/schema.js +0 -863
  115. package/lib/utils/generateManifest/strategy/implementations/cacheManifestStrategy.js +0 -90
  116. package/lib/utils/generateManifest/strategy/implementations/domainManifestStrategy.js +0 -64
  117. package/lib/utils/generateManifest/strategy/implementations/originManifestStrategy.js +0 -97
  118. package/lib/utils/generateManifest/strategy/implementations/purgeManifestStrategy.js +0 -53
  119. package/lib/utils/generateManifest/strategy/implementations/rulesManifestStrategy.js +0 -106
  120. package/lib/utils/generateManifest/strategy/manifestContext.js +0 -35
  121. package/lib/utils/generateManifest/strategy/manifestStrategy.js +0 -20
  122. /package/lib/presets/angular/{deliver/azion.config.js → azion.config.js} +0 -0
  123. /package/lib/presets/astro/{deliver/azion.config.js → azion.config.js} +0 -0
  124. /package/lib/presets/astro/{deliver/prebuild.js → prebuild.js} +0 -0
  125. /package/lib/presets/docusaurus/{deliver/azion.config.js → azion.config.js} +0 -0
  126. /package/lib/presets/docusaurus/{deliver/prebuild.js → prebuild.js} +0 -0
  127. /package/lib/presets/eleventy/{deliver/azion.config.js → azion.config.js} +0 -0
  128. /package/lib/presets/eleventy/{deliver/prebuild.js → prebuild.js} +0 -0
  129. /package/lib/presets/emscripten/{compute/azion.config.js → azion.config.js} +0 -0
  130. /package/lib/presets/gatsby/{deliver/azion.config.js → azion.config.js} +0 -0
  131. /package/lib/presets/gatsby/{deliver/prebuild.js → prebuild.js} +0 -0
  132. /package/lib/presets/hexo/{deliver/azion.config.js → azion.config.js} +0 -0
  133. /package/lib/presets/hexo/{deliver/prebuild.js → prebuild.js} +0 -0
  134. /package/lib/presets/html/{deliver/azion.config.js → azion.config.js} +0 -0
  135. /package/lib/presets/html/{deliver/prebuild.js → prebuild.js} +0 -0
  136. /package/lib/presets/hugo/{deliver/azion.config.js → azion.config.js} +0 -0
  137. /package/lib/presets/hugo/{deliver/prebuild.js → prebuild.js} +0 -0
  138. /package/lib/presets/javascript/{compute/azion.config.js → azion.config.js} +0 -0
  139. /package/lib/presets/javascript/{compute/prebuild.js → prebuild.js} +0 -0
  140. /package/lib/presets/jekyll/{deliver/azion.config.js → azion.config.js} +0 -0
  141. /package/lib/presets/jekyll/{deliver/prebuild.js → prebuild.js} +0 -0
  142. /package/lib/presets/next/{compute/azion.config.js → azion.config.js} +0 -0
  143. /package/lib/presets/next/{compute/default → default}/handler/async-local-storage.js +0 -0
  144. /package/lib/presets/next/{compute/default → default}/handler/images.js +0 -0
  145. /package/lib/presets/next/{compute/default → default}/handler/routing/http.js +0 -0
  146. /package/lib/presets/next/{compute/default → default}/handler/routing/http.test.js +0 -0
  147. /package/lib/presets/next/{compute/default → default}/handler/routing/index.js +0 -0
  148. /package/lib/presets/next/{compute/default → default}/handler/routing/libs.js +0 -0
  149. /package/lib/presets/next/{compute/default → default}/handler/routing/matcher.js +0 -0
  150. /package/lib/presets/next/{compute/default → default}/handler/routing/matcher.test.js +0 -0
  151. /package/lib/presets/next/{compute/default → default}/handler/routing/pcre.js +0 -0
  152. /package/lib/presets/next/{compute/default → default}/handler/routing/pcre.test.js +0 -0
  153. /package/lib/presets/next/{compute/default → default}/handler/routing/routes-matcher.js +0 -0
  154. /package/lib/presets/next/{compute/default → default}/handler/routing/utils.js +0 -0
  155. /package/lib/presets/next/{compute/default → default}/handler/routing/utils.test.js +0 -0
  156. /package/lib/presets/next/{compute/default → default}/prebuild/edge/index.js +0 -0
  157. /package/lib/presets/next/{compute/default → default}/prebuild/mapping/assets.js +0 -0
  158. /package/lib/presets/next/{compute/default → default}/prebuild/mapping/assets.test.js +0 -0
  159. /package/lib/presets/next/{compute/default → default}/prebuild/mapping/index.test.js +0 -0
  160. /package/lib/presets/next/{compute/default → default}/prebuild/mapping/process-mapping.js +0 -0
  161. /package/lib/presets/next/{compute/default → default}/prebuild/mapping/process-mapping.test.js +0 -0
  162. /package/lib/presets/next/{compute/default → default}/prebuild/prerendered/index.js +0 -0
  163. /package/lib/presets/next/{compute/default → default}/prebuild/validation/support.js +0 -0
  164. /package/lib/presets/next/{compute/default → default}/prebuild/validation/support.test.js +0 -0
  165. /package/lib/presets/next/{compute/default → default}/prebuild/validation/supported-versions.js +0 -0
  166. /package/lib/presets/next/{compute/node → node}/custom-server/12.3.x/index.js +0 -0
  167. /package/lib/presets/next/{compute/node → node}/custom-server/12.3.x/server/base-http/compute-js.js +0 -0
  168. /package/lib/presets/next/{compute/node → node}/custom-server/12.3.x/server/compute-js.js +0 -0
  169. /package/lib/presets/next/{compute/node → node}/custom-server/12.3.x/server/load-components.js +0 -0
  170. /package/lib/presets/next/{compute/node → node}/custom-server/12.3.x/server/next-compute-js-server.js +0 -0
  171. /package/lib/presets/next/{compute/node → node}/custom-server/12.3.x/server/next.js +0 -0
  172. /package/lib/presets/next/{compute/node → node}/custom-server/12.3.x/server/require.js +0 -0
  173. /package/lib/presets/next/{compute/node → node}/custom-server/12.3.x/server/response-cache/index.js +0 -0
  174. /package/lib/presets/next/{compute/node → node}/custom-server/12.3.x/server/serve-static.js +0 -0
  175. /package/lib/presets/next/{compute/node → node}/custom-server/12.3.x/util/etag.js +0 -0
  176. /package/lib/presets/next/{compute/node → node}/prebuild/statics/index.js +0 -0
  177. /package/lib/presets/next/{compute/postbuild.js → postbuild.js} +0 -0
  178. /package/lib/presets/next/{compute/utils → utils}/fs.js +0 -0
  179. /package/lib/presets/next/{compute/utils → utils}/next.js +0 -0
  180. /package/lib/presets/next/{compute/utils → utils}/routing.js +0 -0
  181. /package/lib/presets/react/{deliver/azion.config.js → azion.config.js} +0 -0
  182. /package/lib/presets/react/{deliver/prebuild.js → prebuild.js} +0 -0
  183. /package/lib/presets/rustwasm/{compute/azion.config.js → azion.config.js} +0 -0
  184. /package/lib/presets/rustwasm/{compute/prebuild.js → prebuild.js} +0 -0
  185. /package/lib/presets/svelte/{deliver/azion.config.js → azion.config.js} +0 -0
  186. /package/lib/presets/svelte/{deliver/prebuild.js → prebuild.js} +0 -0
  187. /package/lib/presets/typescript/{compute/azion.config.js → azion.config.js} +0 -0
  188. /package/lib/presets/typescript/{compute/prebuild.js → prebuild.js} +0 -0
  189. /package/lib/presets/{next/deliver → vitepress}/azion.config.js +0 -0
  190. /package/lib/presets/vitepress/{deliver/prebuild.js → prebuild.js} +0 -0
  191. /package/lib/presets/vue/{deliver/azion.config.js → azion.config.js} +0 -0
  192. /package/lib/presets/vue/{deliver/prebuild.js → prebuild.js} +0 -0
@@ -1,5 +1,4 @@
1
1
  import RuntimeApis from './runtime-apis.constants.js';
2
- import AzionEdges from './azion-edges.constants.js';
3
2
  import Messages from './messages/index.js';
4
3
 
5
- export { AzionEdges, RuntimeApis, Messages };
4
+ export { RuntimeApis, Messages };
@@ -6,19 +6,19 @@ Build messages object.
6
6
  */
7
7
  const build = {
8
8
  success: {
9
- prebuild_succeeded: 'Prebuild succeeded!',
9
+ prebuild_succeeded: 'Preb-uild succeeded!',
10
10
  vulcan_build_succeeded: 'Build completed!',
11
- manifest_succeeded: 'Manifest generated successfully!',
11
+ manifest_succeeded: 'Azion Manifest generated successfully!',
12
12
  },
13
13
  info: {
14
14
  rebuilding: 'We are rebuilding with the new changes...',
15
- prebuild_starting: 'Starting prebuild...',
16
- vulcan_build_starting: 'Starting Vulcan build...',
15
+ prebuild_starting: 'Starting pre-build...',
16
+ vulcan_build_starting: 'Starting Azion build...',
17
17
  },
18
18
  error: {
19
- vulcan_build_failed: 'Vulcan build failed.',
19
+ vulcan_build_failed: 'Azion build failed.',
20
20
  invalid_preset:
21
- 'Invalid build preset. Run "vulcan preset ls" to view available presets.',
21
+ 'Invalid build preset. Run "azion preset ls" to view available presets.',
22
22
  invalid_preset_mode: (mode, preset) =>
23
23
  `Mode '${mode}' does not exists in preset '${preset}'. Try 'deliver' or 'compute'.`,
24
24
  prebuild_error_validation_support: (framework, version, runtimes) =>
@@ -47,7 +47,7 @@ const build = {
47
47
  },
48
48
  warning: {
49
49
  use_node_polyfill_mode_deliver:
50
- 'The use of useNodePolyfills is not available for this deliver mode preset.',
50
+ 'The use of polyfills is not available for this deliver mode preset.',
51
51
  },
52
52
  };
53
53
 
@@ -1,145 +1,178 @@
1
- import { afterEach, beforeEach, describe, expect } from '@jest/globals';
1
+ import { afterEach, beforeEach, describe, expect, it } from '@jest/globals';
2
2
  import mockFs from 'mock-fs';
3
3
  import fs from 'fs';
4
- import runtime from './runtime.env.js';
4
+ import path from 'path';
5
5
  import vulcanEnv from './vulcan.env.js';
6
6
 
7
- describe('runtime env', () => {
8
- it('Should instantiate a edge runtime', () => {
9
- const code = `
10
- addEventListener('fetch', event => {
11
- const { searchParams } = new URL(event.request.url)
12
- const url = searchParams.get('url')
13
- return event.respondWith(fetch(url))
14
- })`;
15
- const edgeRuntime = runtime(code);
16
-
17
- expect(edgeRuntime).toBeDefined();
18
- });
19
- });
7
+ jest.mock('prettier', () => ({
8
+ format: jest.fn().mockImplementation((content) => content),
9
+ }));
10
+
11
+ jest.mock('#utils', () => ({
12
+ feedback: {
13
+ error: jest.fn(),
14
+ },
15
+ debug: {
16
+ error: jest.fn(),
17
+ },
18
+ }));
19
+
20
+ jest.mock('#constants', () => ({
21
+ Messages: {
22
+ errors: {
23
+ folder_creation_failed: jest.fn(),
24
+ file_doesnt_exist: jest.fn(),
25
+ write_file_failed: jest.fn(),
26
+ },
27
+ },
28
+ }));
20
29
 
21
30
  describe('vulcan env', () => {
22
- const { env } = process;
31
+ const originalEnv = process.env;
32
+ const mockTempPath = '/mock/temp/path';
33
+
23
34
  beforeEach(() => {
24
35
  jest.resetModules();
25
- process.env = { HOME: '/home/user' };
26
- process.cwd = jest.fn(() => '/');
36
+ process.env = { ...originalEnv, HOME: '/home/user' };
37
+ process.cwd = jest.fn(() => '/project');
38
+ global.vulcan = {
39
+ tempPath: mockTempPath,
40
+ };
27
41
  });
28
42
 
29
43
  afterEach(() => {
30
- process.env = env;
44
+ process.env = originalEnv;
45
+ mockFs.restore();
31
46
  });
32
47
 
33
- it('Should create a vulcan env with global scope', async () => {
34
- mockFs({});
35
- await vulcanEnv.createVulcanEnv(
36
- { API_KEY: 'abc123', ANOTHER_KEY: 'xyz' },
37
- 'global',
38
- );
48
+ describe('createVulcanEnv', () => {
49
+ it('Should create a vulcan env with global scope', async () => {
50
+ mockFs({
51
+ [mockTempPath]: {},
52
+ });
53
+
54
+ await vulcanEnv.createVulcanEnv(
55
+ { API_KEY: 'abc123', ANOTHER_KEY: 'xyz' },
56
+ 'global',
57
+ );
39
58
 
40
- const vulcanEnvContent = fs.readFileSync(
41
- '/home/user/.azion/.vulcan',
42
- 'utf8',
43
- );
59
+ const vulcanEnvContent = fs.readFileSync(
60
+ path.join(mockTempPath, '.azion-bundler'),
61
+ 'utf8',
62
+ );
44
63
 
45
- expect(vulcanEnvContent.trim()).toEqual(
46
- `API_KEY=abc123
64
+ expect(vulcanEnvContent.trim()).toEqual(
65
+ `API_KEY=abc123
47
66
  ANOTHER_KEY=xyz`,
48
- );
49
- mockFs.restore();
50
- });
67
+ );
68
+ });
69
+
70
+ it('Should create a vulcan env with local scope', async () => {
71
+ mockFs({
72
+ '/project': {},
73
+ });
51
74
 
52
- it('Should create a vulcan env with default scope', async () => {
53
- mockFs({});
54
- await vulcanEnv.createVulcanEnv({ API_KEY: 'abc123', ANOTHER_KEY: 'xyz' });
75
+ await vulcanEnv.createVulcanEnv(
76
+ { API_KEY: 'abc123', ANOTHER_KEY: 'xyz' },
77
+ 'local',
78
+ );
55
79
 
56
- const vulcanEnvContent = fs.readFileSync(
57
- '/home/user/.azion/.vulcan',
58
- 'utf8',
59
- );
80
+ const vulcanEnvContent = fs.readFileSync(
81
+ '/project/.azion-bundler',
82
+ 'utf8',
83
+ );
60
84
 
61
- expect(vulcanEnvContent.trim()).toEqual(
62
- `API_KEY=abc123
85
+ expect(vulcanEnvContent.trim()).toEqual(
86
+ `API_KEY=abc123
63
87
  ANOTHER_KEY=xyz`,
64
- );
65
- mockFs.restore();
66
- });
88
+ );
89
+ });
67
90
 
68
- it('Should create a vulcan env with local scope', async () => {
69
- mockFs({});
70
- await vulcanEnv.createVulcanEnv(
71
- { API_KEY: 'abc123', ANOTHER_KEY: 'xyz' },
72
- 'local',
73
- );
91
+ it('Should update existing variables', async () => {
92
+ mockFs({
93
+ '/project/.azion-bundler': 'API_KEY=old_value\n',
94
+ });
95
+
96
+ await vulcanEnv.createVulcanEnv(
97
+ { API_KEY: 'new_value', NEW_KEY: 'new_key_value' },
98
+ 'local',
99
+ );
100
+
101
+ const vulcanEnvContent = fs.readFileSync(
102
+ '/project/.azion-bundler',
103
+ 'utf8',
104
+ );
105
+
106
+ expect(vulcanEnvContent.trim()).toEqual(
107
+ `API_KEY=new_value
108
+ NEW_KEY=new_key_value`,
109
+ );
110
+ });
111
+ });
74
112
 
75
- const vulcanEnvContent = fs.readFileSync('/.vulcan', 'utf8');
113
+ describe('readVulcanEnv', () => {
114
+ it('Should read a vulcan env with global scope', async () => {
115
+ mockFs({
116
+ [path.join(mockTempPath, '.azion-bundler')]: 'API_KEY=abc123',
117
+ });
76
118
 
77
- expect(vulcanEnvContent.trim()).toEqual(
78
- `API_KEY=abc123
79
- ANOTHER_KEY=xyz`,
80
- );
81
- mockFs.restore();
82
- });
119
+ const envContent = await vulcanEnv.readVulcanEnv('global');
83
120
 
84
- it('Should update a vulcan env with local scope', async () => {
85
- mockFs({
86
- '/.vulcan': `API_KEY=abc123`,
121
+ expect(envContent).toEqual({ API_KEY: 'abc123' });
87
122
  });
88
- await vulcanEnv.createVulcanEnv({ API_KEY: 'abc456' }, 'local');
89
123
 
90
- const vulcanEnvContent = fs.readFileSync('/.vulcan', 'utf8');
124
+ it('Should read a vulcan env with local scope', async () => {
125
+ mockFs({
126
+ '/project/.azion-bundler': 'API_KEY=abc123\nANOTHER_KEY=xyz',
127
+ });
91
128
 
92
- expect(vulcanEnvContent.trim()).toEqual(`API_KEY=abc456`);
93
- mockFs.restore();
94
- });
129
+ const envContent = await vulcanEnv.readVulcanEnv('local');
95
130
 
96
- it('Should read a vulcan env with default scope', async () => {
97
- mockFs({
98
- '/home/user/.azion/.vulcan': `API_KEY=abc123`,
131
+ expect(envContent).toEqual({ API_KEY: 'abc123', ANOTHER_KEY: 'xyz' });
99
132
  });
100
- const envContent = await vulcanEnv.readVulcanEnv();
101
133
 
102
- expect(envContent).toMatchObject({ API_KEY: 'abc123' });
103
- mockFs.restore();
104
- });
134
+ it('Should return null if file does not exist', async () => {
135
+ mockFs({});
105
136
 
106
- it('Should read a vulcan env with global scope', async () => {
107
- mockFs({
108
- '/home/user/.azion/.vulcan': `API_KEY=abc123`,
109
- });
110
- const envContent = await vulcanEnv.readVulcanEnv('global');
137
+ const envContent = await vulcanEnv.readVulcanEnv('local');
111
138
 
112
- expect(envContent).toMatchObject({ API_KEY: 'abc123' });
113
- mockFs.restore();
139
+ expect(envContent).toBeNull();
140
+ });
114
141
  });
115
142
 
116
- it('Should read a vulcan env with local scope', async () => {
117
- mockFs({
118
- '/.vulcan': `API_KEY=abc123`,
143
+ describe('loadAzionConfig', () => {
144
+ it('Should load an Azion config file', async () => {
145
+ const configContent = `
146
+ export default {
147
+ build: {
148
+ entry: './src/index.js',
149
+ output: './dist',
150
+ },
151
+ };
152
+ `;
153
+
154
+ mockFs({
155
+ '/project/azion.config.js': configContent,
156
+ });
157
+
158
+ const config = await vulcanEnv.loadAzionConfig(
159
+ '/project/azion.config.js',
160
+ );
161
+
162
+ expect(config).toEqual({
163
+ build: {
164
+ entry: './src/index.js',
165
+ output: './dist',
166
+ },
167
+ });
119
168
  });
120
- const envContent = await vulcanEnv.readVulcanEnv('local');
121
169
 
122
- expect(envContent).toMatchObject({ API_KEY: 'abc123' });
123
- mockFs.restore();
124
- });
170
+ it('Should return null if Azion config file does not exist', async () => {
171
+ mockFs({});
125
172
 
126
- it('Should read a vulcanconfig file', async () => {
127
- mockFs({
128
- '/vulcan.config.js': `module.exports = {
129
- memoryFS: {
130
- injectionDirs: ['.faststore/@generated/graphql'],
131
- removePathPrefix: '.faststore/',
132
- }
133
- };`,
173
+ const config = await vulcanEnv.loadAzionConfig();
174
+
175
+ expect(config).toBeNull();
134
176
  });
135
- const expectedContent = {
136
- memoryFS: {
137
- injectionDirs: ['.faststore/@generated/graphql'],
138
- removePathPrefix: '.faststore/',
139
- },
140
- };
141
- const vulcaConfigFileContent = await vulcanEnv.loadVulcanConfigFile();
142
- expect(vulcaConfigFileContent).toEqual(expectedContent);
143
- mockFs.restore();
144
177
  });
145
178
  });
@@ -102,7 +102,7 @@ class StorageContext {
102
102
  (entry) => entry.isFile() && !entry.name.includes(this.#metadataPrefix),
103
103
  )
104
104
  .map((file) => {
105
- const pathFile = file.path.split(pathBucketRoot)?.[1];
105
+ const pathFile = file.path?.split(pathBucketRoot)?.[1];
106
106
  const key = pathFile ? `${pathFile}/${file.name}` : file.name;
107
107
  return { key };
108
108
  });
@@ -89,7 +89,7 @@ async function initializeServer(port, workerCode) {
89
89
  * @param {boolean} isFirewall - (Experimental) Enable isFirewall for local environment.
90
90
  */
91
91
  async function buildToLocalServer(isFirewall) {
92
- const vulcanEnv = await vulcan.readVulcanEnv('local');
92
+ const vulcanEnv = await vulcan.readVulcanEnv('global');
93
93
 
94
94
  if (!vulcanEnv) {
95
95
  const msg = Messages.env.server.errors.run_build_command;
@@ -149,10 +149,10 @@ async function handleFileChange(path, workerPath, port, isFirewall) {
149
149
  if (isChangeHandlerRunning) return;
150
150
 
151
151
  if (
152
- path.startsWith('.vulcan') ||
153
- (path.startsWith('vulcan') && path.includes('.temp')) ||
152
+ path.startsWith('.azion-bundler') ||
153
+ (path.startsWith('azion') && path.includes('.temp')) ||
154
154
  path.startsWith('.edge') ||
155
- path.startsWith('node_modules/.cache') ||
155
+ path.startsWith('node_modules') ||
156
156
  path.startsWith('.vercel')
157
157
  ) {
158
158
  return;
@@ -3,6 +3,9 @@ import { Messages } from '#constants';
3
3
  import fs from 'fs';
4
4
  import fsPromises from 'fs/promises';
5
5
  import path from 'path';
6
+ import { transpileModule } from 'typescript';
7
+ import prettier from 'prettier';
8
+ import { createRequire } from 'module';
6
9
 
7
10
  /**
8
11
  * Creates or updates Vulcan environment variables.
@@ -19,7 +22,7 @@ async function createVulcanEnv(variables, scope = 'global') {
19
22
  let basePath;
20
23
  switch (scope) {
21
24
  case 'global':
22
- basePath = path.join(process.env.HOME, '.azion');
25
+ basePath = globalThis.vulcan.tempPath;
23
26
  break;
24
27
  case 'local':
25
28
  basePath = path.join(process.cwd());
@@ -28,7 +31,7 @@ async function createVulcanEnv(variables, scope = 'global') {
28
31
  basePath = scope;
29
32
  break;
30
33
  }
31
- const vulcanEnvPath = path.join(basePath, '.vulcan');
34
+ const vulcanEnvPath = path.join(basePath, '.azion-bundler');
32
35
 
33
36
  try {
34
37
  await fsPromises.mkdir(basePath, { recursive: true });
@@ -86,11 +89,11 @@ async function createVulcanEnv(variables, scope = 'global') {
86
89
  * .then(env => console.log(env))
87
90
  * .catch(error => console.error(error));
88
91
  */
89
- async function readVulcanEnv(scope = 'global') {
92
+ async function readVulcanEnv(scope = 'local') {
90
93
  let basePath;
91
94
  switch (scope) {
92
95
  case 'global':
93
- basePath = path.join(process.env.HOME, '.azion');
96
+ basePath = globalThis.vulcan.tempPath;
94
97
  break;
95
98
  case 'local':
96
99
  basePath = path.join(process.cwd());
@@ -99,7 +102,7 @@ async function readVulcanEnv(scope = 'global') {
99
102
  basePath = scope;
100
103
  break;
101
104
  }
102
- const vulcanEnvPath = path.join(basePath, '.vulcan');
105
+ const vulcanEnvPath = path.join(basePath, '.azion-bundler');
103
106
 
104
107
  try {
105
108
  await fsPromises.access(vulcanEnvPath);
@@ -121,37 +124,160 @@ async function readVulcanEnv(scope = 'global') {
121
124
  return null;
122
125
  }
123
126
  debug.error(error);
124
- feedback.error(Messages.errors.read_file_failed(vulcanEnvPath));
127
+ feedback.error(Messages.errors.file_doesnt_exist(vulcanEnvPath));
128
+ throw error;
129
+ }
130
+ }
131
+ /**
132
+ * Loads the azion.config file and returns the entire configuration object.
133
+ * @async
134
+ * @param {string} [configPath] - Optional path to the config file. If not provided, it will search in the current working directory.
135
+ * @returns {Promise<object|null>} A promise that resolves to the entire configuration from azion.config, or null if not found.
136
+ * @throws {Error} Throws an error if there are issues reading or parsing the configuration file.
137
+ */
138
+ async function loadAzionConfig(configPath) {
139
+ const require = createRequire(import.meta.url);
140
+ const extensions = ['.js', '.mjs', '.cjs', '.ts'];
141
+ const configName = 'azion.config';
142
+
143
+ if (!configPath) {
144
+ // eslint-disable-next-line no-restricted-syntax
145
+ for (const ext of extensions) {
146
+ const testPath = path.join(process.cwd(), `${configName}${ext}`);
147
+ if (fs.existsSync(testPath)) {
148
+ // eslint-disable-next-line no-param-reassign
149
+ configPath = testPath;
150
+ break;
151
+ }
152
+ }
153
+ }
154
+
155
+ if (!configPath || !fs.existsSync(configPath)) {
156
+ return null;
157
+ }
158
+
159
+ const extension = path.extname(configPath);
160
+ let configModule;
161
+
162
+ try {
163
+ switch (extension) {
164
+ case '.ts':
165
+ // eslint-disable-next-line no-case-declarations
166
+ const tsContent = await fsPromises.readFile(configPath, 'utf-8');
167
+ // eslint-disable-next-line no-case-declarations
168
+ const jsContent = transpileModule(tsContent, {
169
+ compilerOptions: {
170
+ module: 'commonjs',
171
+ target: 'es2020',
172
+ moduleResolution: 'node',
173
+ },
174
+ }).outputText;
175
+
176
+ // eslint-disable-next-line no-case-declarations
177
+ const tempJsPath = configPath.replace('.ts', '.temp.js');
178
+ await fsPromises.writeFile(tempJsPath, jsContent);
179
+
180
+ try {
181
+ // eslint-disable-next-line import/no-dynamic-require
182
+ configModule = require(tempJsPath);
183
+ } finally {
184
+ await fsPromises.unlink(tempJsPath);
185
+ }
186
+ break;
187
+ case '.mjs':
188
+ configModule = await import(configPath);
189
+ break;
190
+ case '.cjs':
191
+ case '.js':
192
+ try {
193
+ configModule = await import(configPath);
194
+ } catch (error) {
195
+ if (error.code === 'ERR_REQUIRE_ESM') {
196
+ throw error;
197
+ }
198
+ // eslint-disable-next-line import/no-dynamic-require
199
+ configModule = require(configPath);
200
+ }
201
+ break;
202
+ default:
203
+ throw new Error(`Unsupported file extension: ${extension}`);
204
+ }
205
+
206
+ return configModule.default || configModule;
207
+ } catch (error) {
208
+ debug.error(error);
209
+ feedback.error(Messages.errors.file_doesnt_exist(configPath));
125
210
  throw error;
126
211
  }
127
212
  }
128
213
 
129
214
  /**
130
- * Loads a custom Vulcan configuration file from the current working directory.
215
+ * Creates an Azion configuration file with the appropriate extension if it does not exist.
131
216
  * @async
132
- * @returns {Promise<object|null>} A promise that resolves to the custom Vulcan configuration module if it exists, or null otherwise.
133
- * @throws {Error} Throws an error if there are issues importing the configuration file.
134
- * @example
135
- * loadVulcanConfigFile()
136
- * .then(config => {
137
- * if (config) {
138
- * console.log('Custom configuration loaded:', config);
139
- * } else {
140
- * console.log('No custom configuration found.');
141
- * }
142
- * })
143
- * .catch(error => console.error('Failed to load custom configuration:', error));
217
+ * @param {boolean} useCommonJS - If true, uses the '.cjs' extension and CommonJS format; otherwise, uses '.mjs' for ES Modules.
218
+ * @param {object} module - The configuration object to be written to the file.
219
+ * @returns {Promise<void>}
144
220
  */
145
- async function loadVulcanConfigFile() {
146
- const buildConfigPath = path.join(process.cwd(), 'vulcan.config.js');
147
- let vulcanCustomConfig = null;
221
+ async function createAzionConfigFile(useCommonJS, module) {
222
+ const extension = useCommonJS ? '.cjs' : '.mjs';
223
+ const configPath = path.join(process.cwd(), `azion.config${extension}`);
224
+ const moduleExportStyle = useCommonJS ? 'module.exports =' : 'export default';
225
+
226
+ const replacer = (key, value) => {
227
+ if (typeof value === 'function') {
228
+ return `__FUNCTION_START__${value.toString()}__FUNCTION_END__`;
229
+ }
230
+ return value;
231
+ };
232
+
233
+ let jsonString = JSON.stringify(module, replacer, 2);
234
+
235
+ jsonString = jsonString.replace(
236
+ /"__FUNCTION_START__(.*?)__FUNCTION_END__"/g,
237
+ (match, p1) => {
238
+ return p1.replace(/\\n/g, ' ').replace(/\\'/g, "'");
239
+ },
240
+ );
241
+
242
+ const formattedContent = await prettier.format(
243
+ `${moduleExportStyle} ${jsonString};`,
244
+ {
245
+ parser: 'babel',
246
+ semi: false,
247
+ singleQuote: true,
248
+ trailingComma: 'none',
249
+ },
250
+ );
148
251
 
149
- if (fs.existsSync(buildConfigPath)) {
150
- const vulcanCustomConfigModule = await import(buildConfigPath);
151
- vulcanCustomConfig = vulcanCustomConfigModule.default || {};
252
+ if (!fs.existsSync(configPath)) {
253
+ await fsPromises.writeFile(configPath, formattedContent);
254
+ }
255
+ }
256
+
257
+ /**
258
+ * Gets the path of the existing Azion configuration file in the current working directory.
259
+ * @async
260
+ * @returns {Promise<string|null>} The path of the Azion configuration file if it exists, otherwise null.
261
+ */
262
+ async function getAzionConfigPath() {
263
+ const extensions = ['.js', '.mjs', '.cjs', '.ts'];
264
+ const configName = 'azion.config';
265
+
266
+ // eslint-disable-next-line no-restricted-syntax
267
+ for (const ext of extensions) {
268
+ const configPath = path.join(process.cwd(), `${configName}${ext}`);
269
+ if (fs.existsSync(configPath)) {
270
+ return configPath;
271
+ }
152
272
  }
153
273
 
154
- return vulcanCustomConfig;
274
+ return null;
155
275
  }
156
276
 
157
- export default { createVulcanEnv, readVulcanEnv, loadVulcanConfigFile };
277
+ export default {
278
+ createVulcanEnv,
279
+ readVulcanEnv,
280
+ loadAzionConfig,
281
+ createAzionConfigFile,
282
+ getAzionConfigPath,
283
+ };