@modern-js/generator-utils 1.1.3 → 1.2.2

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/.eslintrc.js ADDED
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ root: true,
3
+ extends: ['@modern-js'],
4
+ parserOptions: {
5
+ tsconfigRootDir: __dirname,
6
+ project: ['./tsconfig.json'],
7
+ },
8
+ };
package/CHANGELOG.md CHANGED
@@ -1,5 +1,46 @@
1
1
  # @modern-js/generator-utils
2
2
 
3
+ ## 1.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 6cffe99d: chore:
8
+ remove react eslint rules for `modern-js` rule set.
9
+ add .eslintrc for each package to speed up linting
10
+ - 04ae5262: chore: bump @modern-js/utils to v1.4.1 in dependencies
11
+ - 60f7d8bf: feat: add tests dir to npmignore
12
+ - Updated dependencies [b8599d09]
13
+ - Updated dependencies [6cffe99d]
14
+ - Updated dependencies [04ae5262]
15
+ - Updated dependencies [60f7d8bf]
16
+ - Updated dependencies [3bf4f8b0]
17
+ - @modern-js/utils@1.5.0
18
+ - @modern-js/plugin-i18n@1.2.4
19
+
20
+ ## 1.2.1
21
+
22
+ ### Patch Changes
23
+
24
+ - 83166714: change .npmignore
25
+ - Updated dependencies [83166714]
26
+ - @modern-js/plugin-i18n@1.2.1
27
+ - @modern-js/utils@1.2.2
28
+
29
+ ## 1.2.0
30
+
31
+ ### Minor Changes
32
+
33
+ - cfe11628: Make Modern.js self bootstraping
34
+
35
+ ### Patch Changes
36
+
37
+ - 2c049918: feat: polyfill function support enable using new command
38
+ - Updated dependencies [2da09c69]
39
+ - Updated dependencies [c3d46ee4]
40
+ - Updated dependencies [cfe11628]
41
+ - @modern-js/utils@1.2.0
42
+ - @modern-js/plugin-i18n@1.2.0
43
+
3
44
  ## 1.1.3
4
45
 
5
46
  ### Patch Changes
@@ -1,13 +1,11 @@
1
1
  import path from 'path';
2
- import { fs, getMonorepoPackages, canUseNpm, canUsePnpm, canUseYarn } from '@modern-js/utils';
3
- import execa from 'execa';
2
+ import { fs, execa, getMonorepoPackages, canUseNpm, canUsePnpm, canUseYarn } from '@modern-js/utils';
4
3
  import ora from 'ora';
5
4
  import { stripAnsi } from "./utils/strip-ansi";
6
5
  import { i18n, localeKeys } from "./locale";
7
6
  export * from "./utils";
8
7
  export { fs, readTsConfigByFile, getPackageManager, canUseNpm, canUsePnpm, canUseYarn } from '@modern-js/utils';
9
- export { i18n } from "./locale"; // eslint-disable-next-line max-statements
10
-
8
+ export { i18n } from "./locale";
11
9
  export async function getPackageVersion(packageName, registry) {
12
10
  const spinner = ora('Loading...').start();
13
11
  spinner.color = 'yellow';
@@ -77,8 +77,6 @@ var _path = _interopRequireDefault(require("path"));
77
77
 
78
78
  var _utils = require("@modern-js/utils");
79
79
 
80
- var _execa = _interopRequireDefault(require("execa"));
81
-
82
80
  var _ora = _interopRequireDefault(require("ora"));
83
81
 
84
82
  var _stripAnsi = require("./utils/strip-ansi");
@@ -101,7 +99,6 @@ Object.keys(_utils2).forEach(function (key) {
101
99
 
102
100
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
103
101
 
104
- // eslint-disable-next-line max-statements
105
102
  async function getPackageVersion(packageName, registry) {
106
103
  const spinner = (0, _ora.default)('Loading...').start();
107
104
  spinner.color = 'yellow';
@@ -113,7 +110,7 @@ async function getPackageVersion(packageName, registry) {
113
110
  args.push(`--registry=${registry}`);
114
111
  }
115
112
 
116
- const result = await (0, _execa.default)('pnpm', args);
113
+ const result = await (0, _utils.execa)('pnpm', args);
117
114
  spinner.stop();
118
115
  return (0, _stripAnsi.stripAnsi)(result.stdout);
119
116
  }
@@ -125,7 +122,7 @@ async function getPackageVersion(packageName, registry) {
125
122
  args.push(`--registry=${registry}`);
126
123
  }
127
124
 
128
- const result = await (0, _execa.default)('yarn', args);
125
+ const result = await (0, _utils.execa)('yarn', args);
129
126
  spinner.stop();
130
127
  return (0, _stripAnsi.stripAnsi)(result.stdout);
131
128
  }
@@ -137,7 +134,7 @@ async function getPackageVersion(packageName, registry) {
137
134
  args.push(`--registry=${registry}`);
138
135
  }
139
136
 
140
- const result = await (0, _execa.default)('npm', args);
137
+ const result = await (0, _utils.execa)('npm', args);
141
138
  spinner.stop();
142
139
  return (0, _stripAnsi.stripAnsi)(result.stdout);
143
140
  }
package/jest.config.js ADDED
@@ -0,0 +1,11 @@
1
+ const sharedConfig = require('@scripts/jest-config');
2
+
3
+ /** @type {import('@jest/types').Config.InitialOptions} */
4
+ module.exports = {
5
+ ...sharedConfig,
6
+ rootDir: __dirname,
7
+ modulePathIgnorePatterns: [
8
+ // TODO: 很容易超时导致失败,暂时先绕过
9
+ 'tests/index.test.ts',
10
+ ],
11
+ };
package/modern.config.js CHANGED
@@ -1,8 +1,2 @@
1
1
  /** @type {import('@modern-js/module-tools').UserConfig} */
2
- module.exports = {
3
- testing: {
4
- jest: {
5
- testTimeout: 30000,
6
- },
7
- },
8
- };
2
+ module.exports = {};
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.1.3",
14
+ "version": "1.2.2",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -29,9 +29,8 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@babel/runtime": "^7",
32
- "@modern-js/plugin-i18n": "^1.1.2",
33
- "@modern-js/utils": "^1.1.6",
34
- "execa": "^5.1.1",
32
+ "@modern-js/plugin-i18n": "^1.2.4",
33
+ "@modern-js/utils": "^1.5.0",
35
34
  "ora": "^5.4.1"
36
35
  },
