@commercetools-frontend/mc-scripts 0.0.0-CRAFT-1791-20251006162610

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.
Files changed (121) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -0
  3. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.d.ts +2 -0
  4. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.dev.js +7 -0
  5. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.js +7 -0
  6. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.prod.js +7 -0
  7. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.esm.js +5 -0
  8. package/application-runtime/package.json +4 -0
  9. package/bin/cli.js +8 -0
  10. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.d.ts +2 -0
  11. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +199 -0
  12. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.js +7 -0
  13. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +199 -0
  14. package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +184 -0
  15. package/cli/package.json +4 -0
  16. package/config/create-webpack-config-for-development.js +8 -0
  17. package/config/create-webpack-config-for-production.js +8 -0
  18. package/config/vendors-to-transpile.js +6 -0
  19. package/dist/build-2a0a18bd.esm.js +155 -0
  20. package/dist/build-521f3f9f.cjs.prod.js +169 -0
  21. package/dist/build-988fc0f7.cjs.dev.js +169 -0
  22. package/dist/build-vite-16b1a575.cjs.dev.js +238 -0
  23. package/dist/build-vite-59e1f185.esm.js +208 -0
  24. package/dist/build-vite-5d317720.cjs.prod.js +238 -0
  25. package/dist/commercetools-frontend-mc-scripts.cjs.d.ts +2 -0
  26. package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +29 -0
  27. package/dist/commercetools-frontend-mc-scripts.cjs.js +7 -0
  28. package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +29 -0
  29. package/dist/commercetools-frontend-mc-scripts.esm.js +21 -0
  30. package/dist/compile-html-025cd493.esm.js +34 -0
  31. package/dist/compile-html-50fd05ec.cjs.prod.js +42 -0
  32. package/dist/compile-html-f4ac88cc.cjs.dev.js +42 -0
  33. package/dist/config-sync-70a16916.cjs.dev.js +852 -0
  34. package/dist/config-sync-72c20d80.cjs.prod.js +846 -0
  35. package/dist/config-sync-bc895390.esm.js +830 -0
  36. package/dist/create-postcss-config-cb7be312.cjs.dev.js +81 -0
  37. package/dist/create-postcss-config-dde0ccf1.esm.js +75 -0
  38. package/dist/create-postcss-config-edca0c33.cjs.prod.js +81 -0
  39. package/dist/create-webpack-config-for-development-1aed1cc0.cjs.prod.js +465 -0
  40. package/dist/create-webpack-config-for-development-a95f3634.esm.js +440 -0
  41. package/dist/create-webpack-config-for-development-d003697b.cjs.dev.js +465 -0
  42. package/dist/create-webpack-config-for-production-15fbe7db.cjs.dev.js +523 -0
  43. package/dist/create-webpack-config-for-production-764c482f.cjs.prod.js +523 -0
  44. package/dist/create-webpack-config-for-production-9f42c336.esm.js +493 -0
  45. package/dist/credentials-storage-66c1e51f.cjs.prod.js +95 -0
  46. package/dist/credentials-storage-d001f726.esm.js +83 -0
  47. package/dist/credentials-storage-e7884d17.cjs.dev.js +95 -0
  48. package/dist/declarations/src/application-runtime.d.ts +1 -0
  49. package/dist/declarations/src/cli.d.ts +4 -0
  50. package/dist/declarations/src/config/create-postcss-config.d.ts +4 -0
  51. package/dist/declarations/src/config/create-webpack-config-for-development.d.ts +10 -0
  52. package/dist/declarations/src/config/create-webpack-config-for-production.d.ts +10 -0
  53. package/dist/declarations/src/config/vendors-to-transpile.d.ts +2 -0
  54. package/dist/declarations/src/deprecated-entry-points.d.ts +7 -0
  55. package/dist/declarations/src/index.d.ts +3 -0
  56. package/dist/declarations/src/postcss.d.ts +1 -0
  57. package/dist/declarations/src/types.d.ts +94 -0
  58. package/dist/declarations/src/version.d.ts +2 -0
  59. package/dist/declarations/src/webpack-loaders/i18n-message-compilation-loader.d.ts +3 -0
  60. package/dist/declarations/src/webpack.d.ts +2 -0
  61. package/dist/deployment-previews-set-17e8ed48.cjs.prod.js +202 -0
  62. package/dist/deployment-previews-set-3648972f.esm.js +191 -0
  63. package/dist/deployment-previews-set-37aef990.cjs.dev.js +202 -0
  64. package/dist/does-file-exist-32618334.esm.js +12 -0
  65. package/dist/does-file-exist-be53305d.cjs.prod.js +18 -0
  66. package/dist/does-file-exist-eb86baca.cjs.dev.js +18 -0
  67. package/dist/graphql-requests-6a47ad5b.esm.js +247 -0
  68. package/dist/graphql-requests-779b867b.cjs.dev.js +270 -0
  69. package/dist/graphql-requests-8086eba7.cjs.prod.js +270 -0
  70. package/dist/has-jsx-runtime-aa5d21ee.cjs.dev.js +15 -0
  71. package/dist/has-jsx-runtime-c3202df5.cjs.prod.js +15 -0
  72. package/dist/has-jsx-runtime-e3ecb09b.esm.js +13 -0
  73. package/dist/i18n-message-complilation-21d3b0aa.esm.js +15 -0
  74. package/dist/i18n-message-complilation-7311cb29.cjs.dev.js +23 -0
  75. package/dist/i18n-message-complilation-7762da61.cjs.prod.js +23 -0
  76. package/dist/login-0a728449.esm.js +229 -0
  77. package/dist/login-817a5a26.cjs.dev.js +270 -0
  78. package/dist/login-85c25393.cjs.prod.js +270 -0
  79. package/dist/optimizations-7789145e.cjs.dev.js +85 -0
  80. package/dist/optimizations-bf991634.esm.js +67 -0
  81. package/dist/optimizations-fb93514f.cjs.prod.js +85 -0
  82. package/dist/package-7e170dc4.cjs.dev.js +160 -0
  83. package/dist/package-940b0a2a.cjs.prod.js +160 -0
  84. package/dist/package-99e547a7.esm.js +158 -0
  85. package/dist/paths-39f22b8b.esm.js +36 -0
  86. package/dist/paths-7768b440.cjs.prod.js +44 -0
  87. package/dist/paths-b76fc753.cjs.dev.js +44 -0
  88. package/dist/serve-1036c2de.esm.js +55 -0
  89. package/dist/serve-50d33f0b.cjs.dev.js +64 -0
  90. package/dist/serve-8a506da6.cjs.prod.js +64 -0
  91. package/dist/start-1d677ad8.cjs.dev.js +177 -0
  92. package/dist/start-2a7ae03d.esm.js +164 -0
  93. package/dist/start-f56cb5f7.cjs.prod.js +177 -0
  94. package/dist/start-vite-068e9f73.cjs.dev.js +128 -0
  95. package/dist/start-vite-29078b3a.cjs.prod.js +128 -0
  96. package/dist/start-vite-7d1161e8.esm.js +116 -0
  97. package/dist/vendors-to-transpile-04a49d40.cjs.prod.js +5 -0
  98. package/dist/vendors-to-transpile-6ab4ea06.cjs.dev.js +5 -0
  99. package/dist/vendors-to-transpile-7dc84a72.esm.js +3 -0
  100. package/dist/vite-plugin-svgr-4034a834.cjs.prod.js +151 -0
  101. package/dist/vite-plugin-svgr-7d06f400.cjs.dev.js +151 -0
  102. package/dist/vite-plugin-svgr-de6ee7da.esm.js +125 -0
  103. package/package.json +156 -0
  104. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.d.ts +2 -0
  105. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +12 -0
  106. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.js +7 -0
  107. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +12 -0
  108. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +4 -0
  109. package/postcss/package.json +4 -0
  110. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.d.ts +2 -0
  111. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +57 -0
  112. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.js +7 -0
  113. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +57 -0
  114. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +48 -0
  115. package/webpack/package.json +4 -0
  116. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.d.ts +3 -0
  117. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.dev.js +30 -0
  118. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.js +7 -0
  119. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.prod.js +30 -0
  120. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.esm.js +26 -0
  121. package/webpack-loaders/i18n-message-compilation-loader/package.json +4 -0
