-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpnpmfile.cjs
More file actions
22 lines (18 loc) · 837 Bytes
/
pnpmfile.cjs
File metadata and controls
22 lines (18 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const path = require('node:path')
const { pathToFileURL } = require('node:url');
module.exports = {
hooks: {
updateConfig: (config) => {
// Resolve paths and convert to proper file URLs
const loaderPath = path.resolve(__dirname, 'esm_loader.mjs')
const loaderUrl = pathToFileURL(loaderPath).href
const baseUrl = pathToFileURL(path.resolve('./')).href
// Build the registration code
const registrationCode = `import{register}from'node:module';register('${loaderUrl}','${baseUrl}');`
// Create NODE_OPTIONS with properly encoded data URL
const importFlag = `--import=data:text/javascript,${encodeURIComponent(registrationCode)}`
config.extraEnv.NODE_OPTIONS = `${process.env.NODE_OPTIONS ? `${process.env.NODE_OPTIONS} ` : ''}${importFlag}`
return config
},
},
}