MM-52282 Remove ExperimentalSettings.PatchPluginsReactDOM (#23172)
* MM-52282 Remove ExperimentalSettings.PatchPluginsReactDOM * Fix missing file from last commit * Fix test usage of plugin.NewEnvironment
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
44920deab6
Коммит
d001994ef9
@@ -4,12 +4,10 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -59,7 +57,6 @@ type Environment struct {
|
||||
dbDriver Driver
|
||||
pluginDir string
|
||||
webappPluginDir string
|
||||
patchReactDOM bool
|
||||
prepackagedPlugins []*PrepackagedPlugin
|
||||
prepackagedPluginsLock sync.RWMutex
|
||||
}
|
||||
@@ -69,7 +66,6 @@ func NewEnvironment(
|
||||
dbDriver Driver,
|
||||
pluginDir string,
|
||||
webappPluginDir string,
|
||||
patchReactDOM bool,
|
||||
logger *mlog.Logger,
|
||||
metrics einterfaces.MetricsInterface,
|
||||
) (*Environment, error) {
|
||||
@@ -80,7 +76,6 @@ func NewEnvironment(
|
||||
dbDriver: dbDriver,
|
||||
pluginDir: pluginDir,
|
||||
webappPluginDir: webappPluginDir,
|
||||
patchReactDOM: patchReactDOM,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -488,17 +483,6 @@ func (env *Environment) UnpackWebappBundle(id string) (*model.Manifest, error) {
|
||||
return nil, errors.Wrapf(err, "unable to read webapp bundle: %v", id)
|
||||
}
|
||||
|
||||
if env.patchReactDOM {
|
||||
newContents, changed := patchReactDOM(sourceBundleFileContents)
|
||||
if changed {
|
||||
sourceBundleFileContents = newContents
|
||||
err = os.WriteFile(sourceBundleFilepath, sourceBundleFileContents, 0644)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to overwrite webapp bundle: %v", id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hash := fnv.New64a()
|
||||
if _, err = hash.Write(sourceBundleFileContents); err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to generate hash for webapp bundle: %v", id)
|
||||
@@ -515,52 +499,6 @@ func (env *Environment) UnpackWebappBundle(id string) (*model.Manifest, error) {
|
||||
return manifest, nil
|
||||
}
|
||||
|
||||
func patchReactDOM(initialBytes []byte) ([]byte, bool) {
|
||||
if !bytes.Contains(initialBytes, []byte("react-dom.production.min.js")) {
|
||||
return initialBytes, false
|
||||
}
|
||||
|
||||
initial := string(initialBytes)
|
||||
nameIndex := strings.Index(initial, "react-dom.production.min.js")
|
||||
|
||||
beginning := strings.LastIndex(initial[:nameIndex], "{")
|
||||
var end int
|
||||
|
||||
argDefBeginning := strings.LastIndex(initial[:beginning], "function") + 9
|
||||
argDefEnd := strings.LastIndex(initial[:beginning], ")") - 1
|
||||
argsNames := strings.Split(initial[argDefBeginning:argDefEnd], ",")
|
||||
if len(argsNames) != 3 {
|
||||
return initialBytes, false
|
||||
}
|
||||
|
||||
exportsArgName := strings.TrimSpace(argsNames[1])
|
||||
|
||||
numOpenBraces := 0
|
||||
for i, c := range initial[beginning:] {
|
||||
if end != 0 {
|
||||
break
|
||||
}
|
||||
switch c {
|
||||
case '}':
|
||||
numOpenBraces--
|
||||
|
||||
if numOpenBraces == 0 {
|
||||
end = beginning + i
|
||||
}
|
||||
case '{':
|
||||
numOpenBraces++
|
||||
}
|
||||
}
|
||||
|
||||
beforePatch := initial[:end]
|
||||
afterPatch := initial[end:]
|
||||
|
||||
patch := fmt.Sprintf("; Object.assign(%s, window.ReactDOM)", exportsArgName)
|
||||
|
||||
result := fmt.Sprintf("%s%s%s", beforePatch, patch, afterPatch)
|
||||
return []byte(result), true
|
||||
}
|
||||
|
||||
// HooksForPlugin returns the hooks API for the plugin with the given id.
|
||||
//
|
||||
// Consider using RunMultiPluginHook instead.
|
||||
|
||||
Ссылка в новой задаче
Block a user