From a4f222957bd824317e0db668d8f292f15f298932 Mon Sep 17 00:00:00 2001 From: Pavlo Batov Date: Wed, 2 Aug 2023 10:44:23 +0300 Subject: [PATCH 1/8] chore!: migrate package to esm format --- package.json | 13 ++++--------- tsconfig.json | 10 ++++++++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 70c9c18..9d738f8 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,9 @@ "email": "vlad@shelf.io", "url": "https://shelf.io" }, + "sideEffects": false, + "type": "module", + "exports": "./lib/index.js", "main": "lib", "types": "lib/index.d.ts", "files": [ @@ -16,9 +19,7 @@ "scripts": { "benchmark:memory": "yarn build && cd benchmark/memory && ./test.sh", "benchmark:speed": "yarn build && cd benchmark/speed && babel test.ts | node", - "build": "rm -rf lib/ && yarn build:types && yarn build:code", - "build:code": "babel src --out-dir lib --ignore '**/*.test.ts' --extensions '.ts' && find ./lib -name '*.test.d.ts' -delete", - "build:types": "tsc --emitDeclarationOnly --declaration --isolatedModules false --declarationDir lib", + "build": "rm -rf lib/ && tsc", "coverage": "yarn test --coverage", "lint": "yarn lint:ci --fix", "lint:ci": "eslint . --ext .js,.ts,.json", @@ -35,14 +36,8 @@ "eslint --fix" ] }, - "babel": { - "extends": "@shelf/babel-config/backend" - }, "prettier": "@shelf/prettier-config", "devDependencies": { - "@babel/cli": "7.22.5", - "@babel/core": "7.22.5", - "@shelf/babel-config": "1.2.0", "@shelf/eslint-config": "2.27.1", "@shelf/prettier-config": "1.0.0", "@shelf/tsconfig": "0.0.11", diff --git a/tsconfig.json b/tsconfig.json index 5bbaf96..6ab995e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,14 @@ { "extends": "@shelf/tsconfig/backend", "compilerOptions": { - "strict": true + "strict": true, + "module": "ESNext", + "target": "ESNext", + "moduleResolution": "node", + "declaration": true, + "resolveJsonModule": false, + "outDir": "lib" }, - "exclude": ["node_modules"], + "exclude": ["node_modules", "**/*.test.*", "**/*.mock.ts"], "include": ["src"] } From 8437210caf057dc799a97cf106f8c5c7d9f4f094 Mon Sep 17 00:00:00 2001 From: Pavlo Batov Date: Wed, 2 Aug 2023 10:55:42 +0300 Subject: [PATCH 2/8] chore: use @swc/jest to transpile ts tests --- jest.config.ts | 9 +++++++++ package.json | 3 +++ 2 files changed, 12 insertions(+) create mode 100644 jest.config.ts diff --git a/jest.config.ts b/jest.config.ts new file mode 100644 index 0000000..bc0021b --- /dev/null +++ b/jest.config.ts @@ -0,0 +1,9 @@ +import type {Config} from 'jest'; + +const config: Config = { + transform: { + '^.+\\.(t|j)sx?$': '@swc/jest', + }, +}; + +export default config; diff --git a/package.json b/package.json index 9d738f8..830edd4 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,8 @@ "@shelf/eslint-config": "2.27.1", "@shelf/prettier-config": "1.0.0", "@shelf/tsconfig": "0.0.11", + "@swc/core": "1.3.73", + "@swc/jest": "0.2.27", "@types/jest": "29.4.0", "@types/node": "14", "benny": "3.7.1", @@ -51,6 +53,7 @@ "lint-staged": "13.2.2", "normalize-space-x": "4.1.2", "prettier": "2.8.8", + "ts-node": "10.9.1", "typescript": "5.1.3" }, "engines": { From 1b595d63ac6f3e7c3d4f6e255a75a3de031bc729 Mon Sep 17 00:00:00 2001 From: Pavlo Batov Date: Wed, 2 Aug 2023 11:03:51 +0300 Subject: [PATCH 3/8] test: increase overall coverage to 100% --- jest.config.ts | 9 +++++++++ src/index.test.ts | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/jest.config.ts b/jest.config.ts index bc0021b..599a668 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -4,6 +4,15 @@ const config: Config = { transform: { '^.+\\.(t|j)sx?$': '@swc/jest', }, + resetMocks: true, + coverageThreshold: { + global: { + branches: 100, + functions: 100, + lines: 100, + statements: 100, + }, + }, }; export default config; diff --git a/src/index.test.ts b/src/index.test.ts index 51f2209..7a9e799 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -15,6 +15,12 @@ describe('#normalizeSpaces', () => { expect(result).toEqual('a b'); }); + it('should normalize text without spaces at the start and at the end correctly', () => { + const result = normalizeSpaces(`a${ALL_WHITESPACE_CHARS_2018}b`); + + expect(result).toEqual('a b'); + }); + it('should normalize text with character that consists of surrogate pairs correctly', () => { const result = normalizeSpaces(' hello \n\n\n interesting \n \n \tworld 😀 '); From 96289290590019c19754dcab246684978bb034fa Mon Sep 17 00:00:00 2001 From: Pavlo Batov Date: Wed, 2 Aug 2023 11:05:08 +0300 Subject: [PATCH 4/8] chore: use yarn coverage command in ci --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5327e18..3fd09b9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,6 +26,6 @@ jobs: steps: - checkout - install_deps - - run: yarn test --maxWorkers=4 - run: yarn type-check - run: yarn lint:ci + - run: yarn coverage --maxWorkers=4 From 8450e2c7e5808262ac7fff5cf1625e8647711fde Mon Sep 17 00:00:00 2001 From: Pavlo Batov Date: Wed, 2 Aug 2023 11:05:50 +0300 Subject: [PATCH 5/8] chore: update node version to 16.17.0 in ci --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3fd09b9..6ed6d33 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,7 +6,7 @@ orbs: parameters: node_version: type: string - default: '16.15.0' + default: '16.17.0' commands: install_deps: From 404728dd47765b491153638c64f303daa98c4881 Mon Sep 17 00:00:00 2001 From: Pavlo Batov Date: Wed, 2 Aug 2023 11:07:26 +0300 Subject: [PATCH 6/8] chore: add retry logic for yarn install in ci --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6ed6d33..656bbf6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,7 +15,8 @@ commands: pkg-manager: yarn cache-version: v1-all app-dir: ~/repo - override-ci-command: yarn install --pure-lockfile --ignore-scripts --no-progress + override-ci-command: npx --yes retry-cli -n 5 -t 3000 -- \ + yarn install --pure-lockfile --ignore-scripts --no-progress jobs: build: From 9de496a837c43f0132069abdd80e587d0369b6e0 Mon Sep 17 00:00:00 2001 From: Pavlo Batov Date: Wed, 2 Aug 2023 11:10:42 +0300 Subject: [PATCH 7/8] chore: fix yarn install with retry command --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 656bbf6..32d1243 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,7 +15,8 @@ commands: pkg-manager: yarn cache-version: v1-all app-dir: ~/repo - override-ci-command: npx --yes retry-cli -n 5 -t 3000 -- \ + override-ci-command: > + npx --yes retry-cli -n 5 -t 3000 -- yarn install --pure-lockfile --ignore-scripts --no-progress jobs: From d57f9dec7635319e84e2daab0d2f02b62f6acb20 Mon Sep 17 00:00:00 2001 From: Pavlo Batov Date: Wed, 2 Aug 2023 11:32:25 +0300 Subject: [PATCH 8/8] chore: specify exact path in main property --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 830edd4..1b9a426 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "sideEffects": false, "type": "module", "exports": "./lib/index.js", - "main": "lib", + "main": "lib/index.js", "types": "lib/index.d.ts", "files": [ "lib"