@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.
- package/CHANGELOG.md +1164 -6
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +5 -0
- package/dist/config/createDefaultConfig.d.ts +2 -0
- package/dist/config/createDefaultConfig.js +9 -0
- package/dist/config/createLoadedConfig.d.ts +6 -0
- package/dist/config/createLoadedConfig.js +35 -0
- package/dist/config/createResolvedConfig.d.ts +3 -0
- package/dist/config/createResolvedConfig.js +92 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.js +19 -0
- package/dist/context.d.ts +35 -0
- package/dist/context.js +61 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.js +150 -0
- package/dist/load-configs/index.d.ts +34 -0
- package/dist/load-configs/index.js +124 -0
- package/dist/{types/loadEnv.d.ts → loadEnv.d.ts} +1 -1
- package/dist/loadEnv.js +21 -0
- package/dist/loadPlugins.d.ts +18 -0
- package/dist/loadPlugins.js +65 -0
- package/dist/manager.d.ts +87 -0
- package/dist/manager.js +24 -0
- package/dist/runBin.d.ts +5 -0
- package/dist/runBin.js +51 -0
- package/dist/schema/patchSchema.d.ts +19 -0
- package/dist/schema/patchSchema.js +57 -0
- package/dist/schema/source.d.ts +9 -0
- package/dist/schema/source.js +10 -0
- package/dist/schema/testing.d.ts +13 -0
- package/dist/schema/testing.js +11 -0
- package/dist/schema/traverseSchema.d.ts +2 -0
- package/dist/schema/traverseSchema.js +20 -0
- package/dist/types/config/index.d.ts +49 -125
- package/dist/types/config/index.js +2 -0
- package/dist/types/config/testing.d.ts +15 -0
- package/dist/types/config/testing.js +2 -0
- package/dist/types/context.d.ts +28 -14
- package/dist/types/context.js +2 -0
- package/dist/types/hooks.d.ts +44 -0
- package/dist/types/hooks.js +2 -0
- package/dist/types/index.d.ts +9 -87
- package/dist/types/index.js +21 -0
- package/dist/types/plugin.d.ts +26 -0
- package/dist/types/plugin.js +2 -0
- package/dist/types/pluginAPI.d.ts +18 -0
- package/dist/types/pluginAPI.js +2 -0
- package/dist/utils/commander.d.ts +4 -0
- package/dist/utils/commander.js +20 -0
- package/dist/utils/mergeConfig.d.ts +2 -0
- package/dist/utils/mergeConfig.js +32 -0
- package/dist/utils/repeatKeyWarning.d.ts +3 -0
- package/dist/utils/repeatKeyWarning.js +22 -0
- package/package.json +52 -48
- package/bin/modern-js.js +0 -18
- package/dist/js/modern/config/defaults.js +0 -100
- package/dist/js/modern/config/index.js +0 -104
- package/dist/js/modern/config/mergeConfig.js +0 -20
- package/dist/js/modern/config/schema/deploy.js +0 -20
- package/dist/js/modern/config/schema/index.js +0 -107
- package/dist/js/modern/config/schema/output.js +0 -147
- package/dist/js/modern/config/schema/server.js +0 -170
- package/dist/js/modern/config/schema/source.js +0 -59
- package/dist/js/modern/config/schema/tools.js +0 -33
- package/dist/js/modern/context.js +0 -25
- package/dist/js/modern/index.js +0 -142
- package/dist/js/modern/initWatcher.js +0 -46
- package/dist/js/modern/loadEnv.js +0 -12
- package/dist/js/modern/loadPlugins.js +0 -66
- package/dist/js/modern/utils/commander.js +0 -19
- package/dist/js/modern/utils/repeatKeyWarning.js +0 -18
- package/dist/js/node/config/defaults.js +0 -107
- package/dist/js/node/config/index.js +0 -142
- package/dist/js/node/config/mergeConfig.js +0 -32
- package/dist/js/node/config/schema/deploy.js +0 -29
- package/dist/js/node/config/schema/index.js +0 -129
- package/dist/js/node/config/schema/output.js +0 -156
- package/dist/js/node/config/schema/server.js +0 -179
- package/dist/js/node/config/schema/source.js +0 -68
- package/dist/js/node/config/schema/tools.js +0 -40
- package/dist/js/node/context.js +0 -52
- package/dist/js/node/index.js +0 -247
- package/dist/js/node/initWatcher.js +0 -67
- package/dist/js/node/loadEnv.js +0 -28
- package/dist/js/node/loadPlugins.js +0 -76
- package/dist/js/node/utils/commander.js +0 -35
- package/dist/js/node/utils/repeatKeyWarning.js +0 -31
- package/dist/types/config/defaults.d.ts +0 -25
- package/dist/types/config/mergeConfig.d.ts +0 -29
- package/dist/types/config/schema/deploy.d.ts +0 -19
- package/dist/types/config/schema/index.d.ts +0 -466
- package/dist/types/config/schema/output.d.ts +0 -146
- package/dist/types/config/schema/server.d.ts +0 -182
- package/dist/types/config/schema/source.d.ts +0 -58
- package/dist/types/config/schema/tools.d.ts +0 -33
- package/dist/types/initWatcher.d.ts +0 -3
- package/dist/types/loadPlugins.d.ts +0 -16
- package/dist/types/utils/commander.d.ts +0 -7
- package/dist/types/utils/repeatKeyWarning.d.ts +0 -3
- package/modern.config.js +0 -13
- package/src/config/defaults.ts +0 -101
- package/src/config/index.ts +0 -296
- package/src/config/mergeConfig.ts +0 -68
- package/src/config/schema/deploy.ts +0 -17
- package/src/config/schema/index.ts +0 -116
- package/src/config/schema/output.ts +0 -66
- package/src/config/schema/server.ts +0 -106
- package/src/config/schema/source.ts +0 -34
- package/src/config/schema/tools.ts +0 -15
- package/src/context.ts +0 -46
- package/src/index.ts +0 -247
- package/src/initWatcher.ts +0 -77
- package/src/loadEnv.ts +0 -21
- package/src/loadPlugins.ts +0 -81
- package/src/types.d.ts +0 -0
- package/src/utils/commander.ts +0 -22
- package/src/utils/repeatKeyWarning.ts +0 -29
- package/tests/.eslintrc.js +0 -6
- package/tests/fixtures/load-plugin/not-found/package.json +0 -3
- package/tests/fixtures/load-plugin/not-found/test-plugin-a.js +0 -1
- package/tests/fixtures/load-plugin/user-plugins/package.json +0 -3
- package/tests/fixtures/load-plugin/user-plugins/test-plugin-a.js +0 -1
- package/tests/fixtures/load-plugin/user-plugins/test-plugin-b.js +0 -3
- package/tests/loadEnv.test.ts +0 -100
- package/tests/loadPlugin.test.ts +0 -29
- package/tests/mergeConfig.test.ts +0 -78
- package/tests/repeatKeyWarning.test.ts +0 -68
- package/tests/schema.test.ts +0 -109
- package/tests/tsconfig.json +0 -13
- package/tsconfig.json +0 -14
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { ENTRY_NAME_PATTERN } from '@modern-js/utils';
|
|
2
|
-
const SERVER_ROUTE_OBJECT = {
|
|
3
|
-
type: 'object',
|
|
4
|
-
properties: {
|
|
5
|
-
path: {
|
|
6
|
-
type: 'string'
|
|
7
|
-
},
|
|
8
|
-
headers: {
|
|
9
|
-
type: 'object'
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
additionalProperties: false
|
|
13
|
-
};
|
|
14
|
-
export const server = {
|
|
15
|
-
type: 'object',
|
|
16
|
-
additionalProperties: false,
|
|
17
|
-
properties: {
|
|
18
|
-
port: {
|
|
19
|
-
type: 'number'
|
|
20
|
-
},
|
|
21
|
-
ssr: {
|
|
22
|
-
if: {
|
|
23
|
-
type: 'object'
|
|
24
|
-
},
|
|
25
|
-
then: {
|
|
26
|
-
properties: {
|
|
27
|
-
disableLoadable: {
|
|
28
|
-
type: 'boolean'
|
|
29
|
-
},
|
|
30
|
-
disableHelmet: {
|
|
31
|
-
type: 'boolean'
|
|
32
|
-
},
|
|
33
|
-
disableRedirect: {
|
|
34
|
-
type: 'boolean'
|
|
35
|
-
},
|
|
36
|
-
enableAsyncData: {
|
|
37
|
-
type: 'boolean'
|
|
38
|
-
},
|
|
39
|
-
enableProductWarning: {
|
|
40
|
-
type: 'boolean'
|
|
41
|
-
},
|
|
42
|
-
timeout: {
|
|
43
|
-
type: 'number'
|
|
44
|
-
},
|
|
45
|
-
asyncDataTimeout: {
|
|
46
|
-
type: 'number'
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
else: {
|
|
51
|
-
type: 'boolean'
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
ssrByEntries: {
|
|
55
|
-
type: 'object',
|
|
56
|
-
patternProperties: {
|
|
57
|
-
[ENTRY_NAME_PATTERN]: {
|
|
58
|
-
if: {
|
|
59
|
-
type: 'object'
|
|
60
|
-
},
|
|
61
|
-
then: {
|
|
62
|
-
properties: {
|
|
63
|
-
disableLoadable: {
|
|
64
|
-
type: 'boolean'
|
|
65
|
-
},
|
|
66
|
-
disableHelmet: {
|
|
67
|
-
type: 'boolean'
|
|
68
|
-
},
|
|
69
|
-
disableRedirect: {
|
|
70
|
-
type: 'boolean'
|
|
71
|
-
},
|
|
72
|
-
enableProductWarning: {
|
|
73
|
-
type: 'boolean'
|
|
74
|
-
},
|
|
75
|
-
enableAsyncData: {
|
|
76
|
-
type: 'boolean'
|
|
77
|
-
},
|
|
78
|
-
timeout: {
|
|
79
|
-
type: 'number'
|
|
80
|
-
},
|
|
81
|
-
asyncDataTimeout: {
|
|
82
|
-
type: 'number'
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
additionalProperties: false
|
|
86
|
-
},
|
|
87
|
-
else: {
|
|
88
|
-
type: 'boolean'
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
routes: {
|
|
94
|
-
type: 'object',
|
|
95
|
-
patternProperties: {
|
|
96
|
-
[ENTRY_NAME_PATTERN]: {
|
|
97
|
-
if: {
|
|
98
|
-
type: 'object'
|
|
99
|
-
},
|
|
100
|
-
then: {
|
|
101
|
-
properties: {
|
|
102
|
-
route: {
|
|
103
|
-
oneOf: [{
|
|
104
|
-
type: 'string'
|
|
105
|
-
}, {
|
|
106
|
-
type: 'array',
|
|
107
|
-
items: {
|
|
108
|
-
oneOf: [{
|
|
109
|
-
type: 'string'
|
|
110
|
-
}, SERVER_ROUTE_OBJECT]
|
|
111
|
-
}
|
|
112
|
-
}, SERVER_ROUTE_OBJECT]
|
|
113
|
-
},
|
|
114
|
-
disableSpa: {
|
|
115
|
-
type: 'boolean'
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
additionalProperties: false
|
|
119
|
-
},
|
|
120
|
-
else: {
|
|
121
|
-
oneOf: [{
|
|
122
|
-
type: 'string'
|
|
123
|
-
}, {
|
|
124
|
-
type: 'array',
|
|
125
|
-
items: {
|
|
126
|
-
type: 'string'
|
|
127
|
-
}
|
|
128
|
-
}]
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
publicRoutes: {
|
|
134
|
-
type: 'object',
|
|
135
|
-
patternProperties: {
|
|
136
|
-
[ENTRY_NAME_PATTERN]: {
|
|
137
|
-
type: ['string']
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
baseUrl: {
|
|
142
|
-
oneOf: [{
|
|
143
|
-
type: 'string'
|
|
144
|
-
}, {
|
|
145
|
-
type: 'array',
|
|
146
|
-
items: [{
|
|
147
|
-
type: 'string'
|
|
148
|
-
}]
|
|
149
|
-
}]
|
|
150
|
-
},
|
|
151
|
-
middleware: {
|
|
152
|
-
instanceof: ['Array', 'Function']
|
|
153
|
-
},
|
|
154
|
-
renderHook: {
|
|
155
|
-
instanceof: 'Function'
|
|
156
|
-
},
|
|
157
|
-
logger: {
|
|
158
|
-
type: 'object'
|
|
159
|
-
},
|
|
160
|
-
measure: {
|
|
161
|
-
type: 'object'
|
|
162
|
-
},
|
|
163
|
-
proxy: {
|
|
164
|
-
type: 'object'
|
|
165
|
-
},
|
|
166
|
-
enableMicroFrontendDebug: {
|
|
167
|
-
type: 'boolean'
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { ENTRY_NAME_PATTERN } from '@modern-js/utils';
|
|
2
|
-
export const source = {
|
|
3
|
-
type: 'object',
|
|
4
|
-
additionalProperties: false,
|
|
5
|
-
properties: {
|
|
6
|
-
entries: {
|
|
7
|
-
type: 'object',
|
|
8
|
-
patternProperties: {
|
|
9
|
-
[ENTRY_NAME_PATTERN]: {
|
|
10
|
-
if: {
|
|
11
|
-
type: 'object'
|
|
12
|
-
},
|
|
13
|
-
then: {
|
|
14
|
-
required: ['entry'],
|
|
15
|
-
properties: {
|
|
16
|
-
entry: {
|
|
17
|
-
type: ['string', 'array']
|
|
18
|
-
},
|
|
19
|
-
disableMount: {
|
|
20
|
-
type: 'boolean'
|
|
21
|
-
},
|
|
22
|
-
enableFileSystemRoutes: {
|
|
23
|
-
type: 'boolean'
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
additionalProperties: false
|
|
27
|
-
},
|
|
28
|
-
else: {
|
|
29
|
-
type: ['string', 'array']
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
alias: {
|
|
35
|
-
typeof: ['object', 'function']
|
|
36
|
-
},
|
|
37
|
-
disableDefaultEntries: {
|
|
38
|
-
type: 'boolean'
|
|
39
|
-
},
|
|
40
|
-
envVars: {
|
|
41
|
-
type: 'array'
|
|
42
|
-
},
|
|
43
|
-
globalVars: {
|
|
44
|
-
type: 'object'
|
|
45
|
-
},
|
|
46
|
-
moduleScopes: {
|
|
47
|
-
instanceof: ['Array', 'Function']
|
|
48
|
-
},
|
|
49
|
-
entriesDir: {
|
|
50
|
-
type: 'string'
|
|
51
|
-
},
|
|
52
|
-
configDir: {
|
|
53
|
-
type: 'string'
|
|
54
|
-
},
|
|
55
|
-
include: {
|
|
56
|
-
type: ['array']
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export const tools = {
|
|
2
|
-
type: 'object',
|
|
3
|
-
additionalProperties: false,
|
|
4
|
-
properties: {
|
|
5
|
-
webpack: {
|
|
6
|
-
typeof: ['object', 'function']
|
|
7
|
-
},
|
|
8
|
-
babel: {
|
|
9
|
-
typeof: ['object', 'function']
|
|
10
|
-
},
|
|
11
|
-
postcss: {
|
|
12
|
-
typeof: ['object', 'function']
|
|
13
|
-
},
|
|
14
|
-
lodash: {
|
|
15
|
-
typeof: ['object', 'function']
|
|
16
|
-
},
|
|
17
|
-
devServer: {
|
|
18
|
-
type: 'object'
|
|
19
|
-
},
|
|
20
|
-
tsLoader: {
|
|
21
|
-
typeof: ['object', 'function']
|
|
22
|
-
},
|
|
23
|
-
autoprefixer: {
|
|
24
|
-
typeof: ['object', 'function']
|
|
25
|
-
},
|
|
26
|
-
terser: {
|
|
27
|
-
typeof: ['object', 'function']
|
|
28
|
-
},
|
|
29
|
-
minifyCss: {
|
|
30
|
-
typeof: ['object', 'function']
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { createContext } from '@modern-js/plugin';
|
|
3
|
-
import address from 'address';
|
|
4
|
-
export const AppContext = createContext({});
|
|
5
|
-
export const ConfigContext = createContext({});
|
|
6
|
-
export const ResolvedConfigContext = createContext({});
|
|
7
|
-
export const useAppContext = () => AppContext.use().value;
|
|
8
|
-
export const useConfigContext = () => ConfigContext.use().value;
|
|
9
|
-
export const useResolvedConfigContext = () => ResolvedConfigContext.use().value;
|
|
10
|
-
export const initAppContext = (appDirectory, plugins, configFile) => ({
|
|
11
|
-
appDirectory,
|
|
12
|
-
configFile,
|
|
13
|
-
ip: address.ip(),
|
|
14
|
-
port: 0,
|
|
15
|
-
packageName: require(path.resolve(appDirectory, './package.json')).name,
|
|
16
|
-
srcDirectory: path.resolve(appDirectory, './src'),
|
|
17
|
-
distDirectory: '',
|
|
18
|
-
sharedDirectory: path.resolve(appDirectory, './shared'),
|
|
19
|
-
nodeModulesDirectory: path.resolve(appDirectory, './node_modules'),
|
|
20
|
-
internalDirectory: path.resolve(appDirectory, './node_modules/.modern-js'),
|
|
21
|
-
plugins,
|
|
22
|
-
htmlTemplates: {},
|
|
23
|
-
serverRoutes: [],
|
|
24
|
-
entrypoints: []
|
|
25
|
-
});
|
package/dist/js/modern/index.js
DELETED
|
@@ -1,142 +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 path from 'path';
|
|
8
|
-
import { compatRequire, pkgUp, ensureAbsolutePath, logger } from '@modern-js/utils';
|
|
9
|
-
import { createAsyncManager, createAsyncWorkflow, createParallelWorkflow } from '@modern-js/plugin';
|
|
10
|
-
import { enable } from '@modern-js/plugin/node';
|
|
11
|
-
import { program } from "./utils/commander";
|
|
12
|
-
import { resolveConfig, defineConfig, loadUserConfig } from "./config";
|
|
13
|
-
import { loadPlugins } from "./loadPlugins";
|
|
14
|
-
import { AppContext, ConfigContext, initAppContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext } from "./context";
|
|
15
|
-
import { initWatcher } from "./initWatcher";
|
|
16
|
-
import { loadEnv } from "./loadEnv";
|
|
17
|
-
export { defaultsConfig } from "./config";
|
|
18
|
-
export * from '@modern-js/plugin';
|
|
19
|
-
export * from '@modern-js/plugin/node';
|
|
20
|
-
program.name('modern').usage('<command> [options]').version(process.env.MODERN_JS_VERSION || '0.1.0');
|
|
21
|
-
const hooksMap = {
|
|
22
|
-
config: createParallelWorkflow(),
|
|
23
|
-
validateSchema: createParallelWorkflow(),
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
25
|
-
prepare: createAsyncWorkflow(),
|
|
26
|
-
commands: createAsyncWorkflow(),
|
|
27
|
-
watchFiles: createParallelWorkflow(),
|
|
28
|
-
fileChange: createAsyncWorkflow(),
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
30
|
-
beforeExit: createAsyncWorkflow()
|
|
31
|
-
};
|
|
32
|
-
export const manager = createAsyncManager(hooksMap);
|
|
33
|
-
export const {
|
|
34
|
-
createPlugin,
|
|
35
|
-
registe: registerHook,
|
|
36
|
-
useRunner: mountHook
|
|
37
|
-
} = manager;
|
|
38
|
-
export const usePlugins = plugins => plugins.forEach(plugin => manager.usePlugin(compatRequire(require.resolve(plugin))));
|
|
39
|
-
export { defineConfig, AppContext, useAppContext, useConfigContext, useResolvedConfigContext };
|
|
40
|
-
|
|
41
|
-
const initAppDir = async () => {
|
|
42
|
-
const pkg = await pkgUp({
|
|
43
|
-
cwd: process.cwd()
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
if (!pkg) {
|
|
47
|
-
throw new Error(`no package.json found in current work dir: ${process.cwd()}`);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return path.dirname(pkg);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const createCli = () => {
|
|
54
|
-
let hooksRunner;
|
|
55
|
-
let isRestart = false;
|
|
56
|
-
|
|
57
|
-
const init = async (argv = []) => {
|
|
58
|
-
enable();
|
|
59
|
-
manager.clear();
|
|
60
|
-
const appDirectory = await initAppDir();
|
|
61
|
-
loadEnv(appDirectory);
|
|
62
|
-
const loaded = await loadUserConfig(appDirectory);
|
|
63
|
-
const plugins = loadPlugins(appDirectory, loaded.config.plugins || []);
|
|
64
|
-
plugins.forEach(plugin => plugin.cli && manager.usePlugin(plugin.cli));
|
|
65
|
-
const appContext = initAppContext(appDirectory, plugins, loaded.filePath);
|
|
66
|
-
manager.run(() => {
|
|
67
|
-
ConfigContext.set(loaded.config);
|
|
68
|
-
AppContext.set(appContext);
|
|
69
|
-
});
|
|
70
|
-
hooksRunner = await manager.init();
|
|
71
|
-
['SIGINT', 'SIGTERM', 'unhandledRejection', 'uncaughtException'].forEach(event => {
|
|
72
|
-
process.on(event, async err => {
|
|
73
|
-
await hooksRunner.beforeExit();
|
|
74
|
-
|
|
75
|
-
if (err instanceof Error) {
|
|
76
|
-
logger.error(err.stack);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
process.nextTick(() => {
|
|
80
|
-
// eslint-disable-next-line no-process-exit
|
|
81
|
-
process.exit(1);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
const extraConfigs = await hooksRunner.config();
|
|
86
|
-
const extraSchemas = await hooksRunner.validateSchema();
|
|
87
|
-
const resolved = await resolveConfig(loaded, extraConfigs, extraSchemas, isRestart, argv); // update context value
|
|
88
|
-
|
|
89
|
-
manager.run(() => {
|
|
90
|
-
ConfigContext.set(loaded.config);
|
|
91
|
-
ResolvedConfigContext.set(resolved);
|
|
92
|
-
AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
|
|
93
|
-
port: resolved.server.port,
|
|
94
|
-
distDirectory: ensureAbsolutePath(appDirectory, resolved.output.path)
|
|
95
|
-
}));
|
|
96
|
-
});
|
|
97
|
-
await hooksRunner.prepare();
|
|
98
|
-
return {
|
|
99
|
-
loadedConfig: loaded,
|
|
100
|
-
appContext,
|
|
101
|
-
resolved
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
async function run(argv) {
|
|
106
|
-
const {
|
|
107
|
-
loadedConfig,
|
|
108
|
-
appContext,
|
|
109
|
-
resolved
|
|
110
|
-
} = await init(argv);
|
|
111
|
-
await hooksRunner.commands({
|
|
112
|
-
program
|
|
113
|
-
});
|
|
114
|
-
initWatcher(loadedConfig, appContext.appDirectory, resolved.source.configDir, hooksRunner, argv);
|
|
115
|
-
manager.run(() => program.parse(process.argv));
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async function restart() {
|
|
119
|
-
isRestart = true;
|
|
120
|
-
logger.info('Restart...\n');
|
|
121
|
-
let hasGetError = false;
|
|
122
|
-
|
|
123
|
-
try {
|
|
124
|
-
await init(process.argv.slice(2));
|
|
125
|
-
} catch (err) {
|
|
126
|
-
console.error(err);
|
|
127
|
-
hasGetError = true;
|
|
128
|
-
} finally {
|
|
129
|
-
if (!hasGetError) {
|
|
130
|
-
manager.run(() => program.parse(process.argv));
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return {
|
|
136
|
-
init,
|
|
137
|
-
run,
|
|
138
|
-
restart
|
|
139
|
-
};
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
export const cli = createCli();
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { isDev, createDebugger } from '@modern-js/utils';
|
|
5
|
-
import chokidar from 'chokidar';
|
|
6
|
-
const debug = createDebugger('watch-files');
|
|
7
|
-
|
|
8
|
-
const md5 = data => crypto.createHash('md5').update(data).digest('hex');
|
|
9
|
-
|
|
10
|
-
const hashMap = new Map();
|
|
11
|
-
export const initWatcher = async (loaded, appDirectory, configDir, hooksRunner, argv) => {
|
|
12
|
-
// only add fs watcher on dev mode.
|
|
13
|
-
if (isDev() && argv[0] === 'dev') {
|
|
14
|
-
const extraFiles = await hooksRunner.watchFiles();
|
|
15
|
-
const configPath = path.join(appDirectory, configDir);
|
|
16
|
-
const watched = [`${configPath}/html`, ...extraFiles, loaded === null || loaded === void 0 ? void 0 : loaded.filePath, ...loaded.dependencies].filter(Boolean);
|
|
17
|
-
debug(`watched: %o`, watched);
|
|
18
|
-
const watcher = chokidar.watch(watched, {
|
|
19
|
-
cwd: appDirectory,
|
|
20
|
-
ignorePermissionErrors: true,
|
|
21
|
-
ignored: [/node_modules/, '**/__test__/**', '**/*.test.(js|jsx|ts|tsx)', '**/*.spec.(js|jsx|ts|tsx)', '**/*.stories.(js|jsx|ts|tsx)']
|
|
22
|
-
});
|
|
23
|
-
watcher.on('change', changed => {
|
|
24
|
-
const lastHash = hashMap.get(changed);
|
|
25
|
-
const currentHash = md5(fs.readFileSync(path.join(appDirectory, changed), 'utf8'));
|
|
26
|
-
|
|
27
|
-
if (currentHash !== lastHash) {
|
|
28
|
-
debug(`file change: %s`, changed);
|
|
29
|
-
hashMap.set(changed, currentHash);
|
|
30
|
-
hooksRunner.fileChange({
|
|
31
|
-
filename: changed
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
watcher.on('unlink', name => {
|
|
36
|
-
debug(`remove file: %s`, name);
|
|
37
|
-
|
|
38
|
-
if (hashMap.has(name)) {
|
|
39
|
-
hashMap.delete(name);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
watcher.on('error', err => {
|
|
43
|
-
throw err;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import dotenv from 'dotenv';
|
|
4
|
-
import dotenvExpand from 'dotenv-expand';
|
|
5
|
-
export const loadEnv = (appDirectory, mode = process.env.NODE_ENV) => {
|
|
6
|
-
[`.env.${mode}`, '.env'].map(name => path.resolve(appDirectory, name)).filter(filePath => fs.existsSync(filePath) && !fs.statSync(filePath).isDirectory()).forEach(filePath => {
|
|
7
|
-
const envConfig = dotenv.config({
|
|
8
|
-
path: filePath
|
|
9
|
-
});
|
|
10
|
-
dotenvExpand(envConfig);
|
|
11
|
-
});
|
|
12
|
-
};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { isDepExists, createDebugger, compatRequire, INTERNAL_PLUGINS } from '@modern-js/utils';
|
|
2
|
-
const debug = createDebugger('load-plugins');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Try to resolve plugin entry file path.
|
|
6
|
-
* @param appDirectory - Application root directory.
|
|
7
|
-
* @param plugin - Plugin name or plugin name with options.
|
|
8
|
-
* @returns Resolved file path.
|
|
9
|
-
*/
|
|
10
|
-
const resolvePlugin = (appDirectory, plugin) => {
|
|
11
|
-
const tryResolve = name => {
|
|
12
|
-
let filePath = '';
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
filePath = require.resolve(name, {
|
|
16
|
-
paths: [appDirectory]
|
|
17
|
-
});
|
|
18
|
-
delete require.cache[filePath];
|
|
19
|
-
} catch (err) {
|
|
20
|
-
if (err.code === 'MODULE_NOT_FOUND') {
|
|
21
|
-
throw new Error(`Can not find plugin ${name}.`);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
throw err;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return filePath;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const resolved = {};
|
|
31
|
-
|
|
32
|
-
if (plugin.cli) {
|
|
33
|
-
resolved.cli = tryResolve(plugin.cli);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (plugin.server) {
|
|
37
|
-
resolved.server = tryResolve(plugin.server);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return resolved;
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Load internal plugins which in @modern-js scope and user's custom plugins.
|
|
44
|
-
* @param appDirectory - Application root directory.
|
|
45
|
-
* @param pluginsConfig - Plugins declared in the user configuration.
|
|
46
|
-
* @returns Plugin Objects has been required.
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
export const loadPlugins = (appDirectory, pluginConfig) => {
|
|
51
|
-
const plugins = [...Object.keys(INTERNAL_PLUGINS).filter(name => isDepExists(appDirectory, name)).map(name => INTERNAL_PLUGINS[name]), ...pluginConfig];
|
|
52
|
-
return plugins.map(plugin => {
|
|
53
|
-
const {
|
|
54
|
-
cli,
|
|
55
|
-
server
|
|
56
|
-
} = resolvePlugin(appDirectory, plugin);
|
|
57
|
-
debug(`resolve plugin %s: %s`, plugin, {
|
|
58
|
-
cli,
|
|
59
|
-
server
|
|
60
|
-
});
|
|
61
|
-
return {
|
|
62
|
-
cli: cli && compatRequire(cli),
|
|
63
|
-
server: server && compatRequire(server)
|
|
64
|
-
};
|
|
65
|
-
});
|
|
66
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { program, Command } from 'commander';
|
|
2
|
-
|
|
3
|
-
if (!program.hasOwnProperty('commandsMap')) {
|
|
4
|
-
Object.defineProperty(program, 'commandsMap', {
|
|
5
|
-
get() {
|
|
6
|
-
const map = new Map();
|
|
7
|
-
|
|
8
|
-
for (const command of program.commands) {
|
|
9
|
-
map.set(command._name, command);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return map;
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
configurable: false
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export { program, Command };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { traverseSchema } from "../config/schema";
|
|
2
|
-
export const deepGet = (obj, key) => {
|
|
3
|
-
for (const p of key.split('.')) {
|
|
4
|
-
// eslint-disable-next-line no-param-reassign
|
|
5
|
-
obj = obj ? obj[p] : undefined;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return obj;
|
|
9
|
-
};
|
|
10
|
-
export const repeatKeyWarning = (schema, jsConfig, pkgConfig) => {
|
|
11
|
-
const keys = traverseSchema(schema);
|
|
12
|
-
|
|
13
|
-
for (const key of keys) {
|
|
14
|
-
if (deepGet(jsConfig, key) !== undefined && deepGet(pkgConfig, key) !== undefined) {
|
|
15
|
-
throw new Error(`The same configuration ${key} exists in modern.config.js and package.json.\n Please remove it from package.json.`);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
};
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.defaults = void 0;
|
|
7
|
-
const sourceDefaults = {
|
|
8
|
-
entries: undefined,
|
|
9
|
-
disableDefaultEntries: false,
|
|
10
|
-
entriesDir: './src',
|
|
11
|
-
configDir: './config',
|
|
12
|
-
apiDir: './api',
|
|
13
|
-
envVars: [],
|
|
14
|
-
globalVars: undefined,
|
|
15
|
-
alias: undefined,
|
|
16
|
-
moduleScopes: undefined,
|
|
17
|
-
include: []
|
|
18
|
-
};
|
|
19
|
-
const outputDefaults = {
|
|
20
|
-
assetPrefix: '/',
|
|
21
|
-
htmlPath: 'html',
|
|
22
|
-
jsPath: 'static/js',
|
|
23
|
-
cssPath: 'static/css',
|
|
24
|
-
mediaPath: 'static/media',
|
|
25
|
-
path: 'dist',
|
|
26
|
-
title: '',
|
|
27
|
-
titleByEntries: undefined,
|
|
28
|
-
meta: {
|
|
29
|
-
charset: {
|
|
30
|
-
charset: 'utf-8'
|
|
31
|
-
},
|
|
32
|
-
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',
|
|
33
|
-
'http-equiv': {
|
|
34
|
-
'http-equiv': 'x-ua-compatible',
|
|
35
|
-
content: 'ie=edge'
|
|
36
|
-
},
|
|
37
|
-
renderer: 'webkit',
|
|
38
|
-
layoutmode: 'standard',
|
|
39
|
-
imagemode: 'force',
|
|
40
|
-
'wap-font-scale': 'no',
|
|
41
|
-
'format-detection': 'telephone=no'
|
|
42
|
-
},
|
|
43
|
-
metaByEntries: undefined,
|
|
44
|
-
inject: 'head',
|
|
45
|
-
injectByEntries: undefined,
|
|
46
|
-
mountId: 'root',
|
|
47
|
-
favicon: '',
|
|
48
|
-
faviconByEntries: undefined,
|
|
49
|
-
copy: undefined,
|
|
50
|
-
scriptExt: undefined,
|
|
51
|
-
disableHtmlFolder: false,
|
|
52
|
-
disableCssModuleExtension: false,
|
|
53
|
-
disableCssExtract: false,
|
|
54
|
-
enableCssModuleTSDeclaration: false,
|
|
55
|
-
disableMinimize: false,
|
|
56
|
-
enableInlineStyles: false,
|
|
57
|
-
enableInlineScripts: false,
|
|
58
|
-
disableSourceMap: false,
|
|
59
|
-
disableInlineRuntimeChunk: false,
|
|
60
|
-
disableAssetsCache: false,
|
|
61
|
-
enableLatestDecorators: false,
|
|
62
|
-
polyfill: 'entry',
|
|
63
|
-
dataUriLimit: 10000,
|
|
64
|
-
templateParameters: {},
|
|
65
|
-
templateParametersByEntries: undefined,
|
|
66
|
-
cssModuleLocalIdentName: '[name]__[local]--[hash:base64:5]',
|
|
67
|
-
enableModernMode: false,
|
|
68
|
-
federation: undefined,
|
|
69
|
-
disableNodePolyfill: false,
|
|
70
|
-
enableTsLoader: false
|
|
71
|
-
};
|
|
72
|
-
const serverDefaults = {
|
|
73
|
-
routes: undefined,
|
|
74
|
-
publicRoutes: undefined,
|
|
75
|
-
ssr: undefined,
|
|
76
|
-
ssrByEntries: undefined,
|
|
77
|
-
baseUrl: '/',
|
|
78
|
-
port: 8080
|
|
79
|
-
};
|
|
80
|
-
const devDefaults = {
|
|
81
|
-
assetPrefix: false,
|
|
82
|
-
https: false
|
|
83
|
-
};
|
|
84
|
-
const deployDefaults = {
|
|
85
|
-
domain: '',
|
|
86
|
-
domainByEntries: undefined
|
|
87
|
-
};
|
|
88
|
-
const toolsDefaults = {
|
|
89
|
-
webpack: undefined,
|
|
90
|
-
babel: undefined,
|
|
91
|
-
postcss: undefined,
|
|
92
|
-
autoprefixer: undefined,
|
|
93
|
-
lodash: undefined,
|
|
94
|
-
devServer: undefined,
|
|
95
|
-
tsLoader: undefined,
|
|
96
|
-
terser: undefined,
|
|
97
|
-
minifyCss: undefined
|
|
98
|
-
};
|
|
99
|
-
const defaults = {
|
|
100
|
-
source: sourceDefaults,
|
|
101
|
-
output: outputDefaults,
|
|
102
|
-
server: serverDefaults,
|
|
103
|
-
dev: devDefaults,
|
|
104
|
-
deploy: deployDefaults,
|
|
105
|
-
tools: toolsDefaults
|
|
106
|
-
};
|
|
107
|
-
exports.defaults = defaults;
|