Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@alcalzone/esm2cjs

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alcalzone/esm2cjs - npm Package Compare versions

Comparing version 1.2.3 to 1.3.0

3

build/cjs/esm2cjs.d.ts

@@ -13,3 +13,4 @@ import { BuildOptions } from "esbuild";

writePackageJson?: boolean;
packageJsonSideEffects?: boolean | "inherit" | string[];
}
export declare function esm2cjs({ inDir, outDir, globs, sourcemap, logLevel, platform, target, cleanOutDir, writePackageJson, }: ESM2CJSOptions): Promise<void>;
export declare function esm2cjs({ inDir, outDir, globs, sourcemap, logLevel, platform, target, cleanOutDir, writePackageJson, packageJsonSideEffects, }: ESM2CJSOptions): Promise<void>;

@@ -43,3 +43,3 @@ "use strict";

const shimsDir = import_node_path.default.join(_dirname, "../../shims");
async function esm2cjs({ inDir, outDir, globs = ["**/*.js"], sourcemap = true, logLevel = "warning", platform = "node", target = "node18", cleanOutDir = false, writePackageJson = true }) {
async function esm2cjs({ inDir, outDir, globs = ["**/*.js"], sourcemap = true, logLevel = "warning", platform = "node", target = "node18", cleanOutDir = false, writePackageJson = true, packageJsonSideEffects = "inherit" }) {
if (cleanOutDir)

@@ -78,8 +78,23 @@ await import_fs_extra.default.emptyDir(outDir);

if (writePackageJson) {
await import_fs_extra.default.writeJSON(import_node_path.default.join(inDir, "package.json"), { type: "module" }, {
spaces: 4
});
await import_fs_extra.default.writeJSON(import_node_path.default.join(outDir, "package.json"), { type: "commonjs" }, {
spaces: 4
});
let inheritedSideEffects;
if (packageJsonSideEffects === "inherit") {
const parentPackageJson = await import_fs_extra.default.readJSON(import_node_path.default.join(process.cwd(), "package.json")).catch(() => void 0);
if (parentPackageJson?.sideEffects != void 0) {
inheritedSideEffects = {
sideEffects: parentPackageJson.sideEffects
};
}
}
const sideEffects = (
// Assume the package has side effects, unless explicitly stated otherwise
packageJsonSideEffects === true || packageJsonSideEffects === void 0 ? {} : packageJsonSideEffects === "inherit" ? inheritedSideEffects ?? {} : { sideEffects: packageJsonSideEffects }
);
await import_fs_extra.default.writeJSON(import_node_path.default.join(inDir, "package.json"), {
type: "module",
...sideEffects
}, { spaces: 4 });
await import_fs_extra.default.writeJSON(import_node_path.default.join(outDir, "package.json"), {
type: "commonjs",
...sideEffects
}, { spaces: 4 });
}

@@ -86,0 +101,0 @@ }

@@ -13,3 +13,4 @@ import { BuildOptions } from "esbuild";

writePackageJson?: boolean;
packageJsonSideEffects?: boolean | "inherit" | string[];
}
export declare function esm2cjs({ inDir, outDir, globs, sourcemap, logLevel, platform, target, cleanOutDir, writePackageJson, }: ESM2CJSOptions): Promise<void>;
export declare function esm2cjs({ inDir, outDir, globs, sourcemap, logLevel, platform, target, cleanOutDir, writePackageJson, packageJsonSideEffects, }: ESM2CJSOptions): Promise<void>;

@@ -8,3 +8,3 @@ import path from "node:path";

export const shimsDir = path.join(_dirname, "../../shims");
export async function esm2cjs({ inDir, outDir, globs = ["**/*.js"], sourcemap = true, logLevel = "warning", platform = "node", target = "node18", cleanOutDir = false, writePackageJson = true, }) {
export async function esm2cjs({ inDir, outDir, globs = ["**/*.js"], sourcemap = true, logLevel = "warning", platform = "node", target = "node18", cleanOutDir = false, writePackageJson = true, packageJsonSideEffects = "inherit", }) {
// Clean the output dir if necessary

@@ -51,10 +51,31 @@ if (cleanOutDir)

if (writePackageJson) {
await fs.writeJSON(path.join(inDir, "package.json"), { type: "module" }, {
spaces: 4,
});
await fs.writeJSON(path.join(outDir, "package.json"), { type: "commonjs" }, {
spaces: 4,
});
let inheritedSideEffects;
if (packageJsonSideEffects === "inherit") {
const parentPackageJson = await fs
.readJSON(path.join(process.cwd(), "package.json"))
.catch(() => undefined);
if (parentPackageJson?.sideEffects != undefined) {
inheritedSideEffects = {
sideEffects: parentPackageJson.sideEffects,
};
}
}
const sideEffects =
// Assume the package has side effects, unless explicitly stated otherwise
packageJsonSideEffects === true ||
packageJsonSideEffects === undefined
? {}
: packageJsonSideEffects === "inherit"
? inheritedSideEffects ?? {}
: { sideEffects: packageJsonSideEffects };
await fs.writeJSON(path.join(inDir, "package.json"), {
type: "module",
...sideEffects,
}, { spaces: 4 });
await fs.writeJSON(path.join(outDir, "package.json"), {
type: "commonjs",
...sideEffects,
}, { spaces: 4 });
}
}
//# sourceMappingURL=esm2cjs.js.map

@@ -7,3 +7,3 @@ {

"description": "Command line utility to compile a JS project from ES modules to CommonJS",
"version": "1.2.3",
"version": "1.3.0",
"bin": "bin/esm2cjs.cjs",

@@ -10,0 +10,0 @@ "type": "module",

@@ -153,2 +153,5 @@ # esm2cjs

-->
### 1.3.0 (2024-11-06)
* Support specifying `sideEffects` in the generated `package.json` as a hint for bundlers
### 1.2.3 (2024-11-04)

@@ -155,0 +158,0 @@ * Update default target to node18

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc