@umijs/preset-umi 4.0.40 → 4.0.42

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.
Files changed (30) hide show
  1. package/dist/commands/dev/dev.js +30 -0
  2. package/dist/commands/generators/jest.js +3 -2
  3. package/dist/commands/lint.js +1 -1
  4. package/dist/commands/setup.js +1 -1
  5. package/dist/features/depsOnDemand/depsOnDemand.js +41 -7
  6. package/dist/features/icons/buildForIconExtract.d.ts +9 -0
  7. package/dist/features/icons/buildForIconExtract.js +76 -0
  8. package/dist/features/icons/esbuildAliasPlugin.d.ts +4 -0
  9. package/dist/features/icons/esbuildAliasPlugin.js +86 -0
  10. package/dist/features/icons/esbuildCollectIconPlugin.d.ts +4 -0
  11. package/dist/features/icons/esbuildCollectIconPlugin.js +54 -0
  12. package/dist/features/icons/esbuildExternalPlugin.d.ts +2 -0
  13. package/dist/features/icons/esbuildExternalPlugin.js +85 -0
  14. package/dist/features/icons/extractIcons.d.ts +1 -0
  15. package/dist/features/icons/extractIcons.js +83 -0
  16. package/dist/features/icons/generateSVGR.d.ts +10 -0
  17. package/dist/features/icons/generateSVGR.js +61 -0
  18. package/dist/features/icons/icons.d.ts +3 -0
  19. package/dist/features/icons/icons.js +136 -0
  20. package/dist/features/mock/getMockData.js +1 -1
  21. package/dist/features/phantomDependency/phantomDependency.d.ts +3 -0
  22. package/dist/features/phantomDependency/phantomDependency.js +103 -0
  23. package/dist/features/terminal/terminal.js +0 -1
  24. package/dist/features/tmpFiles/tmpFiles.js +1 -1
  25. package/dist/features/transform/transform.js +1 -1
  26. package/dist/index.js +2 -0
  27. package/dist/libs/folderCache/LazySourceCodeCache.d.ts +1 -0
  28. package/dist/libs/folderCache/LazySourceCodeCache.js +3 -0
  29. package/package.json +15 -12
  30. package/templates/TestBrowser.tpl +0 -1
@@ -178,6 +178,36 @@ PORT=8888 umi dev
178
178
  }
179
179
  });
180
180
  });
