How to use @lwc/module-resolver - 4 common examples

To help you get started, we’ve selected a few @lwc/module-resolver 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 salesforce / lwc-test / packages / @lwc / jest-resolver / src / index.js View on Github external
let resolver;
try {
    resolver = require('jest-resolve/build/default_resolver').default;
} catch (e) {
    resolver = require('jest-resolve/build/defaultResolver').default;
}

const EMPTY_CSS_MOCK = resolve(__dirname, '..', 'resources', 'emptyStyleMock.js');
const EMPTY_HTML_MOCK = resolve(__dirname, '..', 'resources', 'emptyHtmlMock.js');

const WHITELISTED_LWC_PACKAGES = {
    lwc: '@lwc/engine',
    'wire-service': '@lwc/wire-service',
    'wire-service-jest-util': 'lwc-wire-service-jest-util',
};
const lwcMap = lwcResolver.resolveModules();

// This logic is somewhat the same in the compiler resolution system
// We should try to consolidate it at some point.
function isImplicitHTMLImport(importee, { basedir }) {
    const ext = extname(importee);
    const isHTML = ext === '.html';
    const fileName = basename(importee, '.html');
    const absPath = resolve(basedir, importee);
    const jsFile = join(dirname(absPath), fileName + '.js');

    return (
        isHTML && // if is an HTML file
        fs.existsSync(jsFile) && // There must be a js file with the same name in the same folder
        !fs.existsSync(absPath) // and the html must not exist
    );
}
github salesforce / lwc / packages / @lwc / jest-resolver / src / index.js View on Github external
let resolver;
try {
    resolver = require('jest-resolve/build/default_resolver').default;
} catch (e) {
    resolver = require('jest-resolve/build/defaultResolver').default;
}

const EMPTY_CSS_MOCK = resolve(__dirname, '..', 'resources', 'emptyStyleMock.js');
const EMPTY_HTML_MOCK = resolve(__dirname, '..', 'resources', 'emptyHtmlMock.js');

const WHITELISTED_LWC_PACKAGES = {
    lwc: '@lwc/engine',
    'wire-service': '@lwc/wire-service',
    'wire-service-jest-util': 'lwc-wire-service-jest-util',
};
const lwcMap = lwcNpmResolver.resolveLwcNpmModules();

// This logic is somewhat the same in the compiler resolution system
// We should try to consolidate it at some point.
function isImplicitHTMLImport(importee, { basedir }) {
    const ext = extname(importee);
    const isHTML = ext === '.html';
    const fileName = basename(importee, '.html');
    const absPath = resolve(basedir, importee);
    const jsFile = join(dirname(absPath), fileName + '.js');

    return (
        isHTML && // if is an HTML file
        fs.existsSync(jsFile) && // There must be a js file with the same name in the same folder
        !fs.existsSync(absPath) // and the html must not exist
    );
}
github muenzpraeger / create-lwc-app / packages / lwc-services / src / utils / webpack / module.ts View on Github external
const { resolveModules } = require('@lwc/module-resolver')
import * as fs from 'fs'
import * as path from 'path'

import { lwcConfig } from '../../config/lwcConfig'

let npmmodules: any
const pkgJson = JSON.parse(fs.readFileSync(`package.json`, 'utf8'))

let resolvedModules = resolveModules({
    modules: [
        ...lwcConfig.localModulesDirs,
        ...Object.keys(pkgJson.dependencies)
    ]
})

npmmodules = resolvedModules.reduce(
    (map: any, m: any) => ((map[m.specifier] = m), map),
    {}
)

const LAYOUT = {
    /**
     * Modules are stored at the root of the module directory with their full qualified name.
     *      modules
     *      └── x-foo
github salesforce / lwc / packages / @lwc / rollup-plugin / src / index.js View on Github external
options({ input }) {
            const { modules: userModules = [], rootDir } = mergedPluginOptions;
            const defaultModulesDir = rootDir ? path.resolve(rootDir) : path.dirname(input);
            const modules = [...userModules, ...DEFAULT_MODULES, defaultModulesDir];
            const resolvedModules = lwcResolver.resolveModules({ rootDir, modules });
            modulePaths = resolvedModules.reduce((map, m) => ((map[m.specifier] = m), map), {});
        },

@lwc/module-resolver

Resolves paths for LWC components

MIT
Latest version published 16 days ago

Package Health Score

90 / 100
Full package analysis