Skip to content

Commit

Permalink
fix: prevent types resolution on js bundle target
Browse files Browse the repository at this point in the history
  • Loading branch information
adbayb committed Oct 30, 2024
1 parent b30a3a2 commit a6f51b4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/brave-lobsters-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"quickbundle": patch
---

Prevent `exports.xxx.types` high priority resolution for non-dts bundle target.
4 changes: 2 additions & 2 deletions quickbundle/src/bundler/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { rollup } from "rollup";
import type { Configuration } from "./config";
import { onLog } from "./helpers";

export type BuildItemOutput = { elapedTime: number; filename: string };
export type BuildItemOutput = { elapsedTime: number; filename: string };

export const build = async (configurations: Configuration[]) => {
process.env.NODE_ENV ??= "production";
Expand Down Expand Up @@ -40,7 +40,7 @@ export const build = async (configurations: Configuration[]) => {
.write(outputEntry)
.then(() => {
resolve({
elapedTime: Date.now() - initialTime,
elapsedTime: Date.now() - initialTime,
filename: outputFilename,
});
})
Expand Down
17 changes: 9 additions & 8 deletions quickbundle/src/bundler/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,6 @@ const getPlugins = (...customPlugins: InputPluginOption[]) => {
optDeps: true,
peerDeps: true,
}),
nodeResolve({
/**
* The `exports` conditional fields definition order is important in the `package.json file`.
* To be resolved first, `types` field must always come first in the package.json exports definition.
* @see https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#package-json-exports-imports-and-self-referencing.
*/
exportConditions: ["types"],
}),
commonjs(),
url(),
json(),
Expand Down Expand Up @@ -201,6 +193,7 @@ const createMainConfig = (
input: entryPoints.source,
output,
plugins: getPlugins(
nodeResolve(),
swc({
minify: minification,
sourceMaps,
Expand All @@ -216,6 +209,14 @@ const createTypesConfig = (
input: entryPoints.source,
output: [{ file: entryPoints.types }],
plugins: getPlugins(
nodeResolve({
/**
* The `exports` conditional fields definition order is important in the `package.json file`.
* To be resolved first, `types` field must always come first in the package.json exports definition.
* @see https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#package-json-exports-imports-and-self-referencing.
*/
exportConditions: ["types"],
}),
dts({
compilerOptions: {
incremental: false,
Expand Down
2 changes: 1 addition & 1 deletion quickbundle/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const createBuildCommand = (program: Termost) => {
`${item.compressedSize.toString().padStart(padding)} B gz`,
],
{
label: `${item.filename} (took ${item.elapedTime}ms)`,
label: `${item.filename} (took ${item.elapsedTime}ms)`,
type: "information",
},
);
Expand Down

0 comments on commit a6f51b4

Please sign in to comment.