@modern-js/plugin-swc 2.0.0-beta.2 → 2.0.0-beta.4

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 (86) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/package.json +10 -10
  3. package/dist/bin.d.ts +0 -2
  4. package/dist/bin.js +0 -38
  5. package/dist/config/createLoadedConfig.d.ts +0 -6
  6. package/dist/config/createLoadedConfig.js +0 -35
  7. package/dist/config/createResolvedConfig.d.ts +0 -3
  8. package/dist/config/createResolvedConfig.js +0 -91
  9. package/dist/config/defaults.d.ts +0 -29
  10. package/dist/config/defaults.js +0 -110
  11. package/dist/config/index.d.ts +0 -2
  12. package/dist/config/index.js +0 -18
  13. package/dist/config/mergeConfig.d.ts +0 -32
  14. package/dist/config/mergeConfig.js +0 -39
  15. package/dist/config/schema/deploy.d.ts +0 -16
  16. package/dist/config/schema/deploy.js +0 -16
  17. package/dist/config/schema/index.d.ts +0 -499
  18. package/dist/config/schema/index.js +0 -94
  19. package/dist/config/schema/output.d.ts +0 -146
  20. package/dist/config/schema/output.js +0 -68
  21. package/dist/config/schema/server.d.ts +0 -194
  22. package/dist/config/schema/server.js +0 -111
  23. package/dist/config/schema/source.d.ts +0 -64
  24. package/dist/config/schema/source.js +0 -38
  25. package/dist/config/schema/tools.d.ts +0 -51
  26. package/dist/config/schema/tools.js +0 -24
  27. package/dist/config/types/electron.d.ts +0 -13
  28. package/dist/config/types/electron.js +0 -2
  29. package/dist/config/types/index.d.ts +0 -260
  30. package/dist/config/types/index.js +0 -2
  31. package/dist/config/types/less.d.ts +0 -12
  32. package/dist/config/types/less.js +0 -2
  33. package/dist/config/types/postcss.d.ts +0 -28
  34. package/dist/config/types/postcss.js +0 -2
  35. package/dist/config/types/sass.d.ts +0 -10
  36. package/dist/config/types/sass.js +0 -2
  37. package/dist/config/types/ssg.d.ts +0 -15
  38. package/dist/config/types/ssg.js +0 -2
  39. package/dist/config/types/test.d.ts +0 -14
  40. package/dist/config/types/test.js +0 -2
  41. package/dist/config/types/ts-loader.d.ts +0 -23
  42. package/dist/config/types/ts-loader.js +0 -2
  43. package/dist/context.d.ts +0 -34
  44. package/dist/context.js +0 -60
  45. package/dist/initWatcher.d.ts +0 -3
  46. package/dist/initWatcher.js +0 -66
  47. package/dist/load-configs/index.d.ts +0 -34
  48. package/dist/load-configs/index.js +0 -124
  49. package/dist/loadEnv.d.ts +0 -1
  50. package/dist/loadEnv.js +0 -21
  51. package/dist/loadPlugins.d.ts +0 -16
  52. package/dist/loadPlugins.js +0 -60
  53. package/dist/manager.d.ts +0 -87
  54. package/dist/manager.js +0 -24
  55. package/dist/pluginAPI.d.ts +0 -13
  56. package/dist/pluginAPI.js +0 -16
  57. package/dist/schema/patchSchema.d.ts +0 -19
  58. package/dist/schema/patchSchema.js +0 -57
  59. package/dist/schema/source.d.ts +0 -9
  60. package/dist/schema/source.js +0 -10
  61. package/dist/schema/testing.d.ts +0 -13
  62. package/dist/schema/testing.js +0 -11
  63. package/dist/schema/traverseSchema.d.ts +0 -2
  64. package/dist/schema/traverseSchema.js +0 -20
  65. package/dist/types/cli.d.ts +0 -59
  66. package/dist/types/cli.js +0 -2
  67. package/dist/types/config/index.d.ts +0 -41
  68. package/dist/types/config/index.js +0 -2
  69. package/dist/types/config/testing.d.ts +0 -15
  70. package/dist/types/config/testing.js +0 -2
  71. package/dist/types/context.d.ts +0 -26
  72. package/dist/types/context.js +0 -2
  73. package/dist/types/hooks.d.ts +0 -26
  74. package/dist/types/hooks.js +0 -2
  75. package/dist/types/index.d.ts +0 -10
  76. package/dist/types/index.js +0 -21
  77. package/dist/types/plugin.d.ts +0 -26
  78. package/dist/types/plugin.js +0 -2
  79. package/dist/types/pluginAPI.d.ts +0 -18
  80. package/dist/types/pluginAPI.js +0 -2
  81. package/dist/utils/commander.d.ts +0 -4
  82. package/dist/utils/commander.js +0 -20
  83. package/dist/utils/mergeConfig.d.ts +0 -2
  84. package/dist/utils/mergeConfig.js +0 -32
  85. package/dist/utils/repeatKeyWarning.d.ts +0 -3
  86. package/dist/utils/repeatKeyWarning.js +0 -22
