patch so core path is recognized
This commit is contained in:
@@ -143,8 +143,22 @@ function abs_path_to_package(package_dir)
|
||||
{
|
||||
if (!fd.is_file(package_dir + '/cell.toml'))
|
||||
throw new Error('Not a valid package directory (no cell.toml): ' + package_dir)
|
||||
|
||||
|
||||
var packages_prefix = get_packages_dir() + '/'
|
||||
var core_dir = packages_prefix + core_package
|
||||
|
||||
// Check if this is the core package directory (or its symlink target)
|
||||
if (package_dir == core_dir) {
|
||||
return 'core'
|
||||
}
|
||||
// Also check if core_dir is a symlink pointing to package_dir
|
||||
if (fd.is_link(core_dir)) {
|
||||
var core_target = fd.readlink(core_dir)
|
||||
if (core_target == package_dir || fd.realpath(core_dir) == package_dir) {
|
||||
return 'core'
|
||||
}
|
||||
}
|
||||
|
||||
if (package_dir.startsWith(packages_prefix))
|
||||
return package_dir.substring(packages_prefix.length)
|
||||
|
||||
@@ -475,7 +489,10 @@ function resolve_locator(path, ctx)
|
||||
|
||||
if (fd.is_file(ctx_path)) {
|
||||
var fn = resolve_mod_fn(ctx_path, ctx)
|
||||
return {path: ctx_path, scope: SCOPE_LOCAL, symbol: fn}
|
||||
// Check if ctx is the core package (either by name or by path)
|
||||
var is_core = (ctx == 'core') || (ctx_dir == Shop.get_core_dir())
|
||||
var scope = is_core ? SCOPE_CORE : SCOPE_LOCAL
|
||||
return {path: ctx_path, scope: scope, symbol: fn}
|
||||
}
|
||||
|
||||
if (is_internal_path(path))
|
||||
|
||||
55
internal/testlib.cm
Normal file
55
internal/testlib.cm
Normal file
@@ -0,0 +1,55 @@
|
||||
// Shared test/bench infrastructure
|
||||
var fd = use('fd')
|
||||
var pkg = use('package')
|
||||
|
||||
// Check if current directory is a valid cell package
|
||||
function is_valid_package(dir) {
|
||||
if (!dir) dir = '.'
|
||||
return fd.is_file(dir + '/cell.toml')
|
||||
}
|
||||
|
||||
// Get current package name from cell.toml or null
|
||||
function get_current_package_name() {
|
||||
if (!is_valid_package('.')) return null
|
||||
try {
|
||||
var config = pkg.load_config(null)
|
||||
return config.package || 'local'
|
||||
} catch (e) {
|
||||
return 'local'
|
||||
}
|
||||
}
|
||||
|
||||
// Get the directory for a package
|
||||
function get_pkg_dir(package_name) {
|
||||
if (!package_name) {
|
||||
return fd.realpath('.')
|
||||
}
|
||||
if (package_name.startsWith('/')) {
|
||||
return package_name
|
||||
}
|
||||
var shop = use('internal/shop')
|
||||
return shop.get_package_dir(package_name)
|
||||
}
|
||||
|
||||
// Ensure directory exists
|
||||
function ensure_dir(path) {
|
||||
if (fd.is_dir(path)) return true
|
||||
|
||||
var parts = path.split('/')
|
||||
var current = path.startsWith('/') ? '/' : ''
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
if (parts[i] == '') continue
|
||||
current += parts[i] + '/'
|
||||
if (!fd.is_dir(current)) {
|
||||
fd.mkdir(current)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
return {
|
||||
is_valid_package: is_valid_package,
|
||||
get_current_package_name: get_current_package_name,
|
||||
get_pkg_dir: get_pkg_dir,
|
||||
ensure_dir: ensure_dir
|
||||
}
|
||||
Reference in New Issue
Block a user