@@ -0,0 +1,128 @@
1
+ 'use strict';
2
+
3
+ var _parseInt = require('@babel/runtime-corejs3/core-js-stable/parse-int');
4
+ var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
5
+ var path = require('path');
6
+ var pluginGraphql = require('@rollup/plugin-graphql');
7
+ var pluginReact = require('@vitejs/plugin-react-swc');
8
+ var fs = require('fs-extra');
9
+ var vite = require('vite');
10
+ var applicationConfig = require('@commercetools-frontend/application-config');
11
+ var assets = require('@commercetools-frontend/assets');
12
+ var mcHtmlTemplate = require('@commercetools-frontend/mc-html-template');
13
+ var paths = require('./paths-b76fc753.cjs.dev.js');
14
+ var _Object$assign = require('@babel/runtime-corejs3/core-js-stable/object/assign');
15
+ var mcDevAuthentication = require('@commercetools-frontend/mc-dev-authentication');
16
+ var vitePluginSvgr = require('./vite-plugin-svgr-7d06f400.cjs.dev.js');
17
+ require('@babel/runtime-corejs3/core-js-stable/instance/find');
18
+ require('fs');
19
+ require('./does-file-exist-eb86baca.cjs.dev.js');
20
+ require('node:fs');
21
+ require('crypto');
22
+ require('@rollup/pluginutils');
23
+ require('@babel/runtime-corejs3/core-js/instance/match-all');
24
+
25
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
26
+
27
+ var _parseInt__default = /*#__PURE__*/_interopDefault(_parseInt);
28
+ var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
29
+ var path__default = /*#__PURE__*/_interopDefault(path);
30
+ var pluginGraphql__default = /*#__PURE__*/_interopDefault(pluginGraphql);
31
+ var pluginReact__default = /*#__PURE__*/_interopDefault(pluginReact);
32
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
33
+ var _Object$assign__default = /*#__PURE__*/_interopDefault(_Object$assign);
34
+
35
+ const vitePluginCustomApplication = applicationConfig => {
36
+ return {
37
+ name: 'custom-application',
38
+ configureServer(server) {
39
+ return () => {
40
+ // Users do not need to have/maintain the `index.html` (as expected by Vite)
41
+ // as it's generated and maintained by the Merchant Center customization CLI.
42
+ // Therefore, the generated `index.html` (template) is written into the `/public`
43
+ // folder so that it's gitignored.
44
+ // As a result, we need to make sure to point the URI path to the correct location.
45
+ server.middlewares.use((req, _res, next) => {
46
+ if (req.url === '/index.html') {
47
+ req.url = '/public/index.html';
48
+ }
49
+ next();
50
+ });
51
+
52
+ // Handle auth routes for internal local development.
53
+ server.middlewares.use(mcDevAuthentication.createMcDevAuthenticationMiddleware(applicationConfig));
54
+ };
55
+ },
56
+ /**
57
+ * @type {import('vite').IndexHtmlTransformHook}
58
+ */
59
+ transformIndexHtml(rawHtml, _ctx) {
60
+ const compiledHeaders = mcHtmlTemplate.processHeaders(applicationConfig);
61
+ const enhancedLocalEnv = _Object$assign__default["default"]({}, applicationConfig.env,
62
+ // Now that the app config is defined as a `env.json`, when we start the FE app
63
+ // to point to the local backend API by passing the `MC_API_URL` env does not
64
+ // work anymore). To make it work again, we can override the `env.json` config
65
+ // with the env variable before injecting the values into the index.html.
66
+ // NOTE: this is only necessary for development.
67
+ process.env.MC_API_URL ? {
68
+ mcApiUrl: process.env.MC_API_URL
69
+ } : {});
70
+
71
+ // Resolve the placeholders of the `index.html` (template) file, before serving it.
72
+ const html = mcHtmlTemplate.replaceHtmlPlaceholders(rawHtml, {
73
+ env: enhancedLocalEnv,
74
+ headers: compiledHeaders
75
+ });
76
+ return html;
77
+ }
78
+ };
79
+ };
80
+
81
+ async function run() {
82
+ const DEFAULT_PORT = _parseInt__default["default"](String(process.env.HTTP_PORT), 10) || 3001;
83
+
84
+ // Load the Merchant Center customization config file first.
85
+ const applicationConfig$1 = await applicationConfig.processConfig();
86
+
87
+ // Ensure the `/public` folder exists.
88
+ fs__default["default"].mkdirSync(paths.paths.appBuild, {
89
+ recursive: true
90
+ });
91
+
92
+ // Generate `index.html` (template).
93
+ const appEntryPoint = path__default["default"].relative(paths.paths.appRoot, paths.paths.entryPoint);
94
+ const html = mcHtmlTemplate.generateTemplate({
95
+ // Define the module entry point (path relative to the `/public` folder).
96
+ // NOTE: that this is different from the production configuration.
97
+ scriptImports: [`<script type="module" src="/../${appEntryPoint}" defer></script>`]
98
+ });
99
+ // Write `index.html` (template) into the `/public` folder.
100
+ fs__default["default"].writeFileSync(paths.paths.appIndexHtml, html, {
101
+ encoding: 'utf8'
102
+ });
103
+ const compiledHeaders = mcHtmlTemplate.processHeaders(applicationConfig$1);
104
+ const server = await vite.createServer({
105
+ root: paths.paths.appRoot,
106
+ define: {
107
+ 'process.env.DEBUG': _JSON$stringify__default["default"](false),
108
+ 'process.env.NODE_ENV': _JSON$stringify__default["default"]('development')
109
+ },
110
+ server: {
111
+ open: true,
112
+ port: DEFAULT_PORT,
113
+ headers: compiledHeaders
114
+ },
115
+ plugins: [pluginGraphql__default["default"](), pluginReact__default["default"]({
116
+ jsxImportSource: '@emotion/react'
117
+ }), vitePluginSvgr.vitePluginSvgr(), vitePluginCustomApplication(applicationConfig$1)]
118
+ });
119
+ await server.listen();
120
+
121
+ // Copy public assets to `/public` folder (even in development).
122
+ fs__default["default"].copySync(path__default["default"].join(assets.packageLocation, 'html-page'), paths.paths.appBuild, {
123
+ dereference: true
124
+ });
125
+ server.printUrls();
126
+ }
127
+
128
+ exports["default"] = run;
@@ -0,0 +1,128 @@
1
+ 'use strict';
2
+
3
+ var _parseInt = require('@babel/runtime-corejs3/core-js-stable/parse-int');
4
+ var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
5
+ var path = require('path');
6
+ var pluginGraphql = require('@rollup/plugin-graphql');
7
+ var pluginReact = require('@vitejs/plugin-react-swc');
8
+ var fs = require('fs-extra');
9
+ var vite = require('vite');
10
+ var applicationConfig = require('@commercetools-frontend/application-config');
11
+ var assets = require('@commercetools-frontend/assets');
12
+ var mcHtmlTemplate = require('@commercetools-frontend/mc-html-template');
13
+ var paths = require('./paths-7768b440.cjs.prod.js');
14
+ var _Object$assign = require('@babel/runtime-corejs3/core-js-stable/object/assign');
15
+ var mcDevAuthentication = require('@commercetools-frontend/mc-dev-authentication');
16
+ var vitePluginSvgr = require('./vite-plugin-svgr-4034a834.cjs.prod.js');
17
+ require('@babel/runtime-corejs3/core-js-stable/instance/find');
18
+ require('fs');
19
+ require('./does-file-exist-be53305d.cjs.prod.js');
20
+ require('node:fs');
21
+ require('crypto');
22
+ require('@rollup/pluginutils');
23
+ require('@babel/runtime-corejs3/core-js/instance/match-all');
24
+
25
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
26
+
27
+ var _parseInt__default = /*#__PURE__*/_interopDefault(_parseInt);
28
+ var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
29
+ var path__default = /*#__PURE__*/_interopDefault(path);
30
+ var pluginGraphql__default = /*#__PURE__*/_interopDefault(pluginGraphql);
31
+ var pluginReact__default = /*#__PURE__*/_interopDefault(pluginReact);
32
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
33
+ var _Object$assign__default = /*#__PURE__*/_interopDefault(_Object$assign);
34
+
35
+ const vitePluginCustomApplication = applicationConfig => {
36
+ return {
37
+ name: 'custom-application',
38
+ configureServer(server) {
39
+ return () => {
40
+ // Users do not need to have/maintain the `index.html` (as expected by Vite)
41
+ // as it's generated and maintained by the Merchant Center customization CLI.
42
+ // Therefore, the generated `index.html` (template) is written into the `/public`
43
+ // folder so that it's gitignored.
44
+ // As a result, we need to make sure to point the URI path to the correct location.
45
+ server.middlewares.use((req, _res, next) => {
46
+ if (req.url === '/index.html') {
47
+ req.url = '/public/index.html';
48
+ }
49
+ next();
50
+ });
51
+
52
+ // Handle auth routes for internal local development.
53
+ server.middlewares.use(mcDevAuthentication.createMcDevAuthenticationMiddleware(applicationConfig));
54
+ };
55
+ },
56
+ /**
57
+ * @type {import('vite').IndexHtmlTransformHook}
58
+ */
59
+ transformIndexHtml(rawHtml, _ctx) {
60
+ const compiledHeaders = mcHtmlTemplate.processHeaders(applicationConfig);
61
+ const enhancedLocalEnv = _Object$assign__default["default"]({}, applicationConfig.env,
62
+ // Now that the app config is defined as a `env.json`, when we start the FE app
63
+ // to point to the local backend API by passing the `MC_API_URL` env does not
64
+ // work anymore). To make it work again, we can override the `env.json` config
65
+ // with the env variable before injecting the values into the index.html.
66
+ // NOTE: this is only necessary for development.
67
+ process.env.MC_API_URL ? {
68
+ mcApiUrl: process.env.MC_API_URL
69
+ } : {});
70
+
71
+ // Resolve the placeholders of the `index.html` (template) file, before serving it.
72
+ const html = mcHtmlTemplate.replaceHtmlPlaceholders(rawHtml, {
73
+ env: enhancedLocalEnv,
74
+ headers: compiledHeaders
75
+ });
76
+ return html;
77
+ }
78
+ };
79
+ };
80
+
81
+ async function run() {
82
+ const DEFAULT_PORT = _parseInt__default["default"](String(process.env.HTTP_PORT), 10) || 3001;
83
+
84
+ // Load the Merchant Center customization config file first.
85
+ const applicationConfig$1 = await applicationConfig.processConfig();
86
+
87
+ // Ensure the `/public` folder exists.
88
+ fs__default["default"].mkdirSync(paths.paths.appBuild, {
89
+ recursive: true
90
+ });
91
+
92
+ // Generate `index.html` (template).
93
+ const appEntryPoint = path__default["default"].relative(paths.paths.appRoot, paths.paths.entryPoint);
94
+ const html = mcHtmlTemplate.generateTemplate({
95
+ // Define the module entry point (path relative to the `/public` folder).
96
+ // NOTE: that this is different from the production configuration.
97
+ scriptImports: [`<script type="module" src="/../${appEntryPoint}" defer></script>`]
98
+ });
99
+ // Write `index.html` (template) into the `/public` folder.
100
+ fs__default["default"].writeFileSync(paths.paths.appIndexHtml, html, {
101
+ encoding: 'utf8'
102
+ });
103
+ const compiledHeaders = mcHtmlTemplate.processHeaders(applicationConfig$1);
104
+ const server = await vite.createServer({
105
+ root: paths.paths.appRoot,
106
+ define: {
107
+ 'process.env.DEBUG': _JSON$stringify__default["default"](false),
108
+ 'process.env.NODE_ENV': _JSON$stringify__default["default"]('development')
109
+ },
110
+ server: {
111
+ open: true,
112
+ port: DEFAULT_PORT,
113
+ headers: compiledHeaders
114
+ },
115
+ plugins: [pluginGraphql__default["default"](), pluginReact__default["default"]({
116
+ jsxImportSource: '@emotion/react'
117
+ }), vitePluginSvgr.vitePluginSvgr(), vitePluginCustomApplication(applicationConfig$1)]
118
+ });
119
+ await server.listen();
120
+
121
+ // Copy public assets to `/public` folder (even in development).
122
+ fs__default["default"].copySync(path__default["default"].join(assets.packageLocation, 'html-page'), paths.paths.appBuild, {
123
+ dereference: true
124
+ });
125
+ server.printUrls();
126
+ }
127
+
128
+ exports["default"] = run;
@@ -0,0 +1,116 @@
1
+ import _parseInt from '@babel/runtime-corejs3/core-js-stable/parse-int';
2
+ import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
3
+ import path from 'path';
4
+ import pluginGraphql from '@rollup/plugin-graphql';
5
+ import pluginReact from '@vitejs/plugin-react-swc';
6
+ import fs from 'fs-extra';
7
+ import { createServer } from 'vite';
8
+ import { processConfig } from '@commercetools-frontend/application-config';
9
+ import { packageLocation } from '@commercetools-frontend/assets';
10
+ import { processHeaders, replaceHtmlPlaceholders, generateTemplate } from '@commercetools-frontend/mc-html-template';
11
+ import { p as paths } from './paths-39f22b8b.esm.js';
12
+ import _Object$assign from '@babel/runtime-corejs3/core-js-stable/object/assign';
13
+ import { createMcDevAuthenticationMiddleware } from '@commercetools-frontend/mc-dev-authentication';
14
+ import { v as vitePluginSvgr } from './vite-plugin-svgr-de6ee7da.esm.js';
15
+ import '@babel/runtime-corejs3/core-js-stable/instance/find';
16
+ import 'fs';
17
+ import './does-file-exist-32618334.esm.js';
18
+ import 'node:fs';
19
+ import 'crypto';
20
+ import '@rollup/pluginutils';
21
+ import '@babel/runtime-corejs3/core-js/instance/match-all';
22
+
23
+ const vitePluginCustomApplication = applicationConfig => {
24
+ return {
25
+ name: 'custom-application',
26
+ configureServer(server) {
27
+ return () => {
28
+ // Users do not need to have/maintain the `index.html` (as expected by Vite)
29
+ // as it's generated and maintained by the Merchant Center customization CLI.
30
+ // Therefore, the generated `index.html` (template) is written into the `/public`
31
+ // folder so that it's gitignored.
32
+ // As a result, we need to make sure to point the URI path to the correct location.
33
+ server.middlewares.use((req, _res, next) => {
34
+ if (req.url === '/index.html') {
35
+ req.url = '/public/index.html';
36
+ }
37
+ next();
38
+ });
39
+
40
+ // Handle auth routes for internal local development.
41
+ server.middlewares.use(createMcDevAuthenticationMiddleware(applicationConfig));
42
+ };
43
+ },
44
+ /**
45
+ * @type {import('vite').IndexHtmlTransformHook}
46
+ */
47
+ transformIndexHtml(rawHtml, _ctx) {
48
+ const compiledHeaders = processHeaders(applicationConfig);
49
+ const enhancedLocalEnv = _Object$assign({}, applicationConfig.env,
50
+ // Now that the app config is defined as a `env.json`, when we start the FE app
51
+ // to point to the local backend API by passing the `MC_API_URL` env does not
52
+ // work anymore). To make it work again, we can override the `env.json` config
53
+ // with the env variable before injecting the values into the index.html.
54
+ // NOTE: this is only necessary for development.
55
+ process.env.MC_API_URL ? {
56
+ mcApiUrl: process.env.MC_API_URL
57
+ } : {});
58
+
59
+ // Resolve the placeholders of the `index.html` (template) file, before serving it.
60
+ const html = replaceHtmlPlaceholders(rawHtml, {
61
+ env: enhancedLocalEnv,
62
+ headers: compiledHeaders
63
+ });
64
+ return html;
65
+ }
66
+ };
67
+ };
68
+
69
+ async function run() {
70
+ const DEFAULT_PORT = _parseInt(String(process.env.HTTP_PORT), 10) || 3001;
71
+
72
+ // Load the Merchant Center customization config file first.
73
+ const applicationConfig = await processConfig();
74
+
75
+ // Ensure the `/public` folder exists.
76
+ fs.mkdirSync(paths.appBuild, {
77
+ recursive: true
78
+ });
79
+
80
+ // Generate `index.html` (template).
81
+ const appEntryPoint = path.relative(paths.appRoot, paths.entryPoint);
82
+ const html = generateTemplate({
83
+ // Define the module entry point (path relative to the `/public` folder).
84
+ // NOTE: that this is different from the production configuration.
85
+ scriptImports: [`<script type="module" src="/../${appEntryPoint}" defer></script>`]
86
+ });
87
+ // Write `index.html` (template) into the `/public` folder.
88
+ fs.writeFileSync(paths.appIndexHtml, html, {
89
+ encoding: 'utf8'
90
+ });
91
+ const compiledHeaders = processHeaders(applicationConfig);
92
+ const server = await createServer({
93
+ root: paths.appRoot,
94
+ define: {
95
+ 'process.env.DEBUG': _JSON$stringify(false),
96
+ 'process.env.NODE_ENV': _JSON$stringify('development')
97
+ },
98
+ server: {
99
+ open: true,
100
+ port: DEFAULT_PORT,
101
+ headers: compiledHeaders
102
+ },
103
+ plugins: [pluginGraphql(), pluginReact({
104
+ jsxImportSource: '@emotion/react'
105
+ }), vitePluginSvgr(), vitePluginCustomApplication(applicationConfig)]
106
+ });
107
+ await server.listen();
108
+
109
+ // Copy public assets to `/public` folder (even in development).
110
+ fs.copySync(path.join(packageLocation, 'html-page'), paths.appBuild, {
111
+ dereference: true
112
+ });
113
+ server.printUrls();
114
+ }
115
+
116
+ export { run as default };
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ const vendorsToTranspile = [];
4
+
5
+ exports.vendorsToTranspile = vendorsToTranspile;
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ const vendorsToTranspile = [];
4
+
5
+ exports.vendorsToTranspile = vendorsToTranspile;
@@ -0,0 +1,3 @@
1
+ const vendorsToTranspile = [];
2
+
3
+ export { vendorsToTranspile as v };
@@ -0,0 +1,151 @@
1
+ 'use strict';
2
+
3
+ var crypto = require('crypto');
4
+ var fs = require('fs');
5
+ var pluginutils = require('@rollup/pluginutils');
6
+ var vite = require('vite');
7
+ var _matchAllInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/match-all');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
10
+
11
+ function _interopNamespace(e) {
12
+ if (e && e.__esModule) return e;
13
+ var n = Object.create(null);
14
+ if (e) {
15
+ Object.keys(e).forEach(function (k) {
16
+ if (k !== 'default') {
17
+ var d = Object.getOwnPropertyDescriptor(e, k);
18
+ Object.defineProperty(n, k, d.get ? d : {
19
+ enumerable: true,
20
+ get: function () { return e[k]; }
21
+ });
22
+ }
23
+ });
24
+ }
25
+ n["default"] = e;
26
+ return Object.freeze(n);
27
+ }
28
+
29
+ var crypto__default = /*#__PURE__*/_interopDefault(crypto);
30
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
31
+ var _matchAllInstanceProperty__default = /*#__PURE__*/_interopDefault(_matchAllInstanceProperty);
32
+
33
+ async function optimizeEmbeddedPngs(code, id) {
34
+ const pngRegex = /href="data:image\/png;base64,([a-zA-Z0-9+/]+=*)"/gs;
35
+ let modifiedCode = code;
36
+ const matchesIterator = _matchAllInstanceProperty__default["default"](code).call(code, pngRegex);
37
+ for (const match of matchesIterator) {
38
+ const originalBase64 = match[1];
39
+ if (originalBase64) {
40
+ // This length would indicate that the match is greater than ~1mb
41
+ if (originalBase64.length > 1000000) {
42
+ const fileName = id.split('/').pop();
43
+ console.warn(`\n🚨 You have a large png embedded in ${fileName} - consider using an image tag instead 🚨`);
44
+ try {
45
+ const pngBuffer = Buffer.from(originalBase64, 'base64');
46
+ const sharp = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('sharp')); })).default;
47
+ const optimizedBuffer = await sharp(pngBuffer).png({
48
+ quality: 10,
49
+ compressionLevel: 9
50
+ }).toBuffer();
51
+ const optimizedPngBase64 = optimizedBuffer.toString('base64');
52
+ // Construct the new href value
53
+ const originalMatch = match[0];
54
+ const optimizedXlinkHref = originalMatch.replace(originalBase64, optimizedPngBase64);
55
+ // Replace the original href with the optimized one
56
+ modifiedCode = modifiedCode.replace(originalMatch, optimizedXlinkHref);
57
+ } catch (error) {
58
+ console.error('Error processing embedded PNG:', error, 'Original Base64:', originalBase64);
59
+ }
60
+ }
61
+ }
62
+ }
63
+ return modifiedCode;
64
+ }
65
+
66
+ /**
67
+ * COPIED FROM https://github.com/pd4d10/vite-plugin-svgr
68
+ */
69
+ function vitePluginSvgr() {
70
+ const filter = pluginutils.createFilter('**/*.react.svg');
71
+ return {
72
+ name: 'vite-plugin-svgr',
73
+ async transform(_code, id) {
74
+ if (filter(id)) {
75
+ const _await$import = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@svgr/core')); }),
76
+ transform = _await$import.transform;
77
+ const svgCode = await fs__default["default"].promises.readFile(id, 'utf8');
78
+ let transformableSVGCode;
79
+ if (process.env.ENABLE_EXPERIMENTAL_SVG_PNG_OPTIMIZATION === 'true') {
80
+ // This is a temporary fix for the issue with large embedded PNGs
81
+ // in SVGs. It will be removed once we have a better solution.
82
+ transformableSVGCode = await optimizeEmbeddedPngs(svgCode, id);
83
+ } else {
84
+ transformableSVGCode = svgCode;
85
+ }
86
+ const componentCode = await transform(transformableSVGCode, {
87
+ icon: false,
88
+ svgoConfig: {
89
+ plugins: [{
90
+ // https://github.com/svg/svgo#default-preset
91
+ name: 'preset-default',
92
+ params: {
93
+ overrides: {
94
+ removeViewBox: false
95
+ }
96
+ }
97
+ },
98
+ // Avoid collisions with ids in other SVGs,
99
+ // which was causing incorrect masking, gradient directions, etc
100
+ // this is an ongoing issue with both SVGR and SVGO,
101
+ // https://github.com/svg/svgo/issues/913#issuecomment-369373572
102
+ // see SVGR issues:
103
+ // https://github.com/gregberge/svgr/issues/322
104
+ // https://github.com/gregberge/svgr/issues/210
105
+ // see SVGO issues:
106
+ // https://github.com/svg/svgo/issues/674
107
+ // https://github.com/svg/svgo/issues/1746
108
+ //
109
+ // Initially, a naive counter was implemented based on this github comment:
110
+ // https://github.com/svg/svgo/issues/1746#issuecomment-1803600573
111
+ // But while that implementation insured id’s that are unique,
112
+ // it did not work in cases where the id is both declared and referenced in the same file,
113
+ // because the refernce gets a separate unique ID (a different number from the counter).
114
+ //
115
+ // The current implementation is based on this github comment:
116
+ // https://github.com/svg/svgo/issues/913#issuecomment-369373572
117
+ // Generates a hash of the filepath of the svg file, resulting in a prefix which is:
118
+ // - Short,
119
+ // - With characters valid for IDs,
120
+ // - The same within a file,
121
+ // - And different in different files.
122
+ {
123
+ name: 'prefixIds',
124
+ params: {
125
+ delim: '',
126
+ prefix: (_, info) => `svg${crypto__default["default"].createHash('shake256', {
127
+ outputLength: 6
128
+ }).update(info.path || '').digest('hex')}`
129
+ }
130
+ }]
131
+ }
132
+ }, {
133
+ filePath: id,
134
+ caller: {
135
+ previousExport: null
136
+ }
137
+ });
138
+ const res = await vite.transformWithEsbuild(componentCode, id, {
139
+ loader: 'jsx'
140
+ });
141
+ return {
142
+ code: res.code,
143
+ map: null // TODO:
144
+ };
145
+ }
146
+ return null;
147
+ }
148
+ };
149
+ }
150
+
151
+ exports.vitePluginSvgr = vitePluginSvgr;