@modern-js/utils 1.1.6-alpha.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @modern-js/utils
2
2
 
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - cfe11628: Make Modern.js self bootstraping
8
+
9
+ ### Patch Changes
10
+
11
+ - 2da09c69: Add "typescript" to the dependency list
12
+ - c3d46ee4: fix: test config invalid
13
+
14
+ ## 1.1.6
15
+
16
+ ### Patch Changes
17
+
18
+ - b7fb82ec: fix: get package manager function
19
+
3
20
  ## 1.1.5
4
21
 
5
22
  ### Patch Changes
@@ -297,7 +297,7 @@ export const PLUGIN_SCHEMAS = {
297
297
  }, {
298
298
  target: 'tools.jest',
299
299
  schema: {
300
- typeof: ['object']
300
+ typeof: ['object', 'function']
301
301
  }
302
302
  }],
303
303
  '@modern-js/plugin-micro-frontend': [{
@@ -1,4 +1,4 @@
1
- import { loadConfig } from 'browserslist/node';
1
+ import { loadConfig } from 'browserslist';
2
2
  export const defaults = ['> 0.01%', 'not dead', 'not op_mini all'];
3
3
  export const getBrowserslist = appDirectory => loadConfig({
4
4
  path: appDirectory
@@ -21,7 +21,7 @@ const getAddressUrls = (protocol = 'http', port) => {
21
21
  let type = 'Network: ';
22
22
  let url = `${protocol}://${detail.address}:${port}`;
23
23
 
24
- if (detail.address.includes(`127.0.0.1`)) {
24
+ if (detail.address.includes(`localhost`)) {
25
25
  type = 'Local: ';
26
26
  url = `${protocol}://localhost:${port}`;
27
27
  }
@@ -319,7 +319,7 @@ const PLUGIN_SCHEMAS = {
319
319
  }, {
320
320
  target: 'tools.jest',
321
321
  schema: {
322
- typeof: ['object']
322
+ typeof: ['object', 'function']
323
323
  }
324
324
  }],
325
325
  '@modern-js/plugin-micro-frontend': [{
@@ -5,12 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getBrowserslist = exports.defaults = void 0;
7
7
 
8
- var _node = require("browserslist/node");
8
+ var _browserslist = require("browserslist");
9
9
 
10
10
  const defaults = ['> 0.01%', 'not dead', 'not op_mini all'];
11
11
  exports.defaults = defaults;
12
12
 
13
- const getBrowserslist = appDirectory => (0, _node.loadConfig)({
13
+ const getBrowserslist = appDirectory => (0, _browserslist.loadConfig)({
14
14
  path: appDirectory
15
15
  }) || defaults;
16
16
 
@@ -35,7 +35,7 @@ const getAddressUrls = (protocol = 'http', port) => {
35
35
  let type = 'Network: ';
36
36
  let url = `${protocol}://${detail.address}:${port}`;
37
37
 
38
- if (detail.address.includes(`127.0.0.1`)) {
38
+ if (detail.address.includes(`localhost`)) {
39
39
  type = 'Local: ';
40
40
  url = `${protocol}://localhost:${port}`;
41
41
  }
@@ -297,7 +297,7 @@ export var PLUGIN_SCHEMAS = {
297
297
  }, {
298
298
  target: 'tools.jest',
299
299
  schema: {
300
- "typeof": ['object']
300
+ "typeof": ['object', 'function']
301
301
  }
302
302
  }],
303
303
  '@modern-js/plugin-micro-frontend': [{
@@ -1,4 +1,4 @@
1
- import { loadConfig } from 'browserslist/node';
1
+ import { loadConfig } from 'browserslist';
2
2
  export var defaults = ['> 0.01%', 'not dead', 'not op_mini all'];
3
3
  export var getBrowserslist = function getBrowserslist(appDirectory) {
4
4
  return loadConfig({
@@ -39,7 +39,7 @@ var getAddressUrls = function getAddressUrls() {
39
39
  var type = 'Network: ';
40
40
  var url = "".concat(protocol, "://").concat(detail.address, ":").concat(port);
41
41
 
42
- if (detail.address.includes("127.0.0.1")) {
42
+ if (detail.address.includes("localhost")) {
43
43
  type = 'Local: ';
44
44
  url = "".concat(protocol, "://localhost:").concat(port);
45
45
  }
@@ -1,2 +1,2 @@
1
1
  export declare const defaults: string[];
2
- export declare const getBrowserslist: (appDirectory: string) => any;
2
+ export declare const getBrowserslist: (appDirectory: string) => string[];
package/jest.config.js ADDED
@@ -0,0 +1,8 @@
1
+ const sharedConfig = require('@scripts/jest-config');
2
+
3
+ /** @type {import('@jest/types').Config.InitialOptions} */
4
+ module.exports = {
5
+ // eslint-disable-next-line node/no-unsupported-features/es-syntax
6
+ ...sharedConfig,
7
+ rootDir: __dirname,
8
+ };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.1.6-alpha.0",
14
+ "version": "1.2.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -20,13 +20,20 @@
20
20
  "exports": {
21
21
  ".": {
22
22
  "node": {
23
+ "jsnext:source": "./src/index.ts",
23
24
  "import": "./dist/js/modern/index.js",
24
25
  "require": "./dist/js/node/index.js"
25
26
  },
26
27
  "default": "./dist/js/treeshaking/index.js"
27
28
  },
28
- "./formatWebpackMessages": "./dist/js/treeshaking/formatWebpackMessages.js",
29
- "./constants": "./dist/js/treeshaking/constants.js"
29
+ "./formatWebpackMessages": {
30
+ "jsnext:source": "./src/formatWebpackMessages.ts",
31
+ "default": "./dist/js/treeshaking/formatWebpackMessages.js"
32
+ },
33
+ "./constants": {
34
+ "jsnext:source": "./src/constants.ts",
35
+ "default": "./dist/js/treeshaking/constants.js"
36
+ }
30
37
  },
31
38
  "typesVersions": {
32
39
  "*": {
@@ -55,7 +62,8 @@
55
62
  "strip-ansi": "6.0.0",
56
63
  "upath": "^2.0.1",
57
64
  "yaml": "^1.10.2",
58
- "execa": "5"
65
+ "execa": "5",
66
+ "typescript": "^4"
59
67
  },
60
68
  "devDependencies": {
61
69
  "@types/debug": "^4.1.7",
@@ -64,22 +72,21 @@
64
72
  "@types/jest": "^26",
65
73
  "@types/node": "^14",
66
74
  "@types/recursive-readdir": "^2.2.0",
67
- "typescript": "^4",
68
75
  "webpack": "^5.54.0",
69
- "@modern-js/plugin-testing": "^1.2.0",
70
- "@modern-js/module-tools": "^1.1.3"
71
- },
72
- "peerDependencies": {
73
- "typescript": "^4.4.3"
76
+ "@scripts/build": "0.0.0",
77
+ "jest": "^27",
78
+ "@scripts/jest-config": "0.0.0"
74
79
  },
75
80
  "sideEffects": false,
76
81
  "publishConfig": {
77
82
  "registry": "https://registry.npmjs.org/",
78
- "access": "public"
83
+ "access": "public",
84
+ "types": "./dist/types/index.d.ts"
79
85
  },
80
86
  "scripts": {
81
87
  "new": "modern new",
82
88
  "build": "modern build",
83
- "test": "modern test --passWithNoTests"
84
- }
89
+ "test": "jest --passWithNoTests"
90
+ },
91
+ "readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
85
92
  }
package/src/constants.ts CHANGED
@@ -245,7 +245,7 @@ export const PLUGIN_SCHEMAS = {
245
245
  },
246
246
  {
247
247
  target: 'tools.jest',
248
- schema: { typeof: ['object'] },
248
+ schema: { typeof: ['object', 'function'] },
249
249
  },
250
250
  ],
251
251
  '@modern-js/plugin-micro-frontend': [
@@ -1,4 +1,4 @@
1
- import { loadConfig } from 'browserslist/node';
1
+ import { loadConfig } from 'browserslist';
2
2
 
3
3
  export const defaults = ['> 0.01%', 'not dead', 'not op_mini all'];
4
4
 
@@ -34,7 +34,7 @@ const getAddressUrls = (protocol = 'http', port: number) => {
34
34
  (memo: { type: string; url: string }[], detail) => {
35
35
  let type = 'Network: ';
36
36
  let url = `${protocol}://${detail.address}:${port}`;
37
- if (detail.address.includes(`127.0.0.1`)) {
37
+ if (detail.address.includes(`localhost`)) {
38
38
  type = 'Local: ';
39
39
  url = `${protocol}://localhost:${port}`;
40
40
  }
@@ -1,4 +1,4 @@
1
- import { applyOptionsChain } from '@/applyOptionsChain';
1
+ import { applyOptionsChain } from '../src/applyOptionsChain';
2
2
 
3
3
  describe('apply options chain', () => {
4
4
  test(`should return default options`, () => {
@@ -1,5 +1,5 @@
1
1
  import path from 'path';
2
- import { compatRequire } from '@/compatRequire';
2
+ import { compatRequire } from '../src/compatRequire';
3
3
 
4
4
  describe('compat require', () => {
5
5
  const fixturePath = path.resolve(__dirname, './fixtures/compat-require');
@@ -1,5 +1,6 @@
1
1
  import debug from 'debug';
2
- import { createDebugger } from '@/debug';
2
+ import stripAnsi from 'strip-ansi';
3
+ import { createDebugger } from '../src/debug';
3
4
 
4
5
  describe('debug utility', () => {
5
6
  test('should return file path', () => {
@@ -10,7 +11,8 @@ describe('debug utility', () => {
10
11
  debug.enable('modern-js:test2');
11
12
 
12
13
  debug.log = (...args) => {
13
- expect(args[0]).toContain('modern-js:test2 22222');
14
+ // XXX: args[0] 的内容有时候是 ' \x1B[38;5;167;1mmodern-js:test2 \x1B[0m22222' 这种格式
15
+ expect(stripAnsi(args[0])).toContain('modern-js:test2 22222');
14
16
  };
15
17
 
16
18
  debug1('11111');
@@ -1,5 +1,5 @@
1
1
  import path from 'path';
2
- import { ensureAbsolutePath } from '@/ensureAbsolutePath';
2
+ import { ensureAbsolutePath } from '../src/ensureAbsolutePath';
3
3
 
4
4
  describe('ensure absolute file path', () => {
5
5
  test('should return filePath directly', () => {
@@ -1,5 +1,5 @@
1
1
  import path from 'path';
2
- import { findExists } from '@/findExists';
2
+ import { findExists } from '../src/findExists';
3
3
 
4
4
  describe('find first exists file', () => {
5
5
  const fixturePath = path.resolve(__dirname, './fixtures/file-exists');
@@ -1,5 +1,5 @@
1
1
  import path from 'path';
2
- import { getBrowserslist, defaults } from '@/getBrowserslist';
2
+ import { getBrowserslist, defaults } from '../src/getBrowserslist';
3
3
 
4
4
  describe('get browserslist', () => {
5
5
  const fixture = path.resolve(__dirname, './fixtures/browserlist');
@@ -1,4 +1,4 @@
1
- import { getCacheIdentifier } from '@/getCacheIdentifier';
1
+ import { getCacheIdentifier } from '../src/getCacheIdentifier';
2
2
 
3
3
  describe('get cache identifier', () => {
4
4
  test('should use package name and version', () => {
@@ -1,4 +1,4 @@
1
- import { getEntryOptions } from '@/getEntryOptions';
1
+ import { getEntryOptions } from '../src/getEntryOptions';
2
2
 
3
3
  describe('get entry options', () => {
4
4
  test('should return default options', () => {
@@ -0,0 +1,16 @@
1
+ import { canUseNpm, canUsePnpm, canUseYarn } from '../src';
2
+
3
+ describe('test generator utils', () => {
4
+ test('test canUseNpm', async () => {
5
+ const npmAbility = await canUseNpm();
6
+ expect(typeof npmAbility === 'boolean').toBe(true);
7
+ });
8
+ test('test canUsePnpm', async () => {
9
+ const pnpmAbility = await canUsePnpm();
10
+ expect(typeof pnpmAbility === 'boolean').toBe(true);
11
+ });
12
+ test('test canUseYarn', async () => {
13
+ const yarnAbility = await canUseYarn();
14
+ expect(typeof yarnAbility === 'boolean').toBe(true);
15
+ });
16
+ });
@@ -1,4 +1,4 @@
1
- import { logger } from '@/logger';
1
+ import { logger } from '../src/logger';
2
2
 
3
3
  describe('logger', () => {
4
4
  test('should log', () => {
@@ -2,7 +2,7 @@ import {
2
2
  removeLeadingSlash,
3
3
  removeSlash,
4
4
  removeTailSlash,
5
- } from '@/removeSlash';
5
+ } from '../src/removeSlash';
6
6
 
7
7
  describe('remove slash', () => {
8
8
  test(`should remove leading slash`, () => {
@@ -5,9 +5,7 @@
5
5
  "jsx": "preserve",
6
6
  "baseUrl": "./",
7
7
  "isolatedModules": true,
8
- "paths": {
9
- "@/*": ["../src/*"]
10
- },
8
+ "paths": {},
11
9
  "types": ["node", "jest"]
12
10
  }
13
11
  }
package/tsconfig.json CHANGED
@@ -6,9 +6,7 @@
6
6
  "jsx": "preserve",
7
7
  "baseUrl": "./",
8
8
  "isolatedModules": true,
9
- "paths": {
10
- "@/*": ["./src/*"]
11
- }
9
+ "paths": {}
12
10
  },
13
11
  "include": ["src"]
14
12
  }