Skip to content

Commit

Permalink
feat: Dual ESM+CJS build
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Default export has been replaced with a named import:

```ts
import { checkEnv } from '@47ng/check-env'
```
  • Loading branch information
franky47 committed Oct 25, 2022
1 parent 2bbd92d commit 4411c39
Show file tree
Hide file tree
Showing 8 changed files with 749 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ src/
tsconfig.json
yarn-error.log
*.test.*
dist/demo*
output.png
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ yarn add @47ng/check-env
## Usage

```js
import checkEnv from '@47ng/check-env'
import { checkEnv } from '@47ng/check-env'

checkEnv({
// Will log an error and throw if any of these are missing:
Expand Down
24 changes: 18 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"name": "@47ng/check-env",
"version": "0.0.0-semantically-released",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"description": "Check that the critical environment variables are set",
"license": "MIT",
"author": {
Expand All @@ -21,12 +19,25 @@
"publishConfig": {
"access": "public"
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"type": "module",
"sideEffects": false,
"exports": {
".": {
"require": "./dist/index.cjs",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
}
},
"scripts": {
"test": "jest --coverage",
"test:watch": "jest --verbose --watch",
"build:clean": "rm -rf ./dist",
"build:ts": "tsc",
"build": "run-s build:clean build:ts",
"prebuild": "rm -rf ./dist",
"build:typecheck": "tsc",
"build:transpile": "unbuild",
"build": "run-p build:*",
"ci": "run-s test build",
"prepare": "husky install"
},
Expand All @@ -40,7 +51,8 @@
"npm-run-all": "^4.1.5",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"typescript": "^4.8.4"
"typescript": "^4.8.4",
"unbuild": "^0.9.4"
},
"jest": {
"verbose": true,
Expand Down
3 changes: 2 additions & 1 deletion src/check-env.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import checkEnv, {
import {
checkEnv,
CheckEnvInput,
MissingEnvironmentVariableError,
UnsafeEnvironmentVariableError
Expand Down
2 changes: 1 addition & 1 deletion src/demo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import checkEnv from './index'
import { checkEnv } from './index'

const env = {
NODE_ENV: 'production',
Expand Down
4 changes: 1 addition & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class UnsafeEnvironmentVariableError extends Error {

// --

const checkEnv = (
export const checkEnv = (
{
required,
unsafe,
Expand Down Expand Up @@ -111,5 +111,3 @@ const checkEnv = (
unsafe: unsafeProd
}
}

export default checkEnv
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"target": "es2018",
"lib": ["DOM"],
"module": "commonjs",
"declaration": true,
"outDir": "./dist",
"rootDir": "./src",
"moduleResolution": "node",
"esModuleInterop": true,
"noEmit": true,

// Strict Type-Checking Options
"strict": true,
Expand Down
Loading

0 comments on commit 4411c39

Please sign in to comment.