chore: support node 10

This commit is contained in:
calebboyd
2018-04-08 23:35:52 -05:00
committed by Caleb Boyd
parent 5ac93b43ec
commit ad41f07d85
6 changed files with 10817 additions and 495 deletions
+3 -5
View File
@@ -1,17 +1,15 @@
//add placeholder patches so methods can be monkeypatched after being dereferenced
const __nexe_patches = ((process as any).nexe = { patches: {} }).patches as any
function __nexe_noop_patch(this: any, original: any, ...args: any[]) {
return original.call(this, ...args)
}
function __nexe_patch(obj: any, method: string, patch: any) {
__nexe_patches[method] = patch
const original = obj[method]
if (!original) return
__nexe_patches[method] = patch
obj[method] = function(this: any, ...args: any[]) {
return __nexe_patches[method].call(this, original, ...args)
}
}
__nexe_patch((process as any).binding('fs'), 'internalModuleReadFile', __nexe_noop_patch)
__nexe_patch((process as any).binding('fs'), 'internalModuleReadJSON', __nexe_noop_patch)
__nexe_patch((process as any).binding('fs'), 'internalModuleStat', __nexe_noop_patch)
+22 -6
View File
@@ -1,15 +1,31 @@
import { NexeCompiler } from '../compiler'
import { readFileSync } from 'fs'
import semver = require('semver')
import { join } from 'path'
import { wrap } from '../util'
export default async function main(compiler: NexeCompiler, next: () => Promise<void>) {
const bootPath =
(compiler.target.version.startsWith('4') ? 'src/' : 'lib/internal/bootstrap_') + 'node.js'
const file = await compiler.readFileAsync(bootPath)
const parts = file.contents.split('function(process) {')
file.contents =
parts[0] + `function(process) {` + '{{replace:lib/patches/bootstrap.js}}' + parts[1]
let bootFile = 'lib/internal/bootstrap_node.js'
const { version } = compiler.target
if (semver.satisfies(version, '4')) {
bootFile = 'src/node.js'
} else if (semver.gt(version, '9.10.1')) {
bootFile = 'lib/internal/boostrap/node.js'
}
const file = await compiler.readFileAsync(bootFile),
matches = file.contents.match(/\(function.*/),
functionHeader = matches && matches[0]
if (!functionHeader) {
throw new Error('Failed to find bootstrap header in node version: v' + version)
}
file.contents.replace(
functionHeader,
functionHeader + '\n' + '{{replace:lib/patches/bootstrap.js}}'
)
await compiler.setFileContentsAsync(
'lib/_third_party_main.js',