@modern-js/core 0.0.0-windows-20211056953 → 0.0.3-20221226

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 (130) hide show
  1. package/CHANGELOG.md +1164 -6
  2. package/dist/bin.d.ts +2 -0
  3. package/dist/bin.js +5 -0
  4. package/dist/config/createDefaultConfig.d.ts +2 -0
  5. package/dist/config/createDefaultConfig.js +9 -0
  6. package/dist/config/createLoadedConfig.d.ts +6 -0
  7. package/dist/config/createLoadedConfig.js +35 -0
  8. package/dist/config/createResolvedConfig.d.ts +3 -0
  9. package/dist/config/createResolvedConfig.js +92 -0
  10. package/dist/config/index.d.ts +3 -0
  11. package/dist/config/index.js +19 -0
  12. package/dist/context.d.ts +35 -0
  13. package/dist/context.js +61 -0
  14. package/dist/index.d.ts +73 -0
  15. package/dist/index.js +150 -0
  16. package/dist/load-configs/index.d.ts +34 -0
  17. package/dist/load-configs/index.js +124 -0
  18. package/dist/{types/loadEnv.d.ts → loadEnv.d.ts} +1 -1
  19. package/dist/loadEnv.js +21 -0
  20. package/dist/loadPlugins.d.ts +18 -0
  21. package/dist/loadPlugins.js +65 -0
  22. package/dist/manager.d.ts +87 -0
  23. package/dist/manager.js +24 -0
  24. package/dist/runBin.d.ts +5 -0
  25. package/dist/runBin.js +51 -0
  26. package/dist/schema/patchSchema.d.ts +19 -0
  27. package/dist/schema/patchSchema.js +57 -0
  28. package/dist/schema/source.d.ts +9 -0
  29. package/dist/schema/source.js +10 -0
  30. package/dist/schema/testing.d.ts +13 -0
  31. package/dist/schema/testing.js +11 -0
  32. package/dist/schema/traverseSchema.d.ts +2 -0
  33. package/dist/schema/traverseSchema.js +20 -0
  34. package/dist/types/config/index.d.ts +49 -125
  35. package/dist/types/config/index.js +2 -0
  36. package/dist/types/config/testing.d.ts +15 -0
  37. package/dist/types/config/testing.js +2 -0
  38. package/dist/types/context.d.ts +28 -14
  39. package/dist/types/context.js +2 -0
  40. package/dist/types/hooks.d.ts +44 -0
  41. package/dist/types/hooks.js +2 -0
  42. package/dist/types/index.d.ts +9 -87
  43. package/dist/types/index.js +21 -0
  44. package/dist/types/plugin.d.ts +26 -0
  45. package/dist/types/plugin.js +2 -0
  46. package/dist/types/pluginAPI.d.ts +18 -0
  47. package/dist/types/pluginAPI.js +2 -0
  48. package/dist/utils/commander.d.ts +4 -0
  49. package/dist/utils/commander.js +20 -0
  50. package/dist/utils/mergeConfig.d.ts +2 -0
  51. package/dist/utils/mergeConfig.js +32 -0
  52. package/dist/utils/repeatKeyWarning.d.ts +3 -0
  53. package/dist/utils/repeatKeyWarning.js +22 -0
  54. package/package.json +52 -48
  55. package/bin/modern-js.js +0 -18
  56. package/dist/js/modern/config/defaults.js +0 -100
  57. package/dist/js/modern/config/index.js +0 -104
  58. package/dist/js/modern/config/mergeConfig.js +0 -20
  59. package/dist/js/modern/config/schema/deploy.js +0 -20
  60. package/dist/js/modern/config/schema/index.js +0 -107
  61. package/dist/js/modern/config/schema/output.js +0 -147
  62. package/dist/js/modern/config/schema/server.js +0 -170
  63. package/dist/js/modern/config/schema/source.js +0 -59
  64. package/dist/js/modern/config/schema/tools.js +0 -33
  65. package/dist/js/modern/context.js +0 -25
  66. package/dist/js/modern/index.js +0 -142
  67. package/dist/js/modern/initWatcher.js +0 -46
  68. package/dist/js/modern/loadEnv.js +0 -12
  69. package/dist/js/modern/loadPlugins.js +0 -66
  70. package/dist/js/modern/utils/commander.js +0 -19
  71. package/dist/js/modern/utils/repeatKeyWarning.js +0 -18
  72. package/dist/js/node/config/defaults.js +0 -107
  73. package/dist/js/node/config/index.js +0 -142
  74. package/dist/js/node/config/mergeConfig.js +0 -32
  75. package/dist/js/node/config/schema/deploy.js +0 -29
  76. package/dist/js/node/config/schema/index.js +0 -129
  77. package/dist/js/node/config/schema/output.js +0 -156
  78. package/dist/js/node/config/schema/server.js +0 -179
  79. package/dist/js/node/config/schema/source.js +0 -68
  80. package/dist/js/node/config/schema/tools.js +0 -40
  81. package/dist/js/node/context.js +0 -52
  82. package/dist/js/node/index.js +0 -247
  83. package/dist/js/node/initWatcher.js +0 -67
  84. package/dist/js/node/loadEnv.js +0 -28
  85. package/dist/js/node/loadPlugins.js +0 -76
  86. package/dist/js/node/utils/commander.js +0 -35
  87. package/dist/js/node/utils/repeatKeyWarning.js +0 -31
  88. package/dist/types/config/defaults.d.ts +0 -25
  89. package/dist/types/config/mergeConfig.d.ts +0 -29
  90. package/dist/types/config/schema/deploy.d.ts +0 -19
  91. package/dist/types/config/schema/index.d.ts +0 -466
  92. package/dist/types/config/schema/output.d.ts +0 -146
  93. package/dist/types/config/schema/server.d.ts +0 -182
  94. package/dist/types/config/schema/source.d.ts +0 -58
  95. package/dist/types/config/schema/tools.d.ts +0 -33
  96. package/dist/types/initWatcher.d.ts +0 -3
  97. package/dist/types/loadPlugins.d.ts +0 -16
  98. package/dist/types/utils/commander.d.ts +0 -7
  99. package/dist/types/utils/repeatKeyWarning.d.ts +0 -3
  100. package/modern.config.js +0 -13
  101. package/src/config/defaults.ts +0 -101
  102. package/src/config/index.ts +0 -296
  103. package/src/config/mergeConfig.ts +0 -68
  104. package/src/config/schema/deploy.ts +0 -17
  105. package/src/config/schema/index.ts +0 -116
  106. package/src/config/schema/output.ts +0 -66
  107. package/src/config/schema/server.ts +0 -106
  108. package/src/config/schema/source.ts +0 -34
  109. package/src/config/schema/tools.ts +0 -15
  110. package/src/context.ts +0 -46
  111. package/src/index.ts +0 -247
  112. package/src/initWatcher.ts +0 -77
  113. package/src/loadEnv.ts +0 -21
  114. package/src/loadPlugins.ts +0 -81
  115. package/src/types.d.ts +0 -0
  116. package/src/utils/commander.ts +0 -22
  117. package/src/utils/repeatKeyWarning.ts +0 -29
  118. package/tests/.eslintrc.js +0 -6
  119. package/tests/fixtures/load-plugin/not-found/package.json +0 -3
  120. package/tests/fixtures/load-plugin/not-found/test-plugin-a.js +0 -1
  121. package/tests/fixtures/load-plugin/user-plugins/package.json +0 -3
  122. package/tests/fixtures/load-plugin/user-plugins/test-plugin-a.js +0 -1
  123. package/tests/fixtures/load-plugin/user-plugins/test-plugin-b.js +0 -3
  124. package/tests/loadEnv.test.ts +0 -100
  125. package/tests/loadPlugin.test.ts +0 -29
  126. package/tests/mergeConfig.test.ts +0 -78
  127. package/tests/repeatKeyWarning.test.ts +0 -68
  128. package/tests/schema.test.ts +0 -109
  129. package/tests/tsconfig.json +0 -13
  130. package/tsconfig.json +0 -14
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.loadConfig = exports.getConfigFilePath = exports.clearFilesOverTime = exports.getDependencies = exports.getPackageConfig = exports.PACKAGE_JSON_CONFIG_NAME = exports.CONFIG_FILE_NAME = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const utils_1 = require("@modern-js/utils");
9
+ const node_bundle_require_1 = require("@modern-js/node-bundle-require");
10
+ const debug = (0, utils_1.createDebugger)('load-config');
11
+ exports.CONFIG_FILE_NAME = 'modern.config';
12
+ exports.PACKAGE_JSON_CONFIG_NAME = 'modernConfig';
13
+ /**
14
+ * Get user config from package.json.
15
+ * @param appDirectory - App root directory.
16
+ * @returns modernConfig or undefined
17
+ */
18
+ const getPackageConfig = (appDirectory, packageJsonConfig) => {
19
+ const json = JSON.parse(utils_1.fs.readFileSync(path_1.default.resolve(appDirectory, './package.json'), 'utf8'));
20
+ return json[packageJsonConfig !== null && packageJsonConfig !== void 0 ? packageJsonConfig : exports.PACKAGE_JSON_CONFIG_NAME];
21
+ };
22
+ exports.getPackageConfig = getPackageConfig;
23
+ /**
24
+ * Get the file dependencies by module.children, ignore file path in node_modules and this monorepo packages default.
25
+ * @param filePath - Absolute file path.
26
+ * @returns File dependencies array.
27
+ */
28
+ const getDependencies = (filePath) => {
29
+ const mod = require.cache[filePath];
30
+ if (!mod) {
31
+ debug(`${filePath} has not been required yet`);
32
+ return [];
33
+ }
34
+ const deps = [];
35
+ if (!/\/node_modules\/|\/modern-js\/packages\//.test(mod.id)) {
36
+ deps.push(mod.id);
37
+ for (const child of mod.children) {
38
+ deps.push(...(0, exports.getDependencies)(child.id));
39
+ }
40
+ }
41
+ return deps;
42
+ };
43
+ exports.getDependencies = getDependencies;
44
+ /**
45
+ *
46
+ * @param targetDir target dir
47
+ * @param overtime Unit of second
48
+ */
49
+ const clearFilesOverTime = async (targetDir, overtime) => {
50
+ // when stats is true, globby return Stats[]
51
+ const files = (await (0, utils_1.globby)(`${targetDir}/**/*`, {
52
+ stats: true,
53
+ absolute: true,
54
+ }));
55
+ const currentTime = Date.now();
56
+ if (files.length > 0) {
57
+ for (const file of files) {
58
+ if (currentTime - file.stats.birthtimeMs >= overtime * 1000) {
59
+ utils_1.fs.unlinkSync(file.path);
60
+ }
61
+ }
62
+ }
63
+ };
64
+ exports.clearFilesOverTime = clearFilesOverTime;
65
+ const bundleRequireWithCatch = async (configFile, { appDirectory }) => {
66
+ try {
67
+ const mod = await (0, node_bundle_require_1.bundleRequire)(configFile, {
68
+ autoClear: false,
69
+ getOutputFile: async (filePath) => {
70
+ const defaultOutputFileName = path_1.default.basename(await (0, node_bundle_require_1.defaultGetOutputFile)(filePath));
71
+ const outputPath = path_1.default.join(appDirectory, utils_1.CONFIG_CACHE_DIR);
72
+ // 10 min
73
+ const timeLimit = 10 * 60;
74
+ await (0, exports.clearFilesOverTime)(outputPath, timeLimit);
75
+ return path_1.default.join(outputPath, defaultOutputFileName);
76
+ },
77
+ });
78
+ return mod;
79
+ }
80
+ catch (e) {
81
+ if (e instanceof Error) {
82
+ e.message = `Get Error while loading config file: ${configFile}, please check it and retry.\n${e.message || ''}`;
83
+ }
84
+ throw e;
85
+ }
86
+ };
87
+ const getConfigFilePath = (appDirectory, filePath) => {
88
+ if (filePath) {
89
+ if (path_1.default.isAbsolute(filePath)) {
90
+ return filePath;
91
+ }
92
+ return path_1.default.resolve(appDirectory, filePath);
93
+ }
94
+ return (0, utils_1.findExists)(utils_1.CONFIG_FILE_EXTENSIONS.map(extension => path_1.default.resolve(appDirectory, `${exports.CONFIG_FILE_NAME}${extension}`)));
95
+ };
96
+ exports.getConfigFilePath = getConfigFilePath;
97
+ /**
98
+ * Parse and load user config file, support extensions like .ts, mjs, js, ejs.
99
+ * @param appDirectory - App root directory, from which start search user config file.
100
+ * @param filePath - Specific absolute config file path.
101
+ * @returns Object contain config file path, user config object and dependency files used by config file.
102
+ */
103
+ const loadConfig = async (appDirectory, filePath, packageJsonConfig) => {
104
+ const configFile = (0, exports.getConfigFilePath)(appDirectory, filePath);
105
+ const pkgConfig = (0, exports.getPackageConfig)(appDirectory, packageJsonConfig);
106
+ let config;
107
+ const dependencies = pkgConfig
108
+ ? [path_1.default.resolve(appDirectory, './package.json')]
109
+ : [];
110
+ if (configFile) {
111
+ delete require.cache[configFile];
112
+ const mod = await bundleRequireWithCatch(configFile, { appDirectory });
113
+ config = mod.default || mod;
114
+ // TODO: get deps.
115
+ // dependencies = dependencies.concat(getDependencies(configFile));
116
+ }
117
+ return {
118
+ path: configFile,
119
+ config,
120
+ pkgConfig,
121
+ dependencies,
122
+ };
123
+ };
124
+ exports.loadConfig = loadConfig;
@@ -1 +1 @@
1
- export declare const loadEnv: (appDirectory: string, mode?: string) => void;
1
+ export declare const loadEnv: (appDirectory: string, mode?: string) => void;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.loadEnv = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const utils_1 = require("@modern-js/utils");
10
+ const loadEnv = (appDirectory, mode = process.env.NODE_ENV) => {
11
+ // Don't change the order of the filenames, since they are ordered by the priority.
12
+ // Files on the left have more priority than files on the right.
13
+ [`.env.${mode}.local`, '.env.local', `.env.${mode}`, '.env']
14
+ .map(name => path_1.default.resolve(appDirectory, name))
15
+ .filter(filePath => fs_1.default.existsSync(filePath) && !fs_1.default.statSync(filePath).isDirectory())
16
+ .forEach(filePath => {
17
+ const envConfig = utils_1.dotenv.config({ path: filePath });
18
+ (0, utils_1.dotenvExpand)(envConfig);
19
+ });
20
+ };
21
+ exports.loadEnv = loadEnv;
@@ -0,0 +1,18 @@
1
+ import { InternalPlugins } from '@modern-js/types';
2
+ import type { CliPlugin, UserConfig, OldPluginConfig, PluginConfig } from './types';
3
+ export declare type TransformPlugin = (plugin: PluginConfig, resolvedConfig: UserConfig, pluginOptions?: any) => PluginConfig;
4
+ export declare const isOldPluginConfig: (config?: PluginConfig) => config is OldPluginConfig;
5
+ /**
6
+ * Load internal plugins which in @modern-js scope and user's custom plugins.
7
+ * @param appDirectory - Application root directory.
8
+ * @param userConfig - Resolved user config.
9
+ * @param options.internalPlugins - Internal plugins.
10
+ * @param options.transformPlugin - transform plugin before using it. Used for compatible with legacy jupiter plugins.
11
+ * @returns Plugin Objects has been required.
12
+ */
13
+ export declare const loadPlugins: (appDirectory: string, userConfig: UserConfig, options?: {
14
+ internalPlugins?: InternalPlugins;
15
+ autoLoad?: InternalPlugins;
16
+ transformPlugin?: TransformPlugin;
17
+ forceAutoLoadPlugins?: boolean;
18
+ }) => Promise<CliPlugin<{}, {}, {}, {}>[]>;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadPlugins = exports.isOldPluginConfig = void 0;
4
+ const utils_1 = require("@modern-js/utils");
5
+ const manager_1 = require("./manager");
6
+ const debug = (0, utils_1.createDebugger)('load-plugins');
7
+ const resolveCliPlugin = async (p, userConfig, appDirectory, transformPlugin) => {
8
+ const pkg = typeof p === 'string' ? p : p[0];
9
+ const pluginOptions = typeof p === 'string' ? undefined : p[1];
10
+ const path = (0, utils_1.tryResolve)(pkg, appDirectory);
11
+ let module;
12
+ try {
13
+ module = (0, utils_1.compatRequire)(path);
14
+ }
15
+ catch (e) {
16
+ // load esm module
17
+ ({ default: module } = await (0, utils_1.dynamicImport)(path));
18
+ }
19
+ if (transformPlugin) {
20
+ module = transformPlugin(module, userConfig, pluginOptions);
21
+ }
22
+ if (typeof module === 'function') {
23
+ const result = module(pluginOptions);
24
+ return (0, manager_1.createPlugin)(result.setup, result);
25
+ }
26
+ return module;
27
+ };
28
+ const isOldPluginConfig = (config) => Array.isArray(config) &&
29
+ config.some(item => {
30
+ return typeof item === 'string' || Array.isArray(item);
31
+ });
32
+ exports.isOldPluginConfig = isOldPluginConfig;
33
+ /**
34
+ * Load internal plugins which in @modern-js scope and user's custom plugins.
35
+ * @param appDirectory - Application root directory.
36
+ * @param userConfig - Resolved user config.
37
+ * @param options.internalPlugins - Internal plugins.
38
+ * @param options.transformPlugin - transform plugin before using it. Used for compatible with legacy jupiter plugins.
39
+ * @returns Plugin Objects has been required.
40
+ */
41
+ const loadPlugins = async (appDirectory, userConfig, options = {}) => {
42
+ const pluginConfig = userConfig.plugins;
43
+ const plugins = [
44
+ ...(options.forceAutoLoadPlugins || userConfig.autoLoadPlugins
45
+ ? (0, utils_1.getInternalPlugins)(appDirectory, options.internalPlugins)
46
+ : []),
47
+ ...((0, exports.isOldPluginConfig)(pluginConfig) ? pluginConfig : []),
48
+ ...(options.autoLoad
49
+ ? (0, utils_1.getInternalPlugins)(appDirectory, options.autoLoad)
50
+ : []),
51
+ ];
52
+ const loadedPlugins = await Promise.all(plugins.map(plugin => {
53
+ const loadedPlugin = resolveCliPlugin(plugin, userConfig, appDirectory, options.transformPlugin);
54
+ // server plugins don't support to accept params
55
+ debug(`resolve plugin %s: %s`, plugin, loadedPlugin);
56
+ return loadedPlugin;
57
+ }));
58
+ if (!(0, exports.isOldPluginConfig)(pluginConfig)) {
59
+ if (pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.length) {
60
+ loadedPlugins.push(...pluginConfig.map(item => (0, manager_1.createPlugin)(item.setup, item)));
61
+ }
62
+ }
63
+ return loadedPlugins;
64
+ };
65
+ exports.loadPlugins = loadPlugins;
@@ -0,0 +1,87 @@
1
+ import { BasePluginAPI } from './types';
2
+ export declare const manager: import("@modern-js/plugin").AsyncManager<{
3
+ config: import("@modern-js/plugin").ParallelWorkflow<void, import("./types").UserConfig<{}, {}, {}, {}>>;
4
+ resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
5
+ resolved: import("./types").NormalizedConfig<{}, {}, {}, {}>;
6
+ }>;
7
+ validateSchema: import("@modern-js/plugin").ParallelWorkflow<void, any>;
8
+ prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
9
+ commands: import("@modern-js/plugin").AsyncWorkflow<{
10
+ program: import("@modern-js/utils").Command;
11
+ }, void>;
12
+ beforeExit: import("@modern-js/plugin").AsyncWorkflow<void, void>;
13
+ addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
14
+ }, BasePluginAPI<{}, {}, {}, {}>>;
15
+ export declare const createPlugin: (setup?: import("@modern-js/plugin").AsyncSetup<{
16
+ config: import("@modern-js/plugin").ParallelWorkflow<void, import("./types").UserConfig<{}, {}, {}, {}>>;
17
+ resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
18
+ resolved: import("./types").NormalizedConfig<{}, {}, {}, {}>;
19
+ }>;
20
+ validateSchema: import("@modern-js/plugin").ParallelWorkflow<void, any>;
21
+ prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
22
+ commands: import("@modern-js/plugin").AsyncWorkflow<{
23
+ program: import("@modern-js/utils").Command;
24
+ }, void>;
25
+ beforeExit: import("@modern-js/plugin").AsyncWorkflow<void, void>;
26
+ addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
27
+ }, BasePluginAPI<{}, {}, {}, {}>> | undefined, options?: import("@modern-js/plugin").PluginOptions<{
28
+ config: import("@modern-js/plugin").ParallelWorkflow<void, import("./types").UserConfig<{}, {}, {}, {}>>;
29
+ resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
30
+ resolved: import("./types").NormalizedConfig<{}, {}, {}, {}>;
31
+ }>;
32
+ validateSchema: import("@modern-js/plugin").ParallelWorkflow<void, any>;
33
+ prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
34
+ commands: import("@modern-js/plugin").AsyncWorkflow<{
35
+ program: import("@modern-js/utils").Command;
36
+ }, void>;
37
+ beforeExit: import("@modern-js/plugin").AsyncWorkflow<void, void>;
38
+ addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
39
+ }, import("@modern-js/plugin").AsyncSetup<{
40
+ config: import("@modern-js/plugin").ParallelWorkflow<void, import("./types").UserConfig<{}, {}, {}, {}>>;
41
+ resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
42
+ resolved: import("./types").NormalizedConfig<{}, {}, {}, {}>;
43
+ }>;
44
+ validateSchema: import("@modern-js/plugin").ParallelWorkflow<void, any>;
45
+ prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
46
+ commands: import("@modern-js/plugin").AsyncWorkflow<{
47
+ program: import("@modern-js/utils").Command;
48
+ }, void>;
49
+ beforeExit: import("@modern-js/plugin").AsyncWorkflow<void, void>;
50
+ addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
51
+ }, BasePluginAPI<{}, {}, {}, {}>>, Record<string, unknown>> | undefined) => import("@modern-js/plugin").AsyncPlugin<{
52
+ config: import("@modern-js/plugin").ParallelWorkflow<void, import("./types").UserConfig<{}, {}, {}, {}>>;
53
+ resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
54
+ resolved: import("./types").NormalizedConfig<{}, {}, {}, {}>;
55
+ }>;
56
+ validateSchema: import("@modern-js/plugin").ParallelWorkflow<void, any>;
57
+ prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
58
+ commands: import("@modern-js/plugin").AsyncWorkflow<{
59
+ program: import("@modern-js/utils").Command;
60
+ }, void>;
61
+ beforeExit: import("@modern-js/plugin").AsyncWorkflow<void, void>;
62
+ addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
63
+ }, BasePluginAPI<{}, {}, {}, {}>>, registerHook: (newHooks: Partial<{
64
+ config: import("@modern-js/plugin").ParallelWorkflow<void, import("./types").UserConfig<{}, {}, {}, {}>>;
65
+ resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
66
+ resolved: import("./types").NormalizedConfig<{}, {}, {}, {}>;
67
+ }>;
68
+ validateSchema: import("@modern-js/plugin").ParallelWorkflow<void, any>;
69
+ prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
70
+ commands: import("@modern-js/plugin").AsyncWorkflow<{
71
+ program: import("@modern-js/utils").Command;
72
+ }, void>;
73
+ beforeExit: import("@modern-js/plugin").AsyncWorkflow<void, void>;
74
+ addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
75
+ }>) => void, mountHook: () => import("@modern-js/plugin").ToRunners<{
76
+ config: import("@modern-js/plugin").ParallelWorkflow<void, import("./types").UserConfig<{}, {}, {}, {}>>;
77
+ resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
78
+ resolved: import("./types").NormalizedConfig<{}, {}, {}, {}>;
79
+ }>;
80
+ validateSchema: import("@modern-js/plugin").ParallelWorkflow<void, any>;
81
+ prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
82
+ commands: import("@modern-js/plugin").AsyncWorkflow<{
83
+ program: import("@modern-js/utils").Command;
84
+ }, void>;
85
+ beforeExit: import("@modern-js/plugin").AsyncWorkflow<void, void>;
86
+ addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
87
+ }>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mountHook = exports.registerHook = exports.createPlugin = exports.manager = void 0;
4
+ const plugin_1 = require("@modern-js/plugin");
5
+ const context_1 = require("./context");
6
+ // eslint-disable-next-line @typescript-eslint/ban-types
7
+ const baseHooks = {
8
+ config: (0, plugin_1.createParallelWorkflow)(),
9
+ resolvedConfig: (0, plugin_1.createAsyncWaterfall)(),
10
+ validateSchema: (0, plugin_1.createParallelWorkflow)(),
11
+ prepare: (0, plugin_1.createAsyncWorkflow)(),
12
+ commands: (0, plugin_1.createAsyncWorkflow)(),
13
+ beforeExit: (0, plugin_1.createAsyncWorkflow)(),
14
+ addRuntimeExports: (0, plugin_1.createAsyncWaterfall)(),
15
+ };
16
+ // eslint-disable-next-line @typescript-eslint/ban-types
17
+ const pluginAPI = {
18
+ setAppContext: context_1.setAppContext,
19
+ useAppContext: context_1.useAppContext,
20
+ useConfigContext: context_1.useConfigContext,
21
+ useResolvedConfigContext: context_1.useResolvedConfigContext,
22
+ };
23
+ exports.manager = (0, plugin_1.createAsyncManager)(baseHooks, pluginAPI);
24
+ exports.createPlugin = exports.manager.createPlugin, exports.registerHook = exports.manager.registerHook, exports.mountHook = exports.manager.useRunner;
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ import { CoreOptions } from '.';
3
+ export declare const run: (otherCoreOptions?: CoreOptions, options?: {
4
+ override?: boolean | ((coreOptions: CoreOptions) => Promise<CoreOptions> | CoreOptions) | undefined;
5
+ }) => Promise<void>;
package/dist/runBin.js ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.run = void 0;
5
+ const utils_1 = require("@modern-js/utils");
6
+ const _1 = require(".");
7
+ const run = async (otherCoreOptions = {}, options = {}) => {
8
+ const command = process.argv[2];
9
+ if (!process.env.NODE_ENV) {
10
+ if (['build', 'start', 'serve', 'deploy', 'release'].includes(command)) {
11
+ process.env.NODE_ENV = 'production';
12
+ }
13
+ else if (command === 'test') {
14
+ process.env.NODE_ENV = 'test';
15
+ }
16
+ else {
17
+ process.env.NODE_ENV = 'development';
18
+ }
19
+ }
20
+ const { version } = require('../package.json');
21
+ const cliParams = (0, utils_1.minimist)(process.argv.slice(2));
22
+ const runOptions = {
23
+ version,
24
+ };
25
+ /**
26
+ * Commands that support specify config files
27
+ * Some commands can't support this feature, such as `new`
28
+ */
29
+ const SUPPORT_CONFIG_PARAM_COMMANDS = [
30
+ 'dev',
31
+ 'build',
32
+ 'deploy',
33
+ 'start',
34
+ 'serve',
35
+ 'inspect',
36
+ ];
37
+ const customConfigFile = cliParams.config || cliParams.c;
38
+ if (SUPPORT_CONFIG_PARAM_COMMANDS.includes(command) && customConfigFile) {
39
+ runOptions.configFile = customConfigFile;
40
+ }
41
+ if (typeof options.override === 'boolean' && options.override) {
42
+ await _1.cli.run(otherCoreOptions);
43
+ }
44
+ else if (typeof (options === null || options === void 0 ? void 0 : options.override) === 'function') {
45
+ await _1.cli.run(await options.override(runOptions));
46
+ }
47
+ else {
48
+ await _1.cli.run(utils_1.lodash.merge({}, runOptions, otherCoreOptions));
49
+ }
50
+ };
51
+ exports.run = run;
@@ -0,0 +1,19 @@
1
+ import { PluginValidateSchema } from '../types';
2
+ export declare const patchSchema: (pluginSchemas: Array<PluginValidateSchema | PluginValidateSchema[]>) => {
3
+ type: string;
4
+ properties: {
5
+ testing: {
6
+ type: string;
7
+ additionalProperties: boolean;
8
+ properties: {
9
+ transformer: {
10
+ type: string;
11
+ enum: string[];
12
+ };
13
+ jest: {
14
+ typeof: string[];
15
+ };
16
+ };
17
+ };
18
+ };
19
+ };
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.patchSchema = void 0;
4
+ const utils_1 = require("@modern-js/utils");
5
+ const lodash_1 = require("@modern-js/utils/lodash");
6
+ const testing_1 = require("./testing");
7
+ const debug = (0, utils_1.createDebugger)('validate-schema');
8
+ const patchSchema = (pluginSchemas) => {
9
+ const finalSchema = (0, lodash_1.cloneDeep)({
10
+ type: 'object',
11
+ properties: {
12
+ testing: testing_1.testing,
13
+ },
14
+ });
15
+ const findTargetNode = (props) => {
16
+ let node = finalSchema.properties;
17
+ for (const prop of props) {
18
+ if (!node[prop]) {
19
+ node[prop] = {
20
+ type: 'object',
21
+ };
22
+ }
23
+ node = node[prop];
24
+ if (!node || !(0, utils_1.isObject)(node)) {
25
+ throw new Error(`add schema ${props.join('.')} error`);
26
+ }
27
+ node.properties = node.hasOwnProperty('properties')
28
+ ? node.properties
29
+ : {};
30
+ node = node.properties;
31
+ }
32
+ return node;
33
+ };
34
+ const finalPluginSchemas = [];
35
+ pluginSchemas.forEach(item => {
36
+ if (Array.isArray(item)) {
37
+ finalPluginSchemas.push(...item);
38
+ }
39
+ else {
40
+ finalPluginSchemas.push(item);
41
+ }
42
+ });
43
+ for (const { target, schema } of finalPluginSchemas) {
44
+ if (!target) {
45
+ throw new Error(`should return target property in plugin schema.`);
46
+ }
47
+ const props = target.split('.');
48
+ const mountProperty = props.pop();
49
+ const targetNode = findTargetNode(props);
50
+ if (!targetNode.hasOwnProperty(mountProperty)) {
51
+ targetNode[mountProperty] = (0, lodash_1.cloneDeep)(schema);
52
+ }
53
+ }
54
+ debug(`final validate schema: %o`, finalSchema);
55
+ return finalSchema;
56
+ };
57
+ exports.patchSchema = patchSchema;
@@ -0,0 +1,9 @@
1
+ export declare const source: {
2
+ type: string;
3
+ additionalProperties: boolean;
4
+ properties: {
5
+ designSystem: {
6
+ type: string;
7
+ };
8
+ };
9
+ };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.source = void 0;
4
+ exports.source = {
5
+ type: 'object',
6
+ additionalProperties: false,
7
+ properties: {
8
+ designSystem: { type: 'object' },
9
+ },
10
+ };
@@ -0,0 +1,13 @@
1
+ export declare const testing: {
2
+ type: string;
3
+ additionalProperties: boolean;
4
+ properties: {
5
+ transformer: {
6
+ type: string;
7
+ enum: string[];
8
+ };
9
+ jest: {
10
+ typeof: string[];
11
+ };
12
+ };
13
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.testing = void 0;
4
+ exports.testing = {
5
+ type: 'object',
6
+ additionalProperties: false,
7
+ properties: {
8
+ transformer: { type: 'string', enum: ['babel-jest', 'ts-jest'] },
9
+ jest: { typeof: ['object', 'function'] },
10
+ },
11
+ };
@@ -0,0 +1,2 @@
1
+ import { patchSchema } from './patchSchema';
2
+ export declare const traverseSchema: (schema: ReturnType<typeof patchSchema>) => string[];
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.traverseSchema = void 0;
4
+ const traverseSchema = (schema) => {
5
+ const keys = [];
6
+ const traverse = ({ properties }, old = []) => {
7
+ for (const key of Object.keys(properties)) {
8
+ const current = [...old, key];
9
+ if (properties[key].type === 'object' && properties[key].properties) {
10
+ traverse(properties[key], current);
11
+ }
12
+ else {
13
+ keys.push(current.join('.'));
14
+ }
15
+ }
16
+ };
17
+ traverse(schema);
18
+ return keys;
19
+ };
20
+ exports.traverseSchema = traverseSchema;