Skip to content

Commit

Permalink
Merge pull request #154 from JoshuaKGoldberg/fix-cjs
Browse files Browse the repository at this point in the history
fix: add back CJS support, with a test
  • Loading branch information
JoshuaKGoldberg authored Nov 20, 2023
2 parents 54bec24 + 68d554f commit ac996a3
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 20 deletions.
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/prepare
- run: pnpm build
- run: pnpm lint

name: Lint
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/test-cjs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/prepare
- run: pnpm build
- run: pnpm run test:cjs

name: Test CommonJS

on:
pull_request: ~
push:
branches:
- main
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"type": "module",
"exports": {
".": {
"types": {
"import": "./lib/index.d.ts",
"require": "./lib/index.d.cts"
},
"import": "./lib/index.js",
"require": "./lib/index.cjs"
}
Expand All @@ -52,14 +56,15 @@
"prepare": "husky install",
"should-semantic-release": "should-semantic-release --verbose",
"test": "vitest",
"test:cjs": "node ./src/e2e.cjs",
"tsc": "tsc"
},
"lint-staged": {
"*": "prettier --ignore-unknown --write"
},
"dependencies": {
"@sindresorhus/is": "^6.0.0",
"char-regex": "^2.0.0",
"@sindresorhus/is": "^4.6.0",
"char-regex": "^1.0.2",
"emojilib": "^2.4.0",
"skin-tone": "^3.0.0"
},
Expand Down
24 changes: 12 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/e2e.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { strict: assert } = require('node:assert')

const emoji = require('../lib/index.cjs')

assert.equal(emoji.emojify(':wave:'), '👋')
8 changes: 4 additions & 4 deletions src/emojify.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert, default as is } from '@sindresorhus/is'
import is from '@sindresorhus/is'

import { findByName } from './findByName.js'
import { asFunction, normalizeName } from './utils.js'
Expand All @@ -21,9 +21,9 @@ export const emojify = (
const fallbackFunction =
fallback === undefined ? fallback : asFunction(fallback)

assert.string(input)
assert.any([is.undefined, is.function], fallbackFunction)
assert.function(format)
is.assert.string(input)
is.assert.any([is.default.undefined, is.default.function_], fallbackFunction)
is.assert.function_(format)

return input.replace(/:[\w\-+]+:/g, part => {
const found = findByName(part)
Expand Down
2 changes: 1 addition & 1 deletion src/replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const replace = (
const replace = asFunction(replacement)

assert.string(input)
assert.function(replace)
assert.function_(replace)
assert.boolean(preserveSpaces)

const characters = input.match(charRegexMatcher)
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineConfig({
coverage: {
all: true,
branches: 100,
exclude: ['lib', 'src/*.d.ts', 'src/index.ts'],
exclude: ['lib', 'src/*.d.ts', 'src/e2e.cjs', 'src/index.ts'],
functions: 100,
include: ['src'],
lines: 100,
Expand Down

0 comments on commit ac996a3

Please sign in to comment.