From e51b6b21a619b13ce0c7c841afef4dbe65b4c667 Mon Sep 17 00:00:00 2001 From: calebboyd Date: Fri, 10 Jul 2020 07:08:17 -0500 Subject: [PATCH] fix: set filesize for resource files --- package-lock.json | 2 +- package.json | 2 +- src/compiler.ts | 15 ++++++--------- src/fs/bundle.ts | 2 +- src/patches/node-rc.ts | 11 ++++++----- src/patches/third-party-main.ts | 4 ++-- src/steps/resource.ts | 7 ++----- src/util.ts | 12 ++++++------ 8 files changed, 25 insertions(+), 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index b0196c1..57aa79a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "nexe", - "version": "4.0.0-beta.13", + "version": "4.0.0-beta.14", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 053c465..c249943 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "nexe", "description": "Create a single executable out of your Node.js application", "license": "MIT", - "version": "4.0.0-beta.13", + "version": "4.0.0-beta.14", "contributors": [ "Craig Condon (http://crcn.io)", "Jared Allard ", diff --git a/src/compiler.ts b/src/compiler.ts index 0a446b8..dde3b18 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -29,7 +29,7 @@ type StringReplacer = (match: string) => string export interface NexeFile { filename: string absPath: string - contents: string + contents: string | Buffer } export { NexeOptions } @@ -176,11 +176,11 @@ export class NexeCompiler { @bound async replaceInFileAsync(file: string, replace: string | RegExp, value: string | StringReplacer) { const entry = await this.readFileAsync(file) - entry.contents = entry.contents.replace(replace, value as any) + entry.contents = entry.contents.toString().replace(replace, value as any) } @bound - async setFileContentsAsync(file: string, contents: string) { + async setFileContentsAsync(file: string, contents: string | Buffer) { const entry = await this.readFileAsync(file) entry.contents = contents } @@ -258,10 +258,7 @@ export class NexeCompiler { return createReadStream(this.getNodeExecutableLocation()) } - private async _shouldCompileBinaryAsync( - binary: NodeJS.ReadableStream | null, - location: string | undefined - ) { + private async _shouldCompileBinaryAsync(binary: NodeJS.ReadableStream | null, location: string) { //SOMEDAY combine make/configure/vcBuild/and modified times of included files const { snapshot, build } = this.options @@ -299,8 +296,8 @@ export class NexeCompiler { if (!this.options.mangle) { return binary } - const index = this.bundle.renderIndex() - this.shims.unshift(wrap(`process.__nexe = ${JSON.stringify({ resources: index }, null, 4)};\n`)) + const resources = this.bundle.renderIndex() + this.shims.unshift(wrap(`process.__nexe = ${JSON.stringify({ resources })};\n`)) const code = this.code(), codeSize = Buffer.byteLength(code), diff --git a/src/fs/bundle.ts b/src/fs/bundle.ts index cf0cca6..e8ab4e9 100644 --- a/src/fs/bundle.ts +++ b/src/fs/bundle.ts @@ -34,7 +34,7 @@ export function toStream(content: Buffer | string) { async function createFile(absoluteFileName: string) { const stats = await lstat(absoluteFileName), file: File = { - size: 0, + size: stats.size, contents: '', absPath: absoluteFileName, deps: {}, diff --git a/src/patches/node-rc.ts b/src/patches/node-rc.ts index 53fd177..a729c02 100644 --- a/src/patches/node-rc.ts +++ b/src/patches/node-rc.ts @@ -12,14 +12,15 @@ export default async function nodeRc(compiler: NexeCompiler, next: () => Promise let value = options[key] const isVar = /^[A-Z_]+$/.test(value) value = isVar ? value : `"${value}"` - file.contents = file.contents.replace( - new RegExp(`VALUE "${key}",.*`), - `VALUE "${key}", ${value}` - ) + file.contents = file.contents + .toString() + .replace(new RegExp(`VALUE "${key}",.*`), `VALUE "${key}", ${value}`) }) ;['PRODUCTVERSION', 'FILEVERSION'].forEach((x) => { if (options[x]) { - file.contents = file.contents.replace(new RegExp(x + ' .*$', 'm'), `${x} ${options[x]}`) + file.contents = file.contents + .toString() + .replace(new RegExp(x + ' .*$', 'm'), `${x} ${options[x]}`) } }) diff --git a/src/patches/third-party-main.ts b/src/patches/third-party-main.ts index 73200ab..53f1b48 100644 --- a/src/patches/third-party-main.ts +++ b/src/patches/third-party-main.ts @@ -36,7 +36,7 @@ export default async function main(compiler: NexeCompiler, next: () => Promise Promise Promi // and https://github.com/mrmlnc/fast-glob#pattern-syntax const resourcesWithForwardSlashes = resources.map((r) => r.replace(/\\/g, '/')) - await each(globs(resourcesWithForwardSlashes, { cwd }), async (file) => { - if (await isDirectoryAsync(file)) { - return - } + await each(globs(resourcesWithForwardSlashes, { cwd, onlyFiles: true }), async (file) => { count++ step.log(`Including file: ${file}`) await compiler.addResource(file) diff --git a/src/util.ts b/src/util.ts index 789116d..5038ef6 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,9 +1,9 @@ import { readFile, writeFile, stat } from 'fs' import { execFile } from 'child_process' -import pify = require('pify') +import { promisify } from 'util' import rimraf = require('rimraf') -const rimrafAsync = pify(rimraf) +const rimrafAsync = promisify(rimraf) export const STDIN_FLAG = '[stdin]' export async function each( @@ -64,10 +64,10 @@ export interface ReadFileAsync { (path: string, encoding: string): Promise } -const readFileAsync = pify(readFile) -const writeFileAsync = pify(writeFile) -const statAsync = pify(stat) -const execFileAsync = pify(execFile) +const readFileAsync = promisify(readFile) +const writeFileAsync = promisify(writeFile) +const statAsync = promisify(stat) +const execFileAsync = promisify(execFile) const isWindows = process.platform === 'win32' function pathExistsAsync(path: string) {