@xnoxs/flux-lang 4.0.3 → 4.0.5

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.
@@ -1,23 +1,27 @@
1
- // ── Flux stdlib ──
2
-
3
- function join(arr, sep) { return arr.join(sep != null ? sep : ','); }
4
-
5
- function includes(arr, val) { return arr.includes(val); }
6
-
7
- function keys(obj) { return Object.keys(obj); }
8
-
9
- function endsWith(s, suffix) { return String(s).endsWith(suffix); }
10
- // ── end stdlib ──
11
-
12
- // Generated by Flux Transpiler v3.2.0
1
+ /* compiled from src/self/config.flux */
2
+ 'use strict';
3
+ // Generated by Flux Transpiler v3.5.3 (self-hosted)
13
4
  "use strict";
14
5
 
15
6
  const Fs = require("fs");
16
7
  const Path = require("path");
17
- const DEFAULT_CONFIG = { entry: "src/main.flux", outDir: "dist", sourcemap: false, mangle: false, jsx: false, jsxTarget: "browser", typecheck: true, strict: false, watch: false, ignore: [], selfHosted: false, registry: "https://registry.flux-lang.dev", pkg: { name: "", version: "1.0.0", description: "", author: "", license: "MIT", deps: { }, devDeps: { } } };
8
+ const DEFAULT_CONFIG = { entry: "src/main.flux", outDir: "dist", sourcemap: false, mangle: false, jsx: false, jsxTarget: "browser", typecheck: true, strict: false, watch: false, ignore: [], selfHosted: false, registry: "https://registry.npmjs.org", pkg: { name: "", version: "1.0.0", description: "", author: "", license: "MIT", deps: { }, devDeps: { } } };
18
9
  module.exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
