Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lwc/metadata

Package Overview
Dependencies
Maintainers
14
Versions
128
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lwc/metadata

Extract metadata about Lightning Web Components modules. This software is provided as-is with no support provided.

  • 6.5.3-0
  • npm
  • Socket score

Version published
Weekly downloads
2.3K
increased by39.33%
Maintainers
14
Weekly downloads
 
Created
Source

@lwc/metadata

This package can be used to collect metadata about a Lightning Web Component(LWC) by statically analysing html, js and css files of the component. In general, this information about the component is referred to as "component metadata". The metadata can be used for referential integrity checking, dependency analysis, code editor features like type ahead support for component attribute.

To learn more about the detailed design of this package and the schema of the metadata that is produced, refer the component metadata rfc.

Installation

npm install @lwc/metadata --save

APIs

collectBundleMetadata(config: BundleConfig)

Statically analyse the raw source of an LWC bundle and return gathered metadata. This API analyses bundle resources ending with a .html, .js and .css file extensions.

Note: This API is designed to work with the raw source as authored by an LWC developer and is expected to run before any tranformations applied by the @lwc/compiler.

import { collectBundleMetadata } from '@lwc/metadata';

const htmlSource = `
    <template>
        <h1>Hello World!</h1>
    </template>
`;

const jsSource = `
    import { LightningElement } from 'lwc';
    export default class MyComponent extends LightningElement {}
`;

const cssSource = `
    h1 {
        font-size: xx-large;
    }
`;

const metadata = collectBundleMetadata({
    type: 'platform',
    name: 'myComponent',
    namespace: 'c',
    namespaceMapping: { c: 'ns1' },
    files: [
        {
            fileName: 'c/myComponent/myComponent.html',
            source: htmlSource,
        },
        {
            fileName: 'c/myComponent/myComponent.js',
            source: jsSource,
        },
        {
            fileName: 'c/myComponent/myComponent.css',
            source: cssSource,
        },
    ],
});

Parameters:

  • config (BundleConfig, required) - Represents information about the LWC bundle that needs to be analysed. The config also contains the raw source code for all files(.html, .js & .css) that make up the bundle.
type BundleType = 'internal' | 'platform';

interface BundleConfig {
    type: BundleType; // Represents whether the bundle was authored by salesforce or a customer
    name: string; // name of the bundle
    namespace: string; // namespace of the bundle
    namespaceMapping: NamespaceMapping; // namespaceMapping to be used to transform module references like 'c/button' to 'namespaceA/button'. This is useful when the given bundle will be part of a managed package.
    files: {
        fileName: string;
        source: string;
    }[]; // List of file name and source code for each file in utf-8 encoding
    enableKomaci?: boolean; // Advance feature meant to analyze data dependencies of given module. It is meant for internal usage.
}

Return value: A BundleMetadata representing the collected metadata about the LWC bundle.

interface BundleMetadata {
    version: string; // version of @lwc/metadata used to collect metadata
    moduleSpecifier: string; // Full canonical name in camel case
    name: string; // same as input name field
    namespace: string; // same as intput naemspace field
    entryFileName?: string; // main entry file of the bundle
    // A list of metadata objects for each file processed in the bundle
    // The order of file is same as order of 'files' in the input config
    files: (HTMLTemplateFile | ScriptFile | CSSFile)[];
    // All diagnostic issues discovered while collecting bundle metadata.
    diagnostics: CompilerDiagnostic[];
}

The schema used for @lwc/metadata package is well defined in TypeScript. Refer to the type definitions that are included in the package distribution. It can be viewed in an IDE that has TypeScript support.

FAQs

Package last updated on 23 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc