Skip to content

Commit 4c4dc29

Browse files
committed
Allow use of ts-node-dev in pnp yarn berry
1 parent c0df64c commit 4c4dc29

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

lib/child-require-hook.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var getCompiledPath = require('./get-compiled-path')
33
var sep = require('path').sep
44
var join = require('path').join
55
var execSync = require('child_process').execSync
6+
var Module = require("module")
67
var compilationId
78
var timeThreshold = 0
89
var allowJs = false
@@ -97,7 +98,9 @@ function registerJsExtension() {
9798
}
9899
}
99100

100-
require(sourceMapSupportPath).install({
101+
var sourceMapRequire = Module.createRequire ? Module.createRequire(sourceMapSupportPath) : require
102+
103+
sourceMapRequire(sourceMapSupportPath).install({
101104
hookRequire: true
102105
})
103106

lib/resolveMain.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
1-
var resolve = require('resolve').sync;
1+
var resolve = require('resolve');
22

3-
module.exports = function (main) {
4-
var resolved
5-
var opts = {
6-
basedir: process.cwd(),
7-
paths: [process.cwd()]
3+
function resolveRequest(req) {
4+
// The `resolve` package is prebuilt through ncc, which prevents
5+
// PnP from being able to inject itself into it. To circumvent
6+
// this, we simply use PnP directly when available.
7+
// @ts-ignore
8+
if (process.versions.pnp) {
9+
const { resolveRequest } = require(`pnpapi`)
10+
return resolveRequest(req, process.cwd() +"/")
11+
} else {
12+
13+
var opts = {
14+
basedir: process.cwd(),
15+
paths: [process.cwd()]
16+
};
17+
return resolve.sync(req, opts)
818
}
19+
}
20+
21+
module.exports = function (main) {
922
try {
10-
return resolve(main + '.ts', opts);
23+
return resolveRequest(main + '.ts');
1124
} catch (e) {
1225
try {
13-
return resolve(main + '/index.ts', opts);
26+
return resolveRequest(main + '/index.ts');
1427
} catch (e) {
15-
return resolve(main, opts);
28+
return resolveRequest(main);
1629
}
1730
}
1831
};

0 commit comments

Comments
 (0)