Skip to content

Commit f79edd6

Browse files
committed
fixing conflicts
1 parent ccd71a9 commit f79edd6

12 files changed

Lines changed: 1243 additions & 5028 deletions

File tree

.github/workflows/ci.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
pull_request:
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
node: [18, 20, 22, 23, 24]
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: ${{ matrix.node }}
24+
cache: pnpm
25+
26+
- name: Setup pnpm
27+
uses: pnpm/action-setup@v4
28+
with:
29+
version: "10"
30+
31+
- name: Install
32+
run: pnpm install --frozen-lockfile
33+
34+
- name: Test
35+
run: pnpm test
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
name: Release package
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
release-type:
6+
description: 'Release type (one of): patch, minor, major, prepatch, preminor, premajor, prerelease'
7+
required: true
8+
permissions:
9+
id-token: write
10+
contents: write
11+
jobs:
12+
check_ci:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Ensure latest CI on default branch succeeded
16+
uses: actions/github-script@v7
17+
with:
18+
script: |
19+
const { data: repo } = await github.rest.repos.get({
20+
owner: context.repo.owner,
21+
repo: context.repo.repo,
22+
});
23+
const { data: branch } = await github.rest.repos.getBranch({
24+
owner: context.repo.owner,
25+
repo: context.repo.repo,
26+
branch: repo.default_branch,
27+
});
28+
const headSha = branch.commit.sha;
29+
30+
const { data: runs } = await github.rest.actions.listWorkflowRuns({
31+
owner: context.repo.owner,
32+
repo: context.repo.repo,
33+
workflow_id: "ci.yml",
34+
branch: repo.default_branch,
35+
status: "completed",
36+
per_page: 1,
37+
});
38+
if (!runs.workflow_runs.length) {
39+
core.setFailed("No CI runs found on default branch.");
40+
return;
41+
}
42+
const run = runs.workflow_runs[0];
43+
if (run.head_sha !== headSha) {
44+
core.setFailed(`Latest CI run is not for the current ${repo.default_branch} head (${headSha}). Latest run: ${run.html_url}`);
45+
return;
46+
}
47+
if (run.conclusion !== "success") {
48+
core.setFailed(`Latest CI run on ${repo.default_branch} did not succeed: ${run.html_url}`);
49+
}
50+
release:
51+
runs-on: ubuntu-latest
52+
needs: [check_ci]
53+
steps:
54+
# Checkout project repository
55+
- name: Checkout
56+
uses: actions/checkout@v4
57+
58+
# Setup Node.js environment
59+
- name: Setup Node.js
60+
uses: actions/setup-node@v4
61+
with:
62+
registry-url: https://registry.npmjs.org/
63+
node-version: "22"
64+
cache: pnpm
65+
66+
- name: Setup pnpm
67+
uses: pnpm/action-setup@v4
68+
with:
69+
version: "10"
70+
71+
- name: Ensure npm supports trusted publishing
72+
run: npm install -g npm@^11.5.1
73+
74+
- name: Install dependencies
75+
run: pnpm install --frozen-lockfile
76+
77+
# Configure Git
78+
- name: Git configuration
79+
run: |
80+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
81+
git config --global user.name "GitHub Actions"
82+
83+
# Bump package version
84+
# Use tag latest
85+
- name: Bump release version
86+
if: startsWith(github.event.inputs.release-type, 'pre') != true
87+
run: |
88+
echo "NEW_VERSION=$(npm --no-git-tag-version version $RELEASE_TYPE)" >> $GITHUB_ENV
89+
echo "RELEASE_TAG=latest" >> $GITHUB_ENV
90+
env:
91+
RELEASE_TYPE: ${{ github.event.inputs.release-type }}
92+
93+
# Bump package pre-release version
94+
# Use tag beta for pre-release versions
95+
- name: Bump pre-release version
96+
if: startsWith(github.event.inputs.release-type, 'pre')
97+
run: |
98+
echo "NEW_VERSION=$(npm --no-git-tag-version --preid=beta version $RELEASE_TYPE)" >> $GITHUB_ENV
99+
echo "RELEASE_TAG=beta" >> $GITHUB_ENV
100+
env:
101+
RELEASE_TYPE: ${{ github.event.inputs.release-type }}
102+
103+
# Update changelog unreleased section with new version
104+
- name: Update changelog
105+
uses: superfaceai/release-changelog-action@v1
106+
with:
107+
path-to-changelog: CHANGELOG.md
108+
version: ${{ env.NEW_VERSION }}
109+
operation: release
110+
111+
# Commit changes
112+
- name: Sync lockfile after version bump
113+
run: pnpm install --lockfile-only
114+
115+
- name: Commit CHANGELOG.md and package.json changes and create tag
116+
run: |
117+
git add "package.json"
118+
git add "pnpm-lock.yaml"
119+
git add "CHANGELOG.md"
120+
git commit -m "chore: release ${{ env.NEW_VERSION }}"
121+
git tag ${{ env.NEW_VERSION }}
122+
123+
# Publish version to public repository
124+
- name: Publish
125+
run: npm publish --provenance --access public --tag ${{ env.RELEASE_TAG }}
126+
127+
# Push repository changes
128+
- name: Push changes to repository
129+
env:
130+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
131+
run: |
132+
git push origin && git push --tags
133+
134+
# Read version changelog
135+
- id: get-changelog
136+
name: Get version changelog
137+
uses: superfaceai/release-changelog-action@v1
138+
with:
139+
path-to-changelog: CHANGELOG.md
140+
version: ${{ env.NEW_VERSION }}
141+
operation: read
142+
143+
# Update GitHub release with changelog
144+
- name: Update GitHub release documentation
145+
uses: softprops/action-gh-release@v1
146+
with:
147+
tag_name: ${{ env.NEW_VERSION }}
148+
body: ${{ steps.get-changelog.outputs.changelog }}
149+
prerelease: ${{ startsWith(github.event.inputs.release-type, 'pre') }}
150+
env:
151+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
## [Unreleased]
6+
- Initial entry.

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# esbuild-plugin-postcss
44

