@modern-js/core 1.7.1 → 1.9.1
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/.eslintrc.js +1 -0
- package/CHANGELOG.md +47 -0
- package/bin/modern-js.js +1 -1
- package/compiled/ajv/codegen.js +1 -0
- package/compiled/ajv/dist/ajv.d.ts +16 -0
- package/compiled/ajv/dist/compile/codegen/code.d.ts +40 -0
- package/compiled/ajv/dist/compile/codegen/index.d.ts +79 -0
- package/compiled/ajv/dist/compile/codegen/scope.d.ts +79 -0
- package/compiled/ajv/dist/compile/errors.d.ts +13 -0
- package/compiled/ajv/dist/compile/index.d.ts +80 -0
- package/compiled/ajv/dist/compile/ref_error.d.ts +6 -0
- package/compiled/ajv/dist/compile/resolve.d.ts +12 -0
- package/compiled/ajv/dist/compile/rules.d.ts +28 -0
- package/compiled/ajv/dist/compile/util.d.ts +40 -0
- package/compiled/ajv/dist/compile/validate/index.d.ts +42 -0
- package/compiled/ajv/dist/compile/validate/subschema.d.ts +47 -0
- package/compiled/ajv/dist/core.d.ts +173 -0
- package/compiled/ajv/dist/runtime/validation_error.d.ts +7 -0
- package/compiled/ajv/dist/types/index.d.ts +183 -0
- package/compiled/ajv/dist/types/json-schema.d.ts +124 -0
- package/compiled/ajv/dist/types/jtd-schema.d.ts +169 -0
- package/compiled/ajv/index.js +9 -0
- package/compiled/ajv/license +22 -0
- package/compiled/ajv/package.json +1 -0
- package/compiled/ajv/uri-js/dist/es5/uri.all.d.ts +59 -0
- package/compiled/ajv-keywords/ajv/dist/ajv.d.ts +16 -0
- package/compiled/ajv-keywords/ajv/dist/compile/codegen/code.d.ts +40 -0
- package/compiled/ajv-keywords/ajv/dist/compile/codegen/index.d.ts +79 -0
- package/compiled/ajv-keywords/ajv/dist/compile/codegen/scope.d.ts +79 -0
- package/compiled/ajv-keywords/ajv/dist/compile/errors.d.ts +13 -0
- package/compiled/ajv-keywords/ajv/dist/compile/index.d.ts +80 -0
- package/compiled/ajv-keywords/ajv/dist/compile/ref_error.d.ts +6 -0
- package/compiled/ajv-keywords/ajv/dist/compile/resolve.d.ts +12 -0
- package/compiled/ajv-keywords/ajv/dist/compile/rules.d.ts +28 -0
- package/compiled/ajv-keywords/ajv/dist/compile/util.d.ts +40 -0
- package/compiled/ajv-keywords/ajv/dist/compile/validate/index.d.ts +42 -0
- package/compiled/ajv-keywords/ajv/dist/compile/validate/subschema.d.ts +47 -0
- package/compiled/ajv-keywords/ajv/dist/core.d.ts +173 -0
- package/compiled/ajv-keywords/ajv/dist/runtime/validation_error.d.ts +7 -0
- package/compiled/ajv-keywords/ajv/dist/types/index.d.ts +183 -0
- package/compiled/ajv-keywords/ajv/dist/types/json-schema.d.ts +124 -0
- package/compiled/ajv-keywords/ajv/dist/types/jtd-schema.d.ts +169 -0
- package/compiled/ajv-keywords/dist/index.d.ts +4 -0
- package/compiled/ajv-keywords/index.js +1 -0
- package/compiled/ajv-keywords/license +21 -0
- package/compiled/ajv-keywords/package.json +1 -0
- package/compiled/ajv-keywords/uri-js/dist/es5/uri.all.d.ts +59 -0
- package/compiled/better-ajv-errors/ajv/dist/ajv.d.ts +16 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/codegen/code.d.ts +40 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/codegen/index.d.ts +79 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/codegen/scope.d.ts +79 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/errors.d.ts +13 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/index.d.ts +80 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/ref_error.d.ts +6 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/resolve.d.ts +12 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/rules.d.ts +28 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/util.d.ts +40 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/validate/index.d.ts +42 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/validate/subschema.d.ts +47 -0
- package/compiled/better-ajv-errors/ajv/dist/core.d.ts +173 -0
- package/compiled/better-ajv-errors/ajv/dist/runtime/validation_error.d.ts +7 -0
- package/compiled/better-ajv-errors/ajv/dist/types/index.d.ts +183 -0
- package/compiled/better-ajv-errors/ajv/dist/types/json-schema.d.ts +124 -0
- package/compiled/better-ajv-errors/ajv/dist/types/jtd-schema.d.ts +169 -0
- package/compiled/better-ajv-errors/index.js +1 -0
- package/compiled/better-ajv-errors/license +13 -0
- package/compiled/better-ajv-errors/package.json +1 -0
- package/compiled/better-ajv-errors/typings.d.ts +24 -0
- package/compiled/better-ajv-errors/uri-js/dist/es5/uri.all.d.ts +59 -0
- package/compiled/v8-compile-cache/index.js +1 -0
- package/compiled/v8-compile-cache/license +21 -0
- package/compiled/v8-compile-cache/package.json +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +33 -0
- package/dist/config/defaults.d.ts +28 -0
- package/dist/config/defaults.js +98 -0
- package/dist/{types/config → config}/index.d.ts +2 -2
- package/dist/config/index.js +120 -0
- package/dist/config/mergeConfig.d.ts +30 -0
- package/dist/config/mergeConfig.js +26 -0
- package/dist/config/schema/deploy.d.ts +16 -0
- package/dist/config/schema/deploy.js +16 -0
- package/dist/config/schema/index.d.ts +466 -0
- package/dist/config/schema/index.js +95 -0
- package/dist/config/schema/output.d.ts +146 -0
- package/dist/config/schema/output.js +68 -0
- package/dist/config/schema/server.d.ts +182 -0
- package/dist/config/schema/server.js +107 -0
- package/dist/config/schema/source.d.ts +58 -0
- package/dist/config/schema/source.js +36 -0
- package/dist/config/schema/tools.d.ts +36 -0
- package/dist/config/schema/tools.js +19 -0
- package/dist/config/types/electron.d.ts +13 -0
- package/dist/config/types/electron.js +2 -0
- package/dist/config/types/index.d.ts +240 -0
- package/dist/config/types/index.js +2 -0
- package/dist/config/types/less.d.ts +10 -0
- package/dist/config/types/less.js +2 -0
- package/dist/config/types/sass.d.ts +8 -0
- package/dist/config/types/sass.js +2 -0
- package/dist/{types/config → config}/types/ssg.d.ts +8 -8
- package/dist/config/types/ssg.js +2 -0
- package/dist/config/types/test.d.ts +14 -0
- package/dist/config/types/test.js +2 -0
- package/dist/config/types/unbundle.d.ts +25 -0
- package/dist/config/types/unbundle.js +2 -0
- package/dist/{types/context.d.ts → context.d.ts} +12 -22
- package/dist/context.js +59 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +177 -0
- package/dist/{types/initWatcher.d.ts → initWatcher.d.ts} +1 -1
- package/dist/initWatcher.js +75 -0
- package/dist/{types/loadEnv.d.ts → loadEnv.d.ts} +1 -1
- package/dist/loadEnv.js +21 -0
- package/dist/{types/loadPlugins.d.ts → loadPlugins.d.ts} +15 -15
- package/dist/loadPlugins.js +109 -0
- package/dist/manager.d.ts +72 -0
- package/dist/manager.js +24 -0
- package/dist/{types/pluginAPI.d.ts → pluginAPI.d.ts} +5 -6
- package/dist/pluginAPI.js +16 -0
- package/dist/{types/utils → utils}/commander.d.ts +1 -1
- package/dist/utils/commander.js +20 -0
- package/dist/{types/utils → utils}/repeatKeyWarning.d.ts +1 -1
- package/dist/utils/repeatKeyWarning.js +22 -0
- package/package.json +16 -29
- package/tsconfig.json +3 -4
- package/dist/js/modern/cli.js +0 -29
- package/dist/js/modern/config/defaults.js +0 -103
- package/dist/js/modern/config/index.js +0 -115
- package/dist/js/modern/config/mergeConfig.js +0 -22
- package/dist/js/modern/config/schema/deploy.js +0 -17
- package/dist/js/modern/config/schema/index.js +0 -107
- package/dist/js/modern/config/schema/output.js +0 -147
- package/dist/js/modern/config/schema/server.js +0 -170
- package/dist/js/modern/config/schema/source.js +0 -59
- package/dist/js/modern/config/schema/tools.js +0 -36
- package/dist/js/modern/config/types/index.js +0 -1
- package/dist/js/modern/config/types/less.js +0 -0
- package/dist/js/modern/config/types/sass.js +0 -0
- package/dist/js/modern/config/types/ssg.js +0 -0
- package/dist/js/modern/config/types/test.js +0 -0
- package/dist/js/modern/config/types/unbundle.js +0 -0
- package/dist/js/modern/context.js +0 -63
- package/dist/js/modern/index.js +0 -168
- package/dist/js/modern/initWatcher.js +0 -62
- package/dist/js/modern/loadEnv.js +0 -14
- package/dist/js/modern/loadPlugins.js +0 -117
- package/dist/js/modern/manager.js +0 -28
- package/dist/js/modern/pluginAPI.js +0 -11
- package/dist/js/modern/utils/commander.js +0 -19
- package/dist/js/modern/utils/repeatKeyWarning.js +0 -18
- package/dist/js/node/cli.js +0 -35
- package/dist/js/node/config/defaults.js +0 -110
- package/dist/js/node/config/index.js +0 -182
- package/dist/js/node/config/mergeConfig.js +0 -32
- package/dist/js/node/config/schema/deploy.js +0 -26
- package/dist/js/node/config/schema/index.js +0 -127
- package/dist/js/node/config/schema/output.js +0 -156
- package/dist/js/node/config/schema/server.js +0 -179
- package/dist/js/node/config/schema/source.js +0 -68
- package/dist/js/node/config/schema/tools.js +0 -43
- package/dist/js/node/config/types/index.js +0 -5
- package/dist/js/node/config/types/less.js +0 -0
- package/dist/js/node/config/types/sass.js +0 -0
- package/dist/js/node/config/types/ssg.js +0 -0
- package/dist/js/node/config/types/test.js +0 -0
- package/dist/js/node/config/types/unbundle.js +0 -0
- package/dist/js/node/context.js +0 -93
- package/dist/js/node/index.js +0 -328
- package/dist/js/node/initWatcher.js +0 -82
- package/dist/js/node/loadEnv.js +0 -30
- package/dist/js/node/loadPlugins.js +0 -129
- package/dist/js/node/manager.js +0 -45
- package/dist/js/node/pluginAPI.js +0 -54
- package/dist/js/node/utils/commander.js +0 -32
- package/dist/js/node/utils/repeatKeyWarning.js +0 -31
- package/dist/types/cli.d.ts +0 -1
- package/dist/types/config/defaults.d.ts +0 -28
- package/dist/types/config/mergeConfig.d.ts +0 -31
- package/dist/types/config/schema/deploy.d.ts +0 -16
- package/dist/types/config/schema/index.d.ts +0 -466
- package/dist/types/config/schema/output.d.ts +0 -146
- package/dist/types/config/schema/server.d.ts +0 -182
- package/dist/types/config/schema/source.d.ts +0 -58
- package/dist/types/config/schema/tools.d.ts +0 -36
- package/dist/types/config/types/index.d.ts +0 -239
- package/dist/types/config/types/less.d.ts +0 -10
- package/dist/types/config/types/sass.d.ts +0 -8
- package/dist/types/config/types/test.d.ts +0 -15
- package/dist/types/config/types/unbundle.d.ts +0 -28
- package/dist/types/index.d.ts +0 -61
- package/dist/types/manager.d.ts +0 -74
- package/modern.config.js +0 -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/dist/types/manager.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { ToThreads, ToRunners, AsyncSetup, PluginOptions, AsyncWorkflow, AsyncWaterfall, ParallelWorkflow } from '@modern-js/plugin';
|
|
2
|
-
import type { Hooks } from '@modern-js/types';
|
|
3
|
-
import type { Command } from './utils/commander';
|
|
4
|
-
import type { NormalizedConfig } from './config/mergeConfig';
|
|
5
|
-
import { pluginAPI } from './pluginAPI';
|
|
6
|
-
export declare type HooksRunner = ToRunners<{
|
|
7
|
-
config: ParallelWorkflow<void>;
|
|
8
|
-
resolvedConfig: AsyncWaterfall<{
|
|
9
|
-
resolved: NormalizedConfig;
|
|
10
|
-
}>;
|
|
11
|
-
validateSchema: ParallelWorkflow<void>;
|
|
12
|
-
prepare: AsyncWorkflow<void, void>;
|
|
13
|
-
commands: AsyncWorkflow<{
|
|
14
|
-
program: Command;
|
|
15
|
-
}, void>;
|
|
16
|
-
watchFiles: ParallelWorkflow<void>;
|
|
17
|
-
fileChange: AsyncWorkflow<{
|
|
18
|
-
filename: string;
|
|
19
|
-
eventType: 'add' | 'change' | 'unlink';
|
|
20
|
-
}, void>;
|
|
21
|
-
beforeExit: AsyncWorkflow<void, void>;
|
|
22
|
-
beforeRestart: AsyncWorkflow<void, void>;
|
|
23
|
-
}>;
|
|
24
|
-
declare const baseHooks: {
|
|
25
|
-
config: ParallelWorkflow<void, unknown>;
|
|
26
|
-
resolvedConfig: AsyncWaterfall<{
|
|
27
|
-
resolved: NormalizedConfig;
|
|
28
|
-
}>;
|
|
29
|
-
validateSchema: ParallelWorkflow<void, unknown>;
|
|
30
|
-
prepare: AsyncWorkflow<void, void>;
|
|
31
|
-
commands: AsyncWorkflow<{
|
|
32
|
-
program: Command;
|
|
33
|
-
}, void>;
|
|
34
|
-
watchFiles: ParallelWorkflow<void, unknown>;
|
|
35
|
-
fileChange: AsyncWorkflow<{
|
|
36
|
-
filename: string;
|
|
37
|
-
eventType: 'add' | 'change' | 'unlink';
|
|
38
|
-
}, void>;
|
|
39
|
-
beforeExit: AsyncWorkflow<void, void>;
|
|
40
|
-
beforeRestart: AsyncWorkflow<void, void>;
|
|
41
|
-
};
|
|
42
|
-
/** All hooks of cli plugin. */
|
|
43
|
-
|
|
44
|
-
export declare type CliHooks = typeof baseHooks & Hooks;
|
|
45
|
-
/** All hook callbacks of cli plugin. */
|
|
46
|
-
|
|
47
|
-
export declare type CliHookCallbacks = ToThreads<CliHooks>;
|
|
48
|
-
export declare const manager: import("@modern-js/plugin").AsyncManager<CliHooks, {
|
|
49
|
-
setAppContext: (value: import("@modern-js/types").IAppContext) => void;
|
|
50
|
-
useAppContext: () => import("@modern-js/types").IAppContext;
|
|
51
|
-
useConfigContext: () => import("./config").UserConfig;
|
|
52
|
-
useResolvedConfigContext: () => NormalizedConfig;
|
|
53
|
-
}>;
|
|
54
|
-
/** Plugin options of a cli plugin. */
|
|
55
|
-
|
|
56
|
-
export declare type CliPlugin = PluginOptions<CliHooks, AsyncSetup<CliHooks, typeof pluginAPI>>;
|
|
57
|
-
export declare const createPlugin: (setup?: AsyncSetup<CliHooks, {
|
|
58
|
-
setAppContext: (value: import("@modern-js/types").IAppContext) => void;
|
|
59
|
-
useAppContext: () => import("@modern-js/types").IAppContext;
|
|
60
|
-
useConfigContext: () => import("./config").UserConfig;
|
|
61
|
-
useResolvedConfigContext: () => NormalizedConfig;
|
|
62
|
-
}> | undefined, options?: PluginOptions<CliHooks, AsyncSetup<CliHooks, {
|
|
63
|
-
setAppContext: (value: import("@modern-js/types").IAppContext) => void;
|
|
64
|
-
useAppContext: () => import("@modern-js/types").IAppContext;
|
|
65
|
-
useConfigContext: () => import("./config").UserConfig;
|
|
66
|
-
useResolvedConfigContext: () => NormalizedConfig;
|
|
67
|
-
}>> | undefined) => import("@modern-js/plugin").AsyncPlugin<CliHooks, {
|
|
68
|
-
setAppContext: (value: import("@modern-js/types").IAppContext) => void;
|
|
69
|
-
useAppContext: () => import("@modern-js/types").IAppContext;
|
|
70
|
-
useConfigContext: () => import("./config").UserConfig;
|
|
71
|
-
useResolvedConfigContext: () => NormalizedConfig;
|
|
72
|
-
}>, registerHook: (newHooks: Partial<CliHooks>) => void, mountHook: () => ToRunners<CliHooks>;
|
|
73
|
-
export declare const usePlugins: (plugins: string[]) => void;
|
|
74
|
-
export {};
|
package/modern.config.js
DELETED
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' };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = { name: 'a' };
|
package/tests/index.test.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { cli, mergeOptions } from '../src';
|
|
3
|
-
import { resolveConfig, loadUserConfig } from '../src/config';
|
|
4
|
-
import { loadEnv } from '../src/loadEnv';
|
|
5
|
-
|
|
6
|
-
jest.mock('../src/config', () => ({
|
|
7
|
-
__esModule: true,
|
|
8
|
-
...jest.requireActual('../src/config'),
|
|
9
|
-
loadUserConfig: jest.fn(),
|
|
10
|
-
resolveConfig: jest.fn(),
|
|
11
|
-
}));
|
|
12
|
-
|
|
13
|
-
jest.mock('../src/loadEnv', () => ({
|
|
14
|
-
__esModule: true,
|
|
15
|
-
...jest.requireActual('../src/loadEnv'),
|
|
16
|
-
loadEnv: jest.fn(),
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
describe('@modern-js/core test', () => {
|
|
20
|
-
let mockResolveConfig: any = {};
|
|
21
|
-
let mockLoadedConfig: any = {};
|
|
22
|
-
const cwdSpy = jest.spyOn(process, 'cwd');
|
|
23
|
-
const cwd = path.join(__dirname, './fixtures/index-test');
|
|
24
|
-
|
|
25
|
-
const resetMock = () => {
|
|
26
|
-
jest.resetAllMocks();
|
|
27
|
-
cwdSpy.mockReturnValue(cwd);
|
|
28
|
-
(resolveConfig as jest.Mock).mockReturnValue(
|
|
29
|
-
Promise.resolve(mockResolveConfig),
|
|
30
|
-
);
|
|
31
|
-
(loadUserConfig as jest.Mock).mockImplementation(() =>
|
|
32
|
-
Promise.resolve(mockLoadedConfig),
|
|
33
|
-
);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const resetValues = () => {
|
|
37
|
-
mockLoadedConfig = {
|
|
38
|
-
config: {},
|
|
39
|
-
filePath: false,
|
|
40
|
-
dependencies: [],
|
|
41
|
-
pkgConfig: {},
|
|
42
|
-
jsConfig: {},
|
|
43
|
-
};
|
|
44
|
-
mockResolveConfig = {
|
|
45
|
-
server: {
|
|
46
|
-
port: 8080,
|
|
47
|
-
},
|
|
48
|
-
output: {
|
|
49
|
-
path: './my/test/path',
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
beforeEach(() => {
|
|
55
|
-
resetValues();
|
|
56
|
-
resetMock();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('test cli create', () => {
|
|
60
|
-
expect(cli).toBeTruthy();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('test cli init dev', async () => {
|
|
64
|
-
cwdSpy.mockReturnValue(path.join(cwd, 'nested-folder'));
|
|
65
|
-
await cli.init(['dev']);
|
|
66
|
-
expect(loadEnv).toHaveBeenCalledWith(cwd, undefined);
|
|
67
|
-
// TODO: add more test cases
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe('test mergeOptions', () => {
|
|
72
|
-
it('serverConfigFile must exist', () => {
|
|
73
|
-
const options = mergeOptions({});
|
|
74
|
-
expect(options).toHaveProperty('serverConfigFile');
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('serverConfigFile can be overwritten', () => {
|
|
78
|
-
const options = mergeOptions({
|
|
79
|
-
serverConfigFile: 'test',
|
|
80
|
-
});
|
|
81
|
-
expect(options.serverConfigFile).toBe('test');
|
|
82
|
-
});
|
|
83
|
-
});
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import { fs, wait } from '@modern-js/utils';
|
|
3
|
-
import { initWatcher } from '../src/initWatcher';
|
|
4
|
-
|
|
5
|
-
jest.useRealTimers();
|
|
6
|
-
|
|
7
|
-
const mockAppDirectory = path.join(__dirname, './fixtures/index-test');
|
|
8
|
-
const mockConfigDir = './config';
|
|
9
|
-
const mockSrcDirectory = path.join(mockAppDirectory, './src');
|
|
10
|
-
|
|
11
|
-
describe('initWatcher', () => {
|
|
12
|
-
afterAll(() => {
|
|
13
|
-
const file = path.join(mockSrcDirectory, './index.ts');
|
|
14
|
-
if (fs.existsSync(file)) {
|
|
15
|
-
fs.unlinkSync(file);
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
xtest('will trigger add event', async () => {
|
|
20
|
-
let triggeredType = '';
|
|
21
|
-
let triggeredFile = '';
|
|
22
|
-
const loaded = {
|
|
23
|
-
filePath: '',
|
|
24
|
-
dependencies: [],
|
|
25
|
-
};
|
|
26
|
-
const hooksRunner = {
|
|
27
|
-
watchFiles: async () => [mockSrcDirectory],
|
|
28
|
-
fileChange: jest.fn(({ filename, eventType }) => {
|
|
29
|
-
triggeredType = eventType;
|
|
30
|
-
triggeredFile = filename;
|
|
31
|
-
}),
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
if (await fs.pathExists(mockSrcDirectory)) {
|
|
35
|
-
await fs.remove(mockSrcDirectory);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const watcher = await initWatcher(
|
|
39
|
-
loaded as any,
|
|
40
|
-
mockAppDirectory,
|
|
41
|
-
mockConfigDir,
|
|
42
|
-
hooksRunner as any,
|
|
43
|
-
['dev'],
|
|
44
|
-
);
|
|
45
|
-
await wait(100);
|
|
46
|
-
|
|
47
|
-
const file = path.join(mockSrcDirectory, './index.ts');
|
|
48
|
-
await fs.outputFile(file, '');
|
|
49
|
-
await wait(100);
|
|
50
|
-
// expect(hooksRunner.fileChange).toBeCalledTimes(1);
|
|
51
|
-
// expect(triggeredType).toBe('add');
|
|
52
|
-
expect(file.includes(triggeredFile)).toBeTruthy();
|
|
53
|
-
|
|
54
|
-
await wait(100);
|
|
55
|
-
await fs.remove(file);
|
|
56
|
-
await wait(200);
|
|
57
|
-
expect(hooksRunner.fileChange).toBeCalledTimes(2);
|
|
58
|
-
expect(triggeredType).toBe('unlink');
|
|
59
|
-
expect(file.includes(triggeredFile)).toBeTruthy();
|
|
60
|
-
|
|
61
|
-
watcher?.close();
|
|
62
|
-
});
|
|
63
|
-
});
|
package/tests/loadEnv.test.ts
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { loadEnv } from '../src/loadEnv';
|
|
4
|
-
|
|
5
|
-
const fixture = path.resolve(__dirname, './fixtures/load-env');
|
|
6
|
-
|
|
7
|
-
fs.mkdirSync(fixture);
|
|
8
|
-
|
|
9
|
-
const createFixtures = (
|
|
10
|
-
dir: string,
|
|
11
|
-
files: {
|
|
12
|
-
name: string;
|
|
13
|
-
content: string;
|
|
14
|
-
}[],
|
|
15
|
-
) => {
|
|
16
|
-
fs.mkdirSync(path.join(fixture, dir));
|
|
17
|
-
for (const { name, content } of files) {
|
|
18
|
-
fs.writeFileSync(path.join(fixture, dir, name), content, 'utf8');
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
describe('load environment variables', () => {
|
|
23
|
-
const defaultEnv = process.env;
|
|
24
|
-
|
|
25
|
-
beforeEach(() => (process.env = { ...defaultEnv }));
|
|
26
|
-
|
|
27
|
-
afterAll(() => {
|
|
28
|
-
process.env = { ...defaultEnv };
|
|
29
|
-
fs.rmSync(fixture, { force: true, recursive: true });
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test(`support .env file`, () => {
|
|
33
|
-
createFixtures('base', [
|
|
34
|
-
{
|
|
35
|
-
name: '.env',
|
|
36
|
-
content: `DB_HOST=localhost
|
|
37
|
-
DB_USER=root
|
|
38
|
-
DB_PASS=root
|
|
39
|
-
`,
|
|
40
|
-
},
|
|
41
|
-
]);
|
|
42
|
-
loadEnv(path.join(fixture, 'base'));
|
|
43
|
-
|
|
44
|
-
expect(process.env.DB_HOST).toBe('localhost');
|
|
45
|
-
|
|
46
|
-
expect(process.env.DB_USER).toBe('root');
|
|
47
|
-
|
|
48
|
-
expect(process.env.DB_PASS).toBe('root');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test(`support "environment" .env file`, () => {
|
|
52
|
-
createFixtures('environment', [
|
|
53
|
-
{
|
|
54
|
-
name: '.env',
|
|
55
|
-
content: `DB_HOST=localhost
|
|
56
|
-
DB_USER=root
|
|
57
|
-
DB_PASS=root
|
|
58
|
-
`,
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
name: '.env.production',
|
|
62
|
-
content: `DB_HOST=localhost
|
|
63
|
-
DB_USER=root-local-dev
|
|
64
|
-
`,
|
|
65
|
-
},
|
|
66
|
-
]);
|
|
67
|
-
|
|
68
|
-
process.env.NODE_ENV = 'production';
|
|
69
|
-
|
|
70
|
-
loadEnv(path.join(fixture, 'environment'));
|
|
71
|
-
|
|
72
|
-
expect(process.env.DB_HOST).toBe('localhost');
|
|
73
|
-
|
|
74
|
-
expect(process.env.DB_USER).toBe('root-local-dev');
|
|
75
|
-
|
|
76
|
-
expect(process.env.DB_PASS).toBe('root');
|
|
77
|
-
|
|
78
|
-
delete process.env.NODE_ENV;
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test(`should have correct priority`, () => {
|
|
82
|
-
createFixtures('priority', [
|
|
83
|
-
{
|
|
84
|
-
name: '.env',
|
|
85
|
-
content: `DB_HOST=localhost
|
|
86
|
-
DB_USER=user
|
|
87
|
-
DB_PASS=pass
|
|
88
|
-
`,
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
name: '.env.production',
|
|
92
|
-
content: `DB_USER=user_production
|
|
93
|
-
DB_PASS=pass_production
|
|
94
|
-
FOO=foo
|
|
95
|
-
BAR=bar
|
|
96
|
-
`,
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
name: '.env.local',
|
|
100
|
-
content: `FOO=foo_local
|
|
101
|
-
BAR=bar_local
|
|
102
|
-
`,
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
name: '.env.production.local',
|
|
106
|
-
content: `BAR=bar_production_local`,
|
|
107
|
-
},
|
|
108
|
-
]);
|
|
109
|
-
|
|
110
|
-
process.env.NODE_ENV = 'production';
|
|
111
|
-
|
|
112
|
-
loadEnv(path.join(fixture, 'priority'));
|
|
113
|
-
|
|
114
|
-
expect(process.env.DB_HOST).toBe('localhost');
|
|
115
|
-
|
|
116
|
-
expect(process.env.DB_USER).toBe('user_production');
|
|
117
|
-
|
|
118
|
-
expect(process.env.DB_PASS).toBe('pass_production');
|
|
119
|
-
|
|
120
|
-
expect(process.env.FOO).toBe('foo_local');
|
|
121
|
-
|
|
122
|
-
expect(process.env.BAR).toBe('bar_production_local');
|
|
123
|
-
|
|
124
|
-
delete process.env.NODE_ENV;
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
test(`get custom .env file by MODERN_ENV`, () => {
|
|
128
|
-
createFixtures('custom_environment', [
|
|
129
|
-
{
|
|
130
|
-
name: '.env',
|
|
131
|
-
content: `DB_HOST=localhost
|
|
132
|
-
DB_USER=root
|
|
133
|
-
DB_PASS=root
|
|
134
|
-
`,
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
name: '.env.staging',
|
|
138
|
-
content: `DB_HOST=localhost
|
|
139
|
-
DB_USER=root-local-dev
|
|
140
|
-
`,
|
|
141
|
-
},
|
|
142
|
-
]);
|
|
143
|
-
|
|
144
|
-
loadEnv(path.join(fixture, 'custom_environment'), 'staging');
|
|
145
|
-
|
|
146
|
-
expect(process.env.DB_HOST).toBe('localhost');
|
|
147
|
-
|
|
148
|
-
expect(process.env.DB_USER).toBe('root-local-dev');
|
|
149
|
-
|
|
150
|
-
expect(process.env.DB_PASS).toBe('root');
|
|
151
|
-
|
|
152
|
-
delete process.env.MODERN_ENV;
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
test(`support dotenv-expand`, () => {
|
|
156
|
-
createFixtures('expand', [
|
|
157
|
-
{
|
|
158
|
-
name: '.env',
|
|
159
|
-
content: `DB_HOST=localhost
|
|
160
|
-
DB_USER=\${DB_HOST}001
|
|
161
|
-
DB_PASS=root
|
|
162
|
-
`,
|
|
163
|
-
},
|
|
164
|
-
]);
|
|
165
|
-
loadEnv(path.join(fixture, 'expand'));
|
|
166
|
-
|
|
167
|
-
expect(process.env.DB_HOST).toBe('localhost');
|
|
168
|
-
|
|
169
|
-
expect(process.env.DB_USER).toBe('localhost001');
|
|
170
|
-
|
|
171
|
-
expect(process.env.DB_PASS).toBe('root');
|
|
172
|
-
});
|
|
173
|
-
});
|