Skip to content

Commit

Permalink
Dual Package
Browse files Browse the repository at this point in the history
  • Loading branch information
metaskills committed Aug 27, 2024
1 parent ae94c85 commit 69eea14
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ jobs:
run: npm install
- name: Build
run: ./bin/build
- name: Remove Type
run: npm pkg delete type
- name: Publish
uses: JS-DevTools/npm-publish@v3
with:
Expand Down
1 change: 1 addition & 0 deletions bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
set -e

node build.js
npm pkg delete type
27 changes: 17 additions & 10 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as esbuild from "esbuild";
import * as glob from "glob";
import { promises as fs } from "fs";
import { createRequire } from "module";
import path from "path";

const require = createRequire(import.meta.url);
const pkg = require("./package.json");
Expand Down Expand Up @@ -36,24 +37,30 @@ async function build() {
target: "node18",
bundle: true,
outdir: "dist",
external, // This line excludes all packages listed in dependencies and devDependencies
external,
};

// Build ESM version
await esbuild.build({
...commonConfig,
format: "esm",
outExtension: { ".js": ".js" },
});

// Build CommonJS version
// Build CommonJS version only
await esbuild.build({
...commonConfig,
format: "cjs",
outExtension: { ".js": ".cjs" },
outExtension: { ".js": ".js" }, // Output .js files for CommonJS
});

console.log("Build complete");

// Modify the generated files to use module.exports
const distFiles = glob.sync("dist/**/*.js");
for (const file of distFiles) {
let content = await fs.readFile(file, "utf8");
content = content.replace(
/export {([^}]+)};/g,
(_, exports) => `module.exports = { ${exports.trim()} };`
);
await fs.writeFile(file, content);
}

console.log("CommonJS conversion complete");
}

build().catch(console.error);
7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
"version": "1.5.5",
"description": "An opinionated panel of experts implementation using OpenAI's Assistants API",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"exports": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"scripts": {
"setup": "./bin/setup",
"test": "./bin/test",
Expand All @@ -21,6 +15,7 @@
"src",
"test",
"CHANGELOG.md",
"jest.config.mjs",
"LICENSE.md",
"package.json",
"README.md"
Expand Down

0 comments on commit 69eea14

Please sign in to comment.