@modern-js/utils 1.3.8-canary.0 → 1.6.0

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 (186) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/compiled/address/index.js +1 -0
  3. package/compiled/address/lib/address.d.ts +28 -0
  4. package/compiled/address/package.json +1 -0
  5. package/compiled/browserslist/index.js +1 -1
  6. package/compiled/dotenv/index.js +1 -0
  7. package/compiled/dotenv/license +23 -0
  8. package/compiled/dotenv/package.json +1 -0
  9. package/compiled/dotenv/types/index.d.ts +59 -0
  10. package/compiled/dotenv-expand/index.d.ts +15 -0
  11. package/compiled/dotenv-expand/index.js +1 -0
  12. package/compiled/dotenv-expand/license +24 -0
  13. package/compiled/dotenv-expand/package.json +1 -0
  14. package/compiled/fast-glob/@nodelib/fs.scandir/out/adapters/fs.d.ts +20 -0
  15. package/compiled/fast-glob/@nodelib/fs.scandir/out/index.d.ts +12 -0
  16. package/compiled/fast-glob/@nodelib/fs.scandir/out/providers/async.d.ts +7 -0
  17. package/compiled/fast-glob/@nodelib/fs.scandir/out/settings.d.ts +20 -0
  18. package/compiled/fast-glob/@nodelib/fs.scandir/out/types/index.d.ts +20 -0
  19. package/compiled/fast-glob/@nodelib/fs.stat/out/adapters/fs.d.ts +13 -0
  20. package/compiled/fast-glob/@nodelib/fs.stat/out/index.d.ts +12 -0
  21. package/compiled/fast-glob/@nodelib/fs.stat/out/providers/async.d.ts +4 -0
  22. package/compiled/fast-glob/@nodelib/fs.stat/out/settings.d.ts +16 -0
  23. package/compiled/fast-glob/@nodelib/fs.stat/out/types/index.d.ts +4 -0
  24. package/compiled/fast-glob/@nodelib/fs.walk/out/index.d.ts +14 -0
  25. package/compiled/fast-glob/@nodelib/fs.walk/out/providers/async.d.ts +12 -0
  26. package/compiled/fast-glob/@nodelib/fs.walk/out/readers/async.d.ts +30 -0
  27. package/compiled/fast-glob/@nodelib/fs.walk/out/readers/reader.d.ts +6 -0
  28. package/compiled/fast-glob/@nodelib/fs.walk/out/settings.d.ts +30 -0
  29. package/compiled/fast-glob/@nodelib/fs.walk/out/types/index.d.ts +8 -0
  30. package/compiled/fast-glob/index.js +37 -0
  31. package/compiled/fast-glob/license +21 -0
  32. package/compiled/fast-glob/out/index.d.ts +27 -0
  33. package/compiled/fast-glob/out/managers/tasks.d.ts +22 -0
  34. package/compiled/fast-glob/out/settings.d.ts +164 -0
  35. package/compiled/fast-glob/out/types/index.d.ts +31 -0
  36. package/compiled/fast-glob/package.json +1 -0
  37. package/compiled/globby/@nodelib/fs.scandir/out/adapters/fs.d.ts +20 -0
  38. package/compiled/globby/@nodelib/fs.scandir/out/index.d.ts +12 -0
  39. package/compiled/globby/@nodelib/fs.scandir/out/providers/async.d.ts +7 -0
  40. package/compiled/globby/@nodelib/fs.scandir/out/settings.d.ts +20 -0
  41. package/compiled/globby/@nodelib/fs.scandir/out/types/index.d.ts +20 -0
  42. package/compiled/globby/@nodelib/fs.stat/out/adapters/fs.d.ts +13 -0
  43. package/compiled/globby/@nodelib/fs.stat/out/index.d.ts +12 -0
  44. package/compiled/globby/@nodelib/fs.stat/out/providers/async.d.ts +4 -0
  45. package/compiled/globby/@nodelib/fs.stat/out/settings.d.ts +16 -0
  46. package/compiled/globby/@nodelib/fs.stat/out/types/index.d.ts +4 -0
  47. package/compiled/globby/@nodelib/fs.walk/out/index.d.ts +14 -0
  48. package/compiled/globby/@nodelib/fs.walk/out/providers/async.d.ts +12 -0
  49. package/compiled/globby/@nodelib/fs.walk/out/readers/async.d.ts +30 -0
  50. package/compiled/globby/@nodelib/fs.walk/out/readers/reader.d.ts +6 -0
  51. package/compiled/globby/@nodelib/fs.walk/out/settings.d.ts +30 -0
  52. package/compiled/globby/@nodelib/fs.walk/out/types/index.d.ts +8 -0
  53. package/compiled/globby/fast-glob/index.d.ts +27 -0
  54. package/compiled/globby/fast-glob/managers/tasks.d.ts +22 -0
  55. package/compiled/globby/fast-glob/settings.d.ts +164 -0
  56. package/compiled/globby/fast-glob/types/index.d.ts +31 -0
  57. package/compiled/globby/index.d.ts +186 -0
  58. package/compiled/globby/index.js +1 -0
  59. package/compiled/globby/license +9 -0
  60. package/compiled/globby/package.json +1 -0
  61. package/compiled/inquirer/index.d.ts +997 -0
  62. package/compiled/inquirer/index.js +9 -0
  63. package/compiled/inquirer/lib/objects/choice.d.ts +65 -0
  64. package/compiled/inquirer/lib/objects/choices.d.ts +206 -0
  65. package/compiled/inquirer/lib/objects/separator.d.ts +37 -0
  66. package/compiled/inquirer/lib/ui/baseUI.d.ts +37 -0
  67. package/compiled/inquirer/lib/ui/bottom-bar.d.ts +65 -0
  68. package/compiled/inquirer/lib/ui/prompt.d.ts +104 -0
  69. package/compiled/inquirer/license +22 -0
  70. package/compiled/inquirer/package.json +1 -0
  71. package/compiled/inquirer/through/index.d.ts +25 -0
  72. package/compiled/json5/index.js +1 -0
  73. package/compiled/json5/lib/index.d.ts +4 -0
  74. package/compiled/json5/lib/parse.d.ts +15 -0
  75. package/compiled/json5/lib/stringify.d.ts +89 -0
  76. package/compiled/json5/package.json +1 -0
  77. package/compiled/mime-types/index.d.ts +14 -0
  78. package/compiled/mime-types/index.js +14 -0
  79. package/compiled/mime-types/license +23 -0
  80. package/compiled/mime-types/package.json +1 -0
  81. package/compiled/minimist/index.d.ts +95 -0
  82. package/compiled/minimist/index.js +1 -0
  83. package/compiled/minimist/license +18 -0
  84. package/compiled/minimist/package.json +1 -0
  85. package/compiled/ora/cli-spinners/index.d.ts +125 -0
  86. package/compiled/ora/index.d.ts +277 -0
  87. package/compiled/ora/index.js +3 -0
  88. package/compiled/ora/license +9 -0
  89. package/compiled/ora/package.json +1 -0
  90. package/compiled/slash/index.d.ts +25 -0
  91. package/compiled/slash/index.js +1 -0
  92. package/compiled/slash/license +9 -0
  93. package/compiled/slash/package.json +1 -0
  94. package/compiled/url-join/index.d.ts +17 -0
  95. package/compiled/url-join/index.js +1 -0
  96. package/compiled/url-join/license +21 -0
  97. package/compiled/url-join/package.json +1 -0
  98. package/dist/analyzeProject.d.ts +1 -0
  99. package/dist/analyzeProject.js +40 -0
  100. package/dist/compiled.d.ts +33 -17
  101. package/dist/compiled.js +57 -21
  102. package/dist/constants.d.ts +1 -1
  103. package/dist/constants.js +1 -1
  104. package/dist/index.d.ts +2 -2
  105. package/dist/index.js +2 -2
  106. package/dist/prettyInstructions.js +3 -3
  107. package/dist/{ssrHelpers.d.ts → ssr.d.ts} +3 -0
  108. package/dist/{ssrHelpers.js → ssr.js} +0 -0
  109. package/dist/storage.js +1 -1
  110. package/package.json +12 -30
  111. package/dist/getCacheIdentifier.d.ts +0 -7
  112. package/dist/getCacheIdentifier.js +0 -24
  113. package/dist/js/modern/monorepo.js +0 -83
  114. package/dist/js/node/monorepo.js +0 -116
  115. package/dist/js/treeshaking/monorepo.js +0 -96
  116. package/dist/pkgUp.d.ts +0 -2
  117. package/dist/pkgUp.js +0 -8
  118. package/dist/types/FileSizeReporter.d.ts +0 -16
  119. package/dist/types/alias.d.ts +0 -21
  120. package/dist/types/applyOptionsChain.d.ts +0 -6
  121. package/dist/types/clearConsole.d.ts +0 -1
  122. package/dist/types/compatRequire.d.ts +0 -8
  123. package/dist/types/compiled.d.ts +0 -17
  124. package/dist/types/constants.d.ts +0 -222
  125. package/dist/types/debug.d.ts +0 -6
  126. package/dist/types/emptyDir.d.ts +0 -1
  127. package/dist/types/ensureAbsolutePath.d.ts +0 -7
  128. package/dist/types/findExists.d.ts +0 -6
  129. package/dist/types/format.d.ts +0 -16
  130. package/dist/types/generateMetaTags.d.ts +0 -16
  131. package/dist/types/getBrowserslist.d.ts +0 -2
  132. package/dist/types/getCacheIdentifier.d.ts +0 -7
  133. package/dist/types/getEntryOptions.d.ts +0 -1
  134. package/dist/types/getPackageManager.d.ts +0 -1
  135. package/dist/types/getPort.d.ts +0 -7
  136. package/dist/types/getServerConfig.d.ts +0 -1
  137. package/dist/types/import.d.ts +0 -5
  138. package/dist/types/index.d.ts +0 -32
  139. package/dist/types/is/index.d.ts +0 -34
  140. package/dist/types/is/node-env.d.ts +0 -4
  141. package/dist/types/is/platform.d.ts +0 -2
  142. package/dist/types/is/type.d.ts +0 -8
  143. package/dist/types/logger.d.ts +0 -63
  144. package/dist/types/monorepo.d.ts +0 -11
  145. package/dist/types/nodeEnv.d.ts +0 -3
  146. package/dist/types/path.d.ts +0 -3
  147. package/dist/types/prettyInstructions.d.ts +0 -6
  148. package/dist/types/printBuildError.d.ts +0 -8
  149. package/dist/types/readTsConfig.d.ts +0 -2
  150. package/dist/types/removeSlash.d.ts +0 -3
  151. package/dist/types/runtimeExports.d.ts +0 -4
  152. package/dist/types/wait.d.ts +0 -2
  153. package/dist/types/watch.d.ts +0 -8
  154. package/modern.config.js +0 -6
  155. package/tests/.eslintrc.js +0 -6
  156. package/tests/__snapshots__/prettyInstructions.test.ts.snap +0 -19
  157. package/tests/applyOptionsChain.test.ts +0 -100
  158. package/tests/compatRequire.test.ts +0 -32
  159. package/tests/debug.test.ts +0 -25
  160. package/tests/ensureAbsolutePath.test.ts +0 -16
  161. package/tests/findExists.test.ts +0 -22
  162. package/tests/fixtures/browserlist/develop/package.json +0 -11
  163. package/tests/fixtures/browserlist/dotfile/.browserslistrc +0 -3
  164. package/tests/fixtures/browserlist/pkg/package.json +0 -7
  165. package/tests/fixtures/compat-require/cjs.js +0 -1
  166. package/tests/fixtures/compat-require/empty.js +0 -1
  167. package/tests/fixtures/compat-require/esm.js +0 -5
  168. package/tests/fixtures/compat-require/foo.js +0 -3
  169. package/tests/fixtures/file-exists/a.ejs +0 -0
  170. package/tests/fixtures/file-exists/a.js/.gitkeep +0 -0
  171. package/tests/fixtures/file-exists/a.mjs +0 -0
  172. package/tests/fixtures/file-exists/a.ts +0 -0
  173. package/tests/format.test.ts +0 -60
  174. package/tests/generateMetaTags.test.ts +0 -19
  175. package/tests/getBrowserslist.test.ts +0 -32
  176. package/tests/getCacheIdentifier.test.ts +0 -37
  177. package/tests/getEntryOptions.test.ts +0 -53
  178. package/tests/index.test.ts +0 -18
  179. package/tests/is.test.ts +0 -27
  180. package/tests/isPlatform.test.ts +0 -19
  181. package/tests/isType.test.ts +0 -85
  182. package/tests/logger.test.ts +0 -53
  183. package/tests/prettyInstructions.test.ts +0 -139
  184. package/tests/removeSlash.test.ts +0 -19
  185. package/tests/tsconfig.json +0 -11
  186. package/tests/wait.ts +0 -38
