Skip to content

Commit

Permalink
Add CommonJS support (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
kibertoad authored Feb 8, 2024
1 parent 8305b99 commit 30c117c
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 20 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:vitest/recommended",
"plugin:import-esm/recommended",
"prettier"
"plugin:import-esm/recommended"
],
"rules": {
"@typescript-eslint/no-empty-interface": "warn",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Build TS
run: |
npm run build
npm run build:dev
- name: Run Tests
run: |
Expand Down
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@ node_modules
.eslintcache
dist
coverage
/.idea/.gitignore
/.idea/frontend-http-client.iml
/.idea/modules.xml
/.idea/vcs.xml
/.idea
/package-lock.json
34 changes: 24 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,22 @@
"LICENSE",
"README.md"
],
"main": "dist/index.js",
"types": "dist/index.d.ts",
"main": "./dist/index.cjs",
"types": "./dist/index.d.ts",
"module": "./dist/index.mjs",
"type": "module",
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
}
},
"author": {
"name": "Lokalise",
"url": "https://lokalise.com/"
Expand All @@ -23,12 +36,13 @@
"access": "public"
},
"scripts": {
"build": "tsc",
"build:dev": "tsc",
"build:release": "tsup",
"clean": "rimraf dist .eslintcache",
"lint": "eslint --cache --max-warnings=0 . && prettier --check --log-level warn src \"**/*.{json,md,ts,tsx}\" && tsc --noEmit",
"lint": "eslint --cache --max-warnings=0 . && prettier --check src \"**/*.{json,md,ts,tsx}\" && tsc --noEmit",
"lint:fix": "prettier --write src \"**/*.{json,md,ts,tsx}\" --log-level=warn && eslint . --fix",
"test": "vitest run",
"prepublishOnly": "npm run clean && npm run build"
"prepublishOnly": "npm run clean && npm run build:release"
},
"dependencies": {
"fast-querystring": "^1.1.2"
Expand All @@ -42,18 +56,18 @@
"@types/node": "^20.11.5",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"@vitest/coverage-v8": "^1.2.1",
"@vitest/coverage-v8": "^1.2.2",
"jest-fail-on-console": "^3.1.2",
"eslint": "^8.55.0",
"eslint-config-prettier": "^9.1.0",
"eslint": "^8.56.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-vitest": "^0.3.20",
"eslint-plugin-import-esm": "^1.2.1",
"mockttp": "^3.10.1",
"prettier": "^3.2.4",
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"tsup": "8.0.1",
"typescript": "~5.3.3",
"vitest": "^1.2.1"
"vitest": "^1.2.2"
},
"keywords": [
"frontend",
Expand Down
4 changes: 4 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"include": [",./index.ts", "./src/**/*.ts"]
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"resolveJsonModule": true
},
"include": ["src/**/*", "index.ts"],
"exclude": ["src/**/*.spec.ts", "src/**/*.test.ts"],
"exclude": ["src/**/*.spec.ts", "src/**/*.test.ts"]
}
2 changes: 1 addition & 1 deletion tsconfig.lint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": ["./tsconfig.json"],
"include": ["./src/**/*", "index.ts", "vitest.config.ts"],
"include": ["./src/**/*", "index.ts", "vitest.config.ts", "tsup.config.ts"],
"exclude": []
}
22 changes: 22 additions & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { defineConfig } from 'tsup'

// eslint-disable-next-line import/no-default-export
export default defineConfig({
outDir: './dist',
clean: true,
dts: true,
format: ['esm', 'cjs'],
outExtension: ({ format }) => ({
js: format === 'cjs' ? '.cjs' : '.mjs',
}),
cjsInterop: true,
entry: {
index: './index.ts',
},
sourcemap: true,
skipNodeModulesBundle: true,
target: 'es2022',
tsconfig: './tsconfig.build.json',
keepNames: true,
bundle: true,
})

0 comments on commit 30c117c

Please sign in to comment.