diff --git a/package-lock.json b/package-lock.json index 7583eda..80201e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,18 @@ { "name": "streamed-chatgpt-api", - "version": "1.0.0", + "version": "1.0.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "streamed-chatgpt-api", - "version": "1.0.0", + "version": "1.0.8", "license": "MIT", "devDependencies": { "jest": "^29.5.0" }, "engines": { - "node": ">=14.0.0" + "node": ">=18.0.0" }, "optionalDependencies": { "node-fetch": "^3.1.0" diff --git a/package.json b/package.json index a5b43c3..4e59319 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,12 @@ "version": "1.0.8", "description": "A simple module for the server-side allowing you to connect to the ChatGPT and receive the response back in chunks so you can stream the response to the user.", "main": "index.js", + "exports": { + ".": { + "import": "./index.js", + "require": "./index.js" + } + }, "scripts": { "test": "jest" }, diff --git a/test/commonjs-import.test.js b/test/commonjs-import.test.js new file mode 100644 index 0000000..1da1b33 --- /dev/null +++ b/test/commonjs-import.test.js @@ -0,0 +1,21 @@ +// Test CommonJS import in CommonJS context +const { fetchStreamedChat, fetchStreamedChatContent } = require('../index'); + +describe('CommonJS imports', () => { + test('should export fetchStreamedChat function via require', () => { + expect(typeof fetchStreamedChat).toBe('function'); + expect(fetchStreamedChat.name).toBe('fetchStreamedChat'); + }); + + test('should export fetchStreamedChatContent function via require', () => { + expect(typeof fetchStreamedChatContent).toBe('function'); + expect(fetchStreamedChatContent.name).toBe('fetchStreamedChatContent'); + }); + + test('should have correct function signatures', () => { + // fetchStreamedChat should accept 2 parameters + expect(fetchStreamedChat.length).toBe(2); + // fetchStreamedChatContent should accept 1 parameter (options) with optional callbacks + expect(fetchStreamedChatContent.length).toBe(1); + }); +}); \ No newline at end of file diff --git a/test/es-import-test.mjs b/test/es-import-test.mjs new file mode 100644 index 0000000..c1e8b2e --- /dev/null +++ b/test/es-import-test.mjs @@ -0,0 +1,8 @@ +// Simple script to test ES module imports work +// Run with: node test/es-import-test.mjs + +import { fetchStreamedChat, fetchStreamedChatContent } from '../index.js'; + +console.log('✓ ES module imports working'); +console.log(' fetchStreamedChat:', typeof fetchStreamedChat); +console.log(' fetchStreamedChatContent:', typeof fetchStreamedChatContent); \ No newline at end of file