Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@genesiscommunitysuccess/analyzer-import-alias-plugin

Plugin for custom element manifest parser to handle import aliases

custom-elements, custom-elements-json, custom-elements-manifest, customelements, webcomponents, customelementsjson, customelementsmanifest, import, alias

readme

The Genesis Global Community Success initiative is committed to open-sourcing select technologies that we believe the open-source community would benefit from.

NPM version License

Analyzer Import Alias Plugin

This plugin allows you to work around the limitations of import aliasing with the AST that the analyzer uses. Consider the following pattern which you might use if you are using a design system and system of components:

// Imported Button class is a custom element.
import { Button as LibButton } from 'my-library';

// Exported Button has extra styling applied to fit your design system.
export class Button extends LibButton { }

This allows you to apply your custom styling to the library button and export with the same name, and then the consumers of your library can swap the import to get your styling. However, this has a problem...

The AST parser that powers the analyzer will be looking for a class named LibButton in your library dependencies when working out the inheritance tree of your class Button, but because the class is actually called Button in the library, the inheritance tree is broken. This means in your manifest that any members that your Button class inherits from the my-library class (or higher in the inheritance chain) will be lost on the manifest.

This plugin will allow you to fix this issue.

Usage

Installation

Install this package as a dev dependency in the same project that you're using the custom elements manifest analyzer.

npm i @genesiscommunitysuccess/analyzer-import-alias-plugin --save-dev

You then need to apply this plugin in the plugins settings in your custom-elements-manifest.config.mjs, see here.

Configuration

Adding the plugin to the plugins array in the manifest config will not accomplish anything by itself, you must also configure the way the plugin handles the name aliases. You can add a configuration for each npm package such as the following.

import aliasPlugin from '@genesiscommunitysuccess/analyzer-import-alias-plugin';

export default {
    dependencies: true,
    plugins: [
        aliasPlugin({
            'my-library': {
                '*': (name) => name.replace('Lib','')
            }
        })
    ]
}

This will effectively treat any imported superclass from my-library as without the Lib prefix, so in the first example in the readme the local Button class will be correctly inheriting from the package Button class.

The shape of the catch-all function defined as * is (name: string) => string so you may perform more complicated logic than the above example to mutate the names. If you don't want to change a name you should return the input name.

There is also an option to set specific replacements for names such as the following:

aliasPlugin({
    'my-library': {
        '*': (name) => name.replace('Lib', ''),
        LibButton: 'MyButton',
        LibCheckbox: (name) => name.replace('Lib', 'My'),
    }
})

When using this above configuration, the LibButton superclass inheritance will be treated as MyButton. Important, any explicit definition will take precedence over the catch-all * function.

For completeness, you may define as many library imports as you wish.

aliasPlugin({
    'my-library': { 
        LibButton: 'MyButton'
    },
    'another-library': {
        '*': (name) => name.replace('Another', ''),
    }
})

changelog

Changelog

5.0.3 (2024-02-14)

