@ewizardjs/alias-resolver
TypeScript icon, indicating that this package has built-in type declarations

1.1.3 • Public • Published

eWizard.js Path Alias Resolver

Description

This module is used to resolve aliases in monorepo projects. There are three entities in monorepo approach: master template, layout, ewizard template.

The ^ alias can refer to the following locations:

  • the root of the current project;
  • the master template installed as a dependency in node_modules;
  • a specific layout located in the layouts folder in the master template project.

The path to the master template and the layout name are taken from the corresponding fields in the system settings.

The module exports:

  • ALIAS - constant with alias character;
  • AliasResolver - main module class;
  • DynamicAliasResolvePlugin - webpack resolve plugin based on enhanced-resolve;
  • traverseAsync - helper function for asynchronous recursive traversal of non-cyclic objects or arrays.

Usage examples

AliasResolver

const layoutOptions = {
  masterTemplatePath: settings.path.masterTemplatePath ?? '',
  layoutsDir: settings.path.layouts ?? 'layouts',
  layoutName: settings.masterTemplateLayout ?? '',
};

async function resolveAliases(baseDir, paths, layoutOptions) {
  const resolver = new AliasResolver(baseDir, layoutOptions);
  return resolver.resolve(paths);
}

DynamicAliasResolvePlugin

const webpackConfig = {
  resolve: {
    plugins: [new DynamicAliasResolvePlugin(baseDir, layoutOptions)],
  },
};

traverseAsync

async function getModifiedSource(source) {
  return traverseAsync(source, traverseCb);
}

function traverseCb(context) {
  const { parent, key, value, keyPath } = context;
  // do sime action
}

Readme

Keywords

none

Package Sidebar

Install

npm i @ewizardjs/alias-resolver

Weekly Downloads

16

Version

1.1.3

License

ISC

Unpacked Size

24.4 kB

Total Files

26

Last publish

Collaborators

  • serhii_but
  • alexbelov
  • v.kobyletskiy
  • m.polevchuk
  • b.hryhoriev
  • ewizardjs-team
  • vasylshylov