Skip to content

Commit c151996

Browse files
authored
test: skip CSS Modules migration in deploy harness (#3519)
* fix(init): skip CSS Modules migration in deploy harness * test(init): update deploy harness command assertions
1 parent ebc83be commit c151996

5 files changed

Lines changed: 30 additions & 5 deletions

File tree

‎packages/vinext/src/cli.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ async function initCommand() {
304304
root: process.cwd(),
305305
port: parsed.port,
306306
skipCheck,
307+
skipCssModules: rawArgs.includes("--skip-css-modules"),
307308
force,
308309
install,
309310
...initOptions,

‎packages/vinext/src/init.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ export type InitOptions = {
9696
port?: number | false;
9797
/** Skip the compatibility check step */
9898
skipCheck?: boolean;
99+
/** @internal — skip CSS Modules migration in the Next.js deploy harness. */
100+
skipCssModules?: boolean;
99101
/** Force overwrite even if vite.config.ts exists */
100102
force?: boolean;
101103
/** Deployment target selected by the user */
@@ -651,7 +653,7 @@ export async function init(options: InitOptions): Promise<InitResult> {
651653
const viteConfigExists = hasViteConfig(root);
652654

653655
const isApp = detectProject(root).isAppRouter;
654-
const hasCssModules = scanCssModuleFiles(root);
656+
const hasCssModules = !options.skipCssModules && scanCssModuleFiles(root);
655657
const pmName = detectPackageManagerName(root);
656658
const shouldInstall = options.install ?? true;
657659

‎scripts/e2e-deploy.sh‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,20 +741,22 @@ fi
741741
# --skip-check avoids the interactive compat report, --force overwrites any
742742
# existing vite.config.ts. Dep installation is a no-op since we already injected
743743
# them above.
744+
# --skip-css-modules keeps native CSS Module exports for Next.js fixtures
745+
# that import named classes instead of the default-only migration shim.
744746
#
745747
# vinext loads CJS next.config.js in `"type": "module"` packages via a temp
746748
# .cjs sibling (see config/next-config.ts), so we don't rewrite the user's
747749
# config file here.
748750
if [ "${VINEXT_HARNESS_DIR}" != "${VINEXT_DIR}" ]; then
749-
"${VINEXT_BIN}" init --platform=node --skip-check --force >> "${BUILD_LOG}" 2>&1
751+
"${VINEXT_BIN}" init --platform=node --skip-check --skip-css-modules --force >> "${BUILD_LOG}" 2>&1
750752
"${VINEXT_BIN}" build --prerender-all >> "${BUILD_LOG}" 2>&1
751753
else
752754
VITE_BIN="./node_modules/.bin/vite"
753755
if [ ! -x "${VITE_BIN}" ]; then
754756
echo "pnpm install failed: ${VITE_BIN} not found or not executable" >&2
755757
exit 1
756758
fi
757-
"${VINEXT_BIN}" init --platform=node --skip-check --force --prerender >> "${BUILD_LOG}" 2>&1
759+
"${VINEXT_BIN}" init --platform=node --skip-check --skip-css-modules --force --prerender >> "${BUILD_LOG}" 2>&1
758760
"${VITE_BIN}" build >> "${BUILD_LOG}" 2>&1
759761
fi
760762

‎tests/e2e-deploy-script.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,11 @@ describe("Next.js deploy harness", () => {
267267

268268
expect(script).toContain('if [ "${VINEXT_HARNESS_DIR}" != "${VINEXT_DIR}" ]; then');
269269
expect(script).toContain(
270-
'"${VINEXT_BIN}" init --platform=node --skip-check --force >> "${BUILD_LOG}" 2>&1',
270+
'"${VINEXT_BIN}" init --platform=node --skip-check --skip-css-modules --force >> "${BUILD_LOG}" 2>&1',
271271
);
272272
expect(script).toContain('"${VINEXT_BIN}" build --prerender-all >> "${BUILD_LOG}" 2>&1');
273273
expect(script).toContain(
274-
'"${VINEXT_BIN}" init --platform=node --skip-check --force --prerender',
274+
'"${VINEXT_BIN}" init --platform=node --skip-check --skip-css-modules --force --prerender',
275275
);
276276
});
277277

‎tests/init.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,26 @@ function readFile(dir: string, relativePath: string): string {
4343
}
4444

4545
describe("CSS Modules discovery", () => {
46+
// Next.js deploy fixtures rely on named CSS Module exports:
47+
// https://github.com/vercel/next.js/blob/v16.2.6/test/e2e/app-dir/scss/basic-module/pages/index.js
48+
it.each([false, true])(
49+
"can skip CSS Modules setup for the harness (skip: %s)",
50+
async (skipCssModules) => {
51+
setupProject(tmpDir, { router: "pages" });
52+
writeFile(tmpDir, "pages/index.module.scss", ".redText { color: red }");
53+
54+
const { result, output } = await runInit(tmpDir, { platform: "node", skipCssModules });
55+
const config = readFile(tmpDir, "vite.config.ts");
56+
57+
expect(config.includes("patchCssModules")).toBe(!skipCssModules);
58+
expect(config.includes("generateScopedName")).toBe(!skipCssModules);
59+
expect(result.installedDeps.includes("vite-css-modules")).toBe(!skipCssModules);
60+
expect(result.installedDeps.includes("postcss")).toBe(!skipCssModules);
61+
expect(output.includes("Configured vite-css-modules")).toBe(!skipCssModules);
62+
expect(config).toContain("vinext()");
63+
},
64+
);
65+
4666
it("finds CSS, Sass, and hidden source modules without scanning dependencies or output", () => {
4767
writeFile(tmpDir, "node_modules/lib/ignored.module.css", "");
4868
writeFile(tmpDir, "dist/ignored.module.scss", "");

0 commit comments

Comments
 (0)