UNPKG

tsds-publish

Version:

Development stack for TypeScript libraries

27 lines (26 loc) 984 B
import Module from 'module'; import { bind } from 'node-version-call'; import path from 'path'; import url from 'url'; const major = +process.versions.node.split('.')[0]; const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require; const __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename); const dist = path.join(__dirname, '..', '..'); function run(options, callback) { const cwd = options.cwd || process.cwd(); const { needsPublish } = _require('npm-needs-publish'); needsPublish({ cwd }).then((result)=>{ callback(undefined, { changed: result.needsPublish, reason: result.reason }); }).catch(callback); } const worker = major >= 20 ? run : bind('>=20', path.join(dist, 'cjs', 'lib', 'hasChanged.js'), { callbacks: true }); export default function hasChanged(options, callback) { worker(options, callback); }