isolated-function 0.1.21 → 0.1.23

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.21",
5
+ "version": "0.1.23",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js"
@@ -76,6 +76,9 @@
76
76
  "test": "c8 ava"
77
77
  },
78
78
  "license": "MIT",
79
+ "ava": {
80
+ "workerThreads": false
81
+ },
79
82
  "commitlint": {
80
83
  "extends": [
81
84
  "@commitlint/config-conventional"
@@ -20,16 +20,20 @@ const tmpdirDefault = async () => {
20
20
  module.exports = async (snippet, tmpdir = tmpdirDefault) => {
21
21
  const compiledTemplate = generateTemplate(snippet)
22
22
  const dependencies = detectDependencies(compiledTemplate)
23
+ let content = transformDependencies(compiledTemplate)
24
+ let cleanupPromise
23
25
 
24
- const content = transformDependencies(compiledTemplate)
25
- const tmpDir = await duration('tmpdir', tmpdir)
26
- await duration('npm:install', () => installDependencies({ dependencies, cwd: tmpDir.cwd }))
27
- const result = await duration('esbuild', () => build({ content, cwd: tmpDir.cwd }))
28
-
29
- return {
30
- content: result.outputFiles[0].text,
31
- cleanupPromise: duration('tmpDir:cleanup', tmpDir.cleanup)
26
+ if (dependencies.length) {
27
+ const { cwd, cleanup } = await duration('tmpdir', tmpdir)
28
+ await duration('npm:install', () => installDependencies({ dependencies, cwd }), {
29
+ dependencies
30
+ })
31
+ const result = await duration('esbuild', () => build({ content, cwd }))
32
+ content = result.outputFiles[0].text
33
+ cleanupPromise = duration('tmpDir:cleanup', cleanup)
32
34
  }
35
+
36
+ return { content, cleanupPromise }
33
37
  }
34
38
 
35
39
  module.exports.detectDependencies = detectDependencies
package/src/debug.js CHANGED
@@ -2,16 +2,16 @@
2
2
 
3
3
  const debug = require('debug-logfmt')('isolated-function')
4
4
 
5
- const duration = async (name, fn) => {
5
+ const duration = async (name, fn, props) => {
6
6
  const duration = debug.duration(name)
7
7
 
8
8
  return Promise.resolve(fn())
9
9
  .then(result => {
10
- duration()
10
+ props ? duration(props) : duration()
11
11
  return result
12
12
  })
13
13
  .catch(error => {
14
- duration.error()
14
+ props ? duration.error(props) : duration.duration.error()
15
15
  throw error
16
16
  })
17
17
  }