Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: improve ESM/CJS compatibility, drop support for node 12 #5

Merged
merged 1 commit into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .czrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path": "cz-conventional-changelog"
}
61 changes: 48 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,57 @@
name: test
name: CI & Release

on:
- push
- pull_request
push:
pull_request:
branches:
- alpha
- beta
- main

jobs:
test:
name: Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
runs-on: ${{ matrix.platform }}
name: Node.js ${{ matrix.node-version }} / ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
platform: [ubuntu-latest, macos-latest]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen us use this pattern in other repos and in practice we have far fewer macos-latest runners available and it frequently results in long wait times when you have multiple PRs on multiple repos that need merging. I recommend following the pattern we use on repos like sanity client instead, where you have exactly one run of macos-latest and windows-latestand have the rest be strictlyubuntu-latest` 🤔

Copy link
Member Author

@rexxars rexxars Feb 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I think it's (almost) pointless to run tests on windows/mac for modules that do not even use node APIs. There's bound to be differences and pitfalls when doing things like command spawning, file system operations and such - but for pure JS modules it's hard to see where it could fail cross-platform.

Running tests on linux is faster (more availability) and also uncovers any incorrectly cased files, which can sometimes happen when authoring on mac but testing on linux.

node-version: [lts/*, current]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
- run: npm i pnpm@latest -g
- run: pnpm install
- run: pnpm test
- run: pnpm lint

release:
name: 'Semantic release'
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3
with:
# Need to fetch entire commit history to
# analyze every commit since last release
fetch-depth: 0
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3
with:
node-version: lts/*
- run: npm i pnpm@latest -g
- run: pnpm install
# Branches that will release new versions are defined in .releaserc.json
- run: pnpm exec semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
# Build docs
- run: npm run docs:build
# Deploy docs
- uses: peaceiris/actions-gh-pages@v3
if: ${{ github.ref == 'refs/heads/main' }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ package-lock.json

# Compiled portable text library + demo
/dist
/demo/dist
/docs
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ The component function also receives a `children` property that should (usually)

### `block`

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).
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).

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

Expand Down
18 changes: 18 additions & 0 deletions package.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {defineConfig} from '@sanity/pkg-utils'

export default defineConfig({
extract: {
rules: {
'ae-missing-release-tag': 'off',
'tsdoc-undefined-tag': 'off',
},
},

legacyExports: true,

tsconfig: 'tsconfig.dist.json',

babel: {
plugins: ['@babel/plugin-proposal-object-rest-spread'],
},
})
161 changes: 112 additions & 49 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,89 +2,152 @@
"name": "@portabletext/to-html",
"version": "1.0.4",
"description": "Render Portable Text to HTML",
"main": "./dist/to-html.js",
"module": "./dist/to-html.mjs",
"keywords": [
"portable-text"
],
"homepage": "https://github.com/portabletext/to-html#readme",
"bugs": {
"url": "https://github.com/portabletext/to-html/issues"
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/portabletext/to-html.git"
},
"license": "MIT",
"author": "Sanity.io <hello@sanity.io>",
"sideEffects": false,
"exports": {
".": {
"import": "./dist/to-html.mjs",
"require": "./dist/to-html.js"
}
"types": "./dist/pt-to-html.d.ts",
"source": "./src/index.ts",
"require": "./dist/pt-to-html.js",
"node": {
"import": "./dist/pt-to-html.cjs.mjs",
"require": "./dist/pt-to-html.js"
},
"import": "./dist/pt-to-html.esm.js",
"default": "./dist/pt-to-html.esm.js"
},
"./package.json": "./package.json"
},
"sideEffects": false,
"main": "./dist/pt-to-html.js",
"module": "./dist/pt-to-html.esm.js",
"source": "./src/index.ts",
"types": "./dist/pt-to-html.d.ts",
"files": [
"dist",
"!dist/stats.html",
"src",
"README.md"
],
"scripts": {
"lint": "eslint . && tsc --noEmit",
"prepublishOnly": "npm run build && npm run lint",
"build": "vite build",
"build": "run-s clean pkg:build pkg:check",
"clean": "rimraf .nyc_output dist coverage",
"coverage": "tap test/*.test.* --coverage-report=html",
"docs:build": "typedoc",
"format": "prettier --write --cache --ignore-unknown .",
"lint": "eslint .",
"pkg:build": "pkg-utils build --strict",
"pkg:check": "pkg-utils --strict",
"prepare": "husky install",
"prepublishOnly": "run-s build lint type-check",
"test": "tap test/*.test.*",
"prettify": "prettier --write src/**/*.ts src/**/*.tsx test/**/*.ts test/**/*.tsx",
"prettify-check": "prettier --check src/**/*.ts src/**/*.tsx test/**/*.ts test/**/*.tsx"
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/portabletext/to-html.git"
},
"keywords": [
"portable-text"
],
"author": "Sanity.io <hello@sanity.io>",
"license": "MIT",
"dependencies": {
"@portabletext/toolkit": "^1.0.5",
"@portabletext/types": "^1.0.2"
"type-check": "tsc --noEmit"
},
"devDependencies": {
"@rexxars/vite-dts": "^1.0.4",
"@types/tap": "^15.0.5",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"esbuild-register": "^3.2.1",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-sanity": "^5.1.0",
"prettier": "^2.5.1",
"rollup-plugin-visualizer": "^5.5.4",
"tap": "^15.1.5",
"typescript": "^4.5.4",
"vite": "^2.7.4"
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"bugs": {
"url": "https://github.com/portabletext/to-html/issues"
"lint-staged": {
"*": [
"prettier --write --cache --ignore-unknown"
]
},
"homepage": "https://github.com/portabletext/to-html#readme",
"prettier": {
"semi": false,
"printWidth": 100,
"bracketSpacing": false,
"plugins": [
"prettier-plugin-packagejson"
],
"printWidth": 100,
"semi": false,
"singleQuote": true
},
"eslintConfig": {
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"ecmaFeatures": {
"modules": true
}
},
"ecmaVersion": 9,
"sourceType": "module"
},
"extends": [
"sanity",
"sanity/typescript",
"prettier"
],
"ignorePatterns": [
"lib/**/"
"dist/**/"
]
},
"release": {
"branches": [
"+([0-9])?(.{+([0-9]),x}).x",
"main",
{
"name": "beta",
"prerelease": true
},
{
"name": "alpha",
"prerelease": true
}
],
"extends": "@sanity/semantic-release-preset"
},
"tap": {
"check-coverage": false,
"node-arg": [
"-r",
"esbuild-register"
],
"check-coverage": false
]
},
"dependencies": {
"@portabletext/toolkit": "^2.0.1",
"@portabletext/types": "^2.0.2"
},
"devDependencies": {
"@babel/core": "^7.20.12",
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
"@commitlint/cli": "^17.4.2",
"@commitlint/config-conventional": "^17.4.2",
"@sanity/pkg-utils": "^2.2.3",
"@sanity/semantic-release-preset": "^4.0.0",
"@types/tap": "^15.0.7",
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"commitizen": "^4.3.0",
"cz-conventional-changelog": "^3.3.0",
"esbuild": "^0.17.5",
"esbuild-register": "^3.4.2",
"eslint": "^8.8.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-sanity": "^6.0.0",
"husky": "^8.0.3",
"npm-run-all": "^4.1.5",
"prettier": "^2.5.1",
"prettier-plugin-packagejson": "^2.4.2",
"rimraf": "^4.1.2",
"semantic-release": "^20.0.4",
"tap": "^16.3.0",
"typedoc": "^0.23.19",
"typescript": "^4.9.4"
},
"packageManager": "pnpm@7.26.2",
"engines": {
"node": "^14.13.1 || >=16.0.0"
},
"publishConfig": {
"access": "public"
}
}
Loading