@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).
67 lines • 2.31 kB
JavaScript
/**
* 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
*/
import * as path from 'path';
import { hashContent } from '@lwrjs/shared-utils';
/** @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
*/
const MESSAGE_CHANNEL_PREFIX = '@salesforce/messageChannel/';
const MESSAGE_CHANNEL_MODULE_CODE = `import { createMessageChannel } from 'lightning/messageService';
export default createMessageChannel();
`;
/**
* Check whether the given id is a @salesforce/messageChannel scoped module id
*/
function isMessageChannelScopedModule(id) {
return id && id.startsWith(MESSAGE_CHANNEL_PREFIX);
}
/**
* MessageChannelService
*
* This is an AddressableService because we cannot inline message channel modules into a view.
* They need to be shared across views and registered by the framework.
*/
export default class SMCProvider {
constructor() {
this.name = 'salesforce-message-channel-provider';
this.version = '1';
}
async getModuleEntry({ specifier }) {
if (isMessageChannelScopedModule(specifier)) {
return {
id: `${specifier}|${this.version}`,
virtual: true,
entry: `<virtual>/${specifier}${path.extname(specifier) ? '' : '.js'}`,
specifier,
version: this.version,
};
}
}
async getModule({ specifier, namespace, name = specifier, }) {
// Retrieve the Module Entry
const moduleEntry = await this.getModuleEntry({ specifier });
if (!moduleEntry) {
return;
}
return {
id: moduleEntry.id,
specifier,
namespace,
name,
version: this.version,
originalSource: MESSAGE_CHANNEL_MODULE_CODE,
moduleEntry,
ownHash: hashContent(MESSAGE_CHANNEL_MODULE_CODE),
compiledSource: MESSAGE_CHANNEL_MODULE_CODE,
};
}
}
//# sourceMappingURL=salesforce-message-channel-provider.js.map