@servicetitan/startup 31.6.0 → 32.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.
Files changed (64) hide show
  1. package/dist/cli/commands/init.d.ts +2 -1
  2. package/dist/cli/commands/init.d.ts.map +1 -1
  3. package/dist/cli/commands/init.js +24 -43
  4. package/dist/cli/commands/init.js.map +1 -1
  5. package/dist/cli/commands/install.d.ts +4 -0
  6. package/dist/cli/commands/install.d.ts.map +1 -1
  7. package/dist/cli/commands/install.js +91 -3
  8. package/dist/cli/commands/install.js.map +1 -1
  9. package/dist/cli/commands/mfe-package-clean.d.ts.map +1 -1
  10. package/dist/cli/commands/mfe-package-clean.js +5 -7
  11. package/dist/cli/commands/mfe-package-clean.js.map +1 -1
  12. package/dist/cli/commands/mfe-package-publish.d.ts.map +1 -1
  13. package/dist/cli/commands/mfe-package-publish.js +11 -15
  14. package/dist/cli/commands/mfe-package-publish.js.map +1 -1
  15. package/dist/cli/commands/upload-sourcemaps.d.ts.map +1 -1
  16. package/dist/cli/commands/upload-sourcemaps.js +1 -1
  17. package/dist/cli/commands/upload-sourcemaps.js.map +1 -1
  18. package/dist/cli/index.js +1 -2
  19. package/dist/cli/index.js.map +1 -1
  20. package/dist/cli/utils/cli-git.d.ts +11 -2
  21. package/dist/cli/utils/cli-git.d.ts.map +1 -1
  22. package/dist/cli/utils/cli-git.js +60 -4
  23. package/dist/cli/utils/cli-git.js.map +1 -1
  24. package/dist/cli/utils/index.d.ts +6 -0
  25. package/dist/cli/utils/index.d.ts.map +1 -1
  26. package/dist/cli/utils/index.js +6 -0
  27. package/dist/cli/utils/index.js.map +1 -1
  28. package/dist/cli/utils/is-ci.d.ts +2 -0
  29. package/dist/cli/utils/is-ci.d.ts.map +1 -0
  30. package/dist/cli/utils/is-ci.js +15 -0
  31. package/dist/cli/utils/is-ci.js.map +1 -0
  32. package/dist/cli/utils/lerna-exec.d.ts.map +1 -1
  33. package/dist/cli/utils/lerna-exec.js +2 -1
  34. package/dist/cli/utils/lerna-exec.js.map +1 -1
  35. package/dist/utils/get-branch-configs.d.ts +1 -1
  36. package/dist/utils/get-branch-configs.d.ts.map +1 -1
  37. package/dist/utils/get-branch-configs.js +2 -2
  38. package/dist/utils/get-branch-configs.js.map +1 -1
  39. package/dist/utils/index.d.ts +1 -0
  40. package/dist/utils/index.d.ts.map +1 -1
  41. package/dist/utils/index.js +1 -0
  42. package/dist/utils/index.js.map +1 -1
  43. package/package.json +6 -6
  44. package/src/cli/commands/__tests__/init.test.ts +21 -87
  45. package/src/cli/commands/__tests__/install.test.ts +174 -12
  46. package/src/cli/commands/__tests__/mfe-package-clean.test.ts +3 -6
  47. package/src/cli/commands/__tests__/mfe-package-publish.test.ts +6 -8
  48. package/src/cli/commands/__tests__/upload-sourcemaps.test.ts +7 -3
  49. package/src/cli/commands/init.ts +17 -37
  50. package/src/cli/commands/install.ts +95 -6
  51. package/src/cli/commands/mfe-package-clean.ts +2 -4
  52. package/src/cli/commands/mfe-package-publish.ts +18 -6
  53. package/src/cli/commands/upload-sourcemaps.ts +2 -2
  54. package/src/cli/index.ts +1 -2
  55. package/src/cli/utils/__tests__/cli-git.test.ts +142 -6
  56. package/src/cli/utils/__tests__/eslint.test.ts +3 -2
  57. package/src/cli/utils/__tests__/is-ci.test.ts +40 -0
  58. package/src/cli/utils/__tests__/lerna-exec.test.ts +6 -3
  59. package/src/cli/utils/cli-git.ts +55 -5
  60. package/src/cli/utils/index.ts +6 -0
  61. package/src/cli/utils/is-ci.ts +3 -0
  62. package/src/cli/utils/lerna-exec.ts +2 -1
  63. package/src/utils/get-branch-configs.ts +1 -1
  64. package/src/utils/index.ts +1 -0
