@servicetitan/startup 28.5.0 → 29.0.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/dist/cli/commands/mfe-package-clean.d.ts +5 -1
- package/dist/cli/commands/mfe-package-clean.d.ts.map +1 -1
- package/dist/cli/commands/mfe-package-clean.js +46 -36
- package/dist/cli/commands/mfe-package-clean.js.map +1 -1
- package/dist/cli/commands/mfe-package-publish.d.ts +1 -1
- package/dist/cli/commands/mfe-package-publish.d.ts.map +1 -1
- package/dist/cli/commands/mfe-package-publish.js +3 -13
- package/dist/cli/commands/mfe-package-publish.js.map +1 -1
- package/dist/cli/commands/mfe-publish.d.ts.map +1 -1
- package/dist/cli/commands/mfe-publish.js +6 -5
- package/dist/cli/commands/mfe-publish.js.map +1 -1
- package/dist/cli/utils/cli-npm.d.ts +10 -3
- package/dist/cli/utils/cli-npm.d.ts.map +1 -1
- package/dist/cli/utils/cli-npm.js +13 -15
- package/dist/cli/utils/cli-npm.js.map +1 -1
- package/dist/cli/utils/cli-os.d.ts.map +1 -1
- package/dist/cli/utils/publish.d.ts.map +1 -1
- package/dist/utils/get-jest-config.d.ts.map +1 -1
- package/dist/webpack/configs/plugins/ignore-plugin/check-resource.d.ts.map +1 -1
- package/dist/webpack/utils/hash-mod.d.ts.map +1 -1
- package/dist/webpack/utils/testing/execute.d.ts.map +1 -1
- package/dist/webpack/utils/testing/get-compiler.d.ts.map +1 -1
- package/package.json +19 -21
- package/src/cli/commands/__tests__/mfe-package-clean.test.ts +143 -73
- package/src/cli/commands/__tests__/mfe-package-publish.test.ts +27 -20
- package/src/cli/commands/__tests__/mfe-publish.test.ts +18 -7
- package/src/cli/commands/mfe-package-clean.ts +53 -52
- package/src/cli/commands/mfe-package-publish.ts +7 -21
- package/src/cli/commands/mfe-publish.ts +6 -5
- package/src/cli/utils/__tests__/cli-npm.test.ts +39 -26
- package/src/cli/utils/cli-npm.ts +25 -16
|
@@ -2,13 +2,7 @@ import path from 'path';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { getFolders, isWebComponent, log, logErrors, readJson } from '../../utils';
|
|
4
4
|
import { gitGetBranch, gitGetCommitHash } from '../utils/cli-git';
|
|
5
|
-
import {
|
|
6
|
-
npmGetPackageVersions,
|
|
7
|
-
npmPackageSet,
|
|
8
|
-
npmPublish,
|
|
9
|
-
npmPublishDry,
|
|
10
|
-
npmTagVersion,
|
|
11
|
-
} from '../utils/cli-npm';
|
|
5
|
+
import { npmGetPackageVersions, npmPackageSet, npmPublish, npmTagVersion } from '../utils/cli-npm';
|
|
12
6
|
import { getBranchesConfigs } from '../../utils/get-branch-configs';
|
|
13
7
|
import { getDefaultBuildVersion } from '../utils/publish';
|
|
14
8
|
import { EntryPoint, EntryPoints, Metadata } from '../../webpack/configs';
|
|
@@ -20,7 +14,7 @@ export interface ArgsPackagePublish {
|
|
|
20
14
|
dry?: boolean;
|
|
21
15
|
force?: boolean;
|
|
22
16
|
registry?: string;
|
|
23
|
-
tag?: string
|
|
17
|
+
tag?: string;
|
|
24
18
|
}
|
|
25
19
|
|
|
26
20
|
export class MFEPackagePublish implements Command {
|
|
@@ -92,11 +86,7 @@ export class MFEPackagePublish implements Command {
|
|
|
92
86
|
await npmPackageSet('files[1]', 'package.json');
|
|
93
87
|
}
|
|
94
88
|
|
|
95
|
-
|
|
96
|
-
await npmPublishDry();
|
|
97
|
-
} else {
|
|
98
|
-
await npmPublish(data.tag);
|
|
99
|
-
}
|
|
89
|
+
await npmPublish({ dry: data.dry, tag: data.tag || data.fallbackTag });
|
|
100
90
|
|
|
101
91
|
log.info(`${dryRunPrefix}published ${packageName} version ${data.version}`);
|
|
102
92
|
}
|
|
@@ -104,11 +94,12 @@ export class MFEPackagePublish implements Command {
|
|
|
104
94
|
private getPublishData(): {
|
|
105
95
|
version: string;
|
|
106
96
|
buildVersion: string;
|
|
107
|
-
tag
|
|
97
|
+
tag: string;
|
|
108
98
|
registry: string;
|
|
109
99
|
dry: boolean;
|
|
110
100
|
force: boolean;
|
|
111
101
|
isBranchConfigured: boolean;
|
|
102
|
+
fallbackTag: string;
|
|
112
103
|
} {
|
|
113
104
|
const cli = this.args;
|
|
114
105
|
const branch = cli.branch ?? gitGetBranch();
|
|
@@ -119,15 +110,9 @@ export class MFEPackagePublish implements Command {
|
|
|
119
110
|
buildVersion = getDefaultBuildVersion(branch, gitGetCommitHash());
|
|
120
111
|
}
|
|
121
112
|
|
|
122
|
-
if (!buildVersion) {
|
|
123
|
-
throw new Error('build version is not set');
|
|
124
|
-
}
|
|
125
|
-
|
|
126
113
|
let tag: string;
|
|
127
114
|
|
|
128
|
-
if (cli.tag
|
|
129
|
-
tag = '';
|
|
130
|
-
} else if (cli.tag) {
|
|
115
|
+
if (cli.tag) {
|
|
131
116
|
tag = cli.tag;
|
|
132
117
|
} else {
|
|
133
118
|
tag = branchConfig?.publishTag ?? '';
|
|
@@ -143,6 +128,7 @@ export class MFEPackagePublish implements Command {
|
|
|
143
128
|
dry: !!cli.dry,
|
|
144
129
|
force: !!cli.force,
|
|
145
130
|
isBranchConfigured: !!branchConfig,
|
|
131
|
+
fallbackTag: 'latest',
|
|
146
132
|
};
|
|
147
133
|
}
|
|
148
134
|
|
|
@@ -58,17 +58,18 @@ export class MFEPublish implements Command {
|
|
|
58
58
|
...[dry && '--dry'],
|
|
59
59
|
...[force && '--force'],
|
|
60
60
|
...[registry && `--registry ${registry}`],
|
|
61
|
-
...[tag && `--tag ${tag}`],
|
|
62
|
-
...[tag === false && `--no-tag`],
|
|
61
|
+
...[typeof tag === 'string' && `--tag ${tag}`],
|
|
63
62
|
].filter(item => !!item) as string[];
|
|
64
63
|
}
|
|
65
64
|
|
|
66
65
|
getCleanOptions() {
|
|
67
|
-
const { branch, count } = this.args as ArgsPackageClean;
|
|
66
|
+
const { all, branch, count, dry, registry } = this.args as ArgsPackageClean;
|
|
68
67
|
return [
|
|
69
|
-
...[
|
|
70
|
-
...[
|
|
68
|
+
...[all && '--all'],
|
|
69
|
+
...[typeof branch === 'string' && `--branch ${branch}`],
|
|
71
70
|
...[count && `--count ${count}`],
|
|
71
|
+
...[dry && '--dry'],
|
|
72
|
+
...[registry && `--registry ${registry}`],
|
|
72
73
|
].filter(item => !!item) as string[];
|
|
73
74
|
}
|
|
74
75
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { runCommand, runCommandOutput } from '../cli-os';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
npmGetPackageVersionDates,
|
|
5
4
|
npmGetPackageVersions,
|
|
5
|
+
npmGetPackageVersionsDetails,
|
|
6
6
|
npmPackageSet,
|
|
7
7
|
npmPublish,
|
|
8
|
-
npmPublishDry,
|
|
9
8
|
npmTagVersion,
|
|
10
9
|
npmUnpublish,
|
|
11
10
|
} from '../cli-npm';
|
|
@@ -48,7 +47,7 @@ describe('[startup] Cli Utils (Npm)', () => {
|
|
|
48
47
|
});
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
describe(
|
|
50
|
+
describe(npmGetPackageVersions.name, () => {
|
|
52
51
|
let args: Parameters<typeof npmGetPackageVersions>;
|
|
53
52
|
|
|
54
53
|
beforeEach(() => (args = ['{registry}', '{packageName}']));
|
|
@@ -82,30 +81,42 @@ describe('[startup] Cli Utils (Npm)', () => {
|
|
|
82
81
|
});
|
|
83
82
|
});
|
|
84
83
|
|
|
85
|
-
describe(
|
|
86
|
-
let args: Parameters<typeof
|
|
84
|
+
describe(npmGetPackageVersionsDetails.name, () => {
|
|
85
|
+
let args: Parameters<typeof npmGetPackageVersionsDetails>;
|
|
87
86
|
|
|
88
|
-
beforeEach(() =>
|
|
87
|
+
beforeEach(() => {
|
|
88
|
+
jest.useFakeTimers();
|
|
89
|
+
args = ['{registry}', '{packageName}'];
|
|
90
|
+
});
|
|
89
91
|
|
|
90
|
-
|
|
92
|
+
afterEach(() => jest.useRealTimers());
|
|
91
93
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
const subject = () => npmGetPackageVersionsDetails(...args);
|
|
95
|
+
|
|
96
|
+
itRunsCommandOutput(
|
|
97
|
+
subject,
|
|
98
|
+
'npm view {packageName} time dist-tags --registry {registry} --json',
|
|
99
|
+
{ timeout: 10000 }
|
|
100
|
+
);
|
|
95
101
|
|
|
96
|
-
test('converts results to
|
|
102
|
+
test('converts results to Version[]', () => {
|
|
97
103
|
function dayAgo(count: number) {
|
|
98
104
|
const date = new Date();
|
|
99
105
|
date.setDate(-count);
|
|
100
106
|
return date;
|
|
101
107
|
}
|
|
102
|
-
const result = {
|
|
108
|
+
const result = {
|
|
109
|
+
'time': { '1.0.1': dayAgo(3), '2.1.0': dayAgo(2), '3.0.0': dayAgo(1) },
|
|
110
|
+
'dist-tags': { latest: '3.0.0' },
|
|
111
|
+
};
|
|
103
112
|
|
|
104
113
|
jest.mocked(runCommandOutput).mockReturnValue(JSON.stringify(result));
|
|
105
114
|
|
|
106
|
-
expect(subject()).toEqual(
|
|
107
|
-
|
|
108
|
-
|
|
115
|
+
expect(subject()).toEqual([
|
|
116
|
+
{ name: '1.0.1', date: dayAgo(3) },
|
|
117
|
+
{ name: '2.1.0', date: dayAgo(2) },
|
|
118
|
+
{ name: '3.0.0', date: dayAgo(1), tag: 'latest' },
|
|
119
|
+
]);
|
|
109
120
|
});
|
|
110
121
|
|
|
111
122
|
describe('when an error occurs', () => {
|
|
@@ -121,7 +132,7 @@ describe('[startup] Cli Utils (Npm)', () => {
|
|
|
121
132
|
});
|
|
122
133
|
});
|
|
123
134
|
|
|
124
|
-
describe(
|
|
135
|
+
describe(npmPackageSet.name, () => {
|
|
125
136
|
let args: Parameters<typeof npmPackageSet>;
|
|
126
137
|
|
|
127
138
|
beforeEach(() => (args = ['{key}', '{value}']));
|
|
@@ -131,27 +142,29 @@ describe('[startup] Cli Utils (Npm)', () => {
|
|
|
131
142
|
itRunsCommand(subject, 'npm pkg set {key}={value}');
|
|
132
143
|
});
|
|
133
144
|
|
|
134
|
-
describe(
|
|
135
|
-
let
|
|
145
|
+
describe(npmPublish.name, () => {
|
|
146
|
+
let options: Parameters<typeof npmPublish>[0];
|
|
136
147
|
|
|
137
|
-
beforeEach(() => (
|
|
148
|
+
beforeEach(() => (options = {}));
|
|
138
149
|
|
|
139
|
-
const subject = async () => npmPublish(
|
|
150
|
+
const subject = async () => npmPublish(options);
|
|
140
151
|
|
|
141
152
|
itRunsCommand(subject, 'npm publish');
|
|
142
153
|
|
|
143
154
|
describe('with a tag', () => {
|
|
144
|
-
beforeEach(() =>
|
|
155
|
+
beforeEach(() => (options.tag = '{tag}'));
|
|
145
156
|
|
|
146
157
|
itRunsCommand(subject, 'npm publish --tag {tag}');
|
|
147
158
|
});
|
|
148
|
-
});
|
|
149
159
|
|
|
150
|
-
|
|
151
|
-
|
|
160
|
+
describe('with {dry: true}', () => {
|
|
161
|
+
beforeEach(() => (options.dry = true));
|
|
162
|
+
|
|
163
|
+
itRunsCommand(subject, 'npm publish --dry-run');
|
|
164
|
+
});
|
|
152
165
|
});
|
|
153
166
|
|
|
154
|
-
describe(
|
|
167
|
+
describe(npmUnpublish.name, () => {
|
|
155
168
|
let args: Parameters<typeof npmUnpublish>;
|
|
156
169
|
|
|
157
170
|
beforeEach(() => (args = ['{registry}', '{packageName}', '{packageVersion}']));
|
|
@@ -165,7 +178,7 @@ describe('[startup] Cli Utils (Npm)', () => {
|
|
|
165
178
|
);
|
|
166
179
|
});
|
|
167
180
|
|
|
168
|
-
describe(
|
|
181
|
+
describe(npmTagVersion.name, () => {
|
|
169
182
|
let args: Parameters<typeof npmTagVersion>[0];
|
|
170
183
|
|
|
171
184
|
beforeEach(() => {
|
package/src/cli/utils/cli-npm.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { runCommand, runCommandOutput } from './cli-os';
|
|
2
2
|
|
|
3
|
+
export interface Version {
|
|
4
|
+
name: string;
|
|
5
|
+
date: Date;
|
|
6
|
+
tag?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const NPM_TIMEOUT = 10000;
|
|
10
|
+
|
|
3
11
|
export function npmGetPackageVersions(registry: string, packageName: string): string[] {
|
|
4
12
|
try {
|
|
5
13
|
const v = runCommandOutput(
|
|
6
14
|
`npm show ${packageName} versions --registry ${registry} --json`,
|
|
7
|
-
{ timeout:
|
|
15
|
+
{ timeout: NPM_TIMEOUT }
|
|
8
16
|
);
|
|
9
17
|
|
|
10
18
|
return JSON.parse(v);
|
|
@@ -13,17 +21,22 @@ export function npmGetPackageVersions(registry: string, packageName: string): st
|
|
|
13
21
|
}
|
|
14
22
|
}
|
|
15
23
|
|
|
16
|
-
export function
|
|
24
|
+
export function npmGetPackageVersionsDetails(registry: string, packageName: string): Version[] {
|
|
17
25
|
try {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
const result = runCommandOutput(
|
|
27
|
+
`npm view ${packageName} time dist-tags --registry ${registry} --json`,
|
|
28
|
+
{ timeout: NPM_TIMEOUT }
|
|
29
|
+
);
|
|
22
30
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
const { time, 'dist-tags': distTags } = JSON.parse(result);
|
|
32
|
+
|
|
33
|
+
const tags = Object.fromEntries(
|
|
34
|
+
Object.entries(distTags).map(([tag, version]) => [version, tag])
|
|
26
35
|
);
|
|
36
|
+
|
|
37
|
+
return Object.keys(time).reduce((out, version) => {
|
|
38
|
+
return [...out, { name: version, date: new Date(time[version]), tag: tags[version] }];
|
|
39
|
+
}, []);
|
|
27
40
|
} catch {
|
|
28
41
|
return [];
|
|
29
42
|
}
|
|
@@ -31,16 +44,12 @@ export function npmGetPackageVersionDates(registry: string, packageName: string)
|
|
|
31
44
|
|
|
32
45
|
export async function npmUnpublish(registry: string, packageName: string, packageVersion: string) {
|
|
33
46
|
await runCommand(`npm unpublish ${packageName}@${packageVersion} --registry ${registry}`, {
|
|
34
|
-
timeout:
|
|
47
|
+
timeout: NPM_TIMEOUT,
|
|
35
48
|
});
|
|
36
49
|
}
|
|
37
50
|
|
|
38
|
-
export async function
|
|
39
|
-
await runCommand('npm publish
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export async function npmPublish(tag?: string) {
|
|
43
|
-
await runCommand(['npm publish', !!tag && `--tag ${tag}`]);
|
|
51
|
+
export async function npmPublish({ dry, tag }: { dry?: boolean; tag?: string }) {
|
|
52
|
+
await runCommand(['npm publish', !!tag && `--tag ${tag}`, !!dry && `--dry-run`]);
|
|
44
53
|
}
|
|
45
54
|
|
|
46
55
|
export async function npmPackageSet(key: string, value: string) {
|