Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Dual Package "AGAIN" #26

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

See this http://keepachangelog.com link for information on how we want this document formatted.

## v1.5.5

### Fixed

Dual package approach.

## v1.5.4

### Added
Expand Down
52 changes: 42 additions & 10 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,56 @@
import * as esbuild from "esbuild";
import * as glob from "glob";
import { promises as fs } from "fs";
import { createRequire } from "module";

const require = createRequire(import.meta.url);
const pkg = require("./package.json");

async function removeDir(dir) {
try {
await fs.rm(dir, { recursive: true, force: true });
console.log(`Removed ${dir} directory`);
} catch (error) {
if (error.code !== "ENOENT") {
console.error(`Error removing ${dir} directory:`, error);
}
}
}

async function build() {
// Remove dist directory
await removeDir("dist");

// Get all .js files from the src directory
const entryPoints = glob.sync("src/**/*.js");

// Get all dependencies and devDependencies from package.json
const external = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.devDependencies || {}),
];

const commonConfig = {
entryPoints,
platform: "node",
target: "node18",
bundle: true,
outdir: "dist",
external, // This line excludes all packages listed in dependencies and devDependencies
};

// Build ESM version
await esbuild.build({
entryPoints: ["src/index.js"],
outfile: "dist/index.js",
...commonConfig,
format: "esm",
platform: "node",
target: "node14",
bundle: true,
outExtension: { ".js": ".js" },
});

// Build CommonJS version
await esbuild.build({
entryPoints: ["src/index.js"],
outfile: "dist/index.cjs",
...commonConfig,
format: "cjs",
platform: "node",
target: "node14",
bundle: true,
outExtension: { ".js": ".cjs" },
});

console.log("Build complete");
Expand Down
Loading
Loading