Skip to content

Commit

Permalink
feat: build apps with tsup and use js files on production (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlankParticle authored Jul 21, 2024
1 parent 2393f6a commit f23b8ca
Show file tree
Hide file tree
Showing 18 changed files with 791 additions and 296 deletions.
5 changes: 3 additions & 2 deletions apps/mail-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"type": "module",
"scripts": {
"dev": "tsx watch --clear-screen=false app.ts",
"start": "node --import=tsx app.ts",
"build": "echo 'No Build Step Needed'",
"start": "node .output/app.js",
"build": "tsup",
"check": "tsc --noEmit"
},
"exports": {
Expand Down Expand Up @@ -47,6 +47,7 @@
"@types/jsdom": "^21.1.7",
"@types/node": "^20.14.10",
"@types/nodemailer": "^6.4.15",
"tsup": "^8.1.2",
"tsx": "^4.16.2"
}
}
3 changes: 1 addition & 2 deletions apps/mail-bridge/queue/mail-processor/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { sendRealtimeNotification } from '../../utils/realtime';
import { simpleParser, type EmailAddress } from 'mailparser';
import { env } from '../../env';
import { trace } from '@u22n/otel/exports';
import { logger } from '@u22n/otel/logger';
import { discord } from '@u22n/utils/discord';
import mime from 'mime';

Expand Down Expand Up @@ -786,7 +785,7 @@ export const worker = new Worker<
} catch (e) {
span.recordException(e as Error);
span.setStatus({ code: 2 });
logger.error(e, 'Error processing email');
console.error(e, 'Error processing email');
await discord.info(`Mailbridge Queue Error\n${(e as Error).message}`);
// Throw the error to be caught by the worker, and moving to failed jobs
throw e;
Expand Down
26 changes: 26 additions & 0 deletions apps/mail-bridge/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['app.ts'],
outDir: '.output',
format: 'esm',
target: 'esnext',
clean: true,
bundle: true,
treeshake: true,
noExternal: [/^@u22n\/.*/],
external: ['thream-stream'],
cjsInterop: true,
shims: true,
minify: false,
splitting: false,
banner: {
js: [
`import { createRequire } from 'module';`,
`const require = createRequire(import.meta.url);`
].join('\n')
},
esbuildOptions: (options) => {
options.legalComments = 'none';
}
});
5 changes: 3 additions & 2 deletions apps/platform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"type": "module",
"scripts": {
"dev": "tsx watch --clear-screen=false app.ts",
"start": "node --import=tsx app.ts",
"build": "echo 'No Build Step Needed'",
"start": "node .output/app.js",
"build": "tsup",
"check": "tsc --noEmit"
},
"exports": {
Expand Down Expand Up @@ -41,6 +41,7 @@
"@simplewebauthn/types": "^9.0.1",
"@types/node": "^20.14.10",
"@uninbox-ee/billing": "workspace:^",
"tsup": "^8.1.2",
"tsx": "^4.16.2",
"typescript": "5.5.3"
}
Expand Down
24 changes: 24 additions & 0 deletions apps/platform/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['app.ts'],
outDir: '.output',
format: 'esm',
target: 'esnext',
clean: true,
bundle: true,
treeshake: true,
noExternal: [/^@u22n\/.*/],
cjsInterop: true,
shims: true,
minify: false,
banner: {
js: [
`import { createRequire } from 'module';`,
`const require = createRequire(import.meta.url);`
].join('\n')
},
esbuildOptions: (options) => {
options.legalComments = 'none';
}
});
5 changes: 3 additions & 2 deletions apps/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"type": "module",
"scripts": {
"dev": "tsx watch --clear-screen=false app.ts",
"start": "node --import=tsx app.ts",
"build": "echo 'No Build Step Needed'",
"start": "node .output/app.js",
"build": "tsup",
"check": "tsc --noEmit"
},
"dependencies": {
Expand All @@ -25,6 +25,7 @@
},
"devDependencies": {
"@types/node": "^20.14.10",
"tsup": "^8.1.2",
"tsx": "^4.16.2",
"typescript": "5.5.3"
}
Expand Down
24 changes: 24 additions & 0 deletions apps/storage/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['app.ts'],
outDir: '.output',
format: 'esm',
target: 'esnext',
clean: true,
bundle: true,
treeshake: true,
noExternal: [/^@u22n\/.*/],
cjsInterop: true,
shims: true,
minify: false,
banner: {
js: [
`import { createRequire } from 'module';`,
`const require = createRequire(import.meta.url);`
].join('\n')
},
esbuildOptions: (options) => {
options.legalComments = 'none';
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import {
File
} from '@phosphor-icons/react';
import Link from 'next/link';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { useDeleteConvo$Cache, useToggleConvoHidden$Cache } from '../../utils';
import { useDeleteConvo$Cache } from '../../utils';
import useAwaitableModal, {
type ModalComponent
} from '@/src/hooks/use-awaitable-modal';
Expand Down
5 changes: 3 additions & 2 deletions apps/worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"type": "module",
"scripts": {
"dev": "tsx watch --clear-screen=false app.ts",
"start": "node --import=tsx app.ts",
"build": "echo 'No Build Step Needed'",
"start": "node .output/app.js",
"build": "tsup",
"check": "tsc --noEmit"
},
"exports": {
Expand All @@ -31,6 +31,7 @@
"devDependencies": {
"@types/node": "^20.14.10",
"@u22n/tsconfig": "^0.0.2",
"tsup": "^8.1.2",
"tsx": "^4.16.2",
"typescript": "^5.5.3"
}
Expand Down
24 changes: 24 additions & 0 deletions apps/worker/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['app.ts'],
outDir: '.output',
format: 'esm',
target: 'esnext',
clean: true,
bundle: true,
treeshake: true,
noExternal: [/^@u22n\/.*/],
cjsInterop: true,
shims: true,
minify: false,
banner: {
js: [
`import { createRequire } from 'module';`,
`const require = createRequire(import.meta.url);`
].join('\n')
},
esbuildOptions: (options) => {
options.legalComments = 'none';
}
});
5 changes: 3 additions & 2 deletions ee/apps/billing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
},
"scripts": {
"ee:dev": "tsx watch --clear-screen=false app.ts",
"ee:start": "node --import=tsx app.ts",
"ee:build": "echo 'No Build Step Needed'",
"ee:start": "node .output/app.js",
"ee:build": "tsup",
"check": "tsc --noEmit"
},
"dependencies": {
Expand All @@ -31,6 +31,7 @@
},
"devDependencies": {
"@types/node": "^20.14.6",
"tsup": "^8.1.2",
"tsx": "^4.15.6",
"typescript": "5.5.2"
}
Expand Down
24 changes: 24 additions & 0 deletions ee/apps/billing/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['app.ts'],
outDir: '.output',
format: 'esm',
target: 'esnext',
clean: true,
bundle: true,
treeshake: true,
noExternal: [/^@u22n\/.*/],
cjsInterop: true,
shims: true,
minify: false,
banner: {
js: [
`import { createRequire } from 'module';`,
`const require = createRequire(import.meta.url);`
].join('\n')
},
esbuildOptions: (options) => {
options.legalComments = 'none';
}
});
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"check:lint": "eslint . --ext .ts,.tsx --ignore-path .gitignore",
"check": "pnpm check:lint && pnpm check:types",
"fix": "eslint --fix . --ext .ts,.tsx --ignore-path .gitignore",
"start:all": "dotenv -e .env.local -- turbo run start",
"build:all": "dotenv -e .env.local -- turbo run build --cache-dir=.turbo",
"build": "pnpm run -r build",
"build:ee": "pnpm run -r ee:build",
Expand Down Expand Up @@ -40,6 +41,7 @@
"db:up": "dotenv -e .env.local -- turbo run db:up",
"db:check": "dotenv -e .env.local -- turbo run db:generate",
"db:drop": "dotenv -e .env.local -- turbo run db:drop",
"start:all:r": "infisical run --env=remote -- turbo run start",
"dev:r": "infisical run --env=remote -- turbo run dev",
"db:push:r": "infisical run --env=remote -- pnpm --dir packages/database db:push:r",
"db:studio:r": "infisical run --env=remote -- turbo run db:studio",
Expand Down
16 changes: 0 additions & 16 deletions packages/otel/logger.ts

