Skip to content

Commit

Permalink
fix: fixed wrong entries finding if declaration are off, updated roll…
Browse files Browse the repository at this point in the history
…up to v4.22.5 and oxc-parser to 0.30.5
  • Loading branch information
prisis committed Sep 29, 2024
1 parent 400b640 commit 17e0ff5
Show file tree
Hide file tree
Showing 8 changed files with 289 additions and 144 deletions.
2 changes: 1 addition & 1 deletion examples/isolated-declarations-oxc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"devDependencies": {
"@visulima/packem": "workspace:*",
"esbuild": "^0.24.0",
"oxc-transform": "^0.30.4",
"oxc-transform": "^0.30.5",
"rimraf": "^6.0.1",
"typescript": "^5.6.2"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/multi-exports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@
"esbuild": "^0.24.0",
"rimraf": "^6.0.1",
"typescript": "^5.6.2",
"vite": "5.4.7"
"vite": "5.4.8"
}
}
2 changes: 1 addition & 1 deletion examples/react-tsx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
"esbuild": "^0.24.0",
"rimraf": "^6.0.1",
"typescript": "^5.6.2",
"vite": "5.4.7"
"vite": "5.4.8"
}
}
68 changes: 68 additions & 0 deletions packages/packem/__tests__/intigration/package-json-exports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,74 @@ export { index as default };
`);
});

it("should allow to have folder name the same like file for export", async () => {
expect.assertions(4);

writeFileSync(`${temporaryDirectoryPath}/src/config/index.ts`, `export default () => 'index';`);
writeFileSync(`${temporaryDirectoryPath}/src/index.ts`, `export default () => 'index';`);
writeFileSync(`${temporaryDirectoryPath}/src/config.ts`, `export default () => 'config';`);

await installPackage(temporaryDirectoryPath, "typescript");
createTsConfig(temporaryDirectoryPath, {});

await createPackemConfig(temporaryDirectoryPath, {});
createPackageJson(temporaryDirectoryPath, {
devDependencies: {
typescript: "*",
},
exports: {
".": {
import: {
default: "./dist/index.mjs",
types: "./dist/index.d.mts",
},
require: {
default: "./dist/index.cjs",
types: "./dist/index.d.cts",
},
},
"./config": {
import: {
default: "./dist/config.mjs",
types: "./dist/config.d.mts",
},
require: {
default: "./dist/config.cjs",
types: "./dist/config.d.cts",
},
},
},
type: "module",
});

const binProcess = await execPackemSync("build", [], {
cwd: temporaryDirectoryPath,
});

expect(binProcess.stderr).toBe("");
expect(binProcess.exitCode).toBe(0);

const cjs = readFileSync(`${temporaryDirectoryPath}/dist/config.cjs`);

expect(cjs).toBe(`'use strict';
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
const config = /* @__PURE__ */ __name(() => "config", "default");
module.exports = config;
`);

const mjs = readFileSync(`${temporaryDirectoryPath}/dist/config.mjs`);

expect(mjs).toBe(`var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
const config = /* @__PURE__ */ __name(() => "config", "default");
export { config as default };
`);
});

it("should export dual package for type commonjs", async () => {
expect.assertions(4);

Expand Down
70 changes: 70 additions & 0 deletions packages/packem/__tests__/intigration/typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2102,4 +2102,74 @@ export const test = "this should be in final bundle, test2 string";`,
}`);
});
});

it("should use the exports key from package.json if declaration are off", async () => {
expect.assertions(4);

writeFileSync(`${temporaryDirectoryPath}/src/config/index.ts`, `export default () => 'index';`);
writeFileSync(`${temporaryDirectoryPath}/src/index.ts`, `export default () => 'index';`);
writeFileSync(`${temporaryDirectoryPath}/src/config.ts`, `export default () => 'config';`);

await installPackage(temporaryDirectoryPath, "typescript");
createTsConfig(temporaryDirectoryPath, {});

await createPackemConfig(temporaryDirectoryPath, {
declaration: false,
});
createPackageJson(temporaryDirectoryPath, {
devDependencies: {
typescript: "*",
},
exports: {
".": {
import: {
default: "./dist/index.mjs",
types: "./dist/index.d.mts",
},
require: {
default: "./dist/index.cjs",
types: "./dist/index.d.cts",
},
},
"./config": {
import: {
default: "./dist/config.mjs",
types: "./dist/config.d.mts",
},
require: {
default: "./dist/config.cjs",
types: "./dist/config.d.cts",
},
},
},
type: "module",
});

const binProcess = await execPackemSync("build", [], {
cwd: temporaryDirectoryPath,
});

expect(binProcess.stderr).toBe("");
expect(binProcess.exitCode).toBe(0);

const cjs = readFileSync(`${temporaryDirectoryPath}/dist/config.cjs`);

expect(cjs).toBe(`'use strict';
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
const config = /* @__PURE__ */ __name(() => "config", "default");
module.exports = config;
`);

const mjs = readFileSync(`${temporaryDirectoryPath}/dist/config.mjs`);

expect(mjs).toBe(`var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
const config = /* @__PURE__ */ __name(() => "config", "default");
export { config as default };
`);
});
});
16 changes: 8 additions & 8 deletions packages/packem/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@
"@rollup/plugin-replace": "6.0.1",
"@rollup/plugin-wasm": "6.2.2",
"@rollup/pluginutils": "5.1.2",
"@visulima/cerebro": "1.1.21",
"@visulima/cerebro": "1.1.22",
"@visulima/colorize": "1.4.10",
"@visulima/find-cache-dir": "1.0.11",
"@visulima/fs": "2.1.18",
"@visulima/find-cache-dir": "1.0.12",
"@visulima/fs": "2.2.0",
"@visulima/humanizer": "1.0.12",
"@visulima/package": "3.1.1",
"@visulima/package": "3.1.2",
"@visulima/pail": "2.1.9",
"@visulima/path": "1.0.9",
"@visulima/tsconfig": "1.0.13",
"@visulima/tsconfig": "1.0.14",
"defu": "6.1.4",
"es-module-lexer": "1.5.4",
"fastest-levenshtein": "1.0.16",
Expand All @@ -230,8 +230,8 @@
"jiti": "2.0.0",
"magic-string": "0.30.11",
"mlly": "1.7.1",
"oxc-parser": "0.30.1",
"rollup": "4.22.4",
"oxc-parser": "0.30.5",
"rollup": "4.22.5",
"rollup-plugin-dts": "6.1.1",
"rollup-plugin-license": "3.5.3",
"rollup-plugin-polyfill-node": "0.13.0",
Expand Down Expand Up @@ -277,7 +277,7 @@
"eslint-plugin-vitest-globals": "^1.5.0",
"estree-walker": "^3.0.3",
"execa": "^9.4.0",
"oxc-transform": "^0.30.4",
"oxc-transform": "^0.30.5",
"prettier": "^3.3.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/packem/src/utils/extract-export-filenames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ export const extractExportFilenames = (
} else if (typeof packageExport === "object" && packageExport !== null) {
for (const [condition, entryExport] of Object.entries(packageExport)) {
if (declaration === false && condition === "types") {
return [];
// eslint-disable-next-line no-continue
continue;
}

const key: string = Number.isInteger(+exportKey) ? condition : (exportKey as string);
Expand Down
Loading

0 comments on commit 17e0ff5

Please sign in to comment.