types.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. export type Logger = {
  2. info: (message: string) => void;
  3. warn: (message: string) => void;
  4. debug: (message: string) => void;
  5. error: (message: string) => void;
  6. };
  7. export type PluginInfo = {
  8. name: string;
  9. pluginPath: string;
  10. dashboardEntryPath: string | undefined;
  11. /** The original source path of the plugin, only set for local plugins that are compiled */
  12. sourcePluginPath?: string;
  13. };
  14. export type GetCompiledConfigPathFn = (params: {
  15. inputRootDir: string;
  16. outputPath: string;
  17. configFileName: string;
  18. }) => string;
  19. export type TransformTsConfigPathMappingsFn = (params: {
  20. phase: 'compiling' | 'loading';
  21. alias: string;
  22. patterns: string[];
  23. }) => string[];
  24. /**
  25. * @description
  26. * The PathAdapter interface allows customization of how paths are handled
  27. * when compiling the Vendure config and its imports.
  28. *
  29. * It enables support for more complex repository structures, such as
  30. * monorepos, where the Vendure server configuration file may not
  31. * be located in the root directory of the project.
  32. *
  33. * If you get compilation errors like "Error loading Vendure config: Cannot find module",
  34. * you probably need to provide a custom `pathAdapter` to resolve the paths correctly.
  35. *
  36. * This can take some trial-and-error. Try logging values from the functions to figure out
  37. * the exact settings that you need for your repo setup.
  38. *
  39. * @example
  40. * ```ts
  41. * vendureDashboardPlugin({
  42. * pathAdapter: {
  43. * getCompiledConfigPath: ({ inputRootDir, outputPath, configFileName }) => {
  44. * const projectName = inputRootDir.split('/libs/')[1].split('/')[0];
  45. * const pathAfterProject = inputRootDir.split(`/libs/${projectName}`)[1];
  46. * const compiledConfigFilePath = `${outputPath}/${projectName}${pathAfterProject}`;
  47. * return path.join(compiledConfigFilePath, configFileName);
  48. * },
  49. * transformTsConfigPathMappings: ({ phase, patterns }) => {
  50. * // "loading" phase is when the compiled Vendure code is being loaded by
  51. * // the plugin, in order to introspect the configuration of your app.
  52. * if (phase === 'loading') {
  53. * return patterns.map((p) =>
  54. * p.replace('libs/', '').replace(/.ts$/, '.js'),
  55. * );
  56. * }
  57. * return patterns;
  58. * },
  59. * },
  60. * // ...
  61. * }),
  62. * ```
  63. *
  64. * @docsCategory vite-plugin
  65. * @docsPage vendureDashboardPlugin
  66. * @since 3.4.0
  67. */
  68. export interface PathAdapter {
  69. /**
  70. * @description
  71. * A function to determine the path to the compiled Vendure config file.
  72. */
  73. getCompiledConfigPath?: GetCompiledConfigPathFn;
  74. /**
  75. * If your project makes use of the TypeScript `paths` configuration, the compiler will
  76. * attempt to use these paths when compiling the Vendure config and its imports.
  77. */
  78. transformTsConfigPathMappings?: TransformTsConfigPathMappingsFn;
  79. }