fix: set filesize for resource files

This commit is contained in:
calebboyd
2020-07-10 07:08:17 -05:00
parent 2b261728b4
commit e51b6b21a6
8 changed files with 25 additions and 30 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "nexe",
"version": "4.0.0-beta.13",
"version": "4.0.0-beta.14",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
+1 -1
View File
@@ -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 <craig.j.condon@gmail.com> (http://crcn.io)",
"Jared Allard <jaredallard@outlook.com>",
+6 -9
View File
@@ -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),
+1 -1
View File
@@ -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: {},
+6 -5
View File
@@ -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]}`)
}
})
+2 -2
View File
@@ -36,7 +36,7 @@ export default async function main(compiler: NexeCompiler, next: () => Promise<v
}
const file = await compiler.readFileAsync(bootFile),
ast = parse(file.contents, {
ast = parse(file.contents.toString(), {
loc: true,
tolerant: true,
next: true,
@@ -54,7 +54,7 @@ export default async function main(compiler: NexeCompiler, next: () => Promise<v
}
})
const fileLines = file.contents.split('\n')
const fileLines = file.contents.toString().split('\n')
fileLines.splice(
location.start.line,
0,
+2 -5
View File
@@ -1,4 +1,4 @@
import { isDirectoryAsync, each } from '../util'
import { each } from '../util'
import * as globs from 'globby'
import { NexeCompiler } from '../compiler'
@@ -14,10 +14,7 @@ export default async function resource(compiler: NexeCompiler, next: () => 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)
+6 -6
View File
@@ -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<T>(
@@ -64,10 +64,10 @@ export interface ReadFileAsync {
(path: string, encoding: string): Promise<string>
}
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) {