|
1 | 1 | #!/usr/bin/env node |
2 | 2 |
|
3 | | -'use strict'; |
| 3 | +import npx from 'libnpx'; |
| 4 | +import getLockfile from 'npm-lockfile/getLockfile'; |
| 5 | +import finder from 'find-package-json'; |
| 6 | +import semver from 'semver'; |
| 7 | +import colors from 'colors/safe.js'; |
4 | 8 |
|
5 | | -const npx = require('libnpx'); |
6 | | -const getLockfile = require('npm-lockfile/getLockfile'); |
7 | | -const finder = require('find-package-json'); |
8 | | -const semver = require('semver'); |
9 | | -const colors = require('colors/safe'); |
| 9 | +import path from 'path'; |
| 10 | +import { existsSync } from 'fs'; |
| 11 | +import { copyFile, writeFile } from 'fs/promises'; |
| 12 | +import { execSync } from 'child_process'; |
10 | 13 |
|
11 | | -const path = require('path'); |
12 | | -const { existsSync } = require('fs'); |
13 | | -const { copyFile, writeFile } = require('fs').promises; |
14 | | -const { execSync } = require('child_process'); |
15 | | - |
16 | | -const getProjectTempDir = require('./getProjectTempDir'); |
| 14 | +import getProjectTempDir from './getProjectTempDir.js'; |
17 | 15 |
|
18 | 16 | const { filename: pkg } = finder(process.cwd()).next(); |
19 | 17 | const pkgDir = path.dirname(pkg); |
@@ -50,13 +48,14 @@ if (npmIsGood && (hasPkgLock || hasShrink || isFix)) { |
50 | 48 | Promise.all([ |
51 | 49 | getLockfile(pkg), |
52 | 50 | getProjectTempDir({ npmNeeded }), |
53 | | - ]).then(([lockfile, tmpDir]) => { |
| 51 | + ]).then(async ([lockfile, tmpDir]) => { |
54 | 52 | const lockfilePath = path.join(tmpDir, 'package-lock.json'); |
55 | 53 | const writtenLockfile = writeFile(lockfilePath, lockfile, encoding); |
56 | 54 | const writtenPkg = copyFile(pkg, path.join(tmpDir, 'package.json')); |
57 | 55 | const auditLevel = execSync(`npm config get audit-level --no-workspaces --prefix="${process.cwd()}"`, encoding).trim(); |
58 | 56 | const writtenRC = auditLevel && auditLevel !== 'undefined' ? writeFile(path.join(tmpDir, '.npmrc'), `audit-level=${auditLevel}`, encoding) : null; |
59 | | - return Promise.all([writtenLockfile, writtenPkg, writtenRC]).then(() => tmpDir); |
| 57 | + await Promise.all([writtenLockfile, writtenPkg, writtenRC]); |
| 58 | + return tmpDir; |
60 | 59 | }).then((tmpDir) => { |
61 | 60 | process.chdir(tmpDir); |
62 | 61 | process.env.PATH = `${path.join(tmpDir, '../node_modules/.bin')}:${process.env.PATH}`; |
|
0 commit comments