Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MI-39: Convert to Typescript & support CJS #13

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
105 changes: 69 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,97 @@ 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/).
17 changes: 15 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
{
"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"
kai-nguyen-aligent marked this conversation as resolved.
Show resolved Hide resolved
},
"files": [
"dist",
"tsconfigs"
],
"scripts": {
"test": "tsc && eslint .",
"build": "npx rollup -c",
kai-nguyen-aligent marked this conversation as resolved.
Show resolved Hide resolved
"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 +25,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