Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 17 additions & 4 deletions assets/bundler/plugins/entrypoints-generate/studio-plugins.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import fs from 'fs';
import type { RsbuildPlugin, ManifestData, OnAfterBuildFn, OnDevCompileDoneFn } from '@rsbuild/core';

interface PluginOptions {
alternativePluginExportPath?: string;
}

interface EntrypointJson {
entrypoints: {
[key: string]: {
Expand All @@ -19,7 +23,7 @@ interface DevServerContext {
type parameters = Parameters<OnAfterBuildFn | OnDevCompileDoneFn>;
type data = parameters[0];

const generateEntrypoints = (data: data, devServer?: DevServerContext): EntrypointJson => {
const generateEntrypoints = (data: data, devServer?: DevServerContext, options?: PluginOptions): EntrypointJson => {
const manifest: ManifestData = data.environments.web.manifest as unknown as ManifestData;
const entrypoints: EntrypointJson = {
entrypoints: {}
Expand Down Expand Up @@ -116,10 +120,19 @@ const generateEntrypoints = (data: data, devServer?: DevServerContext): Entrypoi
window.pluginRemotes = {}
}

if (window.alternativePluginExportPaths === undefined) {
window.alternativePluginExportPaths = {}
}

${Object.entries(remoteEntrypoints).map((entrypoint) => {
const [key, value] = entrypoint;
return `window.pluginRemotes.${key} = "${hasDevServer && !hasDomain ? `http${devServer.https ? 's' : ''}://${host}:${devServer.port}` : ''}${value}"`
})}

${options?.alternativePluginExportPath ? Object.entries(remoteEntrypoints).map((entrypoint) => {
const [key, value] = entrypoint;
return `window.alternativePluginExportPaths.${key} = "${options.alternativePluginExportPath}"`
}).join('\n ') : ''}
`
)

Expand All @@ -131,18 +144,18 @@ const generateEntrypoints = (data: data, devServer?: DevServerContext): Entrypoi
return entrypoints;
}

export const pluginGenerateEntrypoints = (): RsbuildPlugin => ({
export const pluginGenerateEntrypoints = (options?: PluginOptions): RsbuildPlugin => ({
name: 'entrypoints-generate',
setup(api) {
api.onAfterBuild((data) => {
const entrypoints = generateEntrypoints(data);
const entrypoints = generateEntrypoints(data, undefined, options);
const outPath = data.environments.web.config.output.distPath.root
const entrypointsPath = `${outPath}/entrypoints.json`;
fs.writeFileSync(entrypointsPath, JSON.stringify(entrypoints, null, 2), 'utf-8');
})

api.onDevCompileDone((data) => {
const entrypoints = generateEntrypoints(data, api.context.devServer);
const entrypoints = generateEntrypoints(data, api.context.devServer, options);
const outPath = data.environments.web.config.output.distPath.root
const entrypointsPath = `${outPath}/entrypoints.json`;
fs.writeFileSync(entrypointsPath, JSON.stringify(entrypoints, null, 2), 'utf-8');
Expand Down
6 changes: 5 additions & 1 deletion assets/dist/types/entrypoints.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { RsbuildPlugin } from "@rsbuild/core";

export function pluginGenerateEntrypoints(): RsbuildPlugin
export interface PluginOptions {
alternativePluginExportPath?: string;
}

export function pluginGenerateEntrypoints(options?: PluginOptions): RsbuildPlugin
10 changes: 8 additions & 2 deletions assets/js/src/core/app/plugin-system/plugin-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class PluginSystem {
async loadPlugins (): Promise<void> {
const promises: any[] = []
const remotes = window.pluginRemotes
const alternativePaths = window.alternativePluginExportPaths

if (remotes === undefined) {
return
Expand All @@ -51,7 +52,9 @@ export class PluginSystem {
getInstance()?.registerRemotes(initConfig.remotes)

for (const remote of initConfig.remotes) {
promises.push(loadRemote(remote.alias!))
const alternativeExport = alternativePaths?.[remote.name] ?? ''
const moduleId = alternativeExport !== '' ? `${remote.alias}${alternativeExport}` : remote.alias!
promises.push(loadRemote(moduleId))
}

const result = await Promise.allSettled(promises)
Expand All @@ -67,8 +70,11 @@ export class PluginSystem {
const plugins: Record<string, IAbstractPlugin> = remoteResponse.value

for (const plugin of Object.values(plugins)) {
if (typeof plugin !== 'object') {
continue
}

if (plugin.name === undefined) {
console.error('Plugin name is undefined', plugin)
continue
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ declare global {
interface Window {
Pimcore: typeof Pimcore
pluginRemotes: Record<string, string>
alternativePluginExportPaths: Record<string, string>
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ declare global {
Pimcore: typeof Pimcore
PimcoreDocumentEditor: PublicApiDocumentEditorIframe
pluginRemotes: Record<string, string>
alternativePluginExportPaths: Record<string, string>
}
}

Expand Down
1 change: 1 addition & 0 deletions assets/js/src/sdk/_internal_/mf-bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ declare global {
Pimcore: typeof Pimcore
PimcoreStudio: PimcoreStudioApi
pluginRemotes: Record<string, string>
alternativePluginExportPaths: Record<string, string>
}
}

Expand Down
1 change: 1 addition & 0 deletions assets/js/src/sdk/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ declare global {
interface Window {
Pimcore: typeof PimcoreApi
pluginRemotes: Record<string, string>
alternativePluginExportPaths: Record<string, string>
}
}

Expand Down
23 changes: 0 additions & 23 deletions public/build/07ef4190-a00c-43f9-9c41-1619f84bb3aa/entrypoints.json

This file was deleted.

Loading