From 29d1af2568596bec4e83c8ab7ddd30bf9030be76 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Fri, 26 Jul 2024 11:57:08 -0400 Subject: [PATCH] publish inputs.css; fix namespace --- bin/clean-css.js | 15 +++++++++++++++ package.json | 10 +++++++--- rollup.config.js | 7 +++---- 3 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 bin/clean-css.js diff --git a/bin/clean-css.js b/bin/clean-css.js new file mode 100644 index 0000000..55c23e4 --- /dev/null +++ b/bin/clean-css.js @@ -0,0 +1,15 @@ +import {stdin} from "node:process"; +import CleanCSS from "clean-css"; + +stdin.setEncoding("utf-8"); + +let input = ""; + +for await (const chunk of stdin) { + input += chunk; +} + +// A unique namespace for our styles. +const styleNs = "oi-3a86ea"; + +process.stdout.write(new CleanCSS().minify(input.replace(/\.__ns__\b/g, `.${styleNs}`)).styles); diff --git a/package.json b/package.json index 9eb2a84..398b9ad 100644 --- a/package.json +++ b/package.json @@ -13,14 +13,18 @@ "jsdelivr": "dist/inputs.min.js", "unpkg": "dist/inputs.min.js", "exports": { - "umd": "./dist/inputs.min.js", - "default": "./src/index.js" + ".": { + "umd": "./dist/inputs.min.js", + "default": "./src/index.js" + }, + "./dist/inputs.css": "./dist/inputs.css" }, "repository": { "type": "git", "url": "https://github.com/observablehq/inputs.git" }, "files": [ + "dist/**/*.css", "dist/**/*.js", "src/**/*.js" ], @@ -31,7 +35,7 @@ "test": "yarn test:mocha && yarn test:lint", "test:mocha": "mkdir -p test/output && mocha -r module-alias/register 'test/**/*-test.js' test/input.js", "test:lint": "eslint src test", - "prepublishOnly": "rm -rf dist && rollup -c", + "prepublishOnly": "rm -rf dist && rollup -c && node bin/clean-css < src/style.css > dist/inputs.css", "postpublish": "git push && git push --tags", "dev": "snowpack dev" }, diff --git a/rollup.config.js b/rollup.config.js index c39e8d1..0a08619 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,4 +1,3 @@ -import crypto from "crypto"; import fs from "fs"; import path from "path"; import {terser} from "rollup-plugin-terser"; @@ -22,10 +21,10 @@ const copyrights = fs.readFileSync("./LICENSE", "utf-8") .filter(line => /^copyright\s+/i.test(line)) .map(line => line.replace(/^copyright\s+/i, "")); -// Create a content-hashed namespace for our styles. +// A unique namespace for our styles. +const styleNs = "oi-3a86ea"; + const stylePath = path.resolve("./src/style.css"); -const styleHash = crypto.createHash("sha256").update(fs.readFileSync(stylePath, "utf8")).digest("hex").slice(0, 6); -const styleNs = `oi-${styleHash}`; // A lil’ Rollup plugin to allow importing of style.css. const css = {