@modern-js/generator-utils 1.0.1 → 1.1.2-alpha.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @modern-js/generator-utils
2
2
 
3
+ ## 1.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 0fa83663: support more .env files
8
+ - Updated dependencies [0fa83663]
9
+ - Updated dependencies [f594fbc8]
10
+ - @modern-js/plugin-i18n@1.1.1
11
+ - @modern-js/utils@1.1.2
12
+
13
+ ## 1.1.0
14
+
15
+ ### Minor Changes
16
+
17
+ - 96119db2: Relese v1.1.0
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [96119db2]
22
+ - @modern-js/plugin-i18n@1.1.0
23
+ - @modern-js/utils@1.1.0
24
+
3
25
  ## 1.0.1
4
26
 
5
27
  ### Patch Changes
package/README.md CHANGED
@@ -17,10 +17,7 @@
17
17
 
18
18
  > 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.
19
19
 
20
- - 介绍 Modern.js (即将上线)
21
- - [迈入现代 Web 开发](https://zhuanlan.zhihu.com/p/386607009)
22
- - [现代 Web 开发者问卷调查报告](https://zhuanlan.zhihu.com/p/403206195)
23
- - [字节跳动是如何落地微前端的](https://mp.weixin.qq.com/s/L9wbfNG5fTXF5bx7dcgj4Q)
20
+ - [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)
24
21
 
25
22
  ## Getting Started
26
23
 
@@ -1,12 +1,11 @@
1
- import os from 'os';
2
- import { path, fs, getMonorepoPackages } from '@modern-js/utils';
1
+ import path from 'path';
2
+ import { fs, getMonorepoPackages, canUseNpm, canUsePnpm, canUseYarn } from '@modern-js/utils';
3
3
  import execa from 'execa';
4
4
  import ora from 'ora';
5
- import { canUseNpm, canUsePnpm, canUseYarn } from "./utils/env";
6
5
  import { stripAnsi } from "./utils/strip-ansi";
7
6
  import { i18n, localeKeys } from "./locale";
8
7
  export * from "./utils";
9
- export { fs, path, readTsConfigByFile } from '@modern-js/utils';
8
+ export { fs, readTsConfigByFile, getPackageManager } from '@modern-js/utils';
10
9
  export { i18n } from "./locale"; // eslint-disable-next-line max-statements
11
10
 
12
11
  export async function getPackageVersion(packageName, registry) {
@@ -52,27 +51,6 @@ export async function getPackageVersion(packageName, registry) {
52
51
  spinner.stop();
53
52
  throw new Error('not found npm, please install npm before');
54
53
  }
55
- export function getPackageManager(cwd = process.cwd()) {
56
- let appDirectory = cwd;
57
-
58
- while (os.homedir() !== appDirectory) {
59
- if (fs.existsSync(path.resolve(appDirectory, 'pnpm-lock.yaml'))) {
60
- return 'pnpm';
61
- }
62
-
63
- if (fs.existsSync(path.resolve(appDirectory, 'yarn.lock'))) {
64
- return 'yarn';
65
- }
66
-
67
- if (fs.existsSync(path.resolve(appDirectory, 'package-lock.json'))) {
68
- return 'npm';
69
- }
70
-
71
- appDirectory = path.join(appDirectory, '..');
72
- }
73
-
74
- return 'npm';
75
- }
76
54
  export function getPackageManagerText(packageManager) {
77
55
  return packageManager === 'yarn' ? 'yarn' : `${packageManager} run`;
78
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,
@@ -15,8 +14,8 @@ var _exportNames = {
15
14
  getModuleProjectPath: true,
16
15
  getMWAProjectPath: true,
17
16
  fs: true,
18
- path: true,
19
17
  readTsConfigByFile: true,
18
+ getPackageManager: true,
20
19
  i18n: true
21
20
  };
22
21
  Object.defineProperty(exports, "fs", {
@@ -28,7 +27,12 @@ Object.defineProperty(exports, "fs", {
28
27
  exports.getAllPackages = getAllPackages;
29
28
  exports.getMWAProjectPath = getMWAProjectPath;
30
29
  exports.getModuleProjectPath = getModuleProjectPath;
31
- exports.getPackageManager = getPackageManager;
30
+ Object.defineProperty(exports, "getPackageManager", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _utils.getPackageManager;
34
+ }
35
+ });
32
36
  exports.getPackageManagerText = getPackageManagerText;
33
37
  exports.getPackageObj = getPackageObj;
34
38
  exports.getPackageVersion = getPackageVersion;
@@ -39,12 +43,6 @@ Object.defineProperty(exports, "i18n", {
39
43
  }
40
44
  });
41
45
  exports.isTsProject = isTsProject;
42
- Object.defineProperty(exports, "path", {
43
- enumerable: true,
44
- get: function () {
45
- return _utils.path;
46
- }
47
- });
48
46
  Object.defineProperty(exports, "readTsConfigByFile", {
49
47
  enumerable: true,
50
48
  get: function () {
@@ -54,7 +52,7 @@ Object.defineProperty(exports, "readTsConfigByFile", {
54
52
  exports.validatePackageName = validatePackageName;
55
53
  exports.validatePackagePath = validatePackagePath;
56
54
 
57
- var _os = _interopRequireDefault(require("os"));
55
+ var _path = _interopRequireDefault(require("path"));
58
56
 
59
57
  var _utils = require("@modern-js/utils");
60
58
 
@@ -62,8 +60,6 @@ var _execa = _interopRequireDefault(require("execa"));
62
60
 
63
61
  var _ora = _interopRequireDefault(require("ora"));
64
62
 
65
- var _env = require("./utils/env");
66
-
67
63
  var _stripAnsi = require("./utils/strip-ansi");
68
64
 
69
65
  var _locale = require("./locale");
@@ -89,7 +85,7 @@ async function getPackageVersion(packageName, registry) {
89
85
  const spinner = (0, _ora.default)('Loading...').start();
90
86
  spinner.color = 'yellow';
91
87
 
92
- if (await (0, _env.canUsePnpm)()) {
88
+ if (await (0, _utils.canUsePnpm)()) {
93
89
  const args = ['info', packageName, 'version'];
94
90
 
95
91
  if (registry) {
@@ -101,7 +97,7 @@ async function getPackageVersion(packageName, registry) {
101
97
  return (0, _stripAnsi.stripAnsi)(result.stdout);
102
98
  }
103
99
 
104
- if (await (0, _env.canUseYarn)()) {
100
+ if (await (0, _utils.canUseYarn)()) {
105
101
  const args = ['info', packageName, 'version', '--silent'];
106
102
 
107
103
  if (registry) {
@@ -113,7 +109,7 @@ async function getPackageVersion(packageName, registry) {
113
109
  return (0, _stripAnsi.stripAnsi)(result.stdout);
114
110
  }
115
111
 
116
- if (await (0, _env.canUseNpm)()) {
112
+ if (await (0, _utils.canUseNpm)()) {
117
113
  const args = ['view', packageName, 'version'];
118
114
 
119
115
  if (registry) {
@@ -129,34 +125,12 @@ async function getPackageVersion(packageName, registry) {
129
125
  throw new Error('not found npm, please install npm before');
130
126
  }
131
127
 
132
- function getPackageManager(cwd = process.cwd()) {
133
- let appDirectory = cwd;
134
-
135
- while (_os.default.homedir() !== appDirectory) {
136
- if (_utils.fs.existsSync(_utils.path.resolve(appDirectory, 'pnpm-lock.yaml'))) {
137
- return 'pnpm';
138
- }
139
-
140
- if (_utils.fs.existsSync(_utils.path.resolve(appDirectory, 'yarn.lock'))) {
141
- return 'yarn';
142
- }
143
-
144
- if (_utils.fs.existsSync(_utils.path.resolve(appDirectory, 'package-lock.json'))) {
145
- return 'npm';
146
- }
147
-
148
- appDirectory = _utils.path.join(appDirectory, '..');
149
- }
150
-
151
- return 'npm';
152
- }
153
-
154
128
  function getPackageManagerText(packageManager) {
155
129
  return packageManager === 'yarn' ? 'yarn' : `${packageManager} run`;
156
130
  }
157
131
 
158
132
  function isTsProject(appDir) {
159
- return _utils.fs.existsSync(_utils.path.join(appDir, 'tsconfig.json'));
133
+ return _utils.fs.existsSync(_path.default.join(appDir, 'tsconfig.json'));
160
134
  }
161
135
 
162
136
  async function getPackageObj(context) {
@@ -202,7 +176,7 @@ function validatePackagePath(value, projectDir, options) {
202
176
  dir = isPublic ? 'packages' : 'features';
203
177
  }
204
178
 
205
- const packageDir = _utils.path.resolve(projectDir || '', dir, value);
179
+ const packageDir = _path.default.resolve(projectDir || '', dir, value);
206
180
 
207
181
  if (_utils.fs.existsSync(packageDir)) {
208
182
  return {
@@ -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, path, readTsConfigByFile } from '@modern-js/utils';
3
+ export { fs, readTsConfigByFile, getPackageManager } 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.0.1",
14
+ "version": "1.1.2-alpha.0",
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.0.0",
32
- "@modern-js/utils": "^1.0.0",
31
+ "@modern-js/plugin-i18n": "^1.1.1",
32
+ "@modern-js/utils": "^1.1.2",
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.1",
42
- "@modern-js/plugin-testing": "^1.0.0"
41
+ "@modern-js/module-tools": "^1.1.1",
42
+ "@modern-js/plugin-testing": "^1.1.1"
43
43
  },
44
44
  "sideEffects": false,
45
45
  "modernConfig": {
package/src/index.ts CHANGED
@@ -1,15 +1,20 @@
1
- import os from 'os';
2
- import { path, fs, getMonorepoPackages } from '@modern-js/utils';
1
+ import path from 'path';
2
+ import {
3
+ fs,
4
+ getMonorepoPackages,
5
+ canUseNpm,
6
+ canUsePnpm,
7
+ canUseYarn,
8
+ } from '@modern-js/utils';
3
9
  import execa from 'execa';
4
10
  import ora from 'ora';
5
11
  import { GeneratorContext } from '@modern-js/codesmith';
6
- import { canUseNpm, canUsePnpm, canUseYarn } from './utils/env';
7
12
  import { stripAnsi } from './utils/strip-ansi';
8
13
  import { i18n, localeKeys } from './locale';
9
14
 
10
15
  export * from './utils';
11
16
 
12
- export { fs, path, readTsConfigByFile } from '@modern-js/utils';
17
+ export { fs, readTsConfigByFile, getPackageManager } from '@modern-js/utils';
13
18
 
14
19
  export { i18n } from './locale';
15
20
 
@@ -51,23 +56,6 @@ export async function getPackageVersion(
51
56
  throw new Error('not found npm, please install npm before');
52
57
  }
53
58
 
54
- export function getPackageManager(cwd: string = process.cwd()) {
55
- let appDirectory = cwd;
56
- while (os.homedir() !== appDirectory) {
57
- if (fs.existsSync(path.resolve(appDirectory, 'pnpm-lock.yaml'))) {
58
- return 'pnpm';
59
- }
60
- if (fs.existsSync(path.resolve(appDirectory, 'yarn.lock'))) {
61
- return 'yarn';
62
- }
63
- if (fs.existsSync(path.resolve(appDirectory, 'package-lock.json'))) {
64
- return 'npm';
65
- }
66
- appDirectory = path.join(appDirectory, '..');
67
- }
68
- return 'npm';
69
- }
70
-
71
59
  export function getPackageManagerText(packageManager: 'pnpm' | 'yarn' | 'npm') {
72
60
  return packageManager === 'yarn' ? 'yarn' : `${packageManager} run`;
73
61
  }
@@ -1,2 +1 @@
1
- export * from './env';
2
1
  export * from './strip-ansi';
@@ -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
- }