@vendure/dashboard 3.3.6-master-202507110238 → 3.3.6

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 (68) hide show
  1. package/dist/plugin/types.d.ts +40 -0
  2. package/dist/plugin/utils/ast-utils.d.ts +0 -5
  3. package/dist/plugin/utils/ast-utils.js +0 -67
  4. package/dist/plugin/utils/ast-utils.spec.js +1 -76
  5. package/dist/plugin/utils/compiler.d.ts +22 -0
  6. package/dist/plugin/utils/compiler.js +162 -0
  7. package/dist/plugin/utils/config-loader.d.ts +0 -120
  8. package/dist/plugin/utils/config-loader.js +1 -367
  9. package/dist/plugin/utils/logger.d.ts +3 -0
  10. package/dist/plugin/utils/logger.js +39 -0
  11. package/dist/plugin/utils/plugin-discovery.d.ts +27 -0
  12. package/dist/plugin/utils/plugin-discovery.js +343 -0
  13. package/dist/plugin/utils/tsconfig-utils.d.ts +9 -0
  14. package/dist/plugin/utils/tsconfig-utils.js +50 -0
  15. package/dist/plugin/vite-plugin-config-loader.d.ts +3 -3
  16. package/dist/plugin/vite-plugin-config-loader.js +13 -13
  17. package/dist/plugin/vite-plugin-dashboard-metadata.js +19 -2
  18. package/dist/plugin/vite-plugin-vendure-dashboard.d.ts +7 -7
  19. package/dist/plugin/vite-plugin-vendure-dashboard.js +2 -2
  20. package/package.json +134 -131
  21. package/src/app/routes/_authenticated/_orders/components/customer-address-selector.tsx +0 -1
  22. package/src/app/routes/_authenticated/_orders/components/payment-details.tsx +6 -2
  23. package/src/app/routes/_authenticated/_orders/components/state-transition-control.tsx +2 -2
  24. package/src/app/routes/_authenticated/_orders/orders_.draft.$id.tsx +0 -1
  25. package/src/app/routes/_authenticated/_products/components/option-value-input.tsx +1 -1
  26. package/src/app/routes/_authenticated/_zones/components/zone-countries-table.tsx +0 -7
  27. package/src/lib/components/layout/content-language-selector.tsx +1 -1
  28. package/src/lib/components/shared/asset/asset-preview.tsx +0 -6
  29. package/src/lib/components/shared/option-value-input.tsx +1 -1
  30. package/src/lib/components/shared/product-variant-selector.tsx +1 -1
  31. package/src/lib/components/ui/calendar.tsx +1 -1
  32. package/src/lib/framework/dashboard-widget/metrics-widget/index.tsx +1 -1
  33. package/src/lib/framework/dashboard-widget/orders-summary/index.tsx +0 -2
  34. package/src/lib/hooks/use-extended-list-query.ts +32 -30
  35. package/vite/tests/barrel-exports.spec.ts +13 -4
  36. package/{dist/plugin/tests/barrel-exports/my-plugin/src/my.plugin.js → vite/tests/fixtures-npm-plugin/fake_node_modules/test-plugin/index.js} +6 -6
  37. package/vite/tests/fixtures-npm-plugin/fake_node_modules/test-plugin/package.json +8 -0
  38. package/vite/tests/fixtures-npm-plugin/package.json +6 -0
  39. package/{dist/plugin/tests/barrel-exports/vendure-config.js → vite/tests/fixtures-npm-plugin/vendure-config.ts} +5 -6
  40. package/vite/tests/fixtures-path-alias/aliased-plugin/index.ts +1 -0
  41. package/vite/tests/fixtures-path-alias/aliased-plugin/src/aliased.plugin.ts +8 -0
  42. package/vite/tests/fixtures-path-alias/package.json +6 -0
  43. package/vite/tests/fixtures-path-alias/vendure-config.ts +19 -0
  44. package/vite/tests/npm-plugin.spec.ts +46 -0
  45. package/vite/tests/path-alias.spec.ts +33 -0
  46. package/vite/tests/tsconfig.json +11 -0
  47. package/vite/types.ts +44 -0
  48. package/vite/utils/ast-utils.spec.ts +1 -80
  49. package/vite/utils/ast-utils.ts +0 -86
  50. package/vite/utils/compiler.ts +244 -0
  51. package/vite/utils/config-loader.ts +0 -555
  52. package/vite/utils/logger.ts +43 -0
  53. package/vite/utils/plugin-discovery.ts +442 -0
  54. package/vite/utils/tsconfig-utils.ts +79 -0
  55. package/vite/vite-plugin-config-loader.ts +20 -17
  56. package/vite/vite-plugin-dashboard-metadata.ts +26 -7
  57. package/vite/vite-plugin-tailwind-source.ts +2 -2
  58. package/vite/vite-plugin-vendure-dashboard.ts +9 -9
  59. package/dist/plugin/tests/barrel-exports/my-plugin/index.d.ts +0 -1
  60. package/dist/plugin/tests/barrel-exports/my-plugin/index.js +0 -17
  61. package/dist/plugin/tests/barrel-exports/my-plugin/src/my.plugin.d.ts +0 -2
  62. package/dist/plugin/tests/barrel-exports/vendure-config.d.ts +0 -2
  63. package/dist/plugin/tests/barrel-exports.spec.js +0 -14
  64. /package/dist/plugin/{tests/barrel-exports.spec.d.ts → types.js} +0 -0
  65. /package/vite/tests/{barrel-exports → fixtures-barrel-exports}/my-plugin/index.ts +0 -0
  66. /package/vite/tests/{barrel-exports → fixtures-barrel-exports}/my-plugin/src/my.plugin.ts +0 -0
  67. /package/vite/tests/{barrel-exports → fixtures-barrel-exports}/package.json +0 -0
  68. /package/vite/tests/{barrel-exports → fixtures-barrel-exports}/vendure-config.ts +0 -0
