diff --git a/lib/commands/index.js b/lib/commands/index.js index aae0d337..931702ff 100644 --- a/lib/commands/index.js +++ b/lib/commands/index.js @@ -2,6 +2,7 @@ export * from './info/index.js' export * from './report/index.js' export * from './npm/index.js' export * from './npx/index.js' +export * from './pnpm/index.js' export * from './login/index.js' export * from './logout/index.js' export * from './wrapper/index.js' diff --git a/lib/commands/pnpm/index.js b/lib/commands/pnpm/index.js new file mode 100644 index 00000000..0b639060 --- /dev/null +++ b/lib/commands/pnpm/index.js @@ -0,0 +1,22 @@ +import { spawn } from 'child_process' +import { fileURLToPath } from 'url' + +const description = 'pnpm wrapper functionality' + +/** @type {import('../../utils/meow-with-subcommands').CliSubcommand} */ +export const pnpm = { + description, + run: async (argv, _importMeta, _ctx) => { + const wrapperPath = fileURLToPath(new URL('../../shadow/pnpm-cli.cjs', import.meta.url)) + process.exitCode = 1 + spawn(process.execPath, [wrapperPath, ...argv], { + stdio: 'inherit' + }).on('exit', (code, signal) => { + if (signal) { + process.kill(process.pid, signal) + } else if (code !== null) { + process.exit(code) + } + }) + } +} diff --git a/lib/shadow/pnpm-cli.cjs b/lib/shadow/pnpm-cli.cjs new file mode 100644 index 00000000..e92ad284 --- /dev/null +++ b/lib/shadow/pnpm-cli.cjs @@ -0,0 +1,45 @@ +#!/usr/bin/env node +// THIS FILE USES .cjs to get around the extension-free entrypoint problem with ESM +'use strict' +const { spawn } = require('child_process') +const { realpathSync } = require('fs') +const fs = require('fs') +const path = require('path') + +const realFilename = realpathSync(__filename) +const realDirname = path.dirname(realFilename) + +/** + */ +async function main () { + const pnpmpath = await require('./link.cjs')(path.join(realDirname, 'bin'), 'pnpm') + process.exitCode = 1 + const injectionpath = path.join(realDirname, 'pnpm-injection.cjs') + const pnpmModulePath = `${process.env.PNPM_HOME}/global/5/.pnpm/pnpm@9.1.0/node_modules/pnpm/dist/pnpm.cjs` + + // require.cache[process.argv[1]] = { exports: {} } + // require.cache[pnpmModulePath] = { get exports() {console.log(123)} } + // require('module').Module.runMain = () => {} + + // Read module file + // await fs.readFile(pnpmModulePath, 'utf-8' , (err, data) => { + // if (err) throw err; + // console.log(data); + // }); + + // Require the installed pnpm module + require(pnpmModulePath) + + // spawn(process.execPath, ['--require', injectionpath, pnpmpath, ...process.argv.slice(2)], { + // spawn(process.execPath, ['--require', injectionpath, pnpmModulePath, ...process.argv.slice(2)], { + // spawn(process.execPath, ['--require', pnpmModulePath, ...process.argv.slice(2)], { + // stdio: 'inherit' + // }).on('exit', (code, signal) => { + // if (signal) { + // process.kill(process.pid, signal) + // } else if (code !== null) { + // process.exit(code) + // } + // }) + } + main() \ No newline at end of file diff --git a/lib/shadow/pnpm-injection.cjs b/lib/shadow/pnpm-injection.cjs new file mode 100644 index 00000000..a14dde2e --- /dev/null +++ b/lib/shadow/pnpm-injection.cjs @@ -0,0 +1,31 @@ +/* eslint-disable no-console */ +// THIS MUST BE CJS TO WORK WITH --require +'use strict' + +// const path = require('path') + +// try { +// // due to update-notifier pkg being ESM only we actually spawn a subprocess sadly +// // require('child_process').spawnSync(process.execPath, [ +// // path.join(__dirname, 'update-notifier.mjs') +// // ], { +// // stdio: 'inherit' +// // }) +// } catch (e) { +// // ignore if update notification fails +// } + +// require.cache[process.argv[1]] = { exports: {} } + +const pnpmInjection = async (depGraph) => { + if (process.env.SOCKET_PNPM_WRAPPER) { + + } +} + +const dryRun = Boolean(process.env.SOCKET_PNPM_WRAPPER) + +module.exports = { + pnpmInjection, + dryRun +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ede12c72..bcdca39f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,12 @@ { "name": "@socketsecurity/cli", - "version": "0.9.0", + "version": "0.9.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@socketsecurity/cli", - "version": "0.9.0", - "hasInstallScript": true, + "version": "0.9.3", "license": "MIT", "dependencies": { "@apideck/better-ajv-errors": "^0.3.6",