@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).
81 lines • 3.48 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 fs from 'fs';
import { createRequire } from 'module';
import LwcModuleProvider from '@lwrjs/lwc-module-provider';
import { hashContent } from '@lwrjs/shared-utils';
export const APP_SPECIFIER = 'webruntime/app';
const MOBILE_SPECIFIER = 'mobileruntime/hybridAppManager';
export const DESIGN_SPECIFIER = 'webruntimedesign/designmode';
const require = createRequire(path.join(process.cwd(), './static-provider.js'));
/**
* Addressable service responsible for serving "pre-compiled" LWC modules
*/
/* eslint-disable-next-line webruntime/no-mixed-named-default-export */
export default class StaticProvider extends LwcModuleProvider {
constructor() {
super(...arguments);
this.name = 'communities-static-module-provider';
this.version = '1';
}
async getModuleEntry({ specifier }) {
// Get filename without any query param
const parsedSpecifier = specifier?.split('?')[0];
const mode = process.env.MODE;
// serve these modules in AMD mode only, otherwise, we will fall back to the default resolution to serve from LWC provider
if (mode === 'prod-compat' || mode === 'compat') {
if (parsedSpecifier === APP_SPECIFIER || parsedSpecifier === MOBILE_SPECIFIER) {
return {
id: `${parsedSpecifier}|${this.version}`,
entry: `<virtual>/${parsedSpecifier}${path.extname(parsedSpecifier) ? '' : '.js'}`,
specifier: parsedSpecifier,
version: this.version,
};
}
else if (parsedSpecifier === 'webruntimedesign/designmode') {
return {
id: `${parsedSpecifier}|${this.version}`,
entry: `<virtual>/${parsedSpecifier}${path.extname(parsedSpecifier) ? '' : '.js'}`,
specifier: parsedSpecifier,
version: this.version,
};
}
}
}
async getModule({ specifier, namespace, name = specifier }) {
// Retrieve the Module Entry
const moduleEntry = await this.getModuleEntry({ specifier });
if (!moduleEntry) {
return;
}
let staticModule;
if (specifier === APP_SPECIFIER) {
staticModule = '@communities-webruntime/client/dist/public/module/webruntimeapp.js';
}
else if (specifier === MOBILE_SPECIFIER) {
staticModule = '@communities-webruntime/mobile/dist/public/module/mobileruntime_hybridAppManager.js';
}
else if (specifier === DESIGN_SPECIFIER) {
staticModule = '@communities-webruntime/design/dist/public/module/webruntimedesign.js';
}
const staticModulePath = require.resolve(staticModule);
const staticModuleSource = fs.readFileSync(staticModulePath).toString();
return {
id: moduleEntry.id,
specifier,
namespace,
name,
version: this.version,
originalSource: staticModuleSource,
moduleEntry,
ownHash: hashContent(staticModuleSource),
compiledSource: staticModuleSource,
};
}
}
//# sourceMappingURL=static-provider.js.map