@kubb/cli 0.39.1 → 0.40.0

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/index.js CHANGED
@@ -8,6 +8,7 @@ var ora = require('ora');
8
8
  var execa = require('execa');
9
9
  var stringArgv = require('string-argv');
10
10
  var core = require('@kubb/core');
11
+ var moduleImporter = require('@humanwhocodes/module-importer');
11
12
  var cosmiconfig = require('cosmiconfig');
12
13
  var cosmiconfigTypescriptLoader = require('cosmiconfig-typescript-loader');
13
14
 
@@ -84,19 +85,21 @@ var startWatcher = async (cb, options) => {
84
85
  }
85
86
  });
86
87
  };
87
-
88
- // src/utils/getPlugins.ts
89
88
  var isJSONPlugins = (plugins) => {
90
89
  return !!plugins?.some((plugin) => {
91
90
  return typeof plugin?.[0] === "string";
92
91
  });
93
92
  };
93
+ var importPlugin = async (name, options) => {
94
+ const importer = new moduleImporter.ModuleImporter(process.cwd());
95
+ const importedPlugin = process.env.NODE_ENV === "test" ? await import(name) : await importer.import(name);
96
+ return importedPlugin?.default?.default ? importedPlugin.default.default(options) : importedPlugin.default(options);
97
+ };
94
98
  var getPlugins = (plugins) => {
95
99
  if (isJSONPlugins(plugins)) {
96
100
  const promises = plugins.map(async (plugin) => {
97
101
  const [name, options = {}] = plugin;
98
- const importedPlugin = await import(name);
99
- return importedPlugin?.default ? importedPlugin.default(options) : importedPlugin(options);
102
+ return importPlugin(name, options);
100
103
  });
101
104
  return Promise.all(promises);
102
105
  }
@@ -106,22 +109,20 @@ var getPlugins = (plugins) => {
106
109
  // src/utils/getConfig.ts
107
110
  var getConfig = async (result, options) => {
108
111
  const config = result?.config;
109
- if (result?.filepath.endsWith(".json")) {
110
- let JSONConfig = config;
111
- JSONConfig = {
112
- ...JSONConfig,
113
- plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : void 0
114
- };
115
- return Promise.resolve(JSONConfig);
116
- }
112
+ let kubbUserConfig = Promise.resolve(config);
117
113
  if (typeof config === "function") {
118
114
  const possiblePromise = config(options);
119
115
  if (core.isPromise(possiblePromise)) {
120
- return possiblePromise;
116
+ kubbUserConfig = possiblePromise;
121
117
  }
122
- return Promise.resolve(possiblePromise);
118
+ kubbUserConfig = Promise.resolve(possiblePromise);
123
119
  }
124
- return config;
120
+ let JSONConfig = await kubbUserConfig;
121
+ JSONConfig = {
122
+ ...JSONConfig,
123
+ plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : void 0
124
+ };
125
+ return JSONConfig;
125
126
  };
126
127
  var getCosmiConfig = async (moduleName2, config) => {
127
128
  const explorer = cosmiconfig.cosmiconfig(moduleName2, {
@@ -155,7 +156,7 @@ var getCosmiConfig = async (moduleName2, config) => {
155
156
  };
156
157
 
157
158
  // package.json
158
- var version = "0.39.1";
159
+ var version = "0.40.0";
159
160
 
160
161
  // src/index.ts
161
162
  var moduleName = "kubb";
package/dist/index.mjs CHANGED
@@ -6,6 +6,7 @@ import ora from 'ora';
6
6
  import { execa } from 'execa';
7
7
  import { parseArgsStringToArgv } from 'string-argv';
8
8
  import { build, isPromise } from '@kubb/core';
9
+ import { ModuleImporter } from '@humanwhocodes/module-importer';
9
10
  import { cosmiconfig, defaultLoaders } from 'cosmiconfig';
10
11
  import { TypeScriptLoader } from 'cosmiconfig-typescript-loader';
11
12
 
@@ -77,19 +78,21 @@ var startWatcher = async (cb, options) => {
77
78
  }
78
79
  });
79
80
  };
80
-
81
- // src/utils/getPlugins.ts
82
81
  var isJSONPlugins = (plugins) => {
83
82
  return !!plugins?.some((plugin) => {
84
83
  return typeof plugin?.[0] === "string";
85
84
  });
86
85
  };
86
+ var importPlugin = async (name, options) => {
87
+ const importer = new ModuleImporter(process.cwd());
88
+ const importedPlugin = process.env.NODE_ENV === "test" ? await import(name) : await importer.import(name);
89
+ return importedPlugin?.default?.default ? importedPlugin.default.default(options) : importedPlugin.default(options);
90
+ };
87
91
  var getPlugins = (plugins) => {
88
92
  if (isJSONPlugins(plugins)) {
89
93
  const promises = plugins.map(async (plugin) => {
90
94
  const [name, options = {}] = plugin;
91
- const importedPlugin = await import(name);
92
- return importedPlugin?.default ? importedPlugin.default(options) : importedPlugin(options);
95
+ return importPlugin(name, options);
93
96
  });
94
97
  return Promise.all(promises);
95
98
  }
@@ -99,22 +102,20 @@ var getPlugins = (plugins) => {
99
102
  // src/utils/getConfig.ts
100
103
  var getConfig = async (result, options) => {
101
104
  const config = result?.config;
102
- if (result?.filepath.endsWith(".json")) {
103
- let JSONConfig = config;
104
- JSONConfig = {
105
- ...JSONConfig,
106
- plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : void 0
107
- };
108
- return Promise.resolve(JSONConfig);
109
- }
105
+ let kubbUserConfig = Promise.resolve(config);
110
106
  if (typeof config === "function") {
111
107
  const possiblePromise = config(options);
112
108
  if (isPromise(possiblePromise)) {
113
- return possiblePromise;
109
+ kubbUserConfig = possiblePromise;
114
110
  }
115
- return Promise.resolve(possiblePromise);
111
+ kubbUserConfig = Promise.resolve(possiblePromise);
116
112
  }
117
- return config;
113
+ let JSONConfig = await kubbUserConfig;
114
+ JSONConfig = {
115
+ ...JSONConfig,
116
+ plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : void 0
117
+ };
118
+ return JSONConfig;
118
119
  };
119
120
  var getCosmiConfig = async (moduleName2, config) => {
120
121
  const explorer = cosmiconfig(moduleName2, {
@@ -148,7 +149,7 @@ var getCosmiConfig = async (moduleName2, config) => {
148
149
  };
149
150
 
150
151
  // package.json
151
- var version = "0.39.1";
152
+ var version = "0.40.0";
152
153
 
153
154
  // src/index.ts
154
155
  var moduleName = "kubb";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/cli",
3
- "version": "0.39.1",
3
+ "version": "0.40.0",
4
4
  "description": "Generator cli",
5
5
  "repository": {
6
6
  "type": "git",
@@ -27,7 +27,8 @@
27
27
  "!/**/__tests__/**"
28
28
  ],
29
29
  "dependencies": {
30
- "@kubb/core": "0.39.1",
30
+ "@humanwhocodes/module-importer": "^1.0.1",
31
+ "@kubb/core": "0.40.0",
31
32
  "chokidar": "^3.5.3",
32
33
  "commander": "^10.0.0",
33
34
  "cosmiconfig": "^8.0.0",
@@ -39,6 +40,7 @@
39
40
  "ts-node": "^10.9.1"
40
41
  },
41
42
  "devDependencies": {
43
+ "@kubb/swagger": "0.40.0",
42
44
  "@types/node": "^18.13.0",
43
45
  "tsup": "^6.6.3",
44
46
  "typescript": "^4.9.5"