@modern-js/core 1.7.0 → 1.8.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/CHANGELOG.md +25 -0
- package/dist/js/modern/config/types/electron.js +1 -0
- package/dist/js/modern/context.js +1 -1
- package/dist/js/modern/index.js +2 -1
- package/dist/js/modern/loadPlugins.js +9 -4
- package/dist/js/modern/utils/commander.js +1 -1
- package/dist/js/node/config/types/electron.js +5 -0
- package/dist/js/node/context.js +1 -1
- package/dist/js/node/index.js +2 -1
- package/dist/js/node/loadPlugins.js +9 -4
- package/dist/types/config/types/electron.d.ts +13 -0
- package/dist/types/config/types/index.d.ts +14 -1
- package/dist/types/index.d.ts +9 -1
- package/dist/types/loadPlugins.d.ts +3 -0
- package/dist/types/manager.d.ts +8 -7
- package/dist/types/utils/commander.d.ts +2 -6
- package/package.json +7 -6
- package/tests/.eslintrc.js +0 -6
- package/tests/btsm.test.ts +0 -20
- package/tests/config.test.ts +0 -146
- package/tests/context.test.ts +0 -85
- package/tests/fixtures/index-test/modern.server-runtime.config.js +0 -0
- package/tests/fixtures/index-test/package.json +0 -3
- package/tests/fixtures/load-plugin/not-found/package.json +0 -3
- package/tests/fixtures/load-plugin/not-found/test-plugin-a.js +0 -1
- package/tests/fixtures/load-plugin/user-plugins/package.json +0 -3
- package/tests/fixtures/load-plugin/user-plugins/test-plugin-a.js +0 -1
- package/tests/fixtures/load-plugin/user-plugins/test-plugin-b.js +0 -3
- package/tests/fixtures/load-plugin/user-plugins/test-plugin-c.js +0 -3
- package/tests/index.test.ts +0 -83
- package/tests/initWatcher.test.ts +0 -63
- package/tests/loadEnv.test.ts +0 -173
- package/tests/loadPlugin.test.ts +0 -116
- package/tests/mergeConfig.test.ts +0 -97
- package/tests/pluginAPI.test.ts +0 -19
- package/tests/repeatKeyWarning.test.ts +0 -68
- package/tests/schema.test.ts +0 -107
- package/tests/tsconfig.json +0 -11
- package/tests/utils.test.ts +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @modern-js/core
|
|
2
2
|
|
|
3
|
+
## 1.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a4330c73: fix: electron config type && electron generator template
|
|
8
|
+
- 3bf4f8b0: feat: support start api server only
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- 04ae5262: chore: bump @modern-js/utils to v1.4.1 in dependencies
|
|
13
|
+
- 60f7d8bf: feat: add tests dir to npmignore
|
|
14
|
+
- e4cec1ce: types: fix config hook type
|
|
15
|
+
- 3b7aa8bb: feat: add transformPlugin option for legacy plugins
|
|
16
|
+
- 5dbbeb57: fix: export extended Command type
|
|
17
|
+
- ebfcbb35: chore: bump better-ajv-errors 1.2.0
|
|
18
|
+
- 305e0bb4: fix: commander.commandsMap typing not work
|
|
19
|
+
- Updated dependencies [b8599d09]
|
|
20
|
+
- Updated dependencies [6cffe99d]
|
|
21
|
+
- Updated dependencies [04ae5262]
|
|
22
|
+
- Updated dependencies [60f7d8bf]
|
|
23
|
+
- Updated dependencies [3bf4f8b0]
|
|
24
|
+
- @modern-js/utils@1.5.0
|
|
25
|
+
- @modern-js/load-config@1.3.1
|
|
26
|
+
- @modern-js/plugin@1.3.3
|
|
27
|
+
|
|
3
28
|
## 1.7.0
|
|
4
29
|
|
|
5
30
|
### Minor Changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -56,7 +56,7 @@ export const initAppContext = ({
|
|
|
56
56
|
serverRoutes: [],
|
|
57
57
|
entrypoints: [],
|
|
58
58
|
checkedEntries: [],
|
|
59
|
-
|
|
59
|
+
apiOnly: false,
|
|
60
60
|
internalDirAlias: `@_${metaName.replace(/-/g, '_')}_internal`,
|
|
61
61
|
internalSrcAlias: `@_${metaName.replace(/-/g, '_')}_src`
|
|
62
62
|
};
|
package/dist/js/modern/index.js
CHANGED
|
@@ -66,7 +66,8 @@ const createCli = () => {
|
|
|
66
66
|
loadEnv(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
|
|
67
67
|
const loaded = await loadUserConfig(appDirectory, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.configFile, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.packageJsonConfig);
|
|
68
68
|
const plugins = loadPlugins(appDirectory, loaded.config, {
|
|
69
|
-
internalPlugins: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.plugins
|
|
69
|
+
internalPlugins: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.plugins,
|
|
70
|
+
transformPlugin: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.transformPlugin
|
|
70
71
|
});
|
|
71
72
|
plugins.forEach(plugin => plugin.cli && manager.usePlugin(plugin.cli));
|
|
72
73
|
const appContext = initAppContext({
|
|
@@ -42,13 +42,17 @@ export function getAppPlugins(appDirectory, oldPluginConfig, internalPlugins) {
|
|
|
42
42
|
return appPlugins;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
const resolveCliPlugin = (p, appDirectory) => {
|
|
45
|
+
const resolveCliPlugin = (p, userConfig, appDirectory, transformPlugin) => {
|
|
46
46
|
const pkg = typeof p === 'string' ? p : p[0];
|
|
47
|
+
const pluginOptions = typeof p === 'string' ? undefined : p[1];
|
|
47
48
|
const path = tryResolve(pkg, appDirectory);
|
|
48
|
-
|
|
49
|
+
let module = compatRequire(path);
|
|
50
|
+
|
|
51
|
+
if (transformPlugin) {
|
|
52
|
+
module = transformPlugin(module, userConfig, pluginOptions);
|
|
53
|
+
}
|
|
49
54
|
|
|
50
55
|
if (typeof module === 'function') {
|
|
51
|
-
const pluginOptions = Array.isArray(p) ? p[1] : undefined;
|
|
52
56
|
const result = module(pluginOptions);
|
|
53
57
|
return createPlugin(result.setup, result);
|
|
54
58
|
}
|
|
@@ -68,6 +72,7 @@ const isOldPluginConfig = config => Array.isArray(config) && config.some(item =>
|
|
|
68
72
|
* @param appDirectory - Application root directory.
|
|
69
73
|
* @param userConfig - Resolved user config.
|
|
70
74
|
* @param options.internalPlugins - Internal plugins.
|
|
75
|
+
* @param options.transformPlugin - transform plugin before using it. Used for compatible with legacy jupiter plugins.
|
|
71
76
|
* @returns Plugin Objects has been required.
|
|
72
77
|
*/
|
|
73
78
|
|
|
@@ -87,7 +92,7 @@ export const loadPlugins = (appDirectory, userConfig, options = {}) => {
|
|
|
87
92
|
const loadedPlugin = {};
|
|
88
93
|
|
|
89
94
|
if (cli) {
|
|
90
|
-
loadedPlugin.cli = resolveCliPlugin(cli, appDirectory);
|
|
95
|
+
loadedPlugin.cli = resolveCliPlugin(cli, userConfig, appDirectory, options.transformPlugin);
|
|
91
96
|
} // server plugins don't support to accept params
|
|
92
97
|
|
|
93
98
|
|
package/dist/js/node/context.js
CHANGED
package/dist/js/node/index.js
CHANGED
|
@@ -215,7 +215,8 @@ const createCli = () => {
|
|
|
215
215
|
(0, _loadEnv.loadEnv)(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
|
|
216
216
|
const loaded = await (0, _config.loadUserConfig)(appDirectory, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.configFile, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.packageJsonConfig);
|
|
217
217
|
const plugins = (0, _loadPlugins.loadPlugins)(appDirectory, loaded.config, {
|
|
218
|
-
internalPlugins: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.plugins
|
|
218
|
+
internalPlugins: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.plugins,
|
|
219
|
+
transformPlugin: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.transformPlugin
|
|
219
220
|
});
|
|
220
221
|
plugins.forEach(plugin => plugin.cli && _manager.manager.usePlugin(plugin.cli));
|
|
221
222
|
const appContext = (0, _context.initAppContext)({
|
|
@@ -52,13 +52,17 @@ function getAppPlugins(appDirectory, oldPluginConfig, internalPlugins) {
|
|
|
52
52
|
return appPlugins;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
const resolveCliPlugin = (p, appDirectory) => {
|
|
55
|
+
const resolveCliPlugin = (p, userConfig, appDirectory, transformPlugin) => {
|
|
56
56
|
const pkg = typeof p === 'string' ? p : p[0];
|
|
57
|
+
const pluginOptions = typeof p === 'string' ? undefined : p[1];
|
|
57
58
|
const path = tryResolve(pkg, appDirectory);
|
|
58
|
-
|
|
59
|
+
let module = (0, _utils.compatRequire)(path);
|
|
60
|
+
|
|
61
|
+
if (transformPlugin) {
|
|
62
|
+
module = transformPlugin(module, userConfig, pluginOptions);
|
|
63
|
+
}
|
|
59
64
|
|
|
60
65
|
if (typeof module === 'function') {
|
|
61
|
-
const pluginOptions = Array.isArray(p) ? p[1] : undefined;
|
|
62
66
|
const result = module(pluginOptions);
|
|
63
67
|
return (0, _manager.createPlugin)(result.setup, result);
|
|
64
68
|
}
|
|
@@ -78,6 +82,7 @@ const isOldPluginConfig = config => Array.isArray(config) && config.some(item =>
|
|
|
78
82
|
* @param appDirectory - Application root directory.
|
|
79
83
|
* @param userConfig - Resolved user config.
|
|
80
84
|
* @param options.internalPlugins - Internal plugins.
|
|
85
|
+
* @param options.transformPlugin - transform plugin before using it. Used for compatible with legacy jupiter plugins.
|
|
81
86
|
* @returns Plugin Objects has been required.
|
|
82
87
|
*/
|
|
83
88
|
|
|
@@ -97,7 +102,7 @@ const loadPlugins = (appDirectory, userConfig, options = {}) => {
|
|
|
97
102
|
const loadedPlugin = {};
|
|
98
103
|
|
|
99
104
|
if (cli) {
|
|
100
|
-
loadedPlugin.cli = resolveCliPlugin(cli, appDirectory);
|
|
105
|
+
loadedPlugin.cli = resolveCliPlugin(cli, userConfig, appDirectory, options.transformPlugin);
|
|
101
106
|
} // server plugins don't support to accept params
|
|
102
107
|
|
|
103
108
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TransformOptions } from '@babel/core';
|
|
2
|
+
import { Configuration } from 'electron-builder';
|
|
3
|
+
export declare type BuildConfig = {
|
|
4
|
+
baseConfig: Configuration;
|
|
5
|
+
macConfig?: Configuration;
|
|
6
|
+
winConfig?: Configuration;
|
|
7
|
+
win64Config?: Configuration;
|
|
8
|
+
linuxConfig?: Configuration;
|
|
9
|
+
};
|
|
10
|
+
export declare type ElectronConfig = {
|
|
11
|
+
builder?: BuildConfig;
|
|
12
|
+
babel?: TransformOptions | ((defaultBabelConfig: TransformOptions) => TransformOptions);
|
|
13
|
+
};
|
|
@@ -3,6 +3,7 @@ import type { IncomingMessage, ServerResponse } from 'http';
|
|
|
3
3
|
import type { NextFunction, BffProxyOptions } from '@modern-js/types';
|
|
4
4
|
import type { MetaOptions } from '@modern-js/utils';
|
|
5
5
|
import type { TransformOptions } from '@babel/core';
|
|
6
|
+
import type webpack from 'webpack';
|
|
6
7
|
import type { Configuration as WebpackConfiguration } from 'webpack';
|
|
7
8
|
import autoprefixer from 'autoprefixer';
|
|
8
9
|
import type { BasePluginOptions, TerserOptions as RawTerserOptions } from 'terser-webpack-plugin';
|
|
@@ -12,6 +13,7 @@ import type { SassConfig, SassLoaderOptions } from './sass';
|
|
|
12
13
|
import type { LessConfig, LessLoaderOptions } from './less';
|
|
13
14
|
import type { UnbundleConfig } from './unbundle';
|
|
14
15
|
import type { SSGConfig, SSGRouteOptions, SSGMultiEntryOptions, SSGSingleEntryOptions } from './ssg';
|
|
16
|
+
import { ElectronConfig } from './electron';
|
|
15
17
|
declare type AutoprefixerOptions = autoprefixer.Options;
|
|
16
18
|
declare type TerserOptions = BasePluginOptions & RawTerserOptions;
|
|
17
19
|
export type { TestConfig, JestConfig, UnbundleConfig, SassConfig, SassLoaderOptions, LessConfig, LessLoaderOptions, SSGConfig, SSGRouteOptions, SSGMultiEntryOptions, SSGSingleEntryOptions, TransformOptions, AutoprefixerOptions, TerserOptions };
|
|
@@ -149,7 +151,11 @@ export declare type DevServerConfig = {
|
|
|
149
151
|
after?: RequestHandler[];
|
|
150
152
|
[propsName: string]: any;
|
|
151
153
|
};
|
|
152
|
-
export declare type WebpackConfig = WebpackConfiguration | ((config: WebpackConfiguration, utils
|
|
154
|
+
export declare type WebpackConfig = WebpackConfiguration | ((config: WebpackConfiguration, utils: {
|
|
155
|
+
env: string;
|
|
156
|
+
webpack: typeof webpack;
|
|
157
|
+
[key: string]: any;
|
|
158
|
+
}) => WebpackConfiguration | void);
|
|
153
159
|
export declare type BabelConfig = TransformOptions | ((config: TransformOptions, utils?: any) => TransformOptions | void);
|
|
154
160
|
export declare type AutoprefixerConfig = AutoprefixerOptions | ((config: AutoprefixerOptions) => AutoprefixerOptions | void);
|
|
155
161
|
export declare type TerserConfig = TerserOptions | ((config: TerserOptions) => TerserOptions | void);
|
|
@@ -228,6 +234,13 @@ export interface UserConfig {
|
|
|
228
234
|
*/
|
|
229
235
|
|
|
230
236
|
testing?: TestConfig;
|
|
237
|
+
/**
|
|
238
|
+
* The configuration of `electron` is provided by plugin `@modern-js/plugin-electron`.
|
|
239
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
240
|
+
* @requires `@modern-js/plugin-electron`
|
|
241
|
+
*/
|
|
242
|
+
|
|
243
|
+
electron?: ElectronConfig;
|
|
231
244
|
}
|
|
232
245
|
export declare type ConfigParam = UserConfig | Promise<UserConfig> | ((env: any) => UserConfig | Promise<UserConfig>);
|
|
233
246
|
export interface LoadedConfig {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { INTERNAL_PLUGINS } from '@modern-js/utils';
|
|
2
2
|
import type { Hooks } from '@modern-js/types';
|
|
3
3
|
import { ErrorObject } from 'ajv';
|
|
4
|
+
import { TransformPlugin } from './loadPlugins';
|
|
4
5
|
import { IAppContext, initAppContext } from './context';
|
|
5
6
|
import type { NormalizedConfig } from './config/mergeConfig';
|
|
6
7
|
export type { Hooks };
|
|
@@ -18,6 +19,7 @@ export interface CoreOptions {
|
|
|
18
19
|
serverConfigFile?: string;
|
|
19
20
|
packageJsonConfig?: string;
|
|
20
21
|
plugins?: typeof INTERNAL_PLUGINS;
|
|
22
|
+
transformPlugin?: TransformPlugin;
|
|
21
23
|
onSchemaError?: (error: ErrorObject) => void;
|
|
22
24
|
options?: {
|
|
23
25
|
metaName?: string;
|
|
@@ -36,6 +38,7 @@ export declare const mergeOptions: (options?: CoreOptions | undefined) => {
|
|
|
36
38
|
server?: string | undefined;
|
|
37
39
|
};
|
|
38
40
|
} | undefined;
|
|
41
|
+
transformPlugin?: TransformPlugin | undefined;
|
|
39
42
|
onSchemaError?: ((error: ErrorObject) => void) | undefined;
|
|
40
43
|
options?: {
|
|
41
44
|
metaName?: string | undefined;
|
|
@@ -53,4 +56,9 @@ export declare const cli: {
|
|
|
53
56
|
run: (argv: string[], options?: CoreOptions | undefined) => Promise<void>;
|
|
54
57
|
restart: () => Promise<void>;
|
|
55
58
|
};
|
|
56
|
-
export { initAppDir, initAppContext };
|
|
59
|
+
export { initAppDir, initAppContext };
|
|
60
|
+
declare module '@modern-js/utils/compiled/commander' {
|
|
61
|
+
interface Command {
|
|
62
|
+
commandsMap: Map<string, Command>;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -7,6 +7,7 @@ export declare type LoadedPlugin = {
|
|
|
7
7
|
server?: string;
|
|
8
8
|
serverPkg?: string;
|
|
9
9
|
};
|
|
10
|
+
export declare type TransformPlugin = (plugin: PluginConfig, resolvedConfig: UserConfig, pluginOptions?: any) => PluginConfig;
|
|
10
11
|
/**
|
|
11
12
|
* @deprecated
|
|
12
13
|
* Using NewPluginConfig insteand.
|
|
@@ -32,10 +33,12 @@ export declare function getAppPlugins(appDirectory: string, oldPluginConfig: Old
|
|
|
32
33
|
* @param appDirectory - Application root directory.
|
|
33
34
|
* @param userConfig - Resolved user config.
|
|
34
35
|
* @param options.internalPlugins - Internal plugins.
|
|
36
|
+
* @param options.transformPlugin - transform plugin before using it. Used for compatible with legacy jupiter plugins.
|
|
35
37
|
* @returns Plugin Objects has been required.
|
|
36
38
|
*/
|
|
37
39
|
|
|
38
40
|
export declare const loadPlugins: (appDirectory: string, userConfig: UserConfig, options?: {
|
|
39
41
|
internalPlugins?: typeof INTERNAL_PLUGINS;
|
|
42
|
+
transformPlugin?: TransformPlugin;
|
|
40
43
|
}) => LoadedPlugin[];
|
|
41
44
|
export {};
|
package/dist/types/manager.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ToThreads, ToRunners, AsyncSetup, PluginOptions, AsyncWorkflow, AsyncWaterfall, ParallelWorkflow } from '@modern-js/plugin';
|
|
2
|
-
import { Command } from '@modern-js/utils';
|
|
3
2
|
import type { Hooks } from '@modern-js/types';
|
|
3
|
+
import type { Command } from './utils/commander';
|
|
4
4
|
import type { NormalizedConfig } from './config/mergeConfig';
|
|
5
|
+
import type { UserConfig } from './config';
|
|
5
6
|
import { pluginAPI } from './pluginAPI';
|
|
6
7
|
export declare type HooksRunner = ToRunners<{
|
|
7
|
-
config: ParallelWorkflow<void>;
|
|
8
|
+
config: ParallelWorkflow<void, UserConfig>;
|
|
8
9
|
resolvedConfig: AsyncWaterfall<{
|
|
9
10
|
resolved: NormalizedConfig;
|
|
10
11
|
}>;
|
|
@@ -22,7 +23,7 @@ export declare type HooksRunner = ToRunners<{
|
|
|
22
23
|
beforeRestart: AsyncWorkflow<void, void>;
|
|
23
24
|
}>;
|
|
24
25
|
declare const baseHooks: {
|
|
25
|
-
config: ParallelWorkflow<void,
|
|
26
|
+
config: ParallelWorkflow<void, UserConfig>;
|
|
26
27
|
resolvedConfig: AsyncWaterfall<{
|
|
27
28
|
resolved: NormalizedConfig;
|
|
28
29
|
}>;
|
|
@@ -48,7 +49,7 @@ export declare type CliHookCallbacks = ToThreads<CliHooks>;
|
|
|
48
49
|
export declare const manager: import("@modern-js/plugin").AsyncManager<CliHooks, {
|
|
49
50
|
setAppContext: (value: import("@modern-js/types").IAppContext) => void;
|
|
50
51
|
useAppContext: () => import("@modern-js/types").IAppContext;
|
|
51
|
-
useConfigContext: () =>
|
|
52
|
+
useConfigContext: () => UserConfig;
|
|
52
53
|
useResolvedConfigContext: () => NormalizedConfig;
|
|
53
54
|
}>;
|
|
54
55
|
/** Plugin options of a cli plugin. */
|
|
@@ -57,17 +58,17 @@ export declare type CliPlugin = PluginOptions<CliHooks, AsyncSetup<CliHooks, typ
|
|
|
57
58
|
export declare const createPlugin: (setup?: AsyncSetup<CliHooks, {
|
|
58
59
|
setAppContext: (value: import("@modern-js/types").IAppContext) => void;
|
|
59
60
|
useAppContext: () => import("@modern-js/types").IAppContext;
|
|
60
|
-
useConfigContext: () =>
|
|
61
|
+
useConfigContext: () => UserConfig;
|
|
61
62
|
useResolvedConfigContext: () => NormalizedConfig;
|
|
62
63
|
}> | undefined, options?: PluginOptions<CliHooks, AsyncSetup<CliHooks, {
|
|
63
64
|
setAppContext: (value: import("@modern-js/types").IAppContext) => void;
|
|
64
65
|
useAppContext: () => import("@modern-js/types").IAppContext;
|
|
65
|
-
useConfigContext: () =>
|
|
66
|
+
useConfigContext: () => UserConfig;
|
|
66
67
|
useResolvedConfigContext: () => NormalizedConfig;
|
|
67
68
|
}>> | undefined) => import("@modern-js/plugin").AsyncPlugin<CliHooks, {
|
|
68
69
|
setAppContext: (value: import("@modern-js/types").IAppContext) => void;
|
|
69
70
|
useAppContext: () => import("@modern-js/types").IAppContext;
|
|
70
|
-
useConfigContext: () =>
|
|
71
|
+
useConfigContext: () => UserConfig;
|
|
71
72
|
useResolvedConfigContext: () => NormalizedConfig;
|
|
72
73
|
}>, registerHook: (newHooks: Partial<CliHooks>) => void, mountHook: () => ToRunners<CliHooks>;
|
|
73
74
|
export declare const usePlugins: (plugins: string[]) => void;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import { program } from '@modern-js/utils';
|
|
2
|
-
declare module '@modern-js/utils/compiled/commander' {
|
|
3
|
-
interface Command {
|
|
4
|
-
commandsMap: Map<string, Command>;
|
|
5
|
-
}
|
|
6
|
-
}
|
|
1
|
+
import { program, Command } from '@modern-js/utils';
|
|
7
2
|
export declare function initCommandsMap(): void;
|
|
3
|
+
export type { Command };
|
|
8
4
|
export { program };
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.8.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -42,20 +42,20 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@babel/code-frame": "^7.14.5",
|
|
44
44
|
"@babel/runtime": "^7",
|
|
45
|
-
"@modern-js/load-config": "^1.3.
|
|
46
|
-
"@modern-js/plugin": "^1.3.
|
|
47
|
-
"@modern-js/utils": "^1.
|
|
45
|
+
"@modern-js/load-config": "^1.3.1",
|
|
46
|
+
"@modern-js/plugin": "^1.3.3",
|
|
47
|
+
"@modern-js/utils": "^1.5.0",
|
|
48
48
|
"address": "^1.1.2",
|
|
49
49
|
"ajv": "^8.6.2",
|
|
50
50
|
"ajv-keywords": "^5.0.0",
|
|
51
|
-
"better-ajv-errors": "
|
|
51
|
+
"better-ajv-errors": "1.2.0",
|
|
52
52
|
"dotenv": "^10.0.0",
|
|
53
53
|
"dotenv-expand": "^5.1.0",
|
|
54
54
|
"v8-compile-cache": "^2.3.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@jest/types": "^27.0.6",
|
|
58
|
-
"@modern-js/types": "^1.
|
|
58
|
+
"@modern-js/types": "^1.5.0",
|
|
59
59
|
"@scripts/build": "0.0.0",
|
|
60
60
|
"@scripts/jest-config": "0.0.0",
|
|
61
61
|
"@types/babel__code-frame": "^7.0.3",
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
"btsm": "2.2.2",
|
|
70
70
|
"jest": "^27",
|
|
71
71
|
"sass": "^1.45.0",
|
|
72
|
+
"electron-builder": "22.7.0",
|
|
72
73
|
"terser-webpack-plugin": "^5.1.4",
|
|
73
74
|
"typescript": "^4",
|
|
74
75
|
"webpack": "^5.71.0",
|
package/tests/.eslintrc.js
DELETED
package/tests/btsm.test.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { spawnSync } from 'child_process';
|
|
3
|
-
|
|
4
|
-
const kPackageDir = path.resolve(__dirname, '..');
|
|
5
|
-
|
|
6
|
-
describe('jsnext:source', () => {
|
|
7
|
-
test('process exit status is 0', () => {
|
|
8
|
-
const { status, stdout, stderr } = spawnSync(
|
|
9
|
-
process.execPath,
|
|
10
|
-
['--conditions=jsnext:source', '-r', 'btsm', 'src/cli.ts'],
|
|
11
|
-
{
|
|
12
|
-
cwd: kPackageDir,
|
|
13
|
-
encoding: 'utf-8',
|
|
14
|
-
},
|
|
15
|
-
);
|
|
16
|
-
expect(stdout).toBe('');
|
|
17
|
-
expect(stderr.startsWith('Usage: modern <command> [options]')).toBe(true);
|
|
18
|
-
expect(status).toBe(1);
|
|
19
|
-
});
|
|
20
|
-
});
|
package/tests/config.test.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
// import os from 'os';
|
|
3
|
-
import { isDev, getPort, DEFAULT_SERVER_CONFIG } from '@modern-js/utils';
|
|
4
|
-
import { resolveConfig, addServerConfigToDeps } from '../src/config';
|
|
5
|
-
import {
|
|
6
|
-
cli,
|
|
7
|
-
loadUserConfig,
|
|
8
|
-
initAppContext,
|
|
9
|
-
initAppDir,
|
|
10
|
-
manager,
|
|
11
|
-
createPlugin,
|
|
12
|
-
registerHook,
|
|
13
|
-
useRunner,
|
|
14
|
-
} from '../src';
|
|
15
|
-
import { defaults } from '../src/config/defaults';
|
|
16
|
-
|
|
17
|
-
jest.mock('@modern-js/utils', () => ({
|
|
18
|
-
__esModule: true,
|
|
19
|
-
...jest.requireActual('@modern-js/utils'),
|
|
20
|
-
isDev: jest.fn(),
|
|
21
|
-
getPort: jest.fn(),
|
|
22
|
-
}));
|
|
23
|
-
|
|
24
|
-
// const kOSRootDir =
|
|
25
|
-
// os.platform() === 'win32' ? process.cwd().split(path.sep)[0] : '/';
|
|
26
|
-
|
|
27
|
-
describe('config', () => {
|
|
28
|
-
/**
|
|
29
|
-
* TypeScript Type annotations cannot be used for esbuild-jest
|
|
30
|
-
* test files that use jest.mock('@some/module')
|
|
31
|
-
* refer to this esbuild-jest issue:
|
|
32
|
-
* https://github.com/aelbore/esbuild-jest/issues/57
|
|
33
|
-
* TODO: find a better solution to solve this problem while allowing us
|
|
34
|
-
* to use esbuild, and have good TypeScript support
|
|
35
|
-
*/
|
|
36
|
-
let loaded = {
|
|
37
|
-
config: {},
|
|
38
|
-
filePath: '',
|
|
39
|
-
dependencies: [],
|
|
40
|
-
pkgConfig: {},
|
|
41
|
-
jsConfig: {},
|
|
42
|
-
};
|
|
43
|
-
let schemas: any[] = [];
|
|
44
|
-
let restartWithExistingPort = 0;
|
|
45
|
-
let argv: string[] = ['dev'];
|
|
46
|
-
let configs: any[] = [];
|
|
47
|
-
|
|
48
|
-
const getResolvedConfig = async () =>
|
|
49
|
-
resolveConfig(loaded, configs, schemas, restartWithExistingPort, argv);
|
|
50
|
-
|
|
51
|
-
const resetParams = () => {
|
|
52
|
-
loaded = {
|
|
53
|
-
config: {},
|
|
54
|
-
filePath: '',
|
|
55
|
-
dependencies: [],
|
|
56
|
-
pkgConfig: {},
|
|
57
|
-
jsConfig: {},
|
|
58
|
-
};
|
|
59
|
-
schemas = [];
|
|
60
|
-
restartWithExistingPort = 0;
|
|
61
|
-
argv = ['dev'];
|
|
62
|
-
configs = [];
|
|
63
|
-
};
|
|
64
|
-
const resetMock = () => {
|
|
65
|
-
jest.resetAllMocks();
|
|
66
|
-
(isDev as jest.Mock).mockReturnValue(true);
|
|
67
|
-
(getPort as jest.Mock).mockReturnValue(
|
|
68
|
-
Promise.resolve(defaults.server.port),
|
|
69
|
-
);
|
|
70
|
-
};
|
|
71
|
-
beforeEach(() => {
|
|
72
|
-
resetParams();
|
|
73
|
-
resetMock();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('default', () => {
|
|
77
|
-
expect(resolveConfig).toBeDefined();
|
|
78
|
-
expect(cli).toBeDefined();
|
|
79
|
-
expect(loadUserConfig).toBeDefined();
|
|
80
|
-
expect(initAppContext).toBeDefined();
|
|
81
|
-
expect(initAppDir).toBeDefined();
|
|
82
|
-
expect(manager).toBeDefined();
|
|
83
|
-
expect(createPlugin).toBeDefined();
|
|
84
|
-
expect(registerHook).toBeDefined();
|
|
85
|
-
expect(useRunner).toBeDefined();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('initAppDir', async () => {
|
|
89
|
-
expect(await initAppDir(__dirname)).toBe(path.resolve(__dirname, '..'));
|
|
90
|
-
// expect(await initAppDir()).toBe(path.resolve(__dirname, '..'));
|
|
91
|
-
|
|
92
|
-
// FIXME: windows 下面会失败,先忽略这个测试
|
|
93
|
-
// try {
|
|
94
|
-
// await initAppDir(kOSRootDir);
|
|
95
|
-
// expect(true).toBe(false); // SHOULD NOT BE HERE
|
|
96
|
-
// } catch (err: any) {
|
|
97
|
-
// expect(err.message).toMatch(/no package.json found in current work dir/);
|
|
98
|
-
// }
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test('should use default port if not restarting in dev mode', async () => {
|
|
102
|
-
let resolved = await getResolvedConfig();
|
|
103
|
-
expect(resolved.server.port).toEqual(defaults.server.port);
|
|
104
|
-
expect(getPort).toHaveBeenCalledWith(defaults.server.port);
|
|
105
|
-
|
|
106
|
-
// getResolvedConfig should use the value givin by getPort
|
|
107
|
-
restartWithExistingPort = -1;
|
|
108
|
-
(getPort as jest.Mock).mockClear();
|
|
109
|
-
(getPort as jest.Mock).mockReturnValue(1111);
|
|
110
|
-
resolved = await getResolvedConfig();
|
|
111
|
-
expect(resolved.server.port).toEqual(1111);
|
|
112
|
-
expect(getPort).toHaveBeenCalledWith(defaults.server.port);
|
|
113
|
-
|
|
114
|
-
argv = ['start'];
|
|
115
|
-
(isDev as jest.Mock).mockReturnValue(false);
|
|
116
|
-
restartWithExistingPort = 0;
|
|
117
|
-
resolved = await getResolvedConfig();
|
|
118
|
-
expect(resolved.server.port).toEqual(defaults.server.port);
|
|
119
|
-
|
|
120
|
-
restartWithExistingPort = 1234;
|
|
121
|
-
resolved = await getResolvedConfig();
|
|
122
|
-
expect(resolved.server.port).toEqual(defaults.server.port);
|
|
123
|
-
|
|
124
|
-
restartWithExistingPort = -1;
|
|
125
|
-
resolved = await getResolvedConfig();
|
|
126
|
-
expect(resolved.server.port).toEqual(defaults.server.port);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
test('should reuse existing port if restarting in dev mode', async () => {
|
|
130
|
-
restartWithExistingPort = 1234;
|
|
131
|
-
const resolved = await getResolvedConfig();
|
|
132
|
-
expect(resolved.server.port).toEqual(1234);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
describe('addServerConfigToDeps', () => {
|
|
137
|
-
it('should add server config to deps', async () => {
|
|
138
|
-
const appDirectory = path.join(__dirname, './fixtures/index-test');
|
|
139
|
-
const deps: string[] = [];
|
|
140
|
-
await addServerConfigToDeps(deps, appDirectory, DEFAULT_SERVER_CONFIG);
|
|
141
|
-
expect(deps.length).toBe(1);
|
|
142
|
-
expect(deps[0]).toBe(
|
|
143
|
-
path.join(appDirectory, `${DEFAULT_SERVER_CONFIG}.js`),
|
|
144
|
-
);
|
|
145
|
-
});
|
|
146
|
-
});
|
package/tests/context.test.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { DEFAULT_SERVER_CONFIG } from '@modern-js/utils';
|
|
3
|
-
import { initAppContext } from '../src/context';
|
|
4
|
-
|
|
5
|
-
describe('context', () => {
|
|
6
|
-
it('initAppContext', () => {
|
|
7
|
-
const appDirectory = path.resolve(
|
|
8
|
-
__dirname,
|
|
9
|
-
'./fixtures/load-plugin/user-plugins',
|
|
10
|
-
);
|
|
11
|
-
const appContext = initAppContext({
|
|
12
|
-
appDirectory,
|
|
13
|
-
plugins: [],
|
|
14
|
-
configFile: false,
|
|
15
|
-
serverConfigFile: DEFAULT_SERVER_CONFIG,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
expect(appContext).toEqual({
|
|
19
|
-
appDirectory,
|
|
20
|
-
configFile: false,
|
|
21
|
-
serverConfigFile: DEFAULT_SERVER_CONFIG,
|
|
22
|
-
ip: expect.any(String),
|
|
23
|
-
port: 0,
|
|
24
|
-
packageName: expect.any(String),
|
|
25
|
-
srcDirectory: expect.any(String),
|
|
26
|
-
distDirectory: expect.any(String),
|
|
27
|
-
sharedDirectory: expect.any(String),
|
|
28
|
-
nodeModulesDirectory: expect.any(String),
|
|
29
|
-
internalDirectory: expect.any(String),
|
|
30
|
-
plugins: [],
|
|
31
|
-
htmlTemplates: {},
|
|
32
|
-
serverRoutes: [],
|
|
33
|
-
entrypoints: [],
|
|
34
|
-
checkedEntries: [],
|
|
35
|
-
existSrc: true,
|
|
36
|
-
internalDirAlias: '@_modern_js_internal',
|
|
37
|
-
internalSrcAlias: '@_modern_js_src',
|
|
38
|
-
metaName: 'modern-js',
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('custom AppContext', () => {
|
|
43
|
-
const appDirectory = path.resolve(
|
|
44
|
-
__dirname,
|
|
45
|
-
'./fixtures/load-plugin/user-plugins',
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
const customOptions = {
|
|
49
|
-
srcDir: 'source',
|
|
50
|
-
distDir: 'dist',
|
|
51
|
-
sharedDir: 'myShared',
|
|
52
|
-
metaName: 'jupiter',
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const appContext = initAppContext({
|
|
56
|
-
appDirectory,
|
|
57
|
-
plugins: [],
|
|
58
|
-
configFile: false,
|
|
59
|
-
options: customOptions,
|
|
60
|
-
serverConfigFile: DEFAULT_SERVER_CONFIG,
|
|
61
|
-
});
|
|
62
|
-
expect(appContext).toEqual({
|
|
63
|
-
appDirectory,
|
|
64
|
-
configFile: false,
|
|
65
|
-
serverConfigFile: DEFAULT_SERVER_CONFIG,
|
|
66
|
-
ip: expect.any(String),
|
|
67
|
-
port: 0,
|
|
68
|
-
packageName: 'user-plugins',
|
|
69
|
-
srcDirectory: path.resolve(appDirectory, './source'),
|
|
70
|
-
distDirectory: 'dist',
|
|
71
|
-
sharedDirectory: path.resolve(appDirectory, './myShared'),
|
|
72
|
-
nodeModulesDirectory: expect.any(String),
|
|
73
|
-
internalDirectory: path.resolve(appDirectory, './node_modules/.jupiter'),
|
|
74
|
-
plugins: [],
|
|
75
|
-
htmlTemplates: {},
|
|
76
|
-
serverRoutes: [],
|
|
77
|
-
entrypoints: [],
|
|
78
|
-
checkedEntries: [],
|
|
79
|
-
existSrc: true,
|
|
80
|
-
internalDirAlias: '@_jupiter_internal',
|
|
81
|
-
internalSrcAlias: '@_jupiter_src',
|
|
82
|
-
metaName: 'jupiter',
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
});
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = { name: 'a' };
|