Skip to content

Commit

Permalink
Merge pull request #42 from ilovepixelart/feature/esm-support
Browse files Browse the repository at this point in the history
ESM support
  • Loading branch information
ilovepixelart authored Dec 6, 2023
2 parents 4bfdee6 + 01a0314 commit e1fa803
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 85 deletions.
18 changes: 17 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
"sourceType": "module"
},
"rules": {
"comma-dangle": ["error", "never"],
"comma-dangle": [
"error",
"never"
],
"@typescript-eslint/array-type": "error",
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/method-signature-style": "error",
Expand Down Expand Up @@ -86,6 +89,19 @@
"plugin:@typescript-eslint/stylistic-type-checked"
],
"rules": {
"@typescript-eslint/member-delimiter-style": [
"error",
{
"multiline": {
"delimiter": "none",
"requireLast": true
},
"singleline": {
"delimiter": "comma",
"requireLast": false
}
}
],
"@typescript-eslint/consistent-type-exports": "error",
"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/explicit-module-boundary-types": "error",
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# System files
.DS_Store
Thumbs.db

# Dependency directory
node_modules
dist
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"npmignore",
"parens",
"rhysd",
"singleline",
"sonarcloud",
"sonarjs",
"sonarsource",
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,30 @@ Lightweight rule engine, written in typescript

[![npm](https://nodei.co/npm/ts-rule-engine.png)](https://www.npmjs.com/package/ts-rule-engine)

## Supports and tested with

```json
{
"node": "16.x || 18.x || 20.x",
}
```

## Features

- [x] Structure for rule definition
- [x] Rerun rules after fact is updated
- [x] Stop rule engine on any rule from executing further
- [x] Infinite loop prevention with max iterations limit
- [x] One time rule execution in sequence
- [x] Rule weight for priority
- [x] Supports ESM and CommonJS

## Installation

```bash
npm install ts-rule-engine
yarn add ts-rule-engine
pnpm add ts-rule-engine
```

### 1. Defining a Rule
Expand Down
19 changes: 19 additions & 0 deletions bash/esm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# Define the directory to start the search
root_directory="dist/esm"

echo "Adding .js extension to relative imports in files:"
# Find all JavaScript files and iterate through them and add the .js extension to relative imports
find "$root_directory" -type f -name "*.js" | while read -r file; do
if awk '!/export {};|\/\/# sourceMappingURL:|^[[:space:]]*\/\//' "$file" | grep -q "import .* from '[.]\{0,2\}\/[^']*'"; then
sed -i.bak -E "s/(import .* from '[.]{0,2}\/[^']*)'/\1.js'/g" "$file" && echo "- $file"
fi
done

# Remove all backup files
find "$root_directory" -type f -name "*.bak" -exec rm {} +

echo -e "\nCreating package.json file in $root_directory"
# Create a package.json file to indicate that this is an ESM package
echo '{ "type": "module" }' > "$root_directory/package.json"
3 changes: 1 addition & 2 deletions config/tsconfig.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"rootDir": "../src",
"outDir": "../dist/cjs",
"declarationDir": "../dist/cjs/types",
"module": "commonjs",
"moduleResolution": "node",
"module": "CommonJS"
}
}
3 changes: 1 addition & 2 deletions config/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"rootDir": "../src",
"outDir": "../dist/esm",
"declarationDir": "../dist/esm/types",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"module": "ESNext"
}
}
136 changes: 68 additions & 68 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e1fa803

Please sign in to comment.