|
1 | 1 | // initializing global here for unsafe builtin usage at import time |
2 | 2 | global.unsafeBuiltinUsage = [] |
3 | 3 |
|
4 | | -function createProxyHandler(prefix) { |
| 4 | +function createProxyHandler(prefix, options) { |
5 | 5 | return { |
6 | 6 | get: function (target, key) { |
7 | 7 | const value = target[key] |
| 8 | + const path = key && key.toString ? `${prefix}.${key.toString()}` : prefix |
| 9 | + |
| 10 | + if (options.ignore.includes(path)) { |
| 11 | + return value |
| 12 | + } |
| 13 | + |
8 | 14 | if (typeof value === `function`) { |
9 | 15 | return function wrapper(...args) { |
10 | 16 | const myErrorHolder = { |
11 | | - name: `Unsafe builtin usage ${prefix}.${key}`, |
| 17 | + name: `Unsafe builtin usage ${path}`, |
12 | 18 | } |
13 | 19 | Error.captureStackTrace(myErrorHolder, wrapper) |
14 | 20 |
|
15 | | - // loadPageDataSync already is tracked with dedicated warning messages, |
| 21 | + // - loadPageDataSync already is tracked with dedicated warning messages, |
16 | 22 | // so skipping marking it to avoid multiple messages for same usage |
17 | | - if (!myErrorHolder.stack.includes(`loadPageDataSync`)) { |
| 23 | + // - node-gyp-build will use fs.readDirSync in attempt to load binaries |
| 24 | + // this should be ok to ignore. |
| 25 | + if ( |
| 26 | + !myErrorHolder.stack.includes(`loadPageDataSync`) && |
| 27 | + !myErrorHolder.stack.includes(`node-gyp-build`) |
| 28 | + ) { |
18 | 29 | global.unsafeBuiltinUsage.push(myErrorHolder.stack) |
19 | 30 | } |
20 | 31 |
|
21 | 32 | return value.apply(target, args) |
22 | 33 | } |
23 | 34 | } else if (typeof value === `object` && value !== null) { |
24 | | - return new Proxy( |
25 | | - value, |
26 | | - createProxyHandler( |
27 | | - key && key.toString ? `${prefix}.${key.toString()}` : prefix |
28 | | - ) |
29 | | - ) |
| 35 | + return new Proxy(value, createProxyHandler(path, options)) |
30 | 36 | } |
31 | 37 |
|
32 | 38 | return value |
33 | 39 | }, |
34 | 40 | } |
35 | 41 | } |
36 | 42 |
|
37 | | -function wrapModuleWithTracking(moduleName) { |
| 43 | +function wrapModuleWithTracking(moduleName, options = {}) { |
| 44 | + if (!options.ignore) { |
| 45 | + options.ignore = [] |
| 46 | + } |
| 47 | + |
38 | 48 | const mod = require(moduleName) |
39 | | - return new Proxy(mod, createProxyHandler(moduleName)) |
| 49 | + return new Proxy(mod, createProxyHandler(moduleName, options)) |
40 | 50 | } |
41 | 51 |
|
42 | 52 | exports.wrapModuleWithTracking = wrapModuleWithTracking |
0 commit comments