Skip to content

Commit

Permalink
feat: esm + cjs
Browse files Browse the repository at this point in the history
  • Loading branch information
onhate committed Mar 2, 2024
1 parent 36c52bd commit 885e56f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 11 deletions.
25 changes: 17 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
{
"name": "datelative",
"version": "0.0.3",
"version": "0.0.5",
"description": "A library that converts relative string text to JavaScript dates",
"main": "index.js",
"types": "index.d.ts",
"type": "module",
"exports": {
".": {
"types": "./dist/dts/index.d.ts",
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.js",
"default": "./dist/esm/index.js"
}
},

"scripts": {
"test": "node --test",
"test:watch": "node --test --watch",
"prepublishOnly": "npx tsc"
"prepublishOnly": "npm run build",
"clear": "rm -rf dist/*",
"prebuild": "npm run clear",
"build": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.dts.json",
"postbuild": "./postbuild.sh"
},

"repository": {
"type": "git",
"url": "git+https://github.com/onhate/datelative.git"
},
"files": [
"index.js",
"index.d.ts",
"index.d.ts.map",
"dist/*",
"README.md",
"package.json"
],
Expand Down
8 changes: 8 additions & 0 deletions postbuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

## So entire idea of this script is to generate separate package.json for ESM build (under build/esm directory) with the following content:
# { "type": "module" }
# This will tell the consumer build system that the underlying directory has modern EcmaScript modules. Otherwise, it will complain with:
# SyntaxError: Unexpected token 'export'

echo '{ "type": "module" }' > dist/esm/package.json
5 changes: 2 additions & 3 deletions tsconfig.json → tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
],
"compilerOptions": {
"allowJs": true,
"declaration": true,
"emitDeclarationOnly": true,
"declarationMap": true
"pretty": true,
"strict": true
}
}
8 changes: 8 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "dist/cjs",
"target": "es2015"
}
}
8 changes: 8 additions & 0 deletions tsconfig.dts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"outDir": "dist/dts",
"declaration": true,
"emitDeclarationOnly": true
}
}
8 changes: 8 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "esnext",
"outDir": "dist/esm",
"target": "esnext"
}
}

0 comments on commit 885e56f

Please sign in to comment.