@teambit/workspace 0.0.566 → 0.0.570
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/__snapshots__/pick-outdated-pkgs.spec.ts.snap +88 -0
- package/component-config-file/component-config-file.ts +98 -0
- package/component-config-file/exceptions/already-exists.ts +7 -0
- package/component-config-file/exceptions/index.ts +1 -0
- package/component-config-file/index.ts +2 -0
- package/component-tree.widget.tsx +16 -0
- package/dist/__snapshots__/pick-outdated-pkgs.spec.js.snap +88 -0
- package/dist/__snapshots__/pick-outdated-pkgs.spec.ts.snap +88 -0
- package/dist/pick-outdated-pkgs.d.ts +12 -0
- package/dist/pick-outdated-pkgs.js +201 -0
- package/dist/pick-outdated-pkgs.js.map +1 -0
- package/dist/pick-outdated-pkgs.spec.d.ts +1 -0
- package/dist/pick-outdated-pkgs.spec.js +64 -0
- package/dist/pick-outdated-pkgs.spec.js.map +1 -0
- package/dist/update.cmd.js +3 -5
- package/dist/update.cmd.js.map +1 -1
- package/dist/workspace.d.ts +8 -1
- package/dist/workspace.js +28 -2
- package/dist/workspace.js.map +1 -1
- package/eject-conf.cmd.tsx +62 -0
- package/events/index.ts +3 -0
- package/events/on-component-add-event.ts +14 -0
- package/events/on-component-change-event.ts +14 -0
- package/events/on-component-removed-event.ts +14 -0
- package/exceptions/dependency-type-not-supported-in-policy.ts +7 -0
- package/exceptions/incorrect-env-aspect.ts +8 -0
- package/exceptions/index.ts +1 -0
- package/install.cmd.tsx +67 -0
- package/link/component-list-links.ts +50 -0
- package/link/core-aspects-links.ts +50 -0
- package/link/get-package-name-from-target.ts +5 -0
- package/link/index.ts +1 -0
- package/link/link-row.ts +20 -0
- package/link/link-to-dir.ts +13 -0
- package/link/link.cmd.ts +96 -0
- package/link/nested-deps-in-nm-links.ts +47 -0
- package/link/rewire-row.ts +17 -0
- package/list.cmd.tsx +30 -0
- package/package-tar/teambit-workspace-0.0.570.tgz +0 -0
- package/package.json +54 -65
- package/types/asset.d.ts +29 -0
- package/types/style.d.ts +42 -0
- package/ui/index.ts +1 -0
- package/ui/workspace/default-component.ts +7 -0
- package/ui/workspace/index.ts +1 -0
- package/ui/workspace/use-workspace.ts +193 -0
- package/ui/workspace/workspace-context.tsx +5 -0
- package/ui/workspace/workspace-model.ts +66 -0
- package/ui/workspace/workspace-overview/index.ts +1 -0
- package/ui/workspace/workspace-overview/workspace-overview.tsx +21 -0
- package/ui/workspace/workspace-provider.tsx +23 -0
- package/ui/workspace/workspace.tsx +99 -0
- package/ui/workspace-components-drawer/index.ts +1 -0
- package/ui/workspace-components-drawer/workspace-components.drawer.tsx +49 -0
- package/update.cmd.tsx +30 -0
- package/watch/check-types.ts +5 -0
- package/watch/output-formatter.ts +50 -0
- package/watch/watch.cmd.tsx +142 -0
- package/watch/watcher.ts +289 -0
- package/workspace-component/component-status.ts +67 -0
- package/workspace-component/index.ts +2 -0
- package/workspace-component/workspace-component-loader.ts +276 -0
- package/workspace-component/workspace-component.ts +51 -0
- package/workspace.ui.runtime.tsx +215 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`makeOutdatedPkgChoices should render choices in correct order 1`] = `
|
|
4
|
+
Array [
|
|
5
|
+
Object {
|
|
6
|
+
"choices": Array [
|
|
7
|
+
Object {
|
|
8
|
+
"message": "foo [90m(runtime)[39m 1.0.0 ❯ [91m[1m2.0.0[22m[39m ",
|
|
9
|
+
"name": Object {
|
|
10
|
+
"currentRange": "1.0.0",
|
|
11
|
+
"latestRange": "2.0.0",
|
|
12
|
+
"name": "foo",
|
|
13
|
+
"source": "rootPolicy",
|
|
14
|
+
"targetField": "dependencies",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
Object {
|
|
18
|
+
"message": "qar [90m(runtime)[39m 1.0.0 ❯ 1.[92m[1m1.0[22m[39m ",
|
|
19
|
+
"name": Object {
|
|
20
|
+
"currentRange": "1.0.0",
|
|
21
|
+
"latestRange": "1.1.0",
|
|
22
|
+
"name": "qar",
|
|
23
|
+
"source": "rootPolicy",
|
|
24
|
+
"targetField": "dependencies",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
Object {
|
|
28
|
+
"message": "zoo [90m(dev)[39m 1.0.0 ❯ 1.[92m[1m1.0[22m[39m ",
|
|
29
|
+
"name": Object {
|
|
30
|
+
"currentRange": "1.0.0",
|
|
31
|
+
"latestRange": "1.1.0",
|
|
32
|
+
"name": "zoo",
|
|
33
|
+
"source": "rootPolicy",
|
|
34
|
+
"targetField": "devDependencies",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
Object {
|
|
38
|
+
"message": "bar [90m(peer)[39m 1.0.0 ❯ 1.[92m[1m1.0[22m[39m ",
|
|
39
|
+
"name": Object {
|
|
40
|
+
"currentRange": "1.0.0",
|
|
41
|
+
"latestRange": "1.1.0",
|
|
42
|
+
"name": "bar",
|
|
43
|
+
"source": "rootPolicy",
|
|
44
|
+
"targetField": "peerDependencies",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
"message": "[36mRoot policies[39m",
|
|
49
|
+
},
|
|
50
|
+
]
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
exports[`makeOutdatedPkgChoices should render choices with context information 1`] = `
|
|
54
|
+
Array [
|
|
55
|
+
Object {
|
|
56
|
+
"choices": Array [
|
|
57
|
+
Object {
|
|
58
|
+
"message": "foo [90m(runtime)[39m 1.0.0 ❯ [91m[1m2.0.0[22m[39m ",
|
|
59
|
+
"name": Object {
|
|
60
|
+
"componentId": "comp1",
|
|
61
|
+
"currentRange": "1.0.0",
|
|
62
|
+
"latestRange": "2.0.0",
|
|
63
|
+
"name": "foo",
|
|
64
|
+
"source": "component",
|
|
65
|
+
"targetField": "dependencies",
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
"message": "[36mcomp1 (component)[39m",
|
|
70
|
+
},
|
|
71
|
+
Object {
|
|
72
|
+
"choices": Array [
|
|
73
|
+
Object {
|
|
74
|
+
"message": "bar [90m(peer)[39m 1.0.0 ❯ 1.[92m[1m1.0[22m[39m ",
|
|
75
|
+
"name": Object {
|
|
76
|
+
"currentRange": "1.0.0",
|
|
77
|
+
"latestRange": "1.1.0",
|
|
78
|
+
"name": "bar",
|
|
79
|
+
"source": "variants",
|
|
80
|
+
"targetField": "peerDependencies",
|
|
81
|
+
"variantPattern": "{comp2}",
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
"message": "[36m{comp2} (variant)[39m",
|
|
86
|
+
},
|
|
87
|
+
]
|
|
88
|
+
`;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { ComponentID, AspectList } from '@teambit/component';
|
|
2
|
+
import { COMPONENT_CONFIG_FILE_NAME } from '@teambit/legacy/dist/constants';
|
|
3
|
+
import { ExtensionDataList } from '@teambit/legacy/dist/consumer/config/extension-data';
|
|
4
|
+
import { PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';
|
|
5
|
+
import detectIndent from 'detect-indent';
|
|
6
|
+
import detectNewline from 'detect-newline';
|
|
7
|
+
import fs from 'fs-extra';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import stringifyPackage from 'stringify-package';
|
|
10
|
+
|
|
11
|
+
import { AlreadyExistsError } from './exceptions';
|
|
12
|
+
|
|
13
|
+
interface ComponentConfigFileOptions {
|
|
14
|
+
indent: number;
|
|
15
|
+
newLine: '\r\n' | '\n' | undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface WriteConfigFileOptions {
|
|
19
|
+
override?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface ComponentConfigFileJson {
|
|
23
|
+
componentId: any;
|
|
24
|
+
// TODO: think if we want to change it to aspects
|
|
25
|
+
extensions: any;
|
|
26
|
+
propagate: boolean;
|
|
27
|
+
defaultScope?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const DEFAULT_INDENT = 2;
|
|
31
|
+
const DEFAULT_NEWLINE = '\n';
|
|
32
|
+
|
|
33
|
+
export class ComponentConfigFile {
|
|
34
|
+
constructor(
|
|
35
|
+
public componentId: ComponentID,
|
|
36
|
+
public aspects: AspectList,
|
|
37
|
+
public propagate: boolean = false,
|
|
38
|
+
private options: ComponentConfigFileOptions = { indent: DEFAULT_INDENT, newLine: DEFAULT_NEWLINE },
|
|
39
|
+
public defaultScope?: string
|
|
40
|
+
) {}
|
|
41
|
+
|
|
42
|
+
// TODO: remove consumer from here
|
|
43
|
+
static async load(
|
|
44
|
+
componentDir: PathOsBasedAbsolute,
|
|
45
|
+
aspectListFactory: (extensionDataList: ExtensionDataList) => Promise<AspectList>,
|
|
46
|
+
outsideDefaultScope?: string
|
|
47
|
+
): Promise<ComponentConfigFile | undefined> {
|
|
48
|
+
const filePath = ComponentConfigFile.composePath(componentDir);
|
|
49
|
+
const isExist = await fs.pathExists(filePath);
|
|
50
|
+
if (!isExist) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
54
|
+
const parsed: ComponentConfigFileJson = parseComponentJsonContent(content, componentDir);
|
|
55
|
+
const indent = detectIndent(content).amount;
|
|
56
|
+
const newLine = detectNewline(content);
|
|
57
|
+
const componentId = ComponentID.fromObject(parsed.componentId, parsed.defaultScope || outsideDefaultScope);
|
|
58
|
+
const aspects = await aspectListFactory(ExtensionDataList.fromConfigObject(parsed.extensions));
|
|
59
|
+
|
|
60
|
+
return new ComponentConfigFile(componentId, aspects, !!parsed.propagate, { indent, newLine }, parsed.defaultScope);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static composePath(componentRootFolder: string) {
|
|
64
|
+
return path.join(componentRootFolder, COMPONENT_CONFIG_FILE_NAME);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async write(componentDir: string, options: WriteConfigFileOptions = {}): Promise<void> {
|
|
68
|
+
const json = this.toJson();
|
|
69
|
+
const filePath = ComponentConfigFile.composePath(componentDir);
|
|
70
|
+
const isExist = await fs.pathExists(filePath);
|
|
71
|
+
if (isExist && !options.override) {
|
|
72
|
+
throw new AlreadyExistsError(filePath);
|
|
73
|
+
}
|
|
74
|
+
return fs.writeJsonSync(filePath, json, { spaces: this.options.indent, EOL: this.options.newLine });
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
toJson(): ComponentConfigFileJson {
|
|
78
|
+
return {
|
|
79
|
+
componentId: this.componentId.toObject(),
|
|
80
|
+
propagate: this.propagate,
|
|
81
|
+
defaultScope: this.defaultScope,
|
|
82
|
+
extensions: this.aspects.toConfigObject(),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
toString(): string {
|
|
87
|
+
const json = this.toJson();
|
|
88
|
+
return stringifyPackage(json, this.options.indent, this.options.newLine);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function parseComponentJsonContent(str: string, dir: string) {
|
|
93
|
+
try {
|
|
94
|
+
return JSON.parse(str);
|
|
95
|
+
} catch (err: any) {
|
|
96
|
+
throw new Error(`failed parsing component.json file at ${dir}. original error: ${err.message}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AlreadyExistsError } from './already-exists';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ComponentTreeNode, ComponentTreeNodeProps } from '@teambit/component-tree';
|
|
2
|
+
import { ComponentStatusResolver } from '@teambit/component.ui.component-status-resolver';
|
|
3
|
+
import React, { useContext } from 'react';
|
|
4
|
+
|
|
5
|
+
import { WorkspaceContext } from './ui/workspace/workspace-context';
|
|
6
|
+
|
|
7
|
+
export class ComponentTreeWidget implements ComponentTreeNode {
|
|
8
|
+
widget = ({ component }: ComponentTreeNodeProps) => {
|
|
9
|
+
const workspace = useContext(WorkspaceContext);
|
|
10
|
+
|
|
11
|
+
const workspaceComponent = workspace.getComponent(component.id);
|
|
12
|
+
if (!workspaceComponent) return null;
|
|
13
|
+
|
|
14
|
+
return <ComponentStatusResolver status={workspaceComponent.status} issuesCount={workspaceComponent.issuesCount} />;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`makeOutdatedPkgChoices should render choices in correct order 1`] = `
|
|
4
|
+
Array [
|
|
5
|
+
Object {
|
|
6
|
+
"choices": Array [
|
|
7
|
+
Object {
|
|
8
|
+
"message": "foo [90m(runtime)[39m 1.0.0 ❯ [91m[1m2.0.0[22m[39m ",
|
|
9
|
+
"name": Object {
|
|
10
|
+
"currentRange": "1.0.0",
|
|
11
|
+
"latestRange": "2.0.0",
|
|
12
|
+
"name": "foo",
|
|
13
|
+
"source": "rootPolicy",
|
|
14
|
+
"targetField": "dependencies",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
Object {
|
|
18
|
+
"message": "qar [90m(runtime)[39m 1.0.0 ❯ 1.[92m[1m1.0[22m[39m ",
|
|
19
|
+
"name": Object {
|
|
20
|
+
"currentRange": "1.0.0",
|
|
21
|
+
"latestRange": "1.1.0",
|
|
22
|
+
"name": "qar",
|
|
23
|
+
"source": "rootPolicy",
|
|
24
|
+
"targetField": "dependencies",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
Object {
|
|
28
|
+
"message": "zoo [90m(dev)[39m 1.0.0 ❯ 1.[92m[1m1.0[22m[39m ",
|
|
29
|
+
"name": Object {
|
|
30
|
+
"currentRange": "1.0.0",
|
|
31
|
+
"latestRange": "1.1.0",
|
|
32
|
+
"name": "zoo",
|
|
33
|
+
"source": "rootPolicy",
|
|
34
|
+
"targetField": "devDependencies",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
Object {
|
|
38
|
+
"message": "bar [90m(peer)[39m 1.0.0 ❯ 1.[92m[1m1.0[22m[39m ",
|
|
39
|
+
"name": Object {
|
|
40
|
+
"currentRange": "1.0.0",
|
|
41
|
+
"latestRange": "1.1.0",
|
|
42
|
+
"name": "bar",
|
|
43
|
+
"source": "rootPolicy",
|
|
44
|
+
"targetField": "peerDependencies",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
"message": "[36mRoot policies[39m",
|
|
49
|
+
},
|
|
50
|
+
]
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
exports[`makeOutdatedPkgChoices should render choices with context information 1`] = `
|
|
54
|
+
Array [
|
|
55
|
+
Object {
|
|
56
|
+
"choices": Array [
|
|
57
|
+
Object {
|
|
58
|
+
"message": "foo [90m(runtime)[39m 1.0.0 ❯ [91m[1m2.0.0[22m[39m ",
|
|
59
|
+
"name": Object {
|
|
60
|
+
"componentId": "comp1",
|
|
61
|
+
"currentRange": "1.0.0",
|
|
62
|
+
"latestRange": "2.0.0",
|
|
63
|
+
"name": "foo",
|
|
64
|
+
"source": "component",
|
|
65
|
+
"targetField": "dependencies",
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
"message": "[36mcomp1 (component)[39m",
|
|
70
|
+
},
|
|
71
|
+
Object {
|
|
72
|
+
"choices": Array [
|
|
73
|
+
Object {
|
|
74
|
+
"message": "bar [90m(peer)[39m 1.0.0 ❯ 1.[92m[1m1.0[22m[39m ",
|
|
75
|
+
"name": Object {
|
|
76
|
+
"currentRange": "1.0.0",
|
|
77
|
+
"latestRange": "1.1.0",
|
|
78
|
+
"name": "bar",
|
|
79
|
+
"source": "variants",
|
|
80
|
+
"targetField": "peerDependencies",
|
|
81
|
+
"variantPattern": "{comp2}",
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
"message": "[36m{comp2} (variant)[39m",
|
|
86
|
+
},
|
|
87
|
+
]
|
|
88
|
+
`;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`makeOutdatedPkgChoices should render choices in correct order 1`] = `
|
|
4
|
+
Array [
|
|
5
|
+
Object {
|
|
6
|
+
"choices": Array [
|
|
7
|
+
Object {
|
|
8
|
+
"message": "foo [90m(runtime)[39m 1.0.0 ❯ [91m[1m2.0.0[22m[39m ",
|
|
9
|
+
"name": Object {
|
|
10
|
+
"currentRange": "1.0.0",
|
|
11
|
+
"latestRange": "2.0.0",
|
|
12
|
+
"name": "foo",
|
|
13
|
+
"source": "rootPolicy",
|
|
14
|
+
"targetField": "dependencies",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
Object {
|
|
18
|
+
"message": "qar [90m(runtime)[39m 1.0.0 ❯ 1.[92m[1m1.0[22m[39m ",
|
|
19
|
+
"name": Object {
|
|
20
|
+
"currentRange": "1.0.0",
|
|
21
|
+
"latestRange": "1.1.0",
|
|
22
|
+
"name": "qar",
|
|
23
|
+
"source": "rootPolicy",
|
|
24
|
+
"targetField": "dependencies",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
Object {
|
|
28
|
+
"message": "zoo [90m(dev)[39m 1.0.0 ❯ 1.[92m[1m1.0[22m[39m ",
|
|
29
|
+
"name": Object {
|
|
30
|
+
"currentRange": "1.0.0",
|
|
31
|
+
"latestRange": "1.1.0",
|
|
32
|
+
"name": "zoo",
|
|
33
|
+
"source": "rootPolicy",
|
|
34
|
+
"targetField": "devDependencies",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
Object {
|
|
38
|
+
"message": "bar [90m(peer)[39m 1.0.0 ❯ 1.[92m[1m1.0[22m[39m ",
|
|
39
|
+
"name": Object {
|
|
40
|
+
"currentRange": "1.0.0",
|
|
41
|
+
"latestRange": "1.1.0",
|
|
42
|
+
"name": "bar",
|
|
43
|
+
"source": "rootPolicy",
|
|
44
|
+
"targetField": "peerDependencies",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
"message": "[36mRoot policies[39m",
|
|
49
|
+
},
|
|
50
|
+
]
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
exports[`makeOutdatedPkgChoices should render choices with context information 1`] = `
|
|
54
|
+
Array [
|
|
55
|
+
Object {
|
|
56
|
+
"choices": Array [
|
|
57
|
+
Object {
|
|
58
|
+
"message": "foo [90m(runtime)[39m 1.0.0 ❯ [91m[1m2.0.0[22m[39m ",
|
|
59
|
+
"name": Object {
|
|
60
|
+
"componentId": "comp1",
|
|
61
|
+
"currentRange": "1.0.0",
|
|
62
|
+
"latestRange": "2.0.0",
|
|
63
|
+
"name": "foo",
|
|
64
|
+
"source": "component",
|
|
65
|
+
"targetField": "dependencies",
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
"message": "[36mcomp1 (component)[39m",
|
|
70
|
+
},
|
|
71
|
+
Object {
|
|
72
|
+
"choices": Array [
|
|
73
|
+
Object {
|
|
74
|
+
"message": "bar [90m(peer)[39m 1.0.0 ❯ 1.[92m[1m1.0[22m[39m ",
|
|
75
|
+
"name": Object {
|
|
76
|
+
"currentRange": "1.0.0",
|
|
77
|
+
"latestRange": "1.1.0",
|
|
78
|
+
"name": "bar",
|
|
79
|
+
"source": "variants",
|
|
80
|
+
"targetField": "peerDependencies",
|
|
81
|
+
"variantPattern": "{comp2}",
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
"message": "[36m{comp2} (variant)[39m",
|
|
86
|
+
},
|
|
87
|
+
]
|
|
88
|
+
`;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OutdatedPkg } from '@teambit/dependency-resolver';
|
|
2
|
+
/**
|
|
3
|
+
* Lets the user pick the packages that should be updated.
|
|
4
|
+
*/
|
|
5
|
+
export declare function pickOutdatedPkgs(outdatedPkgs: OutdatedPkg[]): Promise<OutdatedPkg[]>;
|
|
6
|
+
/**
|
|
7
|
+
* Groups the outdated packages and makes choices for enquirer's prompt.
|
|
8
|
+
*/
|
|
9
|
+
export declare function makeOutdatedPkgChoices(outdatedPkgs: OutdatedPkg[]): {
|
|
10
|
+
message: string;
|
|
11
|
+
choices: unknown;
|
|
12
|
+
}[];
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
require("core-js/modules/es.array.iterator.js");
|
|
6
|
+
|
|
7
|
+
require("core-js/modules/es.array.sort.js");
|
|
8
|
+
|
|
9
|
+
require("core-js/modules/es.promise.js");
|
|
10
|
+
|
|
11
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
12
|
+
|
|
13
|
+
Object.defineProperty(exports, "__esModule", {
|
|
14
|
+
value: true
|
|
15
|
+
});
|
|
16
|
+
exports.makeOutdatedPkgChoices = makeOutdatedPkgChoices;
|
|
17
|
+
exports.pickOutdatedPkgs = pickOutdatedPkgs;
|
|
18
|
+
|
|
19
|
+
function _colorizeSemverDiff() {
|
|
20
|
+
const data = _interopRequireDefault(require("@pnpm/colorize-semver-diff"));
|
|
21
|
+
|
|
22
|
+
_colorizeSemverDiff = function () {
|
|
23
|
+
return data;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function _semverDiff() {
|
|
30
|
+
const data = _interopRequireDefault(require("@pnpm/semver-diff"));
|
|
31
|
+
|
|
32
|
+
_semverDiff = function () {
|
|
33
|
+
return data;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function _table() {
|
|
40
|
+
const data = require("table");
|
|
41
|
+
|
|
42
|
+
_table = function () {
|
|
43
|
+
return data;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return data;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function _chalk() {
|
|
50
|
+
const data = _interopRequireDefault(require("chalk"));
|
|
51
|
+
|
|
52
|
+
_chalk = function () {
|
|
53
|
+
return data;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return data;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function _enquirer() {
|
|
60
|
+
const data = require("enquirer");
|
|
61
|
+
|
|
62
|
+
_enquirer = function () {
|
|
63
|
+
return data;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
return data;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Lets the user pick the packages that should be updated.
|
|
71
|
+
*/
|
|
72
|
+
async function pickOutdatedPkgs(outdatedPkgs) {
|
|
73
|
+
const {
|
|
74
|
+
updateDependencies
|
|
75
|
+
} = await (0, _enquirer().prompt)({
|
|
76
|
+
choices: makeOutdatedPkgChoices(outdatedPkgs),
|
|
77
|
+
footer: '\nEnter to start updating. Ctrl-c to cancel.',
|
|
78
|
+
indicator: (state, choice) => ` ${choice.enabled ? '●' : '○'}`,
|
|
79
|
+
message: 'Choose which packages to update ' + `(Press ${_chalk().default.cyan('<space>')} to select, ` + `${_chalk().default.cyan('<a>')} to toggle all, ` + `${_chalk().default.cyan('<i>')} to invert selection)
|
|
80
|
+
${_chalk().default.green('Green')} - indicates a semantically safe update
|
|
81
|
+
${_chalk().default.red('Red')} - indicates a semantically breaking change`,
|
|
82
|
+
name: 'updateDependencies',
|
|
83
|
+
pointer: '❯',
|
|
84
|
+
styles: {
|
|
85
|
+
dark: _chalk().default.white,
|
|
86
|
+
em: _chalk().default.bgBlack.whiteBright,
|
|
87
|
+
success: _chalk().default.white
|
|
88
|
+
},
|
|
89
|
+
type: 'multiselect',
|
|
90
|
+
|
|
91
|
+
validate(value) {
|
|
92
|
+
if (value.length === 0) {
|
|
93
|
+
return 'You must choose at least one package.';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return true;
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
j() {
|
|
100
|
+
return this.down();
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
k() {
|
|
104
|
+
return this.up();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
});
|
|
108
|
+
return updateDependencies.filter(updateDependency => typeof updateDependency !== 'string');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const DEP_TYPE_PRIORITY = {
|
|
112
|
+
dependencies: 0,
|
|
113
|
+
devDependencies: 1,
|
|
114
|
+
peerDependencies: 2
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Groups the outdated packages and makes choices for enquirer's prompt.
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
function makeOutdatedPkgChoices(outdatedPkgs) {
|
|
121
|
+
outdatedPkgs.sort((pkg1, pkg2) => {
|
|
122
|
+
if (pkg1.targetField === pkg2.targetField) return pkg1.name.localeCompare(pkg2.name);
|
|
123
|
+
return DEP_TYPE_PRIORITY[pkg1.targetField] - DEP_TYPE_PRIORITY[pkg2.targetField];
|
|
124
|
+
});
|
|
125
|
+
const renderedTable = alignColumns(outdatedPkgsRows(outdatedPkgs));
|
|
126
|
+
const groupedChoices = {};
|
|
127
|
+
outdatedPkgs.forEach((outdatedPkg, index) => {
|
|
128
|
+
const context = renderContext(outdatedPkg);
|
|
129
|
+
|
|
130
|
+
if (!groupedChoices[context]) {
|
|
131
|
+
groupedChoices[context] = [];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
groupedChoices[context].push({
|
|
135
|
+
message: renderedTable[index],
|
|
136
|
+
name: outdatedPkg
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
const choices = Object.entries(groupedChoices).map(([context, subChoices]) => ({
|
|
140
|
+
message: _chalk().default.cyan(context),
|
|
141
|
+
choices: subChoices
|
|
142
|
+
}));
|
|
143
|
+
return choices;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function renderContext(outdatedPkg) {
|
|
147
|
+
if (outdatedPkg.variantPattern) {
|
|
148
|
+
return `${outdatedPkg.variantPattern} (variant)`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (outdatedPkg.componentId) {
|
|
152
|
+
return `${outdatedPkg.componentId} (component)`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return 'Root policies';
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const TARGET_FIELD_TO_DEP_TYPE = {
|
|
159
|
+
devDependencies: 'dev',
|
|
160
|
+
dependencies: 'runtime',
|
|
161
|
+
peerDependencies: 'peer'
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
function outdatedPkgsRows(outdatedPkgs) {
|
|
165
|
+
return outdatedPkgs.map(outdatedPkg => {
|
|
166
|
+
const {
|
|
167
|
+
change,
|
|
168
|
+
diff
|
|
169
|
+
} = (0, _semverDiff().default)(outdatedPkg.currentRange, outdatedPkg.latestRange);
|
|
170
|
+
let colorizeChange = change !== null && change !== void 0 ? change : 'breaking';
|
|
171
|
+
|
|
172
|
+
if (change === 'feature') {
|
|
173
|
+
colorizeChange = 'fix';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const latest = (0, _colorizeSemverDiff().default)({
|
|
177
|
+
change: colorizeChange,
|
|
178
|
+
diff
|
|
179
|
+
});
|
|
180
|
+
return [outdatedPkg.name, _chalk().default.grey(`(${TARGET_FIELD_TO_DEP_TYPE[outdatedPkg.targetField]})`), outdatedPkg.currentRange, '❯', latest];
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function alignColumns(rows) {
|
|
185
|
+
return (0, _table().table)(rows, {
|
|
186
|
+
border: (0, _table().getBorderCharacters)('void'),
|
|
187
|
+
columnDefault: {
|
|
188
|
+
paddingLeft: 0,
|
|
189
|
+
paddingRight: 1
|
|
190
|
+
},
|
|
191
|
+
columns: {
|
|
192
|
+
// This is the current range column
|
|
193
|
+
2: {
|
|
194
|
+
alignment: 'right'
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
drawHorizontalLine: () => false
|
|
198
|
+
}).split('\n');
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
//# sourceMappingURL=pick-outdated-pkgs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["pick-outdated-pkgs.ts"],"names":["pickOutdatedPkgs","outdatedPkgs","updateDependencies","choices","makeOutdatedPkgChoices","footer","indicator","state","choice","enabled","message","chalk","cyan","green","red","name","pointer","styles","dark","white","em","bgBlack","whiteBright","success","type","validate","value","length","j","down","k","up","filter","updateDependency","DEP_TYPE_PRIORITY","dependencies","devDependencies","peerDependencies","sort","pkg1","pkg2","targetField","localeCompare","renderedTable","alignColumns","outdatedPkgsRows","groupedChoices","forEach","outdatedPkg","index","context","renderContext","push","Object","entries","map","subChoices","variantPattern","componentId","TARGET_FIELD_TO_DEP_TYPE","change","diff","currentRange","latestRange","colorizeChange","latest","grey","rows","border","columnDefault","paddingLeft","paddingRight","columns","alignment","drawHorizontalLine","split"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AACA;AACA;AACO,eAAeA,gBAAf,CAAgCC,YAAhC,EAAqF;AAC1F,QAAM;AAAEC,IAAAA;AAAF,MAA0B,MAAM,wBAAO;AAC3CC,IAAAA,OAAO,EAAEC,sBAAsB,CAACH,YAAD,CADY;AAE3CI,IAAAA,MAAM,EAAE,8CAFmC;AAG3CC,IAAAA,SAAS,EAAE,CAACC,KAAD,EAAaC,MAAb,KAA8B,IAAGA,MAAM,CAACC,OAAP,GAAiB,GAAjB,GAAuB,GAAI,EAH5B;AAI3CC,I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AAVT,GAAZ,EAWJC,KAXI,CAWE,IAXF,CAAP;AAYD","sourcesContent":["import colorizeSemverDiff from '@pnpm/colorize-semver-diff';\nimport semverDiff from '@pnpm/semver-diff';\nimport { OutdatedPkg } from '@teambit/dependency-resolver';\nimport { getBorderCharacters, table } from 'table';\nimport chalk from 'chalk';\nimport { prompt } from 'enquirer';\n\n/**\n * Lets the user pick the packages that should be updated.\n */\nexport async function pickOutdatedPkgs(outdatedPkgs: OutdatedPkg[]): Promise<OutdatedPkg[]> {\n const { updateDependencies } = (await prompt({\n choices: makeOutdatedPkgChoices(outdatedPkgs),\n footer: '\\nEnter to start updating. Ctrl-c to cancel.',\n indicator: (state: any, choice: any) => ` ${choice.enabled ? '●' : '○'}`,\n message:\n 'Choose which packages to update ' +\n `(Press ${chalk.cyan('<space>')} to select, ` +\n `${chalk.cyan('<a>')} to toggle all, ` +\n `${chalk.cyan('<i>')} to invert selection)\n${chalk.green('Green')} - indicates a semantically safe update\n${chalk.red('Red')} - indicates a semantically breaking change`,\n name: 'updateDependencies',\n pointer: '❯',\n styles: {\n dark: chalk.white,\n em: chalk.bgBlack.whiteBright,\n success: chalk.white,\n },\n type: 'multiselect',\n validate(value: string[]) {\n if (value.length === 0) {\n return 'You must choose at least one package.';\n }\n return true;\n },\n j() {\n return this.down();\n },\n k() {\n return this.up();\n },\n } as any)) as { updateDependencies: Array<string | OutdatedPkg> };\n return updateDependencies.filter((updateDependency) => typeof updateDependency !== 'string') as OutdatedPkg[];\n}\n\nconst DEP_TYPE_PRIORITY = {\n dependencies: 0,\n devDependencies: 1,\n peerDependencies: 2,\n};\n\n/**\n * Groups the outdated packages and makes choices for enquirer's prompt.\n */\nexport function makeOutdatedPkgChoices(outdatedPkgs: OutdatedPkg[]) {\n outdatedPkgs.sort((pkg1, pkg2) => {\n if (pkg1.targetField === pkg2.targetField) return pkg1.name.localeCompare(pkg2.name);\n return DEP_TYPE_PRIORITY[pkg1.targetField] - DEP_TYPE_PRIORITY[pkg2.targetField];\n });\n const renderedTable = alignColumns(outdatedPkgsRows(outdatedPkgs));\n const groupedChoices = {};\n outdatedPkgs.forEach((outdatedPkg, index) => {\n const context = renderContext(outdatedPkg);\n if (!groupedChoices[context]) {\n groupedChoices[context] = [];\n }\n groupedChoices[context].push({\n message: renderedTable[index],\n name: outdatedPkg,\n });\n });\n const choices = Object.entries(groupedChoices).map(([context, subChoices]) => ({\n message: chalk.cyan(context),\n choices: subChoices,\n }));\n return choices;\n}\n\nfunction renderContext(outdatedPkg: OutdatedPkg) {\n if (outdatedPkg.variantPattern) {\n return `${outdatedPkg.variantPattern} (variant)`;\n }\n if (outdatedPkg.componentId) {\n return `${outdatedPkg.componentId} (component)`;\n }\n return 'Root policies';\n}\n\nconst TARGET_FIELD_TO_DEP_TYPE = {\n devDependencies: 'dev',\n dependencies: 'runtime',\n peerDependencies: 'peer',\n};\n\nfunction outdatedPkgsRows(outdatedPkgs: OutdatedPkg[]) {\n return outdatedPkgs.map((outdatedPkg) => {\n const { change, diff } = semverDiff(outdatedPkg.currentRange, outdatedPkg.latestRange);\n let colorizeChange = change ?? 'breaking';\n if (change === 'feature') {\n colorizeChange = 'fix';\n }\n const latest = colorizeSemverDiff({\n change: colorizeChange,\n diff,\n });\n return [\n outdatedPkg.name,\n chalk.grey(`(${TARGET_FIELD_TO_DEP_TYPE[outdatedPkg.targetField]})`),\n outdatedPkg.currentRange,\n '❯',\n latest,\n ];\n });\n}\n\nfunction alignColumns(rows: string[][]) {\n return table(rows, {\n border: getBorderCharacters('void'),\n columnDefault: {\n paddingLeft: 0,\n paddingRight: 1,\n },\n columns: {\n // This is the current range column\n 2: { alignment: 'right' },\n },\n drawHorizontalLine: () => false,\n }).split('\\n');\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|