UNPKG

es2049package

Version:

ECMAScript 2049 package: zero-configuration libraries and command-line utilies by Harald Rudell

39 lines (34 loc) 1.36 kB
/* © 2017-present Harald Rudell <harald.rudell@gmail.com> (http://www.haraldrudell.com) This source code is licensed under the ISC-style license found in the LICENSE file in the root directory of this source tree. */ import {spawn} from 'child_process' import {promises} from 'fs' const {lstat, readlink} = promises import {join} from 'path' getPackageDirectory(process.argv[1]).then( directory => execCommand(directory) ).catch(errorHandler) async function execCommand(rollupConfigProjectDir) { const realRollupExecutable = join(rollupConfigProjectDir, 'node_modules', '.bin', 'rollup') const args = process.argv.slice(2) const {status, signal} = await new Promise((resolve, reject) => spawn(realRollupExecutable, args, {stdio: 'inherit'}) .once('close', (st, si) => resolve({status: st, signal: si})) .on('error', reject) ) if (signal) throw new Error(`signal: ${signal} status: ${status} from ${realRollupExecutable}`) process.exit(status) } async function getPackageDirectory(executable) { while ((await lstat(executable)).isSymbolicLink()) { const target = await readlink(executable) executable = target.startsWith('.') ? join(executable, '..', target) : target } return join(executable, '..', '..') } function errorHandler(e) { console.error(e instanceof Error ? e.message : e) process.exit(1) }