@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).
54 lines • 2.02 kB
JavaScript
;
/** @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 SCHEMA_PREFIX = '@salesforce/schema';
function isSchemaScopedModule(id) {
return id && id.startsWith(SCHEMA_PREFIX);
}
/**
* Rollup plugin that produce exports of the name of the requested
* sobject or field schema for scoped imports expressed in the following way:
* 1. @salesforce/schema/[objectApiName] for SObject schema,
* 2. @salesforce/schema/[objectApiName].[fieldApiName] for field schema or
* 3. @salesforce/schema/[objectApiName].[relationshipApiName+].[fieldApiName] for
* spanning field schema.
*
* See https://salesforce.quip.com/MgkVAKaONfcw for details.
*
* example:
* import MyObject__c from '@salesforce/schema/MyObject__c.myField' gets converted to
* export default {"objectApiName":"MyObject__c","fieldApiName":"myField"}
*/
function plugin() {
return {
name: 'rollup-plugin-salesforce-schema',
load(id) {
if (isSchemaScopedModule(id)) {
const resource = id.split('/')[2].split('.js')[0];
const idx = resource.indexOf('.');
let schema;
if (idx === -1) {
schema = { objectApiName: resource };
}
else {
const objectApiName = resource.substring(0, idx);
const fieldApiName = resource.substring(idx + 1);
schema = { fieldApiName, objectApiName };
}
return `export default ${JSON.stringify(schema)}`;
}
return null;
},
resolveId(id) {
return isSchemaScopedModule(id) ? id : null;
},
};
}
exports.default = plugin;
//# sourceMappingURL=rollup-plugin-salesforce-schema.js.map