From 78432e23b575efcb9f43312877c645406b248632 Mon Sep 17 00:00:00 2001 From: await-ovo <13152410380@163.com> Date: Mon, 26 Dec 2022 17:13:25 +0800 Subject: [PATCH] fix: search postcss config from current work dir (#773) fix https://github.com/egoist/tsup/issues/770 --- src/esbuild/postcss.ts | 15 ++++++++------- types.d.ts | 1 - 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/esbuild/postcss.ts b/src/esbuild/postcss.ts index 064d9aa1..49ec0383 100644 --- a/src/esbuild/postcss.ts +++ b/src/esbuild/postcss.ts @@ -2,6 +2,7 @@ import fs from 'fs' import path from 'path' import { Loader, Plugin, transform } from 'esbuild' import { getPostcss } from '../utils' +import type { Result } from 'postcss-load-config'; export const postcssPlugin = ({ css, @@ -16,18 +17,18 @@ export const postcssPlugin = ({ name: 'postcss', setup(build) { - const configCache = new Map() + let configCache: Result - const getPostcssConfig = async (file: string) => { + const getPostcssConfig = async () => { const loadConfig = require('postcss-load-config') - if (configCache.has(file)) { - return configCache.get(file) + if (configCache) { + return configCache } try { - const result = await loadConfig({}, path.dirname(file)) - configCache.set(file, result) + const result = await loadConfig({}, process.cwd()) + configCache = result return result } catch (error: any) { if (error.message.includes('No PostCSS Config found in')) { @@ -87,7 +88,7 @@ export const postcssPlugin = ({ } // Load postcss config - const { plugins, options } = await getPostcssConfig(args.path) + const { plugins, options } = await getPostcssConfig() if (plugins && plugins.length > 0) { // Load postcss diff --git a/types.d.ts b/types.d.ts index f1f085a8..799ae8b9 100644 --- a/types.d.ts +++ b/types.d.ts @@ -1,2 +1 @@ declare module 'rollup-plugin-hashbang' -declare module 'postcss-load-config'