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

fix: add back CJS support, with a test #154

Merged
merged 4 commits into from
Nov 20, 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
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",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

#149 also broke CJS support with char-regex@2.

"emojilib": "^2.4.0",
"skin-tone": "^2.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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I played around with these a bit but couldn't find anything cleaner. Ran out of time today. But not super please about using a .default. 🤔


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
Loading