eliscript 0.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 +674 -0
- package/README.md +135 -0
- package/bin/eliscript +16 -0
- package/bin/eliscript-bootstrap +15 -0
- package/bin/eliscript-build +15 -0
- package/bin/eliscript-check +15 -0
- package/bin/eliscript-eval +15 -0
- package/bin/eliscript-format +15 -0
- package/bin/eliscript-org +10 -0
- package/bin/eliscript-portable +17 -0
- package/bin/eliscript-seed +10 -0
- package/bin/eliscript-seed-build +10 -0
- package/bin/eliscript-watch +15 -0
- package/bootstrap/README.md +100 -0
- package/bootstrap/compiler/analyzer.eli +1426 -0
- package/bootstrap/compiler/compiler.eli +472 -0
- package/bootstrap/compiler/emitter.eli +1745 -0
- package/bootstrap/compiler/expander.eli +2522 -0
- package/bootstrap/compiler/formatter.eli +359 -0
- package/bootstrap/compiler/ir.eli +297 -0
- package/bootstrap/compiler/lower.eli +661 -0
- package/bootstrap/compiler/project.eli +1120 -0
- package/bootstrap/compiler/reader.eli +321 -0
- package/bootstrap/compiler/source-map.eli +165 -0
- package/bootstrap/compiler/symbol.eli +92 -0
- package/bootstrap/compiler/syntax.eli +54 -0
- package/bootstrap/compiler/transient-analysis.eli +825 -0
- package/bootstrap/host/build.mjs +28 -0
- package/bootstrap/host/bun.mjs +282 -0
- package/bootstrap/host/check-cli.mjs +163 -0
- package/bootstrap/host/eliscript-cli.mjs +36 -0
- package/bootstrap/host/evaluation-cli.mjs +401 -0
- package/bootstrap/host/evaluation.mjs +560 -0
- package/bootstrap/host/format-cli.mjs +139 -0
- package/bootstrap/host/project-cli.mjs +295 -0
- package/bootstrap/host/project.mjs +1080 -0
- package/bootstrap/host/watch-cli.mjs +129 -0
- package/bootstrap/host/watch.mjs +267 -0
- package/browser/host.mjs +357 -0
- package/browser/worker.mjs +60 -0
- package/compiler/README.md +118 -0
- package/compiler/eliscript-analyzer.el +716 -0
- package/compiler/eliscript-cli.el +108 -0
- package/compiler/eliscript-diagnostic.el +158 -0
- package/compiler/eliscript-emitter.el +1351 -0
- package/compiler/eliscript-evaluation.el +259 -0
- package/compiler/eliscript-expander.el +1630 -0
- package/compiler/eliscript-form.el +79 -0
- package/compiler/eliscript-ir-emitter.el +1460 -0
- package/compiler/eliscript-ir.el +356 -0
- package/compiler/eliscript-lower.el +463 -0
- package/compiler/eliscript-macro-eval.el +811 -0
- package/compiler/eliscript-parameters.el +324 -0
- package/compiler/eliscript-portable.el +492 -0
- package/compiler/eliscript-project-cli.el +156 -0
- package/compiler/eliscript-project.el +1676 -0
- package/compiler/eliscript-reader.el +421 -0
- package/compiler/eliscript-source-map.el +192 -0
- package/compiler/eliscript-symbol.el +101 -0
- package/compiler/eliscript-transient-analysis.el +817 -0
- package/compiler/eliscript.el +239 -0
- package/dist/bootstrap/analyzer.mjs +968 -0
- package/dist/bootstrap/analyzer.mjs.map +1 -0
- package/dist/bootstrap/compiler.mjs +228 -0
- package/dist/bootstrap/compiler.mjs.map +1 -0
- package/dist/bootstrap/emitter.mjs +1173 -0
- package/dist/bootstrap/emitter.mjs.map +1 -0
- package/dist/bootstrap/expander.mjs +1469 -0
- package/dist/bootstrap/expander.mjs.map +1 -0
- package/dist/bootstrap/formatter.mjs +304 -0
- package/dist/bootstrap/formatter.mjs.map +1 -0
- package/dist/bootstrap/ir.mjs +193 -0
- package/dist/bootstrap/ir.mjs.map +1 -0
- package/dist/bootstrap/lower.mjs +344 -0
- package/dist/bootstrap/lower.mjs.map +1 -0
- package/dist/bootstrap/project.mjs +585 -0
- package/dist/bootstrap/project.mjs.map +1 -0
- package/dist/bootstrap/reader.mjs +259 -0
- package/dist/bootstrap/reader.mjs.map +1 -0
- package/dist/bootstrap/source-map.mjs +154 -0
- package/dist/bootstrap/source-map.mjs.map +1 -0
- package/dist/bootstrap/symbol.mjs +74 -0
- package/dist/bootstrap/symbol.mjs.map +1 -0
- package/dist/bootstrap/syntax.mjs +38 -0
- package/dist/bootstrap/syntax.mjs.map +1 -0
- package/dist/bootstrap/transient-analysis.mjs +660 -0
- package/dist/bootstrap/transient-analysis.mjs.map +1 -0
- package/dist/browser/compiler.js +6491 -0
- package/editor/README.md +83 -0
- package/editor/eliscript-mode.el +878 -0
- package/editor/eliscript-repl.el +501 -0
- package/package.json +163 -0
- package/platform/README.md +48 -0
- package/platform/browser.mjs +204 -0
- package/platform/worker.mjs +166 -0
- package/runtime/README.md +296 -0
- package/runtime/core/collection-internals.mjs +512 -0
- package/runtime/core/collection.mjs +645 -0
- package/runtime/core/data-text.mjs +532 -0
- package/runtime/core/data.mjs +268 -0
- package/runtime/core/identifier.mjs +314 -0
- package/runtime/core/lazy-sequence.mjs +244 -0
- package/runtime/core/list-internals.mjs +18 -0
- package/runtime/core/list.mjs +273 -0
- package/runtime/core/map-internals.mjs +793 -0
- package/runtime/core/map.mjs +394 -0
- package/runtime/core/metadata-internals.mjs +14 -0
- package/runtime/core/metadata.mjs +44 -0
- package/runtime/core/object-impl.mjs +65 -0
- package/runtime/core/object-impl.mjs.map +1 -0
- package/runtime/core/object.mjs +13 -0
- package/runtime/core/order.mjs +234 -0
- package/runtime/core/persistent-kind.mjs +43 -0
- package/runtime/core/protocol-error.mjs +36 -0
- package/runtime/core/protocol-impl.mjs +326 -0
- package/runtime/core/protocol-impl.mjs.map +1 -0
- package/runtime/core/protocol.mjs +14 -0
- package/runtime/core/queue-internals.mjs +27 -0
- package/runtime/core/queue.mjs +238 -0
- package/runtime/core/record.mjs +346 -0
- package/runtime/core/regex.mjs +184 -0
- package/runtime/core/sequence.mjs +632 -0
- package/runtime/core/set-algebra.mjs +287 -0
- package/runtime/core/set-internals.mjs +33 -0
- package/runtime/core/set.mjs +378 -0
- package/runtime/core/sorted-internals.mjs +215 -0
- package/runtime/core/sorted.mjs +598 -0
- package/runtime/core/text-impl.mjs +95 -0
- package/runtime/core/text-impl.mjs.map +1 -0
- package/runtime/core/text.mjs +15 -0
- package/runtime/core/transducer.mjs +668 -0
- package/runtime/core/transient-internals.mjs +38 -0
- package/runtime/core/transient.mjs +53 -0
- package/runtime/core/truth.mjs +3 -0
- package/runtime/core/type.mjs +262 -0
- package/runtime/core/value-internals.mjs +188 -0
- package/runtime/core/value.mjs +93 -0
- package/runtime/core/vector-internals.mjs +102 -0
- package/runtime/core/vector.mjs +951 -0
- package/runtime/literals.mjs +34 -0
- package/runtime/source-mapping.mjs +220 -0
- package/runtime/testing/list.mjs +52 -0
- package/runtime/testing/map.mjs +145 -0
- package/runtime/testing/queue.mjs +49 -0
- package/runtime/testing/set.mjs +61 -0
- package/runtime/testing/sorted.mjs +105 -0
- package/runtime/testing/value.mjs +17 -0
- package/runtime/testing/vector.mjs +102 -0
- package/runtime/worker-value-codec.mjs +565 -0
- package/runtime/worker-value-stream.mjs +786 -0
- package/runtime/worker.mjs +975 -0
- package/stdlib/README.md +774 -0
- package/stdlib/bit.eli +36 -0
- package/stdlib/core/collection.eli +134 -0
- package/stdlib/core/data-text.eli +16 -0
- package/stdlib/core/data.eli +306 -0
- package/stdlib/core/identifier.eli +32 -0
- package/stdlib/core/lazy-sequence.eli +63 -0
- package/stdlib/core/metadata.eli +20 -0
- package/stdlib/core/object.eli +89 -0
- package/stdlib/core/order.eli +133 -0
- package/stdlib/core/protocol.eli +387 -0
- package/stdlib/core/record.eli +16 -0
- package/stdlib/core/regex.eli +17 -0
- package/stdlib/core/seq.eli +701 -0
- package/stdlib/core/set.eli +312 -0
- package/stdlib/core/sorted.eli +53 -0
- package/stdlib/core/text.eli +103 -0
- package/stdlib/core/transducer.eli +59 -0
- package/stdlib/core/transient.eli +24 -0
- package/stdlib/core/type.eli +19 -0
- package/stdlib/core/walk.eli +195 -0
- package/stdlib/core/zipper.eli +508 -0
- package/stdlib/data-text.eli +1092 -0
- package/stdlib/data.eli +42 -0
- package/stdlib/deferred.eli +70 -0
- package/stdlib/function.eli +120 -0
- package/stdlib/hierarchy.eli +245 -0
- package/stdlib/identifier.eli +147 -0
- package/stdlib/interop/js.eli +616 -0
- package/stdlib/json.eli +870 -0
- package/stdlib/metadata.eli +56 -0
- package/stdlib/multimethod.eli +464 -0
- package/stdlib/numeric.eli +193 -0
- package/stdlib/object.eli +96 -0
- package/stdlib/persistent-list.eli +145 -0
- package/stdlib/persistent-map.eli +724 -0
- package/stdlib/persistent-queue.eli +32 -0
- package/stdlib/persistent-set.eli +236 -0
- package/stdlib/persistent-vector.eli +342 -0
- package/stdlib/result.eli +141 -0
- package/stdlib/sequence.eli +106 -0
- package/stdlib/state/atom.eli +265 -0
- package/stdlib/text.eli +88 -0
- package/stdlib/value.eli +325 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { compileFile, loadCompiler } from "./bun.mjs";
|
|
2
|
+
import { buildProject } from "./project.mjs";
|
|
3
|
+
|
|
4
|
+
export async function executeBuild(options) {
|
|
5
|
+
const compiler = options.compiler ?? await loadCompiler(options.moduleDirectory);
|
|
6
|
+
const request = compiler.build_operation_request(options);
|
|
7
|
+
if (request.mode === "single") {
|
|
8
|
+
return compileFile({ ...request, compiler });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const projectOptions = {
|
|
12
|
+
entry: request.entry,
|
|
13
|
+
entries: request.entries,
|
|
14
|
+
outDir: request.outDir,
|
|
15
|
+
root: request.root,
|
|
16
|
+
portableEntries: request.portableEntries,
|
|
17
|
+
macroCapabilities: request.macroCapabilities,
|
|
18
|
+
macroFileDependencies: request.macroFileDependencies,
|
|
19
|
+
useCache: request.useCache,
|
|
20
|
+
sourceOverrides: options.sourceOverrides,
|
|
21
|
+
moduleDirectory: options.moduleDirectory,
|
|
22
|
+
};
|
|
23
|
+
if (options.compiler !== undefined) {
|
|
24
|
+
projectOptions.compiler = compiler;
|
|
25
|
+
projectOptions.compilerDigest = options.compilerDigest;
|
|
26
|
+
}
|
|
27
|
+
return buildProject(projectOptions);
|
|
28
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
lstat,
|
|
5
|
+
mkdir,
|
|
6
|
+
readFile,
|
|
7
|
+
realpath,
|
|
8
|
+
stat,
|
|
9
|
+
writeFile,
|
|
10
|
+
} from "node:fs/promises";
|
|
11
|
+
import { basename, dirname, relative, resolve } from "node:path";
|
|
12
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
13
|
+
|
|
14
|
+
const commandName = process.env.ELISCRIPT_COMMAND_NAME ?? "eliscript-portable";
|
|
15
|
+
const usage = `Usage: ${commandName} [OPTIONS] INPUT
|
|
16
|
+
|
|
17
|
+
Options:
|
|
18
|
+
-o, --output FILE Write the generated ECMAScript module to FILE
|
|
19
|
+
--source-map Write FILE.map and add a sourceMappingURL comment
|
|
20
|
+
--portable NAME Emit a worker entry and its transitive dependencies
|
|
21
|
+
--diagnostic-format human|json
|
|
22
|
+
Select human-readable or JSON failures
|
|
23
|
+
-h, --help Show this help
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
const diagnosticFormat = "eliscript-diagnostic";
|
|
27
|
+
const diagnosticVersion = 1;
|
|
28
|
+
|
|
29
|
+
export function requestedDiagnosticFormat(arguments_) {
|
|
30
|
+
for (let index = 0; index < arguments_.length - 1; index += 1) {
|
|
31
|
+
if (arguments_[index] === "--diagnostic-format" &&
|
|
32
|
+
arguments_[index + 1] === "json") {
|
|
33
|
+
return "json";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return "human";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function parseArguments(arguments_) {
|
|
40
|
+
const argumentsList = [...arguments_];
|
|
41
|
+
if (argumentsList[0] === "--") argumentsList.shift();
|
|
42
|
+
let input;
|
|
43
|
+
let output;
|
|
44
|
+
let sourceMap = false;
|
|
45
|
+
let diagnosticOutput = "human";
|
|
46
|
+
const portableEntries = [];
|
|
47
|
+
|
|
48
|
+
while (argumentsList.length > 0) {
|
|
49
|
+
const argument = argumentsList.shift();
|
|
50
|
+
if (argument === "-h" || argument === "--help") {
|
|
51
|
+
return { help: true };
|
|
52
|
+
}
|
|
53
|
+
if (argument === "-o" || argument === "--output") {
|
|
54
|
+
if (argumentsList.length === 0) {
|
|
55
|
+
throw new Error(`${argument} requires a file`);
|
|
56
|
+
}
|
|
57
|
+
output = argumentsList.shift();
|
|
58
|
+
} else if (argument === "--source-map") {
|
|
59
|
+
sourceMap = true;
|
|
60
|
+
} else if (argument === "--portable") {
|
|
61
|
+
if (argumentsList.length === 0) {
|
|
62
|
+
throw new Error(`${argument} requires a function name`);
|
|
63
|
+
}
|
|
64
|
+
portableEntries.push(argumentsList.shift());
|
|
65
|
+
} else if (argument === "--diagnostic-format") {
|
|
66
|
+
if (argumentsList.length === 0) {
|
|
67
|
+
throw new Error(`${argument} requires human or json`);
|
|
68
|
+
}
|
|
69
|
+
diagnosticOutput = argumentsList.shift();
|
|
70
|
+
if (diagnosticOutput !== "human" && diagnosticOutput !== "json") {
|
|
71
|
+
throw new Error(`unsupported diagnostic format: ${diagnosticOutput}`);
|
|
72
|
+
}
|
|
73
|
+
} else if (argument.startsWith("-")) {
|
|
74
|
+
throw new Error(`unknown option: ${argument}`);
|
|
75
|
+
} else if (input) {
|
|
76
|
+
throw new Error("multiple input files are not supported yet");
|
|
77
|
+
} else {
|
|
78
|
+
input = argument;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!input) throw new Error("missing input file");
|
|
83
|
+
if (sourceMap && !output) {
|
|
84
|
+
throw new Error("--source-map requires --output");
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
input,
|
|
88
|
+
output,
|
|
89
|
+
sourceMap,
|
|
90
|
+
portableEntries,
|
|
91
|
+
diagnosticFormat: diagnosticOutput,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function diagnosticFromError(error) {
|
|
96
|
+
if (error?.eliscriptDiagnostic?.format === diagnosticFormat &&
|
|
97
|
+
error.eliscriptDiagnostic.version === diagnosticVersion) {
|
|
98
|
+
return error.eliscriptDiagnostic;
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
format: diagnosticFormat,
|
|
102
|
+
version: diagnosticVersion,
|
|
103
|
+
code: "ELI-C0001",
|
|
104
|
+
severity: "error",
|
|
105
|
+
phase: "cli",
|
|
106
|
+
message: error instanceof Error ? error.message : String(error),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function renderDiagnostic(diagnostic) {
|
|
111
|
+
const location = diagnostic?.location;
|
|
112
|
+
const start = location?.start;
|
|
113
|
+
if (typeof location?.file === "string" &&
|
|
114
|
+
Number.isSafeInteger(start?.line) &&
|
|
115
|
+
Number.isSafeInteger(start?.column)) {
|
|
116
|
+
return `${location.file}:${start.line}:${start.column}: ${diagnostic.message}`;
|
|
117
|
+
}
|
|
118
|
+
return diagnostic.message;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export async function loadCompiler(moduleDirectory) {
|
|
122
|
+
const hostDirectory = dirname(fileURLToPath(import.meta.url));
|
|
123
|
+
const directory = resolve(
|
|
124
|
+
moduleDirectory ??
|
|
125
|
+
process.env.ELISCRIPT_BOOTSTRAP_MODULE_DIR ??
|
|
126
|
+
resolve(hostDirectory, "../../dist/bootstrap"),
|
|
127
|
+
);
|
|
128
|
+
return import(pathToFileURL(resolve(directory, "compiler.mjs")).href);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function physicalWritePath(path) {
|
|
132
|
+
let existing = resolve(path);
|
|
133
|
+
const missing = [];
|
|
134
|
+
|
|
135
|
+
while (true) {
|
|
136
|
+
try {
|
|
137
|
+
const metadata = await lstat(existing);
|
|
138
|
+
if (metadata.isSymbolicLink()) {
|
|
139
|
+
try {
|
|
140
|
+
const target = await realpath(existing);
|
|
141
|
+
return resolve(target, ...missing.reverse());
|
|
142
|
+
} catch (error) {
|
|
143
|
+
if (error?.code === "ENOENT" || error?.code === "ENOTDIR") {
|
|
144
|
+
throw new Error(
|
|
145
|
+
`generated artifact path contains an unresolved symbolic link: ${path}`,
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return resolve(await realpath(existing), ...missing.reverse());
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if (error?.code !== "ENOENT" && error?.code !== "ENOTDIR") throw error;
|
|
154
|
+
const parent = dirname(existing);
|
|
155
|
+
if (parent === existing) throw error;
|
|
156
|
+
missing.push(basename(existing));
|
|
157
|
+
existing = parent;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async function existingFileIdentity(path) {
|
|
163
|
+
try {
|
|
164
|
+
const metadata = await stat(path);
|
|
165
|
+
return `${metadata.dev}:${metadata.ino}`;
|
|
166
|
+
} catch (error) {
|
|
167
|
+
if (error?.code === "ENOENT" || error?.code === "ENOTDIR") return undefined;
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async function validateFileOutputPaths(inputPath, outputPaths) {
|
|
173
|
+
const inputPhysical = await realpath(inputPath);
|
|
174
|
+
const inputIdentity = await existingFileIdentity(inputPath);
|
|
175
|
+
const artifacts = [];
|
|
176
|
+
|
|
177
|
+
for (const outputPath of outputPaths) {
|
|
178
|
+
const physical = await physicalWritePath(outputPath);
|
|
179
|
+
const identity = await existingFileIdentity(outputPath);
|
|
180
|
+
if (physical === inputPhysical ||
|
|
181
|
+
(identity !== undefined && identity === inputIdentity)) {
|
|
182
|
+
throw new Error(`generated artifact must not overwrite input file: ${outputPath}`);
|
|
183
|
+
}
|
|
184
|
+
for (const artifact of artifacts) {
|
|
185
|
+
if (physical === artifact.physical ||
|
|
186
|
+
(identity !== undefined && identity === artifact.identity)) {
|
|
187
|
+
throw new Error(
|
|
188
|
+
`generated artifacts must be physically distinct: ${artifact.path} and ${outputPath}`,
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
artifacts.push({ path: outputPath, physical, identity });
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export async function compileFile(options) {
|
|
197
|
+
const compiler = options.compiler ?? await loadCompiler(options.moduleDirectory);
|
|
198
|
+
const request = compiler.build_operation_request({
|
|
199
|
+
mode: "single",
|
|
200
|
+
input: options.input,
|
|
201
|
+
output: options.output ?? null,
|
|
202
|
+
sourceMap: options.sourceMap === undefined ? false : options.sourceMap,
|
|
203
|
+
portableEntries: options.portableEntries ?? [],
|
|
204
|
+
});
|
|
205
|
+
const inputPath = resolve(request.input);
|
|
206
|
+
const outputPath = request.output ? resolve(request.output) : undefined;
|
|
207
|
+
if (outputPath) {
|
|
208
|
+
await validateFileOutputPaths(
|
|
209
|
+
inputPath,
|
|
210
|
+
request.sourceMap ? [outputPath, `${outputPath}.map`] : [outputPath],
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
const source = await readFile(inputPath, "utf8");
|
|
214
|
+
|
|
215
|
+
if (!request.sourceMap) {
|
|
216
|
+
const javascript = request.portableEntries.length > 0
|
|
217
|
+
? compiler.compile_portable_string(
|
|
218
|
+
source,
|
|
219
|
+
request.portableEntries,
|
|
220
|
+
inputPath,
|
|
221
|
+
)
|
|
222
|
+
: compiler.compile_string(source, inputPath);
|
|
223
|
+
if (outputPath) {
|
|
224
|
+
await mkdir(dirname(outputPath), { recursive: true });
|
|
225
|
+
await writeFile(outputPath, javascript);
|
|
226
|
+
}
|
|
227
|
+
return { javascript };
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (!outputPath) throw new Error("--source-map requires --output");
|
|
231
|
+
const mapPath = `${outputPath}.map`;
|
|
232
|
+
const mapDirectory = dirname(mapPath);
|
|
233
|
+
const generatedName = relative(mapDirectory, outputPath);
|
|
234
|
+
const sourceName = relative(mapDirectory, inputPath);
|
|
235
|
+
const emission = request.portableEntries.length > 0
|
|
236
|
+
? compiler.compile_portable_string_with_source_map(
|
|
237
|
+
source,
|
|
238
|
+
request.portableEntries,
|
|
239
|
+
inputPath,
|
|
240
|
+
generatedName,
|
|
241
|
+
sourceName,
|
|
242
|
+
)
|
|
243
|
+
: compiler.compile_string_with_source_map(
|
|
244
|
+
source,
|
|
245
|
+
inputPath,
|
|
246
|
+
generatedName,
|
|
247
|
+
sourceName,
|
|
248
|
+
);
|
|
249
|
+
const mapUrl = relative(dirname(outputPath), mapPath);
|
|
250
|
+
const javascript = `${emission.javascript}//# sourceMappingURL=${mapUrl}\n`;
|
|
251
|
+
|
|
252
|
+
await mkdir(mapDirectory, { recursive: true });
|
|
253
|
+
await writeFile(mapPath, emission.sourceMap);
|
|
254
|
+
await mkdir(dirname(outputPath), { recursive: true });
|
|
255
|
+
await writeFile(outputPath, javascript);
|
|
256
|
+
return { javascript, sourceMap: emission.sourceMap };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export async function main(arguments_ = process.argv.slice(2)) {
|
|
260
|
+
const options = parseArguments(arguments_);
|
|
261
|
+
if (options.help) {
|
|
262
|
+
process.stdout.write(usage);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const { executeBuild } = await import("./build.mjs");
|
|
266
|
+
const result = await executeBuild({ mode: "single", ...options });
|
|
267
|
+
if (!options.output) process.stdout.write(result.javascript);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const isMain = process.argv[1] !== undefined &&
|
|
271
|
+
resolve(process.argv[1]) === fileURLToPath(import.meta.url);
|
|
272
|
+
if (isMain) {
|
|
273
|
+
const outputFormat = requestedDiagnosticFormat(process.argv.slice(2));
|
|
274
|
+
main().catch((error) => {
|
|
275
|
+
if (outputFormat === "json") {
|
|
276
|
+
console.error(JSON.stringify(diagnosticFromError(error)));
|
|
277
|
+
} else {
|
|
278
|
+
console.error(`eliscript: ${error.message}`);
|
|
279
|
+
}
|
|
280
|
+
process.exitCode = 1;
|
|
281
|
+
});
|
|
282
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
diagnosticFromError,
|
|
9
|
+
loadCompiler,
|
|
10
|
+
renderDiagnostic,
|
|
11
|
+
requestedDiagnosticFormat,
|
|
12
|
+
} from "./bun.mjs";
|
|
13
|
+
import { checkProject } from "./project.mjs";
|
|
14
|
+
import { readProjectConfiguration } from "./project-cli.mjs";
|
|
15
|
+
|
|
16
|
+
const usage = `Usage: eliscript-check [OPTIONS] [ENTRY ...]
|
|
17
|
+
|
|
18
|
+
Options:
|
|
19
|
+
--config FILE Read entries and root from a versioned project request
|
|
20
|
+
--root DIR Contain local source imports below DIR
|
|
21
|
+
--portable NAME Check NAME and its transitive portable closure
|
|
22
|
+
--stdin-file FILE Use standard input as the current contents of FILE
|
|
23
|
+
--json Print the versioned project check report
|
|
24
|
+
--diagnostic-format human|json
|
|
25
|
+
Select human-readable or JSON failures
|
|
26
|
+
-h, --help Show this help
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
export function parseArguments(arguments_) {
|
|
30
|
+
const argumentsList = [...arguments_];
|
|
31
|
+
if (argumentsList[0] === "--") argumentsList.shift();
|
|
32
|
+
const entries = [];
|
|
33
|
+
const portableEntries = [];
|
|
34
|
+
let configuration;
|
|
35
|
+
let root;
|
|
36
|
+
let stdinFile;
|
|
37
|
+
let jsonReport = false;
|
|
38
|
+
let diagnosticFormat = "human";
|
|
39
|
+
|
|
40
|
+
while (argumentsList.length > 0) {
|
|
41
|
+
const argument = argumentsList.shift();
|
|
42
|
+
if (argument === "-h" || argument === "--help") return { help: true };
|
|
43
|
+
if (argument === "--config") {
|
|
44
|
+
if (argumentsList.length === 0) throw new Error(`${argument} requires a file`);
|
|
45
|
+
if (configuration !== undefined) {
|
|
46
|
+
throw new Error("multiple --config files are not supported");
|
|
47
|
+
}
|
|
48
|
+
configuration = argumentsList.shift();
|
|
49
|
+
} else if (argument === "--root") {
|
|
50
|
+
if (argumentsList.length === 0) throw new Error(`${argument} requires a directory`);
|
|
51
|
+
root = argumentsList.shift();
|
|
52
|
+
} else if (argument === "--portable") {
|
|
53
|
+
if (argumentsList.length === 0) throw new Error(`${argument} requires an entry name`);
|
|
54
|
+
portableEntries.push(argumentsList.shift());
|
|
55
|
+
} else if (argument === "--stdin-file") {
|
|
56
|
+
if (argumentsList.length === 0) throw new Error(`${argument} requires a file`);
|
|
57
|
+
if (stdinFile !== undefined) {
|
|
58
|
+
throw new Error("multiple --stdin-file values are not supported");
|
|
59
|
+
}
|
|
60
|
+
stdinFile = argumentsList.shift();
|
|
61
|
+
} else if (argument === "--json") {
|
|
62
|
+
jsonReport = true;
|
|
63
|
+
} else if (argument === "--diagnostic-format") {
|
|
64
|
+
if (argumentsList.length === 0) {
|
|
65
|
+
throw new Error(`${argument} requires human or json`);
|
|
66
|
+
}
|
|
67
|
+
diagnosticFormat = argumentsList.shift();
|
|
68
|
+
if (diagnosticFormat !== "human" && diagnosticFormat !== "json") {
|
|
69
|
+
throw new Error(`unsupported diagnostic format: ${diagnosticFormat}`);
|
|
70
|
+
}
|
|
71
|
+
} else if (argument.startsWith("-")) {
|
|
72
|
+
throw new Error(`unknown option: ${argument}`);
|
|
73
|
+
} else {
|
|
74
|
+
entries.push(argument);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (configuration === undefined && entries.length === 0) {
|
|
79
|
+
throw new Error("missing entry file");
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
entry: entries.length === 1 ? entries[0] : undefined,
|
|
83
|
+
entries: entries.length > 1 ? entries : undefined,
|
|
84
|
+
root,
|
|
85
|
+
portableEntries,
|
|
86
|
+
configuration,
|
|
87
|
+
stdinFile,
|
|
88
|
+
jsonReport,
|
|
89
|
+
diagnosticFormat,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export async function execute(arguments_, options = {}) {
|
|
94
|
+
const parsed = parseArguments(arguments_);
|
|
95
|
+
if (parsed.help) return { help: true };
|
|
96
|
+
const compiler = options.compiler ?? await loadCompiler(options.moduleDirectory);
|
|
97
|
+
let request;
|
|
98
|
+
if (parsed.configuration !== undefined) {
|
|
99
|
+
const configured = await readProjectConfiguration(parsed.configuration, compiler);
|
|
100
|
+
request = {
|
|
101
|
+
entry: configured.entry,
|
|
102
|
+
entries: configured.entries,
|
|
103
|
+
root: configured.root,
|
|
104
|
+
portableEntries: configured.portableEntries,
|
|
105
|
+
};
|
|
106
|
+
if (parsed.entries !== undefined) {
|
|
107
|
+
request.entries = parsed.entries;
|
|
108
|
+
delete request.entry;
|
|
109
|
+
} else if (parsed.entry !== undefined) {
|
|
110
|
+
request.entry = parsed.entry;
|
|
111
|
+
delete request.entries;
|
|
112
|
+
}
|
|
113
|
+
if (parsed.root !== undefined) request.root = parsed.root;
|
|
114
|
+
if (parsed.portableEntries.length > 0) {
|
|
115
|
+
request.portableEntries = parsed.portableEntries;
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
request = {
|
|
119
|
+
entry: parsed.entry,
|
|
120
|
+
entries: parsed.entries,
|
|
121
|
+
root: parsed.root,
|
|
122
|
+
portableEntries: parsed.portableEntries,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
let sourceOverrides;
|
|
126
|
+
if (parsed.stdinFile !== undefined) {
|
|
127
|
+
const sourceText = options.stdinSource ?? await readFile(0, "utf8");
|
|
128
|
+
sourceOverrides = { [resolve(parsed.stdinFile)]: sourceText };
|
|
129
|
+
}
|
|
130
|
+
const result = await checkProject({
|
|
131
|
+
...request,
|
|
132
|
+
sourceOverrides,
|
|
133
|
+
compiler,
|
|
134
|
+
moduleDirectory: options.moduleDirectory,
|
|
135
|
+
});
|
|
136
|
+
return { result, jsonReport: parsed.jsonReport };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export async function main(arguments_ = process.argv.slice(2)) {
|
|
140
|
+
const execution = await execute(arguments_);
|
|
141
|
+
if (execution.help) {
|
|
142
|
+
process.stdout.write(usage);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
process.stdout.write(execution.jsonReport
|
|
146
|
+
? `${JSON.stringify(execution.result.report)}\n`
|
|
147
|
+
: `Checked ${execution.result.report.counts.modules} modules.\n`);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const isMain = process.argv[1] !== undefined &&
|
|
151
|
+
resolve(process.argv[1]) === fileURLToPath(import.meta.url);
|
|
152
|
+
if (isMain) {
|
|
153
|
+
const outputFormat = requestedDiagnosticFormat(process.argv.slice(2));
|
|
154
|
+
main().catch((error) => {
|
|
155
|
+
const diagnostic = diagnosticFromError(error);
|
|
156
|
+
if (outputFormat === "json") {
|
|
157
|
+
console.error(JSON.stringify(diagnostic));
|
|
158
|
+
} else {
|
|
159
|
+
console.error(`eliscript-check: ${renderDiagnostic(diagnostic)}`);
|
|
160
|
+
}
|
|
161
|
+
process.exitCode = 1;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//
|
|
3
|
+
// Node entry point for the packaged command line.
|
|
4
|
+
//
|
|
5
|
+
// The shell wrappers beside this file locate the checkout through their own
|
|
6
|
+
// path and default to Bun. An installed package has neither a checkout URL nor
|
|
7
|
+
// a guaranteed Bun, so this entry derives the package root from its own
|
|
8
|
+
// location, defaults to the Node runtime it is already running under, and
|
|
9
|
+
// dispatches on the name the command was invoked as. Every name in `bin` points
|
|
10
|
+
// here.
|
|
11
|
+
|
|
12
|
+
import { basename, dirname, resolve } from "node:path";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
|
|
15
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
const root = resolve(here, "../..");
|
|
17
|
+
|
|
18
|
+
// The generated compiler sits beside the package. The shell wrappers read the
|
|
19
|
+
// same variable, so both entry points agree on one location.
|
|
20
|
+
process.env.ELISCRIPT_BOOTSTRAP_MODULE_DIR ??= resolve(root, "dist/bootstrap");
|
|
21
|
+
|
|
22
|
+
const commands = {
|
|
23
|
+
"eliscript": ["bun.mjs", "eliscript"],
|
|
24
|
+
"eliscript-build": ["project-cli.mjs", "eliscript-build"],
|
|
25
|
+
"eliscript-check": ["check-cli.mjs", "eliscript-check"],
|
|
26
|
+
"eliscript-format": ["format-cli.mjs", "eliscript-format"],
|
|
27
|
+
"eliscript-eval": ["evaluation-cli.mjs", "eliscript-eval"],
|
|
28
|
+
"eliscript-watch": ["watch-cli.mjs", "eliscript-watch"],
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const invoked = basename(process.argv[1] ?? "");
|
|
32
|
+
const [entry, commandName] = commands[invoked] ?? commands.eliscript;
|
|
33
|
+
process.env.ELISCRIPT_COMMAND_NAME ??= commandName;
|
|
34
|
+
|
|
35
|
+
const { main } = await import(new URL(`./${entry}`, import.meta.url));
|
|
36
|
+
await main(process.argv.slice(2));
|