19
10
  function loadConfig(cwd_) {
20
11
  const cwd = (cwd_ ?? process.cwd());
12
+ const pkgJsonPath = Path.join(cwd, "package.json");
13
+ if (Fs.existsSync(pkgJsonPath)) {
14
+ try {
15
+ const raw = Fs.readFileSync(pkgJsonPath, "utf8");
16
+ const parsed = JSON.parse(raw);
17
+ if ((parsed.flux && (typeof parsed.flux == "object"))) {
18
+ return mergeConfig(DEFAULT_CONFIG, parsed.flux);
19
+ }
20
+ }
21
+ catch (e) {
22
+ throw new Error(("Invalid package.json: " + e.message));
23
+ }
24
+ }
21
25
  const jsonPath = Path.join(cwd, "flux.json");
22
26
  if (Fs.existsSync(jsonPath)) {
23
27
  try {
@@ -29,16 +33,6 @@ function loadConfig(cwd_) {
29
33
  throw new Error(("Invalid flux.json: " + e.message));
30
34
  }
31
35
  }
32
- const jsPath = Path.join(cwd, "flux.config.js");
33
- if (Fs.existsSync(jsPath)) {
34
- try {
35
- const loaded = require(jsPath);
36
- return mergeConfig(DEFAULT_CONFIG, loaded);
37
- }
38
- catch (e2) {
39
- throw new Error(("Invalid flux.config.js: " + e2.message));
40
- }
41
- }
42
36
  return { ...DEFAULT_CONFIG };
43
37
  }
44
38
  module.exports.loadConfig = loadConfig;
@@ -58,9 +52,18 @@ function mergeConfig(base, overrides) {
58
52
  module.exports.mergeConfig = mergeConfig;
59
53
  function writeConfig(config, cwd_) {
60
54
  const cwd = (cwd_ ?? process.cwd());
61
- const jsonPath = Path.join(cwd, "flux.json");
62
- const content = (JSON.stringify(config, null, 2) + "\n");
63
- Fs.writeFileSync(jsonPath, content, "utf8");
55
+ const pkgPath = Path.join(cwd, "package.json");
56
+ let pkg = { };
57
+ if (Fs.existsSync(pkgPath)) {
58
+ try {
59
+ pkg = JSON.parse(Fs.readFileSync(pkgPath, "utf8"));
60
+ }
61
+ catch (e) {
62
+ pkg = { };
63
+ }
64
+ }
65
+ pkg.flux = config;
66
+ Fs.writeFileSync(pkgPath, (JSON.stringify(pkg, null, 2) + "\n"), "utf8");
64
67
  }
65
68
  module.exports.writeConfig = writeConfig;
66
69
  function validateConfig(config) {
@@ -76,19 +79,19 @@ function validateConfig(config) {
76
79
  module.exports.validateConfig = validateConfig;
77
80
  function readPackage(cwd_) {
78
81
  const cwd = (cwd_ ?? process.cwd());
79
- const fluxJson = Path.join(cwd, "flux.json");
80
82
  const pkgJson = Path.join(cwd, "package.json");
81
- if (Fs.existsSync(fluxJson)) {
83
+ const fluxJson = Path.join(cwd, "flux.json");
84
+ if (Fs.existsSync(pkgJson)) {
82
85
  try {
83
- return JSON.parse(Fs.readFileSync(fluxJson, "utf8"));
86
+ return JSON.parse(Fs.readFileSync(pkgJson, "utf8"));
84
87
  }
85
88
  catch (e) {
86
89
  return null;
87
90
  }
88
91
  }
89
- if (Fs.existsSync(pkgJson)) {
92
+ if (Fs.existsSync(fluxJson)) {
90
93
  try {
91
- return JSON.parse(Fs.readFileSync(pkgJson, "utf8"));
94
+ return JSON.parse(Fs.readFileSync(fluxJson, "utf8"));
92
95
  }
93
96
  catch (e2) {
94
97
  return null;
package/src/self/pkg.flux CHANGED
@@ -3,11 +3,11 @@
3
3
  // src/self/pkg.flux — written in Flux, compiled by stage-0
4
4
  //
5
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
6
+ // flux add <pkg[@version]> install a package (npm install --save)
7
+ // flux remove <pkg> remove a package (npm uninstall)
8
+ // flux install install all from package.json (npm install)
9
9
  // flux list list installed packages
10
- // flux search <query> search the registry
10
+ // flux search <query> search the npm registry
11
11
  // flux publish publish to registry
12
12
  // flux info <pkg> show package info
13
13
  // ============================================================
@@ -17,11 +17,9 @@ import Path from "path"
17
17
  import Https from "https"
18
18
  import Http from "http"
19
19
  import Os from "os"
20
- import { readPackage, writeConfig, loadConfig } from "./config"
20
+ import { readPackage } from "./config"
21
21
 
22
22
  val REGISTRY_URL = "https://registry.npmjs.org"
23
- val FLUX_PKG_DIR = "flux_modules"
24
- val PKG_FILE = "flux.json"
25
23
 
26
24
  // ── ANSI colors ───────────────────────────────────────────────
27
25
  val ESC = "\u001b"
@@ -77,36 +75,6 @@ async fn fetchJson(url):
77
75
  mod.get(url, { headers: { "User-Agent": "flux-pkg/1.0" } }, onRes).on("error", reject)
78
76
  return new Promise(doRequest)
79
77
 
80
- // ── Ensure flux.json exists ───────────────────────────────────
81
- fn ensureFluxJson(cwd_):
82
- val cwd = cwd_ ?? process.cwd()
83
- val file = Path.join(cwd, PKG_FILE)
84
- if not Fs.existsSync(file):
85
- val pkg = {
86
- name: Path.basename(cwd),
87
- version: "1.0.0",
88
- description: "",
89
- author: "",
90
- license: "MIT",
91
- scripts: {
92
- start: "flux run src/main.flux",
93
- build: "flux bundle src/main.flux -o dist/bundle.js",
94
- dev: "flux watch src/main.flux",
95
- check: "flux check src/main.flux",
96
- },
97
- dependencies: {},
98
- devDependencies: {},
99
- }
100
- Fs.writeFileSync(file, JSON.stringify(pkg, null, 2) + "\n", "utf8")
101
- ok("Created flux.json")
102
- return JSON.parse(Fs.readFileSync(file, "utf8"))
103
-
104
- // ── Save flux.json ────────────────────────────────────────────
105
- fn saveFluxJson(pkg, cwd_):
106
- val cwd = cwd_ ?? process.cwd()
107
- val file = Path.join(cwd, PKG_FILE)
108
- Fs.writeFileSync(file, JSON.stringify(pkg, null, 2) + "\n", "utf8")
109
-
110
78
  // ── Resolve package name@version ─────────────────────────────
111
79
  fn parsePackageSpec(spec):
112
80
  val atIdx = spec.lastIndexOf("@")
@@ -115,124 +83,63 @@ fn parsePackageSpec(spec):
115
83
  return { name: spec, version: "latest" }
116
84
 
117
85
  // ── flux add <pkg[@version]> [--dev] ─────────────────────────
86
+ // Equivalent to: npm install <pkg> --save (or --save-dev)
118
87
  export async fn cmdAdd(specs, opts):
88
+ import { execSync } from "child_process"
119
89
  val isDev = opts?.dev ?? false
120
90
  val cwd = process.cwd()
121
- val pkg = ensureFluxJson(cwd)
122
91
 
123
92
  for spec in specs:
124
93
  val { name, version } = parsePackageSpec(spec)
125
- val spinner = startSpinner("Fetching " + clr(C.bold, name) + clr(C.gray, "@" + version) + " ...")
94
+ val spinner = startSpinner("Adding " + clr(C.bold, name) + clr(C.gray, "@" + version) + " ...")
126
95
 
127
96
  try:
128
- val info_ = await fetchJson(REGISTRY_URL + "/" + name)
129
- val resolvedVersion = version == "latest" ? (info_["dist-tags"]?.latest ?? "1.0.0") : version
130
-
131
- val versionInfo = info_.versions?.[resolvedVersion]
97
+ val saveFlag = isDev ? "--save-dev" : "--save"
98
+ val pkgSpec = version == "latest" ? name : name + "@" + version
132
99
  stopSpinner(spinner)
133
- if not versionInfo:
134
- err("Version " + resolvedVersion + " not found for " + name)
135
- continue
136
-
137
- val depKey = isDev ? "devDependencies" : "dependencies"
138
- if not pkg[depKey]: pkg[depKey] = {}
139
- pkg[depKey][name] = "^" + resolvedVersion
140
-
141
- saveFluxJson(pkg, cwd)
142
-
143
- val desc = versionInfo.description ? clr(C.gray, " — " + versionInfo.description) : ""
144
- ok(name + clr(C.green, "@" + resolvedVersion) + desc)
145
- info("Added to " + (isDev ? "devDependencies" : "dependencies"))
146
-
100
+ console.log(clr(C.cyan, " Adding ") + clr(C.bold, pkgSpec) + clr(C.gray, " to node_modules/ and package.json..."))
101
+ execSync("npm install " + pkgSpec + " " + saveFlag, { cwd, stdio: "inherit" })
102
+ ok("Added " + clr(C.bold, name) + " to node_modules/ and package.json")
147
103
  catch(e):
148
104
  stopSpinner(spinner)
149
- err("Failed to fetch " + name + ": " + e.message)
105
+ err("Failed to add " + name + ": " + e.message)
150
106
 
151
107
  console.log()
152
- console.log(clr(C.gray, " Run ") + clr(C.yellow, "flux install") + clr(C.gray, " to install packages"))
153
- console.log()
154
108
 
155
109
  // ── flux remove <pkg> ─────────────────────────────────────────
110
+ // Equivalent to: npm uninstall <pkg>
156
111
  export fn cmdRemove(names, opts):
112
+ import { execSync } from "child_process"
157
113
  val cwd = process.cwd()
158
- val pkg = ensureFluxJson(cwd)
159
- var removed = 0
160
114
 
161
115
  for name in names:
162
- var found = false
163
- if pkg.dependencies and pkg.dependencies[name]:
164
- delete pkg.dependencies[name]
165
- found = true
166
- if pkg.devDependencies and pkg.devDependencies[name]:
167
- delete pkg.devDependencies[name]
168
- found = true
169
-
170
- if found:
116
+ try:
117
+ console.log(clr(C.cyan, " Removing ") + clr(C.bold, name) + " ...")
118
+ execSync("npm uninstall " + name, { cwd, stdio: "inherit" })
171
119
  ok("Removed " + clr(C.bold, name))
172
- removed = removed + 1
173
- else:
174
- err(name + " not found in flux.json")
175
-
176
- if removed > 0:
177
- saveFluxJson(pkg, cwd)
120
+ catch(e):
121
+ err("Failed to remove " + name + ": " + e.message)
178
122
 
179
123
  // ── flux install ──────────────────────────────────────────────
124
+ // Equivalent to: npm install (reads package.json)
180
125
  export async fn cmdInstall(opts):
181
126
  import { execSync } from "child_process"
127
+ val cwd = process.cwd()
182
128
 
183
- val cwd = process.cwd()
184
- val pkg = ensureFluxJson(cwd)
185
- val fluxModDir = Path.join(cwd, "flux_modules")
186
-
187
- val deps = pkg.dependencies ?? {}
188
- val devDeps = pkg.devDependencies ?? {}
189
- val all = { ...deps, ...devDeps }
190
- val names = Object.keys(all)
191
-
192
- if names.length == 0:
193
- info("No dependencies found in flux.json")
129
+ val pkgJsonPath = Path.join(cwd, "package.json")
130
+ if not Fs.existsSync(pkgJsonPath):
131
+ err("No package.json found. Run: flux init")
194
132
  return
195
133
 
196
- console.log(clr(C.cyan, "\n Installing ") + names.length + " package(s) into flux_modules/...\n")
197
-
198
- for name in names:
199
- val spec = all[name]
200
- console.log(clr(C.gray, " ○ ") + name + clr(C.gray, "@" + spec))
201
-
202
- console.log()
203
-
204
- // Ensure flux_modules/ exists with a minimal package.json
205
- if not Fs.existsSync(fluxModDir):
206
- Fs.mkdirSync(fluxModDir, { recursive: true })
207
-
208
- val fluxPkgFile = Path.join(fluxModDir, "package.json")
209
- if not Fs.existsSync(fluxPkgFile):
210
- val fluxPkg = { name: pkg.name + "-flux-modules", version: "1.0.0", private: true }
211
- Fs.writeFileSync(fluxPkgFile, JSON.stringify(fluxPkg, null, 2) + "\n", "utf8")
212
-
213
- val prodNames = Object.keys(deps)
214
- val devNames = Object.keys(devDeps)
215
-
134
+ console.log(clr(C.cyan, "\n Installing dependencies from package.json...\n"))
216
135
  try:
217
- if prodNames.length > 0:
218
- val prodPkgs = prodNames.map(n -> n + "@" + (deps[n] ?? "latest")).join(" ")
219
- val installCmd = "npm install --prefix " + fluxModDir + " " + prodPkgs
220
- info("Running: " + installCmd)
221
- execSync(installCmd, { cwd: cwd, stdio: "inherit" })
222
-
223
- if devNames.length > 0:
224
- val devPkgs = devNames.map(n -> n + "@" + (devDeps[n] ?? "latest")).join(" ")
225
- val devCmd = "npm install --prefix " + fluxModDir + " --save-dev " + devPkgs
226
- info("Running: " + devCmd)
227
- execSync(devCmd, { cwd: cwd, stdio: "inherit" })
228
-
136
+ execSync("npm install", { cwd, stdio: "inherit" })
229
137
  console.log()
230
- ok(names.length + " package(s) installed into flux_modules/node_modules/")
231
- info("Packages resolve automatically when using: flux run, flux bundle")
138
+ ok("Dependencies installed into node_modules/")
232
139
  catch(e):
233
140
  console.log()
234
141
  err("Install failed: " + e.message)
235
- info("Try manually: npm install --prefix ./flux_modules <package>")
142
+ info("Try manually: npm install")
236
143
 
237
144
  console.log()
238
145
 
@@ -242,7 +149,7 @@ export fn cmdList(opts):
242
149
  val pkg = readPackage(cwd)
243
150
 
244
151
  if not pkg:
245
- err("No flux.json found. Run: flux init")
152
+ err("No package.json found. Run: flux init")
246
153
  return
247
154
 
248
155
  console.log()
@@ -325,12 +232,13 @@ export async fn cmdInfo(name, opts):
325
232
 
326
233
  // ── flux upgrade [--check] ────────────────────────────────────
327
234
  export async fn cmdUpgrade(opts):
235
+ import { execSync } from "child_process"
328
236
  val isCheck = opts?.check ?? false
329
237
  val cwd = process.cwd()
330
238
  val pkg = readPackage(cwd)
331
239
 
332
240
  if not pkg:
333
- err("No flux.json found. Run: flux init")
241
+ err("No package.json found. Run: flux init")
334
242
  return
335
243
 
336
244
  val deps = pkg.dependencies ?? {}
@@ -371,11 +279,9 @@ export async fn cmdUpgrade(opts):
371
279
  if isCheck:
372
280
  console.log(" " + clr(C.yellow, "↑ ") + clr(C.bold, name) + clr(C.gray, " " + current + " → ") + clr(C.green, "^" + latest))
373
281
  else:
374
- val isDev = devDeps[name] != null
375
- val depKey = isDev ? "devDependencies" : "dependencies"
376
- pkg[depKey][name] = "^" + latest
377
282
  updated = updated + 1
378
283
  console.log(" " + clr(C.green, "✓ ") + clr(C.bold, name) + clr(C.gray, " " + current + " → ") + clr(C.green, "^" + latest))
284
+ execSync("npm install " + name + "@" + latest + " --save", { cwd, stdio: "pipe" })
379
285
 
380
286
  catch(e):
381
287
  stopSpinner(spinner)
@@ -393,9 +299,7 @@ export async fn cmdUpgrade(opts):
393
299
  if updated == 0:
394
300
  ok("All packages are already up to date")
395
301
  else:
396
- saveFluxJson(pkg, cwd)
397
- ok(updated + " package(s) updated in flux.json")
398
- console.log(clr(C.gray, " Run ") + clr(C.yellow, "flux install") + clr(C.gray, " to install updated versions"))
302
+ ok(updated + " package(s) updated in node_modules/ and package.json")
399
303
 
400
304
  console.log()
401
305
 
@@ -405,21 +309,20 @@ export fn cmdPublish(opts):
405
309
  val pkg = readPackage(cwd)
406
310
 
407
311
  if not pkg:
408
- err("No flux.json found. Run: flux init")
312
+ err("No package.json found. Run: flux init")
409
313
  return
410
314
 
411
315
  console.log()
412
316
  console.log(clr(C.cyan, " Publishing ") + clr(C.bold, pkg.name + "@" + pkg.version) + " ...")
413
317
  console.log()
414
- info("Building package...")
415
- info("Checking flux.json...")
318
+ info("Checking package.json...")
416
319
 
417
320
  if not pkg.name:
418
- err("flux.json must have a name field")
321
+ err("package.json must have a name field")
419
322
  return
420
323
 
421
324
  if not pkg.version:
422
- err("flux.json must have a version field")
325
+ err("package.json must have a version field")
423
326
  return
424
327
 
425
328
  console.log()
package/src/self/pkg.js CHANGED
@@ -1,15 +1,6 @@
1
- // ── Flux stdlib ──
2
-
3
- function map(arr, fn) { return arr.map(fn); }
4
-
5
- function join(arr, sep) { return arr.join(sep != null ? sep : ','); }
6
-
7
- function keys(obj) { return Object.keys(obj); }
8
-
9
- function startsWith(s, prefix) { return String(s).startsWith(prefix); }
10
- // ── end stdlib ──
11
-
12
- // Generated by Flux Transpiler v3.2.0
1
+ /* compiled from src/self/pkg.flux */
2
+ 'use strict';
3
+ // Generated by Flux Transpiler v3.5.3 (self-hosted)
13
4
  "use strict";
14
5
 
15
6
  const Fs = require("fs");
@@ -17,11 +8,9 @@ const Path = require("path");
17
8
  const Https = require("https");
18
9
  const Http = require("http");
19
10
  const Os = require("os");
20
- const { readPackage, writeConfig, loadConfig } = require("./config");
11
+ const { readPackage } = require("./config");
21
12
  const REGISTRY_URL = "https://registry.npmjs.org";
22
- const FLUX_PKG_DIR = "flux_modules";
23
- const PKG_FILE = "flux.json";
24
- const ESC = "\u001b";
13
+ const ESC = "\\u001b";
25
14
  const C = { reset: (ESC + "[0m"), bold: (ESC + "[1m"), dim: (ESC + "[2m"), red: (ESC + "[31m"), green: (ESC + "[32m"), yellow: (ESC + "[33m"), blue: (ESC + "[34m"), cyan: (ESC + "[36m"), gray: (ESC + "[90m") };
26
15
  function clr(c, s) {
27
16
  return ((c + s) + C.reset);
@@ -43,7 +32,7 @@ function startSpinner(label) {
43
32
  }
44
33
  let frame = 0;
45
34
  function tick() {
46
- stdout.write((((("\r" + clr(C.cyan, SPIN_FRAMES[(frame % SPIN_FRAMES.length)])) + " ") + label) + " "));
35
+ stdout.write((((("\\r" + clr(C.cyan, SPIN_FRAMES[(frame % SPIN_FRAMES.length)])) + " ") + label) + " "));
47
36
  frame = (frame + 1);
48
37
  }
49
38
  const timer = setInterval(tick, 80);
@@ -54,7 +43,7 @@ function stopSpinner(timer) {
54
43
  return;
55
44
  }
56
45
  clearInterval(timer);
57
- stdout.write((("\r" + ESC) + "[2K"));
46
+ stdout.write((("\\r" + ESC) + "[2K"));
58
47
  }
59
48
  async function fetchJson(url) {
60
49
  const mod = (url.startsWith("https") ? Https : Http);
@@ -79,21 +68,6 @@ async function fetchJson(url) {
79
68
  }
80
69
  return new Promise(doRequest);
81
70
  }
82
- function ensureFluxJson(cwd_) {
83
- const cwd = (cwd_ ?? process.cwd());
84
- const file = Path.join(cwd, PKG_FILE);
85
- if (!Fs.existsSync(file)) {
86
- 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: { } };
87
- Fs.writeFileSync(file, (JSON.stringify(pkg, null, 2) + "\n"), "utf8");
88
- ok("Created flux.json");
89
- }
90
- return JSON.parse(Fs.readFileSync(file, "utf8"));
91
- }
92
- function saveFluxJson(pkg, cwd_) {
93
- const cwd = (cwd_ ?? process.cwd());
94
- const file = Path.join(cwd, PKG_FILE);
95
- Fs.writeFileSync(file, (JSON.stringify(pkg, null, 2) + "\n"), "utf8");
96
- }
97
71
  function parsePackageSpec(spec) {
98
72
  const atIdx = spec.lastIndexOf("@");
99
73
  if ((atIdx > 0)) {
@@ -102,118 +76,61 @@ function parsePackageSpec(spec) {
102
76
  return { name: spec, version: "latest" };
103
77
  }
104
78
  async function cmdAdd(specs, opts) {
79
+ const { execSync } = require("child_process");
105
80
  const isDev = (opts?.dev ?? false);
106
81
  const cwd = process.cwd();
107
- const pkg = ensureFluxJson(cwd);
108
82
  for (const spec of specs) {
109
83
  const { name, version } = parsePackageSpec(spec);
110
- const spinner = startSpinner(((("Fetching " + clr(C.bold, name)) + clr(C.gray, ("@" + version))) + " ..."));
84
+ const spinner = startSpinner(((("Adding " + clr(C.bold, name)) + clr(C.gray, ("@" + version))) + " ..."));
111
85
  try {
112
- const info_ = await fetchJson(((REGISTRY_URL + "/") + name));
113
- const resolvedVersion = ((version == "latest") ? (info_["dist-tags"]?.latest ?? "1.0.0") : version);
114
- const versionInfo = info_.versions?.[resolvedVersion];
86
+ const saveFlag = (isDev ? "--save-dev" : "--save");
87
+ const pkgSpec = ((version == "latest") ? name : ((name + "@") + version));
115
88
  stopSpinner(spinner);
116
- if (!versionInfo) {
117
- err(((("Version " + resolvedVersion) + " not found for ") + name));
118
- continue;
119
- }
120
- const depKey = (isDev ? "devDependencies" : "dependencies");
121
- if (!pkg[depKey]) {
122
- pkg[depKey] = { };
123
- }
124
- pkg[depKey][name] = ("^" + resolvedVersion);
125
- saveFluxJson(pkg, cwd);
126
- const desc = (versionInfo.description ? clr(C.gray, (" — " + versionInfo.description)) : "");
127
- ok(((name + clr(C.green, ("@" + resolvedVersion))) + desc));
128
- info(("Added to " + (isDev ? "devDependencies" : "dependencies")));
89
+ console.log(((clr(C.cyan, " Adding ") + clr(C.bold, pkgSpec)) + clr(C.gray, " to node_modules/ and package.json...")));
90
+ execSync(((("npm install " + pkgSpec) + " ") + saveFlag), { cwd, stdio: "inherit" });
91
+ ok((("Added " + clr(C.bold, name)) + " to node_modules/ and package.json"));
129
92
  }
130
93
  catch (e) {
131
94
  stopSpinner(spinner);
132
- err(((("Failed to fetch " + name) + ": ") + e.message));
95
+ err(((("Failed to add " + name) + ": ") + e.message));
133
96
  }
134
97
  }
135
98
  console.log();
136
- console.log(((clr(C.gray, " Run ") + clr(C.yellow, "flux install")) + clr(C.gray, " to install packages")));
137
- console.log();
138
99
  }
139
100
  module.exports.cmdAdd = cmdAdd;
140
101
  function cmdRemove(names, opts) {
102
+ const { execSync } = require("child_process");
141
103
  const cwd = process.cwd();
142
- const pkg = ensureFluxJson(cwd);
143
- let removed = 0;
144
104
  for (const name of names) {
145
- let found = false;
146
- if ((pkg.dependencies && pkg.dependencies[name])) {
147
- delete pkg.dependencies[name];
148
- found = true;
149
- }
150
- if ((pkg.devDependencies && pkg.devDependencies[name])) {
151
- delete pkg.devDependencies[name];
152
- found = true;
153
- }
154
- if (found) {
105
+ try {
106
+ console.log(((clr(C.cyan, " Removing ") + clr(C.bold, name)) + " ..."));
107
+ execSync(("npm uninstall " + name), { cwd, stdio: "inherit" });
155
108
  ok(("Removed " + clr(C.bold, name)));
156
- removed = (removed + 1);
157
109
  }
158
- else {
159
- err((name + " not found in flux.json"));
110
+ catch (e) {
111
+ err(((("Failed to remove " + name) + ": ") + e.message));
160
112
  }
161
113
  }
162
- if ((removed > 0)) {
163
- saveFluxJson(pkg, cwd);
164
- }
165
114
  }
166
115
  module.exports.cmdRemove = cmdRemove;
167
116
  async function cmdInstall(opts) {
168
117
  const { execSync } = require("child_process");
169
118
  const cwd = process.cwd();
170
- const pkg = ensureFluxJson(cwd);
171
- const fluxModDir = Path.join(cwd, "flux_modules");
172
- const deps = (pkg.dependencies ?? { });
173
- const devDeps = (pkg.devDependencies ?? { });
174
- const all = { ...deps, ...devDeps };
175
- const names = Object.keys(all);
176
- if ((names.length == 0)) {
177
- info("No dependencies found in flux.json");
119
+ const pkgJsonPath = Path.join(cwd, "package.json");
120
+ if (!Fs.existsSync(pkgJsonPath)) {
121
+ err("No package.json found. Run: flux init");
178
122
  return;
179
123
  }
180
- console.log(((clr(C.cyan, "\n Installing ") + names.length) + " package(s) into flux_modules/...\n"));
181
- for (const name of names) {
182
- const spec = all[name];
183
- console.log(((clr(C.gray, " ○ ") + name) + clr(C.gray, ("@" + spec))));
184
- }
185
- console.log();
186
- if (!Fs.existsSync(fluxModDir)) {
187
- Fs.mkdirSync(fluxModDir, { recursive: true });
188
- }
189
- const fluxPkgFile = Path.join(fluxModDir, "package.json");
190
- if (!Fs.existsSync(fluxPkgFile)) {
191
- const fluxPkg = { name: (pkg.name + "-flux-modules"), version: "1.0.0", private: true };
192
- Fs.writeFileSync(fluxPkgFile, (JSON.stringify(fluxPkg, null, 2) + "\n"), "utf8");
193
- }
194
- const prodNames = Object.keys(deps);
195
- const devNames = Object.keys(devDeps);
124
+ console.log(clr(C.cyan, "\n Installing dependencies from package.json...\n"));
196
125
  try {
197
- if ((prodNames.length > 0)) {
198
- const prodPkgs = prodNames.map((n) => ((n + "@") + (deps[n] ?? "latest"))).join(" ");
199
- const installCmd = ((("npm install --prefix " + fluxModDir) + " ") + prodPkgs);
200
- info(("Running: " + installCmd));
201
- execSync(installCmd, { cwd, stdio: "inherit" });
202
- }
203
- if ((devNames.length > 0)) {
204
- const devPkgs = devNames.map((n) => ((n + "@") + (devDeps[n] ?? "latest"))).join(" ");
205
- const devCmd = ((("npm install --prefix " + fluxModDir) + " --save-dev ") + devPkgs);
206
- info(("Running: " + devCmd));
207
- execSync(devCmd, { cwd, stdio: "inherit" });
208
- }
126
+ execSync("npm install", { cwd, stdio: "inherit" });
209
127
  console.log();
210
- ok((names.length + " package(s) installed into flux_modules/node_modules/"));
211
- info("Packages resolve automatically when using: flux run, flux bundle");
128
+ ok("Dependencies installed into node_modules/");
212
129
  }
213
130
  catch (e) {
214
131
  console.log();
215
132
  err(("Install failed: " + e.message));
216
- info("Try manually: npm install --prefix ./flux_modules <package>");
133
+ info("Try manually: npm install");
217
134
  }
218
135
  console.log();
219
136
  }
@@ -222,7 +139,7 @@ function cmdList(opts) {
222
139
  const cwd = process.cwd();
223
140
  const pkg = readPackage(cwd);
224
141
  if (!pkg) {
225
- err("No flux.json found. Run: flux init");
142
+ err("No package.json found. Run: flux init");
226
143
  return;
227
144
  }
228
145
  console.log();
@@ -311,11 +228,12 @@ async function cmdInfo(name, opts) {
311
228
  }
312
229
  module.exports.cmdInfo = cmdInfo;
313
230
  async function cmdUpgrade(opts) {
231
+ const { execSync } = require("child_process");
314
232
  const isCheck = (opts?.check ?? false);
315
233
  const cwd = process.cwd();
316
234
  const pkg = readPackage(cwd);
317
235
  if (!pkg) {
318
- err("No flux.json found. Run: flux init");
236
+ err("No package.json found. Run: flux init");
319
237
  return;
320
238
  }
321
239
  const deps = (pkg.dependencies ?? { });
@@ -356,11 +274,9 @@ async function cmdUpgrade(opts) {
356
274
  console.log(((((" " + clr(C.yellow, "↑ ")) + clr(C.bold, name)) + clr(C.gray, ((" " + current) + " → "))) + clr(C.green, ("^" + latest))));
357
275
  }
358
276
  else {
359
- const isDev = (devDeps[name] != null);
360
- const depKey = (isDev ? "devDependencies" : "dependencies");
361
- pkg[depKey][name] = ("^" + latest);
362
277
  updated = (updated + 1);
363
278
  console.log(((((" " + clr(C.green, "✓ ")) + clr(C.bold, name)) + clr(C.gray, ((" " + current) + " → "))) + clr(C.green, ("^" + latest))));
279
+ execSync((((("npm install " + name) + "@") + latest) + " --save"), { cwd, stdio: "pipe" });
364
280
  }
365
281
  }
366
282
  }
@@ -384,9 +300,7 @@ async function cmdUpgrade(opts) {
384
300
  ok("All packages are already up to date");
385
301
  }
386
302
  else {
387
- saveFluxJson(pkg, cwd);
388
- ok((updated + " package(s) updated in flux.json"));
389
- console.log(((clr(C.gray, " Run ") + clr(C.yellow, "flux install")) + clr(C.gray, " to install updated versions")));
303
+ ok((updated + " package(s) updated in node_modules/ and package.json"));
390
304
  }
391
305
  }
392
306
  console.log();
@@ -396,20 +310,19 @@ function cmdPublish(opts) {
396
310
  const cwd = process.cwd();
397
311
  const pkg = readPackage(cwd);
398
312
  if (!pkg) {
399
- err("No flux.json found. Run: flux init");
313
+ err("No package.json found. Run: flux init");
400
314
  return;
401
315
  }
402
316
  console.log();
403
317
  console.log(((clr(C.cyan, " Publishing ") + clr(C.bold, ((pkg.name + "@") + pkg.version))) + " ..."));
404
318
  console.log();
405
- info("Building package...");
406
- info("Checking flux.json...");
319
+ info("Checking package.json...");
407
320
  if (!pkg.name) {
408
- err("flux.json must have a name field");
321
+ err("package.json must have a name field");
409
322
  return;
410
323
  }
411
324
  if (!pkg.version) {
412
- err("flux.json must have a version field");
325
+ err("package.json must have a version field");
413
326
  return;
414
327
  }
415
328
  console.log();