@@ -1,124 +0,0 @@
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;
package/dist/loadEnv.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const loadEnv: (appDirectory: string, mode?: string) => void;
package/dist/loadEnv.js DELETED
@@ -1,21 +0,0 @@
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;
@@ -1,16 +0,0 @@
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
- transformPlugin?: TransformPlugin;
16
- }) => Promise<CliPlugin<{}, {}, {}, {}>[]>;
@@ -1,60 +0,0 @@
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
- ...(0, utils_1.getInternalPlugins)(appDirectory, options.internalPlugins),
45
- ...((0, exports.isOldPluginConfig)(pluginConfig) ? pluginConfig : []),
46
- ];
47
- const loadedPlugins = await Promise.all(plugins.map(plugin => {
48
- const loadedPlugin = resolveCliPlugin(plugin, userConfig, appDirectory, options.transformPlugin);
49
- // server plugins don't support to accept params
50
- debug(`resolve plugin %s: %s`, plugin, loadedPlugin);
51
- return loadedPlugin;
52
- }));
53
- if (!(0, exports.isOldPluginConfig)(pluginConfig)) {
54
- if (pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.length) {
55
- loadedPlugins.push(...pluginConfig.map(item => (0, manager_1.createPlugin)(item.setup, item)));
56
- }
57
- }
58
- return loadedPlugins;
59
- };
60
- exports.loadPlugins = loadPlugins;
package/dist/manager.d.ts DELETED
@@ -1,87 +0,0 @@
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>, any, any> | 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
- }>;
package/dist/manager.js DELETED
@@ -1,24 +0,0 @@
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;
@@ -1,13 +0,0 @@
1
- import type { CommonAPI } from '@modern-js/plugin';
2
- import type { CliHooks } from './manager';
3
- import { AppContext, ConfigContext, useAppContext, useConfigContext, ResolvedConfigContext, useResolvedConfigContext } from './context';
4
- export declare const pluginAPI: {
5
- setAppContext: (value: import("@modern-js/types").IAppContext) => void;
6
- useAppContext: () => import("@modern-js/types").IAppContext;
7
- useConfigContext: () => import("./config").UserConfig;
8
- useResolvedConfigContext: () => import("./config").NormalizedConfig;
9
- };
10
- export type { IAppContext } from '@modern-js/types';
11
- /** all apis for cli plugin */
12
- export declare type PluginAPI<ExtendHooks = Record<string, any>> = typeof pluginAPI & CommonAPI<CliHooks & ExtendHooks>;
13
- export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, };
package/dist/pluginAPI.js DELETED
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useResolvedConfigContext = exports.useConfigContext = exports.useAppContext = exports.ResolvedConfigContext = exports.ConfigContext = exports.AppContext = exports.pluginAPI = void 0;
4
- const context_1 = require("./context");
5
- Object.defineProperty(exports, "AppContext", { enumerable: true, get: function () { return context_1.AppContext; } });
6
- Object.defineProperty(exports, "ConfigContext", { enumerable: true, get: function () { return context_1.ConfigContext; } });
7
- Object.defineProperty(exports, "useAppContext", { enumerable: true, get: function () { return context_1.useAppContext; } });
8
- Object.defineProperty(exports, "useConfigContext", { enumerable: true, get: function () { return context_1.useConfigContext; } });
9
- Object.defineProperty(exports, "ResolvedConfigContext", { enumerable: true, get: function () { return context_1.ResolvedConfigContext; } });
10
- Object.defineProperty(exports, "useResolvedConfigContext", { enumerable: true, get: function () { return context_1.useResolvedConfigContext; } });
11
- exports.pluginAPI = {
12
- setAppContext: context_1.setAppContext,
13
- useAppContext: context_1.useAppContext,
14
- useConfigContext: context_1.useConfigContext,
15
- useResolvedConfigContext: context_1.useResolvedConfigContext,
16
- };
@@ -1,19 +0,0 @@
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
- };
@@ -1,57 +0,0 @@
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;
@@ -1,9 +0,0 @@
1
- export declare const source: {
2
- type: string;
3
- additionalProperties: boolean;
4
- properties: {
5
- designSystem: {
6
- type: string;
7
- };
8
- };
9
- };
@@ -1,10 +0,0 @@
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
- };
@@ -1,13 +0,0 @@
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
- };
@@ -1,11 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- import { patchSchema } from './patchSchema';
2
- export declare const traverseSchema: (schema: ReturnType<typeof patchSchema>) => string[];
@@ -1,20 +0,0 @@
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;
@@ -1,59 +0,0 @@
1
- import { AsyncWaterfall, AsyncWorkflow } from '@modern-js/plugin';
2
- import { Entrypoint, HtmlPartials, NestedRoute, PageRoute, RouteLegacy, ServerRoute } from '@modern-js/types';
3
- export interface ImportSpecifier {
4
- local?: string;
5
- imported?: string;
6
- }
7
- export interface ImportStatement {
8
- specifiers: ImportSpecifier[];
9
- value: string;
10
- initialize?: string;
11
- }
12
- export interface RuntimePlugin {
13
- name: string;
14
- options: string;
15
- args?: string;
16
- }
17
- export interface Hooks {
18
- afterMonorepoDeploy: AsyncWorkflow<{
19
- operator: any;
20
- deployProjectNames: string[];
21
- }, void>;
22
- modifyEntryExport: AsyncWaterfall<{
23
- entrypoint: Entrypoint;
24
- exportStatement: string;
25
- }>;
26
- modifyEntryImports: AsyncWaterfall<{
27
- imports: ImportStatement[];
28
- entrypoint: Entrypoint;
29
- }>;
30
- modifyEntryRuntimePlugins: AsyncWaterfall<{
31
- entrypoint: Entrypoint;
32
- plugins: RuntimePlugin[];
33
- }>;
34
- modifyEntryRenderFunction: AsyncWaterfall<{
35
- entrypoint: Entrypoint;
36
- code: string;
37
- }>;
38
- modifyAsyncEntry: AsyncWaterfall<{
39
- entrypoint: Entrypoint;
40
- code: string;
41
- }>;
42
- modifyFileSystemRoutes: AsyncWaterfall<{
43
- entrypoint: Entrypoint;
44
- routes: RouteLegacy[] | (NestedRoute | PageRoute)[];
45
- }>;
46
- modifyServerRoutes: AsyncWaterfall<{
47
- routes: ServerRoute[];
48
- }>;
49
- htmlPartials: AsyncWaterfall<{
50
- entrypoint: Entrypoint;
51
- partials: HtmlPartials;
52
- }>;
53
- addRuntimeExports: AsyncWaterfall<void>;
54
- beforeGenerateRoutes: AsyncWaterfall<{
55
- entrypoint: Entrypoint;
56
- code: string;
57
- }>;
58
- addDefineTypes: AsyncWaterfall<void>;
59
- }
package/dist/types/cli.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,41 +0,0 @@
1
- import { PluginConfig } from '../plugin';
2
- import type { BaseTestingNormalizedConfig, BaseTestingUserConfig } from './testing';
3
- export type { Jest as JestConfig, BaseTestingUserConfig as TestConfig, } from './testing';
4
- declare type DropUndefined<T> = T extends undefined ? never : T;
5
- export declare type UserConfig<Extends extends {
6
- hooks?: ExtendHooks;
7
- userConfig?: ExtendUserConfig;
8
- normalizedConfig?: ExtendNormalizedConfig;
9
- } = {}, ExtendHooks extends Record<string, any> = {}, ExtendUserConfig extends {
10
- source?: Record<string, any>;
11
- tools?: Record<string, any>;
12
- testing?: Record<string, any>;
13
- [property: string]: any;
14
- } = {}, ExtendNormalizedConfig extends Record<string, any> = {}> = {
15
- testing?: BaseTestingUserConfig<DropUndefined<Extends['userConfig']>['testing']>;
16
- plugins?: PluginConfig<Extends>;
17
- } & Omit<Extends['userConfig'], 'plugins' | 'testing'>;
18
- export declare type NormalizedConfig<Extends extends {
19
- hooks?: ExtendHooks;
20
- userConfig?: ExtendUserConfig;
21
- normalizedConfig?: ExtendNormalizedConfig;
22
- } = {}, ExtendHooks extends Record<string, any> = {}, ExtendUserConfig extends Record<string, any> = {}, ExtendNormalizedConfig extends {
23
- source?: Record<string, any>;
24
- tools?: Record<string, any>;
25
- testing?: Record<string, any>;
26
- [property: string]: any;
27
- } = {}> = {
28
- plugins: PluginConfig<Extends>;
29
- testing: BaseTestingNormalizedConfig<DropUndefined<Extends['normalizedConfig']>['testing']>;
30
- } & Omit<Extends['normalizedConfig'], 'plugins' | 'testing'>;
31
- export declare type LoadedConfig<Extends extends {
32
- hooks?: ExtendHooks;
33
- userConfig?: ExtendUserConfig;
34
- } = {}, ExtendHooks extends {} = {}, ExtendUserConfig extends Record<string, any> = {}> = {
35
- config: UserConfig<Extends>;
36
- filePath: string | false;
37
- dependencies: string[];
38
- pkgConfig: UserConfig<Extends>;
39
- jsConfig: UserConfig<Extends>;
40
- };
41
- export declare type ConfigParams = UserConfig | Promise<UserConfig> | ((env: any) => UserConfig | Promise<UserConfig>);
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,15 +0,0 @@
1
- import type { JestConfigTypes, Merge } from '@modern-js/types';
2
- export declare type Jest = JestConfigTypes.InitialOptions;
3
- export declare type BaseTestingUserConfig<ExtendTestingUserConfig = {}> = Merge<{
4
- /**
5
- * Decide which transformer will be used to compile file
6
- * Default: babel-jest
7
- */
8
- transformer?: 'babel-jest' | 'ts-jest';
9
- /**
10
- * Original jest config
11
- * Doc: https://jestjs.io/docs/configuration
12
- */
13
- jest?: Jest | ((jestConfig: Jest) => Jest);
14
- }, ExtendTestingUserConfig>;
15
- export declare type BaseTestingNormalizedConfig<ExtendTestingNormailzedConfig = {}> = BaseTestingUserConfig<ExtendTestingNormailzedConfig>;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });