@payloadcms/figma 0.0.1-alpha.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.
- package/LICENSE.md +11 -0
- package/bin/cli.js +4 -0
- package/dist/api/control-plane.d.ts +124 -0
- package/dist/api/control-plane.d.ts.map +1 -0
- package/dist/api/control-plane.js +245 -0
- package/dist/api/control-plane.js.map +1 -0
- package/dist/api/control-plane.spec.d.ts +2 -0
- package/dist/api/control-plane.spec.d.ts.map +1 -0
- package/dist/api/control-plane.spec.js +296 -0
- package/dist/api/control-plane.spec.js.map +1 -0
- package/dist/api/figma-api.d.ts +31 -0
- package/dist/api/figma-api.d.ts.map +1 -0
- package/dist/api/figma-api.js +169 -0
- package/dist/api/figma-api.js.map +1 -0
- package/dist/api/figma-api.spec.d.ts +14 -0
- package/dist/api/figma-api.spec.d.ts.map +1 -0
- package/dist/api/figma-api.spec.js +201 -0
- package/dist/api/figma-api.spec.js.map +1 -0
- package/dist/auth/__tests__/fixtures.d.ts +26 -0
- package/dist/auth/__tests__/fixtures.d.ts.map +1 -0
- package/dist/auth/__tests__/fixtures.js +67 -0
- package/dist/auth/__tests__/fixtures.js.map +1 -0
- package/dist/auth/__tests__/mocks.d.ts +33 -0
- package/dist/auth/__tests__/mocks.d.ts.map +1 -0
- package/dist/auth/__tests__/mocks.js +63 -0
- package/dist/auth/__tests__/mocks.js.map +1 -0
- package/dist/auth/browser.d.ts +31 -0
- package/dist/auth/browser.d.ts.map +1 -0
- package/dist/auth/browser.js +41 -0
- package/dist/auth/browser.js.map +1 -0
- package/dist/auth/callback-server.d.ts +61 -0
- package/dist/auth/callback-server.d.ts.map +1 -0
- package/dist/auth/callback-server.js +168 -0
- package/dist/auth/callback-server.js.map +1 -0
- package/dist/auth/callback-server.spec.d.ts +2 -0
- package/dist/auth/callback-server.spec.d.ts.map +1 -0
- package/dist/auth/callback-server.spec.js +85 -0
- package/dist/auth/callback-server.spec.js.map +1 -0
- package/dist/auth/crypto-utils.d.ts +33 -0
- package/dist/auth/crypto-utils.d.ts.map +1 -0
- package/dist/auth/crypto-utils.js +96 -0
- package/dist/auth/crypto-utils.js.map +1 -0
- package/dist/auth/crypto-utils.spec.d.ts +2 -0
- package/dist/auth/crypto-utils.spec.d.ts.map +1 -0
- package/dist/auth/crypto-utils.spec.js +36 -0
- package/dist/auth/crypto-utils.spec.js.map +1 -0
- package/dist/auth/jwt-validator.d.ts +41 -0
- package/dist/auth/jwt-validator.d.ts.map +1 -0
- package/dist/auth/jwt-validator.js +113 -0
- package/dist/auth/jwt-validator.js.map +1 -0
- package/dist/auth/jwt-validator.spec.d.ts +10 -0
- package/dist/auth/jwt-validator.spec.d.ts.map +1 -0
- package/dist/auth/jwt-validator.spec.js +236 -0
- package/dist/auth/jwt-validator.spec.js.map +1 -0
- package/dist/auth/oauth-flow.d.ts +62 -0
- package/dist/auth/oauth-flow.d.ts.map +1 -0
- package/dist/auth/oauth-flow.js +172 -0
- package/dist/auth/oauth-flow.js.map +1 -0
- package/dist/auth/oauth-flow.spec.d.ts +2 -0
- package/dist/auth/oauth-flow.spec.d.ts.map +1 -0
- package/dist/auth/oauth-flow.spec.js +134 -0
- package/dist/auth/oauth-flow.spec.js.map +1 -0
- package/dist/auth/pages/error.html +85 -0
- package/dist/auth/pages/success.html +74 -0
- package/dist/auth/pkce.d.ts +51 -0
- package/dist/auth/pkce.d.ts.map +1 -0
- package/dist/auth/pkce.js +71 -0
- package/dist/auth/pkce.js.map +1 -0
- package/dist/auth/pkce.spec.d.ts +2 -0
- package/dist/auth/pkce.spec.d.ts.map +1 -0
- package/dist/auth/pkce.spec.js +32 -0
- package/dist/auth/pkce.spec.js.map +1 -0
- package/dist/auth/project-token.d.ts +47 -0
- package/dist/auth/project-token.d.ts.map +1 -0
- package/dist/auth/project-token.js +134 -0
- package/dist/auth/project-token.js.map +1 -0
- package/dist/auth/project-token.spec.d.ts +2 -0
- package/dist/auth/project-token.spec.d.ts.map +1 -0
- package/dist/auth/project-token.spec.js +332 -0
- package/dist/auth/project-token.spec.js.map +1 -0
- package/dist/auth/refresh.d.ts +35 -0
- package/dist/auth/refresh.d.ts.map +1 -0
- package/dist/auth/refresh.js +149 -0
- package/dist/auth/refresh.js.map +1 -0
- package/dist/auth/refresh.spec.d.ts +2 -0
- package/dist/auth/refresh.spec.d.ts.map +1 -0
- package/dist/auth/refresh.spec.js +105 -0
- package/dist/auth/refresh.spec.js.map +1 -0
- package/dist/auth/token-store.d.ts +110 -0
- package/dist/auth/token-store.d.ts.map +1 -0
- package/dist/auth/token-store.js +188 -0
- package/dist/auth/token-store.js.map +1 -0
- package/dist/auth/token-store.spec.d.ts +2 -0
- package/dist/auth/token-store.spec.d.ts.map +1 -0
- package/dist/auth/token-store.spec.js +276 -0
- package/dist/auth/token-store.spec.js.map +1 -0
- package/dist/auth/types.d.ts +197 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +6 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/cli.d.ts +5 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +108 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/__tests__/test-utils.d.ts +28 -0
- package/dist/commands/__tests__/test-utils.d.ts.map +1 -0
- package/dist/commands/__tests__/test-utils.js +34 -0
- package/dist/commands/__tests__/test-utils.js.map +1 -0
- package/dist/commands/deploy.d.ts +16 -0
- package/dist/commands/deploy.d.ts.map +1 -0
- package/dist/commands/deploy.js +297 -0
- package/dist/commands/deploy.js.map +1 -0
- package/dist/commands/deploy.spec.d.ts +2 -0
- package/dist/commands/deploy.spec.d.ts.map +1 -0
- package/dist/commands/deploy.spec.js +18 -0
- package/dist/commands/deploy.spec.js.map +1 -0
- package/dist/commands/init.d.ts +30 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +410 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/init.spec.d.ts +2 -0
- package/dist/commands/init.spec.d.ts.map +1 -0
- package/dist/commands/init.spec.js +283 -0
- package/dist/commands/init.spec.js.map +1 -0
- package/dist/commands/list-tokens.d.ts +16 -0
- package/dist/commands/list-tokens.d.ts.map +1 -0
- package/dist/commands/list-tokens.js +44 -0
- package/dist/commands/list-tokens.js.map +1 -0
- package/dist/commands/login.d.ts +17 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +69 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +16 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +43 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/config/oauth.d.ts +19 -0
- package/dist/config/oauth.d.ts.map +1 -0
- package/dist/config/oauth.js +43 -0
- package/dist/config/oauth.js.map +1 -0
- package/dist/constants.d.ts +27 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +27 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin/adapter.d.ts +5 -0
- package/dist/plugin/adapter.d.ts.map +1 -0
- package/dist/plugin/adapter.js +139 -0
- package/dist/plugin/adapter.js.map +1 -0
- package/dist/plugin/build-config.d.ts +37 -0
- package/dist/plugin/build-config.d.ts.map +1 -0
- package/dist/plugin/build-config.js +25 -0
- package/dist/plugin/build-config.js.map +1 -0
- package/dist/plugin/build-config.spec.d.ts +2 -0
- package/dist/plugin/build-config.spec.d.ts.map +1 -0
- package/dist/plugin/build-config.spec.js +72 -0
- package/dist/plugin/build-config.spec.js.map +1 -0
- package/dist/types/config.d.ts +45 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +9 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types.d.ts +60 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/asset-collection.d.ts +30 -0
- package/dist/utils/asset-collection.d.ts.map +1 -0
- package/dist/utils/asset-collection.js +117 -0
- package/dist/utils/asset-collection.js.map +1 -0
- package/dist/utils/asset-collection.spec.d.ts +2 -0
- package/dist/utils/asset-collection.spec.d.ts.map +1 -0
- package/dist/utils/asset-collection.spec.js +155 -0
- package/dist/utils/asset-collection.spec.js.map +1 -0
- package/dist/utils/build-detection.d.ts +32 -0
- package/dist/utils/build-detection.d.ts.map +1 -0
- package/dist/utils/build-detection.js +55 -0
- package/dist/utils/build-detection.js.map +1 -0
- package/dist/utils/build-detection.spec.d.ts +2 -0
- package/dist/utils/build-detection.spec.d.ts.map +1 -0
- package/dist/utils/build-detection.spec.js +110 -0
- package/dist/utils/build-detection.spec.js.map +1 -0
- package/dist/utils/config.d.ts +33 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +78 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/config.spec.d.ts +2 -0
- package/dist/utils/config.spec.d.ts.map +1 -0
- package/dist/utils/config.spec.js +167 -0
- package/dist/utils/config.spec.js.map +1 -0
- package/dist/utils/download-template.d.ts +15 -0
- package/dist/utils/download-template.d.ts.map +1 -0
- package/dist/utils/download-template.js +74 -0
- package/dist/utils/download-template.js.map +1 -0
- package/dist/utils/download-template.spec.d.ts +2 -0
- package/dist/utils/download-template.spec.d.ts.map +1 -0
- package/dist/utils/download-template.spec.js +76 -0
- package/dist/utils/download-template.spec.js.map +1 -0
- package/dist/utils/env-management.d.ts +16 -0
- package/dist/utils/env-management.d.ts.map +1 -0
- package/dist/utils/env-management.js +98 -0
- package/dist/utils/env-management.js.map +1 -0
- package/dist/utils/env-management.spec.d.ts +2 -0
- package/dist/utils/env-management.spec.d.ts.map +1 -0
- package/dist/utils/env-management.spec.js +123 -0
- package/dist/utils/env-management.spec.js.map +1 -0
- package/dist/utils/format.d.ts +23 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +49 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/formatter.d.ts +11 -0
- package/dist/utils/formatter.d.ts.map +1 -0
- package/dist/utils/formatter.js +47 -0
- package/dist/utils/formatter.js.map +1 -0
- package/dist/utils/git.d.ts +15 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +92 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/git.spec.d.ts +2 -0
- package/dist/utils/git.spec.d.ts.map +1 -0
- package/dist/utils/git.spec.js +99 -0
- package/dist/utils/git.spec.js.map +1 -0
- package/dist/utils/is-debug.d.ts +6 -0
- package/dist/utils/is-debug.d.ts.map +1 -0
- package/dist/utils/is-debug.js +8 -0
- package/dist/utils/is-debug.js.map +1 -0
- package/dist/utils/lambda-config.d.ts +7 -0
- package/dist/utils/lambda-config.d.ts.map +1 -0
- package/dist/utils/lambda-config.js +144 -0
- package/dist/utils/lambda-config.js.map +1 -0
- package/dist/utils/lambda-config.spec.d.ts +2 -0
- package/dist/utils/lambda-config.spec.d.ts.map +1 -0
- package/dist/utils/lambda-config.spec.js +141 -0
- package/dist/utils/lambda-config.spec.js.map +1 -0
- package/dist/utils/log.d.ts +6 -0
- package/dist/utils/log.d.ts.map +1 -0
- package/dist/utils/log.js +22 -0
- package/dist/utils/log.js.map +1 -0
- package/dist/utils/messages.d.ts +10 -0
- package/dist/utils/messages.d.ts.map +1 -0
- package/dist/utils/messages.js +96 -0
- package/dist/utils/messages.js.map +1 -0
- package/dist/utils/package-manager.d.ts +12 -0
- package/dist/utils/package-manager.d.ts.map +1 -0
- package/dist/utils/package-manager.js +37 -0
- package/dist/utils/package-manager.js.map +1 -0
- package/dist/utils/payload-config-ast.d.ts +30 -0
- package/dist/utils/payload-config-ast.d.ts.map +1 -0
- package/dist/utils/payload-config-ast.js +259 -0
- package/dist/utils/payload-config-ast.js.map +1 -0
- package/dist/utils/payload-config-ast.spec.d.ts +2 -0
- package/dist/utils/payload-config-ast.spec.d.ts.map +1 -0
- package/dist/utils/payload-config-ast.spec.js +303 -0
- package/dist/utils/payload-config-ast.spec.js.map +1 -0
- package/dist/utils/payload-config-finder.d.ts +9 -0
- package/dist/utils/payload-config-finder.d.ts.map +1 -0
- package/dist/utils/payload-config-finder.js +26 -0
- package/dist/utils/payload-config-finder.js.map +1 -0
- package/dist/utils/payload-config-modifier.d.ts +18 -0
- package/dist/utils/payload-config-modifier.d.ts.map +1 -0
- package/dist/utils/payload-config-modifier.int.spec.d.ts +2 -0
- package/dist/utils/payload-config-modifier.int.spec.d.ts.map +1 -0
- package/dist/utils/payload-config-modifier.int.spec.js +116 -0
- package/dist/utils/payload-config-modifier.int.spec.js.map +1 -0
- package/dist/utils/payload-config-modifier.js +232 -0
- package/dist/utils/payload-config-modifier.js.map +1 -0
- package/dist/utils/payload-config-modifier.spec.d.ts +2 -0
- package/dist/utils/payload-config-modifier.spec.d.ts.map +1 -0
- package/dist/utils/payload-config-modifier.spec.js +162 -0
- package/dist/utils/payload-config-modifier.spec.js.map +1 -0
- package/dist/utils/payload-package-check.d.ts +15 -0
- package/dist/utils/payload-package-check.d.ts.map +1 -0
- package/dist/utils/payload-package-check.js +116 -0
- package/dist/utils/payload-package-check.js.map +1 -0
- package/dist/utils/payload-package-check.spec.d.ts +2 -0
- package/dist/utils/payload-package-check.spec.d.ts.map +1 -0
- package/dist/utils/payload-package-check.spec.js +148 -0
- package/dist/utils/payload-package-check.spec.js.map +1 -0
- package/dist/utils/project.d.ts +58 -0
- package/dist/utils/project.d.ts.map +1 -0
- package/dist/utils/project.js +252 -0
- package/dist/utils/project.js.map +1 -0
- package/dist/utils/project.spec.d.ts +2 -0
- package/dist/utils/project.spec.d.ts.map +1 -0
- package/dist/utils/project.spec.js +222 -0
- package/dist/utils/project.spec.js.map +1 -0
- package/dist/utils/s3-upload.d.ts +43 -0
- package/dist/utils/s3-upload.d.ts.map +1 -0
- package/dist/utils/s3-upload.js +128 -0
- package/dist/utils/s3-upload.js.map +1 -0
- package/dist/utils/s3-upload.spec.d.ts +2 -0
- package/dist/utils/s3-upload.spec.d.ts.map +1 -0
- package/dist/utils/s3-upload.spec.js +140 -0
- package/dist/utils/s3-upload.spec.js.map +1 -0
- package/dist/utils/token-display.d.ts +14 -0
- package/dist/utils/token-display.d.ts.map +1 -0
- package/dist/utils/token-display.js +62 -0
- package/dist/utils/token-display.js.map +1 -0
- package/dist/utils/typescript-validator.d.ts +11 -0
- package/dist/utils/typescript-validator.d.ts.map +1 -0
- package/dist/utils/typescript-validator.js +58 -0
- package/dist/utils/typescript-validator.js.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload-config-finder.d.ts","sourceRoot":"","sources":["../../src/utils/payload-config-finder.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,CAmBnF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { findConfig } from 'payload/node';
|
|
2
|
+
/**
|
|
3
|
+
* Find the Payload config file using Payload's built-in finder
|
|
4
|
+
* Changes to project directory temporarily and restores afterward
|
|
5
|
+
*
|
|
6
|
+
* @param projectPath - Absolute path to project directory
|
|
7
|
+
* @returns Absolute path to config file, or null if not found
|
|
8
|
+
*/ export async function findPayloadConfig(projectPath) {
|
|
9
|
+
const originalCwd = process.cwd();
|
|
10
|
+
try {
|
|
11
|
+
// findConfig requires being in the project directory
|
|
12
|
+
process.chdir(projectPath);
|
|
13
|
+
// Use Payload's official config finder
|
|
14
|
+
const configPath = findConfig();
|
|
15
|
+
// Wrap in Promise.resolve to satisfy async requirement
|
|
16
|
+
return await Promise.resolve(configPath || null);
|
|
17
|
+
} catch {
|
|
18
|
+
// Config not found or error occurred
|
|
19
|
+
return null;
|
|
20
|
+
} finally{
|
|
21
|
+
// Always restore original working directory
|
|
22
|
+
process.chdir(originalCwd);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=payload-config-finder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/payload-config-finder.ts"],"sourcesContent":["import { findConfig } from 'payload/node'\n\n/**\n * Find the Payload config file using Payload's built-in finder\n * Changes to project directory temporarily and restores afterward\n *\n * @param projectPath - Absolute path to project directory\n * @returns Absolute path to config file, or null if not found\n */\nexport async function findPayloadConfig(projectPath: string): Promise<null | string> {\n const originalCwd = process.cwd()\n\n try {\n // findConfig requires being in the project directory\n process.chdir(projectPath)\n\n // Use Payload's official config finder\n const configPath = findConfig()\n\n // Wrap in Promise.resolve to satisfy async requirement\n return await Promise.resolve(configPath || null)\n } catch {\n // Config not found or error occurred\n return null\n } finally {\n // Always restore original working directory\n process.chdir(originalCwd)\n }\n}\n"],"names":["findConfig","findPayloadConfig","projectPath","originalCwd","process","cwd","chdir","configPath","Promise","resolve"],"mappings":"AAAA,SAASA,UAAU,QAAQ,eAAc;AAEzC;;;;;;CAMC,GACD,OAAO,eAAeC,kBAAkBC,WAAmB;IACzD,MAAMC,cAAcC,QAAQC,GAAG;IAE/B,IAAI;QACF,qDAAqD;QACrDD,QAAQE,KAAK,CAACJ;QAEd,uCAAuC;QACvC,MAAMK,aAAaP;QAEnB,uDAAuD;QACvD,OAAO,MAAMQ,QAAQC,OAAO,CAACF,cAAc;IAC7C,EAAE,OAAM;QACN,qCAAqC;QACrC,OAAO;IACT,SAAU;QACR,4CAA4C;QAC5CH,QAAQE,KAAK,CAACH;IAChB;AACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { PackageManager } from './package-manager.js';
|
|
2
|
+
export type ModificationResult = {
|
|
3
|
+
changes: string[];
|
|
4
|
+
error?: string;
|
|
5
|
+
modified: boolean;
|
|
6
|
+
success: boolean;
|
|
7
|
+
warnings?: string[];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Main orchestrator for payload config modification
|
|
11
|
+
* Checks package, detects needed changes, applies modifications
|
|
12
|
+
*/
|
|
13
|
+
export declare function ensurePayloadFigmaConfig(projectPath: string, packageManager: PackageManager): Promise<ModificationResult>;
|
|
14
|
+
/**
|
|
15
|
+
* Display manual configuration instructions
|
|
16
|
+
*/
|
|
17
|
+
export declare function displayManualInstructions(reason: string): void;
|
|
18
|
+
//# sourceMappingURL=payload-config-modifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload-config-modifier.d.ts","sourceRoot":"","sources":["../../src/utils/payload-config-modifier.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAU1D,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,OAAO,CAAA;IACjB,OAAO,EAAE,OAAO,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CACpB,CAAA;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,kBAAkB,CAAC,CAgN7B;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAwC9D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload-config-modifier.int.spec.d.ts","sourceRoot":"","sources":["../../src/utils/payload-config-modifier.int.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { Project } from 'ts-morph';
|
|
4
|
+
import { beforeEach, describe, expect, it } from 'vitest';
|
|
5
|
+
import { applyModifications, detectRequiredChanges } from './payload-config-ast.js';
|
|
6
|
+
describe('payload-config-modifier - integration tests', ()=>{
|
|
7
|
+
const fixturesDir = path.join(process.cwd(), 'test/fixtures/payload-configs');
|
|
8
|
+
let project;
|
|
9
|
+
beforeEach(()=>{
|
|
10
|
+
project = new Project({
|
|
11
|
+
useInMemoryFileSystem: false
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
it('should handle minimal config correctly', async ()=>{
|
|
15
|
+
const fixturePath = path.join(fixturesDir, 'minimal.ts');
|
|
16
|
+
const content = await fs.readFile(fixturePath, 'utf-8');
|
|
17
|
+
const sourceFile = project.createSourceFile('test-minimal.ts', content);
|
|
18
|
+
const detection = detectRequiredChanges(sourceFile);
|
|
19
|
+
expect(detection.needsImportChange).toBe(true);
|
|
20
|
+
expect(detection.dbProperty).toBeDefined();
|
|
21
|
+
expect(detection.secretProperty).toBe(true);
|
|
22
|
+
expect(detection.editorProperty?.isDefault).toBe(true);
|
|
23
|
+
const { changes, modified } = applyModifications(sourceFile, detection);
|
|
24
|
+
expect(modified).toBe(true);
|
|
25
|
+
expect(changes).toContain('Removed db property');
|
|
26
|
+
expect(changes).toContain('Removed secret property');
|
|
27
|
+
expect(changes).toContain('Removed default editor property');
|
|
28
|
+
expect(changes).toContain('Changed buildConfig import to @payloadcms/figma');
|
|
29
|
+
// Verify final state
|
|
30
|
+
const finalText = sourceFile.getFullText();
|
|
31
|
+
expect(finalText).toContain("from '@payloadcms/figma'");
|
|
32
|
+
expect(finalText).not.toContain('db:');
|
|
33
|
+
expect(finalText).not.toContain('secret:');
|
|
34
|
+
expect(finalText).not.toContain('editor:');
|
|
35
|
+
});
|
|
36
|
+
it('should skip already-figma config', async ()=>{
|
|
37
|
+
const fixturePath = path.join(fixturesDir, 'already-figma.ts');
|
|
38
|
+
const content = await fs.readFile(fixturePath, 'utf-8');
|
|
39
|
+
const sourceFile = project.createSourceFile('test-already-figma.ts', content);
|
|
40
|
+
const detection = detectRequiredChanges(sourceFile);
|
|
41
|
+
expect(detection.needsImportChange).toBe(false);
|
|
42
|
+
const { modified } = applyModifications(sourceFile, detection);
|
|
43
|
+
expect(modified).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
it('should preserve other payload imports', async ()=>{
|
|
46
|
+
const fixturePath = path.join(fixturesDir, 'with-other-imports.ts');
|
|
47
|
+
const content = await fs.readFile(fixturePath, 'utf-8');
|
|
48
|
+
const sourceFile = project.createSourceFile('test-with-other-imports.ts', content);
|
|
49
|
+
const detection = detectRequiredChanges(sourceFile);
|
|
50
|
+
expect(detection.needsImportChange).toBe(true);
|
|
51
|
+
expect(detection.hasOtherPayloadImports).toBe(true);
|
|
52
|
+
const { changes, modified } = applyModifications(sourceFile, detection);
|
|
53
|
+
expect(modified).toBe(true);
|
|
54
|
+
expect(changes).toContain('Split buildConfig import to @payloadcms/figma');
|
|
55
|
+
const finalText = sourceFile.getFullText();
|
|
56
|
+
expect(finalText).toContain("import { CollectionConfig } from 'payload'");
|
|
57
|
+
// ts-morph uses double quotes for new imports
|
|
58
|
+
expect(finalText).toContain('import { buildConfig } from "@payloadcms/figma"');
|
|
59
|
+
});
|
|
60
|
+
it('should preserve custom editor config', async ()=>{
|
|
61
|
+
const fixturePath = path.join(fixturesDir, 'custom-editor.ts');
|
|
62
|
+
const content = await fs.readFile(fixturePath, 'utf-8');
|
|
63
|
+
const sourceFile = project.createSourceFile('test-custom-editor.ts', content);
|
|
64
|
+
const detection = detectRequiredChanges(sourceFile);
|
|
65
|
+
expect(detection.editorProperty?.isDefault).toBe(false);
|
|
66
|
+
applyModifications(sourceFile, detection);
|
|
67
|
+
const finalText = sourceFile.getFullText();
|
|
68
|
+
expect(finalText).toContain('editor:');
|
|
69
|
+
expect(finalText).toContain('lexicalEditor');
|
|
70
|
+
});
|
|
71
|
+
it('should handle postgres adapter', async ()=>{
|
|
72
|
+
const fixturePath = path.join(fixturesDir, 'postgres-adapter.ts');
|
|
73
|
+
const content = await fs.readFile(fixturePath, 'utf-8');
|
|
74
|
+
const sourceFile = project.createSourceFile('test-postgres.ts', content);
|
|
75
|
+
const detection = detectRequiredChanges(sourceFile);
|
|
76
|
+
expect(detection.dbProperty?.adapter).toBe('postgresAdapter');
|
|
77
|
+
expect(detection.dbProperty?.importSource).toBe('@payloadcms/db-postgres');
|
|
78
|
+
const { changes, modified } = applyModifications(sourceFile, detection);
|
|
79
|
+
expect(modified).toBe(true);
|
|
80
|
+
expect(changes).toContain('Removed postgresAdapter import');
|
|
81
|
+
const finalText = sourceFile.getFullText();
|
|
82
|
+
expect(finalText).not.toContain('@payloadcms/db-postgres');
|
|
83
|
+
});
|
|
84
|
+
it('should fail gracefully on alias', async ()=>{
|
|
85
|
+
const fixturePath = path.join(fixturesDir, 'with-alias.ts');
|
|
86
|
+
const content = await fs.readFile(fixturePath, 'utf-8');
|
|
87
|
+
const sourceFile = project.createSourceFile('test-alias.ts', content);
|
|
88
|
+
const detection = detectRequiredChanges(sourceFile);
|
|
89
|
+
expect(detection.hasAlias).toBe(true);
|
|
90
|
+
const { modified } = applyModifications(sourceFile, detection);
|
|
91
|
+
expect(modified).toBe(false);
|
|
92
|
+
});
|
|
93
|
+
it('should fail gracefully on missing buildConfig call', async ()=>{
|
|
94
|
+
const fixturePath = path.join(fixturesDir, 'no-buildconfig.ts');
|
|
95
|
+
const content = await fs.readFile(fixturePath, 'utf-8');
|
|
96
|
+
const sourceFile = project.createSourceFile('test-no-buildconfig.ts', content);
|
|
97
|
+
const detection = detectRequiredChanges(sourceFile);
|
|
98
|
+
expect(detection.buildConfigNotFound).toBe(true);
|
|
99
|
+
const { modified } = applyModifications(sourceFile, detection);
|
|
100
|
+
expect(modified).toBe(false);
|
|
101
|
+
});
|
|
102
|
+
it('should handle syntax errors gracefully', async ()=>{
|
|
103
|
+
const fixturePath = path.join(fixturesDir, 'syntax-error.ts');
|
|
104
|
+
const content = await fs.readFile(fixturePath, 'utf-8');
|
|
105
|
+
// ts-morph parses as much as it can, even with syntax errors
|
|
106
|
+
// It doesn't throw, but the AST may be incomplete
|
|
107
|
+
const sourceFile = project.createSourceFile('test-syntax-error.ts', content);
|
|
108
|
+
// Detection should handle incomplete AST gracefully
|
|
109
|
+
const detection = detectRequiredChanges(sourceFile);
|
|
110
|
+
// With syntax errors, detection may fail to find buildConfig properly
|
|
111
|
+
// The code should not crash
|
|
112
|
+
expect(()=>applyModifications(sourceFile, detection)).not.toThrow();
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
//# sourceMappingURL=payload-config-modifier.int.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/payload-config-modifier.int.spec.ts"],"sourcesContent":["import fs from 'fs/promises'\nimport path from 'path'\nimport { Project } from 'ts-morph'\nimport { beforeEach, describe, expect, it } from 'vitest'\n\nimport { applyModifications, detectRequiredChanges } from './payload-config-ast.js'\n\ndescribe('payload-config-modifier - integration tests', () => {\n const fixturesDir = path.join(process.cwd(), 'test/fixtures/payload-configs')\n let project: Project\n\n beforeEach(() => {\n project = new Project({ useInMemoryFileSystem: false })\n })\n\n it('should handle minimal config correctly', async () => {\n const fixturePath = path.join(fixturesDir, 'minimal.ts')\n const content = await fs.readFile(fixturePath, 'utf-8')\n\n const sourceFile = project.createSourceFile('test-minimal.ts', content)\n\n const detection = detectRequiredChanges(sourceFile)\n expect(detection.needsImportChange).toBe(true)\n expect(detection.dbProperty).toBeDefined()\n expect(detection.secretProperty).toBe(true)\n expect(detection.editorProperty?.isDefault).toBe(true)\n\n const { changes, modified } = applyModifications(sourceFile, detection)\n expect(modified).toBe(true)\n expect(changes).toContain('Removed db property')\n expect(changes).toContain('Removed secret property')\n expect(changes).toContain('Removed default editor property')\n expect(changes).toContain('Changed buildConfig import to @payloadcms/figma')\n\n // Verify final state\n const finalText = sourceFile.getFullText()\n expect(finalText).toContain(\"from '@payloadcms/figma'\")\n expect(finalText).not.toContain('db:')\n expect(finalText).not.toContain('secret:')\n expect(finalText).not.toContain('editor:')\n })\n\n it('should skip already-figma config', async () => {\n const fixturePath = path.join(fixturesDir, 'already-figma.ts')\n const content = await fs.readFile(fixturePath, 'utf-8')\n\n const sourceFile = project.createSourceFile('test-already-figma.ts', content)\n\n const detection = detectRequiredChanges(sourceFile)\n expect(detection.needsImportChange).toBe(false)\n\n const { modified } = applyModifications(sourceFile, detection)\n expect(modified).toBe(false)\n })\n\n it('should preserve other payload imports', async () => {\n const fixturePath = path.join(fixturesDir, 'with-other-imports.ts')\n const content = await fs.readFile(fixturePath, 'utf-8')\n\n const sourceFile = project.createSourceFile('test-with-other-imports.ts', content)\n\n const detection = detectRequiredChanges(sourceFile)\n expect(detection.needsImportChange).toBe(true)\n expect(detection.hasOtherPayloadImports).toBe(true)\n\n const { changes, modified } = applyModifications(sourceFile, detection)\n expect(modified).toBe(true)\n expect(changes).toContain('Split buildConfig import to @payloadcms/figma')\n\n const finalText = sourceFile.getFullText()\n expect(finalText).toContain(\"import { CollectionConfig } from 'payload'\")\n // ts-morph uses double quotes for new imports\n expect(finalText).toContain('import { buildConfig } from \"@payloadcms/figma\"')\n })\n\n it('should preserve custom editor config', async () => {\n const fixturePath = path.join(fixturesDir, 'custom-editor.ts')\n const content = await fs.readFile(fixturePath, 'utf-8')\n\n const sourceFile = project.createSourceFile('test-custom-editor.ts', content)\n\n const detection = detectRequiredChanges(sourceFile)\n expect(detection.editorProperty?.isDefault).toBe(false)\n\n applyModifications(sourceFile, detection)\n\n const finalText = sourceFile.getFullText()\n expect(finalText).toContain('editor:')\n expect(finalText).toContain('lexicalEditor')\n })\n\n it('should handle postgres adapter', async () => {\n const fixturePath = path.join(fixturesDir, 'postgres-adapter.ts')\n const content = await fs.readFile(fixturePath, 'utf-8')\n\n const sourceFile = project.createSourceFile('test-postgres.ts', content)\n\n const detection = detectRequiredChanges(sourceFile)\n expect(detection.dbProperty?.adapter).toBe('postgresAdapter')\n expect(detection.dbProperty?.importSource).toBe('@payloadcms/db-postgres')\n\n const { changes, modified } = applyModifications(sourceFile, detection)\n expect(modified).toBe(true)\n expect(changes).toContain('Removed postgresAdapter import')\n\n const finalText = sourceFile.getFullText()\n expect(finalText).not.toContain('@payloadcms/db-postgres')\n })\n\n it('should fail gracefully on alias', async () => {\n const fixturePath = path.join(fixturesDir, 'with-alias.ts')\n const content = await fs.readFile(fixturePath, 'utf-8')\n\n const sourceFile = project.createSourceFile('test-alias.ts', content)\n\n const detection = detectRequiredChanges(sourceFile)\n expect(detection.hasAlias).toBe(true)\n\n const { modified } = applyModifications(sourceFile, detection)\n expect(modified).toBe(false)\n })\n\n it('should fail gracefully on missing buildConfig call', async () => {\n const fixturePath = path.join(fixturesDir, 'no-buildconfig.ts')\n const content = await fs.readFile(fixturePath, 'utf-8')\n\n const sourceFile = project.createSourceFile('test-no-buildconfig.ts', content)\n\n const detection = detectRequiredChanges(sourceFile)\n expect(detection.buildConfigNotFound).toBe(true)\n\n const { modified } = applyModifications(sourceFile, detection)\n expect(modified).toBe(false)\n })\n\n it('should handle syntax errors gracefully', async () => {\n const fixturePath = path.join(fixturesDir, 'syntax-error.ts')\n const content = await fs.readFile(fixturePath, 'utf-8')\n\n // ts-morph parses as much as it can, even with syntax errors\n // It doesn't throw, but the AST may be incomplete\n const sourceFile = project.createSourceFile('test-syntax-error.ts', content)\n\n // Detection should handle incomplete AST gracefully\n const detection = detectRequiredChanges(sourceFile)\n\n // With syntax errors, detection may fail to find buildConfig properly\n // The code should not crash\n expect(() => applyModifications(sourceFile, detection)).not.toThrow()\n })\n})\n"],"names":["fs","path","Project","beforeEach","describe","expect","it","applyModifications","detectRequiredChanges","fixturesDir","join","process","cwd","project","useInMemoryFileSystem","fixturePath","content","readFile","sourceFile","createSourceFile","detection","needsImportChange","toBe","dbProperty","toBeDefined","secretProperty","editorProperty","isDefault","changes","modified","toContain","finalText","getFullText","not","hasOtherPayloadImports","adapter","importSource","hasAlias","buildConfigNotFound","toThrow"],"mappings":"AAAA,OAAOA,QAAQ,cAAa;AAC5B,OAAOC,UAAU,OAAM;AACvB,SAASC,OAAO,QAAQ,WAAU;AAClC,SAASC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;A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pDf,OAAOwB,UAAUP,IAAI,CAAC;IACxB;IAEAhB,GAAG,0CAA0C;QAC3C,MAAMS,cAAcd,KAAKS,IAAI,CAACD,aAAa;QAC3C,MAAMO,UAAU,MAAMhB,GAAGiB,QAAQ,CAACF,aAAa;QAE/C,6DAA6D;QAC7D,kDAAkD;QAClD,MAAMG,aAAaL,QAAQM,gBAAgB,CAAC,wBAAwBH;QAEpE,oDAAoD;QACpD,MAAMI,YAAYZ,sBAAsBU;QAExC,sEAAsE;QACtE,4BAA4B;QAC5Bb,OAAO,IAAME,mBAAmBW,YAAYE,YAAYa,GAAG,CAACM,OAAO;IACrE;AACF"}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import pc from 'picocolors';
|
|
2
|
+
import { Project } from 'ts-morph';
|
|
3
|
+
import { formatFile } from './formatter.js';
|
|
4
|
+
import { isDebug } from './is-debug.js';
|
|
5
|
+
import * as log from './log.js';
|
|
6
|
+
import { applyModifications, detectRequiredChanges } from './payload-config-ast.js';
|
|
7
|
+
import { findPayloadConfig } from './payload-config-finder.js';
|
|
8
|
+
import { checkPackageInstalled, installPackage, uninstallPackage } from './payload-package-check.js';
|
|
9
|
+
import { runTypeScriptCheck } from './typescript-validator.js';
|
|
10
|
+
/**
|
|
11
|
+
* Main orchestrator for payload config modification
|
|
12
|
+
* Checks package, detects needed changes, applies modifications
|
|
13
|
+
*/ export async function ensurePayloadFigmaConfig(projectPath, packageManager) {
|
|
14
|
+
const changes = [];
|
|
15
|
+
const warnings = [];
|
|
16
|
+
let modified = false;
|
|
17
|
+
try {
|
|
18
|
+
if (isDebug()) {
|
|
19
|
+
log.debug(`Starting payload config modification for: ${projectPath}`);
|
|
20
|
+
}
|
|
21
|
+
// 1. Find config file
|
|
22
|
+
const configPath = await findPayloadConfig(projectPath);
|
|
23
|
+
if (!configPath) {
|
|
24
|
+
if (isDebug()) {
|
|
25
|
+
log.debug(`Config file not found in: ${projectPath}`);
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
changes: [],
|
|
29
|
+
error: 'payload.config.ts not found in project',
|
|
30
|
+
modified: false,
|
|
31
|
+
success: false
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (isDebug()) {
|
|
35
|
+
log.debug(`Found config file: ${configPath}`);
|
|
36
|
+
}
|
|
37
|
+
// 2. Check/install @payloadcms/figma package
|
|
38
|
+
const isInstalled = await checkPackageInstalled(projectPath, '@payloadcms/figma');
|
|
39
|
+
if (!isInstalled) {
|
|
40
|
+
if (isDebug()) {
|
|
41
|
+
log.debug('@payloadcms/figma not installed, attempting installation...');
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
await installPackage(projectPath, '@payloadcms/figma', packageManager);
|
|
45
|
+
changes.push('Installed @payloadcms/figma');
|
|
46
|
+
modified = true;
|
|
47
|
+
if (isDebug()) {
|
|
48
|
+
log.debug('@payloadcms/figma installed successfully');
|
|
49
|
+
}
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (isDebug()) {
|
|
52
|
+
log.debug(`Failed to install @payloadcms/figma: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
changes: [],
|
|
56
|
+
error: 'Failed to install @payloadcms/figma',
|
|
57
|
+
modified: false,
|
|
58
|
+
success: false
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
} else if (isDebug()) {
|
|
62
|
+
log.debug('@payloadcms/figma already installed');
|
|
63
|
+
}
|
|
64
|
+
// 3. Parse config with ts-morph
|
|
65
|
+
if (isDebug()) {
|
|
66
|
+
log.debug('Parsing config file with ts-morph...');
|
|
67
|
+
}
|
|
68
|
+
const project = new Project({
|
|
69
|
+
skipAddingFilesFromTsConfig: true
|
|
70
|
+
});
|
|
71
|
+
const sourceFile = project.addSourceFileAtPath(configPath);
|
|
72
|
+
// 4. Detect required changes
|
|
73
|
+
if (isDebug()) {
|
|
74
|
+
log.debug('Detecting required changes...');
|
|
75
|
+
}
|
|
76
|
+
const detection = detectRequiredChanges(sourceFile);
|
|
77
|
+
if (isDebug()) {
|
|
78
|
+
log.debug(`Detection results: needsImportChange=${detection.needsImportChange}, hasAlias=${detection.hasAlias}, buildConfigNotFound=${detection.buildConfigNotFound}`);
|
|
79
|
+
}
|
|
80
|
+
// Handle failure modes
|
|
81
|
+
if (detection.hasAlias) {
|
|
82
|
+
if (isDebug()) {
|
|
83
|
+
log.debug('Config uses import alias (e.g., buildConfig as X)');
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
changes,
|
|
87
|
+
error: 'Config uses import alias - manual modification required',
|
|
88
|
+
modified,
|
|
89
|
+
success: false
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (detection.buildConfigNotFound) {
|
|
93
|
+
if (isDebug()) {
|
|
94
|
+
log.debug('No buildConfig call found in config file');
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
changes,
|
|
98
|
+
error: 'Config structure not recognized (no buildConfig call found)',
|
|
99
|
+
modified,
|
|
100
|
+
success: false
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
// 5. Apply modifications
|
|
104
|
+
if (isDebug()) {
|
|
105
|
+
log.debug('Applying modifications...');
|
|
106
|
+
}
|
|
107
|
+
const modResult = applyModifications(sourceFile, detection);
|
|
108
|
+
if (modResult.modified) {
|
|
109
|
+
changes.push(...modResult.changes);
|
|
110
|
+
modified = true;
|
|
111
|
+
if (isDebug()) {
|
|
112
|
+
log.debug(`Applied ${modResult.changes.length} modifications`);
|
|
113
|
+
}
|
|
114
|
+
// Save file
|
|
115
|
+
await sourceFile.save();
|
|
116
|
+
if (isDebug()) {
|
|
117
|
+
log.debug('Config file saved');
|
|
118
|
+
}
|
|
119
|
+
// 6. Uninstall orphaned packages
|
|
120
|
+
const packagesToUninstall = [];
|
|
121
|
+
if (detection.dbProperty) {
|
|
122
|
+
packagesToUninstall.push(detection.dbProperty.importSource);
|
|
123
|
+
}
|
|
124
|
+
if (detection.editorProperty?.isDefault) {
|
|
125
|
+
packagesToUninstall.push(detection.editorProperty.importSource);
|
|
126
|
+
}
|
|
127
|
+
if (packagesToUninstall.length > 0 && isDebug()) {
|
|
128
|
+
log.debug(`Uninstalling ${packagesToUninstall.length} orphaned packages...`);
|
|
129
|
+
}
|
|
130
|
+
for (const pkg of packagesToUninstall){
|
|
131
|
+
try {
|
|
132
|
+
await uninstallPackage(projectPath, pkg, packageManager);
|
|
133
|
+
changes.push(`Uninstalled ${pkg}`);
|
|
134
|
+
if (isDebug()) {
|
|
135
|
+
log.debug(`Uninstalled ${pkg}`);
|
|
136
|
+
}
|
|
137
|
+
} catch (error) {
|
|
138
|
+
if (isDebug()) {
|
|
139
|
+
log.debug(`Failed to uninstall ${pkg}: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
140
|
+
}
|
|
141
|
+
// Don't fail on uninstall errors - orphaned package is better than broken config
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// 7. Format file
|
|
145
|
+
if (isDebug()) {
|
|
146
|
+
log.debug('Formatting config file...');
|
|
147
|
+
}
|
|
148
|
+
const formatResult = await formatFile(configPath, packageManager);
|
|
149
|
+
if (!formatResult.success && formatResult.warning) {
|
|
150
|
+
warnings.push(formatResult.warning);
|
|
151
|
+
if (isDebug()) {
|
|
152
|
+
log.debug(`Formatting warning: ${formatResult.warning}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// 8. Run TypeScript validation
|
|
156
|
+
if (isDebug()) {
|
|
157
|
+
log.debug('Running TypeScript validation...');
|
|
158
|
+
}
|
|
159
|
+
const tsResult = await runTypeScriptCheck(projectPath, packageManager);
|
|
160
|
+
if (!tsResult.success && tsResult.errors.length > 0) {
|
|
161
|
+
warnings.push("TypeScript validation found issues - run 'pnpm build' for details");
|
|
162
|
+
if (isDebug()) {
|
|
163
|
+
log.debug(`TypeScript validation found ${tsResult.errors.length} issues`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
} else if (isDebug()) {
|
|
167
|
+
log.debug('No modifications needed - config already correct');
|
|
168
|
+
}
|
|
169
|
+
if (isDebug()) {
|
|
170
|
+
log.debug('Payload config modification completed successfully');
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
changes,
|
|
174
|
+
modified,
|
|
175
|
+
success: true,
|
|
176
|
+
warnings: warnings.length > 0 ? warnings : undefined
|
|
177
|
+
};
|
|
178
|
+
} catch (error) {
|
|
179
|
+
if (isDebug()) {
|
|
180
|
+
log.debug(`Unexpected error in ensurePayloadFigmaConfig: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
181
|
+
if (error instanceof Error && error.stack) {
|
|
182
|
+
log.debug(`Stack trace: ${error.stack}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
changes,
|
|
187
|
+
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
188
|
+
modified,
|
|
189
|
+
success: false
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Display manual configuration instructions
|
|
195
|
+
*/ export function displayManualInstructions(reason) {
|
|
196
|
+
const leftLineWrap = (message)=>{
|
|
197
|
+
// Add '┌ ' prefix to first line, '│ ' to subsequent lines, and '└ ' to last line
|
|
198
|
+
return message.split('\n').map((line, index, arr)=>{
|
|
199
|
+
if (index === 0) {
|
|
200
|
+
return `${pc.dim('┌ ')}${line}`;
|
|
201
|
+
} else if (index === arr.length - 1) {
|
|
202
|
+
return `${pc.dim('└ ')}${line}`;
|
|
203
|
+
} else {
|
|
204
|
+
return `${pc.dim('│ ')}${line}`;
|
|
205
|
+
}
|
|
206
|
+
}).join('\n');
|
|
207
|
+
};
|
|
208
|
+
const message = leftLineWrap(`${pc.cyan(pc.bold('Manual Configuration Required'))}
|
|
209
|
+
|
|
210
|
+
Unable to automatically modify payload.config.ts
|
|
211
|
+
Reason: ${pc.yellow(reason)}
|
|
212
|
+
|
|
213
|
+
${pc.bold('Required changes:')}
|
|
214
|
+
|
|
215
|
+
1. Replace buildConfig import:
|
|
216
|
+
${pc.dim('- FROM: ')}${pc.cyan("import { buildConfig } from 'payload'")}
|
|
217
|
+
${pc.dim('- TO: ')}${pc.cyan("import { buildConfig } from '@payloadcms/figma'")}
|
|
218
|
+
|
|
219
|
+
2. Remove these properties from buildConfig():
|
|
220
|
+
• db
|
|
221
|
+
• secret
|
|
222
|
+
• editor (if using default lexicalEditor())
|
|
223
|
+
|
|
224
|
+
3. Install package:
|
|
225
|
+
${pc.cyan('pnpm add @payloadcms/figma')}
|
|
226
|
+
|
|
227
|
+
Then run: ${pc.cyan('@payloadcms/figma init')}`);
|
|
228
|
+
// eslint-disable-next-line no-console
|
|
229
|
+
console.log(message);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
//# sourceMappingURL=payload-config-modifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/payload-config-modifier.ts"],"sourcesContent":["import pc from 'picocolors'\nimport { Project } from 'ts-morph'\n\nimport type { PackageManager } from './package-manager.js'\n\nimport { formatFile } from './formatter.js'\nimport { isDebug } from './is-debug.js'\nimport * as log from './log.js'\nimport { applyModifications, detectRequiredChanges } from './payload-config-ast.js'\nimport { findPayloadConfig } from './payload-config-finder.js'\nimport { checkPackageInstalled, installPackage, uninstallPackage } from './payload-package-check.js'\nimport { runTypeScriptCheck } from './typescript-validator.js'\n\nexport type ModificationResult = {\n changes: string[]\n error?: string\n modified: boolean\n success: boolean\n warnings?: string[]\n}\n\n/**\n * Main orchestrator for payload config modification\n * Checks package, detects needed changes, applies modifications\n */\nexport async function ensurePayloadFigmaConfig(\n projectPath: string,\n packageManager: PackageManager,\n): Promise<ModificationResult> {\n const changes: string[] = []\n const warnings: string[] = []\n let modified = false\n\n try {\n if (isDebug()) {\n log.debug(`Starting payload config modification for: ${projectPath}`)\n }\n\n // 1. Find config file\n const configPath = await findPayloadConfig(projectPath)\n if (!configPath) {\n if (isDebug()) {\n log.debug(`Config file not found in: ${projectPath}`)\n }\n return {\n changes: [],\n error: 'payload.config.ts not found in project',\n modified: false,\n success: false,\n }\n }\n\n if (isDebug()) {\n log.debug(`Found config file: ${configPath}`)\n }\n\n // 2. Check/install @payloadcms/figma package\n const isInstalled = await checkPackageInstalled(projectPath, '@payloadcms/figma')\n if (!isInstalled) {\n if (isDebug()) {\n log.debug('@payloadcms/figma not installed, attempting installation...')\n }\n try {\n await installPackage(projectPath, '@payloadcms/figma', packageManager)\n changes.push('Installed @payloadcms/figma')\n modified = true\n if (isDebug()) {\n log.debug('@payloadcms/figma installed successfully')\n }\n } catch (error) {\n if (isDebug()) {\n log.debug(\n `Failed to install @payloadcms/figma: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n }\n return {\n changes: [],\n error: 'Failed to install @payloadcms/figma',\n modified: false,\n success: false,\n }\n }\n } else if (isDebug()) {\n log.debug('@payloadcms/figma already installed')\n }\n\n // 3. Parse config with ts-morph\n if (isDebug()) {\n log.debug('Parsing config file with ts-morph...')\n }\n const project = new Project({\n skipAddingFilesFromTsConfig: true,\n })\n const sourceFile = project.addSourceFileAtPath(configPath)\n\n // 4. Detect required changes\n if (isDebug()) {\n log.debug('Detecting required changes...')\n }\n const detection = detectRequiredChanges(sourceFile)\n\n if (isDebug()) {\n log.debug(\n `Detection results: needsImportChange=${detection.needsImportChange}, hasAlias=${detection.hasAlias}, buildConfigNotFound=${detection.buildConfigNotFound}`,\n )\n }\n\n // Handle failure modes\n if (detection.hasAlias) {\n if (isDebug()) {\n log.debug('Config uses import alias (e.g., buildConfig as X)')\n }\n return {\n changes,\n error: 'Config uses import alias - manual modification required',\n modified,\n success: false,\n }\n }\n\n if (detection.buildConfigNotFound) {\n if (isDebug()) {\n log.debug('No buildConfig call found in config file')\n }\n return {\n changes,\n error: 'Config structure not recognized (no buildConfig call found)',\n modified,\n success: false,\n }\n }\n\n // 5. Apply modifications\n if (isDebug()) {\n log.debug('Applying modifications...')\n }\n const modResult = applyModifications(sourceFile, detection)\n if (modResult.modified) {\n changes.push(...modResult.changes)\n modified = true\n\n if (isDebug()) {\n log.debug(`Applied ${modResult.changes.length} modifications`)\n }\n\n // Save file\n await sourceFile.save()\n if (isDebug()) {\n log.debug('Config file saved')\n }\n\n // 6. Uninstall orphaned packages\n const packagesToUninstall: string[] = []\n\n if (detection.dbProperty) {\n packagesToUninstall.push(detection.dbProperty.importSource)\n }\n\n if (detection.editorProperty?.isDefault) {\n packagesToUninstall.push(detection.editorProperty.importSource)\n }\n\n if (packagesToUninstall.length > 0 && isDebug()) {\n log.debug(`Uninstalling ${packagesToUninstall.length} orphaned packages...`)\n }\n\n for (const pkg of packagesToUninstall) {\n try {\n await uninstallPackage(projectPath, pkg, packageManager)\n changes.push(`Uninstalled ${pkg}`)\n if (isDebug()) {\n log.debug(`Uninstalled ${pkg}`)\n }\n } catch (error) {\n if (isDebug()) {\n log.debug(\n `Failed to uninstall ${pkg}: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n }\n // Don't fail on uninstall errors - orphaned package is better than broken config\n }\n }\n\n // 7. Format file\n if (isDebug()) {\n log.debug('Formatting config file...')\n }\n const formatResult = await formatFile(configPath, packageManager)\n if (!formatResult.success && formatResult.warning) {\n warnings.push(formatResult.warning)\n if (isDebug()) {\n log.debug(`Formatting warning: ${formatResult.warning}`)\n }\n }\n\n // 8. Run TypeScript validation\n if (isDebug()) {\n log.debug('Running TypeScript validation...')\n }\n const tsResult = await runTypeScriptCheck(projectPath, packageManager)\n if (!tsResult.success && tsResult.errors.length > 0) {\n warnings.push(\"TypeScript validation found issues - run 'pnpm build' for details\")\n if (isDebug()) {\n log.debug(`TypeScript validation found ${tsResult.errors.length} issues`)\n }\n }\n } else if (isDebug()) {\n log.debug('No modifications needed - config already correct')\n }\n\n if (isDebug()) {\n log.debug('Payload config modification completed successfully')\n }\n\n return {\n changes,\n modified,\n success: true,\n warnings: warnings.length > 0 ? warnings : undefined,\n }\n } catch (error) {\n if (isDebug()) {\n log.debug(\n `Unexpected error in ensurePayloadFigmaConfig: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n if (error instanceof Error && error.stack) {\n log.debug(`Stack trace: ${error.stack}`)\n }\n }\n return {\n changes,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n modified,\n success: false,\n }\n }\n}\n\n/**\n * Display manual configuration instructions\n */\nexport function displayManualInstructions(reason: string): void {\n const leftLineWrap = (message: string): string => {\n // Add '┌ ' prefix to first line, '│ ' to subsequent lines, and '└ ' to last line\n return message\n .split('\\n')\n .map((line, index, arr) => {\n if (index === 0) {\n return `${pc.dim('┌ ')}${line}`\n } else if (index === arr.length - 1) {\n return `${pc.dim('└ ')}${line}`\n } else {\n return `${pc.dim('│ ')}${line}`\n }\n })\n .join('\\n')\n }\n\n const message = leftLineWrap(`${pc.cyan(pc.bold('Manual Configuration Required'))}\n\nUnable to automatically modify payload.config.ts\nReason: ${pc.yellow(reason)}\n\n${pc.bold('Required changes:')}\n\n1. Replace buildConfig import:\n ${pc.dim('- FROM: ')}${pc.cyan(\"import { buildConfig } from 'payload'\")}\n ${pc.dim('- TO: ')}${pc.cyan(\"import { buildConfig } from '@payloadcms/figma'\")}\n\n2. Remove these properties from buildConfig():\n • db\n • secret\n • editor (if using default lexicalEditor())\n\n3. Install package:\n ${pc.cyan('pnpm add @payloadcms/figma')}\n\nThen run: ${pc.cyan('@payloadcms/figma init')}`)\n\n // eslint-disable-next-line no-console\n console.log(message)\n}\n"],"names":["pc","Project","formatFile","isDebug","log","applyModifications","detectRequiredChanges","findPayloadConfig","checkPackageInstalled","installPackage","uninstallPackage","runTypeScriptCheck","ensurePayloadFigmaConfig","projectPath","packageManager","changes","warnings","modified","debug","configPath","error","success","isInstalled","push","Error","message","project","skipAddingFilesFromTsConfig","sourceFile","addSourceFileAtPath","detection","needsImportChange","hasAlias","buildConfigNotFound","modResult","length","save","packagesToUninstall","dbProperty","importSource","editorProperty","isDefault","pkg","formatResult","warning","tsResult","errors","undefined","stack","displayManualInstructions","reason","leftLineWrap","split","map","line","index","arr","dim","join","cyan","bold","yellow","console"],"mappings":"AAAA,OAAOA,QAAQ,aAAY;AAC3B,SAASC,OAAO,QAAQ,WAAU;AAIlC,SAASC,UAAU,QAAQ,iBAAgB;AAC3C,SAASC,OAAO,QAAQ,gBAAe;AACvC,YAAYC,SAAS,WAAU;AAC/B,SAASC,kBAAkB,EAAEC,qBAAqB,QAAQ,0BAAyB;AACnF,SAASC,iBAAiB,QAAQ,6BAA4B;AAC9D,SAASC,qBAAqB,EAAEC,cAAc,EAAEC,gBAAgB,QAAQ,6BAA4B;AACpG,SAASC,kBAAkB,QAAQ,4BAA2B;AAU9D;;;CAGC,GACD,OAAO,eAAeC,yBACpBC,WAAmB,EACnBC,cAA8B;IAE9B,MAAMC,UAAoB,EAAE;IAC5B,MAAMC,WAAqB,EAAE;IAC7B,IAAIC,WAAW;IAEf,IAAI;QACF,IAAId,WAAW;YACbC,IAAIc,KAAK,CAAC,CAAC,0CAA0C,EAAEL,aAAa;QACtE;QAEA,sBAAsB;QACtB,MAAMM,aAAa,MAAMZ,kBAAkBM;QAC3C,IAAI,CAACM,YAAY;YACf,IAAIhB,WAAW;gBACbC,IAAIc,KAAK,CAAC,CAAC,0BAA0B,EAAEL,aAAa;YACtD;YACA,OAAO;gBACLE,SAAS,EAAE;gBACXK,OAAO;gBACPH,UAAU;gBACVI,SAAS;YACX;QACF;QAEA,IAAIlB,WAAW;YACbC,IAAIc,KAAK,CAAC,CAAC,mBAAmB,EAAEC,YAAY;QAC9C;QAEA,6CAA6C;QAC7C,MAAMG,cAAc,MAAMd,sBAAsBK,aAAa;QAC7D,IAAI,CAACS,aAAa;YAChB,IAAInB,WAAW;gBACbC,IAAIc,KAAK,CAAC;YACZ;YACA,IAAI;gBACF,MAAMT,eAAeI,aAAa,qBAAqBC;gBACvDC,QAAQQ,IAAI,CAAC;gBACbN,WAAW;gBACX,IAAId,WAAW;oBACbC,IAAIc,K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GAAGyD,GAAG,CAAC,SAASH,MAAM;YAClC,OAAO,IAAIC,UAAUC,IAAIrB,MAAM,GAAG,GAAG;gBACnC,OAAO,GAAGnC,GAAGyD,GAAG,CAAC,SAASH,MAAM;YAClC,OAAO;gBACL,OAAO,GAAGtD,GAAGyD,GAAG,CAAC,SAASH,MAAM;YAClC;QACF,GACCI,IAAI,CAAC;IACV;IAEA,MAAMjC,UAAU0B,aAAa,GAAGnD,GAAG2D,IAAI,CAAC3D,GAAG4D,IAAI,CAAC,kCAAkC;;;QAG5E,EAAE5D,GAAG6D,MAAM,CAACX,QAAQ;;AAE5B,EAAElD,GAAG4D,IAAI,CAAC,qBAAqB;;;GAG5B,EAAE5D,GAAGyD,GAAG,CAAC,cAAczD,GAAG2D,IAAI,CAAC,yCAAyC;GACxE,EAAE3D,GAAGyD,GAAG,CAAC,cAAczD,GAAG2D,IAAI,CAAC,mDAAmD;;;;;;;;GAQlF,EAAE3D,GAAG2D,IAAI,CAAC,8BAA8B;;UAEjC,EAAE3D,GAAG2D,IAAI,CAAC,2BAA2B;IAE7C,sCAAsC;IACtCG,QAAQ1D,GAAG,CAACqB;AACd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload-config-modifier.spec.d.ts","sourceRoot":"","sources":["../../src/utils/payload-config-modifier.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { displayManualInstructions, ensurePayloadFigmaConfig } from './payload-config-modifier.js';
|
|
3
|
+
vi.mock('./payload-config-finder.js');
|
|
4
|
+
vi.mock('./payload-package-check.js');
|
|
5
|
+
vi.mock('./payload-config-ast.js');
|
|
6
|
+
vi.mock('./typescript-validator.js');
|
|
7
|
+
vi.mock('./formatter.js');
|
|
8
|
+
describe('payload-config-modifier', ()=>{
|
|
9
|
+
beforeEach(()=>{
|
|
10
|
+
vi.clearAllMocks();
|
|
11
|
+
});
|
|
12
|
+
describe('ensurePayloadFigmaConfig', ()=>{
|
|
13
|
+
it('should return error when config not found', async ()=>{
|
|
14
|
+
const { findPayloadConfig } = await import('./payload-config-finder.js');
|
|
15
|
+
vi.mocked(findPayloadConfig).mockResolvedValue(null);
|
|
16
|
+
const result = await ensurePayloadFigmaConfig('/test/project', 'pnpm');
|
|
17
|
+
expect(result.success).toBe(false);
|
|
18
|
+
expect(result.error).toContain('payload.config.ts not found');
|
|
19
|
+
});
|
|
20
|
+
it('should install package if missing', async ()=>{
|
|
21
|
+
const { findPayloadConfig } = await import('./payload-config-finder.js');
|
|
22
|
+
const { checkPackageInstalled, installPackage } = await import('./payload-package-check.js');
|
|
23
|
+
vi.mocked(findPayloadConfig).mockResolvedValue('/test/project/payload.config.ts');
|
|
24
|
+
vi.mocked(checkPackageInstalled).mockResolvedValue(false);
|
|
25
|
+
vi.mocked(installPackage).mockResolvedValue();
|
|
26
|
+
// Mock ts-morph to avoid file system operations
|
|
27
|
+
const { Project } = await import('ts-morph');
|
|
28
|
+
vi.spyOn(Project.prototype, 'addSourceFileAtPath').mockReturnValue({
|
|
29
|
+
getFullText: vi.fn().mockReturnValue('')
|
|
30
|
+
});
|
|
31
|
+
const { detectRequiredChanges } = await import('./payload-config-ast.js');
|
|
32
|
+
vi.mocked(detectRequiredChanges).mockReturnValue({
|
|
33
|
+
hasAlias: false,
|
|
34
|
+
hasOtherPayloadImports: false,
|
|
35
|
+
needsImportChange: false
|
|
36
|
+
});
|
|
37
|
+
const result = await ensurePayloadFigmaConfig('/test/project', 'pnpm');
|
|
38
|
+
expect(installPackage).toHaveBeenCalledWith('/test/project', '@payloadcms/figma', 'pnpm');
|
|
39
|
+
expect(result.changes).toContain('Installed @payloadcms/figma');
|
|
40
|
+
});
|
|
41
|
+
it('should apply modifications when needed', async ()=>{
|
|
42
|
+
const { findPayloadConfig } = await import('./payload-config-finder.js');
|
|
43
|
+
const { checkPackageInstalled } = await import('./payload-package-check.js');
|
|
44
|
+
const { applyModifications, detectRequiredChanges } = await import('./payload-config-ast.js');
|
|
45
|
+
vi.mocked(findPayloadConfig).mockResolvedValue('/test/project/payload.config.ts');
|
|
46
|
+
vi.mocked(checkPackageInstalled).mockResolvedValue(true);
|
|
47
|
+
// Mock source file
|
|
48
|
+
const mockSourceFile = {
|
|
49
|
+
getFullText: vi.fn().mockReturnValue(''),
|
|
50
|
+
save: vi.fn().mockResolvedValue(undefined)
|
|
51
|
+
};
|
|
52
|
+
const { Project } = await import('ts-morph');
|
|
53
|
+
vi.spyOn(Project.prototype, 'addSourceFileAtPath').mockReturnValue(mockSourceFile);
|
|
54
|
+
vi.mocked(detectRequiredChanges).mockReturnValue({
|
|
55
|
+
dbProperty: {
|
|
56
|
+
adapter: 'mongooseAdapter',
|
|
57
|
+
importSource: '@payloadcms/db-mongodb'
|
|
58
|
+
},
|
|
59
|
+
hasAlias: false,
|
|
60
|
+
hasOtherPayloadImports: false,
|
|
61
|
+
needsImportChange: true
|
|
62
|
+
});
|
|
63
|
+
vi.mocked(applyModifications).mockReturnValue({
|
|
64
|
+
changes: [
|
|
65
|
+
'Removed db property',
|
|
66
|
+
'Changed buildConfig import to @payloadcms/figma'
|
|
67
|
+
],
|
|
68
|
+
modified: true
|
|
69
|
+
});
|
|
70
|
+
const { runTypeScriptCheck } = await import('./typescript-validator.js');
|
|
71
|
+
vi.mocked(runTypeScriptCheck).mockResolvedValue({
|
|
72
|
+
errors: [],
|
|
73
|
+
success: true
|
|
74
|
+
});
|
|
75
|
+
const { formatFile } = await import('./formatter.js');
|
|
76
|
+
vi.mocked(formatFile).mockResolvedValue({
|
|
77
|
+
success: true
|
|
78
|
+
});
|
|
79
|
+
const result = await ensurePayloadFigmaConfig('/test/project', 'pnpm');
|
|
80
|
+
expect(result.success).toBe(true);
|
|
81
|
+
expect(result.modified).toBe(true);
|
|
82
|
+
expect(result.changes.length).toBeGreaterThan(0);
|
|
83
|
+
expect(mockSourceFile.save).toHaveBeenCalled();
|
|
84
|
+
});
|
|
85
|
+
it('should return error when buildConfig has alias', async ()=>{
|
|
86
|
+
const { findPayloadConfig } = await import('./payload-config-finder.js');
|
|
87
|
+
const { checkPackageInstalled } = await import('./payload-package-check.js');
|
|
88
|
+
const { detectRequiredChanges } = await import('./payload-config-ast.js');
|
|
89
|
+
vi.mocked(findPayloadConfig).mockResolvedValue('/test/project/payload.config.ts');
|
|
90
|
+
vi.mocked(checkPackageInstalled).mockResolvedValue(true);
|
|
91
|
+
const mockSourceFile = {
|
|
92
|
+
getFullText: vi.fn().mockReturnValue('')
|
|
93
|
+
};
|
|
94
|
+
const { Project } = await import('ts-morph');
|
|
95
|
+
vi.spyOn(Project.prototype, 'addSourceFileAtPath').mockReturnValue(mockSourceFile);
|
|
96
|
+
vi.mocked(detectRequiredChanges).mockReturnValue({
|
|
97
|
+
hasAlias: true,
|
|
98
|
+
hasOtherPayloadImports: false,
|
|
99
|
+
needsImportChange: true
|
|
100
|
+
});
|
|
101
|
+
const result = await ensurePayloadFigmaConfig('/test/project', 'pnpm');
|
|
102
|
+
expect(result.success).toBe(false);
|
|
103
|
+
expect(result.error).toContain('Config uses import alias');
|
|
104
|
+
});
|
|
105
|
+
it('should uninstall orphaned packages', async ()=>{
|
|
106
|
+
const { findPayloadConfig } = await import('./payload-config-finder.js');
|
|
107
|
+
const { checkPackageInstalled, uninstallPackage } = await import('./payload-package-check.js');
|
|
108
|
+
const { applyModifications, detectRequiredChanges } = await import('./payload-config-ast.js');
|
|
109
|
+
vi.mocked(findPayloadConfig).mockResolvedValue('/test/project/payload.config.ts');
|
|
110
|
+
vi.mocked(checkPackageInstalled).mockResolvedValue(true);
|
|
111
|
+
const mockSourceFile = {
|
|
112
|
+
getFullText: vi.fn().mockReturnValue(''),
|
|
113
|
+
save: vi.fn().mockResolvedValue(undefined)
|
|
114
|
+
};
|
|
115
|
+
const { Project } = await import('ts-morph');
|
|
116
|
+
vi.spyOn(Project.prototype, 'addSourceFileAtPath').mockReturnValue(mockSourceFile);
|
|
117
|
+
vi.mocked(detectRequiredChanges).mockReturnValue({
|
|
118
|
+
dbProperty: {
|
|
119
|
+
adapter: 'mongooseAdapter',
|
|
120
|
+
importSource: '@payloadcms/db-mongodb'
|
|
121
|
+
},
|
|
122
|
+
editorProperty: {
|
|
123
|
+
importSource: '@payloadcms/richtext-lexical',
|
|
124
|
+
isDefault: true
|
|
125
|
+
},
|
|
126
|
+
hasAlias: false,
|
|
127
|
+
hasOtherPayloadImports: false,
|
|
128
|
+
needsImportChange: false
|
|
129
|
+
});
|
|
130
|
+
vi.mocked(applyModifications).mockReturnValue({
|
|
131
|
+
changes: [
|
|
132
|
+
'Removed db property',
|
|
133
|
+
'Removed default editor property'
|
|
134
|
+
],
|
|
135
|
+
modified: true
|
|
136
|
+
});
|
|
137
|
+
vi.mocked(uninstallPackage).mockResolvedValue();
|
|
138
|
+
const { runTypeScriptCheck } = await import('./typescript-validator.js');
|
|
139
|
+
vi.mocked(runTypeScriptCheck).mockResolvedValue({
|
|
140
|
+
errors: [],
|
|
141
|
+
success: true
|
|
142
|
+
});
|
|
143
|
+
const { formatFile } = await import('./formatter.js');
|
|
144
|
+
vi.mocked(formatFile).mockResolvedValue({
|
|
145
|
+
success: true
|
|
146
|
+
});
|
|
147
|
+
const result = await ensurePayloadFigmaConfig('/test/project', 'pnpm');
|
|
148
|
+
expect(uninstallPackage).toHaveBeenCalledWith('/test/project', '@payloadcms/db-mongodb', 'pnpm');
|
|
149
|
+
expect(uninstallPackage).toHaveBeenCalledWith('/test/project', '@payloadcms/richtext-lexical', 'pnpm');
|
|
150
|
+
expect(result.changes).toContain('Uninstalled @payloadcms/db-mongodb');
|
|
151
|
+
expect(result.changes).toContain('Uninstalled @payloadcms/richtext-lexical');
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
describe('displayManualInstructions', ()=>{
|
|
155
|
+
it('should format manual instructions correctly', ()=>{
|
|
156
|
+
// This is a formatting function, just verify it doesn't throw
|
|
157
|
+
expect(()=>displayManualInstructions('Test reason')).not.toThrow();
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
//# sourceMappingURL=payload-config-modifier.spec.js.map
|