create-payload-app 3.0.0-canary.95fcd13 → 3.0.0-canary.98cbdb9

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,7 +29,7 @@ describe('createProject', ()=>{
29
29
  'project-name'
30
30
  ],
31
31
  '--db': 'mongodb',
32
- '--local-template': 'blank-3.0',
32
+ '--local-template': 'blank',
33
33
  '--no-deps': true
34
34
  };
35
35
  const packageManager = 'yarn';
@@ -57,11 +57,11 @@ describe('createProject', ()=>{
57
57
  const templates = getValidTemplates();
58
58
  it.each([
59
59
  [
60
- 'blank-3.0',
60
+ 'blank',
61
61
  'mongodb'
62
62
  ],
63
63
  [
64
- 'blank-3.0',
64
+ 'blank',
65
65
  'postgres'
66
66
  ]
67
67
  ])('update config and deps: %s, %s', async (templateName, db)=>{
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/create-project.spec.ts"],"sourcesContent":["import { jest } from '@jest/globals'\nimport fs from 'fs'\nimport fse from 'fs-extra'\nimport globby from 'globby'\nimport * as os from 'node:os'\nimport path from 'path'\n\nimport type { CliArgs, DbType, ProjectTemplate } from '../types.js'\n\nimport { createProject } from './create-project.js'\nimport { dbReplacements } from './replacements.js'\nimport { getValidTemplates } from './templates.js'\n\ndescribe('createProject', () => {\n let projectDir: string\n beforeAll(() => {\n console.log = jest.fn()\n })\n\n beforeEach(() => {\n const tempDirectory = fs.realpathSync(os.tmpdir())\n projectDir = `${tempDirectory}/${Math.random().toString(36).substring(7)}`\n })\n\n afterEach(() => {\n if (fse.existsSync(projectDir)) {\n fse.rmSync(projectDir, { recursive: true })\n }\n })\n\n describe('#createProject', () => {\n const args = {\n _: ['project-name'],\n '--db': 'mongodb',\n '--local-template': 'blank-3.0',\n '--no-deps': true,\n } as CliArgs\n const packageManager = 'yarn'\n\n it('creates plugin template', async () => {\n const projectName = 'plugin'\n const template: ProjectTemplate = {\n name: 'plugin',\n type: 'plugin',\n description: 'Template for creating a Payload plugin',\n url: 'https://github.com/payloadcms/payload-plugin-template',\n }\n await createProject({\n cliArgs: args,\n packageManager,\n projectDir,\n projectName,\n template,\n })\n\n const packageJsonPath = path.resolve(projectDir, 'package.json')\n const packageJson = fse.readJsonSync(packageJsonPath)\n\n // Check package name and description\n expect(packageJson.name).toEqual(projectName)\n })\n\n describe('creates project from template', () => {\n const templates = getValidTemplates()\n\n it.each([\n ['blank-3.0', 'mongodb'],\n ['blank-3.0', 'postgres'],\n\n // TODO: Re-enable these once 3.0 is stable and templates updated\n // ['website', 'mongodb'],\n // ['website', 'postgres'],\n // ['ecommerce', 'mongodb'],\n // ['ecommerce', 'postgres'],\n ])('update config and deps: %s, %s', async (templateName, db) => {\n const projectName = 'starter-project'\n\n const template = templates.find((t) => t.name === templateName)\n\n const cliArgs = {\n ...args,\n '--db': db,\n '--local-template': templateName,\n } as CliArgs\n\n await createProject({\n cliArgs,\n dbDetails: {\n type: db as DbType,\n dbUri: `${db}://localhost:27017/create-project-test`,\n },\n packageManager,\n projectDir,\n projectName,\n template: template as ProjectTemplate,\n })\n\n const dbReplacement = dbReplacements[db as DbType]\n\n const packageJsonPath = path.resolve(projectDir, 'package.json')\n const packageJson = fse.readJsonSync(packageJsonPath)\n\n // Verify git was initialized\n expect(fse.existsSync(path.resolve(projectDir, '.git'))).toBe(true)\n\n // Should only have one db adapter\n expect(\n Object.keys(packageJson.dependencies).filter((n) => n.startsWith('@payloadcms/db-')),\n ).toHaveLength(1)\n\n const payloadConfigPath = (\n await globby('**/payload.config.ts', {\n absolute: true,\n cwd: projectDir,\n })\n )?.[0]\n\n if (!payloadConfigPath) {\n throw new Error(`Could not find payload.config.ts inside ${projectDir}`)\n }\n\n const content = fse.readFileSync(payloadConfigPath, 'utf-8')\n\n // Check payload.config.ts\n expect(content).not.toContain('// database-adapter-import')\n expect(content).toContain(dbReplacement.importReplacement)\n\n expect(content).not.toContain('// database-adapter-config-start')\n expect(content).not.toContain('// database-adapter-config-end')\n expect(content).toContain(dbReplacement.configReplacement().join('\\n'))\n })\n })\n })\n})\n"],"names":["jest","fs","fse","globby","os","path","createProject","dbReplacements","getValidTemplates","describe","projectDir","beforeAll","console","log","fn","beforeEach","tempDirectory","realpathSync","tmpdir","Math","random","toString","substring","afterEach","existsSync","rmSync","recursive","args","_","packageManager","it","projectName","template","name","type","description","url","cliArgs","packageJsonPath","resolve","packageJson","readJsonSync","expect","toEqual","templates","each","templateName","db","find","t","dbDetails","dbUri","dbReplacement","toBe","Object","keys","dependencies","filter","n","startsWith","toHaveLength","payloadConfigPath","absolute","cwd","Error","content","readFileSync","not","toContain","importReplacement","configReplacement","join"],"mappings":"AAAA,SAASA,IAAI,QAAQ,gBAAe;AACpC,OAAOC,QAAQ,KAAI;AACnB,OAAOC,SAAS,WAAU;AAC1B,OAAOC,YAAY,SAAQ;AAC3B,YAAYC,QAAQ,UAAS;AAC7B,OAAOC,UAAU,OAAM;AAIvB,SAASC,aAAa,QAAQ,sBAAqB;AACnD,SAASC,cAAc,QAAQ,oBAAmB;AAClD,SAASC,iBAAiB,QAAQ,iBAAgB;AAElDC,SAAS,iBAAiB;IACxB,IAAIC;IACJC,UAAU;QACRC,QAAQC,GAAG,GAAGb,KAAKc,EAAE;IACvB;IAEAC,WAAW;QACT,MAAMC,gBAAgBf,GAAGgB,YAAY,CAACb,GAAGc,MAAM;QAC/CR,aAAa,CAAC,EAAEM,cAAc,CAAC,EAAEG,KAAKC,MAAM,GAAGC,QAAQ,CAAC,IAAIC,SAAS,CAAC,GAAG,CAAC;IAC5E;IAEAC,UAAU;QACR,IAAIrB,IAAIsB,UAAU,CAACd,aAAa;YAC9BR,IAAIuB,MAAM,CAACf,YAAY;gBAAEgB,WAAW;YAAK;QAC3C;IACF;IAEAjB,SAAS,kBAAkB;QACzB,MAAMkB,OAAO;YACXC,GAAG;gBAAC;aAAe;YACnB,QAAQ;YACR,oBAAoB;YACpB,aAAa;QACf;QACA,MAAMC,iBAAiB;QAEvBC,GAAG,2BAA2B;YAC5B,MAAMC,cAAc;YACpB,MAAMC,WAA4B;gBAChCC,MAAM;gBACN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,KAAKrD;gBACP,EAAC,GACA,CAAC,EAAE;gBAEN,IAAI,CAACmD,mBAAmB;oBACtB,MAAM,IAAIG,MAAM,CAAC,wCAAwC,EAAEtD,WAAW,CAAC;gBACzE;gBAEA,MAAMuD,UAAU/D,IAAIgE,YAAY,CAACL,mBAAmB;gBAEpD,0BAA0B;gBAC1BnB,OAAOuB,SAASE,GAAG,CAACC,SAAS,CAAC;gBAC9B1B,OAAOuB,SAASG,SAAS,CAAChB,cAAciB,iBAAiB;gBAEzD3B,OAAOuB,SAASE,GAAG,CAACC,SAAS,CAAC;gBAC9B1B,OAAOuB,SAASE,GAAG,CAACC,SAAS,CAAC;gBAC9B1B,OAAOuB,SAASG,SAAS,CAAChB,cAAckB,iBAAiB,GAAGC,IAAI,CAAC;YACnE;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/lib/create-project.spec.ts"],"sourcesContent":["import { jest } from '@jest/globals'\nimport fs from 'fs'\nimport fse from 'fs-extra'\nimport globby from 'globby'\nimport * as os from 'node:os'\nimport path from 'path'\n\nimport type { CliArgs, DbType, ProjectTemplate } from '../types.js'\n\nimport { createProject } from './create-project.js'\nimport { dbReplacements } from './replacements.js'\nimport { getValidTemplates } from './templates.js'\n\ndescribe('createProject', () => {\n let projectDir: string\n beforeAll(() => {\n console.log = jest.fn()\n })\n\n beforeEach(() => {\n const tempDirectory = fs.realpathSync(os.tmpdir())\n projectDir = `${tempDirectory}/${Math.random().toString(36).substring(7)}`\n })\n\n afterEach(() => {\n if (fse.existsSync(projectDir)) {\n fse.rmSync(projectDir, { recursive: true })\n }\n })\n\n describe('#createProject', () => {\n const args = {\n _: ['project-name'],\n '--db': 'mongodb',\n '--local-template': 'blank',\n '--no-deps': true,\n } as CliArgs\n const packageManager = 'yarn'\n\n it('creates plugin template', async () => {\n const projectName = 'plugin'\n const template: ProjectTemplate = {\n name: 'plugin',\n type: 'plugin',\n description: 'Template for creating a Payload plugin',\n url: 'https://github.com/payloadcms/payload-plugin-template',\n }\n await createProject({\n cliArgs: args,\n packageManager,\n projectDir,\n projectName,\n template,\n })\n\n const packageJsonPath = path.resolve(projectDir, 'package.json')\n const packageJson = fse.readJsonSync(packageJsonPath)\n\n // Check package name and description\n expect(packageJson.name).toEqual(projectName)\n })\n\n describe('creates project from template', () => {\n const templates = getValidTemplates()\n\n it.each([\n ['blank', 'mongodb'],\n ['blank', 'postgres'],\n\n // TODO: Re-enable these once 3.0 is stable and templates updated\n // ['website', 'mongodb'],\n // ['website', 'postgres'],\n // ['ecommerce', 'mongodb'],\n // ['ecommerce', 'postgres'],\n ])('update config and deps: %s, %s', async (templateName, db) => {\n const projectName = 'starter-project'\n\n const template = templates.find((t) => t.name === templateName)\n\n const cliArgs = {\n ...args,\n '--db': db,\n '--local-template': templateName,\n } as CliArgs\n\n await createProject({\n cliArgs,\n dbDetails: {\n type: db as DbType,\n dbUri: `${db}://localhost:27017/create-project-test`,\n },\n packageManager,\n projectDir,\n projectName,\n template: template as ProjectTemplate,\n })\n\n const dbReplacement = dbReplacements[db as DbType]\n\n const packageJsonPath = path.resolve(projectDir, 'package.json')\n const packageJson = fse.readJsonSync(packageJsonPath)\n\n // Verify git was initialized\n expect(fse.existsSync(path.resolve(projectDir, '.git'))).toBe(true)\n\n // Should only have one db adapter\n expect(\n Object.keys(packageJson.dependencies).filter((n) => n.startsWith('@payloadcms/db-')),\n ).toHaveLength(1)\n\n const payloadConfigPath = (\n await globby('**/payload.config.ts', {\n absolute: true,\n cwd: projectDir,\n })\n )?.[0]\n\n if (!payloadConfigPath) {\n throw new Error(`Could not find payload.config.ts inside ${projectDir}`)\n }\n\n const content = fse.readFileSync(payloadConfigPath, 'utf-8')\n\n // Check payload.config.ts\n expect(content).not.toContain('// database-adapter-import')\n expect(content).toContain(dbReplacement.importReplacement)\n\n expect(content).not.toContain('// database-adapter-config-start')\n expect(content).not.toContain('// database-adapter-config-end')\n expect(content).toContain(dbReplacement.configReplacement().join('\\n'))\n })\n })\n })\n})\n"],"names":["jest","fs","fse","globby","os","path","createProject","dbReplacements","getValidTemplates","describe","projectDir","beforeAll","console","log","fn","beforeEach","tempDirectory","realpathSync","tmpdir","Math","random","toString","substring","afterEach","existsSync","rmSync","recursive","args","_","packageManager","it","projectName","template","name","type","description","url","cliArgs","packageJsonPath","resolve","packageJson","readJsonSync","expect","toEqual","templates","each","templateName","db","find","t","dbDetails","dbUri","dbReplacement","toBe","Object","keys","dependencies","filter","n","startsWith","toHaveLength","payloadConfigPath","absolute","cwd","Error","content","readFileSync","not","toContain","importReplacement","configReplacement","join"],"mappings":"AAAA,SAASA,IAAI,QAAQ,gBAAe;AACpC,OAAOC,QAAQ,KAAI;AACnB,OAAOC,SAAS,WAAU;AAC1B,OAAOC,YAAY,SAAQ;AAC3B,YAAYC,QAAQ,UAAS;AAC7B,OAAOC,UAAU,OAAM;AAIvB,SAASC,aAAa,QAAQ,sBAAqB;AACnD,SAASC,cAAc,QAAQ,oBAAmB;AAClD,SAASC,iBAAiB,QAAQ,iBAAgB;AAElDC,SAAS,iBAAiB;IACxB,IAAIC;IACJC,UAAU;QACRC,QAAQC,GAAG,GAAGb,KAAKc,EAAE;IACvB;IAEAC,WAAW;QACT,MAAMC,gBAAgBf,GAAGgB,YAAY,CAACb,GAAGc,MAAM;QAC/CR,aAAa,CAAC,EAAEM,cAAc,CAAC,EAAEG,KAAKC,MAAM,GAAGC,QAAQ,CAAC,IAAIC,SAAS,CAAC,GAAG,CAAC;IAC5E;IAEAC,UAAU;QACR,IAAIrB,IAAIsB,UAAU,CAACd,aAAa;YAC9BR,IAAIuB,MAAM,CAACf,YAAY;gBAAEgB,WAAW;YAAK;QAC3C;IACF;IAEAjB,SAAS,kBAAkB;QACzB,MAAMkB,OAAO;YACXC,GAAG;gBAAC;aAAe;YACnB,QAAQ;YACR,oBAAoB;YACpB,aAAa;QACf;QACA,MAAMC,iBAAiB;QAEvBC,GAAG,2BAA2B;YAC5B,MAAMC,cAAc;YACpB,MAAMC,WAA4B;gBAChCC,MAA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;oBACVC,KAAKrD;gBACP,EAAC,GACA,CAAC,EAAE;gBAEN,IAAI,CAACmD,mBAAmB;oBACtB,MAAM,IAAIG,MAAM,CAAC,wCAAwC,EAAEtD,WAAW,CAAC;gBACzE;gBAEA,MAAMuD,UAAU/D,IAAIgE,YAAY,CAACL,mBAAmB;gBAEpD,0BAA0B;gBAC1BnB,OAAOuB,SAASE,GAAG,CAACC,SAAS,CAAC;gBAC9B1B,OAAOuB,SAASG,SAAS,CAAChB,cAAciB,iBAAiB;gBAEzD3B,OAAOuB,SAASE,GAAG,CAACC,SAAS,CAAC;gBAC9B1B,OAAOuB,SAASE,GAAG,CAACC,SAAS,CAAC;gBAC9B1B,OAAOuB,SAASG,SAAS,CAAChB,cAAckB,iBAAiB,GAAGC,IAAI,CAAC;YACnE;QACF;IACF;AACF"}
@@ -129,7 +129,7 @@ async function installAndConfigurePayload(args) {
129
129
  success: false
130
130
  };
131
131
  }
132
- const templateFilesPath = dirname.endsWith('dist') || useDistFiles ? path.resolve(dirname, '../..', 'dist/template') : path.resolve(dirname, '../../../../templates/blank-3.0');
132
+ const templateFilesPath = dirname.endsWith('dist') || useDistFiles ? path.resolve(dirname, '../..', 'dist/template') : path.resolve(dirname, '../../../../templates/blank');
133
133
  logDebug(`Using template files from: ${templateFilesPath}`);
134
134
  if (!fs.existsSync(templateFilesPath)) {
135
135
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/init-next.ts"],"sourcesContent":["import type { CompilerOptions } from 'typescript'\n\nimport * as p from '@clack/prompts'\nimport { parse, stringify } from 'comment-json'\nimport execa from 'execa'\nimport fs from 'fs'\nimport fse from 'fs-extra'\nimport globby from 'globby'\nimport { fileURLToPath } from 'node:url'\nimport path from 'path'\nimport { promisify } from 'util'\n\nimport type { CliArgs, DbType, NextAppDetails, NextConfigType, PackageManager } from '../types.js'\n\nimport { copyRecursiveSync } from '../utils/copy-recursive-sync.js'\nimport { debug as origDebug, warning } from '../utils/log.js'\nimport { moveMessage } from '../utils/messages.js'\nimport { installPackages } from './install-packages.js'\nimport { wrapNextConfig } from './wrap-next-config.js'\n\nconst readFile = promisify(fs.readFile)\nconst writeFile = promisify(fs.writeFile)\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\ntype InitNextArgs = {\n dbType: DbType\n nextAppDetails?: NextAppDetails\n packageManager: PackageManager\n projectDir: string\n useDistFiles?: boolean\n} & Pick<CliArgs, '--debug'>\n\ntype InitNextResult =\n | {\n isSrcDir: boolean\n nextAppDir: string\n payloadConfigPath: string\n success: true\n }\n | { isSrcDir: boolean; nextAppDir?: string; reason: string; success: false }\n\nexport async function initNext(args: InitNextArgs): Promise<InitNextResult> {\n const { dbType: dbType, packageManager, projectDir } = args\n\n const nextAppDetails = args.nextAppDetails || (await getNextAppDetails(projectDir))\n\n if (!nextAppDetails.nextAppDir) {\n warning(`Could not find app directory in ${projectDir}, creating...`)\n const createdAppDir = path.resolve(projectDir, nextAppDetails.isSrcDir ? 'src/app' : 'app')\n fse.mkdirSync(createdAppDir, { recursive: true })\n nextAppDetails.nextAppDir = createdAppDir\n }\n\n const { hasTopLevelLayout, isPayloadInstalled, isSrcDir, nextAppDir, nextConfigType } =\n nextAppDetails\n\n if (!nextConfigType) {\n return {\n isSrcDir,\n nextAppDir,\n reason: `Could not determine Next Config type in ${projectDir}. Possibly try renaming next.config.js to next.config.cjs or next.config.mjs.`,\n success: false,\n }\n }\n\n if (hasTopLevelLayout) {\n // Output directions for user to move all files from app to top-level directory named `(app)`\n p.log.warn(moveMessage({ nextAppDir, projectDir }))\n return {\n isSrcDir,\n nextAppDir,\n reason: 'Found existing layout.tsx in app directory',\n success: false,\n }\n }\n\n const installSpinner = p.spinner()\n installSpinner.start('Installing Payload and dependencies...')\n\n const configurationResult = await installAndConfigurePayload({\n ...args,\n nextAppDetails,\n nextConfigType,\n useDistFiles: true, // Requires running 'pnpm pack-template-files' in cpa\n })\n\n if (configurationResult.success === false) {\n installSpinner.stop(configurationResult.reason, 1)\n return { ...configurationResult, isSrcDir, success: false }\n }\n\n const { success: installSuccess } = await installDeps(projectDir, packageManager, dbType)\n if (!installSuccess) {\n installSpinner.stop('Failed to install dependencies', 1)\n return {\n ...configurationResult,\n isSrcDir,\n reason: 'Failed to install dependencies',\n success: false,\n }\n }\n\n // Add `@payload-config` to tsconfig.json `paths`\n await addPayloadConfigToTsConfig(projectDir, isSrcDir)\n installSpinner.stop('Successfully installed Payload and dependencies')\n return { ...configurationResult, isSrcDir, nextAppDir, success: true }\n}\n\nasync function addPayloadConfigToTsConfig(projectDir: string, isSrcDir: boolean) {\n const tsConfigPath = path.resolve(projectDir, 'tsconfig.json')\n\n // Check if tsconfig.json exists\n if (!fs.existsSync(tsConfigPath)) {\n warning(`Could not find tsconfig.json to add @payload-config path.`)\n return\n }\n const userTsConfigContent = await readFile(tsConfigPath, {\n encoding: 'utf8',\n })\n const userTsConfig = parse(userTsConfigContent) as {\n compilerOptions?: CompilerOptions\n }\n\n const hasBaseUrl =\n userTsConfig?.compilerOptions?.baseUrl && userTsConfig?.compilerOptions?.baseUrl !== '.'\n const baseUrl = hasBaseUrl ? userTsConfig?.compilerOptions?.baseUrl : './'\n\n if (!userTsConfig.compilerOptions && !('extends' in userTsConfig)) {\n userTsConfig.compilerOptions = {}\n }\n\n if (\n !userTsConfig.compilerOptions?.paths?.['@payload-config'] &&\n userTsConfig.compilerOptions?.paths\n ) {\n userTsConfig.compilerOptions.paths = {\n ...(userTsConfig.compilerOptions.paths || {}),\n '@payload-config': [`${baseUrl}${isSrcDir ? 'src/' : ''}payload.config.ts`],\n }\n await writeFile(tsConfigPath, stringify(userTsConfig, null, 2), { encoding: 'utf8' })\n }\n}\n\nasync function installAndConfigurePayload(\n args: {\n nextAppDetails: NextAppDetails\n nextConfigType: NextConfigType\n useDistFiles?: boolean\n } & InitNextArgs,\n): Promise<\n | { payloadConfigPath: string; success: true }\n | { payloadConfigPath?: string; reason: string; success: false }\n> {\n const {\n '--debug': debug,\n nextAppDetails: { isSrcDir, nextAppDir, nextConfigPath } = {},\n nextConfigType,\n projectDir,\n useDistFiles,\n } = args\n\n if (!nextAppDir || !nextConfigPath) {\n return {\n reason: 'Could not find app directory or next.config.js',\n success: false,\n }\n }\n\n const logDebug = (message: string) => {\n if (debug) origDebug(message)\n }\n\n if (!fs.existsSync(projectDir)) {\n return {\n reason: `Could not find specified project directory at ${projectDir}`,\n success: false,\n }\n }\n\n const templateFilesPath =\n dirname.endsWith('dist') || useDistFiles\n ? path.resolve(dirname, '../..', 'dist/template')\n : path.resolve(dirname, '../../../../templates/blank-3.0')\n\n logDebug(`Using template files from: ${templateFilesPath}`)\n\n if (!fs.existsSync(templateFilesPath)) {\n return {\n reason: `Could not find template source files from ${templateFilesPath}`,\n success: false,\n }\n } else {\n logDebug('Found template source files')\n }\n\n logDebug(`Copying template files from ${templateFilesPath} to ${nextAppDir}`)\n\n const templateSrcDir = path.resolve(templateFilesPath, isSrcDir ? '' : 'src')\n\n logDebug(`templateSrcDir: ${templateSrcDir}`)\n logDebug(`nextAppDir: ${nextAppDir}`)\n logDebug(`projectDir: ${projectDir}`)\n logDebug(`nextConfigPath: ${nextConfigPath}`)\n logDebug(`payloadConfigPath: ${path.resolve(projectDir, 'payload.config.ts')}`)\n\n logDebug(\n `isSrcDir: ${isSrcDir}. source: ${templateSrcDir}. dest: ${path.dirname(nextConfigPath)}`,\n )\n\n // This is a little clunky and needs to account for isSrcDir\n copyRecursiveSync(templateSrcDir, path.dirname(nextConfigPath), debug)\n\n // Wrap next.config.js with withPayload\n await wrapNextConfig({ nextConfigPath, nextConfigType })\n\n return {\n payloadConfigPath: path.resolve(nextAppDir, '../payload.config.ts'),\n success: true,\n }\n}\n\nasync function installDeps(projectDir: string, packageManager: PackageManager, dbType: DbType) {\n const packagesToInstall = [\n 'payload',\n '@payloadcms/next',\n '@payloadcms/richtext-lexical',\n '@payloadcms/plugin-cloud',\n ].map((pkg) => `${pkg}@beta`)\n\n packagesToInstall.push(`@payloadcms/db-${dbType}@beta`)\n\n // Match graphql version of @payloadcms/next\n packagesToInstall.push('graphql@^16.8.1')\n\n return await installPackages({ packageManager, packagesToInstall, projectDir })\n}\n\nexport async function getNextAppDetails(projectDir: string): Promise<NextAppDetails> {\n const isSrcDir = fs.existsSync(path.resolve(projectDir, 'src'))\n\n // Match next.config.js, next.config.ts, next.config.mjs, next.config.cjs\n const nextConfigPath: string | undefined = (\n await globby('next.config.(\\\\w)?(t|j)s', { absolute: true, cwd: projectDir })\n )?.[0]\n\n if (!nextConfigPath || nextConfigPath.length === 0) {\n return {\n hasTopLevelLayout: false,\n isSrcDir,\n isSupportedNextVersion: false,\n nextConfigPath: undefined,\n nextVersion: null,\n }\n }\n\n const packageObj = await fse.readJson(path.resolve(projectDir, 'package.json'))\n // Check if Next.js version is new enough\n let nextVersion = null\n if (packageObj.dependencies?.next) {\n nextVersion = packageObj.dependencies.next\n // Match versions using regex matching groups\n const versionMatch = /(?<major>\\d+)/.exec(nextVersion)\n if (!versionMatch) {\n p.log.warn(`Could not determine Next.js version from ${nextVersion}`)\n return {\n hasTopLevelLayout: false,\n isSrcDir,\n isSupportedNextVersion: false,\n nextConfigPath,\n nextVersion,\n }\n }\n\n const { major } = versionMatch.groups as { major: string }\n const majorVersion = parseInt(major)\n if (majorVersion < 15) {\n return {\n hasTopLevelLayout: false,\n isSrcDir,\n isSupportedNextVersion: false,\n nextConfigPath,\n nextVersion,\n }\n }\n }\n\n const isSupportedNextVersion = true\n\n // Check if Payload already installed\n if (packageObj.dependencies?.payload) {\n return {\n hasTopLevelLayout: false,\n isPayloadInstalled: true,\n isSrcDir,\n isSupportedNextVersion,\n nextConfigPath,\n nextVersion,\n }\n }\n\n let nextAppDir: string | undefined = (\n await globby(['**/app'], {\n absolute: true,\n cwd: projectDir,\n ignore: ['**/node_modules/**'],\n onlyDirectories: true,\n })\n )?.[0]\n\n if (!nextAppDir || nextAppDir.length === 0) {\n nextAppDir = undefined\n }\n\n const configType = getProjectType({ nextConfigPath, packageObj })\n\n const hasTopLevelLayout = nextAppDir\n ? fs.existsSync(path.resolve(nextAppDir, 'layout.tsx'))\n : false\n\n return {\n hasTopLevelLayout,\n isSrcDir,\n isSupportedNextVersion,\n nextAppDir,\n nextConfigPath,\n nextConfigType: configType,\n nextVersion,\n }\n}\n\nfunction getProjectType(args: {\n nextConfigPath: string\n packageObj: Record<string, unknown>\n}): NextConfigType {\n const { nextConfigPath, packageObj } = args\n\n if (nextConfigPath.endsWith('.ts')) {\n return 'ts'\n }\n\n if (nextConfigPath.endsWith('.mjs')) {\n return 'esm'\n }\n if (nextConfigPath.endsWith('.cjs')) {\n return 'cjs'\n }\n\n const packageJsonType = packageObj.type\n if (packageJsonType === 'module') {\n return 'esm'\n }\n if (packageJsonType === 'commonjs') {\n return 'cjs'\n }\n\n return 'cjs'\n}\n"],"names":["p","parse","stringify","fs","fse","globby","fileURLToPath","path","promisify","copyRecursiveSync","debug","origDebug","warning","moveMessage","installPackages","wrapNextConfig","readFile","writeFile","filename","url","dirname","initNext","args","dbType","packageManager","projectDir","nextAppDetails","getNextAppDetails","nextAppDir","createdAppDir","resolve","isSrcDir","mkdirSync","recursive","hasTopLevelLayout","isPayloadInstalled","nextConfigType","reason","success","log","warn","installSpinner","spinner","start","configurationResult","installAndConfigurePayload","useDistFiles","stop","installSuccess","installDeps","addPayloadConfigToTsConfig","tsConfigPath","existsSync","userTsConfigContent","encoding","userTsConfig","hasBaseUrl","compilerOptions","baseUrl","paths","nextConfigPath","logDebug","message","templateFilesPath","endsWith","templateSrcDir","payloadConfigPath","packagesToInstall","map","pkg","push","absolute","cwd","length","isSupportedNextVersion","undefined","nextVersion","packageObj","readJson","dependencies","next","versionMatch","exec","major","groups","majorVersion","parseInt","payload","ignore","onlyDirectories","configType","getProjectType","packageJsonType","type"],"mappings":"AAEA,YAAYA,OAAO,iBAAgB;AACnC,SAASC,KAAK,EAAEC,SAAS,QAAQ,eAAc;AAE/C,OAAOC,QAAQ,KAAI;AACnB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,WAAW6C,MAAM,KAAK,GAAG;QAC1C7C,aAAa+C;IACf;IAEA,MAAMe,aAAaC,eAAe;QAAE/B;QAAgBiB;IAAW;IAE/D,MAAM3C,oBAAoBN,aACtBzB,GAAGiD,UAAU,CAAC7C,KAAKuB,OAAO,CAACF,YAAY,iBACvC;IAEJ,OAAO;QACLM;QACAH;QACA2C;QACA9C;QACAgC;QACAxB,gBAAgBsD;QAChBd;IACF;AACF;AAEA,SAASe,eAAerE,IAGvB;IACC,MAAM,EAAEsC,cAAc,EAAEiB,UAAU,EAAE,GAAGvD;IAEvC,IAAIsC,eAAeI,QAAQ,CAAC,QAAQ;QAClC,OAAO;IACT;IAEA,IAAIJ,eAAeI,QAAQ,CAAC,SAAS;QACnC,OAAO;IACT;IACA,IAAIJ,eAAeI,QAAQ,CAAC,SAAS;QACnC,OAAO;IACT;IAEA,MAAM4B,kBAAkBf,WAAWgB,IAAI;IACvC,IAAID,oBAAoB,UAAU;QAChC,OAAO;IACT;IACA,IAAIA,oBAAoB,YAAY;QAClC,OAAO;IACT;IAEA,OAAO;AACT"}
1
+ {"version":3,"sources":["../../src/lib/init-next.ts"],"sourcesContent":["import type { CompilerOptions } from 'typescript'\n\nimport * as p from '@clack/prompts'\nimport { parse, stringify } from 'comment-json'\nimport execa from 'execa'\nimport fs from 'fs'\nimport fse from 'fs-extra'\nimport globby from 'globby'\nimport { fileURLToPath } from 'node:url'\nimport path from 'path'\nimport { promisify } from 'util'\n\nimport type { CliArgs, DbType, NextAppDetails, NextConfigType, PackageManager } from '../types.js'\n\nimport { copyRecursiveSync } from '../utils/copy-recursive-sync.js'\nimport { debug as origDebug, warning } from '../utils/log.js'\nimport { moveMessage } from '../utils/messages.js'\nimport { installPackages } from './install-packages.js'\nimport { wrapNextConfig } from './wrap-next-config.js'\n\nconst readFile = promisify(fs.readFile)\nconst writeFile = promisify(fs.writeFile)\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\ntype InitNextArgs = {\n dbType: DbType\n nextAppDetails?: NextAppDetails\n packageManager: PackageManager\n projectDir: string\n useDistFiles?: boolean\n} & Pick<CliArgs, '--debug'>\n\ntype InitNextResult =\n | {\n isSrcDir: boolean\n nextAppDir: string\n payloadConfigPath: string\n success: true\n }\n | { isSrcDir: boolean; nextAppDir?: string; reason: string; success: false }\n\nexport async function initNext(args: InitNextArgs): Promise<InitNextResult> {\n const { dbType: dbType, packageManager, projectDir } = args\n\n const nextAppDetails = args.nextAppDetails || (await getNextAppDetails(projectDir))\n\n if (!nextAppDetails.nextAppDir) {\n warning(`Could not find app directory in ${projectDir}, creating...`)\n const createdAppDir = path.resolve(projectDir, nextAppDetails.isSrcDir ? 'src/app' : 'app')\n fse.mkdirSync(createdAppDir, { recursive: true })\n nextAppDetails.nextAppDir = createdAppDir\n }\n\n const { hasTopLevelLayout, isPayloadInstalled, isSrcDir, nextAppDir, nextConfigType } =\n nextAppDetails\n\n if (!nextConfigType) {\n return {\n isSrcDir,\n nextAppDir,\n reason: `Could not determine Next Config type in ${projectDir}. Possibly try renaming next.config.js to next.config.cjs or next.config.mjs.`,\n success: false,\n }\n }\n\n if (hasTopLevelLayout) {\n // Output directions for user to move all files from app to top-level directory named `(app)`\n p.log.warn(moveMessage({ nextAppDir, projectDir }))\n return {\n isSrcDir,\n nextAppDir,\n reason: 'Found existing layout.tsx in app directory',\n success: false,\n }\n }\n\n const installSpinner = p.spinner()\n installSpinner.start('Installing Payload and dependencies...')\n\n const configurationResult = await installAndConfigurePayload({\n ...args,\n nextAppDetails,\n nextConfigType,\n useDistFiles: true, // Requires running 'pnpm pack-template-files' in cpa\n })\n\n if (configurationResult.success === false) {\n installSpinner.stop(configurationResult.reason, 1)\n return { ...configurationResult, isSrcDir, success: false }\n }\n\n const { success: installSuccess } = await installDeps(projectDir, packageManager, dbType)\n if (!installSuccess) {\n installSpinner.stop('Failed to install dependencies', 1)\n return {\n ...configurationResult,\n isSrcDir,\n reason: 'Failed to install dependencies',\n success: false,\n }\n }\n\n // Add `@payload-config` to tsconfig.json `paths`\n await addPayloadConfigToTsConfig(projectDir, isSrcDir)\n installSpinner.stop('Successfully installed Payload and dependencies')\n return { ...configurationResult, isSrcDir, nextAppDir, success: true }\n}\n\nasync function addPayloadConfigToTsConfig(projectDir: string, isSrcDir: boolean) {\n const tsConfigPath = path.resolve(projectDir, 'tsconfig.json')\n\n // Check if tsconfig.json exists\n if (!fs.existsSync(tsConfigPath)) {\n warning(`Could not find tsconfig.json to add @payload-config path.`)\n return\n }\n const userTsConfigContent = await readFile(tsConfigPath, {\n encoding: 'utf8',\n })\n const userTsConfig = parse(userTsConfigContent) as {\n compilerOptions?: CompilerOptions\n }\n\n const hasBaseUrl =\n userTsConfig?.compilerOptions?.baseUrl && userTsConfig?.compilerOptions?.baseUrl !== '.'\n const baseUrl = hasBaseUrl ? userTsConfig?.compilerOptions?.baseUrl : './'\n\n if (!userTsConfig.compilerOptions && !('extends' in userTsConfig)) {\n userTsConfig.compilerOptions = {}\n }\n\n if (\n !userTsConfig.compilerOptions?.paths?.['@payload-config'] &&\n userTsConfig.compilerOptions?.paths\n ) {\n userTsConfig.compilerOptions.paths = {\n ...(userTsConfig.compilerOptions.paths || {}),\n '@payload-config': [`${baseUrl}${isSrcDir ? 'src/' : ''}payload.config.ts`],\n }\n await writeFile(tsConfigPath, stringify(userTsConfig, null, 2), { encoding: 'utf8' })\n }\n}\n\nasync function installAndConfigurePayload(\n args: {\n nextAppDetails: NextAppDetails\n nextConfigType: NextConfigType\n useDistFiles?: boolean\n } & InitNextArgs,\n): Promise<\n | { payloadConfigPath: string; success: true }\n | { payloadConfigPath?: string; reason: string; success: false }\n> {\n const {\n '--debug': debug,\n nextAppDetails: { isSrcDir, nextAppDir, nextConfigPath } = {},\n nextConfigType,\n projectDir,\n useDistFiles,\n } = args\n\n if (!nextAppDir || !nextConfigPath) {\n return {\n reason: 'Could not find app directory or next.config.js',\n success: false,\n }\n }\n\n const logDebug = (message: string) => {\n if (debug) origDebug(message)\n }\n\n if (!fs.existsSync(projectDir)) {\n return {\n reason: `Could not find specified project directory at ${projectDir}`,\n success: false,\n }\n }\n\n const templateFilesPath =\n dirname.endsWith('dist') || useDistFiles\n ? path.resolve(dirname, '../..', 'dist/template')\n : path.resolve(dirname, '../../../../templates/blank')\n\n logDebug(`Using template files from: ${templateFilesPath}`)\n\n if (!fs.existsSync(templateFilesPath)) {\n return {\n reason: `Could not find template source files from ${templateFilesPath}`,\n success: false,\n }\n } else {\n logDebug('Found template source files')\n }\n\n logDebug(`Copying template files from ${templateFilesPath} to ${nextAppDir}`)\n\n const templateSrcDir = path.resolve(templateFilesPath, isSrcDir ? '' : 'src')\n\n logDebug(`templateSrcDir: ${templateSrcDir}`)\n logDebug(`nextAppDir: ${nextAppDir}`)\n logDebug(`projectDir: ${projectDir}`)\n logDebug(`nextConfigPath: ${nextConfigPath}`)\n logDebug(`payloadConfigPath: ${path.resolve(projectDir, 'payload.config.ts')}`)\n\n logDebug(\n `isSrcDir: ${isSrcDir}. source: ${templateSrcDir}. dest: ${path.dirname(nextConfigPath)}`,\n )\n\n // This is a little clunky and needs to account for isSrcDir\n copyRecursiveSync(templateSrcDir, path.dirname(nextConfigPath), debug)\n\n // Wrap next.config.js with withPayload\n await wrapNextConfig({ nextConfigPath, nextConfigType })\n\n return {\n payloadConfigPath: path.resolve(nextAppDir, '../payload.config.ts'),\n success: true,\n }\n}\n\nasync function installDeps(projectDir: string, packageManager: PackageManager, dbType: DbType) {\n const packagesToInstall = [\n 'payload',\n '@payloadcms/next',\n '@payloadcms/richtext-lexical',\n '@payloadcms/plugin-cloud',\n ].map((pkg) => `${pkg}@beta`)\n\n packagesToInstall.push(`@payloadcms/db-${dbType}@beta`)\n\n // Match graphql version of @payloadcms/next\n packagesToInstall.push('graphql@^16.8.1')\n\n return await installPackages({ packageManager, packagesToInstall, projectDir })\n}\n\nexport async function getNextAppDetails(projectDir: string): Promise<NextAppDetails> {\n const isSrcDir = fs.existsSync(path.resolve(projectDir, 'src'))\n\n // Match next.config.js, next.config.ts, next.config.mjs, next.config.cjs\n const nextConfigPath: string | undefined = (\n await globby('next.config.(\\\\w)?(t|j)s', { absolute: true, cwd: projectDir })\n )?.[0]\n\n if (!nextConfigPath || nextConfigPath.length === 0) {\n return {\n hasTopLevelLayout: false,\n isSrcDir,\n isSupportedNextVersion: false,\n nextConfigPath: undefined,\n nextVersion: null,\n }\n }\n\n const packageObj = await fse.readJson(path.resolve(projectDir, 'package.json'))\n // Check if Next.js version is new enough\n let nextVersion = null\n if (packageObj.dependencies?.next) {\n nextVersion = packageObj.dependencies.next\n // Match versions using regex matching groups\n const versionMatch = /(?<major>\\d+)/.exec(nextVersion)\n if (!versionMatch) {\n p.log.warn(`Could not determine Next.js version from ${nextVersion}`)\n return {\n hasTopLevelLayout: false,\n isSrcDir,\n isSupportedNextVersion: false,\n nextConfigPath,\n nextVersion,\n }\n }\n\n const { major } = versionMatch.groups as { major: string }\n const majorVersion = parseInt(major)\n if (majorVersion < 15) {\n return {\n hasTopLevelLayout: false,\n isSrcDir,\n isSupportedNextVersion: false,\n nextConfigPath,\n nextVersion,\n }\n }\n }\n\n const isSupportedNextVersion = true\n\n // Check if Payload already installed\n if (packageObj.dependencies?.payload) {\n return {\n hasTopLevelLayout: false,\n isPayloadInstalled: true,\n isSrcDir,\n isSupportedNextVersion,\n nextConfigPath,\n nextVersion,\n }\n }\n\n let nextAppDir: string | undefined = (\n await globby(['**/app'], {\n absolute: true,\n cwd: projectDir,\n ignore: ['**/node_modules/**'],\n onlyDirectories: true,\n })\n )?.[0]\n\n if (!nextAppDir || nextAppDir.length === 0) {\n nextAppDir = undefined\n }\n\n const configType = getProjectType({ nextConfigPath, packageObj })\n\n const hasTopLevelLayout = nextAppDir\n ? fs.existsSync(path.resolve(nextAppDir, 'layout.tsx'))\n : false\n\n return {\n hasTopLevelLayout,\n isSrcDir,\n isSupportedNextVersion,\n nextAppDir,\n nextConfigPath,\n nextConfigType: configType,\n nextVersion,\n }\n}\n\nfunction getProjectType(args: {\n nextConfigPath: string\n packageObj: Record<string, unknown>\n}): NextConfigType {\n const { nextConfigPath, packageObj } = args\n\n if (nextConfigPath.endsWith('.ts')) {\n return 'ts'\n }\n\n if (nextConfigPath.endsWith('.mjs')) {\n return 'esm'\n }\n if (nextConfigPath.endsWith('.cjs')) {\n return 'cjs'\n }\n\n const packageJsonType = packageObj.type\n if (packageJsonType === 'module') {\n return 'esm'\n }\n if (packageJsonType === 'commonjs') {\n return 'cjs'\n }\n\n return 'cjs'\n}\n"],"names":["p","parse","stringify","fs","fse","globby","fileURLToPath","path","promisify","copyRecursiveSync","debug","origDebug","warning","moveMessage","installPackages","wrapNextConfig","readFile","writeFile","filename","url","dirname","initNext","args","dbType","packageManager","projectDir","nextAppDetails","getNextAppDetails","nextAppDir","createdAppDir","resolve","isSrcDir","mkdirSync","recursive","hasTopLevelLayout","isPayloadInstalled","nextConfigType","reason","success","log","warn","installSpinner","spinner","start","configurationResult","installAndConfigurePayload","useDistFiles","stop","installSuccess","installDeps","addPayloadConfigToTsConfig","tsConfigPath","existsSync","userTsConfigContent","encoding","userTsConfig","hasBaseUrl","compilerOptions","baseUrl","paths","nextConfigPath","logDebug","message","templateFilesPath","endsWith","templateSrcDir","payloadConfigPath","packagesToInstall","map","pkg","push","absolute","cwd","length","isSupportedNextVersion","undefined","nextVersion","packageObj","readJson","dependencies","next","versionMatch","exec","major","groups","majorVersion","parseInt","payload","ignore","onlyDirectories","configType","getProjectType","packageJsonType","type"],"mappings":"AAEA,YAAYA,OAAO,iBAAgB;AACnC,SAASC,KAAK,EAAEC,SAAS,QAAQ,eAAc;AAE/C,OAAOC,QAAQ,KAAI;AACnB,OAAOC,SAAS,WAAU;AAC1B,OAAOC,YAAY,SAAQ;AAC3B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AACvB,SAASC,SAAS,QAAQ,OAAM;AAIhC,SAASC,iBAAiB,QAAQ,kCAAiC;AACnE,SAASC,SAASC,S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EJ,OAAO;QACLM;QACAH;QACA2C;QACA9C;QACAgC;QACAxB,gBAAgBsD;QAChBd;IACF;AACF;AAEA,SAASe,eAAerE,IAGvB;IACC,MAAM,EAAEsC,cAAc,EAAEiB,UAAU,EAAE,GAAGvD;IAEvC,IAAIsC,eAAeI,QAAQ,CAAC,QAAQ;QAClC,OAAO;IACT;IAEA,IAAIJ,eAAeI,QAAQ,CAAC,SAAS;QACnC,OAAO;IACT;IACA,IAAIJ,eAAeI,QAAQ,CAAC,SAAS;QACnC,OAAO;IACT;IAEA,MAAM4B,kBAAkBf,WAAWgB,IAAI;IACvC,IAAID,oBAAoB,UAAU;QAChC,OAAO;IACT;IACA,IAAIA,oBAAoB,YAAY;QAClC,OAAO;IACT;IAEA,OAAO;AACT"}
@@ -14,7 +14,7 @@ export function getValidTemplates() {
14
14
  name: 'blank',
15
15
  type: 'starter',
16
16
  description: 'Blank 3.0 Template',
17
- url: 'https://github.com/payloadcms/payload/templates/blank-3.0#beta'
17
+ url: 'https://github.com/payloadcms/payload/templates/blank#beta'
18
18
  },
19
19
  {
20
20
  name: 'website',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/templates.ts"],"sourcesContent":["import type { ProjectTemplate } from '../types.js'\n\nimport { error, info } from '../utils/log.js'\n\nexport function validateTemplate(templateName: string): boolean {\n const validTemplates = getValidTemplates()\n if (!validTemplates.map((t) => t.name).includes(templateName)) {\n error(`'${templateName}' is not a valid template.`)\n info(`Valid templates: ${validTemplates.map((t) => t.name).join(', ')}`)\n return false\n }\n return true\n}\n\nexport function getValidTemplates(): ProjectTemplate[] {\n return [\n {\n name: 'blank',\n type: 'starter',\n description: 'Blank 3.0 Template',\n url: 'https://github.com/payloadcms/payload/templates/blank-3.0#beta',\n },\n {\n name: 'website',\n type: 'starter',\n description: 'Website Template',\n url: 'https://github.com/payloadcms/payload/templates/website#beta',\n },\n\n // Remove these until they have been updated for 3.0\n\n // {\n // name: 'blank',\n // type: 'starter',\n // description: 'Blank Template',\n // url: 'https://github.com/payloadcms/payload/templates/blank',\n // },\n // {\n // name: 'ecommerce',\n // type: 'starter',\n // description: 'E-commerce Template',\n // url: 'https://github.com/payloadcms/payload/templates/ecommerce',\n // },\n // {\n // name: 'plugin',\n // type: 'plugin',\n // description: 'Template for creating a Payload plugin',\n // url: 'https://github.com/payloadcms/payload-plugin-template#beta',\n // },\n // {\n // name: 'payload-demo',\n // type: 'starter',\n // description: 'Payload demo site at https://demo.payloadcms.com',\n // url: 'https://github.com/payloadcms/public-demo',\n // },\n // {\n // name: 'payload-website',\n // type: 'starter',\n // description: 'Payload website CMS at https://payloadcms.com',\n // url: 'https://github.com/payloadcms/website-cms',\n // },\n ]\n}\n"],"names":["error","info","validateTemplate","templateName","validTemplates","getValidTemplates","map","t","name","includes","join","type","description","url"],"mappings":"AAEA,SAASA,KAAK,EAAEC,IAAI,QAAQ,kBAAiB;AAE7C,OAAO,SAASC,iBAAiBC,YAAoB;IACnD,MAAMC,iBAAiBC;IACvB,IAAI,CAACD,eAAeE,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI,EAAEC,QAAQ,CAACN,eAAe;QAC7DH,MAAM,CAAC,CAAC,EAAEG,aAAa,0BAA0B,CAAC;QAClDF,KAAK,CAAC,iBAAiB,EAAEG,eAAeE,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI,EAAEE,IAAI,CAAC,MAAM,CAAC;QACvE,OAAO;IACT;IACA,OAAO;AACT;AAEA,OAAO,SAASL;IACd,OAAO;QACL;YACEG,MAAM;YACNG,MAAM;YACNC,aAAa;YACbC,KAAK;QACP;QACA;YACEL,MAAM;YACNG,MAAM;YACNC,aAAa;YACbC,KAAK;QACP;KAkCD;AACH"}
1
+ {"version":3,"sources":["../../src/lib/templates.ts"],"sourcesContent":["import type { ProjectTemplate } from '../types.js'\n\nimport { error, info } from '../utils/log.js'\n\nexport function validateTemplate(templateName: string): boolean {\n const validTemplates = getValidTemplates()\n if (!validTemplates.map((t) => t.name).includes(templateName)) {\n error(`'${templateName}' is not a valid template.`)\n info(`Valid templates: ${validTemplates.map((t) => t.name).join(', ')}`)\n return false\n }\n return true\n}\n\nexport function getValidTemplates(): ProjectTemplate[] {\n return [\n {\n name: 'blank',\n type: 'starter',\n description: 'Blank 3.0 Template',\n url: 'https://github.com/payloadcms/payload/templates/blank#beta',\n },\n {\n name: 'website',\n type: 'starter',\n description: 'Website Template',\n url: 'https://github.com/payloadcms/payload/templates/website#beta',\n },\n\n // Remove these until they have been updated for 3.0\n\n // {\n // name: 'blank',\n // type: 'starter',\n // description: 'Blank Template',\n // url: 'https://github.com/payloadcms/payload/templates/blank',\n // },\n // {\n // name: 'ecommerce',\n // type: 'starter',\n // description: 'E-commerce Template',\n // url: 'https://github.com/payloadcms/payload/templates/ecommerce',\n // },\n // {\n // name: 'plugin',\n // type: 'plugin',\n // description: 'Template for creating a Payload plugin',\n // url: 'https://github.com/payloadcms/payload-plugin-template#beta',\n // },\n // {\n // name: 'payload-demo',\n // type: 'starter',\n // description: 'Payload demo site at https://demo.payloadcms.com',\n // url: 'https://github.com/payloadcms/public-demo',\n // },\n // {\n // name: 'payload-website',\n // type: 'starter',\n // description: 'Payload website CMS at https://payloadcms.com',\n // url: 'https://github.com/payloadcms/website-cms',\n // },\n ]\n}\n"],"names":["error","info","validateTemplate","templateName","validTemplates","getValidTemplates","map","t","name","includes","join","type","description","url"],"mappings":"AAEA,SAASA,KAAK,EAAEC,IAAI,QAAQ,kBAAiB;AAE7C,OAAO,SAASC,iBAAiBC,YAAoB;IACnD,MAAMC,iBAAiBC;IACvB,IAAI,CAACD,eAAeE,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI,EAAEC,QAAQ,CAACN,eAAe;QAC7DH,MAAM,CAAC,CAAC,EAAEG,aAAa,0BAA0B,CAAC;QAClDF,KAAK,CAAC,iBAAiB,EAAEG,eAAeE,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI,EAAEE,IAAI,CAAC,MAAM,CAAC;QACvE,OAAO;IACT;IACA,OAAO;AACT;AAEA,OAAO,SAASL;IACd,OAAO;QACL;YACEG,MAAM;YACNG,MAAM;YACNC,aAAa;YACbC,KAAK;QACP;QACA;YACEL,MAAM;YACNG,MAAM;YACNC,aAAa;YACbC,KAAK;QACP;KAkCD;AACH"}
@@ -59,7 +59,7 @@ export async function updatePayloadInProject(appDetails) {
59
59
  }
60
60
  info('Payload packages updated successfully.');
61
61
  info(`Updating Payload Next.js files...`);
62
- const templateFilesPath = process.env.JEST_WORKER_ID !== undefined ? path.resolve(dirname, '../../../../templates/blank-3.0') : path.resolve(dirname, '../..', 'dist/template');
62
+ const templateFilesPath = process.env.JEST_WORKER_ID !== undefined ? path.resolve(dirname, '../../../../templates/blank') : path.resolve(dirname, '../..', 'dist/template');
63
63
  const templateSrcDir = path.resolve(templateFilesPath, 'src/app/(payload)');
64
64
  copyRecursiveSync(templateSrcDir, path.resolve(projectDir, appDetails.isSrcDir ? 'src/app' : 'app', '(payload)'));
65
65
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/update-payload-in-project.ts"],"sourcesContent":["import execa from 'execa'\nimport fse from 'fs-extra'\nimport { fileURLToPath } from 'node:url'\nimport path from 'path'\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nimport type { NextAppDetails } from '../types.js'\n\nimport { copyRecursiveSync } from '../utils/copy-recursive-sync.js'\nimport { info } from '../utils/log.js'\nimport { getPackageManager } from './get-package-manager.js'\nimport { installPackages } from './install-packages.js'\n\nexport async function updatePayloadInProject(\n appDetails: NextAppDetails,\n): Promise<{ message: string; success: boolean }> {\n if (!appDetails.nextConfigPath) return { message: 'No Next.js config found', success: false }\n\n const projectDir = path.dirname(appDetails.nextConfigPath)\n\n const packageObj = (await fse.readJson(path.resolve(projectDir, 'package.json'))) as {\n dependencies?: Record<string, string>\n }\n if (!packageObj?.dependencies) {\n throw new Error('No package.json found in this project')\n }\n\n const payloadVersion = packageObj.dependencies?.payload\n if (!payloadVersion) {\n throw new Error('Payload is not installed in this project')\n }\n\n const packageManager = await getPackageManager({ projectDir })\n\n // Fetch latest Payload version from npm\n const { exitCode: getLatestVersionExitCode, stdout: latestPayloadVersion } = await execa('npm', [\n 'show',\n 'payload@beta',\n 'version',\n ])\n if (getLatestVersionExitCode !== 0) {\n throw new Error('Failed to fetch latest Payload version')\n }\n\n if (payloadVersion === latestPayloadVersion) {\n return { message: `Payload v${payloadVersion} is already up to date.`, success: true }\n }\n\n // Update all existing Payload packages\n const payloadPackages = Object.keys(packageObj.dependencies).filter((dep) =>\n dep.startsWith('@payloadcms/'),\n )\n\n const packageNames = ['payload', ...payloadPackages]\n\n const packagesToUpdate = packageNames.map((pkg) => `${pkg}@${latestPayloadVersion}`)\n\n info(`Using ${packageManager}.\\n`)\n info(\n `Updating ${packagesToUpdate.length} Payload packages to v${latestPayloadVersion}...\\n\\n${packageNames.map((p) => ` - ${p}`).join('\\n')}`,\n )\n\n const { success: updateSuccess } = await installPackages({\n packageManager,\n packagesToInstall: packagesToUpdate,\n projectDir,\n })\n\n if (!updateSuccess) {\n throw new Error('Failed to update Payload packages')\n }\n info('Payload packages updated successfully.')\n\n info(`Updating Payload Next.js files...`)\n\n const templateFilesPath =\n process.env.JEST_WORKER_ID !== undefined\n ? path.resolve(dirname, '../../../../templates/blank-3.0')\n : path.resolve(dirname, '../..', 'dist/template')\n\n const templateSrcDir = path.resolve(templateFilesPath, 'src/app/(payload)')\n\n copyRecursiveSync(\n templateSrcDir,\n path.resolve(projectDir, appDetails.isSrcDir ? 'src/app' : 'app', '(payload)'),\n )\n\n return { message: 'Payload updated successfully.', success: true }\n}\n"],"names":["execa","fse","fileURLToPath","path","filename","url","dirname","copyRecursiveSync","info","getPackageManager","installPackages","updatePayloadInProject","appDetails","nextConfigPath","message","success","projectDir","packageObj","readJson","resolve","dependencies","Error","payloadVersion","payload","packageManager","exitCode","getLatestVersionExitCode","stdout","latestPayloadVersion","payloadPackages","Object","keys","filter","dep","startsWith","packageNames","packagesToUpdate","map","pkg","length","p","join","updateSuccess","packagesToInstall","templateFilesPath","process","env","JEST_WORKER_ID","undefined","templateSrcDir","isSrcDir"],"mappings":"AAAA,OAAOA,WAAW,QAAO;AACzB,OAAOC,SAAS,WAAU;AAC1B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AAEvB,MAAMC,WAAWF,cAAc,YAAYG,GAAG;AAC9C,MAAMC,UAAUH,KAAKG,OAAO,CAACF;AAI7B,SAASG,iBAAiB,QAAQ,kCAAiC;AACnE,SAASC,IAAI,QAAQ,kBAAiB;AACtC,SAASC,iBAAiB,QAAQ,2BAA0B;AAC5D,SAASC,eAAe,QAAQ,wBAAuB;AAEvD,OAAO,eAAeC,uBACpBC,UAA0B;IAE1B,IAAI,CAACA,WAAWC,cAAc,EAAE,OAAO;QAAEC,SAAS;QAA2BC,SAAS;IAAM;IAE5F,MAAMC,aAAab,KAAKG,OAAO,CAACM,WAAWC,cAAc;IAEzD,MAAMI,aAAc,MAAMhB,IAAIiB,QAAQ,CAACf,KAAKgB,OAAO,CAACH,YAAY;IAGhE,IAAI,CAACC,YAAYG,cAAc;QAC7B,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,iBAAiBL,WAAWG,YAAY,EAAEG;IAChD,IAAI,CAACD,gBAAgB;QACnB,MAAM,IAAID,MAAM;IAClB;IAEA,MAAMG,iBAAiB,MAAMf,kBAAkB;QAAEO;IAAW;IAE5D,wCAAwC;IACxC,MAAM,EAAES,UAAUC,wBAAwB,EAAEC,QAAQC,oBAAoB,EAAE,GAAG,MAAM5B,MAAM,OAAO;QAC9F;QACA;QACA;KACD;IACD,IAAI0B,6BAA6B,GAAG;QAClC,MAAM,IAAIL,MAAM;IAClB;IAEA,IAAIC,mBAAmBM,sBAAsB;QAC3C,OAAO;YAAEd,SAAS,CAAC,SAAS,EAAEQ,eAAe,uBAAuB,CAAC;YAAEP,SAAS;QAAK;IACvF;IAEA,uCAAuC;IACvC,MAAMc,kBAAkBC,OAAOC,IAAI,CAACd,WAAWG,YAAY,EAAEY,MAAM,CAAC,CAACC,MACnEA,IAAIC,UAAU,CAAC;IAGjB,MAAMC,eAAe;QAAC;WAAcN;KAAgB;IAEpD,MAAMO,mBAAmBD,aAAaE,GAAG,CAAC,CAACC,MAAQ,CAAC,EAAEA,IAAI,CAAC,EAAEV,qBAAqB,CAAC;IAEnFpB,KAAK,CAAC,MAAM,EAAEgB,eAAe,GAAG,CAAC;IACjChB,KACE,CAAC,SAAS,EAAE4B,iBAAiBG,MAAM,CAAC,sBAAsB,EAAEX,qBAAqB,OAAO,EAAEO,aAAaE,GAAG,CAAC,CAACG,IAAM,CAAC,IAAI,EAAEA,EAAE,CAAC,EAAEC,IAAI,CAAC,MAAM,CAAC;IAG5I,MAAM,EAAE1B,SAAS2B,aAAa,EAAE,GAAG,MAAMhC,gBAAgB;QACvDc;QACAmB,mBAAmBP;QACnBpB;IACF;IAEA,IAAI,CAAC0B,eAAe;QAClB,MAAM,IAAIrB,MAAM;IAClB;IACAb,KAAK;IAELA,KAAK,CAAC,iCAAiC,CAAC;IAExC,MAAMoC,oBACJC,QAAQC,GAAG,CAACC,cAAc,KAAKC,YAC3B7C,KAAKgB,OAAO,CAACb,SAAS,qCACtBH,KAAKgB,OAAO,CAACb,SAAS,SAAS;IAErC,MAAM2C,iBAAiB9C,KAAKgB,OAAO,CAACyB,mBAAmB;IAEvDrC,kBACE0C,gBACA9C,KAAKgB,OAAO,CAACH,YAAYJ,WAAWsC,QAAQ,GAAG,YAAY,OAAO;IAGpE,OAAO;QAAEpC,SAAS;QAAiCC,SAAS;IAAK;AACnE"}
1
+ {"version":3,"sources":["../../src/lib/update-payload-in-project.ts"],"sourcesContent":["import execa from 'execa'\nimport fse from 'fs-extra'\nimport { fileURLToPath } from 'node:url'\nimport path from 'path'\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nimport type { NextAppDetails } from '../types.js'\n\nimport { copyRecursiveSync } from '../utils/copy-recursive-sync.js'\nimport { info } from '../utils/log.js'\nimport { getPackageManager } from './get-package-manager.js'\nimport { installPackages } from './install-packages.js'\n\nexport async function updatePayloadInProject(\n appDetails: NextAppDetails,\n): Promise<{ message: string; success: boolean }> {\n if (!appDetails.nextConfigPath) return { message: 'No Next.js config found', success: false }\n\n const projectDir = path.dirname(appDetails.nextConfigPath)\n\n const packageObj = (await fse.readJson(path.resolve(projectDir, 'package.json'))) as {\n dependencies?: Record<string, string>\n }\n if (!packageObj?.dependencies) {\n throw new Error('No package.json found in this project')\n }\n\n const payloadVersion = packageObj.dependencies?.payload\n if (!payloadVersion) {\n throw new Error('Payload is not installed in this project')\n }\n\n const packageManager = await getPackageManager({ projectDir })\n\n // Fetch latest Payload version from npm\n const { exitCode: getLatestVersionExitCode, stdout: latestPayloadVersion } = await execa('npm', [\n 'show',\n 'payload@beta',\n 'version',\n ])\n if (getLatestVersionExitCode !== 0) {\n throw new Error('Failed to fetch latest Payload version')\n }\n\n if (payloadVersion === latestPayloadVersion) {\n return { message: `Payload v${payloadVersion} is already up to date.`, success: true }\n }\n\n // Update all existing Payload packages\n const payloadPackages = Object.keys(packageObj.dependencies).filter((dep) =>\n dep.startsWith('@payloadcms/'),\n )\n\n const packageNames = ['payload', ...payloadPackages]\n\n const packagesToUpdate = packageNames.map((pkg) => `${pkg}@${latestPayloadVersion}`)\n\n info(`Using ${packageManager}.\\n`)\n info(\n `Updating ${packagesToUpdate.length} Payload packages to v${latestPayloadVersion}...\\n\\n${packageNames.map((p) => ` - ${p}`).join('\\n')}`,\n )\n\n const { success: updateSuccess } = await installPackages({\n packageManager,\n packagesToInstall: packagesToUpdate,\n projectDir,\n })\n\n if (!updateSuccess) {\n throw new Error('Failed to update Payload packages')\n }\n info('Payload packages updated successfully.')\n\n info(`Updating Payload Next.js files...`)\n\n const templateFilesPath =\n process.env.JEST_WORKER_ID !== undefined\n ? path.resolve(dirname, '../../../../templates/blank')\n : path.resolve(dirname, '../..', 'dist/template')\n\n const templateSrcDir = path.resolve(templateFilesPath, 'src/app/(payload)')\n\n copyRecursiveSync(\n templateSrcDir,\n path.resolve(projectDir, appDetails.isSrcDir ? 'src/app' : 'app', '(payload)'),\n )\n\n return { message: 'Payload updated successfully.', success: true }\n}\n"],"names":["execa","fse","fileURLToPath","path","filename","url","dirname","copyRecursiveSync","info","getPackageManager","installPackages","updatePayloadInProject","appDetails","nextConfigPath","message","success","projectDir","packageObj","readJson","resolve","dependencies","Error","payloadVersion","payload","packageManager","exitCode","getLatestVersionExitCode","stdout","latestPayloadVersion","payloadPackages","Object","keys","filter","dep","startsWith","packageNames","packagesToUpdate","map","pkg","length","p","join","updateSuccess","packagesToInstall","templateFilesPath","process","env","JEST_WORKER_ID","undefined","templateSrcDir","isSrcDir"],"mappings":"AAAA,OAAOA,WAAW,QAAO;AACzB,OAAOC,SAAS,WAAU;AAC1B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AAEvB,MAAMC,WAAWF,cAAc,YAAYG,GAAG;AAC9C,MAAMC,UAAUH,KAAKG,OAAO,CAACF;AAI7B,SAASG,iBAAiB,QAAQ,kCAAiC;AACnE,SAASC,IAAI,QAAQ,kBAAiB;AACtC,SAASC,iBAAiB,QAAQ,2BAA0B;AAC5D,SAASC,eAAe,QAAQ,wBAAuB;AAEvD,OAAO,eAAeC,uBACpBC,UAA0B;IAE1B,IAAI,CAACA,WAAWC,cAAc,EAAE,OAAO;QAAEC,SAAS;QAA2BC,SAAS;IAAM;IAE5F,MAAMC,aAAab,KAAKG,OAAO,CAACM,WAAWC,cAAc;IAEzD,MAAMI,aAAc,MAAMhB,IAAIiB,QAAQ,CAACf,KAAKgB,OAAO,CAACH,YAAY;IAGhE,IAAI,CAACC,YAAYG,cAAc;QAC7B,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,iBAAiBL,WAAWG,YAAY,EAAEG;IAChD,IAAI,CAACD,gBAAgB;QACnB,MAAM,IAAID,M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iB9C,KAAKgB,OAAO,CAACyB,mBAAmB;IAEvDrC,kBACE0C,gBACA9C,KAAKgB,OAAO,CAACH,YAAYJ,WAAWsC,QAAQ,GAAG,YAAY,OAAO;IAGpE,OAAO;QAAEpC,SAAS;QAAiCC,SAAS;IAAK;AACnE"}
@@ -1,4 +1,4 @@
1
- import swc from '@swc/core';
1
+ import { parse } from '@swc/core';
2
2
  import chalk from 'chalk';
3
3
  import { Syntax, parseModule } from 'esprima-next';
4
4
  import fs from 'fs';
@@ -173,9 +173,9 @@ function insertBeforeAndAfterSWC(content, span, /**
173
173
  *
174
174
  * https://github.com/swc-project/swc/issues/1366
175
175
  */ if (process.env.NODE_ENV === 'test') {
176
- parseOffset = (await swc.parse('')).span.end;
176
+ parseOffset = (await parse('')).span.end;
177
177
  }
178
- const module = await swc.parse(fileContent, {
178
+ const module = await parse(fileContent, {
179
179
  syntax: 'typescript'
180
180
  });
181
181
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/wrap-next-config.ts"],"sourcesContent":["import type { ExportDefaultExpression, ModuleItem } from '@swc/core'\n\nimport swc from '@swc/core'\nimport chalk from 'chalk'\nimport { Syntax, parseModule } from 'esprima-next'\nimport fs from 'fs'\n\nimport type { NextConfigType } from '../types.js'\n\nimport { log, warning } from '../utils/log.js'\n\nexport const withPayloadStatement = {\n cjs: `const { withPayload } = require(\"@payloadcms/next/withPayload\");`,\n esm: `import { withPayload } from \"@payloadcms/next/withPayload\";`,\n ts: `import { withPayload } from \"@payloadcms/next/withPayload\";`,\n}\n\nexport const wrapNextConfig = async (args: {\n nextConfigPath: string\n nextConfigType: NextConfigType\n}) => {\n const { nextConfigPath, nextConfigType: configType } = args\n const configContent = fs.readFileSync(nextConfigPath, 'utf8')\n const { modifiedConfigContent: newConfig, success } = await parseAndModifyConfigContent(\n configContent,\n configType,\n )\n\n if (!success) {\n return\n }\n\n fs.writeFileSync(nextConfigPath, newConfig)\n}\n\n/**\n * Parses config content with AST and wraps it with withPayload function\n */\nexport async function parseAndModifyConfigContent(\n content: string,\n configType: NextConfigType,\n): Promise<{ modifiedConfigContent: string; success: boolean }> {\n content = withPayloadStatement[configType] + '\\n' + content\n\n console.log({ configType, content })\n\n if (configType === 'cjs' || configType === 'esm') {\n try {\n const ast = parseModule(content, { loc: true })\n\n if (configType === 'cjs') {\n // Find `module.exports = X`\n const moduleExports = ast.body.find(\n (p) =>\n p.type === Syntax.ExpressionStatement &&\n p.expression?.type === Syntax.AssignmentExpression &&\n p.expression.left?.type === Syntax.MemberExpression &&\n p.expression.left.object?.type === Syntax.Identifier &&\n p.expression.left.object.name === 'module' &&\n p.expression.left.property?.type === Syntax.Identifier &&\n p.expression.left.property.name === 'exports',\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) as any\n\n if (moduleExports && moduleExports.expression.right?.loc) {\n const modifiedConfigContent = insertBeforeAndAfter(\n content,\n moduleExports.expression.right.loc,\n )\n return { modifiedConfigContent, success: true }\n }\n\n return Promise.resolve({\n modifiedConfigContent: content,\n success: false,\n })\n } else if (configType === 'esm') {\n const exportDefaultDeclaration = ast.body.find(\n (p) => p.type === Syntax.ExportDefaultDeclaration,\n ) as Directive | undefined\n\n const exportNamedDeclaration = ast.body.find(\n (p) => p.type === Syntax.ExportNamedDeclaration,\n ) as ExportNamedDeclaration | undefined\n\n if (!exportDefaultDeclaration && !exportNamedDeclaration) {\n throw new Error('Could not find ExportDefaultDeclaration in next.config.js')\n }\n\n if (exportDefaultDeclaration && exportDefaultDeclaration.declaration?.loc) {\n const modifiedConfigContent = insertBeforeAndAfter(\n content,\n exportDefaultDeclaration.declaration.loc,\n )\n return { modifiedConfigContent, success: true }\n } else if (exportNamedDeclaration) {\n const exportSpecifier = exportNamedDeclaration.specifiers.find(\n (s) =>\n s.type === 'ExportSpecifier' &&\n s.exported?.name === 'default' &&\n s.local?.type === 'Identifier' &&\n s.local?.name,\n )\n\n if (exportSpecifier) {\n warning('Could not automatically wrap next.config.js with withPayload.')\n warning('Automatic wrapping of named exports as default not supported yet.')\n\n warnUserWrapNotSuccessful(configType)\n return {\n modifiedConfigContent: content,\n success: false,\n }\n }\n }\n\n warning('Could not automatically wrap Next config with withPayload.')\n warnUserWrapNotSuccessful(configType)\n return Promise.resolve({\n modifiedConfigContent: content,\n success: false,\n })\n }\n } catch (error: unknown) {\n if (error instanceof Error) {\n warning(`Unable to parse Next config. Error: ${error.message} `)\n warnUserWrapNotSuccessful(configType)\n }\n return {\n modifiedConfigContent: content,\n success: false,\n }\n }\n } else if (configType === 'ts') {\n const { moduleItems, parseOffset } = await compileTypeScriptFileToAST(content)\n\n const exportDefaultDeclaration = moduleItems.find(\n (m) =>\n m.type === 'ExportDefaultExpression' &&\n (m.expression.type === 'Identifier' || m.expression.type === 'CallExpression'),\n ) as ExportDefaultExpression | undefined\n\n if (exportDefaultDeclaration) {\n if (!('span' in exportDefaultDeclaration.expression)) {\n warning('Could not automatically wrap Next config with withPayload.')\n warnUserWrapNotSuccessful(configType)\n return Promise.resolve({\n modifiedConfigContent: content,\n success: false,\n })\n }\n\n const modifiedConfigContent = insertBeforeAndAfterSWC(\n content,\n exportDefaultDeclaration.expression.span,\n parseOffset,\n )\n return { modifiedConfigContent, success: true }\n }\n }\n\n warning('Could not automatically wrap Next config with withPayload.')\n warnUserWrapNotSuccessful(configType)\n return Promise.resolve({\n modifiedConfigContent: content,\n success: false,\n })\n}\n\nfunction warnUserWrapNotSuccessful(configType: NextConfigType) {\n // Output directions for user to update next.config.js\n const withPayloadMessage = `\n\n ${chalk.bold(`Please manually wrap your existing Next config with the withPayload function. Here is an example:`)}\n\n ${withPayloadStatement[configType]}\n\n const nextConfig = {\n // Your Next.js config here\n }\n\n ${configType === 'cjs' ? 'module.exports = withPayload(nextConfig)' : 'export default withPayload(nextConfig)'}\n\n`\n\n log(withPayloadMessage)\n}\n\ntype Directive = {\n declaration?: {\n loc: Loc\n }\n}\n\ntype ExportNamedDeclaration = {\n declaration: null\n loc: Loc\n specifiers: {\n exported: {\n loc: Loc\n name: string\n type: string\n }\n loc: Loc\n local: {\n loc: Loc\n name: string\n type: string\n }\n type: string\n }[]\n type: string\n}\n\ntype Loc = {\n end: { column: number; line: number }\n start: { column: number; line: number }\n}\n\nfunction insertBeforeAndAfter(content: string, loc: Loc): string {\n const { end, start } = loc\n const lines = content.split('\\n')\n\n const insert = (line: string, column: number, text: string) => {\n return line.slice(0, column) + text + line.slice(column)\n }\n\n // insert ) after end\n lines[end.line - 1] = insert(lines[end.line - 1], end.column, ')')\n // insert withPayload before start\n if (start.line === end.line) {\n lines[end.line - 1] = insert(lines[end.line - 1], start.column, 'withPayload(')\n } else {\n lines[start.line - 1] = insert(lines[start.line - 1], start.column, 'withPayload(')\n }\n\n return lines.join('\\n')\n}\n\nfunction insertBeforeAndAfterSWC(\n content: string,\n span: ModuleItem['span'],\n /**\n * WARNING: This is ONLY for unit tests. Defaults to 0 otherwise.\n *\n * @see compileTypeScriptFileToAST\n */\n parseOffset: number,\n): string {\n const { end: preOffsetEnd, start: preOffsetStart } = span\n\n const start = preOffsetStart - parseOffset\n const end = preOffsetEnd - parseOffset\n\n const insert = (pos: number, text: string): string => {\n return content.slice(0, pos) + text + content.slice(pos)\n }\n\n // insert ) after end\n content = insert(end - 1, ')')\n // insert withPayload before start\n content = insert(start - 1, 'withPayload(')\n\n return content\n}\n\n/**\n * Compile typescript to AST using the swc compiler\n */\nasync function compileTypeScriptFileToAST(\n fileContent: string,\n): Promise<{ moduleItems: ModuleItem[]; parseOffset: number }> {\n let parseOffset = 0\n\n /**\n * WARNING: This is ONLY for unit tests.\n *\n * Multiple instances of swc DO NOT reset the .span.end value.\n * During unit tests, the .spawn.end value is read and accounted for.\n *\n * https://github.com/swc-project/swc/issues/1366\n */\n if (process.env.NODE_ENV === 'test') {\n parseOffset = (await swc.parse('')).span.end\n }\n\n const module = await swc.parse(fileContent, {\n syntax: 'typescript',\n })\n\n return { moduleItems: module.body, parseOffset }\n}\n"],"names":["swc","chalk","Syntax","parseModule","fs","log","warning","withPayloadStatement","cjs","esm","ts","wrapNextConfig","args","nextConfigPath","nextConfigType","configType","configContent","readFileSync","modifiedConfigContent","newConfig","success","parseAndModifyConfigContent","writeFileSync","content","console","ast","loc","moduleExports","body","find","p","type","ExpressionStatement","expression","AssignmentExpression","left","MemberExpression","object","Identifier","name","property","right","insertBeforeAndAfter","Promise","resolve","exportDefaultDeclaration","ExportDefaultDeclaration","exportNamedDeclaration","ExportNamedDeclaration","Error","declaration","exportSpecifier","specifiers","s","exported","local","warnUserWrapNotSuccessful","error","message","moduleItems","parseOffset","compileTypeScriptFileToAST","m","insertBeforeAndAfterSWC","span","withPayloadMessage","bold","end","start","lines","split","insert","line","column","text","slice","join","preOffsetEnd","preOffsetStart","pos","fileContent","process","env","NODE_ENV","parse","module","syntax"],"mappings":"AAEA,OAAOA,SAAS,YAAW;AAC3B,OAAOC,WAAW,QAAO;AACzB,SAASC,MAAM,EAAEC,WAAW,QAAQ,eAAc;AAClD,OAAOC,QAAQ,KAAI;AAInB,SAASC,GAAG,EAAEC,OAAO,QAAQ,kBAAiB;AAE9C,OAAO,MAAMC,uBAAuB;IAClCC,KAAK,CAAC,gEAAgE,CAAC;IACvEC,KAAK,CAAC,2DAA2D,CAAC;IAClEC,IAAI,CAAC,2DAA2D,CAAC;AACnE,EAAC;AAED,OAAO,MAAMC,iBAAiB,OAAOC;IAInC,MAAM,EAAEC,cAAc,EAAEC,gBAAgBC,UAAU,EAAE,GAAGH;IACvD,MAAMI,gBAAgBZ,GAAGa,YAAY,CAACJ,gBAAgB;IACtD,MAAM,EAAEK,uBAAuBC,SAAS,EAAEC,OAAO,EAAE,GAAG,MAAMC,4BAC1DL,eACAD;IAGF,IAAI,CAACK,SAAS;QACZ;IACF;IAEAhB,GAAGkB,aAAa,CAACT,gBAAgBM;AACnC,EAAC;AAED;;CAEC,GACD,OAAO,eAAeE,4BACpBE,OAAe,EACfR,UAA0B;IAE1BQ,UAAUhB,oBAAoB,CAACQ,WAAW,GAA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AOF,KAAK,CAACF,IAAIK,IAAI,GAAG,EAAE,EAAEJ,MAAMK,MAAM,EAAE;IAClE,OAAO;QACLJ,KAAK,CAACD,MAAMI,IAAI,GAAG,EAAE,GAAGD,OAAOF,KAAK,CAACD,MAAMI,IAAI,GAAG,EAAE,EAAEJ,MAAMK,MAAM,EAAE;IACtE;IAEA,OAAOJ,MAAMO,IAAI,CAAC;AACpB;AAEA,SAASb,wBACPxC,OAAe,EACfyC,IAAwB,EACxB;;;;GAIC,GACDJ,WAAmB;IAEnB,MAAM,EAAEO,KAAKU,YAAY,EAAET,OAAOU,cAAc,EAAE,GAAGd;IAErD,MAAMI,QAAQU,iBAAiBlB;IAC/B,MAAMO,MAAMU,eAAejB;IAE3B,MAAMW,SAAS,CAACQ,KAAaL;QAC3B,OAAOnD,QAAQoD,KAAK,CAAC,GAAGI,OAAOL,OAAOnD,QAAQoD,KAAK,CAACI;IACtD;IAEA,qBAAqB;IACrBxD,UAAUgD,OAAOJ,MAAM,GAAG;IAC1B,kCAAkC;IAClC5C,UAAUgD,OAAOH,QAAQ,GAAG;IAE5B,OAAO7C;AACT;AAEA;;CAEC,GACD,eAAesC,2BACbmB,WAAmB;IAEnB,IAAIpB,cAAc;IAElB;;;;;;;GAOC,GACD,IAAIqB,QAAQC,GAAG,CAACC,QAAQ,KAAK,QAAQ;QACnCvB,cAAc,AAAC,CAAA,MAAM5D,IAAIoF,KAAK,CAAC,GAAE,EAAGpB,IAAI,CAACG,GAAG;IAC9C;IAEA,MAAMkB,SAAS,MAAMrF,IAAIoF,KAAK,CAACJ,aAAa;QAC1CM,QAAQ;IACV;IAEA,OAAO;QAAE3B,aAAa0B,OAAOzD,IAAI;QAAEgC;IAAY;AACjD"}
1
+ {"version":3,"sources":["../../src/lib/wrap-next-config.ts"],"sourcesContent":["import type { ExportDefaultExpression, ModuleItem } from '@swc/core'\n\nimport { parse } from '@swc/core'\nimport chalk from 'chalk'\nimport { Syntax, parseModule } from 'esprima-next'\nimport fs from 'fs'\n\nimport type { NextConfigType } from '../types.js'\n\nimport { log, warning } from '../utils/log.js'\n\nexport const withPayloadStatement = {\n cjs: `const { withPayload } = require(\"@payloadcms/next/withPayload\");`,\n esm: `import { withPayload } from \"@payloadcms/next/withPayload\";`,\n ts: `import { withPayload } from \"@payloadcms/next/withPayload\";`,\n}\n\nexport const wrapNextConfig = async (args: {\n nextConfigPath: string\n nextConfigType: NextConfigType\n}) => {\n const { nextConfigPath, nextConfigType: configType } = args\n const configContent = fs.readFileSync(nextConfigPath, 'utf8')\n const { modifiedConfigContent: newConfig, success } = await parseAndModifyConfigContent(\n configContent,\n configType,\n )\n\n if (!success) {\n return\n }\n\n fs.writeFileSync(nextConfigPath, newConfig)\n}\n\n/**\n * Parses config content with AST and wraps it with withPayload function\n */\nexport async function parseAndModifyConfigContent(\n content: string,\n configType: NextConfigType,\n): Promise<{ modifiedConfigContent: string; success: boolean }> {\n content = withPayloadStatement[configType] + '\\n' + content\n\n console.log({ configType, content })\n\n if (configType === 'cjs' || configType === 'esm') {\n try {\n const ast = parseModule(content, { loc: true })\n\n if (configType === 'cjs') {\n // Find `module.exports = X`\n const moduleExports = ast.body.find(\n (p) =>\n p.type === Syntax.ExpressionStatement &&\n p.expression?.type === Syntax.AssignmentExpression &&\n p.expression.left?.type === Syntax.MemberExpression &&\n p.expression.left.object?.type === Syntax.Identifier &&\n p.expression.left.object.name === 'module' &&\n p.expression.left.property?.type === Syntax.Identifier &&\n p.expression.left.property.name === 'exports',\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) as any\n\n if (moduleExports && moduleExports.expression.right?.loc) {\n const modifiedConfigContent = insertBeforeAndAfter(\n content,\n moduleExports.expression.right.loc,\n )\n return { modifiedConfigContent, success: true }\n }\n\n return Promise.resolve({\n modifiedConfigContent: content,\n success: false,\n })\n } else if (configType === 'esm') {\n const exportDefaultDeclaration = ast.body.find(\n (p) => p.type === Syntax.ExportDefaultDeclaration,\n ) as Directive | undefined\n\n const exportNamedDeclaration = ast.body.find(\n (p) => p.type === Syntax.ExportNamedDeclaration,\n ) as ExportNamedDeclaration | undefined\n\n if (!exportDefaultDeclaration && !exportNamedDeclaration) {\n throw new Error('Could not find ExportDefaultDeclaration in next.config.js')\n }\n\n if (exportDefaultDeclaration && exportDefaultDeclaration.declaration?.loc) {\n const modifiedConfigContent = insertBeforeAndAfter(\n content,\n exportDefaultDeclaration.declaration.loc,\n )\n return { modifiedConfigContent, success: true }\n } else if (exportNamedDeclaration) {\n const exportSpecifier = exportNamedDeclaration.specifiers.find(\n (s) =>\n s.type === 'ExportSpecifier' &&\n s.exported?.name === 'default' &&\n s.local?.type === 'Identifier' &&\n s.local?.name,\n )\n\n if (exportSpecifier) {\n warning('Could not automatically wrap next.config.js with withPayload.')\n warning('Automatic wrapping of named exports as default not supported yet.')\n\n warnUserWrapNotSuccessful(configType)\n return {\n modifiedConfigContent: content,\n success: false,\n }\n }\n }\n\n warning('Could not automatically wrap Next config with withPayload.')\n warnUserWrapNotSuccessful(configType)\n return Promise.resolve({\n modifiedConfigContent: content,\n success: false,\n })\n }\n } catch (error: unknown) {\n if (error instanceof Error) {\n warning(`Unable to parse Next config. Error: ${error.message} `)\n warnUserWrapNotSuccessful(configType)\n }\n return {\n modifiedConfigContent: content,\n success: false,\n }\n }\n } else if (configType === 'ts') {\n const { moduleItems, parseOffset } = await compileTypeScriptFileToAST(content)\n\n const exportDefaultDeclaration = moduleItems.find(\n (m) =>\n m.type === 'ExportDefaultExpression' &&\n (m.expression.type === 'Identifier' || m.expression.type === 'CallExpression'),\n ) as ExportDefaultExpression | undefined\n\n if (exportDefaultDeclaration) {\n if (!('span' in exportDefaultDeclaration.expression)) {\n warning('Could not automatically wrap Next config with withPayload.')\n warnUserWrapNotSuccessful(configType)\n return Promise.resolve({\n modifiedConfigContent: content,\n success: false,\n })\n }\n\n const modifiedConfigContent = insertBeforeAndAfterSWC(\n content,\n exportDefaultDeclaration.expression.span,\n parseOffset,\n )\n return { modifiedConfigContent, success: true }\n }\n }\n\n warning('Could not automatically wrap Next config with withPayload.')\n warnUserWrapNotSuccessful(configType)\n return Promise.resolve({\n modifiedConfigContent: content,\n success: false,\n })\n}\n\nfunction warnUserWrapNotSuccessful(configType: NextConfigType) {\n // Output directions for user to update next.config.js\n const withPayloadMessage = `\n\n ${chalk.bold(`Please manually wrap your existing Next config with the withPayload function. Here is an example:`)}\n\n ${withPayloadStatement[configType]}\n\n const nextConfig = {\n // Your Next.js config here\n }\n\n ${configType === 'cjs' ? 'module.exports = withPayload(nextConfig)' : 'export default withPayload(nextConfig)'}\n\n`\n\n log(withPayloadMessage)\n}\n\ntype Directive = {\n declaration?: {\n loc: Loc\n }\n}\n\ntype ExportNamedDeclaration = {\n declaration: null\n loc: Loc\n specifiers: {\n exported: {\n loc: Loc\n name: string\n type: string\n }\n loc: Loc\n local: {\n loc: Loc\n name: string\n type: string\n }\n type: string\n }[]\n type: string\n}\n\ntype Loc = {\n end: { column: number; line: number }\n start: { column: number; line: number }\n}\n\nfunction insertBeforeAndAfter(content: string, loc: Loc): string {\n const { end, start } = loc\n const lines = content.split('\\n')\n\n const insert = (line: string, column: number, text: string) => {\n return line.slice(0, column) + text + line.slice(column)\n }\n\n // insert ) after end\n lines[end.line - 1] = insert(lines[end.line - 1], end.column, ')')\n // insert withPayload before start\n if (start.line === end.line) {\n lines[end.line - 1] = insert(lines[end.line - 1], start.column, 'withPayload(')\n } else {\n lines[start.line - 1] = insert(lines[start.line - 1], start.column, 'withPayload(')\n }\n\n return lines.join('\\n')\n}\n\nfunction insertBeforeAndAfterSWC(\n content: string,\n span: ModuleItem['span'],\n /**\n * WARNING: This is ONLY for unit tests. Defaults to 0 otherwise.\n *\n * @see compileTypeScriptFileToAST\n */\n parseOffset: number,\n): string {\n const { end: preOffsetEnd, start: preOffsetStart } = span\n\n const start = preOffsetStart - parseOffset\n const end = preOffsetEnd - parseOffset\n\n const insert = (pos: number, text: string): string => {\n return content.slice(0, pos) + text + content.slice(pos)\n }\n\n // insert ) after end\n content = insert(end - 1, ')')\n // insert withPayload before start\n content = insert(start - 1, 'withPayload(')\n\n return content\n}\n\n/**\n * Compile typescript to AST using the swc compiler\n */\nasync function compileTypeScriptFileToAST(\n fileContent: string,\n): Promise<{ moduleItems: ModuleItem[]; parseOffset: number }> {\n let parseOffset = 0\n\n /**\n * WARNING: This is ONLY for unit tests.\n *\n * Multiple instances of swc DO NOT reset the .span.end value.\n * During unit tests, the .spawn.end value is read and accounted for.\n *\n * https://github.com/swc-project/swc/issues/1366\n */\n if (process.env.NODE_ENV === 'test') {\n parseOffset = (await parse('')).span.end\n }\n\n const module = await parse(fileContent, {\n syntax: 'typescript',\n })\n\n return { moduleItems: module.body, parseOffset }\n}\n"],"names":["parse","chalk","Syntax","parseModule","fs","log","warning","withPayloadStatement","cjs","esm","ts","wrapNextConfig","args","nextConfigPath","nextConfigType","configType","configContent","readFileSync","modifiedConfigContent","newConfig","success","parseAndModifyConfigContent","writeFileSync","content","console","ast","loc","moduleExports","body","find","p","type","ExpressionStatement","expression","AssignmentExpression","left","MemberExpression","object","Identifier","name","property","right","insertBeforeAndAfter","Promise","resolve","exportDefaultDeclaration","ExportDefaultDeclaration","exportNamedDeclaration","ExportNamedDeclaration","Error","declaration","exportSpecifier","specifiers","s","exported","local","warnUserWrapNotSuccessful","error","message","moduleItems","parseOffset","compileTypeScriptFileToAST","m","insertBeforeAndAfterSWC","span","withPayloadMessage","bold","end","start","lines","split","insert","line","column","text","slice","join","preOffsetEnd","preOffsetStart","pos","fileContent","process","env","NODE_ENV","module","syntax"],"mappings":"AAEA,SAASA,KAAK,QAAQ,YAAW;AACjC,OAAOC,WAAW,QAAO;AACzB,SAASC,MAAM,EAAEC,WAAW,QAAQ,eAAc;AAClD,OAAOC,QAAQ,KAAI;AAInB,SAASC,GAAG,EAAEC,OAAO,QAAQ,kBAAiB;AAE9C,OAAO,MAAMC,uBAAuB;IAClCC,KAAK,CAAC,gEAAgE,CAAC;IACvEC,KAAK,CAAC,2DAA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ElB;;;;;;;GAOC,GACD,IAAIqB,QAAQC,GAAG,CAACC,QAAQ,KAAK,QAAQ;QACnCvB,cAAc,AAAC,CAAA,MAAM5D,MAAM,GAAE,EAAGgE,IAAI,CAACG,GAAG;IAC1C;IAEA,MAAMiB,SAAS,MAAMpF,MAAMgF,aAAa;QACtCK,QAAQ;IACV;IAEA,OAAO;QAAE1B,aAAayB,OAAOxD,IAAI;QAAEgC;IAAY;AACjD"}
@@ -7,13 +7,13 @@ const dirname = path.dirname(filename);
7
7
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
8
8
  main();
9
9
  /**
10
- * Copy the necessary template files from `templates/blank-3.0` to `dist/template`
10
+ * Copy the necessary template files from `templates/blank` to `dist/template`
11
11
  *
12
12
  * Eventually, this should be replaced with using tar.x to stream from the git repo
13
13
  */ async function main() {
14
14
  const root = path.resolve(dirname, '../../../../');
15
15
  const outputPath = path.resolve(dirname, '../../dist/template');
16
- const sourceTemplatePath = path.resolve(root, 'templates/blank-3.0');
16
+ const sourceTemplatePath = path.resolve(root, 'templates/blank');
17
17
  if (!fs.existsSync(sourceTemplatePath)) {
18
18
  throw new Error(`Source path does not exist: ${sourceTemplatePath}`);
19
19
  }
@@ -22,7 +22,7 @@ main();
22
22
  recursive: true
23
23
  });
24
24
  }
25
- // Copy the src directory from `templates/blank-3.0` to `dist`
25
+ // Copy the src directory from `templates/blank` to `dist`
26
26
  const srcPath = path.resolve(sourceTemplatePath, 'src');
27
27
  const distSrcPath = path.resolve(outputPath, 'src');
28
28
  // Copy entire file structure from src to dist
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/scripts/pack-template-files.ts"],"sourcesContent":["import fs from 'fs'\nimport fsp from 'fs/promises'\nimport { fileURLToPath } from 'node:url'\nimport path from 'path'\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\n// eslint-disable-next-line @typescript-eslint/no-floating-promises\nmain()\n\n/**\n * Copy the necessary template files from `templates/blank-3.0` to `dist/template`\n *\n * Eventually, this should be replaced with using tar.x to stream from the git repo\n */\n\nasync function main() {\n const root = path.resolve(dirname, '../../../../')\n const outputPath = path.resolve(dirname, '../../dist/template')\n const sourceTemplatePath = path.resolve(root, 'templates/blank-3.0')\n\n if (!fs.existsSync(sourceTemplatePath)) {\n throw new Error(`Source path does not exist: ${sourceTemplatePath}`)\n }\n\n if (!fs.existsSync(outputPath)) {\n fs.mkdirSync(outputPath, { recursive: true })\n }\n\n // Copy the src directory from `templates/blank-3.0` to `dist`\n const srcPath = path.resolve(sourceTemplatePath, 'src')\n const distSrcPath = path.resolve(outputPath, 'src')\n // Copy entire file structure from src to dist\n await fsp.cp(srcPath, distSrcPath, { recursive: true })\n}\n"],"names":["fs","fsp","fileURLToPath","path","filename","url","dirname","main","root","resolve","outputPath","sourceTemplatePath","existsSync","Error","mkdirSync","recursive","srcPath","distSrcPath","cp"],"mappings":"AAAA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,SAAS,cAAa;AAC7B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AACvB,MAAMC,WAAWF,cAAc,YAAYG,GAAG;AAC9C,MAAMC,UAAUH,KAAKG,OAAO,CAACF;AAE7B,mEAAmE;AACnEG;AAEA;;;;CAIC,GAED,eAAeA;IACb,MAAMC,OAAOL,KAAKM,OAAO,CAACH,SAAS;IACnC,MAAMI,aAAaP,KAAKM,OAAO,CAACH,SAAS;IACzC,MAAMK,qBAAqBR,KAAKM,OAAO,CAACD,MAAM;IAE9C,IAAI,CAACR,GAAGY,UAAU,CAACD,qBAAqB;QACtC,MAAM,IAAIE,MAAM,CAAC,4BAA4B,EAAEF,mBAAmB,CAAC;IACrE;IAEA,IAAI,CAACX,GAAGY,UAAU,CAACF,aAAa;QAC9BV,GAAGc,SAAS,CAACJ,YAAY;YAAEK,WAAW;QAAK;IAC7C;IAEA,8DAA8D;IAC9D,MAAMC,UAAUb,KAAKM,OAAO,CAACE,oBAAoB;IACjD,MAAMM,cAAcd,KAAKM,OAAO,CAACC,YAAY;IAC7C,8CAA8C;IAC9C,MAAMT,IAAIiB,EAAE,CAACF,SAASC,aAAa;QAAEF,WAAW;IAAK;AACvD"}
1
+ {"version":3,"sources":["../../src/scripts/pack-template-files.ts"],"sourcesContent":["import fs from 'fs'\nimport fsp from 'fs/promises'\nimport { fileURLToPath } from 'node:url'\nimport path from 'path'\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\n// eslint-disable-next-line @typescript-eslint/no-floating-promises\nmain()\n\n/**\n * Copy the necessary template files from `templates/blank` to `dist/template`\n *\n * Eventually, this should be replaced with using tar.x to stream from the git repo\n */\n\nasync function main() {\n const root = path.resolve(dirname, '../../../../')\n const outputPath = path.resolve(dirname, '../../dist/template')\n const sourceTemplatePath = path.resolve(root, 'templates/blank')\n\n if (!fs.existsSync(sourceTemplatePath)) {\n throw new Error(`Source path does not exist: ${sourceTemplatePath}`)\n }\n\n if (!fs.existsSync(outputPath)) {\n fs.mkdirSync(outputPath, { recursive: true })\n }\n\n // Copy the src directory from `templates/blank` to `dist`\n const srcPath = path.resolve(sourceTemplatePath, 'src')\n const distSrcPath = path.resolve(outputPath, 'src')\n // Copy entire file structure from src to dist\n await fsp.cp(srcPath, distSrcPath, { recursive: true })\n}\n"],"names":["fs","fsp","fileURLToPath","path","filename","url","dirname","main","root","resolve","outputPath","sourceTemplatePath","existsSync","Error","mkdirSync","recursive","srcPath","distSrcPath","cp"],"mappings":"AAAA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,SAAS,cAAa;AAC7B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AACvB,MAAMC,WAAWF,cAAc,YAAYG,GAAG;AAC9C,MAAMC,UAAUH,KAAKG,OAAO,CAACF;AAE7B,mEAAmE;AACnEG;AAEA;;;;CAIC,GAED,eAAeA;IACb,MAAMC,OAAOL,KAAKM,OAAO,CAACH,SAAS;IACnC,MAAMI,aAAaP,KAAKM,OAAO,CAACH,SAAS;IACzC,MAAMK,qBAAqBR,KAAKM,OAAO,CAACD,MAAM;IAE9C,IAAI,CAACR,GAAGY,UAAU,CAACD,qBAAqB;QACtC,MAAM,IAAIE,MAAM,CAAC,4BAA4B,EAAEF,mBAAmB,CAAC;IACrE;IAEA,IAAI,CAACX,GAAGY,UAAU,CAACF,aAAa;QAC9BV,GAAGc,SAAS,CAACJ,YAAY;YAAEK,WAAW;QAAK;IAC7C;IAEA,0DAA0D;IAC1D,MAAMC,UAAUb,KAAKM,OAAO,CAACE,oBAAoB;IACjD,MAAMM,cAAcd,KAAKM,OAAO,CAACC,YAAY;IAC7C,8CAA8C;IAC9C,MAAMT,IAAIiB,EAAE,CAACF,SAASC,aAAa;QAAEF,WAAW;IAAK;AACvD"}
@@ -4,6 +4,7 @@ import type { Metadata } from 'next'
4
4
  import config from '@payload-config'
5
5
  /* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
6
6
  import { NotFoundPage, generatePageMetadata } from '@payloadcms/next/views'
7
+ import { importMap } from '../importMap'
7
8
 
8
9
  type Args = {
9
10
  params: {
@@ -17,6 +18,7 @@ type Args = {
17
18
  export const generateMetadata = ({ params, searchParams }: Args): Promise<Metadata> =>
18
19
  generatePageMetadata({ config, params, searchParams })
19
20
 
20
- const NotFound = ({ params, searchParams }: Args) => NotFoundPage({ config, params, searchParams })
21
+ const NotFound = ({ params, searchParams }: Args) =>
22
+ NotFoundPage({ config, params, searchParams, importMap })
21
23
 
22
24
  export default NotFound
@@ -4,6 +4,7 @@ import type { Metadata } from 'next'
4
4
  import config from '@payload-config'
5
5
  /* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
6
6
  import { RootPage, generatePageMetadata } from '@payloadcms/next/views'
7
+ import { importMap } from '../importMap'
7
8
 
8
9
  type Args = {
9
10
  params: {
@@ -17,6 +18,7 @@ type Args = {
17
18
  export const generateMetadata = ({ params, searchParams }: Args): Promise<Metadata> =>
18
19
  generatePageMetadata({ config, params, searchParams })
19
20
 
20
- const Page = ({ params, searchParams }: Args) => RootPage({ config, params, searchParams })
21
+ const Page = ({ params, searchParams }: Args) =>
22
+ RootPage({ config, params, searchParams, importMap })
21
23
 
22
24
  export default Page
@@ -0,0 +1 @@
1
+ export const importMap = {}
@@ -6,11 +6,16 @@ import { RootLayout } from '@payloadcms/next/layouts'
6
6
  import React from 'react'
7
7
 
8
8
  import './custom.scss'
9
+ import { importMap } from './admin/importMap'
9
10
 
10
11
  type Args = {
11
12
  children: React.ReactNode
12
13
  }
13
14
 
14
- const Layout = ({ children }: Args) => <RootLayout config={configPromise}>{children}</RootLayout>
15
+ const Layout = ({ children }: Args) => (
16
+ <RootLayout importMap={importMap} config={configPromise}>
17
+ {children}
18
+ </RootLayout>
19
+ )
15
20
 
16
21
  export default Layout
@@ -0,0 +1,127 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * This file was automatically generated by Payload.
5
+ * DO NOT MODIFY IT BY HAND. Instead, modify your source Payload config,
6
+ * and re-run `payload generate:types` to regenerate this file.
7
+ */
8
+
9
+ export interface Config {
10
+ auth: {
11
+ users: UserAuthOperations;
12
+ };
13
+ collections: {
14
+ users: User;
15
+ media: Media;
16
+ 'payload-preferences': PayloadPreference;
17
+ 'payload-migrations': PayloadMigration;
18
+ };
19
+ db: {
20
+ defaultIDType: string;
21
+ };
22
+ globals: {};
23
+ locale: null;
24
+ user: User & {
25
+ collection: 'users';
26
+ };
27
+ }
28
+ export interface UserAuthOperations {
29
+ forgotPassword: {
30
+ email: string;
31
+ password: string;
32
+ };
33
+ login: {
34
+ email: string;
35
+ password: string;
36
+ };
37
+ registerFirstUser: {
38
+ email: string;
39
+ password: string;
40
+ };
41
+ unlock: {
42
+ email: string;
43
+ password: string;
44
+ };
45
+ }
46
+ /**
47
+ * This interface was referenced by `Config`'s JSON-Schema
48
+ * via the `definition` "users".
49
+ */
50
+ export interface User {
51
+ id: string;
52
+ updatedAt: string;
53
+ createdAt: string;
54
+ email: string;
55
+ resetPasswordToken?: string | null;
56
+ resetPasswordExpiration?: string | null;
57
+ salt?: string | null;
58
+ hash?: string | null;
59
+ loginAttempts?: number | null;
60
+ lockUntil?: string | null;
61
+ password?: string | null;
62
+ }
63
+ /**
64
+ * This interface was referenced by `Config`'s JSON-Schema
65
+ * via the `definition` "media".
66
+ */
67
+ export interface Media {
68
+ id: string;
69
+ alt: string;
70
+ updatedAt: string;
71
+ createdAt: string;
72
+ url?: string | null;
73
+ thumbnailURL?: string | null;
74
+ filename?: string | null;
75
+ mimeType?: string | null;
76
+ filesize?: number | null;
77
+ width?: number | null;
78
+ height?: number | null;
79
+ focalX?: number | null;
80
+ focalY?: number | null;
81
+ }
82
+ /**
83
+ * This interface was referenced by `Config`'s JSON-Schema
84
+ * via the `definition` "payload-preferences".
85
+ */
86
+ export interface PayloadPreference {
87
+ id: string;
88
+ user: {
89
+ relationTo: 'users';
90
+ value: string | User;
91
+ };
92
+ key?: string | null;
93
+ value?:
94
+ | {
95
+ [k: string]: unknown;
96
+ }
97
+ | unknown[]
98
+ | string
99
+ | number
100
+ | boolean
101
+ | null;
102
+ updatedAt: string;
103
+ createdAt: string;
104
+ }
105
+ /**
106
+ * This interface was referenced by `Config`'s JSON-Schema
107
+ * via the `definition` "payload-migrations".
108
+ */
109
+ export interface PayloadMigration {
110
+ id: string;
111
+ name?: string | null;
112
+ batch?: number | null;
113
+ updatedAt: string;
114
+ createdAt: string;
115
+ }
116
+ /**
117
+ * This interface was referenced by `Config`'s JSON-Schema
118
+ * via the `definition` "auth".
119
+ */
120
+ export interface Auth {
121
+ [k: string]: unknown;
122
+ }
123
+
124
+
125
+ declare module 'payload' {
126
+ export interface GeneratedTypes extends Config {}
127
+ }
@@ -15,6 +15,9 @@ const dirname = path.dirname(filename)
15
15
  export default buildConfig({
16
16
  admin: {
17
17
  user: Users.slug,
18
+ importMap: {
19
+ baseDir: path.resolve(dirname),
20
+ },
18
21
  },
19
22
  collections: [Users, Media],
20
23
  editor: lexicalEditor(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-payload-app",
3
- "version": "3.0.0-canary.95fcd13",
3
+ "version": "3.0.0-canary.98cbdb9",
4
4
  "homepage": "https://payloadcms.com",
5
5
  "repository": {
6
6
  "type": "git",
@@ -41,7 +41,7 @@
41
41
  "dependencies": {
42
42
  "@clack/prompts": "^0.7.0",
43
43
  "@sindresorhus/slugify": "^1.1.0",
44
- "@swc/core": "^1.6.13",
44
+ "@swc/core": "1.7.10",
45
45
  "arg": "^5.0.0",
46
46
  "chalk": "^4.1.0",
47
47
  "comment-json": "^4.2.3",
@@ -64,7 +64,7 @@
64
64
  "build": "pnpm pack-template-files && pnpm typecheck && pnpm build:swc",
65
65
  "build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
66
66
  "clean": "rimraf {dist,*.tsbuildinfo}",
67
- "pack-template-files": "tsx src/scripts/pack-template-files.ts",
67
+ "pack-template-files": "node --no-deprecation --import @swc-node/register/esm-register src/scripts/pack-template-files.ts",
68
68
  "test": "jest",
69
69
  "typecheck": "tsc"
70
70
  }