@modern-js/core 1.3.1 → 1.3.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.
@@ -1,69 +0,0 @@
1
- import mergeWith from 'lodash.mergewith';
2
- import { isFunction } from '@modern-js/utils';
3
- import { UserConfig, SourceConfig, ToolsConfig } from '.';
4
-
5
- export interface NormalizedSourceConfig
6
- extends Omit<SourceConfig, 'alias' | 'moduleScopes'> {
7
- alias: SourceConfig['alias'] | Array<SourceConfig['alias']>;
8
- moduleScopes:
9
- | SourceConfig['moduleScopes']
10
- | Array<SourceConfig['moduleScopes']>;
11
- }
12
-
13
- export interface NormalizedToolsConfig
14
- extends Omit<
15
- ToolsConfig,
16
- | 'webpack'
17
- | 'babel'
18
- | 'postcss'
19
- | 'autoprefixer'
20
- | 'lodash'
21
- | 'tsLoader'
22
- | 'terser'
23
- | 'minifyCss'
24
- | 'esbuild'
25
- > {
26
- webpack: ToolsConfig['webpack'] | Array<NonNullable<ToolsConfig['webpack']>>;
27
- babel: ToolsConfig['babel'] | Array<NonNullable<ToolsConfig['babel']>>;
28
- postcss: ToolsConfig['postcss'] | Array<NonNullable<ToolsConfig['postcss']>>;
29
- autoprefixer:
30
- | ToolsConfig['autoprefixer']
31
- | Array<NonNullable<ToolsConfig['autoprefixer']>>;
32
- lodash: ToolsConfig['lodash'] | Array<ToolsConfig['lodash']>;
33
- tsLoader:
34
- | ToolsConfig['tsLoader']
35
- | Array<NonNullable<ToolsConfig['tsLoader']>>;
36
- terser: ToolsConfig['terser'] | Array<NonNullable<ToolsConfig['terser']>>;
37
- minifyCss:
38
- | ToolsConfig['minifyCss']
39
- | Array<NonNullable<ToolsConfig['minifyCss']>>;
40
- esbuild: ToolsConfig['esbuild'] | Array<NonNullable<ToolsConfig['esbuild']>>;
41
- }
42
- export interface NormalizedConfig
43
- extends Omit<Required<UserConfig>, 'source' | 'tools'> {
44
- source: NormalizedSourceConfig;
45
- tools: NormalizedToolsConfig;
46
- cliOptions?: Record<string, any>;
47
- _raw: UserConfig;
48
- }
49
-
50
- /**
51
- * merge configuration from modern.config.js and plugins.
52
- *
53
- * @param configs - Configuration from modern.config.ts or plugin's config hook.
54
- * @returns - normalized user config.
55
- */
56
- export const mergeConfig = (
57
- configs: Array<UserConfig | NormalizedConfig>,
58
- ): NormalizedConfig =>
59
- mergeWith({}, ...configs, (target: any, source: any) => {
60
- if (Array.isArray(target) && Array.isArray(source)) {
61
- return [...target, ...source];
62
- }
63
- if (isFunction(source)) {
64
- return Array.isArray(target)
65
- ? [...target, source]
66
- : [target, source].filter(Boolean);
67
- }
68
- return undefined;
69
- });
@@ -1,17 +0,0 @@
1
- import { ENTRY_NAME_PATTERN } from '@modern-js/utils';
2
-
3
- export const deploy = {
4
- type: 'object',
5
- properties: {
6
- microFrontend: {
7
- type: ['boolean', 'object'],
8
- },
9
- domain: { type: ['array', 'string'] },
10
- domainByEntries: {
11
- type: 'object',
12
- patternProperties: {
13
- [ENTRY_NAME_PATTERN]: { type: ['array', 'string'] },
14
- },
15
- },
16
- },
17
- };
@@ -1,116 +0,0 @@
1
- import { JSONSchemaType } from 'ajv';
2
- import { isObject, createDebugger } from '@modern-js/utils';
3
- import cloneDeep from 'lodash.clonedeep';
4
- import { source } from './source';
5
- import { output } from './output';
6
- import { server } from './server';
7
- import { deploy } from './deploy';
8
- import { tools } from './tools';
9
-
10
- const debug = createDebugger('validate-schema');
11
-
12
- const plugins = {
13
- type: 'array',
14
- additionalProperties: false,
15
- };
16
-
17
- const dev = {
18
- type: 'object',
19
- properties: {
20
- assetPrefix: { type: ['boolean', 'string'] },
21
- https: {
22
- type: 'boolean',
23
- },
24
- },
25
- additionalProperties: false,
26
- };
27
- export interface PluginValidateSchema {
28
- target: string;
29
- schema: JSONSchemaType<any>;
30
- }
31
-
32
- export const patchSchema = (
33
- pluginSchemas: Array<PluginValidateSchema | PluginValidateSchema[]>,
34
- ) => {
35
- const finalSchema = cloneDeep({
36
- type: 'object',
37
- additionalProperties: false,
38
- properties: {
39
- source,
40
- output,
41
- server,
42
- deploy,
43
- plugins,
44
- dev,
45
- tools,
46
- },
47
- });
48
-
49
- const findTargetNode = (props: string[]) => {
50
- let node = finalSchema.properties;
51
-
52
- for (const prop of props) {
53
- node = node[prop as keyof typeof node] as any;
54
- if (!node || !isObject(node)) {
55
- throw new Error(`add schema ${props.join('.')} error`);
56
- }
57
- (node as any).properties = (node as any).hasOwnProperty('properties')
58
- ? (node as any).properties
59
- : {};
60
-
61
- node = (node as any).properties;
62
- }
63
- return node;
64
- };
65
-
66
- const finalPluginSchemas: PluginValidateSchema[] = [];
67
- pluginSchemas.forEach(item => {
68
- if (Array.isArray(item)) {
69
- finalPluginSchemas.push(...item);
70
- } else {
71
- finalPluginSchemas.push(item);
72
- }
73
- });
74
- for (const { target, schema } of finalPluginSchemas) {
75
- if (!target) {
76
- throw new Error(`should return target property in plugin schema.`);
77
- }
78
- const props = target.split('.');
79
-
80
- const mountProperty = props.pop();
81
-
82
- const targetNode = findTargetNode(props);
83
-
84
- if (targetNode.hasOwnProperty(mountProperty!)) {
85
- throw new Error(`${target} already exists in current validate schema`);
86
- }
87
-
88
- (targetNode as any)[mountProperty as string] = cloneDeep(schema);
89
- }
90
-
91
- debug(`final validate schema: %o`, finalSchema);
92
-
93
- return finalSchema;
94
- };
95
-
96
- export const traverseSchema = (schema: ReturnType<typeof patchSchema>) => {
97
- const keys: string[] = [];
98
-
99
- const traverse = (
100
- { properties }: { properties: any },
101
- old: string[] = [],
102
- ) => {
103
- for (const key of Object.keys(properties)) {
104
- const current = [...old, key];
105
- if (properties[key].type === 'object' && properties[key].properties) {
106
- traverse(properties[key], current);
107
- } else {
108
- keys.push(current.join('.'));
109
- }
110
- }
111
- };
112
-
113
- traverse(schema);
114
-
115
- return keys;
116
- };
@@ -1,65 +0,0 @@
1
- import { ENTRY_NAME_PATTERN } from '@modern-js/utils';
2
-
3
- export const output = {
4
- type: 'object',
5
- additionalProperties: false,
6
- properties: {
7
- assetPrefix: { type: 'string' },
8
- path: { type: 'string' },
9
- jsPath: { type: 'string' },
10
- cssPath: { type: 'string' },
11
- htmlPath: { type: 'string' },
12
- mediaPath: { type: 'string' },
13
- mountId: { type: 'string' },
14
- favicon: { type: 'string' },
15
- faviconByEntries: {
16
- type: 'object',
17
- patternProperties: { [ENTRY_NAME_PATTERN]: { type: 'string' } },
18
- },
19
- title: { type: 'string' },
20
- titleByEntries: {
21
- type: 'object',
22
- patternProperties: { [ENTRY_NAME_PATTERN]: { type: 'string' } },
23
- },
24
- meta: { type: 'object' },
25
- metaByEntries: {
26
- type: 'object',
27
- patternProperties: { [ENTRY_NAME_PATTERN]: { type: 'object' } },
28
- },
29
- inject: { enum: [true, 'head', 'body', false] },
30
- injectByEntries: {
31
- type: 'object',
32
- patternProperties: {
33
- [ENTRY_NAME_PATTERN]: { enum: [true, 'head', 'body', false] },
34
- },
35
- },
36
- copy: { type: 'array' },
37
- scriptExt: { type: 'object' },
38
- disableHtmlFolder: { type: 'boolean' },
39
- disableCssModuleExtension: { type: 'boolean' },
40
- disableCssExtract: { type: 'boolean' },
41
- enableCssModuleTSDeclaration: { type: 'boolean' },
42
- disableMinimize: { type: 'boolean' },
43
- enableInlineStyles: { type: 'boolean' },
44
- enableInlineScripts: { type: 'boolean' },
45
- disableSourceMap: { type: 'boolean' },
46
- disableInlineRuntimeChunk: { type: 'boolean' },
47
- disableAssetsCache: { type: 'boolean' },
48
- enableLatestDecorators: { type: 'boolean' },
49
- enableTsLoader: { type: 'boolean' },
50
- dataUriLimit: { type: 'number' },
51
- templateParameters: { type: 'object' },
52
- templateParametersByEntries: {
53
- type: 'object',
54
- patternProperties: { [ENTRY_NAME_PATTERN]: { type: 'object' } },
55
- },
56
- polyfill: {
57
- type: 'string',
58
- enum: ['usage', 'entry', 'off', 'ua'],
59
- },
60
- cssModuleLocalIdentName: { type: 'string' },
61
- federation: { type: 'object' },
62
- disableNodePolyfill: { type: 'boolean' },
63
- enableModernMode: { type: 'boolean' },
64
- },
65
- };
@@ -1,106 +0,0 @@
1
- import { ENTRY_NAME_PATTERN } from '@modern-js/utils';
2
-
3
- const SERVER_ROUTE_OBJECT = {
4
- type: 'object',
5
- properties: {
6
- path: { type: 'string' },
7
- headers: { type: 'object' },
8
- },
9
- additionalProperties: false,
10
- };
11
-
12
- export const server = {
13
- type: 'object',
14
- additionalProperties: false,
15
- properties: {
16
- port: { type: 'number' },
17
- ssr: {
18
- if: { type: 'object' },
19
- then: {
20
- properties: {
21
- disableLoadable: { type: 'boolean' },
22
- disableHelmet: { type: 'boolean' },
23
- disableRedirect: { type: 'boolean' },
24
- enableAsyncData: { type: 'boolean' },
25
- enableProductWarning: { type: 'boolean' },
26
- timeout: { type: 'number' },
27
- asyncDataTimeout: { type: 'number' },
28
- },
29
- },
30
- else: { type: 'boolean' },
31
- },
32
- ssrByEntries: {
33
- type: 'object',
34
- patternProperties: {
35
- [ENTRY_NAME_PATTERN]: {
36
- if: { type: 'object' },
37
- then: {
38
- properties: {
39
- disableLoadable: { type: 'boolean' },
40
- disableHelmet: { type: 'boolean' },
41
- disableRedirect: { type: 'boolean' },
42
- enableProductWarning: { type: 'boolean' },
43
- enableAsyncData: { type: 'boolean' },
44
- timeout: { type: 'number' },
45
- asyncDataTimeout: { type: 'number' },
46
- },
47
- additionalProperties: false,
48
- },
49
- else: { type: 'boolean' },
50
- },
51
- },
52
- },
53
- routes: {
54
- type: 'object',
55
- patternProperties: {
56
- [ENTRY_NAME_PATTERN]: {
57
- if: { type: 'object' },
58
- then: {
59
- properties: {
60
- route: {
61
- oneOf: [
62
- { type: 'string' },
63
- {
64
- type: 'array',
65
- items: { oneOf: [{ type: 'string' }, SERVER_ROUTE_OBJECT] },
66
- },
67
- SERVER_ROUTE_OBJECT,
68
- ],
69
- },
70
- disableSpa: { type: 'boolean' },
71
- },
72
- additionalProperties: false,
73
- },
74
- else: {
75
- oneOf: [
76
- { type: 'string' },
77
- {
78
- type: 'array',
79
- items: { type: 'string' },
80
- },
81
- ],
82
- },
83
- },
84
- },
85
- },
86
- publicRoutes: {
87
- type: 'object',
88
- patternProperties: { [ENTRY_NAME_PATTERN]: { type: ['string'] } },
89
- },
90
- baseUrl: {
91
- oneOf: [
92
- { type: 'string' },
93
- {
94
- type: 'array',
95
- items: [{ type: 'string' }],
96
- },
97
- ],
98
- },
99
- middleware: { instanceof: ['Array', 'Function'] },
100
- renderHook: { instanceof: 'Function' },
101
- logger: { type: 'object' },
102
- metrics: { type: 'object' },
103
- proxy: { type: 'object' },
104
- enableMicroFrontendDebug: { type: 'boolean' },
105
- },
106
- };
@@ -1,34 +0,0 @@
1
- import { ENTRY_NAME_PATTERN } from '@modern-js/utils';
2
-
3
- export const source = {
4
- type: 'object',
5
- additionalProperties: false,
6
- properties: {
7
- entries: {
8
- type: 'object',
9
- patternProperties: {
10
- [ENTRY_NAME_PATTERN]: {
11
- if: { type: 'object' },
12
- then: {
13
- required: ['entry'],
14
- properties: {
15
- entry: { type: ['string', 'array'] },
16
- disableMount: { type: 'boolean' },
17
- enableFileSystemRoutes: { type: 'boolean' },
18
- },
19
- additionalProperties: false,
20
- },
21
- else: { type: ['string', 'array'] },
22
- },
23
- },
24
- },
25
- alias: { typeof: ['object', 'function'] },
26
- disableDefaultEntries: { type: 'boolean' },
27
- envVars: { type: 'array' },
28
- globalVars: { type: 'object' },
29
- moduleScopes: { instanceof: ['Array', 'Function'] },
30
- entriesDir: { type: 'string' },
31
- configDir: { type: 'string' },
32
- include: { type: ['array'] },
33
- },
34
- };
@@ -1,15 +0,0 @@
1
- export const tools = {
2
- type: 'object',
3
- additionalProperties: false,
4
- properties: {
5
- webpack: { typeof: ['object', 'function'] },
6
- babel: { typeof: ['object', 'function'] },
7
- postcss: { typeof: ['object', 'function'] },
8
- lodash: { typeof: ['object', 'function'] },
9
- devServer: { type: 'object' },
10
- tsLoader: { typeof: ['object', 'function'] },
11
- autoprefixer: { typeof: ['object', 'function'] },
12
- terser: { typeof: ['object', 'function'] },
13
- minifyCss: { typeof: ['object', 'function'] },
14
- },
15
- };
package/src/context.ts DELETED
@@ -1,46 +0,0 @@
1
- import path from 'path';
2
- import { createContext } from '@modern-js/plugin';
3
- import address from 'address';
4
- import type { IAppContext } from '@modern-js/types';
5
- import { UserConfig } from './config';
6
- import { NormalizedConfig } from './config/mergeConfig';
7
-
8
- export type { IAppContext };
9
-
10
- export const AppContext = createContext<IAppContext>({} as IAppContext);
11
-
12
- export const ConfigContext = createContext<UserConfig>({} as UserConfig);
13
-
14
- export const ResolvedConfigContext = createContext<NormalizedConfig>(
15
- {} as NormalizedConfig,
16
- );
17
-
18
- export const useAppContext = () => AppContext.use().value;
19
-
20
- export const useConfigContext = () => ConfigContext.use().value;
21
-
22
- export const useResolvedConfigContext = () => ResolvedConfigContext.use().value;
23
-
24
- export const initAppContext = (
25
- appDirectory: string,
26
- plugins: Array<{
27
- cli: any;
28
- server: any;
29
- }>,
30
- configFile: string | false,
31
- ): IAppContext => ({
32
- appDirectory,
33
- configFile,
34
- ip: address.ip(),
35
- port: 0,
36
- packageName: require(path.resolve(appDirectory, './package.json')).name,
37
- srcDirectory: path.resolve(appDirectory, './src'),
38
- distDirectory: '',
39
- sharedDirectory: path.resolve(appDirectory, './shared'),
40
- nodeModulesDirectory: path.resolve(appDirectory, './node_modules'),
41
- internalDirectory: path.resolve(appDirectory, './node_modules/.modern-js'),
42
- plugins,
43
- htmlTemplates: {},
44
- serverRoutes: [],
45
- entrypoints: [],
46
- });