@servicetitan/startup 28.4.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/get-command.d.ts +1 -3
- package/dist/cli/commands/get-command.d.ts.map +1 -1
- package/dist/cli/commands/get-command.js.map +1 -1
- 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/commands/types.d.ts +1 -0
- package/dist/cli/commands/types.d.ts.map +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/index.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/maybe-create-git-folder.d.ts +2 -1
- package/dist/cli/utils/maybe-create-git-folder.d.ts.map +1 -1
- package/dist/cli/utils/maybe-create-git-folder.js +5 -1
- package/dist/cli/utils/maybe-create-git-folder.js.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 +20 -22
- 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/get-command.ts +1 -3
- 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/commands/types.ts +2 -0
- package/src/cli/index.ts +1 -1
- package/src/cli/utils/__tests__/cli-npm.test.ts +39 -26
- package/src/cli/utils/__tests__/maybe-create-git-folder.test.ts +23 -7
- package/src/cli/utils/cli-npm.ts +25 -16
- package/src/cli/utils/maybe-create-git-folder.ts +7 -1
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { isWebComponent, log, logErrors, readJson } from '../../utils';
|
|
2
|
-
import { gitGetBranch } from '../utils/cli-git';
|
|
3
|
-
import { npmGetPackageVersionDates, npmUnpublish } from '../utils/cli-npm';
|
|
4
2
|
import { getBranchesConfigs } from '../../utils/get-branch-configs';
|
|
3
|
+
import { gitGetBranch } from '../utils/cli-git';
|
|
4
|
+
import { Version, npmGetPackageVersionsDetails, npmUnpublish } from '../utils/cli-npm';
|
|
5
5
|
import { Command } from './types';
|
|
6
6
|
|
|
7
7
|
export interface ArgsPackageClean {
|
|
8
|
-
|
|
8
|
+
all?: true;
|
|
9
|
+
branch?: string;
|
|
9
10
|
count?: number;
|
|
11
|
+
dry?: boolean;
|
|
12
|
+
registry?: string;
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
export class MFEPackageClean implements Command {
|
|
@@ -23,37 +26,34 @@ export class MFEPackageClean implements Command {
|
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
const data = this.getCleanData();
|
|
26
|
-
const
|
|
27
|
-
const packageName = packageJson.name;
|
|
29
|
+
const packageName = readJson('package.json').name;
|
|
28
30
|
const branchedVersions = this.getBranchedVersions(packageName, data.registry);
|
|
29
31
|
|
|
30
|
-
log.info(
|
|
31
|
-
`branched versions (${data.count}):`,
|
|
32
|
-
JSON.stringify(branchedVersions, undefined, 4)
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const branchedVersionsToClean: Record<string, [string, Date][]> = {};
|
|
32
|
+
log.info(`branched versions (${data.count}):`, JSON.stringify(branchedVersions, null, 2));
|
|
36
33
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
const branchedVersionsToClean: Record<string, Version[]> = {};
|
|
35
|
+
for (const [branch, versions] of Object.entries(branchedVersions)) {
|
|
36
|
+
// Limit branches for now
|
|
37
|
+
if (!data.branches.includes(branch)) {
|
|
38
|
+
log.info(`ignoring unrecognized branch "${branch}"`);
|
|
40
39
|
continue;
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
branchedVersionsToClean[branch] = this.excludeTagged(versions)
|
|
43
|
+
.sort(({ date: adt }, { date: bdt }) => (adt > bdt ? -1 : 1))
|
|
44
|
+
.slice(data.count);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
log.info(
|
|
48
|
-
'found versions for unpublish:',
|
|
49
|
-
JSON.stringify(branchedVersionsToClean, undefined, 4)
|
|
50
|
-
);
|
|
51
|
-
|
|
47
|
+
log.info('found versions for unpublish:', JSON.stringify(branchedVersionsToClean, null, 2));
|
|
52
48
|
const unVersions = Object.keys(branchedVersionsToClean).reduce(
|
|
53
|
-
(out, br) => [...out, ...branchedVersionsToClean[br].map((
|
|
49
|
+
(out, br) => [...out, ...branchedVersionsToClean[br].map(({ name }) => name)],
|
|
54
50
|
[]
|
|
55
51
|
);
|
|
56
52
|
|
|
53
|
+
if (this.args.dry) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
57
|
for (const version of unVersions) {
|
|
58
58
|
try {
|
|
59
59
|
// eslint-disable-next-line no-await-in-loop
|
|
@@ -64,6 +64,16 @@ export class MFEPackageClean implements Command {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
private excludeTagged(versions: Version[]) {
|
|
68
|
+
return versions.filter(({ name, tag }) => {
|
|
69
|
+
if (tag) {
|
|
70
|
+
log.info(`ignoring version ${name} tagged "${tag}"`);
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
67
77
|
private getCleanData(): {
|
|
68
78
|
count: number;
|
|
69
79
|
registry: string;
|
|
@@ -76,66 +86,57 @@ export class MFEPackageClean implements Command {
|
|
|
76
86
|
|
|
77
87
|
let branches: string[];
|
|
78
88
|
|
|
79
|
-
if (this.args.
|
|
80
|
-
branches =
|
|
89
|
+
if (this.args.all === true) {
|
|
90
|
+
branches = Object.keys(getBranchesConfigs());
|
|
81
91
|
} else if (typeof this.args.branch === 'string') {
|
|
82
92
|
branches = [this.args.branch];
|
|
83
93
|
} else {
|
|
84
|
-
branches =
|
|
94
|
+
branches = [gitGetBranch()];
|
|
85
95
|
}
|
|
86
96
|
|
|
87
|
-
const registry = 'https://verdaccio.servicetitan.com';
|
|
97
|
+
const registry = this.args.registry ?? 'https://verdaccio.servicetitan.com';
|
|
88
98
|
|
|
89
99
|
return { count, registry, branches };
|
|
90
100
|
}
|
|
91
101
|
|
|
92
102
|
private getBranchedVersions(packageName: string, registry: string) {
|
|
93
|
-
const versions =
|
|
94
|
-
const branchedVersions: Record<string, [
|
|
95
|
-
const unknownVersions: string[] = [];
|
|
96
|
-
|
|
97
|
-
const addVersion = (branch: string, version: string, dt: Date) => {
|
|
98
|
-
if (!branchedVersions[branch]) {
|
|
99
|
-
branchedVersions[branch] = [];
|
|
100
|
-
}
|
|
103
|
+
const versions = npmGetPackageVersionsDetails(registry, packageName);
|
|
104
|
+
const branchedVersions: Record<string, Version[]> = {};
|
|
101
105
|
|
|
102
|
-
|
|
103
|
-
|
|
106
|
+
function addVersion(branch: string, version: Version) {
|
|
107
|
+
branchedVersions[branch] ??= [];
|
|
108
|
+
branchedVersions[branch].push(version);
|
|
109
|
+
}
|
|
104
110
|
|
|
105
|
-
for (const
|
|
106
|
-
|
|
111
|
+
for (const version of versions) {
|
|
112
|
+
const { name } = version;
|
|
113
|
+
if (!name.startsWith('0.0.0-')) {
|
|
107
114
|
continue;
|
|
108
115
|
}
|
|
109
116
|
|
|
110
|
-
const buildVersion =
|
|
117
|
+
const buildVersion = name.replace('0.0.0-', '');
|
|
111
118
|
|
|
119
|
+
// master version generated by nerdbank versioning
|
|
112
120
|
if (/^(\d+)\.(\d+)\.(\d+)$/.test(buildVersion)) {
|
|
113
|
-
|
|
114
|
-
addVersion('master', version, dt);
|
|
121
|
+
addVersion('master', version);
|
|
115
122
|
continue;
|
|
116
123
|
}
|
|
117
124
|
|
|
125
|
+
// branch version generated by nerdbank versioning
|
|
118
126
|
const match1 = buildVersion.match(/^(\d+)\.(\d+)\.(\d+)-([\dA-Za-z-]+).([\dA-Za-z]+)$/);
|
|
119
|
-
|
|
120
127
|
if (match1?.length) {
|
|
121
|
-
|
|
122
|
-
addVersion(match1[4], version, dt);
|
|
128
|
+
addVersion(match1[4], version);
|
|
123
129
|
continue;
|
|
124
130
|
}
|
|
125
131
|
|
|
132
|
+
// branch version generated by mfe-publisher versioning
|
|
126
133
|
const match2 = buildVersion.match(/^([\dA-Za-z-]+).([\dA-Za-z]+)$/);
|
|
127
|
-
|
|
128
134
|
if (match2?.length) {
|
|
129
|
-
|
|
130
|
-
addVersion(match2[1], version, dt);
|
|
135
|
+
addVersion(match2[1], version);
|
|
131
136
|
continue;
|
|
132
137
|
}
|
|
133
138
|
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (unknownVersions.length) {
|
|
138
|
-
log.info('unknown versions:', unknownVersions.join());
|
|
139
|
+
log.info(`skipping unrecognized version: ${name}`);
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
return branchedVersions;
|
|
@@ -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
|
}
|
package/src/cli/index.ts
CHANGED
|
@@ -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(() => {
|
|
@@ -1,18 +1,32 @@
|
|
|
1
1
|
import { fs, vol } from 'memfs';
|
|
2
2
|
|
|
3
3
|
import { maybeCreateGitFolder } from '../maybe-create-git-folder';
|
|
4
|
+
import { Init } from '../../commands/init';
|
|
5
|
+
import { Start } from '../../commands/start';
|
|
4
6
|
|
|
5
7
|
jest.mock('fs', () => fs);
|
|
6
8
|
|
|
7
9
|
describe(`[startup] Utils`, () => {
|
|
8
10
|
describe(`${maybeCreateGitFolder.name}`, () => {
|
|
11
|
+
let command: Parameters<typeof maybeCreateGitFolder>[0];
|
|
9
12
|
const mkdirSpy = jest.spyOn(fs, 'mkdirSync').mockImplementation(jest.fn());
|
|
10
13
|
|
|
11
|
-
beforeEach(() =>
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
command = Start;
|
|
16
|
+
vol.fromJSON({});
|
|
17
|
+
});
|
|
12
18
|
|
|
13
19
|
afterEach(() => vol.reset);
|
|
14
20
|
|
|
15
|
-
const subject = () => maybeCreateGitFolder();
|
|
21
|
+
const subject = () => maybeCreateGitFolder(command);
|
|
22
|
+
|
|
23
|
+
function itDoesNotCreateGitFolder() {
|
|
24
|
+
test('does not create .git folder', () => {
|
|
25
|
+
subject();
|
|
26
|
+
|
|
27
|
+
expect(mkdirSpy).not.toHaveBeenCalledWith();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
16
30
|
|
|
17
31
|
describe('when running on Windows', () => {
|
|
18
32
|
beforeEach(() => {
|
|
@@ -24,6 +38,12 @@ describe(`[startup] Utils`, () => {
|
|
|
24
38
|
|
|
25
39
|
expect(mkdirSpy).toHaveBeenCalledWith('.git');
|
|
26
40
|
});
|
|
41
|
+
|
|
42
|
+
describe('when command is Init', () => {
|
|
43
|
+
beforeEach(() => (command = Init));
|
|
44
|
+
|
|
45
|
+
itDoesNotCreateGitFolder();
|
|
46
|
+
});
|
|
27
47
|
});
|
|
28
48
|
|
|
29
49
|
describe('when not running on Windows', () => {
|
|
@@ -31,11 +51,7 @@ describe(`[startup] Utils`, () => {
|
|
|
31
51
|
Object.defineProperty(process, 'platform', { value: 'linux' });
|
|
32
52
|
});
|
|
33
53
|
|
|
34
|
-
|
|
35
|
-
subject();
|
|
36
|
-
|
|
37
|
-
expect(mkdirSpy).not.toHaveBeenCalledWith();
|
|
38
|
-
});
|
|
54
|
+
itDoesNotCreateGitFolder();
|
|
39
55
|
});
|
|
40
56
|
});
|
|
41
57
|
});
|
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) {
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
|
|
3
|
+
import { Init } from '../commands/init';
|
|
4
|
+
import { Command, Newable } from '../commands/types';
|
|
5
|
+
|
|
3
6
|
/**
|
|
4
7
|
* Create empty .git folder to workaround issue where Lerna does not
|
|
5
8
|
* detect workspace packages on Windows systems. The empty .git folder
|
|
@@ -8,10 +11,13 @@ import fs from 'fs';
|
|
|
8
11
|
* keeps reappearing (e.g., https://github.com/nrwl/nx/issues/9584 and
|
|
9
12
|
* https://github.com/nrwl/nx/issues/18094)
|
|
10
13
|
*/
|
|
11
|
-
export function maybeCreateGitFolder() {
|
|
14
|
+
export function maybeCreateGitFolder(command: Newable<Command>) {
|
|
12
15
|
if (process.platform !== 'win32') {
|
|
13
16
|
return;
|
|
14
17
|
}
|
|
18
|
+
if (command === Init) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
15
21
|
if (!fs.existsSync('.git')) {
|
|
16
22
|
fs.mkdirSync('.git');
|
|
17
23
|
}
|