@@ -0,0 +1,40 @@
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
+ export interface PathAdapter {
30
+ /**
31
+ * @description
32
+ * A function to determine the path to the compiled Vendure config file.
33
+ */
34
+ getCompiledConfigPath?: GetCompiledConfigPathFn;
35
+ /**
36
+ * If your project makes use of the TypeScript `paths` configuration, the compiler will
37
+ * attempt to use these paths when compiling the Vendure config and its imports.
38
+ */
39
+ transformTsConfigPathMappings?: TransformTsConfigPathMappingsFn;
40
+ }
@@ -1,9 +1,4 @@
1
1
  import ts from 'typescript';
2
- import { PluginInfo } from './config-loader.js';
3
- /**
4
- * Get the plugin info from the source file.
5
- */
6
- export declare function getPluginInfo(sourceFile: ts.SourceFile): PluginInfo | undefined;
7
2
  /**
8
3
  * Given the AST of a TypeScript file, finds the name of the variable exported as VendureConfig.
9
4
  */
@@ -1,53 +1,4 @@
1
- import path from 'path';
2
1
  import ts from 'typescript';
3
- /**
4
- * Get the plugin info from the source file.
5
- */
6
- export function getPluginInfo(sourceFile) {
7
- var _a;
8
- const classDeclaration = sourceFile.statements.find(statement => {
9
- return (statement.kind === ts.SyntaxKind.ClassDeclaration &&
10
- statement.getText().includes('@VendurePlugin('));
11
- });
12
- if (classDeclaration) {
13
- const identifier = classDeclaration.getChildren().find(child => {
14
- return child.kind === ts.SyntaxKind.Identifier;
15
- });
16
- const dashboardEntryPath = (_a = classDeclaration
17
- .getChildren()
18
- .map(child => {
19
- if (child.kind === ts.SyntaxKind.SyntaxList) {
20
- const pluginDecorator = child.getChildren().find(_child => {
21
- return _child.kind === ts.SyntaxKind.Decorator;
22
- });
23
- if (pluginDecorator) {
24
- const callExpression = findFirstDescendantOfKind(pluginDecorator, ts.SyntaxKind.CallExpression);
25
- if (callExpression) {
26
- const objectLiteral = findFirstDescendantOfKind(callExpression, ts.SyntaxKind.ObjectLiteralExpression);
27
- if (objectLiteral && ts.isObjectLiteralExpression(objectLiteral)) {
28
- // Now find the specific 'dashboard' property
29
- const dashboardProperty = objectLiteral.properties.find(prop => { var _a; return ts.isPropertyAssignment(prop) && ((_a = prop.name) === null || _a === void 0 ? void 0 : _a.getText()) === 'dashboard'; });
30
- if (dashboardProperty &&
31
- ts.isPropertyAssignment(dashboardProperty) &&
32
- ts.isStringLiteral(dashboardProperty.initializer)) {
33
- const dashboardPath = dashboardProperty.initializer.text;
34
- return dashboardPath;
35
- }
36
- }
37
- }
38
- }
39
- }
40
- })
41
- .filter(Boolean)) === null || _a === void 0 ? void 0 : _a[0];
42
- if (identifier) {
43
- return {
44
- name: identifier.getText(),
45
- pluginPath: path.dirname(sourceFile.fileName),
46
- dashboardEntryPath,
47
- };
48
- }
49
- }
50
- }
51
2
  /**
52
3
  * Given the AST of a TypeScript file, finds the name of the variable exported as VendureConfig.
53
4
  */
