@karry.sun/yapi-gen 0.2.5 → 0.2.6

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/dist/run.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AA4IA,wBAAgB,GAAG,CAAC,OAAO,GAAE;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACZ,GAAG,MAAM,CAqFd"}
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AA0IA,wBAAgB,GAAG,CAAC,OAAO,GAAE;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACZ,GAAG,MAAM,CAqFd"}
package/dist/run.js CHANGED
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { spawnSync } from 'child_process';
7
7
  import { existsSync, mkdirSync, writeFileSync } from 'fs';
8
- import { resolve, dirname, basename, relative, join } from 'path';
8
+ import { resolve, dirname, join } from 'path';
9
9
  import { fileURLToPath } from 'url';
10
10
  import { createRequire } from 'module';
11
11
  import { readFileSync } from 'fs';
@@ -51,21 +51,19 @@ function findConfig(cwd) {
51
51
  function getWrapperContent(cwd, configPath) {
52
52
  const packageName = getPackageName();
53
53
  const absoluteConfig = resolve(cwd, configPath);
54
- const configDir = dirname(absoluteConfig);
55
- const configBase = basename(absoluteConfig).replace(/\.[^.]+$/, '') || 'yapi-gen.config';
56
- const wrapperDir = resolve(cwd, WRAPPER_DIR);
57
- const rel = relative(wrapperDir, configDir).replace(/\\/g, '/');
58
- const relativeImport = (rel ? rel + '/' : '') + configBase;
54
+ const configPathEscaped = JSON.stringify(absoluteConfig);
59
55
  return `/* 由 yapi-gen 自动生成,请勿修改 */
60
- import { defineConfig } from 'yapi-to-typescript';
61
- import { resolveConfig } from '${packageName}';
56
+ const { defineConfig } = require('yapi-to-typescript');
57
+ const { resolveConfig } = require('${packageName}');
58
+ const { createRequire } = require('module');
62
59
 
63
- const userConfig = await import('${relativeImport}');
60
+ const require = createRequire(__filename);
61
+ const userConfig = require(${configPathEscaped});
64
62
  const raw = userConfig.default ?? userConfig;
65
63
  const configList = Array.isArray(raw) ? raw : [raw];
66
64
  const resolvedList = configList.map((c) => resolveConfig(c, process.cwd()));
67
65
 
68
- export default defineConfig(resolvedList);
66
+ module.exports = { default: defineConfig(resolvedList) };
69
67
  `;
70
68
  }
71
69
  function runInit(cwd) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karry.sun/yapi-gen",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "基于 yapi-to-typescript 的 YApi 前端代码生成 CLI,支持可配置的请求适配器与多项目复用",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",