From 105c1b2a53c17bede21cd9a9db40367ff07e927f Mon Sep 17 00:00:00 2001 From: Dean Clatworthy Date: Mon, 13 Jul 2026 15:23:31 +0300 Subject: [PATCH] refactor: remove redundant css resolver --- src/index.ts | 20 +------------------- tests/basic.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/index.ts b/src/index.ts index cdc5660..72fb637 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,26 +15,8 @@ export default function postCssPlugin( return { name: "postcss", setup(build) { - build.onResolve({ filter: /\.css$/, namespace: "file" }, async (args) => { - // Use esbuild path resolution for node_modules, tsconfig paths, etc. - // https://esbuild.github.io/plugins/#resolve - const resolution = await build.resolve(args.path, { - resolveDir: args.resolveDir, - kind: args.kind, - }); - - if (resolution.errors.length > 0) { - return { errors: resolution.errors }; - } - - return { - path: resolution.path, - namespace: "postcss", - }; - }); - build.onLoad( - { filter: /\.css$/, namespace: "postcss" }, + { filter: /\.css$/, namespace: "file" }, async (args) => { const sourceFullPath = args.path; const css = await fs.readFile(sourceFullPath, "utf8"); diff --git a/tests/basic.js b/tests/basic.js index 9ccb9cb..71e34a1 100644 --- a/tests/basic.js +++ b/tests/basic.js @@ -42,3 +42,28 @@ test("simplest case", async () => { assert.ok(fileContent.includes("-webkit-border-radius")); assert.ok(fileContent.includes("display: flex")); }); + +test("processes CSS resolved through tsconfig paths", async () => { + const outputDir = path.join(__dirname, ".output"); + const result = await esbuild.build({ + stdin: { + contents: 'import "example.css";', + resolveDir: __dirname, + loader: "js", + }, + bundle: true, + outfile: path.join(outputDir, "alias.js"), + write: false, + tsconfigRaw: { + compilerOptions: { + baseUrl: __dirname, + paths: { "example.css": ["./basic/example.css"] }, + }, + }, + plugins: [postCssPlugin({ plugins: [autoPrefixerPlugin] })], + }); + esbuild.stop(); + + const css = result.outputFiles.find((file) => file.path.endsWith(".css")); + assert.ok(css?.text.includes("-webkit-border-radius")); +});