@servicetitan/startup 31.5.1 → 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 (199) hide show
  1. package/dist/cli/commands/build.d.ts +1 -1
  2. package/dist/cli/commands/build.d.ts.map +1 -1
  3. package/dist/cli/commands/build.js.map +1 -1
  4. package/dist/cli/commands/bundle-package.d.ts +1 -1
  5. package/dist/cli/commands/bundle-package.d.ts.map +1 -1
  6. package/dist/cli/commands/bundle-package.js.map +1 -1
  7. package/dist/cli/commands/eslint.d.ts +1 -1
  8. package/dist/cli/commands/eslint.d.ts.map +1 -1
  9. package/dist/cli/commands/eslint.js.map +1 -1
  10. package/dist/cli/commands/get-command.js +2 -2
  11. package/dist/cli/commands/get-command.js.map +1 -1
  12. package/dist/cli/commands/index.d.ts +1 -1
  13. package/dist/cli/commands/index.d.ts.map +1 -1
  14. package/dist/cli/commands/index.js +1 -1
  15. package/dist/cli/commands/index.js.map +1 -1
  16. package/dist/cli/commands/init.d.ts +3 -2
  17. package/dist/cli/commands/init.d.ts.map +1 -1
  18. package/dist/cli/commands/init.js +24 -43
  19. package/dist/cli/commands/init.js.map +1 -1
  20. package/dist/cli/commands/install.d.ts +4 -0
  21. package/dist/cli/commands/install.d.ts.map +1 -1
  22. package/dist/cli/commands/install.js +91 -3
  23. package/dist/cli/commands/install.js.map +1 -1
  24. package/dist/cli/commands/lint.d.ts +1 -1
  25. package/dist/cli/commands/lint.d.ts.map +1 -1
  26. package/dist/cli/commands/lint.js.map +1 -1
  27. package/dist/cli/commands/mfe-package-clean.d.ts.map +1 -1
  28. package/dist/cli/commands/mfe-package-clean.js +5 -7
  29. package/dist/cli/commands/mfe-package-clean.js.map +1 -1
  30. package/dist/cli/commands/mfe-package-publish.d.ts.map +1 -1
  31. package/dist/cli/commands/mfe-package-publish.js +11 -15
  32. package/dist/cli/commands/mfe-package-publish.js.map +1 -1
  33. package/dist/cli/commands/mfe-publish.d.ts +1 -1
  34. package/dist/cli/commands/mfe-publish.d.ts.map +1 -1
  35. package/dist/cli/commands/mfe-publish.js.map +1 -1
  36. package/dist/cli/commands/prepare-package.d.ts +1 -1
  37. package/dist/cli/commands/prepare-package.d.ts.map +1 -1
  38. package/dist/cli/commands/prepare-package.js.map +1 -1
  39. package/dist/cli/commands/review/rules/index.d.ts.map +1 -1
  40. package/dist/cli/commands/review/rules/index.js +4 -0
  41. package/dist/cli/commands/review/rules/index.js.map +1 -1
  42. package/dist/cli/commands/review/rules/require-all-react-dependencies.d.ts +14 -0
  43. package/dist/cli/commands/review/rules/require-all-react-dependencies.d.ts.map +1 -0
  44. package/dist/cli/commands/review/rules/require-all-react-dependencies.js +64 -0
  45. package/dist/cli/commands/review/rules/require-all-react-dependencies.js.map +1 -0
  46. package/dist/cli/commands/review/rules/require-one-react-version.d.ts +5 -0
  47. package/dist/cli/commands/review/rules/require-one-react-version.d.ts.map +1 -0
  48. package/dist/cli/commands/review/rules/require-one-react-version.js +25 -0
  49. package/dist/cli/commands/review/rules/require-one-react-version.js.map +1 -0
  50. package/dist/cli/commands/review/rules/require-one-uikit-version.d.ts.map +1 -1
  51. package/dist/cli/commands/review/rules/require-one-uikit-version.js +1 -0
  52. package/dist/cli/commands/review/rules/require-one-uikit-version.js.map +1 -1
  53. package/dist/cli/commands/review/utils/format-depends-on.d.ts +1 -0
  54. package/dist/cli/commands/review/utils/format-depends-on.d.ts.map +1 -1
  55. package/dist/cli/commands/review/utils/format-depends-on.js +15 -8
  56. package/dist/cli/commands/review/utils/format-depends-on.js.map +1 -1
  57. package/dist/cli/commands/review/utils/set-version.d.ts +2 -1
  58. package/dist/cli/commands/review/utils/set-version.d.ts.map +1 -1
  59. package/dist/cli/commands/review/utils/set-version.js +4 -2
  60. package/dist/cli/commands/review/utils/set-version.js.map +1 -1
  61. package/dist/cli/commands/start.d.ts +1 -1
  62. package/dist/cli/commands/start.d.ts.map +1 -1
  63. package/dist/cli/commands/start.js.map +1 -1
  64. package/dist/cli/commands/test/index.d.ts +2 -0
  65. package/dist/cli/commands/test/index.d.ts.map +1 -0
  66. package/dist/cli/commands/test/index.js +20 -0
  67. package/dist/cli/commands/test/index.js.map +1 -0
  68. package/dist/cli/commands/test/runners/index.d.ts +3 -0
  69. package/dist/cli/commands/test/runners/index.d.ts.map +1 -0
  70. package/dist/cli/commands/test/runners/index.js +21 -0
  71. package/dist/cli/commands/test/runners/index.js.map +1 -0
  72. package/dist/cli/commands/test/runners/jest.d.ts +7 -0
  73. package/dist/cli/commands/test/runners/jest.d.ts.map +1 -0
  74. package/dist/cli/commands/test/runners/jest.js +43 -0
  75. package/dist/cli/commands/test/runners/jest.js.map +1 -0
  76. package/dist/cli/commands/test/runners/vitest.d.ts +4 -0
  77. package/dist/cli/commands/test/runners/vitest.d.ts.map +1 -0
  78. package/dist/cli/commands/test/runners/vitest.js +86 -0
  79. package/dist/cli/commands/test/runners/vitest.js.map +1 -0
  80. package/dist/cli/commands/test/tests.d.ts +18 -0
  81. package/dist/cli/commands/test/tests.d.ts.map +1 -0
  82. package/dist/cli/commands/{tests.js → test/tests.js} +10 -9
  83. package/dist/cli/commands/test/tests.js.map +1 -0
  84. package/dist/cli/commands/upload-sourcemaps.d.ts.map +1 -1
  85. package/dist/cli/commands/upload-sourcemaps.js +1 -1
  86. package/dist/cli/commands/upload-sourcemaps.js.map +1 -1
  87. package/dist/cli/index.js +1 -2
  88. package/dist/cli/index.js.map +1 -1
  89. package/dist/cli/utils/bundle.d.ts.map +1 -1
  90. package/dist/cli/utils/bundle.js +7 -4
  91. package/dist/cli/utils/bundle.js.map +1 -1
  92. package/dist/cli/utils/cli-git.d.ts +11 -2
  93. package/dist/cli/utils/cli-git.d.ts.map +1 -1
  94. package/dist/cli/utils/cli-git.js +60 -4
  95. package/dist/cli/utils/cli-git.js.map +1 -1
  96. package/dist/cli/utils/index.d.ts +6 -0
  97. package/dist/cli/utils/index.d.ts.map +1 -1
  98. package/dist/cli/utils/index.js +6 -0
  99. package/dist/cli/utils/index.js.map +1 -1
  100. package/dist/cli/utils/is-ci.d.ts +2 -0
  101. package/dist/cli/utils/is-ci.d.ts.map +1 -0
  102. package/dist/cli/utils/is-ci.js +15 -0
  103. package/dist/cli/utils/is-ci.js.map +1 -0
  104. package/dist/cli/utils/lerna-exec.d.ts.map +1 -1
  105. package/dist/cli/utils/lerna-exec.js +2 -1
  106. package/dist/cli/utils/lerna-exec.js.map +1 -1
  107. package/dist/cli/utils/set-node-options.d.ts.map +1 -1
  108. package/dist/cli/utils/set-node-options.js.map +1 -1
  109. package/dist/index.d.ts +0 -1
  110. package/dist/index.d.ts.map +1 -1
  111. package/dist/index.js +0 -1
  112. package/dist/index.js.map +1 -1
  113. package/dist/utils/get-branch-configs.d.ts +1 -1
  114. package/dist/utils/get-branch-configs.d.ts.map +1 -1
  115. package/dist/utils/get-branch-configs.js +2 -2
  116. package/dist/utils/get-branch-configs.js.map +1 -1
  117. package/dist/utils/get-configuration.d.ts +8 -2
  118. package/dist/utils/get-configuration.d.ts.map +1 -1
  119. package/dist/utils/get-configuration.js +10 -2
  120. package/dist/utils/get-configuration.js.map +1 -1
  121. package/dist/utils/get-jest-config.d.ts +1 -7
  122. package/dist/utils/get-jest-config.d.ts.map +1 -1
  123. package/dist/utils/get-jest-config.js +49 -58
  124. package/dist/utils/get-jest-config.js.map +1 -1
  125. package/dist/utils/index.d.ts +1 -0
  126. package/dist/utils/index.d.ts.map +1 -1
  127. package/dist/utils/index.js +1 -0
  128. package/dist/utils/index.js.map +1 -1
  129. package/dist/webpack/utils/testing/get-compiler.js.map +1 -1
  130. package/package.json +16 -14
  131. package/src/cli/commands/__tests__/init.test.ts +21 -87
  132. package/src/cli/commands/__tests__/install.test.ts +174 -12
  133. package/src/cli/commands/__tests__/mfe-package-clean.test.ts +3 -6
  134. package/src/cli/commands/__tests__/mfe-package-publish.test.ts +6 -8
  135. package/src/cli/commands/__tests__/upload-sourcemaps.test.ts +7 -3
  136. package/src/cli/commands/build.ts +1 -1
  137. package/src/cli/commands/bundle-package.ts +1 -1
  138. package/src/cli/commands/eslint.ts +1 -1
  139. package/src/cli/commands/get-command.ts +1 -1
  140. package/src/cli/commands/index.ts +1 -1
  141. package/src/cli/commands/init.ts +18 -38
  142. package/src/cli/commands/install.ts +95 -6
  143. package/src/cli/commands/lint.ts +1 -1
  144. package/src/cli/commands/mfe-package-clean.ts +2 -4
  145. package/src/cli/commands/mfe-package-publish.ts +18 -6
  146. package/src/cli/commands/mfe-publish.ts +1 -1
  147. package/src/cli/commands/prepare-package.ts +1 -1
  148. package/src/cli/commands/review/rules/__tests__/require-all-react-dependencies.test.ts +132 -0
  149. package/src/cli/commands/review/rules/__tests__/require-one-package-version.test.ts +0 -1
  150. package/src/cli/commands/review/rules/__tests__/require-one-react-version.test.ts +22 -0
  151. package/src/cli/commands/review/rules/__tests__/{require-one-uikit-version.ts → require-one-uikit-version.test.ts} +1 -0
  152. package/src/cli/commands/review/rules/index.ts +4 -0
  153. package/src/cli/commands/review/rules/require-all-react-dependencies.ts +53 -0
  154. package/src/cli/commands/review/rules/require-one-react-version.ts +9 -0
  155. package/src/cli/commands/review/rules/require-one-uikit-version.ts +1 -0
  156. package/src/cli/commands/review/utils/__tests__/set-version.test.ts +18 -8
  157. package/src/cli/commands/review/utils/format-depends-on.ts +8 -5
  158. package/src/cli/commands/review/utils/set-version.ts +10 -2
  159. package/src/cli/commands/start.ts +1 -1
  160. package/src/cli/commands/test/__tests__/tests.test.ts +78 -0
  161. package/src/cli/commands/test/index.ts +1 -0
  162. package/src/cli/commands/{__tests__/tests.test.ts → test/runners/__tests__/jest.test.ts} +10 -13
  163. package/src/cli/commands/test/runners/__tests__/vitest.test.ts +150 -0
  164. package/src/cli/commands/test/runners/index.ts +2 -0
  165. package/src/cli/commands/{tests.ts → test/runners/jest.ts} +5 -16
  166. package/src/cli/commands/test/runners/vitest.ts +70 -0
  167. package/src/cli/commands/test/tests.ts +34 -0
  168. package/src/cli/commands/upload-sourcemaps.ts +2 -2
  169. package/src/cli/index.ts +1 -2
  170. package/src/cli/utils/__tests__/bundle.test.ts +1 -1
  171. package/src/cli/utils/__tests__/cli-git.test.ts +142 -6
  172. package/src/cli/utils/__tests__/eslint.test.ts +3 -2
  173. package/src/cli/utils/__tests__/is-ci.test.ts +40 -0
  174. package/src/cli/utils/__tests__/lerna-exec.test.ts +6 -3
  175. package/src/cli/utils/bundle.ts +8 -3
  176. package/src/cli/utils/cli-git.ts +55 -5
  177. package/src/cli/utils/index.ts +6 -0
  178. package/src/cli/utils/is-ci.ts +3 -0
  179. package/src/cli/utils/lerna-exec.ts +2 -1
  180. package/src/cli/utils/set-node-options.ts +2 -2
  181. package/src/index.ts +0 -1
  182. package/src/utils/__tests__/get-configuration.test.ts +48 -11
  183. package/src/utils/__tests__/get-jest-config.test.ts +35 -61
  184. package/src/utils/get-branch-configs.ts +1 -1
  185. package/src/utils/get-configuration.ts +14 -3
  186. package/src/utils/get-jest-config.ts +39 -47
  187. package/src/utils/index.ts +1 -0
  188. package/src/webpack/__tests__/create-webpack-config-shared-dependencies.test.ts +1 -1
  189. package/src/webpack/__tests__/create-webpack-config-web-component.test.ts +1 -1
  190. package/src/webpack/__tests__/create-webpack-config.test.ts +1 -1
  191. package/src/webpack/utils/testing/get-compiler.ts +1 -1
  192. package/dist/cli/commands/tests.d.ts +0 -13
  193. package/dist/cli/commands/tests.d.ts.map +0 -1
  194. package/dist/cli/commands/tests.js.map +0 -1
  195. package/dist/jest/index.d.ts +0 -2
  196. package/dist/jest/index.d.ts.map +0 -1
  197. package/dist/jest/index.js +0 -16
  198. package/dist/jest/index.js.map +0 -1
  199. package/src/jest/index.ts +0 -5
