@modern-js/core 1.9.1 → 1.9.2

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 (82) hide show
  1. package/dist/config/index.js +5 -1
  2. package/dist/config/schema/index.js +2 -3
  3. package/dist/index.js +5 -1
  4. package/dist/js/modern/cli.js +29 -0
  5. package/dist/js/modern/config/defaults.js +103 -0
  6. package/dist/js/modern/config/index.js +115 -0
  7. package/dist/js/modern/config/mergeConfig.js +22 -0
  8. package/dist/js/modern/config/schema/deploy.js +17 -0
  9. package/dist/js/modern/config/schema/index.js +107 -0
  10. package/dist/js/modern/config/schema/output.js +147 -0
  11. package/dist/js/modern/config/schema/server.js +170 -0
  12. package/dist/js/modern/config/schema/source.js +59 -0
  13. package/dist/js/modern/config/schema/tools.js +36 -0
  14. package/dist/js/modern/config/types/electron.js +1 -0
  15. package/dist/js/modern/config/types/index.js +1 -0
  16. package/dist/js/modern/config/types/less.js +0 -0
  17. package/dist/js/modern/config/types/sass.js +0 -0
  18. package/dist/js/modern/config/types/ssg.js +0 -0
  19. package/dist/js/modern/config/types/test.js +0 -0
  20. package/dist/js/modern/config/types/unbundle.js +0 -0
  21. package/dist/js/modern/context.js +63 -0
  22. package/dist/js/modern/index.js +169 -0
  23. package/dist/js/modern/initWatcher.js +62 -0
  24. package/dist/js/modern/loadEnv.js +14 -0
  25. package/dist/js/modern/loadPlugins.js +122 -0
  26. package/dist/js/modern/manager.js +28 -0
  27. package/dist/js/modern/pluginAPI.js +11 -0
  28. package/dist/js/modern/utils/commander.js +19 -0
  29. package/dist/js/modern/utils/repeatKeyWarning.js +18 -0
  30. package/dist/js/node/cli.js +35 -0
  31. package/dist/js/node/config/defaults.js +110 -0
  32. package/dist/js/node/config/index.js +182 -0
  33. package/dist/js/node/config/mergeConfig.js +32 -0
  34. package/dist/js/node/config/schema/deploy.js +26 -0
  35. package/dist/js/node/config/schema/index.js +127 -0
  36. package/dist/js/node/config/schema/output.js +156 -0
  37. package/dist/js/node/config/schema/server.js +179 -0
  38. package/dist/js/node/config/schema/source.js +68 -0
  39. package/dist/js/node/config/schema/tools.js +43 -0
  40. package/dist/js/node/config/types/electron.js +5 -0
  41. package/dist/js/node/config/types/index.js +5 -0
  42. package/dist/js/node/config/types/less.js +0 -0
  43. package/dist/js/node/config/types/sass.js +0 -0
  44. package/dist/js/node/config/types/ssg.js +0 -0
  45. package/dist/js/node/config/types/test.js +0 -0
  46. package/dist/js/node/config/types/unbundle.js +0 -0
  47. package/dist/js/node/context.js +93 -0
  48. package/dist/js/node/index.js +329 -0
  49. package/dist/js/node/initWatcher.js +82 -0
  50. package/dist/js/node/loadEnv.js +30 -0
  51. package/dist/js/node/loadPlugins.js +134 -0
  52. package/dist/js/node/manager.js +45 -0
  53. package/dist/js/node/pluginAPI.js +54 -0
  54. package/dist/js/node/utils/commander.js +32 -0
  55. package/dist/js/node/utils/repeatKeyWarning.js +31 -0
  56. package/dist/types/cli.d.ts +1 -0
  57. package/dist/types/config/defaults.d.ts +28 -0
  58. package/dist/types/config/index.d.ts +12 -0
  59. package/dist/types/config/mergeConfig.d.ts +31 -0
  60. package/dist/types/config/schema/deploy.d.ts +16 -0
  61. package/dist/types/config/schema/index.d.ts +466 -0
  62. package/dist/types/config/schema/output.d.ts +146 -0
  63. package/dist/types/config/schema/server.d.ts +182 -0
  64. package/dist/types/config/schema/source.d.ts +58 -0
  65. package/dist/types/config/schema/tools.d.ts +36 -0
  66. package/dist/types/config/types/electron.d.ts +13 -0
  67. package/dist/types/config/types/index.d.ts +252 -0
  68. package/dist/types/config/types/less.d.ts +10 -0
  69. package/dist/types/config/types/sass.d.ts +8 -0
  70. package/dist/types/config/types/ssg.d.ts +13 -0
  71. package/dist/types/config/types/test.d.ts +15 -0
  72. package/dist/types/config/types/unbundle.d.ts +28 -0
  73. package/dist/types/context.d.ts +47 -0
  74. package/dist/types/index.d.ts +64 -0
  75. package/dist/types/initWatcher.d.ts +3 -0
  76. package/dist/types/loadEnv.d.ts +1 -0
  77. package/dist/types/loadPlugins.d.ts +44 -0
  78. package/dist/types/manager.d.ts +75 -0
  79. package/dist/types/pluginAPI.d.ts +13 -0
  80. package/dist/types/utils/commander.d.ts +4 -0
  81. package/dist/types/utils/repeatKeyWarning.d.ts +3 -0
  82. package/package.json +4 -4
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.traverseSchema = exports.patchSchema = void 0;
7
+
8
+ var _utils = require("@modern-js/utils");
9
+
10
+ var _lodash = require("@modern-js/utils/lodash");
11
+
12
+ var _source = require("./source");
13
+
14
+ var _output = require("./output");
15
+
16
+ var _server = require("./server");
17
+
18
+ var _deploy = require("./deploy");
19
+
20
+ var _tools = require("./tools");
21
+
22
+ const debug = (0, _utils.createDebugger)('validate-schema');
23
+ const plugins = {
24
+ type: 'array',
25
+ additionalProperties: false
26
+ };
27
+ const dev = {
28
+ type: 'object',
29
+ properties: {
30
+ assetPrefix: {
31
+ type: ['boolean', 'string']
32
+ },
33
+ https: {
34
+ type: 'boolean'
35
+ }
36
+ },
37
+ additionalProperties: false
38
+ };
39
+
40
+ const patchSchema = pluginSchemas => {
41
+ const finalSchema = (0, _lodash.cloneDeep)({
42
+ type: 'object',
43
+ additionalProperties: false,
44
+ properties: {
45
+ source: _source.source,
46
+ output: _output.output,
47
+ server: _server.server,
48
+ deploy: _deploy.deploy,
49
+ plugins,
50
+ dev,
51
+ tools: _tools.tools
52
+ }
53
+ });
54
+
55
+ const findTargetNode = props => {
56
+ let node = finalSchema.properties;
57
+
58
+ for (const prop of props) {
59
+ node = node[prop];
60
+
61
+ if (!node || !(0, _utils.isObject)(node)) {
62
+ throw new Error(`add schema ${props.join('.')} error`);
63
+ }
64
+
65
+ node.properties = node.hasOwnProperty('properties') ? node.properties : {};
66
+ node = node.properties;
67
+ }
68
+
69
+ return node;
70
+ };
71
+
72
+ const finalPluginSchemas = [];
73
+ pluginSchemas.forEach(item => {
74
+ if (Array.isArray(item)) {
75
+ finalPluginSchemas.push(...item);
76
+ } else {
77
+ finalPluginSchemas.push(item);
78
+ }
79
+ });
80
+
81
+ for (const {
82
+ target,
83
+ schema
84
+ } of finalPluginSchemas) {
85
+ if (!target) {
86
+ throw new Error(`should return target property in plugin schema.`);
87
+ }
88
+
89
+ const props = target.split('.');
90
+ const mountProperty = props.pop();
91
+ const targetNode = findTargetNode(props);
92
+
93
+ if (targetNode.hasOwnProperty(mountProperty)) {
94
+ throw new Error(`${target} already exists in current validate schema`);
95
+ }
96
+
97
+ targetNode[mountProperty] = (0, _lodash.cloneDeep)(schema);
98
+ }
99
+
100
+ debug(`final validate schema: %o`, finalSchema);
101
+ return finalSchema;
102
+ };
103
+
104
+ exports.patchSchema = patchSchema;
105
+
106
+ const traverseSchema = schema => {
107
+ const keys = [];
108
+
109
+ const traverse = ({
110
+ properties
111
+ }, old = []) => {
112
+ for (const key of Object.keys(properties)) {
113
+ const current = [...old, key];
114
+
115
+ if (properties[key].type === 'object' && properties[key].properties) {
116
+ traverse(properties[key], current);
117
+ } else {
118
+ keys.push(current.join('.'));
119
+ }
120
+ }
121
+ };
122
+
123
+ traverse(schema);
124
+ return keys;
125
+ };
126
+
127
+ exports.traverseSchema = traverseSchema;
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.output = void 0;
7
+
8
+ var _utils = require("@modern-js/utils");
9
+
10
+ const output = {
11
+ type: 'object',
12
+ additionalProperties: false,
13
+ properties: {
14
+ assetPrefix: {
15
+ type: 'string'
16
+ },
17
+ path: {
18
+ type: 'string'
19
+ },
20
+ jsPath: {
21
+ type: 'string'
22
+ },
23
+ cssPath: {
24
+ type: 'string'
25
+ },
26
+ htmlPath: {
27
+ type: 'string'
28
+ },
29
+ mediaPath: {
30
+ type: 'string'
31
+ },
32
+ mountId: {
33
+ type: 'string'
34
+ },
35
+ favicon: {
36
+ type: 'string'
37
+ },
38
+ faviconByEntries: {
39
+ type: 'object',
40
+ patternProperties: {
41
+ [_utils.ENTRY_NAME_PATTERN]: {
42
+ type: 'string'
43
+ }
44
+ }
45
+ },
46
+ title: {
47
+ type: 'string'
48
+ },
49
+ titleByEntries: {
50
+ type: 'object',
51
+ patternProperties: {
52
+ [_utils.ENTRY_NAME_PATTERN]: {
53
+ type: 'string'
54
+ }
55
+ }
56
+ },
57
+ meta: {
58
+ type: 'object'
59
+ },
60
+ metaByEntries: {
61
+ type: 'object',
62
+ patternProperties: {
63
+ [_utils.ENTRY_NAME_PATTERN]: {
64
+ type: 'object'
65
+ }
66
+ }
67
+ },
68
+ inject: {
69
+ enum: [true, 'head', 'body', false]
70
+ },
71
+ injectByEntries: {
72
+ type: 'object',
73
+ patternProperties: {
74
+ [_utils.ENTRY_NAME_PATTERN]: {
75
+ enum: [true, 'head', 'body', false]
76
+ }
77
+ }
78
+ },
79
+ copy: {
80
+ type: 'array'
81
+ },
82
+ scriptExt: {
83
+ type: 'object'
84
+ },
85
+ disableTsChecker: {
86
+ type: 'boolean'
87
+ },
88
+ disableHtmlFolder: {
89
+ type: 'boolean'
90
+ },
91
+ disableCssModuleExtension: {
92
+ type: 'boolean'
93
+ },
94
+ disableCssExtract: {
95
+ type: 'boolean'
96
+ },
97
+ enableCssModuleTSDeclaration: {
98
+ type: 'boolean'
99
+ },
100
+ disableMinimize: {
101
+ type: 'boolean'
102
+ },
103
+ enableInlineStyles: {
104
+ type: 'boolean'
105
+ },
106
+ enableInlineScripts: {
107
+ type: 'boolean'
108
+ },
109
+ disableSourceMap: {
110
+ type: 'boolean'
111
+ },
112
+ disableInlineRuntimeChunk: {
113
+ type: 'boolean'
114
+ },
115
+ disableAssetsCache: {
116
+ type: 'boolean'
117
+ },
118
+ enableLatestDecorators: {
119
+ type: 'boolean'
120
+ },
121
+ enableTsLoader: {
122
+ type: 'boolean'
123
+ },
124
+ dataUriLimit: {
125
+ type: 'number'
126
+ },
127
+ templateParameters: {
128
+ type: 'object'
129
+ },
130
+ templateParametersByEntries: {
131
+ type: 'object',
132
+ patternProperties: {
133
+ [_utils.ENTRY_NAME_PATTERN]: {
134
+ type: 'object'
135
+ }
136
+ }
137
+ },
138
+ polyfill: {
139
+ type: 'string',
140
+ enum: ['usage', 'entry', 'off', 'ua']
141
+ },
142
+ cssModuleLocalIdentName: {
143
+ type: 'string'
144
+ },
145
+ federation: {
146
+ type: 'object'
147
+ },
148
+ disableNodePolyfill: {
149
+ type: 'boolean'
150
+ },
151
+ enableModernMode: {
152
+ type: 'boolean'
153
+ }
154
+ }
155
+ };
156
+ exports.output = output;
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.server = void 0;
7
+
8
+ var _utils = require("@modern-js/utils");
9
+
10
+ const SERVER_ROUTE_OBJECT = {
11
+ type: 'object',
12
+ properties: {
13
+ path: {
14
+ type: 'string'
15
+ },
16
+ headers: {
17
+ type: 'object'
18
+ }
19
+ },
20
+ additionalProperties: false
21
+ };
22
+ const server = {
23
+ type: 'object',
24
+ additionalProperties: false,
25
+ properties: {
26
+ port: {
27
+ type: 'number'
28
+ },
29
+ ssr: {
30
+ if: {
31
+ type: 'object'
32
+ },
33
+ then: {
34
+ properties: {
35
+ disableLoadable: {
36
+ type: 'boolean'
37
+ },
38
+ disableHelmet: {
39
+ type: 'boolean'
40
+ },
41
+ disableRedirect: {
42
+ type: 'boolean'
43
+ },
44
+ enableAsyncData: {
45
+ type: 'boolean'
46
+ },
47
+ enableProductWarning: {
48
+ type: 'boolean'
49
+ },
50
+ timeout: {
51
+ type: 'number'
52
+ },
53
+ asyncDataTimeout: {
54
+ type: 'number'
55
+ }
56
+ }
57
+ },
58
+ else: {
59
+ type: 'boolean'
60
+ }
61
+ },
62
+ ssrByEntries: {
63
+ type: 'object',
64
+ patternProperties: {
65
+ [_utils.ENTRY_NAME_PATTERN]: {
66
+ if: {
67
+ type: 'object'
68
+ },
69
+ then: {
70
+ properties: {
71
+ disableLoadable: {
72
+ type: 'boolean'
73
+ },
74
+ disableHelmet: {
75
+ type: 'boolean'
76
+ },
77
+ disableRedirect: {
78
+ type: 'boolean'
79
+ },
80
+ enableProductWarning: {
81
+ type: 'boolean'
82
+ },
83
+ enableAsyncData: {
84
+ type: 'boolean'
85
+ },
86
+ timeout: {
87
+ type: 'number'
88
+ },
89
+ asyncDataTimeout: {
90
+ type: 'number'
91
+ }
92
+ },
93
+ additionalProperties: false
94
+ },
95
+ else: {
96
+ type: 'boolean'
97
+ }
98
+ }
99
+ }
100
+ },
101
+ routes: {
102
+ type: 'object',
103
+ patternProperties: {
104
+ [_utils.ENTRY_NAME_PATTERN]: {
105
+ if: {
106
+ type: 'object'
107
+ },
108
+ then: {
109
+ properties: {
110
+ route: {
111
+ oneOf: [{
112
+ type: 'string'
113
+ }, {
114
+ type: 'array',
115
+ items: {
116
+ oneOf: [{
117
+ type: 'string'
118
+ }, SERVER_ROUTE_OBJECT]
119
+ }
120
+ }, SERVER_ROUTE_OBJECT]
121
+ },
122
+ disableSpa: {
123
+ type: 'boolean'
124
+ }
125
+ },
126
+ additionalProperties: false
127
+ },
128
+ else: {
129
+ oneOf: [{
130
+ type: 'string'
131
+ }, {
132
+ type: 'array',
133
+ items: {
134
+ type: 'string'
135
+ }
136
+ }]
137
+ }
138
+ }
139
+ }
140
+ },
141
+ publicRoutes: {
142
+ type: 'object',
143
+ patternProperties: {
144
+ [_utils.ENTRY_NAME_PATTERN]: {
145
+ type: ['string']
146
+ }
147
+ }
148
+ },
149
+ baseUrl: {
150
+ oneOf: [{
151
+ type: 'string'
152
+ }, {
153
+ type: 'array',
154
+ items: [{
155
+ type: 'string'
156
+ }]
157
+ }]
158
+ },
159
+ middleware: {
160
+ instanceof: ['Array', 'Function']
161
+ },
162
+ renderHook: {
163
+ instanceof: 'Function'
164
+ },
165
+ logger: {
166
+ type: ['object', 'boolean']
167
+ },
168
+ metrics: {
169
+ type: ['object', 'boolean']
170
+ },
171
+ proxy: {
172
+ type: 'object'
173
+ },
174
+ enableMicroFrontendDebug: {
175
+ type: 'boolean'
176
+ }
177
+ }
178
+ };
179
+ exports.server = server;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.source = void 0;
7
+
8
+ var _utils = require("@modern-js/utils");
9
+
10
+ const source = {
11
+ type: 'object',
12
+ additionalProperties: false,
13
+ properties: {
14
+ entries: {
15
+ type: 'object',
16
+ patternProperties: {
17
+ [_utils.ENTRY_NAME_PATTERN]: {
18
+ if: {
19
+ type: 'object'
20
+ },
21
+ then: {
22
+ required: ['entry'],
23
+ properties: {
24
+ entry: {
25
+ type: ['string', 'array']
26
+ },
27
+ disableMount: {
28
+ type: 'boolean'
29
+ },
30
+ enableFileSystemRoutes: {
31
+ type: 'boolean'
32
+ }
33
+ },
34
+ additionalProperties: false
35
+ },
36
+ else: {
37
+ type: ['string', 'array']
38
+ }
39
+ }
40
+ }
41
+ },
42
+ alias: {
43
+ typeof: ['object', 'function']
44
+ },
45
+ disableDefaultEntries: {
46
+ type: 'boolean'
47
+ },
48
+ envVars: {
49
+ type: 'array'
50
+ },
51
+ globalVars: {
52
+ type: 'object'
53
+ },
54
+ moduleScopes: {
55
+ instanceof: ['Array', 'Function']
56
+ },
57
+ entriesDir: {
58
+ type: 'string'
59
+ },
60
+ configDir: {
61
+ type: 'string'
62
+ },
63
+ include: {
64
+ type: ['array']
65
+ }
66
+ }
67
+ };
68
+ exports.source = source;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.tools = void 0;
7
+ const tools = {
8
+ type: 'object',
9
+ additionalProperties: false,
10
+ properties: {
11
+ webpack: {
12
+ typeof: ['object', 'function']
13
+ },
14
+ babel: {
15
+ typeof: ['object', 'function']
16
+ },
17
+ postcss: {
18
+ typeof: ['object', 'function']
19
+ },
20
+ lodash: {
21
+ typeof: ['object', 'function']
22
+ },
23
+ devServer: {
24
+ type: 'object'
25
+ },
26
+ tsLoader: {
27
+ typeof: ['object', 'function']
28
+ },
29
+ autoprefixer: {
30
+ typeof: ['object', 'function']
31
+ },
32
+ terser: {
33
+ typeof: ['object', 'function']
34
+ },
35
+ minifyCss: {
36
+ typeof: ['object', 'function']
37
+ },
38
+ styledComponents: {
39
+ typeof: ['object', 'function']
40
+ }
41
+ }
42
+ };
43
+ exports.tools = tools;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useResolvedConfigContext = exports.useConfigContext = exports.useAppContext = exports.setAppContext = exports.initAppContext = exports.ResolvedConfigContext = exports.ConfigContext = exports.AppContext = void 0;
7
+
8
+ var _path = _interopRequireDefault(require("path"));
9
+
10
+ var _plugin = require("@modern-js/plugin");
11
+
12
+ var _address = _interopRequireDefault(require("address"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ const AppContext = (0, _plugin.createContext)({});
17
+ exports.AppContext = AppContext;
18
+ const ConfigContext = (0, _plugin.createContext)({});
19
+ exports.ConfigContext = ConfigContext;
20
+ const ResolvedConfigContext = (0, _plugin.createContext)({});
21
+ /**
22
+ * Set app context.
23
+ * @param value new app context. It will override previous app context.
24
+ */
25
+
26
+ exports.ResolvedConfigContext = ResolvedConfigContext;
27
+
28
+ const setAppContext = value => AppContext.set(value);
29
+ /**
30
+ * Get app context, including directories, plugins and some static infos.
31
+ */
32
+
33
+
34
+ exports.setAppContext = setAppContext;
35
+
36
+ const useAppContext = () => AppContext.use().value;
37
+ /**
38
+ * Get original content of user config.
39
+ */
40
+
41
+
42
+ exports.useAppContext = useAppContext;
43
+
44
+ const useConfigContext = () => ConfigContext.use().value;
45
+ /**
46
+ * Get normalized content of user config.
47
+ */
48
+
49
+
50
+ exports.useConfigContext = useConfigContext;
51
+
52
+ const useResolvedConfigContext = () => ResolvedConfigContext.use().value;
53
+
54
+ exports.useResolvedConfigContext = useResolvedConfigContext;
55
+
56
+ const initAppContext = ({
57
+ appDirectory,
58
+ plugins,
59
+ configFile,
60
+ options,
61
+ serverConfigFile
62
+ }) => {
63
+ const {
64
+ metaName = 'modern-js',
65
+ srcDir = 'src',
66
+ distDir = '',
67
+ sharedDir = 'shared'
68
+ } = options || {};
69
+ return {
70
+ metaName,
71
+ appDirectory,
72
+ configFile,
73
+ serverConfigFile,
74
+ ip: _address.default.ip(),
75
+ port: 0,
76
+ packageName: require(_path.default.resolve(appDirectory, './package.json')).name,
77
+ srcDirectory: _path.default.resolve(appDirectory, srcDir),
78
+ distDirectory: distDir,
79
+ sharedDirectory: _path.default.resolve(appDirectory, sharedDir),
80
+ nodeModulesDirectory: _path.default.resolve(appDirectory, './node_modules'),
81
+ internalDirectory: _path.default.resolve(appDirectory, `./node_modules/.${metaName}`),
82
+ plugins,
83
+ htmlTemplates: {},
84
+ serverRoutes: [],
85
+ entrypoints: [],
86
+ checkedEntries: [],
87
+ apiOnly: false,
88
+ internalDirAlias: `@_${metaName.replace(/-/g, '_')}_internal`,
89
+ internalSrcAlias: `@_${metaName.replace(/-/g, '_')}_src`
90
+ };
91
+ };
92
+
93
+ exports.initAppContext = initAppContext;