@modern-js/app-tools 1.4.4 → 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 +25 -0
- package/dist/js/modern/commands/build.js +9 -10
- package/dist/js/modern/commands/deploy.js +4 -4
- package/dist/js/modern/commands/dev.js +8 -11
- package/dist/js/modern/commands/start.js +4 -8
- package/dist/js/modern/{lifecycle.js → hooks.js} +10 -13
- package/dist/js/modern/index.js +74 -73
- 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 +8 -9
- package/dist/js/node/commands/deploy.js +4 -5
- package/dist/js/node/commands/dev.js +8 -14
- package/dist/js/node/commands/start.js +4 -9
- package/dist/js/node/{lifecycle.js → hooks.js} +12 -18
- package/dist/js/node/index.js +81 -77
- 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 +2 -1
- 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 -7
- package/dist/types/utils/createCompiler.d.ts +3 -1
- package/dist/types/utils/printInstructions.d.ts +2 -2
- package/dist/types/utils/routes.d.ts +1 -1
- package/modern.config.js +1 -0
- package/package.json +10 -14
- package/tests/.eslintrc.js +8 -0
- package/tests/commands/build.test.ts +25 -24
package/.eslintrc.js
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
+
## 1.4.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 32c9772c: feat: convert to new plugin
|
|
8
|
+
- Updated dependencies [05ce88a0]
|
|
9
|
+
- Updated dependencies [a8df060e]
|
|
10
|
+
- Updated dependencies [c2046f37]
|
|
11
|
+
- Updated dependencies [dc88abf9]
|
|
12
|
+
- Updated dependencies [d2d0fa11]
|
|
13
|
+
- Updated dependencies [66cbef42]
|
|
14
|
+
- Updated dependencies [0462ff77]
|
|
15
|
+
- Updated dependencies [61e3f623]
|
|
16
|
+
- Updated dependencies [6a7acb81]
|
|
17
|
+
- Updated dependencies [681a1ff9]
|
|
18
|
+
- Updated dependencies [4e2026e4]
|
|
19
|
+
- @modern-js/core@1.6.0
|
|
20
|
+
- @modern-js/server@1.4.8
|
|
21
|
+
- @modern-js/utils@1.3.6
|
|
22
|
+
- @modern-js/plugin@1.3.2
|
|
23
|
+
- @modern-js/prod-server@1.0.5
|
|
24
|
+
- @modern-js/webpack@1.5.0
|
|
25
|
+
- @modern-js/plugin-fast-refresh@1.2.2
|
|
26
|
+
- @modern-js/plugin-analyze@1.3.4
|
|
27
|
+
|
|
3
28
|
## 1.4.4
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
|
@@ -6,32 +6,31 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
6
6
|
|
|
7
7
|
import { webpack } from 'webpack';
|
|
8
8
|
import { WebpackConfigTarget, getWebpackConfig } from '@modern-js/webpack';
|
|
9
|
-
import {
|
|
9
|
+
import { manager, ResolvedConfigContext } from '@modern-js/core';
|
|
10
10
|
import { formatWebpackMessages, measureFileSizesBeforeBuild, printFileSizesAfterBuild, printBuildError, logger, isUseSSRBundle, emptyDir } from '@modern-js/utils';
|
|
11
11
|
import { generateRoutes } from "../utils/routes";
|
|
12
12
|
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
|
13
13
|
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
|
14
14
|
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024; // eslint-disable-next-line max-statements
|
|
15
15
|
|
|
16
|
-
export const build = async options => {
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
const
|
|
16
|
+
export const build = async (api, options) => {
|
|
17
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
18
|
+
const appContext = api.useAppContext();
|
|
19
|
+
const hookRunners = api.useHookRunners();
|
|
20
20
|
const {
|
|
21
21
|
existSrc
|
|
22
22
|
} = appContext;
|
|
23
|
-
/* eslint-enable react-hooks/rules-of-hooks */
|
|
24
23
|
|
|
25
24
|
if (!existSrc) {
|
|
26
25
|
const {
|
|
27
26
|
distDirectory
|
|
28
27
|
} = appContext;
|
|
29
28
|
await emptyDir(distDirectory);
|
|
30
|
-
await
|
|
29
|
+
await hookRunners.beforeBuild({
|
|
31
30
|
webpackConfigs: []
|
|
32
31
|
});
|
|
33
32
|
await generateRoutes(appContext);
|
|
34
|
-
await
|
|
33
|
+
await hookRunners.afterBuild();
|
|
35
34
|
return;
|
|
36
35
|
}
|
|
37
36
|
|
|
@@ -116,7 +115,7 @@ export const build = async options => {
|
|
|
116
115
|
});
|
|
117
116
|
}
|
|
118
117
|
|
|
119
|
-
await
|
|
118
|
+
await hookRunners.beforeBuild({
|
|
120
119
|
webpackConfigs: buildConfigs.map(({
|
|
121
120
|
config
|
|
122
121
|
}) => config)
|
|
@@ -138,5 +137,5 @@ export const build = async options => {
|
|
|
138
137
|
}
|
|
139
138
|
|
|
140
139
|
await generateRoutes(appContext);
|
|
141
|
-
await
|
|
140
|
+
await hookRunners.afterBuild();
|
|
142
141
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
await
|
|
4
|
-
await
|
|
1
|
+
export const deploy = async (api, options) => {
|
|
2
|
+
const hookRunners = api.useHookRunners();
|
|
3
|
+
await hookRunners.beforeDeploy(options);
|
|
4
|
+
await hookRunners.afterDeploy(options);
|
|
5
5
|
};
|
|
@@ -5,18 +5,15 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
5
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
6
|
|
|
7
7
|
import { fs, logger, HMR_SOCK_PATH, clearConsole, chalk, isSSR } from '@modern-js/utils';
|
|
8
|
-
import { useAppContext, useResolvedConfigContext, mountHook, AppContext } from '@modern-js/core';
|
|
9
8
|
import { createCompiler } from "../utils/createCompiler";
|
|
10
9
|
import { createServer } from "../utils/createServer";
|
|
11
10
|
import { generateRoutes } from "../utils/routes";
|
|
12
11
|
import { printInstructions } from "../utils/printInstructions";
|
|
13
12
|
import { getSpecifiedEntries } from "../utils/getSpecifiedEntries";
|
|
14
|
-
export const dev = async options => {
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
/* eslint-enable react-hooks/rules-of-hooks */
|
|
19
|
-
|
|
13
|
+
export const dev = async (api, options) => {
|
|
14
|
+
const appContext = api.useAppContext();
|
|
15
|
+
const userConfig = api.useResolvedConfigContext();
|
|
16
|
+
const hookRunners = api.useHookRunners();
|
|
20
17
|
const {
|
|
21
18
|
appDirectory,
|
|
22
19
|
distDirectory,
|
|
@@ -25,12 +22,12 @@ export const dev = async options => {
|
|
|
25
22
|
entrypoints
|
|
26
23
|
} = appContext;
|
|
27
24
|
const checkedEntries = await getSpecifiedEntries(options.entry || false, entrypoints);
|
|
28
|
-
|
|
25
|
+
api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
|
|
29
26
|
checkedEntries
|
|
30
27
|
}));
|
|
31
28
|
appContext.checkedEntries = checkedEntries;
|
|
32
29
|
fs.emptyDirSync(distDirectory);
|
|
33
|
-
await
|
|
30
|
+
await hookRunners.beforeDev();
|
|
34
31
|
let compiler = null;
|
|
35
32
|
|
|
36
33
|
if (existSrc) {
|
|
@@ -40,6 +37,7 @@ export const dev = async options => {
|
|
|
40
37
|
} = await import('@modern-js/webpack');
|
|
41
38
|
const webpackConfigs = [isSSR(userConfig) && getWebpackConfig(WebpackConfigTarget.NODE), getWebpackConfig(WebpackConfigTarget.CLIENT)].filter(Boolean);
|
|
42
39
|
compiler = await createCompiler({
|
|
40
|
+
api,
|
|
43
41
|
webpackConfigs,
|
|
44
42
|
userConfig,
|
|
45
43
|
appContext
|
|
@@ -50,7 +48,6 @@ export const dev = async options => {
|
|
|
50
48
|
const app = await createServer({
|
|
51
49
|
dev: _objectSpread(_objectSpread({}, {
|
|
52
50
|
client: {
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
54
51
|
port: port.toString(),
|
|
55
52
|
overlay: false,
|
|
56
53
|
logging: 'none',
|
|
@@ -79,7 +76,7 @@ export const dev = async options => {
|
|
|
79
76
|
clearConsole();
|
|
80
77
|
logger.log(chalk.cyan(`Starting the development server...`));
|
|
81
78
|
} else {
|
|
82
|
-
await printInstructions(appContext, userConfig);
|
|
79
|
+
await printInstructions(api, appContext, userConfig);
|
|
83
80
|
}
|
|
84
81
|
});
|
|
85
82
|
};
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { logger, chalk } from '@modern-js/utils';
|
|
2
|
-
import { useAppContext, useResolvedConfigContext } from '@modern-js/core';
|
|
3
2
|
import server from '@modern-js/prod-server';
|
|
4
3
|
import { printInstructions } from "../utils/printInstructions";
|
|
5
|
-
export const start = async
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const userConfig = useResolvedConfigContext();
|
|
9
|
-
/* eslint-enable react-hooks/rules-of-hooks */
|
|
10
|
-
|
|
4
|
+
export const start = async api => {
|
|
5
|
+
const appContext = api.useAppContext();
|
|
6
|
+
const userConfig = api.useResolvedConfigContext();
|
|
11
7
|
const {
|
|
12
8
|
appDirectory,
|
|
13
9
|
port
|
|
@@ -23,6 +19,6 @@ export const start = async () => {
|
|
|
23
19
|
throw err;
|
|
24
20
|
}
|
|
25
21
|
|
|
26
|
-
await printInstructions(appContext, userConfig);
|
|
22
|
+
await printInstructions(api, appContext, userConfig);
|
|
27
23
|
});
|
|
28
24
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createAsyncWaterfall, createAsyncWorkflow } from '@modern-js/plugin';
|
|
2
|
-
import { registerHook } from '@modern-js/core';
|
|
3
2
|
export const beforeDev = createAsyncWorkflow();
|
|
4
3
|
export const afterDev = createAsyncWorkflow();
|
|
5
4
|
export const beforeCreateCompiler = createAsyncWorkflow();
|
|
@@ -9,16 +8,14 @@ export const beforeBuild = createAsyncWorkflow();
|
|
|
9
8
|
export const afterBuild = createAsyncWorkflow();
|
|
10
9
|
export const beforeDeploy = createAsyncWorkflow();
|
|
11
10
|
export const afterDeploy = createAsyncWorkflow();
|
|
12
|
-
export const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
afterDeploy
|
|
23
|
-
});
|
|
11
|
+
export const hooks = {
|
|
12
|
+
beforeDev,
|
|
13
|
+
afterDev,
|
|
14
|
+
beforeCreateCompiler,
|
|
15
|
+
afterCreateCompiler,
|
|
16
|
+
beforePrintInstructions,
|
|
17
|
+
beforeBuild,
|
|
18
|
+
afterBuild,
|
|
19
|
+
beforeDeploy,
|
|
20
|
+
afterDeploy
|
|
24
21
|
};
|
package/dist/js/modern/index.js
CHANGED
|
@@ -5,90 +5,91 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
5
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
6
|
|
|
7
7
|
import * as path from 'path';
|
|
8
|
-
import {
|
|
8
|
+
import { defineConfig, cli } from '@modern-js/core';
|
|
9
|
+
import AnalyzePlugin from '@modern-js/plugin-analyze';
|
|
10
|
+
import FastRefreshPlugin from '@modern-js/plugin-fast-refresh/cli';
|
|
9
11
|
import { cleanRequireCache } from '@modern-js/utils';
|
|
10
|
-
import {
|
|
12
|
+
import { hooks } from "./hooks";
|
|
11
13
|
import { i18n, localeKeys } from "./locale";
|
|
12
14
|
import { getLocaleLanguage } from "./utils/language";
|
|
13
15
|
import { start } from "./commands/start";
|
|
14
16
|
import { dev } from "./commands/dev";
|
|
15
17
|
import { closeServer } from "./utils/createServer";
|
|
16
|
-
export { defineConfig };
|
|
18
|
+
export { defineConfig };
|
|
19
|
+
export default (() => ({
|
|
20
|
+
name: '@modern-js/app-tools',
|
|
21
|
+
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'],
|
|
22
|
+
registerHook: hooks,
|
|
23
|
+
usePlugins: [AnalyzePlugin(), FastRefreshPlugin()],
|
|
24
|
+
setup: api => {
|
|
25
|
+
const locale = getLocaleLanguage();
|
|
26
|
+
i18n.changeLanguage({
|
|
27
|
+
locale
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
commands({
|
|
31
|
+
program
|
|
32
|
+
}) {
|
|
33
|
+
program.command('dev').usage('[options]').description(i18n.t(localeKeys.command.dev.describe)).option('-c --config <config>', i18n.t(localeKeys.command.dev.config)).option('-e --entry [entry...]', i18n.t(localeKeys.command.dev.entry)).action(async options => {
|
|
34
|
+
await dev(api, options);
|
|
35
|
+
});
|
|
36
|
+
program.command('build').usage('[options]').description(i18n.t(localeKeys.command.build.describe)).option('--analyze', i18n.t(localeKeys.command.build.analyze)).action(async options => {
|
|
37
|
+
const {
|
|
38
|
+
build
|
|
39
|
+
} = await import("./commands/build");
|
|
40
|
+
await build(api, options); // force exit after build.
|
|
41
|
+
// eslint-disable-next-line no-process-exit
|
|
17
42
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
program.command('build').usage('[options]').description(i18n.t(localeKeys.command.build.describe)).option('--analyze', i18n.t(localeKeys.command.build.analyze)).action(async options => {
|
|
33
|
-
const {
|
|
34
|
-
build
|
|
35
|
-
} = await import("./commands/build");
|
|
36
|
-
await build(options); // force exit after build.
|
|
37
|
-
// eslint-disable-next-line no-process-exit
|
|
43
|
+
process.exit(0);
|
|
44
|
+
});
|
|
45
|
+
program.command('start').usage('[options]').description(i18n.t(localeKeys.command.start.describe)).action(async () => {
|
|
46
|
+
await start(api);
|
|
47
|
+
});
|
|
48
|
+
program.command('deploy').usage('[options]').description(i18n.t(localeKeys.command.deploy.describe)).action(async options => {
|
|
49
|
+
const {
|
|
50
|
+
build
|
|
51
|
+
} = await import("./commands/build");
|
|
52
|
+
await build(api);
|
|
53
|
+
const {
|
|
54
|
+
deploy
|
|
55
|
+
} = await import("./commands/deploy");
|
|
56
|
+
await deploy(api, options); // eslint-disable-next-line no-process-exit
|
|
38
57
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
deploy
|
|
51
|
-
} = await import("./commands/deploy");
|
|
52
|
-
await deploy(options); // eslint-disable-next-line no-process-exit
|
|
58
|
+
process.exit(0);
|
|
59
|
+
});
|
|
60
|
+
program.command('new').usage('[options]').description(i18n.t(localeKeys.command.new.describe)).option('-d, --debug', i18n.t(localeKeys.command.new.debug), false).option('-c, --config <config>', i18n.t(localeKeys.command.new.config)).option('--dist-tag <tag>', i18n.t(localeKeys.command.new.distTag)).option('--registry', i18n.t(localeKeys.command.new.registry)).action(async options => {
|
|
61
|
+
const {
|
|
62
|
+
MWANewAction
|
|
63
|
+
} = await import('@modern-js/new-action');
|
|
64
|
+
await MWANewAction(_objectSpread(_objectSpread({}, options), {}, {
|
|
65
|
+
locale
|
|
66
|
+
}));
|
|
67
|
+
});
|
|
68
|
+
},
|
|
53
69
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
program.command('new').usage('[options]').description(i18n.t(localeKeys.command.new.describe)).option('-d, --debug', i18n.t(localeKeys.command.new.debug), false).option('-c, --config <config>', i18n.t(localeKeys.command.new.config)).option('--dist-tag <tag>', i18n.t(localeKeys.command.new.distTag)).option('--registry', i18n.t(localeKeys.command.new.registry)).action(async options => {
|
|
70
|
+
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
|
71
|
+
async fileChange(e) {
|
|
57
72
|
const {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
async fileChange(e) {
|
|
68
|
-
const {
|
|
69
|
-
filename,
|
|
70
|
-
eventType
|
|
71
|
-
} = e; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
73
|
+
filename,
|
|
74
|
+
eventType
|
|
75
|
+
} = e;
|
|
76
|
+
const appContext = api.useAppContext();
|
|
77
|
+
const {
|
|
78
|
+
appDirectory,
|
|
79
|
+
srcDirectory
|
|
80
|
+
} = appContext;
|
|
81
|
+
const absolutePath = path.resolve(appDirectory, filename);
|
|
72
82
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
const absolutePath = path.resolve(appDirectory, filename);
|
|
83
|
+
if (!absolutePath.includes(srcDirectory) && (eventType === 'change' || eventType === 'unlink')) {
|
|
84
|
+
await closeServer();
|
|
85
|
+
await cli.restart();
|
|
86
|
+
}
|
|
87
|
+
},
|
|
79
88
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
await cli.restart();
|
|
89
|
+
async beforeRestart() {
|
|
90
|
+
cleanRequireCache([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
|
|
83
91
|
}
|
|
84
|
-
},
|
|
85
92
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
};
|
|
91
|
-
}, {
|
|
92
|
-
name: '@modern-js/app-tools',
|
|
93
|
-
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']
|
|
94
|
-
});
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}));
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import webpack from 'webpack';
|
|
2
|
-
import { mountHook } from '@modern-js/core';
|
|
3
2
|
import { chalk, logger, formatWebpackMessages, clearConsole } from '@modern-js/utils';
|
|
4
3
|
import { printInstructions } from "./printInstructions";
|
|
5
4
|
|
|
@@ -10,17 +9,19 @@ const prettyTime = stats => {
|
|
|
10
9
|
};
|
|
11
10
|
|
|
12
11
|
export const createCompiler = async ({
|
|
12
|
+
api,
|
|
13
13
|
webpackConfigs,
|
|
14
14
|
// TODO: params
|
|
15
15
|
userConfig,
|
|
16
16
|
appContext
|
|
17
17
|
}) => {
|
|
18
18
|
try {
|
|
19
|
-
|
|
19
|
+
const hookRunners = api.useHookRunners();
|
|
20
|
+
await hookRunners.beforeCreateCompiler({
|
|
20
21
|
webpackConfigs
|
|
21
22
|
});
|
|
22
23
|
const compiler = webpack(webpackConfigs);
|
|
23
|
-
await
|
|
24
|
+
await hookRunners.afterCreateCompiler({
|
|
24
25
|
compiler
|
|
25
26
|
});
|
|
26
27
|
let isFirstCompile = true;
|
|
@@ -46,7 +47,7 @@ export const createCompiler = async ({
|
|
|
46
47
|
logger.log(errors.join('\n\n'));
|
|
47
48
|
logger.log();
|
|
48
49
|
} else if (process.stdout.isTTY || isFirstCompile) {
|
|
49
|
-
await
|
|
50
|
+
await hookRunners.afterDev();
|
|
50
51
|
|
|
51
52
|
if (warnings.length) {
|
|
52
53
|
logger.log(chalk.yellow(`Compiled with warnings.\n`));
|
|
@@ -56,7 +57,7 @@ export const createCompiler = async ({
|
|
|
56
57
|
logger.log(chalk.green(`Compiled successfully in ${prettyTime(statsData)} ms.\n`));
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
await printInstructions(appContext, userConfig);
|
|
60
|
+
await printInstructions(api, appContext, userConfig);
|
|
60
61
|
} // eslint-disable-next-line require-atomic-updates
|
|
61
62
|
|
|
62
63
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { prettyInstructions, logger, isDev, chalk } from '@modern-js/utils';
|
|
2
|
-
|
|
3
|
-
export const printInstructions = async (appContext, config) => {
|
|
2
|
+
export const printInstructions = async (api, appContext, config) => {
|
|
4
3
|
let message = prettyInstructions(appContext, config);
|
|
5
4
|
const {
|
|
6
5
|
existSrc
|
|
@@ -11,9 +10,10 @@ export const printInstructions = async (appContext, config) => {
|
|
|
11
10
|
} // call beforePrintInstructions hook.
|
|
12
11
|
|
|
13
12
|
|
|
13
|
+
const hookRunners = api.useHookRunners();
|
|
14
14
|
const {
|
|
15
15
|
instructions
|
|
16
|
-
} = await
|
|
16
|
+
} = await hookRunners.beforePrintInstructions({
|
|
17
17
|
instructions: message
|
|
18
18
|
});
|
|
19
19
|
logger.log(instructions);
|
|
@@ -25,25 +25,24 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
25
25
|
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
|
26
26
|
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024; // eslint-disable-next-line max-statements
|
|
27
27
|
|
|
28
|
-
const build = async options => {
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
const
|
|
28
|
+
const build = async (api, options) => {
|
|
29
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
30
|
+
const appContext = api.useAppContext();
|
|
31
|
+
const hookRunners = api.useHookRunners();
|
|
32
32
|
const {
|
|
33
33
|
existSrc
|
|
34
34
|
} = appContext;
|
|
35
|
-
/* eslint-enable react-hooks/rules-of-hooks */
|
|
36
35
|
|
|
37
36
|
if (!existSrc) {
|
|
38
37
|
const {
|
|
39
38
|
distDirectory
|
|
40
39
|
} = appContext;
|
|
41
40
|
await (0, _utils.emptyDir)(distDirectory);
|
|
42
|
-
await
|
|
41
|
+
await hookRunners.beforeBuild({
|
|
43
42
|
webpackConfigs: []
|
|
44
43
|
});
|
|
45
44
|
await (0, _routes.generateRoutes)(appContext);
|
|
46
|
-
await
|
|
45
|
+
await hookRunners.afterBuild();
|
|
47
46
|
return;
|
|
48
47
|
}
|
|
49
48
|
|
|
@@ -132,7 +131,7 @@ const build = async options => {
|
|
|
132
131
|
});
|
|
133
132
|
}
|
|
134
133
|
|
|
135
|
-
await
|
|
134
|
+
await hookRunners.beforeBuild({
|
|
136
135
|
webpackConfigs: buildConfigs.map(({
|
|
137
136
|
config
|
|
138
137
|
}) => config)
|
|
@@ -154,7 +153,7 @@ const build = async options => {
|
|
|
154
153
|
}
|
|
155
154
|
|
|
156
155
|
await (0, _routes.generateRoutes)(appContext);
|
|
157
|
-
await
|
|
156
|
+
await hookRunners.afterBuild();
|
|
158
157
|
};
|
|
159
158
|
|
|
160
159
|
exports.build = build;
|
|
@@ -5,11 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.deploy = void 0;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
await
|
|
12
|
-
await (0, _core.mountHook)().afterDeploy(options);
|
|
8
|
+
const deploy = async (api, options) => {
|
|
9
|
+
const hookRunners = api.useHookRunners();
|
|
10
|
+
await hookRunners.beforeDeploy(options);
|
|
11
|
+
await hookRunners.afterDeploy(options);
|
|
13
12
|
};
|
|
14
13
|
|
|
15
14
|
exports.deploy = deploy;
|
|
@@ -7,8 +7,6 @@ exports.dev = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _utils = require("@modern-js/utils");
|
|
9
9
|
|
|
10
|
-
var _core = require("@modern-js/core");
|
|
11
|
-
|
|
12
10
|
var _createCompiler = require("../utils/createCompiler");
|
|
13
11
|
|
|
14
12
|
var _createServer = require("../utils/createServer");
|
|
@@ -29,12 +27,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
29
27
|
|
|
30
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; }
|
|
31
29
|
|
|
32
|
-
const dev = async options => {
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
/* eslint-enable react-hooks/rules-of-hooks */
|
|
37
|
-
|
|
30
|
+
const dev = async (api, options) => {
|
|
31
|
+
const appContext = api.useAppContext();
|
|
32
|
+
const userConfig = api.useResolvedConfigContext();
|
|
33
|
+
const hookRunners = api.useHookRunners();
|
|
38
34
|
const {
|
|
39
35
|
appDirectory,
|
|
40
36
|
distDirectory,
|
|
@@ -43,16 +39,14 @@ const dev = async options => {
|
|
|
43
39
|
entrypoints
|
|
44
40
|
} = appContext;
|
|
45
41
|
const checkedEntries = await (0, _getSpecifiedEntries.getSpecifiedEntries)(options.entry || false, entrypoints);
|
|
46
|
-
|
|
47
|
-
_core.AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
|
|
42
|
+
api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
|
|
48
43
|
checkedEntries
|
|
49
44
|
}));
|
|
50
|
-
|
|
51
45
|
appContext.checkedEntries = checkedEntries;
|
|
52
46
|
|
|
53
47
|
_utils.fs.emptyDirSync(distDirectory);
|
|
54
48
|
|
|
55
|
-
await
|
|
49
|
+
await hookRunners.beforeDev();
|
|
56
50
|
let compiler = null;
|
|
57
51
|
|
|
58
52
|
if (existSrc) {
|
|
@@ -62,6 +56,7 @@ const dev = async options => {
|
|
|
62
56
|
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/webpack')));
|
|
63
57
|
const webpackConfigs = [(0, _utils.isSSR)(userConfig) && getWebpackConfig(WebpackConfigTarget.NODE), getWebpackConfig(WebpackConfigTarget.CLIENT)].filter(Boolean);
|
|
64
58
|
compiler = await (0, _createCompiler.createCompiler)({
|
|
59
|
+
api,
|
|
65
60
|
webpackConfigs,
|
|
66
61
|
userConfig,
|
|
67
62
|
appContext
|
|
@@ -72,7 +67,6 @@ const dev = async options => {
|
|
|
72
67
|
const app = await (0, _createServer.createServer)({
|
|
73
68
|
dev: _objectSpread(_objectSpread({}, {
|
|
74
69
|
client: {
|
|
75
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
76
70
|
port: port.toString(),
|
|
77
71
|
overlay: false,
|
|
78
72
|
logging: 'none',
|
|
@@ -102,7 +96,7 @@ const dev = async options => {
|
|
|
102
96
|
|
|
103
97
|
_utils.logger.log(_utils.chalk.cyan(`Starting the development server...`));
|
|
104
98
|
} else {
|
|
105
|
-
await (0, _printInstructions.printInstructions)(appContext, userConfig);
|
|
99
|
+
await (0, _printInstructions.printInstructions)(api, appContext, userConfig);
|
|
106
100
|
}
|
|
107
101
|
});
|
|
108
102
|
};
|
|
@@ -7,20 +7,15 @@ exports.start = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _utils = require("@modern-js/utils");
|
|
9
9
|
|
|
10
|
-
var _core = require("@modern-js/core");
|
|
11
|
-
|
|
12
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
|
|
@@ -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,2 +1,3 @@
|
|
|
1
|
+
import { PluginAPI } from '@modern-js/core';
|
|
1
2
|
import type { BuildOptions } from '../utils/types';
|
|
2
|
-
export declare const build: (options?: BuildOptions | undefined) => Promise<void>;
|
|
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,11 +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
|
-
setAppContext: (value: import("@modern-js/core").IAppContext) => void;
|
|
6
|
-
useAppContext: () => import("@modern-js/core").IAppContext;
|
|
7
|
-
useConfigContext: () => import("@modern-js/core/src/config").UserConfig;
|
|
8
|
-
useResolvedConfigContext: () => import("@modern-js/core").NormalizedConfig;
|
|
9
|
-
}>;
|
|
4
|
+
declare const _default: () => CliPlugin;
|
|
10
5
|
|
|
11
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,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>;
|
package/modern.config.js
CHANGED
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.4.
|
|
14
|
+
"version": "1.4.5",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -49,19 +49,19 @@
|
|
|
49
49
|
"modern": "./bin/modern.js"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@modern-js/core": "^1.
|
|
52
|
+
"@modern-js/core": "^1.6.0",
|
|
53
53
|
"@babel/runtime": "^7",
|
|
54
54
|
"@modern-js/types": "^1.3.5",
|
|
55
55
|
"@modern-js/i18n-cli-language-detector": "^1.2.1",
|
|
56
56
|
"@modern-js/new-action": "^1.3.3",
|
|
57
|
-
"@modern-js/plugin": "^1.3.
|
|
58
|
-
"@modern-js/plugin-analyze": "^1.3.
|
|
59
|
-
"@modern-js/plugin-fast-refresh": "^1.2.
|
|
57
|
+
"@modern-js/plugin": "^1.3.2",
|
|
58
|
+
"@modern-js/plugin-analyze": "^1.3.4",
|
|
59
|
+
"@modern-js/plugin-fast-refresh": "^1.2.2",
|
|
60
60
|
"@modern-js/plugin-i18n": "^1.2.1",
|
|
61
|
-
"@modern-js/server": "^1.4.
|
|
62
|
-
"@modern-js/prod-server": "^1.0.
|
|
63
|
-
"@modern-js/utils": "^1.3.
|
|
64
|
-
"@modern-js/webpack": "^1.
|
|
61
|
+
"@modern-js/server": "^1.4.8",
|
|
62
|
+
"@modern-js/prod-server": "^1.0.5",
|
|
63
|
+
"@modern-js/utils": "^1.3.6",
|
|
64
|
+
"@modern-js/webpack": "^1.5.0",
|
|
65
65
|
"inquirer": "^8.2.0",
|
|
66
66
|
"webpack": "^5.54.0"
|
|
67
67
|
},
|
|
@@ -77,17 +77,13 @@
|
|
|
77
77
|
"@types/inquirer": "^8.2.0"
|
|
78
78
|
},
|
|
79
79
|
"sideEffects": false,
|
|
80
|
-
"modernConfig": {
|
|
81
|
-
"output": {
|
|
82
|
-
"packageMode": "node-js"
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
80
|
"publishConfig": {
|
|
86
81
|
"registry": "https://registry.npmjs.org/",
|
|
87
82
|
"access": "public"
|
|
88
83
|
},
|
|
89
84
|
"scripts": {
|
|
90
85
|
"new": "modern new",
|
|
86
|
+
"dev": "modern build --watch",
|
|
91
87
|
"build": "modern build",
|
|
92
88
|
"test": "jest --passWithNoTests"
|
|
93
89
|
},
|
|
@@ -1,27 +1,8 @@
|
|
|
1
|
+
import { manager } from '@modern-js/core';
|
|
1
2
|
import { build } from '../../src/commands/build';
|
|
2
3
|
|
|
3
|
-
const mockBeforeBuild = jest.fn();
|
|
4
|
-
const mockAfterBuild = jest.fn();
|
|
5
4
|
const mockGenerateRoutes = jest.fn();
|
|
6
5
|
|
|
7
|
-
// eslint-disable-next-line arrow-body-style
|
|
8
|
-
jest.mock('@modern-js/core', () => {
|
|
9
|
-
return {
|
|
10
|
-
__esModule: true,
|
|
11
|
-
mountHook() {
|
|
12
|
-
return {
|
|
13
|
-
beforeBuild: mockBeforeBuild,
|
|
14
|
-
afterBuild: mockAfterBuild,
|
|
15
|
-
};
|
|
16
|
-
},
|
|
17
|
-
useAppContext: jest.fn(() => ({
|
|
18
|
-
existSrc: false,
|
|
19
|
-
distDirectory: '',
|
|
20
|
-
})),
|
|
21
|
-
useResolvedConfigContext: jest.fn(),
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
|
|
25
6
|
jest.mock('../../src/utils/routes', () => ({
|
|
26
7
|
__esModule: true,
|
|
27
8
|
generateRoutes: () => mockGenerateRoutes(),
|
|
@@ -33,9 +14,29 @@ describe('command build', () => {
|
|
|
33
14
|
});
|
|
34
15
|
|
|
35
16
|
test('existSrc is false', async () => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
17
|
+
const mockBeforeBuild = jest.fn();
|
|
18
|
+
const mockAfterBuild = jest.fn();
|
|
19
|
+
const mockAPI = {
|
|
20
|
+
useAppContext: jest.fn((): any => ({
|
|
21
|
+
existSrc: false,
|
|
22
|
+
distDirectory: '',
|
|
23
|
+
})),
|
|
24
|
+
useResolvedConfigContext: jest.fn(),
|
|
25
|
+
useHookRunners: (): any => ({
|
|
26
|
+
afterBuild: mockAfterBuild,
|
|
27
|
+
beforeBuild: mockBeforeBuild,
|
|
28
|
+
}),
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const cloned = manager.clone(mockAPI);
|
|
32
|
+
cloned.usePlugin({
|
|
33
|
+
async setup(api) {
|
|
34
|
+
await build(api);
|
|
35
|
+
expect(mockBeforeBuild).toBeCalled();
|
|
36
|
+
expect(mockGenerateRoutes).toBeCalled();
|
|
37
|
+
expect(mockAfterBuild).toBeCalled();
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
await cloned.init();
|
|
40
41
|
});
|
|
41
42
|
});
|