181
+ function watchPublicDirChange() {
182
+ const publicDir = (0, import_path.join)(api.cwd, "public");
183
+ const isPublicAvailable = (0, import_fs.existsSync)(publicDir) && (0, import_fs.readdirSync)(publicDir).length;
184
+ let restarted = false;
185
+ const restartServer = () => {
186
+ if (restarted)
187
+ return;
188
+ restarted = true;
189
+ import_utils.logger.event(`public dir changed, restart server...`);
190
+ api.restartServer();
191
+ };
192
+ (0, import_watch.watch)({
193
+ path: publicDir,
194
+ addToUnWatches: true,
195
+ onChange(event, path) {
196
+ if (isPublicAvailable) {
197
+ if (event === "unlinkDir" && path === publicDir) {
198
+ restartServer();
199
+ } else if (event === "unlink" && (0, import_fs.existsSync)(publicDir) && (0, import_fs.readdirSync)(publicDir).length === 0) {
200
+ restartServer();
201
+ }
202
+ } else {
203
+ if (event === "add" && (0, import_fs.existsSync)(publicDir) && (0, import_fs.readdirSync)(publicDir).length === 1) {
204
+ restartServer();
205
+ }
206
+ }
207
+ }
208
+ });
209
+ }
210
+ watchPublicDirChange();
181
211
  const beforeMiddlewares = await api.applyPlugins({
182
212
  key: "addBeforeMiddlewares",
183
213
  initialValue: []
@@ -54,7 +54,8 @@ var jest_default = (api) => {
54
54
  jest: "^27",
55
55
  "@types/jest": "^27",
56
56
  typescript: "^4",
57
- "ts-node": "^10"
57
+ "ts-node": "^10",
58
+ "cross-env": "^7"
58
59
  };
59
60
  const packageToInstall = res.willUseTLR ? {
60
61
  ...basicDeps,
@@ -63,7 +64,7 @@ var jest_default = (api) => {
63
64
  "@types/testing-library__jest-dom": "^5.14.5"
64
65
  } : basicDeps;
65
66
  h.addDevDeps(packageToInstall);
66
- h.addScript("test", "TS_NODE_TRANSPILE_ONLY=yes jest --passWithNoTests");
67
+ h.addScript("test", "cross-env TS_NODE_TRANSPILE_ONLY=yes jest --passWithNoTests");
67
68
  const setupImports = res.willUseTLR ? [
68
69
  `import '@testing-library/jest-dom';`,
69
70
  `import '${api.appData.umi.importSource}/test-setup'`
@@ -53,7 +53,7 @@ umi lint --quiet
53
53
  try {
54
54
  require.resolve("@umijs/lint/package.json");
55
55
  } catch (err) {
56
- throw new Error("@umijs/lint is not built-in, please install it manually before run umi lint.");
56
+ throw new Error("@umijs/lint is not built-in, please install it manually before run umi lint.", { cause: err });
57
57
  }
58
58
  if (args._.length === 0) {
59
59
  args._.unshift("{src,test}/**/*.{js,jsx,ts,tsx,less,css}");
@@ -34,7 +34,7 @@ var setup_default = (api) => {
34
34
  key: "onGenerateFiles",
35
35
  args: {
36
36
  files: null,
37
- isFirstTime: false
37
+ isFirstTime: true
38
38
  }
39
39
  });
40
40
  }
@@ -26,16 +26,27 @@ var import_utils = require("@umijs/utils");
26
26
  var import_fs = require("fs");
27
27
  var import_path = require("path");
28
28
  var depsOnDemand_default = (api) => {
29
+ const bundlerWebpackPkg = require("@umijs/bundler-webpack/package.json");
29
30
  api.onStart(() => {
30
- var _a, _b;
31
31
  const hasSwcConfig = api.config.srcTranspiler === "swc" || api.config.depTranspiler === "swc";
32
- const swcInstalled = ((_a = api.pkg.dependencies) == null ? void 0 : _a["@swc/core"]) || ((_b = api.pkg.devDependencies) == null ? void 0 : _b["@swc/core"]);
33
- if (hasSwcConfig && !swcInstalled) {
34
- api.logger.info("Since swc is used, install @swc/core on demand.");
32
+ const swcDeps = [
33
+ {
34
+ name: "@swc/core",
35
+ version: `^${bundlerWebpackPkg.devDependencies["@swc/core"]}`
36
+ },
37
+ {
38
+ name: "swc-plugin-auto-css-modules",
39
+ version: `^${bundlerWebpackPkg.devDependencies["swc-plugin-auto-css-modules"]}`
40
+ }
41
+ ];
42
+ const { missingDeps } = checkDeps({
43
+ deps: swcDeps
44
+ });
45
+ if (hasSwcConfig && missingDeps.length) {
46
+ api.logger.info(`Since swc is used, install swc dependencies ${missingDeps.map(({ name }) => import_utils.chalk.green(name)).join(", ")} on demand.`);
35
47
  addDeps({
36
48
  pkgPath: api.pkgPath || (0, import_path.join)(api.cwd, "package.json"),
37
- name: "@swc/core",
38
- version: `^${require("@umijs/bundler-webpack/package.json").devDependencies["@swc/core"]}`
49
+ deps: missingDeps
39
50
  });
40
51
  (0, import_utils.installWithNpmClient)({
41
52
  npmClient: api.appData.npmClient,
@@ -43,11 +54,34 @@ var depsOnDemand_default = (api) => {
43
54
  });
44
55
  }
45
56
  });
57
+ function checkDeps(opts) {
58
+ const missingDeps = [];
59
+ const { deps } = opts;
60
+ deps.forEach((dep) => {
61
+ var _a, _b;
62
+ const { name } = dep;
63
+ const installed = ((_a = api.pkg.dependencies) == null ? void 0 : _a[name]) || ((_b = api.pkg.devDependencies) == null ? void 0 : _b[name]);
64
+ if (!installed) {
65
+ missingDeps.push(dep);
66
+ } else {
67
+ const userVersion = import_utils.semver.minVersion(installed);
68
+ const isOutdated = !userVersion || import_utils.semver.ltr(userVersion, dep.version);
69
+ if (isOutdated) {
70
+ missingDeps.push(dep);
71
+ }
72
+ }
73
+ });
74
+ return {
75
+ missingDeps
76
+ };
77
+ }
46
78
  };
47
79
  function addDeps(opts) {
48
80
  const pkg = (0, import_fs.existsSync)(opts.pkgPath) ? import_utils.fsExtra.readJSONSync(opts.pkgPath) : {};
49
81
  pkg.devDependencies = pkg.devDependencies || {};
50
- pkg.devDependencies[opts.name] = opts.version;
82
+ opts.deps.forEach((dep) => {
83
+ pkg.devDependencies[dep.name] = dep.version;
84
+ });
51
85
  import_utils.fsExtra.writeJSONSync(opts.pkgPath, pkg, { spaces: 2 });
52
86
  }
53
87
  // Annotate the CommonJS export names for ESM import in node:
@@ -0,0 +1,9 @@
1
+ export declare function buildForIconExtract(opts: {
2
+ entryPoints: string[];
3
+ watch?: {
4
+ onRebuildSuccess(): void;
5
+ } | false;
6
+ config?: {
7
+ alias?: any;
8
+ };
9
+ }): Promise<Set<string>>;
@@ -0,0 +1,76 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/features/icons/buildForIconExtract.ts
23
+ var buildForIconExtract_exports = {};
24
+ __export(buildForIconExtract_exports, {
25
+ buildForIconExtract: () => buildForIconExtract
26
+ });
27
+ module.exports = __toCommonJS(buildForIconExtract_exports);
28
+ var import_esbuild = __toESM(require("@umijs/bundler-utils/compiled/esbuild"));
29
+ var import_esbuildExternalPlugin = require("./esbuildExternalPlugin");
30
+ var import_path = __toESM(require("path"));
31
+ var import_esbuildAliasPlugin = require("./esbuildAliasPlugin");
32
+ var import_esbuildCollectIconPlugin = require("./esbuildCollectIconPlugin");
33
+ var import_utils = require("@umijs/utils");
34
+ async function buildForIconExtract(opts) {
35
+ var _a;
36
+ const icons = /* @__PURE__ */ new Set();
37
+ await import_esbuild.default.build({
38
+ format: "esm",
39
+ platform: "browser",
40
+ target: "esnext",
41
+ loader: {
42
+ ".js": "jsx",
43
+ ".jsx": "jsx",
44
+ ".ts": "ts",
45
+ ".tsx": "tsx"
46
+ },
47
+ watch: !!opts.watch && {
48
+ onRebuild(err) {
49
+ if (err) {
50
+ import_utils.logger.error(`[icons] build failed: ${err}`);
51
+ } else {
52
+ if (opts.watch) {
53
+ opts.watch.onRebuildSuccess();
54
+ }
55
+ }
56
+ }
57
+ },
58
+ bundle: true,
59
+ logLevel: "error",
60
+ entryPoints: opts.entryPoints,
61
+ write: false,
62
+ outdir: import_path.default.join(import_path.default.dirname(opts.entryPoints[0]), "out"),
63
+ plugins: [
64
+ (0, import_esbuildAliasPlugin.esbuildAliasPlugin)({ alias: ((_a = opts.config) == null ? void 0 : _a.alias) || {} }),
65
+ (0, import_esbuildExternalPlugin.esbuildExternalPlugin)(),
66
+ (0, import_esbuildCollectIconPlugin.esbuildCollectIconPlugin)({
67
+ icons
68
+ })
69
+ ]
70
+ });
71
+ return icons;
72
+ }
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ buildForIconExtract
76
+ });
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from '@umijs/bundler-utils/compiled/esbuild';
2
+ export declare function esbuildAliasPlugin(opts: {
3
+ alias: Record<string, string>;
4
+ }): Plugin;
@@ -0,0 +1,86 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/features/icons/esbuildAliasPlugin.ts
23
+ var esbuildAliasPlugin_exports = {};
24
+ __export(esbuildAliasPlugin_exports, {
25
+ esbuildAliasPlugin: () => esbuildAliasPlugin
26
+ });
27
+ module.exports = __toCommonJS(esbuildAliasPlugin_exports);
28
+ var import_fs = require("fs");
29
+ var import_enhanced_resolve = __toESM(require("enhanced-resolve"));
30
+ var resolver = import_enhanced_resolve.default.create({
31
+ mainFields: ["module", "browser", "main"],
32
+ extensions: [".json", ".js", ".jsx", ".ts", ".tsx", ".cjs", ".mjs"],
33
+ exportsFields: []
34
+ });
35
+ async function resolve(context, path) {
36
+ return new Promise((resolve2, reject) => {
37
+ resolver(context, path, (err, result) => err ? reject(err) : resolve2(result));
38
+ });
39
+ }
40
+ function sortByAffix(opts) {
41
+ return opts.keys.sort((a, b) => {
42
+ if (a.endsWith(opts.affix) && b.endsWith(opts.affix))
43
+ return 0;
44
+ if (a.endsWith(opts.affix))
45
+ return -1;
46
+ if (b.endsWith(opts.affix))
47
+ return 1;
48
+ else
49
+ return 0;
50
+ });
51
+ }
52
+ function addSlashAffix(key) {
53
+ return key.endsWith("/") ? key : `${key}/`;
54
+ }
55
+ function esbuildAliasPlugin(opts) {
56
+ return {
57
+ name: "esbuildExternalPlugin",
58
+ setup(build) {
59
+ sortByAffix({ keys: Object.keys(opts.alias), affix: "$" }).filter((key) => {
60
+ return opts.alias[key].startsWith("/") && !opts.alias[key].includes("node_modules");
61
+ }).forEach((key) => {
62
+ const value = opts.alias[key];
63
+ const filter = key.endsWith("$") ? new RegExp(key) : new RegExp(`${key}$`);
64
+ build.onResolve({ filter }, async (args) => {
65
+ const path = await resolve(args.importer, args.path.replace(filter, value));
66
+ return {
67
+ path
68
+ };
69
+ });
70
+ if (!key.endsWith("/") && (0, import_fs.existsSync)(value) && (0, import_fs.statSync)(value).isDirectory()) {
71
+ const filter2 = new RegExp(`^${addSlashAffix(key)}`);
72
+ build.onResolve({ filter: filter2 }, async (args) => {
73
+ const path = await resolve(args.importer, args.path.replace(filter2, addSlashAffix(value)));
74
+ return {
75
+ path
76
+ };
77
+ });
78
+ }
79
+ });
80
+ }
81
+ };
82
+ }
83
+ // Annotate the CommonJS export names for ESM import in node:
84
+ 0 && (module.exports = {
85
+ esbuildAliasPlugin
86
+ });
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from '@umijs/bundler-utils/compiled/esbuild';
2
+ export declare function esbuildCollectIconPlugin(opts: {
3
+ icons: Set<string>;
4
+ }): Plugin;
@@ -0,0 +1,54 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/features/icons/esbuildCollectIconPlugin.ts
23
+ var esbuildCollectIconPlugin_exports = {};
24
+ __export(esbuildCollectIconPlugin_exports, {
25
+ esbuildCollectIconPlugin: () => esbuildCollectIconPlugin
26
+ });
27
+ module.exports = __toCommonJS(esbuildCollectIconPlugin_exports);
28
+ var import_fs = __toESM(require("fs"));
29
+ var import_extractIcons = require("./extractIcons");
30
+ function esbuildCollectIconPlugin(opts) {
31
+ return {
32
+ name: "esbuildCollectIconPlugin",
33
+ setup(build) {
34
+ const loaders = ["js", "jsx", "ts", "tsx"];
35
+ loaders.forEach((loader) => {
36
+ const filter = new RegExp(`\\.(${loader})$`);
37
+ build.onLoad({ filter }, async (args) => {
38
+ const contents = import_fs.default.readFileSync(args.path, "utf-8");
39
+ (0, import_extractIcons.extractIcons)(contents).forEach((icon) => {
40
+ opts.icons.add(icon);
41
+ });
42
+ return {
43
+ contents,
44
+ loader
45
+ };
46
+ });
47
+ });
48
+ }
49
+ };
50
+ }
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ esbuildCollectIconPlugin
54
+ });
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from '@umijs/bundler-utils/compiled/esbuild';
2
+ export declare function esbuildExternalPlugin(): Plugin;
@@ -0,0 +1,85 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/features/icons/esbuildExternalPlugin.ts
20
+ var esbuildExternalPlugin_exports = {};
21
+ __export(esbuildExternalPlugin_exports, {
22
+ esbuildExternalPlugin: () => esbuildExternalPlugin
23
+ });
24
+ module.exports = __toCommonJS(esbuildExternalPlugin_exports);
25
+ function esbuildExternalPlugin() {
26
+ return {
27
+ name: "esbuildExternalPlugin",
28
+ setup(build) {
29
+ externalsExtensions.forEach((ext) => {
30
+ const filter = new RegExp(`.${ext}(\\?.*)?$`);
31
+ build.onResolve({ filter }, () => {
32
+ return {
33
+ external: true
34
+ };
35
+ });
36
+ });
37
+ build.onResolve({ filter: /.*/ }, (args) => {
38
+ if (args.path.startsWith(".")) {
39
+ return null;
40
+ }
41
+ if (args.kind === "entry-point") {
42
+ return null;
43
+ }
44
+ if (args.path.startsWith("/") && !args.path.includes("node_modules")) {
45
+ return null;
46
+ }
47
+ return {
48
+ external: true
49
+ };
50
+ });
51
+ }
52
+ };
53
+ }
54
+ var externalsExtensions = [
55
+ "aac",
56
+ "css",
57
+ "less",
58
+ "sass",
59
+ "scss",
60
+ "eot",
61
+ "flac",
62
+ "gif",
63
+ "ico",
64
+ "jpeg",
65
+ "jpg",
66
+ "json",
67
+ "md",
68
+ "mdx",
69
+ "mp3",
70
+ "mp4",
71
+ "ogg",
72
+ "otf",
73
+ "png",
74
+ "svg",
75
+ "ttf",
76
+ "wav",
77
+ "webm",
78
+ "webp",
79
+ "woff",
80
+ "woff2"
81
+ ];
82
+ // Annotate the CommonJS export names for ESM import in node:
83
+ 0 && (module.exports = {
84
+ esbuildExternalPlugin
85
+ });
@@ -0,0 +1 @@
1
+ export declare function extractIcons(code: string): string[];
@@ -0,0 +1,83 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/features/icons/extractIcons.ts
20
+ var extractIcons_exports = {};
21
+ __export(extractIcons_exports, {
22
+ extractIcons: () => extractIcons
23
+ });
24
+ module.exports = __toCommonJS(extractIcons_exports);
25
+ function extractIcons(code) {
26
+ const icons = [];
27
+ let current = 0;
28
+ function isIconStart() {
29
+ return code[current] === "<" && code[current + 1] === "I" && code[current + 2] === "c" && code[current + 3] === "o" && code[current + 4] === "n" && isEmptyChar(code[current + 5]);
30
+ }
31
+ let quotationMark = "";
32
+ function isNameAttributeStart() {
33
+ if (isEmptyChar(code[current]) && code[current + 1] === "i" && code[current + 2] === "c" && code[current + 3] === "o" && code[current + 4] === "n" && code[current + 5] === "=" && (code[current + 6] === "'" || code[current + 6] === '"')) {
34
+ quotationMark = code[current + 6];
35
+ return true;
36
+ } else {
37
+ return false;
38
+ }
39
+ }
40
+ function isEmptyChar(char) {
41
+ return char === " " || char === "\n" || char === "\r";
42
+ }
43
+ function findNameValue() {
44
+ let value = "";
45
+ while (code[current] !== quotationMark && code[current] !== ">") {
46
+ value += code[current];
47
+ current += 1;
48
+ }
49
+ return value;
50
+ }
51
+ function finishJSXTag() {
52
+ let icon = null;
53
+ while (code[current] !== ">") {
54
+ if (isNameAttributeStart()) {
55
+ current += 7;
56
+ icon = findNameValue();
57
+ if (icon) {
58
+ icons.push(icon);
59
+ return;
60
+ }
61
+ } else {
62
+ current += 1;
63
+ }
64
+ }
65
+ if (code[current] === ">") {
66
+ current += 1;
67
+ return;
68
+ }
69
+ }
70
+ while (current < code.length) {
71
+ if (isIconStart()) {
72
+ current += 5;
73
+ finishJSXTag();
74
+ } else {
75
+ current += 1;
76
+ }
77
+ }
78
+ return icons;
79
+ }
80
+ // Annotate the CommonJS export names for ESM import in node:
81
+ 0 && (module.exports = {
82
+ extractIcons
83
+ });
@@ -0,0 +1,10 @@
1
+ export declare function generateIconName(opts: {
2
+ collect: string;
3
+ icon: string;
4
+ }): string;
5
+ export declare function generateSVGR(opts: {
6
+ collect: string;
7
+ icon: string;
8
+ iconifyOptions?: object;
9
+ svgrOptions?: object;
10
+ }): Promise<string | null>;
@@ -0,0 +1,61 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/features/icons/generateSVGR.ts
20
+ var generateSVGR_exports = {};
21
+ __export(generateSVGR_exports, {
22
+ generateIconName: () => generateIconName,
23
+ generateSVGR: () => generateSVGR
24
+ });
25
+ module.exports = __toCommonJS(generateSVGR_exports);
26
+ var import_node_loader = require("@iconify/utils/lib/loader/node-loader");
27
+ var import_core = require("@svgr/core");
28
+ function camelCase(str) {
29
+ return str.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
30
+ }
31
+ function generateIconName(opts) {
32
+ return camelCase(`${opts.collect}-${opts.icon}`);
33
+ }
34
+ async function generateSVGR(opts) {
35
+ const warn = `${opts.collect}/${opts.icon}`;
36
+ const componentName = generateIconName(opts);
37
+ const svg = await (0, import_node_loader.loadNodeIcon)(opts.collect, opts.icon, {
38
+ warn,
39
+ addXmlNs: false,
40
+ autoInstall: false,
41
+ ...opts.iconifyOptions
42
+ });
43
+ if (!svg) {
44
+ return null;
45
+ }
46
+ return normalizeSvgr(await (0, import_core.transform)(svg, opts.svgrOptions || {}, { componentName }));
47
+ }
48
+ function normalizeSvgr(str) {
49
+ return str.split("\n").filter((line) => {
50
+ if (line.startsWith('import * as React from "react";'))
51
+ return false;
52
+ if (line.startsWith("export default "))
53
+ return false;
54
+ return true;
55
+ }).join("\n");
56
+ }
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ generateIconName,
60
+ generateSVGR
61
+ });
@@ -0,0 +1,3 @@
1
+ import { IApi } from '../../types';
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;
@@ -0,0 +1,136 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/features/icons/icons.ts
23
+ var icons_exports = {};
24
+ __export(icons_exports, {
25
+ default: () => icons_default
26
+ });
27
+ module.exports = __toCommonJS(icons_exports);
28
+ var import_path = __toESM(require("path"));
29
+ var import_buildForIconExtract = require("./buildForIconExtract");
30
+ var import_utils = require("@umijs/utils");
31
+ var import_generateSVGR = require("./generateSVGR");
32
+ var icons_default = (api) => {
33
+ api.describe({
34
+ config: {
35
+ schema(Joi) {
36
+ return Joi.object({
37
+ autoInstall: Joi.object(),
38
+ defaultComponentConfig: Joi.object(),
39
+ alias: Joi.object()
40
+ });
41
+ }
42
+ },
43
+ enableBy: api.EnableBy.config
44
+ });
45
+ api.register({
46
+ key: "onGenerateFiles",
47
+ async fn({ isFirstTime }) {
48
+ if (!isFirstTime)
49
+ return;
50
+ const entryFile = import_path.default.join(api.paths.absTmpPath, "umi.ts");
51
+ const icons = await (0, import_buildForIconExtract.buildForIconExtract)({
52
+ entryPoints: [entryFile],
53
+ watch: api.name === "dev" && {
54
+ onRebuildSuccess() {
55
+ generate().catch((e) => {
56
+ import_utils.logger.error(e);
57
+ });
58
+ }
59
+ },
60
+ config: {
61
+ alias: api.config.alias
62
+ }
63
+ });
64
+ const generate = async () => {
65
+ import_utils.logger.info(`[icons] generate icons.tsx`);
66
+ const code = [];
67
+ for (const iconStr of icons) {
68
+ const [collect, icon] = iconStr.split(":");
69
+ const iconName = (0, import_generateSVGR.generateIconName)({ collect, icon });
70
+ const svgr = await (0, import_generateSVGR.generateSVGR)({
71
+ collect,
72
+ icon,
73
+ iconifyOptions: { autoInstall: api.config.icons.autoInstall }
74
+ });
75
+ if (svgr) {
76
+ code.push(svgr);
77
+ code.push(`export { ${iconName} };`);
78
+ } else {
79
+ if (api.env === "development") {
80
+ import_utils.logger.error(`[icons] Icon ${iconStr} not found`);
81
+ } else {
82
+ throw new Error(`[icons] Icon ${iconStr} not found`);
83
+ }
84
+ }
85
+ }
86
+ api.writeTmpFile({
87
+ path: "icons.tsx",
88
+ content: code.join("\n") || `export const __no_icons = true;`
89
+ });
90
+ };
91
+ generate().catch((e) => {
92
+ import_utils.logger.error(e);
93
+ });
94
+ },
95
+ stage: Infinity
96
+ });
97
+ api.onGenerateFiles(() => {
98
+ api.writeTmpFile({
99
+ path: "index.tsx",
100
+ content: `
101
+ import React from 'react';
102
+ import * as iconsMap from './icons';
103
+
104
+ export const Icon = React.forwardRef((props: {
105
+ icon: string;
106
+ className?: string;
107
+ viewBox?: string;
108
+ width?: string;
109
+ height?: string;
110
+ style?: any;
111
+ }, ref) => {
112
+ const { icon, ...extraProps } = props;
113
+ const iconName = normalizeIconName(icon);
114
+ const Component = iconsMap[iconName];
115
+ if (!Component) {
116
+ // TODO: give a error icon when dev, to help developer find the error
117
+ return null;
118
+ }
119
+ return (
120
+ <span role="img" ref={ref}><Component {...extraProps} /></span>
121
+ );
122
+ });
123
+
124
+ function camelCase(str: string) {
125
+ return str.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
126
+ }
127
+
128
+ function normalizeIconName(name: string) {
129
+ return camelCase(name.replace(':', '-'));
130
+ }
131
+ `
132
+ });
133
+ });
134
+ };
135
+ // Annotate the CommonJS export names for ESM import in node:
136
+ 0 && (module.exports = {});
@@ -53,7 +53,7 @@ function getMockData(opts) {
53
53
  m = require(mockFile);
54
54
  } catch (e) {
55
55
  throw new Error(`Mock file ${mockFile} parse failed.
56
- ${e.message}`);
56
+ ${e.message}`, { cause: e });
57
57
  }
58
58
  const obj = (m == null ? void 0 : m.default) || m || {};
59
59
  for (const key of Object.keys(obj)) {
@@ -0,0 +1,3 @@
1
+ import { IApi } from '../../types';
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;
@@ -0,0 +1,103 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/features/phantomDependency/phantomDependency.ts
20
+ var phantomDependency_exports = {};
21
+ __export(phantomDependency_exports, {
22
+ default: () => phantomDependency_default
23
+ });
24
+ module.exports = __toCommonJS(phantomDependency_exports);
25
+ var phantomDependency_default = (api) => {
26
+ api.describe({
27
+ key: "phantomDependency",
28
+ config: {
29
+ schema(Joi) {
30
+ return Joi.object({
31
+ exclude: Joi.array().items(Joi.string())
32
+ });
33
+ }
34
+ },
35
+ enableBy: api.EnableBy.config
36
+ });
37
+ api.onStart(() => {
38
+ if (api.appData.npmClient === "pnpm") {
39
+ api.logger.warn("Phantom dependencies check is not needed in pnpm.");
40
+ }
41
+ });
42
+ api.onCheckCode((opts) => {
43
+ if (opts.isFromTmp)
44
+ return;
45
+ if (/node_modules/.test(opts.file))
46
+ return;
47
+ opts.imports.forEach((imp) => {
48
+ var _a, _b, _c, _d;
49
+ const { source, loc } = imp;
50
+ if (source.startsWith("."))
51
+ return;
52
+ if (source.startsWith("/"))
53
+ return;
54
+ if (source.startsWith("@/") || source.startsWith("@@/"))
55
+ return;
56
+ const pkgName = getPkgName(source);
57
+ if ((_a = api.config.phantomDependency.exclude) == null ? void 0 : _a.includes(pkgName))
58
+ return;
59
+ if ((_b = api.pkg.dependencies) == null ? void 0 : _b[pkgName])
60
+ return;
61
+ if ((_c = api.pkg.devDependencies) == null ? void 0 : _c[pkgName])
62
+ return;
63
+ if ((_d = api.pkg.clientDependencies) == null ? void 0 : _d[pkgName])
64
+ return;
65
+ if (matchAlias(source, api.config.alias || {}))
66
+ return;
67
+ if (matchExternals(source, api.config.externals || {}))
68
+ return;
69
+ throw new opts.CodeFrameError(`${source} is a phantom dependency, please specify it in package.json.`, loc);
70
+ });
71
+ });
72
+ function getPkgName(source) {
73
+ const arr = source.split("/");
74
+ if (source.startsWith("@"))
75
+ return arr[0] + "/" + arr[1];
76
+ return arr[0];
77
+ }
78
+ function matchAlias(source, alias) {
79
+ const keys = Object.keys(alias);
80
+ for (let i = 0; i < keys.length; i++) {
81
+ const key = keys[i];
82
+ const keyWithSlashAffix = key.endsWith("/") ? key : `${key}/`;
83
+ if (key.endsWith("$") && source === key.slice(0, -1)) {
84
+ return true;
85
+ } else if (source === key || source.startsWith(keyWithSlashAffix)) {
86
+ return true;
87
+ }
88
+ }
89
+ return false;
90
+ }
91
+ function matchExternals(source, externals) {
92
+ const keys = Object.keys(externals);
93
+ for (let i = 0; i < keys.length; i++) {
94
+ const key = keys[i];
95
+ if (source === key) {
96
+ return true;
97
+ }
98
+ }
99
+ return false;
100
+ }
101
+ };
102
+ // Annotate the CommonJS export names for ESM import in node:
103
+ 0 && (module.exports = {});
@@ -37,7 +37,6 @@ var terminal_default = (api) => {
37
37
  path: "core/terminal.ts",
38
38
  noPluginDir: true,
39
39
  content: `
40
- const console = globalThis.console;
41
40
  let count = 0;
42
41
  let groupLevel = 0;
43
42
  function send(type: string, message?: string) {
@@ -518,7 +518,7 @@ export default function EmptyRoute() {
518
518
  content: exports.join("\n")
519
519
  });
520
520
  },
