How to use @boost/internal - 10 common examples

To help you get started, we’ve selected a few @boost/internal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github milesj / boost / packages / plugin / src / Loader.ts View on Github external
// @scope/name
    } else if (
      moduleName.match(new RegExp(`^@${modulePattern}/${modulePattern}$`, 'u')) &&
      isNotToolOrType
    ) {
      const [scope, customName] = moduleName.split('/');
      const customModuleName = `${scope}/${projectName}-${typeName}-${customName}`;

      this.debug('Found a shorthand module with custom scope: %s', color.moduleName(moduleName));

      resolver.lookupNodeModule(customModuleName);

      // tool-plugin-name
    } else if (moduleName.match(new RegExp(`^${projectName}-${typeName}-${modulePattern}$`, 'u'))) {
      this.debug('Found an explicit public module: %s', color.moduleName(moduleName));

      resolver.lookupNodeModule(moduleName);

      // The previous 2 patterns if only name provided
    } else if (moduleName.match(new RegExp(`^${modulePattern}$`, 'u')) && isNotToolOrType) {
      this.debug(
        'Resolving modules with internal "%s" scope and public "%s" prefix',
        color.toolName(`@${projectName}`),
        color.toolName(projectName),
      );

      // Detect internal scopes before public ones
      resolver.lookupNodeModule(this.manager.formatModuleName(moduleName, true));
      resolver.lookupNodeModule(this.manager.formatModuleName(moduleName));

      // Unknown plugin module pattern
github milesj / boost / packages / pipeline / src / createWorkUnit.ts View on Github external
export default function createWorkUnit<input>(
  titleOrWorkUnit: string | WorkUnit&lt;{}, Input, Output&gt;,
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  action?: Action,
  scope?: unknown,
): WorkUnit&lt;{}, Input, Output&gt; {
  if (titleOrWorkUnit instanceof WorkUnit) {
    return titleOrWorkUnit;
  }

  if (typeof titleOrWorkUnit === 'string' &amp;&amp; typeof action === 'function') {
    return new Task(titleOrWorkUnit, scope ? action.bind(scope) : action);
  }

  throw new RuntimeError('pipeline', 'PL_INVALID_WORK_UNIT');
}
github milesj / boost / packages / core / src / ModuleLoader.ts View on Github external
importModule(name: string | Path, args: any[] = []): Tm {
    const { typeName } = this;
    const { appName, scoped } = this.tool.options;

    // Determine modules to attempt to load
    const modulesToAttempt = [];
    let isFilePath = false;
    let importedModule: any = null;
    let moduleName;

    // File path
    if (name instanceof Path || name.match(/^\.|\/|\\|[A-Z]:/u)) {
      this.debug('Locating %s from path %s', typeName, color.filePath(name));

      modulesToAttempt.push(Path.create(name).path());
      isFilePath = true;

      // Module name
    } else {
      this.debug('Locating %s module %s', typeName, color.moduleName(name));

      if (scoped) {
        modulesToAttempt.push(formatModuleName(appName, typeName, name, true));
      }

      modulesToAttempt.push(formatModuleName(appName, typeName, name));

      // Additional scopes to load
      this.scopes.forEach(otherScope => {
github milesj / boost / packages / core / src / ModuleLoader.ts View on Github external
// Determine modules to attempt to load
    const modulesToAttempt = [];
    let isFilePath = false;
    let importedModule: any = null;
    let moduleName;

    // File path
    if (name instanceof Path || name.match(/^\.|\/|\\|[A-Z]:/u)) {
      this.debug('Locating %s from path %s', typeName, color.filePath(name));

      modulesToAttempt.push(Path.create(name).path());
      isFilePath = true;

      // Module name
    } else {
      this.debug('Locating %s module %s', typeName, color.moduleName(name));

      if (scoped) {
        modulesToAttempt.push(formatModuleName(appName, typeName, name, true));
      }

      modulesToAttempt.push(formatModuleName(appName, typeName, name));

      // Additional scopes to load
      this.scopes.forEach(otherScope => {
        modulesToAttempt.push(
          formatModuleName(otherScope, typeName, name, true),
          formatModuleName(otherScope, typeName, name),
        );
      });

      this.debug('Resolving in order: %s', modulesToAttempt.join(', '));
github milesj / boost / packages / plugin / src / Loader.ts View on Github external
createResolver(name: ModuleName): PathResolver {
    const resolver = new PathResolver();
    const { singularName: typeName, projectName } = this.manager;
    const moduleName = name.toLowerCase();
    const modulePattern = MODULE_PART_PATTERN.source;
    const isNotToolOrType = !moduleName.includes(projectName) && !moduleName.includes(typeName);

    this.debug('Resolving possible %s modules', color.pluginName(typeName));

    // @scope/tool-plugin-name
    if (
      moduleName.match(
        new RegExp(`^@${modulePattern}/${projectName}-${typeName}-${modulePattern}$`, 'u'),
      )
    ) {
      this.debug('Found an explicit module with custom scope: %s', color.moduleName(moduleName));

      resolver.lookupNodeModule(moduleName);

      // @tool/plugin-name
    } else if (
      moduleName.match(new RegExp(`^@${projectName}/${typeName}-${modulePattern}$`, 'u'))
    ) {
      this.debug('Found an explicit internal module with scope: %s', color.moduleName(moduleName));

      resolver.lookupNodeModule(moduleName);

      // @scope/name
    } else if (
      moduleName.match(new RegExp(`^@${modulePattern}/${modulePattern}$`, 'u')) &&
      isNotToolOrType
    ) {
github milesj / boost / packages / core / src / Tool.ts View on Github external
protected loadReporters(): this {
    if (this.initialized) {
      return this;
    }

    if (isEmpty(this.config)) {
      throw new Error(this.msg('errors:configNotLoaded', { name: 'reporters' }));
    }

    const reporters = this.plugins.reporter!;
    const { loader } = this.pluginTypes.reporter!;

    // Use a special reporter when in a CI
    // istanbul ignore next
    if (this.isCI() && !env('ENV')) {
      loader.debug('CI environment detected, using %s CI reporter', color.moduleName('boost'));

      this.addPlugin('reporter', new CIReporter());

      // Use default reporter
    } else if (
      reporters.size === 0 ||
      (reporters.size === 1 && instanceOf(Array.from(reporters)[0], ErrorReporter))
    ) {
      loader.debug('Using default %s reporter', color.moduleName('boost'));

      this.addPlugin('reporter', new BoostReporter());
    }

    return this;
  }
github milesj / boost / packages / core / src / Tool.ts View on Github external
header: string(),
        root: string(process.cwd()),
        scoped: bool(),
        settingsBlueprint: object(),
        workspaceRoot: string(),
      },
      {
        name: this.constructor.name,
      },
    );

    this.appPath = Path.resolve(this.options.appPath);
    this.rootPath = Path.resolve(this.options.root);

    // Set environment variables
    env('DEBUG_GLOBAL_NAMESPACE', this.options.appName);

    // Core debugger, logger, and translator for the entire tool
    this.debug = createDebugger('core');

    this.log = createLogger();

    this.msg = createTranslator(
      ['app', 'errors'],
      [
        new Path(__dirname, '../res'),
        this.appPath.append('res'),
        // TODO Remove in 2.0
        this.appPath.append('resources'),
      ],
      {
        // TODO Change to yaml in 2.0
github milesj / boost / packages / debug / src / createDebugger.ts View on Github external
export default function createDebugger(namespace: string | string[]): Debugger {
  const globalNamespace = env('DEBUG_GLOBAL_NAMESPACE');
  const namespaces = toArray(namespace);

  if (globalNamespace) {
    namespaces.unshift(globalNamespace);
  }

  const mainNamespace = namespaces.join(':');

  debug(
    'New debugger created: %s %s',
    mainNamespace,
    env('DEBUG_VERBOSE') ? '(verbose enabled)' : '',
  );

  const logger = coreDebug(mainNamespace) as Debugger;

  // `debug` doesn't support this on an individual namespace basis,
  // so we have to manually support it using this hacky regex.
  logger.disable = () => {
    debug('Debugger %s disabled', mainNamespace);

    process.env.DEBUG = (process.env.DEBUG || '')
      .replace(new RegExp(`${logger.namespace}(:\\*)?`, 'u'), '')
      .replace(/(^,)|(,$)/u, '')
      .replace(',,', ',');
  };

  logger.enable = () => {
github milesj / boost / packages / plugin / src / Loader.ts View on Github external
this.debug('Found a shorthand module with custom scope: %s', color.moduleName(moduleName));

      resolver.lookupNodeModule(customModuleName);

      // tool-plugin-name
    } else if (moduleName.match(new RegExp(`^${projectName}-${typeName}-${modulePattern}$`, 'u'))) {
      this.debug('Found an explicit public module: %s', color.moduleName(moduleName));

      resolver.lookupNodeModule(moduleName);

      // The previous 2 patterns if only name provided
    } else if (moduleName.match(new RegExp(`^${modulePattern}$`, 'u')) && isNotToolOrType) {
      this.debug(
        'Resolving modules with internal "%s" scope and public "%s" prefix',
        color.toolName(`@${projectName}`),
        color.toolName(projectName),
      );

      // Detect internal scopes before public ones
      resolver.lookupNodeModule(this.manager.formatModuleName(moduleName, true));
      resolver.lookupNodeModule(this.manager.formatModuleName(moduleName));

      // Unknown plugin module pattern
    } else {
      throw new Error(`Unknown plugin module format "${moduleName}".`);
    }

    return resolver;
  }
github milesj / boost / packages / plugin / src / Loader.ts View on Github external
this.debug('Found a shorthand module with custom scope: %s', color.moduleName(moduleName));

      resolver.lookupNodeModule(customModuleName);

      // tool-plugin-name
    } else if (moduleName.match(new RegExp(`^${projectName}-${typeName}-${modulePattern}$`, 'u'))) {
      this.debug('Found an explicit public module: %s', color.moduleName(moduleName));

      resolver.lookupNodeModule(moduleName);

      // The previous 2 patterns if only name provided
    } else if (moduleName.match(new RegExp(`^${modulePattern}$`, 'u')) && isNotToolOrType) {
      this.debug(
        'Resolving modules with internal "%s" scope and public "%s" prefix',
        color.toolName(`@${projectName}`),
        color.toolName(projectName),
      );

      // Detect internal scopes before public ones
      resolver.lookupNodeModule(this.manager.formatModuleName(moduleName, true));
      resolver.lookupNodeModule(this.manager.formatModuleName(moduleName));

      // Unknown plugin module pattern
    } else {
      throw new Error(`Unknown plugin module format "${moduleName}".`);
    }

    return resolver;
  }