@@ -1,100 +0,0 @@
1
- import { applyOptionsChain } from '../src/applyOptionsChain';
2
-
3
- describe('apply options chain', () => {
4
- test(`should return default options`, () => {
5
- expect(applyOptionsChain({ default: 'a' })).toEqual({ default: 'a' });
6
- });
7
-
8
- test(`should merge default options`, () => {
9
- expect(
10
- applyOptionsChain(
11
- { name: 'a' },
12
- {
13
- name: 'b',
14
- custom: 'c',
15
- },
16
- ),
17
- ).toEqual({
18
- name: 'b',
19
- custom: 'c',
20
- });
21
- });
22
-
23
- test(`should support custom merge function`, () => {
24
- const merge = (target: any, source: any) => {
25
- for (const key in source) {
26
- if (target.hasOwnProperty(key)) {
27
- target[key] += source[key];
28
- } else {
29
- target[key] = source[key];
30
- }
31
- }
32
- return target;
33
- };
34
-
35
- expect(
36
- applyOptionsChain(
37
- {
38
- a: 1,
39
- b: 'b',
40
- },
41
- {
42
- a: 2,
43
- b: 'b',
44
- c: 'c',
45
- },
46
- {},
47
- merge,
48
- ),
49
- ).toEqual({
50
- a: 3,
51
- b: 'bb',
52
- c: 'c',
53
- });
54
- });
55
-
56
- test(`should support funciton or object array`, () => {
57
- const defaults = { a: 'a' };
58
-
59
- const options = [
60
- { b: 'b' },
61
- (o: any, { add }: { add: any }) => {
62
- o.c = add(1, 2);
63
- },
64
- (o: any) => ({
65
- ...o,
66
- d: 'd',
67
- }),
68
- { e: 'e' },
69
- ];
70
- expect(
71
- applyOptionsChain(defaults, options as any, {
72
- add: (a: any, b: any) => a + b,
73
- }),
74
- ).toEqual({
75
- a: 'a',
76
- b: 'b',
77
- c: 3,
78
- d: 'd',
79
- e: 'e',
80
- });
81
- });
82
-
83
- test(`should throw error`, () => {
84
- expect(() => {
85
- applyOptionsChain(1, 2);
86
- }).toThrow(/^applyOptionsChain error:/);
87
- });
88
-
89
- test(`should log warning about function result`, () => {
90
- let outputs = '';
91
- /* eslint-disable no-console */
92
- console.log = jest.fn(input => (outputs += input));
93
- /* eslint-enable no-console */
94
- applyOptionsChain({ name: 'a' } as any, [() => 111]);
95
-
96
- expect(outputs).toContain(
97
- 'Function should mutate the config and return nothing, Or return a cloned or merged version of config object.',
98
- );
99
- });
100
- });
@@ -1,32 +0,0 @@
1
- import path from 'path';
2
- import { compatRequire, cleanRequireCache } from '../src/compatRequire';
3
-
4
- describe('compat require', () => {
5
- const fixturePath = path.resolve(__dirname, './fixtures/compat-require');
6
-
7
- test(`should support default property`, () => {
8
- expect(compatRequire(path.join(fixturePath, 'esm.js'))).toEqual({
9
- name: 'esm',
10
- });
11
- });
12
-
13
- test(`should support commonjs module`, () => {
14
- expect(compatRequire(path.join(fixturePath, 'cjs.js'))).toEqual({
15
- name: 'cjs',
16
- });
17
- });
18
-
19
- test(`should return null`, () => {
20
- expect(compatRequire(path.join(fixturePath, 'empty.js'))).toEqual(null);
21
- });
22
-
23
- test('should clearn cache after fn', () => {
24
- const foo = module.require('./fixtures/compat-require/foo');
25
- const requirePath = require.resolve('./fixtures/compat-require/foo.js');
26
- expect(foo.name).toBe('foo');
27
- expect(require.cache[requirePath]).toBeDefined();
28
- cleanRequireCache([requirePath]);
29
- jest.resetModules();
30
- expect(require.cache[requirePath]).toBeUndefined();
31
- });
32
- });
@@ -1,25 +0,0 @@
1
- import { debug } from '../src/compiled';
2
- import { stripAnsi } from '../src';
3
- import { createDebugger } from '../src/debug';
4
-
5
- describe('debug utility', () => {
6
- test('should return file path', () => {
7
- const debug1 = createDebugger('test');
8
-
9
- const debug2 = createDebugger('test2');
10
-
11
- debug.enable('modern-js:test2');
12
-
13
- debug.log = (...args) => {
14
- // XXX: args[0] 的内容有时候是 ' \x1B[38;5;167;1mmodern-js:test2 \x1B[0m22222' 这种格式
15
- expect(stripAnsi(args[0])).toContain('modern-js:test2 22222');
16
- };
17
-
18
- debug1('11111');
19
- debug2('22222');
20
-
21
- expect(debug2.enabled).toBe(true);
22
-
23
- expect(debug1.enabled).toBe(false);
24
- });
25
- });
@@ -1,16 +0,0 @@
1
- import path from 'path';
2
- import { ensureAbsolutePath } from '../src/ensureAbsolutePath';
3
-
4
- describe('ensure absolute file path', () => {
5
- test('should return filePath directly', () => {
6
- expect(
7
- path.isAbsolute(ensureAbsolutePath('/a/b', '/a/b/c/d/e.jsx')),
8
- ).toBeTruthy();
9
- });
10
-
11
- test(`should resolve absolute path`, () => {
12
- expect(
13
- path.isAbsolute(ensureAbsolutePath('/a/b', 'c/d/e.jsx')),
14
- ).toBeTruthy();
15
- });
16
- });
@@ -1,22 +0,0 @@
1
- import path from 'path';
2
- import { findExists } from '../src/findExists';
3
-
4
- describe('find first exists file', () => {
5
- const fixturePath = path.resolve(__dirname, './fixtures/file-exists');
6
-
7
- test('should return file path', () => {
8
- expect(
9
- findExists(
10
- ['.js', '.ts', '.ejs', '.mjs'].map(ext =>
11
- path.join(fixturePath, `a${ext}`),
12
- ),
13
- ),
14
- ).toEqual(path.join(fixturePath, 'a.ts'));
15
- });
16
-
17
- test('should return false when no file exists', () => {
18
- expect(
19
- findExists(['.jsx'].map(ext => path.join(fixturePath, `a${ext}`))),
20
- ).toBe(false);
21
- });
22
- });
@@ -1,11 +0,0 @@
1
- {
2
- "name": "test-browserlist-develop",
3
- "browserslist": {
4
- "development": [
5
- "last 1 chrome version"
6
- ],
7
- "production": [
8
- "IOS 7"
9
- ]
10
- }
11
- }
@@ -1,3 +0,0 @@
1
- defaults
2
- not IE 11
3
- maintained node versions
@@ -1,7 +0,0 @@
1
- {
2
- "name": "test-browserlist-pkg",
3
- "browserslist": [
4
- "not IE 11",
5
- "maintained node versions"
6
- ]
7
- }
@@ -1 +0,0 @@
1
- module.exports = { name: 'cjs' };
@@ -1 +0,0 @@
1
- module.exports = null;
@@ -1,5 +0,0 @@
1
- Object.defineProperty(exports, '__esModule', { value: true });
2
-
3
- const _default = { name: 'esm' };
4
-
5
- exports.default = _default;
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- name: 'foo',
3
- };
File without changes
File without changes
File without changes
File without changes
@@ -1,60 +0,0 @@
1
- import { formatProxyOptions } from '../src/format';
2
-
3
- describe('test format', () => {
4
- it('should format correctly use simply options', async () => {
5
- const proxy = {
6
- '/simple': `http://localhost`,
7
- };
8
-
9
- const options = formatProxyOptions(proxy);
10
- expect(options).toEqual([
11
- {
12
- context: '/simple',
13
- changeOrigin: true,
14
- logLevel: 'warn',
15
- target: 'http://localhost',
16
- },
17
- ]);
18
- });
19
-
20
- it('should format correctly use simply options', async () => {
21
- const proxy = {
22
- '/simple-obj': {
23
- target: `http://localhost`,
24
- },
25
- };
26
- const options = formatProxyOptions(proxy);
27
- expect(options).toEqual([
28
- {
29
- context: '/simple-obj',
30
- changeOrigin: true,
31
- logLevel: 'warn',
32
- target: 'http://localhost',
33
- },
34
- ]);
35
- });
36
-
37
- it('should format correctly use simply options', async () => {
38
- const proxy = {
39
- context: '/context',
40
- target: `http://localhost`,
41
- };
42
- const options = formatProxyOptions(proxy);
43
- expect(options).toEqual([
44
- { context: '/context', target: 'http://localhost' },
45
- ]);
46
- });
47
-
48
- it('should format correctly use simply options', async () => {
49
- const proxy = [
50
- {
51
- context: '/array',
52
- target: `http://localhost`,
53
- },
54
- ];
55
- const options = formatProxyOptions(proxy);
56
- expect(options).toEqual([
57
- { context: '/array', target: 'http://localhost' },
58
- ]);
59
- });
60
- });
@@ -1,19 +0,0 @@
1
- import { generateMetaTags } from '../src/generateMetaTags';
2
-
3
- describe('generateMetaTags', () => {
4
- it('should return empty string when params is empty', () => {
5
- expect(generateMetaTags()).toEqual('');
6
- });
7
-
8
- it('should generate meta tag correctly', () => {
9
- const options = {
10
- foo: {
11
- name: 'viewport',
12
- content: 'width=500, initial-scale=1',
13
- },
14
- };
15
- expect(generateMetaTags(options).trim()).toEqual(
16
- '<meta name="viewport" content="width=500, initial-scale=1">',
17
- );
18
- });
19
- });
@@ -1,32 +0,0 @@
1
- import path from 'path';
2
- import { getBrowserslist, defaults } from '../src/getBrowserslist';
3
-
4
- describe('get browserslist', () => {
5
- const fixture = path.resolve(__dirname, './fixtures/browserlist');
6
-
7
- test(`should load browserslist from package.json`, () => {
8
- expect(getBrowserslist(path.join(fixture, 'pkg'))).toEqual([
9
- 'not IE 11',
10
- 'maintained node versions',
11
- ]);
12
- });
13
-
14
- test(`should load browerslist from .browserslistrc`, () => {
15
- expect(getBrowserslist(path.join(fixture, 'dotfile'))).toEqual([
16
- 'defaults',
17
- 'not IE 11',
18
- 'maintained node versions',
19
- ]);
20
- });
21
-
22
- test(`should load browserslist base on environment`, () => {
23
- process.env.NODE_ENV = 'development';
24
- expect(getBrowserslist(path.join(fixture, 'develop'))).toEqual([
25
- 'last 1 chrome version',
26
- ]);
27
- });
28
-
29
- test(`should return default browserslist config`, () => {
30
- expect(getBrowserslist(path.join(fixture))).toEqual(defaults);
31
- });
32
- });
@@ -1,37 +0,0 @@
1
- import { getCacheIdentifier } from '../src/getCacheIdentifier';
2
-
3
- describe('get cache identifier', () => {
4
- test('should use package name and version', () => {
5
- expect(
6
- getCacheIdentifier([
7
- {
8
- name: 'package-a',
9
- version: '0.1.0',
10
- },
11
- {
12
- name: 'package-b',
13
- version: '1.0.1',
14
- },
15
- ]),
16
- ).toEqual(`test:package-a@0.1.0:package-b@1.0.1`);
17
- });
18
-
19
- test(`should return identifier with node environment`, () => {
20
- const packages = [
21
- {
22
- name: 'a',
23
- version: '0.1.0',
24
- },
25
- ];
26
-
27
- process.env.NODE_ENV = 'development';
28
- expect(getCacheIdentifier(packages)).toEqual('development:a@0.1.0');
29
-
30
- process.env.NODE_ENV = 'production';
31
- expect(getCacheIdentifier(packages)).toEqual('production:a@0.1.0');
32
-
33
- process.env.NODE_ENV = '';
34
-
35
- expect(getCacheIdentifier(packages)).toEqual(`:a@0.1.0`);
36
- });
37
- });
@@ -1,53 +0,0 @@
1
- import { getEntryOptions } from '../src/getEntryOptions';
2
-
3
- describe('get entry options', () => {
4
- test('should return default options', () => {
5
- expect(getEntryOptions('page-a', 'default value')).toEqual('default value');
6
-
7
- expect(
8
- getEntryOptions('page-a', 'default value', { 'page-b': 'a' }),
9
- ).toEqual('default value');
10
- });
11
-
12
- test(`should return options from optionsByEntries`, () => {
13
- expect(
14
- getEntryOptions('page-a', 'default value', { 'page-a': 'a' }),
15
- ).toEqual('a');
16
- });
17
-
18
- test(`should compatible with main entry using packageName as key`, () => {
19
- expect(
20
- getEntryOptions(
21
- 'main',
22
- 'default value',
23
- { 'package-name': 'a' },
24
- 'package-name',
25
- ),
26
- ).toEqual('a');
27
- });
28
-
29
- expect(
30
- getEntryOptions(
31
- 'page-a',
32
- { name: 'a' },
33
- {
34
- 'page-a': {
35
- name: 'page-a',
36
- about: 'b',
37
- },
38
- },
39
- ),
40
- ).toEqual({
41
- name: 'page-a',
42
- about: 'b',
43
- });
44
-
45
- expect(
46
- getEntryOptions<
47
- | {
48
- [name: string]: string;
49
- }
50
- | boolean
51
- >('page-a', { name: 'a' }, { 'page-a': false }),
52
- ).toEqual(false);
53
- });
@@ -1,18 +0,0 @@
1
- import { canUseNpm, canUsePnpm, canUseYarn } from '../src';
2
-
3
- jest.setTimeout(40000);
4
-
5
- describe('test generator utils', () => {
6
- test('test canUseNpm', async () => {
7
- const npmAbility = await canUseNpm();
8
- expect(typeof npmAbility === 'boolean').toBe(true);
9
- });
10
- test('test canUsePnpm', async () => {
11
- const pnpmAbility = await canUsePnpm();
12
- expect(typeof pnpmAbility === 'boolean').toBe(true);
13
- });
14
- test('test canUseYarn', async () => {
15
- const yarnAbility = await canUseYarn();
16
- expect(typeof yarnAbility === 'boolean').toBe(true);
17
- });
18
- });
package/tests/is.test.ts DELETED
@@ -1,27 +0,0 @@
1
- import { isEmpty, isFastRefresh } from '../src/is';
2
-
3
- describe('validate', () => {
4
- it('should validate empty object correctly', () => {
5
- expect(isEmpty({})).toBeTruthy();
6
- expect(isEmpty({ foo: 'bar' })).toBeFalsy();
7
- });
8
-
9
- it('should validate fast refresh correctly', () => {
10
- const { NODE_ENV, FAST_REFRESH } = process.env;
11
-
12
- process.env.NODE_ENV = 'development';
13
- process.env.FAST_REFRESH = 'true';
14
- expect(isFastRefresh()).toBeTruthy();
15
-
16
- process.env.NODE_ENV = 'production';
17
- process.env.FAST_REFRESH = 'true';
18
- expect(isFastRefresh()).toBeFalsy();
19
-
20
- process.env.NODE_ENV = 'development';
21
- process.env.FAST_REFRESH = 'false';
22
- expect(isFastRefresh()).toBeFalsy();
23
-
24
- process.env.NODE_ENV = NODE_ENV;
25
- process.env.FAST_REFRESH = FAST_REFRESH;
26
- });
27
- });
@@ -1,19 +0,0 @@
1
- import { isNodeJS, isBrowser } from '../src/is/platform';
2
-
3
- describe('validate platform', () => {
4
- it('should validate Node.js correctly', () => {
5
- expect(isNodeJS()).toBeTruthy();
6
- });
7
-
8
- it('should validate browser correctly', () => {
9
- const windowSpy = jest.spyOn(window, 'window', 'get');
10
-
11
- windowSpy.mockImplementation((): any => undefined);
12
- expect(isBrowser()).toBeFalsy();
13
-
14
- windowSpy.mockImplementation((): any => global);
15
- expect(isBrowser()).toBeTruthy();
16
-
17
- windowSpy.mockRestore();
18
- });
19
- });
@@ -1,85 +0,0 @@
1
- import {
2
- isArray,
3
- isObject,
4
- isString,
5
- isRegExp,
6
- isPromise,
7
- isUndefined,
8
- isPlainObject,
9
- } from '../src/is/type';
10
-
11
- describe('validate type', () => {
12
- it('should validate string correctly', () => {
13
- expect(isString('')).toBeTruthy();
14
- expect(isString('foo')).toBeTruthy();
15
- expect(isString(null)).toBeFalsy();
16
- expect(isString(123)).toBeFalsy();
17
- });
18
-
19
- it('should validate undefined correctly', () => {
20
- expect(isUndefined(undefined)).toBeTruthy();
21
- expect(isUndefined(null)).toBeFalsy();
22
- expect(isUndefined('')).toBeFalsy();
23
- expect(isUndefined(123)).toBeFalsy();
24
- });
25
-
26
- it('should validate array correctly', () => {
27
- expect(isArray(undefined)).toBeFalsy();
28
- expect(isArray(null)).toBeFalsy();
29
- expect(isArray('')).toBeFalsy();
30
- expect(isArray(123)).toBeFalsy();
31
- expect(isArray({})).toBeFalsy();
32
- expect(isArray([])).toBeTruthy();
33
- });
34
-
35
- it('should validate object correctly', () => {
36
- expect(isObject(1)).toBeFalsy();
37
- expect(isObject('1')).toBeFalsy();
38
- expect(isObject(undefined)).toBeFalsy();
39
- expect(isObject(null)).toBeFalsy();
40
- // eslint-disable-next-line @typescript-eslint/no-empty-function
41
- expect(isObject(() => {})).toBeFalsy();
42
- expect(isObject({})).toBeTruthy();
43
- expect(isObject([])).toBeTruthy();
44
- expect(isObject(/foo/)).toBeTruthy();
45
- });
46
-
47
- it('should validate plain object correctly', () => {
48
- expect(isPlainObject(1)).toBeFalsy();
49
- expect(isPlainObject('1')).toBeFalsy();
50
- expect(isPlainObject(undefined)).toBeFalsy();
51
- expect(isPlainObject(null)).toBeFalsy();
52
- // eslint-disable-next-line @typescript-eslint/no-empty-function
53
- expect(isPlainObject(() => {})).toBeFalsy();
54
- expect(isPlainObject({})).toBeTruthy();
55
- expect(isPlainObject([])).toBeFalsy();
56
- expect(isPlainObject(/foo/)).toBeFalsy();
57
- });
58
-
59
- it('should validate RegExp correctly', () => {
60
- expect(isRegExp(1)).toBeFalsy();
61
- expect(isRegExp('1')).toBeFalsy();
62
- expect(isRegExp(undefined)).toBeFalsy();
63
- expect(isRegExp(null)).toBeFalsy();
64
- expect(isRegExp({})).toBeFalsy();
65
- expect(isRegExp([])).toBeFalsy();
66
- expect(isRegExp(/foo/)).toBeTruthy();
67
- });
68
-
69
- it('should validate Promise correctly', () => {
70
- expect(isPromise(1)).toBeFalsy();
71
- expect(isPromise('1')).toBeFalsy();
72
- expect(isPromise(undefined)).toBeFalsy();
73
- expect(isPromise(null)).toBeFalsy();
74
- expect(isPromise({})).toBeFalsy();
75
- expect(isPromise([])).toBeFalsy();
76
- expect(isPromise(/foo/)).toBeFalsy();
77
- expect(
78
- isPromise(
79
- new Promise<void>(resolve => {
80
- resolve();
81
- }),
82
- ),
83
- ).toBeTruthy();
84
- });
85
- });
@@ -1,53 +0,0 @@
1
- import { logger } from '../src/logger';
2
-
3
- describe('logger', () => {
4
- test('should log', () => {
5
- // eslint-disable-next-line no-console
6
- console.log = jest.fn();
7
-
8
- logger.log('this is a log message');
9
-
10
- // eslint-disable-next-line no-console
11
- expect((console.log as jest.Mock).mock.calls[0][0]).toBe(
12
- 'this is a log message',
13
- );
14
-
15
- logger.info('this is an info message');
16
-
17
- logger.warn('this is a warn message');
18
-
19
- logger.error(new Error('this is an error message'));
20
-
21
- // eslint-disable-next-line no-console
22
- expect(console.log as jest.Mock).toHaveBeenCalledTimes(4);
23
- });
24
-
25
- test('should create new logger', () => {
26
- // eslint-disable-next-line no-console
27
- console.log = jest.fn();
28
-
29
- const customLogger = new logger.Logger({
30
- config: {
31
- displayLabel: true,
32
- underlineLabel: false,
33
- uppercaseLabel: false,
34
- },
35
- types: {
36
- custom: {
37
- color: 'blue',
38
- label: 'custom',
39
- level: 'info',
40
- },
41
- },
42
- });
43
-
44
- customLogger.custom('custom log');
45
-
46
- const reg = new RegExp(`custom.*custom log$`);
47
- // eslint-disable-next-line no-console
48
- expect((console.log as jest.Mock).mock.calls[0][0]).toMatch(reg);
49
-
50
- // eslint-disable-next-line no-console
51
- expect(console.log as jest.Mock).toHaveBeenCalledTimes(1);
52
- });
53
- });