@elixir-playground/elixir 0.0.0-stage → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +73 -0
- package/NOTICE.md +25 -0
- package/builds.d.ts +9 -0
- package/builds.js +25 -0
- package/cli.js +112 -0
- package/commands.d.ts +3 -0
- package/commands.js +43 -0
- package/elixir.d.ts +27 -0
- package/elixir.js +42 -0
- package/hex.d.ts +4 -0
- package/hex.js +112 -0
- package/index.d.ts +8 -0
- package/index.js +97 -0
- package/layer.d.ts +16 -0
- package/layer.js +107 -0
- package/licenses/bbmustache-rebar3_3.28.0/LICENSE +22 -0
- package/licenses/cf-rebar3_3.28.0/LICENSE +29 -0
- package/licenses/cth_readable-rebar3_3.28.0/LICENSE +29 -0
- package/licenses/elixir-1.20.5/Apache-2.0.txt +73 -0
- package/licenses/elixir-1.20.5/LICENSE +176 -0
- package/licenses/elixir-1.20.5/LicenseRef-elixir-trademark-policy.txt +98 -0
- package/licenses/elixir-1.20.5/LicenseRef-scancode-unicode.txt +58 -0
- package/licenses/elixir-1.20.5/license_compliance.yml +41 -0
- package/licenses/elixir-playground-playground/LICENSE +73 -0
- package/licenses/elixir-playground-playground/NOTICE +11 -0
- package/licenses/erlware_commons-rebar3_3.28.0/Apache-2.0.txt +73 -0
- package/licenses/erlware_commons-rebar3_3.28.0/MIT.txt +18 -0
- package/licenses/eunit_formatters-rebar3_3.28.0/LICENSE +67 -0
- package/licenses/getopt-rebar3_3.28.0/LICENSE.txt +26 -0
- package/licenses/hex-2.7.0/Apache-2.0.txt +73 -0
- package/licenses/index.json +150 -0
- package/licenses/phx_new-1.8.16/MIT.txt +18 -0
- package/licenses/providers-rebar3_3.28.0/LICENSE +202 -0
- package/licenses/rebar3-3.28.0/LICENSE +178 -0
- package/licenses/relx-rebar3_3.28.0/LICENSE.md +194 -0
- package/licenses/ssl_verify_fun-rebar3_3.28.0/LICENSE +22 -0
- package/package.json +67 -4
- package/prepare.d.ts +27 -0
- package/prepare.js +257 -0
- package/run.d.ts +10 -0
- package/run.js +68 -0
- package/zip.d.ts +6 -0
- package/zip.js +44 -0
- package/README.md +0 -3
package/prepare.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type WrittenLayer } from './layer.js';
|
|
2
|
+
export interface PrepareOptions {
|
|
3
|
+
build?: string;
|
|
4
|
+
archives?: Record<string, string>;
|
|
5
|
+
otp: string;
|
|
6
|
+
into: string;
|
|
7
|
+
cache?: string;
|
|
8
|
+
untested?: boolean;
|
|
9
|
+
force?: boolean;
|
|
10
|
+
log?: (line: string) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface PreparedArchive {
|
|
13
|
+
version: string;
|
|
14
|
+
path: string;
|
|
15
|
+
layer: WrittenLayer;
|
|
16
|
+
}
|
|
17
|
+
export interface Prepared {
|
|
18
|
+
build: string;
|
|
19
|
+
elixir: string;
|
|
20
|
+
otp: string;
|
|
21
|
+
hex: string;
|
|
22
|
+
rebar3: string;
|
|
23
|
+
sha256: string;
|
|
24
|
+
layer: WrittenLayer;
|
|
25
|
+
archives: Record<string, PreparedArchive>;
|
|
26
|
+
}
|
|
27
|
+
export declare function prepare(options: PrepareOptions): Promise<Prepared>;
|
package/prepare.js
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
// The elixir package's layers for a build (docs/packages.md, "Elixir
|
|
2
|
+
// builds"): Elixir's precompiled release from builds.hex.pm, with the
|
|
3
|
+
// rebar3 that Mix installs for it; and Mix's archives, Hex's and those
|
|
4
|
+
// asked for (phx_new), as Mix installs them. All on the site's own OTP (an
|
|
5
|
+
// otp package, under Node through the runtime's harness). No OTP or
|
|
6
|
+
// Elixir on the machine is needed.
|
|
7
|
+
//
|
|
8
|
+
// await prepare({ build: '1.20.5-otp-29', archives: { phx_new: '1.8.16' }, otp: 'node_modules/@elixir-playground/otp-29.1.3', into: 'public/npm/@elixir-playground/elixir@3.0.0' });
|
|
9
|
+
//
|
|
10
|
+
// It writes versions/BUILD/ below `into`: fs.json (Elixir's layer, which
|
|
11
|
+
// create() reads as the descriptor's `layer`) and fs/, archives/NAME/
|
|
12
|
+
// with each archive's (builds.ts archivePath), licenses/, and
|
|
13
|
+
// prepared.json (what it was made of: the same again is not made twice).
|
|
14
|
+
import { createHash } from 'node:crypto';
|
|
15
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync, } from 'node:fs';
|
|
16
|
+
import { tmpdir } from 'node:os';
|
|
17
|
+
import { dirname, join, relative } from 'node:path';
|
|
18
|
+
import { start } from '@elixir-playground/runtime/harness';
|
|
19
|
+
import { ARCHIVES, BUILDS, DEFAULT, archivePath, buildPath, parseBuild } from './builds.js';
|
|
20
|
+
import { writeLayer } from './layer.js';
|
|
21
|
+
import { unzip } from './zip.js';
|
|
22
|
+
// Where Mix installs Hex and rebar3 from (HEX_BUILDS_URL), and Elixir's
|
|
23
|
+
// builds.
|
|
24
|
+
const BUILDS_URL = 'https://builds.hex.pm';
|
|
25
|
+
// The applications of Elixir's release that a node loads (build.py's
|
|
26
|
+
// ELIXIR_APPS), and its scripts, the package's commands.
|
|
27
|
+
const APPS = ['elixir', 'eex', 'ex_unit', 'iex', 'logger', 'mix'];
|
|
28
|
+
const SCRIPTS = ['elixir', 'elixirc', 'iex', 'mix'];
|
|
29
|
+
// Hex's repository, which archive.install hex fetches from (HEX_MIRROR).
|
|
30
|
+
const REPO_URL = 'https://repo.hex.pm';
|
|
31
|
+
// The harness's ports that answer Mix's downloads and Hex's.
|
|
32
|
+
const MIRROR_PORT = 4001;
|
|
33
|
+
const REPO_PORT = 4002;
|
|
34
|
+
// What a prepared build records (prepared.json); another number makes it
|
|
35
|
+
// again.
|
|
36
|
+
const FORMAT = 2;
|
|
37
|
+
const sha256 = (bytes) => createHash('sha256').update(bytes).digest('hex');
|
|
38
|
+
async function download(url) {
|
|
39
|
+
const response = await fetch(url);
|
|
40
|
+
if (!response.ok)
|
|
41
|
+
throw new Error(`${url}: ${response.status} ${response.statusText}`);
|
|
42
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
43
|
+
}
|
|
44
|
+
// The build's SHA-256: builds.ts's, or (untested) builds.txt's.
|
|
45
|
+
async function checksum(build, untested) {
|
|
46
|
+
if (BUILDS[build])
|
|
47
|
+
return BUILDS[build];
|
|
48
|
+
if (!untested)
|
|
49
|
+
throw new Error(`Elixir ${build} is not among the builds this package was tested with ` +
|
|
50
|
+
`(${Object.keys(BUILDS).join(', ')}); ask for it as untested to prepare it anyway`);
|
|
51
|
+
const listed = new TextDecoder().decode(await download(`${BUILDS_URL}/builds/elixir/builds.txt`));
|
|
52
|
+
const line = listed.split('\n').find((each) => each.startsWith(`v${build} `));
|
|
53
|
+
if (!line)
|
|
54
|
+
throw new Error(`Elixir ${build}: not on builds.hex.pm`);
|
|
55
|
+
return line.split(' ')[3];
|
|
56
|
+
}
|
|
57
|
+
// The release's zip, from the cache or builds.hex.pm, checked.
|
|
58
|
+
async function release(build, expected, cache) {
|
|
59
|
+
const kept = cache && join(cache, `elixir-v${build}.zip`);
|
|
60
|
+
if (kept && existsSync(kept)) {
|
|
61
|
+
const bytes = new Uint8Array(readFileSync(kept));
|
|
62
|
+
if (sha256(bytes) === expected)
|
|
63
|
+
return bytes;
|
|
64
|
+
}
|
|
65
|
+
const url = `${BUILDS_URL}/builds/elixir/v${build}.zip`;
|
|
66
|
+
const bytes = await download(url);
|
|
67
|
+
if (sha256(bytes) !== expected)
|
|
68
|
+
throw new Error(`${url}: SHA-256 ${sha256(bytes)}, not ${expected}`);
|
|
69
|
+
if (kept) {
|
|
70
|
+
mkdirSync(cache, { recursive: true });
|
|
71
|
+
writeFileSync(kept, bytes);
|
|
72
|
+
}
|
|
73
|
+
return bytes;
|
|
74
|
+
}
|
|
75
|
+
// Every file below `top`, by its path relative to it.
|
|
76
|
+
function walk(top) {
|
|
77
|
+
const out = [];
|
|
78
|
+
const visit = (directory) => {
|
|
79
|
+
for (const name of readdirSync(directory).sort()) {
|
|
80
|
+
const path = join(directory, name);
|
|
81
|
+
if (statSync(path).isDirectory())
|
|
82
|
+
visit(path);
|
|
83
|
+
else
|
|
84
|
+
out.push(relative(top, path).split('\\').join('/'));
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
if (existsSync(top))
|
|
88
|
+
visit(top);
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
const packageJson = (directory) => JSON.parse(readFileSync(join(directory, 'package.json'), 'utf8'));
|
|
92
|
+
export async function prepare(options) {
|
|
93
|
+
const build = options.build ?? DEFAULT;
|
|
94
|
+
const log = options.log ?? ((line) => console.error(line));
|
|
95
|
+
const { elixir, otp: major } = parseBuild(build);
|
|
96
|
+
const otpPackage = packageJson(options.otp);
|
|
97
|
+
const otpVersion = otpPackage.playground?.otp;
|
|
98
|
+
if (!otpVersion)
|
|
99
|
+
throw new Error(`${options.otp}: not an otp package`);
|
|
100
|
+
if (Number(otpVersion.split('.')[0]) !== major)
|
|
101
|
+
throw new Error(`Elixir ${build} is for OTP ${major}, not ${otpPackage.name}`);
|
|
102
|
+
const otp = `${otpPackage.name}@${otpPackage.version}`;
|
|
103
|
+
const sha = await checksum(build, !!options.untested);
|
|
104
|
+
const asked = options.archives ?? {};
|
|
105
|
+
for (const [name, version] of Object.entries(asked))
|
|
106
|
+
if (!/^[a-z][a-z0-9_]*$/.test(name) || !/^\d+\.\d+\.\d+(-[0-9A-Za-z.]+)?$/.test(version))
|
|
107
|
+
throw new Error(`${name} ${version}: not a Hex package and version`);
|
|
108
|
+
const directory = join(options.into, buildPath(build));
|
|
109
|
+
const record = join(directory, 'prepared.json');
|
|
110
|
+
if (!options.force && existsSync(record)) {
|
|
111
|
+
const before = JSON.parse(readFileSync(record, 'utf8'));
|
|
112
|
+
const has = Object.entries(asked).every(([name, version]) => before.archives?.[name]?.version === version);
|
|
113
|
+
if (before.format === FORMAT && before.sha256 === sha && before.otp === otp && has) {
|
|
114
|
+
const { format: _, ...prepared } = before;
|
|
115
|
+
return prepared;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
log(`elixir: Elixir ${build} from builds.hex.pm`);
|
|
119
|
+
const zip = await release(build, sha, options.cache);
|
|
120
|
+
const scratch = mkdtempSync(join(tmpdir(), 'elixir-playground-'));
|
|
121
|
+
try {
|
|
122
|
+
const unpacked = join(scratch, 'elixir');
|
|
123
|
+
const files = [];
|
|
124
|
+
const texts = {};
|
|
125
|
+
for (const entry of unzip(zip)) {
|
|
126
|
+
const [top, app, part] = entry.name.split('/');
|
|
127
|
+
let path = null;
|
|
128
|
+
if (top === 'lib' && APPS.includes(app) && ['ebin', 'priv', 'include'].includes(part))
|
|
129
|
+
path = entry.name;
|
|
130
|
+
else if (top === 'bin' && SCRIPTS.includes(app))
|
|
131
|
+
path = entry.name;
|
|
132
|
+
else if (entry.name === 'LICENSE')
|
|
133
|
+
texts.LICENSE = entry.data;
|
|
134
|
+
if (!path)
|
|
135
|
+
continue;
|
|
136
|
+
files.push({ path, data: entry.data, executable: top === 'bin' });
|
|
137
|
+
mkdirSync(dirname(join(unpacked, path)), { recursive: true });
|
|
138
|
+
writeFileSync(join(unpacked, path), entry.data);
|
|
139
|
+
}
|
|
140
|
+
// Mix installs Hex and rebar3 into an empty MIX_HOME, from
|
|
141
|
+
// builds.hex.pm through the harness's port: it checks Hex's and
|
|
142
|
+
// rebar3's SHA-512 itself. Then the archives asked for, from Hex's
|
|
143
|
+
// repository through another (Hex checks the registry's signature
|
|
144
|
+
// and each tarball's checksum), compiled with this Elixir. Below
|
|
145
|
+
// /tmp: the node's own directories are those its tree has when it
|
|
146
|
+
// starts.
|
|
147
|
+
const names = Object.entries(asked).map(([name, version]) => `${name} ${version}`);
|
|
148
|
+
log(`elixir: Hex, rebar3${names.map((each) => `, ${each}`).join('')} for Elixir ${elixir} on ${otp}`);
|
|
149
|
+
const install = Object.entries(asked).map(([name, version]) => `Mix.Tasks.Archive.Install.run(["hex", "${name}", "${version}", "--force"]); `);
|
|
150
|
+
const root = `/opt/elixir/${elixir}`;
|
|
151
|
+
const output = [];
|
|
152
|
+
const keep = (bytes) => output.push(new TextDecoder().decode(bytes));
|
|
153
|
+
const node = await start({
|
|
154
|
+
packages: [options.otp],
|
|
155
|
+
args: [
|
|
156
|
+
'-noshell',
|
|
157
|
+
'-elixir_root',
|
|
158
|
+
`${root}/lib`,
|
|
159
|
+
'-pa',
|
|
160
|
+
`${root}/lib/elixir/ebin`,
|
|
161
|
+
'-user',
|
|
162
|
+
'elixir',
|
|
163
|
+
'-extra',
|
|
164
|
+
'-e',
|
|
165
|
+
'Mix.start(); Mix.Tasks.Local.Hex.run(["--force"]); Mix.Tasks.Local.Rebar.run(["--force"]); ' +
|
|
166
|
+
install.join(''),
|
|
167
|
+
],
|
|
168
|
+
mounts: { [root]: unpacked },
|
|
169
|
+
env: {
|
|
170
|
+
MIX_HOME: '/tmp/mix',
|
|
171
|
+
HEX_BUILDS_URL: `http://localhost:${MIRROR_PORT}`,
|
|
172
|
+
HEX_MIRROR: `http://localhost:${REPO_PORT}`,
|
|
173
|
+
},
|
|
174
|
+
http: {
|
|
175
|
+
[MIRROR_PORT]: (path) => `${BUILDS_URL}${path}`,
|
|
176
|
+
[REPO_PORT]: (path) => `${REPO_URL}${path}`,
|
|
177
|
+
},
|
|
178
|
+
stdout: keep,
|
|
179
|
+
stderr: keep,
|
|
180
|
+
});
|
|
181
|
+
node.end();
|
|
182
|
+
const result = await node.done;
|
|
183
|
+
if (result.status !== 0)
|
|
184
|
+
throw new Error(`Mix could not install Hex, rebar3 and the archives (exit ${result.status}):\n${output.join('')}`);
|
|
185
|
+
const mix = join(scratch, 'mix');
|
|
186
|
+
result.snapshot('/tmp/mix', mix);
|
|
187
|
+
const installed = walk(mix);
|
|
188
|
+
const rebar = installed.find((path) => /^elixir\/[^/]+\/rebar3$/.test(path));
|
|
189
|
+
// Each archive's files, by its name: their paths below the archives'
|
|
190
|
+
// directory (NAME-VERSION/…), and its version.
|
|
191
|
+
const archived = new Map();
|
|
192
|
+
for (const path of installed) {
|
|
193
|
+
const found = /^archives\/(([a-z][a-z0-9_]*)-([^/]+))\//.exec(path);
|
|
194
|
+
if (!found)
|
|
195
|
+
continue;
|
|
196
|
+
const [, , name, version] = found;
|
|
197
|
+
if (!archived.has(name))
|
|
198
|
+
archived.set(name, { version, files: [] });
|
|
199
|
+
archived.get(name).files.push({
|
|
200
|
+
path: path.slice('archives/'.length),
|
|
201
|
+
data: new Uint8Array(readFileSync(join(mix, path))),
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
const hex = archived.get('hex')?.version;
|
|
205
|
+
const missing = Object.entries(asked).filter(([name, version]) => archived.get(name)?.version !== version);
|
|
206
|
+
if (!hex || !rebar || missing.length)
|
|
207
|
+
throw new Error(`Mix installed no Hex, no rebar3, or not ${missing.map((each) => each.join(' ')).join(', ')}:\n${output.join('')}`);
|
|
208
|
+
const rebar3 = new Uint8Array(readFileSync(join(mix, rebar)));
|
|
209
|
+
files.push({ path: 'mix/rebar3', data: rebar3, executable: true });
|
|
210
|
+
const rebarVersion = /Rebar3 (\S+)/.exec(new TextDecoder().decode(rebar3.subarray(0, 200)))?.[1] ?? 'unknown';
|
|
211
|
+
rmSync(directory, { recursive: true, force: true });
|
|
212
|
+
mkdirSync(directory, { recursive: true });
|
|
213
|
+
const layer = writeLayer(directory, files, root);
|
|
214
|
+
writeFileSync(join(directory, 'fs.json'), JSON.stringify(layer, null, 1) + '\n');
|
|
215
|
+
const archives = {};
|
|
216
|
+
for (const [name, { version, files: archive }] of archived) {
|
|
217
|
+
// Hex's is Mix's choice; another is at the version asked for.
|
|
218
|
+
const path = archivePath(build, name, name === 'hex' ? undefined : version);
|
|
219
|
+
const at = join(options.into, path);
|
|
220
|
+
mkdirSync(at, { recursive: true });
|
|
221
|
+
const written = writeLayer(at, archive, ARCHIVES);
|
|
222
|
+
writeFileSync(join(at, 'fs.json'), JSON.stringify(written, null, 1) + '\n');
|
|
223
|
+
archives[name] = { version, path, layer: written };
|
|
224
|
+
}
|
|
225
|
+
// What the layer has, and their licenses (all Apache-2.0).
|
|
226
|
+
mkdirSync(join(directory, 'licenses'), { recursive: true });
|
|
227
|
+
if (texts.LICENSE)
|
|
228
|
+
writeFileSync(join(directory, 'licenses', 'elixir-LICENSE'), texts.LICENSE);
|
|
229
|
+
writeFileSync(join(directory, 'licenses', 'README'), [
|
|
230
|
+
`Elixir ${build}, Apache-2.0 (elixir-LICENSE): https://elixir-lang.org, ${BUILDS_URL}/builds/elixir/v${build}.zip`,
|
|
231
|
+
`Hex ${hex}, Apache-2.0: https://hex.pm, as Mix installed it`,
|
|
232
|
+
`rebar3 ${rebarVersion}, Apache-2.0: https://rebar3.org, as Mix installed it`,
|
|
233
|
+
...[...archived]
|
|
234
|
+
.filter(([name]) => name !== 'hex')
|
|
235
|
+
.map(([name, { version }]) => `${name} ${version}: https://hex.pm/packages/${name}, as Mix installed it`),
|
|
236
|
+
'',
|
|
237
|
+
].join('\n'));
|
|
238
|
+
const prepared = {
|
|
239
|
+
build,
|
|
240
|
+
elixir,
|
|
241
|
+
otp,
|
|
242
|
+
hex,
|
|
243
|
+
rebar3: rebarVersion,
|
|
244
|
+
sha256: sha,
|
|
245
|
+
layer,
|
|
246
|
+
archives,
|
|
247
|
+
};
|
|
248
|
+
writeFileSync(record, JSON.stringify({ format: FORMAT, ...prepared }, null, 1) + '\n');
|
|
249
|
+
log(`elixir: ${directory} (${files.length} files, rebar3 ${rebarVersion}; archives ` +
|
|
250
|
+
[...archived].map(([name, { version }]) => `${name} ${version}`).join(', ') +
|
|
251
|
+
')');
|
|
252
|
+
return prepared;
|
|
253
|
+
}
|
|
254
|
+
finally {
|
|
255
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
256
|
+
}
|
|
257
|
+
}
|
package/run.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { COMMANDS } from './commands.js';
|
|
2
|
+
export interface RunOptions {
|
|
3
|
+
build?: string;
|
|
4
|
+
command: string;
|
|
5
|
+
args: string[];
|
|
6
|
+
otp?: string;
|
|
7
|
+
archives?: Record<string, string>;
|
|
8
|
+
log?: (line: string) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function run(options: RunOptions): Promise<number>;
|
package/run.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Elixir's commands under Node (the elixir package's command: `npx
|
|
2
|
+
// @elixir-playground/elixir --version 1.20.5-otp-29 iex`): a build
|
|
3
|
+
// prepared into the user's cache, run on an installed otp package through
|
|
4
|
+
// the runtime's harness, in this terminal or over a pipe.
|
|
5
|
+
import { homedir } from 'node:os';
|
|
6
|
+
import { dirname, join } from 'node:path';
|
|
7
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
8
|
+
import { envMounts, processTerminal, start } from '@elixir-playground/runtime/harness';
|
|
9
|
+
import { BUILDS, DEFAULT, parseBuild } from './builds.js';
|
|
10
|
+
import { PLAYGROUND, described } from './elixir.js';
|
|
11
|
+
import { prepare } from './prepare.js';
|
|
12
|
+
import { COMMANDS, buildName, findOtp } from './commands.js';
|
|
13
|
+
export { COMMANDS } from './commands.js';
|
|
14
|
+
// Where builds are prepared for the command: the user's cache.
|
|
15
|
+
const cacheDirectory = () => join(process.env.XDG_CACHE_HOME || join(homedir(), '.cache'), 'elixir-playground', 'elixir');
|
|
16
|
+
// Runs the command; its exit status.
|
|
17
|
+
export async function run(options) {
|
|
18
|
+
const log = options.log ?? ((line) => console.error(line));
|
|
19
|
+
const build = buildName(options.build ?? DEFAULT);
|
|
20
|
+
const { elixir, otp: major } = parseBuild(build);
|
|
21
|
+
const command = COMMANDS[options.command];
|
|
22
|
+
if (!command)
|
|
23
|
+
throw new Error(`${options.command}: not one of ${Object.keys(COMMANDS).join(', ')}`);
|
|
24
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
25
|
+
const otp = options.otp ?? findOtp(major, [process.cwd(), here])[0];
|
|
26
|
+
if (!otp)
|
|
27
|
+
throw new Error(`Elixir ${build} runs on OTP ${major}, and no @elixir-playground/otp-${major}.… is installed: ` +
|
|
28
|
+
`npx -p @elixir-playground/otp-${major}.… -p @elixir-playground/elixir elixir-playground-elixir …, ` +
|
|
29
|
+
'or --otp DIR');
|
|
30
|
+
// A build the package was not tested with runs too, checked against
|
|
31
|
+
// builds.hex.pm's builds.txt.
|
|
32
|
+
if (!BUILDS[build])
|
|
33
|
+
log(`elixir: Elixir ${build} is not among the builds this package was tested with`);
|
|
34
|
+
const cache = cacheDirectory();
|
|
35
|
+
await prepare({
|
|
36
|
+
build,
|
|
37
|
+
otp,
|
|
38
|
+
into: cache,
|
|
39
|
+
archives: options.archives,
|
|
40
|
+
cache: join(cache, 'downloads'),
|
|
41
|
+
untested: true,
|
|
42
|
+
log,
|
|
43
|
+
});
|
|
44
|
+
const descriptor = {
|
|
45
|
+
name: '@elixir-playground/elixir',
|
|
46
|
+
version: '0.0.0',
|
|
47
|
+
base: pathToFileURL(`${cache}/`).href,
|
|
48
|
+
files: {},
|
|
49
|
+
playground: PLAYGROUND,
|
|
50
|
+
};
|
|
51
|
+
const root = `/opt/elixir/${elixir}`;
|
|
52
|
+
const terminal = processTerminal();
|
|
53
|
+
const node = await start({
|
|
54
|
+
packages: [otp, ...described(descriptor, build, { archives: options.archives })],
|
|
55
|
+
args: [
|
|
56
|
+
'-noshell',
|
|
57
|
+
'-elixir_root',
|
|
58
|
+
`${root}/lib`,
|
|
59
|
+
'-pa',
|
|
60
|
+
`${root}/lib/elixir/ebin`,
|
|
61
|
+
...command(root),
|
|
62
|
+
...options.args,
|
|
63
|
+
],
|
|
64
|
+
mounts: envMounts(),
|
|
65
|
+
...terminal.options,
|
|
66
|
+
});
|
|
67
|
+
return terminal.attach(node);
|
|
68
|
+
}
|
package/zip.d.ts
ADDED
package/zip.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// A zip archive's files (Elixir's precompiled builds): stored or deflated
|
|
2
|
+
// entries, read through the central directory. No ZIP64, no encryption.
|
|
3
|
+
import { inflateRawSync } from 'node:zlib';
|
|
4
|
+
export function unzip(zip) {
|
|
5
|
+
const view = new DataView(zip.buffer, zip.byteOffset, zip.byteLength);
|
|
6
|
+
// The end of central directory record: its signature, searched from the
|
|
7
|
+
// end (a comment may follow it).
|
|
8
|
+
let end = zip.length - 22;
|
|
9
|
+
while (end >= 0 && view.getUint32(end, true) !== 0x06054b50)
|
|
10
|
+
end--;
|
|
11
|
+
if (end < 0)
|
|
12
|
+
throw new Error('not a zip archive');
|
|
13
|
+
const count = view.getUint16(end + 10, true);
|
|
14
|
+
let at = view.getUint32(end + 16, true);
|
|
15
|
+
const decoder = new TextDecoder();
|
|
16
|
+
const out = [];
|
|
17
|
+
for (let i = 0; i < count; i++) {
|
|
18
|
+
if (view.getUint32(at, true) !== 0x02014b50)
|
|
19
|
+
throw new Error('a broken central directory');
|
|
20
|
+
const method = view.getUint16(at + 10, true);
|
|
21
|
+
const compressed = view.getUint32(at + 20, true);
|
|
22
|
+
const nameLength = view.getUint16(at + 28, true);
|
|
23
|
+
const extraLength = view.getUint16(at + 30, true);
|
|
24
|
+
const commentLength = view.getUint16(at + 32, true);
|
|
25
|
+
const external = view.getUint32(at + 38, true);
|
|
26
|
+
const local = view.getUint32(at + 42, true);
|
|
27
|
+
const name = decoder.decode(zip.subarray(at + 46, at + 46 + nameLength));
|
|
28
|
+
at += 46 + nameLength + extraLength + commentLength;
|
|
29
|
+
if (name.endsWith('/'))
|
|
30
|
+
continue;
|
|
31
|
+
// The local header's own name and extra field come before the data.
|
|
32
|
+
const start = local + 30 + view.getUint16(local + 26, true) + view.getUint16(local + 28, true);
|
|
33
|
+
const raw = zip.subarray(start, start + compressed);
|
|
34
|
+
let data;
|
|
35
|
+
if (method === 0)
|
|
36
|
+
data = raw;
|
|
37
|
+
else if (method === 8)
|
|
38
|
+
data = new Uint8Array(inflateRawSync(raw));
|
|
39
|
+
else
|
|
40
|
+
throw new Error(`${name}: compression method ${method}`);
|
|
41
|
+
out.push({ name, mode: external >>> 16, data });
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
package/README.md
DELETED