Skip to content

Commit

Permalink
feat(core): makePathWrapper with a native executable
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz committed Sep 19, 2020
1 parent 511d440 commit cccad39
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 9 additions & 0 deletions packages/yarnpkg-core/sources/binjumper.ts

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions packages/yarnpkg-core/sources/scriptUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {ReportError, Report} from './Report';
import {StreamReport} from './StreamReport';
import {Workspace} from './Workspace';
import {YarnVersion} from './YarnVersion';
import {binjumper} from './binjumper';
import * as execUtils from './execUtils';
import * as formatUtils from './formatUtils';
import * as miscUtils from './miscUtils';
Expand All @@ -29,8 +30,13 @@ enum PackageManager {
}

async function makePathWrapper(location: PortablePath, name: Filename, argv0: NativePath, args: Array<string> = []) {
if (process.platform === `win32`)
await xfs.writeFilePromise(ppath.format({dir: location, name, ext: `.cmd`}), `@"${argv0}" ${args.map(arg => `"${arg.replace(`"`, `""`)}"`).join(` `)} %*\n`);
if (process.platform === `win32`) {
await Promise.all([
xfs.writeFilePromise(ppath.format({dir: location, name, ext: `.exe`}), binjumper()),
xfs.writeFilePromise(ppath.format({dir: location, name, ext: `.exe.info`}), [argv0, ...args].join(`\n`)),
xfs.writeFilePromise(ppath.format({dir: location, name, ext: `.cmd`}), `@"${argv0}" ${args.map(arg => `"${arg.replace(`"`, `""`)}"`).join(` `)} %*\n`),
]);
}

await xfs.writeFilePromise(ppath.join(location, name), `#!/bin/sh\nexec "${argv0}" ${args.map(arg => `'${arg.replace(/'/g, `'"'"'`)}'`).join(` `)} "$@"\n`);
await xfs.chmodPromise(ppath.join(location, name), 0o755);
Expand Down

0 comments on commit cccad39

Please sign in to comment.