edge-functions 2.7.1 → 2.7.2

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/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ### [2.7.2](https://github.com/aziontech/vulcan/compare/v2.7.1...v2.7.2) (2024-05-10)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * vite with typescript and react.js ([#326](https://github.com/aziontech/vulcan/issues/326)) ([7b8a235](https://github.com/aziontech/vulcan/commit/7b8a235ef3fbaf45b2035d99212ba42bf21fdb2d))
7
+
8
+ ### [2.7.2-stage.1](https://github.com/aziontech/vulcan/compare/v2.7.1...v2.7.2-stage.1) (2024-05-09)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * react with vite ([d1eb167](https://github.com/aziontech/vulcan/commit/d1eb1676df781eca28271da29a0fbdfe1e4676a3))
14
+ * react/vue with vite (preset) ([#325](https://github.com/aziontech/vulcan/issues/325)) ([976bb2e](https://github.com/aziontech/vulcan/commit/976bb2e23a8ccd5ffce5ffb85fb7ea812f4be5d6))
15
+ * vite/vue with ts ([5446750](https://github.com/aziontech/vulcan/commit/54467505644c34f60330e14074786ddda6169fea))
16
+
1
17
  ### [2.7.1](https://github.com/aziontech/vulcan/compare/v2.7.0...v2.7.1) (2024-05-08)
2
18
 
3
19
 
package/README.md CHANGED
@@ -40,7 +40,7 @@ Table:
40
40
  | Simple Js Esm | ✅ |
41
41
  | Simple Ts Esm | ✅ |
42
42
 
43
- Last test run date: 05/08/24 02:51:13 AM
43
+ Last test run date: 05/10/24 02:55:23 AM
44
44
  ## Quick Installation
45
45
 
46
46
  For those who just want to use Vulcan in their project without contributing to the development, you can install it directly from npm.
@@ -1,6 +1,15 @@
1
- import { exec, getPackageManager, generateManifest } from '#utils';
1
+ import {
2
+ exec,
3
+ getPackageManager,
4
+ generateManifest,
5
+ copyDirectory,
6
+ } from '#utils';
7
+ import { lstat, readFile, rm } from 'fs/promises';
8
+ import { join } from 'path';
2
9
 
3
10
  const packageManager = await getPackageManager();
11
+ const edgeStorageDir = '.edge/storage';
12
+ const defaultViteOutDir = 'dist';
4
13
 
5
14
  const manifest = {
6
15
  origin: [
@@ -39,15 +48,88 @@ const manifest = {
39
48
  },
40
49
  };
41
50
 
51
+ /**
52
+ * Check if the vite.config file exists.
53
+ * @returns {boolean} True if the file exists, false otherwise.
54
+ */
55
+ async function viteConfigExists() {
56
+ const files = ['./vite.config.js', './vite.config.ts'];
57
+ const checks = files.map(async (file) => {
58
+ try {
59
+ await lstat(file);
60
+ return true;
61
+ } catch (err) {
62
+ return false;
63
+ }
64
+ });
65
+
66
+ const results = await Promise.all(checks);
67
+ return results.includes(true);
68
+ }
69
+
70
+ /**
71
+ * Read vite.config build output
72
+ * @returns {object} The parsed configuration object or null if the file doesn't exist.
73
+ */
74
+ async function readViteBuildOutput() {
75
+ try {
76
+ const isTypescript = await lstat('./vite.config.ts').then(
77
+ () => true,
78
+ () => false,
79
+ );
80
+ const pathConfigFile = join(
81
+ process.cwd(),
82
+ isTypescript ? 'vite.config.ts' : 'vite.config.js',
83
+ );
84
+ const configFileContent = await readFile(pathConfigFile, 'utf-8');
85
+ const defineConfig = configFileContent.match(/defineConfig\(([\s\S]*)\)/);
86
+ if (!defineConfig) {
87
+ throw new Error('defineConfig not found');
88
+ }
89
+ const buildConfig = defineConfig[1].match(/build: *({[\s\S]*?}),/);
90
+ // eslint-disable-next-line no-eval
91
+ const buildConfigObject = eval(`(${buildConfig[1]})`);
92
+ return Promise.resolve({ build: buildConfigObject });
93
+ } catch (err) {
94
+ return null;
95
+ }
96
+ }
97
+
42
98
  /**
43
99
  * Runs custom prebuild actions
44
100
  */
45
101
  async function prebuild() {
46
- await exec(
47
- `BUILD_PATH="./.edge/storage" ${packageManager} run build`,
48
- 'React',
49
- true,
50
- );
102
+ const npmArgsForward = packageManager === 'npm' ? '--' : '';
103
+
104
+ let outDir = defaultViteOutDir;
105
+ const destPath = edgeStorageDir;
106
+
107
+ const isViteProject = await viteConfigExists();
108
+
109
+ if (isViteProject) {
110
+ await exec(
111
+ `${packageManager} run build ${npmArgsForward}`,
112
+ 'Vue/Vite',
113
+ true,
114
+ );
115
+
116
+ const config = await readViteBuildOutput();
117
+
118
+ if (config?.build?.outDir) {
119
+ outDir = config.build.outDir;
120
+ }
121
+
122
+ copyDirectory(outDir, destPath);
123
+ rm(outDir, { recursive: true, force: true });
124
+ }
125
+
126
+ if (!isViteProject) {
127
+ await exec(
128
+ `BUILD_PATH="./.edge/storage" ${packageManager} run build`,
129
+ 'React',
130
+ true,
131
+ );
132
+ }
51
133
  await generateManifest(manifest);
52
134
  }
53
135
 
@@ -5,6 +5,7 @@ import {
5
5
  generateManifest,
6
6
  } from '#utils';
7
7
  import { lstat, readFile, rm } from 'fs/promises';
8
+ import { join } from 'path';
8
9
 
9
10
  const packageManager = await getPackageManager();
10
11
  const edgeStorageDir = '.edge/storage';
@@ -48,31 +49,50 @@ const manifest = {
48
49
  };
49
50
 
50
51
  /**
51
- * Check if the vite.config.js file exists.
52
+ * Check if the vite.config file exists.
52
53
  * @returns {boolean} True if the file exists, false otherwise.
53
54
  */
54
55
  async function viteConfigExists() {
55
- try {
56
- await lstat('./vite.config.js');
57
- return true;
58
- } catch (err) {
59
- return false;
60
- }
61
- }
56
+ const files = ['./vite.config.js', './vite.config.ts'];
57
+ const checks = files.map(async (file) => {
58
+ try {
59
+ await lstat(file);
60
+ return true;
61
+ } catch (err) {
62
+ return false;
63
+ }
64
+ });
62
65
 
66
+ const results = await Promise.all(checks);
67
+ return results.includes(true);
68
+ }
63
69
  /**
64
- * Read and parse the vite.config.js file.
70
+ * Read vite.config build output
65
71
  * @returns {object} The parsed configuration object or null if the file doesn't exist.
66
72
  */
67
- async function readViteConfig() {
73
+ async function readViteBuildOutput() {
68
74
  try {
69
- const configFileContent = await readFile('./vite.config.js', 'utf-8');
70
- return JSON.parse(configFileContent.replace(/^module.exports = /, ''));
75
+ const isTypescript = await lstat('./vite.config.ts').then(
76
+ () => true,
77
+ () => false,
78
+ );
79
+ const pathConfigFile = join(
80
+ process.cwd(),
81
+ isTypescript ? 'vite.config.ts' : 'vite.config.js',
82
+ );
83
+ const configFileContent = await readFile(pathConfigFile, 'utf-8');
84
+ const defineConfig = configFileContent.match(/defineConfig\(([\s\S]*)\)/);
85
+ if (!defineConfig) {
86
+ throw new Error('defineConfig not found');
87
+ }
88
+ const buildConfig = defineConfig[1].match(/build: *({[\s\S]*?}),/);
89
+ // eslint-disable-next-line no-eval
90
+ const buildConfigObject = eval(`(${buildConfig[1]})`);
91
+ return Promise.resolve({ build: buildConfigObject });
71
92
  } catch (err) {
72
93
  return null;
73
94
  }
74
95
  }
75
-
76
96
  /**
77
97
  * Runs custom prebuild actions.
78
98
  */
@@ -91,7 +111,7 @@ async function prebuild() {
91
111
  true,
92
112
  );
93
113
 
94
- const config = await readViteConfig();
114
+ const config = await readViteBuildOutput();
95
115
 
96
116
  if (config?.build?.outDir) {
97
117
  outDir = config.build.outDir;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "edge-functions",
3
3
  "type": "module",
4
- "version": "2.7.1",
4
+ "version": "2.7.2",
5
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
6
  "main": "lib/main.js",
7
7
  "bin": {