Skip to content

Commit

Permalink
Merge pull request #26 from metaskills/DualPackageAgain
Browse files Browse the repository at this point in the history
Fix Dual Package "AGAIN"
  • Loading branch information
metaskills authored Aug 27, 2024
2 parents bcf6f35 + e745e71 commit ae94c85
Show file tree
Hide file tree
Showing 4 changed files with 421 additions and 27 deletions.
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

0 comments on commit ae94c85

Please sign in to comment.