@@ -76,21 +27,3 @@ export function findConfigExport(sourceFile) {
76
27
  visit(sourceFile);
77
28
  return exportedSymbolName;
78
29
  }
79
- function findFirstDescendantOfKind(node, kind) {
80
- let foundNode;
81
- function visit(_node) {
82
- if (foundNode) {
83
- // Stop searching if we already found it
84
- return;
85
- }
86
- if (_node.kind === kind) {
87
- foundNode = _node;
88
- return;
89
- }
90
- // Recursively visit children
91
- ts.forEachChild(_node, visit);
92
- }
93
- // Start the traversal from the initial node's children
94
- ts.forEachChild(node, visit);
95
- return foundNode;
96
- }
@@ -1,81 +1,6 @@
1
1
  import ts from 'typescript';
2
2
  import { describe, expect, it } from 'vitest';
3
- import { findConfigExport, getPluginInfo } from './ast-utils.js';
4
- describe('getPluginInfo', () => {
5
- it('should return undefined when no plugin class is found', () => {
6
- const sourceText = `
7
- class NotAPlugin {
8
- constructor() {}
9
- }
10
- `;
11
- const sourceFile = ts.createSourceFile('path/to/test.ts', sourceText, ts.ScriptTarget.Latest, true);
12
- const result = getPluginInfo(sourceFile);
13
- expect(result).toBeUndefined();
14
- });
15
- it('should return plugin info when a valid plugin class is found', () => {
16
- const sourceText = `
17
- @VendurePlugin({
18
- imports: [],
19
- providers: []
20
- })
21
- class TestPlugin {
22
- constructor() {}
23
- }
24
- `;
25
- const sourceFile = ts.createSourceFile('path/to/test.ts', sourceText, ts.ScriptTarget.Latest, true);
26
- const result = getPluginInfo(sourceFile);
27
- expect(result).toEqual({
28
- name: 'TestPlugin',
29
- pluginPath: 'path/to',
30
- dashboardEntryPath: undefined,
31
- });
32
- });
33
- it('should handle multiple classes but only return the plugin one', () => {
34
- const sourceText = `
35
- class NotAPlugin {
36
- constructor() {}
37
- }
38
-
39
- @VendurePlugin({
40
- imports: [],
41
- providers: []
42
- })
43
- class TestPlugin {
44
- constructor() {}
45
- }
46
-
47
- class AnotherClass {
48
- constructor() {}
49
- }
50
- `;
51
- const sourceFile = ts.createSourceFile('path/to/test.ts', sourceText, ts.ScriptTarget.Latest, true);
52
- const result = getPluginInfo(sourceFile);
53
- expect(result).toEqual({
54
- name: 'TestPlugin',
55
- pluginPath: 'path/to',
56
- dashboardEntryPath: undefined,
57
- });
58
- });
59
- it('should determine the dashboard entry path when it is provided', () => {
60
- const sourceText = `
61
- @VendurePlugin({
62
- imports: [],
63
- providers: [],
64
- dashboard: './dashboard/index.tsx',
65
- })
66
- class TestPlugin {
67
- constructor() {}
68
- }
69
- `;
70
- const sourceFile = ts.createSourceFile('path/to/test.ts', sourceText, ts.ScriptTarget.Latest, true);
71
- const result = getPluginInfo(sourceFile);
72
- expect(result).toEqual({
73
- name: 'TestPlugin',
74
- pluginPath: 'path/to',
75
- dashboardEntryPath: './dashboard/index.tsx',
76
- });
77
- });
78
- });
3
+ import { findConfigExport } from './ast-utils.js';
79
4
  describe('findConfigExport', () => {
80
5
  it('should return undefined when no VendureConfig export is found', () => {
81
6
  const sourceText = `
@@ -0,0 +1,22 @@
1
+ import { VendureConfig } from '@vendure/core';
2
+ import { Logger, PathAdapter, PluginInfo } from '../types.js';
3
+ export interface PackageScannerConfig {
4
+ nodeModulesRoot?: string;
5
+ }
6
+ export interface CompilerOptions {
7
+ vendureConfigPath: string;
8
+ outputPath: string;
9
+ pathAdapter?: PathAdapter;
10
+ logger?: Logger;
11
+ pluginPackageScanner?: PackageScannerConfig;
12
+ }
13
+ export interface CompileResult {
14
+ vendureConfig: VendureConfig;
15
+ exportedSymbolName: string;
16
+ pluginInfo: PluginInfo[];
17
+ }
18
+ /**
19
+ * Compiles TypeScript files and discovers Vendure plugins in both the compiled output
20
+ * and in node_modules.
21
+ */
22
+ export declare function compile(options: CompilerOptions): Promise<CompileResult>;
@@ -0,0 +1,162 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import tsConfigPaths from 'tsconfig-paths';
4
+ import * as ts from 'typescript';
5
+ import { pathToFileURL } from 'url';
6
+ import { findConfigExport } from './ast-utils.js';
7
+ import { noopLogger } from './logger.js';
8
+ import { discoverPlugins } from './plugin-discovery.js';
9
+ import { findTsConfigPaths } from './tsconfig-utils.js';
10
+ const defaultPathAdapter = {
11
+ getCompiledConfigPath: ({ outputPath, configFileName }) => path.join(outputPath, configFileName),
12
+ transformTsConfigPathMappings: ({ patterns }) => patterns,
13
+ };
14
+ /**
15
+ * Compiles TypeScript files and discovers Vendure plugins in both the compiled output
16
+ * and in node_modules.
17
+ */
18
+ export async function compile(options) {
19
+ var _a, _b;
20
+ const { vendureConfigPath, outputPath, pathAdapter, logger = noopLogger, pluginPackageScanner } = options;
21
+ const getCompiledConfigPath = (_a = pathAdapter === null || pathAdapter === void 0 ? void 0 : pathAdapter.getCompiledConfigPath) !== null && _a !== void 0 ? _a : defaultPathAdapter.getCompiledConfigPath;
22
+ const transformTsConfigPathMappings = (_b = pathAdapter === null || pathAdapter === void 0 ? void 0 : pathAdapter.transformTsConfigPathMappings) !== null && _b !== void 0 ? _b : defaultPathAdapter.transformTsConfigPathMappings;
23
+ // 1. Compile TypeScript files
24
+ const compileStart = Date.now();
25
+ await compileTypeScript({
26
+ inputPath: vendureConfigPath,
27
+ outputPath,
28
+ logger,
29
+ transformTsConfigPathMappings,
30
+ });
31
+ logger.info(`TypeScript compilation completed in ${Date.now() - compileStart}ms`);
32
+ // 2. Discover plugins
33
+ const analyzePluginsStart = Date.now();
34
+ const plugins = await discoverPlugins({
35
+ vendureConfigPath,
36
+ transformTsConfigPathMappings,
37
+ logger,
38
+ outputPath,
39
+ pluginPackageScanner,
40
+ });
41
+ logger.info(`Analyzed plugins and found ${plugins.length} dashboard extensions in ${Date.now() - analyzePluginsStart}ms`);
42
+ // 3. Load the compiled config
43
+ const configFileName = path.basename(vendureConfigPath);
44
+ const compiledConfigFilePath = pathToFileURL(getCompiledConfigPath({
45
+ inputRootDir: path.dirname(vendureConfigPath),
46
+ outputPath,
47
+ configFileName,
48
+ })).href.replace(/.ts$/, '.js');
49
+ // Create package.json with type commonjs
50
+ await fs.writeFile(path.join(outputPath, 'package.json'), JSON.stringify({ type: 'commonjs', private: true }, null, 2));
51
+ // Find the exported config symbol
52
+ const sourceFile = ts.createSourceFile(vendureConfigPath, await fs.readFile(vendureConfigPath, 'utf-8'), ts.ScriptTarget.Latest, true);
53
+ const exportedSymbolName = findConfigExport(sourceFile);
54
+ if (!exportedSymbolName) {
55
+ throw new Error(`Could not find a variable exported as VendureConfig. Please specify the name of the exported variable.`);
56
+ }
57
+ const loadConfigStart = Date.now();
58
+ await registerTsConfigPaths({
59
+ outputPath,
60
+ configPath: vendureConfigPath,
61
+ logger,
62
+ phase: 'loading',
63
+ transformTsConfigPathMappings,
64
+ });
65
+ let config;
66
+ try {
67
+ config = await import(compiledConfigFilePath).then(m => m[exportedSymbolName]);
68
+ }
69
+ catch (e) {
70
+ logger.error(`Error loading config: ${e instanceof Error ? e.message : String(e)}`);
71
+ }
72
+ if (!config) {
73
+ throw new Error(`Could not find a variable exported as VendureConfig with the name "${exportedSymbolName}".`);
74
+ }
75
+ logger.debug(`Loaded config in ${Date.now() - loadConfigStart}ms`);
76
+ return { vendureConfig: config, exportedSymbolName, pluginInfo: plugins };
77
+ }
78
+ /**
79
+ * Compiles TypeScript files to JavaScript
80
+ */
81
+ async function compileTypeScript({ inputPath, outputPath, logger, transformTsConfigPathMappings, }) {
82
+ var _a;
83
+ await fs.ensureDir(outputPath);
84
+ // Find tsconfig paths first
85
+ const tsConfigInfo = await findTsConfigPaths(inputPath, logger, 'compiling', transformTsConfigPathMappings);
86
+ const compilerOptions = {
87
+ target: ts.ScriptTarget.ES2020,
88
+ module: ts.ModuleKind.CommonJS,
89
+ moduleResolution: ts.ModuleResolutionKind.Node10, // More explicit CJS resolution
90
+ experimentalDecorators: true,
91
+ emitDecoratorMetadata: true,
92
+ esModuleInterop: true,
93
+ skipLibCheck: true,
94
+ noEmit: false,
95
+ // Speed optimizations
96
+ noEmitOnError: false, // Emit output even if there are errors
97
+ noImplicitAny: false, // Don't require implicit any
98
+ noUnusedLocals: false, // Don't check for unused locals
99
+ noUnusedParameters: false, // Don't check for unused parameters
100
+ allowJs: true,
101
+ checkJs: false, // Don't type check JS files
102
+ skipDefaultLibCheck: true, // Skip checking .d.ts files
103
+ isolatedModules: false, // Need to check cross-file references to compile dependencies
104
+ incremental: false, // Don't use incremental compilation (faster for one-off builds)
105
+ resolveJsonModule: true,
106
+ preserveSymlinks: false,
107
+ outDir: outputPath,
108
+ };
109
+ logger.debug(`Compiling ${inputPath} to ${outputPath} using TypeScript...`);
110
+ // Add path mappings if found
111
+ if (tsConfigInfo) {
112
+ // We need to set baseUrl and paths for TypeScript to resolve the imports
113
+ compilerOptions.baseUrl = tsConfigInfo.baseUrl;
114
+ compilerOptions.paths = tsConfigInfo.paths;
115
+ // This is critical - it tells TypeScript to preserve the paths in the output
116
+ // compilerOptions.rootDir = tsConfigInfo.baseUrl;
117
+ }
118
+ logger.debug(`tsConfig paths: ${JSON.stringify(tsConfigInfo === null || tsConfigInfo === void 0 ? void 0 : tsConfigInfo.paths, null, 2)}`);
119
+ logger.debug(`tsConfig baseUrl: ${(_a = tsConfigInfo === null || tsConfigInfo === void 0 ? void 0 : tsConfigInfo.baseUrl) !== null && _a !== void 0 ? _a : 'UNKNOWN'}`);
120
+ // Create a custom transformer to rewrite the output paths
121
+ const customTransformers = {
122
+ after: [
123
+ context => {
124
+ return sourceFile => {
125
+ // Only transform files that are not the entry point
126
+ if (sourceFile.fileName === inputPath) {
127
+ return sourceFile;
128
+ }
129
+ sourceFile.fileName = path.join(outputPath, path.basename(sourceFile.fileName));
130
+ return sourceFile;
131
+ };
132
+ },
133
+ ],
134
+ };
135
+ const program = ts.createProgram([inputPath], compilerOptions);
136
+ const emitResult = program.emit(undefined, undefined, undefined, undefined, customTransformers);
137
+ // Only log actual emit errors, not type errors
138
+ if (emitResult.emitSkipped) {
139
+ for (const diagnostic of emitResult.diagnostics) {
140
+ if (diagnostic.file && diagnostic.start !== undefined) {
141
+ const { line, character } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
142
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
143
+ logger.warn(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
144
+ }
145
+ else {
146
+ logger.warn(ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'));
147
+ }
148
+ }
149
+ }
150
+ }
151
+ async function registerTsConfigPaths(options) {
152
+ const { outputPath, configPath, logger, phase, transformTsConfigPathMappings } = options;
153
+ const tsConfigInfo = await findTsConfigPaths(configPath, logger, phase, transformTsConfigPathMappings);
154
+ if (tsConfigInfo) {
155
+ const params = {
156
+ baseUrl: outputPath,
157
+ paths: tsConfigInfo.paths,
158
+ };
159
+ logger.debug(`Registering tsconfig paths: ${JSON.stringify(params, null, 2)}`);
160
+ tsConfigPaths.register(params);
161
+ }
162
+ }
@@ -1,121 +1 @@
1
- import { VendureConfig } from '@vendure/core';
2
- type Logger = {
3
- info: (message: string) => void;
4
- warn: (message: string) => void;
5
- debug: (message: string) => void;
6
- };
7
- export type PluginInfo = {
8
- name: string;
9
- pluginPath: string;
10
- dashboardEntryPath: string | undefined;
11
- };
12
- /**
13
- * @description
14
- * The PathAdapter interface allows customization of how paths are handled
15
- * when compiling the Vendure config and its imports.
16
- *
17
- * This is particularly useful in complex project structures, such as monorepos,
18
- * where the Vendure config file may not be in the root directory,
19
- * or when you need to transform TypeScript path mappings.
20
- */
21
- export interface PathAdapter {
22
- /**
23
- * @description
24
- * A function to determine the path to the compiled Vendure config file. The default implementation
25
- * simple joins the output directory with the config file name:
26
- *
27
- * ```ts
28
- * return path.join(outputPath, configFileName)
29
- * ```
30
- *
31
- * However, in some cases with more complex project structures, you may need to
32
- * provide a custom implementation to ensure the compiled config file is
33
- * correctly located.
34
- *
35
- * @example
36
- * ```ts
37
- * getCompiledConfigPath: ({ inputRootDir, outputPath, configFileName }) => {
38
- * const projectName = inputRootDir.split('/libs/')[1].split('/')[0];
39
- * const pathAfterProject = inputRootDir.split(`/libs/${projectName}`)[1];
40
- * const compiledConfigFilePath = `${outputPath}/${projectName}${pathAfterProject}`;
41
- * return path.join(compiledConfigFilePath, configFileName);
42
- * },
43
- * ```
44
- */
45
- getCompiledConfigPath?: (params: {
46
- inputRootDir: string;
47
- outputPath: string;
48
- configFileName: string;
49
- }) => string;
50
- /**
51
- * If your project makes use of the TypeScript `paths` configuration, the compiler will
52
- * attempt to use these paths when compiling the Vendure config and its imports.
53
- *
54
- * In certain cases, you may need to transform these paths before they are used. For instance,
55
- * if your project is a monorepo and the paths are defined relative to the root of the monorepo,
56
- * you may need to adjust them to be relative to the output directory where the compiled files are located.
57
- *
58
- * @example
59
- * ```ts
60
- * transformTsConfigPathMappings: ({ phase, patterns }) => {
61
- * // "loading" phase is when the compiled Vendure code is being loaded by
62
- * // the plugin, in order to introspect the configuration of your app.
63
- * if (phase === 'loading') {
64
- * return patterns.map((p) =>
65
- * p.replace('libs/', '').replace(/.ts$/, '.js'),
66
- * );
67
- * }
68
- * return patterns;
69
- * },
70
- * ```
71
- * @param params
72
- */
73
- transformTsConfigPathMappings?: (params: {
74
- phase: 'compiling' | 'loading';
75
- alias: string;
76
- patterns: string[];
77
- }) => string[];
78
- }
79
- export interface ConfigLoaderOptions {
80
- vendureConfigPath: string;
81
- tempDir: string;
82
- pathAdapter?: PathAdapter;
83
- vendureConfigExport?: string;
84
- logger?: Logger;
85
- reportCompilationErrors?: boolean;
86
- }
87
- export interface LoadVendureConfigResult {
88
- vendureConfig: VendureConfig;
89
- exportedSymbolName: string;
90
- pluginInfo: PluginInfo[];
91
- }
92
- /**
93
- * @description
94
- * This function compiles the given Vendure config file and any imported relative files (i.e.
95
- * project files, not npm packages) into a temporary directory, and returns the compiled config.
96
- *
97
- * The reason we need to do this is that Vendure code makes use of TypeScript experimental decorators
98
- * (e.g. for NestJS decorators and TypeORM column decorators) which are not supported by esbuild.
99
- *
100
- * In Vite, when we load some TypeScript into the top-level Vite config file (in the end-user project), Vite
101
- * internally uses esbuild to temporarily compile that TypeScript code. Unfortunately, esbuild does not support
102
- * these experimental decorators, errors will be thrown as soon as e.g. a TypeORM column decorator is encountered.
103
- *
104
- * To work around this, we compile the Vendure config file and all its imports using the TypeScript compiler,
105
- * which fully supports these experimental decorators. The compiled files are then loaded by Vite, which is able
106
- * to handle the compiled JavaScript output.
107
- */
108
- export declare function loadVendureConfig(options: ConfigLoaderOptions): Promise<LoadVendureConfigResult>;
109
- type CompileFileOptions = {
110
- inputRootDir: string;
111
- inputPath: string;
112
- outputDir: string;
113
- transformTsConfigPathMappings: Required<PathAdapter>['transformTsConfigPathMappings'];
114
- logger?: Logger;
115
- compiledFiles?: Set<string>;
116
- isRoot?: boolean;
117
- pluginInfo?: PluginInfo[];
118
- reportCompilationErrors?: boolean;
119
- };
120
- export declare function compileFile({ inputRootDir, inputPath, outputDir, transformTsConfigPathMappings, logger, compiledFiles, isRoot, pluginInfo, reportCompilationErrors, }: CompileFileOptions): Promise<PluginInfo[]>;
121
1
  export {};