@servicetitan/startup 29.0.0 → 30.1.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 (122) hide show
  1. package/bin/index.js +1 -1
  2. package/dist/cli/commands/convert-eslint-config.d.ts +21 -0
  3. package/dist/cli/commands/convert-eslint-config.d.ts.map +1 -0
  4. package/dist/cli/commands/convert-eslint-config.js +235 -0
  5. package/dist/cli/commands/convert-eslint-config.js.map +1 -0
  6. package/dist/cli/commands/get-command.d.ts.map +1 -1
  7. package/dist/cli/commands/get-command.js +6 -0
  8. package/dist/cli/commands/get-command.js.map +1 -1
  9. package/dist/cli/commands/init.d.ts.map +1 -1
  10. package/dist/cli/commands/init.js +4 -3
  11. package/dist/cli/commands/init.js.map +1 -1
  12. package/dist/cli/commands/lint.d.ts +1 -1
  13. package/dist/cli/commands/lint.js +2 -2
  14. package/dist/cli/commands/run-task.d.ts +13 -0
  15. package/dist/cli/commands/run-task.d.ts.map +1 -0
  16. package/dist/cli/commands/run-task.js +53 -0
  17. package/dist/cli/commands/run-task.js.map +1 -0
  18. package/dist/cli/index.js +13 -4
  19. package/dist/cli/index.js.map +1 -1
  20. package/dist/cli/tasks/cli-task.d.ts +16 -0
  21. package/dist/cli/tasks/cli-task.d.ts.map +1 -0
  22. package/dist/cli/tasks/cli-task.js +58 -0
  23. package/dist/cli/tasks/cli-task.js.map +1 -0
  24. package/dist/cli/tasks/swc-compile-package.d.ts +12 -0
  25. package/dist/cli/tasks/swc-compile-package.d.ts.map +1 -0
  26. package/dist/cli/tasks/swc-compile-package.js +66 -0
  27. package/dist/cli/tasks/swc-compile-package.js.map +1 -0
  28. package/dist/cli/tasks/task.d.ts +42 -0
  29. package/dist/cli/tasks/task.d.ts.map +1 -0
  30. package/dist/cli/tasks/task.js +113 -0
  31. package/dist/cli/tasks/task.js.map +1 -0
  32. package/dist/cli/tasks/tsc-compile-package.d.ts +12 -0
  33. package/dist/cli/tasks/tsc-compile-package.d.ts.map +1 -0
  34. package/dist/cli/tasks/tsc-compile-package.js +42 -0
  35. package/dist/cli/tasks/tsc-compile-package.js.map +1 -0
  36. package/dist/cli/tasks/tsc-compile.d.ts +16 -0
  37. package/dist/cli/tasks/tsc-compile.d.ts.map +1 -0
  38. package/dist/cli/tasks/tsc-compile.js +48 -0
  39. package/dist/cli/tasks/tsc-compile.js.map +1 -0
  40. package/dist/cli/utils/bundle.js +1 -1
  41. package/dist/cli/utils/bundle.js.map +1 -1
  42. package/dist/cli/utils/cli-os.js +2 -2
  43. package/dist/cli/utils/cli-os.js.map +1 -1
  44. package/dist/cli/utils/eslint.d.ts.map +1 -1
  45. package/dist/cli/utils/eslint.js +13 -12
  46. package/dist/cli/utils/eslint.js.map +1 -1
  47. package/dist/cli/utils/is-module-installed.js +1 -1
  48. package/dist/cli/utils/is-module-installed.js.map +1 -1
  49. package/dist/cli/utils/tsc.d.ts +3 -2
  50. package/dist/cli/utils/tsc.d.ts.map +1 -1
  51. package/dist/cli/utils/tsc.js +20 -16
  52. package/dist/cli/utils/tsc.js.map +1 -1
  53. package/dist/utils/get-configuration.d.ts +3 -1
  54. package/dist/utils/get-configuration.d.ts.map +1 -1
  55. package/dist/utils/get-configuration.js +2 -0
  56. package/dist/utils/get-configuration.js.map +1 -1
  57. package/dist/utils/get-destination-folders.d.ts.map +1 -1
  58. package/dist/utils/get-destination-folders.js +9 -13
  59. package/dist/utils/get-destination-folders.js.map +1 -1
  60. package/dist/utils/get-folders.js +2 -2
  61. package/dist/utils/get-folders.js.map +1 -1
  62. package/dist/utils/log.d.ts +1 -0
  63. package/dist/utils/log.d.ts.map +1 -1
  64. package/dist/utils/log.js +3 -0
  65. package/dist/utils/log.js.map +1 -1
  66. package/dist/webpack/configs/plugins/assets-manifest-plugin.d.ts +1 -1
  67. package/dist/webpack/configs/plugins/assets-manifest-plugin.d.ts.map +1 -1
  68. package/dist/webpack/configs/plugins/assets-manifest-plugin.js +4 -6
  69. package/dist/webpack/configs/plugins/assets-manifest-plugin.js.map +1 -1
  70. package/dist/webpack/configs/plugins/ignore-plugin/check-resource.js +1 -1
  71. package/dist/webpack/configs/plugins/ignore-plugin/check-resource.js.map +1 -1
  72. package/dist/webpack/configs/plugins/moment-locales-plugin.d.ts +1 -2
  73. package/dist/webpack/configs/plugins/moment-locales-plugin.d.ts.map +1 -1
  74. package/dist/webpack/configs/plugins/moment-locales-plugin.js +13 -7
  75. package/dist/webpack/configs/plugins/moment-locales-plugin.js.map +1 -1
  76. package/dist/webpack/utils/testing/normalize-errors.d.ts +1 -2
  77. package/dist/webpack/utils/testing/normalize-errors.d.ts.map +1 -1
  78. package/dist/webpack/utils/testing/normalize-errors.js.map +1 -1
  79. package/package.json +34 -21
  80. package/src/cli/commands/__tests__/convert-eslint-config.test.ts +455 -0
  81. package/src/cli/commands/__tests__/lint.test.ts +2 -2
  82. package/src/cli/commands/convert-eslint-config.ts +289 -0
  83. package/src/cli/commands/get-command.ts +6 -0
  84. package/src/cli/commands/init.ts +4 -3
  85. package/src/cli/commands/lint.ts +3 -3
  86. package/src/cli/commands/run-task.ts +41 -0
  87. package/src/cli/index.ts +16 -4
  88. package/src/cli/tasks/__tests__/cli-task.test.ts +115 -0
  89. package/src/cli/tasks/__tests__/swc-compile.test.ts +192 -0
  90. package/src/cli/tasks/__tests__/task.test.ts +88 -0
  91. package/src/cli/tasks/__tests__/tsc-compile-package.test.ts +72 -0
  92. package/src/cli/tasks/__tests__/tsc-compile.test.ts +156 -0
  93. package/src/cli/tasks/cli-task.ts +64 -0
  94. package/src/cli/tasks/swc-cli.d.ts +3 -0
  95. package/src/cli/tasks/swc-compile-package.ts +70 -0
  96. package/src/cli/tasks/task.ts +112 -0
  97. package/src/cli/tasks/tsc-compile-package.ts +47 -0
  98. package/src/cli/tasks/tsc-compile.ts +64 -0
  99. package/src/cli/utils/__tests__/assets-copy.test.ts +1 -1
  100. package/src/cli/utils/__tests__/bundle.test.ts +6 -1
  101. package/src/cli/utils/__tests__/cli-os.test.ts +2 -2
  102. package/src/cli/utils/__tests__/eslint.test.ts +37 -8
  103. package/src/cli/utils/__tests__/styles-copy.test.ts +1 -1
  104. package/src/cli/utils/__tests__/tsc.test.ts +34 -55
  105. package/src/cli/utils/bundle.ts +1 -1
  106. package/src/cli/utils/cli-os.ts +2 -2
  107. package/src/cli/utils/eslint.ts +16 -13
  108. package/src/cli/utils/is-module-installed.ts +1 -1
  109. package/src/cli/utils/tsc.ts +25 -20
  110. package/src/utils/__tests__/get-destination-folders.test.ts +1 -1
  111. package/src/utils/__tests__/get-folders.test.ts +6 -18
  112. package/src/utils/__tests__/log.test.ts +6 -0
  113. package/src/utils/get-configuration.ts +2 -0
  114. package/src/utils/get-destination-folders.ts +11 -17
  115. package/src/utils/get-folders.ts +2 -2
  116. package/src/utils/log.ts +4 -0
  117. package/src/webpack/__tests__/create-webpack-config-web-component.test.ts +2 -2
  118. package/src/webpack/__tests__/create-webpack-config.test.ts +1 -1
  119. package/src/webpack/configs/plugins/assets-manifest-plugin.ts +3 -2
  120. package/src/webpack/configs/plugins/ignore-plugin/check-resource.ts +1 -1
  121. package/src/webpack/configs/plugins/moment-locales-plugin.ts +17 -4
  122. package/src/webpack/utils/testing/normalize-errors.ts +1 -3
