edge-functions 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.
Files changed (230) hide show
  1. package/.babelrc +13 -0
  2. package/.eslintignore +3 -0
  3. package/.eslintrc.json +42 -0
  4. package/.github/workflows/major.yml +28 -0
  5. package/.github/workflows/minor.yml +31 -0
  6. package/.vscode/settings.json +20 -0
  7. package/CODEOWNERS +2 -0
  8. package/CODE_OF_CONDUCT.md +73 -0
  9. package/CONTRIBUTING.md +90 -0
  10. package/LICENSE.md +21 -0
  11. package/README.md +60 -0
  12. package/aliases.js +13 -0
  13. package/docs/overview.md +36 -0
  14. package/docs/presets.md +115 -0
  15. package/examples/angular-static/.editorconfig +16 -0
  16. package/examples/angular-static/README.md +27 -0
  17. package/examples/angular-static/angular.json +98 -0
  18. package/examples/angular-static/package.json +39 -0
  19. package/examples/angular-static/src/app/app-routing.module.ts +10 -0
  20. package/examples/angular-static/src/app/app.component.css +0 -0
  21. package/examples/angular-static/src/app/app.component.html +484 -0
  22. package/examples/angular-static/src/app/app.component.spec.ts +29 -0
  23. package/examples/angular-static/src/app/app.component.ts +10 -0
  24. package/examples/angular-static/src/app/app.module.ts +18 -0
  25. package/examples/angular-static/src/assets/.gitkeep +0 -0
  26. package/examples/angular-static/src/favicon.ico +0 -0
  27. package/examples/angular-static/src/index.html +13 -0
  28. package/examples/angular-static/src/main.ts +7 -0
  29. package/examples/angular-static/src/styles.css +1 -0
  30. package/examples/angular-static/tsconfig.app.json +14 -0
  31. package/examples/angular-static/tsconfig.json +33 -0
  32. package/examples/angular-static/tsconfig.spec.json +14 -0
  33. package/examples/astro-static/README.md +55 -0
  34. package/examples/astro-static/astro.config.mjs +5 -0
  35. package/examples/astro-static/package.json +15 -0
  36. package/examples/astro-static/public/favicon.svg +9 -0
  37. package/examples/astro-static/src/components/Card.astro +63 -0
  38. package/examples/astro-static/src/env.d.ts +1 -0
  39. package/examples/astro-static/src/layouts/Layout.astro +36 -0
  40. package/examples/astro-static/src/pages/edge/index.astro +55 -0
  41. package/examples/astro-static/src/pages/index.astro +81 -0
  42. package/examples/astro-static/tsconfig.json +3 -0
  43. package/examples/hexo-static/.github/dependabot.yml +7 -0
  44. package/examples/hexo-static/_config.landscape.yml +0 -0
  45. package/examples/hexo-static/_config.yml +105 -0
  46. package/examples/hexo-static/package.json +26 -0
  47. package/examples/hexo-static/scaffolds/draft.md +4 -0
  48. package/examples/hexo-static/scaffolds/page.md +4 -0
  49. package/examples/hexo-static/scaffolds/post.md +5 -0
  50. package/examples/hexo-static/source/_posts/hello-world.md +38 -0
  51. package/examples/hexo-static/source/_posts/other-page.md +62 -0
  52. package/examples/hexo-static/themes/.gitkeep +0 -0
  53. package/examples/hexo-static/yarn.lock +1625 -0
  54. package/examples/next-12-static/.babelrc +3 -0
  55. package/examples/next-12-static/README.md +21 -0
  56. package/examples/next-12-static/components/post.jsx +27 -0
  57. package/examples/next-12-static/package-lock.json +6191 -0
  58. package/examples/next-12-static/package.json +18 -0
  59. package/examples/next-12-static/pages/index.jsx +34 -0
  60. package/examples/next-12-static/pages/post/[id].jsx +63 -0
  61. package/examples/next-static/README.md +34 -0
  62. package/examples/next-static/jsconfig.json +7 -0
  63. package/examples/next-static/next.config.js +9 -0
  64. package/examples/next-static/package.json +16 -0
  65. package/examples/next-static/public/next.svg +1 -0
  66. package/examples/next-static/public/vercel.svg +1 -0
  67. package/examples/next-static/src/app/blog/[slug]/page.js +27 -0
  68. package/examples/next-static/src/app/favicon.ico +0 -0
  69. package/examples/next-static/src/app/globals.css +107 -0
  70. package/examples/next-static/src/app/layout.js +17 -0
  71. package/examples/next-static/src/app/misty-mountains/moria/page.js +15 -0
  72. package/examples/next-static/src/app/page.js +96 -0
  73. package/examples/next-static/src/app/page.module.css +229 -0
  74. package/examples/next-static/yarn.lock +199 -0
  75. package/examples/react-static/README.md +70 -0
  76. package/examples/react-static/package.json +38 -0
  77. package/examples/react-static/public/favicon.ico +0 -0
  78. package/examples/react-static/public/index.html +43 -0
  79. package/examples/react-static/public/logo192.png +0 -0
  80. package/examples/react-static/public/logo512.png +0 -0
  81. package/examples/react-static/public/manifest.json +25 -0
  82. package/examples/react-static/public/robots.txt +3 -0
  83. package/examples/react-static/src/App.css +38 -0
  84. package/examples/react-static/src/App.js +25 -0
  85. package/examples/react-static/src/App.test.js +8 -0
  86. package/examples/react-static/src/index.css +13 -0
  87. package/examples/react-static/src/index.js +17 -0
  88. package/examples/react-static/src/logo.svg +1 -0
  89. package/examples/react-static/src/reportWebVitals.js +13 -0
  90. package/examples/react-static/src/setupTests.js +5 -0
  91. package/examples/simple-js-esm/main.js +14 -0
  92. package/examples/simple-js-esm/messages.js +7 -0
  93. package/examples/simple-js-node/main.js +18 -0
  94. package/examples/vue-static/README.md +24 -0
  95. package/examples/vue-static/babel.config.js +5 -0
  96. package/examples/vue-static/jsconfig.json +19 -0
  97. package/examples/vue-static/package.json +45 -0
  98. package/examples/vue-static/public/favicon.ico +0 -0
  99. package/examples/vue-static/public/index.html +17 -0
  100. package/examples/vue-static/src/App.vue +16 -0
  101. package/examples/vue-static/src/assets/logo.png +0 -0
  102. package/examples/vue-static/src/components/HelloWorld.vue +58 -0
  103. package/examples/vue-static/src/main.js +28 -0
  104. package/examples/vue-static/src/views/Home.vue +14 -0
  105. package/examples/vue-static/vue.config.js +4 -0
  106. package/jest.config.js +6 -0
  107. package/jsconfig.json +40 -0
  108. package/jsdoc.json +52 -0
  109. package/lib/build/bundlers/index.js +4 -0
  110. package/lib/build/bundlers/webpack/index.js +40 -0
  111. package/lib/build/bundlers/webpack/webpack.config.js +38 -0
  112. package/lib/build/dispatcher/dispatcher.js +211 -0
  113. package/lib/build/dispatcher/dispatcher.test.js +0 -0
  114. package/lib/build/dispatcher/index.js +3 -0
  115. package/lib/build/polyfills/index.js +0 -0
  116. package/lib/constants/azion-edges.constants.js +98 -0
  117. package/lib/constants/index.js +5 -0
  118. package/lib/constants/messages/build.messages.js +23 -0
  119. package/lib/constants/messages/env.messages.js +38 -0
  120. package/lib/constants/messages/global.messages.js +19 -0
  121. package/lib/constants/messages/index.js +10 -0
  122. package/lib/constants/messages/platform.messages.js +84 -0
  123. package/lib/constants/runtime-apis.constants.js +118 -0
  124. package/lib/env/index.js +5 -0
  125. package/lib/env/runtime.env.js +69 -0
  126. package/lib/env/server.env.js +90 -0
  127. package/lib/env/vulcan.env.js +93 -0
  128. package/lib/main.js +260 -0
  129. package/lib/notations/namespaces.js +30 -0
  130. package/lib/notations/typedef.js +10 -0
  131. package/lib/platform/actions/application/createApplication.actions.js +33 -0
  132. package/lib/platform/actions/application/enableEdgeFunctions.actions.js +34 -0
  133. package/lib/platform/actions/application/instantiateFunction.actions.js +37 -0
  134. package/lib/platform/actions/application/setFunctionAsDefaultRule.actions.js +33 -0
  135. package/lib/platform/actions/core/auth.actions.js +67 -0
  136. package/lib/platform/actions/core/deploy.actions.js +73 -0
  137. package/lib/platform/actions/core/propagation.actions.js +75 -0
  138. package/lib/platform/actions/core/storage.actions.js +84 -0
  139. package/lib/platform/actions/domain/createDomain.actions.js +42 -0
  140. package/lib/platform/actions/function/createFunction.actions.js +79 -0
  141. package/lib/platform/actions/function/showFunctionLogs.actions.js +149 -0
  142. package/lib/platform/edgehooks/ErrorHTML/ErrorHTML.hooks.js +101 -0
  143. package/lib/platform/edgehooks/ErrorHTML/index.js +3 -0
  144. package/lib/platform/edgehooks/index.js +5 -0
  145. package/lib/platform/edgehooks/mountSPA/index.js +3 -0
  146. package/lib/platform/edgehooks/mountSPA/mountSPA.hooks.js +55 -0
  147. package/lib/platform/edgehooks/mountSPA/mountSPA.hooks.test.js +19 -0
  148. package/lib/platform/edgehooks/mountSSG/index.js +3 -0
  149. package/lib/platform/edgehooks/mountSSG/mountSSG.hooks.js +61 -0
  150. package/lib/platform/edgehooks/mountSSG/mountSSG.hooks.test.js +0 -0
  151. package/lib/platform/index.js +65 -0
  152. package/lib/platform/services/application.service.js +140 -0
  153. package/lib/platform/services/base.service.js +200 -0
  154. package/lib/platform/services/domain.service.js +80 -0
  155. package/lib/platform/services/events.service.js +65 -0
  156. package/lib/platform/services/function.service.js +105 -0
  157. package/lib/platform/services/index.js +8 -0
  158. package/lib/platform/services/storage.service.js +59 -0
  159. package/lib/platform/services/tokens.service.js +55 -0
  160. package/lib/presets/custom/angular/deliver/config.js +12 -0
  161. package/lib/presets/custom/angular/deliver/handler.js +8 -0
  162. package/lib/presets/custom/angular/deliver/prebuild.js +20 -0
  163. package/lib/presets/custom/astro/deliver/config.js +12 -0
  164. package/lib/presets/custom/astro/deliver/handler.js +8 -0
  165. package/lib/presets/custom/astro/deliver/prebuild.js +37 -0
  166. package/lib/presets/custom/hexo/deliver/config.js +12 -0
  167. package/lib/presets/custom/hexo/deliver/handler.js +8 -0
  168. package/lib/presets/custom/hexo/deliver/prebuild.js +37 -0
  169. package/lib/presets/custom/next/deliver/config.js +14 -0
  170. package/lib/presets/custom/next/deliver/handler.js +9 -0
  171. package/lib/presets/custom/next/deliver/prebuild.js +193 -0
  172. package/lib/presets/custom/react/deliver/config.js +12 -0
  173. package/lib/presets/custom/react/deliver/handler.js +8 -0
  174. package/lib/presets/custom/react/deliver/prebuild.js +16 -0
  175. package/lib/presets/custom/vue/deliver/config.js +12 -0
  176. package/lib/presets/custom/vue/deliver/handler.js +8 -0
  177. package/lib/presets/custom/vue/deliver/prebuild.js +20 -0
  178. package/lib/presets/default/html/deliver/config.js +13 -0
  179. package/lib/presets/default/html/deliver/handler.js +9 -0
  180. package/lib/presets/default/html/deliver/prebuild.js +15 -0
  181. package/lib/presets/default/javascript/compute/config.js +13 -0
  182. package/lib/presets/default/javascript/compute/handler.js +5 -0
  183. package/lib/presets/default/javascript/compute/prebuild.js +6 -0
  184. package/lib/presets/default/typescript/compute/config.js +0 -0
  185. package/lib/presets/default/typescript/compute/handler.js +0 -0
  186. package/lib/presets/default/typescript/compute/prebuild.js +0 -0
  187. package/lib/providers/azion/worker.js +12 -0
  188. package/lib/utils/copyDirectory/copyDirectory.utils.js +54 -0
  189. package/lib/utils/copyDirectory/copyDirectory.utils.test.js +43 -0
  190. package/lib/utils/copyDirectory/index.js +3 -0
  191. package/lib/utils/debug/debug.utils.js +36 -0
  192. package/lib/utils/debug/debug.utils.test.js +43 -0
  193. package/lib/utils/debug/index.js +3 -0
  194. package/lib/utils/exec/exec.utils.js +58 -0
  195. package/lib/utils/exec/exec.utils.test.js +84 -0
  196. package/lib/utils/exec/index.js +3 -0
  197. package/lib/utils/feedback/feedback.utils.js +81 -0
  198. package/lib/utils/feedback/feedback.utils.test.js +11 -0
  199. package/lib/utils/feedback/index.js +3 -0
  200. package/lib/utils/generateTimestamp/generateTimestamp.utils.js +25 -0
  201. package/lib/utils/generateTimestamp/generateTimestamp.utils.test.js +10 -0
  202. package/lib/utils/generateTimestamp/index.js +3 -0
  203. package/lib/utils/getAbsoluteLibDirPath/getAbsoluteLibDirPath.utils.js +21 -0
  204. package/lib/utils/getAbsoluteLibDirPath/getAbsoluteLibDirPath.utils.test.js +13 -0
  205. package/lib/utils/getAbsoluteLibDirPath/index.js +3 -0
  206. package/lib/utils/getPackageManager/getPackageManager.utils.js +118 -0
  207. package/lib/utils/getPackageManager/getPackageManager.utils.test.js +35 -0
  208. package/lib/utils/getPackageManager/index.js +3 -0
  209. package/lib/utils/getPackageVersion/getPackageVersion.utils.js +25 -0
  210. package/lib/utils/getPackageVersion/getPackageVersion.utils.test.js +48 -0
  211. package/lib/utils/getPackageVersion/index.js +3 -0
  212. package/lib/utils/getPresetsList/getPresetsList.utils.js +50 -0
  213. package/lib/utils/getPresetsList/getPresetsList.utils.test.js +19 -0
  214. package/lib/utils/getPresetsList/index.js +3 -0
  215. package/lib/utils/getProjectJsonFile/getProjectJsonFile.utils.js +21 -0
  216. package/lib/utils/getProjectJsonFile/getProjectJsonFile.utils.test.js +39 -0
  217. package/lib/utils/getProjectJsonFile/index.js +3 -0
  218. package/lib/utils/getVulcanBuildId/getVulcanBuildId.utils.js +49 -0
  219. package/lib/utils/getVulcanBuildId/getVulcanBuildId.utils.test.js +36 -0
  220. package/lib/utils/getVulcanBuildId/index.js +3 -0
  221. package/lib/utils/index.js +29 -0
  222. package/lib/utils/overrideStaticOutputPath/index.js +3 -0
  223. package/lib/utils/overrideStaticOutputPath/overrideStaticOutputPath.utils.js +47 -0
  224. package/lib/utils/overrideStaticOutputPath/overrideStaticOutputPath.utils.test.js +35 -0
  225. package/lib/utils/readWorkerFile/index.js +3 -0
  226. package/lib/utils/readWorkerFile/readWorkerFile.utils.js +36 -0
  227. package/lib/utils/readWorkerFile/readWorkerFile.utils.test.js +24 -0
  228. package/package.json +99 -0
  229. package/releaserc.json +87 -0
  230. package/tasks/sync-aliases.js +115 -0
