isolated-function 0.1.18 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "isolated-function",
3
3
  "description": "Runs untrusted code in a Node.js v8 sandbox.",
4
4
  "homepage": "https://github.com/Kikobeats/isolated-function",
5
- "version": "0.1.18",
5
+ "version": "0.1.19",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js"
@@ -5,6 +5,61 @@ const acorn = require('acorn')
5
5
 
6
6
  const parseDependency = require('./parse-dependency')
7
7
 
8
+ // List of built-in Node.js modules
9
+ // https://github.com/sindresorhus/builtin-modules/blob/main/builtin-modules.json
10
+ const builtins = [
11
+ 'crypto',
12
+ 'dgram',
13
+ 'diagnostics_channel',
14
+ 'dns',
15
+ 'dns/promises',
16
+ 'domain',
17
+ 'events',
18
+ 'fs',
19
+ 'fs/promises',
20
+ 'http',
21
+ 'http2',
22
+ 'https',
23
+ 'inspector',
24
+ 'inspector/promises',
25
+ 'module',
26
+ 'net',
27
+ 'os',
28
+ 'path',
29
+ 'path/posix',
30
+ 'path/win32',
31
+ 'perf_hooks',
32
+ 'process',
33
+ 'punycode',
34
+ 'querystring',
35
+ 'readline',
36
+ 'readline/promises',
37
+ 'repl',
38
+ 'stream',
39
+ 'stream/consumers',
40
+ 'stream/promises',
41
+ 'stream/web',
42
+ 'string_decoder',
43
+ 'timers',
44
+ 'timers/promises',
45
+ 'tls',
46
+ 'trace_events',
47
+ 'tty',
48
+ 'url',
49
+ 'util',
50
+ 'util/types',
51
+ 'v8',
52
+ 'vm',
53
+ 'wasi',
54
+ 'worker_threads',
55
+ 'zlib'
56
+ ]
57
+
58
+ const isBuiltinModule = moduleName => {
59
+ if (moduleName.startsWith('node:')) moduleName = moduleName.slice('node:'.length)
60
+ return builtins.includes(moduleName)
61
+ }
62
+
8
63
  module.exports = code => {
9
64
  const dependencies = new Set()
10
65
 
@@ -20,12 +75,12 @@ module.exports = code => {
20
75
  node.arguments[0].type === 'Literal'
21
76
  ) {
22
77
  const dependency = node.arguments[0].value
23
- dependencies.add(parseDependency(dependency))
78
+ if (!isBuiltinModule(dependency)) dependencies.add(parseDependency(dependency))
24
79
  }
25
80
  },
26
81
  ImportDeclaration (node) {
27
82
  const source = node.source.value
28
- dependencies.add(parseDependency(source))
83
+ if (!isBuiltinModule(source)) dependencies.add(parseDependency(source))
29
84
  }
30
85
  })
31
86