5-
![Node.js CI](https://github.com/deanc/esbuild-plugin-postcss/workflows/Node.js%20CI/badge.svg)
5+
![CI](https://github.com/deanc/esbuild-plugin-postcss/actions/workflows/ci.yml/badge.svg)
66

77
Plugin for [esbuild](https://esbuild.github.io/) to support PostCSS
88

@@ -15,6 +15,10 @@ or yarn
1515
```bash
1616
yarn add esbuild @deanc/esbuild-plugin-postcss
1717
```
18+
or pnpm
19+
```bash
20+
pnpm add esbuild @deanc/esbuild-plugin-postcss
21+
```
1822

1923
## Usage example
2024

@@ -46,7 +50,7 @@ esbuild
4650
outfile: "bundle.js",
4751
plugins: [
4852
postCssPlugin({
49-
plugins: [autoprefixer],
53+
plugins: [autoprefixer()],
5054
}),
5155
],
5256
})
@@ -60,3 +64,19 @@ node build.js
6064
```
6165

6266
File named `bundle.css` with appropriate postcss plugins applied.
67+
68+
## Requirements
69+
70+
- Node.js 18+
71+
72+
## Contributing
73+
74+
- This repo uses pnpm for CI. If you use pnpm locally, run `pnpm import` once to create `pnpm-lock.yaml`.
75+
76+
## Releases
77+
78+
- The release workflow uses npm trusted publishing with provenance. Ensure trusted publishing is enabled for this package in npm before running the workflow.
79+
- Release checklist:
80+
1. Ensure CI is green on `main`.
81+
2. Verify `CHANGELOG.md` has entries under `[Unreleased]`.
82+
3. Run the "Release package" workflow with the desired release type.

index.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { Plugin } from "esbuild";
2+
import type { AcceptedPlugin } from "postcss";
3+
4+
export interface PostCssPluginOptions {
5+
plugins?: AcceptedPlugin[];
6+
}
7+
8+
declare function postCssPlugin(options?: PostCssPluginOptions): Plugin;
9+
export = postCssPlugin;

index.js

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,55 @@
1-
const fs = require("fs-extra");
1+
const fs = require("node:fs/promises");
22
const postcss = require("postcss");
3-
const util = require("util");
4-
const tmp = require("tmp");
5-
const path = require("path");
6-
7-
const readFile = util.promisify(fs.readFile);
8-
const writeFile = util.promisify(fs.writeFile);
9-
const ensureDir = util.promisify(fs.ensureDir);
10-
11-
module.exports = (options = { plugins: [] }) => ({
12-
name: "postcss",
13-
setup: function (build) {
14-
const { rootDir = options.rootDir || process.cwd() } = options;
15-
const tmpDirPath = tmp.dirSync().name;
16-
build.onResolve(
17-
{ filter: /.\.(css)$/, namespace: "file" },
18-
async (args) => {
19-
// use esbuild path resolution for node_modules, typescript paths, etc.
3+
const path = require("node:path");
4+
5+
module.exports = (options = {}) => {
6+
const plugins = options.plugins ?? [];
7+
8+
return {
9+
name: "postcss",
10+
setup(build) {
11+
build.onResolve({ filter: /\.css$/, namespace: "file" }, async (args) => {
12+
// Use esbuild path resolution for node_modules, tsconfig paths, etc.
2013
// https://esbuild.github.io/plugins/#resolve
2114
const resolution = await build.resolve(args.path, {
2215
resolveDir: args.resolveDir,
2316
kind: args.kind,
2417
});
18+
2519
if (resolution.errors.length > 0) {
26-
return { errors: result.errors }
20+
return { errors: resolution.errors };
2721
}
2822

29-
const sourceFullPath = resolution.path;
30-
const sourceExt = path.extname(sourceFullPath);
31-
const sourceBaseName = path.basename(sourceFullPath, sourceExt);
32-
const sourceDir = path.dirname(sourceFullPath);
33-
const sourceRelDir = path.relative(path.dirname(rootDir), sourceDir);
23+
return {
24+
path: resolution.path,
25+
namespace: "postcss",
26+
};
27+
});
28+
29+
build.onLoad({ filter: /\.css$/, namespace: "postcss" }, async (args) => {
30+
const sourceFullPath = args.path;
31+
const css = await fs.readFile(sourceFullPath, "utf8");
3432

35-
const tmpDir = path.resolve(tmpDirPath, sourceRelDir);
36-
const tmpFilePath = path.resolve(tmpDir, `${sourceBaseName}.css`);
37-
await ensureDir(tmpDir);
33+
if (plugins.length === 0) {
34+
return {
35+
contents: css,
36+
loader: "css",
37+
resolveDir: path.dirname(sourceFullPath),
38+
watchFiles: [sourceFullPath],
39+
};
40+
}
3841

39-
const css = await readFile(sourceFullPath);
40-
const result = await postcss(options.plugins).process(css, {
42+
const result = await postcss(plugins).process(css, {
4143
from: sourceFullPath,
42-
to: tmpFilePath,
4344
});
4445

45-
// Write the result file
46-
await writeFile(tmpFilePath, result.css);
47-
48-
// https://esbuild.github.io/plugins/#on-resolve-results
4946
return {
50-
path: tmpFilePath,
51-
// watch for changes to the original input for automatic rebuilds
52-
watchFiles: [ sourceFullPath ],
47+
contents: result.css,
48+
loader: "css",
49+
resolveDir: path.dirname(sourceFullPath),
50+
watchFiles: [sourceFullPath],
5351
};
54-
}
55-
);
56-
},
57-
});
52+
});
53+
},
54+
};
55+
};

0 commit comments

Comments
 (0)