<commit_before>"use strict";

if (typeof Map !== 'function') throw new Error('Package "jspm-fs" requires ES6 language features');

const path = require('path');
const fs = require('graceful-fs');
const semver = require('semver');
const unzip = require('unzip');
const utils = require('./lib/utils');

// Constants
const BASEDIR_ENV_NAME = 'JSPM_REGISTRY_FS_BASEDIR';

class FilesystemLocationError extends Error {}

class FilesystemLocator {

  /**
   *
   * @param {object} config
   * @param {object} ui
   * @returns {Promise}
   */
  static configure(config, ui) {
    return ui.input(
      'Enter absolute directory path to where your package release files reside: ',
      config.baseDir || process.env[BASEDIR_ENV_NAME]
    ).then(baseDir => config.baseDir = baseDir);
  }

  constructor(options, ui) {
    this._ui = ui;
    this.versionString = options.versionString + '.1';

    console.log(options.apiVersion);
    
    if (!semver.satisfies(options.apiVersion, '^1.0')) {
      throw new FilesystemLocationError('Current jspm-fs version isn\'t compatible to the jspm Endpoint API v' + options.apiVersion + '\n' +
      'Please update or install a compatible version of jspm-fs.');
    }

    // Determine base directory used to resolve symbolic package names
    this._baseDir = path.resolve(options.baseDir || process.env[BASEDIR_ENV_NAME] || '');
    if (!utils.isDirectory(this._baseDir)) {
      throw new FilesystemLocator(
        `Environment variable ${BASEDIR_ENV_NAME} doesn't point to a valid registry base directory: "${this._baseDir}"`);
    }
  }

  /**
   * Locate given package name
   * @param {string} packageName
   * @returns {Promise}
   */
  locate(packageName) {
    // TODO: Add support for absolute file paths (when pkgName doesn't begin with alphanum char)
    const expectedSourceDir = path.resolve(path.join(this._baseDir, packageName));
    if (!expectedSourceDir.startsWith(this._baseDir)) {
      const error = new FilesystemLocationError('FilesystemLocator: Invalid package name! Package name must not contain relative path fragments');
      error.config = true;
      return Promise.reject(error);
    }

    if (!utils.isDirectory(expectedSourceDir))<commit_msg>Adapt JSPM registry api version checking<commit_after>"use strict";

if (typeof Map !== 'function') throw new Error('Package "jspm-fs" requires ES6 language features');

const path = require('path');
const fs = require('graceful-fs');
const semver = require('semver');
const unzip = require('unzip');
const utils = require('./lib/utils');

// Constants
const BASEDIR_ENV_NAME = 'JSPM_REGISTRY_FS_BASEDIR';

class FilesystemLocationError extends Error {}

class FilesystemLocator {

  /**
   *
   * @param {object} config
   * @param {object} ui
   * @returns {Promise}
   */
  static configure(config, ui) {
    return ui.input(
      'Enter absolute directory path to where your package release files reside: ',
      config.baseDir || process.env[BASEDIR_ENV_NAME]
    ).then(baseDir => config.baseDir = baseDir);
  }

  constructor(options, ui) {
    this._ui = ui;
    this.versionString = options.versionString + '.1';

    console.log(options.apiVersion);
    
    if (!semver.satisfies(options.apiVersion, '>=1.7')) {
      throw new FilesystemLocatiorError('Current jspm-fs version isn\'t compatible to the jspm Endpoint API v' + options.apiVersion + '\n' +
      'Please update or install a compatible version of jspm-fs.');
    }

    // Determine base directory used to resolve symbolic package names
    this._baseDir = path.resolve(options.baseDir || process.env[BASEDIR_ENV_NAME] || '');
    if (!utils.isDirectory(this._baseDir)) {
      throw new FilesystemLocator(
        `Environment variable ${BASEDIR_ENV_NAME} doesn't point to a valid registry base directory: "${this._baseDir}"`);
    }
  }

  /**
   * Locate given package name
   * @param {string} packageName
   * @returns {Promise}
   */
  locate(packageName) {
    // TODO: Add support for absolute file paths (when pkgName doesn't begin with alphanum char)
    const expectedSourceDir = path.resolve(path.join(this._baseDir, packageName));
    if (!expectedSourceDir.startsWith(this._baseDir)) {
      const error = new FilesystemLocationError('FilesystemLocator: Invalid package name! Package name must not contain relative path fragments');
      error.config = true;
      return Promise.reject(error);
    }

    if (!utils.isDirectory(expectedSourceDir))
{'fraction_non_alphanumeric': 0.12072841726618705, 'fraction_numerical': 0.0017985611510791368, 'mean_word_length': 3.804535637149028, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1899993', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1302, 'n_words': 370}