@@ -15,15 +15,9 @@ describe('[Startup] utils:get-folders', () => {
15
15
  'tsconfig.json': JSON.stringify({ compilerOptions: { ourDir: 'dist' } }),
16
16
  });
17
17
 
18
- let error;
19
-
20
- try {
21
- getFolders();
22
- } catch (e) {
23
- error = e;
24
- }
25
-
26
- expect(error).toBe('"compilerOptions.rootDir" must be defined in the "tsconfig.json"!');
18
+ expect(() => getFolders()).toThrow(
19
+ '"compilerOptions.rootDir" must be defined in the "tsconfig.json"!'
20
+ );
27
21
  });
28
22
 
29
23
  test('getFolders throws an exception if "compilerOptions.outDir" isn\'t defined', () => {
@@ -32,15 +26,9 @@ describe('[Startup] utils:get-folders', () => {
32
26
  'tsconfig.json': JSON.stringify({ compilerOptions: { rootDir: 'src' } }),
33
27
  });
34
28
 
35
- let error;
36
-
37
- try {
38
- getFolders();
39
- } catch (e) {
40
- error = e;
41
- }
42
-
43
- expect(error).toBe('"compilerOptions.outDir" must be defined in the "tsconfig.json"!');
29
+ expect(() => getFolders()).toThrow(
30
+ '"compilerOptions.outDir" must be defined in the "tsconfig.json"!'
31
+ );
44
32
  });
