vovk-cli 0.0.1-beta.84 → 0.0.1-beta.86

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.
@@ -1,10 +1,10 @@
1
1
  import type { VovkSchema } from 'vovk';
2
- import { VovkReadmeConfig, VovkSamplesConfig, type VovkStrictConfig } from 'vovk/internal';
2
+ import { type VovkReadmeConfig, type VovkSamplesConfig, type VovkStrictConfig } from 'vovk/internal';
3
3
  import type { PackageJson } from 'type-fest';
4
+ import type { OpenAPIObject } from 'openapi3-ts/oas31';
4
5
  import type { ProjectInfo } from '../getProjectInfo/index.mjs';
5
6
  import type { ClientTemplateFile } from './getClientTemplateFiles.mjs';
6
7
  import type { Segment } from '../utils/locateSegments.mjs';
7
- import { OpenAPIObject } from 'openapi3-ts/oas31';
8
8
  export declare function normalizeOutTemplatePath(out: string, packageJson: PackageJson): string;
9
9
  export declare function writeOneClientFile({ cwd, projectInfo, clientTemplateFile, fullSchema, prettifyClient, segmentName, templateContent, matterResult: { data, content }, openAPIObject, package: packageJson, readme, samples, reExports, isEnsuringClient, outCwdRelativeDir, templateDef, locatedSegments, isNodeNextResolution, hasMixins, isVovkProject, vovkCliPackage, isBundle, origin, configKey, cliSchemaPath, projectConfig, }: {
10
10
  cwd: string;
@@ -1,14 +1,15 @@
1
- import fs from 'fs/promises';
1
+ import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
  import ejs from 'ejs';
4
4
  import _ from 'lodash';
5
- import { createCodeSamples, VovkSchemaIdEnum, } from 'vovk/internal';
6
5
  import * as YAML from 'yaml';
7
6
  import TOML from '@iarna/toml';
8
- import { prettify } from '../utils/prettify.mjs';
9
- import { ROOT_SEGMENT_FILE_NAME } from '../dev/writeOneSegmentSchemaFile.mjs';
7
+ import { createCodeSamples, VovkSchemaIdEnum, } from 'vovk/internal';
10
8
  import { compileJSONSchemaToTypeScriptType } from '../utils/compileJSONSchemaToTypeScriptType.mjs';
11
9
  import { getTemplateClientImports } from './getTemplateClientImports.mjs';
10
+ import { chalkHighlightThing } from '../utils/chalkHighlightThing.mjs';
11
+ import { ROOT_SEGMENT_FILE_NAME } from '../dev/writeOneSegmentSchemaFile.mjs';
12
+ import { prettify } from '../utils/prettify.mjs';
12
13
  export function normalizeOutTemplatePath(out, packageJson) {
13
14
  return out.replace('[package_name]', packageJson.name?.replace(/-/g, '_') ?? 'my_package_name');
14
15
  }
@@ -141,7 +142,7 @@ templateContent, matterResult: { data, content }, openAPIObject, package: packag
141
142
  : !existingContent ||
142
143
  existingContent.trim().split('\n').slice(1).join('\n') !== rendered.trim().split('\n').slice(1).join('\n');
143
144
  if (needsWriting) {
144
- log.debug(`Writing file: ${outPath} ${existingContent ? '(updated)' : '(new)'}`);
145
+ log.debug(`Writing file: ${chalkHighlightThing(outPath)} ${existingContent ? '(updated)' : '(new)'}`);
145
146
  await fs.mkdir(path.dirname(outPath), { recursive: true });
146
147
  await fs.writeFile(outPath, rendered, 'utf-8');
147
148
  }
@@ -15,12 +15,15 @@ export const BUNDLE_BUILD_TSDOWN = async ({ entry, outDir }) => {
15
15
  outDir,
16
16
  platform: 'neutral',
17
17
  outExtensions: () => ({ js: '.js', dts: '.d.ts' }),
18
+ outputOptions: {
19
+ inlineDynamicImports: true,
20
+ },
18
21
  inputOptions: {
19
22
  resolve: {
20
23
  mainFields: ['module', 'main'],
21
24
  },
22
25
  },
23
- noExternal: ['vovk', 'vovk/*', 'vovk-ajv', 'ajv/**', 'ajv-errors', 'ajv-formats/**'],
26
+ noExternal: ['!next/**'],
24
27
  });
25
28
  };
