@servicetitan/startup 27.2.1 → 27.4.0-canary.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 (135) hide show
  1. package/dist/cli/commands/get-branch-configs.d.ts +4 -0
  2. package/dist/cli/commands/get-branch-configs.d.ts.map +1 -0
  3. package/dist/cli/commands/get-branch-configs.js +13 -0
  4. package/dist/cli/commands/get-branch-configs.js.map +1 -0
  5. package/dist/cli/commands/get-command.d.ts.map +1 -1
  6. package/dist/cli/commands/get-command.js +4 -2
  7. package/dist/cli/commands/get-command.js.map +1 -1
  8. package/dist/cli/commands/init.d.ts +0 -1
  9. package/dist/cli/commands/init.d.ts.map +1 -1
  10. package/dist/cli/commands/init.js +39 -9
  11. package/dist/cli/commands/init.js.map +1 -1
  12. package/dist/cli/commands/mfe-package-clean.d.ts +13 -0
  13. package/dist/cli/commands/mfe-package-clean.d.ts.map +1 -0
  14. package/dist/cli/commands/mfe-package-clean.js +113 -0
  15. package/dist/cli/commands/mfe-package-clean.js.map +1 -0
  16. package/dist/cli/commands/mfe-package-publish.d.ts +20 -0
  17. package/dist/cli/commands/mfe-package-publish.d.ts.map +1 -0
  18. package/dist/cli/commands/mfe-package-publish.js +153 -0
  19. package/dist/cli/commands/mfe-package-publish.js.map +1 -0
  20. package/dist/cli/commands/mfe-publish.d.ts +4 -29
  21. package/dist/cli/commands/mfe-publish.d.ts.map +1 -1
  22. package/dist/cli/commands/mfe-publish.js +1 -213
  23. package/dist/cli/commands/mfe-publish.js.map +1 -1
  24. package/dist/cli/utils/assets-copy.d.ts.map +1 -1
  25. package/dist/cli/utils/assets-copy.js +3 -3
  26. package/dist/cli/utils/assets-copy.js.map +1 -1
  27. package/dist/cli/utils/bundle.d.ts.map +1 -1
  28. package/dist/cli/utils/bundle.js +10 -11
  29. package/dist/cli/utils/bundle.js.map +1 -1
  30. package/dist/cli/utils/cli-os.d.ts +9 -2
  31. package/dist/cli/utils/cli-os.d.ts.map +1 -1
  32. package/dist/cli/utils/cli-os.js +16 -8
  33. package/dist/cli/utils/cli-os.js.map +1 -1
  34. package/dist/cli/utils/styles-copy.d.ts.map +1 -1
  35. package/dist/cli/utils/styles-copy.js +3 -3
  36. package/dist/cli/utils/styles-copy.js.map +1 -1
  37. package/dist/index.d.ts +1 -0
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +4 -0
  40. package/dist/index.js.map +1 -1
  41. package/dist/utils/get-configuration.d.ts +2 -1
  42. package/dist/utils/get-configuration.d.ts.map +1 -1
  43. package/dist/utils/get-configuration.js +5 -0
  44. package/dist/utils/get-configuration.js.map +1 -1
  45. package/dist/utils/get-exposed-dependencies.d.ts +7 -0
  46. package/dist/utils/get-exposed-dependencies.d.ts.map +1 -0
  47. package/dist/utils/get-exposed-dependencies.js +10 -0
  48. package/dist/utils/get-exposed-dependencies.js.map +1 -0
  49. package/dist/utils/get-folders.js +2 -2
  50. package/dist/utils/get-folders.js.map +1 -1
  51. package/dist/utils/index.d.ts +1 -0
  52. package/dist/utils/index.d.ts.map +1 -1
  53. package/dist/utils/index.js +1 -0
  54. package/dist/utils/index.js.map +1 -1
  55. package/dist/webpack/configs/dev-server-config.d.ts.map +1 -1
  56. package/dist/webpack/configs/dev-server-config.js +4 -1
  57. package/dist/webpack/configs/dev-server-config.js.map +1 -1
  58. package/dist/webpack/configs/plugins/define-exposed-dependencies-plugin.d.ts.map +1 -1
  59. package/dist/webpack/configs/plugins/define-exposed-dependencies-plugin.js +2 -9
  60. package/dist/webpack/configs/plugins/define-exposed-dependencies-plugin.js.map +1 -1
  61. package/dist/webpack/configs/plugins/virtual-modules-plugin.d.ts.map +1 -1
  62. package/dist/webpack/configs/plugins/virtual-modules-plugin.js +15 -5
  63. package/dist/webpack/configs/plugins/virtual-modules-plugin.js.map +1 -1
  64. package/dist/webpack/configs/types.d.ts +16 -0
  65. package/dist/webpack/configs/types.d.ts.map +1 -1
  66. package/dist/webpack/configs/utils/generate-metadata.d.ts.map +1 -1
  67. package/dist/webpack/configs/utils/generate-metadata.js +3 -3
  68. package/dist/webpack/configs/utils/generate-metadata.js.map +1 -1
  69. package/package.json +15 -20
  70. package/src/cli/commands/__tests__/init.test.ts +108 -28
  71. package/src/cli/commands/__tests__/mfe-package-clean.test.ts +1 -1
  72. package/src/cli/commands/__tests__/mfe-package-publish.test.ts +77 -7
  73. package/src/cli/commands/get-branch-configs.ts +8 -0
  74. package/src/cli/commands/get-command.ts +3 -1
  75. package/src/cli/commands/init.ts +40 -10
  76. package/src/cli/commands/mfe-package-clean.ts +132 -0
  77. package/src/cli/commands/mfe-package-publish.ts +189 -0
  78. package/src/cli/commands/mfe-publish.ts +5 -294
  79. package/src/cli/utils/__tests__/assets-copy.test.ts +3 -7
  80. package/src/cli/utils/__tests__/bundle.test.ts +45 -6
  81. package/src/cli/utils/__tests__/cli-os.test.ts +41 -6
  82. package/src/cli/utils/__tests__/styles-copy.test.ts +3 -7
  83. package/src/cli/utils/assets-copy.ts +3 -3
  84. package/src/cli/utils/bundle.ts +14 -20
  85. package/src/cli/utils/cli-os.ts +20 -8
  86. package/src/cli/utils/styles-copy.ts +3 -3
  87. package/src/index.ts +2 -0
  88. package/src/utils/__tests__/get-configuration.test.ts +6 -0
  89. package/src/utils/get-configuration.ts +6 -1
  90. package/src/utils/get-exposed-dependencies.ts +19 -0
  91. package/src/utils/get-folders.ts +1 -1
  92. package/src/utils/index.ts +1 -0
  93. package/src/webpack/__tests__/create-webpack-config-web-component.test.ts +47 -13
  94. package/src/webpack/__tests__/create-webpack-config.test.ts +10 -0
  95. package/src/webpack/configs/dev-server-config.ts +7 -2
  96. package/src/webpack/configs/plugins/define-exposed-dependencies-plugin.ts +6 -16
  97. package/src/webpack/configs/plugins/virtual-modules-plugin.ts +17 -5
  98. package/src/webpack/configs/types.ts +19 -0
  99. package/src/webpack/configs/utils/generate-metadata.ts +5 -5
  100. package/template/.eslintrc.json +0 -3
  101. package/template/.gitignore +0 -21
  102. package/template/.npmrc +0 -3
  103. package/template/.prettierrc +0 -9
  104. package/template/.stylelintignore +0 -1
  105. package/template/.stylelintrc.json +0 -3
  106. package/template/.vscode/extensions.json +0 -18
  107. package/template/.vscode/settings.json +0 -4
  108. package/template/lerna.json +0 -4
  109. package/template/package.json +0 -32
  110. package/template/packages/application/package.json +0 -35
  111. package/template/packages/application/src/__tests__/app.test.tsx +0 -33
  112. package/template/packages/application/src/app.css +0 -3
  113. package/template/packages/application/src/app.tsx +0 -45
  114. package/template/packages/application/src/design-system.css +0 -3
  115. package/template/packages/application/src/index.tsx +0 -8
  116. package/template/packages/application/src/main-page.tsx +0 -5
  117. package/template/packages/application/src/second-page.tsx +0 -5
  118. package/template/packages/application/tsconfig.json +0 -13
  119. package/template/packages/feature-a/package.json +0 -19
  120. package/template/packages/feature-a/src/index.ts +0 -0
  121. package/template/packages/feature-a/tsconfig.json +0 -9
  122. package/template/packages/feature-b/package.json +0 -19
  123. package/template/packages/feature-b/src/index.ts +0 -0
  124. package/template/packages/feature-b/tsconfig.json +0 -9
  125. package/template/packages/feature-c/package.json +0 -19
  126. package/template/packages/feature-c/src/index.ts +0 -0
  127. package/template/packages/feature-c/tsconfig.json +0 -9
  128. package/template/setupTests.ts +0 -27
  129. package/template/tsconfig.test.json +0 -5
  130. package/template-react18/packages/application/package.json +0 -35
  131. package/template-react18/packages/application/src/index.tsx +0 -9
  132. package/template-react18/packages/feature-a/package.json +0 -19
  133. package/template-react18/packages/feature-b/package.json +0 -19
  134. package/template-react18/packages/feature-c/package.json +0 -19
  135. package/tsconfig.json +0 -13
