Skip to content

Commit

Permalink
Merge pull request #363 from jaredwray/moving-to-cjs-and-esm-via-tsup
Browse files Browse the repository at this point in the history
moving to cjs and esm via tsup
  • Loading branch information
jaredwray authored Sep 17, 2024
2 parents 14e15b0 + 6e6d615 commit aaf5695
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 240 deletions.
11 changes: 1 addition & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,4 @@ services:
container_name: httpbin_container
ports:
- "8081:80" # Maps port 8080 on your machine to port 80 in the container
restart: always

pubsub-emulator:
image: gcr.io/google.com/cloudsdktool/cloud-sdk:emulators
command: gcloud beta emulators pubsub start --project=airhorn-project --host-port=0.0.0.0:8085
ports:
- "8085:8085"
environment:
- PUBSUB_PROJECT_ID=airhorn-project
- PUBSUB_EMULATOR_HOST=0.0.0.0:8085
restart: always
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
"version": "4.0.0",
"description": "Cloud Notification Library",
"type": "module",
"exports": "./dist/airhorn.js",
"main": "./dist/airhorn.cjs",
"module": "./dist/airhorn.js",
"types": "./dist/airhorn.d.ts",
"exports": {
".": {
"require": "./dist/airhorn.cjs",
"import": "./dist/airhorn.js"
}
},
"engines": {
"node": ">=20"
},
Expand All @@ -16,7 +23,7 @@
"test": "xo --fix && vitest run --coverage",
"clean": "rimraf ./dist ./coverage ./node_modules ./package-lock.json ./yarn.lock ./pnpm-lock.yaml ./site/dist",
"prepare": "npm run build",
"build": "tsc --project tsconfig.dist.json",
"build": "rimraf ./dist && tsup src/airhorn.ts --format cjs,esm --dts --clean",
"website:build": "rimraf ./site/readme.md && npx -y docula build -s ./site -o ./site/dist",
"website:serve": "rimraf ./site/readme.md && npx -y docula serve -s ./site -o ./site/dist",
"test:services:start": "docker compose -f docker-compose.yml up -d",
Expand All @@ -28,6 +35,7 @@
"docula": "^0.9.0",
"rimraf": "^6.0.1",
"ts-node": "^10.9.2",
"tsup": "^8.2.4",
"typescript": "^5.5.4",
"vitest": "^2.0.5",
"webpack": "^5.94.0",
Expand Down
124 changes: 0 additions & 124 deletions src/queue-providers/google-pubsub.ts

This file was deleted.

20 changes: 15 additions & 5 deletions test/airhorn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import {
} from 'vitest';
import type * as admin from 'firebase-admin';
import {AirhornProviderType} from '../src/provider-type.js';
import {Airhorn, AirhornNotificationStatus} from '../src/airhorn.js';
import {Airhorn, type AirhornNotification, AirhornNotificationStatus} from '../src/airhorn.js';
import {FirebaseMessaging} from '../src/providers/firebase-messaging.js';
import { MongoStoreProvider } from '../src/store-providers/mongo.js';
import { GooglePubSubQueue } from '../src/queue-providers/google-pubsub.js';
import { type CreateAirhornNotification } from '../src/store.js';
import {TestingData} from './testing-data.js';

Expand Down Expand Up @@ -318,13 +317,24 @@ describe('Airhorn Store and Subscription', async () => {
});

describe('Airhorn - Notification / Queue', async () => {
const providerMock = {
name: 'mock',
uri: 'mock://localhost',
// eslint-disable-next-line @typescript-eslint/no-empty-function
async publish(notification: AirhornNotification) {},
// eslint-disable-next-line @typescript-eslint/no-empty-function
async subscribe(callback: (notification: AirhornNotification, acknowledge: () => void) => void) {},
// eslint-disable-next-line @typescript-eslint/no-empty-function
async clearSubscription() {},
};

test('Airhorn Queue Initialization', async () => {
const QUEUE_PROVIDER = new GooglePubSubQueue();
const QUEUE_PROVIDER = providerMock;
const airhorn = new Airhorn({QUEUE_PROVIDER});
expect(airhorn.queue?.provider).toBeDefined();
});
test('Airhorn Queue Publish Notification', async () => {
const QUEUE_PROVIDER = new GooglePubSubQueue();
const QUEUE_PROVIDER = providerMock;
const STORE_PROVIDER = new MongoStoreProvider({uri: 'mongodb://localhost:27017/airhorn'});
const createNotification: CreateAirhornNotification = {
to: 'john@doe.org',
Expand All @@ -342,7 +352,7 @@ describe('Airhorn - Notification / Queue', async () => {
await airhorn.publishNotification(createNotification);
});
test('Airhorn Queue Publish Notification with no Store', async () => {
const QUEUE_PROVIDER = new GooglePubSubQueue();
const QUEUE_PROVIDER = providerMock;
const airhorn = new Airhorn({QUEUE_PROVIDER});
const createNotification: CreateAirhornNotification = {
to: 'john@doe.org',
Expand Down
78 changes: 0 additions & 78 deletions test/queue-providers/google-pubsub.test.ts

This file was deleted.

1 change: 0 additions & 1 deletion test/queue.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import { subscribe } from 'node:diagnostics_channel';
import {describe, test, expect} from 'vitest';
import {AirhornQueue} from '../src/queue.js';
import { AirhornNotificationStatus, type AirhornNotification } from '../src/notification.js';
Expand Down
6 changes: 0 additions & 6 deletions tsconfig.dist.json

This file was deleted.

35 changes: 23 additions & 12 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
{
"compilerOptions": {
"target": "ESNext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
"module": "NodeNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"declarationMap": true, /* Create sourcemaps for d.ts files. */
"sourceMap": true, /* Generates corresponding '.map' file. */
"outDir": "./dist", /* Redirect output structure to the directory. */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
"strict": true, /* Enable all strict type-checking options. */
"moduleResolution": "NodeNext" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
"baseUrl": "./src", /* Specify the base directory to resolve non-relative module names. */

/* Emit */
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
"sourceMap": true, /* Create source map files for emitted JavaScript files. */
"outDir": "./dist", /* Specify an output folder for all emitted files. */

/* Interop Constraints */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */

/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */

/* Completeness */
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
"lib": [
"ESNext", "DOM"
]
}
}
}
4 changes: 2 additions & 2 deletions vite.config.mjs → vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export default defineConfig({
coverage: {
exclude: [
'src/provider-interface.ts',
'site/dist/**',
'src/subscription.ts',
'dist/**',
'site/**',
'test/**',
'vite.config.mjs',
'vite.config.ts',
],
},
},
Expand Down

0 comments on commit aaf5695

Please sign in to comment.