Skip to content

Commit aabcfb5

Browse files
authored
feat!: improve ESM/CJS compatibility, drop support for node 12 (#5)
BREAKING CHANGE: Only node 14.13.1 and higher is now supported. BREAKING CHANGE: ESM/CommonJS compatibility is now improved, but may cause new behavior in certain contexts. It should however be more forward-compatible, and allow usage in a wider range of tools and environments. ADDED: Semantic release automation ADDED: Use @sanity/pkg-utils instead of vite directly, for better control of bundling
1 parent 5f57bef commit aabcfb5

12 files changed

+7509
-103
lines changed

.czrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"path": "cz-conventional-changelog"
3+
}

.github/workflows/test.yml

+48-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,57 @@
1-
name: test
1+
name: CI & Release
2+
23
on:
3-
- push
4-
- pull_request
4+
push:
5+
pull_request:
6+
branches:
7+
- alpha
8+
- beta
9+
- main
10+
511
jobs:
612
test:
7-
name: Node.js ${{ matrix.node-version }}
8-
runs-on: ubuntu-latest
13+
runs-on: ${{ matrix.platform }}
14+
name: Node.js ${{ matrix.node-version }} / ${{ matrix.platform }}
915
strategy:
1016
fail-fast: false
1117
matrix:
12-
node-version:
13-
- 16
14-
- 14
15-
- 12
18+
platform: [ubuntu-latest, macos-latest]
19+
node-version: [lts/*, current]
1620
steps:
17-
- uses: actions/checkout@v2
18-
- uses: actions/setup-node@v1
21+
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3
22+
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3
1923
with:
2024
node-version: ${{ matrix.node-version }}
21-
- run: npm install
22-
- run: npm test
25+
- run: npm i pnpm@latest -g
26+
- run: pnpm install
27+
- run: pnpm test
28+
- run: pnpm lint
29+
30+
release:
31+
name: 'Semantic release'
32+
needs: test
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3
36+
with:
37+
# Need to fetch entire commit history to
38+
# analyze every commit since last release
39+
fetch-depth: 0
40+
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3
41+
with:
42+
node-version: lts/*
43+
- run: npm i pnpm@latest -g
44+
- run: pnpm install
45+
# Branches that will release new versions are defined in .releaserc.json
46+
- run: pnpm exec semantic-release
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
50+
# Build docs
51+
- run: npm run docs:build
52+
# Deploy docs
53+
- uses: peaceiris/actions-gh-pages@v3
54+
if: ${{ github.ref == 'refs/heads/main' }}
55+
with:
56+
github_token: ${{ secrets.GITHUB_TOKEN }}
57+
publish_dir: ./docs

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ package-lock.json
5151

5252
# Compiled portable text library + demo
5353
/dist
54-
/demo/dist
54+
/docs

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ The component function also receives a `children` property that should (usually)
103103

104104
### `block`
105105

106-
An object of component functions that renders portable text blocks with different `style` properties. The object has the shape {styleName: ComponentFn}`, where `styleName`is the value set in individual `style` attributes on blocks (`normal` being the default).
106+
An object of component functions that renders portable text blocks with different `style` properties. The object has the shape `{styleName: ComponentFn}`, where `styleName` is the value set in individual `style` attributes on blocks (`normal` being the default).
107107

108108
Can also be set to a single component function, which would handle block styles of _any_ type.
109109

package.config.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {defineConfig} from '@sanity/pkg-utils'
2+
3+
export default defineConfig({
4+
extract: {
5+
rules: {
6+
'ae-missing-release-tag': 'off',
7+
'tsdoc-undefined-tag': 'off',
8+
},
9+
},
10+
11+
legacyExports: true,
12+
13+
tsconfig: 'tsconfig.dist.json',
14+
15+
babel: {
16+
plugins: ['@babel/plugin-proposal-object-rest-spread'],
17+
},
18+
})

package.json

+112-49
Original file line numberDiff line numberDiff line change
@@ -2,89 +2,152 @@
22
"name": "@portabletext/to-html",
33
"version": "1.0.4",
44
"description": "Render Portable Text to HTML",
5-
"main": "./dist/to-html.js",
6-
"module": "./dist/to-html.mjs",
5+
"keywords": [
6+
"portable-text"
7+
],
8+
"homepage": "https://github.com/portabletext/to-html#readme",
9+
"bugs": {
10+
"url": "https://github.com/portabletext/to-html/issues"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git+ssh://git@github.com/portabletext/to-html.git"
15+
},
16+
"license": "MIT",
17+
"author": "Sanity.io <hello@sanity.io>",
18+
"sideEffects": false,
719
"exports": {
820
".": {
9-
"import": "./dist/to-html.mjs",
10-
"require": "./dist/to-html.js"
11-
}
21+
"types": "./dist/pt-to-html.d.ts",
22+
"source": "./src/index.ts",
23+
"require": "./dist/pt-to-html.js",
24+
"node": {
25+
"import": "./dist/pt-to-html.cjs.mjs",
26+
"require": "./dist/pt-to-html.js"
27+
},
28+
"import": "./dist/pt-to-html.esm.js",
29+
"default": "./dist/pt-to-html.esm.js"
30+
},
31+
"./package.json": "./package.json"
1232
},
13-
"sideEffects": false,
33+
"main": "./dist/pt-to-html.js",
34+
"module": "./dist/pt-to-html.esm.js",
35+
"source": "./src/index.ts",
36+
"types": "./dist/pt-to-html.d.ts",
1437
"files": [
1538
"dist",
1639
"!dist/stats.html",
1740
"src",
1841
"README.md"
1942
],
2043
"scripts": {
21-
"lint": "eslint . && tsc --noEmit",
22-
"prepublishOnly": "npm run build && npm run lint",
23-
"build": "vite build",
44+
"build": "run-s clean pkg:build pkg:check",
45+
"clean": "rimraf .nyc_output dist coverage",
46+
"coverage": "tap test/*.test.* --coverage-report=html",
47+
"docs:build": "typedoc",
48+
"format": "prettier --write --cache --ignore-unknown .",
49+
"lint": "eslint .",
50+
"pkg:build": "pkg-utils build --strict",
51+
"pkg:check": "pkg-utils --strict",
52+
"prepare": "husky install",
53+
"prepublishOnly": "run-s build lint type-check",
2454
"test": "tap test/*.test.*",
25-
"prettify": "prettier --write src/**/*.ts src/**/*.tsx test/**/*.ts test/**/*.tsx",
26-
"prettify-check": "prettier --check src/**/*.ts src/**/*.tsx test/**/*.ts test/**/*.tsx"
27-
},
28-
"repository": {
29-
"type": "git",
30-
"url": "git+ssh://git@github.com/portabletext/to-html.git"
31-
},
32-
"keywords": [
33-
"portable-text"
34-
],
35-
"author": "Sanity.io <hello@sanity.io>",
36-
"license": "MIT",
37-
"dependencies": {
38-
"@portabletext/toolkit": "^1.0.5",
39-
"@portabletext/types": "^1.0.2"
55+
"type-check": "tsc --noEmit"
4056
},
41-
"devDependencies": {
42-
"@rexxars/vite-dts": "^1.0.4",
43-
"@types/tap": "^15.0.5",
44-
"@typescript-eslint/eslint-plugin": "^5.7.0",
45-
"@typescript-eslint/parser": "^5.7.0",
46-
"esbuild-register": "^3.2.1",
47-
"eslint": "^7.32.0",
48-
"eslint-config-prettier": "^8.3.0",
49-
"eslint-config-sanity": "^5.1.0",
50-
"prettier": "^2.5.1",
51-
"rollup-plugin-visualizer": "^5.5.4",
52-
"tap": "^15.1.5",
53-
"typescript": "^4.5.4",
54-
"vite": "^2.7.4"
57+
"commitlint": {
58+
"extends": [
59+
"@commitlint/config-conventional"
60+
]
5561
},
56-
"bugs": {
57-
"url": "https://github.com/portabletext/to-html/issues"
62+
"lint-staged": {
63+
"*": [
64+
"prettier --write --cache --ignore-unknown"
65+
]
5866
},
59-
"homepage": "https://github.com/portabletext/to-html#readme",
6067
"prettier": {
61-
"semi": false,
62-
"printWidth": 100,
6368
"bracketSpacing": false,
69+
"plugins": [
70+
"prettier-plugin-packagejson"
71+
],
72+
"printWidth": 100,
73+
"semi": false,
6474
"singleQuote": true
6575
},
6676
"eslintConfig": {
6777
"parserOptions": {
68-
"ecmaVersion": 9,
69-
"sourceType": "module",
7078
"ecmaFeatures": {
7179
"modules": true
72-
}
80+
},
81+
"ecmaVersion": 9,
82+
"sourceType": "module"
7383
},
7484
"extends": [
7585
"sanity",
7686
"sanity/typescript",
7787
"prettier"
7888
],
7989
"ignorePatterns": [
80-
"lib/**/"
90+
"dist/**/"
8191
]
8292
},
93+
"release": {
94+
"branches": [
95+
"+([0-9])?(.{+([0-9]),x}).x",
96+
"main",
97+
{
98+
"name": "beta",
99+
"prerelease": true
100+
},
101+
{
102+
"name": "alpha",
103+
"prerelease": true
104+
}
105+
],
106+
"extends": "@sanity/semantic-release-preset"
107+
},
83108
"tap": {
109+
"check-coverage": false,
84110
"node-arg": [
85111
"-r",
86112
"esbuild-register"
87-
],
88-
"check-coverage": false
113+
]
114+
},
115+
"dependencies": {
116+
"@portabletext/toolkit": "^2.0.1",
117+
"@portabletext/types": "^2.0.2"
118+
},
119+
"devDependencies": {
120+
"@babel/core": "^7.20.12",
121+
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
122+
"@commitlint/cli": "^17.4.2",
123+
"@commitlint/config-conventional": "^17.4.2",
124+
"@sanity/pkg-utils": "^2.2.3",
125+
"@sanity/semantic-release-preset": "^4.0.0",
126+
"@types/tap": "^15.0.7",
127+
"@typescript-eslint/eslint-plugin": "^5.11.0",
128+
"@typescript-eslint/parser": "^5.11.0",
129+
"commitizen": "^4.3.0",
130+
"cz-conventional-changelog": "^3.3.0",
131+
"esbuild": "^0.17.5",
132+
"esbuild-register": "^3.4.2",
133+
"eslint": "^8.8.0",
134+
"eslint-config-prettier": "^8.3.0",
135+
"eslint-config-sanity": "^6.0.0",
136+
"husky": "^8.0.3",
137+
"npm-run-all": "^4.1.5",
138+
"prettier": "^2.5.1",
139+
"prettier-plugin-packagejson": "^2.4.2",
140+
"rimraf": "^4.1.2",
141+
"semantic-release": "^20.0.4",
142+
"tap": "^16.3.0",
143+
"typedoc": "^0.23.19",
144+
"typescript": "^4.9.4"
145+
},
146+
"packageManager": "pnpm@7.26.2",
147+
"engines": {
148+
"node": "^14.13.1 || >=16.0.0"
149+
},
150+
"publishConfig": {
151+
"access": "public"
89152
}
90153
}

0 commit comments

Comments
 (0)