Skip to content

Commit

Permalink
Merge pull request #50 from Enase/typescript
Browse files Browse the repository at this point in the history
Convert Project to TypeScript - ESM Version
  • Loading branch information
Enase authored Sep 26, 2023
2 parents 41a5b76 + cd83b3c commit b1eac1a
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 34 deletions.
1 change: 0 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
enable-pre-post-scripts=true
publish-branch=typescript-cjs
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Unreleased list of features goes here...
-->

## [5.0.2] - 2023-09-26
## [6.0.0] - 2023-09-26

### Breaking Changes
- **Migration to TypeScript**: The project has been refactored using TypeScript. [Learn about our motivation and the detailed changes](https://github.com/Enase/serverless-ses-template/discussions/61).
- **Pure ESM Package**: Plugin transitioned to a pure ESM module. If you're unfamiliar with this, please [consult this guide](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) to understand the implications.
- **Serverless Version Requirement**: Ensure you are using `serverless` version [v3.2.0](https://github.com/serverless/serverless/releases/tag/v3.2.0) or above, as this is now the minimum supported version.


## [5.0.2] - 2023-09-26

### Breaking Changes
- **Migration to TypeScript**: The project has been refactored using TypeScript. [Learn about our motivation and the detailed changes](https://github.com/Enase/serverless-ses-template/discussions/61).
- **Serverless Version Requirement**: Ensure you are using `serverless` version [v3.2.0](https://github.com/serverless/serverless/releases/tag/v3.2.0) or above, as this is now the minimum supported version.

## [4.0.7] - 2023-06-27

### Fixed
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ Template sync plugin for Amazon Simple Email Service
A serverless plugin that allows automatically creating, updating and removing
AWS SES Templates using a configuration file and keeps your AWS SES Templates
synced with your configuration file.

> 🚨 **Important Notice**: Starting from 6.x version, plugin has transitioned to **[pure ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)** and requires serverless [v3.2.0](https://github.com/serverless/serverless/releases/tag/v3.2.0) or newer.
---
> 🚨 **Important Notice**: Starting from [6.x](https://github.com/Enase/serverless-ses-template/tree/6.0.0) version, plugin has transitioned to **[pure ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)** and requires serverless [v3.2.0](https://github.com/serverless/serverless/releases/tag/v3.2.0) or newer.
>
> If you need for **CJS package** use [5.x](https://github.com/Enase/serverless-ses-template/tree/5.0.2) plugin series
>
> If you need compatibility with `serverless<=3.2.0`, please use tag [v4.0.7](https://github.com/Enase/serverless-ses-template/tree/4.0.7).
>
> Read [motivation here](https://github.com/Enase/serverless-ses-template/discussions/61)
---
**REQUIRES** nodejs 18+

---
Expand Down
3 changes: 2 additions & 1 deletion examples/simple-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"name": "simple-service",
"version": "1.0.0",
"keywords": [],
"type": "module",
"dependencies": {
"aws-sdk": "^2.1464.0"
},
"devDependencies": {
"@haftahave/serverless-ses-template": "5.0.2"
"@haftahave/serverless-ses-template": "6.0.0"
},
"engines": {
"node": ">= 12.18.4",
Expand Down
10 changes: 8 additions & 2 deletions examples/simple-service/ses-email-templates/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const path = require("path")
import path from "node:path"
import { fileURLToPath } from "node:url"

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

const templateList = [
{
Expand All @@ -23,7 +27,7 @@ templateList.reduce((acc, templateInfo) => {
* @param {Object} _options - runtime options
* @returns {Promise<{name: string, subject: string, html: string, text}[]>}
*/
module.exports = async (serverless, _options) => {
const templateConfiguration = async (serverless, _options) => {
// You can load template configuration from filesystem using serverless object + runtime options
// or from any other source like database or API

Expand All @@ -44,3 +48,5 @@ module.exports = async (serverless, _options) => {
})
return sesEmailTemplates
}

export default templateConfiguration
12 changes: 11 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ import type { Config } from "jest"

const config: Config = {
verbose: true,
preset: "ts-jest",
preset: "ts-jest/presets/default-esm",
extensionsToTreatAsEsm: [".ts"],
transform: {
tsconfig: "<rootDir>/tsconfig.test.json",
"^.+\\.tsx?$": [
"ts-jest",
{
useESM: true,
},
],
},
projects: [
{
Expand All @@ -13,6 +20,9 @@ const config: Config = {
testRegex: "(/tests/.*|(\\.|/)test)\\.ts$",
testPathIgnorePatterns: ["./dist", ".eslintrc.cjs"],
moduleDirectories: ["node_modules", "node_modules/.pnpm", "src"],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
},
],
coverageReporters: ["text"],
Expand Down
40 changes: 32 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"version": "5.0.2",
"version": "6.0.0",
"description": "Serverless template sync plugin for Amazon Simple Email Service",
"keywords": [
"serverless",
Expand Down Expand Up @@ -38,16 +38,38 @@
"email": "[email protected]"
}
],
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/esm/index.js",
"default": "./dist/esm/index.js"
},
"./package.json": "./package.json"
},
"types": "index.d.ts",
"scripts": {
"build:clean": "shx rm -rf ./dist",
"build:package": "npm-run-all build:clean compile",
"compile": "npm-run-all compile:cjs",
"compile:cjs": "tsc -b ./src/tsconfig.cjs.json",
"prepublishOnly": "npm-run-all build:package typecheck lint test",
"compile": "npm-run-all compile:esm compile:types",
"compile:esm": "tsc -b ./src/tsconfig.esm.json",
"compile:types": "tsc -b ./src/tsconfig.types.json",
"prepublishOnly": "npm-run-all module:set build:package typecheck lint test",
"postpublish": "pnpm run module:delete",
"lint": "eslint .",
"typecheck": "tsc -noEmit",
"test": "jest --runInBand"
"module:set": "pnpm pkg set 'type'='module'",
"module:delete": "pnpm pkg delete 'type'",
"pretest": "pnpm run module:delete",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --runInBand",
"posttest": "pnpm pkg set 'type'='module'"
},
"typesVersions": {
">=4.2": {
"*": [
"dist/types/*"
]
}
},
"peerDependencies": {
"serverless": ">=3.2.0"
Expand Down Expand Up @@ -82,12 +104,14 @@
"typescript": "5.1.6"
},
"files": [
"dist/cjs/**/!(*.tsbuildinfo|types.js)",
"dist/esm/**/!(*.tsbuildinfo|types.js)",
"dist/types/**/!(*.tsbuildinfo)",
"package.json",
"LICENSE",
"*.md"
],
"engines": {
"node": ">=18.8.0"
}
},
"type": "module"
}
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import path from "node:path"
import chalk from "chalk"
import Table from "cli-table"
import commandsConfig from "./commands-config"
import SesTemplatePluginLogger from "./logger"
import RequestHandler from "./request-handler"
import RuntimeUtils from "./runtime-utils"
import commandsConfig from "./commands-config.js"
import SesTemplatePluginLogger from "./logger.js"
import RequestHandler from "./request-handler.js"
import RuntimeUtils from "./runtime-utils.js"
import type {
Configuration,
ConfigurationItem,
PluginOptions,
ServerlessExtended,
ServerlessHooksDefinition,
ServerlessLogging,
} from "./types"
} from "./types.js"

const defaultSesTemplatesDeployHook = "before:deploy:deploy"

Expand Down Expand Up @@ -362,4 +362,4 @@ class ServerlessSesTemplatePlugin {
}
}

export = ServerlessSesTemplatePlugin
export default ServerlessSesTemplatePlugin
2 changes: 1 addition & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ServerlessLogging } from "./types"
import type { ServerlessLogging } from "./types.js"

class SesTemplatePluginLogger {
private readonly log: ServerlessLogging["log"]
Expand Down
6 changes: 3 additions & 3 deletions src/request-handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SesTemplatePluginLogger from "./logger"
import RuntimeUtils from "./runtime-utils"
import SesTemplatePluginLogger from "./logger.js"
import RuntimeUtils from "./runtime-utils.js"
import type {
ConfigurationItem,
LoadTemplatesParams,
Expand All @@ -9,7 +9,7 @@ import type {
SesGetEmailTemplateResponse,
SesListEmailTemplatesResponse,
SesTemplateResponseItem,
} from "./types"
} from "./types.js"

class RequestHandler {
private readonly AWS_SES_SERVICE_NAME = "SESV2"
Expand Down
2 changes: 1 addition & 1 deletion src/runtime-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PluginOptions, ServerlessExtended } from "./types"
import type { PluginOptions, ServerlessExtended } from "./types.js"

const defaultSesTemplatesConfigFilePath = "./ses-email-templates/index.js"

Expand Down
9 changes: 4 additions & 5 deletions src/tsconfig.cjs.json → src/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"target": "ES2020",
"downlevelIteration": true,
"outDir": "../dist/cjs"
}
"target": "esnext",
"module": "ES2022",
"outDir": "../dist/esm"
},
}
12 changes: 12 additions & 0 deletions src/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./tsconfig.esm.json",
"compilerOptions": {
"removeComments": false,
"declaration": true,
"declarationMap": true,
"outDir": "../dist/types",
"declarationDir": "../dist/types",
"emitDeclarationOnly": true
}
}
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"incremental": true,
"removeComments": true,
"preserveConstEnums": true,
Expand Down

0 comments on commit b1eac1a

Please sign in to comment.