@servicetitan/startup 39.0.1 → 39.2.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/dist/cli/commands/mfe-list.d.ts +0 -2
  2. package/dist/cli/commands/mfe-list.d.ts.map +1 -1
  3. package/dist/cli/commands/mfe-list.js +4 -30
  4. package/dist/cli/commands/mfe-list.js.map +1 -1
  5. package/dist/cli/commands/mfe-package-clean.js +1 -2
  6. package/dist/cli/commands/mfe-package-clean.js.map +1 -1
  7. package/dist/cli/commands/mfe-package-publish.d.ts.map +1 -1
  8. package/dist/cli/commands/mfe-package-publish.js +7 -5
  9. package/dist/cli/commands/mfe-package-publish.js.map +1 -1
  10. package/dist/cli/commands/mfe-package-rollback.d.ts.map +1 -1
  11. package/dist/cli/commands/mfe-package-rollback.js +5 -3
  12. package/dist/cli/commands/mfe-package-rollback.js.map +1 -1
  13. package/dist/cli/commands/mfe-publish.d.ts +1 -0
  14. package/dist/cli/commands/mfe-publish.d.ts.map +1 -1
  15. package/dist/cli/commands/mfe-publish.js +14 -12
  16. package/dist/cli/commands/mfe-publish.js.map +1 -1
  17. package/dist/cli/commands/registry/command-registry.d.ts +13 -4
  18. package/dist/cli/commands/registry/command-registry.d.ts.map +1 -1
  19. package/dist/cli/commands/registry/mfe-list.d.ts +2 -1
  20. package/dist/cli/commands/registry/mfe-list.d.ts.map +1 -1
  21. package/dist/cli/commands/registry/mfe-list.js +3 -1
  22. package/dist/cli/commands/registry/mfe-list.js.map +1 -1
  23. package/dist/cli/commands/registry/mfe-package-clean.d.ts +2 -1
  24. package/dist/cli/commands/registry/mfe-package-clean.d.ts.map +1 -1
  25. package/dist/cli/commands/registry/mfe-package-clean.js +4 -2
  26. package/dist/cli/commands/registry/mfe-package-clean.js.map +1 -1
  27. package/dist/cli/commands/registry/mfe-package-publish.d.ts +2 -1
  28. package/dist/cli/commands/registry/mfe-package-publish.d.ts.map +1 -1
  29. package/dist/cli/commands/registry/mfe-package-publish.js +4 -2
  30. package/dist/cli/commands/registry/mfe-package-publish.js.map +1 -1
  31. package/dist/cli/commands/registry/mfe-package-rollback.d.ts +2 -1
  32. package/dist/cli/commands/registry/mfe-package-rollback.d.ts.map +1 -1
  33. package/dist/cli/commands/registry/mfe-package-rollback.js +4 -2
  34. package/dist/cli/commands/registry/mfe-package-rollback.js.map +1 -1
  35. package/dist/cli/commands/registry/upload-sourcemaps.d.ts +5 -0
  36. package/dist/cli/commands/registry/upload-sourcemaps.d.ts.map +1 -1
  37. package/dist/cli/commands/registry/upload-sourcemaps.js +5 -0
  38. package/dist/cli/commands/registry/upload-sourcemaps.js.map +1 -1
  39. package/dist/cli/commands/review/types.js.map +1 -1
  40. package/dist/cli/commands/upload-sourcemaps.d.ts.map +1 -1
  41. package/dist/cli/commands/upload-sourcemaps.js +4 -7
  42. package/dist/cli/commands/upload-sourcemaps.js.map +1 -1
  43. package/dist/cli/commands/utils/get-mfe-registry.d.ts +4 -0
  44. package/dist/cli/commands/utils/get-mfe-registry.d.ts.map +1 -0
  45. package/dist/cli/commands/utils/get-mfe-registry.js +28 -0
  46. package/dist/cli/commands/utils/get-mfe-registry.js.map +1 -0
  47. package/dist/cli/commands/utils/get-unpkg-host.d.ts +2 -0
  48. package/dist/cli/commands/utils/get-unpkg-host.d.ts.map +1 -0
  49. package/dist/cli/commands/utils/get-unpkg-host.js +18 -0
  50. package/dist/cli/commands/utils/get-unpkg-host.js.map +1 -0
  51. package/dist/cli/commands/utils/index.d.ts +3 -1
  52. package/dist/cli/commands/utils/index.d.ts.map +1 -1
  53. package/dist/cli/commands/utils/index.js +3 -1
  54. package/dist/cli/commands/utils/index.js.map +1 -1
  55. package/dist/cli/commands/utils/login.d.ts +2 -0
  56. package/dist/cli/commands/utils/login.d.ts.map +1 -0
  57. package/dist/cli/commands/utils/login.js +56 -0
  58. package/dist/cli/commands/utils/login.js.map +1 -0
  59. package/dist/cli/commands/utils/purge-cache.d.ts.map +1 -1
  60. package/dist/cli/commands/utils/purge-cache.js +2 -4
  61. package/dist/cli/commands/utils/purge-cache.js.map +1 -1
  62. package/dist/cli/index.js +4 -1
  63. package/dist/cli/index.js.map +1 -1
  64. package/dist/vite/build-escaped-reg-exp.d.ts +2 -0
  65. package/dist/vite/build-escaped-reg-exp.d.ts.map +1 -0
  66. package/dist/vite/build-escaped-reg-exp.js +16 -0
  67. package/dist/vite/build-escaped-reg-exp.js.map +1 -0
  68. package/dist/vite/config/base-config.d.ts.map +1 -1
  69. package/dist/vite/config/base-config.js +7 -2
  70. package/dist/vite/config/base-config.js.map +1 -1
  71. package/dist/vite/config/create-resolve-config.d.ts +6 -0
  72. package/dist/vite/config/create-resolve-config.d.ts.map +1 -0
  73. package/dist/vite/config/create-resolve-config.js +52 -0
  74. package/dist/vite/config/create-resolve-config.js.map +1 -0
  75. package/dist/vite/plugins/css-injector-plugin.d.ts.map +1 -1
  76. package/dist/vite/plugins/css-injector-plugin.js +5 -1
  77. package/dist/vite/plugins/css-injector-plugin.js.map +1 -1
  78. package/dist/vite/plugins/externals-plugin.d.ts.map +1 -1
  79. package/dist/vite/plugins/externals-plugin.js +3 -3
  80. package/dist/vite/plugins/externals-plugin.js.map +1 -1
  81. package/package.json +15 -16
  82. package/src/cli/commands/__tests__/mfe-list.test.ts +25 -56
  83. package/src/cli/commands/__tests__/mfe-package-clean.test.ts +6 -0
  84. package/src/cli/commands/__tests__/mfe-package-publish.test.ts +52 -47
  85. package/src/cli/commands/__tests__/mfe-package-rollback.test.ts +4 -2
  86. package/src/cli/commands/__tests__/mfe-publish.test.ts +51 -14
  87. package/src/cli/commands/__tests__/upload-sourcemaps.test.ts +27 -13
  88. package/src/cli/commands/mfe-list.ts +7 -36
  89. package/src/cli/commands/mfe-package-clean.ts +2 -2
  90. package/src/cli/commands/mfe-package-publish.ts +10 -8
  91. package/src/cli/commands/mfe-package-rollback.ts +6 -5
  92. package/src/cli/commands/mfe-publish.ts +17 -16
  93. package/src/cli/commands/registry/mfe-list.ts +6 -1
  94. package/src/cli/commands/registry/mfe-package-clean.ts +7 -1
  95. package/src/cli/commands/registry/mfe-package-publish.ts +7 -1
  96. package/src/cli/commands/registry/mfe-package-rollback.ts +4 -2
  97. package/src/cli/commands/registry/upload-sourcemaps.ts +1 -0
  98. package/src/cli/commands/upload-sourcemaps.ts +4 -7
  99. package/src/cli/commands/utils/__tests__/get-mfe-registry.test.ts +24 -0
  100. package/src/cli/commands/utils/__tests__/get-unpkg-host.test.ts +32 -0
  101. package/src/cli/commands/utils/__tests__/login.test.ts +122 -0
  102. package/src/cli/commands/utils/__tests__/purge-cache.test.ts +17 -15
  103. package/src/cli/commands/utils/get-mfe-registry.ts +6 -0
  104. package/src/cli/commands/utils/get-unpkg-host.ts +8 -0
  105. package/src/cli/commands/utils/index.ts +3 -1
  106. package/src/cli/commands/utils/login.ts +38 -0
  107. package/src/cli/commands/utils/purge-cache.ts +2 -5
  108. package/src/cli/index.ts +2 -1
  109. package/src/vite/__tests__/build-escaped-reg-exp.test.ts +25 -0
  110. package/src/vite/build-escaped-reg-exp.ts +6 -0
  111. package/src/vite/config/__tests__/base-config.test.ts +1 -1
  112. package/src/vite/config/__tests__/create-resolve-config.test.ts +85 -0
  113. package/src/vite/config/base-config.ts +4 -2
  114. package/src/vite/config/create-resolve-config.ts +43 -0
  115. package/src/vite/plugins/__tests__/css-injector-plugin.test.ts +1 -1
  116. package/src/vite/plugins/css-injector-plugin.ts +6 -1
  117. package/src/vite/plugins/externals-plugin.ts +1 -4
  118. package/dist/cli/commands/utils/constants.d.ts +0 -2
  119. package/dist/cli/commands/utils/constants.d.ts.map +0 -1
  120. package/dist/cli/commands/utils/constants.js +0 -13
  121. package/dist/cli/commands/utils/constants.js.map +0 -1
  122. package/src/cli/commands/utils/constants.ts +0 -1
