diff --git a/packages/server/src/ChunkExtractor.js b/packages/server/src/ChunkExtractor.js index bf0cf47c..a1cd755b 100644 --- a/packages/server/src/ChunkExtractor.js +++ b/packages/server/src/ChunkExtractor.js @@ -20,15 +20,19 @@ function getAssets(chunks, getAsset) { return _.uniqBy(_.flatMap(chunks, chunk => getAsset(chunk)), 'url') } -function assetToScriptTag(asset) { +function extraPropsToString(extraProps) { + return Object.keys(extraProps).reduce((acc, key) => `${acc} ${key}="${extraProps[key]}"`, ''); +} + +function assetToScriptTag(asset, extraProps) { return `` + }"${extraPropsToString(extraProps)}>` } -function assetToScriptElement(asset) { +function assetToScriptElement(asset, extraProps) { return ( - ` + getRequiredChunksScriptTag(extraProps) { + return `${this.getRequiredChunksScriptContent()}` } - getRequiredChunksScriptElement() { + getRequiredChunksScriptElement(extraProps) { return ( " +`) + }) + + it('should add extra props if specified', () => { + extractor.addChunk('letters-A') + expect(extractor.getScriptTags({ nonce: 'testnonce' })) + .toMatchInlineSnapshot(` +" + +" `) }) }) @@ -100,6 +110,35 @@ Array [ src="/dist/node/main.js" />, ] +`) + }) + + it('should add extra props if specified', () => { + extractor.addChunk('letters-A') + expect(extractor.getScriptElements({ nonce: 'testnonce' })) + .toMatchInlineSnapshot(` +Array [ +