/
bytenode+1.3.7.dev.patch
124 lines (112 loc) · 4.07 KB
/
bytenode+1.3.7.dev.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
diff --git a/node_modules/bytenode/lib/cli.js b/node_modules/bytenode/lib/cli.js
index 9f57493..3ba173e 100755
--- a/node_modules/bytenode/lib/cli.js
+++ b/node_modules/bytenode/lib/cli.js
@@ -2,11 +2,15 @@
'use strict';
-const fs = require('fs');
-const path = require('path');
-const wrap = require('module').wrap;
-const spawnSync = require('child_process').spawnSync;
-const bytenode = require('./index.js');
+import fs from 'fs';
+import path from 'path';
+import * as mod from 'module';
+import { spawnSync } from 'child_process';
+import * as bytenode from './index.js';
+import * as url from 'url';
+
+const __filename = url.fileURLToPath(import.meta.url);
+const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
const args = process.argv.slice(2);
@@ -100,7 +104,7 @@ if (program.flags.includes('--compile')) {
if (program.flags.includes('--no-module')) {
process.stdout.write(bytenode.compileCode(script));
} else {
- process.stdout.write(bytenode.compileCode(wrap(script)));
+ process.stdout.write(bytenode.compileCode(mod.wrap(script)));
}
} catch (error) {
console.error(error);
@@ -136,13 +140,6 @@ if (program.flags.includes('--compile')) {
$ echo 'console.log("Hello");' | bytenode --compile - > hello.jsc
compile from stdin and save to \`hello.jsc\`
`);
-} else if (program.flags.includes('--version') && program.flags.length === 1 && program.files.length === 0) {
- const pkg = require('../package.json');
- console.log(pkg.name, pkg.version);
- console.log('Node', process.versions.node);
- if (process.versions.electron) {
- console.log('Electron', process.versions.electron);
- }
} else {
try {
spawnSync(program.nodeBin, [
diff --git a/node_modules/bytenode/lib/index.js b/node_modules/bytenode/lib/index.js
index cdd98cc..635bc27 100644
--- a/node_modules/bytenode/lib/index.js
+++ b/node_modules/bytenode/lib/index.js
@@ -1,11 +1,13 @@
'use strict';
-const fs = require('fs');
-const vm = require('vm');
-const v8 = require('v8');
-const path = require('path');
-const Module = require('module');
-const fork = require('child_process').fork;
+import fs from 'fs';
+import vm from 'vm';
+import v8 from 'v8';
+import path from 'path';
+import Module from 'module';
+import { fork } from 'child_process';
+import { createRequire } from 'module';
+import * as url from 'url';
v8.setFlagsFromString('--no-lazy');
@@ -46,10 +48,12 @@ const compileElectronCode = function (javascriptCode) {
return new Promise((resolve, reject) => {
let data = Buffer.from([]);
+ const require = createRequire(import.meta.url)
const electronPath = path.join(path.dirname(require.resolve('electron')), 'cli.js');
if (!fs.existsSync(electronPath)) {
throw new Error('Electron not installed');
}
+ const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
const bytenodePath = path.join(__dirname, 'cli.js');
// create a subprocess in which we run Electron as our Node and V8 engine
@@ -249,7 +253,7 @@ const runBytecodeFile = function (filename) {
return runBytecode(bytecodeBuffer);
};
-Module._extensions[COMPILED_EXTNAME] = function (fileModule, filename) {
+const runBytecodeAsModule = function (fileModule, filename) {
const bytecodeBuffer = fs.readFileSync(filename);
fixBytecode(bytecodeBuffer);
@@ -333,14 +337,13 @@ const loaderCode = function (targetPath) {
`;
};
-global.bytenode = {
+export {
compileCode,
compileFile,
compileElectronCode,
runBytecode,
runBytecodeFile,
addLoaderFile,
- loaderCode
+ loaderCode,
+ runBytecodeAsModule,
};
-
-module.exports = global.bytenode;
diff --git a/node_modules/bytenode/package.json b/node_modules/bytenode/package.json
index 6caff7c..72e2c46 100644
--- a/node_modules/bytenode/package.json
+++ b/node_modules/bytenode/package.json
@@ -3,6 +3,7 @@
"version": "1.3.7",
"description": "A minimalist bytecode compiler for Node.js",
"main": "lib/index.js",
+ "type": "module",
"bin": "lib/cli.js",
"types": "lib/index.d.ts",
"files": [