From a6f51b47ae9f33b28724c0c5beaa212b489a3af2 Mon Sep 17 00:00:00 2001 From: Ayoub Adib Date: Wed, 30 Oct 2024 07:53:42 +0100 Subject: [PATCH] fix: prevent types resolution on js bundle target --- .changeset/brave-lobsters-run.md | 5 +++++ quickbundle/src/bundler/build.ts | 4 ++-- quickbundle/src/bundler/config.ts | 17 +++++++++-------- quickbundle/src/commands/build.ts | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 .changeset/brave-lobsters-run.md diff --git a/.changeset/brave-lobsters-run.md b/.changeset/brave-lobsters-run.md new file mode 100644 index 0000000..b447822 --- /dev/null +++ b/.changeset/brave-lobsters-run.md @@ -0,0 +1,5 @@ +--- +"quickbundle": patch +--- + +Prevent `exports.xxx.types` high priority resolution for non-dts bundle target. diff --git a/quickbundle/src/bundler/build.ts b/quickbundle/src/bundler/build.ts index d4b9905..c1ece9a 100644 --- a/quickbundle/src/bundler/build.ts +++ b/quickbundle/src/bundler/build.ts @@ -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"; @@ -40,7 +40,7 @@ export const build = async (configurations: Configuration[]) => { .write(outputEntry) .then(() => { resolve({ - elapedTime: Date.now() - initialTime, + elapsedTime: Date.now() - initialTime, filename: outputFilename, }); }) diff --git a/quickbundle/src/bundler/config.ts b/quickbundle/src/bundler/config.ts index 06d636c..0f1d9dc 100644 --- a/quickbundle/src/bundler/config.ts +++ b/quickbundle/src/bundler/config.ts @@ -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(), @@ -201,6 +193,7 @@ const createMainConfig = ( input: entryPoints.source, output, plugins: getPlugins( + nodeResolve(), swc({ minify: minification, sourceMaps, @@ -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, diff --git a/quickbundle/src/commands/build.ts b/quickbundle/src/commands/build.ts index ee185d9..1f32718 100644 --- a/quickbundle/src/commands/build.ts +++ b/quickbundle/src/commands/build.ts @@ -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", }, );