vovk 0.2.3-beta.120 → 0.2.3-beta.122

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.
@@ -2,22 +2,7 @@
2
2
  import fs from 'fs/promises';
3
3
  import path from 'path';
4
4
  import getReturnPath from './lib/getReturnPath.mjs';
5
-
6
- /** @type {(moduleName: string) => Promise<boolean>} */
7
- async function canImport(moduleName) {
8
- try {
9
- if (moduleName.endsWith('.json')) {
10
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
11
- // @ts-ignore Ignore dynamic imports errors
12
- await import(moduleName, { assert: { type: 'json' } });
13
- } else {
14
- await import(moduleName);
15
- }
16
- return true; // The module exists and can be imported
17
- } catch (e) {
18
- return false; // The module does not exist or cannot be imported
19
- }
20
- }
5
+ import fileExists from './lib/fileExists.mjs';
21
6
 
22
7
  /**
23
8
  * Generates client code with string concatenation so it should be much faster than using AST
@@ -32,7 +17,7 @@ export default async function generateClient({ ...env }) {
32
17
  const fetcherPath = env.VOVK_FETCHER.startsWith('.') ? path.join(returnDir, env.VOVK_FETCHER) : env.VOVK_FETCHER;
33
18
 
34
19
  if (!env.VOVK_VALIDATE_ON_CLIENT) {
35
- env.VOVK_VALIDATE_ON_CLIENT = (await canImport('vovk-zod/zodValidateOnClient'))
20
+ env.VOVK_VALIDATE_ON_CLIENT = (await fileExists('vovk-zod/zodValidateOnClient'))
36
21
  ? 'vovk-zod/zodValidateOnClient'
37
22
  : '';
38
23
  }
@@ -41,13 +26,13 @@ export default async function generateClient({ ...env }) {
41
26
  : env.VOVK_VALIDATE_ON_CLIENT;
42
27
  const localValidatePath = env.VOVK_VALIDATE_ON_CLIENT.startsWith('.') ? path.join('..', validatePath) : validatePath;
43
28
 
44
- if (env.VOVK_VALIDATE_ON_CLIENT && !(await canImport(localValidatePath))) {
29
+ if (env.VOVK_VALIDATE_ON_CLIENT && !(await fileExists(localValidatePath))) {
45
30
  throw new Error(
46
31
  `Unble to generate Vovk Client: cannot find "validateOnClient" module '${env.VOVK_VALIDATE_ON_CLIENT}'. Check your vovk.config.js file`
47
32
  );
48
33
  }
49
34
 
50
- if (!(await canImport(localJsonPath))) {
35
+ if (!(await fileExists(localJsonPath))) {
51
36
  throw new Error(
52
37
  `Unble to generate Vovk Client: cannot find ".vovk.json" file '${localJsonPath}' (original value '${jsonPath}').`
53
38
  );
package/cli/getVars.mjs CHANGED
@@ -20,8 +20,9 @@ export default async function getVars(configPath, options = {}) {
20
20
  // make PORT available to the config file
21
21
  process.env.PORT = options.PORT || process.env.PORT || '3000';
22
22
  Object.assign(vovkConfig, await import(configPath));
23
+ console.info('🐺 Vovk config loaded from', configPath);
23
24
  } catch {
24
- // noop
25
+ console.info(`🐺 No vovk.config.js found at path '${configPath}', using defaults`);
25
26
  }
26
27
 
27
28
  vars = {
@@ -0,0 +1,11 @@
1
+ import fs from 'fs/promises';
2
+
3
+ /** @type {(moduleName: string) => Promise<boolean>} */
4
+ export default async function fileExists(filePath) {
5
+ try {
6
+ await fs.stat(filePath);
7
+ return true; // The file exists
8
+ } catch (e) {
9
+ return false; // The file does not exist
10
+ }
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk",
3
- "version": "0.2.3-beta.120",
3
+ "version": "0.2.3-beta.122",
4
4
  "description": "Structural add-on for Next.js",
5
5
  "bin": "./cli/index.mjs",
6
6
  "scripts": {