Skip to content

Commit

Permalink
Merge pull request #221 from shelfio/feature/INT-11-migrate-to-esm
Browse files Browse the repository at this point in the history
INT-11 [BREAKING CHANGES] Migrate to ESM, update supported Node.js to v18
  • Loading branch information
batovpasha authored Mar 28, 2024
2 parents 083cdc8 + 9e82b4f commit d9057dd
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 34 deletions.
19 changes: 10 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ orbs:
parameters:
node_version:
type: string
default: '16.15.0'
default: '18.18.2'

commands:
install_deps:
steps:
- node/with-cache:
cache-version: v1-all
cache-key: package.json
dir: ~/repo/node_modules
use-strict-cache: true
steps:
- run: yarn install --pure-lockfile --no-progress
- node/install-packages:
pkg-manager: yarn
cache-version: v1
cache-only-lockfile: false
app-dir: ~/repo
override-ci-command: >
npx --yes retry-cli -n 5 -t 3000 --
yarn install --pure-lockfile --ignore-scripts --no-progress
jobs:
build:
Expand All @@ -28,6 +29,6 @@ jobs:
steps:
- checkout
- install_deps
- run: yarn test
- run: yarn type-check
- run: yarn lint:ci
- run: yarn test
2 changes: 1 addition & 1 deletion benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import benny from 'benny';
// @ts-ignore
import fLI from 'fast-lorem-ipsum';
// @ts-ignore
// eslint-disable-next-line no-restricted-imports
import uslug from 'uslug';
import {fastUslug} from './lib';

Expand Down
25 changes: 25 additions & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const ES_PACKAGES_TO_TRANSFORM = [];

/** @type {import('jest').Config} */
const config = {
collectCoverageFrom: ['src/**/*.ts', '!src/**/schema.ts', '!src/**/types.ts'],
reporters: ['default', 'jest-junit'],
transform: {
'^.+\\.(t|j)sx?$': [
'@swc/jest',
{
jsc: {
parser: {
syntax: 'typescript',
},
},
},
],
},
resolver: 'ts-jest-resolver',
transformIgnorePatterns: [
`node_modules/(?!(${ES_PACKAGES_TO_TRANSFORM.join('|')}))/node_modules/.+\\.js`,
],
};

export default config;
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
"email": "[email protected]",
"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 && 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",
"benchmark": "tsx benchmark.ts",
"build": "rm -rf lib/ && tsc",
"coverage": "yarn test --coverage",
"lint": "yarn lint:ci --fix",
"lint:ci": "eslint . --ext .js,.ts,.json",
Expand All @@ -34,18 +35,14 @@
"eslint --fix"
]
},
"babel": {
"extends": "@shelf/babel-config/backend"
},
"prettier": "@shelf/prettier-config",
"dependencies": {},
"devDependencies": {
"@babel/cli": "7.24.1",
"@babel/core": "7.24.3",
"@shelf/babel-config": "3.0.0",
"@shelf/eslint-config": "3.15.1",
"@shelf/prettier-config": "1.0.0",
"@shelf/tsconfig": "0.1.0",
"@swc/core": "1.4.11",
"@swc/jest": "0.2.36",
"@types/jest": "29.5.12",
"@types/node": "16",
"@types/uslug": "1.0.4",
Expand All @@ -54,13 +51,16 @@
"fast-lorem-ipsum": "1.2.0",
"husky": "9.0.11",
"jest": "29.7.0",
"jest-junit": "16.0.0",
"lint-staged": "15.2.2",
"prettier": "3.2.5",
"ts-jest-resolver": "2.0.1",
"tsx": "4.7.1",
"typescript": "5.4.3",
"uslug": "1.0.4"
},
"engines": {
"node": ">=16"
"node": ">=18"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 2 additions & 2 deletions src/codes/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './LMN';
export * from './Z';
export * from './LMN.js';
export * from './Z.js';
4 changes: 2 additions & 2 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {LMN, Z} from './codes';
import {LMN, Z} from './codes/index.js';
import {
chineseL,
chineseR,
Expand All @@ -12,7 +12,7 @@ import {
lmnSymbol,
spaceSymbol,
zSymbol,
} from './consts';
} from './consts.js';

export const getRawSlug = (chars: string, allowedChars: Set<string>): string => {
const rawSlug = [];
Expand Down
7 changes: 5 additions & 2 deletions src/index.benchmark.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// eslint-disable-next-line no-restricted-imports
import uslug from 'uslug';
import mocks from './mocks';
import {fastUslug} from './index';
import mocks from './mocks.js';
import {fastUslug} from './index.js';

const runTimes = 10;
const desirableRunTimes = 1000;
Expand All @@ -23,6 +24,7 @@ describe.skip('old-new-uslug-benchmark', () => {
sumFaster += spentTimeOld / spentTimeNew;
});

// eslint-disable-next-line require-await
it.concurrent('should old slugify', async () => {
const startOld = +new Date();
for (const test of desirableTests) {
Expand All @@ -32,6 +34,7 @@ describe.skip('old-new-uslug-benchmark', () => {
spentTimeOld = endOld - startOld;
});

// eslint-disable-next-line require-await
it.concurrent('should new slugify', async () => {
const startNew = +new Date();
for (const test of desirableTests) {
Expand Down
4 changes: 2 additions & 2 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mocks from './mocks';
import {fastUslug} from './index';
import mocks from './mocks.js';
import {fastUslug} from './index.js';

it('should return slugified strings', () => {
for (const mock of mocks) {
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
severalSpacesOrHyphensRegex,
severalSpacesRegex,
spaceSymbol,
} from './consts';
import {getRawSlug} from './helpers';
} from './consts.js';
import {getRawSlug} from './helpers.js';

type OptionParams = {lower?: boolean; spaces?: boolean; allowedChars?: Set<string>};

Expand Down
8 changes: 6 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"extends": "@shelf/tsconfig/backend",
"compilerOptions": {
"strict": true
"strict": true,
"module": "NodeNext",
"declaration": true,
"declarationMap": true,
"outDir": "lib"
},
"exclude": ["node_modules"],
"exclude": ["node_modules", "**/*.test.*", "**/mocks.ts"],
"include": ["src"]
}

0 comments on commit d9057dd

Please sign in to comment.