Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

Lf/message server graceful error #267

Merged
merged 4 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/server/LocalDevServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export default class LocalDevServer {
}

config.addMiddleware(middleware);

const routes: ContainerAppExtension[] = [
projectMetadata(this.sessionNonce, this.project)
];
Expand Down
4 changes: 2 additions & 2 deletions src/server/__tests__/LocalDevServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jest.mock('@webruntime/server', () => {
super(...args);
mockServerConstructor(...args);
}
initialize() { }
start() { }
initialize() {}
start() {}
shutdown() {
this.emit('shutdown');
}
Expand Down
5 changes: 4 additions & 1 deletion src/server/config/WebruntimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { Plugin } from 'rollup';
import { ApexService, SchemaService } from '@communities-webruntime/services';
import { ResourceUrlService } from '../services/ResourceUrlService';
import { ApexContinuationService } from '../services/ApexContinuationService';
import { LWCMessageService } from '../services/LWCMessageService';

import alias from '@rollup/plugin-alias';

export default class WebruntimeConfig implements Config {
Expand Down Expand Up @@ -76,7 +78,8 @@ export default class WebruntimeConfig implements Config {
AppBootstrapService,
ImportMapService,
ResourceUrlService,
SchemaService
SchemaService,
LWCMessageService
];

this.bundle = [
Expand Down
41 changes: 41 additions & 0 deletions src/server/services/LWCMessageService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { CompileService } from '@webruntime/api';
import path from 'path';

const APEX_LWC_MESSAGE_SERVICE_REGEX = /^(@salesforce\/messageChannel\/.*)/;

function matchesLWCMessageServiceScopedModule(id: string) {
return id && id.match(APEX_LWC_MESSAGE_SERVICE_REGEX);
}

/**
* Rollup plugin to resolve @salesforce/apexContinuation
*
*/
function plugin() {
return {
name: 'rollup-plugin-lwc-message-service',

resolveId(id: string) {
return matchesLWCMessageServiceScopedModule(id) ? id : null;
},
load(id: any) {
const idParts = matchesLWCMessageServiceScopedModule(id);
if (idParts) {
throw new Error(
"You can't preview a component using Lightning Messages Service. Test the component directly in the org"
LisandroFernandezSF marked this conversation as resolved.
Show resolved Hide resolved
);
}
return null;
}
};
}

export class LWCMessageService implements CompileService {
LisandroFernandezSF marked this conversation as resolved.
Show resolved Hide resolved
getPlugin() {
return plugin();
}

async initialize() {}

shutdown() {}
}