521
- stage: Infinity
521
+ stage: 1e4
522
522
  });
523
523
  };
524
524
  // Annotate the CommonJS export names for ESM import in node:
@@ -56,7 +56,7 @@ ${(0, import_code_frame.codeFrameColumns)(args.code, err.location, {
56
56
  highlightCode: true,
57
57
  message: err.message
58
58
  })}
59
- `);
59
+ `, { cause: err });
60
60
  } else if (err instanceof Error) {
61
61
  throw new Error(import_utils.chalk.redBright(err.message));
62
62
  } else {
package/dist/index.js CHANGED
@@ -43,9 +43,11 @@ var src_default = () => {
43
43
  require.resolve("./features/esmi/esmi"),
44
44
  require.resolve("./features/exportStatic/exportStatic"),
45
45
  require.resolve("./features/favicons/favicons"),
46
+ require.resolve("./features/icons/icons"),
46
47
  require.resolve("./features/mock/mock"),
47
48
  require.resolve("./features/mpa/mpa"),
48
49
  require.resolve("./features/overrides/overrides"),
50
+ require.resolve("./features/phantomDependency/phantomDependency"),
49
51
  require.resolve("./features/polyfill/polyfill"),
50
52
  require.resolve("./features/polyfill/publicPathPolyfill"),
51
53
  require.resolve("./features/routePrefetch/routePrefetch"),
@@ -18,6 +18,7 @@ export declare class LazySourceCodeCache {
18
18
  cachePath: string;
19
19
  });
20
20
  init(): Promise<void>;
21
+ getSrcPath(): string;
21
22
  loadFiles(files: string[]): Promise<void>;
22
23
  private initFileList;
23
24
  getMergedCode(): {
@@ -59,6 +59,9 @@ var LazySourceCodeCache = class {
59
59
  ]);
60
60
  await this.loadFiles(files);
61
61
  }
