rigjs 2.1.1 → 2.1.4

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.
@@ -7,6 +7,6 @@
7
7
  {
8
8
  name: "rig-test-2",
9
9
  source: "git@github.com:FlashHand/rig-test-2.git",
10
- version: "1.0.1",
10
+ version: "1.0.2",
11
11
  },
12
12
  ]
package/jest.config.ts ADDED
@@ -0,0 +1,7 @@
1
+ const config = {
2
+ verbose: false,
3
+ collectCoverage: true,
4
+
5
+ };
6
+
7
+ module.exports = config;
@@ -1,6 +1,7 @@
1
1
  declare namespace preinstall {
2
2
  function load(): void;
3
3
  const name: string;
4
+ const checkDepsValid: (rigJSON5:any) => void
4
5
 
5
6
  }
6
7
  export default preinstall;
@@ -9,6 +9,8 @@ const fs = require('fs');
9
9
  const json5 = require('json5');
10
10
  const print = require('../print');
11
11
  const path = require('path');
12
+ const compareVersions = require('compare-versions');
13
+
12
14
  // let semverReg = /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/;
13
15
  let gitUrlReg = /(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\.git)(\/?|\#[-\d\w._]+?)$/;
14
16
  const validateName = (name) => {
@@ -76,53 +78,63 @@ const clone = (target, dep) => {
76
78
  }
77
79
  }
78
80
  const checkDepsValid = (rigJson5) => {
79
- // git show origin/master:package.json
80
- // ➜ projects git show tags/2.0.1:package.json
81
+ let valid = true;
81
82
  for (let rig of rigJson5) {
82
83
  try {
83
- const cmd = `git fetch ${rig.source} --tag ${rig.version} -n && git show FETCH_HEAD:package.json`;
84
+ const cmd = `git fetch ${rig.source} refs/tags/${rig.version} && git show FETCH_HEAD:package.json`;
84
85
  console.log(cmd);
85
86
  let showPackageProcess = shell.exec(cmd,
86
87
  {silent: true}
87
88
  );
88
89
  let pkgStr = showPackageProcess.stdout.trim();
89
90
  const pkg = JSON.parse(pkgStr);
90
- console.log(pkgStr);
91
91
  //获取rig依赖
92
- if (pkg.rig){
92
+ if (pkg.rig) {
93
93
  const rigConfig = pkg.rig;
94
94
  //遍历rig依赖
95
95
  Object.keys(rigConfig).forEach(key => {
96
96
  //获取该rig依赖的要求的版本范围
97
- let max='';
97
+ let max = '';
98
98
  let min = '';
99
- if (Array.isArray(rigConfig[key]) ) {
99
+ if (Array.isArray(rigConfig[key])) {
100
100
  //使用数组的情况
101
- if (rigConfig[key].length === 2){
102
- console.log('array\'s length must equal to 2!');
103
- process.exit(1);
104
- }else{
101
+ if (rigConfig[key].length !== 2) {
102
+ print.error('array\'s length must equal to 2!');
103
+ valid = false;
104
+ } else {
105
105
  min = rigConfig[key][0]
106
106
  max = rigConfig[key][1];
107
107
  }
108
108
  } else {
109
109
  //使用字典的情况
110
- min = rigConfig[key]['min'];
111
- max = rigConfig[key]['max'];
110
+ min = rigConfig[key]['min'] || '';
111
+ max = rigConfig[key]['max'] || '';
112
112
  }
113
+
113
114
  //从rigJson5获取该依赖的版本号
114
115
  const dep = rigJson5.find(r => r.name === key);
115
- if (dep){
116
-
117
- }else{
118
- console.log(`${key}[${min},${max}] is required`);
119
- process.exit(1);
116
+ if (dep) {
117
+ console.log(min,max,dep);
118
+ if (min) {
119
+ valid = compareVersions(dep.version, min) >= 0
120
+ }
121
+ if (max) {
122
+ valid = compareVersions(dep.version, max) <= 0
123
+ }
124
+ if (!valid){
125
+ print.error(`${rig.name} requires ${key}[${min},${max}],but ${key} is ${dep.version}!`);
126
+ }
127
+ } else {
128
+ print.error(`${key}[${min},${max}] is required`);
129
+ valid = false;
120
130
  }
121
131
  })
122
132
  }
123
133
  } catch (e) {
124
- console.log(e);
134
+
135
+ valid = false;
125
136
  }
137
+ return valid;
126
138
  }
127
139
  }
128
140
  //加载命令控制器
@@ -133,7 +145,7 @@ const load = async (cmd) => {
133
145
  let rigJson5Str = fs.readFileSync(path.join(process.cwd(), 'package.rig.json5'));
134
146
  let rigJson5 = json5.parse(rigJson5Str);
135
147
  if (!validate(rigJson5)) process.exit(1);
136
- checkDepsValid(rigJson5);
148
+ if (!checkDepsValid(rigJson5)) process.exit(1);
137
149
  //重置rigs
138
150
  if (!(fs.existsSync('./rigs') && fs.lstatSync('./rigs').isDirectory())) {
139
151
  print.info('create folder rigs');
@@ -181,5 +193,6 @@ const load = async (cmd) => {
181
193
  }
182
194
  module.exports = {
183
195
  name: 'install',
184
- load
196
+ load,
197
+ checkDepsValid
185
198
  }
@@ -0,0 +1,16 @@
1
+ const checkDepsValid = require('./index').checkDepsValid;
2
+ const testRigPkgArr = [
3
+ {
4
+ name: "rig-test-1",
5
+ source: "git@github.com:FlashHand/rig-test-1.git",
6
+ version: "1.0.1",
7
+ },
8
+ {
9
+ name: "rig-test-2",
10
+ source: "git@github.com:FlashHand/rig-test-2.git",
11
+ version: "1.0.2",
12
+ },
13
+ ];
14
+ test('checkDepsValid', () => {
15
+ expect(checkDepsValid(testRigPkgArr)).toBe(true);
16
+ });
package/lib/tag/index.js CHANGED
@@ -30,7 +30,7 @@ const load = async () => {
30
30
  }
31
31
  } catch (e) {
32
32
  console.log(red(e.message));
33
- process.exit(1)
33
+ process.exit(1);
34
34
  }
35
35
  }
36
36
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rigjs",
3
- "version": "2.1.1",
3
+ "version": "2.1.4",
4
4
  "description": "A multi-repos dev tool based on yarn and git.Rig is inspired by cocoapods. Not like those monorepo solutions,rig is a tool for organizing multi-repos.",
5
5
  "keywords": [
6
6
  "modular",
@@ -20,6 +20,7 @@
20
20
  "rig": "bin/rig.js"
21
21
  },
22
22
  "scripts": {
23
+ "test": "jest",
23
24
  "init": "cd demo && node ../lib/rig/index.js init",
24
25
  "i": "cd demo && node ../lib/rig/index.js install",
25
26
  "p": "cd demo && node ../lib/rig/index.js publish",
@@ -30,7 +31,7 @@
30
31
  "t": "node lib/rig/index.js tag",
31
32
  "deliver": "rig tag & yarn build & npm publish --registry=https://registry.npmjs.org",
32
33
  "deliver:alpha": "rig tag & yarn build & npm publish --registry=https://registry.npmjs.org --tag alpha",
33
- "build": "esbuild lib/rig/index.ts --platform=node --bundle --minify --outfile=built/index.js --external:shelljs"
34
+ "build": "esbuild lib/rig/index.ts --platform=node --bundle --sourcemap=inline --outfile=built/index.js --external:shelljs"
34
35
  },
35
36
  "dependencies": {
36
37
  "@types/ali-oss": "^6.16.3",
@@ -42,14 +43,20 @@
42
43
  "axios": "^0.26.1",
43
44
  "chalk": "^4.1.0",
44
45
  "commander": "6.1.0",
46
+ "compare-versions": "^4.1.3",
45
47
  "dayjs": "^1.11.0",
46
48
  "inquirer": "7.3.3",
47
49
  "json5": "2.1.3",
48
50
  "ora": "^5.1.0",
51
+ "semver": "^7.3.6",
49
52
  "shelljs": "^0.8.4",
50
53
  "uuid": "^8.3.2"
51
54
  },
52
55
  "devDependencies": {
53
- "@types/node": "^17.0.21"
56
+ "@types/jest": "^27.4.1",
57
+ "@types/node": "^17.0.21",
58
+ "jest": "^27.5.1",
59
+ "ts-node": "^10.7.0",
60
+ "typescript": "^4.6.3"
54
61
  }
55
62
  }