Skip to content

Commit

Permalink
refactor: commonjs => esm
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
- CommonJS => ESM.
- The minimal version of Node.js is 16.
  • Loading branch information
BlackGlory committed Jan 27, 2023
1 parent 10342e4 commit 73c71ce
Show file tree
Hide file tree
Showing 16 changed files with 979 additions and 1,838 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x]
node-version: [16.x]

steps:
- uses: actions/checkout@v2
Expand Down
8 changes: 5 additions & 3 deletions __tests__/group.spec.ts
@@ -1,7 +1,9 @@
import { group } from '@src/group'
import { group } from '@src/group.js'
import { jest } from '@jest/globals'
import { pass } from '@blackglory/pass'

const groupSpy = jest.spyOn(console, 'group').mockImplementation()
const groupEndSpy = jest.spyOn(console, 'groupEnd').mockImplementation()
const groupSpy = jest.spyOn(console, 'group').mockImplementation(pass)
const groupEndSpy = jest.spyOn(console, 'groupEnd').mockImplementation(pass)

afterEach(() => {
groupSpy.mockClear()
Expand Down
6 changes: 4 additions & 2 deletions __tests__/log.spec.ts
@@ -1,6 +1,8 @@
import { log } from '@src/log'
import { log } from '@src/log.js'
import { jest } from '@jest/globals'
import { pass } from '@blackglory/pass'

const logSpy = jest.spyOn(console, 'log').mockImplementation()
const logSpy = jest.spyOn(console, 'log').mockImplementation(pass)

afterEach(() => logSpy.mockClear())

Expand Down
6 changes: 4 additions & 2 deletions __tests__/time-async-function.spec.ts
@@ -1,8 +1,10 @@
import { timeAsyncFunction } from '@src/time-async-function'
import { timeAsyncFunction } from '@src/time-async-function.js'
import { delay } from 'extra-promise'
import { jest } from '@jest/globals'
import { pass } from '@blackglory/pass'

const TIME_ERROR = 1
const logSpy = jest.spyOn(console, 'log').mockImplementation()
const logSpy = jest.spyOn(console, 'log').mockImplementation(pass)

afterEach(() => logSpy.mockClear())

Expand Down
6 changes: 4 additions & 2 deletions __tests__/time-function.spec.ts
@@ -1,6 +1,8 @@
import { timeFunction } from '@src/time-function'
import { timeFunction } from '@src/time-function.js'
import { jest } from '@jest/globals'
import { pass } from '@blackglory/pass'

const logSpy = jest.spyOn(console, 'log').mockImplementation()
const logSpy = jest.spyOn(console, 'log').mockImplementation(pass)

afterEach(() => logSpy.mockClear())

Expand Down
6 changes: 4 additions & 2 deletions __tests__/time.spec.ts
@@ -1,8 +1,10 @@
import { time } from '@src/time'
import { time } from '@src/time.js'
import { delay } from 'extra-promise'
import { jest } from '@jest/globals'
import { pass } from '@blackglory/pass'

const TIME_ERROR = 1
const logSpy = jest.spyOn(console, 'log').mockImplementation()
const logSpy = jest.spyOn(console, 'log').mockImplementation(pass)

afterEach(() => logSpy.mockClear())

Expand Down
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'
, testEnvironment: 'node'
, testMatch: ['**/__tests__/**/?(*.)+(spec|test).[jt]s?(x)']
, moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
Expand Down
40 changes: 24 additions & 16 deletions package.json
Expand Up @@ -6,50 +6,58 @@
"files": [
"lib"
],
"type": "module",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"sideEffects": false,
"engines": {
"node": ">=16"
},
"repository": "git@github.com:BlackGlory/log.git",
"author": "BlackGlory <woshenmedoubuzhidao@blackglory.me>",
"license": "MIT",
"scripts": {
"prepare": "ts-patch install -s",
"lint": "eslint --ext .js,.jsx,.ts,.tsx --quiet src",
"test": "jest --config jest.config.js",
"test:coverage": "jest --coverage --config jest.config.js",
"prepublishOnly": "run-s clean build",
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --config jest.config.cjs",
"test:coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules 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",
"release": "standard-version"
},
"husky": {
"hooks": {
"pre-commit": "run-s lint build test",
"pre-commit": "run-s prepare clean lint build test",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"devDependencies": {
"@blackglory/jest-resolver": "^0.3.0",
"@blackglory/pass": "^1.1.0",
"@commitlint/cli": "^17.2.0",
"@commitlint/config-conventional": "^17.2.0",
"@types/jest": "^27.4.1",
"@types/jest": "^29.4.0",
"@typescript-eslint/eslint-plugin": "^5.41.0",
"@typescript-eslint/parser": "^5.41.0",
"cross-env": "^7.0.3",
"eslint": "^8.26.0",
"husky": "4",
"jest": "^27.5.1",
"jest": "^29.4.1",
"jest-resolve": "^29.4.1",
"npm-run-all": "^4.1.5",
"rimraf": "^3.0.2",
"rimraf": "^4.1.2",
"standard-version": "^9.5.0",
"ts-jest": "^27.1.4",
"tscpaths": "^0.0.9",
"ts-jest": "^29.0.5",
"ts-patch": "^2.1.0",
"tslib": "^2.3.1",
"typescript": "^4.6.3"
"typescript": "4.8",
"typescript-transform-paths": "^3.4.6"
},
"dependencies": {
"@blackglory/go": "^1.1.2",
"extra-compatible": "^0.1.0",
"extra-promise": "5",
"extra-utils": "4"
"extra-compatible": "^0.2.0",
"extra-promise": "^6.0.3",
"extra-utils": "^5.0.1"
}
}
10 changes: 5 additions & 5 deletions src/index.ts
@@ -1,5 +1,5 @@
export * from './log'
export * from './time'
export * from './time-function'
export * from './time-async-function'
export * from './group'
export * from './log.js'
export * from './time.js'
export * from './time-function.js'
export * from './time-async-function.js'
export * from './group.js'
2 changes: 1 addition & 1 deletion src/time-async-function.ts
@@ -1,5 +1,5 @@
import { performanceNow } from 'extra-compatible'
import { getElapsedTime } from '@utils/get-elapsed-time'
import { getElapsedTime } from '@utils/get-elapsed-time.js'

export function timeAsyncFunction<Result, Args extends any[]>(
message: string
Expand Down
2 changes: 1 addition & 1 deletion src/time-function.ts
@@ -1,5 +1,5 @@
import { performanceNow } from 'extra-compatible'
import { getElapsedTime } from '@utils/get-elapsed-time'
import { getElapsedTime } from '@utils/get-elapsed-time.js'

export function timeFunction<Result, Args extends any[]>(
message: string
Expand Down
2 changes: 1 addition & 1 deletion src/time.ts
@@ -1,5 +1,5 @@
import { performanceNow } from 'extra-compatible'
import { getElapsedTime } from '@utils/get-elapsed-time'
import { getElapsedTime } from '@utils/get-elapsed-time.js'
import { isPromiseLike } from 'extra-promise'

export function time<T>(message: string, fn: () => T): T
Expand Down
10 changes: 8 additions & 2 deletions tsconfig.base.json
@@ -1,7 +1,9 @@
{
"compilerOptions": {
"target": "ES2019"
, "module": "CommonJS"
"target": "ES2018"
, "module": "NodeNext"
, "moduleResolution": "NodeNext"
, "esModuleInterop": true
, "strict": true
, "noUnusedLocals": true
, "noUnusedParameters": true
Expand All @@ -11,5 +13,9 @@
, "@utils/*": ["src/utils/*"]
, "@test/*": ["__tests__/*"]
}
, "plugins": [
{ "transform": "typescript-transform-paths" }
, { "transform": "typescript-transform-paths", "afterDeclarations": true }
]
}
}

0 comments on commit 73c71ce

Please sign in to comment.