@coze/cli 0.0.2

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.
@@ -0,0 +1,15 @@
1
+ import { type Argument, type Option, type Command } from 'commander';
2
+ export interface CommandSpec {
3
+ name: string;
4
+ description: string;
5
+ action?: (...args: any[]) => Promise<void> | void;
6
+ subCommands?: CommandSpec[];
7
+ options?: Option[];
8
+ arguments?: Argument[];
9
+ auth?: boolean;
10
+ }
11
+ export declare function addCommand({ program, spec, runAuth, }: {
12
+ program: Command;
13
+ spec: CommandSpec;
14
+ runAuth?: () => Promise<void>;
15
+ }): void;
@@ -0,0 +1,28 @@
1
+ export function addCommand({ program, spec, runAuth, }) {
2
+ var _a, _b, _c;
3
+ const command = program.command(spec.name);
4
+ command.description(spec.description);
5
+ ((_a = spec.arguments) !== null && _a !== void 0 ? _a : []).forEach((argument) => {
6
+ command.addArgument(argument);
7
+ });
8
+ ((_b = spec.options) !== null && _b !== void 0 ? _b : []).forEach((option) => {
9
+ command.addOption(option);
10
+ });
11
+ if (spec.action) {
12
+ command.action(async (...args) => {
13
+ var _a;
14
+ if (spec.auth && runAuth) {
15
+ await runAuth();
16
+ }
17
+ await ((_a = spec.action) === null || _a === void 0 ? void 0 : _a.call(spec, ...args));
18
+ });
19
+ }
20
+ ((_c = spec.subCommands) !== null && _c !== void 0 ? _c : []).forEach(subCommand => {
21
+ addCommand({
22
+ program: command,
23
+ spec: subCommand,
24
+ runAuth,
25
+ });
26
+ });
27
+ }
28
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1,6 @@
1
+ import { type Region } from '../helpers/constants';
2
+ import { type CommandSpec } from './base';
3
+ export declare function loginAction({ region }: {
4
+ region?: Region;
5
+ }): Promise<void>;
6
+ export declare const loginSpec: CommandSpec;
@@ -0,0 +1,18 @@
1
+ import { Option } from 'commander';
2
+ import { OauthClient } from '../oauth';
3
+ import { NpmConfig } from '../npm';
4
+ import { REGION_VALUES } from '../helpers/constants';
5
+ export async function loginAction({ region }) {
6
+ const npmConfig = new NpmConfig({ region });
7
+ const authClient = new OauthClient(region);
8
+ await authClient.activate(npmConfig);
9
+ }
10
+ export const loginSpec = {
11
+ name: 'login',
12
+ description: 'log in to the hub',
13
+ action: loginAction,
14
+ options: [
15
+ new Option('-r, --region <name>', 'the region of hub').choices(REGION_VALUES),
16
+ ],
17
+ };
18
+ //# sourceMappingURL=login.js.map
@@ -0,0 +1,8 @@
1
+ import { type Region } from '../helpers/constants';
2
+ import { type CommandSpec } from './base';
3
+ export declare function logoutAction({ region, scope, source, }: {
4
+ region?: Region;
5
+ scope?: string;
6
+ source?: string;
7
+ }): Promise<void>;
8
+ export declare const logoutSpec: CommandSpec;
@@ -0,0 +1,20 @@
1
+ import { Option } from 'commander';
2
+ import { OauthClient } from '../oauth';
3
+ import { NpmConfig } from '../npm';
4
+ import { REGION_VALUES } from '../helpers/constants';
5
+ export async function logoutAction({ region, scope, source, }) {
6
+ const npmConfig = new NpmConfig({ region, scope, source });
7
+ const authClient = new OauthClient(region);
8
+ await authClient.deactivate(npmConfig);
9
+ }
10
+ export const logoutSpec = {
11
+ name: 'logout',
12
+ description: 'log out of the hub',
13
+ action: logoutAction,
14
+ options: [
15
+ new Option('-r, --region <name>', 'the region of hub').choices(REGION_VALUES),
16
+ new Option('-s, --scope <name>', 'the scope of package'),
17
+ new Option('-b, --source <name>', 'the business source'),
18
+ ],
19
+ };
20
+ //# sourceMappingURL=logout.js.map
@@ -0,0 +1,10 @@
1
+ export declare enum Region {
2
+ CN = "cn"
3
+ }
4
+ declare let REGISTRY_HOST: Record<string, string>;
5
+ declare let CLIENT_ID_MAP: Record<string, string>;
6
+ declare let ISSUER_MAP: Record<string, string>;
7
+ declare let REGION_VALUES: string[];
8
+ declare let isLocalDev: (region: string) => boolean;
9
+ export declare const DEFAULT_REGION = Region.CN;
10
+ export { REGION_VALUES, isLocalDev, REGISTRY_HOST, CLIENT_ID_MAP, ISSUER_MAP };
@@ -0,0 +1,44 @@
1
+ export var Region;
2
+ (function (Region) {
3
+ Region["CN"] = "cn";
4
+ // I18N = 'i18n',
5
+ })(Region || (Region = {}));
6
+ let REGISTRY_HOST = {
7
+ [Region.CN]: 'npm-hub.coze.cn',
8
+ // [Region.I18N]: 'npm-hub.coze.com',
9
+ };
10
+ let CLIENT_ID_MAP = {
11
+ [Region.CN]: '13474932957575400683007237571476.app.coze',
12
+ };
13
+ let ISSUER_MAP = {
14
+ [Region.CN]: 'https://api.coze.cn',
15
+ };
16
+ let REGION_VALUES = Object.values(Region);
17
+ let isLocalDev = () => false;
18
+ if (import.meta.env.PUBLIC_INHOUSE) {
19
+ let DevRegion;
20
+ (function (DevRegion) {
21
+ DevRegion["LOCAL"] = "local";
22
+ DevRegion["CN_BOE"] = "boe";
23
+ })(DevRegion || (DevRegion = {}));
24
+ REGISTRY_HOST = {
25
+ ...REGISTRY_HOST,
26
+ [DevRegion.CN_BOE]: 'npm-hub-boe.bytedance.net',
27
+ [DevRegion.LOCAL]: 'localhost:3000',
28
+ };
29
+ CLIENT_ID_MAP = {
30
+ ...CLIENT_ID_MAP,
31
+ [DevRegion.CN_BOE]: '70653688608994412341629476687797.app.coze',
32
+ [DevRegion.LOCAL]: '70653688608994412341629476687797.app.coze',
33
+ };
34
+ ISSUER_MAP = {
35
+ ...ISSUER_MAP,
36
+ [DevRegion.CN_BOE]: 'https://api-bot-boe.bytedance.net',
37
+ [DevRegion.LOCAL]: 'https://api-bot-boe.bytedance.net',
38
+ };
39
+ REGION_VALUES = Object.values({ ...DevRegion, ...Region });
40
+ isLocalDev = (region) => region === DevRegion.LOCAL;
41
+ }
42
+ export const DEFAULT_REGION = Region.CN;
43
+ export { REGION_VALUES, isLocalDev, REGISTRY_HOST, CLIENT_ID_MAP, ISSUER_MAP };
44
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1,7 @@
1
+ export declare const logger: {
2
+ info(...messages: unknown[]): void;
3
+ success(...messages: unknown[]): void;
4
+ warning(...messages: unknown[]): void;
5
+ error(...messages: unknown[]): void;
6
+ debug(...messages: unknown[]): void;
7
+ };
@@ -0,0 +1,21 @@
1
+ import colors from 'picocolors';
2
+ export const logger = {
3
+ info(...messages) {
4
+ console.log(colors.blue('[INFO]'), ...messages);
5
+ },
6
+ success(...messages) {
7
+ console.log(colors.green('[SUCCESS]'), ...messages);
8
+ },
9
+ warning(...messages) {
10
+ console.log(colors.yellow('[WARNING]'), ...messages);
11
+ },
12
+ error(...messages) {
13
+ console.error(colors.red('[ERROR]'), ...messages);
14
+ },
15
+ debug(...messages) {
16
+ if (process.env.DEBUG) {
17
+ console.log(colors.magenta('[DEBUG]'), ...messages);
18
+ }
19
+ },
20
+ };
21
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1,8 @@
1
+ export declare function resolvePackageJson(projectDir: string): Record<string, any>;
2
+ export declare function resolvePackageDir(dir?: string): string;
3
+ /**
4
+ * @coze/a-b -> __coze__a_b
5
+ * @coze-ui/a-b -> __coze_ui__a_b
6
+ * a-b -> a_b
7
+ */
8
+ export declare function pkgName2RemoteName(pkgName: string): string;
@@ -0,0 +1,33 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any -- ignore */
2
+ /* eslint-disable security/detect-non-literal-fs-filename -- ignore */
3
+ import path from 'node:path';
4
+ import fs from 'node:fs';
5
+ export function resolvePackageJson(projectDir) {
6
+ const pkgJsonFilePath = path.join(projectDir, 'package.json');
7
+ if (!fs.existsSync(pkgJsonFilePath)) {
8
+ throw new Error(`package.json not found in ${projectDir}`);
9
+ }
10
+ const content = fs.readFileSync(pkgJsonFilePath, 'utf-8');
11
+ return JSON.parse(content);
12
+ }
13
+ export function resolvePackageDir(dir = '') {
14
+ if (path.isAbsolute(dir)) {
15
+ return dir;
16
+ }
17
+ else {
18
+ return path.join(process.cwd(), dir);
19
+ }
20
+ }
21
+ /**
22
+ * @coze/a-b -> __coze__a_b
23
+ * @coze-ui/a-b -> __coze_ui__a_b
24
+ * a-b -> a_b
25
+ */
26
+ export function pkgName2RemoteName(pkgName) {
27
+ const hasScope = pkgName.startsWith('@');
28
+ const parts = pkgName.split('/');
29
+ return `${hasScope ? `__${parts[0].slice(1)}__` : parts[0]}${parts
30
+ .slice(1)
31
+ .join('_')}`.replace(/-/g, '_');
32
+ }
33
+ //# sourceMappingURL=package.js.map
@@ -0,0 +1,3 @@
1
+ import { type AxiosRequestConfig } from 'axios';
2
+ export type RequestConfig = (url: string, options: AxiosRequestConfig) => Promise<AxiosRequestConfig>;
3
+ export declare function loadRequestConfig(): Promise<RequestConfig | undefined>;
@@ -0,0 +1,24 @@
1
+ import path from 'node:path';
2
+ import os from 'node:os';
3
+ import fs from 'node:fs';
4
+ import { logger } from './logger';
5
+ export async function loadRequestConfig() {
6
+ const configPath = path.join(os.homedir(), '.coze-hub', 'request.js');
7
+ if (!fs.existsSync(configPath)) {
8
+ return undefined;
9
+ }
10
+ try {
11
+ const fileContent = fs.readFileSync(configPath, 'utf8');
12
+ const moduleWrapper = new Function('module', 'exports', fileContent);
13
+ const module = { exports: {} };
14
+ await moduleWrapper(module, module.exports);
15
+ const config = module.exports;
16
+ logger.info('loadRequestConfig', config);
17
+ return config;
18
+ }
19
+ catch (error) {
20
+ logger.warning('Failed to load request config:', error);
21
+ return undefined;
22
+ }
23
+ }
24
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1,16 @@
1
+ import { type TokenSetParameters } from 'openid-client';
2
+ export interface BaseConfigData {
3
+ authToken: string;
4
+ refreshToken: string;
5
+ registryUrl: string;
6
+ scope?: string;
7
+ }
8
+ export interface INpmConfig<T extends BaseConfigData = BaseConfigData> {
9
+ loadConfig: () => Promise<T>;
10
+ storeToken: (token: TokenSetParameters) => Promise<void>;
11
+ clearToken: () => Promise<void>;
12
+ }
13
+ export interface IAuthClient {
14
+ activate: (npmConfig: INpmConfig) => Promise<void>;
15
+ deactivate: (npmConfig: INpmConfig) => Promise<void>;
16
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ export { addCommand, type CommandSpec } from './commands/base';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { addCommand } from './commands/base';
2
+ //# sourceMappingURL=index.js.map
package/dist/index.mjs ADDED
@@ -0,0 +1,263 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_node_fs__ from "node:fs";
3
+ import * as __WEBPACK_EXTERNAL_MODULE_node_module__ from "node:module";
4
+ import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core__ from "@rsbuild/core";
5
+ import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
6
+ import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react__ from "@rsbuild/plugin-react";
7
+ import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_less__ from "@rsbuild/plugin-less";
8
+ import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
9
+ import "prettier";
10
+ import * as __WEBPACK_EXTERNAL_MODULE__rslib_core__ from "@rslib/core";
11
+ import * as __WEBPACK_EXTERNAL_MODULE_commander__ from "commander";
12
+ /* eslint-disable @typescript-eslint/no-explicit-any -- ignore */ function addCommand({ program, spec, runAuth }) {
13
+ const command = program.command(spec.name);
14
+ command.description(spec.description);
15
+ (spec.arguments ?? []).forEach((argument)=>{
16
+ command.addArgument(argument);
17
+ });
18
+ (spec.options ?? []).forEach((option)=>{
19
+ command.addOption(option);
20
+ });
21
+ if (spec.action) command.action(async (...args)=>{
22
+ if (spec.auth && runAuth) await runAuth();
23
+ await spec.action?.(...args);
24
+ });
25
+ (spec.subCommands ?? []).forEach((subCommand)=>{
26
+ addCommand({
27
+ program: command,
28
+ spec: subCommand,
29
+ runAuth
30
+ });
31
+ });
32
+ }
33
+ const logger = {
34
+ info (...messages) {
35
+ console.log(__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].blue('[INFO]'), ...messages);
36
+ },
37
+ success (...messages) {
38
+ console.log(__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].green('[SUCCESS]'), ...messages);
39
+ },
40
+ warning (...messages) {
41
+ console.log(__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow('[WARNING]'), ...messages);
42
+ },
43
+ error (...messages) {
44
+ console.error(__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].red('[ERROR]'), ...messages);
45
+ },
46
+ debug (...messages) {
47
+ if (process.env.DEBUG) console.log(__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].magenta('[DEBUG]'), ...messages);
48
+ }
49
+ };
50
+ /**
51
+ * @coze/a-b -> __coze__a_b
52
+ * @coze-ui/a-b -> __coze_ui__a_b
53
+ * a-b -> a_b
54
+ */ function pkgName2RemoteName(pkgName) {
55
+ const hasScope = pkgName.startsWith('@');
56
+ const parts = pkgName.split('/');
57
+ return `${hasScope ? `__${parts[0].slice(1)}__` : parts[0]}${parts.slice(1).join('_')}`.replace(/-/g, '_');
58
+ }
59
+ // @module-federation/rsbuild-plugin only support cjs
60
+ const config_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(import.meta.url);
61
+ const pluginModuleFederation = config_require('@module-federation/rsbuild-plugin').pluginModuleFederation;
62
+ const { isEmpty, merge } = __WEBPACK_EXTERNAL_MODULE_lodash__["default"];
63
+ const CONFIG_FILE_NAME = 'ui.config';
64
+ const CONFIG_FILE_EXTNAME = [
65
+ '.js',
66
+ '.ts',
67
+ '.tsx',
68
+ '.mjs',
69
+ '.mts',
70
+ '.cjs',
71
+ '.cts'
72
+ ];
73
+ const CDN_MAP = {
74
+ boe: '//lf0-fast-deliver-inner.bytedance.net/obj/eden-internal/ibo-lgvj/ljhwZthlaukjlkulzlp/',
75
+ cn: '//lf3-static.bytednsdoc.com/obj/eden-cn/ibo-lgvj/ljhwZthlaukjlkulzlp/'
76
+ };
77
+ function defineConfig(config) {
78
+ return config;
79
+ }
80
+ async function loadConfig({ cwd = process.cwd(), path }) {
81
+ const configFilePath = resolveConfigPath(cwd, path);
82
+ const { content } = await (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.loadConfig)({
83
+ cwd: (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(configFilePath),
84
+ path: configFilePath
85
+ });
86
+ content._privateMeta = {
87
+ configFilePath
88
+ };
89
+ return content;
90
+ }
91
+ function getShareRslibConfig(uiConfig, libConfig) {
92
+ const projectDir = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(uiConfig._privateMeta.configFilePath);
93
+ const pkgJson = JSON.parse(__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].readFileSync(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(projectDir, 'package.json'), 'utf-8'));
94
+ const umdName = pkgName2RemoteName(pkgJson.name);
95
+ const entries = resolveExports(uiConfig);
96
+ const tsconfigPath = resolveTsconfigPath(projectDir);
97
+ const libs = [];
98
+ const formats = [
99
+ 'cjs',
100
+ 'esm',
101
+ 'umd',
102
+ 'mf'
103
+ ];
104
+ Object.entries(entries).forEach(([dist, src])=>{
105
+ for (const format of formats){
106
+ // mf should use exposes instead of multiple entries
107
+ if ('mf' === format && '.' !== dist) continue;
108
+ const config = {
109
+ dts: {
110
+ bundle: false
111
+ },
112
+ format,
113
+ output: {
114
+ distPath: {
115
+ root: __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join('dist', format, dist)
116
+ }
117
+ },
118
+ source: {
119
+ tsconfigPath,
120
+ entry: {
121
+ index: src
122
+ }
123
+ },
124
+ shims: {
125
+ cjs: {
126
+ 'import.meta.url': true
127
+ },
128
+ esm: {
129
+ __filename: true,
130
+ __dirname: true,
131
+ require: true
132
+ }
133
+ },
134
+ // each entry should have unique name
135
+ umdName: __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(umdName, dist).replace(/\//g, '_')
136
+ };
137
+ if ('mf' === format) {
138
+ // default use boe
139
+ const cdn = CDN_MAP[process.env.REGION ?? ''] ?? CDN_MAP.boe;
140
+ const singleton = [
141
+ 'react',
142
+ 'react-dom'
143
+ ];
144
+ let shared = uiConfig.shared ?? {};
145
+ if (isEmpty(shared) && null !== uiConfig.shared) for (const type of [
146
+ 'dependencies',
147
+ 'peerDependencies'
148
+ ])Object.entries(pkgJson[type]).forEach(([name])=>{
149
+ shared[name] = {
150
+ singleton: singleton.includes(name)
151
+ };
152
+ });
153
+ merge(config, {
154
+ output: {
155
+ assetPrefix: `${cdn}${__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(`${pkgJson.name}@${pkgJson.version}`, 'dist/mf', dist)}`
156
+ },
157
+ plugins: [
158
+ pluginModuleFederation({
159
+ name: umdName,
160
+ exposes: entries,
161
+ shared
162
+ })
163
+ ]
164
+ });
165
+ } else if ('umd' === format) merge(config, {
166
+ output: {
167
+ minify: true,
168
+ injectStyles: true
169
+ }
170
+ });
171
+ libs.push(merge(config, libConfig));
172
+ }
173
+ });
174
+ return merge({
175
+ lib: libs,
176
+ plugins: [
177
+ (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react__.pluginReact)(),
178
+ (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_less__.pluginLess)()
179
+ ]
180
+ }, uiConfig.rslib ?? {}, {
181
+ _privateMeta: uiConfig._privateMeta
182
+ });
183
+ }
184
+ function resolveConfigPath(root, customConfig) {
185
+ if (customConfig) {
186
+ const customConfigPath = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].isAbsolute(customConfig) ? customConfig : __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(root, customConfig);
187
+ if (__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync(customConfigPath)) {
188
+ if (__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].statSync(customConfigPath).isFile()) return customConfigPath;
189
+ root = customConfigPath;
190
+ } else throw new Error(`${CONFIG_FILE_NAME} not found in ${customConfigPath}`);
191
+ }
192
+ const configFilePath = CONFIG_FILE_EXTNAME.map((extname)=>`${__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(root, CONFIG_FILE_NAME)}${extname}`).find((p)=>__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync(p));
193
+ if (configFilePath) return configFilePath;
194
+ throw new Error(`${CONFIG_FILE_NAME} not found in ${root}`);
195
+ }
196
+ function resolveTsconfigPath(root) {
197
+ // Preferred tsconfig.build.json
198
+ if (__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(root, 'tsconfig.build.json'))) return 'tsconfig.build.json';
199
+ return 'tsconfig.json';
200
+ }
201
+ function resolveMainEntry(projectDir) {
202
+ const mainEntry = CONFIG_FILE_EXTNAME.map((extname)=>`index${extname}`).find((e)=>__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(projectDir, `src/${e}`)));
203
+ return mainEntry;
204
+ }
205
+ /**
206
+ * The `exports` field in `package.json` must adhere to the following format:
207
+ *
208
+ * ```
209
+ * exports: {
210
+ * ".": {
211
+ * ...
212
+ * "src": "./src/index.tsx"
213
+ * },
214
+ * "./button": {
215
+ * ...
216
+ * "src": "./src/button/index.tsx"
217
+ * }
218
+ * }
219
+ * ```
220
+ */ function resolveExports(uiConfig) {
221
+ const projectDir = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(uiConfig._privateMeta.configFilePath);
222
+ const srcEntry = resolveMainEntry(projectDir);
223
+ if (!srcEntry) throw new Error('entry not found, maybe you forget the "src/index.ts"?');
224
+ const pkgJson = JSON.parse(__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].readFileSync(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(projectDir, 'package.json'), 'utf-8'));
225
+ let exposes = {};
226
+ Object.entries(pkgJson.exports ?? {}).forEach(([key, config])=>{
227
+ if (!config.src) {
228
+ logger.warning([
229
+ `exports.${key} does't have "src", the builder will ignore this export.`,
230
+ `you should add "src" field, such as:\n`,
231
+ 'exports: {\n',
232
+ ` "${key}": {\n`,
233
+ ' "src": "./src/index.tsx"\n',
234
+ ' }\n',
235
+ '}'
236
+ ].join(''));
237
+ return;
238
+ }
239
+ // mfplugin doesn't support "./"
240
+ const k = './' === key ? '.' : key;
241
+ exposes[k] = config.src;
242
+ });
243
+ // use default export
244
+ if (isEmpty(exposes)) exposes['.'] = `./src/${srcEntry}`;
245
+ return exposes;
246
+ }
247
+ /* eslint-disable security/detect-non-literal-fs-filename -- ignore */ const buildAction = async (options = {})=>{
248
+ const uiConfig = await loadConfig({
249
+ path: options.dir
250
+ });
251
+ const projectDir = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(uiConfig._privateMeta.configFilePath);
252
+ // esm/cjs/umd/mf
253
+ const prevCwd = process.cwd();
254
+ try {
255
+ process.chdir(projectDir);
256
+ const rslibConfig = getShareRslibConfig(uiConfig, options.libConfig);
257
+ await (0, __WEBPACK_EXTERNAL_MODULE__rslib_core__.build)(rslibConfig);
258
+ } catch (e) {} finally{
259
+ process.chdir(prevCwd);
260
+ }
261
+ };
262
+ new __WEBPACK_EXTERNAL_MODULE_commander__.Option('-d, --dir <componentDir>', 'the path of component');
263
+ export { addCommand, buildAction, defineConfig };
package/dist/npm.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { type TokenSetParameters } from 'openid-client';
2
+ import Config from '@npmcli/config';
3
+ import { type INpmConfig, type BaseConfigData } from './helpers/types';
4
+ import { type Region } from './helpers/constants';
5
+ export interface NpmConfigOptions {
6
+ projectDir?: string;
7
+ scope?: string;
8
+ region?: Region;
9
+ source?: string;
10
+ }
11
+ export interface ConfigData extends BaseConfigData {
12
+ region?: Region;
13
+ source?: string;
14
+ }
15
+ export declare class NpmConfig implements INpmConfig<ConfigData> {
16
+ private proxy;
17
+ private config;
18
+ constructor({ projectDir, scope, region, source }?: NpmConfigOptions);
19
+ get registryScope(): string;
20
+ get registryUrl(): string;
21
+ get registryAuthUrl(): string;
22
+ get refreshKey(): string;
23
+ get region(): string;
24
+ loadConfig(): Promise<ConfigData>;
25
+ storeToken(tokenSet: TokenSetParameters): Promise<void>;
26
+ clearToken(): Promise<void>;
27
+ getProxy(): Config;
28
+ }