This commit is contained in:
2026-01-09 07:36:48 -06:00
parent d044bde4f9
commit e04b15973a
3 changed files with 108 additions and 9 deletions

84
link.cm
View File

@@ -90,7 +90,7 @@ Link.add = function(canonical, target, shop) {
if (!lock[canonical]) {
throw new Error('Package ' + canonical + ' is not installed. Install it first with: cell get ' + canonical)
}
// Validate target is a valid package
if (target.startsWith('/')) {
// Local path - must have cell.toml
@@ -101,14 +101,44 @@ Link.add = function(canonical, target, shop) {
// Remote package target - ensure it's installed
shop.get(target)
}
var links = Link.load()
links[canonical] = target
Link.save(links)
// Create the symlink immediately
Link.sync_one(canonical, target, shop)
// Install dependencies of the linked package
// Read the target's cell.toml to find its dependencies
var target_path = target.startsWith('/') ? target : get_package_abs_dir(target)
var toml_path = target_path + '/cell.toml'
if (fd.is_file(toml_path)) {
try {
var content = text(fd.slurp(toml_path))
var cfg = toml.decode(content)
if (cfg.dependencies) {
for (var alias in cfg.dependencies) {
var dep_locator = cfg.dependencies[alias]
// Skip local dependencies that don't exist
if (dep_locator.startsWith('/') && !fd.is_dir(dep_locator)) {
log.console(" Skipping missing local dependency: " + dep_locator)
continue
}
// Install the dependency if not already in shop
try {
shop.get(dep_locator)
shop.extract(dep_locator)
} catch (e) {
log.console(" Warning: Could not install dependency " + dep_locator + ": " + e.message)
}
}
}
} catch (e) {
log.console(" Warning: Could not read dependencies from " + toml_path)
}
}
log.console("Linked " + canonical + " -> " + target)
return true
}
@@ -177,12 +207,12 @@ Link.sync_one = function(canonical, target, shop) {
return true
}
// Sync all links - ensure all symlinks are in place
// Sync all links - ensure all symlinks are in place and dependencies are installed
Link.sync_all = function(shop) {
var links = Link.load()
var count = 0
var errors = []
for (var canonical in links) {
var target = links[canonical]
try {
@@ -196,14 +226,40 @@ Link.sync_all = function(shop) {
errors.push(canonical + ': target ' + link_target + ' is not a valid package')
continue
}
Link.sync_one(canonical, target, shop)
// Install dependencies of the linked package
var toml_path = link_target + '/cell.toml'
try {
var content = text(fd.slurp(toml_path))
var cfg = toml.decode(content)
if (cfg.dependencies) {
for (var alias in cfg.dependencies) {
var dep_locator = cfg.dependencies[alias]
// Skip local dependencies that don't exist
if (dep_locator.startsWith('/') && !fd.is_dir(dep_locator)) {
continue
}
// Install the dependency if not already in shop
try {
shop.get(dep_locator)
shop.extract(dep_locator)
} catch (e) {
// Silently continue - dependency may already be installed
}
}
}
} catch (e) {
// Could not read dependencies - continue anyway
}
count++
} catch (e) {
errors.push(canonical + ': ' + e.message)
}
}
return { synced: count, errors: errors }
}
@@ -219,4 +275,16 @@ Link.get_target = function(canonical) {
return links[canonical] || null
}
// Get the canonical package name that links to this target (reverse lookup)
// Returns null if no package links to this target
Link.get_origin = function(target) {
var links = Link.load()
for (var origin in links) {
if (links[origin] == target) {
return origin
}
}
return null
}
return Link