Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
21e8 committed Dec 7, 2024
1 parent f36e3f1 commit 9da84c4
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 50 deletions.
58 changes: 40 additions & 18 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
/* eslint-env node */
import * as esbuild from 'esbuild';
import { build } from 'esbuild';
import { nodeExternalsPlugin } from 'esbuild-node-externals';
import { execSync } from 'child_process';

const watch = process.argv.includes('--watch');

const buildOptions = {
entryPoints: ['src/index.ts'],
outdir: 'dist',
// Common options
const commonOptions = {
bundle: true,
minify: true,
platform: 'node',
target: 'node16',
format: 'cjs',
sourcemap: true,
plugins: [nodeExternalsPlugin()],
minify: true,
treeShaking: true,
external: ['node-fetch'],
plugins: [nodeExternalsPlugin()]
};

// Generate types
await esbuild.build({
await build({
entryPoints: ['src/index.ts'],
plugins: [
{
Expand All @@ -33,16 +32,39 @@ await esbuild.build({
],
});

// ESM build
await build({
...commonOptions,
entryPoints: ['src/index.ts'],
format: 'esm',
outfile: 'dist/index.js',
});

// CJS build
await build({
...commonOptions,
entryPoints: ['src/index.ts'],
format: 'cjs',
outfile: 'dist/index.cjs',
});

if (watch) {
esbuild.context(buildOptions).then((context) => {
context.watch();
console.log('Watching for changes...');
console.log('Watching for changes...');
// Watch ESM build
build({
...commonOptions,
entryPoints: ['src/index.ts'],
format: 'esm',
outfile: 'dist/index.js',
watch: true,
});

// Watch CJS build
build({
...commonOptions,
entryPoints: ['src/index.ts'],
format: 'cjs',
outfile: 'dist/index.cjs',
watch: true,
});
} else {
esbuild
.build({
...buildOptions,
external: ['typescript'],
})
.catch(() => process.exit(1));
}
17 changes: 11 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
/* eslint-env node */
/** @type {import('ts-jest').JestConfigWithTsJest} */
/** @type {import('jest').Config} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'js'],
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
transform: {
'^.+\\.ts$': 'ts-jest',
'^.+\\.tsx?$': ['ts-jest', {
tsconfig: 'tsconfig.json'
}]
},
testMatch: ['**/__tests__/**/*.test.ts'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
testMatch: ['**/__tests__/**/*.(test|spec).(ts|tsx|js)'],
globals: {
'ts-jest': {
isolatedModules: true
}
}
};
5 changes: 5 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Extend Jest timeout for slower tests
jest.setTimeout(30000)

// Add any global test setup here
process.env.NODE_ENV = 'test'
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"name": "0xalice-tgram-bot",
"version": "0.2.5",
"version": "0.2.6",
"description": "Batched Telegram notification bot for 0xAlice",
"main": "dist/index.js",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"engines": {
"node": ">=14.0.0"
},
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
"import": "./dist/index.js",
"require": "./dist/index.cjs"
}
},
"scripts": {
Expand Down Expand Up @@ -40,21 +42,21 @@
"author": "VBase",
"license": "MIT",
"dependencies": {
"node-fetch": "^3.3.2",
"node-fetch": "^3.3.0",
"typescript": "^4.9.5"
},
"devDependencies": {
"@types/jest": "^29.5.0",
"@types/jest": "^29.5.14",
"@types/node": "^18.15.11",
"@types/sinon": "^17.0.3",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"esbuild": "^0.24.0",
"esbuild-node-externals": "^1.15.0",
"eslint": "^8.37.0",
"jest": "^29.5.0",
"jest": "^29.7.0",
"prettier": "^2.8.7",
"sinon": "^19.0.2",
"ts-jest": "^29.1.0"
"ts-jest": "^29.2.5"
}
}
Loading

0 comments on commit 9da84c4

Please sign in to comment.