Fixing issue with string templates importing vm2 which requires other prebuilts for JS in the CLI - no need for these to add to build size when JS is unused.
This commit is contained in:
parent
5c62bdac2e
commit
feda4e61c1
|
@ -0,0 +1 @@
|
||||||
|
process.env.NO_JS = "1"
|
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
require("./prebuilds")
|
require("./prebuilds")
|
||||||
|
require("./environment")
|
||||||
const { getCommands } = require("./options")
|
const { getCommands } = require("./options")
|
||||||
const { Command } = require("commander")
|
const { Command } = require("commander")
|
||||||
const { getHelpDescription } = require("./utils")
|
const { getHelpDescription } = require("./utils")
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
const os = require("os")
|
const os = require("os")
|
||||||
const { join } = require("path")
|
const { join } = require("path")
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
|
const { error } = require("./utils")
|
||||||
const PREBUILDS = "prebuilds"
|
const PREBUILDS = "prebuilds"
|
||||||
const ARCH = `${os.platform()}-${os.arch()}`
|
const ARCH = `${os.platform()}-${os.arch()}`
|
||||||
const PREBUILD_DIR = join(process.execPath, "..", PREBUILDS, ARCH)
|
const PREBUILD_DIR = join(process.execPath, "..", PREBUILDS, ARCH)
|
||||||
|
@ -25,7 +26,15 @@ function checkForBinaries() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup(evt) {
|
||||||
|
if (evt && evt.errno) {
|
||||||
|
console.error(
|
||||||
|
error(
|
||||||
|
"Failed to run CLI command - please report with the following message:"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
console.error(error(evt))
|
||||||
|
}
|
||||||
if (fs.existsSync(PREBUILD_DIR)) {
|
if (fs.existsSync(PREBUILD_DIR)) {
|
||||||
fs.rmSync(PREBUILD_DIR, { recursive: true })
|
fs.rmSync(PREBUILD_DIR, { recursive: true })
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,9 @@ const getContextValue = (path, context) => {
|
||||||
|
|
||||||
// Evaluates JS code against a certain context
|
// Evaluates JS code against a certain context
|
||||||
module.exports.processJS = (handlebars, context) => {
|
module.exports.processJS = (handlebars, context) => {
|
||||||
|
if (process && process.env.NO_JS) {
|
||||||
|
throw new Error("JS disabled in environment.")
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
// Wrap JS in a function and immediately invoke it.
|
// Wrap JS in a function and immediately invoke it.
|
||||||
// This is required to allow the final `return` statement to be valid.
|
// This is required to allow the final `return` statement to be valid.
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
const { VM } = require("vm2")
|
|
||||||
const templates = require("./index.js")
|
const templates = require("./index.js")
|
||||||
const { setJSRunner } = require("./helpers/javascript")
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CJS entrypoint for rollup
|
* CJS entrypoint for rollup
|
||||||
|
@ -21,6 +19,9 @@ module.exports.disableEscaping = templates.disableEscaping
|
||||||
module.exports.findHBSBlocks = templates.findHBSBlocks
|
module.exports.findHBSBlocks = templates.findHBSBlocks
|
||||||
module.exports.convertToJS = templates.convertToJS
|
module.exports.convertToJS = templates.convertToJS
|
||||||
|
|
||||||
|
if (!process.env.NO_JS) {
|
||||||
|
const { VM } = require("vm2")
|
||||||
|
const { setJSRunner } = require("./helpers/javascript")
|
||||||
/**
|
/**
|
||||||
* Use vm2 to run JS scripts in a node env
|
* Use vm2 to run JS scripts in a node env
|
||||||
*/
|
*/
|
||||||
|
@ -31,3 +32,4 @@ setJSRunner((js, context) => {
|
||||||
})
|
})
|
||||||
return vm.run(js)
|
return vm.run(js)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ export const disableEscaping = templates.disableEscaping
|
||||||
export const findHBSBlocks = templates.findHBSBlocks
|
export const findHBSBlocks = templates.findHBSBlocks
|
||||||
export const convertToJS = templates.convertToJS
|
export const convertToJS = templates.convertToJS
|
||||||
|
|
||||||
|
if (process && !process.env.NO_JS) {
|
||||||
/**
|
/**
|
||||||
* Use polyfilled vm to run JS scripts in a browser Env
|
* Use polyfilled vm to run JS scripts in a browser Env
|
||||||
*/
|
*/
|
||||||
|
@ -34,3 +35,4 @@ setJSRunner((js, context) => {
|
||||||
vm.createContext(context)
|
vm.createContext(context)
|
||||||
return vm.runInNewContext(js, context, { timeout: 1000 })
|
return vm.runInNewContext(js, context, { timeout: 1000 })
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue