@rife/cli 0.0.6-beta.1
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/dist/build.js +3 -0
- package/dist/build.js.map +1 -0
- package/dist/cli.js +18 -0
- package/dist/cli.js.map +1 -0
- package/dist/compiler.js +82 -0
- package/dist/compiler.js.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.js +26 -0
- package/dist/logger.js.map +1 -0
- package/dist/plugin/commander.js +42 -0
- package/dist/plugin/commander.js.map +1 -0
- package/dist/plugin/compiler/compiler.js +166 -0
- package/dist/plugin/compiler/compiler.js.map +1 -0
- package/dist/plugin/compiler/index.js +83 -0
- package/dist/plugin/compiler/index.js.map +1 -0
- package/dist/plugin/compiler/swc.js +47 -0
- package/dist/plugin/compiler/swc.js.map +1 -0
- package/dist/plugin/compiler/tsc.js +75 -0
- package/dist/plugin/compiler/tsc.js.map +1 -0
- package/dist/plugin/config.js +61 -0
- package/dist/plugin/config.js.map +1 -0
- package/dist/plugin/index.js +8 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/package copy.js +32 -0
- package/dist/plugin/package copy.js.map +1 -0
- package/dist/plugin/package.js +32 -0
- package/dist/plugin/package.js.map +1 -0
- package/dist/plugin/release.js +32 -0
- package/dist/plugin/release.js.map +1 -0
- package/dist/plugin.js +161 -0
- package/dist/plugin.js.map +1 -0
- package/dist/pnpmfile.js +144 -0
- package/dist/runner.js +53 -0
- package/dist/runner.js.map +1 -0
- package/dist/swc.js +78 -0
- package/dist/swc.js.map +1 -0
- package/dist/sync.js +59 -0
- package/dist/sync.js.map +1 -0
- package/dist/tsc.js +94 -0
- package/dist/tsc.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +53 -0
- package/src/build.ts +0 -0
- package/src/cli.ts +19 -0
- package/src/index.ts +3 -0
- package/src/logger.ts +34 -0
- package/src/plugin/commander.ts +44 -0
- package/src/plugin/compiler/compiler.ts +198 -0
- package/src/plugin/compiler/index.ts +109 -0
- package/src/plugin/compiler/swc.ts +55 -0
- package/src/plugin/compiler/tsc.ts +101 -0
- package/src/plugin/config.ts +63 -0
- package/src/plugin/index.ts +4 -0
- package/src/plugin/package.ts +32 -0
- package/src/plugin/release.ts +32 -0
- package/src/pnpmfile.ts +121 -0
- package/src/runner.ts +88 -0
- package/src/sync.ts +62 -0
- package/src/test/pnpmfile.test.ts +223 -0
package/src/pnpmfile.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
let root: any;
|
|
2
|
+
let exit: (message: string) => any;
|
|
3
|
+
const origin: any = {};
|
|
4
|
+
|
|
5
|
+
export function parseVersion(version: string) {
|
|
6
|
+
const [_, a = '', b = '', c = '', d = ''] = /(\d+?)\.(\d+?)\.(\d+?)\D*(\d+)?/.exec(version) || [];
|
|
7
|
+
if (!a || !b || !c) {
|
|
8
|
+
exit(`version ${version}`);
|
|
9
|
+
}
|
|
10
|
+
return [a, b, c, d].map(t => t.padStart(3, '0')).join('.');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function compareVersion(v1: string, v2: string) {
|
|
14
|
+
const v = [v1, v2].filter(t => Boolean(t));
|
|
15
|
+
if (v.length === 0) {
|
|
16
|
+
exit('version empty');
|
|
17
|
+
}
|
|
18
|
+
if (v.length === 1) {
|
|
19
|
+
return v[0];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return parseVersion(v1) > parseVersion(v2) ? v1 : v2;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const host: any = {};
|
|
26
|
+
function updateRoot(type: 'dependencies' | 'devDependencies', name: string, version: string, from: string) {
|
|
27
|
+
if (origin[type][name]) return;
|
|
28
|
+
if (!host[type]) {
|
|
29
|
+
host[type] = {};
|
|
30
|
+
}
|
|
31
|
+
const dependencies = host[type];
|
|
32
|
+
dependencies[name] = {
|
|
33
|
+
version: compareVersion(version, dependencies[name]?.version),
|
|
34
|
+
from,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const readPackage = (pkg: any, context: any) => {
|
|
39
|
+
if (!exit) {
|
|
40
|
+
exit = (message: string) => {
|
|
41
|
+
context.log(message);
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
process.exit(1);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (!root) {
|
|
47
|
+
root = pkg;
|
|
48
|
+
origin.dependencies = { ...root.dependencies };
|
|
49
|
+
origin.devDependencies = { ...root.devDependencies };
|
|
50
|
+
}
|
|
51
|
+
const dependencies = pkg.dependencies || {};
|
|
52
|
+
const devDependencies = pkg.devDependencies || {};
|
|
53
|
+
const peerDependencies = (pkg.peerDependencies = pkg.peerDependencies || {});
|
|
54
|
+
const { hostDependencies = {} } = pkg.rife || {};
|
|
55
|
+
const from = `${pkg.name}@${pkg.version}`;
|
|
56
|
+
Object.keys(hostDependencies).forEach(name => {
|
|
57
|
+
const version = dependencies[name] || devDependencies[name];
|
|
58
|
+
if (!version) {
|
|
59
|
+
exit('cannot not found version');
|
|
60
|
+
}
|
|
61
|
+
const isDev = Boolean(devDependencies[name]);
|
|
62
|
+
if (isDev) {
|
|
63
|
+
peerDependencies[name] = version;
|
|
64
|
+
updateRoot('devDependencies', name, version, from);
|
|
65
|
+
} else {
|
|
66
|
+
updateRoot('dependencies', name, version, from);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return pkg;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const afterAllResolved = (lockfile, context) => {
|
|
73
|
+
const fact = lockfile.importers['.'];
|
|
74
|
+
context.log(JSON.stringify(host));
|
|
75
|
+
return lockfile;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// const logDiff = (type: 'dependencies' | 'devDependencies', diff: any, context) => {
|
|
79
|
+
// if (diff.desc) {
|
|
80
|
+
// context.log(`${type} is wrong, ${diff.desc}.`);
|
|
81
|
+
// }
|
|
82
|
+
// };
|
|
83
|
+
|
|
84
|
+
// export function testReadPackage(list: any[]) {
|
|
85
|
+
// root = null;
|
|
86
|
+
// origin = {};
|
|
87
|
+
// list.map(t => readPackage(t, { log: console.log }));
|
|
88
|
+
// return root;
|
|
89
|
+
// }
|
|
90
|
+
|
|
91
|
+
// function compareObject(fact: any = {}, expect: any = {}) {
|
|
92
|
+
// const more: any[] = [];
|
|
93
|
+
// const less: any[] = [];
|
|
94
|
+
// Object.keys(fact).forEach(name => {
|
|
95
|
+
// if (fact[name] !== expect[name]) {
|
|
96
|
+
// more.push({ name, version: fact[name] });
|
|
97
|
+
// }
|
|
98
|
+
// });
|
|
99
|
+
// Object.keys(expect).forEach(name => {
|
|
100
|
+
// if (fact[name] !== expect[name]) {
|
|
101
|
+
// less.push({ name, version: expect[name] });
|
|
102
|
+
// }
|
|
103
|
+
// });
|
|
104
|
+
// const desc: string[] = [];
|
|
105
|
+
// if (more.length) {
|
|
106
|
+
// desc.push(`${more.map(t => `${t.name}@${t.version}`).join(' ')} is redundant`);
|
|
107
|
+
// }
|
|
108
|
+
// if (less.length) {
|
|
109
|
+
// desc.push(`cannot found ${less.map(t => `${t.name}@${t.version}`).join(' ')}`);
|
|
110
|
+
// }
|
|
111
|
+
// return {
|
|
112
|
+
// more, //
|
|
113
|
+
// less,
|
|
114
|
+
// desc: desc.join(', '),
|
|
115
|
+
// };
|
|
116
|
+
// }
|
|
117
|
+
|
|
118
|
+
// export function testCompareObject(fact: any = {}, expect: any = {}) {
|
|
119
|
+
// const { more, less } = compareObject(fact, expect);
|
|
120
|
+
// return { more, less };
|
|
121
|
+
// }
|
package/src/runner.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { AsyncSeriesHook } from 'tapable';
|
|
2
|
+
import zod from 'zod';
|
|
3
|
+
|
|
4
|
+
import { Logger, createLogger } from './logger';
|
|
5
|
+
|
|
6
|
+
export interface Config {
|
|
7
|
+
name: string;
|
|
8
|
+
plugins: Plugin[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface Runner {
|
|
12
|
+
env: 'prod' | 'dev';
|
|
13
|
+
hook: {
|
|
14
|
+
loadPackage: AsyncSeriesHook<[]>;
|
|
15
|
+
loadConfig: AsyncSeriesHook<[]>;
|
|
16
|
+
validateConfig: AsyncSeriesHook<[]>;
|
|
17
|
+
applyConfig: AsyncSeriesHook<[any]>;
|
|
18
|
+
startCommand: AsyncSeriesHook<[]>;
|
|
19
|
+
finishCommand: AsyncSeriesHook<[]>;
|
|
20
|
+
dev: AsyncSeriesHook<[]>;
|
|
21
|
+
build: AsyncSeriesHook<[]>;
|
|
22
|
+
test: AsyncSeriesHook<[]>;
|
|
23
|
+
release: AsyncSeriesHook<[]>;
|
|
24
|
+
deploy: AsyncSeriesHook<[any]>;
|
|
25
|
+
lint: AsyncSeriesHook<[]>;
|
|
26
|
+
};
|
|
27
|
+
logger: Logger;
|
|
28
|
+
config: {
|
|
29
|
+
all: Config[];
|
|
30
|
+
current: Config;
|
|
31
|
+
};
|
|
32
|
+
package: any;
|
|
33
|
+
z: typeof zod;
|
|
34
|
+
fs: typeof import('fs-extra');
|
|
35
|
+
tapable: typeof import('tapable');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface Plugin {
|
|
39
|
+
name: string;
|
|
40
|
+
apply: (runner: Runner) => any;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (typeof Promise.withResolvers === 'undefined') {
|
|
44
|
+
Promise.withResolvers = <T>() => {
|
|
45
|
+
let resolve: (value: T | PromiseLike<T>) => void;
|
|
46
|
+
let reject: (reason?: unknown) => void;
|
|
47
|
+
const promise = new Promise<T>((res, rej) => {
|
|
48
|
+
resolve = res;
|
|
49
|
+
reject = rej;
|
|
50
|
+
});
|
|
51
|
+
return { promise, resolve: resolve!, reject: reject! };
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function createRunner() {
|
|
56
|
+
const runner: Runner = {
|
|
57
|
+
env: 'prod',
|
|
58
|
+
hook: {
|
|
59
|
+
loadPackage: new AsyncSeriesHook([]),
|
|
60
|
+
loadConfig: new AsyncSeriesHook([]),
|
|
61
|
+
validateConfig: new AsyncSeriesHook([]),
|
|
62
|
+
applyConfig: new AsyncSeriesHook(['options']),
|
|
63
|
+
startCommand: new AsyncSeriesHook([]),
|
|
64
|
+
finishCommand: new AsyncSeriesHook([]),
|
|
65
|
+
dev: new AsyncSeriesHook([]),
|
|
66
|
+
build: new AsyncSeriesHook([]),
|
|
67
|
+
test: new AsyncSeriesHook([]),
|
|
68
|
+
release: new AsyncSeriesHook([]),
|
|
69
|
+
deploy: new AsyncSeriesHook(['options']),
|
|
70
|
+
lint: new AsyncSeriesHook([]),
|
|
71
|
+
},
|
|
72
|
+
logger: createLogger(),
|
|
73
|
+
config: {
|
|
74
|
+
all: [],
|
|
75
|
+
// @ts-expect-error
|
|
76
|
+
current: undefined,
|
|
77
|
+
},
|
|
78
|
+
package: {},
|
|
79
|
+
z: zod,
|
|
80
|
+
fs: require('fs-extra') as typeof import('fs-extra'),
|
|
81
|
+
tapable: require('tapable') as typeof import('tapable'),
|
|
82
|
+
};
|
|
83
|
+
return runner;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function defineConfig(all: Config[]) {
|
|
87
|
+
return all;
|
|
88
|
+
}
|
package/src/sync.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
async function sync(name: string) {
|
|
2
|
+
const res = await fetch(`https://registry-direct.npmmirror.com/-/package/${name}/syncs`, {
|
|
3
|
+
headers: {
|
|
4
|
+
accept: '*/*',
|
|
5
|
+
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
|
6
|
+
'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
|
|
7
|
+
'sec-ch-ua-mobile': '?0',
|
|
8
|
+
'sec-ch-ua-platform': '"Windows"',
|
|
9
|
+
'sec-fetch-dest': 'empty',
|
|
10
|
+
'sec-fetch-mode': 'cors',
|
|
11
|
+
'sec-fetch-site': 'same-site',
|
|
12
|
+
Referer: 'https://npmmirror.com/',
|
|
13
|
+
'Referrer-Policy': 'strict-origin-when-cross-origin',
|
|
14
|
+
},
|
|
15
|
+
body: null,
|
|
16
|
+
method: 'PUT',
|
|
17
|
+
});
|
|
18
|
+
const body = await res.json();
|
|
19
|
+
if (body.ok === true) {
|
|
20
|
+
console.log(`同步 ${name} 成功`);
|
|
21
|
+
}
|
|
22
|
+
return body;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const list = [
|
|
26
|
+
'@rife/config', //
|
|
27
|
+
// '@rife/infra',
|
|
28
|
+
'@rife/logger',
|
|
29
|
+
// '@rife/react',
|
|
30
|
+
// '@rife/next',
|
|
31
|
+
// '@rife/nest',
|
|
32
|
+
// '@rife/wxa',
|
|
33
|
+
'@rife/fast',
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
async function main() {
|
|
37
|
+
for (const item of list) {
|
|
38
|
+
// https://registry.npmmirror.com/-/package/@rife/infra/syncs/65a255a2afa293666acf6655/log
|
|
39
|
+
await sync(item);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
poll();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
main();
|
|
46
|
+
|
|
47
|
+
async function get(name: string) {
|
|
48
|
+
try {
|
|
49
|
+
const res = await fetch(`https://r.cnpmjs.org/${name}?t=${Date.now()}&cache=0`);
|
|
50
|
+
const data = await res.json();
|
|
51
|
+
return `${name} ${data?.['dist-tags']?.['latest']}`;
|
|
52
|
+
} catch (e) {
|
|
53
|
+
return `${name} error`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function poll() {
|
|
58
|
+
const res = await Promise.all(list.map(get));
|
|
59
|
+
console.log(`${res.join('\n')}\n`);
|
|
60
|
+
|
|
61
|
+
setTimeout(poll, 1000);
|
|
62
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { compareObject, parseVersion, testCompareObject, testReadPackage } from '../pnpmfile';
|
|
4
|
+
|
|
5
|
+
describe('解析版本号', () => {
|
|
6
|
+
test('范围版本号', () => {
|
|
7
|
+
expect(parseVersion('^1.0.0')).toBe('001.000.000.000');
|
|
8
|
+
expect(parseVersion('1.10.0')).toBe('001.010.000.000');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('beta 版本号', () => {
|
|
12
|
+
expect(parseVersion('1.0.0-beta.1')).toBe('001.000.000.001');
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe('直接依赖提升', () => {
|
|
17
|
+
test('提升 dependencies', () => {
|
|
18
|
+
const root = {
|
|
19
|
+
name: '@rife/root',
|
|
20
|
+
dependencies: {
|
|
21
|
+
'@rife/a': 'workspace:*',
|
|
22
|
+
root: '^1.0.0',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const a = {
|
|
26
|
+
name: '@rife/a',
|
|
27
|
+
dependencies: {
|
|
28
|
+
a1: '^1.0.0',
|
|
29
|
+
},
|
|
30
|
+
rife: {
|
|
31
|
+
hostDependencies: {
|
|
32
|
+
a1: true,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
const z = {
|
|
37
|
+
name: '@rife/root',
|
|
38
|
+
dependencies: {
|
|
39
|
+
'@rife/a': 'workspace:*',
|
|
40
|
+
root: '^1.0.0',
|
|
41
|
+
a1: '^1.0.0',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
expect(testReadPackage([root, a])).toStrictEqual(z);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('提升 devDependencies', () => {
|
|
48
|
+
const root = {
|
|
49
|
+
name: '@rife/root',
|
|
50
|
+
dependencies: {
|
|
51
|
+
'@rife/a': 'workspace:*',
|
|
52
|
+
root: '^1.0.0',
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
const a = {
|
|
56
|
+
name: '@rife/a',
|
|
57
|
+
devDependencies: {
|
|
58
|
+
a1: '^1.0.0',
|
|
59
|
+
},
|
|
60
|
+
rife: {
|
|
61
|
+
hostDependencies: {
|
|
62
|
+
a1: true,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
const z = {
|
|
67
|
+
name: '@rife/root',
|
|
68
|
+
dependencies: {
|
|
69
|
+
'@rife/a': 'workspace:*',
|
|
70
|
+
root: '^1.0.0',
|
|
71
|
+
},
|
|
72
|
+
devDependencies: {
|
|
73
|
+
a1: '^1.0.0',
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
expect(testReadPackage([root, a])).toStrictEqual(z);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('同时提升 dependencies 和 devDependencies', () => {
|
|
80
|
+
const root = {
|
|
81
|
+
name: '@rife/root',
|
|
82
|
+
dependencies: {
|
|
83
|
+
'@rife/a': 'workspace:*',
|
|
84
|
+
root: '^1.0.0',
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
const a = {
|
|
88
|
+
name: '@rife/a',
|
|
89
|
+
dependencies: {
|
|
90
|
+
a1: '^1.0.0',
|
|
91
|
+
},
|
|
92
|
+
devDependencies: {
|
|
93
|
+
a2: '^1.0.0',
|
|
94
|
+
},
|
|
95
|
+
rife: {
|
|
96
|
+
hostDependencies: {
|
|
97
|
+
a1: true,
|
|
98
|
+
a2: true,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
const z = {
|
|
103
|
+
name: '@rife/root',
|
|
104
|
+
dependencies: {
|
|
105
|
+
'@rife/a': 'workspace:*',
|
|
106
|
+
root: '^1.0.0',
|
|
107
|
+
a1: '^1.0.0',
|
|
108
|
+
},
|
|
109
|
+
devDependencies: {
|
|
110
|
+
a2: '^1.0.0',
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
expect(testReadPackage([root, a])).toStrictEqual(z);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('提升不能覆盖现有版本号', () => {
|
|
117
|
+
const root = {
|
|
118
|
+
name: '@rife/root',
|
|
119
|
+
dependencies: {
|
|
120
|
+
'@rife/a': 'workspace:*',
|
|
121
|
+
root: '^1.0.0',
|
|
122
|
+
a1: '^1.0.0',
|
|
123
|
+
},
|
|
124
|
+
devDependencies: {
|
|
125
|
+
a2: '^1.0.0',
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
const a = {
|
|
129
|
+
name: '@rife/a',
|
|
130
|
+
dependencies: {
|
|
131
|
+
a1: '^1.0.1',
|
|
132
|
+
},
|
|
133
|
+
devDependencies: {
|
|
134
|
+
a2: '^1.0.1',
|
|
135
|
+
},
|
|
136
|
+
rife: {
|
|
137
|
+
hostDependencies: {
|
|
138
|
+
a1: true,
|
|
139
|
+
a2: true,
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
const z = {
|
|
144
|
+
name: '@rife/root',
|
|
145
|
+
dependencies: {
|
|
146
|
+
'@rife/a': 'workspace:*',
|
|
147
|
+
root: '^1.0.0',
|
|
148
|
+
a1: '^1.0.0',
|
|
149
|
+
},
|
|
150
|
+
devDependencies: {
|
|
151
|
+
a2: '^1.0.0',
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
expect(testReadPackage([root, a])).toStrictEqual(z);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe('依赖同一个依赖的多个版本', () => {
|
|
159
|
+
test('总是提升最新版本', () => {
|
|
160
|
+
const root = {
|
|
161
|
+
name: '@rife/root',
|
|
162
|
+
dependencies: {
|
|
163
|
+
'@rife/a': 'workspace:*',
|
|
164
|
+
root: '^1.0.0',
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
const a = {
|
|
168
|
+
name: '@rife/a',
|
|
169
|
+
dependencies: {
|
|
170
|
+
a1: '^1.0.0',
|
|
171
|
+
},
|
|
172
|
+
rife: {
|
|
173
|
+
hostDependencies: {
|
|
174
|
+
a1: true,
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
const b = {
|
|
179
|
+
name: '@rife/b',
|
|
180
|
+
dependencies: {
|
|
181
|
+
a1: '^1.0.1',
|
|
182
|
+
b1: '^1.0.0',
|
|
183
|
+
},
|
|
184
|
+
rife: {
|
|
185
|
+
hostDependencies: {
|
|
186
|
+
a1: true,
|
|
187
|
+
b1: true,
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
const z = {
|
|
192
|
+
name: '@rife/root',
|
|
193
|
+
dependencies: {
|
|
194
|
+
'@rife/a': 'workspace:*',
|
|
195
|
+
root: '^1.0.0',
|
|
196
|
+
a1: '^1.0.1',
|
|
197
|
+
b1: '^1.0.0',
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
expect(testReadPackage([root, a, b])).toStrictEqual(z);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
describe('比较差异', () => {
|
|
205
|
+
test('相同', () => {
|
|
206
|
+
expect(testCompareObject({}, {})).toStrictEqual({ more: [], less: [] });
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test('多了', () => {
|
|
210
|
+
expect(testCompareObject({ a: 1 }, {})).toStrictEqual({ more: [{ name: 'a', version: 1 }], less: [] });
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test('少了', () => {
|
|
214
|
+
expect(testCompareObject({}, { a: 1 })).toStrictEqual({ more: [], less: [{ name: 'a', version: 1 }] });
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('差异', () => {
|
|
218
|
+
expect(testCompareObject({ b: 2 }, { a: 1 })).toStrictEqual({
|
|
219
|
+
more: [{ name: 'b', version: 2 }],
|
|
220
|
+
less: [{ name: 'a', version: 1 }],
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
});
|