isolated-function 0.1.16 → 0.1.18

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.16",
5
+ "version": "0.1.18",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js"
@@ -58,7 +58,7 @@
58
58
  "standard-version": "latest"
59
59
  },
60
60
  "engines": {
61
- "node": ">= 18"
61
+ "node": ">= 20"
62
62
  },
63
63
  "files": [
64
64
  "src"
@@ -0,0 +1,26 @@
1
+ 'use strict'
2
+
3
+ const esbuild = require('esbuild')
4
+
5
+ const MINIFY = (() => {
6
+ return process.env.ISOLATED_FUNCTIONS_MINIFY !== 'false'
7
+ ? {}
8
+ : {
9
+ minifyWhitespace: true,
10
+ minifyIdentifiers: false,
11
+ minifySyntax: true
12
+ }
13
+ })()
14
+
15
+ module.exports = ({ content, cwd }) =>
16
+ esbuild.build({
17
+ stdin: {
18
+ contents: content,
19
+ resolveDir: cwd,
20
+ sourcefile: 'index.js'
21
+ },
22
+ bundle: true,
23
+ ...MINIFY,
24
+ write: false,
25
+ platform: 'node'
26
+ })
@@ -1,34 +1,14 @@
1
1
  'use strict'
2
2
 
3
- const { execSync } = require('child_process')
4
- const esbuild = require('esbuild')
5
3
  const fs = require('fs/promises')
6
- const $ = require('tinyspawn')
7
4
  const path = require('path')
8
5
 
9
6
  const transformDependencies = require('./transform-dependencies')
10
7
  const detectDependencies = require('./detect-dependencies')
8
+ const installDependencies = require('./install-dependencies')
11
9
  const generateTemplate = require('../template')
12
10
  const { duration } = require('../debug')
13
-
14
- const MINIFY = (() => {
15
- return process.env.ISOLATED_FUNCTIONS_MINIFY !== 'false'
16
- ? {}
17
- : {
18
- minifyWhitespace: true,
19
- minifyIdentifiers: false,
20
- minifySyntax: true
21
- }
22
- })()
23
-
24
- const install = (() => {
25
- try {
26
- execSync('which pnpm').toString().trim()
27
- return 'pnpm install'
28
- } catch {
29
- return 'npm install'
30
- }
31
- })()
11
+ const build = require('./build')
32
12
 
33
13
  const tmpdirDefault = async () => {
34
14
  const cwd = await fs.mkdtemp(path.join(require('os').tmpdir(), 'compile-'))
@@ -43,25 +23,8 @@ module.exports = async (snippet, tmpdir = tmpdirDefault) => {
43
23
 
44
24
  const content = transformDependencies(compiledTemplate)
45
25
  const tmpDir = await duration('tmpdir', tmpdir)
46
-
47
- await duration('npm:init', () => fs.writeFile(path.join(tmpDir.cwd, 'package.json'), '{}'))
48
- await duration('npm:install', () =>
49
- $(`${install} ${dependencies.join(' ')}`, { cwd: tmpDir.cwd })
50
- )
51
-
52
- const result = await duration('esbuild', () =>
53
- esbuild.build({
54
- stdin: {
55
- contents: content,
56
- resolveDir: tmpDir.cwd,
57
- sourcefile: 'index.js'
58
- },
59
- bundle: true,
60
- ...MINIFY,
61
- write: false,
62
- platform: 'node'
63
- })
64
- )
26
+ await duration('npm:install', () => installDependencies({ dependencies, cwd: tmpDir.cwd }))
27
+ const result = await duration('esbuild', () => build({ content, cwd: tmpDir.cwd }))
65
28
 
66
29
  return {
67
30
  content: result.outputFiles[0].text,
@@ -0,0 +1,20 @@
1
+ 'use strict'
2
+
3
+ const { execSync } = require('child_process')
4
+ const { writeFile } = require('fs/promises')
5
+ const $ = require('tinyspawn')
6
+ const path = require('path')
7
+
8
+ const install = (() => {
9
+ try {
10
+ execSync('which pnpm').toString().trim()
11
+ return 'pnpm install'
12
+ } catch {
13
+ return 'npm install'
14
+ }
15
+ })()
16
+
17
+ module.exports = async ({ dependencies, cwd }) => {
18
+ await writeFile(path.join(cwd, 'package.json'), '{}')
19
+ return $(`${install} ${dependencies.join(' ')}`, { cwd })
20
+ }