UNPKG

@communities-webruntime/services

Version:

If you would like to run Lightning Web Runtime without the CLI, we expose some of our programmatic APIs available in Node.js. If you're looking for the CLI documentation [you can find that here](https://www.npmjs.com/package/@communities-webruntime/cli).

66 lines (65 loc) 2.68 kB
"use strict"; /** @hidden */ /** * Copyright (c) 2019, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ Object.defineProperty(exports, "__esModule", { value: true }); const APEX_REGEX = /^(@salesforce\/apex)(?:\/([\w-]+\.[\w-]+(?:\.[\w-]+)?))?$/; function matchesApexScopedModule(id) { return id && id.match(APEX_REGEX); } /** * Rollup plugin that produce exports of the name of the requested * apex method from a standard or custom controller: * 1. @salesforce/apex for refreshApex and getSObjectValue functions * 2. @salesforce/apex/[apexClass].[apexMethod] for custom, non-namespaced apex or * 3. @salesforce/apex/[namespace].[apexClass].[apexMethod] for * namespaced apex. * * examples: * * import getCommunityName from '@salesforce/apex/applauncher.CommunityLogoController.getCommunityName'; * * import getContactList from '@salesforce/apex/MyContactController.getContactList'; * * import { refreshApex } from '@salesforce/apex'; */ function plugin() { return { name: 'rollup-plugin-apex', resolveId(id) { return matchesApexScopedModule(id) ? id : null; }, load(id) { const idParts = matchesApexScopedModule(id); if (idParts) { // the first element is the whole id const [scope, apexDefinition] = idParts.slice(1, 3); if (apexDefinition) { // handle @salesforce/apex/(ns.)class.method // reverse because we don't require the namespace, but if // its included, it will come first const [method, classname, namespace = '""'] = apexDefinition .split('.') .reverse() .map(JSON.stringify); return ` import { getApexInvoker } from 'force/ldsAdaptersApex'; const apexInvoker = getApexInvoker(${namespace}, ${classname}, ${method}, false); export default apexInvoker; `; } else if (scope) { // otherwise, handle @salesforce/apex // refreshApex and getSObjectValue special case return ` export { refresh as refreshApex, getSObjectValue } from 'force/ldsAdaptersApex'; `; } } return null; }, }; } exports.default = plugin; //# sourceMappingURL=rollup-plugin-salesforce-apex.js.map