Skip to content
This repository was archived by the owner on Jul 28, 2021. It is now read-only.

Commit 09a157f

Browse files
committed
feat(cli): got a baseline CLI working again
1 parent 195b75c commit 09a157f

File tree

6 files changed

+177
-110
lines changed

6 files changed

+177
-110
lines changed

index.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,42 @@
22

33
require('./lib/node/index.js')
44

5+
const cp = require('child_process')
56
const fs = require('fs')
67
const npmlog = require('npmlog')
78
const path = require('path')
89
const util = require('util')
10+
const yargs = require('yargs')
911

1012
const readFileAsync = util.promisify(fs.readFile)
1113

1214
if (require.main === module) {
1315
main()
1416
}
1517
module.exports = main
16-
async function main () {
17-
const startTime = Date.now()
18+
function main () {
1819
npmlog.heading = 'frog'
19-
let pkgMap = await checkPkgMap()
20+
let pkgMap = checkPkgMap()
2021
if (!pkgMap) {
21-
const config = await require('./lib/config.js').fromNpm(process.argv)
22-
npmlog.level = config.loglevel
23-
pkgMap = (await require('./lib/installer.js')(config.concat({
24-
log (level, ...args) { return npmlog[level](...args) }
25-
}))).pkgMap
22+
cp.spawnSync(process.argv[0], [
23+
require.resolve('./lib/worker.js'), ...process.argv.slice(2)
24+
], {
25+
stdio: 'inherit'
26+
})
2627
}
27-
npmlog.info('package-map', 'package map loaded in', `${(Date.now() - startTime) / 1000}s`)
28-
npmlog.notice('exec', 'executing `main` using frogged dependencies (TODO)')
29-
npmlog.notice('exec', 'dep lockfile integrity:', pkgMap.lockfile_integrity)
28+
const nodeArgs = [...([].concat(yargs.argv.nodeArg || [])), ...yargs.argv._]
29+
cp.spawnSync(
30+
process.argv[0],
31+
['-r', require.resolve('./lib/node'), ...nodeArgs],
32+
{stdio: 'inherit'}
33+
)
3034
}
3135

32-
async function checkPkgMap () {
36+
function checkPkgMap () {
3337
try {
3438
const base = process.cwd()
35-
const lock = JSON.parse(stripBOM(await readFileAsync(path.join(base, 'package-lock.json'), 'utf8')))
36-
const map = JSON.parse(stripBOM(await readFileAsync(path.join(base, 'node_modules', '.package-map.json'), 'utf8')))
39+
const lock = JSON.parse(stripBOM(readFileAsync(path.join(base, 'package-lock.json'), 'utf8')))
40+
const map = JSON.parse(stripBOM(readFileAsync(path.join(base, 'node_modules', '.package-map.json'), 'utf8')))
3741
require('ssri').checkData(
3842
JSON.stringify(lock), map.lockfile_integrity, {error: true}
3943
)

lib/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async function getNpmConfig (argv) {
3939
})
4040
}
4141

42-
return await new Promise((resolve, reject) => {
42+
return new Promise((resolve, reject) => {
4343
child.on('error', reject)
4444
child.on('close', (code) => {
4545
if (code === 127) {

lib/installer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ const writeFileAsync = BB.promisify(fs.writeFile)
2626
class Installer {
2727
constructor (opts) {
2828
this.opts = config(opts)
29+
this.opts = this.opts.concat({
30+
cache: path.join(this.opts.cache, '_cacache')
31+
})
2932

3033
// Stats
3134
this.startTime = Date.now()
@@ -314,6 +317,7 @@ class Installer {
314317
const lockStr = JSON.stringify(this.pkg._shrinkwrap)
315318
const lockHash = ssri.fromData(lockStr, {algorithms: ['sha256']})
316319
const pkgMap = {
320+
'cache': this.opts.cache,
317321
'lockfile_integrity': lockHash.toString(),
318322
'path_prefix': '/node_modules'
319323
}

lib/worker.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
'use strict'
22

3+
require('./node/index.js')
4+
35
const npmlog = require('npmlog')
46

57
main()
68
async function main () {
79
npmlog.heading = 'frog'
810

9-
const config = await require('../lib/config.js').fromNpm(process.argv)
11+
const config = await require('./config.js').fromNpm(process.argv)
1012
npmlog.level = config.loglevel
11-
const pkgMap = await require('../index.js')(config.concat({
13+
await require('./installer.js')(config.concat({
1214
log (level, ...args) { return npmlog[level](...args) }
1315
}))
14-
console.log(JSON.stringify({
15-
pkgMap,
16-
cache: config.cache
17-
}))
1816
}

0 commit comments

Comments
 (0)