rollup-plugin-conditional-exec
Advanced tools
Comparing version 2.0.4 to 2.1.0
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const child_process_1 = require("child_process"); | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
default: () => conditionalExec | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
var import_child_process = require("child_process"); | ||
function conditionalExec(opts) { | ||
const cmd = opts.command; | ||
const options = opts.options || { stdio: "inherit" }; | ||
const condition = opts.condition || (() => true); | ||
const afterExec = opts.afterExec || (() => undefined); | ||
const onError = opts.onError || | ||
((error) => { | ||
// eslint-disable-next-line no-console | ||
console.error(`Exec has failed: ${error.message}`); | ||
// eslint-disable-next-line no-console | ||
console.debug(error.stack); | ||
// Do not hide errors by default | ||
throw error; | ||
const cmd = opts.command; | ||
const options = opts.options || { stdio: "inherit" }; | ||
const condition = opts.condition || (() => true); | ||
const afterExec = opts.afterExec || (() => void 0); | ||
const onError = opts.onError || ((error) => { | ||
console.error(`Exec has failed: ${error.message}`); | ||
console.debug(error.stack); | ||
throw error; | ||
}); | ||
return { | ||
name: "conditional-exec", | ||
buildStart() { | ||
if (!cmd) { | ||
const errReason = cmd === "" ? "empty string" : "undefined or null"; | ||
throw new Error( | ||
`rollup-plugin-conditional-exec requires a command to be used, received: ${errReason}` | ||
); | ||
} | ||
}, | ||
writeBundle: async (outputOptions) => { | ||
if (await condition(outputOptions)) { | ||
const cmdPromise = new Promise((resolve, reject) => { | ||
(0, import_child_process.exec)(cmd, options, (error) => { | ||
if (error) { | ||
return reject(error); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
return { | ||
name: "conditional-exec", | ||
buildStart() { | ||
if (!cmd) { | ||
const errReason = cmd === "" ? "empty string" : "undefined or null"; | ||
throw new Error(`rollup-plugin-conditional-exec requires a command to be used, received: ${errReason}`); | ||
} | ||
}, | ||
writeBundle: (outputOptions) => __awaiter(this, void 0, void 0, function* () { | ||
if (yield condition(outputOptions)) { | ||
const cmdPromise = new Promise((resolve, reject) => { | ||
(0, child_process_1.exec)(cmd, options, (error) => { | ||
if (error) { | ||
return reject(error); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
try { | ||
yield cmdPromise; | ||
yield afterExec(); | ||
} | ||
catch (error) { | ||
if (error instanceof Error) { | ||
yield onError(error); | ||
} | ||
} | ||
} | ||
}), | ||
}; | ||
try { | ||
await cmdPromise; | ||
await afterExec(); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
await onError(error); | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
exports.default = conditionalExec; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = {}); |
@@ -1,55 +0,47 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
// src/index.ts | ||
import { exec } from "child_process"; | ||
export default function conditionalExec(opts) { | ||
const cmd = opts.command; | ||
const options = opts.options || { stdio: "inherit" }; | ||
const condition = opts.condition || (() => true); | ||
const afterExec = opts.afterExec || (() => undefined); | ||
const onError = opts.onError || | ||
((error) => { | ||
// eslint-disable-next-line no-console | ||
console.error(`Exec has failed: ${error.message}`); | ||
// eslint-disable-next-line no-console | ||
console.debug(error.stack); | ||
// Do not hide errors by default | ||
throw error; | ||
function conditionalExec(opts) { | ||
const cmd = opts.command; | ||
const options = opts.options || { stdio: "inherit" }; | ||
const condition = opts.condition || (() => true); | ||
const afterExec = opts.afterExec || (() => void 0); | ||
const onError = opts.onError || ((error) => { | ||
console.error(`Exec has failed: ${error.message}`); | ||
console.debug(error.stack); | ||
throw error; | ||
}); | ||
return { | ||
name: "conditional-exec", | ||
buildStart() { | ||
if (!cmd) { | ||
const errReason = cmd === "" ? "empty string" : "undefined or null"; | ||
throw new Error( | ||
`rollup-plugin-conditional-exec requires a command to be used, received: ${errReason}` | ||
); | ||
} | ||
}, | ||
writeBundle: async (outputOptions) => { | ||
if (await condition(outputOptions)) { | ||
const cmdPromise = new Promise((resolve, reject) => { | ||
exec(cmd, options, (error) => { | ||
if (error) { | ||
return reject(error); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
return { | ||
name: "conditional-exec", | ||
buildStart() { | ||
if (!cmd) { | ||
const errReason = cmd === "" ? "empty string" : "undefined or null"; | ||
throw new Error(`rollup-plugin-conditional-exec requires a command to be used, received: ${errReason}`); | ||
} | ||
}, | ||
writeBundle: (outputOptions) => __awaiter(this, void 0, void 0, function* () { | ||
if (yield condition(outputOptions)) { | ||
const cmdPromise = new Promise((resolve, reject) => { | ||
exec(cmd, options, (error) => { | ||
if (error) { | ||
return reject(error); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
try { | ||
yield cmdPromise; | ||
yield afterExec(); | ||
} | ||
catch (error) { | ||
if (error instanceof Error) { | ||
yield onError(error); | ||
} | ||
} | ||
} | ||
}), | ||
}; | ||
try { | ||
await cmdPromise; | ||
await afterExec(); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
await onError(error); | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
export { | ||
conditionalExec as default | ||
}; |
{ | ||
"name": "rollup-plugin-conditional-exec", | ||
"version": "2.0.4", | ||
"version": "2.1.0", | ||
"author": "Alex Miller <codex.nz@gmail.com>", | ||
@@ -24,12 +24,12 @@ "description": "Execute a given command after a bundle has been written", | ||
"module": "dist/esm/index.js", | ||
"types": "dist/cjs/index.d.ts", | ||
"types": "dist/types/index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": { | ||
"types": "./dist/esm/index.d.ts", | ||
"default": "./dist/esm/index.js" | ||
"default": "./dist/esm/index.js", | ||
"types": "./dist/types/index.d.ts" | ||
}, | ||
"require": { | ||
"types": "./dist/cjs/index.d.ts", | ||
"default": "./dist/cjs/index.js" | ||
"default": "./dist/cjs/index.js", | ||
"types": "./dist/types/index.d.ts" | ||
} | ||
@@ -39,3 +39,6 @@ } | ||
"scripts": { | ||
"build": "tsc -p tsconfig.cjs.json & tsc -p tsconfig.esm.json", | ||
"build": "npm run build:types && npm run build:bundles", | ||
"build:bundles": "node ./esbuild.config.mjs", | ||
"build:types": "tsc -p tsconfig.build.json", | ||
"check:types": "tsc -p tsconfig.json", | ||
"format:check": "prettier --check \"{**/*,*}.{js,ts}\"", | ||
@@ -54,18 +57,20 @@ "format:write": "npm run format:check -- --write", | ||
"devDependencies": { | ||
"@types/jest": "^27.5.1", | ||
"@types/node": "^17.0.38", | ||
"@typescript-eslint/eslint-plugin": "^5.27.0", | ||
"@typescript-eslint/parser": "^5.27.0", | ||
"eslint": "^8.16.0", | ||
"@types/jest": "^28.1.6", | ||
"@types/node": "^18.6.3", | ||
"@typescript-eslint/eslint-plugin": "^5.31.0", | ||
"@typescript-eslint/parser": "^5.31.0", | ||
"chalk": "^5.0.1", | ||
"esbuild": "^0.14.51", | ||
"eslint": "^8.20.0", | ||
"eslint-config-airbnb-typescript": "^17.0.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"jest": "^28.1.0", | ||
"prettier": "^2.6.2", | ||
"release-it": "^15.0.0", | ||
"ts-jest": "^28.0.3", | ||
"ts-node": "^10.8.0", | ||
"typescript": "^4.7.2" | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"jest": "^28.1.3", | ||
"prettier": "^2.7.1", | ||
"release-it": "^15.2.0", | ||
"ts-jest": "^28.0.7", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.7.4" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
14124
17
6
143
3