This commit is contained in:
2025-12-03 07:59:31 -06:00
parent 814ee7c0db
commit 76bdccc4ee
3 changed files with 58 additions and 84 deletions

View File

@@ -9,11 +9,6 @@ cell.os = null
var dylib_ext
function mod_scriptor(name, script)
{
return `(function setup_${name}_module($_){${script}})`
}
switch(os.platform()) {
case 'Windows': dylib_ext = '.dll'; break;
case 'macOS': dylib_ext = '.dylib'; break;
@@ -35,11 +30,6 @@ var js = use_embed('js')
var use_cache = {}
// Three domains:
// core
// local
// module scope
function use_core(path) {
var cache_path = `2:${path}`;
if (use_cache[cache_path])
@@ -49,7 +39,7 @@ function use_core(path) {
var script = core_qop.read(path + MOD_EXT);
if (script) {
script = utf8.decode(script)
var mod = mod_scriptor(path, script)
var mod = `(function setup_${path}_module($_){${script}})`
var fn = js.eval(path, mod)
var result = fn.call(sym);
use_cache[cache_path] = result;
@@ -72,16 +62,13 @@ function deepFreeze(object) {
if (object instanceof blob)
blob_stone.call(object);
// Retrieve the property names defined on object
var propNames = Object.keys(object);
// Freeze properties before freezing self
for (var name of propNames) {
var value = object[name];
if ((value && typeof value == "object") || typeof value == "function") {
if ((value && typeof value == "object") || typeof value == "function")
deepFreeze(value);
}
}
return Object.freeze(object);
@@ -96,11 +83,9 @@ stone.p = function(object)
return Object.isFrozen(object)
}
var actor_mod = use_embed('actor')
var wota = use_embed('wota')
var nota = use_embed('nota')
var fd = use_embed('fd')
var actor_mod = use('actor')
var wota = use('wota')
var nota = use('nota')
globalThis.text = use('text')
var ENETSERVICE = 0.1
@@ -451,7 +436,7 @@ $_.delay = function delay(fn, seconds = 0) {
return function() { actor_mod.removetimer(id) }
}
var enet = use_embed('enet')
var enet = use('enet')
// causes this actor to stop when another actor stops.
var couplings = new Set()

View File

@@ -17,27 +17,6 @@ if (args.length < 1) {
var locator = args[0]
var parsed = shop.parse_locator(locator)
// If no version specified, append @head
if (!parsed) {
if (locator.indexOf('@') == -1) {
locator = locator + '@head'
parsed = shop.parse_locator(locator)
}
}
if (!parsed) {
log.error("Invalid locator format. Expected: host/owner/name[@version]")
$_.stop()
return
}
// Initialize shop if needed
if (!fd.stat('.cell/cell.toml').isFile) {
log.console("No cell.toml found. Initializing...")
shop.init()
}
// Load current config
var config = shop.load_config()
if (!config) {
log.error("Failed to load cell.toml")
@@ -47,8 +26,13 @@ if (!config) {
// Use the module name as the default alias
var alias = parsed.name
if (args.length > 1) {
if (args.length > 1)
alias = args[1]
if (!alias) {
log.error("Failed to determine alias")
$_.stop()
return
}
// Check if already exists
@@ -65,18 +49,10 @@ shop.add_dependency(alias, locator)
// Create module directory
var module_dir = '.cell/modules/' + alias + '@' + parsed.version
if (!fd.stat(module_dir).isDirectory) {
if (!fd.is_directory(module_dir))
fd.mkdir(module_dir)
}
// TODO: Actually fetch the module from the repository
log.console("Module directory created at: " + module_dir)
log.console("TODO: Implement actual fetching from " + parsed.path)
log.console("")
log.console("For now, manually place module files in: " + module_dir)
log.console("Then run 'cell build' to compile modules")
// Update lock.toml
// TODO: Calculate and store checksums
$_.stop()

View File

@@ -152,56 +152,80 @@ Shop.save_config = function(config) {
slurpwrite(shop_path, toml.encode(config));
}
function lock_path(pkg)
{
if (pkg)
return `.cell/modules/${pkg}/.cell/lock.toml`
else
return '.cell/lock.toml'
}
// Load lock.toml configuration
Shop.load_lock = function() {
if (!fd.stat(lock_path).isFile)
return {}
Shop.load_lock = function(pkg) {
var path = lock_path(pkg)
if (!fd.is_file(path))
return null
var content = text(fd.slurp(lock_path))
return toml.decode(content) || {}
return toml.decode(content)
}
// Save lock.toml configuration
Shop.save_lock = function(lock) {
slurpwrite(lock_path, toml.encode(lock));
Shop.save_lock = function(pkg, lock) {
var path = lock_path(pkg)
slurpwrite(path, toml.encode(lock));
}
// Initialize .cell directory structure
Shop.init = function() {
if (!fd.stat('.cell').isDirectory) {
if (!fd.is_directory('.cell')) {
fd.mkdir('.cell')
}
if (!fd.stat('.cell/modules').isDirectory) {
if (!fd.is_directory('.cell/modules')) {
fd.mkdir('.cell/modules')
}
if (!fd.stat('.cell/build').isDirectory) {
if (!fd.is_directory('.cell/build')) {
fd.mkdir('.cell/build')
}
if (!fd.stat('.cell/patches').isDirectory) {
fd.mkdir('.cell/patches')
}
if (!fd.stat('.cell/lock.toml').isFile) {
if (!fd.is_file('.cell/lock.toml')) {
slurpwrite('.cell/lock.toml', '# Lock file for module integrity\n');
}
return true
}
// Parse module locator (e.g., "git.world/jj/mod@v0.6.3")
// Parse module locator (e.g., "https://git.world/jj/mod@v0.6.3")
Shop.parse_locator = function(locator) {
var parts = locator.split('@')
if (parts.length != 2) {
return null
var protocol = null
var path = locator
var version = null
// Extract method (e.g., "https")
if (locator.includes('://')) {
var methodParts = locator.split('://')
protocol = methodParts[0]
path = methodParts[1]
}
// Extract version if present
if (path.includes('@')) {
var versionParts = path.split('@')
path = versionParts[0]
version = versionParts[1]
}
// Extract name (last part of path)
var name = path.split('/').pop()
return {
path: parts[0],
version: parts[1],
name: parts[0].split('/').pop()
protocol,
path,
name,
version
}
}
@@ -480,19 +504,8 @@ Shop.verify = function() {
return all_ok
}
var open_dls = {}
function get_locator_module_path(locator)
{
var canon_pkg = get_package_from_path(locator);
var path = `.cell/modules/${canon_pkg}`;
if (fd.is_directory(path))
return path;
return null
}
function resolve_locator(path, ext, ctx)
{
var deps = Shop.load_config(ctx).dependencies || {}