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

refactor: convert to esm #18

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
File renamed without changes.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist
node_modules
.idea
coverage
dist/
node_modules/
.idea/
coverage/
.tsimp/
61 changes: 40 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,36 @@
"Gary Crye <[email protected]>",
"Spencer Tuft <[email protected]>"
],
"main": "dist/env-ssm.js",
"types": "dist/env-ssm.d.ts",
"type": "module",
"main": "./dist/cjs/index.js",
"types": "./dist/cjs/index.d.ts",
"module": "./dist/esm/index.js",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
}
}
},
"files": [
"dist"
],
"scripts": {
"build": "rimraf dist && tsc",
"build": "npm run clean && concurrently \"npm:build:*\" -c cyanBright --raw",
"build:cjs": "tsc -p tsconfig.cjs.json && echo-cli \"{\\\"type\\\": \\\"commonjs\\\"}\" > dist/cjs/package.json",
"build:esm": "tsc -p tsconfig.json && echo-cli \"{\\\"type\\\": \\\"module\\\"}\" > dist/esm/package.json",
"clean": "rimraf dist .tsimp",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"test": "jest --colors",
"test:coverage": "jest --colors --coverage || exit 0",
"//test": "ava test/**/*.spec.ts",
"test": "echo-cli \"The tests need to be converted to ava or node:test\" && exit 1",
"test:coverage": "c8 ava test/**/*.spec.ts",
"test:watch": "jest --colors --watch",
"prepublishOnly": "npm run build"
},
Expand Down Expand Up @@ -45,20 +64,25 @@
"@types/lodash.merge": "^4.6.6",
"@types/lodash.set": "^4.3.6",
"@typescript-eslint/eslint-plugin": "^5.46.1",
"ava": "^6.1.3",
"aws-sdk-client-mock": "^4.0.1",
"c8": "^10.1.2",
"commitizen": "^4.2.4",
"concurrently": "^8.2.2",
"cz-conventional-changelog": "^3.3.0",
"dotenv": "^8.2.0",
"echo-cli": "^2.0.0",
"env-var": "^7.0.0",
"eslint": "^8.29.0",
"eslint-config-standard-with-typescript": "^23.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-n": "^15.6.0",
"eslint-plugin-promise": "^6.1.1",
"jest": "^29.3.1",
"lint-staged": "^10.5.4",
"rimraf": "^3.0.2",
"ts-jest": "^29.0.3",
"typescript": "^4.9.4"
"sinon": "^18.0.0",
"tsimp": "^2.0.11",
"typescript": "^5.5.4"
},
"peerDependencies": {
"@aws-sdk/client-ssm": ">=3",
Expand All @@ -68,25 +92,20 @@
"@byu-oit/dottfvars": "^0.0.6",
"dotenv": "^8.2.0"
},
"jest": {
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
},
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": 80
}
}
},
"lint-staged": {
"*.ts": "npm run lint:fix"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"ava": {
"extensions": {
"ts": "module"
},
"nodeArguments": [
"--import=tsimp/import"
]
}
}
8 changes: 5 additions & 3 deletions src/env-ssm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
resolveProcessEnv,
resolveSSMClient,
resolveTfVar
} from './loaders'
import { PathSsm, PathSsmLike } from './path-ssm'
} from './loaders/index.js'
import { PathSsm, PathSsmLike } from './path-ssm.js'

