@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
package/package.json CHANGED
@@ -6,83 +6,87 @@
6
6
  "repository": "modern-js-dev/modern.js",
7
7
  "license": "MIT",
8
8
  "keywords": [
9
- "react",
10
9
  "framework",
11
10
  "modern",
12
11
  "modern.js"
13
12
  ],
14
- "version": "0.0.0-windows-20211056953",
13
+ "version": "0.0.3-20221226",
15
14
  "jsnext:source": "./src/index.ts",
16
- "types": "./dist/types/index.d.ts",
17
- "main": "./dist/js/node/index.js",
18
- "module": "./dist/js/treeshaking/index.js",
19
- "jsnext:modern": "./dist/js/modern/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "main": "./dist/index.js",
17
+ "module": "./dist/index.js",
18
+ "jsnext:modern": "./dist/index.js",
20
19
  "exports": {
21
20
  ".": {
22
21
  "node": {
23
- "import": "./dist/js/modern/index.js",
24
- "require": "./dist/js/node/index.js"
22
+ "jsnext:source": "./src/index.ts",
23
+ "import": "./dist/index.js",
24
+ "require": "./dist/index.js"
25
25
  },
26
- "default": "./dist/js/treeshaking/index.js"
26
+ "default": "./dist/index.js"
27
27
  },
28
- "./bin": "./bin/modern-js.js"
28
+ "./bin": {
29
+ "jsnext:source": "./src/bin.ts",
30
+ "default": "./dist/bin.js"
31
+ },
32
+ "./runBin": {
33
+ "jsnext:source": "./src/runBin.ts",
34
+ "default": "./dist/runBin.js"
35
+ },
36
+ "./types": {
37
+ "default": "./dist/types/index.js"
38
+ }
29
39
  },
30
40
  "typesVersions": {
31
41
  "*": {
32
42
  "config": [
33
- "./dist/types/config/index.d.ts"
43
+ "./dist/config/types/index.d.ts"
44
+ ],
45
+ "types": [
46
+ "./dist/types/index.d.ts"
47
+ ],
48
+ "runBin": [
49
+ "./dist/runBin.d.ts"
34
50
  ]
35
51
  }
36
52
  },
37
- "bin": "./bin/modern-js.js",
38
53
  "dependencies": {
39
- "@babel/code-frame": "^7.14.5",
40
- "@babel/runtime": "^7",
41
- "@modern-js/load-config": "^0.0.0-windows-20211056953",
42
- "@modern-js/plugin": "^0.0.0-windows-20211056953",
43
- "@modern-js/utils": "^0.0.0-windows-20211056953",
44
- "address": "^1.1.2",
45
- "ajv": "^8.6.2",
46
- "ajv-keywords": "^5.0.0",
47
- "better-ajv-errors": "^0.7.0",
48
- "chokidar": "^3.5.2",
49
- "commander": "^8.1.0",
50
- "dotenv": "^10.0.0",
51
- "dotenv-expand": "^5.1.0",
52
- "lodash.clonedeep": "^4.5.0",
53
- "lodash.mergewith": "^4.6.2",
54
- "minimist": "^1.2.5",
55
- "signale": "^1.4.0",
56
- "v8-compile-cache": "^2.3.0"
54
+ "@modern-js/node-bundle-require": "2.0.0-beta.6",
55
+ "@modern-js/utils": "2.0.0-beta.6",
56
+ "@modern-js/plugin": "2.0.0-beta.6"
57
57
  },
58
58
  "devDependencies": {
59
+ "@jest/types": "^27.0.6",
59
60
  "@types/babel__code-frame": "^7.0.3",
60
- "@modern-js/types": "^0.0.0-windows-20211056953",
61
- "@types/jest": "^26",
62
- "@types/lodash.clonedeep": "^4.5.6",
63
- "@types/lodash.mergewith": "^4.6.6",
61
+ "@types/babel__core": "^7.1.16",
62
+ "@types/jest": "^27",
63
+ "@types/less": "^3.0.3",
64
64
  "@types/node": "^14",
65
- "@types/react": "^17",
66
- "@types/react-dom": "^17",
67
- "@types/signale": "^1.4.2",
65
+ "autoprefixer": "^10.3.1",
66
+ "btsm": "2.2.2",
67
+ "electron-builder": "22.7.0",
68
+ "html-webpack-plugin": "5.5.0",
69
+ "jest": "^27",
70
+ "postcss": "^8.4.14",
71
+ "sass": "^1.45.0",
72
+ "terser-webpack-plugin": "^5.1.4",
68
73
  "typescript": "^4",
69
- "@modern-js/plugin-testing": "^0.0.0-windows-20211056953",
70
- "@modern-js/module-tools": "^0.0.0-windows-20211056953"
74
+ "webpack": "^5.75.0",
75
+ "@modern-js/builder-shared": "2.0.0-beta.6",
76
+ "@modern-js/types": "2.0.0-beta.6",
77
+ "@scripts/build": "2.0.0-beta.6",
78
+ "@modern-js/babel-preset-app": "2.0.0-beta.6",
79
+ "@scripts/jest-config": "2.0.0-beta.6"
71
80
  },