@@ -6,9 +6,11 @@ import {
6
6
  } from 'child_process';
7
7
  import { log } from '../../utils';
8
8
 
9
+ type RunCommandOptions = SpawnOptionsWithoutStdio & { quiet?: boolean };
10
+
9
11
  export const runCommand = (
10
12
  command: string | (string | false)[],
11
- opts?: SpawnOptionsWithoutStdio
13
+ { quiet, ...spawnOptions }: RunCommandOptions = {}
12
14
  ): Promise<void> => {
13
15
  return new Promise((resolve, reject) => {
14
16
  const commandArray: string[] = Array.isArray(command)
@@ -28,15 +30,19 @@ export const runCommand = (
28
30
  return;
29
31
  }
30
32
 
31
- log.info(`run command ${fullCommand}`);
33
+ if (!quiet) {
34
+ log.info(`run command ${fullCommand}`);
35
+ }
32
36
 
33
- const proc = spawn(commandName, commandArray, opts);
37
+ const proc = spawn(commandName, commandArray, spawnOptions);
34
38
 
35
39
  proc.stdout.pipe(process.stdout);
36
40
  proc.stderr.pipe(process.stderr);
37
41
 
38
42
  proc.on('exit', function (code: any) {
39
- log.info(`command finished with code ${code}`, fullCommand);
43
+ if (!quiet) {
44
+ log.info(`command finished with code ${code}`, fullCommand);
45
+ }
40
46
 
41
47
  if (code) {
42
48
  reject();
@@ -47,9 +53,11 @@ export const runCommand = (
47
53
  });
48
54
  };
49
55
 
56
+ type RunCommandOutputOptions = ExecSyncOptionsWithBufferEncoding & { quiet?: boolean };
57
+
50
58
  export const runCommandOutput = (
51
59
  command: string | (string | false)[],
52
- options?: ExecSyncOptionsWithBufferEncoding
60
+ { quiet, ...execSyncOptions }: RunCommandOutputOptions = {}
53
61
  ): string => {
54
62
  const commandArray: string[] = Array.isArray(command)
55
63
  ? command
@@ -66,11 +74,15 @@ export const runCommandOutput = (
66
74
  throw new Error();
67
75
  }
68
76
 
69
- log.info(`run command ${fullCommand}`);
77
+ if (!quiet) {
78
+ log.info(`run command ${fullCommand}`);
79
+ }
70
80
 
71
- const result = execSync(fullCommand, options).toString();
81
+ const result = execSync(fullCommand, execSyncOptions).toString();
72
82
 
73
- log.info('command finished', result);
83
+ if (!quiet) {
84
+ log.info('command finished', result);
85
+ }
74
86
 
75
87
  return result;
76
88
  };
@@ -1,15 +1,15 @@
1
1
  import cpx from 'cpx2';
2
- import util from 'util';
3
2
 
4
3
  import { getFolders, log } from '../../utils';
5
4
  import { styleExtensions } from '.';
6
5
 
7
- export async function stylesCopy() {
6
+ export function stylesCopy() {
8
7
  const { source, destination } = getFolders();
9
8
 
10
9
  log.info('Copying style files...');
11
10
 
12
- await util.promisify(cpx.copy)(`${source}/**/*.{${styleExtensions.join()}}`, destination);
11
+ cpx.copySync(`${source}/**/*.{${styleExtensions.join()}}`, destination);
12
+ return Promise.resolve();
13
13
  }
14
14
 
15
15
  export async function stylesCopyWatch() {
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from './webpack';
2
2
  export * from './jest';
3
3
  export * from './utils/get-packages';
4
+
5
+ export { ExposedDependency, getExposedDependencies, loadSharedDependencies } from './utils';
@@ -8,6 +8,7 @@ import {
8
8
  getStylelintConfiguration,
9
9
  isBundle,
10
10
  isCustomStyleRules,
11
+ isDevServerDisabled,
11
12
  isExposeSharedDependencies,
12
13
  isLegacy,
13
14
  isLegacyRoot,
@@ -193,6 +194,11 @@ describe('[startup] Utils', () => {
193
194
  defaultValue: false,
194
195
  trigger: { cli: { webpack: { 'custom-style-rules': true } } },
195
196
  },
197
+ {
198
+ fn: isDevServerDisabled,
199
+ defaultValue: false,
200
+ trigger: { cli: { webpack: { devServer: false } } },
201
+ },
196
202
  {
197
203
  fn: isExposeSharedDependencies,
198
204
  defaultValue: false,
@@ -30,7 +30,7 @@ export interface WebpackConfiguration
30
30
  'contentBase'?: boolean | string | string[] | number; // deprecated 2024-07
31
31
  'custom-style-rules'?: boolean;
32
32
  'expose-shared-dependencies'?: boolean;
33
- 'devServer'?: WebpackDevServerConfiguration;
33
+ 'devServer'?: false | WebpackDevServerConfiguration;
34
34
  'disable-style-check'?: boolean;
35
35
  'minify'?: MinifyOptions;
36
36
  'proxy'?: WebpackDevServerConfiguration['proxy'] | string;
@@ -128,6 +128,11 @@ export function isCustomStyleRules() {
128
128
  return getWebpackConfiguration()['custom-style-rules'] === true;
129
129
  }
130
130
 
131
+ export function isDevServerDisabled() {
132
+ const webpackConfiguration = getWebpackConfiguration();
133
+ return webpackConfiguration.devServer === false;
134
+ }
135
+
131
136
  export function isExposeSharedDependencies() {
132
137
  return getWebpackConfiguration()['expose-shared-dependencies'] === true;
133
138
  }
@@ -0,0 +1,19 @@
1
+ export interface ExposedDependency {
2
+ version: string;
3
+ variable: string;
4
+ }
5
+
6
+ export type ExposedDependencies = Record<string, ExposedDependency>;
7
+
8
+ export function getExposedDependencies(
9
+ sharedDependencies: Record<string, string>,
10
+ getVersion: (dependency: string) => string
11
+ ) {
12
+ return Object.entries(sharedDependencies).reduce(
13
+ (result, [dependency, variable]) => ({
14
+ ...result,
15
+ [dependency]: { version: getVersion(dependency), variable },
16
+ }),
17
+ {} as ExposedDependencies
18
+ );
19
+ }
@@ -1,6 +1,6 @@
1
1
  import path from 'path';
2
2
 
3
- import { readJson } from '.';
3
+ import { readJson } from './read-json';
4
4
 
5
5
  /**
6
6
  * Returns folders of sources and compilation target
@@ -1,5 +1,6 @@
1
1
  export * from './get-configuration';
2
2
  export * from './get-destination-folders';
3
+ export * from './get-exposed-dependencies';
3
4
  export * from './get-folders';
4
5
  export * from './get-jest-config';
5
6
  export * from './get-package-data';
@@ -67,16 +67,19 @@ describe(`[startup] ${createWebpackConfig.name}`, () => {
67
67
  const indexCode = ({
68
68
  embed = false,
69
69
  legacyRoot = false,
70
- }: { embed?: boolean; legacyRoot?: boolean } = {}) =>
70
+ designSystem,
71
+ }: { embed?: boolean; legacyRoot?: boolean; designSystem?: boolean } = {}) =>
71
72
  [
72
- ...(embed ? [] : [`require('./design-system.css');`]),
73
+ ...(designSystem ? [`require('./design-system.css');`] : []),
73
74
  `import { register } from '@servicetitan/web-components';`,
74
75
  `import { App } from './app';`,
75
- `register(App, ${embed}, { legacyRoot: ${legacyRoot}, sharedDependenciesNames: [] });`,
76
+ `register(App, ${embed}, { legacyRoot: ${legacyRoot}, sharedDependenciesNames: ${JSON.stringify(Object.keys(sharedDependencies))} });`,
76
77
  ].join('\n');
77
78
 
78
79
  let overrides: Parameters<typeof createWebpackConfig>[0];
79
80
  let options: NonNullable<Parameters<typeof createWebpackConfig>[1]>;
81
+ let dependencies: Record<string, string>;
82
+ let sharedDependencies: Record<string, string>;
80
83
 
81
84
  function mockPlugIn(name: string) {
82
85
  return (options: Record<string, any>): any => ({ [name]: options });
@@ -85,6 +88,10 @@ describe(`[startup] ${createWebpackConfig.name}`, () => {
85
88
  beforeEach(() => {
86
89
  overrides = { plugins: { HtmlWebpackPlugin: { favicon: 'foo' } } };
87
90
  options = { name: packageName };
91
+ dependencies = { '@servicetitan/design-system': '*' };
92
+ sharedDependencies = {
93
+ '@servicetitan/design-system': 'SharedDependencies.ServiceTitan.DesignSystem',
94
+ };
88
95
 
89
96
  jest.resetAllMocks();
90
97
  jest.mocked(MiniCssExtractPlugin).mockImplementation(mockPlugIn('MiniCssExtractPlugin'));
@@ -95,11 +102,11 @@ describe(`[startup] ${createWebpackConfig.name}`, () => {
95
102
 
96
103
  jest.mocked(getCallerFile).mockReturnValue('');
97
104
  jest.mocked(getFolders).mockReturnValue({ source, destination });
98
- jest.mocked(getPackageData).mockReturnValue({
105
+ jest.mocked(getPackageData).mockImplementation(() => ({
99
106
  name: packageName,
100
- dependencies: {},
101
- sharedDependencies: {},
102
- });
107
+ dependencies,
108
+ sharedDependencies,
109
+ }));
103
110
  jest.mocked(getPackages).mockReturnValue([]);
104
111
  jest.mocked(getTsConfig).mockReturnValue(tsConfig);
105
112
  jest.mocked(isLegacyRoot).mockReturnValue(false);
@@ -233,7 +240,7 @@ describe(`[startup] ${createWebpackConfig.name}`, () => {
233
240
  expect(subject().plugins).toContainEqual(
234
241
  new VirtualModulesPlugin({
235
242
  [designSystemPath()]: designSystemCode,
236
- [indexPath()]: indexCode(),
243
+ [indexPath()]: indexCode({ designSystem: true }),
237
244
  })
238
245
  );
239
246
  });
@@ -245,7 +252,7 @@ describe(`[startup] ${createWebpackConfig.name}`, () => {
245
252
  expect(subject().plugins).toContainEqual(
246
253
  new VirtualModulesPlugin({
247
254
  [designSystemPath()]: designSystemCode,
248
- [indexPath()]: indexCode({ legacyRoot: true }),
255
+ [indexPath()]: indexCode({ designSystem: true, legacyRoot: true }),
249
256
  })
250
257
  );
251
258
  });
@@ -262,7 +269,22 @@ describe(`[startup] ${createWebpackConfig.name}`, () => {
262
269
  test('omits design system virtual module', () => {
263
270
  expect(subject().plugins).toContainEqual(
264
271
  new VirtualModulesPlugin({
265
- [indexPath()]: indexCode(),
272
+ [indexPath()]: indexCode({ designSystem: true }),
273
+ })
274
+ );
275
+ });
276
+ });
277
+
278
+ describe('when package does not depend on design system', () => {
279
+ beforeEach(() => {
280
+ delete dependencies['@servicetitan/design-system'];
281
+ delete sharedDependencies['@servicetitan/design-system'];
282
+ });
283
+
284
+ test('omits design system', () => {
285
+ expect(subject().plugins).toContainEqual(
286
+ new VirtualModulesPlugin({
287
+ [indexPath()]: indexCode({ designSystem: false }),
266
288
  })
267
289
  );
268
290
  });
@@ -271,11 +293,10 @@ describe(`[startup] ${createWebpackConfig.name}`, () => {
271
293
  describe('when embed option is set to true', () => {
272
294
  beforeEach(() => (options.embed = true));
273
295
 
274
- test(`changes virtual index module to omit design system and to register App`, () => {
296
+ test(`omits design system and registers App with embed set to true`, () => {
275
297
  expect(subject().plugins).toContainEqual(
276
298
  new VirtualModulesPlugin({
277
- [designSystemPath()]: designSystemCode,
278
- [indexPath()]: indexCode({ embed: true }),
299
+ [indexPath()]: indexCode({ designSystem: false, embed: true }),
279
300
  })
280
301
  );
281
302
  });
@@ -285,6 +306,19 @@ describe(`[startup] ${createWebpackConfig.name}`, () => {
285
306
  expect.stringContaining(path.join(destination, 'bundle', 'light'))
286
307
  );
287
308
  });
309
+
310
+ describe('when package does not share design system', () => {
311
+ beforeEach(() => delete sharedDependencies['@servicetitan/design-system']);
312
+
313
+ test('includes design system', () => {
314
+ expect(subject().plugins).toContainEqual(
315
+ new VirtualModulesPlugin({
316
+ [designSystemPath()]: designSystemCode,
317
+ [indexPath()]: indexCode({ designSystem: true, embed: true }),
318
+ })
319
+ );
320
+ });
321
+ });
288
322
  });
289
323
 
290
324
  describe.each([webpackDevConfigFileName, webpackProdConfigFileName])(
@@ -25,6 +25,7 @@ import {
25
25
  getTsConfig,
26
26
  getWebpackConfiguration,
27
27
  isCustomStyleRules,
28
+ isDevServerDisabled,
28
29
  isWebComponent,
29
30
  loadSharedDependencies,
30
31
  log,
@@ -64,6 +65,7 @@ jest.mock('../../utils', () => ({
64
65
  getTsConfig: jest.fn(),
65
66
  getWebpackConfiguration: jest.fn(),
66
67
  isCustomStyleRules: jest.fn(),
68
+ isDevServerDisabled: jest.fn(),
67
69
  isExposeSharedDependencies: jest.fn(),
68
70
  isWebComponent: jest.fn(),
69
71
  loadSharedDependencies: jest.fn(),
@@ -220,6 +222,14 @@ describe(`[startup] ${createWebpackConfig.name}`, () => {
220
222
  expect(subject().devServer).toEqual(defaultDefServerConfig);
221
223
  });
222
224
 
225
+ describe('when "devServer" is disabled', () => {
226
+ beforeEach(() => jest.mocked(isDevServerDisabled).mockReturnValue(true));
227
+
228
+ test('omits "devServer" configuration', () => {
229
+ expect(subject().devServer).toBeUndefined();
230
+ });
231
+ });
232
+
223
233
  describe('with custom devServer options', () => {
224
234
  const options: WebpackDevServer.Configuration = {
225
235
  // allowed options
@@ -4,9 +4,10 @@ import { Configuration } from 'webpack';
4
4
  import {
5
5
  PackageType,
6
6
  allowedWebpackDevServerOptions,
7
- getConfiguration,
8
7
  getPackageName,
9
8
  getPackages,
9
+ getWebpackConfiguration,
10
+ isDevServerDisabled,
10
11
  log,
11
12
  pick,
12
13
  } from '../../utils';
@@ -23,6 +24,10 @@ export function devServerConfig(context: Context, overrides: Overrides): Result
23
24
  }
24
25
 
25
26
  const watchOptions = watchOptionsConfig();
27
+ if (isDevServerDisabled()) {
28
+ return { watchOptions };
29
+ }
30
+
26
31
  const devServer = {
27
32
  hot: false,
28
33
  port: 8080,
@@ -41,7 +46,7 @@ export function devServerConfig(context: Context, overrides: Overrides): Result
41
46
  }
42
47
 
43
48
  function getDevServerConfig() {
44
- const webpack = getConfiguration().webpack || {}; // eslint-disable-line @typescript-eslint/prefer-nullish-coalescing
49
+ const webpack = getWebpackConfiguration();
45
50
  /* istanbul ignore next: debug only */
46
51
  log.debug('dev-server-config', () => JSON.stringify({ webpack }, null, 2));
47
52
 
@@ -1,5 +1,5 @@
1
1
  import { DefinePlugin } from 'webpack';
2
- import { getPackageDependencyVersion } from '../../../utils';
2
+ import { getExposedDependencies, getPackageDependencyVersion } from '../../../utils';
3
3
  import { Context, Overrides } from '../types';
4
4
 
5
5
  export function defineExposedDependenciesPlugin(context: Context, _: Overrides) {
@@ -8,22 +8,12 @@ export function defineExposedDependenciesPlugin(context: Context, _: Overrides)
8
8
  return;
9
9
  }
10
10
 
11
+ const exposedDependencies = getExposedDependencies(sharedDependencies, dependency =>
12
+ getPackageDependencyVersion(dependency, packageData.dependencies?.[dependency])
13
+ );
14
+
11
15
  return new DefinePlugin({
12
16
  // eslint-disable-next-line @typescript-eslint/naming-convention
13
- EXPOSED_DEPENDENCIES: JSON.stringify(
14
- Object.entries(sharedDependencies).reduce(
15
- (result, [dependency, variable]) =>
16
- Object.assign(result, {
17
- [dependency]: {
18
- version: getPackageDependencyVersion(
19
- dependency,
20
- packageData.dependencies?.[dependency]
21
- ),
22
- variable,
23
- },
24
- }),
25
- {}
26
- )
27
- ),
17
+ EXPOSED_DEPENDENCIES: JSON.stringify(exposedDependencies),
28
18
  });
29
19
  }
@@ -15,9 +15,11 @@ export function virtualModulesPlugin(context: Context, _: Overrides) {
15
15
  [indexPath]: indexCode(context),
16
16
  };
17
17
 
18
- const designSystemPath = path.join(process.cwd(), `${source}/design-system.css`);
19
- if (!fs.existsSync(designSystemPath)) {
20
- modules[designSystemPath] = designSystemCode();
18
+ if (needsToIncludeDesignSystem(context)) {
19
+ const designSystemPath = path.join(process.cwd(), `${source}/design-system.css`);
20
+ if (!fs.existsSync(designSystemPath)) {
21
+ modules[designSystemPath] = designSystemCode();
22
+ }
21
23
  }
22
24
 
23
25
  return new VirtualModulesPlugin(modules);
@@ -31,14 +33,24 @@ function designSystemCode() {
31
33
  ].join('\n');
32
34
  }
33
35
 
34
- function indexCode({ embed = false, isLegacyRoot, sharedDependencies }: Context) {
36
+ function indexCode(context: Context) {
37
+ const { embed = false, isLegacyRoot, sharedDependencies } = context;
35
38
  const options = `{ legacyRoot: ${isLegacyRoot}, sharedDependenciesNames: ${JSON.stringify(
36
39
  Object.keys(sharedDependencies)
37
40
  )} }`;
38
41
  return [
39
- ...(embed ? [] : [`require('./design-system.css');`]),
42
+ ...(needsToIncludeDesignSystem(context) ? [`require('./design-system.css');`] : []),
40
43
  `import { register } from '@servicetitan/web-components';`,
41
44
  `import { App } from './app';`,
42
45
  `register(App, ${embed}, ${options});`,
43
46
  ].join('\n');
44
47
  }
48
+
49
+ function needsToIncludeDesignSystem({ embed, packageData, sharedDependencies }: Context) {
50
+ return (
51
+ // Depends on design system
52
+ !!packageData.dependencies['@servicetitan/design-system'] &&
53
+ // ... and is not light bundle with private copy of design system
54
+ !(embed && !!sharedDependencies['@servicetitan/design-system'])
55
+ );
56
+ }
@@ -13,7 +13,26 @@ export interface Context extends Options {
13
13
  isProduction: boolean;
14
14
  isWebComponent: boolean;
15
15
  minify?: MinifyOptions;
16
+ name: string;
16
17
  packageData: ReturnType<typeof getPackageData>;
17
18
  sharedDependencies: ReturnType<typeof loadSharedDependencies>;
18
19
  source: string;
19
20
  }
21
+
22
+ export interface EntryPoint {
23
+ css?: string[];
24
+ js?: string[];
25
+ }
26
+
27
+ export interface EntryPoints {
28
+ full?: EntryPoint;
29
+ light?: EntryPoint;
30
+ }
31
+
32
+ export interface Metadata {
33
+ name: string;
34
+ bundledWith: Record<string, string>;
35
+ sharedDependencies: Record<string, string>;
36
+ dependencies: Record<string, string>;
37
+ entrypoints: EntryPoints;
38
+ }
@@ -1,21 +1,20 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { log, getStartupVersion, readJsonSafe } from '../../../utils';
4
- import { Context } from '../types';
4
+ import { Context, Metadata } from '../types';
5
5
 
6
6
  import { getWebComponentsVersion } from './get-web-components-version';
7
7
 
8
8
  export function generateMetadata(context: Context) {
9
9
  const { destination, name, packageData, sharedDependencies } = context;
10
- const outputFile = `./${destination}/metadata.json`;
11
10
 
12
- if (!fs.existsSync(`./${destination}`)) {
13
- fs.mkdirSync(`./${destination}`, { recursive: true });
11
+ if (!fs.existsSync(destination)) {
12
+ fs.mkdirSync(destination, { recursive: true });
14
13
  }
15
14
 
16
15
  const full = readJsonSafe(path.join(destination, 'bundle', 'full', 'entrypoints.json'));
17
16
  const light = readJsonSafe(path.join(destination, 'bundle', 'light', 'entrypoints.json'));
18
- const metadata = {
17
+ const metadata: Metadata = {
19
18
  name,
20
19
  bundledWith: {
21
20
  '@servicetitan/startup': getStartupVersion(),
@@ -26,6 +25,7 @@ export function generateMetadata(context: Context) {
26
25
  entrypoints: { ...(full ? { full } : {}), ...(light ? { light } : {}) },
27
26
  };
28
27
 
28
+ const outputFile = path.join(destination, 'metadata.json');
29
29
  fs.writeFileSync(outputFile, JSON.stringify(metadata, null, 2), 'utf8');
30
30
 
31
31
  /* istanbul ignore next: debug only */
@@ -1,3 +0,0 @@
1
- {
2
- "extends": ["@servicetitan/eslint-config/mono"]
3
- }
@@ -1,21 +0,0 @@
1
- # Mac-related stuff
2
- ._.DS_Store/
3
- .DS_Store/
4
- *.DS_Store
5
-
6
- # Node.js
7
- node_modules/
8
-
9
- # yalc store
10
- .yalc/
11
- yalc.lock
12
-
13
- #SonarQube
14
- .scannerwork/
15
-
16
- *.css.d.ts
17
- *.less.d.ts
18
- *.scss.d.ts
19
- /coverage/
20
- dist/
21
- *.tsbuildinfo
package/template/.npmrc DELETED
@@ -1,3 +0,0 @@
1
- engine-strict=true
2
- legacy-peer-deps=true
3
- no-audit=true
@@ -1,9 +0,0 @@
1
- {
2
- "printWidth": 100,
3
- "tabWidth": 4,
4
- "singleQuote": true,
5
- "quoteProps": "consistent",
6
- "arrowParens": "avoid",
7
- "endOfLine": "auto",
8
- "trailingComma": "es5"
9
- }
@@ -1 +0,0 @@
1
- /coverage
@@ -1,3 +0,0 @@
1
- {
2
- "extends": ["@servicetitan/stylelint-config"]
3
- }
@@ -1,18 +0,0 @@
1
- {
2
- // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
3
- // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
4
-
5
- // List of extensions which should be recommended for users of this workspace.
6
- "recommendations": [
7
- "dbaeumer.vscode-eslint",
8
- "esbenp.prettier-vscode",
9
- "stylelint.vscode-stylelint",
10
- "editorconfig.editorconfig",
11
- "yoavbls.pretty-ts-errors",
12
- "streetsidesoftware.code-spell-checker",
13
- "eamodio.gitlens",
14
- "pomber.git-file-history"
15
- ],
16
- // List of extensions recommended by VS Code that should not be recommended for users of this workspace.
17
- "unwantedRecommendations": []
18
- }
@@ -1,4 +0,0 @@
1
- {
2
- "typescript.tsdk": "node_modules/typescript/lib",
3
- "editor.formatOnSave": true
4
- }
@@ -1,4 +0,0 @@
1
- {
2
- "packages": ["packages/*"],
3
- "version": "0.0.0"
4
- }
@@ -1,32 +0,0 @@
1
- {
2
- "name": "root",
3
- "version": "0.0.0",
4
- "description": "Multi-package web application template",
5
- "private": true,
6
- "engines": {
7
- "node": ">=18",
8
- "npm": ">=10"
9
- },
10
- "scripts": {
11
- "bootstrap": "npx --yes @servicetitan/startup install",
12
- "prestart": "npm run bootstrap",
13
- "start": "startup start",
14
- "prebuild": "npm run bootstrap",
15
- "build": "startup build",
16
- "lint": "startup lint",
17
- "test": "startup test"
18
- },
19
- "devDependencies": {
20
- "@servicetitan/startup": ">=22.21.0"
21
- },
22
- "workspaces": [
23
- "packages/*"
24
- ],
25
- "cli": {
26
- "test": {
27
- "setupFilesAfterEnv": [
28
- "./setupTests.ts"
29
- ]
30
- }
31
- }
32
- }
@@ -1,35 +0,0 @@
1
- {
2
- "name": "application",
3
- "version": "0.0.0",
4
- "description": "",
5
- "private": true,
6
- "main": "./dist/index.js",
7
- "typings": "./dist/index.d.ts",
8
- "scripts": {},
9
- "dependencies": {
10
- "@servicetitan/design-system": "^13.4.3",
11
- "@servicetitan/hash-browser-router": "^24.1.0",
12
- "@servicetitan/link-item": "^26.1.0",
13
- "@servicetitan/log-service": "^24.1.0",
14
- "@servicetitan/react-ioc": "^24.1.0",
15
- "@servicetitan/web-components": "^24.1.0",
16
- "axios": "^0.28.1",
17
- "feature-a": "^0.0.0",
18
- "feature-b": "^0.0.0",
19
- "feature-c": "^0.0.0",
20
- "history": "~4.10.1",
21
- "mobx": "~6.10.2",
22
- "react": "^17.0.2",
23
- "react-dom": "^17.0.2",
24
- "react-router-dom": "^5.3.0"
25
- },
26
- "devDependencies": {
27
- "@servicetitan/testing-library": "^1.2.0",
28
- "@testing-library/jest-dom": "^5.17.0",
29
- "@testing-library/react": "^12.1.5",
30
- "@testing-library/react-hooks": "^8.0.1",
31
- "@types/react": "^17.0.37",
32
- "@types/react-dom": "^17.0.11",
33
- "@types/react-router-dom": "^5.3.2"
34
- }
35
- }