@modern-js/app-tools 2.53.0 → 2.53.1-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/plugins/deploy/dependencies/index.js +5 -13
- package/dist/cjs/plugins/deploy/platforms/netlify.js +1 -1
- package/dist/cjs/plugins/deploy/platforms/node.js +1 -1
- package/dist/cjs/plugins/deploy/platforms/vercel.js +1 -1
- package/dist/esm/plugins/deploy/dependencies/index.js +20 -28
- package/dist/esm/plugins/deploy/platforms/netlify.js +1 -1
- package/dist/esm/plugins/deploy/platforms/node.js +1 -1
- package/dist/esm/plugins/deploy/platforms/vercel.js +1 -1
- package/dist/esm-node/plugins/deploy/dependencies/index.js +6 -14
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +1 -1
- package/dist/esm-node/plugins/deploy/platforms/node.js +1 -1
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +1 -1
- package/dist/js/modern/analyze/constants.js +15 -0
- package/dist/js/modern/analyze/generateCode.js +179 -0
- package/dist/js/modern/analyze/getBundleEntry.js +75 -0
- package/dist/js/modern/analyze/getClientRoutes.js +219 -0
- package/dist/js/modern/analyze/getFileSystemEntry.js +74 -0
- package/dist/js/modern/analyze/getHtmlTemplate.js +82 -0
- package/dist/js/modern/analyze/getServerRoutes.js +192 -0
- package/dist/js/modern/analyze/index.js +148 -0
- package/dist/js/modern/analyze/isDefaultExportFunction.js +32 -0
- package/dist/js/modern/analyze/makeLegalIdentifier.js +16 -0
- package/dist/js/modern/analyze/templates.js +88 -0
- package/dist/js/modern/analyze/utils.js +92 -0
- package/dist/js/modern/commands/build.js +154 -0
- package/dist/js/modern/commands/deploy.js +5 -0
- package/dist/js/modern/commands/dev.js +95 -0
- package/dist/js/modern/commands/index.js +3 -0
- package/dist/js/modern/commands/inspect.js +69 -0
- package/dist/js/modern/commands/start.js +31 -0
- package/dist/js/modern/exports/server.js +1 -0
- package/dist/js/modern/hooks.js +21 -0
- package/dist/js/modern/index.js +109 -0
- package/dist/js/modern/locale/en.js +35 -0
- package/dist/js/modern/locale/index.js +9 -0
- package/dist/js/modern/locale/zh.js +35 -0
- package/dist/js/modern/utils/config.js +78 -0
- package/dist/js/modern/utils/createCompiler.js +61 -0
- package/dist/js/modern/utils/createServer.js +18 -0
- package/dist/js/modern/utils/getSpecifiedEntries.js +36 -0
- package/dist/js/modern/utils/language.js +5 -0
- package/dist/js/modern/utils/printInstructions.js +11 -0
- package/dist/js/modern/utils/routes.js +15 -0
- package/dist/js/modern/utils/types.js +0 -0
- package/dist/js/node/analyze/constants.js +36 -0
- package/dist/js/node/analyze/generateCode.js +208 -0
- package/dist/js/node/analyze/getBundleEntry.js +89 -0
- package/dist/js/node/analyze/getClientRoutes.js +241 -0
- package/dist/js/node/analyze/getFileSystemEntry.js +90 -0
- package/dist/js/node/analyze/getHtmlTemplate.js +106 -0
- package/dist/js/node/analyze/getServerRoutes.js +208 -0
- package/dist/js/node/analyze/index.js +178 -0
- package/dist/js/node/analyze/isDefaultExportFunction.js +50 -0
- package/dist/js/node/analyze/makeLegalIdentifier.js +24 -0
- package/dist/js/node/analyze/templates.js +106 -0
- package/dist/js/node/analyze/utils.js +113 -0
- package/dist/js/node/commands/build.js +174 -0
- package/dist/js/node/commands/deploy.js +14 -0
- package/dist/js/node/commands/dev.js +120 -0
- package/dist/js/node/commands/index.js +44 -0
- package/dist/js/node/commands/inspect.js +98 -0
- package/dist/js/node/commands/start.js +47 -0
- package/dist/js/node/exports/server.js +13 -0
- package/dist/js/node/hooks.js +39 -0
- package/dist/js/node/index.js +141 -0
- package/dist/js/node/locale/en.js +42 -0
- package/dist/js/node/locale/index.js +20 -0
- package/dist/js/node/locale/zh.js +42 -0
- package/dist/js/node/utils/config.js +103 -0
- package/dist/js/node/utils/createCompiler.js +81 -0
- package/dist/js/node/utils/createServer.js +35 -0
- package/dist/js/node/utils/getSpecifiedEntries.js +46 -0
- package/dist/js/node/utils/language.js +13 -0
- package/dist/js/node/utils/printInstructions.js +22 -0
- package/dist/js/node/utils/routes.js +25 -0
- package/dist/js/node/utils/types.js +0 -0
- package/dist/types/config/initialize/inits.d.ts +1 -1
- package/dist/types/plugins/deploy/dependencies/index.d.ts +2 -1
- package/package.json +5 -5
@@ -0,0 +1,141 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
Object.defineProperty(exports, "defineConfig", {
|
8
|
+
enumerable: true,
|
9
|
+
get: function () {
|
10
|
+
return _core.defineConfig;
|
11
|
+
}
|
12
|
+
});
|
13
|
+
|
14
|
+
var _path = _interopRequireDefault(require("path"));
|
15
|
+
|
16
|
+
var _core = require("@modern-js/core");
|
17
|
+
|
18
|
+
var _pluginJarvis = _interopRequireDefault(require("@modern-js/plugin-jarvis"));
|
19
|
+
|
20
|
+
var _utils = require("@modern-js/utils");
|
21
|
+
|
22
|
+
var _analyze = _interopRequireDefault(require("./analyze"));
|
23
|
+
|
24
|
+
var _hooks = require("./hooks");
|
25
|
+
|
26
|
+
var _locale = require("./locale");
|
27
|
+
|
28
|
+
var _language = require("./utils/language");
|
29
|
+
|
30
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
31
|
+
|
32
|
+
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
|
+
|
34
|
+
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; }
|
35
|
+
|
36
|
+
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; }
|
37
|
+
|
38
|
+
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); }
|
39
|
+
|
40
|
+
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
|
+
|
42
|
+
const upgradeModel = _utils.Import.lazy('@modern-js/upgrade', require);
|
43
|
+
|
44
|
+
var _default = () => ({
|
45
|
+
name: '@modern-js/app-tools',
|
46
|
+
post: ['@modern-js/plugin-analyze', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-router', '@modern-js/plugin-polyfill'],
|
47
|
+
registerHook: _hooks.hooks,
|
48
|
+
usePlugins: [(0, _analyze.default)(), (0, _pluginJarvis.default)()],
|
49
|
+
setup: api => {
|
50
|
+
const locale = (0, _language.getLocaleLanguage)();
|
51
|
+
|
52
|
+
_locale.i18n.changeLanguage({
|
53
|
+
locale
|
54
|
+
});
|
55
|
+
|
56
|
+
return {
|
57
|
+
commands({
|
58
|
+
program
|
59
|
+
}) {
|
60
|
+
program.command('dev').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.dev.describe)).option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.shared.config)).option('-e --entry [entry...]', _locale.i18n.t(_locale.localeKeys.command.dev.entry)).option('--analyze', _locale.i18n.t(_locale.localeKeys.command.shared.analyze)).option('--api-only', _locale.i18n.t(_locale.localeKeys.command.dev.apiOnly)).action(async options => {
|
61
|
+
const {
|
62
|
+
dev
|
63
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/dev")));
|
64
|
+
await dev(api, options);
|
65
|
+
});
|
66
|
+
program.command('build').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.build.describe)).option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.shared.config)).option('--analyze', _locale.i18n.t(_locale.localeKeys.command.shared.analyze)).action(async options => {
|
67
|
+
const {
|
68
|
+
build
|
69
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/build")));
|
70
|
+
await build(api, options); // force exit after build.
|
71
|
+
// eslint-disable-next-line no-process-exit
|
72
|
+
|
73
|
+
process.exit(0);
|
74
|
+
});
|
75
|
+
program.command('start').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.start.describe)).option('--api-only', _locale.i18n.t(_locale.localeKeys.command.dev.apiOnly)).option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.shared.config)).action(async () => {
|
76
|
+
const {
|
77
|
+
start
|
78
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/start")));
|
79
|
+
await start(api);
|
80
|
+
});
|
81
|
+
program.command('deploy').usage('[options]').option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.shared.config)).description(_locale.i18n.t(_locale.localeKeys.command.deploy.describe)).action(async options => {
|
82
|
+
const {
|
83
|
+
build
|
84
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/build")));
|
85
|
+
await build(api);
|
86
|
+
const {
|
87
|
+
deploy
|
88
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/deploy")));
|
89
|
+
await deploy(api, options); // eslint-disable-next-line no-process-exit
|
90
|
+
|
91
|
+
process.exit(0);
|
92
|
+
});
|
93
|
+
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 => {
|
94
|
+
const {
|
95
|
+
MWANewAction
|
96
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/new-action')));
|
97
|
+
await MWANewAction(_objectSpread(_objectSpread({}, options), {}, {
|
98
|
+
locale
|
99
|
+
}));
|
100
|
+
});
|
101
|
+
program.command('inspect').description('inspect internal webpack config').option(`--env <env>`, _locale.i18n.t(_locale.localeKeys.command.inspect.env), 'development').option('--output <output>', _locale.i18n.t(_locale.localeKeys.command.inspect.output), '/').option('--no-console', _locale.i18n.t(_locale.localeKeys.command.inspect.noConsole)).option('--verbose', _locale.i18n.t(_locale.localeKeys.command.inspect.verbose)).option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.shared.config)).action(async options => {
|
102
|
+
const {
|
103
|
+
inspect
|
104
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/inspect")));
|
105
|
+
inspect(api, options);
|
106
|
+
});
|
107
|
+
upgradeModel.defineCommand(program.command('upgrade'));
|
108
|
+
},
|
109
|
+
|
110
|
+
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
111
|
+
async fileChange(e) {
|
112
|
+
const {
|
113
|
+
filename,
|
114
|
+
eventType
|
115
|
+
} = e;
|
116
|
+
const appContext = api.useAppContext();
|
117
|
+
const {
|
118
|
+
appDirectory,
|
119
|
+
srcDirectory
|
120
|
+
} = appContext;
|
121
|
+
|
122
|
+
const absolutePath = _path.default.resolve(appDirectory, filename);
|
123
|
+
|
124
|
+
if (!absolutePath.includes(srcDirectory) && (eventType === 'change' || eventType === 'unlink')) {
|
125
|
+
const {
|
126
|
+
closeServer
|
127
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./utils/createServer")));
|
128
|
+
await closeServer();
|
129
|
+
await _core.cli.restart();
|
130
|
+
}
|
131
|
+
},
|
132
|
+
|
133
|
+
async beforeRestart() {
|
134
|
+
(0, _utils.cleanRequireCache)([require.resolve("./analyze")]);
|
135
|
+
}
|
136
|
+
|
137
|
+
};
|
138
|
+
}
|
139
|
+
});
|
140
|
+
|
141
|
+
exports.default = _default;
|
@@ -0,0 +1,42 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.EN_LOCALE = void 0;
|
7
|
+
const EN_LOCALE = {
|
8
|
+
command: {
|
9
|
+
shared: {
|
10
|
+
analyze: 'analyze bundle size',
|
11
|
+
config: 'specify config file'
|
12
|
+
},
|
13
|
+
dev: {
|
14
|
+
describe: 'start dev server',
|
15
|
+
entry: 'compiler by entry',
|
16
|
+
apiOnly: 'start api server only'
|
17
|
+
},
|
18
|
+
build: {
|
19
|
+
describe: 'build application'
|
20
|
+
},
|
21
|
+
start: {
|
22
|
+
describe: 'start server'
|
23
|
+
},
|
24
|
+
deploy: {
|
25
|
+
describe: 'deploy application'
|
26
|
+
},
|
27
|
+
new: {
|
28
|
+
describe: 'generator runner for MWA project',
|
29
|
+
debug: 'using debug mode to log something',
|
30
|
+
config: 'set default generator config(json string)',
|
31
|
+
distTag: `use specified tag version for it's generator`,
|
32
|
+
registry: 'set npm registry url to run npm command'
|
33
|
+
},
|
34
|
+
inspect: {
|
35
|
+
env: 'specify env mode',
|
36
|
+
output: 'specify inspect content output path',
|
37
|
+
noConsole: 'do not log the result in terminal',
|
38
|
+
verbose: 'show full function definitions in output'
|
39
|
+
}
|
40
|
+
}
|
41
|
+
};
|
42
|
+
exports.EN_LOCALE = EN_LOCALE;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.localeKeys = exports.i18n = void 0;
|
7
|
+
|
8
|
+
var _pluginI18n = require("@modern-js/plugin-i18n");
|
9
|
+
|
10
|
+
var _zh = require("./zh");
|
11
|
+
|
12
|
+
var _en = require("./en");
|
13
|
+
|
14
|
+
const i18n = new _pluginI18n.I18n();
|
15
|
+
exports.i18n = i18n;
|
16
|
+
const localeKeys = i18n.init('zh', {
|
17
|
+
zh: _zh.ZH_LOCALE,
|
18
|
+
en: _en.EN_LOCALE
|
19
|
+
});
|
20
|
+
exports.localeKeys = localeKeys;
|
@@ -0,0 +1,42 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.ZH_LOCALE = void 0;
|
7
|
+
const ZH_LOCALE = {
|
8
|
+
command: {
|
9
|
+
shared: {
|
10
|
+
analyze: '分析构建产物体积,查看各个模块打包后的大小',
|
11
|
+
config: '指定配置文件路径,可以为相对路径或绝对路径'
|
12
|
+
},
|
13
|
+
dev: {
|
14
|
+
describe: '本地开发命令',
|
15
|
+
entry: '指定入口,编译特定的页面',
|
16
|
+
apiOnly: '仅启动 API 接口服务'
|
17
|
+
},
|
18
|
+
build: {
|
19
|
+
describe: '构建应用命令'
|
20
|
+
},
|
21
|
+
start: {
|
22
|
+
describe: '应用启动命令'
|
23
|
+
},
|
24
|
+
deploy: {
|
25
|
+
describe: '部署应用命令'
|
26
|
+
},
|
27
|
+
new: {
|
28
|
+
describe: 'MWA 项目中执行生成器',
|
29
|
+
debug: '开启 Debug 模式,打印调试日志信息',
|
30
|
+
config: '生成器运行默认配置(JSON 字符串)',
|
31
|
+
distTag: '生成器使用特殊的 npm Tag 版本',
|
32
|
+
registry: '生成器运行过程中定制 npm Registry'
|
33
|
+
},
|
34
|
+
inspect: {
|
35
|
+
env: '查看指定环境下的配置',
|
36
|
+
output: '指定在 dist 目录下输出的路径',
|
37
|
+
noConsole: '不在终端中输出完整结果',
|
38
|
+
verbose: '在结果中展示函数的完整内容'
|
39
|
+
}
|
40
|
+
}
|
41
|
+
};
|
42
|
+
exports.ZH_LOCALE = ZH_LOCALE;
|
@@ -0,0 +1,103 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.safeReplacer = exports.emitResolvedConfig = exports.defineServerConfig = exports.buildServerConfig = void 0;
|
7
|
+
|
8
|
+
var path = _interopRequireWildcard(require("path"));
|
9
|
+
|
10
|
+
var _nodeBundleRequire = require("@modern-js/node-bundle-require");
|
11
|
+
|
12
|
+
var _utils = require("@modern-js/utils");
|
13
|
+
|
14
|
+
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); }
|
15
|
+
|
16
|
+
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; }
|
17
|
+
|
18
|
+
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; }
|
19
|
+
|
20
|
+
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; }
|
21
|
+
|
22
|
+
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; }
|
23
|
+
|
24
|
+
const defineServerConfig = config => config;
|
25
|
+
|
26
|
+
exports.defineServerConfig = defineServerConfig;
|
27
|
+
|
28
|
+
const buildServerConfig = async ({
|
29
|
+
appDirectory,
|
30
|
+
distDirectory,
|
31
|
+
configFile,
|
32
|
+
options
|
33
|
+
}) => {
|
34
|
+
const configFilePath = await (0, _utils.getServerConfig)(appDirectory, configFile);
|
35
|
+
|
36
|
+
const getOutputFile = async filepath => path.resolve(distDirectory, `${filepath.replace(new RegExp(_utils.CONFIG_FILE_EXTENSIONS.join('|')), '')}.js`);
|
37
|
+
|
38
|
+
if (configFilePath) {
|
39
|
+
const configHelperFilePath = path.normalize(path.join(distDirectory, './config-helper.js'));
|
40
|
+
const helperCode = `
|
41
|
+
export const defineConfig = (config) => config;
|
42
|
+
`;
|
43
|
+
await _utils.fs.ensureDir(distDirectory);
|
44
|
+
await _utils.fs.writeFile(configHelperFilePath, helperCode);
|
45
|
+
await (0, _nodeBundleRequire.bundle)(configFilePath, _objectSpread(_objectSpread({}, options), {}, {
|
46
|
+
getOutputFile,
|
47
|
+
esbuildPlugins: [{
|
48
|
+
name: 'native-build-config',
|
49
|
+
|
50
|
+
setup(ctx) {
|
51
|
+
ctx.onResolve({
|
52
|
+
filter: /app-tools\/server/
|
53
|
+
}, () => {
|
54
|
+
return {
|
55
|
+
path: configHelperFilePath
|
56
|
+
};
|
57
|
+
});
|
58
|
+
}
|
59
|
+
|
60
|
+
}]
|
61
|
+
}));
|
62
|
+
}
|
63
|
+
};
|
64
|
+
/**
|
65
|
+
*
|
66
|
+
* 处理循环引用的 replacer
|
67
|
+
*/
|
68
|
+
|
69
|
+
|
70
|
+
exports.buildServerConfig = buildServerConfig;
|
71
|
+
|
72
|
+
const safeReplacer = () => {
|
73
|
+
const cache = [];
|
74
|
+
const keyCache = [];
|
75
|
+
return function (key, value) {
|
76
|
+
if (typeof value === 'object' && value !== null) {
|
77
|
+
const index = cache.indexOf(value);
|
78
|
+
|
79
|
+
if (index !== -1) {
|
80
|
+
return `[Circular ${keyCache[index]}]`;
|
81
|
+
}
|
82
|
+
|
83
|
+
cache.push(value);
|
84
|
+
keyCache.push(key || 'root');
|
85
|
+
}
|
86
|
+
|
87
|
+
return value;
|
88
|
+
};
|
89
|
+
};
|
90
|
+
|
91
|
+
exports.safeReplacer = safeReplacer;
|
92
|
+
|
93
|
+
const emitResolvedConfig = async (appDirectory, resolvedConfig) => {
|
94
|
+
var _resolvedConfig$outpu;
|
95
|
+
|
96
|
+
const outputPath = path.join(appDirectory, (resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$outpu = resolvedConfig.output) === null || _resolvedConfig$outpu === void 0 ? void 0 : _resolvedConfig$outpu.path) || './dist', _utils.OUTPUT_CONFIG_FILE);
|
97
|
+
await _utils.fs.writeJSON(outputPath, resolvedConfig, {
|
98
|
+
spaces: 2,
|
99
|
+
replacer: safeReplacer()
|
100
|
+
});
|
101
|
+
};
|
102
|
+
|
103
|
+
exports.emitResolvedConfig = emitResolvedConfig;
|
@@ -0,0 +1,81 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.createCompiler = void 0;
|
7
|
+
|
8
|
+
var _webpack = require("@modern-js/webpack");
|
9
|
+
|
10
|
+
var _utils = require("@modern-js/utils");
|
11
|
+
|
12
|
+
var _printInstructions = require("./printInstructions");
|
13
|
+
|
14
|
+
const createCompiler = async ({
|
15
|
+
api,
|
16
|
+
webpackConfigs,
|
17
|
+
// TODO: params
|
18
|
+
userConfig,
|
19
|
+
appContext
|
20
|
+
}) => {
|
21
|
+
try {
|
22
|
+
const hookRunners = api.useHookRunners();
|
23
|
+
await hookRunners.beforeCreateCompiler({
|
24
|
+
webpackConfigs
|
25
|
+
});
|
26
|
+
const compiler = (0, _webpack.webpack)(webpackConfigs);
|
27
|
+
await hookRunners.afterCreateCompiler({
|
28
|
+
compiler
|
29
|
+
});
|
30
|
+
let isFirstCompile = true;
|
31
|
+
compiler.hooks.invalid.tap('invalid', () => {
|
32
|
+
(0, _utils.clearConsole)();
|
33
|
+
|
34
|
+
_utils.logger.log('Compiling...');
|
35
|
+
});
|
36
|
+
compiler.hooks.done.tap('done', async stats => {
|
37
|
+
const statsData = stats.toJson({
|
38
|
+
preset: 'errors-warnings'
|
39
|
+
});
|
40
|
+
const {
|
41
|
+
errors,
|
42
|
+
warnings
|
43
|
+
} = (0, _utils.formatWebpackMessages)(statsData);
|
44
|
+
|
45
|
+
if (errors.length) {
|
46
|
+
_utils.logger.log(_utils.chalk.red(`Failed to compile.\n`));
|
47
|
+
|
48
|
+
_utils.logger.log(errors.join('\n\n'));
|
49
|
+
|
50
|
+
_utils.logger.log();
|
51
|
+
} else if (process.stdout.isTTY || isFirstCompile) {
|
52
|
+
await hookRunners.afterDev();
|
53
|
+
|
54
|
+
if (warnings.length) {
|
55
|
+
_utils.logger.log(_utils.chalk.yellow(`Compiled with warnings.\n`));
|
56
|
+
|
57
|
+
_utils.logger.log(warnings.join('\n\n'));
|
58
|
+
|
59
|
+
_utils.logger.log();
|
60
|
+
}
|
61
|
+
|
62
|
+
await (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
|
63
|
+
}
|
64
|
+
|
65
|
+
isFirstCompile = false;
|
66
|
+
});
|
67
|
+
return compiler;
|
68
|
+
} catch (err) {
|
69
|
+
_utils.logger.log(_utils.chalk.red(`Failed to compile.`));
|
70
|
+
|
71
|
+
_utils.logger.log();
|
72
|
+
|
73
|
+
_utils.logger.log(err); // FIXME: 这里最好抛出异常,执行 process.exit 的地方尽可能少或者控制在几个统一的地方比较合适
|
74
|
+
// eslint-disable-next-line no-process-exit
|
75
|
+
|
76
|
+
|
77
|
+
process.exit(1);
|
78
|
+
}
|
79
|
+
};
|
80
|
+
|
81
|
+
exports.createCompiler = createCompiler;
|
@@ -0,0 +1,35 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.getServer = exports.createServer = exports.closeServer = void 0;
|
7
|
+
|
8
|
+
var _server = require("@modern-js/server");
|
9
|
+
|
10
|
+
let server = null;
|
11
|
+
|
12
|
+
const getServer = () => server;
|
13
|
+
|
14
|
+
exports.getServer = getServer;
|
15
|
+
|
16
|
+
const closeServer = async () => {
|
17
|
+
if (server) {
|
18
|
+
await server.close();
|
19
|
+
server = null;
|
20
|
+
}
|
21
|
+
};
|
22
|
+
|
23
|
+
exports.closeServer = closeServer;
|
24
|
+
|
25
|
+
const createServer = async options => {
|
26
|
+
if (server) {
|
27
|
+
await server.close();
|
28
|
+
}
|
29
|
+
|
30
|
+
server = new _server.Server(options);
|
31
|
+
const app = await server.init();
|
32
|
+
return app;
|
33
|
+
};
|
34
|
+
|
35
|
+
exports.createServer = createServer;
|
@@ -0,0 +1,46 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.getSpecifiedEntries = void 0;
|
7
|
+
|
8
|
+
var _utils = require("@modern-js/utils");
|
9
|
+
|
10
|
+
const getSpecifiedEntries = async (entry, entrypoints) => {
|
11
|
+
const entryNames = entrypoints.map(e => e.entryName);
|
12
|
+
|
13
|
+
if (!entry) {
|
14
|
+
return entryNames;
|
15
|
+
}
|
16
|
+
|
17
|
+
if (typeof entry === 'boolean') {
|
18
|
+
const {
|
19
|
+
selected
|
20
|
+
} = await _utils.inquirer.prompt([{
|
21
|
+
type: 'checkbox',
|
22
|
+
name: 'selected',
|
23
|
+
choices: entryNames,
|
24
|
+
message: '请选择需要构建的入口',
|
25
|
+
|
26
|
+
validate(answer) {
|
27
|
+
if (answer.length < 1) {
|
28
|
+
return 'You must choose at least one topping.';
|
29
|
+
}
|
30
|
+
|
31
|
+
return true;
|
32
|
+
}
|
33
|
+
|
34
|
+
}]);
|
35
|
+
return selected;
|
36
|
+
}
|
37
|
+
|
38
|
+
entry.forEach(name => {
|
39
|
+
if (!entryNames.includes(name)) {
|
40
|
+
throw new Error(`can not found entry ${name}, compiler entry should in ${entryNames.join(', ')}`);
|
41
|
+
}
|
42
|
+
});
|
43
|
+
return entry;
|
44
|
+
};
|
45
|
+
|
46
|
+
exports.getSpecifiedEntries = getSpecifiedEntries;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.getLocaleLanguage = getLocaleLanguage;
|
7
|
+
|
8
|
+
var _languageDetector = require("@modern-js/plugin-i18n/language-detector");
|
9
|
+
|
10
|
+
function getLocaleLanguage() {
|
11
|
+
const detector = new _languageDetector.I18CLILanguageDetector();
|
12
|
+
return detector.detect();
|
13
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.printInstructions = void 0;
|
7
|
+
|
8
|
+
var _utils = require("@modern-js/utils");
|
9
|
+
|
10
|
+
const printInstructions = async (hookRunners, appContext, config) => {
|
11
|
+
const message = (0, _utils.prettyInstructions)(appContext, config); // call beforePrintInstructions hook.
|
12
|
+
|
13
|
+
const {
|
14
|
+
instructions
|
15
|
+
} = await hookRunners.beforePrintInstructions({
|
16
|
+
instructions: message
|
17
|
+
});
|
18
|
+
|
19
|
+
_utils.logger.log(instructions);
|
20
|
+
};
|
21
|
+
|
22
|
+
exports.printInstructions = printInstructions;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.generateRoutes = void 0;
|
7
|
+
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
9
|
+
|
10
|
+
var _utils = require("@modern-js/utils");
|
11
|
+
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
|
+
|
14
|
+
const generateRoutes = async appContext => {
|
15
|
+
const {
|
16
|
+
serverRoutes,
|
17
|
+
distDirectory
|
18
|
+
} = appContext;
|
19
|
+
const output = JSON.stringify({
|
20
|
+
routes: serverRoutes
|
21
|
+
}, null, 2);
|
22
|
+
await _utils.fs.outputFile(_path.default.join(distDirectory, _utils.ROUTE_SPEC_FILE), output);
|
23
|
+
};
|
24
|
+
|
25
|
+
exports.generateRoutes = generateRoutes;
|
File without changes
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import { AppNormalizedConfig, IAppContext } from '../../types';
|
2
2
|
export declare function initHtmlConfig(config: AppNormalizedConfig<'shared'>, appContext: IAppContext): AppNormalizedConfig<'shared'>['html'];
|
3
3
|
export declare function initSourceConfig(config: AppNormalizedConfig<'shared'>, appContext: IAppContext, bundler: 'webpack' | 'rspack'): void;
|
4
|
-
export declare function createBuilderModuleScope(config: AppNormalizedConfig<'webpack'>):
|
4
|
+
export declare function createBuilderModuleScope(config: AppNormalizedConfig<'webpack'>): any;
|
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
import type { PackageJson } from 'pkg-types';
|
2
|
+
export declare const handleDependencies: (appDir: string, serverRootDir: string, includeEntries: string[], entryFilter?: ((filePath: string) => boolean) | undefined, modifyPackageJson?: ((pkgJson: PackageJson) => PackageJson) | undefined) => Promise<void>;
|
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.53.
|
18
|
+
"version": "2.53.1-alpha.1",
|
19
19
|
"jsnext:source": "./src/index.ts",
|
20
20
|
"types": "./dist/types/index.d.ts",
|
21
21
|
"main": "./dist/cjs/index.js",
|
@@ -82,18 +82,18 @@
|
|
82
82
|
"std-env": "^3.7.0",
|
83
83
|
"@modern-js/core": "2.53.0",
|
84
84
|
"@modern-js/node-bundle-require": "2.53.0",
|
85
|
-
"@modern-js/plugin-i18n": "2.53.0",
|
86
85
|
"@modern-js/plugin": "2.53.0",
|
87
86
|
"@modern-js/plugin-data-loader": "2.53.0",
|
88
87
|
"@modern-js/prod-server": "2.53.0",
|
89
88
|
"@modern-js/plugin-lint": "2.53.0",
|
90
|
-
"@modern-js/
|
89
|
+
"@modern-js/plugin-i18n": "2.53.0",
|
91
90
|
"@modern-js/server": "2.53.0",
|
92
91
|
"@modern-js/server-utils": "2.53.0",
|
92
|
+
"@modern-js/rsbuild-plugin-esbuild": "2.53.0",
|
93
93
|
"@modern-js/types": "2.53.0",
|
94
|
+
"@modern-js/server-core": "2.53.0",
|
94
95
|
"@modern-js/uni-builder": "2.53.0",
|
95
|
-
"@modern-js/utils": "2.53.0"
|
96
|
-
"@modern-js/server-core": "2.53.0"
|
96
|
+
"@modern-js/utils": "2.53.0"
|
97
97
|
},
|
98
98
|
"devDependencies": {
|
99
99
|
"@rsbuild/plugin-swc": "0.7.3",
|