@modern-js/core 1.2.0 → 1.3.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/js/modern/cli.js +29 -0
  3. package/dist/js/modern/config/index.js +11 -5
  4. package/dist/js/modern/context.js +24 -16
  5. package/dist/js/modern/index.js +19 -10
  6. package/dist/js/modern/loadPlugins.js +16 -2
  7. package/dist/js/node/cli.js +35 -0
  8. package/dist/js/node/config/index.js +11 -5
  9. package/dist/js/node/context.js +24 -16
  10. package/dist/js/node/index.js +28 -37
  11. package/dist/js/node/loadPlugins.js +17 -1
  12. package/dist/types/cli.d.ts +1 -0
  13. package/dist/types/config/index.d.ts +14 -13
  14. package/dist/types/context.d.ts +6 -1
  15. package/dist/types/index.d.ts +13 -7
  16. package/dist/types/loadPlugins.d.ts +5 -0
  17. package/jest.config.js +8 -0
  18. package/modern.config.js +0 -7
  19. package/package.json +17 -10
  20. package/tests/btsm.test.ts +20 -0
  21. package/tests/config.test.ts +137 -0
  22. package/tests/context.test.ts +63 -0
  23. package/tests/fixtures/index-test/package.json +3 -0
  24. package/tests/index.test.ts +74 -0
  25. package/tests/loadEnv.test.ts +1 -1
  26. package/tests/loadPlugin.test.ts +36 -1
  27. package/tests/mergeConfig.test.ts +1 -1
  28. package/tests/repeatKeyWarning.test.ts +2 -2
  29. package/tests/schema.test.ts +1 -1
  30. package/tests/tsconfig.json +1 -3
  31. package/tests/utils.test.ts +8 -0
  32. package/tsconfig.json +1 -3
  33. package/src/config/defaults.ts +0 -101
  34. package/src/config/index.ts +0 -297
  35. package/src/config/mergeConfig.ts +0 -69
  36. package/src/config/schema/deploy.ts +0 -17
  37. package/src/config/schema/index.ts +0 -116
  38. package/src/config/schema/output.ts +0 -65
  39. package/src/config/schema/server.ts +0 -106
  40. package/src/config/schema/source.ts +0 -34
  41. package/src/config/schema/tools.ts +0 -15
  42. package/src/context.ts +0 -46
  43. package/src/index.ts +0 -277
  44. package/src/initWatcher.ts +0 -77
  45. package/src/loadEnv.ts +0 -23
  46. package/src/loadPlugins.ts +0 -91
  47. package/src/types.d.ts +0 -0
  48. package/src/utils/commander.ts +0 -22
  49. package/src/utils/repeatKeyWarning.ts +0 -29
