diff --git a/package-lock.json b/package-lock.json index 822469c..727efc3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "nexe", - "version": "3.0.0-beta.2", + "version": "3.0.0-beta.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/compiler.ts b/src/compiler.ts index a4a1237..e7e43eb 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -8,6 +8,7 @@ import { readFileAsync, writeFileAsync, pathExistsAsync, + statAsync, dequote, isWindows, bound, @@ -268,6 +269,28 @@ export class NexeCompiler { return createReadStream(filename) } + private async _shouldCompileBinaryAsync() { + const build = this.options.build + const binaryLocation = this.getNodeExecutableLocation() + + if (!(await pathExistsAsync(binaryLocation))) { + return true + } + + const snapshot = this.options.snapshot + + if (build && snapshot != null && (await pathExistsAsync(snapshot))) { + const snapshotLastModified = (await statAsync(snapshot)).mtimeMs + const binaryLastModified = (await statAsync(binaryLocation)).mtimeMs + + // if build was requested and there's a snapshot to embed in the binary, + // we need to rebuild if the snapshot was just modified. + return snapshotLastModified > binaryLastModified + } + + return false + } + async compileAsync(target: NexeTarget) { const step = (this.compileStep = this.log.step('Compiling result')) const build = this.options.build @@ -277,11 +300,11 @@ export class NexeCompiler { step.modify('Fetching prebuilt binary') binary = await this._fetchPrebuiltBinaryAsync(target) } - if (!binary) { + if (await this._shouldCompileBinaryAsync()) { binary = await this._buildAsync() step.log('Node binary compiled') } - return this._assembleDeliverable(binary) + return this._assembleDeliverable(binary!) } code() {