Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// ==========================================================================
// Project: Seed - Flexible Package Manager
// Copyright: ©2009-2010 Apple Inc. All rights reserved.
// License: Licened under MIT license (see __preamble__.js)
// ==========================================================================
var core = require('private/core');
// exports some core API
exports.FIXTURES_ROOT = core.path.join(core.SEED_ROOT, 'fixtures');
exports.path = core.path;
exports.fs = core.fs;
exports.tiki = core.tiki;
// make a unit tmpdir just for this guy
if (!core.TMPDIR || core.TMPDIR.length===0) throw "no platform.TMPDIR";
exports.TMPDIR = core.path.join(core.TMPDIR, core.uuid());
// stage a fixture by copying it to the tmp directory.
exports.stage = function(fixturePath) {
var path = core.path.join.apply(core.path, arguments);
var src = core.path.join(exports.FIXTURES_ROOT, path);
var dst = core.path.join(exports.TMPDIR, path);
if (!core.fs.exists(src)) throw 'stage fixtures '+path+' not found';
core.fs.mkdir_p(core.path.dirname(dst), core.fs.A_RWX);
CORE.async(function() {
var pkg, dstPath;
// find the requested package in the repos
pkg = require.packageFor(packageId, vers);
if (!pkg) throw new Error(packageId+' '+vers+' not found');
// remove existing copy if forced or throw error
dstPath = CORE.path.join(dstRoot, pkg.get('name'));
if (CORE.fs.exists(dstPath)) {
if (!force) {
throw new Error(packageId+' already exists in working package. Use --force to override');
}
CORE.verbose("Removing existing package at "+dstPath);
CORE.fs.rm_r(dstPath);
}
// copy package into target
CORE.fs.mkdir_p(dstRoot, CORE.fs.A_RWX);
CORE.verbose("Copying "+pkg.path+" to "+dstPath);
pkg.copy(dstPath, function(err) {
if (err) return done(err);
CORE.println("Froze package "+packageId);
return done();
function forkPackage(workingPackage, vers, force, dirname) {
// compute the root to install at
var dstRoot = CORE.path.join(workingPackage.path, dirname);
return function(packageId, done) {
var pkg = require.packageFor(packageId, vers);
var repo;
if (!pkg) {
return done(new Error(packageId+' '+vers+' not found'));
}
// find a matching repository
repo = (pkg.get('repositories') || []).filter(function(r) {
return r.type && (r.type.toLowerCase() === 'git');
})[0];
if (!repo) {
return done(new Error(packageId+' does not list a git repository in its package info. Try just freezing instead.'));
}
function freezePackage(workingPackage, vers, force, dirname) {
// compute the root to install at
var dstRoot = CORE.path.join(workingPackage.path, dirname);
var mkdstRoot = CORE.once(function(done) {
CORE.fs.mkdir_p(dstRoot, 511, done);
});
return function(packageId, done) {
CORE.async(function() {
var pkg, dstPath;
// find the requested package in the repos
pkg = require.packageFor(packageId, vers);
if (!pkg) throw new Error(packageId+' '+vers+' not found');
// remove existing copy if forced or throw error
dstPath = CORE.path.join(dstRoot, pkg.get('name'));
if (CORE.fs.exists(dstPath)) {
if (!force) {
})(function(err) {
if (err) return done(err);
CORE.fs.mkdir_p(dstRoot, CORE.fs.A_RWX);
CORE.verbose("Cloning "+repo.url+" to "+dstPath);
var cmd = 'cd '+CORE.path.dirname(dstPath)+'; git clone '+repo.url+' '+CORE.path.basename(dstPath);
// we need to use ChildProcess so we can stream output as it
// comes
CORE.fs.exec(cmd, true, function(err) {
if (err) return done(err);
CORE.println("Forked package "+packageId);
return done();
});
});
};
(function(done) {
working = CORE.path.normalize(working);
CORE.async(function() {
return require.loader.openNearestPackage(working);
})(function(err, workingPackage) {
if (!err && !workingPackage) {
err = new Error("working package could not be found for "+working);
}
return err ? done(err) : done(null, workingPackage);
});
// next, find the packages for the packageId's in seed
})(function(err, workingPackage) {
if (err) return done(err);
tokens: function() {
if (this._tokens) return this._tokens;
var path = CORE.path.normalize('~/.seeds/tokens.json');
this._tokens = CORE.fs.exists(path) ? CORE.fs.readJSON(path) : {};
return this._tokens;
},