@@ -0,0 +1,48 @@
1
+ import { writeFileSync } from 'fs';
2
+ import { tmpdir } from 'os';
3
+ import { join } from 'path';
4
+
5
+ import getPackageVersion from './index.js';
6
+
7
+ const FILE_NAME = 'package.json';
8
+ const CURRENT_DIR = process.cwd();
9
+ const TMP_DIR = tmpdir();
10
+ const FILE_PATH = join(TMP_DIR, FILE_NAME);
11
+
12
+ describe('getPackageVersion utils', () => {
13
+ beforeAll(() => {
14
+ writeFileSync(FILE_PATH, `
15
+ {
16
+ "dependencies": {
17
+ "next": "13.3.4"
18
+ }
19
+ }
20
+ `);
21
+
22
+ process.chdir(TMP_DIR);
23
+ });
24
+
25
+ afterAll(() => {
26
+ process.chdir(CURRENT_DIR);
27
+ });
28
+
29
+ test('Should get package version from user project.', async () => {
30
+ const expectedOutput = '13.3.4';
31
+
32
+ const version = getPackageVersion('next');
33
+
34
+ expect(version).toBe(expectedOutput);
35
+ });
36
+
37
+ test('Should throw an ERROR when package name is invalid', async () => {
38
+ const expectedOutput = 'Invalid package name!';
39
+
40
+ expect(() => getPackageVersion('')).toThrow(expectedOutput);
41
+ });
42
+
43
+ test('Should throw an ERROR when package is NOT found', async () => {
44
+ const expectedOutput = '\'other\' not detected in project dependencies!';
45
+
46
+ expect(() => getPackageVersion('other')).toThrow(expectedOutput);
47
+ });
48
+ });
@@ -0,0 +1,3 @@
1
+ import getPackageVersion from './getPackageVersion.utils.js';
2
+
3
+ export default getPackageVersion;
@@ -0,0 +1,50 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ /**
5
+ * Get the list of presets.
6
+ * @function
7
+ * @name getPresetsList
8
+ * @memberof utils
9
+ * @param {string[]} [types=['default', 'custom']] - The types of presets to list.
10
+ * Each type corresponds to a folder in the 'presets' directory.
11
+ * @returns {string[]} The list of presets with '(Static)' or '(Server)' suffixes when applicable.
12
+ * @example
13
+ * const presetsList = getPresetsList(['default', 'custom']);
14
+ * console.log(presetsList);
15
+ * // Output: ['Next (Static)', 'Next (Server)', 'Frodo (Nine Fingers)']
16
+ */
17
+ function getPresetsList(types = ['default', 'custom']) {
18
+ const currentModuleFullPath = import.meta.url;
19
+ let baselibPath = currentModuleFullPath.match(/(.*lib)(.*)/)[1];
20
+ baselibPath = baselibPath.replace('file://', '');
21
+
22
+ const presets = [];
23
+
24
+ types.forEach((type) => {
25
+ const presetsDir = path.join(baselibPath, `presets/${type}`);
26
+ const folders = fs.readdirSync(presetsDir, { withFileTypes: true })
27
+
28
+ .filter((dirent) => dirent.isDirectory())
29
+ .flatMap((dirent) => {
30
+ const presetName = dirent.name;
31
+ const subDirs = fs.readdirSync(path.join(presetsDir, presetName), { withFileTypes: true })
32
+ .filter((subDirent) => subDirent.isDirectory());
33
+
34
+ if (subDirs.length === 0) {
35
+ return [presetName.charAt(0).toUpperCase() + presetName.slice(1)];
36
+ }
37
+
38
+ return subDirs.map((subDir) => {
39
+ const subDirName = subDir.name.charAt(0).toUpperCase() + subDir.name.slice(1);
40
+ return `${presetName.charAt(0).toUpperCase() + presetName.slice(1)} (${subDirName})`;
41
+ });
42
+ });
43
+
44
+ presets.push(...folders);
45
+ });
46
+
47
+ return presets;
48
+ }
49
+
50
+ export default getPresetsList;
@@ -0,0 +1,19 @@
1
+ import getPresetsList from './index.js';
2
+
3
+ describe('getPresetsList utils', () => {
4
+ test('Should get the list of presets based on type', async () => {
5
+ const expectedOutput = [
6
+ 'Javascript (Compute)',
7
+ 'Typescript (Compute)',
8
+ 'Astro (Deliver)',
9
+ 'Hexo (Deliver)',
10
+ 'Next (Deliver)',
11
+ 'React (Deliver)',
12
+ 'Vue (Deliver)',
13
+ ];
14
+
15
+ const result = getPresetsList();
16
+
17
+ expect(result).toEqual(expectedOutput);
18
+ });
19
+ });
@@ -0,0 +1,3 @@
1
+ import getPresetsList from './getPresetsList.utils.js';
2
+
3
+ export default getPresetsList;
@@ -0,0 +1,21 @@
1
+ import { join } from 'path';
2
+ import { readFileSync } from 'fs';
3
+
4
+ /**
5
+ * Reads json file content
6
+ * @param {string} filePath - path to json file to be readed.
7
+ * @returns {object} - JSON object with file content.
8
+ */
9
+ function getProjectJsonFile(filePath) {
10
+ try {
11
+ const packageJsonPath = join(process.cwd(), filePath);
12
+ const packageJsonContent = readFileSync(packageJsonPath, 'utf8');
13
+ const packageJson = JSON.parse(packageJsonContent);
14
+
15
+ return packageJson;
16
+ } catch (error) {
17
+ throw Error(`Error getting '${filePath}' file: ${error}`);
18
+ }
19
+ }
20
+
21
+ export default getProjectJsonFile;
@@ -0,0 +1,39 @@
1
+ import { writeFileSync } from 'fs';
2
+ import { tmpdir } from 'os';
3
+ import { join } from 'path';
4
+
5
+ import getProjectJsonFile from './index.js';
6
+
7
+ const FILE_NAME = 'package.json';
8
+ const CURRENT_DIR = process.cwd();
9
+ const TMP_DIR = tmpdir();
10
+ const FILE_PATH = join(TMP_DIR, FILE_NAME);
11
+
12
+ describe('getProjectJsonFile utils', () => {
13
+ beforeAll(() => {
14
+ writeFileSync(FILE_PATH, `
15
+ {
16
+ "name": "next",
17
+ "version": "0.1.0"
18
+ }
19
+ `);
20
+
21
+ process.chdir(TMP_DIR);
22
+ });
23
+
24
+ afterAll(() => {
25
+ process.chdir(CURRENT_DIR);
26
+ });
27
+
28
+ test('Should read a json file content', async () => {
29
+ const expectedOutput = {
30
+ name: 'next',
31
+ version: '0.1.0',
32
+ };
33
+
34
+ const result = getProjectJsonFile(FILE_NAME);
35
+
36
+ expect(result.name).toBe(expectedOutput.name);
37
+ expect(result.version).toBe(expectedOutput.version);
38
+ });
39
+ });
@@ -0,0 +1,3 @@
1
+ import getProjectJsonFile from './getProjectJsonFile.utils.js';
2
+
3
+ export default getProjectJsonFile;
@@ -0,0 +1,49 @@
1
+ import { readFileSync, existsSync } from 'fs';
2
+ import { join } from 'path';
3
+
4
+ /**
5
+ * @namespace Utils
6
+ * @function
7
+ * @name getVulcanBuildId
8
+ * @description Fetches the unique build ID for the current project from the
9
+ * .env file in the .edge directory.
10
+ * The build ID is a unique identifier for a specific version of the project's
11
+ * code and is used to fetch the correct assets within the Edge Function.
12
+ * The .edge directory is assumed to be in the same directory where the Node.js
13
+ * process was started (process.cwd()).
14
+ * @returns {string|null} The build ID if found, or null if the .env file doesn'
15
+ * t exist or doesn't contain the VERSION_ID.
16
+ * @example
17
+ * // If the .edge/.env file contains "VERSION_ID=123",
18
+ * this will log "123"
19
+ * console.log(getVulcanBuildId());
20
+ * @example
21
+ * // If the .edge/.env file does not exist or does not contain "VERSION_ID=...",
22
+ * // this will log "null"
23
+ * console.log(getVulcanBuildId());
24
+ */
25
+ function getVulcanBuildId() {
26
+ // Define the path to the .env file
27
+ const envFilePath = join(process.cwd(), '.edge', '.env');
28
+
29
+ // Define the regular expression to match the build ID
30
+ const VERSION_ID_REGEX = /VERSION_ID=(\d+)/;
31
+
32
+ // If the .env file exists, read its contents
33
+ if (existsSync(envFilePath)) {
34
+ const envFileContent = readFileSync(envFilePath, 'utf8');
35
+
36
+ // Try to match the build ID in the file's contents
37
+ const buildIdMatch = envFileContent.match(VERSION_ID_REGEX);
38
+
39
+ // If a match is found, return the build ID (which is the second item in the match array)
40
+ if (buildIdMatch && buildIdMatch[1]) {
41
+ return buildIdMatch[1].trim();
42
+ }
43
+ }
44
+
45
+ // If the .env file doesn't exist or doesn't contain the VERSION_ID, return null
46
+ return null;
47
+ }
48
+
49
+ export default getVulcanBuildId;
@@ -0,0 +1,36 @@
1
+ import { writeFileSync, mkdirSync, rmSync } from 'fs';
2
+ import { tmpdir } from 'os';
3
+ import { join } from 'path';
4
+
5
+ import getVulcanBuildId from './index.js';
6
+
7
+ const FILE_NAME = '.env';
8
+ const FILE_DIR = '.edge';
9
+ const CURRENT_DIR = process.cwd();
10
+ const TMP_DIR = tmpdir();
11
+ const DIR_PATH = join(TMP_DIR, FILE_DIR);
12
+ const FILE_PATH = join(TMP_DIR, FILE_DIR, FILE_NAME);
13
+
14
+ describe('getVulcanBuildId utils', () => {
15
+ beforeAll(() => {
16
+ process.chdir(TMP_DIR);
17
+
18
+ mkdirSync(DIR_PATH);
19
+
20
+ writeFileSync(FILE_PATH, 'VERSION_ID=20230627142534');
21
+ });
22
+
23
+ afterAll(() => {
24
+ process.chdir(CURRENT_DIR);
25
+
26
+ rmSync(DIR_PATH, { recursive: true, force: true });
27
+ });
28
+
29
+ test('Should fetch the unique build ID for the current project', async () => {
30
+ const expectedOutput = '20230627142534';
31
+
32
+ const result = getVulcanBuildId();
33
+
34
+ expect(result).toBe(expectedOutput);
35
+ });
36
+ });
@@ -0,0 +1,3 @@
1
+ import getVulcanBuildId from './getVulcanBuildId.utils.js';
2
+
3
+ export default getVulcanBuildId;
@@ -0,0 +1,29 @@
1
+ import copyDirectory from './copyDirectory/index.js';
2
+ import debug from './debug/index.js';
3
+ import exec from './exec/index.js';
4
+ import feedback from './feedback/index.js';
5
+ import generateTimestamp from './generateTimestamp/index.js';
6
+ import getAbsoluteLibDirPath from './getAbsoluteLibDirPath/index.js';
7
+ import getVulcanBuildId from './getVulcanBuildId/index.js';
8
+ import getPackageManager from './getPackageManager/index.js';
9
+ import getPresetsList from './getPresetsList/index.js';
10
+ import readWorkerFile from './readWorkerFile/index.js';
11
+ import overrideStaticOutputPath from './overrideStaticOutputPath/index.js';
12
+ import getProjectJsonFile from './getProjectJsonFile/index.js';
13
+ import getPackageVersion from './getPackageVersion/index.js';
14
+
15
+ export {
16
+ copyDirectory,
17
+ debug,
18
+ exec,
19
+ feedback,
20
+ generateTimestamp,
21
+ getAbsoluteLibDirPath,
22
+ getPackageManager,
23
+ getPackageVersion,
24
+ getProjectJsonFile,
25
+ getVulcanBuildId,
26
+ getPresetsList,
27
+ overrideStaticOutputPath,
28
+ readWorkerFile,
29
+ };
@@ -0,0 +1,3 @@
1
+ import overrideStaticOutputPath from './overrideStaticOutputPath.utils.js';
2
+
3
+ export default overrideStaticOutputPath;
@@ -0,0 +1,47 @@
1
+ import { readFileSync, writeFileSync } from 'fs';
2
+
3
+ /**
4
+ * Overrides the output path for static files in a provided configuration file.
5
+ * @
6
+ * @function
7
+ * @name overrideStaticOutputPath
8
+ * @memberof utils
9
+ * @param {string} configFilePath - The path to the configuration file to be modified.
10
+ * @param {RegExp} regexPattern - The RegExp object to be used
11
+ * for matching within the configuration file.
12
+ * The regex pattern should include a capturing group (i.e., (.*) )
13
+ * to identify the value to be replaced.
14
+ * For example, /out:(.*)\n/.
15
+ * @param {string} [newOutputPath='.edge/statics'] - The default is '.edge/statics'.
16
+ * @throws Will throw an error if the function fails to override the output path.
17
+ * @example
18
+ *
19
+ * overrideStaticOutputPath('./config.js', /out:(.*)\n/);
20
+ */
21
+ function overrideStaticOutputPath(configFilePath, regexPattern, newOutputPath = '.edge/statics') {
22
+ try {
23
+ const fileContent = readFileSync(configFilePath, 'utf-8');
24
+
25
+ const pattern = new RegExp(regexPattern.source, `${regexPattern.flags}g`);
26
+ const attributeMatch = Array.from(fileContent.matchAll(pattern), (match) => match)[0];
27
+
28
+ // find last occurrence to replace
29
+ let newValue = attributeMatch[0];
30
+ const contentToReplace = attributeMatch[1].trim();
31
+ const lastIndex = newValue.lastIndexOf(contentToReplace);
32
+
33
+ // generate new value and replace old content with new one
34
+ if (lastIndex !== -1) {
35
+ newValue = newValue.substring(0, lastIndex) + newOutputPath
36
+ + newValue.substring(lastIndex, newValue.length).replace(contentToReplace, '');
37
+
38
+ const newContent = fileContent.replace(regexPattern, newValue);
39
+
40
+ writeFileSync(configFilePath, newContent);
41
+ }
42
+ } catch (error) {
43
+ throw Error(`Error overriding the output path: ${error}`);
44
+ }
45
+ }
46
+
47
+ export default overrideStaticOutputPath;
@@ -0,0 +1,35 @@
1
+ import { writeFileSync, readFileSync } from 'fs';
2
+ import { tmpdir } from 'os';
3
+ import { join } from 'path';
4
+
5
+ import overrideStaticOutputPath from './index.js';
6
+
7
+ const CONFIG_FILE_PATH = join(tmpdir(), 'config.json');
8
+
9
+ describe('overrideStaticOutputPath utils', () => {
10
+ beforeAll(() => {
11
+ writeFileSync(CONFIG_FILE_PATH, `
12
+ {
13
+ other: true,
14
+ publicOut: "./public",
15
+ another: "x"
16
+ }
17
+ `);
18
+ });
19
+
20
+ test('Should override the output path for static files in a provided configuration file.', async () => {
21
+ const expectedOutput = `
22
+ {
23
+ other: true,
24
+ publicOut: "./out",
25
+ another: "x"
26
+ }
27
+ `;
28
+
29
+ overrideStaticOutputPath(CONFIG_FILE_PATH, /publicOut:(.*),\n/, '"./out"');
30
+
31
+ const result = readFileSync(CONFIG_FILE_PATH, 'utf-8');
32
+
33
+ expect(result).toBe(expectedOutput);
34
+ });
35
+ });
@@ -0,0 +1,3 @@
1
+ import readWorkerFile from './readWorkerFile.utils.js';
2
+
3
+ export default readWorkerFile;
@@ -0,0 +1,36 @@
1
+ import fs from 'fs/promises';
2
+
3
+ /**
4
+ * Reads the content of a worker file.
5
+ * @async
6
+ * @function
7
+ * @name readWorkerFile
8
+ * @memberof utils
9
+ * @param {string} filePath - The path to the worker file.
10
+ * @returns {Promise<string>} A Promise that resolves to the content of the worker file.
11
+ * @throws {Error} Will throw an error if the file doesn't exist or there was an error reading it.
12
+ * @example
13
+ *
14
+ * // Example usage:
15
+ * readWorkerFile('./worker.js')
16
+ * .then(content => console.log(content)) // Logs: Content of worker.js
17
+ * .catch(err => console.error(err)); // Logs: Error message
18
+ */
19
+ async function readWorkerFile(filePath) {
20
+ try {
21
+ // Check if the file exists
22
+ await fs.access(filePath);
23
+
24
+ // If the file exists, read it and return its contents
25
+ const workerCode = await fs.readFile(filePath, 'utf8');
26
+ return workerCode;
27
+ } catch (error) {
28
+ // If the file does not exist or there was an error reading it, throw a detailed error
29
+ const errorMessage = error.code === 'ENOENT'
30
+ ? 'File does not exist.'
31
+ : `An error occurred while reading the ${filePath} file.`;
32
+ throw new Error(errorMessage);
33
+ }
34
+ }
35
+
36
+ export default readWorkerFile;
@@ -0,0 +1,24 @@
1
+ import fs from 'fs/promises';
2
+ import readWorkerFile from './index.js';
3
+
4
+ describe('readWorkerFile utils', () => {
5
+ test('Should read the content of a worker file.', async () => {
6
+ // Create a test file
7
+ const filePath = './testFile.js';
8
+ const testContent = 'console.log("Hello, World!");';
9
+
10
+ await fs.writeFile(filePath, testContent);
11
+
12
+ // Use readWorkerFile function to load code from the test file
13
+ const workerCode = await readWorkerFile(filePath);
14
+
15
+ // Expected content is the same as the content of the file created
16
+ const expectedContent = testContent;
17
+
18
+ // Assert that the workerCode is same as expectedContent
19
+ expect(workerCode).toBe(expectedContent);
20
+
21
+ // Cleanup: remove the test file
22
+ await fs.unlink(filePath);
23
+ });
24
+ });
package/package.json ADDED
@@ -0,0 +1,99 @@
1
+ {
2
+ "name": "edge-functions",
3
+ "type": "module",
4
+ "version": "1.0.0",
5
+ "description": "Tool to launch and build JavaScript/Frameworks. This tool automates polyfills for Edge Computing and assists in creating Workers, notably for the Azion platform.",
6
+ "main": "lib/main.js",
7
+ "bin": {
8
+ "vulcan": "lib/main.js",
9
+ "edge-functions": "lib/main.js",
10
+ "ef": "lib/main.js"
11
+ },
12
+ "release": {
13
+ "branches": [
14
+ "main",
15
+ "dev"
16
+ ]
17
+ },
18
+ "scripts": {
19
+ "start": "node lib/main.js",
20
+ "task:aliases": "node tasks/sync-aliases.js",
21
+ "task:docs": "jsdoc --configure jsdoc.json --verbose",
22
+ "test": "jest",
23
+ "test:watch": "jest --watch"
24
+ },
25
+ "author": "aziontech",
26
+ "contributors": [
27
+ {
28
+ "name": "Magnun A V F"
29
+ },
30
+ {
31
+ "name": "João Narciso",
32
+ "url": "https://jotanarciso.com"
33
+ }
34
+ ],
35
+ "license": "MIT",
36
+ "dependencies": {
37
+ "@semantic-release/changelog": "^6.0.3",
38
+ "@semantic-release/commit-analyzer": "^10.0.1",
39
+ "@semantic-release/git": "^10.0.1",
40
+ "@semantic-release/npm": "^10.0.4",
41
+ "@semantic-release/release-notes-generator": "^11.0.4",
42
+ "bottleneck": "^2.19.5",
43
+ "chokidar": "^3.5.3",
44
+ "commander": "^10.0.1",
45
+ "conventional-changelog-conventionalcommits": "^6.1.0",
46
+ "form-data": "^4.0.0",
47
+ "inquirer": "^9.2.7",
48
+ "install": "^0.13.0",
49
+ "lodash": "^4.17.21",
50
+ "log-update": "^5.0.1",
51
+ "mime-types": "^2.1.35",
52
+ "node-polyfill-webpack-plugin": "^2.0.1",
53
+ "npm": "^9.8.0",
54
+ "open": "^9.1.0",
55
+ "pkg-dir": "^7.0.0",
56
+ "semantic-release": "^21.0.7",
57
+ "semver": "^7.5.2",
58
+ "signale": "^1.4.0",
59
+ "vm2": "^3.9.19",
60
+ "webpack": "^5.84.0",
61
+ "webpack-merge": "^5.9.0"
62
+ },
63
+ "devDependencies": {
64
+ "@babel/core": "^7.22.5",
65
+ "@babel/preset-env": "^7.22.5",
66
+ "@jest/globals": "^29.5.0",
67
+ "babel-jest": "^29.5.0",
68
+ "babel-plugin-transform-import-meta": "^2.2.0",
69
+ "clean-jsdoc-theme": "^4.2.9",
70
+ "eslint": "^7.32.0 || ^8.2.0",
71
+ "eslint-config-airbnb-base": "^15.0.0",
72
+ "eslint-import-resolver-alias": "^1.1.2",
73
+ "eslint-plugin-import": "^2.25.2",
74
+ "eslint-plugin-jest": "^27.2.2",
75
+ "eslint-plugin-jsdoc": "^44.2.5",
76
+ "jest": "^29.5.0"
77
+ },
78
+ "imports": {
79
+ "#root/*": "./",
80
+ "#lib/*": "./lib",
81
+ "#utils": "./lib/utils/index.js",
82
+ "#polyfills": "./lib/build/polyfills/index.js",
83
+ "#build": "./lib/build/dispatcher/index.js",
84
+ "#bundlers": "./lib/build/bundlers/index.js",
85
+ "#notations/*": "./lib/notations",
86
+ "#env": "./lib/env/index.js",
87
+ "#platform": "./lib/platform/index.js",
88
+ "#constants": "./lib/constants/index.js",
89
+ "#edge": "./lib/platform/edgehooks/index.js"
90
+ },
91
+ "repository": {
92
+ "type": "git",
93
+ "url": "git+https://github.com/aziontech/vulcan.git"
94
+ },
95
+ "bugs": {
96
+ "url": "https://github.com/aziontech/vulcan/issues"
97
+ },
98
+ "homepage": "https://github.com/aziontech/vulcan#readme"
99
+ }
package/releaserc.json ADDED
@@ -0,0 +1,87 @@
1
+ {
2
+ "analyzeCommits": {
3
+ "preset": "conventionalcommits",
4
+ "parserOpts": {
5
+ "headerPattern": "^(\\[ISSUE-.*])?\\s?(\\w+):\\s(.*)$",
6
+ "headerCorrespondence": ["scope", "type", "subject"]
7
+ }
8
+ },
9
+ "generateNotes": {
10
+ "preset": "conventionalcommits",
11
+ "parserOpts": {
12
+ "headerPattern": "^(\\[ISSUE-.*])?\\s?(\\w+):\\s(.*)$",
13
+ "headerCorrespondence": ["scope", "type", "subject"]
14
+ },
15
+ "options": {
16
+ "preset": {
17
+ "name": "conventionalchangelog",
18
+ "issuePrefixes": ["ISSUE-"],
19
+ "issueUrlFormat": "https://github.com/aziontech/vulcan/issues/{id}"
20
+ }
21
+ }
22
+ },
23
+ "prepare": [
24
+ {
25
+ "path": "@semantic-release/npm",
26
+ "npmPublish": true
27
+ }
28
+ ],
29
+ "plugins": [
30
+ [
31
+ "@semantic-release/commit-analyzer",
32
+ {
33
+ "preset": "conventionalcommits",
34
+ "releaseRules": [
35
+ { "breaking": true, "release": "major" },
36
+ { "revert": true, "release": "patch" },
37
+ { "type": "feat", "release": "minor" },
38
+ { "type": "fix", "release": "minor" },
39
+ { "type": "chore", "release": "patch" },
40
+ { "type": "docs", "release": "patch" },
41
+ { "type": "style", "release": "patch" },
42
+ { "type": "refactor", "release": "patch" },
43
+ { "type": "test", "release": "patch" }
44
+ ]
45
+ }
46
+ ],
47
+ [
48
+ "@semantic-release/release-notes-generator",
49
+ {
50
+ "preset": "conventionalcommits",
51
+ "parserOpts": {
52
+ "headerPattern": "^(\\[ISSUE-.*])?\\s?(\\w+):\\s(.*)$",
53
+ "headerCorrespondence": ["scope", "type", "subject"]
54
+ },
55
+ "writerOpts": {
56
+ "commitsSort": ["subject", "scope"]
57
+ }
58
+ }
59
+ ],
60
+ [
61
+ "@semantic-release/changelog",
62
+ {
63
+ "changelogFile": "CHANGELOG.md",
64
+ "changelogTitle": "# Changelog"
65
+ }
66
+ ],
67
+ [
68
+ "@semantic-release/npm",
69
+ {
70
+ "npmPublish": true,
71
+ "pkgRoot": "./",
72
+ "tarballDir": "dist",
73
+ "tarballFile": "dist/package-${nextRelease.version}.tgz"
74
+ }
75
+ ],
76
+ [
77
+ "@semantic-release/git",
78
+ {
79
+ "assets": ["CHANGELOG.md", "package.json", "dist"],
80
+ "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
81
+ }
82
+ ]
83
+ ],
84
+ "preset": "conventionalcommits",
85
+ "increment": "minor",
86
+ "tagFormat": "${version}"
87
+ }