diff --git a/packages/packem/README.md b/packages/packem/README.md index 1674c8965..2bc5a03c5 100644 --- a/packages/packem/README.md +++ b/packages/packem/README.md @@ -438,7 +438,7 @@ Not only does `packem` shim `ESM ⇄ CJS`, but fixes the `export` and `export ty To enable both features you need to add `cjsInterop: true` to your `packem` config. -```ts +```js export default defineConfig({ cjsInterop: true, // ... diff --git a/packages/packem/__tests__/intigration/package-json-exports.test.ts b/packages/packem/__tests__/intigration/package-json-exports.test.ts index b8fd3ddd5..44bcaab9c 100644 --- a/packages/packem/__tests__/intigration/package-json-exports.test.ts +++ b/packages/packem/__tests__/intigration/package-json-exports.test.ts @@ -85,7 +85,6 @@ export function method() { expect(binProcess.stderr).toBe(""); expect(binProcess.exitCode).toBe(0); - for (const file of ["index.cjs", "index.mjs"]) { // eslint-disable-next-line security/detect-non-literal-fs-filename expect(existsSync(`${temporaryDirectoryPath}/dist/${file}`)).toBeTruthy(); @@ -129,7 +128,6 @@ export function method() { expect(binProcess.stderr).toBe(""); expect(binProcess.exitCode).toBe(0); - for (const [file, regex] of [ ["index.development.cjs", /= "development"/], ["index.development.mjs", /= "development"/], @@ -198,7 +196,6 @@ export function method() { expect(binProcess.stderr).toBe(""); expect(binProcess.exitCode).toBe(0); - for (const [file, regex] of [ ["index.development.cjs", /= "development"/], ["index.development.mjs", /= "development"/], @@ -271,7 +268,6 @@ export { IString };`, expect(binProcess.stderr).toBe(""); expect(binProcess.exitCode).toBe(0); - for (const [file, regex] of [ ["./index.mjs", /const shared = true/], ["./index.react-server.mjs", /"react-server"/], diff --git a/packages/packem/__tests__/intigration/package-json-imports.test.ts b/packages/packem/__tests__/intigration/package-json-imports.test.ts index 020193aaa..8a86156fe 100644 --- a/packages/packem/__tests__/intigration/package-json-imports.test.ts +++ b/packages/packem/__tests__/intigration/package-json-imports.test.ts @@ -33,8 +33,8 @@ describe("packem package.json imports", () => { }, exports: { ".": { - "import": "./dist/index.mjs", - "require": "./dist/index.cjs", + import: "./dist/index.mjs", + require: "./dist/index.cjs", }, }, imports: { diff --git a/packages/packem/__tests__/intigration/typescript.test.ts b/packages/packem/__tests__/intigration/typescript.test.ts index 9f1778fc0..50b0ad5df 100644 --- a/packages/packem/__tests__/intigration/typescript.test.ts +++ b/packages/packem/__tests__/intigration/typescript.test.ts @@ -1300,7 +1300,7 @@ export type Num = number; }, ); - it.each(["typescript", /* "oxc", "swc" */])( + it.each(["typescript", "oxc", "swc"])( "should patch cjs default export with '%s' isolated declarations transformer", async (isolatedDeclarationTransformer) => { expect.assertions(6); diff --git a/packages/packem/__tests__/unit/hooks/preset/utils/infer-entries.test.ts b/packages/packem/__tests__/unit/hooks/preset/utils/infer-entries.test.ts index 15c881dcb..f02e4ef1d 100644 --- a/packages/packem/__tests__/unit/hooks/preset/utils/infer-entries.test.ts +++ b/packages/packem/__tests__/unit/hooks/preset/utils/infer-entries.test.ts @@ -9,7 +9,6 @@ import inferEntries from "../../../../../src/hooks/preset/utils/infer-entries"; import type { BuildContext, InferEntriesResult } from "../../../../../src/types"; const createFiles = (files: string[], directory: string) => { - for (const file of files) { writeFileSync(`${directory}/${file}`, "", { overwrite: true, diff --git a/packages/packem/src/rollup/plugins/cjs-interop.ts b/packages/packem/src/rollup/plugins/cjs-interop.ts index cdfbb10c3..3c36d378b 100644 --- a/packages/packem/src/rollup/plugins/cjs-interop.ts +++ b/packages/packem/src/rollup/plugins/cjs-interop.ts @@ -25,7 +25,6 @@ export const cjsInteropPlugin = ({ ): Promise<{ code: string; map: SourceMapInput; - } | null> => { // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (chunk.type !== "chunk" || !chunk.isEntry) { diff --git a/packages/packem/src/validator/package-json/validate-package-fields.ts b/packages/packem/src/validator/package-json/validate-package-fields.ts index b90655a89..f3043f874 100644 --- a/packages/packem/src/validator/package-json/validate-package-fields.ts +++ b/packages/packem/src/validator/package-json/validate-package-fields.ts @@ -18,7 +18,10 @@ const validatePackageFields = (context: BuildContext): void => { } else if (pkg.files.length === 0) { warn(context, "The 'files' field in your package.json is empty. Please specify the files to be included in the package."); } else if (!pkg.files.some((file) => file.includes(context.options.outDir))) { - warn(context, `The 'files' field in your package.json is missing the '${context.options.outDir}' directory. Ensure the output directory is included.`); + warn( + context, + `The 'files' field in your package.json is missing the '${context.options.outDir}' directory. Ensure the output directory is included.`, + ); } } @@ -42,7 +45,10 @@ const validatePackageFields = (context: BuildContext): void => { } if (pkg.module && pkg.main && pkg.module === pkg.main) { - warn(context, `Conflict detected: The 'module' and 'main' fields both point to '${pkg.module as string}'. Please ensure they refer to different module types.`); + warn( + context, + `Conflict detected: The 'module' and 'main' fields both point to '${pkg.module as string}'. Please ensure they refer to different module types.`, + ); } if (context.options.emitESM && pkg.module?.includes(".cjs")) { @@ -69,7 +75,10 @@ const validatePackageFields = (context: BuildContext): void => { } if (pkg.module && pkg.main && pkg.module === pkg.main) { - warn(context, `Conflict detected: The 'module' and 'main' fields both point to '${pkg.module as string}'. Please ensure they refer to different module types.`); + warn( + context, + `Conflict detected: The 'module' and 'main' fields both point to '${pkg.module as string}'. Please ensure they refer to different module types.`, + ); } } @@ -85,11 +94,17 @@ const validatePackageFields = (context: BuildContext): void => { if (validation?.packageJson?.bin !== false) { if (typeof pkg.bin === "string" && pkg.bin.includes(isCjs ? ".mjs" : ".cjs")) { - warn(context, `The 'bin' field in your package.json should not use a ${isCjs ? ".mjs" : ".cjs"} extension for ${isCjs ? "CommonJS" : "ES modules"} binaries.`); + warn( + context, + `The 'bin' field in your package.json should not use a ${isCjs ? ".mjs" : ".cjs"} extension for ${isCjs ? "CommonJS" : "ES modules"} binaries.`, + ); } else if (typeof pkg.bin === "object") { for (const [bin, binPath] of Object.entries(pkg.bin)) { if (binPath && (binPath as string).includes(isCjs ? ".mjs" : ".cjs")) { - warn(context, `The 'bin.${bin}' field in your package.json should not use a ${isCjs ? ".mjs" : ".cjs"} extension for ${isCjs ? "CommonJS" : "ES modules"} binaries.`); + warn( + context, + `The 'bin.${bin}' field in your package.json should not use a ${isCjs ? ".mjs" : ".cjs"} extension for ${isCjs ? "CommonJS" : "ES modules"} binaries.`, + ); } } } @@ -105,7 +120,10 @@ const validatePackageFields = (context: BuildContext): void => { validation?.packageJson?.typesVersions !== false && (pkg.typesVersions === undefined || Object.keys(pkg.typesVersions).length === 0) ) { - warn(context, "No 'typesVersions' field found in your package.json. Consider adding this field, or change the declaration option to 'node16' or 'false'."); + warn( + context, + "No 'typesVersions' field found in your package.json. Consider adding this field, or change the declaration option to 'node16' or 'false'.", + ); } } };