72
81
  "sideEffects": false,
73
- "modernConfig": {
74
- "output": {
75
- "packageMode": "node-js"
76
- }
77
- },
78
82
  "publishConfig": {
79
83
  "registry": "https://registry.npmjs.org/",
80
84
  "access": "public"
81
85
  },
82
86
  "scripts": {
83
- "new": "modern new",
84
- "build": "modern build",
85
- "dev": "modern build --watch",
86
- "test": "modern test --passWithNoTests"
87
+ "new": "modern-lib new",
88
+ "build": "tsc",
89
+ "dev": "tsc --watch",
90
+ "test": "jest"
87
91
  }
88
92
  }
package/bin/modern-js.js DELETED
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- require('v8-compile-cache');
4
- const { cli } = require('../');
5
- const { version } = require('../package.json');
6
-
7
- process.env.MODERN_JS_VERSION = version;
8
- if (!process.env.NODE_ENV) {
9
- process.env.NODE_ENV =
10
- // eslint-disable-next-line no-nested-ternary
11
- ['build', 'start', 'deploy'].indexOf(process.argv[2]) !== -1
12
- ? 'production'
13
- : process.argv[2] === 'test'
14
- ? 'test'
15
- : 'development';
16
- }
17
-
18
- cli.run(process.argv.slice(2));
@@ -1,100 +0,0 @@
1
- const sourceDefaults = {
2
- entries: undefined,
3
- disableDefaultEntries: false,
4
- entriesDir: './src',
5
- configDir: './config',
6
- apiDir: './api',
7
- envVars: [],
8
- globalVars: undefined,
9
- alias: undefined,
10
- moduleScopes: undefined,
11
- include: []
12
- };
13
- const outputDefaults = {
14
- assetPrefix: '/',
15
- htmlPath: 'html',
16
- jsPath: 'static/js',
17
- cssPath: 'static/css',
18
- mediaPath: 'static/media',
19
- path: 'dist',
20
- title: '',
21
- titleByEntries: undefined,
22
- meta: {
23
- charset: {
24
- charset: 'utf-8'
25
- },
26
- viewport: 'width=device-width, initial-scale=1.0, shrink-to-fit=no, viewport-fit=cover, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no',
27
- 'http-equiv': {
28
- 'http-equiv': 'x-ua-compatible',
29
- content: 'ie=edge'
30
- },
31
- renderer: 'webkit',
32
- layoutmode: 'standard',
33
- imagemode: 'force',
34
- 'wap-font-scale': 'no',
35
- 'format-detection': 'telephone=no'
36
- },
37
- metaByEntries: undefined,
38
- inject: 'head',
39
- injectByEntries: undefined,
40
- mountId: 'root',
41
- favicon: '',
42
- faviconByEntries: undefined,
43
- copy: undefined,
44
- scriptExt: undefined,
45
- disableHtmlFolder: false,
46
- disableCssModuleExtension: false,
47
- disableCssExtract: false,
48
- enableCssModuleTSDeclaration: false,
49
- disableMinimize: false,
50
- enableInlineStyles: false,
51
- enableInlineScripts: false,
52
- disableSourceMap: false,
53
- disableInlineRuntimeChunk: false,
54
- disableAssetsCache: false,
55
- enableLatestDecorators: false,
56
- polyfill: 'entry',
57
- dataUriLimit: 10000,
58
- templateParameters: {},
59
- templateParametersByEntries: undefined,
60
- cssModuleLocalIdentName: '[name]__[local]--[hash:base64:5]',
61
- enableModernMode: false,
62
- federation: undefined,
63
- disableNodePolyfill: false,
64
- enableTsLoader: false
65
- };
66
- const serverDefaults = {
67
- routes: undefined,
68
- publicRoutes: undefined,
69
- ssr: undefined,
70
- ssrByEntries: undefined,
71
- baseUrl: '/',
72
- port: 8080
73
- };
74
- const devDefaults = {
75
- assetPrefix: false,
76
- https: false
77
- };
78
- const deployDefaults = {
79
- domain: '',
80
- domainByEntries: undefined
81
- };
82
- const toolsDefaults = {
83
- webpack: undefined,
84
- babel: undefined,
85
- postcss: undefined,
86
- autoprefixer: undefined,
87
- lodash: undefined,
88
- devServer: undefined,
89
- tsLoader: undefined,
90
- terser: undefined,
91
- minifyCss: undefined
92
- };
93
- export const defaults = {
94
- source: sourceDefaults,
95
- output: outputDefaults,
96
- server: serverDefaults,
97
- dev: devDefaults,
98
- deploy: deployDefaults,
99
- tools: toolsDefaults
100
- };
@@ -1,104 +0,0 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
2
-
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4
-
5
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
7
- import { loadConfig } from '@modern-js/load-config';
8
- import Ajv from 'ajv';
9
- import ajvKeywords from 'ajv-keywords';
10
- import logger from 'signale';
11
- import { createDebugger, getPort, isDev, PLUGIN_SCHEMAS, chalk } from '@modern-js/utils';
12
- import mergeWith from 'lodash.mergewith';
13
- import betterAjvErrors from 'better-ajv-errors';
14
- import { codeFrameColumns } from '@babel/code-frame';
15
- import { repeatKeyWarning } from "../utils/repeatKeyWarning";
16
- import { defaults } from "./defaults";
17
- import { mergeConfig } from "./mergeConfig";
18
- import { patchSchema } from "./schema";
19
- const debug = createDebugger('resolve-config');
20
- export { defaults as defaultsConfig };
21
- export const defineConfig = config => config;
22
- export const loadUserConfig = async (appDirectory, filePath) => {
23
- const loaded = await loadConfig(appDirectory, filePath);
24
- const config = !loaded ? {} : await (typeof loaded.config === 'function' ? loaded.config(0) : loaded.config);
25
- return {
26
- config: mergeWith({}, config || {}, (loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {}),
27
- jsConfig: config || {},
28
- pkgConfig: (loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {},
29
- filePath: loaded === null || loaded === void 0 ? void 0 : loaded.path,
30
- dependencies: (loaded === null || loaded === void 0 ? void 0 : loaded.dependencies) || []
31
- };
32
- };
33
-
34
- const showAdditionalPropertiesError = error => {
35
- if (error.keyword === 'additionalProperties' && error.instancePath && error.params.additionalProperty) {
36
- const target = `${error.instancePath.substr(1)}.${error.params.additionalProperty}`;
37
- const name = Object.keys(PLUGIN_SCHEMAS).find(key => PLUGIN_SCHEMAS[key].some(schemaItem => schemaItem.target === target));
38
-
39
- if (name) {
40
- logger.warn(`The configuration of ${chalk.bold(target)} is provided by plugin ${chalk.bold(name)}. Please use ${chalk.bold('yarn new')} to enable the corresponding capability.\n`);
41
- }
42
- }
43
- };
44
- /* eslint-disable max-statements, max-params */
45
-
46
-
47
- export const resolveConfig = async (loaded, configs, schemas, isRestart, argv) => {
48
- var _validate$errors;
49
-
50
- const {
51
- config: userConfig,
52
- jsConfig,
53
- pkgConfig
54
- } = loaded;
55
- const ajv = new Ajv({
56
- $data: true,
57
- strict: false
58
- });
59
- ajvKeywords(ajv);
60
- const validateSchema = patchSchema(schemas);
61
- const validate = ajv.compile(validateSchema);
62
- repeatKeyWarning(validateSchema, jsConfig, pkgConfig); // validate user config.
63
-
64
- const valid = validate(userConfig);
65
-
66
- if (!valid && (_validate$errors = validate.errors) !== null && _validate$errors !== void 0 && _validate$errors.length) {
67
- var _validate$errors2;
68
-
69
- showAdditionalPropertiesError(validate === null || validate === void 0 ? void 0 : validate.errors[0]);
70
- const errors = betterAjvErrors(validateSchema, userConfig, (_validate$errors2 = validate.errors) === null || _validate$errors2 === void 0 ? void 0 : _validate$errors2.map(e => _objectSpread(_objectSpread({}, e), {}, {
71
- dataPath: e.instancePath
72
- })), {
73
- format: 'js',
74
- indent: 2
75
- });
76
- logger.log(codeFrameColumns(JSON.stringify(userConfig, null, 2), {
77
- start: errors === null || errors === void 0 ? void 0 : errors[0].start,
78
- end: errors === null || errors === void 0 ? void 0 : errors[0].end
79
- }, {
80
- highlightCode: true,
81
- message: errors === null || errors === void 0 ? void 0 : errors[0].error
82
- }));
83
- throw new Error(`Validate configuration error`);
84
- } // validate config from plugins.
85
-
86
-
87
- for (const config of configs) {
88
- if (!validate(config)) {
89
- logger.error(validate.errors);
90
- throw new Error(`Validate configuration error.`);
91
- }
92
- }
93
-
94
- const resolved = mergeConfig([defaults, ...configs, userConfig]);
95
- resolved._raw = loaded.config;
96
-
97
- if (isDev() && argv[0] === 'dev' && !isRestart) {
98
- resolved.server.port = await getPort(resolved.server.port);
99
- }
100
-
101
- debug('resolved %o', resolved);
102
- return resolved;
103
- };
104
- /* eslint-enable max-statements, max-params */
@@ -1,20 +0,0 @@
1
- import mergeWith from 'lodash.mergewith';
2
- import { isFunction } from '@modern-js/utils';
3
-
4
- /**
5
- * merge configuration from modern.config.js and plugins.
6
- *
7
- * @param configs - Configuration from modern.config.ts or plugin's config hook.
8
- * @returns - normalized user config.
9
- */
10
- export const mergeConfig = configs => mergeWith({}, ...configs, (target, source) => {
11
- if (Array.isArray(target) && Array.isArray(source)) {
12
- return [...target, ...source];
13
- }
14
-
15
- if (isFunction(source)) {
16
- return Array.isArray(target) ? [...target, source] : [target, source].filter(Boolean);
17
- }
18
-
19
- return undefined;
20
- });
@@ -1,20 +0,0 @@
1
- import { ENTRY_NAME_PATTERN } from '@modern-js/utils';
2
- export const deploy = {
3
- type: 'object',
4
- properties: {
5
- microFrontend: {
6
- type: ['boolean', 'object']
7
- },
8
- domain: {
9
- type: ['array', 'string']
10
- },
11
- domainByEntries: {
12
- type: 'object',
13
- patternProperties: {
14
- [ENTRY_NAME_PATTERN]: {
15
- type: ['array', 'string']
16
- }
17
- }
18
- }
19
- }
20
- };
@@ -1,107 +0,0 @@
1
- import { isObject, createDebugger } from '@modern-js/utils';
2
- import cloneDeep from 'lodash.clonedeep';
3
- import { source } from "./source";
4
- import { output } from "./output";
5
- import { server } from "./server";
6
- import { deploy } from "./deploy";
7
- import { tools } from "./tools";
8
- const debug = createDebugger('validate-schema');
9
- const plugins = {
10
- type: 'array',
11
- additionalProperties: false
12
- };
13
- const dev = {
14
- type: 'object',
15
- properties: {
16
- assetPrefix: {
17
- type: ['boolean', 'string']
18
- },
19
- https: {
20
- type: 'boolean'
21
- }
22
- },
23
- additionalProperties: false
24
- };
25
- export const patchSchema = pluginSchemas => {
26
- const finalSchema = cloneDeep({
27
- type: 'object',
28
- additionalProperties: false,
29
- properties: {
30
- source,
31
- output,
32
- server,
33
- deploy,
34
- plugins,
35
- dev,
36
- tools
37
- }
38
- });
39
-
40
- const findTargetNode = props => {
41
- let node = finalSchema.properties;
42
-
43
- for (const prop of props) {
44
- node = node[prop];
45
-
46
- if (!node || !isObject(node)) {
47
- throw new Error(`add schema ${props.join('.')} error`);
48
- }
49
-
50
- node.properties = node.hasOwnProperty('properties') ? node.properties : {};
51
- node = node.properties;
52
- }
53
-
54
- return node;
55
- };
56
-
57
- const finalPluginSchemas = [];
58
- pluginSchemas.forEach(item => {
59
- if (Array.isArray(item)) {
60
- finalPluginSchemas.push(...item);
61
- } else {
62
- finalPluginSchemas.push(item);
63
- }
64
- });
65
-
66
- for (const {
67
- target,
68
- schema
69
- } of finalPluginSchemas) {
70
- if (!target) {
71
- throw new Error(`should return target property in plugin schema.`);
72
- }
73
-
74
- const props = target.split('.');
75
- const mountProperty = props.pop();
76
- const targetNode = findTargetNode(props);
77
-
78
- if (targetNode.hasOwnProperty(mountProperty)) {
79
- throw new Error(`${target} already exists in current validate schema`);
80
- }
81
-
82
- targetNode[mountProperty] = cloneDeep(schema);
83
- }
84
-
85
- debug(`final validate schema: %o`, finalSchema);
86
- return finalSchema;
87
- };
88
- export const traverseSchema = schema => {
89
- const keys = [];
90
-
91
- const traverse = ({
92
- properties
93
- }, old = []) => {
94
- for (const key of Object.keys(properties)) {
95
- const current = [...old, key];
96
-
97
- if (properties[key].type === 'object' && properties[key].properties) {
98
- traverse(properties[key], current);
99
- } else {
100
- keys.push(current.join('.'));
101
- }
102
- }
103
- };
104
-
105
- traverse(schema);
106
- return keys;
107
- };
@@ -1,147 +0,0 @@
1
- import { ENTRY_NAME_PATTERN } from '@modern-js/utils';
2
- export const output = {
3
- type: 'object',
4
- additionalProperties: false,
5
- properties: {
6
- assetPrefix: {
7
- type: 'string'
8
- },
9
- path: {
10
- type: 'string'
11
- },
12
- jsPath: {
13
- type: 'string'
14
- },
15
- cssPath: {
16
- type: 'string'
17
- },
18
- htmlPath: {
19
- type: 'string'
20
- },
21
- mediaPath: {
22
- type: 'string'
23
- },
24
- mountId: {
25
- type: 'string'
26
- },
27
- favicon: {
28
- type: 'string'
29
- },
30
- faviconByEntries: {
31
- type: 'object',
32
- patternProperties: {
33
- [ENTRY_NAME_PATTERN]: {
34
- type: 'string'
35
- }
36
- }
37
- },
38
- title: {
39
- type: 'string'
40
- },
41
- titleByEntries: {
42
- type: 'object',
43
- patternProperties: {
44
- [ENTRY_NAME_PATTERN]: {
45
- type: 'string'
46
- }
47
- }
48
- },
49
- meta: {
50
- type: 'object'
51
- },
52
- metaByEntries: {
53
- type: 'object',
54
- patternProperties: {
55
- [ENTRY_NAME_PATTERN]: {
56
- type: 'object'
57
- }
58
- }
59
- },
60
- inject: {
61
- enum: [true, 'head', 'body', false]
62
- },
63
- injectByEntries: {
64
- type: 'object',
65
- patternProperties: {
66
- [ENTRY_NAME_PATTERN]: {
67
- enum: [true, 'head', 'body', false]
68
- }
69
- }
70
- },
71
- copy: {
72
- type: 'array'
73
- },
74
- scriptExt: {
75
- type: 'object'
76
- },
77
- disableHtmlFolder: {
78
- type: 'boolean'
79
- },
80
- disableCssModuleExtension: {
81
- type: 'boolean'
82
- },
83
- disableCssExtract: {
84
- type: 'boolean'
85
- },
86
- enableCssModuleTSDeclaration: {
87
- type: 'boolean'
88
- },
89
- disableMinimize: {
90
- type: 'boolean'
91
- },
92
- enableInlineStyles: {
93
- type: 'boolean'
94
- },
95
- enableInlineScripts: {
96
- type: 'boolean'
97
- },
98
- disableSourceMap: {
99
- type: 'boolean'
100
- },
101
- disableInlineRuntimeChunk: {
102
- type: 'boolean'
103
- },
104
- disableAssetsCache: {
105
- type: 'boolean'
106
- },
107
- enableLatestDecorators: {
108
- type: 'boolean'
109
- },
110
- enableUsageBuiltIns: {
111
- type: 'boolean'
112
- },
113
- enableTsLoader: {
114
- type: 'boolean'
115
- },
116
- dataUriLimit: {
117
- type: 'number'
118
- },
119
- templateParameters: {
120
- type: 'object'
121
- },
122
- templateParametersByEntries: {
123
- type: 'object',
124
- patternProperties: {
125
- [ENTRY_NAME_PATTERN]: {
126
- type: 'object'
127
- }
128
- }
129
- },
130
- polyfill: {
131
- type: 'string',
132
- enum: ['usage', 'entry', 'off', 'ua']
133
- },
134
- cssModuleLocalIdentName: {
135
- type: 'string'
136
- },
137
- federation: {
138
- type: 'object'
139
- },
140
- disableNodePolyfill: {
141
- type: 'boolean'
142
- },
143
- enableModernMode: {
144
- type: 'boolean'
145
- }
146
- }
147
- };