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
125
126
127
128
129
130
131
132
133
134
135
|
// Hardcoded module "node:os"
export var tmpdir = function () {
var { Bun } = $lazy("primordials");
var env = Bun.env;
tmpdir = function () {
var path = env["TMPDIR"] || env["TMP"] || env["TEMP"] || "/tmp";
const length = path.length;
if (length > 1 && path[length - 1] === "/") path = path.slice(0, -1);
return path;
};
return tmpdir();
};
// os.cpus() is super expensive
// Specifically: getting the CPU speed on Linux is very expensive
// Some packages like FastGlob only bother to read the length of the array
// so instead of actually populating the entire object
// we turn them into getters
function lazyCpus({ cpus }) {
return () => {
const array = new Array(navigator.hardwareConcurrency);
function populate() {
const results = cpus();
const length = results.length;
array.length = length;
for (let i = 0; i < length; i++) {
array[i] = results[i];
}
}
for (let i = 0; i < array.length; i++) {
// This is technically still observable via
// Object.getOwnPropertyDescriptors(), but it should be okay.
const instance = {
get model() {
if (array[i] === instance) populate();
return array[i].model;
},
set model(value) {
if (array[i] === instance) populate();
array[i].model = value;
},
get speed() {
if (array[i] === instance) populate();
return array[i].speed;
},
set speed(value) {
if (array[i] === instance) populate();
array[i].speed = value;
},
get times() {
if (array[i] === instance) populate();
return array[i].times;
},
set times(value) {
if (array[i] === instance) populate();
array[i].times = value;
},
toJSON() {
if (array[i] === instance) populate();
return array[i];
},
};
array[i] = instance;
}
return array;
};
}
function bound(obj) {
return {
arch: obj.arch.bind(obj),
cpus: lazyCpus(obj),
endianness: obj.endianness.bind(obj),
freemem: obj.freemem.bind(obj),
getPriority: obj.getPriority.bind(obj),
homedir: obj.homedir.bind(obj),
hostname: obj.hostname.bind(obj),
loadavg: obj.loadavg.bind(obj),
networkInterfaces: obj.networkInterfaces.bind(obj),
platform: obj.platform.bind(obj),
release: obj.release.bind(obj),
setPriority: obj.setPriority.bind(obj),
get tmpdir() {
return tmpdir;
},
totalmem: obj.totalmem.bind(obj),
type: obj.type.bind(obj),
uptime: obj.uptime.bind(obj),
userInfo: obj.userInfo.bind(obj),
version: obj.version.bind(obj),
machine: obj.machine.bind(obj),
devNull: obj.devNull,
EOL: obj.EOL,
constants: obj.constants,
[Symbol.for("CommonJS")]: 0,
};
}
var os = bound(Bun._Os());
export var {
arch,
cpus,
endianness,
freemem,
getPriority,
homedir,
hostname,
loadavg,
networkInterfaces,
platform,
release,
setPriority,
totalmem,
type,
uptime,
userInfo,
version,
machine,
devNull,
EOL,
constants,
} = os;
export default os;
|