@@ -1,11 +1,16 @@
1
- import { runCommandOutput } from '../cli-os';
1
+ import { runCommand, runCommandOutput } from '../cli-os';
2
2
 
3
- import { gitGetBranch, gitGetCommitHash } from '../cli-git';
3
+ import { gitCloneRepo, gitGetBranch, gitGetCommitHash, gitIsReachable } from '../cli-git';
4
+ import { isCI } from '../is-ci';
4
5
 
5
- jest.mock('../cli-os', () => ({ runCommandOutput: jest.fn() }));
6
+ jest.mock('../is-ci', () => ({ isCI: jest.fn() }));
7
+ jest.mock('../cli-os', () => ({ runCommand: jest.fn(), runCommandOutput: jest.fn() }));
6
8
 
7
9
  describe('[startup] Cli Utils (Git)', () => {
8
- beforeEach(() => jest.resetAllMocks());
10
+ beforeEach(() => {
11
+ jest.resetAllMocks();
12
+ jest.mocked(isCI).mockReturnValue(false);
13
+ });
9
14
 
10
15
  function itRunsCommand(subject: Function, command: string) {
11
16
  test(`runs "${command}"`, () => {
@@ -18,11 +23,142 @@ describe('[startup] Cli Utils (Git)', () => {
18
23
  });
19
24
  }
20
25
 
21
- describe(`${gitGetBranch.name}`, () => {
26
+ describe(gitGetBranch.name, () => {
22
27
  itRunsCommand(gitGetBranch, 'git rev-parse --abbrev-ref HEAD');
23
28
  });
24
29
 
25
- describe(`${gitGetCommitHash.name}`, () => {
30
+ describe(gitGetCommitHash.name, () => {
26
31
  itRunsCommand(gitGetCommitHash, 'git rev-parse --short HEAD');
27
32
  });
33
+
34
+ describe(gitCloneRepo.name, () => {
35
+ const destination = 'foo';
36
+ const name = '{name}';
37
+
38
+ const webUrl = `https://github.com/servicetitan/${name}.git`;
39
+ const sshUrl = `git@github.com:servicetitan/${name}.git`;
40
+
41
+ let params: Parameters<typeof gitCloneRepo>[0];
42
+
43
+ beforeEach(() => (params = { destination, name }));
44
+
45
+ const subject = () => gitCloneRepo(params);
46
+
47
+ function itReturns(value: boolean) {
48
+ test(`it returns ${value}`, async () => {
49
+ expect(await subject()).toBe(value);
50
+ });
51
+ }
52
+
53
+ test(`clones ${webUrl} to destination directory`, async () => {
54
+ await subject();
55
+
56
+ expect(runCommand).toHaveBeenCalledWith(`git clone -q ${webUrl} ${destination}`, {
57
+ quiet: true,
58
+ });
59
+ });
60
+
61
+ itReturns(true);
62
+
63
+ describe(`when cloning ${webUrl} fails`, () => {
64
+ beforeEach(() => jest.mocked(runCommand).mockRejectedValueOnce('Nope!'));
65
+
66
+ test(`clones ${sshUrl} to destination directory`, async () => {
67
+ await subject();
68
+
69
+ expect(runCommand).toHaveBeenCalledWith(
70
+ `git clone -q ${sshUrl} ${destination}`,
71
+ expect.anything()
72
+ );
73
+ });
74
+
75
+ itReturns(true);
76
+
77
+ describe(`when cloning ${sshUrl} also fails`, () => {
78
+ beforeEach(() => {
79
+ jest.mocked(runCommand).mockRejectedValue('Nope!');
80
+ });
81
+
82
+ itReturns(false);
83
+ });
84
+ });
85
+
86
+ describe('when running in CI environment with GITHUB_TOKEN', () => {
87
+ const originalEnv = process.env;
88
+ const token = 'foo-bar';
89
+
90
+ beforeEach(() => {
91
+ jest.mocked(isCI).mockReturnValue(true);
92
+ process.env.GITHUB_TOKEN = token;
93
+ });
94
+ afterEach(() => (process.env = originalEnv));
95
+
96
+ test(`adds token to ${webUrl}`, async () => {
97
+ await subject();
98
+
99
+ const urlWithToken = webUrl.replace('github.com', `oauth2:${token}@github.com`);
100
+ expect(runCommand).toHaveBeenCalledWith(
101
+ `git clone -q ${urlWithToken} ${destination}`,
102
+ expect.anything()
103
+ );
104
+ });
105
+ });
106
+ });
107
+
108
+ describe(gitIsReachable.name, () => {
109
+ const name = '{name}';
110
+
111
+ let params: Parameters<typeof gitIsReachable>[0];
112
+
113
+ beforeEach(() => (params = { name }));
114
+
115
+ const subject = () => gitIsReachable(params);
116
+
117
+ function itReturns(value: boolean) {
118
+ test(`it returns ${value}`, () => {
119
+ expect(subject()).toBe(value);
120
+ });
121
+ }
122
+
123
+ const webUrl = `https://github.com/servicetitan/${name}.git`;
124
+ const sshUrl = `git@github.com:servicetitan/${name}.git`;
125
+
126
+ test(`checks if ${webUrl} is reachable`, () => {
127
+ subject();
128
+
129
+ expect(runCommandOutput).toHaveBeenCalledWith(`git ls-remote -qt ${webUrl}`, {
130
+ quiet: true,
131
+ });
132
+ });
133
+
134
+ itReturns(true);
135
+
136
+ describe(`when ${webUrl} is not reachable`, () => {
137
+ beforeEach(() => {
138
+ jest.mocked(runCommandOutput).mockImplementationOnce(() => {
139
+ throw new Error('Oops!');
140
+ });
141
+ });
142
+
143
+ test(`checks if ${sshUrl} is reachable`, () => {
144
+ subject();
145
+
146
+ expect(runCommandOutput).toHaveBeenCalledWith(`git ls-remote -qt ${sshUrl}`, {
147
+ quiet: true,
148
+ });
149
+ });
150
+
151
+ itReturns(true);
152
+
153
+ describe(`when ${sshUrl} is also unreachable`, () => {
154
+ beforeEach(() =>
155
+ jest.mocked(runCommandOutput).mockImplementation(() => {
156
+ throw new Error('Oops');
157
+ })
158
+ );
159
+
160
+ itReturns(false);
161
+ });
162
+ });
163
+ });
28
164
  });
@@ -1,12 +1,13 @@
1
1
  import { fs, vol } from 'memfs';
2
2
  import { ESLint } from 'eslint';
3
3
 
4
+ import { getDestinationFolders } from '../../../utils';
4
5
  import { eslint } from '../eslint';
5
- import { getDestinationFolders } from '../../../utils/get-destination-folders';
6
6
 
7
7
  jest.mock('fs', () => fs);
8
8
  jest.mock('eslint');
9
- jest.mock('../../../utils/get-destination-folders', () => ({
9
+ jest.mock('../../../utils', () => ({
10
+ ...jest.requireActual('../../../utils'),
10
11
  getDestinationFolders: jest.fn(),
11
12
  }));
12
13
 
@@ -0,0 +1,40 @@
1
+ import { isCI } from '../is-ci';
2
+
3
+ describe(`[startup] Utils ${isCI.name}`, () => {
4
+ const originalCI = process.env.CI;
5
+
6
+ beforeAll(() => delete process.env.CI);
7
+ afterAll(() => (process.env.CI = originalCI));
8
+
9
+ const subject = () => isCI();
10
+
11
+ function itReturns(value: boolean) {
12
+ test(`returns ${value}`, () => {
13
+ expect(subject()).toBe(value);
14
+ });
15
+ }
16
+
17
+ itReturns(false);
18
+
19
+ describe.each([
20
+ { value: '', result: false },
21
+ { value: '1', result: true },
22
+ ])('when process.env.CI is "$value"', ({ value, result }) => {
23
+ beforeEach(() => (process.env.CI = value));
24
+
25
+ afterEach(() => delete process.env.CI);
26
+
27
+ itReturns(result);
28
+ });
29
+
30
+ describe.each([
31
+ { value: '', result: false },
32
+ { value: '1', result: true },
33
+ ])('when process.env.TEAMCITY_VERSION is "$value"', ({ value, result }) => {
34
+ beforeEach(() => (process.env.TEAMCITY_VERSION = value));
35
+
36
+ afterEach(() => delete process.env.TEAMCITY_VERSION);
37
+
38
+ itReturns(result);
39
+ });
40
+ });
@@ -1,9 +1,11 @@
1
1
  import execa from 'execa';
2
2
 
3
3
  import { log } from '../../../utils';
4
+ import { isCI } from '../is-ci';
4
5
  import { lernaExec } from '../lerna-exec';
5
6
 
6
7
  jest.mock('execa');
8
+ jest.mock('../is-ci', () => ({ isCI: jest.fn() }));
7
9
 
8
10
  const AVAILABLE_PARALLELISM = 2;
9
11
 
@@ -17,9 +19,9 @@ describe(`${lernaExec.name}`, () => {
17
19
 
18
20
  beforeEach(() => {
19
21
  jest.clearAllMocks();
22
+ jest.mocked(isCI).mockReturnValue(false);
20
23
  jest.spyOn(log, 'info').mockImplementation(jest.fn()); // suppress log output
21
24
  args = { cmd: 'foo' };
22
- delete process.env.CI;
23
25
  });
24
26
 
25
27
  const subject = () => lernaExec(args);
@@ -60,10 +62,11 @@ describe(`${lernaExec.name}`, () => {
60
62
  itRunsLernaExec(option);
61
63
  });
62
64
 
63
- describe('when process.env.CI=true', () => {
65
+ describe('when in CI environment', () => {
64
66
  beforeEach(() => {
65
- process.env.CI = 'true';
67
+ jest.mocked(isCI).mockReturnValue(true);
66
68
  });
69
+
67
70
  describe.each([
68
71
  { arg: { parallel: true }, option: `--concurrency=${AVAILABLE_PARALLELISM}` },
69
72
  { arg: { parallel: 10 }, option: '--concurrency=10' },
@@ -1,9 +1,59 @@
1
- import { runCommandOutput } from './cli-os';
1
+ import { log } from '../../utils';
2
+ import { runCommand, runCommandOutput } from './cli-os';
3
+ import { isCI } from './is-ci';
2
4
 
3
- export const gitGetBranch = (): string => {
5
+ export function gitGetBranch(): string {
4
6
  return runCommandOutput('git rev-parse --abbrev-ref HEAD').trim();
5
- };
7
+ }
6
8
 
7
- export const gitGetCommitHash = (): string => {
9
+ export function gitGetCommitHash(): string {
8
10
  return runCommandOutput('git rev-parse --short HEAD').trim();
9
- };
11
+ }
12
+
13
+ interface Repo {
14
+ owner?: string;
15
+ name: string;
16
+ }
17
+
18
+ export async function gitCloneRepo(params: Repo & { destination: string }) {
19
+ const { destination, name, owner = 'servicetitan' } = params;
20
+ const gitUrls = getGitUrls({ owner, name });
21
+
22
+ for (const url of gitUrls) {
23
+ try {
24
+ const command = `git clone -q ${url} ${destination}`;
25
+ log.debug('git:clone-repo', `running ${command}`);
26
+
27
+ // eslint-disable-next-line no-await-in-loop
28
+ await runCommand(command, { quiet: true });
29
+ return true;
30
+ } catch {
31
+ // ignore error
32
+ }
33
+ }
34
+
35
+ return false;
36
+ }
37
+
38
+ export function gitIsReachable({ owner = 'servicetitan', name }: Repo) {
39
+ return getGitUrls({ owner, name }).some(url => {
40
+ try {
41
+ runCommandOutput(`git ls-remote -qt ${url}`, { quiet: true });
42
+ return true;
43
+ } catch {
44
+ return false;
45
+ }
46
+ });
47
+ }
48
+
49
+ function getGitUrls({ owner, name }: Repo) {
50
+ const webUrl = `https://github.com/${owner}/${name}.git`;
51
+ const sshUrl = `git@github.com:${owner}/${name}.git`;
52
+
53
+ const urls = [webUrl, sshUrl];
54
+ if (isCI() && !!process.env.GITHUB_TOKEN) {
55
+ urls.unshift(webUrl.replace('github.com', `oauth2:${process.env.GITHUB_TOKEN}@github.com`));
56
+ }
57
+
58
+ return urls;
59
+ }
@@ -1,15 +1,21 @@
1
1
  export * from './bundle';
2
2
  export * from './check-args';
3
+ export * from './cli-git';
4
+ export * from './cli-npm';
5
+ export * from './cli-os';
3
6
  export * from './compile';
4
7
  export * from './compile-less';
5
8
  export * from './compile-sass';
6
9
  export * from './copy-files';
7
10
  export * from './eslint';
8
11
  export * from './get-module-type';
12
+ export * from './is-ci';
9
13
  export * from './is-module-installed';
10
14
  export * from './lerna-exec';
15
+ export * from './maybe-create-git-folder';
11
16
  export * from './pipe-stdout';
12
17
  export * from './process-tree';
18
+ export * from './publish';
13
19
  export * from './set-node-options';
14
20
  export * from './ts-config';
15
21
  export * from './type-check';
@@ -0,0 +1,3 @@
1
+ export function isCI() {
2
+ return !!process.env.CI || !!process.env.TEAMCITY_VERSION;
3
+ }
@@ -2,6 +2,7 @@ import execa, { StdioOption } from 'execa';
2
2
  import os from 'node:os';
3
3
 
4
4
  import { log } from '../../utils';
5
+ import { isCI } from './is-ci';
5
6
 
6
7
  interface Args {
7
8
  'bail'?: boolean;
@@ -37,7 +38,7 @@ function getOptions(args: Args) {
37
38
  result.push('--no-bail');
38
39
  }
39
40
  if (args.parallel === true) {
40
- result.push(process.env.CI ? `--concurrency=${os.availableParallelism()}` : '--parallel');
41
+ result.push(isCI() ? `--concurrency=${os.availableParallelism()}` : '--parallel');
41
42
  } else if (typeof args.parallel === 'number') {
42
43
  result.push(`--concurrency=${args.parallel}`);
43
44
  }
@@ -1,4 +1,4 @@
1
- import { getWebComponentBranchConfigs, WebComponentBranchConfigs } from './index';
1
+ import { getWebComponentBranchConfigs, WebComponentBranchConfigs } from './get-configuration';
2
2
 
3
3
  function getDefaultConfigs(): Record<string, WebComponentBranchConfigs> {
4
4
  return {
@@ -1,6 +1,7 @@
1
1
  export * from './find-packages';
2
2
  export * from './find-up';
3
3
  export * from './format-duration';
4
+ export * from './get-branch-configs';
4
5
  export * from './get-configuration';
5
6
  export * from './get-destination-folders';
6
7
  export * from './get-folders';