vovk 0.2.3-beta.32 → 0.2.3-beta.34

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.
@@ -13,41 +13,48 @@ function canRequire(moduleName) {
13
13
 
14
14
  /**
15
15
  * Generates client code with string concatenation so it should be much faster than using AST
16
- * TODO: Check modules for existence before compiling, use vovk-zod by default
16
+ * TODO: Check fetcher and streamFetcher for existence
17
17
  * @type {(rcPath: string) => Promise<void>}
18
18
  */
19
19
  async function generateClient(rcPath) {
20
20
  const vovkrc = getVovkrc(rcPath);
21
21
  const jsonPath = '../../.vovk.json';
22
- const fetcherPath = vovkrc.fetcher.startsWith('.')
23
- ? path.join(__dirname, '../../..', vovkrc.fetcher)
24
- : vovkrc.fetcher;
22
+ const localJsonPath = path.join('..', jsonPath);
23
+ const fetcherPath = vovkrc.fetcher.startsWith('.') ? path.join(__dirname, '../..', vovkrc.fetcher) : vovkrc.fetcher;
24
+ const localFetcherPath = vovkrc.fetcher.startsWith('.') ? path.join('..', fetcherPath) : fetcherPath;
25
25
  const streamFetcherPath = vovkrc.streamFetcher.startsWith('.')
26
- ? path.join(process.cwd(), vovkrc.streamFetcher)
26
+ ? path.join(__dirname, '../..', vovkrc.streamFetcher)
27
27
  : vovkrc.streamFetcher;
28
+ const localStreamFetcherPath = vovkrc.streamFetcher.startsWith('.')
29
+ ? path.join('..', streamFetcherPath)
30
+ : streamFetcherPath;
31
+ const validatePath = vovkrc.validateOnClient?.startsWith('.')
32
+ ? path.join(__dirname, '../..', vovkrc.validateOnClient)
33
+ : vovkrc.validateOnClient;
34
+ const localValidatePath = vovkrc.validateOnClient?.startsWith('.') ? path.join('..', validatePath) : validatePath;
28
35
 
29
36
  if (typeof vovkrc.validateOnClient === 'undefined') {
30
37
  vovkrc.validateOnClient = canRequire('vovk-zod/zodValidateOnClient') ? 'vovk-zod/zodValidateOnClient' : null;
31
- } else if (vovkrc.validateOnClient && !canRequire(vovkrc.validateOnClient)) {
38
+ } else if (vovkrc.validateOnClient && !canRequire(localValidatePath)) {
32
39
  throw new Error(
33
40
  `Unble to generate Vovk Client: cannot find "validateOnClient" module '${vovkrc.validateOnClient}'. Check your .vovkrc.js file`
34
41
  );
35
42
  }
36
43
 
37
- if (!canRequire(fetcherPath)) {
38
- throw new Error(
39
- `Unble to generate Vovk Client: cannot find "fetcher" module '${fetcherPath}'. Check your .vovkrc.js file`
40
- );
44
+ if (!canRequire(localJsonPath)) {
45
+ throw new Error(`Unble to generate Vovk Client: cannot find ".vovk.json" file '${jsonPath}'.`);
41
46
  }
42
47
 
43
- if (!canRequire(streamFetcherPath)) {
48
+ if (!canRequire(localFetcherPath)) {
44
49
  throw new Error(
45
- `Unble to generate Vovk Client: cannot find "streamFetcher" module '${streamFetcherPath}'. Check your .vovkrc.js file`
50
+ `Unble to generate Vovk Client: cannot find "fetcher" module '${vovkrc.fetcher}'. Check your .vovkrc.js file`
46
51
  );
47
52
  }
48
53
 
49
- if (!canRequire(jsonPath)) {
50
- throw new Error(`Unble to generate Vovk Client: cannot find ".vovk.json" file '${jsonPath}'.`);
54
+ if (!canRequire(localStreamFetcherPath)) {
55
+ throw new Error(
56
+ `Unble to generate Vovk Client: cannot find "streamFetcher" module '${vovkrc.streamFetcher}'. Check your .vovkrc.js file`
57
+ );
51
58
  }
52
59
 
53
60
  const controllersPath = path.join('../..', vovkrc.route).replace(/\.ts$/, '');
@@ -61,7 +68,7 @@ type Options = typeof fetcher extends VovkClientFetcher<infer U> ? U : never;
61
68
  `;
62
69
  let js = `const { clientizeController } = require('vovk/client');
63
70
  const { promisifyWorker } = require('vovk/worker');
64
- const metadata = require('${jsonPath}');
71
+ const metadata = require('${localJsonPath}');
65
72
  const { default: fetcher } = require('${fetcherPath}');
66
73
  const { default: streamFetcher } = require('${streamFetcherPath}');
67
74
  const prefix = '${vovkrc.prefix ?? '/api'}';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk",
3
- "version": "0.2.3-beta.32",
3
+ "version": "0.2.3-beta.34",
4
4
  "description": "Structural add-on for Next.js",
5
5
  "bin": "./cli/index.js",
6
6
  "scripts": {