@@ -1,22 +1,11 @@
1
- import { Config } from '@jest/types';
2
1
  import { runCLI } from '@jest/core';
3
- import { getJestConfigCLI, logErrors } from '../../utils';
4
- import { Command } from '.';
5
-
6
- /**
7
- * Named as tests to exclude it from the Jest pattern
8
- */
9
- export class Tests implements Command {
10
- readonly greedy = true;
11
-
12
- constructor(private args: Config.Argv) {}
2
+ import { Config } from '@jest/types';
3
+ import { getJestConfigCLI } from '../../../../utils';
13
4
 
14
- description() {
15
- return 'run tests';
16
- }
5
+ export class Jest {
6
+ constructor(private readonly args: Config.Argv) {}
17
7
 
18
- @logErrors
19
- async execute() {
8
+ async run() {
20
9
  const jestConfig = getJestConfigCLI(this.args);
21
10
  const {
22
11
  results: { success },
@@ -0,0 +1,70 @@
1
+ import { configDefaults, coverageConfigDefaults, mergeConfig, ViteUserConfig } from 'vitest/config';
2
+ import { startVitest, parseCLI, resolveConfig } from 'vitest/node';
3
+ import { getVitestConfiguration, log } from '../../../../utils';
4
+
5
+ type VitestConfig = NonNullable<ViteUserConfig['test']>;
6
+
7
+ export class Vitest {
8
+ async run() {
9
+ const cliOptions = getCliOptions();
10
+ const userConfig = await getUserConfig();
11
+
12
+ // startVitest sets process.exitCode to 1 when tests fail
13
+ const vitest = await startVitest('test', cliOptions.filter, cliOptions.options, userConfig);
14
+ await vitest.close();
15
+ }
16
+ }
17
+
18
+ const RUNNER_OPTION = '--runner';
19
+
20
+ function excludeRunnerOption(args: string[]) {
21
+ return args.reduce<string[]>((result, item, index) => {
22
+ if (!item.startsWith(RUNNER_OPTION) && (index === 0 || args[index - 1] !== RUNNER_OPTION)) {
23
+ result.push(item);
24
+ }
25
+ return result;
26
+ }, []);
27
+ }
28
+
29
+ function getCliOptions() {
30
+ // parseCLI requires the first element to be "vitest"
31
+ const result = parseCLI(['vitest', ...excludeRunnerOption(process.argv.slice(3))]);
32
+
33
+ /* istanbul ignore next: debug only */
34
+ log.debug('vitest:cliOptions', () => JSON.stringify(result, null, 2));
35
+
36
+ return result;
37
+ }
38
+
39
+ function getDefaultConfig(): VitestConfig {
40
+ return {
41
+ coverage: {
42
+ exclude: [
43
+ ...coverageConfigDefaults.exclude,
44
+ '**/__mocks__/**',
45
+ '**/*.stories.*',
46
+ '\\.yalc',
47
+ ],
48
+ include: ['**/*.{ts,tsx}'],
49
+ reporter: ['html-spa', 'text', 'json', 'cobertura', 'lcov'],
50
+ },
51
+ environment: 'jsdom',
52
+ exclude: [...configDefaults.exclude, '\\.yalc'],
53
+ restoreMocks: true,
54
+ server: { deps: { inline: ['@servicetitan/anvil2'] } }, // fixes css parser errors
55
+ };
56
+ }
57
+
58
+ async function getUserConfig(): Promise<ViteUserConfig> {
59
+ const { viteConfig } = await resolveConfig();
60
+
61
+ const result = mergeConfig(
62
+ mergeConfig(getDefaultConfig(), getVitestConfiguration()),
63
+ viteConfig.test ?? {}
64
+ );
65
+
66
+ /* istanbul ignore next: debug only */
67
+ log.debug('vitest:userConfig', () => JSON.stringify(result, null, 2));
68
+
69
+ return { test: result };
70
+ }
@@ -0,0 +1,34 @@
1
+ import { Config } from '@jest/types';
2
+ import { getConfiguration, logErrors } from '../../../utils';
3
+ import { Command } from '../types';
4
+ import { Jest, Vitest } from './runners';
5
+
6
+ type Args = Config.Argv & {
7
+ runner?: 'jest' | 'vitest';
8
+ };
9
+
10
+ /**
11
+ * This class is named "Tests" instead of "Test" because the corresponding
12
+ * "test.ts" would be interpreted as a test file.
13
+ */
14
+ export class Tests implements Command {
15
+ readonly greedy = true;
16
+
17
+ constructor(private readonly args: Args) {}
18
+
19
+ description() {
20
+ return 'run tests';
21
+ }
22
+
23
+ @logErrors
24
+ async execute() {
25
+ const { runner = getConfiguration().testRunner ?? 'jest', ...restArgs } = this.args;
26
+ if (runner === 'jest') {
27
+ await new Jest(restArgs).run();
28
+ } else if (runner === 'vitest') {
29
+ await new Vitest().run();
30
+ } else {
31
+ throw new Error(`unrecognized runner "${runner}"`);
32
+ }
33
+ }
34
+ }
@@ -1,8 +1,8 @@
1
1
  import path from 'path';
2
2
  import { execSync } from 'child_process';
3
3
  import { getTsConfig, isWebComponent, log, logErrors, readJson } from '../../utils';
4
+ import { isCI, TSConfig } from '../utils';
4
5
  import { Command } from './types';
5
- import { TSConfig } from '../utils';
6
6
 
7
7
  interface Args {
8
8
  dry?: boolean;
@@ -35,7 +35,7 @@ export class UploadSourcemaps implements Command {
35
35
  private checkArgs() {
36
36
  if (!process.env.DATADOG_API_KEY) {
37
37
  const message = 'DATADOG_API_KEY environment variable is not set';
38
- if (!process.env.CI) {
38
+ if (!isCI()) {
39
39
  throw new Error(message);
40
40
  }
41
41
  log.warning(`${message}; skipping sourcemaps`);
package/src/cli/index.ts CHANGED
@@ -3,8 +3,7 @@ import path from 'path';
3
3
  import { argv, Arguments } from 'yargs';
4
4
  import { CommandName, getStartupVersion, log } from '../utils';
5
5
  import { getCommand, getUserCommands } from './commands';
6
- import { setNodeOptions } from './utils';
7
- import { maybeCreateGitFolder } from './utils/maybe-create-git-folder';
6
+ import { maybeCreateGitFolder, setNodeOptions } from './utils';
8
7
 
9
8
  const argvSync = argv as Arguments;
10
9
  const name = argvSync._[0]?.toString() as CommandName;
@@ -34,7 +34,7 @@ jest.mock('../../../webpack', () => ({ createWebpackConfig: jest.fn() }));
34
34
  describe('[startup] Cli Utils', () => {
35
35
  const pkg = createPackage({});
36
36
  const createWebpackResult = { stats: { all: true } };
37
- let compiler: Partial<ReturnType<typeof webpack>>;
37
+ let compiler: Partial<NonNullable<ReturnType<typeof webpack>>>;
38
38
 
39
39
  beforeEach(() => {
40
40
  jest.resetAllMocks();
@@ -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' },
@@ -57,6 +57,7 @@ export async function bundle(options: Options = {}) {
57
57
  const customConfig = readWebpackConfig({ ...options, fallback });
58
58
  const webpackOptions = getWebpackOptions(options, customConfig);
59
59
 
60
+ /* istanbul ignore next: debug only */
60
61
  log.debug('custom-webpack-config', () => stringifyConfig(customConfig));
61
62
 
62
63
  if (isWebComponent()) {
@@ -135,7 +136,7 @@ function readConfig(relativePath?: string): Record<string, any> | undefined {
135
136
  }
136
137
 
137
138
  async function run(config: Configuration) {
138
- const compiler = webpack(config);
139
+ const compiler = createWebpackCompiler(config);
139
140
 
140
141
  const stats = await new Promise<webpack.Stats>((resolve, reject) => {
141
142
  compiler.run((error, stats) => {
@@ -155,7 +156,7 @@ async function run(config: Configuration) {
155
156
  }
156
157
 
157
158
  async function runServe({ devServer = {}, ...config }: Configuration) {
158
- const compiler = webpack(config);
159
+ const compiler = createWebpackCompiler(config);
159
160
  const host = devServer.host ?? 'localhost';
160
161
  const port = await getPortPromise({
161
162
  port: Number(devServer.port) || 8080,
@@ -175,7 +176,7 @@ async function runServe({ devServer = {}, ...config }: Configuration) {
175
176
  }
176
177
 
177
178
  async function runWatch(config: Configuration) {
178
- const compiler = webpack(config);
179
+ const compiler = createWebpackCompiler(config);
179
180
  return new Promise<void>((_0, reject) => {
180
181
  const watching = compiler.watch({}, e => {
181
182
  if (e) {
@@ -186,3 +187,7 @@ async function runWatch(config: Configuration) {
186
187
  });
187
188
  });
188
189
  }
190
+
191
+ function createWebpackCompiler(config: Configuration) {
192
+ return webpack(config)!; // webpack only potentially returns null when given a callback argument
193
+ }
@@ -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,5 +1,5 @@
1
1
  import os from 'os';
2
- import { CommandName, NodeConfiguration, getConfigurationSafe } from '../../utils';
2
+ import { CommandName, getConfigurationSafe } from '../../utils';
3
3
  import { Command } from '../commands';
4
4
 
5
5
  const MAX_OLD_SPACE_SIZE_OPTION = 'max_old_space_size';
@@ -13,7 +13,7 @@ const MIN_REMAINING_MEMORY_MB = 512;
13
13
  */
14
14
  export function setNodeOptions(commandName: CommandName, command: Command) {
15
15
  const cliConfig = getConfigurationSafe();
16
- const cmdConfig: NodeConfiguration = cliConfig[commandName];
16
+ const cmdConfig = cliConfig[commandName];
17
17
 
18
18
  const cliNodeOptions = cliConfig.NODE_OPTIONS ?? [];
19
19
  const cmdNodeOptions = cmdConfig?.NODE_OPTIONS ?? [];
package/src/index.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from './webpack';
2
- export * from './jest';
3
2
  export * from './utils/get-packages';