Skip to content

Commit

Permalink
refactor: commonjs => esm
Browse files Browse the repository at this point in the history
BREAKING CHANGE: CommonJS => ESM
  • Loading branch information
BlackGlory committed Jan 21, 2023
1 parent b438e4e commit ac144c4
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 778 deletions.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion jest.config.js → jest.config.cjs
Expand Up @@ -2,7 +2,8 @@ const { pathsToModuleNameMapper } = require('ts-jest')
const { compilerOptions } = require('./tsconfig.base.json')

module.exports = {
preset: 'ts-jest'
preset: 'ts-jest/presets/default-esm'
, resolver: '@blackglory/jest-resolver'
, testMatch: ['**/__tests__/**/?(*.)+(spec|test).[jt]s?(x)']
, moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
prefix: '<rootDir>/'
Expand Down
21 changes: 12 additions & 9 deletions package.json
Expand Up @@ -5,6 +5,7 @@
"files": [
"lib"
],
"type": "module",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"sideEffects": false,
Expand All @@ -15,15 +16,14 @@
"node": ">=16"
},
"scripts": {
"prepare": "ts-patch install -s",
"lint": "eslint --ext .js,.jsx,.ts,.tsx --quiet src __tests__",
"test": "jest --runInBand --config jest.config.js",
"test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand --config jest.config.js",
"test:coverage": "jest --coverage --config jest.config.js",
"prepublishOnly": "run-s clean build",
"test": "jest --runInBand --config jest.config.cjs",
"test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand --config jest.config.cjs",
"test:coverage": "jest --coverage --config jest.config.cjs",
"prepublishOnly": "run-s prepare clean build",
"clean": "rimraf lib",
"build": "run-s build:*",
"build:compile": "tsc --project tsconfig.build.json --module commonjs --target es2018 --outDir lib",
"build:patch": "tscpaths -p tsconfig.build.json -s ./src -o ./lib",
"build": "tsc --project tsconfig.build.json --outDir lib",
"bench": "run-s bench:*",
"bench:bit-set": "ts-node --require tsconfig-paths/register benches/bit-set.ts",
"bench:sparse-map": "ts-node --require tsconfig-paths/register benches/sparse-map.ts",
Expand All @@ -36,6 +36,7 @@
}
},
"devDependencies": {
"@blackglory/jest-resolver": "^0.3.0",
"@commitlint/cli": "^17.4.2",
"@commitlint/config-conventional": "^17.4.2",
"@types/jest": "^29.2.6",
Expand All @@ -47,16 +48,18 @@
"extra-generator": "^0.2.23",
"husky": "^4.3.8",
"jest": "^29.3.1",
"jest-resolve": "^29.3.1",
"npm-run-all": "^4.1.5",
"return-style": "^1.0.1",
"rimraf": "^4.1.1",
"standard-version": "^9.5.0",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
"ts-patch": "^2.1.0",
"tsconfig-paths": "^4.1.2",
"tscpaths": "^0.0.9",
"tslib": "^2.4.1",
"typescript": "^4.9.4"
"typescript": "^4.9.4",
"typescript-transform-paths": "^3.4.6"
},
"dependencies": {
"@blackglory/errors": "^2.4.3",
Expand Down
2 changes: 1 addition & 1 deletion src/bit-set.ts
@@ -1,5 +1,5 @@
import { assert } from '@blackglory/errors'
import { trailingZeros } from '@utils/trailing-zeros'
import { trailingZeros } from '@utils/trailing-zeros.js'

export class BitSet {
private array: number[] = []
Expand Down
48 changes: 24 additions & 24 deletions src/index.ts
@@ -1,24 +1,24 @@
export * from './box'
export * from './cons'
export * from './array'
export * from './emitter'
export * from './big-map'
export * from './big-set'
export * from './hash-map'
export * from './hash-set'
export * from './queue'
export * from './lru-map'
export * from './expirable-map'
export * from './tlru-map'
export * from './trie-map'
export * from './string-trie-map'
export { RadixTree } from './radix-tree'
export { StringRadixTree } from './string-radix-tree'
export * from './sparse-set'
export * from './sparse-map'
export * from './typed-sparse-map'
export * from './typed-sparse-set'
export { DynamicTypedArray } from './dynamic-typed-array'
export * from './sorted-set'
export * from './bit-set'
export * from './typed-bit-set'
export * from './box.js'
export * from './cons.js'
export * from './array.js'
export * from './emitter.js'
export * from './big-map.js'
export * from './big-set.js'
export * from './hash-map.js'
export * from './hash-set.js'
export * from './queue.js'
export * from './lru-map.js'
export * from './expirable-map.js'
export * from './tlru-map.js'
export * from './trie-map.js'
export * from './string-trie-map.js'
export { RadixTree } from './radix-tree.js'
export { StringRadixTree } from './string-radix-tree.js'
export * from './sparse-set.js'
export * from './sparse-map.js'
export * from './typed-sparse-map.js'
export * from './typed-sparse-set.js'
export { DynamicTypedArray } from './dynamic-typed-array.js'
export * from './sorted-set.js'
export * from './bit-set.js'
export * from './typed-bit-set.js'
2 changes: 1 addition & 1 deletion src/sorted-set.ts
@@ -1,4 +1,4 @@
import { SkipList } from '@utils/skip-list'
import { SkipList } from '@utils/skip-list.js'
import { map } from 'iterable-operator'

export class SortedSet<T> implements Iterable<T> {
Expand Down
4 changes: 2 additions & 2 deletions src/typed-bit-set.ts
@@ -1,7 +1,7 @@
import { DynamicTypedArray } from './dynamic-typed-array'
import { UnsignedTypedArrayConstructor } from 'justypes'
import { assert } from '@blackglory/errors'
import { trailingZeros } from '@utils/trailing-zeros'
import { DynamicTypedArray } from './dynamic-typed-array.js'
import { trailingZeros } from '@utils/trailing-zeros.js'

export class TypedBitSet<T extends UnsignedTypedArrayConstructor> {
private bitsPerElement: number
Expand Down
2 changes: 1 addition & 1 deletion src/typed-sparse-map.ts
@@ -1,6 +1,6 @@
import { assert } from '@blackglory/errors'
import { TypedArrayConstructor, TypedArrayOfConstructor } from 'justypes'
import { DynamicTypedArray } from './dynamic-typed-array'
import { DynamicTypedArray } from './dynamic-typed-array.js'

export class TypedSparseMap<T extends TypedArrayConstructor> {
private keyToIndex: Array<number | undefined> = []
Expand Down
2 changes: 1 addition & 1 deletion src/typed-sparse-set.ts
@@ -1,5 +1,5 @@
import { UnsignedTypedArrayConstructor } from 'justypes'
import { DynamicTypedArray } from './dynamic-typed-array'
import { DynamicTypedArray } from './dynamic-typed-array.js'

export class TypedSparseSet<
T extends UnsignedTypedArrayConstructor
Expand Down
8 changes: 6 additions & 2 deletions tsconfig.base.json
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "ES2019"
, "module": "CommonJS"
"target": "ES2018"
, "module": "NodeNext"
, "strict": true
, "noUnusedLocals": true
, "noUnusedParameters": true
Expand All @@ -11,5 +11,9 @@
, "@utils/*": ["src/utils/*"]
, "@test/*": ["__tests__/*"]
}
, "plugins": [
{ "transform": "typescript-transform-paths" }
, { "transform": "typescript-transform-paths", "afterDeclarations": true }
]
}
}

0 comments on commit ac144c4

Please sign in to comment.