Skip to content

Commit 5b2c707

Browse files
authored
fix(vitest): silence Vite native configLoader warnings (#1922)
* fix(vitest): silence Vite native configLoader warnings Vite's configLoader: "native" (the future default) can't load config files that use ESM syntax under CommonJS resolution or extensionless relative imports. Fix both classes of warning: - Rename root-level *.config.ts files (and packages/design-token-ts-plugin/vitest.config.ts) to .mts, since the nearest package.json has no "type" field and defaults to CommonJS. - Add "type": "module" to packages/i18n/package.json, matching packages/nimbus and packages/nimbus-mcp. It's an internal build tool only ever invoked via tsx (unaffected by "type") or imported from Vite config loaders, so this is safe. - Add explicit .ts extensions to the now-flagged relative imports in packages/nimbus's vite/vitest configs (allowImportingTsExtensions is already enabled in tsconfig). Verified pnpm test:dev, the unit/unit-isolated/ts-plugin/scripts projects, and typecheck:dev all pass with the warnings gone. * docs(testing): update root orchestrator filename to vitest.config.mts Keeps the unit-testing guideline in sync with the rename in a4c1efb (fix(vitest): silence Vite native configLoader warnings). * fix(i18n): fix CI build breakage from prior commit The previous commit added "type": "module" to packages/i18n/package.json to silence a Vite native configLoader warning about ESM syntax loaded as CommonJS. That broke this package's build pipeline: its tsx-invoked scripts (build:split, build:compile-strings, build:dictionaries) use CommonJS __dirname without an ESM fallback, and tsx treats a file as ESM once the nearest package.json sets "type": "module". Every script failed with `ReferenceError: __dirname is not defined`, no *.messages.ts files got generated, and packages/nimbus's build then failed with ~36 "Cannot find module '*.messages'" errors. Fix by reverting the package-wide "type": "module" and instead renaming just the offending file to locales.mts (same approach already used for the root-level vitest configs), which makes Vite's native config loader treat it as ESM without touching how tsx resolves every other file in the package. Updated the file's extensionless importers (compile-component-messages.ts, extract-messages.ts, generate-dictionaries.ts, split-by-component.ts) to the explicit .mts extension, since tsx's CJS-mode resolver doesn't probe for .mts on extensionless specifiers. Also updated the one cross-package import in packages/nimbus/vite.config.ts and doc references (packages/i18n/CLAUDE.md, packages/i18n/README.md). Verified: pnpm --filter @commercetools/nimbus-i18n build succeeds, pnpm --filter @commercetools/nimbus build succeeds (the exact command that failed in CI), and the unit/unit-isolated/ts-plugin/nimbus-mcp/ scripts vitest projects all pass (2019 tests).
1 parent cec7e2b commit 5b2c707

18 files changed

Lines changed: 23 additions & 23 deletions

docs/file-type-guidelines/unit-testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ See [Testing Strategy Guide](./testing-strategy.md) for detailed rules.
4444
The project uses **Vitest** with two separate test projects:
4545

4646
```typescript
47-
// vitest.config.ts - Root orchestrator
47+
// vitest.config.mts - Root orchestrator
4848
export default defineConfig({
4949
test: {
5050
projects: [

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"test": "pnpm vitest run",
3535
"test:unit": "pnpm vitest run --project=unit",
3636
"test:storybook": "pnpm vitest run --project=storybook",
37-
"test:dev": "pnpm vitest run --config vitest.dev.config.ts",
38-
"test:storybook:dev": "pnpm vitest run --config vitest.dev.config.ts --project=storybook-dev",
37+
"test:dev": "pnpm vitest run --config vitest.dev.config.mts",
38+
"test:storybook:dev": "pnpm vitest run --config vitest.dev.config.mts --project=storybook-dev",
3939
"check:bundle-size": "node .github/actions/bundle-size/check-bundle-size.mjs",
4040
"check:package-shape": "node scripts/check-package-shape.mjs",
4141
"bundle-sizes:trend": "node scripts/bundle-sizes-trend.mjs"
File renamed without changes.

packages/i18n/CLAUDE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ packages/i18n/
6868
│ ├── split-by-component.ts
6969
│ ├── compile-component-messages.ts
7070
│ ├── generate-dictionaries.ts
71-
│ └── locales.ts
71+
│ └── locales.mts
7272
├── .temp/ # Temporary build artifacts (gitignored)
7373
│ └── by-component/ # Messages grouped by component
7474
├── package.json
@@ -286,7 +286,7 @@ from the generated `*.messages.ts` files.
286286
287287
## Supported Locales
288288
289-
Available locales (defined in `scripts/locales.ts`):
289+
Available locales (defined in `scripts/locales.mts`):
290290
291291
- `en` - English
292292
- `de` - German
@@ -300,7 +300,7 @@ English for unsupported locales.
300300
301301
To add a new locale:
302302
303-
1. Add locale code to `scripts/locales.ts`
303+
1. Add locale code to `scripts/locales.mts`
304304
2. Create `data/[locale].json` file with Transifex translations
305305
3. Update Vite config's `optimize-locales-plugin` to include new locale
306306
4. Run build to compile: `pnpm --filter @commercetools/nimbus-i18n build`

packages/i18n/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ This is an **internal build tool package** that:
3333
### Locale Configuration
3434

3535
**Single Source of Truth:** All supported locales are defined in
36-
`packages/i18n/scripts/locales.ts` and shared between the build scripts and the
36+
`packages/i18n/scripts/locales.mts` and shared between the build scripts and the
3737
Vite config (`optimize-locales-plugin`).
3838

3939
### Build Pipeline

packages/i18n/scripts/compile-component-messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { compileStrings } from "@internationalized/string-compiler";
3232
import fs from "fs/promises";
3333
import path from "path";
3434
import { format } from "prettier";
35-
import { LOCALE_CODES } from "./locales";
35+
import { LOCALE_CODES } from "./locales.mts";
3636

3737
const LOCALES = LOCALE_CODES;
3838

packages/i18n/scripts/extract-messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { glob } from "glob";
99
import * as fs from "fs";
1010
import * as path from "path";
11-
import { LOCALE_CODES } from "./locales";
11+
import { LOCALE_CODES } from "./locales.mts";
1212

1313
// Type definitions for message descriptors in .i18n.ts files
1414
type MessageDescriptor = {

packages/i18n/scripts/generate-dictionaries.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import fs from "fs/promises";
3838
import path from "path";
3939
import { format, resolveConfig } from "prettier";
40-
import { SUPPORTED_LOCALES } from "./locales";
40+
import { SUPPORTED_LOCALES } from "./locales.mts";
4141

4242
const LOCALES = SUPPORTED_LOCALES;
4343

packages/i18n/scripts/split-by-component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
import fs from "fs/promises";
4444
import path from "path";
45-
import { LOCALE_CODES } from "./locales";
45+
import { LOCALE_CODES } from "./locales.mts";
4646

4747
const LOCALES = LOCALE_CODES;
4848

0 commit comments

Comments
 (0)