@@ -1,106 +0,0 @@
1
- import { ENTRY_NAME_PATTERN } from '@modern-js/utils';
2
-
3
- const SERVER_ROUTE_OBJECT = {
4
- type: 'object',
5
- properties: {
6
- path: { type: 'string' },
7
- headers: { type: 'object' },
8
- },
9
- additionalProperties: false,
10
- };
11
-
12
- export const server = {
13
- type: 'object',
14
- additionalProperties: false,
15
- properties: {
16
- port: { type: 'number' },
17
- ssr: {
18
- if: { type: 'object' },
19
- then: {
20
- properties: {
21
- disableLoadable: { type: 'boolean' },
22
- disableHelmet: { type: 'boolean' },
23
- disableRedirect: { type: 'boolean' },
24
- enableAsyncData: { type: 'boolean' },
25
- enableProductWarning: { type: 'boolean' },
26
- timeout: { type: 'number' },
27
- asyncDataTimeout: { type: 'number' },
28
- },
29
- },
30
- else: { type: 'boolean' },
31
- },
32
- ssrByEntries: {
33
- type: 'object',
34
- patternProperties: {
35
- [ENTRY_NAME_PATTERN]: {
36
- if: { type: 'object' },
37
- then: {
38
- properties: {
39
- disableLoadable: { type: 'boolean' },
40
- disableHelmet: { type: 'boolean' },
41
- disableRedirect: { type: 'boolean' },
42
- enableProductWarning: { type: 'boolean' },
43
- enableAsyncData: { type: 'boolean' },
44
- timeout: { type: 'number' },
45
- asyncDataTimeout: { type: 'number' },
46
- },
47
- additionalProperties: false,
48
- },
49
- else: { type: 'boolean' },
50
- },
51
- },
52
- },
53
- routes: {
54
- type: 'object',
55
- patternProperties: {
56
- [ENTRY_NAME_PATTERN]: {
57
- if: { type: 'object' },
58
- then: {
59
- properties: {
60
- route: {
61
- oneOf: [
62
- { type: 'string' },
63
- {
64
- type: 'array',
65
- items: { oneOf: [{ type: 'string' }, SERVER_ROUTE_OBJECT] },
66
- },
67
- SERVER_ROUTE_OBJECT,
68
- ],
69
- },
70
- disableSpa: { type: 'boolean' },
71
- },
72
- additionalProperties: false,
73
- },
74
- else: {
75
- oneOf: [
76
- { type: 'string' },
77
- {
78
- type: 'array',
79
- items: { type: 'string' },
80
- },
81
- ],
82
- },
83
- },
84
- },
85
- },
86
- publicRoutes: {
87
- type: 'object',
88
- patternProperties: { [ENTRY_NAME_PATTERN]: { type: ['string'] } },
89
- },
90
- baseUrl: {
91
- oneOf: [
92
- { type: 'string' },
93
- {
94
- type: 'array',
95
- items: [{ type: 'string' }],
96
- },
97
- ],
98
- },
99
- middleware: { instanceof: ['Array', 'Function'] },
100
- renderHook: { instanceof: 'Function' },
101
- logger: { type: 'object' },
102
- metrics: { type: 'object' },
103
- proxy: { type: 'object' },
104
- enableMicroFrontendDebug: { type: 'boolean' },
105
- },
106
- };
@@ -1,34 +0,0 @@
1
- import { ENTRY_NAME_PATTERN } from '@modern-js/utils';
2
-
3
- export const source = {
4
- type: 'object',
5
- additionalProperties: false,
6
- properties: {
7
- entries: {
8
- type: 'object',
9
- patternProperties: {
10
- [ENTRY_NAME_PATTERN]: {
11
- if: { type: 'object' },
12
- then: {
13
- required: ['entry'],
14
- properties: {
15
- entry: { type: ['string', 'array'] },
16
- disableMount: { type: 'boolean' },
17
- enableFileSystemRoutes: { type: 'boolean' },
18
- },
19
- additionalProperties: false,
20
- },
21
- else: { type: ['string', 'array'] },
22
- },
23
- },
24
- },
25
- alias: { typeof: ['object', 'function'] },
26
- disableDefaultEntries: { type: 'boolean' },
27
- envVars: { type: 'array' },
28
- globalVars: { type: 'object' },
29
- moduleScopes: { instanceof: ['Array', 'Function'] },
30
- entriesDir: { type: 'string' },
31
- configDir: { type: 'string' },
32
- include: { type: ['array'] },
33
- },
34
- };
@@ -1,15 +0,0 @@
1
- export const tools = {
2
- type: 'object',
3
- additionalProperties: false,
4
- properties: {
5
- webpack: { typeof: ['object', 'function'] },
6
- babel: { typeof: ['object', 'function'] },
7
- postcss: { typeof: ['object', 'function'] },
8
- lodash: { typeof: ['object', 'function'] },
9
- devServer: { type: 'object' },
10
- tsLoader: { typeof: ['object', 'function'] },
11
- autoprefixer: { typeof: ['object', 'function'] },
12
- terser: { typeof: ['object', 'function'] },
13
- minifyCss: { typeof: ['object', 'function'] },
14
- },
15
- };
package/src/context.ts DELETED
@@ -1,46 +0,0 @@
1
- import path from 'path';
2
- import { createContext } from '@modern-js/plugin';
3
- import address from 'address';
4
- import type { IAppContext } from '@modern-js/types';
5
- import { UserConfig } from './config';
6
- import { NormalizedConfig } from './config/mergeConfig';
7
-
8
- export type { IAppContext };
9
-
10
- export const AppContext = createContext<IAppContext>({} as IAppContext);
11
-
12
- export const ConfigContext = createContext<UserConfig>({} as UserConfig);
13
-
14
- export const ResolvedConfigContext = createContext<NormalizedConfig>(
15
- {} as NormalizedConfig,
16
- );
17
-
18
- export const useAppContext = () => AppContext.use().value;
19
-
20
- export const useConfigContext = () => ConfigContext.use().value;
21
-
22
- export const useResolvedConfigContext = () => ResolvedConfigContext.use().value;
23
-
24
- export const initAppContext = (
25
- appDirectory: string,
26
- plugins: Array<{
27
- cli: any;
28
- server: any;
29
- }>,
30
- configFile: string | false,
31
- ): IAppContext => ({
32
- appDirectory,
33
- configFile,
34
- ip: address.ip(),
35
- port: 0,
36
- packageName: require(path.resolve(appDirectory, './package.json')).name,
37
- srcDirectory: path.resolve(appDirectory, './src'),
38
- distDirectory: '',
39
- sharedDirectory: path.resolve(appDirectory, './shared'),
40
- nodeModulesDirectory: path.resolve(appDirectory, './node_modules'),
41
- internalDirectory: path.resolve(appDirectory, './node_modules/.modern-js'),
42
- plugins,
43
- htmlTemplates: {},
44
- serverRoutes: [],
45
- entrypoints: [],
46
- });
package/src/index.ts DELETED
@@ -1,277 +0,0 @@
1
- import path from 'path';
2
- import {
3
- compatRequire,
4
- pkgUp,
5
- ensureAbsolutePath,
6
- logger,
7
- INTERNAL_PLUGINS,
8
- } from '@modern-js/utils';
9
- import {
10
- createAsyncManager,
11
- createAsyncWorkflow,
12
- createParallelWorkflow,
13
- ParallelWorkflow,
14
- AsyncWorkflow,
15
- Progresses2Runners,
16
- createAsyncWaterfall,
17
- AsyncWaterfall,
18
- } from '@modern-js/plugin';
19
- import { enable } from '@modern-js/plugin/node';
20
-
21
- import type { Hooks } from '@modern-js/types';
22
- import { program, Command } from './utils/commander';
23
- import {
24
- resolveConfig,
25
- defineConfig,
26
- loadUserConfig,
27
- UserConfig,
28
- ToolsConfig,
29
- } from './config';
30
- import { loadPlugins } from './loadPlugins';
31
- import {
32
- AppContext,
33
- ConfigContext,
34
- IAppContext,
35
- initAppContext,
36
- ResolvedConfigContext,
37
- useAppContext,
38
- useConfigContext,
39
- useResolvedConfigContext,
40
- } from './context';
41
- import { initWatcher } from './initWatcher';
42
- import { NormalizedConfig } from './config/mergeConfig';
43
- import { loadEnv } from './loadEnv';
44
-
45
- export type { Hooks };
46
- export { defaultsConfig, mergeConfig } from './config';
47
-
48
- export * from '@modern-js/plugin';
49
- export * from '@modern-js/plugin/node';
50
-
51
- program
52
- .name('modern')
53
- .usage('<command> [options]')
54
- .version(process.env.MODERN_JS_VERSION || '0.1.0');
55
-
56
- export type HooksRunner = Progresses2Runners<{
57
- config: ParallelWorkflow<void>;
58
- resolvedConfig: AsyncWaterfall<{
59
- resolved: NormalizedConfig;
60
- }>;
61
- validateSchema: ParallelWorkflow<void>;
62
- prepare: AsyncWorkflow<void, void>;
63
- commands: AsyncWorkflow<
64
- {
65
- program: Command;
66
- },
67
- void
68
- >;
69
- watchFiles: ParallelWorkflow<void>;
70
- fileChange: AsyncWorkflow<
71
- {
72
- filename: string;
73
- },
74
- void
75
- >;
76
- beforeExit: AsyncWorkflow<void, void>;
77
- }>;
78
-
79
- const hooksMap = {
80
- config: createParallelWorkflow(),
81
- resolvedConfig: createAsyncWaterfall<{
82
- resolved: NormalizedConfig;
83
- }>(),
84
- validateSchema: createParallelWorkflow(),
85
- // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
86
- prepare: createAsyncWorkflow<void, void>(),
87
- commands: createAsyncWorkflow<
88
- {
89
- program: Command;
90
- },
91
- // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
92
- void
93
- >(),
94
- watchFiles: createParallelWorkflow(),
95
- fileChange: createAsyncWorkflow<
96
- {
97
- filename: string;
98
- },
99
- // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
100
- void
101
- >(),
102
- // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
103
- beforeExit: createAsyncWorkflow<void, void>(),
104
- };
105
-
106
- export const manager = createAsyncManager<Hooks, typeof hooksMap>(hooksMap);
107
-
108
- export const {
109
- createPlugin,
110
- registe: registerHook,
111
- useRunner: mountHook,
112
- } = manager;
113
-
114
- export const usePlugins = (plugins: string[]) =>
115
- plugins.forEach(plugin =>
116
- manager.usePlugin(compatRequire(require.resolve(plugin))),
117
- );
118
-
119
- export {
120
- defineConfig,
121
- AppContext,
122
- ResolvedConfigContext,
123
- useAppContext,
124
- useConfigContext,
125
- useResolvedConfigContext,
126
- ConfigContext,
127
- };
128
-
129
- export type { NormalizedConfig, IAppContext, UserConfig, ToolsConfig };
130
-
131
- const initAppDir = async (): Promise<string> => {
132
- const pkg = await pkgUp({ cwd: process.cwd() });
133
-
134
- if (!pkg) {
135
- throw new Error(
136
- `no package.json found in current work dir: ${process.cwd()}`,
137
- );
138
- }
139
-
140
- return path.dirname(pkg);
141
- };
142
-
143
- export interface CoreOptions {
144
- configFile?: string;
145
- plugins?: typeof INTERNAL_PLUGINS;
146
- beforeUsePlugins: (
147
- plugins: any,
148
- config: any,
149
- ) => { cli: any; cliPath: any; server: any; serverPath: any }[];
150
- }
151
-
152
- const createCli = () => {
153
- let hooksRunner: HooksRunner;
154
- let isRestart = false;
155
-
156
- const init = async (argv: string[] = [], options?: CoreOptions) => {
157
- enable();
158
-
159
- manager.clear();
160
-
161
- const appDirectory = await initAppDir();
162
-
163
- loadEnv(appDirectory);
164
-
165
- const loaded = await loadUserConfig(appDirectory, options?.configFile);
166
-
167
- let plugins = loadPlugins(
168
- appDirectory,
169
- loaded.config.plugins || [],
170
- options?.plugins,
171
- );
172
-
173
- if (options?.beforeUsePlugins) {
174
- plugins = options.beforeUsePlugins(plugins, loaded.config);
175
- }
176
-
177
- plugins.forEach(plugin => plugin.cli && manager.usePlugin(plugin.cli));
178
-
179
- const appContext = initAppContext(appDirectory, plugins, loaded.filePath);
180
-
181
- manager.run(() => {
182
- ConfigContext.set(loaded.config);
183
- AppContext.set(appContext);
184
- });
185
-
186
- hooksRunner = await manager.init();
187
-
188
- ['SIGINT', 'SIGTERM', 'unhandledRejection', 'uncaughtException'].forEach(
189
- event => {
190
- process.on(event, async err => {
191
- await hooksRunner.beforeExit();
192
- if (err instanceof Error) {
193
- logger.error(err.stack);
194
- }
195
- process.nextTick(() => {
196
- // eslint-disable-next-line no-process-exit
197
- process.exit(1);
198
- });
199
- });
200
- },
201
- );
202
-
203
- const extraConfigs = await hooksRunner.config();
204
-
205
- const extraSchemas = await hooksRunner.validateSchema();
206
-
207
- const config = await resolveConfig(
208
- loaded,
209
- extraConfigs as any,
210
- extraSchemas as any,
211
- isRestart,
212
- argv,
213
- );
214
-
215
- const { resolved } = await hooksRunner.resolvedConfig({
216
- resolved: config,
217
- });
218
-
219
- // update context value
220
- manager.run(() => {
221
- ConfigContext.set(loaded.config);
222
- ResolvedConfigContext.set(resolved);
223
- AppContext.set({
224
- ...appContext,
225
- port: resolved.server.port!,
226
- distDirectory: ensureAbsolutePath(appDirectory, resolved.output.path!),
227
- });
228
- });
229
-
230
- await hooksRunner.prepare();
231
-
232
- return { loadedConfig: loaded, appContext, resolved };
233
- };
234
-
235
- async function run(argv: string[], options?: CoreOptions) {
236
- const { loadedConfig, appContext, resolved } = await init(argv, options);
237
-
238
- await hooksRunner.commands({ program });
239
-
240
- initWatcher(
241
- loadedConfig,
242
- appContext.appDirectory,
243
- resolved.source.configDir,
244
- hooksRunner,
245
- argv,
246
- );
247
- manager.run(() => program.parse(process.argv));
248
- }
249
-
250
- async function restart() {
251
- isRestart = true;
252
-
253
- logger.info('Restart...\n');
254
-
255
- let hasGetError = false;
256
- try {
257
- await init(process.argv.slice(2));
258
- } catch (err) {
259
- console.error(err);
260
- hasGetError = true;
261
- } finally {
262
- if (!hasGetError) {
263
- manager.run(() => program.parse(process.argv));
264
- }
265
- }
266
- }
267
-
268
- return {
269
- init,
270
- run,
271
- restart,
272
- };
273
- };
274
-
275
- export const cli = createCli();
276
-
277
- export { loadUserConfig, initAppDir, initAppContext };
@@ -1,77 +0,0 @@
1
- import crypto from 'crypto';
2
- import fs from 'fs';
3
- import path from 'path';
4
- import { isDev, createDebugger } from '@modern-js/utils';
5
- import chokidar from 'chokidar';
6
- import { LoadedConfig } from './config';
7
- import { HooksRunner } from '.';
8
-
9
- const debug = createDebugger('watch-files');
10
-
11
- const md5 = (data: string) =>
12
- crypto.createHash('md5').update(data).digest('hex');
13
-
14
- const hashMap = new Map<string, string>();
15
-
16
- export const initWatcher = async (
17
- loaded: LoadedConfig,
18
- appDirectory: string,
19
- configDir: string | undefined,
20
- hooksRunner: HooksRunner,
21
- argv: string[],
22
- // eslint-disable-next-line max-params
23
- ) => {
24
- // only add fs watcher on dev mode.
25
- if (isDev() && argv[0] === 'dev') {
26
- const extraFiles = await hooksRunner.watchFiles();
27
-
28
- const configPath = path.join(appDirectory, configDir!);
29
-
30
- const watched = [
31
- `${configPath}/html`,
32
- ...(extraFiles as any),
33
- loaded?.filePath,
34
- ...loaded.dependencies,
35
- ].filter(Boolean);
36
-
37
- debug(`watched: %o`, watched);
38
-
39
- const watcher = chokidar.watch(watched, {
40
- cwd: appDirectory,
41
- ignorePermissionErrors: true,
42
- ignored: [
43
- /node_modules/,
44
- '**/__test__/**',
45
- '**/*.test.(js|jsx|ts|tsx)',
46
- '**/*.spec.(js|jsx|ts|tsx)',
47
- '**/*.stories.(js|jsx|ts|tsx)',
48
- ],
49
- });
50
-
51
- watcher.on('change', changed => {
52
- const lastHash = hashMap.get(changed);
53
- const currentHash = md5(
54
- fs.readFileSync(path.join(appDirectory, changed), 'utf8'),
55
- );
56
- if (currentHash !== lastHash) {
57
- debug(`file change: %s`, changed);
58
-
59
- hashMap.set(changed, currentHash);
60
-
61
- hooksRunner.fileChange({ filename: changed });
62
- }
63
- });
64
-
65
- watcher.on('unlink', name => {
66
- debug(`remove file: %s`, name);
67
-
68
- if (hashMap.has(name)) {
69
- hashMap.delete(name);
70
- }
71
- });
72
-
73
- watcher.on('error', err => {
74
- throw err;
75
- });
76
- }
77
- };
package/src/loadEnv.ts DELETED
@@ -1,23 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import dotenv from 'dotenv';
4
- import dotenvExpand from 'dotenv-expand';
5
-
6
- export const loadEnv = (
7
- appDirectory: string,
8
- mode: string = process.env.NODE_ENV as string,
9
- ) => {
10
- // Don't change the order of the filenames, since they are ordered by the priority.
11
- // Files on the left have more priority than files on the right.
12
- [`.env.${mode}.local`, '.env.local', `.env.${mode}`, '.env']
13
- .map(name => path.resolve(appDirectory, name))
14
- .filter(
15
- filePath =>
16
- fs.existsSync(filePath) && !fs.statSync(filePath).isDirectory(),
17
- )
18
- .forEach(filePath => {
19
- const envConfig = dotenv.config({ path: filePath });
20
-
21
- dotenvExpand(envConfig);
22
- });
23
- };
@@ -1,91 +0,0 @@
1
- import {
2
- isDepExists,
3
- createDebugger,
4
- compatRequire,
5
- INTERNAL_PLUGINS,
6
- } from '@modern-js/utils';
7
-
8
- const debug = createDebugger('load-plugins');
9
-
10
- export interface PluginConfigItem {
11
- cli?: string;
12
- server?: string;
13
- }
14
-
15
- export type PluginConfig = Array<PluginConfigItem>;
16
-
17
- /**
18
- * Try to resolve plugin entry file path.
19
- * @param appDirectory - Application root directory.
20
- * @param plugin - Plugin name or plugin name with options.
21
- * @returns Resolved file path.
22
- */
23
- const resolvePlugin = (appDirectory: string, plugin: PluginConfigItem) => {
24
- const tryResolve = (name: string) => {
25
- let filePath = '';
26
- try {
27
- filePath = require.resolve(name, { paths: [appDirectory] });
28
- delete require.cache[filePath];
29
- } catch (err) {
30
- if ((err as any).code === 'MODULE_NOT_FOUND') {
31
- throw new Error(`Can not find plugin ${name}.`);
32
- }
33
- throw err;
34
- }
35
- return filePath;
36
- };
37
-
38
- const resolved: PluginConfigItem = {};
39
-
40
- if (typeof plugin === 'string' || plugin.cli) {
41
- resolved.cli =
42
- typeof plugin === 'string' ? tryResolve(plugin) : tryResolve(plugin.cli!);
43
- }
44
-
45
- if (plugin.server) {
46
- resolved.server = tryResolve(plugin.server);
47
- }
48
-
49
- return resolved;
50
- };
51
-
52
- /**
53
- * Load internal plugins which in @modern-js scope and user's custom plugins.
54
- * @param appDirectory - Application root directory.
55
- * @param pluginsConfig - Plugins declared in the user configuration.
56
- * @returns Plugin Objects has been required.
57
- */
58
- export const loadPlugins = (
59
- appDirectory: string,
60
- pluginConfig: PluginConfig,
61
- internalPlugins?: typeof INTERNAL_PLUGINS,
62
- ) => {
63
- const plugins = [
64
- ...Object.keys(internalPlugins || INTERNAL_PLUGINS)
65
- .filter(name => isDepExists(appDirectory, name))
66
- .map(name => (internalPlugins || INTERNAL_PLUGINS)[name]),
67
- ...pluginConfig,
68
- ];
69
-
70
- return plugins.map(plugin => {
71
- const { cli, server } = resolvePlugin(appDirectory, plugin);
72
-
73
- debug(`resolve plugin %s: %s`, plugin, {
74
- cli,
75
- server,
76
- });
77
-
78
- const cliPlugin = cli && { ...compatRequire(cli), pluginPath: cli };
79
- const serverPlugin = server && {
80
- ...compatRequire(server),
81
- pluginPath: server,
82
- };
83
-
84
- return {
85
- cli: cliPlugin,
86
- cliPath: typeof plugin === 'string' ? plugin : plugin.cli,
87
- server: serverPlugin,
88
- serverPath: typeof plugin === 'string' ? undefined : plugin.server,
89
- };
90
- });
91
- };
package/src/types.d.ts DELETED
File without changes
@@ -1,22 +0,0 @@
1
- import { program, Command } from 'commander';
2
-
3
- declare module 'commander' {
4
- interface Command {
5
- commandsMap: Map<string, Command>;
6
- }
7
- }
8
-
9
- if (!program.hasOwnProperty('commandsMap')) {
10
- Object.defineProperty(program, 'commandsMap', {
11
- get() {
12
- const map = new Map<string, Command>();
13
- for (const command of program.commands) {
14
- map.set((command as any)._name, command);
15
- }
16
- return map;
17
- },
18
- configurable: false,
19
- });
20
- }
21
-
22
- export { program, Command };