From 0a417a036812dfd7b102190fde2b7ae84b5b1341 Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Tue, 15 Mar 2022 08:51:00 +0530 Subject: [PATCH] Revert "feat: add writeToFile option" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 07545133649c7ec93e18da9960080b318ec222da. This feature used convert css files to js (mostly because it esbuild internally was using js loader because of export statement 🤷‍♂️) --- README.md | 1 + package.json | 16 ++++++++++----- src/index.ts | 55 ++++++++++++++++------------------------------------ 3 files changed, 29 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 369179b..c040a84 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Looking for a maintainer! + Unfortunately I don't have time for this plugin. Please contact me if you'd like to take on this project. # esbuild-plugin-postcss2 diff --git a/package.json b/package.json index 2b2da21..36e5402 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,11 @@ { - "name": "esbuild-plugin-postcss2", - "version": "0.1.2", + "name": "@frappe/esbuild-plugin-postcss2", + "version": "0.1.3", "description": "Use postcss with esbuild", - "repository": "https://github.com/martonlederer/esbuild-plugin-postcss2", + "repository": { + "type": "git", + "url": "git+https://github.com/frappe/esbuild-plugin-postcss2.git" + }, "author": "Marton Lederer ", "license": "MIT", "private": false, @@ -30,7 +33,6 @@ "autoprefixer": "^10.2.5", "fs-extra": "^9.1.0", "less": "^4.x", - "postcss": "8.x", "postcss-modules": "^4.0.0", "resolve-file": "^0.3.0", "sass": "^1.x", @@ -61,5 +63,9 @@ "postcss": "8.x", "sass": "^1.x", "stylus": "^0.x" - } + }, + "bugs": { + "url": "https://github.com/frappe/esbuild-plugin-postcss2/issues" + }, + "homepage": "https://github.com/frappe/esbuild-plugin-postcss2#readme" } diff --git a/src/index.ts b/src/index.ts index ff0a795..10beb96 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,7 +30,6 @@ interface PostCSSPluginOptions { sassOptions?: SassOptions; lessOptions?: Less.Options; stylusOptions?: StylusRenderOptions; - writeToFile?: boolean; fileIsModule?: (filename: string) => boolean; } @@ -48,18 +47,16 @@ export const defaultOptions: PostCSSPluginOptions = { sassOptions: {}, lessOptions: {}, stylusOptions: {}, - writeToFile: true, fileIsModule: null }; const postCSSPlugin = ({ - plugins, - modules, - rootDir, - sassOptions, - lessOptions, - stylusOptions, - writeToFile, + plugins = [], + modules = true, + rootDir = process.cwd(), + sassOptions = {}, + lessOptions = {}, + stylusOptions = {}, fileIsModule }: PostCSSPluginOptions = defaultOptions): Plugin => ({ name: "postcss2", @@ -144,7 +141,10 @@ const postCSSPlugin = ({ // parse files with preprocessors if (sourceExt === ".sass" || sourceExt === ".scss") { - const sassResult = await renderSass({...sassOptions, file: sourceFullPath}) + const sassResult = await renderSass({ + ...sassOptions, + file: sourceFullPath + }); css = sassResult.css.toString(); watchFiles.push(...sassResult.stats.includedFiles); } @@ -172,21 +172,14 @@ const postCSSPlugin = ({ watchFiles.push(...getPostCssDependencies(result.messages)); // Write result CSS - if (writeToFile) { - await writeFile(tmpFilePath, result.css); - } + await writeFile(tmpFilePath, result.css); return { - namespace: isModule - ? "postcss-module" - : writeToFile - ? "file" - : "postcss-text", + namespace: isModule ? "postcss-module" : "file", path: tmpFilePath, watchFiles, pluginData: { - originalPath: sourceFullPath, - css: result.css + originalPath: sourceFullPath } }; } @@ -199,30 +192,16 @@ const postCSSPlugin = ({ const mod = modulesMap.find( ({ path }) => path === args?.pluginData?.originalPath ), - resolveDir = path.dirname(args.path), - css = args?.pluginData?.css || ""; + resolveDir = path.dirname(args.path); return { resolveDir, - contents: [ - writeToFile ? `import ${JSON.stringify(args.path)};` : null, - `export default ${JSON.stringify(mod && mod.map ? mod.map : {})};`, - writeToFile - ? null - : `export const stylesheet=${JSON.stringify(css)};` - ] - .filter(Boolean) - .join("\n") + contents: `import ${JSON.stringify( + args.path + )};\nexport default ${JSON.stringify(mod && mod.map ? mod.map : {})};` }; } ); - - build.onLoad({ filter: /.*/, namespace: "postcss-text" }, async (args) => { - const css = args?.pluginData?.css || ""; - return { - contents: `export default ${JSON.stringify(css)};` - }; - }); } });