isolated-function 0.1.18 → 0.1.20

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.20",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js"
@@ -20,7 +20,9 @@ module.exports = ({ content, cwd }) =>
20
20
  sourcefile: 'index.js'
21
21
  },
22
22
  bundle: true,
23
- ...MINIFY,
24
23
  write: false,
25
- platform: 'node'
24
+ platform: 'node',
25
+ legalComments: 'eof',
26
+ target: 'es2023',
27
+ ...MINIFY
26
28
  })
@@ -5,11 +5,66 @@ 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
 
11
66
  // Parse the code into an AST
12
- const ast = acorn.parse(code, { ecmaVersion: 2020, sourceType: 'module' })
67
+ const ast = acorn.parse(code, { ecmaVersion: 2023, sourceType: 'module' })
13
68
 
14
69
  // Traverse the AST to find require and import statements
15
70
  walk.simple(ast, {
@@ -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
 
@@ -4,7 +4,7 @@ const walk = require('acorn-walk')
4
4
  const acorn = require('acorn')
5
5
 
6
6
  module.exports = code => {
7
- const ast = acorn.parse(code, { ecmaVersion: 2020, sourceType: 'module' })
7
+ const ast = acorn.parse(code, { ecmaVersion: 2023, sourceType: 'module' })
8
8
 
9
9
  let newCode = ''
10
10
  let lastIndex = 0