Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bolt/src/PackageStore.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ const PACKAGE_STORE_DIR = 'bolts';
const MAX_DEPTH = 100;

class PackageStore {
static find(workDir) {
static find(workDir, searched) {
let base = process.env.BUILDDIR ?? process.cwd();
let foundPath;

for (let i = 0; i < MAX_DEPTH; ++i) {
const path = resolve(base + '/' + PACKAGE_STORE_DIR);
searched?.push(path);

if (statSync(path, { throwIfNoEntry: false })?.isDirectory()) {
foundPath = path;
Expand Down
5 changes: 3 additions & 2 deletions bolt/src/fetch.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,10 @@ async function fetch(packageName, options) {
throw new Error('No package store URL configured. Set "packageStoreURL" in ~/.bolt/config.json');
}

const packageStore = PackageStore.find(process.cwd());
const searchedStoreDirs = [];
const packageStore = PackageStore.find(process.cwd(), searchedStoreDirs);
if (!packageStore) {
throw new Error('Local package store not found');
throw new Error(`Could not find the local package store. Searched in:\n${searchedStoreDirs.join('\n')}`);
}

const packageFileName = Package.isPackageFileName(packageName)
Expand Down
5 changes: 3 additions & 2 deletions bolt/src/make.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ async function makeCommand(packageAlias, workDir, options) {

const packageConfigBuilder = new PackageConfigBuilder(packageConfig);
packageConfigBuilder.resolveAutoValues(packageConfigStore.getPath());
const packageStore = PackageStore.find(workDir);
const searchedStoreDirs = [];
const packageStore = PackageStore.find(workDir, searchedStoreDirs);

if (options.install && !packageStore) {
throw new Error(`Package store not found!`);
throw new Error(`Could not find the local package store. Searched in:\n${searchedStoreDirs.join('\n')}`);
}

let contentFile;
Expand Down
14 changes: 10 additions & 4 deletions bolt/src/push.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function push(remoteName, pkg, options) {
}
}

function findPackage(pkgParam, workDir, locations) {
function findPackage(pkgParam, workDir, locations, searchedStoreDirs) {
let result = Package.fromPath(pkgParam, workDir);

if (result) return result;
Expand All @@ -51,8 +51,9 @@ function findPackage(pkgParam, workDir, locations) {
locations.push(fileName);
}

const packageStore = PackageStore.find(workDir);
const packageStore = PackageStore.find(workDir, searchedStoreDirs);
if (packageStore) {
searchedStoreDirs?.splice(0);
result = packageStore.getPackage(pkgParam);
if (result) return result;
locations.push(packageStore.generatePackagePath(pkgParam));
Expand All @@ -64,10 +65,15 @@ function findPackage(pkgParam, workDir, locations) {

function pushCommand(remoteName, pkgParam, workDir, options) {
const pkgSearchLocations = [];
const pkg = findPackage(pkgParam, workDir, pkgSearchLocations);
const searchedStoreDirs = [];
const pkg = findPackage(pkgParam, workDir, pkgSearchLocations, searchedStoreDirs);

if (!pkg) {
throw new Error(`Package ${pkgParam} not found, tried:\n${pkgSearchLocations.join('\n')}`);
let message = `Package ${pkgParam} not found, tried:\n${pkgSearchLocations.join('\n')}`;
if (searchedStoreDirs.length > 0) {
message += `\nNo local package store found. Searched in:\n${searchedStoreDirs.join('\n')}`;
}
throw new Error(message);
}

const remote = new Remote(remoteName);
Expand Down
Loading