@modern-js/core 1.9.2 → 1.10.0
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 +15 -0
- package/compiled/ajv-keywords/index.d.ts +1 -0
- package/compiled/ajv-keywords/package.json +1 -1
- package/compiled/better-ajv-errors/index.d.ts +1 -0
- package/compiled/better-ajv-errors/package.json +1 -1
- package/compiled/v8-compile-cache/index.d.ts +1 -0
- package/compiled/v8-compile-cache/package.json +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +19 -28
- package/dist/config/types/index.d.ts +36 -36
- package/dist/index.js +55 -60
- package/dist/initWatcher.js +3 -12
- package/package.json +7 -8
- package/tsconfig.json +1 -0
- package/compiled/ajv-keywords/ajv/dist/ajv.d.ts +0 -16
- package/compiled/ajv-keywords/ajv/dist/compile/codegen/code.d.ts +0 -40
- package/compiled/ajv-keywords/ajv/dist/compile/codegen/index.d.ts +0 -79
- package/compiled/ajv-keywords/ajv/dist/compile/codegen/scope.d.ts +0 -79
- package/compiled/ajv-keywords/ajv/dist/compile/errors.d.ts +0 -13
- package/compiled/ajv-keywords/ajv/dist/compile/index.d.ts +0 -80
- package/compiled/ajv-keywords/ajv/dist/compile/ref_error.d.ts +0 -6
- package/compiled/ajv-keywords/ajv/dist/compile/resolve.d.ts +0 -12
- package/compiled/ajv-keywords/ajv/dist/compile/rules.d.ts +0 -28
- package/compiled/ajv-keywords/ajv/dist/compile/util.d.ts +0 -40
- package/compiled/ajv-keywords/ajv/dist/compile/validate/index.d.ts +0 -42
- package/compiled/ajv-keywords/ajv/dist/compile/validate/subschema.d.ts +0 -47
- package/compiled/ajv-keywords/ajv/dist/core.d.ts +0 -173
- package/compiled/ajv-keywords/ajv/dist/runtime/validation_error.d.ts +0 -7
- package/compiled/ajv-keywords/ajv/dist/types/index.d.ts +0 -183
- package/compiled/ajv-keywords/ajv/dist/types/json-schema.d.ts +0 -124
- package/compiled/ajv-keywords/ajv/dist/types/jtd-schema.d.ts +0 -169
- package/compiled/ajv-keywords/dist/index.d.ts +0 -4
- package/compiled/ajv-keywords/uri-js/dist/es5/uri.all.d.ts +0 -59
- package/compiled/better-ajv-errors/ajv/dist/ajv.d.ts +0 -16
- package/compiled/better-ajv-errors/ajv/dist/compile/codegen/code.d.ts +0 -40
- package/compiled/better-ajv-errors/ajv/dist/compile/codegen/index.d.ts +0 -79
- package/compiled/better-ajv-errors/ajv/dist/compile/codegen/scope.d.ts +0 -79
- package/compiled/better-ajv-errors/ajv/dist/compile/errors.d.ts +0 -13
- package/compiled/better-ajv-errors/ajv/dist/compile/index.d.ts +0 -80
- package/compiled/better-ajv-errors/ajv/dist/compile/ref_error.d.ts +0 -6
- package/compiled/better-ajv-errors/ajv/dist/compile/resolve.d.ts +0 -12
- package/compiled/better-ajv-errors/ajv/dist/compile/rules.d.ts +0 -28
- package/compiled/better-ajv-errors/ajv/dist/compile/util.d.ts +0 -40
- package/compiled/better-ajv-errors/ajv/dist/compile/validate/index.d.ts +0 -42
- package/compiled/better-ajv-errors/ajv/dist/compile/validate/subschema.d.ts +0 -47
- package/compiled/better-ajv-errors/ajv/dist/core.d.ts +0 -173
- package/compiled/better-ajv-errors/ajv/dist/runtime/validation_error.d.ts +0 -7
- package/compiled/better-ajv-errors/ajv/dist/types/index.d.ts +0 -183
- package/compiled/better-ajv-errors/ajv/dist/types/json-schema.d.ts +0 -124
- package/compiled/better-ajv-errors/ajv/dist/types/jtd-schema.d.ts +0 -169
- package/compiled/better-ajv-errors/typings.d.ts +0 -24
- package/compiled/better-ajv-errors/uri-js/dist/es5/uri.all.d.ts +0 -59
- package/dist/js/modern/cli.js +0 -29
- package/dist/js/modern/config/defaults.js +0 -103
- package/dist/js/modern/config/index.js +0 -115
- package/dist/js/modern/config/mergeConfig.js +0 -22
- package/dist/js/modern/config/schema/deploy.js +0 -17
- 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 -36
- package/dist/js/modern/config/types/electron.js +0 -1
- package/dist/js/modern/config/types/index.js +0 -1
- package/dist/js/modern/config/types/less.js +0 -0
- package/dist/js/modern/config/types/sass.js +0 -0
- package/dist/js/modern/config/types/ssg.js +0 -0
- package/dist/js/modern/config/types/test.js +0 -0
- package/dist/js/modern/config/types/unbundle.js +0 -0
- package/dist/js/modern/context.js +0 -63
- package/dist/js/modern/index.js +0 -169
- package/dist/js/modern/initWatcher.js +0 -62
- package/dist/js/modern/loadEnv.js +0 -14
- package/dist/js/modern/loadPlugins.js +0 -122
- package/dist/js/modern/manager.js +0 -28
- package/dist/js/modern/pluginAPI.js +0 -11
- package/dist/js/modern/utils/commander.js +0 -19
- package/dist/js/modern/utils/repeatKeyWarning.js +0 -18
- package/dist/js/node/cli.js +0 -35
- package/dist/js/node/config/defaults.js +0 -110
- package/dist/js/node/config/index.js +0 -182
- package/dist/js/node/config/mergeConfig.js +0 -32
- package/dist/js/node/config/schema/deploy.js +0 -26
- package/dist/js/node/config/schema/index.js +0 -127
- 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 -43
- package/dist/js/node/config/types/electron.js +0 -5
- package/dist/js/node/config/types/index.js +0 -5
- package/dist/js/node/config/types/less.js +0 -0
- package/dist/js/node/config/types/sass.js +0 -0
- package/dist/js/node/config/types/ssg.js +0 -0
- package/dist/js/node/config/types/test.js +0 -0
- package/dist/js/node/config/types/unbundle.js +0 -0
- package/dist/js/node/context.js +0 -93
- package/dist/js/node/index.js +0 -329
- package/dist/js/node/initWatcher.js +0 -82
- package/dist/js/node/loadEnv.js +0 -30
- package/dist/js/node/loadPlugins.js +0 -134
- package/dist/js/node/manager.js +0 -45
- package/dist/js/node/pluginAPI.js +0 -54
- package/dist/js/node/utils/commander.js +0 -32
- package/dist/js/node/utils/repeatKeyWarning.js +0 -31
- package/dist/types/cli.d.ts +0 -1
- package/dist/types/config/defaults.d.ts +0 -28
- package/dist/types/config/index.d.ts +0 -12
- package/dist/types/config/mergeConfig.d.ts +0 -31
- package/dist/types/config/schema/deploy.d.ts +0 -16
- 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 -36
- package/dist/types/config/types/electron.d.ts +0 -13
- package/dist/types/config/types/index.d.ts +0 -252
- package/dist/types/config/types/less.d.ts +0 -10
- package/dist/types/config/types/sass.d.ts +0 -8
- package/dist/types/config/types/ssg.d.ts +0 -13
- package/dist/types/config/types/test.d.ts +0 -15
- package/dist/types/config/types/unbundle.d.ts +0 -28
- package/dist/types/context.d.ts +0 -47
- package/dist/types/index.d.ts +0 -64
- package/dist/types/initWatcher.d.ts +0 -3
- package/dist/types/loadEnv.d.ts +0 -1
- package/dist/types/loadPlugins.d.ts +0 -44
- package/dist/types/manager.d.ts +0 -75
- package/dist/types/pluginAPI.d.ts +0 -13
- package/dist/types/utils/commander.d.ts +0 -4
- package/dist/types/utils/repeatKeyWarning.d.ts +0 -3
|
@@ -1,63 +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
|
-
/**
|
|
8
|
-
* Set app context.
|
|
9
|
-
* @param value new app context. It will override previous app context.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
export const setAppContext = value => AppContext.set(value);
|
|
13
|
-
/**
|
|
14
|
-
* Get app context, including directories, plugins and some static infos.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
export const useAppContext = () => AppContext.use().value;
|
|
18
|
-
/**
|
|
19
|
-
* Get original content of user config.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
export const useConfigContext = () => ConfigContext.use().value;
|
|
23
|
-
/**
|
|
24
|
-
* Get normalized content of user config.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
export const useResolvedConfigContext = () => ResolvedConfigContext.use().value;
|
|
28
|
-
export const initAppContext = ({
|
|
29
|
-
appDirectory,
|
|
30
|
-
plugins,
|
|
31
|
-
configFile,
|
|
32
|
-
options,
|
|
33
|
-
serverConfigFile
|
|
34
|
-
}) => {
|
|
35
|
-
const {
|
|
36
|
-
metaName = 'modern-js',
|
|
37
|
-
srcDir = 'src',
|
|
38
|
-
distDir = '',
|
|
39
|
-
sharedDir = 'shared'
|
|
40
|
-
} = options || {};
|
|
41
|
-
return {
|
|
42
|
-
metaName,
|
|
43
|
-
appDirectory,
|
|
44
|
-
configFile,
|
|
45
|
-
serverConfigFile,
|
|
46
|
-
ip: address.ip(),
|
|
47
|
-
port: 0,
|
|
48
|
-
packageName: require(path.resolve(appDirectory, './package.json')).name,
|
|
49
|
-
srcDirectory: path.resolve(appDirectory, srcDir),
|
|
50
|
-
distDirectory: distDir,
|
|
51
|
-
sharedDirectory: path.resolve(appDirectory, sharedDir),
|
|
52
|
-
nodeModulesDirectory: path.resolve(appDirectory, './node_modules'),
|
|
53
|
-
internalDirectory: path.resolve(appDirectory, `./node_modules/.${metaName}`),
|
|
54
|
-
plugins,
|
|
55
|
-
htmlTemplates: {},
|
|
56
|
-
serverRoutes: [],
|
|
57
|
-
entrypoints: [],
|
|
58
|
-
checkedEntries: [],
|
|
59
|
-
apiOnly: false,
|
|
60
|
-
internalDirAlias: `@_${metaName.replace(/-/g, '_')}_internal`,
|
|
61
|
-
internalSrcAlias: `@_${metaName.replace(/-/g, '_')}_src`
|
|
62
|
-
};
|
|
63
|
-
};
|
package/dist/js/modern/index.js
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : 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 { pkgUp, program, ensureAbsolutePath, logger, DEFAULT_SERVER_CONFIG } from '@modern-js/utils';
|
|
9
|
-
import { enable } from '@modern-js/plugin/node';
|
|
10
|
-
import { initCommandsMap } from "./utils/commander";
|
|
11
|
-
import { resolveConfig, loadUserConfig, addServerConfigToDeps } from "./config";
|
|
12
|
-
import { loadPlugins } from "./loadPlugins";
|
|
13
|
-
import { AppContext, ConfigContext, initAppContext, ResolvedConfigContext } from "./context";
|
|
14
|
-
import { initWatcher } from "./initWatcher";
|
|
15
|
-
import { loadEnv } from "./loadEnv";
|
|
16
|
-
import { manager } from "./manager";
|
|
17
|
-
export * from "./config";
|
|
18
|
-
export * from '@modern-js/plugin';
|
|
19
|
-
export * from '@modern-js/plugin/node'; // TODO: remove export after refactor all plugins
|
|
20
|
-
|
|
21
|
-
export { manager, mountHook, usePlugins, createPlugin, registerHook } from "./manager";
|
|
22
|
-
// TODO: remove export after refactor all plugins
|
|
23
|
-
export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext } from "./pluginAPI";
|
|
24
|
-
program.name('modern').usage('<command> [options]').version(process.env.MODERN_JS_VERSION || '0.1.0');
|
|
25
|
-
|
|
26
|
-
const initAppDir = async cwd => {
|
|
27
|
-
if (!cwd) {
|
|
28
|
-
// eslint-disable-next-line no-param-reassign
|
|
29
|
-
cwd = process.cwd();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const pkg = await pkgUp({
|
|
33
|
-
cwd
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
if (!pkg) {
|
|
37
|
-
throw new Error(`no package.json found in current work dir: ${cwd}`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return path.dirname(pkg);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export const mergeOptions = options => {
|
|
44
|
-
const defaultOptions = {
|
|
45
|
-
serverConfigFile: DEFAULT_SERVER_CONFIG
|
|
46
|
-
};
|
|
47
|
-
return _objectSpread(_objectSpread({}, defaultOptions), options);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const createCli = () => {
|
|
51
|
-
let hooksRunner;
|
|
52
|
-
let isRestart = false;
|
|
53
|
-
let restartWithExistingPort = 0;
|
|
54
|
-
let restartOptions;
|
|
55
|
-
|
|
56
|
-
const init = async (argv = [], options) => {
|
|
57
|
-
var _mergedOptions$option, _mergedOptions$option2;
|
|
58
|
-
|
|
59
|
-
enable();
|
|
60
|
-
manager.clear();
|
|
61
|
-
const mergedOptions = mergeOptions(options);
|
|
62
|
-
restartOptions = mergedOptions;
|
|
63
|
-
const appDirectory = await initAppDir();
|
|
64
|
-
initCommandsMap();
|
|
65
|
-
const metaName = (_mergedOptions$option = mergedOptions === null || mergedOptions === void 0 ? void 0 : (_mergedOptions$option2 = mergedOptions.options) === null || _mergedOptions$option2 === void 0 ? void 0 : _mergedOptions$option2.metaName) !== null && _mergedOptions$option !== void 0 ? _mergedOptions$option : 'MODERN';
|
|
66
|
-
loadEnv(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
|
|
67
|
-
const loaded = await loadUserConfig(appDirectory, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.configFile, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.packageJsonConfig);
|
|
68
|
-
const plugins = loadPlugins(appDirectory, loaded.config, {
|
|
69
|
-
internalPlugins: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.plugins,
|
|
70
|
-
transformPlugin: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.transformPlugin
|
|
71
|
-
});
|
|
72
|
-
plugins.forEach(plugin => plugin.cli && manager.usePlugin(plugin.cli));
|
|
73
|
-
const appContext = initAppContext({
|
|
74
|
-
appDirectory,
|
|
75
|
-
plugins,
|
|
76
|
-
configFile: loaded.filePath,
|
|
77
|
-
options: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.options,
|
|
78
|
-
serverConfigFile: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.serverConfigFile
|
|
79
|
-
}); // 将 server.config 加入到 loaded.dependencies,以便对文件监听做热更新
|
|
80
|
-
|
|
81
|
-
addServerConfigToDeps(loaded.dependencies, appDirectory, mergedOptions.serverConfigFile);
|
|
82
|
-
manager.run(() => {
|
|
83
|
-
ConfigContext.set(loaded.config);
|
|
84
|
-
AppContext.set(appContext);
|
|
85
|
-
});
|
|
86
|
-
hooksRunner = await manager.init();
|
|
87
|
-
['SIGINT', 'SIGTERM', 'unhandledRejection', 'uncaughtException'].forEach(event => {
|
|
88
|
-
process.on(event, async err => {
|
|
89
|
-
await hooksRunner.beforeExit();
|
|
90
|
-
|
|
91
|
-
if (err instanceof Error) {
|
|
92
|
-
logger.error(err.stack);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
process.nextTick(() => {
|
|
96
|
-
// eslint-disable-next-line no-process-exit
|
|
97
|
-
process.exit(1);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
const extraConfigs = await hooksRunner.config();
|
|
102
|
-
const extraSchemas = await hooksRunner.validateSchema();
|
|
103
|
-
const config = await resolveConfig(loaded, extraConfigs, extraSchemas, restartWithExistingPort, argv, options === null || options === void 0 ? void 0 : options.onSchemaError);
|
|
104
|
-
const {
|
|
105
|
-
resolved
|
|
106
|
-
} = await hooksRunner.resolvedConfig({
|
|
107
|
-
resolved: config
|
|
108
|
-
}); // update context value
|
|
109
|
-
|
|
110
|
-
manager.run(() => {
|
|
111
|
-
ConfigContext.set(loaded.config);
|
|
112
|
-
ResolvedConfigContext.set(resolved);
|
|
113
|
-
AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
|
|
114
|
-
port: resolved.server.port,
|
|
115
|
-
distDirectory: ensureAbsolutePath(appDirectory, resolved.output.path)
|
|
116
|
-
}));
|
|
117
|
-
});
|
|
118
|
-
await hooksRunner.prepare();
|
|
119
|
-
return {
|
|
120
|
-
loadedConfig: loaded,
|
|
121
|
-
appContext,
|
|
122
|
-
resolved
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
async function run(argv, options) {
|
|
127
|
-
const {
|
|
128
|
-
loadedConfig,
|
|
129
|
-
appContext,
|
|
130
|
-
resolved
|
|
131
|
-
} = await init(argv, options);
|
|
132
|
-
await hooksRunner.commands({
|
|
133
|
-
program
|
|
134
|
-
});
|
|
135
|
-
initWatcher(loadedConfig, appContext.appDirectory, resolved.source.configDir, hooksRunner, argv);
|
|
136
|
-
manager.run(() => program.parse(process.argv));
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
async function restart() {
|
|
140
|
-
var _AppContext$use$value, _AppContext$use$value2;
|
|
141
|
-
|
|
142
|
-
isRestart = true;
|
|
143
|
-
restartWithExistingPort = isRestart ? (_AppContext$use$value = (_AppContext$use$value2 = AppContext.use().value) === null || _AppContext$use$value2 === void 0 ? void 0 : _AppContext$use$value2.port) !== null && _AppContext$use$value !== void 0 ? _AppContext$use$value : 0 : 0;
|
|
144
|
-
logger.info('Restart...\n');
|
|
145
|
-
let hasGetError = false;
|
|
146
|
-
const runner = manager.useRunner();
|
|
147
|
-
await runner.beforeRestart();
|
|
148
|
-
|
|
149
|
-
try {
|
|
150
|
-
await init(process.argv.slice(2), restartOptions);
|
|
151
|
-
} catch (err) {
|
|
152
|
-
console.error(err);
|
|
153
|
-
hasGetError = true;
|
|
154
|
-
} finally {
|
|
155
|
-
if (!hasGetError) {
|
|
156
|
-
manager.run(() => program.parse(process.argv));
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return {
|
|
162
|
-
init,
|
|
163
|
-
run,
|
|
164
|
-
restart
|
|
165
|
-
};
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
export const cli = createCli();
|
|
169
|
-
export { initAppDir, initAppContext };
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { isDev, chokidar, createDebugger, isTest } from '@modern-js/utils';
|
|
5
|
-
const debug = createDebugger('watch-files');
|
|
6
|
-
|
|
7
|
-
const md5 = data => crypto.createHash('md5').update(data).digest('hex');
|
|
8
|
-
|
|
9
|
-
const hashMap = new Map();
|
|
10
|
-
export const initWatcher = async (loaded, appDirectory, configDir, hooksRunner, argv) => {
|
|
11
|
-
// only add fs watcher on dev mode.
|
|
12
|
-
if ((isDev() || isTest()) && argv[0] === 'dev') {
|
|
13
|
-
const extraFiles = await hooksRunner.watchFiles();
|
|
14
|
-
const configPath = path.join(appDirectory, configDir);
|
|
15
|
-
const watched = [`${configPath}/html`, ...extraFiles, loaded === null || loaded === void 0 ? void 0 : loaded.filePath, ...loaded.dependencies].filter(Boolean);
|
|
16
|
-
debug(`watched: %o`, watched);
|
|
17
|
-
const watcher = chokidar.watch(watched, {
|
|
18
|
-
cwd: appDirectory,
|
|
19
|
-
ignoreInitial: true,
|
|
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
|
-
eventType: 'change'
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
watcher.on('add', name => {
|
|
37
|
-
debug(`add file: %s`, name);
|
|
38
|
-
const currentHash = md5(fs.readFileSync(path.join(appDirectory, name), 'utf8'));
|
|
39
|
-
hashMap.set(name, currentHash);
|
|
40
|
-
hooksRunner.fileChange({
|
|
41
|
-
filename: name,
|
|
42
|
-
eventType: 'add'
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
watcher.on('unlink', name => {
|
|
46
|
-
debug(`remove file: %s`, name);
|
|
47
|
-
|
|
48
|
-
if (hashMap.has(name)) {
|
|
49
|
-
hashMap.delete(name);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
hooksRunner.fileChange({
|
|
53
|
-
filename: name,
|
|
54
|
-
eventType: 'unlink'
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
watcher.on('error', err => {
|
|
58
|
-
throw err;
|
|
59
|
-
});
|
|
60
|
-
return watcher;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
@@ -1,14 +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
|
-
// Don't change the order of the filenames, since they are ordered by the priority.
|
|
7
|
-
// Files on the left have more priority than files on the right.
|
|
8
|
-
[`.env.${mode}.local`, '.env.local', `.env.${mode}`, '.env'].map(name => path.resolve(appDirectory, name)).filter(filePath => fs.existsSync(filePath) && !fs.statSync(filePath).isDirectory()).forEach(filePath => {
|
|
9
|
-
const envConfig = dotenv.config({
|
|
10
|
-
path: filePath
|
|
11
|
-
});
|
|
12
|
-
dotenvExpand(envConfig);
|
|
13
|
-
});
|
|
14
|
-
};
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { isDepExists, createDebugger, compatRequire, INTERNAL_PLUGINS } from '@modern-js/utils';
|
|
2
|
-
import { createPlugin } from "./manager";
|
|
3
|
-
const debug = createDebugger('load-plugins');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Try to resolve plugin entry file path.
|
|
7
|
-
* @param name - Plugin name.
|
|
8
|
-
* @param appDirectory - Application root directory.
|
|
9
|
-
* @returns Resolved file path.
|
|
10
|
-
*/
|
|
11
|
-
const tryResolve = (name, appDirectory) => {
|
|
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
|
-
export function getAppPlugins(appDirectory, oldPluginConfig, internalPlugins) {
|
|
31
|
-
const allPlugins = internalPlugins || INTERNAL_PLUGINS;
|
|
32
|
-
const appPlugins = [...Object.keys(allPlugins).filter(name => {
|
|
33
|
-
const config = allPlugins[name];
|
|
34
|
-
|
|
35
|
-
if (config.forced === true) {
|
|
36
|
-
// 参考 packages/cli/core/src/cli.ts 文件
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return isDepExists(appDirectory, name);
|
|
41
|
-
}).map(name => allPlugins[name]), ...oldPluginConfig];
|
|
42
|
-
return appPlugins;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const resolveCliPlugin = (p, userConfig, appDirectory, transformPlugin) => {
|
|
46
|
-
const pkg = typeof p === 'string' ? p : p[0];
|
|
47
|
-
const pluginOptions = typeof p === 'string' ? undefined : p[1];
|
|
48
|
-
const path = tryResolve(pkg, appDirectory);
|
|
49
|
-
let module = compatRequire(path);
|
|
50
|
-
|
|
51
|
-
if (transformPlugin) {
|
|
52
|
-
module = transformPlugin(module, userConfig, pluginOptions);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (typeof module === 'function') {
|
|
56
|
-
const result = module(pluginOptions);
|
|
57
|
-
return createPlugin(result.setup, result);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return module;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const isOldPluginConfig = config => Array.isArray(config) && config.some(item => {
|
|
64
|
-
if (typeof item === 'string' || Array.isArray(item)) {
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return 'cli' in item || 'server' in item;
|
|
69
|
-
});
|
|
70
|
-
/**
|
|
71
|
-
* Load internal plugins which in @modern-js scope and user's custom plugins.
|
|
72
|
-
* @param appDirectory - Application root directory.
|
|
73
|
-
* @param userConfig - Resolved user config.
|
|
74
|
-
* @param options.internalPlugins - Internal plugins.
|
|
75
|
-
* @param options.transformPlugin - transform plugin before using it. Used for compatible with legacy jupiter plugins.
|
|
76
|
-
* @returns Plugin Objects has been required.
|
|
77
|
-
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
export const loadPlugins = (appDirectory, userConfig, options = {}) => {
|
|
81
|
-
const pluginConfig = userConfig.plugins;
|
|
82
|
-
const plugins = getAppPlugins(appDirectory, isOldPluginConfig(pluginConfig) ? pluginConfig : [], options.internalPlugins);
|
|
83
|
-
const loadedPlugins = plugins.map(plugin => {
|
|
84
|
-
const _plugin = typeof plugin === 'string' || Array.isArray(plugin) ? {
|
|
85
|
-
cli: plugin
|
|
86
|
-
} : plugin;
|
|
87
|
-
|
|
88
|
-
const {
|
|
89
|
-
cli,
|
|
90
|
-
server
|
|
91
|
-
} = _plugin;
|
|
92
|
-
const loadedPlugin = {};
|
|
93
|
-
|
|
94
|
-
if (cli) {
|
|
95
|
-
loadedPlugin.cli = resolveCliPlugin(cli, userConfig, appDirectory, options.transformPlugin);
|
|
96
|
-
} // server plugins don't support to accept params
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (server && typeof server === 'string') {
|
|
100
|
-
loadedPlugin.server = server;
|
|
101
|
-
loadedPlugin.serverPkg = server;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
debug(`resolve plugin %s: %s`, plugin, {
|
|
105
|
-
cli: loadedPlugin.cli,
|
|
106
|
-
server: loadedPlugin.server
|
|
107
|
-
});
|
|
108
|
-
return loadedPlugin;
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
if (!isOldPluginConfig(pluginConfig)) {
|
|
112
|
-
const cliPlugins = Array.isArray(pluginConfig) ? pluginConfig : pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.cli;
|
|
113
|
-
|
|
114
|
-
if (cliPlugins !== null && cliPlugins !== void 0 && cliPlugins.length) {
|
|
115
|
-
loadedPlugins.push(...cliPlugins.map(item => ({
|
|
116
|
-
cli: createPlugin(item.setup, item)
|
|
117
|
-
})));
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return loadedPlugins;
|
|
122
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { createAsyncManager, createAsyncWorkflow, createAsyncWaterfall, createParallelWorkflow } from '@modern-js/plugin';
|
|
2
|
-
import { compatRequire } from '@modern-js/utils';
|
|
3
|
-
import { pluginAPI } from "./pluginAPI";
|
|
4
|
-
const baseHooks = {
|
|
5
|
-
config: createParallelWorkflow(),
|
|
6
|
-
resolvedConfig: createAsyncWaterfall(),
|
|
7
|
-
validateSchema: createParallelWorkflow(),
|
|
8
|
-
prepare: createAsyncWorkflow(),
|
|
9
|
-
commands: createAsyncWorkflow(),
|
|
10
|
-
watchFiles: createParallelWorkflow(),
|
|
11
|
-
fileChange: createAsyncWorkflow(),
|
|
12
|
-
beforeExit: createAsyncWorkflow(),
|
|
13
|
-
beforeRestart: createAsyncWorkflow()
|
|
14
|
-
};
|
|
15
|
-
/** All hooks of cli plugin. */
|
|
16
|
-
|
|
17
|
-
export const manager = createAsyncManager(baseHooks, pluginAPI);
|
|
18
|
-
/** Plugin options of a cli plugin. */
|
|
19
|
-
|
|
20
|
-
export const {
|
|
21
|
-
createPlugin,
|
|
22
|
-
registerHook,
|
|
23
|
-
useRunner: mountHook
|
|
24
|
-
} = manager;
|
|
25
|
-
export const usePlugins = plugins => plugins.forEach(pluginPath => {
|
|
26
|
-
const module = compatRequire(require.resolve(pluginPath));
|
|
27
|
-
manager.usePlugin(module);
|
|
28
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AppContext, ConfigContext, setAppContext, useAppContext, useConfigContext, ResolvedConfigContext, useResolvedConfigContext } from "./context";
|
|
2
|
-
export const pluginAPI = {
|
|
3
|
-
setAppContext,
|
|
4
|
-
useAppContext,
|
|
5
|
-
useConfigContext,
|
|
6
|
-
useResolvedConfigContext
|
|
7
|
-
};
|
|
8
|
-
/** all apis for cli plugin */
|
|
9
|
-
|
|
10
|
-
// TODO: only export types after refactor all plugins
|
|
11
|
-
export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { program } from '@modern-js/utils';
|
|
2
|
-
export function initCommandsMap() {
|
|
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 };
|
|
@@ -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
|
-
};
|
package/dist/js/node/cli.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _path = _interopRequireDefault(require("path"));
|
|
4
|
-
|
|
5
|
-
var _ = require(".");
|
|
6
|
-
|
|
7
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
-
|
|
9
|
-
// 这个文件跟 bin/modern-js.js 基本一样
|
|
10
|
-
// 在开发阶段,因为 package.json 的 exports['./bin']['jsnext:source'] 配置
|
|
11
|
-
// 了这个文件,所以需要保留, 后续如果找到更好的方式之后会移除这个文件
|
|
12
|
-
const {
|
|
13
|
-
version
|
|
14
|
-
} = require("../../package.json"); // XXX: 通过这个方式去掉了 package.json 里面对于 @modern-js/module-tools 的 devDependencies 依赖
|
|
15
|
-
// 然后可以正常的执行 modern build
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const kModuleToolsCliPath = _path.default.resolve(__dirname, '../../../solutions/module-tools/src/index.ts');
|
|
19
|
-
|
|
20
|
-
process.env.MODERN_JS_VERSION = version;
|
|
21
|
-
|
|
22
|
-
if (!process.env.NODE_ENV) {
|
|
23
|
-
process.env.NODE_ENV = // eslint-disable-next-line no-nested-ternary
|
|
24
|
-
['build', 'start', 'deploy'].includes(process.argv[2]) ? 'production' : process.argv[2] === 'test' ? 'test' : 'development';
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
_.cli.run(process.argv.slice(2), {
|
|
28
|
-
plugins: {
|
|
29
|
-
'@modern-js/module-tools': {
|
|
30
|
-
cli: kModuleToolsCliPath,
|
|
31
|
-
// 是否需要强制加载这个组件,跳过 loadPlugins 里面 filter 的检测逻辑
|
|
32
|
-
forced: true
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
@@ -1,110 +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
|
-
plugins: [],
|
|
107
|
-
runtime: {},
|
|
108
|
-
runtimeByEntries: {}
|
|
109
|
-
};
|
|
110
|
-
exports.defaults = defaults;
|