Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create-next-app: fix font file corruption when using import alias #69806

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/create-next-app/templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/**/*"],
// 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(
Expand Down
79 changes: 79 additions & 0 deletions test/integration/create-next-app/templates/matrix.test.ts
Original file line number Diff line number Diff line change
@@ -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<string, string>(
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 = <T>(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,
})
})
})
}
)
Loading