Bug Fixes

  • add full filepath to main file in package.json FUI-1827 (#89) 9057656

5.0.2 (2023-12-20)

Bug Fixes

  • relocate chalk to packages FUI-1722 (#85) c63e1e3

5.0.1 (2023-12-20)

Bug Fixes

  • exclude scripts dirs from .npmignore FUI-1722 (#84) 0c78f7b

5.0.0 (2023-12-13)

⚠ BREAKING CHANGES

  • analyzer-import-alias-plugin: Changes the API of the import plugin, users will need to update their config after this change

Features

  • analyzer-import-alias-plugin: simplify override api FUI-1706 (#78) f9853a0

4.1.3 (2023-12-12)

Bug Fixes

  • links to doc images accounting for monorepo FUI-1591 (#76) 9f67399, closes FUi-1591

4.1.2 (2023-12-12)

Bug Fixes

  • documentation examples and gif demos FUI-1591 (#75) 69c48f2

4.1.1 (2023-11-22)

Bug Fixes

  • custom-elements-lsp: decouple tests exports from jest FUI-1595 (#74) 609abc1

4.1.0 (2023-11-21)

Features

  • custom-elements-lsp: pass user config into any plugins FUI-1600 (#73) d803287

4.0.1 (2023-11-17)

Bug Fixes

  • custom-elements-lsp: publish test util files which are used by plugins FUI-1595 (#72) f93b4f0

4.0.0 (2023-11-16)

⚠ BREAKING CHANGES

  • changing the output bundle breaks the import path for cep plugins

Bug Fixes

  • manifset analyzer debug script FUI-1286 (#71) c3580a1, closes FUI-1331

3.1.0 (2023-11-13)

Features

  • allow usage with tsconfig target es2015 or later FUI-1576 (#70) 58735f6, closes FUI-1567

3.0.0 (2023-11-10)

⚠ BREAKING CHANGES

  • add plugin api and refactor fast functionality into its own plugin FUI-1331 (#65)

Features

  • add plugin api and refactor fast functionality into its own plugin FUI-1331 (#65) f1f7b8b

2.2.0 (2023-11-03)

Features

  • analyzer import alias plugin FUI-1528 (#63) 2f78ec8

2.1.2 (2023-10-20)

Bug Fixes

  • bump audit package versions FUI-1529 (#61) 2c8344e

2.1.1 (2023-10-20)

Bug Fixes

  • remove source files from dist bundle FUI-1516 (#60) 3213d74

2.1.0 (2023-10-16)

Features

  • refactor into packages and publish skeleton analyzer plugin FUI-1512 (#54) 11461ee, closes FUi-1512

2.0.1 (2023-09-05)

Bug Fixes

  • account for hoisted typescript binary when running analyzer script FUI-1411 (#52) a46fa9f

2.0.0 (2023-08-30)

⚠ BREAKING CHANGES

  • This alters the API that you call the analyzer binary which is bundled with the LSP

Features

  • use the parser config from tsconfig when running analyzer script FUI-1444 (#48) e4d257f

1.0.0 (2023-08-17)

Features

  • account for FAST propety binding attributes FUI-1193 (#19) (06eb44b)
  • account for global valid FAST boolean bindings FUI-1194 (#18) (65470d7)
  • add quickinfo for custom element when invoking quickinfo on tagname FUI-1226 (#22) (857e7af)
  • add quickinfo for html element tags and attributes FUI-1227 (#33) (1dd1706)
  • add tagname completion for plain html elements FUI-1227 (#29) (3619d96)
  • attribute autocompletion from superclass FUI-1191 (#9) (20141d7)
  • Attribute diagnostics for duplicates and deprecated FUI-1194 (#16) (f2b1676)
  • autocomplete attributes on plain html elements FUI-1227 (#32) (8f652bb)
  • better event binding handling in FAST FUI-1306 (#20) (de3853f)
  • continuously analyse source code to update custom elements manifest (#26) (0396631), closes FUI-1195
  • diagnostics support for non-custom elements FUI-1227 (#34) (e9da5be)
  • event binding autocompletion for FAST FUI-1191 (#10) (992ec2c)
  • fast binding boolean attr and show deprecated attr during autocomplete FUI-1191 (#11) (6741f94)
  • global attribute autocompletion FUI-1191 (#8) (8e93261)
  • handle design system prefix composed element definitions FUI-1197 (#4) (535e957)
  • jump to definiton of tag names FUI-1190 (#21) (9e97abe)
  • Property autocompletion in FAST templates (#13) (a1812fb), closes FUI-1192 FUI-1192 FUI-1192](https://github.com/genesiscommunitysuccess/custom-elements-lsp/issues/1192)
  • quickinfo for plain and FAST syntax attributes FUI-1226 (#24) (d89f08f)
  • Setup unit tests for completions FUI-1189 (#1) (0b24169)

Bug Fixes

  • attribute completions for a multi-line opening tag FUI-1302 (#14) (30d8210)
  • attribute diagnostics where attributes are substrings of others FUI-1416 (#36) (797b84f)
  • behaviour for attribute values containing whitespace FUI-1324 (#27) (09f21f9)
  • regression with custom element losing superclass into from library FUI-1388 (#28) (71d8ff5)
  • text parsing bug involving empty quotes FUI-1409 (#31) (82faffa)