Skip to content

Commit

Permalink
Merge pull request #34 from SeedCompany/next/nest
Browse files Browse the repository at this point in the history
API libs: CJS -> ESM / Node 20
  • Loading branch information
CarsonF authored Sep 26, 2024
2 parents 798b29d + 7db5b43 commit e518db7
Show file tree
Hide file tree
Showing 22 changed files with 1,961 additions and 1,748 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
!.yarn/versions
.pnp.*

.turbo
.nx

.env.local
.env.*.local
Expand Down
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { JestConfigWithTsJest } from 'ts-jest';

export default (): JestConfigWithTsJest => ({
preset: 'ts-jest/presets/default-esm',
extensionsToTreatAsEsm: ['.ts', '.tsx'],
testRegex: '\\.test\\.tsx?$',
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
}
},
"engines": {
"node": ">=16"
"node": ">=20"
},
"workspaces": [
"packages/*",
Expand All @@ -65,5 +65,5 @@
"url": "ssh://[email protected]/SeedCompany/libs.git",
"directory": "."
},
"packageManager": "yarn@4.1.1"
"packageManager": "yarn@4.5.0"
}
21 changes: 9 additions & 12 deletions packages/cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "NestJS library wrapper for external caching",
"license": "MIT",
"engines": {
"node": ">=16"
"node": ">=20"
},
"dependencies": {
"@nestjs/common": "^10",
Expand Down Expand Up @@ -40,16 +40,17 @@
"scripts": {
"build": "tsup",
"typecheck": "tsc",
"test": "jest"
"test": "node --experimental-vm-modules ../../node_modules/.bin/jest"
},
"devDependencies": {
"@apollo/utils.keyvaluecache": "^2.1.0",
"@nestjs/cache-manager": "^2.1.0",
"@nestjs/testing": "^9",
"@nestjs/testing": "^10.4.4",
"cache-manager": "^5.2.0",
"ioredis": "^5.3.1",
"keyv": "^4.5.4",
"lru-cache": "^11.0.1",
"reflect-metadata": "^0.1.12",
"rxjs": "^7.5.7"
},
"repository": {
Expand All @@ -61,21 +62,17 @@
"url": "https://github.com/seedcompany/libs/issues"
},
"files": [
"*"
"dist"
],
"type": "module",
"main": "./index.cjs",
"types": "./index.d.ts",
"exports": {
".": {
"import": "./index.js",
"require": "./index.cjs",
"types": "./index.d.ts"
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./stores/*": {
"import": "./stores/*.js",
"require": "./stores/*.cjs",
"types": "./stores/*.d.ts"
"types": "./dist/stores/*.d.ts",
"default": "./dist/stores/*.js"
}
}
}
6 changes: 1 addition & 5 deletions packages/cache/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ targets:
commitMessageFormat: >
release(${projectName}): ${version}
postTargets:
- cache:copy-assets-to-dist
- cache:publish-npm
- cache:publish-github
copy-assets-to-dist:
options:
cwd: packages/cache
publish-npm:
options:
distFolderPath: packages/cache/dist
distFolderPath: packages/cache
publish-github:
options:
tag: ${tag}
Expand Down
6 changes: 2 additions & 4 deletions packages/cache/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { defineConfig } from 'tsup';

export const tsup = defineConfig({
entry: ['src', '!src/**/*.test.ts'],
esbuildOptions: (opts) => {
opts.sourceRoot = './dist/';
},
format: ['cjs', 'esm'],
format: ['esm'],
bundle: false,
dts: true,
sourcemap: true,
clean: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"scripts": {
"build": "tsup",
"typecheck": "tsc",
"test": "jest"
"test": "node --experimental-vm-modules ../../node_modules/.bin/jest"
},
"repository": {
"type": "git",
Expand Down
12 changes: 5 additions & 7 deletions packages/data-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "NestJS library wrapper for data loaders",
"license": "MIT",
"engines": {
"node": ">=16"
"node": ">=20"
},
"dependencies": {
"@nestjs/common": "^9 || ^10",
Expand All @@ -21,7 +21,7 @@
"scripts": {
"build": "tsup",
"typecheck": "tsc",
"test": "jest"
"test": "node --experimental-vm-modules ../../node_modules/.bin/jest"
},
"devDependencies": {
"@apollo/server": "^4.7.5",
Expand All @@ -32,6 +32,7 @@
"@types/supertest": "^2.0.12",
"express": "^4.18.2",
"graphql": "^16",
"reflect-metadata": "^0.1.12",
"rxjs": "^7.5.7",
"supertest": "^6.3.3"
},
Expand All @@ -47,13 +48,10 @@
"dist"
],
"type": "module",
"main": "./dist/index.cjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
}
5 changes: 3 additions & 2 deletions packages/data-loader/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { defineConfig } from 'tsup';

export const tsup = defineConfig({
entry: ['src/index.ts', '!src/**/*.test.ts'],
format: ['cjs', 'esm'],
entry: ['src', '!src/**/*.test.ts'],
format: ['esm'],
bundle: false,
dts: true,
sourcemap: true,
clean: true,
Expand Down
52 changes: 25 additions & 27 deletions packages/email/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
"description": "NestJS library to generate emails via JSX and send them via AWS",
"license": "MIT",
"engines": {
"node": ">=16"
"node": ">=20"
},
"dependencies": {
"@aws-sdk/client-sesv2": "^3.218.0",
"@faire/mjml-react": "^3.1.1",
"@aws-sdk/client-sesv2": "^3.658.1",
"@faire/mjml-react": "^3.3.0",
"@nestjs/common": "^7.6.4 || ^8 || ^9 || ^10",
"emailjs": "^3.8.1",
"html-to-text": "^8.2.1",
"mjml": "^4.13.0",
"open": "^8.4.0",
"emailjs": "^4.0.3",
"html-to-text": "^9.0.5",
"mjml": "^4.15.3",
"open": "^10.1.0",
"reflect-metadata": "^0.1.13",
"tempy": "^1.0.1"
"tempy": "^3.1.0"
},
"peerDependencies": {
"@nestjs/common": "^7 || ^8 || ^9 || ^10",
Expand All @@ -26,19 +26,19 @@
"scripts": {
"build": "tsup",
"typecheck": "tsc",
"test": "jest"
"test": "node --experimental-vm-modules ../../node_modules/.bin/jest"
},
"devDependencies": {
"@nestjs/common": "^10.1.0",
"@nestjs/core": "^10.1.0",
"@nestjs/platform-express": "^10.1.0",
"@nestjs/testing": "^10.1.0",
"@types/html-to-text": "^8.1.1",
"@types/mjml-core": "^4.7.1",
"@types/react": "^18.0.25",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rxjs": "^7.5.7"
"@nestjs/common": "^10.4.4",
"@nestjs/core": "^10.4.4",
"@nestjs/platform-express": "^10.4.4",
"@nestjs/testing": "^10.4.4",
"@types/html-to-text": "^9.0.4",
"@types/mjml-core": "^4.15.0",
"@types/react": "^18.3.9",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"rxjs": "^7.8.1"
},
"repository": {
"type": "git",
Expand All @@ -49,19 +49,17 @@
"url": "https://github.com/seedcompany/libs/issues"
},
"files": [
"*"
"dist"
],
"type": "commonjs",
"main": "./index.js",
"types": "./index.d.ts",
"type": "module",
"exports": {
".": {
"default": "./index.js",
"types": "./index.d.ts"
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./templates": {
"default": "./templates/index.js",
"types": "./templates/index.d.ts"
"types": "./dist/templates/index.d.ts",
"default": "./dist/templates/index.js"
}
}
}
6 changes: 1 addition & 5 deletions packages/email/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ targets:
commitMessageFormat: >
release(${projectName}): ${version}
postTargets:
- email:copy-assets-to-dist
- email:publish-npm
- email:publish-github
copy-assets-to-dist:
options:
cwd: packages/email
publish-npm:
options:
distFolderPath: packages/email/dist
distFolderPath: packages/email
publish-github:
options:
tag: ${tag}
Expand Down
18 changes: 6 additions & 12 deletions packages/email/src/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { SendEmailCommand, SESv2Client as SES } from '@aws-sdk/client-sesv2';
import { render } from '@faire/mjml-react/utils/render';
import { Inject, Injectable, Logger } from '@nestjs/common';
import { promises as fs } from 'fs';
import { convert as htmlToText } from 'html-to-text';
import * as textFormatters from 'html-to-text/lib/formatter';
import { htmlToText } from 'html-to-text';
import openUrl from 'open';
import { createElement, ReactElement } from 'react';
import { file as tempFile } from 'tempy';
import { temporaryFile as tempFile } from 'tempy';
import {
EMAIL_MODULE_OPTIONS,
type EmailOptions,
Expand Down Expand Up @@ -118,18 +117,13 @@ export class EmailService {
}

private renderHtml(templateEl: ReactElement) {
const { html } = render(templateEl, {
minify: false,
});
const { html } = render(templateEl);
return html;
}

private renderText(templateEl: ReactElement) {
const { html: htmlForText } = render(
createElement(RenderForText, null, templateEl),
{
minify: false,
},
);

const text = htmlToText(htmlForText, {
Expand All @@ -143,7 +137,7 @@ export class EmailService {
table: (el, walk, builder, options) =>
el.attribs.role === 'presentation'
? walk(el.children, builder)
: textFormatters.dataTable(el, walk, builder, options),
: builder.options.formatters.dataTable(el, walk, builder, options),
},
});

Expand All @@ -154,9 +148,9 @@ export class EmailService {
const temp = tempFile({ extension: 'html' });
await fs.writeFile(temp, html);
await openUrl(`file://${temp}`);
// try to wait for chrome to open before deleting temp file
// try to wait for chrome to open before deleting the temp file
void sleep(10_000)
.then(() => fs.unlink(temp))
.then(() => fs.rm(temp, { recursive: true, force: true, maxRetries: 2 }))
.catch();
}
}
2 changes: 1 addition & 1 deletion packages/email/src/templates/attachment.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageAttachment } from 'emailjs/smtp/message';
import type { MessageAttachment } from 'emailjs';
import { createContext, ReactNode, useContext } from 'react';

export interface AttachmentProps
Expand Down
5 changes: 1 addition & 4 deletions packages/email/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import { defineConfig } from 'tsup';

export const tsup = defineConfig({
entry: ['src', '!src/**/*.test.ts'],
esbuildOptions: (opts) => {
opts.sourceRoot = './email/dist/';
},
format: ['esm'],
bundle: false,
format: ['cjs'],
inject: ['./react-shim.ts'],
dts: true,
sourcemap: true,
Expand Down
12 changes: 11 additions & 1 deletion packages/eslint-plugin/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
import type { JestConfigWithTsJest } from 'ts-jest';
import base from '../../jest.config';

const { testRegex, moduleNameMapper } = base();

// No ESM here yet.
// eslint-disable-next-line import/no-default-export
export { default } from '../../jest.config';
export default (): JestConfigWithTsJest => ({
preset: 'ts-jest',
testRegex,
moduleNameMapper,
});
5 changes: 3 additions & 2 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@
"scripts": {
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
"typecheck": "tsc",
"test": "jest"
"test": "node --experimental-vm-modules ../../node_modules/.bin/jest"
},
"devDependencies": {
"@types/common-tags": "^1.8.1",
"@typescript-eslint/utils": "^5.54.0",
"common-tags": "^1.8.2",
"react": "^18.0.0",
"react-dom": "^18.0.0"
"react-dom": "^18.0.0",
"typescript": "5.0.4"
},
"repository": {
"type": "git",
Expand Down
Loading

0 comments on commit e518db7

Please sign in to comment.