umi 4.0.0-rc.1 → 4.0.0-rc.10

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/bin/forkedDev.js CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- require('v8-compile-cache');
3
+ // require('v8-compile-cache');
4
4
  require('../dist/cli/forkedDev');
package/bin/umi.js CHANGED
@@ -1,6 +1,25 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- require('v8-compile-cache');
3
+ // disable since it's conflicted with typescript cjs + dynamic import
4
+ // require('v8-compile-cache');
5
+
6
+ // patch console for debug
7
+ // ref: https://remysharp.com/2014/05/23/where-is-that-console-log
8
+ if (process.env.DEBUG_CONSOLE) {
9
+ ['log', 'warn', 'error'].forEach((method) => {
10
+ const old = console[method];
11
+ console[method] = function () {
12
+ let stack = new Error().stack.split(/\n/);
13
+ // Chrome includes a single "Error" line, FF doesn't.
14
+ if (stack[0].indexOf('Error') === 0) {
15
+ stack = stack.slice(1);
16
+ }
17
+ const args = [].slice.apply(arguments).concat([stack[1].trim()]);
18
+ return old.apply(console, args);
19
+ };
20
+ });
21
+ }
22
+
4
23
  require('../dist/cli/cli')
5
24
  .run()
6
25
  .catch((e) => {
@@ -52,6 +52,9 @@ export class PluginManager {
52
52
  if (args) {
53
53
  assert(typeof args === 'object', `applyPlugins failed, args must be plain object.`);
54
54
  }
55
+ if (async) {
56
+ assert(type === ApplyPluginsType.modify || type === ApplyPluginsType.event, `async only works with modify and event type.`);
57
+ }
55
58
  switch (type) {
56
59
  case ApplyPluginsType.modify:
57
60
  if (async) {
@@ -94,10 +97,15 @@ export class PluginManager {
94
97
  }, initialValue);
95
98
  }
96
99
  case ApplyPluginsType.event:
97
- return hooks.forEach((hook) => {
98
- assert(typeof hook === 'function', `applyPlugins failed, all hooks for key ${key} must be function.`);
99
- hook(args);
100
- });
100
+ return (() => __awaiter(this, void 0, void 0, function* () {
101
+ for (const hook of hooks) {
102
+ assert(typeof hook === 'function', `applyPlugins failed, all hooks for key ${key} must be function.`);
103
+ const ret = hook(args);
104
+ if (async && isPromiseLike(ret)) {
105
+ yield ret;
106
+ }
107
+ }
108
+ }))();
101
109
  case ApplyPluginsType.compose:
102
110
  return () => {
103
111
  return compose({
@@ -55,6 +55,9 @@ class PluginManager {
55
55
  if (args) {
56
56
  (0, utils_1.assert)(typeof args === 'object', `applyPlugins failed, args must be plain object.`);
57
57
  }
58
+ if (async) {
59
+ (0, utils_1.assert)(type === ApplyPluginsType.modify || type === ApplyPluginsType.event, `async only works with modify and event type.`);
60
+ }
58
61
  switch (type) {
59
62
  case ApplyPluginsType.modify:
60
63
  if (async) {
@@ -97,10 +100,15 @@ class PluginManager {
97
100
  }, initialValue);
98
101
  }
99
102
  case ApplyPluginsType.event:
100
- return hooks.forEach((hook) => {
101
- (0, utils_1.assert)(typeof hook === 'function', `applyPlugins failed, all hooks for key ${key} must be function.`);
102
- hook(args);
103
- });
103
+ return (() => __awaiter(this, void 0, void 0, function* () {
104
+ for (const hook of hooks) {
105
+ (0, utils_1.assert)(typeof hook === 'function', `applyPlugins failed, all hooks for key ${key} must be function.`);
106
+ const ret = hook(args);
107
+ if (async && (0, utils_1.isPromiseLike)(ret)) {
108
+ yield ret;
109
+ }
110
+ }
111
+ }))();
104
112
  case ApplyPluginsType.compose:
105
113
  return () => {
106
114
  return (0, utils_1.compose)({
@@ -1 +1,5 @@
1
- export declare function defineConfig(config: any): any;
1
+ import { IConfigFromPlugins } from '@@/core/pluginConfig';
2
+ import type { IConfig } from '@umijs/preset-umi';
3
+ declare type ConfigType = IConfigFromPlugins & IConfig;
4
+ export declare function defineConfig(config: ConfigType): ConfigType;
5
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { IServicePluginAPI, PluginAPI } from '@umijs/core';
2
+ export { run } from './cli/cli';
2
3
  export { defineConfig } from './defineConfig';
3
4
  export * from './service/service';
4
5
  export declare type IApi = PluginAPI & IServicePluginAPI;
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -10,7 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
15
  };
12
16
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.defineConfig = void 0;
17
+ exports.defineConfig = exports.run = void 0;
18
+ var cli_1 = require("./cli/cli");
19
+ Object.defineProperty(exports, "run", { enumerable: true, get: function () { return cli_1.run; } });
14
20
  var defineConfig_1 = require("./defineConfig");
15
21
  Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return defineConfig_1.defineConfig; } });
16
22
  __exportStar(require("./service/service"), exports);
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/dist/test.d.ts ADDED
@@ -0,0 +1,117 @@
1
+ import { Config } from '@umijs/test';
2
+ export * from '@umijs/test';
3
+ export declare function configUmiAlias(config: Config.InitialOptions): Promise<Partial<{
4
+ automock: boolean;
5
+ bail: number | boolean;
6
+ cache: boolean;
7
+ cacheDirectory: string;
8
+ ci: boolean;
9
+ clearMocks: boolean;
10
+ changedFilesWithAncestor: boolean;
11
+ changedSince: string;
12
+ collectCoverage: boolean;
13
+ collectCoverageFrom: string[];
14
+ collectCoverageOnlyFrom: {
15
+ [key: string]: boolean;
16
+ };
17
+ coverageDirectory: string;
18
+ coveragePathIgnorePatterns: string[];
19
+ coverageProvider: "babel" | "v8";
20
+ coverageReporters: Config.CoverageReporters;
21
+ coverageThreshold: {
22
+ [path: string]: Config.CoverageThresholdValue;
23
+ global: Config.CoverageThresholdValue;
24
+ };
25
+ dependencyExtractor: string;
26
+ detectLeaks: boolean;
27
+ detectOpenHandles: boolean;
28
+ displayName: string | Config.DisplayName;
29
+ expand: boolean;
30
+ extensionsToTreatAsEsm: string[];
31
+ extraGlobals: string[];
32
+ filter: string;
33
+ findRelatedTests: boolean;
34
+ forceCoverageMatch: string[];
35
+ forceExit: boolean;
36
+ json: boolean;
37
+ globals: Config.ConfigGlobals;
38
+ globalSetup: string | null | undefined;
39
+ globalTeardown: string | null | undefined;
40
+ haste: Config.HasteConfig;
41
+ injectGlobals: boolean;
42
+ reporters: (string | Config.ReporterConfig)[];
43
+ logHeapUsage: boolean;
44
+ lastCommit: boolean;
45
+ listTests: boolean;
46
+ maxConcurrency: number;
47
+ maxWorkers: string | number;
48
+ moduleDirectories: string[];
49
+ moduleFileExtensions: string[];
50
+ moduleLoader: string;
51
+ moduleNameMapper: {
52
+ [key: string]: string | string[];
53
+ };
54
+ modulePathIgnorePatterns: string[];
55
+ modulePaths: string[];
56
+ name: string;
57
+ noStackTrace: boolean;
58
+ notify: boolean;
59
+ notifyMode: string;
60
+ onlyChanged: boolean;
61
+ onlyFailures: boolean;
62
+ outputFile: string;
63
+ passWithNoTests: boolean;
64
+ preprocessorIgnorePatterns: string[];
65
+ preset: string | null | undefined;
66
+ prettierPath: string | null | undefined;
67
+ projects: (string | Config.InitialProjectOptions)[];
68
+ replname: string | null | undefined;
69
+ resetMocks: boolean;
70
+ resetModules: boolean;
71
+ resolver: string | null | undefined;
72
+ restoreMocks: boolean;
73
+ rootDir: string;
74
+ roots: string[];
75
+ runner: string;
76
+ runTestsByPath: boolean;
77
+ scriptPreprocessor: string;
78
+ setupFiles: string[];
79
+ setupTestFrameworkScriptFile: string;
80
+ setupFilesAfterEnv: string[];
81
+ silent: boolean;
82
+ skipFilter: boolean;
83
+ skipNodeResolution: boolean;
84
+ slowTestThreshold: number;
85
+ snapshotResolver: string;
86
+ snapshotSerializers: string[];
87
+ snapshotFormat: Config.PrettyFormatOptions;
88
+ errorOnDeprecated: boolean;
89
+ testEnvironment: string;
90
+ testEnvironmentOptions: Record<string, unknown>;
91
+ testFailureExitCode: string | number;
92
+ testLocationInResults: boolean;
93
+ testMatch: string[];
94
+ testNamePattern: string;
95
+ testPathDirs: string[];
96
+ testPathIgnorePatterns: string[];
97
+ testRegex: string | string[];
98
+ testResultsProcessor: string;
99
+ testRunner: string;
100
+ testSequencer: string;
101
+ testURL: string;
102
+ testTimeout: number;
103
+ timers: "real" | "fake" | "modern" | "legacy";
104
+ transform: {
105
+ [regex: string]: string | Config.TransformerConfig;
106
+ };
107
+ transformIgnorePatterns: string[];
108
+ watchPathIgnorePatterns: string[];
109
+ unmockedModulePathPatterns: string[];
110
+ updateSnapshot: boolean;
111
+ useStderr: boolean;
112
+ verbose?: boolean | undefined;
113
+ watch: boolean;
114
+ watchAll: boolean;
115
+ watchman: boolean;
116
+ watchPlugins: (string | [string, Record<string, unknown>])[];
117
+ }>>;
package/dist/test.js ADDED
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.configUmiAlias = void 0;
27
+ const fs_1 = require("fs");
28
+ const service_1 = require("./service/service");
29
+ __exportStar(require("@umijs/test"), exports);
30
+ function getAliasPathWithKey(alias, key) {
31
+ const thePath = alias[key];
32
+ if (alias[thePath]) {
33
+ return getAliasPathWithKey(alias, thePath);
34
+ }
35
+ return thePath;
36
+ }
37
+ let service;
38
+ function configUmiAlias(config) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ if (!service) {
41
+ service = new service_1.Service();
42
+ yield service.run2({
43
+ name: 'setup',
44
+ args: { quiet: true },
45
+ });
46
+ }
47
+ config.moduleNameMapper || (config.moduleNameMapper = {});
48
+ const { alias } = service.config;
49
+ for (const key of Object.keys(alias)) {
50
+ const aliasPath = getAliasPathWithKey(alias, key);
51
+ if ((0, fs_1.existsSync)(aliasPath) && (0, fs_1.statSync)(aliasPath).isDirectory()) {
52
+ config.moduleNameMapper[`^${key}/(.*)$`] = `${aliasPath}/$1`;
53
+ config.moduleNameMapper[`^${key}$`] = aliasPath;
54
+ }
55
+ else {
56
+ config.moduleNameMapper[`^${key}$`] = aliasPath;
57
+ }
58
+ }
59
+ return config;
60
+ });
61
+ }
62
+ exports.configUmiAlias = configUmiAlias;
package/index.d.ts CHANGED
@@ -1,3 +1,10 @@
1
+ // @ts-ignore
1
2
  export * from '@@/exports';
2
- export type { IApi } from '@umijs/preset-umi';
3
+ export type {
4
+ IApi,
5
+ webpack,
6
+ IRoute,
7
+ UmiApiRequest,
8
+ UmiApiResponse,
9
+ } from '@umijs/preset-umi';
3
10
  export * from './dist';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "umi",
3
- "version": "4.0.0-rc.1",
3
+ "version": "4.0.0-rc.10",
4
4
  "description": "umi",
5
5
  "homepage": "https://github.com/umijs/umi-next/tree/master/packages/umi#readme",
6
6
  "bugs": "https://github.com/umijs/umi-next/issues",
@@ -10,7 +10,6 @@
10
10
  },
11
11
  "license": "MIT",
12
12
  "main": "dist/index.js",
13
- "module": "index.esm.js",
14
13
  "types": "index.d.ts",
15
14
  "bin": {
16
15
  "umi": "bin/umi.js"
@@ -23,20 +22,29 @@
23
22
  "bin",
24
23
  "plugin.js",
25
24
  "plugin-utils.d.ts",
26
- "plugin-utils.js"
25
+ "plugin-utils.js",
26
+ "prettier.js",
27
+ "test.d.ts",
28
+ "test.js"
27
29
  ],
28
30
  "scripts": {
29
31
  "build": "pnpm tsc",
30
32
  "build:client": "pnpm tsc --project ./tsconfig.client.json",
31
33
  "build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
32
- "dev": "pnpm build -- --watch"
34
+ "dev": "pnpm build -- --watch",
35
+ "test": "jest -c ../../jest.turbo.config.ts"
33
36
  },
34
37
  "dependencies": {
35
- "@umijs/core": "4.0.0-rc.1",
36
- "@umijs/preset-umi": "4.0.0-rc.1",
37
- "@umijs/renderer-react": "4.0.0-rc.1",
38
- "@umijs/utils": "4.0.0-rc.1",
39
- "v8-compile-cache": "2.3.0"
38
+ "@umijs/core": "4.0.0-rc.10",
39
+ "@umijs/preset-umi": "4.0.0-rc.10",
40
+ "@umijs/renderer-react": "4.0.0-rc.10",
41
+ "@umijs/test": "4.0.0-rc.10",
42
+ "@umijs/utils": "4.0.0-rc.10",
43
+ "prettier-plugin-organize-imports": "^2.3.4",
44
+ "prettier-plugin-packagejson": "^2.2.16"
45
+ },
46
+ "engines": {
47
+ "node": ">=14"
40
48
  },
41
49
  "publishConfig": {
42
50
  "access": "public"
package/prettier.js ADDED
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ printWidth: 80,
3
+ singleQuote: true,
4
+ trailingComma: 'all',
5
+ proseWrap: 'never',
6
+ endOfLine: 'lf',
7
+ overrides: [{ files: '.prettierrc', options: { parser: 'json' } }],
8
+ plugins: [
9
+ require.resolve('prettier-plugin-packagejson'),
10
+ require.resolve('prettier-plugin-organize-imports'),
11
+ ],
12
+ };
package/test.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/test';
package/test.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/test');