feat: resources
This commit is contained in:
+5
-6
@@ -132,7 +132,7 @@ export class NexeCompiler {
|
||||
}
|
||||
|
||||
_generateHeader (paddingOverride) {
|
||||
const zeros = padLeft(0, 20)
|
||||
const zeros = padLeft(0, 9)
|
||||
const header = {
|
||||
configure: this.options.configure.slice().sort(),
|
||||
make: this.options.make.slice().sort(),
|
||||
@@ -145,9 +145,9 @@ export class NexeCompiler {
|
||||
binaryOffset: zeros
|
||||
}
|
||||
const serializedHeader = this._serializeHeader(header)
|
||||
header.contentSize = padLeft(Buffer.byteLength(this._getPayload(header)), 20)
|
||||
header.paddingSize = padLeft(this._findPaddingSize(+header.contentSize, paddingOverride), 20)
|
||||
header.resourceOffset = padLeft(Buffer.byteLength(serializedHeader + this.input + '/**'), 20)
|
||||
header.contentSize = padLeft(Buffer.byteLength(this._getPayload(header)), 9)
|
||||
header.paddingSize = padLeft(this._findPaddingSize(+header.contentSize, paddingOverride), 9)
|
||||
header.resourceOffset = padLeft(Buffer.byteLength(serializedHeader + this.input + '/**'), 9)
|
||||
return header
|
||||
}
|
||||
|
||||
@@ -216,7 +216,6 @@ export class NexeCompiler {
|
||||
const header = this._generateHeader(this.options.padding)
|
||||
target = target && `${target}-${header.paddingSize}`
|
||||
const existingBinaryHeader = await this._getExistingBinaryHeaderAsync(target)
|
||||
|
||||
if (existingBinaryHeader && this._headersAreEqual(header, existingBinaryHeader)) {
|
||||
prebuiltSource = createReadStream(this._getArtifactLocation(target))
|
||||
}
|
||||
@@ -252,7 +251,7 @@ export class NexeCompiler {
|
||||
artifact.push(x)
|
||||
}
|
||||
if (needles === 1 && !+header.binaryOffset) {
|
||||
header.binaryOffset = padLeft(currentStackSize, 20)
|
||||
header.binaryOffset = padLeft(currentStackSize, 9)
|
||||
artifact.push(
|
||||
Buffer.from(
|
||||
inflate(this._getPayload(header), +header.paddingSize) +
|
||||
|
||||
+5
-13
@@ -1,5 +1,4 @@
|
||||
import { createGunzip as unZip } from 'zlib'
|
||||
import { extract as unTar } from 'tar-fs'
|
||||
import { extract as unTar } from 'tar'
|
||||
import request from 'request'
|
||||
import Bluebird from 'bluebird'
|
||||
import { stat } from 'fs'
|
||||
@@ -25,8 +24,7 @@ function progress (req, log, precision = 10) {
|
||||
})
|
||||
}
|
||||
|
||||
function fetchNodeSource (path, url, log) {
|
||||
const prefix = url.split('/').pop().replace('.tar.gz', '/')
|
||||
function fetchNodeSource (cwd, url, log) {
|
||||
log.info('Downloading Node: ' + url)
|
||||
return new Bluebird((resolve, reject) => {
|
||||
progress(request.get(url), (pc) => {
|
||||
@@ -35,15 +33,9 @@ function fetchNodeSource (path, url, log) {
|
||||
log.info('Complete...')
|
||||
}
|
||||
}).on('error', reject)
|
||||
.pipe(unZip().on('error', reject))
|
||||
.pipe(unTar(path, {
|
||||
map (header) {
|
||||
header.name = header.name.replace(prefix, '')
|
||||
return header
|
||||
}
|
||||
}))
|
||||
.pipe(unTar({ x: 1, strip: 1, cwd }))
|
||||
.on('error', reject)
|
||||
.on('end', () => resolve(log.info('Extracted to: ' + path)))
|
||||
.on('close', () => resolve(log.info('Extracted to: ' + cwd)))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -58,7 +50,7 @@ function cleanSrc (clean, src, log) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes (maybe) and downloads the node source to the configured temporary directory
|
||||
* Downloads the node source to the configured temporary directory
|
||||
* @param {*} compiler
|
||||
* @param {*} next
|
||||
*/
|
||||
|
||||
@@ -25,6 +25,8 @@ const alias = {
|
||||
t: 'target',
|
||||
n: 'name',
|
||||
v: 'version',
|
||||
r: 'resource',
|
||||
a: 'resource',
|
||||
p: 'python',
|
||||
f: 'flag',
|
||||
c: 'configure',
|
||||
|
||||
@@ -36,7 +36,7 @@ fs.readFile = function readFile (file, options, callback) {
|
||||
|
||||
fs.open(process.execPath, 'r', function (err, fd) {
|
||||
if (err) return callback(err, null)
|
||||
fs.read(fd, Buffer.alloc(length), 0, length, binaryOffset, function (error, bytesRead, buffer) {
|
||||
fs.read(fd, Buffer.alloc(length), 0, length, resourceOffset, function (error, bytesRead, buffer) {
|
||||
if (error) {
|
||||
return fs.close(fd, function () {
|
||||
callback(error, null)
|
||||
|
||||
+2
-1
@@ -5,7 +5,7 @@ import globs from 'globby'
|
||||
import { stat } from 'fs'
|
||||
|
||||
async function isDirectoryAsync (path) {
|
||||
const stats = fromCallback(cb => stat(path, cb))
|
||||
const stats = await fromCallback(cb => stat(path, cb))
|
||||
return stats.isDirectory()
|
||||
}
|
||||
|
||||
@@ -31,4 +31,5 @@ export default async function resource (compiler, next) {
|
||||
]
|
||||
resources.bundle = resources.bundle + encodedContents
|
||||
})
|
||||
return next()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user