@vantaloom/cli 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/cli.mjs +98 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vantaloom/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Vantaloom local runtime manager.",
package/src/cli.mjs CHANGED
@@ -1,5 +1,16 @@
1
1
  import { execFileSync, spawnSync } from "node:child_process"
2
- import { chmodSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"
2
+ import {
3
+ chmodSync,
4
+ existsSync,
5
+ lstatSync,
6
+ mkdirSync,
7
+ mkdtempSync,
8
+ readdirSync,
9
+ readFileSync,
10
+ readlinkSync,
11
+ rmSync,
12
+ writeFileSync,
13
+ } from "node:fs"
3
14
  import { cp, writeFile } from "node:fs/promises"
4
15
  import os from "node:os"
5
16
  import path from "node:path"
@@ -32,6 +43,8 @@ export async function main(argv) {
32
43
  case "install":
33
44
  if (options.package) {
34
45
  await installFromPackage({ ...options, update: false })
46
+ } else if (shouldUseDistSync(options)) {
47
+ await syncFromDist(options, "install")
35
48
  } else {
36
49
  await installFromSource(options)
37
50
  }
@@ -39,8 +52,8 @@ export async function main(argv) {
39
52
  case "update":
40
53
  if (options.package) {
41
54
  await installFromPackage({ ...options, update: true })
42
- } else if (shouldUseDistUpdate(options)) {
43
- await updateFromDist(options)
55
+ } else if (shouldUseDistSync(options)) {
56
+ await syncFromDist(options, "update")
44
57
  } else {
45
58
  await installFromSource({ ...options, update: true })
46
59
  }
@@ -145,7 +158,7 @@ async function buildRuntimePackage(sourceRoot, packageRoot, options) {
145
158
  buildGo(sourceRoot, buildBin, "vantaloomctl")
146
159
 
147
160
  if (options.buildWeb) {
148
- run("pnpm", ["--filter", "vantaloom-app", "build"], { cwd: sourceRoot })
161
+ runPnpm(["--filter", "vantaloom-app", "build"], { cwd: sourceRoot })
149
162
  }
150
163
 
151
164
  await copyStandaloneWeb(sourceRoot, buildWeb)
@@ -176,7 +189,7 @@ async function applyPackage(packageRoot, prefix, options) {
176
189
  await cp(path.join(packageRoot, name), path.join(prefix, name), {
177
190
  recursive: true,
178
191
  force: true,
179
- dereference: true,
192
+ dereference: false,
180
193
  })
181
194
  }
182
195
 
@@ -206,7 +219,7 @@ async function applyPackage(packageRoot, prefix, options) {
206
219
  return version
207
220
  }
208
221
 
209
- async function updateFromDist(options) {
222
+ async function syncFromDist(options, action) {
210
223
  const prefix = safeDirectory(options.prefix ?? defaultPrefix())
211
224
  const installedConfig = readInstalledConfig(prefix)
212
225
  const sourceRoot = installedConfig.sourceRoot
@@ -241,10 +254,10 @@ async function updateFromDist(options) {
241
254
  const version = await applyPackage(packageRoot, prefix, {
242
255
  noStart: options.noStart,
243
256
  sourceRoot: installedConfig.sourceRoot,
244
- update: true,
257
+ update: action === "update",
245
258
  })
246
259
 
247
- console.log(`updated Vantaloom: ${prefix}`)
260
+ console.log(`${action === "update" ? "updated" : "installed"} Vantaloom: ${prefix}`)
248
261
  console.log(`version: ${version}`)
249
262
  console.log(`source: ${repo}#${distBranch}`)
250
263
  console.log(`run: ${displayCommand(prefix)} status`)
@@ -253,7 +266,7 @@ async function updateFromDist(options) {
253
266
  }
254
267
  }
255
268
 
256
- function shouldUseDistUpdate(options) {
269
+ function shouldUseDistSync(options) {
257
270
  return !options.local && !options.source && !options.buildWeb
258
271
  }
259
272
 
@@ -399,7 +412,11 @@ async function copyStandaloneWeb(sourceRoot, buildWeb) {
399
412
  }
400
413
 
401
414
  removeKnownPath(buildWeb, path.dirname(buildWeb))
402
- await copyDir(standalone, buildWeb)
415
+ const preserveStandaloneLinks = process.platform !== "win32"
416
+ await copyDir(standalone, buildWeb, { dereference: !preserveStandaloneLinks })
417
+ if (preserveStandaloneLinks) {
418
+ await copyStandaloneHoistedTargets(sourceRoot, buildWeb)
419
+ }
403
420
  await copyDir(staticSource, path.join(buildWeb, "apps", "vantaloom", ".next", "static"))
404
421
  await copyDir(publicSource, path.join(buildWeb, "apps", "vantaloom", "public"))
405
422
 
@@ -486,13 +503,72 @@ async function copyPnpmRuntimePackage(sourceRoot, packageName, destinationNodeMo
486
503
  await copyDir(source, path.join(destinationNodeModules, ...packageName.split("/")))
487
504
  }
488
505
 
489
- async function copyDir(source, destination) {
506
+ async function copyStandaloneHoistedTargets(sourceRoot, buildWeb) {
507
+ const sourceHoisted = path.join(sourceRoot, "node_modules", ".pnpm", "node_modules")
508
+ const buildHoisted = path.join(buildWeb, "node_modules", ".pnpm", "node_modules")
509
+ const packageNames = findHoistedSymlinkPackages(path.join(buildWeb, "node_modules"))
510
+
511
+ for (const packageName of packageNames) {
512
+ const source = path.join(sourceHoisted, ...packageName.split("/"))
513
+ if (existsSync(source)) {
514
+ await copyDir(source, path.join(buildHoisted, ...packageName.split("/")))
515
+ }
516
+ }
517
+ }
518
+
519
+ function findHoistedSymlinkPackages(nodeModules) {
520
+ const packages = new Set()
521
+ if (!existsSync(nodeModules)) {
522
+ return packages
523
+ }
524
+
525
+ for (const entry of readdirSync(nodeModules, { withFileTypes: true })) {
526
+ if (entry.name === ".pnpm" || entry.name.startsWith(".")) {
527
+ continue
528
+ }
529
+
530
+ const entryPath = path.join(nodeModules, entry.name)
531
+ if (entry.name.startsWith("@") && entry.isDirectory()) {
532
+ for (const scopedEntry of readdirSync(entryPath, { withFileTypes: true })) {
533
+ addHoistedSymlinkPackage(packages, path.join(entryPath, scopedEntry.name), `${entry.name}/${scopedEntry.name}`)
534
+ }
535
+ continue
536
+ }
537
+
538
+ addHoistedSymlinkPackage(packages, entryPath, entry.name)
539
+ }
540
+
541
+ return packages
542
+ }
543
+
544
+ function addHoistedSymlinkPackage(packages, packagePath, packageName) {
545
+ let stat
546
+ try {
547
+ stat = lstatSync(packagePath)
548
+ } catch {
549
+ return
550
+ }
551
+ if (!stat.isSymbolicLink()) {
552
+ return
553
+ }
554
+
555
+ const target = readlinkSync(packagePath).replaceAll("\\", "/")
556
+ if (target.includes(".pnpm/node_modules/")) {
557
+ packages.add(packageName)
558
+ }
559
+ }
560
+
561
+ async function copyDir(source, destination, options = {}) {
490
562
  if (!existsSync(source)) {
491
563
  throw new Error(`missing source directory: ${source}`)
492
564
  }
493
565
  removeKnownPath(destination, path.dirname(destination))
494
566
  mkdirSync(destination, { recursive: true })
495
- await cp(source, destination, { recursive: true, force: true, dereference: true })
567
+ await cp(source, destination, {
568
+ recursive: true,
569
+ force: true,
570
+ dereference: options.dereference ?? true,
571
+ })
496
572
  }
497
573
 
498
574
  function writeBuildManifest(buildRoot, version, platform) {
@@ -621,6 +697,14 @@ function run(command, args, options = {}) {
621
697
  }
622
698
  }
623
699
 
700
+ function runPnpm(args, options = {}) {
701
+ if (process.platform === "win32") {
702
+ run("cmd.exe", ["/d", "/s", "/c", "pnpm", ...args], options)
703
+ return
704
+ }
705
+ run("pnpm", args, options)
706
+ }
707
+
624
708
  function binaryName(name) {
625
709
  return process.platform === "win32" ? `${name}.exe` : name
626
710
  }
@@ -662,7 +746,8 @@ function printHelp() {
662
746
  console.log(`Vantaloom CLI
663
747
 
664
748
  Usage:
665
- vantaloom install [--prefix <dir>] [--source <repo>] [--build-web] [--package <dir>] [--no-start]
749
+ vantaloom install [--prefix <dir>] [--repo <owner/name>] [--remote <git-url>] [--dist-branch <branch>] [--package <dir>] [--no-start]
750
+ vantaloom install --local [--prefix <dir>] [--source <repo>] [--build-web] [--no-start]
666
751
  vantaloom update [--prefix <dir>] [--repo <owner/name>] [--remote <git-url>] [--dist-branch <branch>] [--no-start]
667
752
  vantaloom update --local [--prefix <dir>] [--source <repo>] [--build-web] [--no-start]
668
753
  vantaloom package [--source <repo>] [--output <dir>] [--build-web] [--archive]