@umijs/preset-umi 4.0.0-beta.16 → 4.0.0-beta.17
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/dist/commands/dev/dev.js +4 -3
- package/dist/commands/generate/prettier.js +35 -3
- package/dist/features/appData/appData.js +27 -0
- package/dist/features/configPlugins/configPlugins.js +3 -0
- package/dist/features/configPlugins/schema.js +4 -0
- package/dist/features/esmi/esmi.js +3 -11
- package/dist/features/mock/getMockData.js +5 -1
- package/dist/features/polyfill/polyfill.js +27 -15
- package/dist/features/tmpFiles/routes.js +20 -1
- package/dist/features/tmpFiles/tmpFiles.js +12 -2
- package/dist/features/vite/vite.d.ts +3 -0
- package/dist/features/vite/vite.js +34 -0
- package/dist/index.js +1 -0
- package/dist/libs/scan.js +19 -4
- package/dist/registerMethods.js +1 -1
- package/dist/types.d.ts +3 -0
- package/dist/utils/transformIEAR.js +2 -1
- package/package.json +10 -10
package/dist/commands/dev/dev.js
CHANGED
|
@@ -56,7 +56,7 @@ umi dev
|
|
|
56
56
|
PORT=8888 umi dev
|
|
57
57
|
`,
|
|
58
58
|
fn() {
|
|
59
|
-
var _a;
|
|
59
|
+
var _a, _b;
|
|
60
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
61
|
const enableVite = api.args.vite;
|
|
62
62
|
// clear tmp except cache
|
|
@@ -102,9 +102,10 @@ PORT=8888 umi dev
|
|
|
102
102
|
key: 'addTmpGenerateWatcherPaths',
|
|
103
103
|
initialValue: [
|
|
104
104
|
absPagesPath,
|
|
105
|
+
!api.config.routes && ((_a = api.config.conventionRoutes) === null || _a === void 0 ? void 0 : _a.base),
|
|
105
106
|
(0, path_1.join)(absSrcPath, 'layouts'),
|
|
106
107
|
...(0, watch_1.expandJSPaths)((0, path_1.join)(absSrcPath, 'app')),
|
|
107
|
-
],
|
|
108
|
+
].filter(Boolean),
|
|
108
109
|
});
|
|
109
110
|
utils_1.lodash.uniq(watcherPaths.map(utils_1.winPath)).forEach((p) => {
|
|
110
111
|
(0, watch_1.watch)({
|
|
@@ -238,7 +239,7 @@ PORT=8888 umi dev
|
|
|
238
239
|
key: 'onDevCompileDone',
|
|
239
240
|
args: opts,
|
|
240
241
|
});
|
|
241
|
-
}, mfsuWithESBuild: (
|
|
242
|
+
}, mfsuWithESBuild: (_b = api.config.mfsu) === null || _b === void 0 ? void 0 : _b.esbuild, cache: {
|
|
242
243
|
buildDependencies: [
|
|
243
244
|
api.pkgPath,
|
|
244
245
|
api.service.configManager.mainConfigFile || '',
|
|
@@ -8,8 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
const core_1 = require("@umijs/core");
|
|
16
|
+
const utils_1 = require("@umijs/utils");
|
|
17
|
+
const assert_1 = __importDefault(require("assert"));
|
|
13
18
|
const fs_1 = require("fs");
|
|
14
19
|
const path_1 = require("path");
|
|
15
20
|
exports.default = (api) => {
|
|
@@ -23,9 +28,36 @@ exports.default = (api) => {
|
|
|
23
28
|
// 存在 .prettierrc,不开启
|
|
24
29
|
return !(0, fs_1.existsSync)((0, path_1.join)(api.paths.cwd, '.prettierrc'));
|
|
25
30
|
},
|
|
26
|
-
fn: (
|
|
27
|
-
//
|
|
28
|
-
|
|
31
|
+
fn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
// 1、修改 package.json,加上 prettier 和插件
|
|
33
|
+
api.pkg.devDependencies = Object.assign(Object.assign({}, api.pkg.devDependencies), { prettier: '^2', 'prettier-plugin-organize-imports': '^2', 'prettier-plugin-packagejson': '^2' });
|
|
34
|
+
(0, fs_1.writeFileSync)(api.pkgPath, JSON.stringify(api.pkg, null, 2));
|
|
35
|
+
utils_1.logger.info('Write package.json');
|
|
36
|
+
// 2、添加 .prettierrc 和 .prettierignore
|
|
37
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(api.cwd, '.prettierrc'), `
|
|
38
|
+
{
|
|
39
|
+
"printWidth": 80,
|
|
40
|
+
"singleQuote": true,
|
|
41
|
+
"trailingComma": "all",
|
|
42
|
+
"proseWrap": "never",
|
|
43
|
+
"overrides": [{ "files": ".prettierrc", "options": { "parser": "json" } }],
|
|
44
|
+
"plugins": ["prettier-plugin-organize-imports", "prettier-plugin-packagejson"]
|
|
45
|
+
}
|
|
46
|
+
`.trimLeft());
|
|
47
|
+
utils_1.logger.info('Write .prettierrc');
|
|
48
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(api.cwd, '.prettierignore'), `
|
|
49
|
+
node_modules
|
|
50
|
+
.umi
|
|
51
|
+
.umi-production
|
|
52
|
+
`.trimLeft());
|
|
53
|
+
utils_1.logger.info('Write .prettierignore');
|
|
54
|
+
// 3、执行 npm install
|
|
55
|
+
const npmClient = api.userConfig.npmClient;
|
|
56
|
+
(0, assert_1.default)(npmClient, `npmClient is required in your config.`);
|
|
57
|
+
(0, utils_1.installWithNpmClient)({
|
|
58
|
+
npmClient,
|
|
59
|
+
});
|
|
60
|
+
utils_1.logger.info(`Install dependencies with ${npmClient}`);
|
|
29
61
|
}),
|
|
30
62
|
});
|
|
31
63
|
};
|
|
@@ -14,6 +14,7 @@ const utils_1 = require("@umijs/utils");
|
|
|
14
14
|
const fs_1 = require("fs");
|
|
15
15
|
const path_1 = require("path");
|
|
16
16
|
const watch_1 = require("../../commands/dev/watch");
|
|
17
|
+
const scan_1 = require("../../libs/scan");
|
|
17
18
|
const routes_1 = require("../tmpFiles/routes");
|
|
18
19
|
exports.default = (api) => {
|
|
19
20
|
api.modifyAppData((memo) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -29,6 +30,7 @@ exports.default = (api) => {
|
|
|
29
30
|
version: require((0, path_1.join)(api.config.alias.react, 'package.json')).version,
|
|
30
31
|
};
|
|
31
32
|
memo.appJS = yield getAppJsInfo();
|
|
33
|
+
memo.vite = api.args.vite ? {} : undefined;
|
|
32
34
|
return memo;
|
|
33
35
|
}));
|
|
34
36
|
// Execute earliest, so that other onGenerateFiles can get it
|
|
@@ -43,6 +45,31 @@ exports.default = (api) => {
|
|
|
43
45
|
},
|
|
44
46
|
stage: Number.NEGATIVE_INFINITY,
|
|
45
47
|
});
|
|
48
|
+
// used in esmi and vite
|
|
49
|
+
api.register({
|
|
50
|
+
key: 'updateAppDataDeps',
|
|
51
|
+
fn() {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const resolver = (0, scan_1.createResolver)({
|
|
54
|
+
alias: api.config.alias,
|
|
55
|
+
});
|
|
56
|
+
api.appData.deps = yield (0, scan_1.scan)({
|
|
57
|
+
entry: (0, path_1.join)(api.paths.absTmpPath, 'umi.ts'),
|
|
58
|
+
externals: api.config.externals,
|
|
59
|
+
resolver,
|
|
60
|
+
});
|
|
61
|
+
// FIXME: force include react & react-dom
|
|
62
|
+
if (api.appData.deps['react']) {
|
|
63
|
+
api.appData.deps['react'].version = api.appData.react.version;
|
|
64
|
+
}
|
|
65
|
+
api.appData.deps['react-dom'] = {
|
|
66
|
+
version: api.appData.react.version,
|
|
67
|
+
matches: ['react-dom'],
|
|
68
|
+
subpaths: [],
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
});
|
|
46
73
|
function getAppJsInfo() {
|
|
47
74
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
75
|
for (const path of (0, watch_1.expandJSPaths)((0, path_1.join)(api.paths.absSrcPath, 'app'))) {
|
|
@@ -5,6 +5,10 @@ const utils_1 = require("@umijs/utils");
|
|
|
5
5
|
function getSchemas() {
|
|
6
6
|
return {
|
|
7
7
|
base: (Joi) => Joi.string(),
|
|
8
|
+
conventionRoutes: (Joi) => Joi.object({
|
|
9
|
+
exclude: Joi.array().items(Joi.any()),
|
|
10
|
+
base: Joi.string(),
|
|
11
|
+
}),
|
|
8
12
|
favicon: (Joi) => Joi.string(),
|
|
9
13
|
headScripts: (Joi) => Joi.array(),
|
|
10
14
|
history: (Joi) => Joi.object({
|
|
@@ -140,20 +140,12 @@ exports.default = (api) => {
|
|
|
140
140
|
return __awaiter(this, void 0, void 0, function* () {
|
|
141
141
|
// scan and module graph
|
|
142
142
|
// TODO: module graph
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
resolver,
|
|
143
|
+
yield api.applyPlugins({
|
|
144
|
+
key: 'updateAppDataDeps',
|
|
145
|
+
type: api.ApplyPluginsType.event,
|
|
147
146
|
});
|
|
148
147
|
// skip umi by default
|
|
149
148
|
delete api.appData.deps['umi'];
|
|
150
|
-
// FIXME: force include react & react-dom
|
|
151
|
-
api.appData.deps['react'].version = api.appData.react.version;
|
|
152
|
-
api.appData.deps['react-dom'] = {
|
|
153
|
-
version: api.appData.react.version,
|
|
154
|
-
matches: ['react-dom'],
|
|
155
|
-
subpaths: [],
|
|
156
|
-
};
|
|
157
149
|
const data = generatePkgData(api);
|
|
158
150
|
const deps = data.pkgInfo.exports.reduce((r, exp) => r.concat(exp.deps.map((dep) => dep.name)), []);
|
|
159
151
|
const hasNewDep = deps.some((i) => !importmap.imports[i]);
|
|
@@ -13,6 +13,10 @@ function getMockData(opts) {
|
|
|
13
13
|
implementor: esbuild_1.default,
|
|
14
14
|
});
|
|
15
15
|
utils_1.register.clearFiles();
|
|
16
|
+
function normalizeMockFile(file) {
|
|
17
|
+
const cwd = opts.cwd.endsWith('/') ? opts.cwd : `${opts.cwd}/`;
|
|
18
|
+
return utils_1.chalk.yellow(file.replace(cwd, ''));
|
|
19
|
+
}
|
|
16
20
|
const ret = [constants_1.MOCK_FILE_GLOB, ...(opts.mockConfig.include || [])]
|
|
17
21
|
.reduce((memo, pattern) => {
|
|
18
22
|
memo.push(...utils_1.glob.sync(pattern, { cwd: opts.cwd, ignore: ['**/*.d.ts'] }));
|
|
@@ -32,7 +36,7 @@ function getMockData(opts) {
|
|
|
32
36
|
utils_1.lodash.isPlainObject(mock.handler) ||
|
|
33
37
|
typeof mock.handler === 'function', `Mock handler must be function or array or object, but got ${typeof mock.handler} for ${mock.method} in ${mock.file}`);
|
|
34
38
|
if (memo[id]) {
|
|
35
|
-
utils_1.logger.warn(`${id} is duplicated in ${mockFile} and ${memo[id].file}`);
|
|
39
|
+
utils_1.logger.warn(`${id} is duplicated in ${normalizeMockFile(mockFile)} and ${normalizeMockFile(memo[id].file)}`);
|
|
36
40
|
}
|
|
37
41
|
memo[id] = mock;
|
|
38
42
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@umijs/bundler-utils/compiled/babel/core");
|
|
3
4
|
const path_1 = require("path");
|
|
4
5
|
exports.default = (api) => {
|
|
5
6
|
api.describe({
|
|
@@ -16,28 +17,39 @@ exports.default = (api) => {
|
|
|
16
17
|
},
|
|
17
18
|
});
|
|
18
19
|
api.onGenerateFiles(() => {
|
|
19
|
-
var _a;
|
|
20
|
+
var _a, _b;
|
|
21
|
+
const coreJsImports = ((_a = api.config.polyfill) === null || _a === void 0 ? void 0 : _a.imports)
|
|
22
|
+
? (_b = api.config.polyfill) === null || _b === void 0 ? void 0 : _b.imports.map((item) => `import '${item}';`).join('\n')
|
|
23
|
+
: `import 'core-js';`;
|
|
24
|
+
const { code } = (0, core_1.transform)(`
|
|
25
|
+
${coreJsImports}
|
|
26
|
+
import 'regenerator-runtime/runtime';
|
|
27
|
+
export {};
|
|
28
|
+
`, {
|
|
29
|
+
filename: 'polyfill.ts',
|
|
30
|
+
presets: [
|
|
31
|
+
[
|
|
32
|
+
require.resolve('@umijs/bundler-utils/compiled/babel/preset-env'),
|
|
33
|
+
{
|
|
34
|
+
useBuiltIns: 'entry',
|
|
35
|
+
corejs: '3',
|
|
36
|
+
modules: false,
|
|
37
|
+
targets: api.config.targets,
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
],
|
|
41
|
+
plugins: [
|
|
42
|
+
require.resolve('@umijs/babel-preset-umi/dist/plugins/lockCoreJS'),
|
|
43
|
+
],
|
|
44
|
+
});
|
|
20
45
|
api.writeTmpFile({
|
|
21
46
|
path: 'core/polyfill.ts',
|
|
22
47
|
noPluginDir: true,
|
|
23
|
-
|
|
24
|
-
{{#imports}}
|
|
25
|
-
import '{{{ . }}}';
|
|
26
|
-
{{/imports}}
|
|
27
|
-
{{^imports}}
|
|
28
|
-
import 'core-js';
|
|
29
|
-
{{/imports}}
|
|
30
|
-
import 'regenerator-runtime/runtime';
|
|
31
|
-
export {};
|
|
32
|
-
`,
|
|
33
|
-
context: {
|
|
34
|
-
imports: ((_a = api.config.polyfill) === null || _a === void 0 ? void 0 : _a.imports) || [],
|
|
35
|
-
},
|
|
48
|
+
content: code,
|
|
36
49
|
});
|
|
37
50
|
});
|
|
38
51
|
api.addPolyfillImports(() => [{ source: `./core/polyfill` }]);
|
|
39
52
|
api.modifyConfig((memo) => {
|
|
40
|
-
memo.alias['core-js'] = (0, path_1.dirname)(require.resolve('core-js/package'));
|
|
41
53
|
memo.alias['regenerator-runtime'] = (0, path_1.dirname)(require.resolve('regenerator-runtime/package'));
|
|
42
54
|
return memo;
|
|
43
55
|
});
|
|
@@ -16,6 +16,7 @@ const fs_1 = require("fs");
|
|
|
16
16
|
const path_1 = require("path");
|
|
17
17
|
// get route config
|
|
18
18
|
function getRoutes(opts) {
|
|
19
|
+
var _a, _b, _c;
|
|
19
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
21
|
let routes = null;
|
|
21
22
|
if (opts.api.config.routes) {
|
|
@@ -25,10 +26,19 @@ function getRoutes(opts) {
|
|
|
25
26
|
}
|
|
26
27
|
else {
|
|
27
28
|
routes = (0, core_1.getConventionRoutes)({
|
|
28
|
-
base: opts.api.paths.absPagesPath,
|
|
29
|
+
base: ((_a = opts.api.config.conventionRoutes) === null || _a === void 0 ? void 0 : _a.base) || opts.api.paths.absPagesPath,
|
|
30
|
+
exclude: (_b = opts.api.config.conventionRoutes) === null || _b === void 0 ? void 0 : _b.exclude,
|
|
29
31
|
prefix: '',
|
|
30
32
|
});
|
|
31
33
|
}
|
|
34
|
+
for (const id of Object.keys(routes)) {
|
|
35
|
+
// TODO: cache for performance
|
|
36
|
+
const file = (0, path_1.isAbsolute)(routes[id].file)
|
|
37
|
+
? routes[id].file
|
|
38
|
+
: (0, path_1.join)(((_c = opts.api.config.conventionRoutes) === null || _c === void 0 ? void 0 : _c.base) || opts.api.paths.absPagesPath, routes[id].file);
|
|
39
|
+
routes[id].__content = (0, fs_1.readFileSync)(file, 'utf-8');
|
|
40
|
+
}
|
|
41
|
+
// layout routes
|
|
32
42
|
const absLayoutPath = (0, path_1.join)(opts.api.paths.absSrcPath, 'layouts/index.tsx');
|
|
33
43
|
const layouts = yield opts.api.applyPlugins({
|
|
34
44
|
key: 'addLayouts',
|
|
@@ -52,6 +62,15 @@ function getRoutes(opts) {
|
|
|
52
62
|
test: layout.test,
|
|
53
63
|
});
|
|
54
64
|
}
|
|
65
|
+
// patch routes
|
|
66
|
+
for (const id of Object.keys(routes)) {
|
|
67
|
+
yield opts.api.applyPlugins({
|
|
68
|
+
key: 'onPatchRoute',
|
|
69
|
+
args: {
|
|
70
|
+
route: routes[id],
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
55
74
|
routes = yield opts.api.applyPlugins({
|
|
56
75
|
key: 'modifyRoutes',
|
|
57
76
|
initialValue: routes,
|
|
@@ -26,6 +26,7 @@ exports.default = (api) => {
|
|
|
26
26
|
},
|
|
27
27
|
});
|
|
28
28
|
api.onGenerateFiles((opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
var _a;
|
|
29
30
|
const rendererPath = yield api.applyPlugins({
|
|
30
31
|
key: 'modifyRendererPath',
|
|
31
32
|
initialValue: (0, path_1.dirname)(require.resolve('@umijs/renderer-react/package.json')),
|
|
@@ -85,13 +86,22 @@ export default function EmptyRoute() {
|
|
|
85
86
|
}
|
|
86
87
|
const hasSrc = api.appData.hasSrcDir;
|
|
87
88
|
// @/pages/
|
|
88
|
-
const
|
|
89
|
+
const pages = (0, path_1.basename)(((_a = api.config.conventionRoutes) === null || _a === void 0 ? void 0 : _a.base) || api.paths.absPagesPath);
|
|
90
|
+
const prefix = hasSrc ? `../../../src/${pages}/` : `../../${pages}/`;
|
|
91
|
+
const clonedRoutes = utils_1.lodash.cloneDeep(routes);
|
|
92
|
+
for (const id of Object.keys(clonedRoutes)) {
|
|
93
|
+
for (const key of Object.keys(clonedRoutes[id])) {
|
|
94
|
+
if (key.startsWith('__')) {
|
|
95
|
+
delete clonedRoutes[id][key];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
89
99
|
api.writeTmpFile({
|
|
90
100
|
noPluginDir: true,
|
|
91
101
|
path: 'core/route.tsx',
|
|
92
102
|
tplPath: (0, path_1.join)(constants_1.TEMPLATES_DIR, 'route.tpl'),
|
|
93
103
|
context: {
|
|
94
|
-
routes: JSON.stringify(
|
|
104
|
+
routes: JSON.stringify(clonedRoutes),
|
|
95
105
|
routeComponents: yield (0, routes_1.getRouteComponents)({ routes, prefix }),
|
|
96
106
|
},
|
|
97
107
|
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.default = (api) => {
|
|
13
|
+
// scan deps into api.appData by default for vite mode
|
|
14
|
+
api.register({
|
|
15
|
+
key: 'onBeforeCompiler',
|
|
16
|
+
stage: Number.POSITIVE_INFINITY,
|
|
17
|
+
fn() {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
yield api.applyPlugins({
|
|
20
|
+
key: 'updateAppDataDeps',
|
|
21
|
+
type: api.ApplyPluginsType.event,
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
// include extra monorepo package deps for vite pre-bundle
|
|
27
|
+
api.modifyViteConfig((memo) => {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
memo.optimizeDeps = Object.assign(Object.assign({}, (memo.optimizeDeps || {})), { include: (_b = (_a = memo.optimizeDeps) === null || _a === void 0 ? void 0 : _a.include) === null || _b === void 0 ? void 0 : _b.concat(Object.values(api.appData.deps)
|
|
30
|
+
.map(({ matches }) => matches[0])
|
|
31
|
+
.filter((item) => (item === null || item === void 0 ? void 0 : item.startsWith('@fs')) && !(item === null || item === void 0 ? void 0 : item.includes('node_modules')))) });
|
|
32
|
+
return memo;
|
|
33
|
+
});
|
|
34
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ exports.default = () => {
|
|
|
17
17
|
require.resolve('./features/tmpFiles/tmpFiles'),
|
|
18
18
|
require.resolve('./features/transform/transform'),
|
|
19
19
|
require.resolve('./features/lowImport/lowImport'),
|
|
20
|
+
require.resolve('./features/vite/vite'),
|
|
20
21
|
// commands
|
|
21
22
|
require.resolve('./commands/build'),
|
|
22
23
|
require.resolve('./commands/config/config'),
|
package/dist/libs/scan.js
CHANGED
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.scan = exports.createResolver = exports.getContent = exports.scanContent = void 0;
|
|
16
|
+
const bundler_utils_1 = require("@umijs/bundler-utils");
|
|
16
17
|
const es_module_lexer_1 = require("@umijs/bundler-utils/compiled/es-module-lexer");
|
|
17
18
|
const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
|
|
18
19
|
const utils_1 = require("@umijs/utils");
|
|
@@ -31,7 +32,22 @@ function scanContent(opts) {
|
|
|
31
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
33
|
yield es_module_lexer_1.init;
|
|
33
34
|
const [imports] = (0, es_module_lexer_1.parse)(opts.content);
|
|
34
|
-
const deps = imports
|
|
35
|
+
const deps = imports
|
|
36
|
+
.filter(
|
|
37
|
+
// exclude all type-only deps
|
|
38
|
+
(imp) => {
|
|
39
|
+
const stmt = opts.content.slice(imp.ss, imp.se);
|
|
40
|
+
return (
|
|
41
|
+
// skip dynamicImport
|
|
42
|
+
imp.d > -1 ||
|
|
43
|
+
// import a from or import a,
|
|
44
|
+
/^import\s+[a-zA-Z_$][\w_$]*(\s+from|\s*,)/.test(stmt) ||
|
|
45
|
+
// export a from or export *
|
|
46
|
+
/^export\s+([a-zA-Z_$][\w_$]*\s+from|\*)/.test(stmt) ||
|
|
47
|
+
// { a, type b } or { type a, b }
|
|
48
|
+
/(?<!type\s+){(\s*(?!type)[a-zA-Z_$]|.*,\s*(?!type)[a-zA-Z_$])/.test(stmt));
|
|
49
|
+
})
|
|
50
|
+
.map((imp) => {
|
|
35
51
|
let importType = ImportType.import;
|
|
36
52
|
if (imp.d > -1)
|
|
37
53
|
importType = ImportType.dynamicImport;
|
|
@@ -94,13 +110,12 @@ function scan(opts) {
|
|
|
94
110
|
cache.set(depPath, deps);
|
|
95
111
|
for (const dep of deps) {
|
|
96
112
|
const resolved = yield opts.resolver.resolve((0, path_1.dirname)(depPath), dep.url);
|
|
97
|
-
if (
|
|
98
|
-
resolved.includes('umi-next/packages')) {
|
|
113
|
+
if ((0, bundler_utils_1.isDepPath)(resolved)) {
|
|
99
114
|
const pkgPath = utils_1.pkgUp.sync({ cwd: resolved });
|
|
100
115
|
(0, assert_1.default)(pkgPath, `package.json for found for ${resolved}`);
|
|
101
116
|
const pkg = require(pkgPath);
|
|
102
117
|
const entryResolved = yield opts.resolver
|
|
103
|
-
.resolve((0, path_1.dirname)(pkgPath),
|
|
118
|
+
.resolve((0, path_1.dirname)(pkgPath), '.')
|
|
104
119
|
// alias may resolve error (eg: dva from @umijs/plugins)
|
|
105
120
|
// fallback to null for mark it as subpath usage
|
|
106
121
|
.catch(() => null);
|
package/dist/registerMethods.js
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -101,6 +101,9 @@ export declare type IApi = PluginAPI & IServicePluginAPI & {
|
|
|
101
101
|
stats: any;
|
|
102
102
|
time: number;
|
|
103
103
|
}>;
|
|
104
|
+
onPatchRoute: IEvent<{
|
|
105
|
+
route: IRoute;
|
|
106
|
+
}>;
|
|
104
107
|
addEntryImports: IAdd<null, IEntryImport[]>;
|
|
105
108
|
addEntryImportsAhead: IAdd<null, IEntryImport[]>;
|
|
106
109
|
addEntryCodeAhead: IAdd<null, string[]>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IEAR_REG_EXP = void 0;
|
|
4
|
+
const bundler_utils_1 = require("@umijs/bundler-utils");
|
|
4
5
|
const utils_1 = require("@umijs/utils");
|
|
5
6
|
const path_1 = require("path");
|
|
6
7
|
/**
|
|
@@ -88,7 +89,7 @@ function transformIEAR({ content, path }, api) {
|
|
|
88
89
|
// prepend ./ for same or sub level imports
|
|
89
90
|
/^(?!\.\.\/)/, './');
|
|
90
91
|
}
|
|
91
|
-
else if (
|
|
92
|
+
else if ((0, bundler_utils_1.isDepPath)(absPath)) {
|
|
92
93
|
// transform node_modules absolute imports
|
|
93
94
|
// why @fs
|
|
94
95
|
// 由于我们临时文件下大量绝对路径的引用,而绝对路径的引用不会被 Vite 预编译
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/preset-umi",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.17",
|
|
4
4
|
"description": "@umijs/preset-umi",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/preset-umi#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@types/multer": "1.4.7",
|
|
27
|
-
"@umijs/ast": "4.0.0-beta.
|
|
28
|
-
"@umijs/babel-preset-umi": "4.0.0-beta.
|
|
29
|
-
"@umijs/bundler-utils": "4.0.0-beta.
|
|
30
|
-
"@umijs/bundler-vite": "4.0.0-beta.
|
|
31
|
-
"@umijs/bundler-webpack": "4.0.0-beta.
|
|
32
|
-
"@umijs/core": "4.0.0-beta.
|
|
33
|
-
"@umijs/renderer-react": "4.0.0-beta.
|
|
34
|
-
"@umijs/server": "4.0.0-beta.
|
|
35
|
-
"@umijs/utils": "4.0.0-beta.
|
|
27
|
+
"@umijs/ast": "4.0.0-beta.17",
|
|
28
|
+
"@umijs/babel-preset-umi": "4.0.0-beta.17",
|
|
29
|
+
"@umijs/bundler-utils": "4.0.0-beta.17",
|
|
30
|
+
"@umijs/bundler-vite": "4.0.0-beta.17",
|
|
31
|
+
"@umijs/bundler-webpack": "4.0.0-beta.17",
|
|
32
|
+
"@umijs/core": "4.0.0-beta.17",
|
|
33
|
+
"@umijs/renderer-react": "4.0.0-beta.17",
|
|
34
|
+
"@umijs/server": "4.0.0-beta.17",
|
|
35
|
+
"@umijs/utils": "4.0.0-beta.17",
|
|
36
36
|
"core-js": "3.19.2",
|
|
37
37
|
"current-script-polyfill": "1.0.0",
|
|
38
38
|
"enhanced-resolve": "5.8.3",
|