@umijs/utils 4.0.0-beta.8 → 4.0.0-canary.20220317.1

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 (52) hide show
  1. package/compiled/axios/index.d.ts +29 -14
  2. package/compiled/axios/index.js +1 -1
  3. package/compiled/chalk/LICENSE +1 -1
  4. package/compiled/chalk/index.js +1 -1
  5. package/compiled/chalk/package.json +1 -1
  6. package/compiled/chalk/source/index.d.ts +318 -0
  7. package/compiled/chalk/source/vendor/supports-color/index.d.ts +55 -0
  8. package/compiled/color/color-convert/conversions.d.ts +87 -87
  9. package/compiled/color/color-convert/index.d.ts +75 -60
  10. package/compiled/color/color-convert/route.d.ts +271 -271
  11. package/compiled/color/index.d.ts +118 -121
  12. package/compiled/color/index.js +1 -1
  13. package/compiled/color/package.json +1 -4
  14. package/compiled/debug/LICENSE +10 -9
  15. package/compiled/debug/index.js +1 -1
  16. package/compiled/debug/package.json +1 -1
  17. package/compiled/execa/index.d.ts +467 -445
  18. package/compiled/execa/index.js +1 -1
  19. package/compiled/fs-extra/index.d.ts +347 -116
  20. package/compiled/fs-extra/index.js +1 -1
  21. package/compiled/pirates/LICENSE +21 -0
  22. package/compiled/pirates/index.d.ts +82 -0
  23. package/compiled/pirates/index.js +1 -0
  24. package/compiled/pirates/package.json +1 -0
  25. package/compiled/pkg-up/LICENSE +1 -1
  26. package/compiled/pkg-up/index.d.ts +55 -44
  27. package/compiled/pkg-up/index.js +1 -1
  28. package/compiled/pkg-up/package.json +1 -1
  29. package/compiled/prettier/index.d.ts +568 -679
  30. package/compiled/prettier/index.js +62 -274
  31. package/compiled/prettier/package.json +1 -5
  32. package/compiled/resolve/index.js +1 -1
  33. package/compiled/strip-ansi/LICENSE +1 -1
  34. package/compiled/strip-ansi/index.d.ts +2 -4
  35. package/compiled/strip-ansi/index.js +1 -1
  36. package/compiled/strip-ansi/package.json +1 -1
  37. package/compiled/yargs-parser/index.js +1 -1
  38. package/dist/BaseGenerator/BaseGenerator.js +3 -4
  39. package/dist/getCorejsVersion.d.ts +1 -0
  40. package/dist/getCorejsVersion.js +11 -0
  41. package/dist/index.d.ts +5 -3
  42. package/dist/index.js +11 -6
  43. package/dist/installDeps.js +24 -4
  44. package/dist/isStyleFile.d.ts +5 -0
  45. package/dist/isStyleFile.js +16 -0
  46. package/dist/logger.d.ts +8 -6
  47. package/dist/logger.js +8 -1
  48. package/dist/npmClient.js +2 -2
  49. package/dist/register.js +22 -22
  50. package/dist/tryPaths.d.ts +1 -0
  51. package/dist/tryPaths.js +11 -0
  52. package/package.json +35 -33
package/dist/register.js CHANGED
@@ -1,32 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.restore = exports.clearFiles = exports.getFiles = exports.register = void 0;
4
- const fs_1 = require("fs");
4
+ const path_1 = require("path");
5
+ const pirates_1 = require("../compiled/pirates");
6
+ const COMPILE_EXTS = ['.ts', '.tsx', '.js', '.jsx'];
7
+ const HOOK_EXTS = [...COMPILE_EXTS, '.mjs'];
5
8
  let registered = false;
6
9
  let files = [];
7
- const Extensions = {};
10
+ let revert = () => { };
8
11
  function transform(opts) {
9
- return (mod, filename) => {
10
- files.push(filename);
11
- let code = (0, fs_1.readFileSync)(filename, 'utf-8');
12
- if (['.ts', '.tsx'].includes(opts.extname)) {
13
- code = opts.implementor.transformSync(code, {
14
- loader: opts.extname.slice(1),
15
- target: 'es2017',
16
- format: 'cjs',
17
- }).code;
18
- }
19
- mod._compile(code, filename);
20
- };
12
+ const { code, filename, implementor } = opts;
13
+ files.push(filename);
14
+ const ext = (0, path_1.extname)(filename);
15
+ if (COMPILE_EXTS.includes(ext)) {
16
+ return implementor.transformSync(code, {
17
+ loader: ext.slice(1),
18
+ target: 'es2017',
19
+ format: 'cjs',
20
+ }).code;
21
+ }
22
+ return code;
21
23
  }
22
24
  function register(opts) {
23
25
  files = [];
24
- const types = ['.ts', '.tsx', '.js', '.jsx', '.mjs'];
25
26
  if (!registered) {
26
- for (const type of types) {
27
- Extensions[type] = require.extensions[type];
28
- require.extensions[type] = transform(Object.assign(Object.assign({}, opts), { extname: type }));
29
- }
27
+ revert = (0, pirates_1.addHook)((code, filename) => transform({ code, filename, implementor: opts.implementor }), {
28
+ ext: HOOK_EXTS,
29
+ ignoreNodeModules: true,
30
+ });
30
31
  registered = true;
31
32
  }
32
33
  }
@@ -40,8 +41,7 @@ function clearFiles() {
40
41
  }