export interface Options {
/**
Expand Down Expand Up @@ -75,7 +75,7 @@ async function resolveOptions (input: PathSsmLike | PathSsmLike[] | Options = {}
/**
* Creates an environment container from an SSM Parameter Store path
*/
export default async function EnvSsm<T extends Record<string, unknown>> (input: PathSsmLike | PathSsmLike[] | Options = {}, delimiter?: string): Promise<IEnv<IOptionalVariable, T>> {
export async function EnvSsm<T extends Record<string, unknown>> (input: PathSsmLike | PathSsmLike[] | Options = {}, delimiter?: string): Promise<IEnv<IOptionalVariable, T>> {
const options = await resolveOptions(input, delimiter)
const { tfvar, dotenv, processEnv, ssm, paths } = options

Expand All @@ -90,10 +90,12 @@ export default async function EnvSsm<T extends Record<string, unknown>> (input:

// Ensure all parameter values are of type string
for (const prop in container) {
/* eslint-disable-next-line @typescript-eslint/strict-boolean-expressions */
if (!Object.hasOwnProperty.call(container, prop) || typeof container[prop] === 'string') continue
container[prop] = JSON.stringify(container[prop])
}

// Return an instance of EnvVar for read-able and typed interactions with environment variables
return from(container)
}
export default EnvSsm
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './env-ssm.js'
2 changes: 1 addition & 1 deletion src/loaders/dotenv.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs'
import { Options } from '../env-ssm'
import { Options } from '../env-ssm.js'
import Debugger from 'debug'
import path from 'path'

Expand Down
8 changes: 4 additions & 4 deletions src/loaders/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './dotenv'
export * from './process'
export * from './ssm'
export * from './tfvars'
export * from './dotenv.js'
export * from './process.js'
export * from './ssm.js'
export * from './tfvars.js'
2 changes: 1 addition & 1 deletion src/loaders/process.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Debugger from 'debug'
import { Options } from '../env-ssm'
import { Options } from '../env-ssm.js'

const logger = Debugger('env-ssm/process-loader')

Expand Down
4 changes: 2 additions & 2 deletions src/loaders/ssm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
ParameterMetadata,
SSMClient
} from '@aws-sdk/client-ssm'
import { Options } from '../env-ssm'
import { PathSsm } from '../path-ssm'
import { Options } from '../env-ssm.js'
import { PathSsm } from '../path-ssm.js'
import Debugger from 'debug'

const logger = Debugger('env-ssm/ssm-loader')
Expand Down
2 changes: 1 addition & 1 deletion src/loaders/tfvars.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs'
import { Options } from '../env-ssm'
import { Options } from '../env-ssm.js'
import Debugger from 'debug'
import path from 'path'

Expand Down
6 changes: 3 additions & 3 deletions test/env-ssm.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs'
import { SSMClient } from './__mocks__/@aws-sdk/client-ssm'
import EnvSsm from '../src/env-ssm'
import { SSMClient } from './__mocks__/@aws-sdk/client-ssm.js'
import EnvSsm from '../src/env-ssm.js'
import { DescribeParametersResult, GetParametersByPathResult, GetParametersResult } from '@aws-sdk/client-ssm'
import {
ENV_SSM_DOTENV_KEY,
Expand All @@ -12,7 +12,7 @@ import {
resolvePathDelimiter,
resolvePaths, resolveProcessEnv,
resolveTfVar
} from '../src/loaders'
} from '../src/loaders/index.js'

const ssm = new SSMClient({ region: 'us-west-2' })

Expand Down
22 changes: 22 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"declaration": true,
"declarationDir": "dist/cjs",
"outDir": "dist/cjs",
"target": "es2022",
"declaration": true,
"declarationMap": true,
"module": "CommonJS",
"moduleResolution": "node",
"esModuleInterop": true,
"importHelpers": true,
"strictNullChecks": true,
"lib": [
"DOM",
"ES2022"
]
},
"include": [
"src"
]
}
4 changes: 4 additions & 0 deletions tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": [
"src",
"test"
]
}
16 changes: 13 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"declaration": true,
"sourceMap": true
"declarationDir": "dist/esm",
"outDir": "dist/esm",
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strictNullChecks": true,
"skipLibCheck": true,
"esModuleInterop": true,
"importHelpers": true,
"lib": [
"DOM",
"ES2022"
]
},
"include": [
"src"
Expand Down
Loading