Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
charliegerard committed May 29, 2024
1 parent f83a463 commit c1e86ee
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
18 changes: 17 additions & 1 deletion lib/shadow/pnpm-cli.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'use strict'
const { spawn } = require('child_process')
const { realpathSync } = require('fs')
const fs = require('fs')
const path = require('path')

const realFilename = realpathSync(__filename)
Expand All @@ -14,9 +15,24 @@ 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')
console.log(process.execPath)
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) {
Expand Down
35 changes: 23 additions & 12 deletions lib/shadow/pnpm-injection.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@
// THIS MUST BE CJS TO WORK WITH --require
'use strict'

const path = require('path')
// 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
// 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) {

}
}

// console.log('HERE: ', process.argv[1])
const dryRun = Boolean(process.env.SOCKET_PNPM_WRAPPER)

require.cache[process.argv[1]] = { exports: {} }
module.exports = {
pnpmInjection,
dryRun
}

0 comments on commit c1e86ee

Please sign in to comment.