From e2856d980d1e9335d5e62c7de25c1d22e6956584 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Mon, 20 Nov 2023 08:34:42 +0100 Subject: [PATCH 1/4] fix: add back CJS support, with a test --- package.json | 8 ++++++-- pnpm-lock.yaml | 24 ++++++++++++------------ src/e2e.test.cjs | 5 +++++ src/emojify.ts | 8 ++++---- src/replace.ts | 2 +- 5 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 src/e2e.test.cjs diff --git a/package.json b/package.json index 9b89c9c..38a6450 100644 --- a/package.json +++ b/package.json @@ -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" } @@ -58,8 +62,8 @@ "*": "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": "^2.0.0" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 39497b3..1aa128b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,11 +6,11 @@ settings: dependencies: '@sindresorhus/is': - specifier: ^6.0.0 - version: 6.0.0 + specifier: ^4.6.0 + version: 4.6.0 char-regex: - specifier: ^2.0.0 - version: 2.0.1 + specifier: ^1.0.2 + version: 1.0.2 emojilib: specifier: ^2.4.0 version: 2.4.0 @@ -1434,16 +1434,16 @@ packages: resolution: {integrity: sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==} dev: true + /@sindresorhus/is@4.6.0: + resolution: {integrity: sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==} + engines: {node: '>=10'} + dev: false + /@sindresorhus/is@5.3.0: resolution: {integrity: sha512-CX6t4SYQ37lzxicAqsBtxA3OseeoVrh9cSJ5PFYam0GksYlupRfy1A+Q4aYD3zvcfECLc0zO2u+ZnR2UYKvCrw==} engines: {node: '>=14.16'} dev: true - /@sindresorhus/is@6.0.0: - resolution: {integrity: sha512-iVkg+3V+GJfof7yAHOxHyoiEfgpRJhnddOY3EsTM/uqwcm6M/jDQwK1n1nnraMpTRT36CxS0RCtJohggaQ0jgQ==} - engines: {node: '>=16'} - dev: false - /@sindresorhus/merge-streams@1.0.0: resolution: {integrity: sha512-rUV5WyJrJLoloD4NDN1V1+LDMDWOa4OTsT4yYJwQNpTU6FWxkxHpL7eu4w+DmiH8x/EAM1otkPE1+LaspIbplw==} engines: {node: '>=18'} @@ -2313,9 +2313,9 @@ packages: engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} dev: true - /char-regex@2.0.1: - resolution: {integrity: sha512-oSvEeo6ZUD7NepqAat3RqoucZ5SeqLJgOvVIwkafu6IP3V0pO38s/ypdVUmDDK6qIIHNlYHJAKX9E7R7HoKElw==} - engines: {node: '>=12.20'} + /char-regex@1.0.2: + resolution: {integrity: sha512-kWWXztvZ5SBQV+eRgKFeh8q5sLuZY2+8WUIzlxWVTg+oGwY14qylx1KbKzHd8P6ZYkAg0xyIDU9JMHhyJMZ1jw==} + engines: {node: '>=10'} dev: false /character-entities-legacy@1.1.4: diff --git a/src/e2e.test.cjs b/src/e2e.test.cjs new file mode 100644 index 0000000..e35c73f --- /dev/null +++ b/src/e2e.test.cjs @@ -0,0 +1,5 @@ +const { strict: assert } = require('node:assert') + +const emoji = require('../lib/index.cjs') + +assert.equal(emoji.emojify(':wave:'), '👋') diff --git a/src/emojify.ts b/src/emojify.ts index d21107d..e1d41eb 100644 --- a/src/emojify.ts +++ b/src/emojify.ts @@ -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' @@ -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) diff --git a/src/replace.ts b/src/replace.ts index 663258b..5ea5966 100644 --- a/src/replace.ts +++ b/src/replace.ts @@ -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) From f2de23424a97dce9cea6d835741044b3bbd526f2 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Mon, 20 Nov 2023 08:40:34 +0100 Subject: [PATCH 2/4] build before lint and test --- .github/workflows/lint.yml | 1 + .github/workflows/test.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f174caa..67a9ae5 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,6 +4,7 @@ jobs: steps: - uses: actions/checkout@v4 - uses: ./.github/actions/prepare + - run: pnpm build - run: pnpm lint name: Lint diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0c7400b..1ea15f3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,6 +4,7 @@ jobs: steps: - uses: actions/checkout@v4 - uses: ./.github/actions/prepare + - run: pnpm build - run: pnpm run test --coverage - name: Codecov uses: codecov/codecov-action@v3 From b53ad876a43ee9ea3f003d7e2489847b0391f1c2 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Mon, 20 Nov 2023 08:42:19 +0100 Subject: [PATCH 3/4] Move CJS test to its own file --- .github/workflows/test-cjs.yml | 16 ++++++++++++++++ .github/workflows/test.yml | 1 - package.json | 1 + src/{e2e.test.cjs => e2e.cjs} | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test-cjs.yml rename src/{e2e.test.cjs => e2e.cjs} (60%) diff --git a/.github/workflows/test-cjs.yml b/.github/workflows/test-cjs.yml new file mode 100644 index 0000000..1fe7c07 --- /dev/null +++ b/.github/workflows/test-cjs.yml @@ -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 + +on: + pull_request: ~ + push: + branches: + - main diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1ea15f3..0c7400b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,6 @@ jobs: steps: - uses: actions/checkout@v4 - uses: ./.github/actions/prepare - - run: pnpm build - run: pnpm run test --coverage - name: Codecov uses: codecov/codecov-action@v3 diff --git a/package.json b/package.json index 38a6450..8bf5815 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "prepare": "husky install", "should-semantic-release": "should-semantic-release --verbose", "test": "vitest", + "test:cjs": "node ./src/e2e.cjs", "tsc": "tsc" }, "lint-staged": { diff --git a/src/e2e.test.cjs b/src/e2e.cjs similarity index 60% rename from src/e2e.test.cjs rename to src/e2e.cjs index e35c73f..1895ace 100644 --- a/src/e2e.test.cjs +++ b/src/e2e.cjs @@ -2,4 +2,4 @@ const { strict: assert } = require('node:assert') const emoji = require('../lib/index.cjs') -assert.equal(emoji.emojify(':wave:'), '👋') +assert.equal(emoji.emojify(':wave:'), 'intentional failure') From 68d554ffe4e50ae61c6ed8c14f2eca3425d848f2 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Mon, 20 Nov 2023 08:44:12 +0100 Subject: [PATCH 4/4] Fix coverage --- .github/workflows/test-cjs.yml | 2 +- src/e2e.cjs | 2 +- vitest.config.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-cjs.yml b/.github/workflows/test-cjs.yml index 1fe7c07..9348c04 100644 --- a/.github/workflows/test-cjs.yml +++ b/.github/workflows/test-cjs.yml @@ -7,7 +7,7 @@ jobs: - run: pnpm build - run: pnpm run test:cjs -name: Test +name: Test CommonJS on: pull_request: ~ diff --git a/src/e2e.cjs b/src/e2e.cjs index 1895ace..e35c73f 100644 --- a/src/e2e.cjs +++ b/src/e2e.cjs @@ -2,4 +2,4 @@ const { strict: assert } = require('node:assert') const emoji = require('../lib/index.cjs') -assert.equal(emoji.emojify(':wave:'), 'intentional failure') +assert.equal(emoji.emojify(':wave:'), '👋') diff --git a/vitest.config.ts b/vitest.config.ts index d209a18..6a43cb1 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -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,