41
42
  exports.clearFiles = clearFiles;
42
43
  function restore() {
43
- for (const type of Object.keys(Extensions)) {
44
- require.extensions[type] = Extensions[type];
45
- }
44
+ revert();
45
+ registered = false;
46
46
  }
47
47
  exports.restore = restore;
@@ -0,0 +1 @@
1
+ export declare function tryPaths(paths: string[]): string | undefined;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tryPaths = void 0;
4
+ const fs_1 = require("fs");
5
+ function tryPaths(paths) {
6
+ for (const path of paths) {
7
+ if ((0, fs_1.existsSync)(path))
8
+ return path;
9
+ }
10
+ }
11
+ exports.tryPaths = tryPaths;
package/package.json CHANGED
@@ -1,6 +1,13 @@
1
1
  {
2
2
  "name": "@umijs/utils",
3
- "version": "4.0.0-beta.8",
3
+ "version": "4.0.0-canary.20220317.1",
4
+ "homepage": "https://github.com/umijs/umi-next/tree/master/packages/utils#readme",
5
+ "bugs": "https://github.com/umijs/umi-next/issues",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/umijs/umi-next"
9
+ },
10
+ "license": "MIT",
4
11
  "main": "dist/index.js",
5
12
  "types": "dist/index.d.ts",
6
13
  "files": [
@@ -10,59 +17,52 @@
10
17
  "scripts": {
11
18
  "build": "pnpm tsc",
12
19
  "build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
13
- "dev": "pnpm build -- --watch"
14
- },
15
- "repository": {
16
- "type": "git",
17
- "url": "https://github.com/umijs/umi-next"
18
- },
19
- "authors": [
20
- "chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
21
- ],
22
- "license": "MIT",
23
- "bugs": "https://github.com/umijs/umi-next/issues",
24
- "homepage": "https://github.com/umijs/umi-next/tree/master/packages/utils#readme",
25
- "publishConfig": {
26
- "access": "public"
20
+ "dev": "pnpm build -- --watch",
21
+ "test": "jest -c ../../jest.turbo.config.ts"
27
22
  },
28
23
  "dependencies": {
29
- "chokidar": "3.5.2",
30
- "clipboardy": "2.3.0"
24
+ "chokidar": "3.5.3"
31
25
  },
32
26
  "devDependencies": {
33
- "@types/color": "3.0.2",
27
+ "@types/color": "3.0.3",
34
28
  "@types/cross-spawn": "6.0.2",
35
29
  "@types/debug": "4.1.7",
36
- "@types/lodash": "4.14.176",
30
+ "@types/lodash": "4.14.179",
37
31
  "@types/mustache": "4.1.2",
38
32
  "@types/prompts": "^2.0.14",
39
33
  "@types/rimraf": "3.0.2",
40
34
  "@types/semver": "7.3.9",
41
35
  "address": "1.1.2",
42
- "axios": "0.23.0",
43
- "chalk": "4.1.2",
36
+ "axios": "0.26.1",
37
+ "chalk": "5.0.1",
44
38
  "cheerio": "1.0.0-rc.10",
45
- "color": "4.0.1",
39
+ "color": "4.2.1",
46
40
  "cross-spawn": "7.0.3",
47
- "debug": "4.3.2",
41
+ "debug": "4.3.3",
48
42
  "deepmerge": "4.2.2",
49
- "execa": "5.1.1",
50
- "fs-extra": "10.0.0",
43
+ "execa": "6.1.0",
44
+ "fs-extra": "10.0.1",
51
45
  "glob": "7.2.0",
52
- "globby": "11.0.4",
53
46
  "import-lazy": "4.0.0",
54
47
  "lodash": "4.17.21",
55
48
  "mustache": "4.2.0",
56
- "pkg-up": "3.1.0",
49
+ "pirates": "4.0.5",
50
+ "pkg-up": "4.0.0",
57
51
  "portfinder": "1.0.28",
58
- "prettier": "2.4.1",
52
+ "prettier": "2.5.1",
59
53
  "prompts": "2.4.2",
60
- "resolve": "1.20.0",
54
+ "resolve": "1.22.0",
61
55
  "rimraf": "3.0.2",
62
56
  "semver": "7.3.5",
63
- "strip-ansi": "6.0.1",
64
- "yargs-parser": "20.2.9"
57
+ "strip-ansi": "7.0.1",
58
+ "yargs-parser": "21.0.1"
65
59
  },
60
+ "publishConfig": {
61
+ "access": "public"
62
+ },
63
+ "authors": [
64
+ "chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
65
+ ],
66
66
  "compiledConfig": {
67
67
  "deps": [
68
68
  "address",
@@ -87,7 +87,8 @@
87
87
  "resolve",
88
88
  "semver",
89
89
  "strip-ansi",
90
- "yargs-parser"
90
+ "yargs-parser",
91
+ "pirates"
91
92
  ],
92
93
  "externals": {
93
94
  "address": "$$LOCAL",
@@ -107,7 +108,8 @@
107
108
  "resolve": "$$LOCAL",
108
109
  "semver": "$$LOCAL",
109
110
  "strip-ansi": "$$LOCAL",
110
- "yargs-parser": "$$LOCAL"
111
+ "yargs-parser": "$$LOCAL",
112
+ "pirates": "$$LOCAL"
111
113
  }
112
114
  }
113
115
  }