@modern-js/generator-utils 1.1.0 → 1.1.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/CHANGELOG.md CHANGED
@@ -1,85 +1,31 @@
1
1
  # @modern-js/generator-utils
2
2
 
3
- ## 1.1.0
4
-
5
- ### Minor Changes
6
-
7
- - 96119db2: Relese v1.1.0
8
-
9
- 1. 全面支持 Windows 平台
10
-
11
- ISSUE:
12
-
13
- - [182](https://github.com/modern-js-dev/modern.js/issues/182)
14
- - [236](https://github.com/modern-js-dev/modern.js/issues/236)
15
-
16
- PR
17
-
18
- - [219](https://github.com/modern-js-dev/modern.js/pull/219)
19
- - [247](https://github.com/modern-js-dev/modern.js/pull/247)
20
- - [249](https://github.com/modern-js-dev/modern.js/pull/249)
21
- - [253](https://github.com/modern-js-dev/modern.js/pull/253)
22
- - [268](https://github.com/modern-js-dev/modern.js/pull/268)
23
- - [270](https://github.com/modern-js-dev/modern.js/pull/270)
24
- - [273](https://github.com/modern-js-dev/modern.js/pull/273)
25
- - [276](https://github.com/modern-js-dev/modern.js/pull/276)
26
-
27
- 2. 修复 Unbundled 模式启用问题
28
-
29
- ISSUE
30
-
31
- - [186](https://github.com/modern-js-dev/modern.js/issues/186)
32
- - [224](https://github.com/modern-js-dev/modern.js/issues/224)
33
- - [225](https://github.com/modern-js-dev/modern.js/issues/225)
34
- - [238](https://github.com/modern-js-dev/modern.js/issues/238)
35
-
36
- PR
37
-
38
- - [226](https://github.com/modern-js-dev/modern.js/pull/226)
39
- - [264](https://github.com/modern-js-dev/modern.js/pull/264)
40
- - [codesmith-12](https://github.com/modern-js-dev/codesmith/pull/12)
41
-
42
- 3. 修复模块工程方案 .npmignore 文件初始化未生成
3
+ ## 1.1.2
43
4
 
44
- ISSUE
45
-
46
- - [198](https://github.com/modern-js-dev/modern.js/issues/198)
47
-
48
- PR
49
-
50
- - [209](https://github.com/modern-js-dev/modern.js/pull/209)
51
-
52
- 4. 修复 Storybook 使用时浏览器打开页面报错
53
-
54
- ISSUE
55
-
56
- - [228](https://github.com/modern-js-dev/modern.js/issues/228)
57
-
58
- PR
59
-
60
- - [254](https://github.com/modern-js-dev/modern.js/pull/254)
61
-
62
- 5. 修复 BFF 一体化开发不支持 unbundle 模式
63
-
64
- ISSUE
65
-
66
- - [235](https://github.com/modern-js-dev/modern.js/issues/235)
67
- - [257](https://github.com/modern-js-dev/modern.js/issues/257)
5
+ ### Patch Changes
68
6
 
69
- PR
7
+ - 4819a3c7: feat: update generator version
8
+ - b7fb82ec: fix: get package manager function
9
+ - Updated dependencies [5e3de7d8]
10
+ - Updated dependencies [b7fb82ec]
11
+ - @modern-js/plugin-i18n@1.1.2
12
+ - @modern-js/utils@1.1.6
70
13
 
71
- - [269](https://github.com/modern-js-dev/modern.js/pull/269)
72
- - [271](https://github.com/modern-js-dev/modern.js/pull/271)
14
+ ## 1.1.1
73
15
 
74
- 6. 修复 Node17 dev 命令报错问题
16
+ ### Patch Changes
75
17
 
76
- ISSUE
18
+ - 0fa83663: support more .env files
19
+ - Updated dependencies [0fa83663]
20
+ - Updated dependencies [f594fbc8]
21
+ - @modern-js/plugin-i18n@1.1.1
22
+ - @modern-js/utils@1.1.2
77
23
 
78
- - [180](https://github.com/modern-js-dev/modern.js/issues/180)
24
+ ## 1.1.0
79
25
 
80
- PR
26
+ ### Minor Changes
81
27
 
82
- - [214](https://github.com/modern-js-dev/modern.js/pull/214)
28
+ - 96119db2: Relese v1.1.0
83
29
 
84
30
  ### Patch Changes
85
31
 
@@ -1,13 +1,11 @@
1
- import os from 'os';
2
1
  import path from 'path';
3
- import { fs, getMonorepoPackages } from '@modern-js/utils';
2
+ import { fs, getMonorepoPackages, canUseNpm, canUsePnpm, canUseYarn } from '@modern-js/utils';
4
3
  import execa from 'execa';
5
4
  import ora from 'ora';
6
- import { canUseNpm, canUsePnpm, canUseYarn } from "./utils/env";
7
5
  import { stripAnsi } from "./utils/strip-ansi";
8
6
  import { i18n, localeKeys } from "./locale";
9
7
  export * from "./utils";
10
- export { fs, readTsConfigByFile } from '@modern-js/utils';
8
+ export { fs, readTsConfigByFile, getPackageManager, canUseNpm, canUsePnpm, canUseYarn } from '@modern-js/utils';
11
9
  export { i18n } from "./locale"; // eslint-disable-next-line max-statements
12
10
 
13
11
  export async function getPackageVersion(packageName, registry) {
@@ -53,27 +51,6 @@ export async function getPackageVersion(packageName, registry) {
53
51
  spinner.stop();
54
52
  throw new Error('not found npm, please install npm before');
55
53
  }
56
- export function getPackageManager(cwd = process.cwd()) {
57
- let appDirectory = cwd;
58
-
59
- while (os.homedir() !== appDirectory) {
60
- if (fs.existsSync(path.resolve(appDirectory, 'pnpm-lock.yaml'))) {
61
- return 'pnpm';
62
- }
63
-
64
- if (fs.existsSync(path.resolve(appDirectory, 'yarn.lock'))) {
65
- return 'yarn';
66
- }
67
-
68
- if (fs.existsSync(path.resolve(appDirectory, 'package-lock.json'))) {
69
- return 'npm';
70
- }
71
-
72
- appDirectory = path.join(appDirectory, '..');
73
- }
74
-
75
- return 'npm';
76
- }
77
54
  export function getPackageManagerText(packageManager) {
78
55
  return packageManager === 'yarn' ? 'yarn' : `${packageManager} run`;
79
56
  }
@@ -1,2 +1 @@
1
- export * from "./env";
2
1
  export * from "./strip-ansi";
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  var _exportNames = {
7
7
  getPackageVersion: true,
8
- getPackageManager: true,
9
8
  getPackageManagerText: true,
10
9
  isTsProject: true,
11
10
  getPackageObj: true,
@@ -16,8 +15,30 @@ var _exportNames = {
16
15
  getMWAProjectPath: true,
17
16
  fs: true,
18
17
  readTsConfigByFile: true,
18
+ getPackageManager: true,
19
+ canUseNpm: true,
20
+ canUsePnpm: true,
21
+ canUseYarn: true,
19
22
  i18n: true
20
23
  };
24
+ Object.defineProperty(exports, "canUseNpm", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _utils.canUseNpm;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "canUsePnpm", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _utils.canUsePnpm;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "canUseYarn", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _utils.canUseYarn;
40
+ }
41
+ });
21
42
  Object.defineProperty(exports, "fs", {
22
43
  enumerable: true,
23
44
  get: function () {
@@ -27,7 +48,12 @@ Object.defineProperty(exports, "fs", {
27
48
  exports.getAllPackages = getAllPackages;
28
49
  exports.getMWAProjectPath = getMWAProjectPath;
29
50
  exports.getModuleProjectPath = getModuleProjectPath;
30
- exports.getPackageManager = getPackageManager;
51
+ Object.defineProperty(exports, "getPackageManager", {
52
+ enumerable: true,
53
+ get: function () {
54
+ return _utils.getPackageManager;
55
+ }
56
+ });
31
57
  exports.getPackageManagerText = getPackageManagerText;
32
58
  exports.getPackageObj = getPackageObj;
33
59
  exports.getPackageVersion = getPackageVersion;
@@ -47,8 +73,6 @@ Object.defineProperty(exports, "readTsConfigByFile", {
47
73
  exports.validatePackageName = validatePackageName;
48
74
  exports.validatePackagePath = validatePackagePath;
49
75
 
50
- var _os = _interopRequireDefault(require("os"));
51
-
52
76
  var _path = _interopRequireDefault(require("path"));
53
77
 
54
78
  var _utils = require("@modern-js/utils");
@@ -57,8 +81,6 @@ var _execa = _interopRequireDefault(require("execa"));
57
81
 
58
82
  var _ora = _interopRequireDefault(require("ora"));
59
83
 
60
- var _env = require("./utils/env");
61
-
62
84
  var _stripAnsi = require("./utils/strip-ansi");
63
85
 
64
86
  var _locale = require("./locale");
@@ -84,7 +106,7 @@ async function getPackageVersion(packageName, registry) {
84
106
  const spinner = (0, _ora.default)('Loading...').start();
85
107
  spinner.color = 'yellow';
86
108
 
87
- if (await (0, _env.canUsePnpm)()) {
109
+ if (await (0, _utils.canUsePnpm)()) {
88
110
  const args = ['info', packageName, 'version'];
89
111
 
90
112
  if (registry) {
@@ -96,7 +118,7 @@ async function getPackageVersion(packageName, registry) {
96
118
  return (0, _stripAnsi.stripAnsi)(result.stdout);
97
119
  }
98
120
 
99
- if (await (0, _env.canUseYarn)()) {
121
+ if (await (0, _utils.canUseYarn)()) {
100
122
  const args = ['info', packageName, 'version', '--silent'];
101
123
 
102
124
  if (registry) {
@@ -108,7 +130,7 @@ async function getPackageVersion(packageName, registry) {
108
130
  return (0, _stripAnsi.stripAnsi)(result.stdout);
109
131
  }
110
132
 
111
- if (await (0, _env.canUseNpm)()) {
133
+ if (await (0, _utils.canUseNpm)()) {
112
134
  const args = ['view', packageName, 'version'];
113
135
 
114
136
  if (registry) {
@@ -124,28 +146,6 @@ async function getPackageVersion(packageName, registry) {
124
146
  throw new Error('not found npm, please install npm before');
125
147
  }
126
148
 
127
- function getPackageManager(cwd = process.cwd()) {
128
- let appDirectory = cwd;
129
-
130
- while (_os.default.homedir() !== appDirectory) {
131
- if (_utils.fs.existsSync(_path.default.resolve(appDirectory, 'pnpm-lock.yaml'))) {
132
- return 'pnpm';
133
- }
134
-
135
- if (_utils.fs.existsSync(_path.default.resolve(appDirectory, 'yarn.lock'))) {
136
- return 'yarn';
137
- }
138
-
139
- if (_utils.fs.existsSync(_path.default.resolve(appDirectory, 'package-lock.json'))) {
140
- return 'npm';
141
- }
142
-
143
- appDirectory = _path.default.join(appDirectory, '..');
144
- }
145
-
146
- return 'npm';
147
- }
148
-
149
149
  function getPackageManagerText(packageManager) {
150
150
  return packageManager === 'yarn' ? 'yarn' : `${packageManager} run`;
151
151
  }
@@ -4,19 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
 
7
- var _env = require("./env");
8
-
9
- Object.keys(_env).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- if (key in exports && exports[key] === _env[key]) return;
12
- Object.defineProperty(exports, key, {
13
- enumerable: true,
14
- get: function () {
15
- return _env[key];
16
- }
17
- });
18
- });
19
-
20
7
  var _stripAnsi = require("./strip-ansi");
21
8
 
22
9
  Object.keys(_stripAnsi).forEach(function (key) {
@@ -1,9 +1,8 @@
1
1
  import { GeneratorContext } from '@modern-js/codesmith';
2
2
  export * from './utils';
3
- export { fs, readTsConfigByFile } from '@modern-js/utils';
3
+ export { fs, readTsConfigByFile, getPackageManager, canUseNpm, canUsePnpm, canUseYarn } from '@modern-js/utils';
4
4
  export { i18n } from './locale';
5
5
  export declare function getPackageVersion(packageName: string, registry?: string): Promise<string>;
6
- export declare function getPackageManager(cwd?: string): "npm" | "yarn" | "pnpm";
7
6
  export declare function getPackageManagerText(packageManager: 'pnpm' | 'yarn' | 'npm'): string;
8
7
  export declare function isTsProject(appDir: string): boolean;
9
8
  export declare function getPackageObj(context: GeneratorContext): Promise<any>;
@@ -1,2 +1 @@
1
- export * from './env';
2
1
  export * from './strip-ansi';
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.1.0",
14
+ "version": "1.1.2",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -28,18 +28,18 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@babel/runtime": "^7",
31
- "@modern-js/plugin-i18n": "^1.1.0",
32
- "@modern-js/utils": "^1.1.0",
31
+ "@modern-js/plugin-i18n": "^1.1.2",
32
+ "@modern-js/utils": "^1.1.6",
33
33
  "execa": "^5.1.1",
34
34
  "ora": "^5.4.1"
35
35
  },
36
36
  "devDependencies": {
37
- "@modern-js/codesmith": "^1.0.0",
37
+ "@modern-js/codesmith": "^1.0.7",
38
38
  "@types/jest": "^26",
39
39
  "@types/node": "^14",
40
40
  "typescript": "^4",
41
- "@modern-js/module-tools": "^1.0.2",
42
- "@modern-js/plugin-testing": "^1.0.2"
41
+ "@modern-js/module-tools": "^1.1.4",
42
+ "@modern-js/plugin-testing": "^1.2.2"
43
43
  },
44
44
  "sideEffects": false,
45
45
  "modernConfig": {
@@ -55,5 +55,6 @@
55
55
  "new": "modern new",
56
56
  "build": "modern build",
57
57
  "test": "modern test --passWithNoTests"
58
- }
58
+ },
59
+ "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"
59
60
  }
package/src/index.ts CHANGED
@@ -1,16 +1,27 @@
1
- import os from 'os';
2
1
  import path from 'path';
3
- import { fs, getMonorepoPackages } from '@modern-js/utils';
2
+ import {
3
+ fs,
4
+ getMonorepoPackages,
5
+ canUseNpm,
6
+ canUsePnpm,
7
+ canUseYarn,
8
+ } from '@modern-js/utils';
4
9
  import execa from 'execa';
5
10
  import ora from 'ora';
6
11
  import { GeneratorContext } from '@modern-js/codesmith';
7
- import { canUseNpm, canUsePnpm, canUseYarn } from './utils/env';
8
12
  import { stripAnsi } from './utils/strip-ansi';
9
13
  import { i18n, localeKeys } from './locale';
10
14
 
11
15
  export * from './utils';
12
16
 
13
- export { fs, readTsConfigByFile } from '@modern-js/utils';
17
+ export {
18
+ fs,
19
+ readTsConfigByFile,
20
+ getPackageManager,
21
+ canUseNpm,
22
+ canUsePnpm,
23
+ canUseYarn,
24
+ } from '@modern-js/utils';
14
25
 
15
26
  export { i18n } from './locale';
16
27
 
@@ -52,23 +63,6 @@ export async function getPackageVersion(
52
63
  throw new Error('not found npm, please install npm before');
53
64
  }
54
65
 
55
- export function getPackageManager(cwd: string = process.cwd()) {
56
- let appDirectory = cwd;
57
- while (os.homedir() !== appDirectory) {
58
- if (fs.existsSync(path.resolve(appDirectory, 'pnpm-lock.yaml'))) {
59
- return 'pnpm';
60
- }
61
- if (fs.existsSync(path.resolve(appDirectory, 'yarn.lock'))) {
62
- return 'yarn';
63
- }
64
- if (fs.existsSync(path.resolve(appDirectory, 'package-lock.json'))) {
65
- return 'npm';
66
- }
67
- appDirectory = path.join(appDirectory, '..');
68
- }
69
- return 'npm';
70
- }
71
-
72
66
  export function getPackageManagerText(packageManager: 'pnpm' | 'yarn' | 'npm') {
73
67
  return packageManager === 'yarn' ? 'yarn' : `${packageManager} run`;
74
68
  }
@@ -1,2 +1 @@
1
- export * from './env';
2
1
  export * from './strip-ansi';
@@ -1,20 +1,8 @@
1
- import { getPackageVersion, canUseNpm, canUsePnpm, canUseYarn } from '@/index';
1
+ import { getPackageVersion } from '@/index';
2
2
 
3
3
  describe('test generator utils', () => {
4
4
  test('test getPackageVersion', async () => {
5
5
  const version = await getPackageVersion('lodash');
6
6
  expect(typeof version === 'string').toBe(true);
7
7
  });
8
- test('test canUseNpm', async () => {
9
- const npmAbility = await canUseNpm();
10
- expect(typeof npmAbility === 'boolean').toBe(true);
11
- });
12
- test('test canUsePnpm', async () => {
13
- const pnpmAbility = await canUsePnpm();
14
- expect(typeof pnpmAbility === 'boolean').toBe(true);
15
- });
16
- test('test canUseYarn', async () => {
17
- const yarnAbility = await canUseYarn();
18
- expect(typeof yarnAbility === 'boolean').toBe(true);
19
- });
20
8
  });
@@ -1,31 +0,0 @@
1
- import execa from 'execa';
2
- export async function canUseNpm() {
3
- try {
4
- await execa('npm', ['--version'], {
5
- env: process.env
6
- });
7
- return true;
8
- } catch (e) {
9
- return false;
10
- }
11
- }
12
- export async function canUseYarn() {
13
- try {
14
- await execa('yarn', ['--version'], {
15
- env: process.env
16
- });
17
- return true;
18
- } catch (e) {
19
- return false;
20
- }
21
- }
22
- export async function canUsePnpm() {
23
- try {
24
- await execa('pnpm', ['--version'], {
25
- env: process.env
26
- });
27
- return true;
28
- } catch (e) {
29
- return false;
30
- }
31
- }
@@ -1,45 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.canUseNpm = canUseNpm;
7
- exports.canUsePnpm = canUsePnpm;
8
- exports.canUseYarn = canUseYarn;
9
-
10
- var _execa = _interopRequireDefault(require("execa"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- async function canUseNpm() {
15
- try {
16
- await (0, _execa.default)('npm', ['--version'], {
17
- env: process.env
18
- });
19
- return true;
20
- } catch (e) {
21
- return false;
22
- }
23
- }
24
-
25
- async function canUseYarn() {
26
- try {
27
- await (0, _execa.default)('yarn', ['--version'], {
28
- env: process.env
29
- });
30
- return true;
31
- } catch (e) {
32
- return false;
33
- }
34
- }
35
-
36
- async function canUsePnpm() {
37
- try {
38
- await (0, _execa.default)('pnpm', ['--version'], {
39
- env: process.env
40
- });
41
- return true;
42
- } catch (e) {
43
- return false;
44
- }
45
- }
@@ -1,3 +0,0 @@
1
- export declare function canUseNpm(): Promise<boolean>;
2
- export declare function canUseYarn(): Promise<boolean>;
3
- export declare function canUsePnpm(): Promise<boolean>;
package/src/utils/env.ts DELETED
@@ -1,28 +0,0 @@
1
- import execa from 'execa';
2
-
3
- export async function canUseNpm() {
4
- try {
5
- await execa('npm', ['--version'], { env: process.env });
6
- return true;
7
- } catch (e) {
8
- return false;
9
- }
10
- }
11
-
12
- export async function canUseYarn() {
13
- try {
14
- await execa('yarn', ['--version'], { env: process.env });
15
- return true;
16
- } catch (e) {
17
- return false;
18
- }
19
- }
20
-
21
- export async function canUsePnpm() {
22
- try {
23
- await execa('pnpm', ['--version'], { env: process.env });
24
- return true;
25
- } catch (e) {
26
- return false;
27
- }
28
- }