@@ -22,17 +22,6 @@ let webpackManifest
2222 * @param {FormRequest | FormRequestPayload | null } request
2323 */
2424export function context ( request ) {
25- const manifestPath = join ( config . get ( 'publicDir' ) , 'assets-manifest.json' )
26-
27- if ( ! webpackManifest ) {
28- try {
29- // eslint-disable-next-line -- Allow JSON type 'any'
30- webpackManifest = JSON . parse ( readFileSync ( manifestPath , 'utf-8' ) )
31- } catch {
32- logger . error ( `Webpack ${ basename ( manifestPath ) } not found` )
33- }
34- }
35-
3625 const { params, path, response } = request ?? { }
3726
3827 const isPreviewMode = path ?. startsWith ( PREVIEW_PATH_PREFIX )
@@ -54,7 +43,6 @@ export function context(request) {
5443 // take consumers props first so we can override it
5544 ...consumerViewContext ,
5645 appVersion : pkg . version ,
57- assetPath : '/assets' ,
5846 config : {
5947 cdpEnvironment : config . get ( 'cdpEnvironment' ) ,
6048 designerUrl : config . get ( 'designerUrl' ) ,
@@ -66,14 +54,34 @@ export function context(request) {
6654 crumb : safeGenerateCrumb ( request ) ,
6755 currentPath : request ? `${ request . path } ${ request . url . search } ` : undefined ,
6856 previewMode : isPreviewMode ? params ?. state : undefined ,
69- slug : isResponseOK ? params ?. slug : undefined ,
57+ slug : isResponseOK ? params ?. slug : undefined
58+ }
59+
60+ return ctx
61+ }
7062
63+ /**
64+ * Returns the context for the devtool. Consumers won't have access to this.
65+ */
66+ export function devtoolContext ( ) {
67+ const manifestPath = join ( config . get ( 'publicDir' ) , 'assets-manifest.json' )
68+
69+ if ( ! webpackManifest ) {
70+ try {
71+ // eslint-disable-next-line -- Allow JSON type 'any'
72+ webpackManifest = JSON . parse ( readFileSync ( manifestPath , 'utf-8' ) )
73+ } catch {
74+ logger . error ( `Webpack ${ basename ( manifestPath ) } not found` )
75+ }
76+ }
77+
78+ return {
79+ baseLayoutPath : 'dxt-devtool-baselayout.html' , // from plugin.options.nunjucks.paths
80+ assetPath : '/assets' ,
7181 getDxtAssetPath : ( asset = '' ) => {
7282 return `/${ webpackManifest ?. [ asset ] ?? asset } `
7383 }
7484 }
75-
76- return ctx
7785}
7886
7987/**
0 commit comments