Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip #113

Closed
wants to merge 2 commits into from
Closed

wip #113

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
22 changes: 22 additions & 0 deletions lib/commands/pnpm/index.js
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
45 changes: 45 additions & 0 deletions lib/shadow/pnpm-cli.cjs
Original file line number Diff line number Diff line change
@@ -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/[email protected]/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()
31 changes: 31 additions & 0 deletions lib/shadow/pnpm-injection.cjs
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading