From 631424d1861b701c84c3a3ac4b2ce32dbc35272d Mon Sep 17 00:00:00 2001 From: jorenbroekema Date: Sat, 21 Jan 2023 00:05:58 +0100 Subject: [PATCH] fix: prebundle CJS-only dependency to ESM --- .changeset/wild-emus-yawn.md | 5 +++++ .eslintignore | 20 ++++++++++++++++++-- .gitignore | 3 ++- .prettierignore | 18 ++++++++++++++++++ README.md | 3 --- package.json | 3 ++- tsconfig.json | 2 +- 7 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 .changeset/wild-emus-yawn.md create mode 100644 .prettierignore diff --git a/.changeset/wild-emus-yawn.md b/.changeset/wild-emus-yawn.md new file mode 100644 index 0000000..79c9d37 --- /dev/null +++ b/.changeset/wild-emus-yawn.md @@ -0,0 +1,5 @@ +--- +'@tokens-studio/sd-transforms': patch +--- + +No longer need to commit to using @rollup/plugin-commonjs. We prebundle the dependency that is CJS-only so users don't need to worry about it. diff --git a/.eslintignore b/.eslintignore index 6f0b942..0305e4d 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,18 @@ -node_modules -coverage/ \ No newline at end of file +## editors +/.idea +/.vscode +/*.code-workspace +/.history + +## system files +.DS_Store + +## npm/yarn +node_modules/ +npm-debug.log + +## temp folders +/coverage/ + +index.cjs +src/postcss-calc-ast-parser.js \ No newline at end of file diff --git a/.gitignore b/.gitignore index a56d321..0305e4d 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ npm-debug.log ## temp folders /coverage/ -index.cjs \ No newline at end of file +index.cjs +src/postcss-calc-ast-parser.js \ No newline at end of file diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..0305e4d --- /dev/null +++ b/.prettierignore @@ -0,0 +1,18 @@ +## editors +/.idea +/.vscode +/*.code-workspace +/.history + +## system files +.DS_Store + +## npm/yarn +node_modules/ +npm-debug.log + +## temp folders +/coverage/ + +index.cjs +src/postcss-calc-ast-parser.js \ No newline at end of file diff --git a/README.md b/README.md index aa43644..0d8bf3a 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,6 @@ to work with Design Tokens that are exported from [Tokens Studio](https://tokens - Transform Tokens Studio shadow objects to CSS shadow format - Registers these transforms, in addition to `attribute/cti`, `name/cti/camelCase` for naming purposes, as a transform group called `tokens-studio` -> If you consume this library using ESM, I am afraid that you will need something like `@rollup/plugin-commonjs` to deal with the fact that I am reliant on a CJS-written library called `postcss-calc-ast-parser` and its dependency `postcss-value-parser`. -> I will look into creating a PR to those repos to bundle as `mjs` and publish that, or publish it through a fork. - ## Usage ```js diff --git a/package.json b/package.json index b577ac4..b613a36 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "src/**/*" ], "scripts": { + "esm-postcss-calc": "rollup node_modules/postcss-calc-ast-parser/dist/index.js --file src/postcss-calc-ast-parser.js --format esm --plugin @rollup/plugin-commonjs --plugin @rollup/plugin-node-resolve", "build:cjs": "rollup index.js --file index.cjs --format cjs --plugin @rollup/plugin-commonjs --plugin rollup-plugin-cleanup --plugin @rollup/plugin-node-resolve", "build:types": "tsc -p tsconfig.build.types.json", "format": "npm run format:eslint && npm run format:prettier", @@ -26,7 +27,7 @@ "lint:eslint": "eslint --ext .js,.html .", "lint:prettier": "prettier \"**/*.js\" --list-different || (echo '↑↑ these files are not prettier formatted ↑↑' && exit 1)", "lint:types": "tsc", - "release": "run-p build:* && changeset publish", + "release": "npm run esm-postcss-calc && run-p build:* && changeset publish", "prepare": "husky install" }, "dependencies": { diff --git a/tsconfig.json b/tsconfig.json index 7270811..5a4b2dc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,5 +16,5 @@ "suppressImplicitAnyIndexErrors": true }, "include": ["**/*.js"], - "exclude": ["node_modules", "**/coverage/*"] + "exclude": ["node_modules", "**/coverage/*", "src/postcss-calc-ast-parser.js"] }