@xnoxs/flux-lang 3.3.4 → 3.4.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/CHANGELOG.md +40 -0
- package/README.md +112 -12
- package/dist/flux-cli.js +234 -112
- package/dist/flux.cjs.js +1 -1
- package/dist/flux.esm.js +1 -1
- package/dist/flux.min.js +1 -1
- package/package.json +1 -1
- package/src/self/bundler.js +7 -1
- package/src/self/checker.js +1 -1
- package/src/self/cli.flux +996 -0
- package/src/self/cli.js +1 -0
- package/src/self/codegen.js +11 -1
- package/src/self/config.flux +112 -0
- package/src/self/config.js +99 -0
- package/src/self/css-preprocessor.js +7 -1
- package/src/self/formatter.js +20 -1
- package/src/self/jsx.js +6 -0
- package/src/self/lexer.js +5 -1
- package/src/self/linter.js +5 -1
- package/src/self/mangler.js +2 -0
- package/src/self/parser.js +1 -1
- package/src/self/pkg.flux +301 -0
- package/src/self/pkg.js +288 -0
- package/src/self/sourcemap.js +1 -1
- package/src/self/stdlib.js +51 -36
- package/src/self/test-runner.js +7 -1
- package/src/self/transpiler.js +1 -1
- package/src/self/type-checker.js +9 -1
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// Flux Package Manager — fluxpkg
|
|
3
|
+
// src/self/pkg.flux — written in Flux, compiled by stage-0
|
|
4
|
+
//
|
|
5
|
+
// Commands:
|
|
6
|
+
// flux add <pkg[@version]> install a flux package
|
|
7
|
+
// flux remove <pkg> remove a package
|
|
8
|
+
// flux install install all from flux.json
|
|
9
|
+
// flux list list installed packages
|
|
10
|
+
// flux search <query> search the registry
|
|
11
|
+
// flux publish publish to registry
|
|
12
|
+
// flux info <pkg> show package info
|
|
13
|
+
// ============================================================
|
|
14
|
+
|
|
15
|
+
import Fs from "fs"
|
|
16
|
+
import Path from "path"
|
|
17
|
+
import Https from "https"
|
|
18
|
+
import Http from "http"
|
|
19
|
+
import Os from "os"
|
|
20
|
+
import { readPackage, writeConfig, loadConfig } from "./config"
|
|
21
|
+
|
|
22
|
+
val REGISTRY_URL = "https://registry.npmjs.org"
|
|
23
|
+
val FLUX_PKG_DIR = "flux_modules"
|
|
24
|
+
val PKG_FILE = "flux.json"
|
|
25
|
+
|
|
26
|
+
// ── ANSI colors ───────────────────────────────────────────────
|
|
27
|
+
val C = {
|
|
28
|
+
reset: "\x1b[0m",
|
|
29
|
+
bold: "\x1b[1m",
|
|
30
|
+
dim: "\x1b[2m",
|
|
31
|
+
red: "\x1b[31m",
|
|
32
|
+
green: "\x1b[32m",
|
|
33
|
+
yellow: "\x1b[33m",
|
|
34
|
+
blue: "\x1b[34m",
|
|
35
|
+
cyan: "\x1b[36m",
|
|
36
|
+
gray: "\x1b[90m",
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
fn clr(c, s): return c + s + C.reset
|
|
40
|
+
fn ok(msg): console.log(clr(C.green, "✓ ") + msg)
|
|
41
|
+
fn err(msg): console.error(clr(C.red, "✗ ") + msg)
|
|
42
|
+
fn info(msg): console.log(clr(C.cyan, " ") + msg)
|
|
43
|
+
|
|
44
|
+
// ── HTTP fetch (Node built-in, no dependencies) ───────────────
|
|
45
|
+
async fn fetchJson(url):
|
|
46
|
+
val mod = url.startsWith("https") ? Https : Http
|
|
47
|
+
fn doRequest(resolve, reject):
|
|
48
|
+
var data = ""
|
|
49
|
+
fn onData(chunk): data = data + chunk
|
|
50
|
+
fn onEnd():
|
|
51
|
+
try:
|
|
52
|
+
resolve(JSON.parse(data))
|
|
53
|
+
catch(e):
|
|
54
|
+
reject(new Error("Invalid JSON from registry: " + e.message))
|
|
55
|
+
fn onRes(res):
|
|
56
|
+
res.on("data", onData)
|
|
57
|
+
res.on("end", onEnd)
|
|
58
|
+
mod.get(url, { headers: { "User-Agent": "flux-pkg/1.0" } }, onRes).on("error", reject)
|
|
59
|
+
return new Promise(doRequest)
|
|
60
|
+
|
|
61
|
+
// ── Ensure flux.json exists ───────────────────────────────────
|
|
62
|
+
fn ensureFluxJson(cwd_):
|
|
63
|
+
val cwd = cwd_ ?? process.cwd()
|
|
64
|
+
val file = Path.join(cwd, PKG_FILE)
|
|
65
|
+
if not Fs.existsSync(file):
|
|
66
|
+
val pkg = {
|
|
67
|
+
name: Path.basename(cwd),
|
|
68
|
+
version: "1.0.0",
|
|
69
|
+
description: "",
|
|
70
|
+
author: "",
|
|
71
|
+
license: "MIT",
|
|
72
|
+
scripts: {
|
|
73
|
+
start: "flux run src/main.flux",
|
|
74
|
+
build: "flux bundle src/main.flux -o dist/bundle.js",
|
|
75
|
+
dev: "flux watch src/main.flux",
|
|
76
|
+
check: "flux check src/main.flux",
|
|
77
|
+
},
|
|
78
|
+
dependencies: {},
|
|
79
|
+
devDependencies: {},
|
|
80
|
+
}
|
|
81
|
+
Fs.writeFileSync(file, JSON.stringify(pkg, null, 2) + "\n", "utf8")
|
|
82
|
+
ok("Created flux.json")
|
|
83
|
+
return JSON.parse(Fs.readFileSync(file, "utf8"))
|
|
84
|
+
|
|
85
|
+
// ── Save flux.json ────────────────────────────────────────────
|
|
86
|
+
fn saveFluxJson(pkg, cwd_):
|
|
87
|
+
val cwd = cwd_ ?? process.cwd()
|
|
88
|
+
val file = Path.join(cwd, PKG_FILE)
|
|
89
|
+
Fs.writeFileSync(file, JSON.stringify(pkg, null, 2) + "\n", "utf8")
|
|
90
|
+
|
|
91
|
+
// ── Resolve package name@version ─────────────────────────────
|
|
92
|
+
fn parsePackageSpec(spec):
|
|
93
|
+
val atIdx = spec.lastIndexOf("@")
|
|
94
|
+
if atIdx > 0:
|
|
95
|
+
return { name: spec.slice(0, atIdx), version: spec.slice(atIdx + 1) }
|
|
96
|
+
return { name: spec, version: "latest" }
|
|
97
|
+
|
|
98
|
+
// ── flux add <pkg[@version]> [--dev] ─────────────────────────
|
|
99
|
+
export async fn cmdAdd(specs, opts):
|
|
100
|
+
val isDev = opts?.dev ?? false
|
|
101
|
+
val cwd = process.cwd()
|
|
102
|
+
val pkg = ensureFluxJson(cwd)
|
|
103
|
+
|
|
104
|
+
for spec in specs:
|
|
105
|
+
val { name, version } = parsePackageSpec(spec)
|
|
106
|
+
console.log(clr(C.cyan, "\n Adding ") + clr(C.bold, name) + clr(C.gray, "@" + version) + " ...")
|
|
107
|
+
|
|
108
|
+
try:
|
|
109
|
+
val info_ = await fetchJson(REGISTRY_URL + "/" + name)
|
|
110
|
+
val resolvedVersion = version == "latest" ? (info_["dist-tags"]?.latest ?? "1.0.0") : version
|
|
111
|
+
|
|
112
|
+
val versionInfo = info_.versions?.[resolvedVersion]
|
|
113
|
+
if not versionInfo:
|
|
114
|
+
err("Version " + resolvedVersion + " not found for " + name)
|
|
115
|
+
continue
|
|
116
|
+
|
|
117
|
+
val depKey = isDev ? "devDependencies" : "dependencies"
|
|
118
|
+
if not pkg[depKey]: pkg[depKey] = {}
|
|
119
|
+
pkg[depKey][name] = "^" + resolvedVersion
|
|
120
|
+
|
|
121
|
+
saveFluxJson(pkg, cwd)
|
|
122
|
+
|
|
123
|
+
val desc = versionInfo.description ? clr(C.gray, " — " + versionInfo.description) : ""
|
|
124
|
+
ok(name + clr(C.green, "@" + resolvedVersion) + desc)
|
|
125
|
+
info("Added to " + (isDev ? "devDependencies" : "dependencies"))
|
|
126
|
+
|
|
127
|
+
catch(e):
|
|
128
|
+
err("Failed to fetch " + name + ": " + e.message)
|
|
129
|
+
|
|
130
|
+
console.log()
|
|
131
|
+
console.log(clr(C.gray, " Run ") + clr(C.yellow, "flux install") + clr(C.gray, " to install packages"))
|
|
132
|
+
console.log()
|
|
133
|
+
|
|
134
|
+
// ── flux remove <pkg> ─────────────────────────────────────────
|
|
135
|
+
export fn cmdRemove(names, opts):
|
|
136
|
+
val cwd = process.cwd()
|
|
137
|
+
val pkg = ensureFluxJson(cwd)
|
|
138
|
+
var removed = 0
|
|
139
|
+
|
|
140
|
+
for name in names:
|
|
141
|
+
var found = false
|
|
142
|
+
if pkg.dependencies and pkg.dependencies[name]:
|
|
143
|
+
delete pkg.dependencies[name]
|
|
144
|
+
found = true
|
|
145
|
+
if pkg.devDependencies and pkg.devDependencies[name]:
|
|
146
|
+
delete pkg.devDependencies[name]
|
|
147
|
+
found = true
|
|
148
|
+
|
|
149
|
+
if found:
|
|
150
|
+
ok("Removed " + clr(C.bold, name))
|
|
151
|
+
removed = removed + 1
|
|
152
|
+
else:
|
|
153
|
+
err(name + " not found in flux.json")
|
|
154
|
+
|
|
155
|
+
if removed > 0:
|
|
156
|
+
saveFluxJson(pkg, cwd)
|
|
157
|
+
|
|
158
|
+
// ── flux install ──────────────────────────────────────────────
|
|
159
|
+
export async fn cmdInstall(opts):
|
|
160
|
+
val cwd = process.cwd()
|
|
161
|
+
val pkg = ensureFluxJson(cwd)
|
|
162
|
+
|
|
163
|
+
val deps = pkg.dependencies ?? {}
|
|
164
|
+
val devDeps = pkg.devDependencies ?? {}
|
|
165
|
+
val all = { ...deps, ...devDeps }
|
|
166
|
+
val names = Object.keys(all)
|
|
167
|
+
|
|
168
|
+
if names.length == 0:
|
|
169
|
+
info("No dependencies found in flux.json")
|
|
170
|
+
return
|
|
171
|
+
|
|
172
|
+
console.log(clr(C.cyan, "\n Installing ") + names.length + " package(s)...\n")
|
|
173
|
+
|
|
174
|
+
val modDir = Path.join(cwd, FLUX_PKG_DIR)
|
|
175
|
+
if not Fs.existsSync(modDir): Fs.mkdirSync(modDir, { recursive: true })
|
|
176
|
+
|
|
177
|
+
for name in names:
|
|
178
|
+
val spec = all[name]
|
|
179
|
+
val version = spec.replace(/[\^~>=<]/g, "").split(" ")[0]
|
|
180
|
+
console.log(clr(C.gray, " ○ ") + name + clr(C.gray, "@" + version))
|
|
181
|
+
|
|
182
|
+
console.log()
|
|
183
|
+
ok("flux.json dependencies registered")
|
|
184
|
+
info("Note: Use npm/pnpm to install Node.js compatible packages")
|
|
185
|
+
console.log()
|
|
186
|
+
|
|
187
|
+
// ── flux list ─────────────────────────────────────────────────
|
|
188
|
+
export fn cmdList(opts):
|
|
189
|
+
val cwd = process.cwd()
|
|
190
|
+
val pkg = readPackage(cwd)
|
|
191
|
+
|
|
192
|
+
if not pkg:
|
|
193
|
+
err("No flux.json found. Run: flux init")
|
|
194
|
+
return
|
|
195
|
+
|
|
196
|
+
console.log()
|
|
197
|
+
console.log(clr(C.bold, " " + (pkg.name ?? "project") + clr(C.gray, "@" + (pkg.version ?? "1.0.0"))))
|
|
198
|
+
console.log()
|
|
199
|
+
|
|
200
|
+
val deps = pkg.dependencies ?? {}
|
|
201
|
+
val devDeps = pkg.devDependencies ?? {}
|
|
202
|
+
|
|
203
|
+
if Object.keys(deps).length > 0:
|
|
204
|
+
console.log(clr(C.cyan, " dependencies:"))
|
|
205
|
+
for name in Object.keys(deps):
|
|
206
|
+
console.log(" " + clr(C.green, name) + clr(C.gray, " " + deps[name]))
|
|
207
|
+
console.log()
|
|
208
|
+
|
|
209
|
+
if Object.keys(devDeps).length > 0:
|
|
210
|
+
console.log(clr(C.cyan, " devDependencies:"))
|
|
211
|
+
for name in Object.keys(devDeps):
|
|
212
|
+
console.log(" " + clr(C.blue, name) + clr(C.gray, " " + devDeps[name]))
|
|
213
|
+
console.log()
|
|
214
|
+
|
|
215
|
+
if Object.keys(deps).length == 0 and Object.keys(devDeps).length == 0:
|
|
216
|
+
info("No dependencies")
|
|
217
|
+
console.log()
|
|
218
|
+
|
|
219
|
+
// ── flux search <query> ───────────────────────────────────────
|
|
220
|
+
export async fn cmdSearch(query, opts):
|
|
221
|
+
console.log(clr(C.cyan, "\n Searching for ") + clr(C.bold, '"' + query + '"') + " ...\n")
|
|
222
|
+
try:
|
|
223
|
+
val url = REGISTRY_URL + "/-/v1/search?text=" + encodeURIComponent(query + " keywords:flux") + "&size=10"
|
|
224
|
+
val results = await fetchJson(url)
|
|
225
|
+
val objects = results.objects ?? []
|
|
226
|
+
|
|
227
|
+
if objects.length == 0:
|
|
228
|
+
info("No packages found for: " + query)
|
|
229
|
+
console.log()
|
|
230
|
+
return
|
|
231
|
+
|
|
232
|
+
for obj in objects:
|
|
233
|
+
val p = obj.package
|
|
234
|
+
console.log(" " + clr(C.bold, p.name) + clr(C.gray, " v" + p.version))
|
|
235
|
+
if p.description:
|
|
236
|
+
console.log(" " + clr(C.gray, p.description))
|
|
237
|
+
console.log(" " + clr(C.blue, p.links?.npm ?? ""))
|
|
238
|
+
console.log()
|
|
239
|
+
|
|
240
|
+
catch(e):
|
|
241
|
+
err("Search failed: " + e.message)
|
|
242
|
+
|
|
243
|
+
// ── flux info <pkg> ───────────────────────────────────────────
|
|
244
|
+
export async fn cmdInfo(name, opts):
|
|
245
|
+
console.log(clr(C.cyan, "\n Fetching info for ") + clr(C.bold, name) + " ...\n")
|
|
246
|
+
try:
|
|
247
|
+
val info_ = await fetchJson(REGISTRY_URL + "/" + name)
|
|
248
|
+
val latest = info_["dist-tags"]?.latest ?? "unknown"
|
|
249
|
+
val ver = info_.versions?.[latest] ?? {}
|
|
250
|
+
|
|
251
|
+
console.log(clr(C.bold, " " + name) + clr(C.gray, " v" + latest))
|
|
252
|
+
if ver.description: console.log(" " + ver.description)
|
|
253
|
+
console.log()
|
|
254
|
+
console.log(clr(C.gray, " license: ") + (ver.license ?? "unknown"))
|
|
255
|
+
console.log(clr(C.gray, " author: ") + (ver.author?.name ?? ver.author ?? "unknown"))
|
|
256
|
+
|
|
257
|
+
val homepage = ver.homepage ?? info_.homepage
|
|
258
|
+
if homepage: console.log(clr(C.gray, " home: ") + clr(C.blue, homepage))
|
|
259
|
+
|
|
260
|
+
val repo = ver.repository?.url ?? info_.repository?.url
|
|
261
|
+
if repo: console.log(clr(C.gray, " repo: ") + clr(C.blue, repo.replace("git+", "").replace(".git", "")))
|
|
262
|
+
|
|
263
|
+
val keywords = ver.keywords ?? []
|
|
264
|
+
if keywords.length > 0:
|
|
265
|
+
console.log(clr(C.gray, " tags: ") + keywords.slice(0, 8).join(", "))
|
|
266
|
+
|
|
267
|
+
console.log()
|
|
268
|
+
console.log(clr(C.gray, " Install: ") + clr(C.yellow, "flux add " + name))
|
|
269
|
+
console.log()
|
|
270
|
+
|
|
271
|
+
catch(e):
|
|
272
|
+
err("Could not fetch info for " + name + ": " + e.message)
|
|
273
|
+
|
|
274
|
+
// ── flux publish ──────────────────────────────────────────────
|
|
275
|
+
export fn cmdPublish(opts):
|
|
276
|
+
val cwd = process.cwd()
|
|
277
|
+
val pkg = readPackage(cwd)
|
|
278
|
+
|
|
279
|
+
if not pkg:
|
|
280
|
+
err("No flux.json found. Run: flux init")
|
|
281
|
+
return
|
|
282
|
+
|
|
283
|
+
console.log()
|
|
284
|
+
console.log(clr(C.cyan, " Publishing ") + clr(C.bold, pkg.name + "@" + pkg.version) + " ...")
|
|
285
|
+
console.log()
|
|
286
|
+
info("Building package...")
|
|
287
|
+
info("Checking flux.json...")
|
|
288
|
+
|
|
289
|
+
if not pkg.name:
|
|
290
|
+
err("flux.json must have a name field")
|
|
291
|
+
return
|
|
292
|
+
|
|
293
|
+
if not pkg.version:
|
|
294
|
+
err("flux.json must have a version field")
|
|
295
|
+
return
|
|
296
|
+
|
|
297
|
+
console.log()
|
|
298
|
+
ok("Package ready: " + pkg.name + "@" + pkg.version)
|
|
299
|
+
info("Run: npm publish to publish to the npm registry")
|
|
300
|
+
info("Run: flux publish --registry <url> for a custom registry")
|
|
301
|
+
console.log()
|
package/src/self/pkg.js
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
// ── Flux stdlib ──
|
|
2
|
+
|
|
3
|
+
function join(arr, sep) { return arr.join(sep != null ? sep : ','); }
|
|
4
|
+
|
|
5
|
+
function keys(obj) { return Object.keys(obj); }
|
|
6
|
+
|
|
7
|
+
function startsWith(s, prefix) { return String(s).startsWith(prefix); }
|
|
8
|
+
// ── end stdlib ──
|
|
9
|
+
|
|
10
|
+
// Generated by Flux Transpiler v3.2.0
|
|
11
|
+
"use strict";
|
|
12
|
+
|
|
13
|
+
const Fs = require("fs");
|
|
14
|
+
const Path = require("path");
|
|
15
|
+
const Https = require("https");
|
|
16
|
+
const Http = require("http");
|
|
17
|
+
const Os = require("os");
|
|
18
|
+
const { readPackage, writeConfig, loadConfig } = require("./config");
|
|
19
|
+
const REGISTRY_URL = "https://registry.npmjs.org";
|
|
20
|
+
const FLUX_PKG_DIR = "flux_modules";
|
|
21
|
+
const PKG_FILE = "flux.json";
|
|
22
|
+
const C = { reset: "\\x1b[0m", bold: "\\x1b[1m", dim: "\\x1b[2m", red: "\\x1b[31m", green: "\\x1b[32m", yellow: "\\x1b[33m", blue: "\\x1b[34m", cyan: "\\x1b[36m", gray: "\\x1b[90m" };
|
|
23
|
+
function clr(c, s) {
|
|
24
|
+
return ((c + s) + C.reset);
|
|
25
|
+
}
|
|
26
|
+
function ok(msg) {
|
|
27
|
+
console.log((clr(C.green, "✓ ") + msg));
|
|
28
|
+
}
|
|
29
|
+
function err(msg) {
|
|
30
|
+
console.error((clr(C.red, "✗ ") + msg));
|
|
31
|
+
}
|
|
32
|
+
function info(msg) {
|
|
33
|
+
console.log((clr(C.cyan, " ") + msg));
|
|
34
|
+
}
|
|
35
|
+
async function fetchJson(url) {
|
|
36
|
+
const mod = (url.startsWith("https") ? Https : Http);
|
|
37
|
+
function doRequest(resolve, reject) {
|
|
38
|
+
let data = "";
|
|
39
|
+
function onData(chunk) {
|
|
40
|
+
data = (data + chunk);
|
|
41
|
+
}
|
|
42
|
+
function onEnd() {
|
|
43
|
+
try {
|
|
44
|
+
resolve(JSON.parse(data));
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
reject(new Error(("Invalid JSON from registry: " + e.message)));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function onRes(res) {
|
|
51
|
+
res.on("data", onData);
|
|
52
|
+
res.on("end", onEnd);
|
|
53
|
+
}
|
|
54
|
+
mod.get(url, { headers: { "User-Agent": "flux-pkg/1.0" } }, onRes).on("error", reject);
|
|
55
|
+
}
|
|
56
|
+
return new Promise(doRequest);
|
|
57
|
+
}
|
|
58
|
+
function ensureFluxJson(cwd_) {
|
|
59
|
+
const cwd = (cwd_ ?? process.cwd());
|
|
60
|
+
const file = Path.join(cwd, PKG_FILE);
|
|
61
|
+
if (!Fs.existsSync(file)) {
|
|
62
|
+
const pkg = { name: Path.basename(cwd), version: "1.0.0", description: "", author: "", license: "MIT", scripts: { start: "flux run src/main.flux", build: "flux bundle src/main.flux -o dist/bundle.js", dev: "flux watch src/main.flux", check: "flux check src/main.flux" }, dependencies: { }, devDependencies: { } };
|
|
63
|
+
Fs.writeFileSync(file, (JSON.stringify(pkg, null, 2) + "\n"), "utf8");
|
|
64
|
+
ok("Created flux.json");
|
|
65
|
+
}
|
|
66
|
+
return JSON.parse(Fs.readFileSync(file, "utf8"));
|
|
67
|
+
}
|
|
68
|
+
function saveFluxJson(pkg, cwd_) {
|
|
69
|
+
const cwd = (cwd_ ?? process.cwd());
|
|
70
|
+
const file = Path.join(cwd, PKG_FILE);
|
|
71
|
+
Fs.writeFileSync(file, (JSON.stringify(pkg, null, 2) + "\n"), "utf8");
|
|
72
|
+
}
|
|
73
|
+
function parsePackageSpec(spec) {
|
|
74
|
+
const atIdx = spec.lastIndexOf("@");
|
|
75
|
+
if ((atIdx > 0)) {
|
|
76
|
+
return { name: spec.slice(0, atIdx), version: spec.slice((atIdx + 1)) };
|
|
77
|
+
}
|
|
78
|
+
return { name: spec, version: "latest" };
|
|
79
|
+
}
|
|
80
|
+
async function cmdAdd(specs, opts) {
|
|
81
|
+
const isDev = (opts?.dev ?? false);
|
|
82
|
+
const cwd = process.cwd();
|
|
83
|
+
const pkg = ensureFluxJson(cwd);
|
|
84
|
+
for (const spec of specs) {
|
|
85
|
+
const { name, version } = parsePackageSpec(spec);
|
|
86
|
+
console.log((((clr(C.cyan, "\n Adding ") + clr(C.bold, name)) + clr(C.gray, ("@" + version))) + " ..."));
|
|
87
|
+
try {
|
|
88
|
+
const info_ = await fetchJson(((REGISTRY_URL + "/") + name));
|
|
89
|
+
const resolvedVersion = ((version == "latest") ? (info_["dist-tags"]?.latest ?? "1.0.0") : version);
|
|
90
|
+
const versionInfo = info_.versions?.[resolvedVersion];
|
|
91
|
+
if (!versionInfo) {
|
|
92
|
+
err(((("Version " + resolvedVersion) + " not found for ") + name));
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const depKey = (isDev ? "devDependencies" : "dependencies");
|
|
96
|
+
if (!pkg[depKey]) {
|
|
97
|
+
pkg[depKey] = { };
|
|
98
|
+
}
|
|
99
|
+
pkg[depKey][name] = ("^" + resolvedVersion);
|
|
100
|
+
saveFluxJson(pkg, cwd);
|
|
101
|
+
const desc = (versionInfo.description ? clr(C.gray, (" — " + versionInfo.description)) : "");
|
|
102
|
+
ok(((name + clr(C.green, ("@" + resolvedVersion))) + desc));
|
|
103
|
+
info(("Added to " + (isDev ? "devDependencies" : "dependencies")));
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
err(((("Failed to fetch " + name) + ": ") + e.message));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
console.log();
|
|
110
|
+
console.log(((clr(C.gray, " Run ") + clr(C.yellow, "flux install")) + clr(C.gray, " to install packages")));
|
|
111
|
+
console.log();
|
|
112
|
+
}
|
|
113
|
+
module.exports.cmdAdd = cmdAdd;
|
|
114
|
+
function cmdRemove(names, opts) {
|
|
115
|
+
const cwd = process.cwd();
|
|
116
|
+
const pkg = ensureFluxJson(cwd);
|
|
117
|
+
let removed = 0;
|
|
118
|
+
for (const name of names) {
|
|
119
|
+
let found = false;
|
|
120
|
+
if ((pkg.dependencies && pkg.dependencies[name])) {
|
|
121
|
+
delete;
|
|
122
|
+
pkg.dependencies[name];
|
|
123
|
+
found = true;
|
|
124
|
+
}
|
|
125
|
+
if ((pkg.devDependencies && pkg.devDependencies[name])) {
|
|
126
|
+
delete;
|
|
127
|
+
pkg.devDependencies[name];
|
|
128
|
+
found = true;
|
|
129
|
+
}
|
|
130
|
+
if (found) {
|
|
131
|
+
ok(("Removed " + clr(C.bold, name)));
|
|
132
|
+
removed = (removed + 1);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
err((name + " not found in flux.json"));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if ((removed > 0)) {
|
|
139
|
+
saveFluxJson(pkg, cwd);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
module.exports.cmdRemove = cmdRemove;
|
|
143
|
+
async function cmdInstall(opts) {
|
|
144
|
+
const cwd = process.cwd();
|
|
145
|
+
const pkg = ensureFluxJson(cwd);
|
|
146
|
+
const deps = (pkg.dependencies ?? { });
|
|
147
|
+
const devDeps = (pkg.devDependencies ?? { });
|
|
148
|
+
const all = { ...deps, ...devDeps };
|
|
149
|
+
const names = Object.keys(all);
|
|
150
|
+
if ((names.length == 0)) {
|
|
151
|
+
info("No dependencies found in flux.json");
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
console.log(((clr(C.cyan, "\n Installing ") + names.length) + " package(s)...\n"));
|
|
155
|
+
const modDir = Path.join(cwd, FLUX_PKG_DIR);
|
|
156
|
+
if (!Fs.existsSync(modDir)) {
|
|
157
|
+
Fs.mkdirSync(modDir, { recursive: true });
|
|
158
|
+
}
|
|
159
|
+
for (const name of names) {
|
|
160
|
+
const spec = all[name];
|
|
161
|
+
const version = spec.replace(/[\^~>=<]/g, "").split(" ")[0];
|
|
162
|
+
console.log(((clr(C.gray, " ○ ") + name) + clr(C.gray, ("@" + version))));
|
|
163
|
+
}
|
|
164
|
+
console.log();
|
|
165
|
+
ok("flux.json dependencies registered");
|
|
166
|
+
info("Note: Use npm/pnpm to install Node.js compatible packages");
|
|
167
|
+
console.log();
|
|
168
|
+
}
|
|
169
|
+
module.exports.cmdInstall = cmdInstall;
|
|
170
|
+
function cmdList(opts) {
|
|
171
|
+
const cwd = process.cwd();
|
|
172
|
+
const pkg = readPackage(cwd);
|
|
173
|
+
if (!pkg) {
|
|
174
|
+
err("No flux.json found. Run: flux init");
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
console.log();
|
|
178
|
+
console.log(clr(C.bold, ((" " + (pkg.name ?? "project")) + clr(C.gray, ("@" + (pkg.version ?? "1.0.0"))))));
|
|
179
|
+
console.log();
|
|
180
|
+
const deps = (pkg.dependencies ?? { });
|
|
181
|
+
const devDeps = (pkg.devDependencies ?? { });
|
|
182
|
+
if ((Object.keys(deps).length > 0)) {
|
|
183
|
+
console.log(clr(C.cyan, " dependencies:"));
|
|
184
|
+
for (const name of Object.keys(deps)) {
|
|
185
|
+
console.log(((" " + clr(C.green, name)) + clr(C.gray, (" " + deps[name]))));
|
|
186
|
+
}
|
|
187
|
+
console.log();
|
|
188
|
+
}
|
|
189
|
+
if ((Object.keys(devDeps).length > 0)) {
|
|
190
|
+
console.log(clr(C.cyan, " devDependencies:"));
|
|
191
|
+
for (const name of Object.keys(devDeps)) {
|
|
192
|
+
console.log(((" " + clr(C.blue, name)) + clr(C.gray, (" " + devDeps[name]))));
|
|
193
|
+
}
|
|
194
|
+
console.log();
|
|
195
|
+
}
|
|
196
|
+
if (((Object.keys(deps).length == 0) && (Object.keys(devDeps).length == 0))) {
|
|
197
|
+
info("No dependencies");
|
|
198
|
+
console.log();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
module.exports.cmdList = cmdList;
|
|
202
|
+
async function cmdSearch(query, opts) {
|
|
203
|
+
console.log(((clr(C.cyan, "\n Searching for ") + clr(C.bold, (("\"" + query) + "\""))) + " ...\n"));
|
|
204
|
+
try {
|
|
205
|
+
const url = (((REGISTRY_URL + "/-/v1/search?text=") + encodeURIComponent((query + " keywords:flux"))) + "&size=10");
|
|
206
|
+
const results = await fetchJson(url);
|
|
207
|
+
const objects = (results.objects ?? []);
|
|
208
|
+
if ((objects.length == 0)) {
|
|
209
|
+
info(("No packages found for: " + query));
|
|
210
|
+
console.log();
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
for (const obj of objects) {
|
|
214
|
+
const p = obj.package;
|
|
215
|
+
console.log(((" " + clr(C.bold, p.name)) + clr(C.gray, (" v" + p.version))));
|
|
216
|
+
if (p.description) {
|
|
217
|
+
console.log((" " + clr(C.gray, p.description)));
|
|
218
|
+
}
|
|
219
|
+
console.log((" " + clr(C.blue, (p.links?.npm ?? ""))));
|
|
220
|
+
console.log();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
catch (e) {
|
|
224
|
+
err(("Search failed: " + e.message));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
module.exports.cmdSearch = cmdSearch;
|
|
228
|
+
async function cmdInfo(name, opts) {
|
|
229
|
+
console.log(((clr(C.cyan, "\n Fetching info for ") + clr(C.bold, name)) + " ...\n"));
|
|
230
|
+
try {
|
|
231
|
+
const info_ = await fetchJson(((REGISTRY_URL + "/") + name));
|
|
232
|
+
const latest = (info_["dist-tags"]?.latest ?? "unknown");
|
|
233
|
+
const ver = (info_.versions?.[latest] ?? { });
|
|
234
|
+
console.log((clr(C.bold, (" " + name)) + clr(C.gray, (" v" + latest))));
|
|
235
|
+
if (ver.description) {
|
|
236
|
+
console.log((" " + ver.description));
|
|
237
|
+
}
|
|
238
|
+
console.log();
|
|
239
|
+
console.log((clr(C.gray, " license: ") + (ver.license ?? "unknown")));
|
|
240
|
+
console.log((clr(C.gray, " author: ") + ((ver.author?.name ?? ver.author) ?? "unknown")));
|
|
241
|
+
const homepage = (ver.homepage ?? info_.homepage);
|
|
242
|
+
if (homepage) {
|
|
243
|
+
console.log((clr(C.gray, " home: ") + clr(C.blue, homepage)));
|
|
244
|
+
}
|
|
245
|
+
const repo = (ver.repository?.url ?? info_.repository?.url);
|
|
246
|
+
if (repo) {
|
|
247
|
+
console.log((clr(C.gray, " repo: ") + clr(C.blue, repo.replace("git+", "").replace(".git", ""))));
|
|
248
|
+
}
|
|
249
|
+
const keywords = (ver.keywords ?? []);
|
|
250
|
+
if ((keywords.length > 0)) {
|
|
251
|
+
console.log((clr(C.gray, " tags: ") + keywords.slice(0, 8).join(", ")));
|
|
252
|
+
}
|
|
253
|
+
console.log();
|
|
254
|
+
console.log((clr(C.gray, " Install: ") + clr(C.yellow, ("flux add " + name))));
|
|
255
|
+
console.log();
|
|
256
|
+
}
|
|
257
|
+
catch (e) {
|
|
258
|
+
err(((("Could not fetch info for " + name) + ": ") + e.message));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
module.exports.cmdInfo = cmdInfo;
|
|
262
|
+
function cmdPublish(opts) {
|
|
263
|
+
const cwd = process.cwd();
|
|
264
|
+
const pkg = readPackage(cwd);
|
|
265
|
+
if (!pkg) {
|
|
266
|
+
err("No flux.json found. Run: flux init");
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
console.log();
|
|
270
|
+
console.log(((clr(C.cyan, " Publishing ") + clr(C.bold, ((pkg.name + "@") + pkg.version))) + " ..."));
|
|
271
|
+
console.log();
|
|
272
|
+
info("Building package...");
|
|
273
|
+
info("Checking flux.json...");
|
|
274
|
+
if (!pkg.name) {
|
|
275
|
+
err("flux.json must have a name field");
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (!pkg.version) {
|
|
279
|
+
err("flux.json must have a version field");
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
console.log();
|
|
283
|
+
ok(((("Package ready: " + pkg.name) + "@") + pkg.version));
|
|
284
|
+
info("Run: npm publish to publish to the npm registry");
|
|
285
|
+
info("Run: flux publish --registry <url> for a custom registry");
|
|
286
|
+
console.log();
|
|
287
|
+
}
|
|
288
|
+
module.exports.cmdPublish = cmdPublish;
|
package/src/self/sourcemap.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
function join(arr, sep) { return arr.join(sep != null ? sep : ','); }
|
|
4
4
|
// ── end stdlib ──
|
|
5
5
|
|
|
6
|
-
// Generated by Flux Transpiler v3.
|
|
6
|
+
// Generated by Flux Transpiler v3.2.0
|
|
7
7
|
"use strict";
|
|
8
8
|
|
|
9
9
|
const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|