Skip to content

Commit

Permalink
Merge pull request #68 from shelfio/feature/INT-11-esm
Browse files Browse the repository at this point in the history
Migrate to ESM
  • Loading branch information
dianakryskuw authored Jan 6, 2025
2 parents 18a1946 + 76a1a3f commit 65dc69c
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ commands:
steps:
- node/install-packages:
pkg-manager: yarn
cache-version: v1-all
cache-version: v2-all
cache-only-lockfile: true
app-dir: ~/repo
override-ci-command: yarn install --pure-lockfile --no-progress
Expand All @@ -27,6 +27,6 @@ jobs:
steps:
- checkout
- install_deps
- run: yarn test
- run: yarn type-check
- run: yarn lint:ci
- run: yarn test
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;
19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
"email": "andrii.bakanov@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": {
"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 . --quiet",
Expand All @@ -43,25 +44,23 @@
".husky/validate-circleci-config.sh"
]
},
"babel": {
"extends": "@shelf/babel-config/backend"
},
"prettier": "@shelf/prettier-config",
"dependencies": {},
"devDependencies": {
"@babel/cli": "7.26.4",
"@babel/core": "7.26.0",
"@shelf/babel-config": "3.0.0",
"@shelf/eslint-config": "4.2.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.14",
"@types/node": "20",
"eslint": "9.17.0",
"husky": "9.1.7",
"jest": "29.7.0",
"jest-junit": "16.0.0",
"lint-staged": "15.3.0",
"prettier": "3.4.2",
"ts-jest-resolver": "2.0.1",
"typescript": "5.7.2"
},
"engines": {
Expand Down
4 changes: 2 additions & 2 deletions src/evaluation.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {Expression} from './types';
import {evaluate} from './evaluation';
import type {Expression} from './types.js';
import {evaluate} from './evaluation.js';

const baseExpression: Expression = {
joiner: 'and',
Expand Down
7 changes: 2 additions & 5 deletions src/evaluation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type {Expression} from './types';
import type {JoinerParameters} from './types';
import type {Rule, StackElement} from './types';
import type {RuleParameters} from './types';
import {validateJoinerInvoke, validateRuleInvoke} from './validations';
import type {Expression, JoinerParameters, Rule, RuleParameters, StackElement} from './types.js';
import {validateJoinerInvoke, validateRuleInvoke} from './validations.js';

export const evaluate = ({
expression,
Expand Down
6 changes: 3 additions & 3 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
jest.mock('./evaluation');
jest.mock('./evaluation.js');

import {evaluate} from './evaluation';
import {evaluateExpression} from './index';
import {evaluate} from './evaluation.js';
import {evaluateExpression} from './index.js';

it('should return true', () => {
jest.mocked(evaluate).mockReturnValue(true);
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {Expression, VariableWithValue} from './types';
import {evaluate} from './evaluation';
import type {Expression, VariableWithValue} from './types.js';
import {evaluate} from './evaluation.js';

export const evaluateExpression = (
expression: Expression,
Expand All @@ -19,4 +19,4 @@ export const evaluateExpression = (
return result;
};

export type {Expression, Rule} from './types';
export type {Expression, Rule} from './types.js';
2 changes: 1 addition & 1 deletion src/validations.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {validateJoinerInvoke, validateRuleInvoke} from './validations';
import {validateJoinerInvoke, validateRuleInvoke} from './validations.js';

describe('validateJoinerInvoke', () => {
it('should throw error if joiner is not SINGLE and left is undefined', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/validations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {Expression, JoinerParameters, Rule} from './types';
import type {Expression, JoinerParameters, Rule} from './types.js';

export const validateJoinerInvoke = ({
joiner,
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 65dc69c

Please sign in to comment.