This file was deleted.

15 changes: 6 additions & 9 deletions packages/otel/otel.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// TODO: add OpenTelemetry exporter

import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { ZipkinExporter } from '@opentelemetry/exporter-zipkin';
import { Resource } from '@opentelemetry/resources';
import {
SEMRESATTRS_SERVICE_NAME,
SEMRESATTRS_SERVICE_VERSION
} from '@opentelemetry/semantic-conventions';
import {
BatchSpanProcessor,
// BatchSpanProcessor,
NodeTracerProvider
} from '@opentelemetry/sdk-trace-node';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
Expand All @@ -22,12 +19,12 @@ export const setupTracer = ({
if (!env.OTEL_ENABLED) return;
const provider = new NodeTracerProvider({
resource: new Resource({
[SEMRESATTRS_SERVICE_NAME]: name,
[SEMRESATTRS_SERVICE_VERSION]: version
'service.name': name,
'service.version': version
})
});

provider.addSpanProcessor(new BatchSpanProcessor(new ZipkinExporter()));
// provider.addSpanProcessor(new BatchSpanProcessor(EXPORTER));
provider.register();

registerInstrumentations({
Expand Down
7 changes: 1 addition & 6 deletions packages/otel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,22 @@
"version": "0.0.0",
"type": "module",
"exports": {
"./logger": "./logger.ts",
"./otel": "./otel.ts",
"./hono": "./hono.ts",
"./exports": "./exports.ts"
},
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/exporter-zipkin": "^1.25.1",
"@opentelemetry/instrumentation": "^0.52.1",
"@opentelemetry/instrumentation-http": "^0.52.1",
"@opentelemetry/resources": "^1.25.1",
"@opentelemetry/sdk-trace-node": "^1.25.1",
"@opentelemetry/semantic-conventions": "^1.25.1",
"@t3-oss/env-core": "^0.10.1",
"pino": "^9.2.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@u22n/tsconfig": "^0.0.2",
"hono": "^4.4.13",
"pino-pretty": "^11.2.0"
"hono": "^4.4.13"
},
"peerDependencies": {
"hono": "^4.4.7"
Expand Down
Loading

0 comments on commit f23b8ca

Please sign in to comment.