rm js fns

This commit is contained in:
2026-01-16 17:44:14 -06:00
parent ac91495679
commit b46406f755
42 changed files with 1954 additions and 2335 deletions

View File

@@ -28,8 +28,8 @@ function put_into_cache(content, obj)
function ensure_dir(path) {
if (fd.stat(path).isDirectory) return
var parts = path.split('/')
var current = path.startsWith('/') ? '/' : ''
var parts = array(path, '/')
var current = starts_with(path, '/') ? '/' : ''
for (var i = 0; i < parts.length; i++) {
if (parts[i] == '') continue
current += parts[i] + '/'
@@ -91,7 +91,7 @@ Shop.get_reports_dir = function() {
}
function get_import_package(name) {
var parts = name.split('/')
var parts = array(name, '/')
if (parts.length > 1)
return parts[0]
@@ -100,17 +100,17 @@ function get_import_package(name) {
function is_internal_path(path)
{
return path && path.startsWith('internal/')
return path && starts_with(path, 'internal/')
}
function split_explicit_package_import(path)
{
if (!path) return null
var parts = path.split('/')
var parts = array(path, '/')
if (parts.length < 2) return null
var looks_explicit = path.startsWith('/') || (parts[0] && parts[0].includes('.'))
var looks_explicit = starts_with(path, '/') || (parts[0] && search(parts[0], '.') != null)
if (!looks_explicit) return null
// Find the longest prefix that is an installed package
@@ -158,8 +158,8 @@ function abs_path_to_package(package_dir)
}
}
if (package_dir.startsWith(packages_prefix))
return package_dir.substring(packages_prefix.length)
if (starts_with(package_dir, packages_prefix))
return text(package_dir, packages_prefix.length)
// Check if this local path is the target of a link
// If so, return the canonical package name (link origin) instead
@@ -195,9 +195,9 @@ Shop.file_info = function(file) {
name: null
}
if (file.endsWith(MOD_EXT))
if (ends_with(file, MOD_EXT))
info.is_module = true
else if (file.endsWith(ACTOR_EXT))
else if (ends_with(file, ACTOR_EXT))
info.is_actor = true
// Find package directory and determine package name
@@ -206,11 +206,11 @@ Shop.file_info = function(file) {
info.package = abs_path_to_package(pkg_dir)
if (info.is_actor)
info.name = file.substring(pkg_dir.length + 1, file.length - ACTOR_EXT.length)
info.name = text(file, pkg_dir.length + 1, file.length - ACTOR_EXT.length)
else if (info.is_module)
info.name = file.substring(pkg_dir.length + 1, file.length - MOD_EXT.length)
info.name = text(file, pkg_dir.length + 1, file.length - MOD_EXT.length)
else
info.name = file.substring(pkg_dir.length + 1)
info.name = text(file, pkg_dir.length + 1)
}
return info
@@ -218,7 +218,7 @@ Shop.file_info = function(file) {
function get_import_name(path)
{
var parts = path.split('/')
var parts = array(path, '/')
if (parts.length < 2) return null
return text(array(parts, 1), '/')
}
@@ -246,7 +246,7 @@ function safe_package_path(pkg)
{
// For absolute paths, replace / with _ to create a valid directory name
// Also replace @ with _
if (pkg && pkg.startsWith('/'))
if (pkg && starts_with(pkg, '/'))
return pkg.replaceAll('/', '_').replaceAll('@', '_')
return pkg.replaceAll('@', '_')
}
@@ -290,8 +290,8 @@ Shop.save_lock = function(lock) {
// Get information about how to resolve a package
// Local packages always start with /
Shop.resolve_package_info = function(pkg) {
if (pkg.startsWith('/')) return 'local'
if (pkg.includes('gitea')) return 'gitea'
if (starts_with(pkg, '/')) return 'local'
if (search(pkg, 'gitea') != null) return 'gitea'
return null
}
@@ -301,8 +301,8 @@ Shop.verify_package_name = function(pkg) {
if (pkg == 'local') throw Error("local is not a valid package name")
if (pkg == 'core') throw Error("core is not a valid package name")
if (pkg.includes('://'))
throw Error(`Invalid package name: ${pkg}; did you mean ${pkg.split('://')[1]}?`)
if (search(pkg, '://') != null)
throw Error(`Invalid package name: ${pkg}; did you mean ${array(pkg, '://')[1]}?`)
}
// Convert module package to download URL
@@ -310,7 +310,7 @@ Shop.get_download_url = function(pkg, commit_hash) {
var info = Shop.resolve_package_info(pkg)
if (info == 'gitea') {
var parts = pkg.split('/')
var parts = array(pkg, '/')
var host = parts[0]
var user = parts[1]
var repo = parts[2]
@@ -326,7 +326,7 @@ Shop.get_api_url = function(pkg) {
var info = Shop.resolve_package_info(pkg)
if (info == 'gitea') {
var parts = pkg.split('/')
var parts = array(pkg, '/')
var host = parts[0]
var user = parts[1]
var repo = parts[2]
@@ -361,7 +361,7 @@ var open_dls = {}
var SHOP_DEFAULT_INJECT = ['$self', '$overling', '$clock', '$delay', '$start', '$receiver', '$contact', '$portal', '$time_limit', '$couple', '$stop', '$unneeded', '$connection', '$fd']
function strip_dollar(name) {
if (name && name[0] == '$') return name.substring(1)
if (name && name[0] == '$') return text(name, 1)
return name
}
@@ -470,7 +470,7 @@ function resolve_locator(path, ctx)
// If ctx is an absolute path (starts with /), use it directly
// Otherwise, look it up in the packages directory
var ctx_dir
if (ctx.startsWith('/')) {
if (starts_with(ctx, '/')) {
ctx_dir = ctx
} else {
ctx_dir = get_packages_dir() + '/' + safe_package_path(ctx)
@@ -541,7 +541,7 @@ Shop.open_package_dylib = function(pkg) {
var resolved_pkg = link_target ? link_target : pkg
var pkg_dir;
if (resolved_pkg.startsWith('/')) {
if (starts_with(resolved_pkg, '/')) {
pkg_dir = resolved_pkg
} else {
pkg_dir = get_packages_dir() + '/' + safe_package_path(resolved_pkg)
@@ -701,10 +701,10 @@ var module_info_cache = {}
function resolve_module_info(path, package_context) {
var lookup_key = package_context ? package_context + ':' + path : ':' + path
if (module_info_cache[lookup_key])
return module_info_cache[lookup_key]
var c_resolve = resolve_c_symbol(path, package_context) || {scope:999}
var mod_resolve = resolve_locator(path + '.cm', package_context) || {scope:999}
var min_scope = min(c_resolve.scope, mod_resolve.scope)
@@ -990,7 +990,7 @@ Shop.extract = function(pkg) {
if (lock_entry && lock_entry.commit) {
var extracted_commit_file = target_dir + '/.cell_commit'
if (fd.is_file(extracted_commit_file)) {
var extracted_commit = text(fd.slurp(extracted_commit_file)).trim()
var extracted_commit = trim(text(fd.slurp(extracted_commit_file)))
if (extracted_commit == lock_entry.commit) {
// Already extracted at this commit, skip
return true
@@ -1100,13 +1100,13 @@ function install_zip(zip_blob, target_dir) {
for (var i = 0; i < count; i++) {
if (zip.is_directory(i)) continue
var filename = zip.get_filename(i)
var parts = filename.split('/')
var parts = array(filename, '/')
if (parts.length <= 1) continue
parts.shift()
var rel_path = text(parts, '/')
var full_path = target_dir + '/' + rel_path
var dir_path = full_path.substring(0, full_path.lastIndexOf('/'))
var dir_path = text(full_path, 0, full_path.lastIndexOf('/'))
if (!created_dirs[dir_path]) {
ensure_dir(dir_path)
@@ -1203,7 +1203,7 @@ function get_package_scripts(package)
for (var i = 0; i < files.length; i++) {
var file = files[i]
if (file.endsWith('.cm') || file.endsWith('.ce')) {
if (ends_with(file, '.cm') || ends_with(file, '.ce')) {
scripts.push(file)
}
}
@@ -1251,7 +1251,7 @@ Shop.get_package_dir = function(pkg) {
// -> 'js_gitea_pockle_world_john_prosperon_sprite_use'
Shop.c_symbol_for_file = function(pkg, file) {
var pkg_safe = pkg.replaceAll(/\//g, '_').replaceAll(/\./g, '_').replaceAll(/-/g, '_')
var file_safe = file.substring(0, file.lastIndexOf('.')).replaceAll(/\//g, '_').replaceAll(/\./g, '_').replaceAll(/-/g, '_')
var file_safe = text(file, 0, file.lastIndexOf('.')).replaceAll(/\//g, '_').replaceAll(/\./g, '_').replaceAll(/-/g, '_')
return 'js_' + pkg_safe + '_' + file_safe + '_use'
}
@@ -1291,15 +1291,15 @@ Shop.parse_package = function(locator) {
// Strip version suffix if present
var clean = locator
if (locator.includes('@')) {
clean = locator.split('@')[0]
if (search(locator, '@') != null) {
clean = array(locator, '@')[0]
}
var info = Shop.resolve_package_info(clean)
if (!info) return null
// Extract package name (last component of path)
var parts = clean.split('/')
var parts = array(clean, '/')
var name = parts[parts.length - 1]
return {