Skip to content

Commit

Permalink
fix: enabled test back
Browse files Browse the repository at this point in the history
  • Loading branch information
prisis committed Sep 16, 2024
1 parent ec9930b commit 01ea66f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/packem/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
// ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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"/],
Expand Down Expand Up @@ -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"/],
Expand Down Expand Up @@ -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"/],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion packages/packem/__tests__/intigration/typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion packages/packem/src/rollup/plugins/cjs-interop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
);
}
}

Expand All @@ -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")) {
Expand All @@ -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.`,
);
}
}

Expand All @@ -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.`,
);
}
}
}
Expand All @@ -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'.",
);
}
}
};
Expand Down

0 comments on commit 01ea66f

Please sign in to comment.