45
33
 
46
34
  test('"compilerOptions.outDir" used as the destination', () => {
@@ -14,6 +14,12 @@ describe(`[startup] Utils`, () => {
14
14
  stdoutSpy = jest.spyOn(process.stdout, 'write').mockImplementation(jest.fn());
15
15
  });
16
16
 
17
+ test('text() writes default text', () => {
18
+ log.text(message);
19
+
20
+ expect(stdoutSpy).toHaveBeenCalledWith(`${chalk(message)}\n`);
21
+ });
22
+
17
23
  test('info() writes cyan text', () => {
18
24
  log.info(message);
19
25
 
@@ -58,6 +58,7 @@ export interface NodeConfiguration {
58
58
  export enum CommandName {
59
59
  'build' = 'build',
60
60
  'bundle-package' = 'bundle-package',
61
+ 'convert-eslint-config' = 'convert-eslint-config',
61
62
  'eslint' = 'eslint',
62
63
  'init' = 'init',
63
64
  'install' = 'install',
@@ -70,6 +71,7 @@ export enum CommandName {
70
71
  'start' = 'start',
71
72
  'styles-check' = 'styles-check',
72
73
  'test' = 'test',
74
+ 'task' = 'task',
73
75
  }
74
76
  /* eslint-enable @typescript-eslint/naming-convention */
75
77
 
@@ -8,24 +8,18 @@ import { getPackages, readJson } from '.';
8
8
  */
9
9
  export function getDestinationFolders() {
10
10
  const packages = getPackages();
11
+ const cwd = process.cwd();
11
12
 
12
- return packages
13
- .map(({ location }) => {
14
- const tsConfigPath = path.join(location, 'tsconfig.json');
15
-
16
- if (!fs.existsSync(tsConfigPath)) {
17
- return '';
18
- }
19
-
13
+ return packages.reduce<string[]>((result, { location }) => {
14
+ const tsConfigPath = path.join(location, 'tsconfig.json');
15
+ if (fs.existsSync(tsConfigPath)) {
20
16
  const { outDir } = readJson(tsConfigPath).compilerOptions ?? {};
21
-
22
- if (!outDir) {
23
- return '';
17
+ if (outDir) {
18
+ result.push(
19
+ path.join(path.relative(cwd, location), outDir, '/').replace(/\\/g, '/')
20
+ );
24
21
  }
25
-
26
- return path
27
- .join('/', path.relative(process.cwd(), location), outDir, '/')
28
- .replace(/\\/g, '/');
29
- })
30
- .filter(path => !!path);
22
+ }
23
+ return result;
24
+ }, []);
31
25
  }
@@ -10,11 +10,11 @@ export function getFolders(location = './') {
10
10
  readJson(path.join(location, 'tsconfig.json')).compilerOptions ?? {};
11
11
 
12
12
  if (!rootDir) {
13
- throw '"compilerOptions.rootDir" must be defined in the "tsconfig.json"!';
13
+ throw new Error('"compilerOptions.rootDir" must be defined in the "tsconfig.json"!');
14
14
  }
15
15
 
16
16
  if (!outDir) {
17
- throw '"compilerOptions.outDir" must be defined in the "tsconfig.json"!';
17
+ throw new Error('"compilerOptions.outDir" must be defined in the "tsconfig.json"!');
18
18
  }
19
19
 
20
20
  return {
package/src/utils/log.ts CHANGED
@@ -10,6 +10,10 @@ class Log {
10
10
  this.debugMap = new Map<string, Debugger>();
11
11
  }
12
12
 
13
+ text(...text: string[]) {
14
+ process.stdout.write(chalk(...text) + '\n');
15
+ }
16
+
13
17
  info(...text: string[]) {
14
18
  process.stdout.write(chalk.bold.cyan(...text) + '\n');
15
19
  }
@@ -3,7 +3,7 @@ import MiniCssExtractPlugin from 'mini-css-extract-plugin';
3
3
  import { fs, vol } from 'memfs';
4
4
  import path from 'path';
5
5
  import { DefinePlugin } from 'webpack';
6
- import WebpackAssetsManifest from 'webpack-assets-manifest';
6
+ import { WebpackAssetsManifest } from 'webpack-assets-manifest';
7
7
  import VirtualModulesPlugin from 'webpack-virtual-modules';
8
8
 
9
9
  import { webpackDevConfigFileName, webpackProdConfigFileName } from '../../cli/utils';
@@ -32,7 +32,7 @@ jest.mock('webpack', () => ({
32
32
  ...jest.requireActual('webpack'),
33
33
  DefinePlugin: jest.fn(),
34
34
  }));
35
- jest.mock('webpack-assets-manifest', () => jest.fn());
35
+ jest.mock('webpack-assets-manifest', () => ({ WebpackAssetsManifest: jest.fn() }));
36
36
  jest.mock('webpack-virtual-modules', () => jest.fn());
37
37
  jest.mock('../../utils', () => ({
38
38
  ...jest.requireActual('../../utils'),
@@ -50,7 +50,7 @@ jest.mock('webpack', () => ({
50
50
  IgnorePlugin: jest.fn(),
51
51
  ProvidePlugin: jest.fn(),
52
52
  }));
53
- jest.mock('webpack-assets-manifest', () => jest.fn());
53
+ jest.mock('webpack-assets-manifest', () => ({ WebpackAssetsManifest: jest.fn() }));
54
54
  jest.mock('webpack-bundle-analyzer', () => ({ BundleAnalyzerPlugin: jest.fn() }));
55
55
  jest.mock('webpack-filter-warnings-plugin', () => jest.fn());
56
56
  jest.mock('webpack-virtual-modules', () => jest.fn());
@@ -1,4 +1,4 @@
1
- import WebpackAssetsManifest from 'webpack-assets-manifest';
1
+ import { WebpackAssetsManifest } from 'webpack-assets-manifest';
2
2
  import { Context, Overrides } from '../types';
3
3
  import { generateMetadata } from '../utils';
4
4
 
@@ -27,7 +27,8 @@ export function assetsManifestPlugin(context: Context, _: Overrides) {
27
27
  js: getAssetsByType('js'),
28
28
  };
29
29
  },
30
- done(_manifest) {
30
+ // eslint-disable-next-line @typescript-eslint/require-await
31
+ done: async (_manifest: WebpackAssetsManifest) => {
31
32
  generateMetadata(context);
32
33
  },
33
34
  });
@@ -20,7 +20,7 @@ export function checkResource(packageContext: Context) {
20
20
  if (isOptionalReactDomPeerDependency({ resource, context })) {
21
21
  try {
22
22
  require.resolve(resource);
23
- } catch (e) {
23
+ } catch {
24
24
  return true;
25
25
  }
26
26
  }
@@ -1,8 +1,21 @@
1
- import MomentLocalesPlugin from 'moment-locales-webpack-plugin';
2
1
  import { Context, Overrides } from '../types';
3
2
 
3
+ const MomentLocalesPlugin: typeof import('moment-locales-webpack-plugin') | undefined =
4
+ isMomentInstalled() ? require('moment-locales-webpack-plugin') : undefined;
5
+
4
6
  export function momentLocalesPlugin(_: Context, _overrides: Overrides) {
5
- return new MomentLocalesPlugin({
6
- localesToKeep: ['en-au', 'en-ca', 'en-gb'],
7
- });
7
+ return (
8
+ MomentLocalesPlugin &&
9
+ new MomentLocalesPlugin({
10
+ localesToKeep: ['en-au', 'en-ca', 'en-gb'],
11
+ })
12
+ );
13
+ }
14
+
15
+ function isMomentInstalled() {
16
+ try {
17
+ return !!require.resolve('moment');
18
+ } catch {
19
+ return false;
20
+ }
8
21
  }
@@ -1,5 +1,3 @@
1
- import { WebpackError } from 'webpack';
2
-
3
1
  function removeCWD(str: string) {
4
2
  const isWin = process.platform === 'win32';
5
3
  let cwd = process.cwd();
@@ -13,6 +11,6 @@ function removeCWD(str: string) {
13
11
  return str.replace(new RegExp(cwd, 'g'), '');
14
12
  }
15
13
 
16
- export function normalizeErrors(errors: WebpackError[]) {
14
+ export function normalizeErrors(errors: Error[]) {
17
15
  return errors.map(error => removeCWD(error.message.split('\n').slice(0, 2).join('\n')));
18
16
  }