Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

defiant-builder

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

defiant-builder - npm Package Compare versions

Comparing version 1.5.6 to 1.5.7

119

lib/index.js
const btoa = require("btoa")
const convert = require("xml-js")

@@ -7,7 +6,6 @@ const less = require("less")

const terser = require("terser")
const jsonminify = require("jsonminify")
const { FS } = require("./common")
const buildFileLimit = 1024 * 1024 * 5 // = 5 MB
const ant_require_rx = /defiant\.require\(['"](.+?)['"]\)/g
const ant_require_rx = /@import ['"](.+?)['"]$/mg

@@ -22,7 +20,7 @@

const buildTasks = async (appXmlDom, appPath, id, namespace, uglify) => {
const xApp = appXmlDom.Application
let xApp = appXmlDom.Application
if (!xApp.Build || !xApp.Build.task) return
let buildTasks = xApp.Build.task
if (buildTasks.constructor !== Array) buildTasks = [buildTasks]
if (buildTasks.letructor !== Array) buildTasks = [buildTasks]

@@ -71,4 +69,4 @@ // check if task is to be skipped

// terser.js
const options = { compress: true, module: true }
const parsed = terser.minify(code, options)
let options = { compress: true, module: true }
let parsed = terser.minify(code, options)

@@ -88,14 +86,19 @@ // create destination dir, if it doesnt exist

let namespace = getMetaValue(meta, "author", "namespace")
const filePath = FS.path.join(appPath, getMetaValue(meta, "script"))
const dirPath = FS.path.dirname(filePath)
let filePath = FS.path.join(appPath, getMetaValue(meta, "script"))
let fileData = await FS.readFile(filePath)
let dirPath = FS.path.dirname(filePath)
// reqursive file "ant_require"
const requireFile = async function(baseDir, reqStr, exclude) {
let reqPath = FS.path.join(baseDir, reqStr.slice(17,-2))
if (!await FS.fileExists(reqPath)) return
let requireFile = async function(baseDir, reqStr, exclude) {
let reqPath = FS.path.join(baseDir, reqStr.slice(9,-1))
if (await FS.fileExists(reqPath)) {
let reqFile = await FS.readFile(reqPath)
let rx = new RegExp(reqStr.replace(/(\(|\))/g, "\\$1"), "i")
code = code.replace(rx, reqFile)
} else {
// insert "throw error"
let rx = new RegExp(reqStr.replace(/(\(|\))/g, "\\$1"), "i")
code = code.replace(rx, `throw "File not found: ${reqStr.slice(9,-1)}";`)
}
let reqFile = await FS.readFile(reqPath)
let rx = new RegExp(reqStr.replace(/(\(|\))/g, "\\$1"), "i")
code = code.replace(rx, reqFile)
exclude = exclude || []

@@ -113,8 +116,22 @@ exclude.push(reqStr)

}
// loop all "@imports"
let code = fileData.toString()
let requires = code.match(ant_require_rx) || []
await Promise.all(requires.map(async item => requireFile(dirPath, item)))
// save temp input entry file
let input = filePath.slice(0, filePath.lastIndexOf("/") + 1) + Date.now() +".js"
await FS.writeFile(input, code)
// rollup.js
let bundle = await rollup.rollup({ input: filePath, treeshake: false })
let bundle = await rollup.rollup({ input, treeshake: false })
// delete temp input entry file
await FS.unlink(input)
let { output } = await bundle.generate({ format: "esm" })
// custom require-parser
let code = output[0].code
code = output[0].code
if (uglify) {

@@ -125,16 +142,9 @@ // remove development-only code

let requires = code.match(ant_require_rx) || []
// loop all requires
await Promise.all(requires.map(async item => requireFile(dirPath, item)))
// fix paths to app public folder
code = code.replace(/(['"])~\/(.+?)(['"])/g, `$1/app/${namespace}/${id}/$2$3`)
// code = code.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '$1');
// code = code.replace(/\t/g, "")
// code = code.replace(/\n\n/gm, "")
if (uglify) {
// terser.js
const options = { compress: false, module: false, mangle: uglify }
const parsed = terser.minify(code, options)
let options = { compress: false, module: false, mangle: uglify }
let parsed = terser.minify(code, options)
return parsed.code

@@ -232,3 +242,3 @@ }

const importFile = async (baseDir, importStr, exclude) => {
let importFile = async (baseDir, importStr, exclude) => {
let importPath = FS.path.join(baseDir, importStr.slice(9,-1))

@@ -330,10 +340,10 @@ if (!await FS.fileExists(importPath)) return

const appJson = convert.xml2json(appXml, { compact: true })
const appXmlDom = JSON.parse(appJson)
const meta = appXmlDom.Application.Head.meta
const appId = getMetaValue(meta, "id")
const name = getMetaValue(meta, "title")
const version = getMetaValue(meta, "title", "version")
const buildInclude = (getMetaValue(meta, "build", "include") || "").split(",")
const namespace = getMetaValue(meta, "author", "namespace")
let appJson = convert.xml2json(appXml, { compact: true })
let appXmlDom = JSON.parse(appJson)
let meta = appXmlDom.Application.Head.meta
let appId = getMetaValue(meta, "id")
let name = getMetaValue(meta, "title")
let version = getMetaValue(meta, "title", "version")
let buildInclude = (getMetaValue(meta, "build", "include") || "").split(",")
let namespace = getMetaValue(meta, "author", "namespace")

@@ -391,2 +401,3 @@ // perform build tasks - if any

}
// copy license to public

@@ -406,2 +417,36 @@ let srcLicense = FS.path.join(srcDir, "LICENSE")

// compress files
let JSZip = require("jszip")()
await Promise.all(files.map(async entry => {
let filePath = FS.path.join(destDir, entry)
let fileData = await FS.readFile(filePath)
return JSZip.file(entry, fileData)
}))
// generate zip file
let buffer = await JSZip.generateAsync({
type: "nodebuffer",
compression: "DEFLATE",
compressionOptions: { level: 9 },
mimetype: "application/defiant-x",
})
// write to disk
let zipDest = FS.path.join(destDir, appId +".app")
await FS.writeFile(zipDest, buffer)
// clean up build files + folders
let folders = []
await Promise.all(files.map(entry => {
if (entry.includes("/")) {
let name = entry.slice(0, entry.lastIndexOf("/"))
if (!folders.includes(name)) {
folders.push(name)
return FS.deleteDir(FS.path.join(destDir, name))
}
} else {
return FS.unlink(FS.path.join(destDir, entry))
}
}))
resolve({

@@ -412,3 +457,3 @@ version,

uglified: uglify || false,
size: appXml.length,
size: buffer.length,
buildPath: destDir,

@@ -415,0 +460,0 @@ buildDir: destDir.slice(process.cwd().length + 1),

{
"name": "defiant-builder",
"version": "1.5.6",
"version": "1.5.7",
"description": "",
"main": "./lib",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node ./test"
},

@@ -20,4 +20,3 @@ "repository": {

"dependencies": {
"btoa": "^1.2.1",
"jsonminify": "^0.4.1",
"jszip": "^3.5.0",
"less": "^3.10.3",

@@ -24,0 +23,0 @@ "rollup": "^1.29.1",

const path = require("path")
const { Build, Bundle} = require("./lib/")
const { Build } = require("./lib/")
let srcDir = path.join(__dirname, "temp/about")
let srcDir = path.join(__dirname, "temp/solitaire")
let destDir = path.join(__dirname, "temp/_build")
let uglify = false
let runIt = async() => {
let runIt = async () => {
let b = await Build(srcDir, destDir, uglify)
//console.log(b)
// console.log(b)
}
runIt()
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc