boxednode
Advanced tools
Comparing version 2.4.1 to 2.4.2
@@ -57,3 +57,4 @@ #!/usr/bin/env node | ||
useCodeCache: argv.H, | ||
useNodeSnapshot: argv.S | ||
useNodeSnapshot: argv.S, | ||
compressBlobs: argv.Z | ||
}); | ||
@@ -60,0 +61,0 @@ } catch (err) { |
@@ -18,2 +18,3 @@ /// <reference types="node" /> | ||
export declare function createCppJsStringDefinition(fnName: string, source: string): string; | ||
export declare function createUncompressedBlobDefinition(fnName: string, source: Uint8Array): Promise<string>; | ||
export declare function createCompressedBlobDefinition(fnName: string, source: Uint8Array): Promise<string>; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createCompressedBlobDefinition = exports.createCppJsStringDefinition = exports.npm = exports.objhash = exports.copyRecursive = exports.spawnBuildCommand = exports.pipeline = void 0; | ||
exports.createCompressedBlobDefinition = exports.createUncompressedBlobDefinition = exports.createCppJsStringDefinition = exports.npm = exports.objhash = exports.copyRecursive = exports.spawnBuildCommand = exports.pipeline = void 0; | ||
const fs_1 = require("fs"); | ||
@@ -94,2 +94,17 @@ const crypto_1 = __importDefault(require("crypto")); | ||
exports.createCppJsStringDefinition = createCppJsStringDefinition; | ||
async function createUncompressedBlobDefinition(fnName, source) { | ||
return ` | ||
static const uint8_t ${fnName}_source_[] = { | ||
${Uint8Array.prototype.toString.call(source) || '0'} | ||
}; | ||
std::vector<char> ${fnName}Vector() { | ||
return std::vector<char>( | ||
reinterpret_cast<const char*>(&${fnName}_source_[0]), | ||
reinterpret_cast<const char*>(&${fnName}_source_[${source.length}])); | ||
} | ||
${blobTypedArrayAccessors(fnName, source.length)}`; | ||
} | ||
exports.createUncompressedBlobDefinition = createUncompressedBlobDefinition; | ||
async function createCompressedBlobDefinition(fnName, source) { | ||
@@ -121,9 +136,2 @@ const compressed = await (0, util_1.promisify)(zlib_1.default.brotliCompress)(source, { | ||
std::string ${fnName}() { | ||
${source.length === 0 ? 'return {};' : ` | ||
std::string dst(${source.length}, 0); | ||
${fnName}_Read(&dst[0]); | ||
return dst;`} | ||
} | ||
std::vector<char> ${fnName}Vector() { | ||
@@ -136,4 +144,10 @@ ${source.length === 0 ? 'return {};' : ` | ||
${blobTypedArrayAccessors(fnName, source.length)} | ||
`; | ||
} | ||
exports.createCompressedBlobDefinition = createCompressedBlobDefinition; | ||
function blobTypedArrayAccessors(fnName, sourceLength) { | ||
return ` | ||
std::shared_ptr<v8::BackingStore> ${fnName}BackingStore() { | ||
std::string* str = new std::string(std::move(${fnName}())); | ||
std::vector<char>* str = new std::vector<char>(std::move(${fnName}Vector())); | ||
return v8::SharedArrayBuffer::NewBackingStore( | ||
@@ -143,3 +157,3 @@ &str->front(), | ||
[](void*, size_t, void* deleter_data) { | ||
delete static_cast<std::string*>(deleter_data); | ||
delete static_cast<std::vector<char>*>(deleter_data); | ||
}, | ||
@@ -150,3 +164,3 @@ static_cast<void*>(str)); | ||
v8::Local<v8::Uint8Array> ${fnName}Buffer(v8::Isolate* isolate) { | ||
${source.length === 0 ? ` | ||
${sourceLength === 0 ? ` | ||
auto array_buffer = v8::SharedArrayBuffer::New(isolate, 0); | ||
@@ -160,3 +174,2 @@ ` : ` | ||
} | ||
exports.createCompressedBlobDefinition = createCompressedBlobDefinition; | ||
//# sourceMappingURL=helpers.js.map |
@@ -21,2 +21,3 @@ import { Logger } from './logger'; | ||
useNodeSnapshot?: boolean; | ||
compressBlobs?: boolean; | ||
nodeSnapshotConfigFlags?: string[]; | ||
@@ -23,0 +24,0 @@ executableMetadata?: ExecutableMetadata; |
@@ -295,2 +295,5 @@ 'use strict'; | ||
} | ||
const createBlobDefinition = options.compressBlobs | ||
? helpers_1.createCompressedBlobDefinition | ||
: helpers_1.createUncompressedBlobDefinition; | ||
async function writeMainFileAndCompile({ codeCacheBlob = new Uint8Array(0), codeCacheMode = 'ignore', snapshotBlob = new Uint8Array(0), snapshotMode = 'ignore' } = {}) { | ||
@@ -303,4 +306,4 @@ logger.stepStarting('Handling main file source'); | ||
mainSource = mainSource.replace(/\bREPLACE_WITH_MAIN_SCRIPT_SOURCE_GETTER\b/g, (0, helpers_1.createCppJsStringDefinition)('GetBoxednodeMainScriptSource', snapshotMode !== 'consume' ? jsMainSource : '') + '\n' + | ||
await (0, helpers_1.createCompressedBlobDefinition)('GetBoxednodeCodeCache', codeCacheBlob) + '\n' + | ||
await (0, helpers_1.createCompressedBlobDefinition)('GetBoxednodeSnapshotBlob', snapshotBlob)); | ||
await createBlobDefinition('GetBoxednodeCodeCache', codeCacheBlob) + '\n' + | ||
await createBlobDefinition('GetBoxednodeSnapshotBlob', snapshotBlob)); | ||
mainSource = mainSource.replace(/\bBOXEDNODE_CODE_CACHE_MODE\b/g, JSON.stringify(codeCacheMode)); | ||
@@ -307,0 +310,0 @@ if (options.useLegacyDefaultUvLoop) { |
{ | ||
"name": "boxednode", | ||
"version": "2.4.1", | ||
"version": "2.4.2", | ||
"description": "Create a shippable binary from a JS file", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
127412
1081