diff --git a/jest.config.mjs b/jest.config.mjs new file mode 100644 index 0000000..2e42917 --- /dev/null +++ b/jest.config.mjs @@ -0,0 +1,16 @@ +const ES_PACKAGES_TO_TRANSFORM = []; + +/** @type {import('jest').Config} */ +const config = { + collectCoverageFrom: ['src/**/*.ts', '!src/**/types.ts'], + reporters: ['default'], + transform: { + '^.+\\.(t|j)sx?$': '@swc/jest', + }, + resolver: 'ts-jest-resolver', + transformIgnorePatterns: [ + `node_modules/(?!(${ES_PACKAGES_TO_TRANSFORM.join('|')}))/node_modules/.+\\.js`, + ], +}; + +export default config; diff --git a/package.json b/package.json index e3ceeec..79895c8 100644 --- a/package.json +++ b/package.json @@ -18,19 +18,20 @@ "email": "vlad@shelf.io", "url": "https://shelf.io" }, - "main": "lib", + "sideEffects": false, + "type": "module", + "exports": "./lib/index.js", + "module": "./lib/index.js", "types": "lib/index.d.ts", "files": [ "lib" ], "scripts": { - "benchmark": "babel benchmark.ts | node", - "build": "rm -rf lib/ && yarn build:types && babel src --out-dir lib --ignore '**/*.test.ts' --extensions '.ts'", - "build:types": "tsc --emitDeclarationOnly --declaration --isolatedModules false --declarationDir lib", + "benchmark": "tsx benchmark.ts", + "build": "rm -rf lib/ && tsc", "coverage": "jest --coverage", "lint": "yarn lint:ci --fix", "lint:ci": "eslint . --quiet", - "prepack": "yarn build", "test": "jest src", "type-check": "tsc --noEmit", "type-check:watch": "npm run type-check -- --watch" @@ -43,22 +44,20 @@ "eslint --fix" ] }, - "babel": { - "extends": "@shelf/babel-config/backend" - }, - "jest": { - "testEnvironment": "node" + "resolutions": { + "strip-ansi": "6.0.1", + "wrap-ansi": "7.0.0", + "string-width": "4.2.3" }, "dependencies": { "runes": "0.4.3", - "string-length": "4.0.2" + "string-length": "6.0.0" }, "devDependencies": { - "@babel/cli": "7.26.4", - "@babel/core": "7.26.0", - "@shelf/babel-config": "3.0.0", "@shelf/eslint-config": "4.4.0", "@shelf/tsconfig": "0.1.0", + "@swc/core": "1.10.7", + "@swc/jest": "0.2.37", "@types/benchmark": "2.1.5", "@types/jest": "29.5.14", "@types/node": "18", @@ -70,6 +69,8 @@ "jest": "29.7.0", "lint-staged": "15.3.0", "prettier": "3.4.2", + "ts-jest-resolver": "2.0.1", + "tsx": "4.19.2", "typescript": "5.7.3" }, "engines": { diff --git a/src/index.test.ts b/src/index.test.ts index eeffcea..648d326 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1,4 +1,4 @@ -import fastChunkString from './index'; +import fastChunkString from './index.js'; const text = 'hello my dear world'; diff --git a/src/index.ts b/src/index.ts index 6d18b01..3facc56 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import runes from 'runes'; import stringLength from 'string-length'; -export default function fastChunkString( +function fastChunkString( str: string, { size, @@ -49,4 +49,4 @@ function getChunksUnicode(str: string, size: number): string[] { return chunks; } -module.exports = fastChunkString; +export default fastChunkString; diff --git a/tsconfig.json b/tsconfig.json index 5bbaf96..e394b40 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,15 @@ { "extends": "@shelf/tsconfig/backend", "compilerOptions": { - "strict": true + "strict": true, + "module": "ESNext", + "target": "ESNext", + "moduleResolution": "bundler", + "declaration": true, + "resolveJsonModule": true, + "declarationMap": true, + "outDir": "lib" }, - "exclude": ["node_modules"], + "exclude": ["node_modules", "**/*.test.*", "**/mocks.ts"], "include": ["src"] }