@teambit/install 1.0.108 → 1.0.109

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.
@@ -1,167 +0,0 @@
1
- import stripAnsi from 'strip-ansi';
2
- import { ComponentID } from '@teambit/component';
3
- import { makeOutdatedPkgChoices } from './pick-outdated-pkgs';
4
-
5
- describe('makeOutdatedPkgChoices', () => {
6
- it('should render choices in correct order', () => {
7
- const choices = makeOutdatedPkgChoices([
8
- {
9
- name: 'zoo',
10
- currentRange: '1.0.0',
11
- latestRange: '1.1.0',
12
- source: 'rootPolicy',
13
- targetField: 'devDependencies',
14
- },
15
- {
16
- name: 'qar',
17
- currentRange: '1.0.0',
18
- latestRange: '1.1.0',
19
- source: 'rootPolicy',
20
- targetField: 'dependencies',
21
- },
22
- {
23
- name: 'foo',
24
- currentRange: '1.0.0',
25
- latestRange: '2.0.0',
26
- source: 'rootPolicy',
27
- targetField: 'dependencies',
28
- },
29
- {
30
- name: 'bar',
31
- currentRange: '1.0.0',
32
- latestRange: '1.1.0',
33
- source: 'rootPolicy',
34
- targetField: 'peerDependencies',
35
- },
36
- ]);
37
- // Removing the ansi chars for better work on bit build on ci
38
- const stripped = stripAnsiFromChoices(choices);
39
- // @ts-ignore
40
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
41
- expect(stripped).toMatchObject(orderedChoices);
42
- });
43
- it('should render choices with context information', () => {
44
- const choices = makeOutdatedPkgChoices([
45
- {
46
- name: 'foo',
47
- currentRange: '1.0.0',
48
- latestRange: '2.0.0',
49
- source: 'component',
50
- componentId: ComponentID.fromString('scope/comp1'),
51
- targetField: 'dependencies',
52
- },
53
- {
54
- name: 'bar',
55
- currentRange: '1.0.0',
56
- latestRange: '1.1.0',
57
- source: 'variants',
58
- variantPattern: '{comp2}',
59
- targetField: 'peerDependencies',
60
- },
61
- ]);
62
- // Removing the ansi chars for better work on bit build on ci
63
- const stripped = stripAnsiFromChoices(choices);
64
- // @ts-ignore
65
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
66
- expect(stripped).toMatchObject(contextOrders);
67
- });
68
- });
69
-
70
- function stripAnsiFromChoices(choices) {
71
- choices.forEach((choice) => {
72
- choice.message = stripAnsi(choice.message);
73
- choice.choices.forEach((currChoice) => {
74
- currChoice.message = stripAnsi(currChoice.message);
75
- });
76
- });
77
- return choices;
78
- }
79
-
80
- const orderedChoices = [
81
- {
82
- choices: [
83
- {
84
- message: 'foo (runtime) 1.0.0 ❯ 2.0.0 ',
85
- name: 'foo',
86
- value: {
87
- currentRange: '1.0.0',
88
- latestRange: '2.0.0',
89
- name: 'foo',
90
- source: 'rootPolicy',
91
- targetField: 'dependencies',
92
- },
93
- },
94
- {
95
- message: 'qar (runtime) 1.0.0 ❯ 1.1.0 ',
96
- name: 'qar',
97
- value: {
98
- currentRange: '1.0.0',
99
- latestRange: '1.1.0',
100
- name: 'qar',
101
- source: 'rootPolicy',
102
- targetField: 'dependencies',
103
- },
104
- },
105
- {
106
- message: 'zoo (dev) 1.0.0 ❯ 1.1.0 ',
107
- name: 'zoo',
108
- value: {
109
- currentRange: '1.0.0',
110
- latestRange: '1.1.0',
111
- name: 'zoo',
112
- source: 'rootPolicy',
113
- targetField: 'devDependencies',
114
- },
115
- },
116
- {
117
- message: 'bar (peer) 1.0.0 ❯ 1.1.0 ',
118
- name: 'bar',
119
- value: {
120
- currentRange: '1.0.0',
121
- latestRange: '1.1.0',
122
- name: 'bar',
123
- source: 'rootPolicy',
124
- targetField: 'peerDependencies',
125
- },
126
- },
127
- ],
128
- message: 'Root policies',
129
- },
130
- ];
131
-
132
- const contextOrders = [
133
- {
134
- choices: [
135
- {
136
- message: 'foo (runtime) 1.0.0 ❯ 2.0.0 ',
137
- name: 'foo',
138
- value: {
139
- componentId: ComponentID.fromString('scope/comp1'),
140
- currentRange: '1.0.0',
141
- latestRange: '2.0.0',
142
- name: 'foo',
143
- source: 'component',
144
- targetField: 'dependencies',
145
- },
146
- },
147
- ],
148
- message: 'scope/comp1 (component)',
149
- },
150
- {
151
- choices: [
152
- {
153
- message: 'bar (peer) 1.0.0 ❯ 1.1.0 ',
154
- name: 'bar',
155
- value: {
156
- currentRange: '1.0.0',
157
- latestRange: '1.1.0',
158
- name: 'bar',
159
- source: 'variants',
160
- targetField: 'peerDependencies',
161
- variantPattern: '{comp2}',
162
- },
163
- },
164
- ],
165
- message: '{comp2} (variant)',
166
- },
167
- ];
@@ -1,155 +0,0 @@
1
- import { ComponentID } from '@teambit/component';
2
- import colorizeSemverDiff from '@pnpm/colorize-semver-diff';
3
- import semverDiff from '@pnpm/semver-diff';
4
- import { MergedOutdatedPkg } from '@teambit/dependency-resolver';
5
- import { getBorderCharacters, table } from 'table';
6
- import chalk from 'chalk';
7
- import { prompt } from 'enquirer';
8
-
9
- /**
10
- * Lets the user pick the packages that should be updated.
11
- */
12
- export async function pickOutdatedPkgs(outdatedPkgs: MergedOutdatedPkg[]): Promise<MergedOutdatedPkg[]> {
13
- if (outdatedPkgs.length === 0) return [];
14
- const { updateDependencies } = (await prompt({
15
- choices: makeOutdatedPkgChoices(outdatedPkgs),
16
- footer: '\nEnter to start updating. Ctrl-c to cancel.',
17
- indicator: (state: any, choice: any) => ` ${choice.enabled ? '●' : '○'}`,
18
- message:
19
- 'Choose which packages to update ' +
20
- `(Press ${chalk.cyan('<space>')} to select, ` +
21
- `${chalk.cyan('<a>')} to toggle all, ` +
22
- `${chalk.cyan('<i>')} to invert selection)
23
- ${chalk.green('Green')} - indicates a semantically safe update
24
- ${chalk.red('Red')} - indicates a semantically breaking change`,
25
- name: 'updateDependencies',
26
- pointer: '❯',
27
- styles: {
28
- dark: chalk.white,
29
- em: chalk.bgBlack.whiteBright,
30
- success: chalk.white,
31
- },
32
- type: 'multiselect',
33
- validate(value: string[]) {
34
- if (value.length === 0) {
35
- return 'You must choose at least one package.';
36
- }
37
- return true;
38
- },
39
- j() {
40
- return this.down();
41
- },
42
- k() {
43
- return this.up();
44
- },
45
- result(names: string[]) {
46
- // This is needed in order to have the values of the choices in the answer object.
47
- // Otherwise, only the names of the selected choices would've been included.
48
- return this.map(names);
49
- },
50
- cancel() {
51
- // By default, canceling the prompt via Ctrl+c throws an empty string.
52
- // The custom cancel function prevents that behavior.
53
- // Otherwise, Bit CLI would print an error and confuse users.
54
- // See related issue: https://github.com/enquirer/enquirer/issues/225
55
- },
56
- } as any)) as { updateDependencies: Record<string, string | MergedOutdatedPkg> };
57
- return Object.values(updateDependencies ?? {}).filter(
58
- (updateDependency) => typeof updateDependency !== 'string'
59
- ) as MergedOutdatedPkg[];
60
- }
61
-
62
- const DEP_TYPE_PRIORITY = {
63
- dependencies: 0,
64
- devDependencies: 1,
65
- peerDependencies: 2,
66
- };
67
-
68
- /**
69
- * Groups the outdated packages and makes choices for enquirer's prompt.
70
- */
71
- export function makeOutdatedPkgChoices(outdatedPkgs: MergedOutdatedPkg[]) {
72
- outdatedPkgs.sort((pkg1, pkg2) => {
73
- if (pkg1.targetField === pkg2.targetField) return pkg1.name.localeCompare(pkg2.name);
74
- return DEP_TYPE_PRIORITY[pkg1.targetField] - DEP_TYPE_PRIORITY[pkg2.targetField];
75
- });
76
- const renderedTable = alignColumns(outdatedPkgsRows(outdatedPkgs));
77
- const groupedChoices = {};
78
- outdatedPkgs.forEach((outdatedPkg, index) => {
79
- const context = renderContext(outdatedPkg);
80
- if (!groupedChoices[context]) {
81
- groupedChoices[context] = [];
82
- }
83
- groupedChoices[context].push({
84
- message: renderedTable[index],
85
- name: outdatedPkg.name,
86
- value: outdatedPkg,
87
- });
88
- });
89
- const choices = Object.entries(groupedChoices).map(([context, subChoices]) => ({
90
- message: chalk.cyan(context),
91
- choices: subChoices,
92
- }));
93
- return choices;
94
- }
95
-
96
- function renderContext(outdatedPkg: MergedOutdatedPkg) {
97
- if (outdatedPkg.variantPattern) {
98
- return `${outdatedPkg.variantPattern} (variant)`;
99
- }
100
- if (outdatedPkg.componentId) {
101
- return `${outdatedPkg.componentId} (component)`;
102
- }
103
- return 'Root policies';
104
- }
105
-
106
- const TARGET_FIELD_TO_DEP_TYPE = {
107
- devDependencies: 'dev',
108
- dependencies: 'runtime',
109
- peerDependencies: 'peer',
110
- };
111
-
112
- function outdatedPkgsRows(outdatedPkgs: MergedOutdatedPkg[]) {
113
- return outdatedPkgs.map((outdatedPkg) => {
114
- const { change, diff } = semverDiff(outdatedPkg.currentRange, outdatedPkg.latestRange);
115
- let colorizeChange = change ?? 'breaking';
116
- if (change === 'feature') {
117
- colorizeChange = 'fix';
118
- }
119
- const latest = colorizeSemverDiff({
120
- change: colorizeChange,
121
- diff,
122
- });
123
- return [
124
- outdatedPkg.name,
125
- chalk.grey(`(${TARGET_FIELD_TO_DEP_TYPE[outdatedPkg.targetField]})`),
126
- outdatedPkg.hasDifferentRanges ? '*' : outdatedPkg.currentRange,
127
- '❯',
128
- latest,
129
- outdatedPkg.dependentComponents ? renderDependents(outdatedPkg.dependentComponents) : ' ',
130
- ];
131
- });
132
- }
133
-
134
- function renderDependents(dependentComponents: ComponentID[]): string {
135
- let result = `because of ${dependentComponents[0]}`;
136
- if (dependentComponents.length > 1) {
137
- result += ` and ${dependentComponents.length - 1} other components`;
138
- }
139
- return result;
140
- }
141
-
142
- function alignColumns(rows: string[][]) {
143
- return table(rows, {
144
- border: getBorderCharacters('void'),
145
- columnDefault: {
146
- paddingLeft: 0,
147
- paddingRight: 1,
148
- },
149
- columns: {
150
- // This is the current range column
151
- 2: { alignment: 'right' },
152
- },
153
- drawHorizontalLine: () => false,
154
- }).split('\n');
155
- }