Commit 07a31da
authored
fix: Use pirates for proper load extensions install/uninstall handling (#219)
This fixes a probably rare problem with a
recursive loop in `restoreExtensions`, when `ts` extension installed by
one `rewire` instance (and not yet restored) is saved to
`originalExtensions.ts` by another one, leading to recursion in
`registerExtensions -> tsExtension -> restoreExtensions` and eventual
`RangeError: Maximum call stack size exceeded` error.
Fixes #97
The problem can be easily reproduced if ts-node is omitted to run tests,
for example.
```
> mocha
....
65 passing (277ms)
1 failing
1) rewire
should work with TypeScript:
RangeError: Maximum call stack size exceeded
at Object.tsExtension [as ts] (lib/moduleEnv.js:136:21)
at Object.tsExtension [as ts] (lib/moduleEnv.js:159:24)
at Object.tsExtension [as ts] (lib/moduleEnv.js:159:24)
...
... few more thousand of the same text
...
at Object.tsExtension [as .ts] (lib/moduleEnv.js:159:24)
at Module.load (node:internal/modules/cjs/loader:1203:32)
at Object.load (lib/moduleEnv.js:54:18)
at internalRewire (lib/rewire.js:49:15)
at rewire (lib/index.js:11:12)
at Context.<anonymous> (test/rewire.test.js:23:20)
at process.processImmediate (node:internal/timers:476:21)
```
It also happens if you use `require(esm)` in some cases, though it is
way harder to reproduce it reliably.
With this patch it never happens :) ("should work with TypeScript" will
still fail w/o ts-node, yet it will be way more trivial reason :) )
Also, this is a groundwork to make rewire ESM-compatible (thanks to
require(esm), esbuild, and some AST magic).
Though, esm-compatibility is a subject for another PR and probably a
major version bump. Anyway, it is not yet ready to be shared, so i'll
get back to you with esm support ready to merge abit later, i hope :")3 files changed
+31
-80
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | 3 | | |
| 4 | + | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
10 | | - | |
11 | 9 | | |
12 | 10 | | |
13 | 11 | | |
| |||
50 | 48 | | |
51 | 49 | | |
52 | 50 | | |
53 | | - | |
| 51 | + | |
| 52 | + | |
54 | 53 | | |
55 | 54 | | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | 82 | | |
106 | 83 | | |
107 | 84 | | |
108 | 85 | | |
109 | | - | |
110 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
111 | 90 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
157 | 96 | | |
158 | | - | |
159 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
160 | 100 | | |
161 | 101 | | |
162 | 102 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
0 commit comments