37
36
  "devDependencies": {
@@ -39,8 +38,9 @@
39
38
  "@types/jest": "^26",
40
39
  "@types/node": "^14",
41
40
  "typescript": "^4",
42
- "@modern-js/module-tools": "^1.1.5",
43
- "@modern-js/plugin-testing": "^1.2.2"
41
+ "@scripts/build": "0.0.0",
42
+ "jest": "^27",
43
+ "@scripts/jest-config": "0.0.0"
44
44
  },
45
45
  "sideEffects": false,
46
46
  "modernConfig": {
@@ -55,7 +55,7 @@
55
55
  "scripts": {
56
56
  "new": "modern new",
57
57
  "build": "modern build",
58
- "test": "modern test --passWithNoTests"
58
+ "test": "jest --passWithNoTests"
59
59
  },
60
60
  "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"
61
61
  }
package/src/index.ts DELETED
@@ -1,148 +0,0 @@
1
- import path from 'path';
2
- import {
3
- fs,
4
- getMonorepoPackages,
5
- canUseNpm,
6
- canUsePnpm,
7
- canUseYarn,
8
- } from '@modern-js/utils';
9
- import execa from 'execa';
10
- import ora from 'ora';
11
- import { GeneratorContext } from '@modern-js/codesmith';
12
- import { stripAnsi } from './utils/strip-ansi';
13
- import { i18n, localeKeys } from './locale';
14
-
15
- export * from './utils';
16
-
17
- export {
18
- fs,
19
- readTsConfigByFile,
20
- getPackageManager,
21
- canUseNpm,
22
- canUsePnpm,
23
- canUseYarn,
24
- } from '@modern-js/utils';
25
-
26
- export { i18n } from './locale';
27
-
28
- // eslint-disable-next-line max-statements
29
- export async function getPackageVersion(
30
- packageName: string,
31
- registry?: string,
32
- ) {
33
- const spinner = ora('Loading...').start();
34
- spinner.color = 'yellow';
35
- if (await canUsePnpm()) {
36
- const args = ['info', packageName, 'version'];
37
- if (registry) {
38
- args.push(`--registry=${registry}`);
39
- }
40
- const result = await execa('pnpm', args);
41
- spinner.stop();
42
- return stripAnsi(result.stdout);
43
- }
44
- if (await canUseYarn()) {
45
- const args = ['info', packageName, 'version', '--silent'];
46
- if (registry) {
47
- args.push(`--registry=${registry}`);
48
- }
49
- const result = await execa('yarn', args);
50
- spinner.stop();
51
- return stripAnsi(result.stdout);
52
- }
53
- if (await canUseNpm()) {
54
- const args = ['view', packageName, 'version'];
55
- if (registry) {
56
- args.push(`--registry=${registry}`);
57
- }
58
- const result = await execa('npm', args);
59
- spinner.stop();
60
- return stripAnsi(result.stdout);
61
- }
62
- spinner.stop();
63
- throw new Error('not found npm, please install npm before');
64
- }
65
-
66
- export function getPackageManagerText(packageManager: 'pnpm' | 'yarn' | 'npm') {
67
- return packageManager === 'yarn' ? 'yarn' : `${packageManager} run`;
68
- }
69
-
70
- export function isTsProject(appDir: string) {
71
- return fs.existsSync(path.join(appDir, 'tsconfig.json'));
72
- }
73
-
74
- export async function getPackageObj(context: GeneratorContext) {
75
- const pkgStr = (await context.materials.default.get(`package.json`).value())
76
- .content;
77
-
78
- return JSON.parse(pkgStr as string);
79
- }
80
-
81
- export function getAllPackages(appDir: string) {
82
- const packages = getMonorepoPackages(appDir);
83
- return packages.map(pkg => pkg.name);
84
- }
85
-
86
- export function validatePackageName(
87
- value: string,
88
- packages: string[],
89
- options: { isMonorepoSubProject: boolean },
90
- ) {
91
- const { isMonorepoSubProject } = options;
92
- if (isMonorepoSubProject && packages.includes(value)) {
93
- return {
94
- success: false,
95
- error: i18n.t(localeKeys.packageName.exit, { value }),
96
- };
97
- }
98
- return { success: true };
99
- }
100
-
101
- export function validatePackagePath(
102
- value: string,
103
- projectDir: string,
104
- options?: { isMwa?: boolean; isPublic?: boolean; isTest?: boolean },
105
- ) {
106
- const { isMwa, isPublic, isTest } = options || {};
107
- let dir = 'apps';
108
- if (isMwa && isTest) {
109
- dir = 'examples';
110
- } else {
111
- dir = isPublic ? 'packages' : 'features';
112
- }
113
- const packageDir = path.resolve(projectDir || '', dir, value);
114
- if (fs.existsSync(packageDir)) {
115
- return {
116
- success: false,
117
- error: i18n.t(localeKeys.pacakgePath.exit, { value }),
118
- };
119
- }
120
- return { success: true };
121
- }
122
-
123
- export function getModuleProjectPath(
124
- packagePath: string,
125
- isMonorepoSubProject: boolean,
126
- isPublic: boolean,
127
- isLocalPackages: boolean,
128
- ) {
129
- if (isLocalPackages && packagePath) {
130
- return `${packagePath}/`;
131
- }
132
- if (isMonorepoSubProject && packagePath) {
133
- return `${isPublic ? 'packages' : 'features'}/${packagePath}/`;
134
- }
135
-
136
- return '';
137
- }
138
-
139
- export function getMWAProjectPath(
140
- packagePath: string,
141
- isMonorepoSubProject: boolean,
142
- isTest = false,
143
- ) {
144
- if (isMonorepoSubProject && packagePath) {
145
- return `${isTest ? 'examples' : 'apps'}/${packagePath}/`;
146
- }
147
- return '';
148
- }
package/src/locale/en.ts DELETED
@@ -1,4 +0,0 @@
1
- export const EN_LOCALE = {
2
- packageName: { exit: 'package name `{value}` is already exists' },
3
- pacakgePath: { exit: 'package path {value} is already exists' },
4
- };
@@ -1,9 +0,0 @@
1
- import { I18n } from '@modern-js/plugin-i18n';
2
- import { ZH_LOCALE } from './zh';
3
- import { EN_LOCALE } from './en';
4
-
5
- const i18n = new I18n();
6
-
7
- const localeKeys = i18n.init('zh', { zh: ZH_LOCALE, en: EN_LOCALE });
8
-
9
- export { i18n, localeKeys };
package/src/locale/zh.ts DELETED
@@ -1,4 +0,0 @@
1
- export const ZH_LOCALE = {
2
- packageName: { exit: '项目名称 {value} 已存在' },
3
- pacakgePath: { exit: '目录 {value} 已存在' },
4
- };
@@ -1 +0,0 @@
1
- export * from './strip-ansi';
@@ -1,16 +0,0 @@
1
- function ansiRegex({ onlyFirst = false } = {}) {
2
- const pattern = [
3
- '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
4
- '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))',
5
- ].join('|');
6
-
7
- return new RegExp(pattern, onlyFirst ? undefined : 'g');
8
- }
9
-
10
- export function stripAnsi(string: string) {
11
- if (typeof string !== 'string') {
12
- throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
13
- }
14
-
15
- return string.replace(ansiRegex(), '');
16
- }
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- extends: ['@modern-js'],
3
- parserOptions: {
4
- project: require.resolve('./tsconfig.json'),
5
- },
6
- };
@@ -1,8 +0,0 @@
1
- import { getPackageVersion } from '../src';
2
-
3
- describe('test generator utils', () => {
4
- test('test getPackageVersion', async () => {
5
- const version = await getPackageVersion('lodash');
6
- expect(typeof version === 'string').toBe(true);
7
- });
8
- });
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "@modern-js/tsconfig/base",
3
- "compilerOptions": {
4
- "declaration": false,
5
- "jsx": "preserve",
6
- "baseUrl": "./",
7
- "paths": {}
8
- }
9
- }