From 2bd06a19c5058bf1182465e786d35adaed73c56b Mon Sep 17 00:00:00 2001 From: Zack Tanner <1939140+ztanner@users.noreply.github.com> Date: Fri, 6 Sep 2024 15:04:16 -0700 Subject: [PATCH 1/3] create-next-app: fix font file corruption when using import alias --- packages/create-next-app/templates/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-next-app/templates/index.ts b/packages/create-next-app/templates/index.ts index ffbcd544c9b58..6d9e4fd401185 100644 --- a/packages/create-next-app/templates/index.ts +++ b/packages/create-next-app/templates/index.ts @@ -103,7 +103,7 @@ export const installTemplate = async ({ stats: false, // We don't want to modify compiler options in [ts/js]config.json // and none of the files in the .git folder - ignore: ["tsconfig.json", "jsconfig.json", ".git/**/*"], + ignore: ["tsconfig.json", "jsconfig.json", ".git/**/*", "**/fonts/**"], }); const writeSema = new Sema(8, { capacity: files.length }); await Promise.all( From 6bb620e4eec2379144646772c2634e9eac6c9fbd Mon Sep 17 00:00:00 2001 From: Janka Uryga Date: Fri, 6 Sep 2024 15:18:31 +0200 Subject: [PATCH 2/3] test: check most possible combination of CNA flags --- .../create-next-app/templates/matrix.test.ts | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 test/integration/create-next-app/templates/matrix.test.ts diff --git a/test/integration/create-next-app/templates/matrix.test.ts b/test/integration/create-next-app/templates/matrix.test.ts new file mode 100644 index 0000000000000..c5965debb21c1 --- /dev/null +++ b/test/integration/create-next-app/templates/matrix.test.ts @@ -0,0 +1,79 @@ +import { run, tryNextDev, useTempDir } from '../utils' + +describe.each(['app', 'pages'] as const)( + 'CNA options matrix - %s', + (pagesOrApp) => { + let nextTgzFilename: string + + beforeAll(() => { + if (!process.env.NEXT_TEST_PKG_PATHS) { + throw new Error('This test needs to be run with `node run-tests.js`.') + } + + const pkgPaths = new Map( + JSON.parse(process.env.NEXT_TEST_PKG_PATHS) + ) + + nextTgzFilename = pkgPaths.get('next')! + }) + + const isApp = pagesOrApp === 'app' + + const allFlagValues = { + app: [isApp ? '--app' : '--no-app'], + turbo: [process.env.TURBOPACK ? '--turbo' : '--no-turbo'], + + ts: ['--js', '--ts'], + importAlias: [ + '--import-alias=@acme/*', + '--import-alias=@/*', + '--no-import-alias', + ], + // doesn't affect if the app builds or not + // eslint: ['--eslint', '--no-eslint'], + eslint: ['--eslint'], + + srcDir: ['--src-dir', '--no-src-dir'], + tailwind: ['--tailwind', '--no-tailwind'], + + // shouldn't affect if the app builds or not + // packageManager: ['--use-npm', '--use-pnpm', '--use-yarn', '--use-bun'], + } + + const getPermutations = (items: T[][]): T[][] => { + if (!items.length) return [[]] + const [first, ...rest] = items + const children = getPermutations(rest) + return first.flatMap((value) => + children.map((child) => [value, ...child]) + ) + } + + const flagPermutations = getPermutations(Object.values(allFlagValues)) + const testCases = flagPermutations.map((flags) => ({ + name: flags.join(' '), + flags, + })) + + let id = 0 + it.each(testCases)('$name', async ({ flags }) => { + await useTempDir(async (cwd) => { + const projectName = `cna-matrix-${pagesOrApp}-${id++}` + const { exitCode } = await run( + [projectName, ...flags], + nextTgzFilename, + { + cwd, + } + ) + expect(exitCode).toBe(0) + + await tryNextDev({ + cwd, + projectName, + isApp, + }) + }) + }) + } +) From 5b2c0ae903c87d036cd054936d622acdc74322aa Mon Sep 17 00:00:00 2001 From: Zack Tanner <1939140+ztanner@users.noreply.github.com> Date: Fri, 6 Sep 2024 16:03:47 -0700 Subject: [PATCH 3/3] also include favicon --- packages/create-next-app/templates/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/create-next-app/templates/index.ts b/packages/create-next-app/templates/index.ts index 6d9e4fd401185..8c6e59a5e94ef 100644 --- a/packages/create-next-app/templates/index.ts +++ b/packages/create-next-app/templates/index.ts @@ -103,7 +103,16 @@ export const installTemplate = async ({ stats: false, // We don't want to modify compiler options in [ts/js]config.json // and none of the files in the .git folder - ignore: ["tsconfig.json", "jsconfig.json", ".git/**/*", "**/fonts/**"], + // TODO: Refactor this to be an allowlist, rather than a denylist, + // to avoid corrupting files that weren't intended to be replaced + + ignore: [ + "tsconfig.json", + "jsconfig.json", + ".git/**/*", + "**/fonts/**", + "**/favicon.ico", + ], }); const writeSema = new Sema(8, { capacity: files.length }); await Promise.all(