Skip to content

Commit

Permalink
Merge pull request #13 from aligent/feature/MI-39-support-cjs
Browse files Browse the repository at this point in the history
MI-39: Convert to Typescript & support CJS
  • Loading branch information
styler3 authored Nov 11, 2024
2 parents 1426967 + 99a9519 commit c292a69
Show file tree
Hide file tree
Showing 8 changed files with 299 additions and 99 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
- name: Install
run: pnpm install

- name: Build
run: pnpm build

- name: Preparing environment for release
run: |
VERSION=$(echo $GITHUB_REF_NAME | sed 's/^.*[A-Za-z]-//g')
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode
node_modules
.pnpm-store
dist
106 changes: 70 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,98 @@ Standard code quality tooling for projects written in TypeScript.

## Usage

Install this module:
### Install this package:

```bash
# NPM
npm install -D @aligent/ts-code-standards
# Yarn
yarn add -D @aligent/ts-code-standards
# PNPM
pnpm add -D @aligent/ts-code-standards
```

# NPM
npm install -D @aligent/ts-code-standards
# Yarn
yarn add -D @aligent/ts-code-standards
# PNPM
pnpm add -D @aligent/ts-code-standards
### Copy the `.editorconfig` from this package into your own project:

Copy the `.editorconfig` from this repo into your own.
```bash
# Assuming your package is installed in `node_modules` folder
cp node_modules/@aligent/ts-code-standards/.editorconfig ./.editorconfig
```

Add the following to your `prettier.config.js`:
### Add the following to your `prettier.config.js`:

```javascript
import { prettierConfig } from '@aligent/ts-code-standards';
- For ES modules project:

export default prettierConfig;
```
```javascript
import { prettierConfig } from '@aligent/ts-code-standards';

Then install the ESLint and TypeScript configs depending on what type of project you are setting up:
export default prettierConfig;
```

### General Projects
- For CommonJS project:

Add the following to your `eslint.config.js`:
```javascript
const { prettierConfig } = require('@aligent/ts-code-standards');

```javascript
import { eslintConfigs } from '@aligent/ts-code-standards';
module.exports = prettierConfig;
```

export default [...eslintConfigs.base];
```
### Install the ESLint and TypeScript configs:

#### General Projects

##### Add the following to your `eslint.config.js`:

- For ES modules project:

```javascript
import { eslintConfigs } from '@aligent/ts-code-standards';

export default [...eslintConfigs.base];
```

Add the following to your `tsconfig.json`:
- For CommonJS project:

```javascript
const { eslintConfigs } = require('@aligent/ts-code-standards');

module.exports = [...eslintConfigs.base];
```

##### Add the following to your `tsconfig.json`:

```json
{
"extends": "@aligent/ts-code-standards/tsconfigs/base.json"
}
{ "extends": "@aligent/ts-code-standards/tsconfigs-base" }
```

### React Projects
#### React Projects

Add the following to your `eslint.config.js`:
##### Add the following to your `eslint.config.js`:

```javascript
import { eslintConfigs } from '@aligent/ts-code-standards';
- For ES modules project:

export default [...eslintConfigs.react];
```
```javascript
import { eslintConfigs } from '@aligent/ts-code-standards';

export default [...eslintConfigs.react];
```

- For CommonJS project:

```javascript
const { eslintConfigs } = require('@aligent/ts-code-standards');

module.exports = [...eslintConfigs.react];
```

Add the following to your `tsconfig.json`:
##### Add the following to your `tsconfig.json`:

```json
{
"extends": "@aligent/ts-code-standards/tsconfigs/react.json"
}
{ "extends": "@aligent/ts-code-standards/tsconfigs-react" }
```

## Notes

- You'll need to add `include`, `exclude`, `paths` etc. to your `tsconfig` file. These settings will
be project specific.
- You'll need to add `include`, `exclude`, `paths` etc. to your `tsconfig` file. These settings will be project specific.
- Your project is considered as `ES modules` project if the `type` option in the nearest `package.json` is set to `module`. Otherwise, it's a CommonJS project. For more information on this, please check [CommonJS vs. ES modules in Node.js](https://blog.logrocket.com/commonjs-vs-es-modules-node-js/).
- For backward compatibility, we also export `./tsconfigs/base.json` and `./tsconfigs/react.json`. However, you should update to the new syntax when configuring your `tsconfig.json` when possible.
19 changes: 17 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
{
"name": "@aligent/ts-code-standards",
"main": "src/index.js",
"type": "module",
"exports": {
".": {
"require": "./dist/index.cjs",
"import": "./dist/index.mjs"
},
"./tsconfigs-base": "./tsconfigs/base.json",
"./tsconfigs-react": "./tsconfigs/react.json",
"./tsconfigs/base.json": "./tsconfigs/base.json",
"./tsconfigs/react.json": "./tsconfigs/react.json"
},
"files": [
"dist",
"tsconfigs"
],
"scripts": {
"test": "tsc && eslint .",
"build": "rollup -c",
"format": "prettier --ignore-path .prettierignore --check \"**/*.+(js|ts|json)\"",
"format:check": "pnpm run format",
"format:fix": "prettier --ignore-path .prettierignore --write \"**/*.+(js|ts|json)\""
Expand All @@ -13,17 +27,18 @@
"@eslint/js": "^9.14.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.0.0",
"prettier-plugin-tailwindcss": "^0.6.8",
"typescript-eslint": "^8.13.0"
},
"devDependencies": {
"@types/eslint-config-prettier": "^6.11.3",
"@types/eslint-plugin-jsx-a11y": "^6.9.0",
"@types/eslint__js": "^8.42.3",
"eslint": "^9.14.0",
"prettier": "^3.3.3",
"rollup": "^4.24.4",
"typescript": "^5.6.3"
},
"packageManager": "[email protected]+sha512.22721b3a11f81661ae1ec68ce1a7b879425a1ca5b991c975b074ac220b187ce56c708fe5db69f4c962c989452eee76c82877f4ee80f474cebd61ee13461b6228"
Expand Down
Loading

0 comments on commit c292a69

Please sign in to comment.