@@ -33,6 +33,7 @@ import { assetFileNames } from './asset-file-names';
33
33
  import { getCodeSplitting } from './code-splitting';
34
34
  import { createCssConfig } from './create-css-config';
35
35
  import { createFilteringLogger } from './create-filtering-logger';
36
+ import { createResolveConfig } from './create-resolve-config';
36
37
 
37
38
  function importMetaRemap(
38
39
  ...definitions: (Record<string, string> | undefined)[]
@@ -79,6 +80,7 @@ function createPlugins(context: ViteBuildContext) {
79
80
  }
80
81
 
81
82
  export function createBaseConfig(context: ViteBuildContext): InlineConfig {
83
+ const optimizedStartupDependencies = ['@servicetitan/startup-utils', 'react-refresh/runtime'];
82
84
  const { isProduction } = context.build;
83
85
  const { isWebComponent } = context.package;
84
86
 
@@ -120,10 +122,10 @@ export function createBaseConfig(context: ViteBuildContext): InlineConfig {
120
122
  ),
121
123
  ...(getProcessEnv(context) ?? {}),
122
124
  },
125
+ resolve: createResolveConfig(context, optimizedStartupDependencies),
123
126
  optimizeDeps: {
124
127
  include: [
125
- '@servicetitan/startup-utils',
126
- 'react-refresh/runtime',
128
+ ...optimizedStartupDependencies,
127
129
  'react/jsx-runtime',
128
130
  'react/jsx-dev-runtime',
129
131
  ],
@@ -0,0 +1,43 @@
1
+ import { createRequire } from 'module';
2
+ import path from 'path';
3
+ import type { InlineConfig } from 'vite';
4
+ import { buildEscapedRegExp } from '../build-escaped-reg-exp';
5
+ import type { ViteBuildContext } from '../types';
6
+
7
+ type Result = InlineConfig['resolve'];
8
+
9
+ const startupRequire = createRequire(__filename);
10
+
11
+ /*
12
+ * Returns a resolver that, when normal resolution fails for a specifier,
13
+ * tries resolving from startup's location.
14
+ */
15
+ export function createResolveConfig(context: ViteBuildContext, specifiers: string[]): Result {
16
+ const source = path.resolve(context.package.source);
17
+
18
+ const alias = specifiers
19
+ .filter(specifier => !isResolvableFrom(specifier, source))
20
+ .map(specifier => ({
21
+ find: buildEscapedRegExp(specifier),
22
+ replacement: resolveFromStartup(specifier),
23
+ }));
24
+
25
+ return { alias };
26
+ }
27
+
28
+ function isResolvableFrom(specifier: string, source: string): boolean {
29
+ try {
30
+ require.resolve(specifier, { paths: [source] });
31
+ return true;
32
+ } catch {
33
+ return false;
34
+ }
35
+ }
36
+
37
+ function resolveFromStartup(specifier: string): string {
38
+ try {
39
+ return startupRequire.resolve(specifier);
40
+ } catch (cause) {
41
+ throw new Error(`[startup] Cannot resolve ${specifier}`, { cause });
42
+ }
43
+ }
@@ -64,7 +64,7 @@ describe(cssInjectorPlugin.name, () => {
64
64
  const result = transform(viteCssOutput, viteId);
65
65
 
66
66
  expect(result.code).toContain(
67
- `import { MfeStyleRegistry as __mfe__Registry } from '@servicetitan/web-components'`
67
+ `import { MfeStyleRegistry as __mfe__Registry } from '@servicetitan/web-components/css-injector/mfe-style-registry'`
68
68
  );
69
69
  });
70
70
 
@@ -48,7 +48,12 @@ export function cssInjectorPlugin(context: BuildContext): Plugin | undefined {
48
48
  transformed = transformed
49
49
  .replace(
50
50
  importPattern,
51
- `import { MfeStyleRegistry as __mfe__Registry } from '@servicetitan/web-components'`
51
+ /*
52
+ * Leaf module, not the package root: the root reaches anvil2, whose
53
+ * stylesheets are rewritten here, and the cycle leaves the registry
54
+ * undefined.
55
+ */
56
+ `import { MfeStyleRegistry as __mfe__Registry } from '@servicetitan/web-components/css-injector/mfe-style-registry'`
52
57
  )
53
58
  .replace(
54
59
  callPattern,
@@ -2,10 +2,7 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
  import type { Plugin } from 'vite';
4
4
  import { BuildContext, getExternals } from '../../core';
5
-
6
- /* Dots are the only valid regex-special character in package names */
7
- const buildEscapedRegExp = (dependency: string) =>
8
- new RegExp(`^${dependency.replace(/\./g, '\\.')}$`);
5
+ import { buildEscapedRegExp } from '../build-escaped-reg-exp';
9
6
 
10
7
  /*
11
8
  * Externalizes shared dependencies by redirecting imports to CJS proxy modules
@@ -1,2 +0,0 @@
1
- export declare const DEFAULT_MFE_REGISTRY = "https://verdaccio.servicetitan.com";
2
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/utils/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,uCAAuC,CAAC"}
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "DEFAULT_MFE_REGISTRY", {
6
- enumerable: true,
7
- get: function() {
8
- return DEFAULT_MFE_REGISTRY;
9
- }
10
- });
11
- const DEFAULT_MFE_REGISTRY = 'https://verdaccio.servicetitan.com';
12
-
13
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/cli/commands/utils/constants.ts"],"sourcesContent":["export const DEFAULT_MFE_REGISTRY = 'https://verdaccio.servicetitan.com';\n"],"names":["DEFAULT_MFE_REGISTRY"],"mappings":";;;;+BAAaA;;;eAAAA;;;AAAN,MAAMA,uBAAuB"}
@@ -1 +0,0 @@
1
- export const DEFAULT_MFE_REGISTRY = 'https://verdaccio.servicetitan.com';