diff --git a/src/fs/bootstrap.js b/src/fs/bootstrap.js new file mode 100644 index 0000000..8af92d2 --- /dev/null +++ b/src/fs/bootstrap.js @@ -0,0 +1,15 @@ +const __nexe_patches = (process.nexe = { patches: {} }).patches +function __nexe_noop_patch(original, ...args) { + return original.call(this, ...args) +} +function __nexe_patch(obj, method, patch) { + const original = obj[method] + if (!original) return + __nexe_patches[method] = patch + obj[method] = function( ...args) { + return __nexe_patches[method].call(this, original, ...args) + } +} +__nexe_patch((process).binding('fs'), 'internalModuleReadFile', __nexe_noop_patch) +__nexe_patch((process).binding('fs'), 'internalModuleReadJSON', __nexe_noop_patch) +__nexe_patch((process).binding('fs'), 'internalModuleStat', __nexe_noop_patch) diff --git a/src/fs/bootstrap.ts b/src/fs/bootstrap.ts deleted file mode 100644 index 919de36..0000000 --- a/src/fs/bootstrap.ts +++ /dev/null @@ -1,15 +0,0 @@ -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) { - 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) diff --git a/tasks/post-build.ts b/tasks/post-build.ts index f41746f..3bf0e67 100644 --- a/tasks/post-build.ts +++ b/tasks/post-build.ts @@ -6,13 +6,14 @@ import { writeFileSync, readFileSync } from 'fs' * And the package.json version. */ //inject('plugins/nexe-daemon/lib/index.js') +cp('src/fs/package.json', 'lib/fs/package.json') +cp('src/fs/bootstrap.js', 'lib/fs/bootstrap.js') +cp('src/fs/README.md', 'lib/fs/README.md') + inject('lib/patches/third-party-main.js') inject('lib/steps/shim.js') inject('lib/options.js', JSON.stringify(require('../package.json').version)) -cp('src/fs/package.json', 'lib/fs/package.json') -cp('src/fs/README.md', 'lib/fs/README.md') - function inject(filename: string, ...replacements: string[]) { let contents = readFileSync(filename, 'utf8') contents = contents.replace(/('{{(.*)}}')/g, (substring: string, ...matches: string[]) => {