26
29
  export async function createConfig({ root, options: { validationLibrary, bundle, lang, dryRun }, }) {
@@ -59,13 +62,31 @@ export async function createConfig({ root, options: { validationLibrary, bundle,
59
62
  config.composedClient.fromTemplates = ['js', ...lang];
60
63
  }
61
64
  config.moduleTemplates = moduleTemplates;
62
- let configStr = await prettify(`// @ts-check
65
+ if (bundle) {
66
+ config.bundle ??= {};
67
+ config.bundle.outputConfig ??= {
68
+ imports: { validateOnClient: null },
69
+ package: {
70
+ type: 'module',
71
+ main: './index.js',
72
+ types: './index.d.ts',
73
+ exports: {
74
+ '.': {
75
+ default: './index.js',
76
+ types: './index.d.ts',
77
+ },
78
+ },
79
+ },
80
+ };
81
+ }
82
+ let configStr = `// @ts-check
63
83
  /** @type {import('vovk').VovkConfig} */
64
84
  const config = ${JSON.stringify(config, null, 2)};
65
- ${isModule ? '\nexport default config;' : 'module.exports = config;'}`, configAbsolutePath);
85
+ ${isModule ? '\nexport default config;' : 'module.exports = config;'};`;
66
86
  if (bundle) {
67
87
  configStr = await updateConfigProperty(configStr, ['bundle', 'build'], BUNDLE_BUILD_TSDOWN);
68
88
  }
89
+ configStr = await prettify(configStr, configAbsolutePath);
69
90
  if (!dryRun)
70
91
  await fs.writeFile(configAbsolutePath, configStr, 'utf-8');
71
92
  return { configAbsolutePath };
@@ -19,7 +19,7 @@ export class Init {
19
19
  log;
20
20
  async #init({ configPaths, pkgJson, }, { useNpm, useYarn, usePnpm, useBun, skipInstall, updateTsConfig, updateScripts, validationLibrary, bundle, lang, dryRun, channel, }) {
21
21
  const { log, root } = this;
22
- const dependencies = ['vovk', 'vovk-client', 'vovk-ajv'];
22
+ const dependencies = ['vovk', 'vovk-client', 'vovk-ajv', 'openapi3-ts', '@standard-schema/spec'];
23
23
  const devDependencies = ['vovk-cli'];
24
24
  if (lang?.includes('py')) {
25
25
  devDependencies.push('vovk-python');
@@ -1,4 +1,4 @@
1
- import { Project, QuoteKind, IndentationText, NewLineKind, SyntaxKind, Node } from 'ts-morph';
1
+ import { Project, QuoteKind, IndentationText, NewLineKind, SyntaxKind, Node, } from 'ts-morph';
2
2
  export function updateConfigProperty(sourceCode, pathToProperty, newValue) {
3
3
  const project = createProject();
4
4
  const sourceFile = project.createSourceFile('config-temp.mts', sourceCode, { overwrite: true });
@@ -20,6 +20,20 @@ function createProject() {
20
20
  },
21
21
  });
22
22
  }
23
+ function findPropertyAssignment(objectNode, key) {
24
+ const properties = objectNode.getProperties();
25
+ for (const prop of properties) {
26
+ if (Node.isPropertyAssignment(prop)) {
27
+ const name = prop.getName();
28
+ // Handle both quoted and unquoted property names
29
+ const unquotedName = name.replace(/^['"]|['"]$/g, '');
30
+ if (unquotedName === key || name === key) {
31
+ return prop;
32
+ }
33
+ }
34
+ }
35
+ return undefined;
36
+ }
23
37
  function mutateConfig(sourceFile, pathToProperty, newValue) {
24
38
  const variableDeclaration = sourceFile.getVariableDeclaration('config');
25
39
  if (!variableDeclaration) {
@@ -32,63 +46,50 @@ function mutateConfig(sourceFile, pathToProperty, newValue) {
32
46
  let currentNode = initializer;
33
47
  for (let i = 0; i < pathToProperty.length; i++) {
34
48
  const key = pathToProperty[i];
35
- if (!Node.isObjectLiteralExpression(currentNode)) {
36
- throw new Error(`Property at path ${pathToProperty.slice(0, i).join('.')} is not an object.`);
37
- }
38
- const property = currentNode.getProperty(key);
49
+ const isLastKey = i === pathToProperty.length - 1;
50
+ const property = findPropertyAssignment(currentNode, key);
39
51
  if (!property) {
40
52
  // Property does not exist
41
53
  if (newValue === undefined) {
42
54
  // Nothing to remove
43
55
  return sourceFile.getFullText();
44
56
  }
57
+ if (isLastKey) {
58
+ // Last key - add the final value
59
+ currentNode.addPropertyAssignment({
60
+ name: key,
61
+ initializer: (writer) => writeInitializer(writer, newValue),
62
+ });
63
+ }
45
64
  else {
46
- // Create property
47
- if (i === pathToProperty.length - 1) {
48
- // Last key
49
- currentNode.addPropertyAssignment({
50
- name: key,
51
- initializer: (writer) => writeInitializer(writer, newValue),
52
- });
53
- }
54
- else {
55
- // Need to create nested object
56
- const newObjectAssignment = currentNode.addPropertyAssignment({
57
- name: key,
58
- initializer: '{}',
59
- });
60
- const init = newObjectAssignment.getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression);
61
- currentNode = init;
62
- }
65
+ // Need to create nested object
66
+ const newObjectAssignment = currentNode.addPropertyAssignment({
67
+ name: key,
68
+ initializer: '{}',
69
+ });
70
+ currentNode = newObjectAssignment.getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression);
63
71
  }
64
72
  }
65
73
  else {
66
74
  // Property exists
67
- if (Node.isPropertyAssignment(property)) {
68
- const propInitializer = property.getInitializer();
69
- if (i === pathToProperty.length - 1) {
70
- // Last key
71
- if (newValue === undefined) {
72
- // Remove the property
73
- property.remove();
74
- }
75
- else {
76
- // Update the value
77
- property.setInitializer((writer) => writeInitializer(writer, newValue));
78
- }
75
+ const propInitializer = property.getInitializer();
76
+ if (isLastKey) {
77
+ // Last key - update or remove the value
78
+ if (newValue === undefined) {
79
+ property.remove();
79
80
  }
80
81
  else {
81
- // Need to go deeper
82
- if (propInitializer && Node.isObjectLiteralExpression(propInitializer)) {
83
- currentNode = propInitializer;
84
- }
85
- else {
86
- throw new Error(`Cannot traverse into non-object property at ${pathToProperty.slice(0, i + 1).join('.')}.`);
87
- }
82
+ property.setInitializer((writer) => writeInitializer(writer, newValue));
88
83
  }
89
84
  }
90
85
  else {
91
- throw new Error(`Unsupported property kind at path ${pathToProperty.slice(0, i + 1).join('.')}.`);
86
+ // Need to go deeper into existing object
87
+ if (propInitializer && Node.isObjectLiteralExpression(propInitializer)) {
88
+ currentNode = propInitializer;
89
+ }
90
+ else {
91
+ throw new Error(`Cannot traverse into non-object property at ${pathToProperty.slice(0, i + 1).join('.')}.`);
92
+ }
92
93
  }
93
94
  }
94
95
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk-cli",
3
- "version": "0.0.1-beta.84",
3
+ "version": "0.0.1-beta.86",
4
4
  "description": "CLI tool for managing Vovk.ts projects",
5
5
  "files": [
6
6
  "dist",
@@ -17,7 +17,7 @@
17
17
  "scripts": {
18
18
  "build": "rm -rf dist tsconfig.build.tsbuildinfo && tsc -P tsconfig.build.json",
19
19
  "postbuild": "chmod +x ./dist/index.mjs",
20
- "pre-test": "npm run build",
20
+ "pre-test": "npm run build && npm run clear-test-cache",
21
21
  "test-only": "npm run pre-test && node --experimental-transform-types --experimental-strip-types --experimental-vm-modules --test --test-only test/spec/**/*.mts",
22
22
  "test": "npm run pre-test && node --experimental-transform-types --experimental-strip-types --experimental-vm-modules --test --test-concurrency=1 test/spec/**/*.mts",
23
23
  "tsc": "tsc --noEmit",
@@ -42,21 +42,21 @@
42
42
  },
43
43
  "homepage": "https://vovk.dev",
44
44
  "peerDependencies": {
45
- "vovk": "^3.0.0-beta.127",
46
- "vovk-ajv": "^0.0.0-beta.20",
47
- "vovk-client": "^0.0.4-beta.21",
48
- "vovk-python": "^0.0.1-beta.10",
49
- "vovk-rust": "^0.0.1-beta.12"
45
+ "vovk": "^3.0.0-beta.130",
46
+ "vovk-ajv": "^0.0.0-beta.22",
47
+ "vovk-client": "^0.0.4-beta.23",
48
+ "vovk-python": "^0.0.1-beta.12",
49
+ "vovk-rust": "^0.0.1-beta.14"
50
50
  },
51
51
  "optionalDependencies": {
52
- "@rolldown/binding-linux-x64-gnu": "1.0.0-beta.57"
52
+ "@rolldown/binding-linux-x64-gnu": "1.0.0-beta.60"
53
53
  },
54
54
  "dependencies": {
55
55
  "@iarna/toml": "^2.2.5",
56
- "@inquirer/prompts": "^8.1.0",
56
+ "@inquirer/prompts": "^8.2.0",
57
57
  "@npmcli/package-json": "^7.0.4",
58
58
  "@types/json-schema": "^7.0.15",
59
- "@types/lodash": "^4.17.21",
59
+ "@types/lodash": "^4.17.23",
60
60
  "chalk": "^5.6.2",
61
61
  "chokidar": "^5.0.0",
62
62
  "clone-deep": "^4.0.1",
@@ -76,8 +76,8 @@
76
76
  "prettier": "^3.7.4",
77
77
  "tar-stream": "^3.1.7",
78
78
  "ts-morph": "^27.0.2",
79
- "type-fest": "^5.3.1",
80
- "undici": "^7.16.0",
79
+ "type-fest": "^5.4.1",
80
+ "undici": "^7.18.2",
81
81
  "yaml": "^2.8.2"
82
82
  },
83
83
  "devDependencies": {
@@ -91,7 +91,7 @@
91
91
  "create-next-app": "^16.1.1",
92
92
  "http-server": "^14.1.1",
93
93
  "node-pty": "0.10.1",
94
- "tsdown": "^0.18.3",
95
- "zod": "^4.2.1"
94
+ "tsdown": "^0.19.0",
95
+ "zod": "^4.3.5"
96
96
  }
97
97
  }