From ef89258e94cf5f5f680293f8eff64920d2dc4c16 Mon Sep 17 00:00:00 2001 From: Carsten Kragelund Date: Fri, 29 Sep 2023 16:41:39 +0200 Subject: [PATCH] feat: initalize repo --- .gitignore | 176 ++++++++++++++++++++++++++++++++++++++++++++++ LICENSE | 16 +++++ README.md | 45 ++++++++++++ bun.lockb | Bin 0 -> 3849 bytes package.json | 39 ++++++++++ postcss.config.js | 7 ++ src/index.ts | 4 ++ src/plugin.ts | 22 ++++++ src/types.d.ts | 4 ++ tsconfig.json | 31 ++++++++ 10 files changed, 344 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100755 bun.lockb create mode 100644 package.json create mode 100644 postcss.config.js create mode 100644 src/index.ts create mode 100644 src/plugin.ts create mode 100644 src/types.d.ts create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ab5afb2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,176 @@ +# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore + +# Logs + +logs +_.log +npm-debug.log_ +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) + +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# Runtime data + +pids +_.pid +_.seed +\*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover + +lib-cov + +# Coverage directory used by tools like istanbul + +coverage +\*.lcov + +# nyc test coverage + +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) + +.grunt + +# Bower dependency directory (https://bower.io/) + +bower_components + +# node-waf configuration + +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) + +build/Release + +# Dependency directories + +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) + +web_modules/ + +# TypeScript cache + +\*.tsbuildinfo + +# Optional npm cache directory + +.npm + +# Optional eslint cache + +.eslintcache + +# Optional stylelint cache + +.stylelintcache + +# Microbundle cache + +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history + +.node_repl_history + +# Output of 'npm pack' + +\*.tgz + +# Yarn Integrity file + +.yarn-integrity + +# dotenv environment variable files + +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) + +.cache +.parcel-cache + +# Next.js build output + +.next +out + +# Nuxt.js build / generate output + +.nuxt +dist + +# Gatsby files + +.cache/ + +# Comment in the public line in if your project uses Gatsby and not Next.js + +# https://nextjs.org/blog/next-9-1#public-directory-support + +# public + +# vuepress build output + +.vuepress/dist + +# vuepress v2.x temp and cache directory + +.temp +.cache + +# Docusaurus cache and generated files + +.docusaurus + +# Serverless directories + +.serverless/ + +# FuseBox cache + +.fusebox/ + +# DynamoDB Local files + +.dynamodb/ + +# TernJS port file + +.tern-port + +# Stores VSCode versions used for testing VSCode extensions + +.vscode-test + +# yarn v2 + +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.\* + +# IntelliJ based IDEs +.idea + +# Finder (MacOS) folder config +.DS_Store + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8c7d0b1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,16 @@ +MIT No Attribution + +Copyright 2023 Carsten Kragelund + +Permission is hereby granted, free of charge, to any person obtaining a copy of this +software and associated documentation files (the "Software"), to deal in the Software +without restriction, including without limitation the rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..9f35ce8 --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +# bun-postcss-plugin + +`bun-postcss-plugin` is a [PostCSS](https://postcss.org/) plugin for [Bun](https://bun.sh/) that enables importing CSS files directly in your JavaScript files. Once imported, the plugin processes the CSS using PostCSS, and returns the processed CSS as a string which can be injected into your document or utilized however you see fit. + +## Installation + +```bash +bun install bun-postcss-plugin --save-dev +``` + +## Getting Started + +Add the plugin to your preload in your `bunfig.toml` + +```toml +preload = [ "bun-postcss-plugin" ] +``` + +and your `tsconfig.json` types field + +```yaml yaml is used here to allow comments in JSON +{ + "compilerOptions": { + // ... + "types": [ + // ... + "bun-postcss-plugin" + ] + } +} +``` + +Then you can import css files in your code directly as such + +```js +// Import your CSS +import styles from './styles.css'; + +// Your CSS is now processed and ready to use! +console.log(styles); // Logs processed CSS as a string +``` + +## Configuration + +`bun-postcss-plugin` will use the standard `postcss.config.js` file, like many other projects do. \ No newline at end of file diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000000000000000000000000000000000000..e192e69949630007900ef373c00a154131ce8225 GIT binary patch literal 3849 zcmeHKdr%Wc7(Xy534#hZ9hE`^u~xmy1H@pFv08x^jf|jBfk+5R2!^|O7nlI;478w7 zZLLMLbbL`-X>nkRBDNG?Xf5&(nJM__NUPR9KRg0pVK|=J=S-X8UU7VD7tOShg={ zxdCmU7^8||uuGut4EpDR7645uNlKT5VHwI)Jp^q546|wyEZ1-?iJ@4w65Ez$`(LfkzJFP01q<=IXqdO@f5;e2ad}D9?gr! zZN+;5U=RmC9uC>jJUW2)2lxrV0H2A-VH}O{`v6`H@URc@XnY*F)vpEMm#}!yv{}$R zlRyLF5f;W^tHAw258OY9bz;G`YUqwQp#J+jLsN#(BG?%I31x>_c)8TPy5(Wax%hl{ zvNLy?&#FV2N6Q}7wtm^vrnnG!qDY`AIP0<2qt&Cw$2+aIZq;S4SL4DyIa#!O^~(7v z3f1sAVI2qz@uGczvGRI$&Mb|Q?d+`E(|Ik1>O5w@V}8X;wJqKmbJOLUR}{u4w(U6^ zn;@Q-?%sR2Px3+eV(oQ@zTn?0c;WJ06He53aCo`<$O~P0H|oIp+WMQHi*xf64hePr3;&y*0aP--H3l?rRt7+)n$%9*w%aE;6Ju zoyA!B%eiZKLue_CYH@w6yQ@LD!H?sf1o17TC6NdA0 z)^P?nO>U0R@Y9UJGmO4lvEZVBk7G9Ed6qGVw^g`z(^ky?e*Z!SK4Z(BI#vsU7+OW> zNXDqt>j_kA5mB^S9W0cJg^Vs!O=%Vi{e?=sPD@f6PyqoM8ny^*!~5_nOXp}YV}hVG zKWQ*PJpm8T0z8lK{RgoS3SscQ1>Z3;mLtgqF5r&ANFWd7gxv7n!@B{;;TYtE+;F}R zSSSY*HwXub2O{se4(gdY)rVdp^vAVJxvLIoCyWu>SF zMl~#JkpcjGl|y0m=mW*5Q`6NnvC?Ez)1*=#X{2?eHdrVbNw&?>+RQ!Vpr@2cxQZe*I&HGiXkeCzM6_C~V~lhL zK^jt17=og;q9=HZ@F$Jp{va-4tLa;Rj4Kj9~ac!N$wsVF@~GYpkRtJHX^ z(txKhV+1+M4{(m^<8Z^Ika!G+kvU;V)&R^{b5QU { + const cssFile = await Bun.file(args.path).text(); + const css = await postcssrc({ + from: args.path, + to: args.path, + }).then(({ plugins }) => postcss(plugins).process(cssFile).async()); + return { + loader: "object", + exports: { + default: css.css, + }, + } satisfies OnLoadResult; + }); + }, +}; diff --git a/src/types.d.ts b/src/types.d.ts new file mode 100644 index 0000000..70793b8 --- /dev/null +++ b/src/types.d.ts @@ -0,0 +1,4 @@ +declare module "*.css" { + var style: string; + export default style; +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..8de0b61 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,31 @@ +{ + "compilerOptions": { + /* Base Options: */ + "esModuleInterop": true, + "skipLibCheck": true, + "target": "es2022", + "verbatimModuleSyntax": true, + "allowSyntheticDefaultImports": true, + "allowJs": true, + "resolveJsonModule": true, + "allowImportingTsExtensions": true, + "moduleDetection": "force", + /* Strictness */ + "strict": true, + "noUncheckedIndexedAccess": true, + "forceConsistentCasingInFileNames": true, + /* If NOT transpiling with TypeScript: */ + "moduleResolution": "Bundler", + "module": "ESNext", + "noEmit": true, + /* If your code doesn't run in the DOM: */ + "lib": ["es2022"], + /* If you're building for a library: */ + "declaration": true, + /* Bun specific options*/ + "types": [ + "bun-types" // add Bun global + ] + }, + "include": ["src/*.ts"] +}