62
+ getSrcPath() {
63
+ return this.srcPath;
64
+ }
62
65
  async loadFiles(files) {
63
66
  const loaded = await this.filesLoader(files);
64
67
  for (const f of Object.keys(loaded)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/preset-umi",
3
- "version": "4.0.40",
3
+ "version": "4.0.42",
4
4
  "description": "@umijs/preset-umi",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/preset-umi#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -25,19 +25,22 @@
25
25
  "test": "umi-scripts jest-turbo"
26
26
  },
27
27
  "dependencies": {
28
- "@umijs/ast": "4.0.40",
29
- "@umijs/babel-preset-umi": "4.0.40",
30
- "@umijs/bundler-utils": "4.0.40",
31
- "@umijs/bundler-vite": "4.0.40",
32
- "@umijs/bundler-webpack": "4.0.40",
33
- "@umijs/core": "4.0.40",
28
+ "@iconify-json/fa": "1",
29
+ "@iconify/utils": "2.0.9",
30
+ "@svgr/core": "6.2.1",
31
+ "@umijs/ast": "4.0.42",
32
+ "@umijs/babel-preset-umi": "4.0.42",
33
+ "@umijs/bundler-utils": "4.0.42",
34
+ "@umijs/bundler-vite": "4.0.42",
35
+ "@umijs/bundler-webpack": "4.0.42",
36
+ "@umijs/core": "4.0.42",
34
37
  "@umijs/did-you-know": "^1.0.0",
35
38
  "@umijs/history": "5.3.1",
36
- "@umijs/mfsu": "4.0.40",
37
- "@umijs/plugin-run": "4.0.40",
38
- "@umijs/renderer-react": "4.0.40",
39
- "@umijs/server": "4.0.40",
40
- "@umijs/utils": "4.0.40",
39
+ "@umijs/mfsu": "4.0.42",
40
+ "@umijs/plugin-run": "4.0.42",
41
+ "@umijs/renderer-react": "4.0.42",
42
+ "@umijs/server": "4.0.42",
43
+ "@umijs/utils": "4.0.42",
41
44
  "babel-plugin-dynamic-import-node": "2.3.3",
42
45
  "click-to-react-component": "^1.0.8",
43
46
  "core-js": "3.22.4",
@@ -6,7 +6,6 @@ import { createPluginManager } from './core/plugin';
6
6
  import { getRoutes } from './core/route';
7
7
  import type { Location } from 'history';
8
8
 
9
- {{{ polyfillImports }}}
10
9
  {{{ importsAhead }}}
11
10
  const publicPath = '/';
12
11
  const runtimePublicPath = false;