edge-functions 4.2.0 → 4.2.1-stage.1

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,10 @@
1
+ ### [4.2.1-stage.1](https://github.com/aziontech/bundler/compare/v4.2.0...v4.2.1-stage.1) (2024-10-23)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * removing the need to pass the preset flag when js ([#402](https://github.com/aziontech/bundler/issues/402)) ([3f3074c](https://github.com/aziontech/bundler/commit/3f3074cee0255c75daa5420356e2cb10c97725e7))
7
+
1
8
  ## [4.2.0](https://github.com/aziontech/bundler/compare/v4.1.0...v4.2.0) (2024-10-18)
2
9
 
3
10
 
@@ -1,5 +1,5 @@
1
1
  import { Commands } from '#namespaces';
2
- import { feedback } from '#utils';
2
+ import { checkingProjectTypeJS, feedback } from '#utils';
3
3
  import vulcan from '../env/vulcan.env.js';
4
4
 
5
5
  /**
@@ -54,7 +54,7 @@ function getPresetValue(
54
54
  * @param {object} options - Configuration options for the build command.
55
55
  * @param {string} [options.entry] - The entry point file for the build.
56
56
  * @param {string} [options.builder] - The name of the Bundler you want to use (Esbuild or Webpack)
57
- * @param {string} [options.preset] - Preset to be used (e.g., 'javascript', 'typescript').
57
+ * @param {string} [options.preset] - Preset to be used (e.g., 'javascript').
58
58
  * @param {boolean} [options.polyfills] - Whether to use Node.js polyfills.
59
59
  * @param {boolean} [options.worker] - This flag indicates that the constructed code inserts its own worker expression, such as addEventListener("fetch") or similar, without the need to inject a provider.
60
60
  * @param {boolean} [options.onlyManifest] - Skip build and process. just the manifest.
@@ -81,7 +81,7 @@ async function buildCommand(
81
81
  customConfigurationModule?.entry,
82
82
  entry,
83
83
  vulcanVariables?.entry,
84
- preset === 'typescript' ? './main.ts' : './main.js',
84
+ (await checkingProjectTypeJS()) ? './main.ts' : './main.js',
85
85
  ),
86
86
  builder: getConfigValue(
87
87
  customConfigurationModule?.builder,
@@ -126,9 +126,9 @@ async function buildCommand(
126
126
 
127
127
  // If no preset is provided, use the default preset.
128
128
  if (config.preset.name === '') {
129
- config.preset.name = 'javascript';
129
+ config.preset.name = await checkingProjectTypeJS();
130
130
  feedback.warn(
131
- 'No preset provided. Using the default preset: javascript. Or you can provide a preset using the --preset argument.',
131
+ `No preset provided. Using the default preset: ${config.preset.name}. Or you can provide a preset using the --preset argument.`,
132
132
  );
133
133
  }
134
134
 
package/lib/main.js CHANGED
@@ -167,7 +167,10 @@ function startVulcanProgram() {
167
167
  program
168
168
  .command('build')
169
169
  .description('Build a project for edge deployment')
170
- .option('--entry <string>', 'Code entrypoint (default: ./main.js)')
170
+ .option(
171
+ '--entry <string>',
172
+ 'Code entrypoint (default: ./main.js or ./main.ts)',
173
+ )
171
174
  .option(
172
175
  '--preset <type>',
173
176
  'Preset of build target (e.g., vue, next, javascript)',
@@ -0,0 +1,25 @@
1
+ import mockFs from 'mock-fs';
2
+ import checkingProjectTypeJS from './checkingProjectType.utils.js';
3
+
4
+ describe('checkingProjectType utils', () => {
5
+ describe('checkingProjectTypeJS', () => {
6
+ it('should return the correct project type typescript', async () => {
7
+ mockFs({
8
+ 'tsconfig.json': 'content',
9
+ 'file.ts': 'content',
10
+ });
11
+ const isTypeScript = await checkingProjectTypeJS();
12
+ expect(isTypeScript).toBe('typescript');
13
+ mockFs.restore();
14
+ });
15
+
16
+ it('should return the correct project type javascript', async () => {
17
+ mockFs({
18
+ 'file.js': 'content',
19
+ });
20
+ const isTypeScript = await checkingProjectTypeJS();
21
+ expect(isTypeScript).toBe('javascript');
22
+ mockFs.restore();
23
+ });
24
+ });
25
+ });
@@ -0,0 +1,27 @@
1
+ import { existsSync, readdirSync } from 'fs';
2
+ import { join, extname } from 'path';
3
+
4
+ /**
5
+ * Checks if the project is a TypeScript or JavaScript project.
6
+ * @param {string} currentDir - The current directory.
7
+ * @returns {Promise<string>} - A promise that resolves to the project type (javascript or typescript).
8
+ */
9
+ const checkingProjectTypeJS = async (currentDir = process.cwd()) => {
10
+ const tsConfigPath = join(currentDir, 'tsconfig.json');
11
+ const tsConfigExist = existsSync(tsConfigPath);
12
+ if (tsConfigExist) {
13
+ return 'typescript';
14
+ }
15
+
16
+ const files = readdirSync(currentDir);
17
+ const hasTypeScriptFiles = files.some((file) =>
18
+ ['.ts', '.tsx'].includes(extname(file)),
19
+ );
20
+ if (hasTypeScriptFiles) {
21
+ return 'typescript';
22
+ }
23
+
24
+ return 'javascript';
25
+ };
26
+
27
+ export default checkingProjectTypeJS;
@@ -0,0 +1,3 @@
1
+ import checkingProjectTypeJS from './checkingProjectType.utils.js';
2
+
3
+ export default checkingProjectTypeJS;
@@ -21,6 +21,7 @@ import injectFilesInMem from './injectFilesInMem/index.js';
21
21
  import helperHandlerCode from './helperHandlerCode/index.js';
22
22
  import generateManifest from './generateManifest/index.js';
23
23
  import copyFilesToFS from './copyFilesToFS/index.js';
24
+ import checkingProjectTypeJS from './checkingProjectType/index.js';
24
25
 
25
26
  export {
26
27
  copyDirectory,
@@ -46,4 +47,5 @@ export {
46
47
  helperHandlerCode,
47
48
  generateManifest,
48
49
  copyFilesToFS,
50
+ checkingProjectTypeJS,
49
51
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "edge-functions",
3
3
  "type": "module",
4
- "version": "4.2.0",
4
+ "version": "4.2.1-stage.1",
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": {