@modern-js/app-tools 1.4.2 → 1.4.5
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/.eslintrc.js +8 -0
- package/CHANGELOG.md +84 -0
- package/dist/js/modern/commands/build.js +24 -19
- package/dist/js/modern/commands/deploy.js +4 -4
- package/dist/js/modern/commands/dev.js +12 -11
- package/dist/js/modern/commands/start.js +5 -9
- package/dist/js/modern/{lifecycle.js → hooks.js} +10 -13
- package/dist/js/modern/index.js +74 -73
- package/dist/js/modern/locale/zh.js +1 -1
- package/dist/js/modern/utils/createCompiler.js +6 -5
- package/dist/js/modern/utils/printInstructions.js +3 -3
- package/dist/js/node/commands/build.js +19 -17
- package/dist/js/node/commands/deploy.js +4 -5
- package/dist/js/node/commands/dev.js +17 -16
- package/dist/js/node/commands/start.js +6 -11
- package/dist/js/node/{lifecycle.js → hooks.js} +12 -18
- package/dist/js/node/index.js +81 -77
- package/dist/js/node/locale/zh.js +1 -1
- package/dist/js/node/utils/createCompiler.js +6 -6
- package/dist/js/node/utils/printInstructions.js +3 -4
- package/dist/types/commands/build.d.ts +3 -5
- package/dist/types/commands/deploy.d.ts +2 -1
- package/dist/types/commands/dev.d.ts +2 -1
- package/dist/types/commands/start.d.ts +2 -1
- package/dist/types/{lifecycle.d.ts → hooks.d.ts} +19 -1
- package/dist/types/index.d.ts +2 -19
- package/dist/types/utils/createCompiler.d.ts +3 -1
- package/dist/types/utils/createServer.d.ts +2 -2
- package/dist/types/utils/printInstructions.d.ts +2 -2
- package/dist/types/utils/routes.d.ts +1 -1
- package/dist/types/utils/types.d.ts +4 -1
- package/lib/types.d.ts +92 -0
- package/modern.config.js +1 -0
- package/package.json +12 -18
- package/tests/.eslintrc.js +8 -0
- package/tests/commands/build.test.ts +25 -20
|
@@ -5,12 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.dev = void 0;
|
|
7
7
|
|
|
8
|
-
var _webpack = require("@modern-js/webpack");
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
9
|
|
|
12
|
-
var _core = require("@modern-js/core");
|
|
13
|
-
|
|
14
10
|
var _createCompiler = require("../utils/createCompiler");
|
|
15
11
|
|
|
16
12
|
var _createServer = require("../utils/createServer");
|
|
@@ -21,18 +17,20 @@ var _printInstructions = require("../utils/printInstructions");
|
|
|
21
17
|
|
|
22
18
|
var _getSpecifiedEntries = require("../utils/getSpecifiedEntries");
|
|
23
19
|
|
|
20
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
|
+
|
|
22
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
|
+
|
|
24
24
|
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; }
|
|
25
25
|
|
|
26
26
|
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; }
|
|
27
27
|
|
|
28
28
|
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; }
|
|
29
29
|
|
|
30
|
-
const dev = async options => {
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
/* eslint-enable react-hooks/rules-of-hooks */
|
|
35
|
-
|
|
30
|
+
const dev = async (api, options) => {
|
|
31
|
+
const appContext = api.useAppContext();
|
|
32
|
+
const userConfig = api.useResolvedConfigContext();
|
|
33
|
+
const hookRunners = api.useHookRunners();
|
|
36
34
|
const {
|
|
37
35
|
appDirectory,
|
|
38
36
|
distDirectory,
|
|
@@ -41,21 +39,24 @@ const dev = async options => {
|
|
|
41
39
|
entrypoints
|
|
42
40
|
} = appContext;
|
|
43
41
|
const checkedEntries = await (0, _getSpecifiedEntries.getSpecifiedEntries)(options.entry || false, entrypoints);
|
|
44
|
-
|
|
45
|
-
_core.AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
|
|
42
|
+
api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
|
|
46
43
|
checkedEntries
|
|
47
44
|
}));
|
|
48
|
-
|
|
49
45
|
appContext.checkedEntries = checkedEntries;
|
|
50
46
|
|
|
51
47
|
_utils.fs.emptyDirSync(distDirectory);
|
|
52
48
|
|
|
53
|
-
await
|
|
49
|
+
await hookRunners.beforeDev();
|
|
54
50
|
let compiler = null;
|
|
55
51
|
|
|
56
52
|
if (existSrc) {
|
|
57
|
-
const
|
|
53
|
+
const {
|
|
54
|
+
getWebpackConfig,
|
|
55
|
+
WebpackConfigTarget
|
|
56
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/webpack')));
|
|
57
|
+
const webpackConfigs = [(0, _utils.isSSR)(userConfig) && getWebpackConfig(WebpackConfigTarget.NODE), getWebpackConfig(WebpackConfigTarget.CLIENT)].filter(Boolean);
|
|
58
58
|
compiler = await (0, _createCompiler.createCompiler)({
|
|
59
|
+
api,
|
|
59
60
|
webpackConfigs,
|
|
60
61
|
userConfig,
|
|
61
62
|
appContext
|
|
@@ -95,7 +96,7 @@ const dev = async options => {
|
|
|
95
96
|
|
|
96
97
|
_utils.logger.log(_utils.chalk.cyan(`Starting the development server...`));
|
|
97
98
|
} else {
|
|
98
|
-
await (0, _printInstructions.printInstructions)(appContext, userConfig);
|
|
99
|
+
await (0, _printInstructions.printInstructions)(api, appContext, userConfig);
|
|
99
100
|
}
|
|
100
101
|
});
|
|
101
102
|
};
|
|
@@ -7,20 +7,15 @@ exports.start = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _utils = require("@modern-js/utils");
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var _server = _interopRequireDefault(require("@modern-js/server"));
|
|
10
|
+
var _prodServer = _interopRequireDefault(require("@modern-js/prod-server"));
|
|
13
11
|
|
|
14
12
|
var _printInstructions = require("../utils/printInstructions");
|
|
15
13
|
|
|
16
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
15
|
|
|
18
|
-
const start = async
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
const userConfig = (0, _core.useResolvedConfigContext)();
|
|
22
|
-
/* eslint-enable react-hooks/rules-of-hooks */
|
|
23
|
-
|
|
16
|
+
const start = async api => {
|
|
17
|
+
const appContext = api.useAppContext();
|
|
18
|
+
const userConfig = api.useResolvedConfigContext();
|
|
24
19
|
const {
|
|
25
20
|
appDirectory,
|
|
26
21
|
port
|
|
@@ -28,7 +23,7 @@ const start = async () => {
|
|
|
28
23
|
|
|
29
24
|
_utils.logger.log(_utils.chalk.cyan(`Starting the modern server...`));
|
|
30
25
|
|
|
31
|
-
const app = await (0,
|
|
26
|
+
const app = await (0, _prodServer.default)({
|
|
32
27
|
pwd: appDirectory,
|
|
33
28
|
config: userConfig,
|
|
34
29
|
plugins: appContext.plugins.filter(p => p.server).map(p => p.server)
|
|
@@ -38,7 +33,7 @@ const start = async () => {
|
|
|
38
33
|
throw err;
|
|
39
34
|
}
|
|
40
35
|
|
|
41
|
-
await (0, _printInstructions.printInstructions)(appContext, userConfig);
|
|
36
|
+
await (0, _printInstructions.printInstructions)(api, appContext, userConfig);
|
|
42
37
|
});
|
|
43
38
|
};
|
|
44
39
|
|
|
@@ -3,12 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.hooks = exports.beforePrintInstructions = exports.beforeDev = exports.beforeDeploy = exports.beforeCreateCompiler = exports.beforeBuild = exports.afterDev = exports.afterDeploy = exports.afterCreateCompiler = exports.afterBuild = void 0;
|
|
7
7
|
|
|
8
8
|
var _plugin = require("@modern-js/plugin");
|
|
9
9
|
|
|
10
|
-
var _core = require("@modern-js/core");
|
|
11
|
-
|
|
12
10
|
const beforeDev = (0, _plugin.createAsyncWorkflow)();
|
|
13
11
|
exports.beforeDev = beforeDev;
|
|
14
12
|
const afterDev = (0, _plugin.createAsyncWorkflow)();
|
|
@@ -27,19 +25,15 @@ const beforeDeploy = (0, _plugin.createAsyncWorkflow)();
|
|
|
27
25
|
exports.beforeDeploy = beforeDeploy;
|
|
28
26
|
const afterDeploy = (0, _plugin.createAsyncWorkflow)();
|
|
29
27
|
exports.afterDeploy = afterDeploy;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
beforeDeploy,
|
|
41
|
-
afterDeploy
|
|
42
|
-
});
|
|
28
|
+
const hooks = {
|
|
29
|
+
beforeDev,
|
|
30
|
+
afterDev,
|
|
31
|
+
beforeCreateCompiler,
|
|
32
|
+
afterCreateCompiler,
|
|
33
|
+
beforePrintInstructions,
|
|
34
|
+
beforeBuild,
|
|
35
|
+
afterBuild,
|
|
36
|
+
beforeDeploy,
|
|
37
|
+
afterDeploy
|
|
43
38
|
};
|
|
44
|
-
|
|
45
|
-
exports.lifecycle = lifecycle;
|
|
39
|
+
exports.hooks = hooks;
|
package/dist/js/node/index.js
CHANGED
|
@@ -15,9 +15,13 @@ var path = _interopRequireWildcard(require("path"));
|
|
|
15
15
|
|
|
16
16
|
var _core = require("@modern-js/core");
|
|
17
17
|
|
|
18
|
+
var _pluginAnalyze = _interopRequireDefault(require("@modern-js/plugin-analyze"));
|
|
19
|
+
|
|
20
|
+
var _cli = _interopRequireDefault(require("@modern-js/plugin-fast-refresh/cli"));
|
|
21
|
+
|
|
18
22
|
var _utils = require("@modern-js/utils");
|
|
19
23
|
|
|
20
|
-
var
|
|
24
|
+
var _hooks = require("./hooks");
|
|
21
25
|
|
|
22
26
|
var _locale = require("./locale");
|
|
23
27
|
|
|
@@ -29,6 +33,8 @@ var _dev = require("./commands/dev");
|
|
|
29
33
|
|
|
30
34
|
var _createServer = require("./utils/createServer");
|
|
31
35
|
|
|
36
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
37
|
+
|
|
32
38
|
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; }
|
|
33
39
|
|
|
34
40
|
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; }
|
|
@@ -39,86 +45,84 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
39
45
|
|
|
40
46
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
41
47
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
48
|
+
var _default = () => ({
|
|
49
|
+
name: '@modern-js/app-tools',
|
|
50
|
+
post: ['@modern-js/plugin-analyze', '@modern-js/plugin-fast-refresh', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-router', '@modern-js/plugin-polyfill'],
|
|
51
|
+
registerHook: _hooks.hooks,
|
|
52
|
+
usePlugins: [(0, _pluginAnalyze.default)(), (0, _cli.default)()],
|
|
53
|
+
setup: api => {
|
|
54
|
+
const locale = (0, _language.getLocaleLanguage)();
|
|
55
|
+
|
|
56
|
+
_locale.i18n.changeLanguage({
|
|
57
|
+
locale
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
commands({
|
|
62
|
+
program
|
|
63
|
+
}) {
|
|
64
|
+
program.command('dev').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.dev.describe)).option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.dev.config)).option('-e --entry [entry...]', _locale.i18n.t(_locale.localeKeys.command.dev.entry)).action(async options => {
|
|
65
|
+
await (0, _dev.dev)(api, options);
|
|
66
|
+
});
|
|
67
|
+
program.command('build').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.build.describe)).option('--analyze', _locale.i18n.t(_locale.localeKeys.command.build.analyze)).action(async options => {
|
|
68
|
+
const {
|
|
69
|
+
build
|
|
70
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/build")));
|
|
71
|
+
await build(api, options); // force exit after build.
|
|
72
|
+
// eslint-disable-next-line no-process-exit
|
|
73
|
+
|
|
74
|
+
process.exit(0);
|
|
75
|
+
});
|
|
76
|
+
program.command('start').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.start.describe)).action(async () => {
|
|
77
|
+
await (0, _start.start)(api);
|
|
78
|
+
});
|
|
79
|
+
program.command('deploy').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.deploy.describe)).action(async options => {
|
|
80
|
+
const {
|
|
81
|
+
build
|
|
82
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/build")));
|
|
83
|
+
await build(api);
|
|
84
|
+
const {
|
|
85
|
+
deploy
|
|
86
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/deploy")));
|
|
87
|
+
await deploy(api, options); // eslint-disable-next-line no-process-exit
|
|
88
|
+
|
|
89
|
+
process.exit(0);
|
|
90
|
+
});
|
|
91
|
+
program.command('new').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.new.describe)).option('-d, --debug', _locale.i18n.t(_locale.localeKeys.command.new.debug), false).option('-c, --config <config>', _locale.i18n.t(_locale.localeKeys.command.new.config)).option('--dist-tag <tag>', _locale.i18n.t(_locale.localeKeys.command.new.distTag)).option('--registry', _locale.i18n.t(_locale.localeKeys.command.new.registry)).action(async options => {
|
|
92
|
+
const {
|
|
93
|
+
MWANewAction
|
|
94
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/new-action')));
|
|
95
|
+
await MWANewAction(_objectSpread(_objectSpread({}, options), {}, {
|
|
96
|
+
locale
|
|
97
|
+
}));
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
|
102
|
+
async fileChange(e) {
|
|
77
103
|
const {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
process.exit(0);
|
|
83
|
-
});
|
|
84
|
-
program.command('new').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.new.describe)).option('-d, --debug', _locale.i18n.t(_locale.localeKeys.command.new.debug), false).option('-c, --config <config>', _locale.i18n.t(_locale.localeKeys.command.new.config)).option('--dist-tag <tag>', _locale.i18n.t(_locale.localeKeys.command.new.distTag)).option('--registry', _locale.i18n.t(_locale.localeKeys.command.new.registry)).action(async options => {
|
|
104
|
+
filename,
|
|
105
|
+
eventType
|
|
106
|
+
} = e;
|
|
107
|
+
const appContext = api.useAppContext();
|
|
85
108
|
const {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
} = e; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
100
|
-
|
|
101
|
-
const appContext = (0, _core.useAppContext)();
|
|
102
|
-
const {
|
|
103
|
-
appDirectory,
|
|
104
|
-
srcDirectory
|
|
105
|
-
} = appContext;
|
|
106
|
-
const absolutePath = path.resolve(appDirectory, filename);
|
|
107
|
-
|
|
108
|
-
if (!absolutePath.includes(srcDirectory) && (eventType === 'change' || eventType === 'unlink')) {
|
|
109
|
-
await (0, _createServer.closeServer)();
|
|
110
|
-
await _core.cli.restart();
|
|
109
|
+
appDirectory,
|
|
110
|
+
srcDirectory
|
|
111
|
+
} = appContext;
|
|
112
|
+
const absolutePath = path.resolve(appDirectory, filename);
|
|
113
|
+
|
|
114
|
+
if (!absolutePath.includes(srcDirectory) && (eventType === 'change' || eventType === 'unlink')) {
|
|
115
|
+
await (0, _createServer.closeServer)();
|
|
116
|
+
await _core.cli.restart();
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
async beforeRestart() {
|
|
121
|
+
(0, _utils.cleanRequireCache)([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
|
|
111
122
|
}
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
async beforeRestart() {
|
|
115
|
-
(0, _utils.cleanRequireCache)([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
|
|
116
|
-
}
|
|
117
123
|
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
name: '@modern-js/app-tools',
|
|
121
|
-
post: ['@modern-js/plugin-analyze', '@modern-js/plugin-fast-refresh', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-router', '@modern-js/plugin-polyfill']
|
|
124
|
+
};
|
|
125
|
+
}
|
|
122
126
|
});
|
|
123
127
|
|
|
124
128
|
exports.default = _default;
|
|
@@ -7,8 +7,6 @@ exports.createCompiler = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _webpack = _interopRequireDefault(require("webpack"));
|
|
9
9
|
|
|
10
|
-
var _core = require("@modern-js/core");
|
|
11
|
-
|
|
12
10
|
var _utils = require("@modern-js/utils");
|
|
13
11
|
|
|
14
12
|
var _printInstructions = require("./printInstructions");
|
|
@@ -22,17 +20,19 @@ const prettyTime = stats => {
|
|
|
22
20
|
};
|
|
23
21
|
|
|
24
22
|
const createCompiler = async ({
|
|
23
|
+
api,
|
|
25
24
|
webpackConfigs,
|
|
26
25
|
// TODO: params
|
|
27
26
|
userConfig,
|
|
28
27
|
appContext
|
|
29
28
|
}) => {
|
|
30
29
|
try {
|
|
31
|
-
|
|
30
|
+
const hookRunners = api.useHookRunners();
|
|
31
|
+
await hookRunners.beforeCreateCompiler({
|
|
32
32
|
webpackConfigs
|
|
33
33
|
});
|
|
34
34
|
const compiler = (0, _webpack.default)(webpackConfigs);
|
|
35
|
-
await
|
|
35
|
+
await hookRunners.afterCreateCompiler({
|
|
36
36
|
compiler
|
|
37
37
|
});
|
|
38
38
|
let isFirstCompile = true;
|
|
@@ -61,7 +61,7 @@ const createCompiler = async ({
|
|
|
61
61
|
|
|
62
62
|
_utils.logger.log();
|
|
63
63
|
} else if (process.stdout.isTTY || isFirstCompile) {
|
|
64
|
-
await
|
|
64
|
+
await hookRunners.afterDev();
|
|
65
65
|
|
|
66
66
|
if (warnings.length) {
|
|
67
67
|
_utils.logger.log(_utils.chalk.yellow(`Compiled with warnings.\n`));
|
|
@@ -73,7 +73,7 @@ const createCompiler = async ({
|
|
|
73
73
|
_utils.logger.log(_utils.chalk.green(`Compiled successfully in ${prettyTime(statsData)} ms.\n`));
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
await (0, _printInstructions.printInstructions)(appContext, userConfig);
|
|
76
|
+
await (0, _printInstructions.printInstructions)(api, appContext, userConfig);
|
|
77
77
|
} // eslint-disable-next-line require-atomic-updates
|
|
78
78
|
|
|
79
79
|
|
|
@@ -7,9 +7,7 @@ exports.printInstructions = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _utils = require("@modern-js/utils");
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const printInstructions = async (appContext, config) => {
|
|
10
|
+
const printInstructions = async (api, appContext, config) => {
|
|
13
11
|
let message = (0, _utils.prettyInstructions)(appContext, config);
|
|
14
12
|
const {
|
|
15
13
|
existSrc
|
|
@@ -20,9 +18,10 @@ const printInstructions = async (appContext, config) => {
|
|
|
20
18
|
} // call beforePrintInstructions hook.
|
|
21
19
|
|
|
22
20
|
|
|
21
|
+
const hookRunners = api.useHookRunners();
|
|
23
22
|
const {
|
|
24
23
|
instructions
|
|
25
|
-
} = await
|
|
24
|
+
} = await hookRunners.beforePrintInstructions({
|
|
26
25
|
instructions: message
|
|
27
26
|
});
|
|
28
27
|
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare const build: (options?: CliOptions | undefined) => Promise<void>;
|
|
5
|
-
export {};
|
|
1
|
+
import { PluginAPI } from '@modern-js/core';
|
|
2
|
+
import type { BuildOptions } from '../utils/types';
|
|
3
|
+
export declare const build: (api: PluginAPI, options?: BuildOptions | undefined) => Promise<void>;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { PluginAPI } from '@modern-js/core';
|
|
2
|
+
export declare const deploy: (api: PluginAPI, options: any) => Promise<void>;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { PluginAPI } from '@modern-js/core';
|
|
2
|
+
export declare const start: (api: PluginAPI) => Promise<void>;
|
|
@@ -16,4 +16,22 @@ export declare const beforeBuild: import("@modern-js/plugin").AsyncWorkflow<{
|
|
|
16
16
|
export declare const afterBuild: import("@modern-js/plugin").AsyncWorkflow<void, unknown>;
|
|
17
17
|
export declare const beforeDeploy: import("@modern-js/plugin").AsyncWorkflow<Record<string, any>, unknown>;
|
|
18
18
|
export declare const afterDeploy: import("@modern-js/plugin").AsyncWorkflow<Record<string, any>, unknown>;
|
|
19
|
-
export declare const
|
|
19
|
+
export declare const hooks: {
|
|
20
|
+
beforeDev: import("@modern-js/plugin").AsyncWorkflow<void, unknown>;
|
|
21
|
+
afterDev: import("@modern-js/plugin").AsyncWorkflow<void, unknown>;
|
|
22
|
+
beforeCreateCompiler: import("@modern-js/plugin").AsyncWorkflow<{
|
|
23
|
+
webpackConfigs: Configuration[];
|
|
24
|
+
}, unknown>;
|
|
25
|
+
afterCreateCompiler: import("@modern-js/plugin").AsyncWorkflow<{
|
|
26
|
+
compiler: Compiler | MultiCompiler | undefined;
|
|
27
|
+
}, unknown>;
|
|
28
|
+
beforePrintInstructions: import("@modern-js/plugin").AsyncWaterfall<{
|
|
29
|
+
instructions: string;
|
|
30
|
+
}>;
|
|
31
|
+
beforeBuild: import("@modern-js/plugin").AsyncWorkflow<{
|
|
32
|
+
webpackConfigs: Configuration[];
|
|
33
|
+
}, unknown>;
|
|
34
|
+
afterBuild: import("@modern-js/plugin").AsyncWorkflow<void, unknown>;
|
|
35
|
+
beforeDeploy: import("@modern-js/plugin").AsyncWorkflow<Record<string, any>, unknown>;
|
|
36
|
+
afterDeploy: import("@modern-js/plugin").AsyncWorkflow<Record<string, any>, unknown>;
|
|
37
|
+
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,23 +1,6 @@
|
|
|
1
|
-
import { defineConfig } from '@modern-js/core';
|
|
1
|
+
import { defineConfig, CliPlugin } from '@modern-js/core';
|
|
2
2
|
export { defineConfig };
|
|
3
3
|
|
|
4
|
-
declare const _default:
|
|
5
|
-
config: import("@modern-js/core").ParallelWorkflow<void, unknown>;
|
|
6
|
-
resolvedConfig: import("@modern-js/core").AsyncWaterfall<{
|
|
7
|
-
resolved: import("@modern-js/core").NormalizedConfig;
|
|
8
|
-
}>;
|
|
9
|
-
validateSchema: import("@modern-js/core").ParallelWorkflow<void, unknown>;
|
|
10
|
-
prepare: import("@modern-js/core").AsyncWorkflow<void, void>;
|
|
11
|
-
commands: import("@modern-js/core").AsyncWorkflow<{
|
|
12
|
-
program: import("commander").Command;
|
|
13
|
-
}, void>;
|
|
14
|
-
watchFiles: import("@modern-js/core").ParallelWorkflow<void, unknown>;
|
|
15
|
-
fileChange: import("@modern-js/core").AsyncWorkflow<{
|
|
16
|
-
filename: string;
|
|
17
|
-
eventType: "add" | "unlink" | "change";
|
|
18
|
-
}, void>;
|
|
19
|
-
beforeExit: import("@modern-js/core").AsyncWorkflow<void, void>;
|
|
20
|
-
beforeRestart: import("@modern-js/core").AsyncWorkflow<void, void>;
|
|
21
|
-
} & import("@modern-js/core").ClearDraftProgress<import("@modern-js/core").Hooks>>>>;
|
|
4
|
+
declare const _default: () => CliPlugin;
|
|
22
5
|
|
|
23
6
|
export default _default;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import webpack, { Configuration } from 'webpack';
|
|
2
|
-
import { IAppContext, NormalizedConfig } from '@modern-js/core';
|
|
2
|
+
import type { IAppContext, NormalizedConfig, PluginAPI } from '@modern-js/core';
|
|
3
3
|
export declare const createCompiler: ({
|
|
4
|
+
api,
|
|
4
5
|
webpackConfigs,
|
|
5
6
|
userConfig,
|
|
6
7
|
appContext
|
|
7
8
|
}: {
|
|
9
|
+
api: PluginAPI;
|
|
8
10
|
webpackConfigs: Configuration[];
|
|
9
11
|
userConfig: NormalizedConfig;
|
|
10
12
|
appContext: IAppContext;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Server,
|
|
1
|
+
import { Server, ModernDevServerOptions } from '@modern-js/server';
|
|
2
2
|
export declare const getServer: () => Server | null;
|
|
3
3
|
export declare const closeServer: () => Promise<void>;
|
|
4
|
-
export declare const createServer: (options:
|
|
4
|
+
export declare const createServer: (options: ModernDevServerOptions) => Promise<Server>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IAppContext, NormalizedConfig } from '@modern-js/core';
|
|
2
|
-
export declare const printInstructions: (appContext: IAppContext, config: NormalizedConfig) => Promise<void>;
|
|
1
|
+
import type { PluginAPI, IAppContext, NormalizedConfig } from '@modern-js/core';
|
|
2
|
+
export declare const printInstructions: (api: PluginAPI, appContext: IAppContext, config: NormalizedConfig) => Promise<void>;
|