@zengenti/contensis-react-base 3.0.0-beta.69 → 3.0.0-beta.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3758,7 +3758,7 @@ const loadableBundleData = ({
3758
3758
  const bundle = {};
3759
3759
 
3760
3760
  try {
3761
- bundle.stats = JSON.parse(readFileSync(stats.replace('/target', build ? `/${build}` : '')));
3761
+ bundle.stats = stats ? JSON.parse(readFileSync(stats.replace('/target', build ? `/${build}` : ''))) : null;
3762
3762
  } catch (ex) {
3763
3763
  // console.info(ex);
3764
3764
  bundle.stats = null;
@@ -3778,31 +3778,51 @@ const loadableBundleData = ({
3778
3778
  return bundle;
3779
3779
  };
3780
3780
  const loadableChunkExtractors = () => {
3781
+ const commonLoadableExtractor = new ChunkExtractor({
3782
+ stats: {}
3783
+ });
3784
+
3781
3785
  try {
3782
- const modern = new ChunkExtractor({
3783
- entrypoints: ['app'],
3784
- namespace: 'modern',
3785
- statsFile: path.resolve('dist/modern/loadable-stats.json')
3786
- });
3787
- const legacy = new ChunkExtractor({
3788
- entrypoints: ['app'],
3789
- namespace: 'legacy',
3790
- statsFile: path.resolve('dist/legacy/loadable-stats.json')
3791
- });
3792
- const commonLoadableExtractor = {
3793
- addChunk(chunk) {
3794
- modern.addChunk(chunk);
3795
- if (typeof legacy.stats.assetsByChunkName[chunk] !== 'undefined') legacy.addChunk(chunk);
3796
- }
3786
+ let modern;
3787
+ let legacy;
3788
+
3789
+ try {
3790
+ modern = new ChunkExtractor({
3791
+ entrypoints: ['app'],
3792
+ namespace: 'modern',
3793
+ statsFile: path.resolve('dist/modern/loadable-stats.json')
3794
+ });
3795
+ } catch (e) {
3796
+ console.info('@loadable/server modern ChunkExtractor not available');
3797
+ }
3797
3798
 
3799
+ try {
3800
+ legacy = new ChunkExtractor({
3801
+ entrypoints: ['app'],
3802
+ namespace: 'legacy',
3803
+ statsFile: path.resolve('dist/legacy/loadable-stats.json')
3804
+ });
3805
+ } catch (e) {
3806
+ console.info('@loadable/server legacy ChunkExtractor not available');
3807
+ }
3808
+
3809
+ commonLoadableExtractor.addChunk = chunk => {
3810
+ var _modern, _legacy, _legacy2;
3811
+
3812
+ (_modern = modern) === null || _modern === void 0 ? void 0 : _modern.addChunk(chunk);
3813
+ if (typeof ((_legacy = legacy) === null || _legacy === void 0 ? void 0 : _legacy.stats.assetsByChunkName[chunk]) !== 'undefined') (_legacy2 = legacy) === null || _legacy2 === void 0 ? void 0 : _legacy2.addChunk(chunk);
3798
3814
  };
3815
+
3799
3816
  return {
3800
3817
  commonLoadableExtractor,
3801
3818
  modern,
3802
3819
  legacy
3803
3820
  };
3804
3821
  } catch (e) {
3805
- console.info('@loadable/server ChunkExtractor not available');
3822
+ console.info('@loadable/server no ChunkExtractor available');
3823
+ return {
3824
+ commonLoadableExtractor
3825
+ };
3806
3826
  }
3807
3827
  };
3808
3828
  const getBundleData = (config, staticRoutePath) => {
@@ -3813,17 +3833,46 @@ const getBundleData = (config, staticRoutePath) => {
3813
3833
  };
3814
3834
  if (!bundleData.default || bundleData.default === {}) bundleData.default = bundleData.legacy || bundleData.modern;
3815
3835
  return bundleData;
3816
- };
3836
+ }; // export const buildBundleTags = (
3837
+ // bundles,
3838
+ // differentialBundles = false,
3839
+ // staticRoutePath = 'static',
3840
+ // attributes = ''
3841
+ // ) => {
3842
+ // // Take the bundles returned from Loadable.Capture
3843
+ // const bundleTags = bundles
3844
+ // .filter(b => b)
3845
+ // .map(bundle => {
3846
+ // if (bundle.publicPath.includes('/modern/'))
3847
+ // return differentialBundles
3848
+ // ? `<script ${attributes} type="module" src="${replaceStaticPath(
3849
+ // bundle.publicPath,
3850
+ // staticRoutePath
3851
+ // )}"></script>`
3852
+ // : null;
3853
+ // return `<script ${attributes}${
3854
+ // differentialBundles ? ' nomodule' : ''
3855
+ // } src="${replaceStaticPath(
3856
+ // bundle.publicPath,
3857
+ // staticRoutePath
3858
+ // )}"></script>`;
3859
+ // })
3860
+ // .filter(f => f);
3861
+ // return bundleTags;
3862
+ // };
3863
+
3817
3864
  const getBundleTags = (loadableExtractor, scripts, staticRoutePath = 'static') => {
3818
3865
  let startupTag = ''; // Add the static startup script to the bundleTags
3819
3866
 
3820
3867
  if (scripts !== null && scripts !== void 0 && scripts.startup) startupTag = `<script ${stringifyAttributes(scripts.attributes)} src="/${staticRoutePath}/${scripts.startup}"></script>`; // Get the script tags from their respective extractor instances
3821
3868
 
3822
3869
  if (loadableExtractor) {
3823
- const legacyScriptTags = loadableExtractor === null || loadableExtractor === void 0 ? void 0 : loadableExtractor.legacy.getScriptTags({
3870
+ var _loadableExtractor$le, _loadableExtractor$mo;
3871
+
3872
+ const legacyScriptTags = (_loadableExtractor$le = loadableExtractor.legacy) === null || _loadableExtractor$le === void 0 ? void 0 : _loadableExtractor$le.getScriptTags({
3824
3873
  nomodule: 'nomodule'
3825
3874
  });
3826
- const modernScriptTags = loadableExtractor === null || loadableExtractor === void 0 ? void 0 : loadableExtractor.modern.getScriptTags({
3875
+ const modernScriptTags = (_loadableExtractor$mo = loadableExtractor.modern) === null || _loadableExtractor$mo === void 0 ? void 0 : _loadableExtractor$mo.getScriptTags({
3827
3876
  type: 'module'
3828
3877
  });
3829
3878
  const scriptTags = `${startupTag}${legacyScriptTags || ''}${modernScriptTags || ''}`.replace(/"\/static\//g, `"/${staticRoutePath}/`);
@@ -3870,6 +3919,17 @@ const addVarnishAuthenticationHeaders = (state, response, groups = {}) => {
3870
3919
  }
3871
3920
  };
3872
3921
 
3922
+ const getVersionInfo = staticFolderPath => {
3923
+ try {
3924
+ const versionData = fs.readFileSync(`dist/${staticFolderPath}/version.json`, 'utf8');
3925
+ const versionInfo = JSON.parse(versionData);
3926
+ return versionInfo;
3927
+ } catch (ex) {
3928
+ console.error(`Unable to read from "version.json"`, ex);
3929
+ return {};
3930
+ }
3931
+ };
3932
+
3873
3933
  const webApp = (app, ReactApp, config) => {
3874
3934
  const {
3875
3935
  stateType = 'immutable',
@@ -3891,7 +3951,7 @@ const webApp = (app, ReactApp, config) => {
3891
3951
  const attributes = stringifyAttributes(scripts.attributes);
3892
3952
  scripts.startup = scripts.startup || startupScriptFilename;
3893
3953
  const responseHandler = typeof handleResponses === 'function' ? handleResponses : handleResponse;
3894
- const versionInfo = JSON.parse(fs.readFileSync(`dist/${staticFolderPath}/version.json`, 'utf8'));
3954
+ const versionInfo = getVersionInfo(staticFolderPath);
3895
3955
  app.get('/*', async (request, response) => {
3896
3956
  const {
3897
3957
  url
@@ -3941,7 +4001,7 @@ const webApp = (app, ReactApp, config) => {
3941
4001
  store.dispatch(setCurrentProject(project, groups, request.hostname));
3942
4002
  const loadableExtractor = loadableChunkExtractors();
3943
4003
  const jsx = /*#__PURE__*/React.createElement(ChunkExtractorManager, {
3944
- extractor: loadableExtractor === null || loadableExtractor === void 0 ? void 0 : loadableExtractor.commonLoadableExtractor
4004
+ extractor: loadableExtractor.commonLoadableExtractor
3945
4005
  }, /*#__PURE__*/React.createElement(CookiesProvider, {
3946
4006
  cookies: cookies
3947
4007
  }, /*#__PURE__*/React.createElement(Provider, {
@@ -3954,9 +4014,9 @@ const webApp = (app, ReactApp, config) => {
3954
4014
  withEvents: withEvents
3955
4015
  })))));
3956
4016
  const {
3957
- templateHTML,
3958
- templateHTMLFragment,
3959
- templateHTMLStatic
4017
+ templateHTML = '',
4018
+ templateHTMLFragment = '',
4019
+ templateHTMLStatic = ''
3960
4020
  } = bundleData.default.templates || bundleData.legacy.templates || {}; // Serve a blank HTML page with client scripts to load the app in the browser
3961
4021
 
3962
4022
  if (accessMethod.DYNAMIC) {
@@ -3982,7 +4042,7 @@ const webApp = (app, ReactApp, config) => {
3982
4042
  Helmet.rewind();
3983
4043
  const htmlAttributes = helmet.htmlAttributes.toString();
3984
4044
  let title = helmet.title.toString();
3985
- const metadata = helmet.meta.toString().concat(helmet.link.toString());
4045
+ const metadata = helmet.meta.toString().concat(helmet.base.toString()).concat(helmet.link.toString()).concat(helmet.script.toString()).concat(helmet.noscript.toString());
3986
4046
 
3987
4047
  if (context.url) {
3988
4048
  return response.redirect(302, context.url);