cache config in package.cm
This commit is contained in:
13
package.cm
13
package.cm
@@ -2,9 +2,13 @@ var package = {}
|
||||
|
||||
var fd = use('fd')
|
||||
var toml = use('toml')
|
||||
var json = use('json')
|
||||
var os = use('os')
|
||||
var link = use('link')
|
||||
|
||||
// Cache for loaded configs to avoid toml re-parsing corruption
|
||||
var config_cache = {}
|
||||
|
||||
// Convert package name to a safe directory name
|
||||
// For absolute paths (local packages), replace / with _
|
||||
// For remote packages, keep slashes as they use nested directories
|
||||
@@ -42,6 +46,11 @@ function get_path(name)
|
||||
package.load_config = function(name)
|
||||
{
|
||||
var config_path = get_path(name) + '/cell.toml'
|
||||
|
||||
// Return cached config if available
|
||||
if (config_cache[config_path])
|
||||
return config_cache[config_path]
|
||||
|
||||
if (!fd.is_file(config_path))
|
||||
throw Error(`${config_path} does not exist`)
|
||||
|
||||
@@ -54,6 +63,10 @@ package.load_config = function(name)
|
||||
return {}
|
||||
}
|
||||
|
||||
// Deep copy to avoid toml module's shared state bug and cache it
|
||||
result = json.decode(json.encode(result))
|
||||
config_cache[config_path] = result
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user