@payloadcms/figma 0.0.1-alpha.0 → 0.0.1-alpha.10
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/dist/api/control-plane.d.ts.map +1 -1
- package/dist/api/control-plane.js +2 -7
- package/dist/api/control-plane.js.map +1 -1
- package/dist/api/figma-api.js +3 -3
- package/dist/api/figma-api.js.map +1 -1
- package/dist/auth/jwt-validator.js.map +1 -1
- package/dist/auth/oauth-flow.d.ts.map +1 -1
- package/dist/auth/oauth-flow.js +3 -6
- package/dist/auth/oauth-flow.js.map +1 -1
- package/dist/auth/project-token.d.ts.map +1 -1
- package/dist/auth/project-token.js +1 -4
- package/dist/auth/project-token.js.map +1 -1
- package/dist/auth/refresh.d.ts.map +1 -1
- package/dist/auth/refresh.js +19 -28
- package/dist/auth/refresh.js.map +1 -1
- package/dist/auth/types.d.ts +1 -1
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/cli.js +1 -3
- package/dist/cli.js.map +1 -1
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +17 -10
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/init.d.ts +4 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +21 -85
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/list-tokens.d.ts +1 -1
- package/dist/commands/list-tokens.d.ts.map +1 -1
- package/dist/commands/list-tokens.js +6 -5
- package/dist/commands/list-tokens.js.map +1 -1
- package/dist/commands/login.d.ts +2 -11
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +4 -7
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.d.ts +1 -1
- package/dist/commands/logout.js +1 -1
- package/dist/commands/logout.js.map +1 -1
- package/dist/exports/client.d.ts +3 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +4 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/oauth/components/LoginButton/index.d.ts +9 -0
- package/dist/oauth/components/LoginButton/index.d.ts.map +1 -0
- package/dist/oauth/components/LoginButton/index.js +52 -0
- package/dist/oauth/components/LoginButton/index.js.map +1 -0
- package/dist/oauth/components/LoginButton/index.scss +10 -0
- package/dist/oauth/components/LogoutButton/index.d.ts +7 -0
- package/dist/oauth/components/LogoutButton/index.d.ts.map +1 -0
- package/dist/oauth/components/LogoutButton/index.js +67 -0
- package/dist/oauth/components/LogoutButton/index.js.map +1 -0
- package/dist/oauth/components/LogoutButton/index.scss +10 -0
- package/dist/oauth/defaults.d.ts +10 -0
- package/dist/oauth/defaults.d.ts.map +1 -0
- package/dist/oauth/defaults.js +91 -0
- package/dist/oauth/defaults.js.map +1 -0
- package/dist/oauth/endpoints/getLoginEndpoint.d.ts +13 -0
- package/dist/oauth/endpoints/getLoginEndpoint.d.ts.map +1 -0
- package/dist/oauth/endpoints/getLoginEndpoint.js +237 -0
- package/dist/oauth/endpoints/getLoginEndpoint.js.map +1 -0
- package/dist/oauth/endpoints/getLogoutEndpoint.d.ts +12 -0
- package/dist/oauth/endpoints/getLogoutEndpoint.d.ts.map +1 -0
- package/dist/oauth/endpoints/getLogoutEndpoint.js +99 -0
- package/dist/oauth/endpoints/getLogoutEndpoint.js.map +1 -0
- package/dist/oauth/endpoints/getMetaEndpoint.d.ts +13 -0
- package/dist/oauth/endpoints/getMetaEndpoint.d.ts.map +1 -0
- package/dist/oauth/endpoints/getMetaEndpoint.js +25 -0
- package/dist/oauth/endpoints/getMetaEndpoint.js.map +1 -0
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.d.ts +13 -0
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.d.ts.map +1 -0
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.js +21 -0
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.js.map +1 -0
- package/dist/oauth/exports/client.d.ts +3 -0
- package/dist/oauth/exports/client.d.ts.map +1 -0
- package/dist/oauth/exports/client.js +4 -0
- package/dist/oauth/exports/client.js.map +1 -0
- package/dist/oauth/hooks/afterLogout.d.ts +8 -0
- package/dist/oauth/hooks/afterLogout.d.ts.map +1 -0
- package/dist/oauth/hooks/afterLogout.js +27 -0
- package/dist/oauth/hooks/afterLogout.js.map +1 -0
- package/dist/oauth/hooks/me.d.ts +5 -0
- package/dist/oauth/hooks/me.d.ts.map +1 -0
- package/dist/oauth/hooks/me.js +55 -0
- package/dist/oauth/hooks/me.js.map +1 -0
- package/dist/oauth/hooks/refresh.d.ts +8 -0
- package/dist/oauth/hooks/refresh.d.ts.map +1 -0
- package/dist/oauth/hooks/refresh.js +91 -0
- package/dist/oauth/hooks/refresh.js.map +1 -0
- package/dist/oauth/index.d.ts +4 -0
- package/dist/oauth/index.d.ts.map +1 -0
- package/dist/oauth/index.js +222 -0
- package/dist/oauth/index.js.map +1 -0
- package/dist/oauth/strategy/index.d.ts +54 -0
- package/dist/oauth/strategy/index.d.ts.map +1 -0
- package/dist/oauth/strategy/index.js +280 -0
- package/dist/oauth/strategy/index.js.map +1 -0
- package/dist/oauth/types.d.ts +192 -0
- package/dist/oauth/types.d.ts.map +1 -0
- package/dist/oauth/types.js +3 -0
- package/dist/oauth/types.js.map +1 -0
- package/dist/oauth/utilities/clearCookie.d.ts +9 -0
- package/dist/oauth/utilities/clearCookie.d.ts.map +1 -0
- package/dist/oauth/utilities/clearCookie.js +21 -0
- package/dist/oauth/utilities/clearCookie.js.map +1 -0
- package/dist/oauth/utilities/createCookieOptions.d.ts +10 -0
- package/dist/oauth/utilities/createCookieOptions.d.ts.map +1 -0
- package/dist/oauth/utilities/createCookieOptions.js +42 -0
- package/dist/oauth/utilities/createCookieOptions.js.map +1 -0
- package/dist/oauth/utilities/createDebugLogger.d.ts +4 -0
- package/dist/oauth/utilities/createDebugLogger.d.ts.map +1 -0
- package/dist/oauth/utilities/createDebugLogger.js +16 -0
- package/dist/oauth/utilities/createDebugLogger.js.map +1 -0
- package/dist/oauth/utilities/extractOrigin.d.ts +2 -0
- package/dist/oauth/utilities/extractOrigin.d.ts.map +1 -0
- package/dist/oauth/utilities/extractOrigin.js +12 -0
- package/dist/oauth/utilities/extractOrigin.js.map +1 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.d.ts +3 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.d.ts.map +1 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.js +18 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.js.map +1 -0
- package/dist/oauth/utilities/getAdminPath.d.ts +8 -0
- package/dist/oauth/utilities/getAdminPath.d.ts.map +1 -0
- package/dist/oauth/utilities/getAdminPath.js +9 -0
- package/dist/oauth/utilities/getAdminPath.js.map +1 -0
- package/dist/oauth/utilities/getAuthorizeURL.d.ts +17 -0
- package/dist/oauth/utilities/getAuthorizeURL.d.ts.map +1 -0
- package/dist/oauth/utilities/getAuthorizeURL.js +45 -0
- package/dist/oauth/utilities/getAuthorizeURL.js.map +1 -0
- package/dist/oauth/utilities/getCookieExpiration.d.ts +4 -0
- package/dist/oauth/utilities/getCookieExpiration.d.ts.map +1 -0
- package/dist/oauth/utilities/getCookieExpiration.js +11 -0
- package/dist/oauth/utilities/getCookieExpiration.js.map +1 -0
- package/dist/oauth/utilities/getSecondsFromTokenExp.d.ts +2 -0
- package/dist/oauth/utilities/getSecondsFromTokenExp.d.ts.map +1 -0
- package/dist/oauth/utilities/getSecondsFromTokenExp.js +7 -0
- package/dist/oauth/utilities/getSecondsFromTokenExp.js.map +1 -0
- package/dist/oauth/utilities/getTokenExp.d.ts +6 -0
- package/dist/oauth/utilities/getTokenExp.d.ts.map +1 -0
- package/dist/oauth/utilities/getTokenExp.js +20 -0
- package/dist/oauth/utilities/getTokenExp.js.map +1 -0
- package/dist/oauth/utilities/getUsernameField.d.ts +9 -0
- package/dist/oauth/utilities/getUsernameField.d.ts.map +1 -0
- package/dist/oauth/utilities/getUsernameField.js +20 -0
- package/dist/oauth/utilities/getUsernameField.js.map +1 -0
- package/dist/oauth/utilities/hasUserTokenPropsChanged.d.ts +8 -0
- package/dist/oauth/utilities/hasUserTokenPropsChanged.d.ts.map +1 -0
- package/dist/oauth/utilities/hasUserTokenPropsChanged.js +25 -0
- package/dist/oauth/utilities/hasUserTokenPropsChanged.js.map +1 -0
- package/dist/oauth/utilities/mergeHeaders.d.ts +2 -0
- package/dist/oauth/utilities/mergeHeaders.d.ts.map +1 -0
- package/dist/oauth/utilities/mergeHeaders.js +37 -0
- package/dist/oauth/utilities/mergeHeaders.js.map +1 -0
- package/dist/oauth/utilities/refreshTokens.d.ts +16 -0
- package/dist/oauth/utilities/refreshTokens.d.ts.map +1 -0
- package/dist/oauth/utilities/refreshTokens.js +67 -0
- package/dist/oauth/utilities/refreshTokens.js.map +1 -0
- package/dist/plugin/build-config.d.ts +7 -1
- package/dist/plugin/build-config.d.ts.map +1 -1
- package/dist/plugin/build-config.js +29 -2
- package/dist/plugin/build-config.js.map +1 -1
- package/dist/types/config.d.ts +0 -11
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +1 -1
- package/dist/types/config.js.map +1 -1
- package/dist/utils/config.d.ts +0 -22
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +0 -46
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/messages.js +11 -11
- package/dist/utils/messages.js.map +1 -1
- package/dist/utils/payload-config-ast.d.ts +17 -1
- package/dist/utils/payload-config-ast.d.ts.map +1 -1
- package/dist/utils/payload-config-ast.js +166 -14
- package/dist/utils/payload-config-ast.js.map +1 -1
- package/dist/utils/payload-config-modifier.d.ts +2 -1
- package/dist/utils/payload-config-modifier.d.ts.map +1 -1
- package/dist/utils/payload-config-modifier.js +50 -79
- package/dist/utils/payload-config-modifier.js.map +1 -1
- package/dist/utils/payload-package-check.d.ts.map +1 -1
- package/dist/utils/payload-package-check.js +14 -33
- package/dist/utils/payload-package-check.js.map +1 -1
- package/dist/utils/project.d.ts +1 -1
- package/dist/utils/project.d.ts.map +1 -1
- package/dist/utils/project.js +3 -5
- package/dist/utils/project.js.map +1 -1
- package/dist/utils/s3-upload.d.ts.map +1 -1
- package/dist/utils/s3-upload.js +3 -8
- package/dist/utils/s3-upload.js.map +1 -1
- package/dist/utils/token-display.d.ts.map +1 -1
- package/dist/utils/token-display.js +3 -2
- package/dist/utils/token-display.js.map +1 -1
- package/package.json +13 -5
- package/dist/api/control-plane.spec.d.ts +0 -2
- package/dist/api/control-plane.spec.d.ts.map +0 -1
- package/dist/api/control-plane.spec.js +0 -296
- package/dist/api/control-plane.spec.js.map +0 -1
- package/dist/api/figma-api.spec.d.ts +0 -14
- package/dist/api/figma-api.spec.d.ts.map +0 -1
- package/dist/api/figma-api.spec.js +0 -201
- package/dist/api/figma-api.spec.js.map +0 -1
- package/dist/auth/__tests__/fixtures.d.ts +0 -26
- package/dist/auth/__tests__/fixtures.d.ts.map +0 -1
- package/dist/auth/__tests__/fixtures.js +0 -67
- package/dist/auth/__tests__/fixtures.js.map +0 -1
- package/dist/auth/__tests__/mocks.d.ts +0 -33
- package/dist/auth/__tests__/mocks.d.ts.map +0 -1
- package/dist/auth/__tests__/mocks.js +0 -63
- package/dist/auth/__tests__/mocks.js.map +0 -1
- package/dist/auth/callback-server.spec.d.ts +0 -2
- package/dist/auth/callback-server.spec.d.ts.map +0 -1
- package/dist/auth/callback-server.spec.js +0 -85
- package/dist/auth/callback-server.spec.js.map +0 -1
- package/dist/auth/crypto-utils.spec.d.ts +0 -2
- package/dist/auth/crypto-utils.spec.d.ts.map +0 -1
- package/dist/auth/crypto-utils.spec.js +0 -36
- package/dist/auth/crypto-utils.spec.js.map +0 -1
- package/dist/auth/jwt-validator.spec.d.ts +0 -10
- package/dist/auth/jwt-validator.spec.d.ts.map +0 -1
- package/dist/auth/jwt-validator.spec.js +0 -236
- package/dist/auth/jwt-validator.spec.js.map +0 -1
- package/dist/auth/oauth-flow.spec.d.ts +0 -2
- package/dist/auth/oauth-flow.spec.d.ts.map +0 -1
- package/dist/auth/oauth-flow.spec.js +0 -134
- package/dist/auth/oauth-flow.spec.js.map +0 -1
- package/dist/auth/pkce.spec.d.ts +0 -2
- package/dist/auth/pkce.spec.d.ts.map +0 -1
- package/dist/auth/pkce.spec.js +0 -32
- package/dist/auth/pkce.spec.js.map +0 -1
- package/dist/auth/project-token.spec.d.ts +0 -2
- package/dist/auth/project-token.spec.d.ts.map +0 -1
- package/dist/auth/project-token.spec.js +0 -332
- package/dist/auth/project-token.spec.js.map +0 -1
- package/dist/auth/refresh.spec.d.ts +0 -2
- package/dist/auth/refresh.spec.d.ts.map +0 -1
- package/dist/auth/refresh.spec.js +0 -105
- package/dist/auth/refresh.spec.js.map +0 -1
- package/dist/auth/token-store.spec.d.ts +0 -2
- package/dist/auth/token-store.spec.d.ts.map +0 -1
- package/dist/auth/token-store.spec.js +0 -276
- package/dist/auth/token-store.spec.js.map +0 -1
- package/dist/commands/__tests__/test-utils.d.ts +0 -28
- package/dist/commands/__tests__/test-utils.d.ts.map +0 -1
- package/dist/commands/__tests__/test-utils.js +0 -34
- package/dist/commands/__tests__/test-utils.js.map +0 -1
- package/dist/commands/deploy.spec.d.ts +0 -2
- package/dist/commands/deploy.spec.d.ts.map +0 -1
- package/dist/commands/deploy.spec.js +0 -18
- package/dist/commands/deploy.spec.js.map +0 -1
- package/dist/commands/init.spec.d.ts +0 -2
- package/dist/commands/init.spec.d.ts.map +0 -1
- package/dist/commands/init.spec.js +0 -283
- package/dist/commands/init.spec.js.map +0 -1
- package/dist/plugin/build-config.spec.d.ts +0 -2
- package/dist/plugin/build-config.spec.d.ts.map +0 -1
- package/dist/plugin/build-config.spec.js +0 -72
- package/dist/plugin/build-config.spec.js.map +0 -1
- package/dist/utils/asset-collection.spec.d.ts +0 -2
- package/dist/utils/asset-collection.spec.d.ts.map +0 -1
- package/dist/utils/asset-collection.spec.js +0 -155
- package/dist/utils/asset-collection.spec.js.map +0 -1
- package/dist/utils/build-detection.spec.d.ts +0 -2
- package/dist/utils/build-detection.spec.d.ts.map +0 -1
- package/dist/utils/build-detection.spec.js +0 -110
- package/dist/utils/build-detection.spec.js.map +0 -1
- package/dist/utils/config.spec.d.ts +0 -2
- package/dist/utils/config.spec.d.ts.map +0 -1
- package/dist/utils/config.spec.js +0 -167
- package/dist/utils/config.spec.js.map +0 -1
- package/dist/utils/download-template.spec.d.ts +0 -2
- package/dist/utils/download-template.spec.d.ts.map +0 -1
- package/dist/utils/download-template.spec.js +0 -76
- package/dist/utils/download-template.spec.js.map +0 -1
- package/dist/utils/env-management.spec.d.ts +0 -2
- package/dist/utils/env-management.spec.d.ts.map +0 -1
- package/dist/utils/env-management.spec.js +0 -123
- package/dist/utils/env-management.spec.js.map +0 -1
- package/dist/utils/git.spec.d.ts +0 -2
- package/dist/utils/git.spec.d.ts.map +0 -1
- package/dist/utils/git.spec.js +0 -99
- package/dist/utils/git.spec.js.map +0 -1
- package/dist/utils/lambda-config.spec.d.ts +0 -2
- package/dist/utils/lambda-config.spec.d.ts.map +0 -1
- package/dist/utils/lambda-config.spec.js +0 -141
- package/dist/utils/lambda-config.spec.js.map +0 -1
- package/dist/utils/payload-config-ast.spec.d.ts +0 -2
- package/dist/utils/payload-config-ast.spec.d.ts.map +0 -1
- package/dist/utils/payload-config-ast.spec.js +0 -303
- package/dist/utils/payload-config-ast.spec.js.map +0 -1
- package/dist/utils/payload-config-modifier.int.spec.d.ts +0 -2
- package/dist/utils/payload-config-modifier.int.spec.d.ts.map +0 -1
- package/dist/utils/payload-config-modifier.int.spec.js +0 -116
- package/dist/utils/payload-config-modifier.int.spec.js.map +0 -1
- package/dist/utils/payload-config-modifier.spec.d.ts +0 -2
- package/dist/utils/payload-config-modifier.spec.d.ts.map +0 -1
- package/dist/utils/payload-config-modifier.spec.js +0 -162
- package/dist/utils/payload-config-modifier.spec.js.map +0 -1
- package/dist/utils/payload-package-check.spec.d.ts +0 -2
- package/dist/utils/payload-package-check.spec.d.ts.map +0 -1
- package/dist/utils/payload-package-check.spec.js +0 -148
- package/dist/utils/payload-package-check.spec.js.map +0 -1
- package/dist/utils/project.spec.d.ts +0 -2
- package/dist/utils/project.spec.d.ts.map +0 -1
- package/dist/utils/project.spec.js +0 -222
- package/dist/utils/project.spec.js.map +0 -1
- package/dist/utils/s3-upload.spec.d.ts +0 -2
- package/dist/utils/s3-upload.spec.d.ts.map +0 -1
- package/dist/utils/s3-upload.spec.js +0 -140
- package/dist/utils/s3-upload.spec.js.map +0 -1
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
4
|
-
import { detectBuild, getBuildCommand } from './build-detection.js';
|
|
5
|
-
describe('build-detection', ()=>{
|
|
6
|
-
const testDir = path.join(process.cwd(), 'test-fixtures', 'build-detection');
|
|
7
|
-
beforeEach(async ()=>{
|
|
8
|
-
await fs.mkdir(testDir, {
|
|
9
|
-
recursive: true
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
afterEach(async ()=>{
|
|
13
|
-
await fs.rm(testDir, {
|
|
14
|
-
force: true,
|
|
15
|
-
recursive: true
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
describe('detectBuild', ()=>{
|
|
19
|
-
it('should return null when no build exists', async ()=>{
|
|
20
|
-
const result = await detectBuild(testDir);
|
|
21
|
-
expect(result).toBeNull();
|
|
22
|
-
});
|
|
23
|
-
it('should detect valid standalone build', async ()=>{
|
|
24
|
-
// Create .next/standalone/server.js
|
|
25
|
-
const standalonePath = path.join(testDir, '.next', 'standalone');
|
|
26
|
-
await fs.mkdir(standalonePath, {
|
|
27
|
-
recursive: true
|
|
28
|
-
});
|
|
29
|
-
await fs.writeFile(path.join(standalonePath, 'server.js'), '// server');
|
|
30
|
-
// Create .next/BUILD_ID
|
|
31
|
-
await fs.writeFile(path.join(testDir, '.next', 'BUILD_ID'), 'abc123xyz');
|
|
32
|
-
const result = await detectBuild(testDir);
|
|
33
|
-
expect(result).not.toBeNull();
|
|
34
|
-
expect(result.buildId).toBe('abc123xyz');
|
|
35
|
-
expect(result.path).toBe('.next/standalone');
|
|
36
|
-
expect(result.timestamp).toBeInstanceOf(Date);
|
|
37
|
-
});
|
|
38
|
-
it('should return null when BUILD_ID missing', async ()=>{
|
|
39
|
-
const standalonePath = path.join(testDir, '.next', 'standalone');
|
|
40
|
-
await fs.mkdir(standalonePath, {
|
|
41
|
-
recursive: true
|
|
42
|
-
});
|
|
43
|
-
await fs.writeFile(path.join(standalonePath, 'server.js'), '// server');
|
|
44
|
-
const result = await detectBuild(testDir);
|
|
45
|
-
expect(result).toBeNull();
|
|
46
|
-
});
|
|
47
|
-
it('should return null when server.js missing', async ()=>{
|
|
48
|
-
await fs.mkdir(path.join(testDir, '.next'), {
|
|
49
|
-
recursive: true
|
|
50
|
-
});
|
|
51
|
-
await fs.writeFile(path.join(testDir, '.next', 'BUILD_ID'), 'test123');
|
|
52
|
-
const result = await detectBuild(testDir);
|
|
53
|
-
expect(result).toBeNull();
|
|
54
|
-
});
|
|
55
|
-
it('should check for existing lambda.zip', async ()=>{
|
|
56
|
-
const standalonePath = path.join(testDir, '.next', 'standalone');
|
|
57
|
-
await fs.mkdir(standalonePath, {
|
|
58
|
-
recursive: true
|
|
59
|
-
});
|
|
60
|
-
await fs.writeFile(path.join(standalonePath, 'server.js'), '// server');
|
|
61
|
-
await fs.writeFile(path.join(testDir, '.next', 'BUILD_ID'), 'test');
|
|
62
|
-
await fs.writeFile(path.join(testDir, 'lambda.zip'), 'mock zip');
|
|
63
|
-
const result = await detectBuild(testDir);
|
|
64
|
-
expect(result.hasLambdaZip).toBe(true);
|
|
65
|
-
});
|
|
66
|
-
it('should set hasLambdaZip to false when zip missing', async ()=>{
|
|
67
|
-
const standalonePath = path.join(testDir, '.next', 'standalone');
|
|
68
|
-
await fs.mkdir(standalonePath, {
|
|
69
|
-
recursive: true
|
|
70
|
-
});
|
|
71
|
-
await fs.writeFile(path.join(standalonePath, 'server.js'), '// server');
|
|
72
|
-
await fs.writeFile(path.join(testDir, '.next', 'BUILD_ID'), 'test');
|
|
73
|
-
const result = await detectBuild(testDir);
|
|
74
|
-
expect(result.hasLambdaZip).toBe(false);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
describe('getBuildCommand', ()=>{
|
|
78
|
-
it('should return build command from package.json', async ()=>{
|
|
79
|
-
const packageJson = {
|
|
80
|
-
scripts: {
|
|
81
|
-
build: 'next build'
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
await fs.writeFile(path.join(testDir, 'package.json'), JSON.stringify(packageJson, null, 2));
|
|
85
|
-
const command = await getBuildCommand(testDir);
|
|
86
|
-
expect(command).toBe('next build');
|
|
87
|
-
});
|
|
88
|
-
it('should return null when no build script', async ()=>{
|
|
89
|
-
const packageJson = {
|
|
90
|
-
scripts: {
|
|
91
|
-
dev: 'next dev'
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
await fs.writeFile(path.join(testDir, 'package.json'), JSON.stringify(packageJson, null, 2));
|
|
95
|
-
const command = await getBuildCommand(testDir);
|
|
96
|
-
expect(command).toBeNull();
|
|
97
|
-
});
|
|
98
|
-
it('should return null when package.json missing', async ()=>{
|
|
99
|
-
const command = await getBuildCommand(testDir);
|
|
100
|
-
expect(command).toBeNull();
|
|
101
|
-
});
|
|
102
|
-
it('should return null when package.json invalid', async ()=>{
|
|
103
|
-
await fs.writeFile(path.join(testDir, 'package.json'), '{ invalid json');
|
|
104
|
-
const command = await getBuildCommand(testDir);
|
|
105
|
-
expect(command).toBeNull();
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
//# sourceMappingURL=build-detection.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/build-detection.spec.ts"],"sourcesContent":["import fs from 'fs/promises'\nimport path from 'path'\nimport { afterEach, beforeEach, describe, expect, it } from 'vitest'\n\nimport { detectBuild, getBuildCommand } from './build-detection.js'\n\ndescribe('build-detection', () => {\n const testDir = path.join(process.cwd(), 'test-fixtures', 'build-detection')\n\n beforeEach(async () => {\n await fs.mkdir(testDir, { recursive: true })\n })\n\n afterEach(async () => {\n await fs.rm(testDir, { force: true, recursive: true })\n })\n\n describe('detectBuild', () => {\n it('should return null when no build exists', async () => {\n const result = await detectBuild(testDir)\n expect(result).toBeNull()\n })\n\n it('should detect valid standalone build', async () => {\n // Create .next/standalone/server.js\n const standalonePath = path.join(testDir, '.next', 'standalone')\n await fs.mkdir(standalonePath, { recursive: true })\n await fs.writeFile(path.join(standalonePath, 'server.js'), '// server')\n\n // Create .next/BUILD_ID\n await fs.writeFile(path.join(testDir, '.next', 'BUILD_ID'), 'abc123xyz')\n\n const result = await detectBuild(testDir)\n\n expect(result).not.toBeNull()\n expect(result!.buildId).toBe('abc123xyz')\n expect(result!.path).toBe('.next/standalone')\n expect(result!.timestamp).toBeInstanceOf(Date)\n })\n\n it('should return null when BUILD_ID missing', async () => {\n const standalonePath = path.join(testDir, '.next', 'standalone')\n await fs.mkdir(standalonePath, { recursive: true })\n await fs.writeFile(path.join(standalonePath, 'server.js'), '// server')\n\n const result = await detectBuild(testDir)\n expect(result).toBeNull()\n })\n\n it('should return null when server.js missing', async () => {\n await fs.mkdir(path.join(testDir, '.next'), { recursive: true })\n await fs.writeFile(path.join(testDir, '.next', 'BUILD_ID'), 'test123')\n\n const result = await detectBuild(testDir)\n expect(result).toBeNull()\n })\n\n it('should check for existing lambda.zip', async () => {\n const standalonePath = path.join(testDir, '.next', 'standalone')\n await fs.mkdir(standalonePath, { recursive: true })\n await fs.writeFile(path.join(standalonePath, 'server.js'), '// server')\n await fs.writeFile(path.join(testDir, '.next', 'BUILD_ID'), 'test')\n await fs.writeFile(path.join(testDir, 'lambda.zip'), 'mock zip')\n\n const result = await detectBuild(testDir)\n\n expect(result!.hasLambdaZip).toBe(true)\n })\n\n it('should set hasLambdaZip to false when zip missing', async () => {\n const standalonePath = path.join(testDir, '.next', 'standalone')\n await fs.mkdir(standalonePath, { recursive: true })\n await fs.writeFile(path.join(standalonePath, 'server.js'), '// server')\n await fs.writeFile(path.join(testDir, '.next', 'BUILD_ID'), 'test')\n\n const result = await detectBuild(testDir)\n\n expect(result!.hasLambdaZip).toBe(false)\n })\n })\n\n describe('getBuildCommand', () => {\n it('should return build command from package.json', async () => {\n const packageJson = {\n scripts: {\n build: 'next build',\n },\n }\n await fs.writeFile(path.join(testDir, 'package.json'), JSON.stringify(packageJson, null, 2))\n\n const command = await getBuildCommand(testDir)\n expect(command).toBe('next build')\n })\n\n it('should return null when no build script', async () => {\n const packageJson = {\n scripts: {\n dev: 'next dev',\n },\n }\n await fs.writeFile(path.join(testDir, 'package.json'), JSON.stringify(packageJson, null, 2))\n\n const command = await getBuildCommand(testDir)\n expect(command).toBeNull()\n })\n\n it('should return null when package.json missing', async () => {\n const command = await getBuildCommand(testDir)\n expect(command).toBeNull()\n })\n\n it('should return null when package.json invalid', async () => {\n await fs.writeFile(path.join(testDir, 'package.json'), '{ invalid json')\n\n const command = await getBuildCommand(testDir)\n expect(command).toBeNull()\n })\n })\n})\n"],"names":["fs","path","afterEach","beforeEach","describe","expect","it","detectBuild","getBuildCommand","testDir","join","process","cwd","mkdir","recursive","rm","force","result","toBeNull","standalonePath","writeFile","not","buildId","toBe","timestamp","toBeInstanceOf","Date","hasLambdaZip","packageJson","scripts","build","JSON","stringify","command","dev"],"mappings":"AAAA,OAAOA,QAAQ,cAAa;AAC5B,OAAOC,UAAU,OAAM;AACvB,SAASC,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAEpE,SAASC,WAAW,EAAEC,eAAe,QAAQ,uBAAsB;AAEnEJ,SAAS,mBAAmB;IAC1B,MAAMK,UAAUR,KAAKS,IAAI,CAACC,QAAQC,GAAG,IAAI,iBAAiB;IAE1DT,WAAW;QACT,MAAMH,GAAGa,KAA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C,MAAMsB,cAAc;gBAClBC,SAAS;oBACPK,KAAK;gBACP;YACF;YACA,MAAMlC,GAAGoB,SAAS,CAACnB,KAAKS,IAAI,CAACD,SAAS,iBAAiBsB,KAAKC,SAAS,CAACJ,aAAa,MAAM;YAEzF,MAAMK,UAAU,MAAMzB,gBAAgBC;YACtCJ,OAAO4B,SAASf,QAAQ;QAC1B;QAEAZ,GAAG,gDAAgD;YACjD,MAAM2B,UAAU,MAAMzB,gBAAgBC;YACtCJ,OAAO4B,SAASf,QAAQ;QAC1B;QAEAZ,GAAG,gDAAgD;YACjD,MAAMN,GAAGoB,SAAS,CAACnB,KAAKS,IAAI,CAACD,SAAS,iBAAiB;YAEvD,MAAMwB,UAAU,MAAMzB,gBAAgBC;YACtCJ,OAAO4B,SAASf,QAAQ;QAC1B;IACF;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.spec.d.ts","sourceRoot":"","sources":["../../src/utils/config.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
4
|
-
import { ensureGitignore, hasFigmaConfig, readFigmaConfig, writeFigmaConfig } from './config.js';
|
|
5
|
-
describe('config utilities', ()=>{
|
|
6
|
-
let testDir;
|
|
7
|
-
beforeEach(async ()=>{
|
|
8
|
-
// Create unique temp directory for each test
|
|
9
|
-
testDir = path.join(process.cwd(), '.test-tmp', `config-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`);
|
|
10
|
-
await fs.mkdir(testDir, {
|
|
11
|
-
recursive: true
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
afterEach(async ()=>{
|
|
15
|
-
// Clean up test directory
|
|
16
|
-
try {
|
|
17
|
-
await fs.rm(testDir, {
|
|
18
|
-
force: true,
|
|
19
|
-
recursive: true
|
|
20
|
-
});
|
|
21
|
-
} catch {
|
|
22
|
-
// Ignore cleanup errors
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
describe('writeFigmaConfig', ()=>{
|
|
26
|
-
it('should write config to figma.config.json', async ()=>{
|
|
27
|
-
const config = {
|
|
28
|
-
domain: 'test-cms.figmacms.com',
|
|
29
|
-
tenantId: 'tenant_test123'
|
|
30
|
-
};
|
|
31
|
-
await writeFigmaConfig(config, testDir);
|
|
32
|
-
const filePath = path.join(testDir, 'figma.config.json');
|
|
33
|
-
const content = await fs.readFile(filePath, 'utf-8');
|
|
34
|
-
const parsed = JSON.parse(content);
|
|
35
|
-
expect(parsed).toEqual(config);
|
|
36
|
-
});
|
|
37
|
-
it('should format JSON with 2 space indentation', async ()=>{
|
|
38
|
-
const config = {
|
|
39
|
-
domain: 'format.figmacms.com',
|
|
40
|
-
tenantId: 'tenant_format'
|
|
41
|
-
};
|
|
42
|
-
await writeFigmaConfig(config, testDir);
|
|
43
|
-
const filePath = path.join(testDir, 'figma.config.json');
|
|
44
|
-
const content = await fs.readFile(filePath, 'utf-8');
|
|
45
|
-
// Check indentation
|
|
46
|
-
expect(content).toContain(' "tenantId"');
|
|
47
|
-
expect(content).toContain(' "domain"');
|
|
48
|
-
});
|
|
49
|
-
it('should include subdomain when provided', async ()=>{
|
|
50
|
-
const config = {
|
|
51
|
-
domain: 'sub.figmacms.com',
|
|
52
|
-
subdomain: 'custom',
|
|
53
|
-
tenantId: 'tenant_sub'
|
|
54
|
-
};
|
|
55
|
-
await writeFigmaConfig(config, testDir);
|
|
56
|
-
const read = await readFigmaConfig(testDir);
|
|
57
|
-
expect(read?.subdomain).toBe('custom');
|
|
58
|
-
});
|
|
59
|
-
it('should throw error if directory does not exist', async ()=>{
|
|
60
|
-
const config = {
|
|
61
|
-
domain: 'fail.figmacms.com',
|
|
62
|
-
tenantId: 'tenant_fail'
|
|
63
|
-
};
|
|
64
|
-
const nonExistentDir = path.join(testDir, 'does-not-exist');
|
|
65
|
-
await expect(writeFigmaConfig(config, nonExistentDir)).rejects.toThrow();
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
describe('readFigmaConfig', ()=>{
|
|
69
|
-
it('should read existing config', async ()=>{
|
|
70
|
-
const config = {
|
|
71
|
-
domain: 'read.figmacms.com',
|
|
72
|
-
tenantId: 'tenant_read'
|
|
73
|
-
};
|
|
74
|
-
await writeFigmaConfig(config, testDir);
|
|
75
|
-
const read = await readFigmaConfig(testDir);
|
|
76
|
-
expect(read).toEqual(config);
|
|
77
|
-
});
|
|
78
|
-
it('should return null if config does not exist', async ()=>{
|
|
79
|
-
const read = await readFigmaConfig(testDir);
|
|
80
|
-
expect(read).toBeNull();
|
|
81
|
-
});
|
|
82
|
-
it('should throw error if config is invalid JSON', async ()=>{
|
|
83
|
-
const filePath = path.join(testDir, 'figma.config.json');
|
|
84
|
-
await fs.writeFile(filePath, 'not valid json{', 'utf-8');
|
|
85
|
-
await expect(readFigmaConfig(testDir)).rejects.toThrow('Failed to read figma.config.json');
|
|
86
|
-
});
|
|
87
|
-
it('should handle config with all optional fields', async ()=>{
|
|
88
|
-
const config = {
|
|
89
|
-
domain: 'full.figmacms.com',
|
|
90
|
-
subdomain: 'custom-sub',
|
|
91
|
-
tenantId: 'tenant_full'
|
|
92
|
-
};
|
|
93
|
-
await writeFigmaConfig(config, testDir);
|
|
94
|
-
const read = await readFigmaConfig(testDir);
|
|
95
|
-
expect(read).toEqual(config);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
describe('hasFigmaConfig', ()=>{
|
|
99
|
-
it('should return true if config exists', async ()=>{
|
|
100
|
-
const config = {
|
|
101
|
-
domain: 'has.figmacms.com',
|
|
102
|
-
tenantId: 'tenant_has'
|
|
103
|
-
};
|
|
104
|
-
await writeFigmaConfig(config, testDir);
|
|
105
|
-
const has = await hasFigmaConfig(testDir);
|
|
106
|
-
expect(has).toBe(true);
|
|
107
|
-
});
|
|
108
|
-
it('should return false if config does not exist', async ()=>{
|
|
109
|
-
const has = await hasFigmaConfig(testDir);
|
|
110
|
-
expect(has).toBe(false);
|
|
111
|
-
});
|
|
112
|
-
it('should handle directory that does not exist', async ()=>{
|
|
113
|
-
const nonExistentDir = path.join(testDir, 'does-not-exist');
|
|
114
|
-
const has = await hasFigmaConfig(nonExistentDir);
|
|
115
|
-
expect(has).toBe(false);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
describe('ensureGitignore', ()=>{
|
|
119
|
-
it('should create .gitignore if it does not exist', async ()=>{
|
|
120
|
-
await ensureGitignore(testDir, [
|
|
121
|
-
'node_modules',
|
|
122
|
-
'.env'
|
|
123
|
-
]);
|
|
124
|
-
const filePath = path.join(testDir, '.gitignore');
|
|
125
|
-
const content = await fs.readFile(filePath, 'utf-8');
|
|
126
|
-
expect(content).toContain('node_modules');
|
|
127
|
-
expect(content).toContain('.env');
|
|
128
|
-
expect(content).toContain('# Figma CMS');
|
|
129
|
-
});
|
|
130
|
-
it('should append to existing .gitignore', async ()=>{
|
|
131
|
-
const filePath = path.join(testDir, '.gitignore');
|
|
132
|
-
await fs.writeFile(filePath, '# Existing content\ndist\n', 'utf-8');
|
|
133
|
-
await ensureGitignore(testDir, [
|
|
134
|
-
'node_modules'
|
|
135
|
-
]);
|
|
136
|
-
const content = await fs.readFile(filePath, 'utf-8');
|
|
137
|
-
expect(content).toContain('# Existing content');
|
|
138
|
-
expect(content).toContain('dist');
|
|
139
|
-
expect(content).toContain('node_modules');
|
|
140
|
-
expect(content).toContain('# Figma CMS');
|
|
141
|
-
});
|
|
142
|
-
it('should not add duplicate entries', async ()=>{
|
|
143
|
-
await ensureGitignore(testDir, [
|
|
144
|
-
'node_modules',
|
|
145
|
-
'.env'
|
|
146
|
-
]);
|
|
147
|
-
await ensureGitignore(testDir, [
|
|
148
|
-
'node_modules',
|
|
149
|
-
'dist'
|
|
150
|
-
]);
|
|
151
|
-
const filePath = path.join(testDir, '.gitignore');
|
|
152
|
-
const content = await fs.readFile(filePath, 'utf-8');
|
|
153
|
-
// Count occurrences of node_modules
|
|
154
|
-
const matches = content.match(/node_modules/g);
|
|
155
|
-
expect(matches?.length).toBe(1);
|
|
156
|
-
});
|
|
157
|
-
it('should handle empty entries array', async ()=>{
|
|
158
|
-
await ensureGitignore(testDir, []);
|
|
159
|
-
const filePath = path.join(testDir, '.gitignore');
|
|
160
|
-
const exists = await fs.access(filePath).then(()=>true).catch(()=>false);
|
|
161
|
-
// Should not create file if no entries to add
|
|
162
|
-
expect(exists).toBe(false);
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
//# sourceMappingURL=config.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/config.spec.ts"],"sourcesContent":["import fs from 'fs/promises'\nimport path from 'path'\nimport { afterEach, beforeEach, describe, expect, it } from 'vitest'\n\nimport type { FigmaConfig } from '../types/config.js'\n\nimport { ensureGitignore, hasFigmaConfig, readFigmaConfig, writeFigmaConfig } from './config.js'\n\ndescribe('config utilities', () => {\n let testDir: string\n\n beforeEach(async () => {\n // Create unique temp directory for each test\n testDir = path.join(\n process.cwd(),\n '.test-tmp',\n `config-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`,\n )\n await fs.mkdir(testDir, { recursive: true })\n })\n\n afterEach(async () => {\n // Clean up test directory\n try {\n await fs.rm(testDir, { force: true, recursive: true })\n } catch {\n // Ignore cleanup errors\n }\n })\n\n describe('writeFigmaConfig', () => {\n it('should write config to figma.config.json', async () => {\n const config: FigmaConfig = {\n domain: 'test-cms.figmacms.com',\n tenantId: 'tenant_test123',\n }\n\n await writeFigmaConfig(config, testDir)\n\n const filePath = path.join(testDir, 'figma.config.json')\n const content = await fs.readFile(filePath, 'utf-8')\n const parsed = JSON.parse(content)\n\n expect(parsed).toEqual(config)\n })\n\n it('should format JSON with 2 space indentation', async () => {\n const config: FigmaConfig = {\n domain: 'format.figmacms.com',\n tenantId: 'tenant_format',\n }\n\n await writeFigmaConfig(config, testDir)\n\n const filePath = path.join(testDir, 'figma.config.json')\n const content = await fs.readFile(filePath, 'utf-8')\n\n // Check indentation\n expect(content).toContain(' \"tenantId\"')\n expect(content).toContain(' \"domain\"')\n })\n\n it('should include subdomain when provided', async () => {\n const config: FigmaConfig = {\n domain: 'sub.figmacms.com',\n subdomain: 'custom',\n tenantId: 'tenant_sub',\n }\n\n await writeFigmaConfig(config, testDir)\n\n const read = await readFigmaConfig(testDir)\n expect(read?.subdomain).toBe('custom')\n })\n\n it('should throw error if directory does not exist', async () => {\n const config: FigmaConfig = {\n domain: 'fail.figmacms.com',\n tenantId: 'tenant_fail',\n }\n\n const nonExistentDir = path.join(testDir, 'does-not-exist')\n\n await expect(writeFigmaConfig(config, nonExistentDir)).rejects.toThrow()\n })\n })\n\n describe('readFigmaConfig', () => {\n it('should read existing config', async () => {\n const config: FigmaConfig = {\n domain: 'read.figmacms.com',\n tenantId: 'tenant_read',\n }\n\n await writeFigmaConfig(config, testDir)\n\n const read = await readFigmaConfig(testDir)\n\n expect(read).toEqual(config)\n })\n\n it('should return null if config does not exist', async () => {\n const read = await readFigmaConfig(testDir)\n\n expect(read).toBeNull()\n })\n\n it('should throw error if config is invalid JSON', async () => {\n const filePath = path.join(testDir, 'figma.config.json')\n await fs.writeFile(filePath, 'not valid json{', 'utf-8')\n\n await expect(readFigmaConfig(testDir)).rejects.toThrow('Failed to read figma.config.json')\n })\n\n it('should handle config with all optional fields', async () => {\n const config: FigmaConfig = {\n domain: 'full.figmacms.com',\n subdomain: 'custom-sub',\n tenantId: 'tenant_full',\n }\n\n await writeFigmaConfig(config, testDir)\n const read = await readFigmaConfig(testDir)\n\n expect(read).toEqual(config)\n })\n })\n\n describe('hasFigmaConfig', () => {\n it('should return true if config exists', async () => {\n const config: FigmaConfig = {\n domain: 'has.figmacms.com',\n tenantId: 'tenant_has',\n }\n\n await writeFigmaConfig(config, testDir)\n\n const has = await hasFigmaConfig(testDir)\n\n expect(has).toBe(true)\n })\n\n it('should return false if config does not exist', async () => {\n const has = await hasFigmaConfig(testDir)\n\n expect(has).toBe(false)\n })\n\n it('should handle directory that does not exist', async () => {\n const nonExistentDir = path.join(testDir, 'does-not-exist')\n\n const has = await hasFigmaConfig(nonExistentDir)\n\n expect(has).toBe(false)\n })\n })\n\n describe('ensureGitignore', () => {\n it('should create .gitignore if it does not exist', async () => {\n await ensureGitignore(testDir, ['node_modules', '.env'])\n\n const filePath = path.join(testDir, '.gitignore')\n const content = await fs.readFile(filePath, 'utf-8')\n\n expect(content).toContain('node_modules')\n expect(content).toContain('.env')\n expect(content).toContain('# Figma CMS')\n })\n\n it('should append to existing .gitignore', async () => {\n const filePath = path.join(testDir, '.gitignore')\n await fs.writeFile(filePath, '# Existing content\\ndist\\n', 'utf-8')\n\n await ensureGitignore(testDir, ['node_modules'])\n\n const content = await fs.readFile(filePath, 'utf-8')\n\n expect(content).toContain('# Existing content')\n expect(content).toContain('dist')\n expect(content).toContain('node_modules')\n expect(content).toContain('# Figma CMS')\n })\n\n it('should not add duplicate entries', async () => {\n await ensureGitignore(testDir, ['node_modules', '.env'])\n await ensureGitignore(testDir, ['node_modules', 'dist'])\n\n const filePath = path.join(testDir, '.gitignore')\n const content = await fs.readFile(filePath, 'utf-8')\n\n // Count occurrences of node_modules\n const matches = content.match(/node_modules/g)\n expect(matches?.length).toBe(1)\n })\n\n it('should handle empty entries array', async () => {\n await ensureGitignore(testDir, [])\n\n const filePath = path.join(testDir, '.gitignore')\n const exists = await fs\n .access(filePath)\n .then(() => true)\n .catch(() => false)\n\n // Should not create file if no entries to add\n expect(exists).toBe(false)\n })\n })\n})\n"],"names":["fs","path","afterEach","beforeEach","describe","expect","it","ensureGitignore","hasFigmaConfig","readFigmaConfig","writeFigmaConfig","testDir","join","process","cwd","Date","now","Math","random","toString","substring","mkdir","recursive","rm","force","config","domain","tenantId","filePath","content","readFile","parsed","JSON","parse","toEqual","toContain","subdomain","read","toBe","nonExistentDir","rejects","toThrow","toBeNull","write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I,SAAS;gBAAC;gBAAgB;aAAO;YACvD,MAAMJ,gBAAgBI,SAAS;gBAAC;gBAAgB;aAAO;YAEvD,MAAMiB,WAAW3B,KAAKW,IAAI,CAACD,SAAS;YACpC,MAAMkB,UAAU,MAAM7B,GAAG8B,QAAQ,CAACF,UAAU;YAE5C,oCAAoC;YACpC,MAAMiB,UAAUhB,QAAQiB,KAAK,CAAC;YAC9BzC,OAAOwC,SAASE,QAAQT,IAAI,CAAC;QAC/B;QAEAhC,GAAG,qCAAqC;YACtC,MAAMC,gBAAgBI,SAAS,EAAE;YAEjC,MAAMiB,WAAW3B,KAAKW,IAAI,CAACD,SAAS;YACpC,MAAMqC,SAAS,MAAMhD,GAClBiD,MAAM,CAACrB,UACPsB,IAAI,CAAC,IAAM,MACXC,KAAK,CAAC,IAAM;YAEf,8CAA8C;YAC9C9C,OAAO2C,QAAQV,IAAI,CAAC;QACtB;IACF;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"download-template.spec.d.ts","sourceRoot":"","sources":["../../src/utils/download-template.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
-
import { downloadTemplateFromGitHub, TemplateDownloadError } from './download-template.js';
|
|
5
|
-
describe('downloadTemplateFromGitHub', ()=>{
|
|
6
|
-
const testTempDir = path.join(process.cwd(), '.test-temp-download');
|
|
7
|
-
beforeEach(async ()=>{
|
|
8
|
-
await fs.mkdir(testTempDir, {
|
|
9
|
-
recursive: true
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
afterEach(async ()=>{
|
|
13
|
-
await fs.rm(testTempDir, {
|
|
14
|
-
force: true,
|
|
15
|
-
recursive: true
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
it('should download and extract template to target directory', async ()=>{
|
|
19
|
-
const targetDir = path.join(testTempDir, 'test-project');
|
|
20
|
-
await downloadTemplateFromGitHub(targetDir);
|
|
21
|
-
// Verify essential files exist
|
|
22
|
-
const packageJson = await fs.readFile(path.join(targetDir, 'package.json'), 'utf-8');
|
|
23
|
-
expect(packageJson).toContain('payload');
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
describe('downloadTemplateFromGitHub - retry logic', ()=>{
|
|
27
|
-
const testTempDir = path.join(process.cwd(), '.test-temp-download');
|
|
28
|
-
beforeEach(async ()=>{
|
|
29
|
-
await fs.mkdir(testTempDir, {
|
|
30
|
-
recursive: true
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
afterEach(async ()=>{
|
|
34
|
-
await fs.rm(testTempDir, {
|
|
35
|
-
force: true,
|
|
36
|
-
recursive: true
|
|
37
|
-
});
|
|
38
|
-
vi.restoreAllMocks();
|
|
39
|
-
});
|
|
40
|
-
it('should retry on network failure up to 3 times', async ()=>{
|
|
41
|
-
const targetDir = path.join(testTempDir, 'retry-test');
|
|
42
|
-
// Mock fetch to fail twice then succeed
|
|
43
|
-
let attemptCount = 0;
|
|
44
|
-
const originalFetch = global.fetch;
|
|
45
|
-
global.fetch = vi.fn(async (...args)=>{
|
|
46
|
-
attemptCount++;
|
|
47
|
-
if (attemptCount < 3) {
|
|
48
|
-
// Simulate network error
|
|
49
|
-
return {
|
|
50
|
-
ok: false,
|
|
51
|
-
status: 500,
|
|
52
|
-
statusText: 'Server Error'
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
// Third attempt succeeds
|
|
56
|
-
return await originalFetch(...args);
|
|
57
|
-
});
|
|
58
|
-
await downloadTemplateFromGitHub(targetDir);
|
|
59
|
-
// Expect at least 3 calls (2 failures + 1 success)
|
|
60
|
-
expect(attemptCount).toBeGreaterThanOrEqual(3);
|
|
61
|
-
});
|
|
62
|
-
it('should throw error after 3 failed attempts', async ()=>{
|
|
63
|
-
const targetDir = path.join(testTempDir, 'fail-test');
|
|
64
|
-
// Mock fetch to always fail
|
|
65
|
-
global.fetch = vi.fn(()=>{
|
|
66
|
-
return Promise.resolve({
|
|
67
|
-
ok: false,
|
|
68
|
-
status: 500,
|
|
69
|
-
statusText: 'Server Error'
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
await expect(downloadTemplateFromGitHub(targetDir)).rejects.toThrow(TemplateDownloadError);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
//# sourceMappingURL=download-template.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/download-template.spec.ts"],"sourcesContent":["import fs from 'fs/promises'\nimport path from 'path'\nimport { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'\n\nimport { downloadTemplateFromGitHub, TemplateDownloadError } from './download-template.js'\n\ndescribe('downloadTemplateFromGitHub', () => {\n const testTempDir = path.join(process.cwd(), '.test-temp-download')\n\n beforeEach(async () => {\n await fs.mkdir(testTempDir, { recursive: true })\n })\n\n afterEach(async () => {\n await fs.rm(testTempDir, { force: true, recursive: true })\n })\n\n it('should download and extract template to target directory', async () => {\n const targetDir = path.join(testTempDir, 'test-project')\n\n await downloadTemplateFromGitHub(targetDir)\n\n // Verify essential files exist\n const packageJson = await fs.readFile(path.join(targetDir, 'package.json'), 'utf-8')\n expect(packageJson).toContain('payload')\n })\n})\n\ndescribe('downloadTemplateFromGitHub - retry logic', () => {\n const testTempDir = path.join(process.cwd(), '.test-temp-download')\n\n beforeEach(async () => {\n await fs.mkdir(testTempDir, { recursive: true })\n })\n\n afterEach(async () => {\n await fs.rm(testTempDir, { force: true, recursive: true })\n vi.restoreAllMocks()\n })\n\n it('should retry on network failure up to 3 times', async () => {\n const targetDir = path.join(testTempDir, 'retry-test')\n\n // Mock fetch to fail twice then succeed\n let attemptCount = 0\n const originalFetch = global.fetch\n global.fetch = vi.fn(async (...args: Parameters<typeof fetch>) => {\n attemptCount++\n if (attemptCount < 3) {\n // Simulate network error\n return {\n ok: false,\n status: 500,\n statusText: 'Server Error',\n } as Response\n }\n // Third attempt succeeds\n return await originalFetch(...args)\n })\n\n await downloadTemplateFromGitHub(targetDir)\n\n // Expect at least 3 calls (2 failures + 1 success)\n expect(attemptCount).toBeGreaterThanOrEqual(3)\n })\n\n it('should throw error after 3 failed attempts', async () => {\n const targetDir = path.join(testTempDir, 'fail-test')\n\n // Mock fetch to always fail\n global.fetch = vi.fn(() => {\n return Promise.resolve({\n ok: false,\n status: 500,\n statusText: 'Server Error',\n } as Response)\n })\n\n await expect(downloadTemplateFromGitHub(targetDir)).rejects.toThrow(TemplateDownloadError)\n })\n})\n"],"names":["fs","path","afterEach","beforeEach","describe","expect","it","vi","downloadTemplateFromGitHub","TemplateDownloadError","testTempDir","join","process","cwd","mkdir","recursive","rm","force","targetDir","packageJson","readFile","toContain","restoreAllMocks","attemptCount","originalFetch","global","fetch","fn","args","ok","status","statusText","toBeGreaterThanOrEqual","Promise","resolve","rejects","toThrow"],"mappings":"AAAA,OAAOA,QAAQ,cAAa;AAC5B,OAAOC,UAAU,OAAM;AACvB,SAASC,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAQ;AAExE,SAASC,0BAA0B,EAAEC,qBAAqB,QAAQ,yBAAwB;AAE1FL,SAAS,8BAA8B;IACrC,MAAMM,cAAcT,KAAKU,IAAI,CAACC,QAAQC,GAAG,IAAI;IAE7CV,WAAW;QACT,MAAMH,GAAGc,KAAK,CAACJ,aAAa;YAAEK,WAAW;QAAK;IAChD;IAEAb,UAAU;QACR,MAAMF,GAAGgB,EAAE,CAACN,aAAa;YAAEO,OAAO;YAAMF,WAAW;QAAK;IAC1D;IAEAT,GAAG,4DAA4D;QAC7D,MAAMY,YAAYjB,KAAKU,IAAI,CAACD,aAAa;QAEzC,MAAMF,2BAA2BU;QAEjC,+BAA+B;QAC/B,MAAMC,cAAc,MAAMnB,GAAGoB,QAAQ,CAACnB,KAAKU,IAAI,CAACO,WAAW,iBAAiB;QAC5Eb,OAAOc,aAAaE,SAAS,CAAC;IAChC;AACF;AAEAjB,SAAS,4CAA4C;IACnD,MAAMM,cAAcT,KAAKU,IAAI,CAACC,QAAQC,GAAG,IAAI;IAE7CV,WAAW;QACT,MAAMH,GAAGc,KAAK,CAACJ,aAAa;YAAEK,WAAW;QAAK;IAChD;IAEAb,UAAU;QACR,MAAMF,GAAGgB,EAAE,CAACN,aAAa;YAAEO,OAAO;YAAMF,WAAW;QAAK;QACxDR,GAAGe,eAAe;IACpB;IAEAhB,GAAG,iDAAiD;QAClD,MAAMY,YAAYjB,KAAKU,IAAI,CAACD,aAAa;QAEzC,wCAAwC;QACxC,IAAIa,eAAe;QACnB,MAAMC,gBAAgBC,OAAOC,KAAK;QAClCD,OAAOC,KAAK,GAAGnB,GAAGoB,EAAE,CAAC,OAAO,GAAGC;YAC7BL;YACA,IAAIA,eAAe,GAAG;gBACpB,yBAAyB;gBACzB,OAAO;oBACLM,IAAI;oBACJC,QAAQ;oBACRC,YAAY;gBACd;YACF;YACA,yBAAyB;YACzB,OAAO,MAAMP,iBAAiBI;QAChC;QAEA,MAAMpB,2BAA2BU;QAEjC,mDAAmD;QACnDb,OAAOkB,cAAcS,sBAAsB,CAAC;IAC9C;IAEA1B,GAAG,8CAA8C;QAC/C,MAAMY,YAAYjB,KAAKU,IAAI,CAACD,aAAa;QAEzC,4BAA4B;QAC5Be,OAAOC,KAAK,GAAGnB,GAAGoB,EAAE,CAAC;YACnB,OAAOM,QAAQC,OAAO,CAAC;gBACrBL,IAAI;gBACJC,QAAQ;gBACRC,YAAY;YACd;QACF;QAEA,MAAM1B,OAAOG,2BAA2BU,YAAYiB,OAAO,CAACC,OAAO,CAAC3B;IACtE;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"env-management.spec.d.ts","sourceRoot":"","sources":["../../src/utils/env-management.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
4
|
-
import { generateSecret, manageEnvFiles } from './env-management.js';
|
|
5
|
-
describe('env-management', ()=>{
|
|
6
|
-
describe('generateSecret', ()=>{
|
|
7
|
-
it('should generate a 24-character hex string', ()=>{
|
|
8
|
-
const secret = generateSecret();
|
|
9
|
-
expect(secret).toHaveLength(24);
|
|
10
|
-
expect(secret).toMatch(/^[0-9a-f]{24}$/);
|
|
11
|
-
});
|
|
12
|
-
it('should generate unique secrets', ()=>{
|
|
13
|
-
const secret1 = generateSecret();
|
|
14
|
-
const secret2 = generateSecret();
|
|
15
|
-
expect(secret1).not.toBe(secret2);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
describe('manageEnvFiles', ()=>{
|
|
19
|
-
let testDir;
|
|
20
|
-
beforeEach(async ()=>{
|
|
21
|
-
testDir = path.join(process.cwd(), '.test-env-management', `test-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`);
|
|
22
|
-
await fs.mkdir(testDir, {
|
|
23
|
-
recursive: true
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
afterEach(async ()=>{
|
|
27
|
-
try {
|
|
28
|
-
await fs.rm(testDir, {
|
|
29
|
-
force: true,
|
|
30
|
-
recursive: true
|
|
31
|
-
});
|
|
32
|
-
} catch {
|
|
33
|
-
// Ignore cleanup errors
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
it('should create .env with PAYLOAD_SECRET when no files exist', async ()=>{
|
|
37
|
-
const secret = await manageEnvFiles(testDir);
|
|
38
|
-
expect(secret).toHaveLength(24);
|
|
39
|
-
expect(secret).toMatch(/^[0-9a-f]{24}$/);
|
|
40
|
-
const envContent = await fs.readFile(path.join(testDir, '.env'), 'utf-8');
|
|
41
|
-
expect(envContent).toContain(`PAYLOAD_SECRET=${secret}`);
|
|
42
|
-
});
|
|
43
|
-
it('should create .env from .env.example with PAYLOAD_SECRET', async ()=>{
|
|
44
|
-
const envExampleContent = `# Example environment variables
|
|
45
|
-
DATABASE_URI=mongodb://localhost/mydb
|
|
46
|
-
NEXT_PUBLIC_API_URL=http://localhost:3000
|
|
47
|
-
PAYLOAD_SECRET=
|
|
48
|
-
`;
|
|
49
|
-
await fs.writeFile(path.join(testDir, '.env.example'), envExampleContent);
|
|
50
|
-
const secret = await manageEnvFiles(testDir);
|
|
51
|
-
const envContent = await fs.readFile(path.join(testDir, '.env'), 'utf-8');
|
|
52
|
-
expect(envContent).toContain(`PAYLOAD_SECRET=${secret}`);
|
|
53
|
-
expect(envContent).toContain('DATABASE_URI=mongodb://localhost/mydb');
|
|
54
|
-
expect(envContent).toContain('NEXT_PUBLIC_API_URL=http://localhost:3000');
|
|
55
|
-
});
|
|
56
|
-
it('should not overwrite existing .env with PAYLOAD_SECRET', async ()=>{
|
|
57
|
-
const existingSecret = 'existing-secret-value';
|
|
58
|
-
const existingEnv = `DATABASE_URI=mongodb://localhost/mydb
|
|
59
|
-
PAYLOAD_SECRET=${existingSecret}
|
|
60
|
-
NEXT_PUBLIC_API_URL=http://localhost:3000
|
|
61
|
-
`;
|
|
62
|
-
await fs.writeFile(path.join(testDir, '.env'), existingEnv);
|
|
63
|
-
await manageEnvFiles(testDir);
|
|
64
|
-
const envContent = await fs.readFile(path.join(testDir, '.env'), 'utf-8');
|
|
65
|
-
expect(envContent).toContain(`PAYLOAD_SECRET=${existingSecret}`);
|
|
66
|
-
expect(envContent).not.toMatch(/PAYLOAD_SECRET=[0-9a-f]{24}/);
|
|
67
|
-
});
|
|
68
|
-
it('should add PAYLOAD_SECRET to existing .env that lacks it', async ()=>{
|
|
69
|
-
const existingEnv = `DATABASE_URI=mongodb://localhost/mydb
|
|
70
|
-
NEXT_PUBLIC_API_URL=http://localhost:3000
|
|
71
|
-
`;
|
|
72
|
-
await fs.writeFile(path.join(testDir, '.env'), existingEnv);
|
|
73
|
-
const secret = await manageEnvFiles(testDir);
|
|
74
|
-
const envContent = await fs.readFile(path.join(testDir, '.env'), 'utf-8');
|
|
75
|
-
expect(envContent).toContain(`PAYLOAD_SECRET=${secret}`);
|
|
76
|
-
expect(envContent).toContain('DATABASE_URI=mongodb://localhost/mydb');
|
|
77
|
-
});
|
|
78
|
-
it('should handle PAYLOAD_SECRET_KEY as alias', async ()=>{
|
|
79
|
-
const envExampleContent = `PAYLOAD_SECRET_KEY=
|
|
80
|
-
DATABASE_URI=mongodb://localhost/mydb
|
|
81
|
-
`;
|
|
82
|
-
await fs.writeFile(path.join(testDir, '.env.example'), envExampleContent);
|
|
83
|
-
const secret = await manageEnvFiles(testDir);
|
|
84
|
-
const envContent = await fs.readFile(path.join(testDir, '.env'), 'utf-8');
|
|
85
|
-
// Should normalize to PAYLOAD_SECRET
|
|
86
|
-
expect(envContent).toContain(`PAYLOAD_SECRET=${secret}`);
|
|
87
|
-
expect(envContent).toContain('DATABASE_URI=mongodb://localhost/mydb');
|
|
88
|
-
});
|
|
89
|
-
it('should remove duplicate PAYLOAD_SECRET entries', async ()=>{
|
|
90
|
-
const envExampleContent = `PAYLOAD_SECRET=
|
|
91
|
-
DATABASE_URI=mongodb://localhost/mydb
|
|
92
|
-
PAYLOAD_SECRET=duplicate
|
|
93
|
-
`;
|
|
94
|
-
await fs.writeFile(path.join(testDir, '.env.example'), envExampleContent);
|
|
95
|
-
const secret = await manageEnvFiles(testDir);
|
|
96
|
-
const envContent = await fs.readFile(path.join(testDir, '.env'), 'utf-8');
|
|
97
|
-
const secretMatches = envContent.match(/PAYLOAD_SECRET=/g);
|
|
98
|
-
expect(secretMatches).toHaveLength(1);
|
|
99
|
-
expect(envContent).toContain(`PAYLOAD_SECRET=${secret}`);
|
|
100
|
-
});
|
|
101
|
-
it('should preserve comments and empty lines', async ()=>{
|
|
102
|
-
const envExampleContent = `# Database configuration
|
|
103
|
-
DATABASE_URI=mongodb://localhost/mydb
|
|
104
|
-
|
|
105
|
-
# API Configuration
|
|
106
|
-
NEXT_PUBLIC_API_URL=http://localhost:3000
|
|
107
|
-
|
|
108
|
-
# Secret key
|
|
109
|
-
PAYLOAD_SECRET=
|
|
110
|
-
`;
|
|
111
|
-
await fs.writeFile(path.join(testDir, '.env.example'), envExampleContent);
|
|
112
|
-
await manageEnvFiles(testDir);
|
|
113
|
-
const envContent = await fs.readFile(path.join(testDir, '.env'), 'utf-8');
|
|
114
|
-
expect(envContent).toContain('# Database configuration');
|
|
115
|
-
expect(envContent).toContain('# API Configuration');
|
|
116
|
-
expect(envContent).toContain('# Secret key');
|
|
117
|
-
// Check for empty lines (might be normalized)
|
|
118
|
-
expect(envContent.split('\n').some((line)=>line.trim() === '')).toBe(true);
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
//# sourceMappingURL=env-management.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/env-management.spec.ts"],"sourcesContent":["import fs from 'fs/promises'\nimport path from 'path'\nimport { afterEach, beforeEach, describe, expect, it } from 'vitest'\n\nimport { generateSecret, manageEnvFiles } from './env-management.js'\n\ndescribe('env-management', () => {\n describe('generateSecret', () => {\n it('should generate a 24-character hex string', () => {\n const secret = generateSecret()\n expect(secret).toHaveLength(24)\n expect(secret).toMatch(/^[0-9a-f]{24}$/)\n })\n\n it('should generate unique secrets', () => {\n const secret1 = generateSecret()\n const secret2 = generateSecret()\n expect(secret1).not.toBe(secret2)\n })\n })\n\n describe('manageEnvFiles', () => {\n let testDir: string\n\n beforeEach(async () => {\n testDir = path.join(\n process.cwd(),\n '.test-env-management',\n `test-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`,\n )\n await fs.mkdir(testDir, { recursive: true })\n })\n\n afterEach(async () => {\n try {\n await fs.rm(testDir, { force: true, recursive: true })\n } catch {\n // Ignore cleanup errors\n }\n })\n\n it('should create .env with PAYLOAD_SECRET when no files exist', async () => {\n const secret = await manageEnvFiles(testDir)\n\n expect(secret).toHaveLength(24)\n expect(secret).toMatch(/^[0-9a-f]{24}$/)\n\n const envContent = await fs.readFile(path.join(testDir, '.env'), 'utf-8')\n expect(envContent).toContain(`PAYLOAD_SECRET=${secret}`)\n })\n\n it('should create .env from .env.example with PAYLOAD_SECRET', async () => {\n const envExampleContent = `# Example environment variables\nDATABASE_URI=mongodb://localhost/mydb\nNEXT_PUBLIC_API_URL=http://localhost:3000\nPAYLOAD_SECRET=\n`\n await fs.writeFile(path.join(testDir, '.env.example'), envExampleContent)\n\n const secret = await manageEnvFiles(testDir)\n\n const envContent = await fs.readFile(path.join(testDir, '.env'), 'utf-8')\n expect(envContent).toContain(`PAYLOAD_SECRET=${secret}`)\n expect(envContent).toContain('DATABASE_URI=mongodb://localhost/mydb')\n expect(envContent).toContain('NEXT_PUBLIC_API_URL=http://localhost:3000')\n })\n\n it('should not overwrite existing .env with PAYLOAD_SECRET', async () => {\n const existingSecret = 'existing-secret-value'\n const existingEnv = `DATABASE_URI=mongodb://localhost/mydb\nPAYLOAD_SECRET=${existingSecret}\nNEXT_PUBLIC_API_URL=http://localhost:3000\n`\n await fs.writeFile(path.join(testDir, '.env'), existingEnv)\n\n await manageEnvFiles(testDir)\n\n const envContent = await fs.readFile(path.join(testDir, '.env'), 'utf-8')\n expect(envContent).toContain(`PAYLOAD_SECRET=${existingSecret}`)\n expect(envContent).not.toMatch(/PAYLOAD_SECRET=[0-9a-f]{24}/)\n })\n\n it('should add PAYLOAD_SECRET to existing .env that lacks it', async () => {\n const existingEnv = `DATABASE_URI=mongodb://localhost/mydb\nNEXT_PUBLIC_API_URL=http://localhost:3000\n`\n await fs.writeFile(path.join(testDir, '.env'), existingEnv)\n\n const secret = await manageEnvFiles(testDir)\n\n const envContent = await fs.readFile(path.join(testDir, '.env'), 'utf-8')\n expect(envContent).toContain(`PAYLOAD_SECRET=${secret}`)\n expect(envContent).toContain('DATABASE_URI=mongodb://localhost/mydb')\n })\n\n it('should handle PAYLOAD_SECRET_KEY as alias', async () => {\n const envExampleContent = `PAYLOAD_SECRET_KEY=\nDATABASE_URI=mongodb://localhost/mydb\n`\n await fs.writeFile(path.join(testDir, '.env.example'), envExampleContent)\n\n const secret = await manageEnvFiles(testDir)\n\n const envContent = await fs.readFile(path.join(testDir, '.env'), 'utf-8')\n // Should normalize to PAYLOAD_SECRET\n expect(envContent).toContain(`PAYLOAD_SECRET=${secret}`)\n expect(envContent).toContain('DATABASE_URI=mongodb://localhost/mydb')\n })\n\n it('should remove duplicate PAYLOAD_SECRET entries', async () => {\n const envExampleContent = `PAYLOAD_SECRET=\nDATABASE_URI=mongodb://localhost/mydb\nPAYLOAD_SECRET=duplicate\n`\n await fs.writeFile(path.join(testDir, '.env.example'), envExampleContent)\n\n const secret = await manageEnvFiles(testDir)\n\n const envContent = await fs.readFile(path.join(testDir, '.env'), 'utf-8')\n const secretMatches = envContent.match(/PAYLOAD_SECRET=/g)\n expect(secretMatches).toHaveLength(1)\n expect(envContent).toContain(`PAYLOAD_SECRET=${secret}`)\n })\n\n it('should preserve comments and empty lines', async () => {\n const envExampleContent = `# Database configuration\nDATABASE_URI=mongodb://localhost/mydb\n\n# API Configuration\nNEXT_PUBLIC_API_URL=http://localhost:3000\n\n# Secret key\nPAYLOAD_SECRET=\n`\n await fs.writeFile(path.join(testDir, '.env.example'), envExampleContent)\n\n await manageEnvFiles(testDir)\n\n const envContent = await fs.readFile(path.join(testDir, '.env'), 'utf-8')\n expect(envContent).toContain('# Database configuration')\n expect(envContent).toContain('# API Configuration')\n expect(envContent).toContain('# Secret key')\n // Check for empty lines (might be normalized)\n expect(envContent.split('\\n').some((line) => line.trim() === '')).toBe(true)\n })\n })\n})\n"],"names":["fs","path","afterEach","beforeEach","describe","expect","it","generateSecret","manageEnvFiles","secret","toHaveLength","toMatch","secret1","secret2","not","toBe","testDir","join","process","cwd","Date","now","Math","random","toString","substring","mkdir","recursive","rm","force","envContent","readFile","toContain","envExampleContent","writeFile","existingSecret","existing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