@strapi/admin 4.2.0-beta.4 → 4.2.2

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 (151) hide show
  1. package/admin/src/app.js +4 -7
  2. package/admin/src/components/OverlayBlocker/index.js +4 -0
  3. package/admin/src/content-manager/components/Wysiwyg/EditorStylesContainer.js +1 -1
  4. package/admin/src/hooks/{useFetchInstalledPlugins → useFetchEnabledPlugins}/index.js +4 -4
  5. package/admin/src/hooks/{useFetchInstalledPlugins → useFetchEnabledPlugins}/utils/api.js +2 -2
  6. package/admin/src/hooks/useFetchMarketplaceProviders/index.js +23 -0
  7. package/admin/src/hooks/useFetchMarketplaceProviders/utils/api.js +11 -0
  8. package/admin/src/pages/Admin/index.js +5 -15
  9. package/admin/src/pages/App/index.js +3 -17
  10. package/admin/src/pages/InstalledPluginsPage/Plugins.js +2 -2
  11. package/admin/src/pages/MarketplacePage/components/{EmptyPluginSearch/EmptyPluginGrid.js → EmptyNpmPackageSearch/EmptyNpmPackageGrid.js} +1 -1
  12. package/admin/src/pages/MarketplacePage/components/{EmptyPluginSearch → EmptyNpmPackageSearch}/index.js +6 -4
  13. package/admin/src/pages/MarketplacePage/components/{PluginCard → NpmPackageCard}/InstallPluginButton.js +0 -0
  14. package/admin/src/pages/MarketplacePage/components/{PluginCard → NpmPackageCard}/index.js +22 -11
  15. package/admin/src/pages/MarketplacePage/components/NpmPackagesGrid/index.js +48 -0
  16. package/admin/src/pages/MarketplacePage/components/PageHeader/index.js +12 -5
  17. package/admin/src/pages/MarketplacePage/index.js +91 -59
  18. package/admin/src/reducers.js +2 -4
  19. package/admin/src/translations/en.json +7 -3
  20. package/admin/src/translations/hi.json +699 -0
  21. package/admin/src/translations/languageNativeNames.js +1 -0
  22. package/admin/src/translations/pl.json +335 -78
  23. package/admin/src/translations/vi.json +17 -17
  24. package/admin/src/translations/zh-Hans.json +28 -1
  25. package/build/1856.6a94980b.chunk.js +172 -0
  26. package/build/2077.5456ccd1.chunk.js +194 -0
  27. package/build/2758.9475712b.chunk.js +162 -0
  28. package/build/2912.dd031292.chunk.js +253 -0
  29. package/build/4715.a6e62860.chunk.js +385 -0
  30. package/build/4982.c57c5675.chunk.js +308 -0
  31. package/build/7197.74d81c4c.chunk.js +113 -0
  32. package/build/{6229.a5cca9f2.chunk.js → 7589.77ef4fbf.chunk.js} +2 -2
  33. package/build/{472.0350a5bd.chunk.js → 7757.f6eb5e92.chunk.js} +58 -58
  34. package/build/7841.9e9cf739.chunk.js +253 -0
  35. package/build/8681.2fd4020a.chunk.js +163 -0
  36. package/build/9066.2847fdff.chunk.js +101 -0
  37. package/build/{4073.e144a91a.chunk.js → 9115.623dc4f7.chunk.js} +1 -1
  38. package/build/9158.c5f772d6.chunk.js +503 -0
  39. package/build/{9298.aff28744.chunk.js → 9298.cb3b6bc1.chunk.js} +93 -93
  40. package/build/9420.ba035f29.chunk.js +508 -0
  41. package/build/Admin-authenticatedApp.2a22d6f4.chunk.js +80 -0
  42. package/build/{Admin_homePage.0ac648e8.chunk.js → Admin_homePage.447df176.chunk.js} +1 -1
  43. package/build/Admin_marketplace.0724f650.chunk.js +11 -0
  44. package/build/Admin_pluginsPage.6f1187fe.chunk.js +1 -0
  45. package/build/{Admin_profilePage.27191ed2.chunk.js → Admin_profilePage.249cbfc9.chunk.js} +2 -2
  46. package/build/Admin_settingsPage.0d138832.chunk.js +180 -0
  47. package/build/{admin-edit-roles-page.fb374555.chunk.js → admin-edit-roles-page.7c2c9752.chunk.js} +1 -1
  48. package/build/admin-edit-users.b835bc48.chunk.js +11 -0
  49. package/build/admin-users.19900b75.chunk.js +12 -0
  50. package/build/{api-tokens-create-page.698f132d.chunk.js → api-tokens-create-page.8d299dde.chunk.js} +1 -1
  51. package/build/{api-tokens-edit-page.afece2fe.chunk.js → api-tokens-edit-page.3e453fc1.chunk.js} +1 -1
  52. package/build/{api-tokens-list-page.46d96dee.chunk.js → api-tokens-list-page.872c3800.chunk.js} +1 -1
  53. package/build/{codemirror-css.b467b1de.chunk.js → codemirror-css.98490df3.chunk.js} +2 -2
  54. package/build/{codemirror-javacript.41bdefda.chunk.js → codemirror-javacript.cafbda9c.chunk.js} +1 -1
  55. package/build/codemirror-theme.b3c64617.chunk.js +34 -0
  56. package/build/{content-manager.7cd28f84.chunk.js → content-manager.18834aa8.chunk.js} +10 -10
  57. package/build/content-type-builder-translation-pl-json.4a42349b.chunk.js +1 -0
  58. package/build/content-type-builder.55dd9554.chunk.js +142 -0
  59. package/build/{cropper-css.ecc0d670.chunk.js → cropper-css.0055cd53.chunk.js} +2 -2
  60. package/build/email-settings-page.1f235173.chunk.js +103 -0
  61. package/build/email-translation-pl-json.a03bcf98.chunk.js +1 -0
  62. package/build/en-json.0a5ba154.chunk.js +1 -0
  63. package/build/{fontawesome-css-all.04f33619.chunk.js → fontawesome-css-all.b88d464e.chunk.js} +3 -3
  64. package/build/{fontawesome-css.477ba714.chunk.js → fontawesome-css.a92a7b6c.chunk.js} +2 -2
  65. package/build/hi-json.b4ae16d1.chunk.js +1 -0
  66. package/build/highlight.js.9d8ef460.chunk.js +86 -0
  67. package/build/i18n-settings-page.06e88cf2.chunk.js +101 -0
  68. package/build/i18n-translation-pl-json.cea5bf23.chunk.js +1 -0
  69. package/build/index.html +1 -1
  70. package/build/main.fcb539e3.js +8406 -0
  71. package/build/pl-json.4d11f53d.chunk.js +1 -0
  72. package/build/runtime~main.ade14a85.js +2 -0
  73. package/build/sso-settings-page.a7c2e854.chunk.js +1 -0
  74. package/build/upload-settings.4ee2f135.chunk.js +101 -0
  75. package/build/upload-translation-pl-json.bb2aa937.chunk.js +1 -0
  76. package/build/upload.0d4153e8.chunk.js +105 -0
  77. package/build/users-advanced-settings-page.583c5dda.chunk.js +101 -0
  78. package/build/users-email-settings-page.8b9a266d.chunk.js +1 -0
  79. package/build/users-permissions-translation-en-json.765abf48.chunk.js +1 -0
  80. package/build/users-permissions-translation-pl-json.1dbdd4a1.chunk.js +1 -0
  81. package/build/users-providers-settings-page.fc9d8f9d.chunk.js +1 -0
  82. package/build/{users-roles-settings-page.988ebc3b.chunk.js → users-roles-settings-page.1bf4ffc5.chunk.js} +2 -2
  83. package/build/vi-json.bf3424be.chunk.js +1 -0
  84. package/build/{webhook-edit-page.a7ae6e3b.chunk.js → webhook-edit-page.142b23ac.chunk.js} +2 -2
  85. package/build/webhook-list-page.671582a0.chunk.js +133 -0
  86. package/build/zh-Hans-json.562f3b6f.chunk.js +1 -0
  87. package/index.js +239 -53
  88. package/package.json +9 -11
  89. package/scripts/build.js +3 -17
  90. package/server/controllers/admin.js +2 -15
  91. package/server/policies/index.js +0 -1
  92. package/server/routes/admin.js +0 -9
  93. package/server/routes/serve-admin-panel.js +1 -1
  94. package/webpack.alias.js +30 -19
  95. package/webpack.config.js +9 -29
  96. package/admin/src/pages/App/constants.js +0 -1
  97. package/admin/src/pages/App/reducer.js +0 -22
  98. package/admin/src/pages/MarketplacePage/utils/api.js +0 -9
  99. package/admin/src/tsconfig.json +0 -10
  100. package/build/1541.6c1c96f9.chunk.js +0 -307
  101. package/build/1856.521a99fd.chunk.js +0 -172
  102. package/build/2077.51485bfb.chunk.js +0 -194
  103. package/build/2912.79c2b3c8.chunk.js +0 -253
  104. package/build/3214.9196aeff.chunk.js +0 -235
  105. package/build/3865.21cec9de.chunk.js +0 -310
  106. package/build/4715.77e04177.chunk.js +0 -385
  107. package/build/4982.f53b78a4.chunk.js +0 -308
  108. package/build/7351.b95e65ae.chunk.js +0 -428
  109. package/build/7418.6db737ce.chunk.js +0 -112
  110. package/build/7841.f0e7d629.chunk.js +0 -253
  111. package/build/8826.58e236d4.chunk.js +0 -1057
  112. package/build/9066.118ecccd.chunk.js +0 -101
  113. package/build/9420.cb0b75e8.chunk.js +0 -508
  114. package/build/9988.f84412d9.chunk.js +0 -162
  115. package/build/Admin-authenticatedApp.162a5805.chunk.js +0 -80
  116. package/build/Admin_marketplace.0bb91ec8.chunk.js +0 -11
  117. package/build/Admin_pluginsPage.788fb2f6.chunk.js +0 -1
  118. package/build/Admin_settingsPage.23e873f0.chunk.js +0 -178
  119. package/build/admin-edit-users.a360deaf.chunk.js +0 -10
  120. package/build/admin-users.47d06d24.chunk.js +0 -11
  121. package/build/codemirror-theme.cf9f9eb6.chunk.js +0 -34
  122. package/build/content-type-builder-translation-pl-json.a866acda.chunk.js +0 -1
  123. package/build/content-type-builder.7456cabe.chunk.js +0 -141
  124. package/build/email-settings-page.f67d13b2.chunk.js +0 -103
  125. package/build/email-translation-pl-json.6da50d0f.chunk.js +0 -1
  126. package/build/en-json.40ee00aa.chunk.js +0 -1
  127. package/build/highlight.js.3381ffc3.chunk.js +0 -86
  128. package/build/i18n-settings-page.6b67cb75.chunk.js +0 -101
  129. package/build/main.b632a0d6.js +0 -11625
  130. package/build/pl-json.94f05d2c.chunk.js +0 -1
  131. package/build/runtime~main.38d418e9.js +0 -2
  132. package/build/sso-settings-page.dfb0b917.chunk.js +0 -1
  133. package/build/upload-settings.3db55de0.chunk.js +0 -101
  134. package/build/upload-translation-pl-json.6071e38c.chunk.js +0 -1
  135. package/build/upload.070c189b.chunk.js +0 -105
  136. package/build/users-advanced-settings-page.a23cda17.chunk.js +0 -101
  137. package/build/users-email-settings-page.0a096388.chunk.js +0 -1
  138. package/build/users-permissions-translation-en-json.3fe86528.chunk.js +0 -1
  139. package/build/users-permissions-translation-pl-json.3c4fe81c.chunk.js +0 -1
  140. package/build/users-providers-settings-page.bfe7755a.chunk.js +0 -1
  141. package/build/vi-json.3d14e91e.chunk.js +0 -1
  142. package/build/webhook-list-page.83297d98.chunk.js +0 -133
  143. package/build/zh-Hans-json.c84ce330.chunk.js +0 -1
  144. package/server/policies/isTelemetryEnabled.js +0 -16
  145. package/utils/create-cache-dir.js +0 -161
  146. package/utils/get-custom-app-config-file.js +0 -23
  147. package/utils/get-custom-webpack-config.js +0 -38
  148. package/utils/get-plugins-path.js +0 -26
  149. package/utils/index.js +0 -13
  150. package/utils/should-build-admin.js +0 -52
  151. package/utils/watch-admin-files.js +0 -59
package/index.js CHANGED
@@ -1,37 +1,66 @@
1
1
  'use strict';
2
2
 
3
3
  const path = require('path');
4
+ const _ = require('lodash');
4
5
  const fs = require('fs-extra');
5
6
  const webpack = require('webpack');
6
7
  const WebpackDevServer = require('webpack-dev-server');
7
- const { isUsingTypeScript } = require('@strapi/typescript-utils');
8
8
  const chalk = require('chalk');
9
+ const chokidar = require('chokidar');
10
+ const getWebpackConfig = require('./webpack.config');
9
11
 
10
- const {
11
- createCacheDir,
12
- getCustomWebpackConfig,
13
- shouldBuildAdmin,
14
- watchAdminFiles,
15
- } = require('./utils');
12
+ const getPkgPath = name => path.dirname(require.resolve(`${name}/package.json`));
16
13
 
17
- async function build({ appDir, buildDestDir, env, forceBuild, optimize, options, plugins }) {
18
- const buildAdmin = await shouldBuildAdmin({ appDir, plugins });
14
+ const DEFAULT_PLUGINS = [
15
+ 'content-type-builder',
16
+ 'content-manager',
17
+ 'upload',
18
+ 'email',
19
+ 'i18n',
20
+ 'users-permissions',
21
+ ];
19
22
 
20
- const useTypeScript = await isUsingTypeScript(
21
- path.join(appDir, 'src', 'admin'),
22
- 'tsconfig.json'
23
- );
23
+ function getCustomWebpackConfig(dir, config) {
24
+ const adminConfigPath = path.join(dir, 'src', 'admin', 'webpack.config.js');
25
+
26
+ let webpackConfig = getWebpackConfig(config);
27
+
28
+ if (fs.existsSync(adminConfigPath)) {
29
+ const webpackAdminConfig = require(path.resolve(adminConfigPath));
30
+
31
+ if (_.isFunction(webpackAdminConfig)) {
32
+ // Expose the devServer configuration
33
+ if (config.devServer) {
34
+ webpackConfig.devServer = config.devServer;
35
+ }
36
+
37
+ webpackConfig = webpackAdminConfig(webpackConfig, webpack);
38
+
39
+ if (!webpackConfig) {
40
+ console.error(
41
+ `${chalk.red('Error:')} Nothing was returned from your custom webpack configuration`
42
+ );
43
+ process.exit(1);
44
+ }
45
+ }
46
+ }
47
+
48
+ return webpackConfig;
49
+ }
50
+
51
+ async function build({ plugins, dir, env, options, optimize, forceBuild }) {
52
+ const buildAdmin = await shouldBuildAdmin({ dir, plugins });
24
53
 
25
54
  if (!buildAdmin && !forceBuild) {
26
55
  return;
27
56
  }
28
57
 
29
58
  // Create the cache dir containing the front-end files.
30
- await createCacheDir({ appDir, plugins });
59
+ await createCacheDir({ dir, plugins });
31
60
 
32
- const cacheDir = path.resolve(appDir, '.cache');
61
+ const cacheDir = path.resolve(dir, '.cache');
33
62
  const entry = path.resolve(cacheDir, 'admin', 'src');
34
- const dest = path.resolve(buildDestDir, 'build');
63
+ const dest = path.resolve(dir, 'build');
35
64
 
36
65
  // Roots for the @strapi/babel-plugin-switch-ee-ce
37
66
  const roots = {
@@ -41,23 +70,15 @@ async function build({ appDir, buildDestDir, env, forceBuild, optimize, options,
41
70
 
42
71
  const pluginsPath = Object.keys(plugins).map(pluginName => plugins[pluginName].pathToPlugin);
43
72
 
44
- // Either use the tsconfig file from the generated app or the one inside the .cache folder
45
- // so we can develop plugins in TS while being in a JS app
46
- const tsConfigFilePath = useTypeScript
47
- ? path.join(appDir, 'src', 'admin', 'tsconfig.json')
48
- : path.resolve(entry, 'tsconfig.json');
49
-
50
- const config = getCustomWebpackConfig(appDir, {
51
- appDir,
73
+ const config = getCustomWebpackConfig(dir, {
74
+ entry,
75
+ pluginsPath,
52
76
  cacheDir,
53
77
  dest,
54
- entry,
55
78
  env,
56
- optimize,
57
79
  options,
58
- pluginsPath,
80
+ optimize,
59
81
  roots,
60
- tsConfigFilePath,
61
82
  });
62
83
 
63
84
  const compiler = webpack(config);
@@ -88,27 +109,115 @@ async function build({ appDir, buildDestDir, env, forceBuild, optimize, options,
88
109
  });
89
110
  }
90
111
 
91
- async function clean({ appDir, buildDestDir }) {
92
- // FIXME rename admin build dir and path to build dir
93
- const buildDir = path.join(buildDestDir, 'build');
94
- // .cache dir is always located at the root of the app
95
- const cacheDir = path.join(appDir, '.cache');
112
+ async function createPluginsJs(plugins, dest) {
113
+ const pluginsArray = plugins.map(({ pathToPlugin, name }) => {
114
+ const shortName = _.camelCase(name);
115
+
116
+ /**
117
+ * path.join, on windows, it uses backslashes to resolve path.
118
+ * The problem is that Webpack does not windows paths
119
+ * With this tool, we need to rely on "/" and not "\".
120
+ * This is the reason why '..\\..\\..\\node_modules\\@strapi\\plugin-content-type-builder/strapi-admin.js' was not working.
121
+ * The regexp at line 105 aims to replace the windows backslashes by standard slash so that webpack can deal with them.
122
+ * Backslash looks to work only for absolute paths with webpack => https://webpack.js.org/concepts/module-resolution/#absolute-paths
123
+ */
124
+ const realPath = path
125
+ .join(path.relative(path.resolve(dest, 'admin', 'src'), pathToPlugin), 'strapi-admin.js')
126
+ .replace(/\\/g, '/');
127
+
128
+ return {
129
+ name,
130
+ pathToPlugin: realPath,
131
+ shortName,
132
+ };
133
+ });
134
+
135
+ const content = `
136
+ ${pluginsArray
137
+ .map(({ pathToPlugin, shortName }) => {
138
+ const req = `'${pathToPlugin}'`;
139
+
140
+ return `import ${shortName} from ${req};`;
141
+ })
142
+ .join('\n')}
143
+
144
+
145
+ const plugins = {
146
+ ${[...pluginsArray]
147
+ .map(({ name, shortName }) => {
148
+ return ` '${name}': ${shortName},`;
149
+ })
150
+ .join('\n')}
151
+ };
152
+
153
+ export default plugins;
154
+ `;
155
+
156
+ return fs.writeFile(path.resolve(dest, 'admin', 'src', 'plugins.js'), content);
157
+ }
158
+
159
+ async function clean({ dir }) {
160
+ const buildDir = path.join(dir, 'build');
161
+ const cacheDir = path.join(dir, '.cache');
96
162
 
97
163
  fs.removeSync(buildDir);
98
164
  fs.removeSync(cacheDir);
99
165
  }
100
166
 
101
- async function watchAdmin({ appDir, browser, buildDestDir, host, options, plugins, port }) {
102
- const useTypeScript = await isUsingTypeScript(
103
- path.join(appDir, 'src', 'admin'),
104
- 'tsconfig.json'
105
- );
167
+ async function copyAdmin(dest) {
168
+ const adminPath = getPkgPath('@strapi/admin');
169
+
170
+ // TODO copy ee folders for plugins
171
+ await fs.copy(path.resolve(adminPath, 'ee', 'admin'), path.resolve(dest, 'ee', 'admin'));
172
+
173
+ await fs.ensureDir(path.resolve(dest, 'config'));
174
+ await fs.copy(path.resolve(adminPath, 'admin'), path.resolve(dest, 'admin'));
175
+
176
+ // Copy package.json
177
+ await fs.copy(path.resolve(adminPath, 'package.json'), path.resolve(dest, 'package.json'));
178
+ }
179
+
180
+ async function createCacheDir({ dir, plugins }) {
181
+ const cacheDir = path.resolve(dir, '.cache');
182
+
183
+ const pluginsWithFront = Object.keys(plugins)
184
+ .filter(pluginName => {
185
+ const pluginInfo = plugins[pluginName];
186
+ return fs.existsSync(path.resolve(pluginInfo.pathToPlugin, 'strapi-admin.js'));
187
+ })
188
+ .map(name => ({ name, ...plugins[name] }));
189
+
190
+ // create .cache dir
191
+ await fs.emptyDir(cacheDir);
192
+
193
+ // copy admin core code
194
+ await copyAdmin(cacheDir);
195
+
196
+ // Copy app.js
197
+ const customAdminConfigFilePath = path.join(dir, 'src', 'admin', 'app.js');
198
+
199
+ if (fs.existsSync(customAdminConfigFilePath)) {
200
+ await fs.copy(customAdminConfigFilePath, path.resolve(cacheDir, 'admin', 'src', 'app.js'));
201
+ }
202
+
203
+ // Copy admin extensions folder
204
+ const adminExtensionFolder = path.join(dir, 'src', 'admin', 'extensions');
205
+
206
+ if (fs.existsSync(adminExtensionFolder)) {
207
+ await fs.copy(adminExtensionFolder, path.resolve(cacheDir, 'admin', 'src', 'extensions'));
208
+ }
209
+
210
+ // create plugins.js with plugins requires
211
+ await createPluginsJs(pluginsWithFront, cacheDir);
212
+ }
213
+
214
+ async function watchAdmin({ plugins, dir, host, port, browser, options }) {
106
215
  // Create the cache dir containing the front-end files.
107
- const cacheDir = path.join(appDir, '.cache');
108
- await createCacheDir({ appDir, plugins });
216
+ const cacheDir = path.join(dir, '.cache');
217
+ await createCacheDir({ dir, plugins });
109
218
 
110
219
  const entry = path.join(cacheDir, 'admin', 'src');
111
- const dest = path.join(buildDestDir, 'build');
220
+ const dest = path.join(dir, 'build');
112
221
  const env = 'development';
113
222
 
114
223
  // Roots for the @strapi/babel-plugin-switch-ee-ce
@@ -119,20 +228,14 @@ async function watchAdmin({ appDir, browser, buildDestDir, host, options, plugin
119
228
 
120
229
  const pluginsPath = Object.keys(plugins).map(pluginName => plugins[pluginName].pathToPlugin);
121
230
 
122
- // Either use the tsconfig file from the generated app or the one inside the .cache folder
123
- // so we can develop plugins in TS while being in a JS app
124
- const tsConfigFilePath = useTypeScript
125
- ? path.join(appDir, 'src', 'admin', 'tsconfig.json')
126
- : path.resolve(entry, 'tsconfig.json');
127
-
128
231
  const args = {
129
- appDir,
232
+ entry,
130
233
  cacheDir,
234
+ pluginsPath,
131
235
  dest,
132
- entry,
133
236
  env,
237
+ port,
134
238
  options,
135
- pluginsPath,
136
239
  roots,
137
240
  devServer: {
138
241
  port,
@@ -143,6 +246,7 @@ async function watchAdmin({ appDir, browser, buildDestDir, host, options, plugin
143
246
  warnings: false,
144
247
  },
145
248
  },
249
+
146
250
  open: browser === 'true' ? true : browser,
147
251
  devMiddleware: {
148
252
  publicPath: options.adminPath,
@@ -152,10 +256,9 @@ async function watchAdmin({ appDir, browser, buildDestDir, host, options, plugin
152
256
  disableDotRule: true,
153
257
  },
154
258
  },
155
- tsConfigFilePath,
156
259
  };
157
260
 
158
- const webpackConfig = getCustomWebpackConfig(appDir, args);
261
+ const webpackConfig = getCustomWebpackConfig(dir, args);
159
262
 
160
263
  const compiler = webpack(webpackConfig);
161
264
 
@@ -176,7 +279,90 @@ async function watchAdmin({ appDir, browser, buildDestDir, host, options, plugin
176
279
 
177
280
  runServer();
178
281
 
179
- watchAdminFiles(appDir, useTypeScript);
282
+ watchFiles(dir);
283
+ }
284
+
285
+ /**
286
+ * Listen to files change and copy the changed files in the .cache/admin folder
287
+ * when using the dev mode
288
+ * @param {string} dir
289
+ */
290
+ async function watchFiles(dir) {
291
+ const cacheDir = path.join(dir, '.cache');
292
+ const appExtensionFile = path.join(dir, 'src', 'admin', 'app.js');
293
+ const extensionsPath = path.join(dir, 'src', 'admin', 'extensions');
294
+
295
+ // Only watch the admin/app.js file and the files that are in the ./admin/extensions/folder
296
+ const filesToWatch = [appExtensionFile, extensionsPath];
297
+
298
+ const watcher = chokidar.watch(filesToWatch, {
299
+ ignoreInitial: true,
300
+ ignorePermissionErrors: true,
301
+ });
302
+
303
+ watcher.on('all', async (event, filePath) => {
304
+ const isAppFile = filePath.includes(appExtensionFile);
305
+
306
+ // The app.js file needs to be copied in the .cache/admin/src/app.js and the other ones needs to
307
+ // be copied in the .cache/admin/src/extensions folder
308
+ const targetPath = isAppFile
309
+ ? path.join(path.normalize(filePath.split(appExtensionFile)[1]), 'app.js')
310
+ : path.join('extensions', path.normalize(filePath.split(extensionsPath)[1]));
311
+
312
+ const destFolder = path.join(cacheDir, 'admin', 'src');
313
+
314
+ if (event === 'unlink' || event === 'unlinkDir') {
315
+ // Remove the file or folder
316
+ // We need to copy the original files when deleting an override one
317
+ try {
318
+ fs.removeSync(path.join(destFolder, targetPath));
319
+ } catch (err) {
320
+ console.log('An error occured while deleting the file', err);
321
+ }
322
+ } else {
323
+ // In any other case just copy the file into the .cache/admin/src folder
324
+ try {
325
+ await fs.copy(filePath, path.join(destFolder, targetPath));
326
+ } catch (err) {
327
+ console.log(err);
328
+ }
329
+ }
330
+ });
331
+ }
332
+
333
+ const hasCustomAdminCode = async dir => {
334
+ const customAdminPath = path.join(dir, 'src', 'admin');
335
+ const customAdminConfigFile = path.join(customAdminPath, 'app.js');
336
+ const customAdminWebpackFile = path.join(customAdminPath, 'webpack.config.js');
337
+
338
+ const hasCustomConfigFile = await fs.pathExists(customAdminConfigFile);
339
+ const hasCustomWebpackFile = await fs.pathExists(customAdminWebpackFile);
340
+
341
+ return hasCustomConfigFile || hasCustomWebpackFile;
342
+ };
343
+
344
+ /**
345
+ * Checks if the project's installed plugins are not the same as a default one.
346
+ * @param {Object} plugins
347
+ * @returns {boolean}
348
+ */
349
+ const hasNonDefaultPlugins = plugins => {
350
+ // List of plugins that are not the ones installed in a generated app
351
+ const installedPlugins = Object.keys(plugins).filter(x => !DEFAULT_PLUGINS.includes(x));
352
+
353
+ // List of default plugins uninstalled from a generated app
354
+ const missingPlugins = DEFAULT_PLUGINS.filter(x => !Object.keys(plugins).includes(x));
355
+
356
+ const diff = [...installedPlugins, ...missingPlugins];
357
+
358
+ return diff.length > 0;
359
+ };
360
+
361
+ async function shouldBuildAdmin({ dir, plugins }) {
362
+ const appHasCustomAdminCode = await hasCustomAdminCode(dir);
363
+ const appHasNonDefaultPlugins = hasNonDefaultPlugins(plugins);
364
+
365
+ return appHasCustomAdminCode || appHasNonDefaultPlugins;
180
366
  }
181
367
 
182
368
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/admin",
3
- "version": "4.2.0-beta.4",
3
+ "version": "4.2.2",
4
4
  "description": "Strapi Admin",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,7 +28,6 @@
28
28
  "develop:webpack": "cross-env NODE_ENV=development webpack serve --config webpack.config.dev.js --progress profile",
29
29
  "prepublishOnly": "yarn build",
30
30
  "build": "rimraf build && node ./scripts/build.js",
31
- "build:mesure": "rimraf build && cross-env MESURE_BUILD_SPEED=true node ./scripts/build.js",
32
31
  "test": "echo \"no tests yet\"",
33
32
  "test:unit": "jest --verbose",
34
33
  "test:front": "cross-env IS_EE=true jest --config ./jest.config.front.js",
@@ -50,12 +49,12 @@
50
49
  "@fortawesome/free-brands-svg-icons": "^5.15.3",
51
50
  "@fortawesome/free-solid-svg-icons": "^5.15.3",
52
51
  "@fortawesome/react-fontawesome": "^0.1.14",
53
- "@strapi/babel-plugin-switch-ee-ce": "4.2.0-beta.4",
54
- "@strapi/design-system": "1.1.0",
55
- "@strapi/helper-plugin": "4.2.0-beta.4",
56
- "@strapi/icons": "1.1.0",
57
- "@strapi/typescript-utils": "4.2.0-beta.4",
58
- "@strapi/utils": "4.2.0-beta.4",
52
+ "@pmmmwh/react-refresh-webpack-plugin": "0.5.4",
53
+ "@strapi/babel-plugin-switch-ee-ce": "4.2.2",
54
+ "@strapi/design-system": "1.2.0",
55
+ "@strapi/helper-plugin": "4.2.2",
56
+ "@strapi/icons": "1.2.0",
57
+ "@strapi/utils": "4.2.2",
59
58
  "axios": "0.24.0",
60
59
  "babel-loader": "8.2.3",
61
60
  "babel-plugin-styled-components": "2.0.2",
@@ -71,7 +70,6 @@
71
70
  "execa": "^1.0.0",
72
71
  "fast-deep-equal": "3.1.3",
73
72
  "font-awesome": "^4.7.0",
74
- "fork-ts-checker-webpack-plugin": "7.2.1",
75
73
  "formik": "^2.2.6",
76
74
  "fs-extra": "10.0.0",
77
75
  "highlight.js": "^10.4.1",
@@ -116,6 +114,7 @@
116
114
  "react-intl": "5.20.2",
117
115
  "react-query": "3.24.3",
118
116
  "react-redux": "7.2.3",
117
+ "react-refresh": "0.11.0",
119
118
  "react-router": "5.2.0",
120
119
  "react-router-dom": "5.2.0",
121
120
  "react-select": "^4.0.2",
@@ -137,12 +136,11 @@
137
136
  },
138
137
  "devDependencies": {
139
138
  "duplicate-dependencies-webpack-plugin": "0.2.0",
140
- "speed-measure-webpack-plugin": "1.5.0",
141
139
  "webpack-bundle-analyzer": "4.4.1"
142
140
  },
143
141
  "engines": {
144
142
  "node": ">=14.19.1 <=16.x.x",
145
143
  "npm": ">=6.0.0"
146
144
  },
147
- "gitHead": "5caff35a30e33b7a660eb946299f9e3d2d35b2b8"
145
+ "gitHead": "376ff3133c13f6eb10d0c90f4b5eb701592aff97"
148
146
  }
package/scripts/build.js CHANGED
@@ -3,11 +3,7 @@
3
3
  const path = require('path');
4
4
  const webpack = require('webpack');
5
5
  const { isObject } = require('lodash');
6
- // eslint-disable-next-line node/no-extraneous-require
7
- const SpeedMeasurePlugin = require('speed-measure-webpack-plugin');
8
-
9
6
  const webpackConfig = require('../webpack.config');
10
- const getPluginsPath = require('../utils/get-plugins-path');
11
7
  const {
12
8
  getCorePluginsPath,
13
9
  getPluginToInstallPath,
@@ -16,39 +12,29 @@ const {
16
12
 
17
13
  const PLUGINS_TO_INSTALL = ['i18n', 'users-permissions'];
18
14
 
19
- // Wrapper that outputs the webpack speed
20
- const smp = new SpeedMeasurePlugin();
21
-
22
15
  const buildAdmin = async () => {
23
16
  const entry = path.join(__dirname, '..', 'admin', 'src');
24
17
  const dest = path.join(__dirname, '..', 'build');
25
- const tsConfigFilePath = path.join(__dirname, '..', 'admin', 'src', 'tsconfig.json');
26
-
27
18
  const corePlugins = getCorePluginsPath();
28
19
  const plugins = getPluginToInstallPath(PLUGINS_TO_INSTALL);
29
20
  const allPlugins = { ...corePlugins, ...plugins };
30
- const pluginsPath = getPluginsPath();
31
21
 
32
22
  await createPluginsFile(allPlugins);
33
23
 
34
24
  const args = {
35
25
  entry,
36
26
  dest,
37
- cacheDir: path.join(__dirname, '..'),
38
- pluginsPath,
27
+ cacheDir: path.resolve(__dirname, '..'),
28
+ pluginsPath: [path.resolve(__dirname, '../../../../packages')],
39
29
  env: 'production',
40
30
  optimize: true,
41
31
  options: {
42
32
  backend: 'http://localhost:1337',
43
33
  adminPath: '/admin/',
44
34
  },
45
- tsConfigFilePath,
46
35
  };
47
36
 
48
- const config =
49
- process.env.MESURE_BUILD_SPEED === 'true' ? smp.wrap(webpackConfig(args)) : webpackConfig(args);
50
-
51
- const compiler = webpack(config);
37
+ const compiler = webpack(webpackConfig(args));
52
38
 
53
39
  console.log('Building the admin panel');
54
40
 
@@ -5,7 +5,6 @@ const execa = require('execa');
5
5
  const _ = require('lodash');
6
6
  const { exists } = require('fs-extra');
7
7
  const { ValidationError } = require('@strapi/utils').errors;
8
- const { isUsingTypeScript } = require('@strapi/typescript-utils');
9
8
  // eslint-disable-next-line node/no-extraneous-require
10
9
  const ee = require('@strapi/strapi/lib/utils/ee');
11
10
 
@@ -82,24 +81,11 @@ module.exports = {
82
81
  return projectSettingsService.updateProjectSettings({ ...body, ...formatedFiles });
83
82
  },
84
83
 
85
- async telemetryProperties() {
86
- const useTypescriptOnServer = await isUsingTypeScript(strapi.dirs.app.root);
87
- const useTypescriptOnAdmin = await isUsingTypeScript(
88
- path.join(strapi.dirs.app.root, 'src', 'admin')
89
- );
90
-
91
- return {
92
- data: {
93
- useTypescriptOnServer,
94
- useTypescriptOnAdmin,
95
- },
96
- };
97
- },
98
-
99
84
  async information() {
100
85
  const currentEnvironment = strapi.config.get('environment');
101
86
  const autoReload = strapi.config.get('autoReload', false);
102
87
  const strapiVersion = strapi.config.get('info.strapi', null);
88
+ const dependencies = strapi.config.get('info.dependencies', {});
103
89
  const nodeVersion = process.version;
104
90
  const communityEdition = !strapi.EE;
105
91
  const useYarn = await exists(path.join(process.cwd(), 'yarn.lock'));
@@ -109,6 +95,7 @@ module.exports = {
109
95
  currentEnvironment,
110
96
  autoReload,
111
97
  strapiVersion,
98
+ dependencies,
112
99
  nodeVersion,
113
100
  communityEdition,
114
101
  useYarn,
@@ -3,5 +3,4 @@
3
3
  module.exports = {
4
4
  isAuthenticatedAdmin: require('./isAuthenticatedAdmin'),
5
5
  hasPermissions: require('./hasPermissions'),
6
- isTelemetryEnabled: require('./isTelemetryEnabled'),
7
6
  };
@@ -49,15 +49,6 @@ module.exports = [
49
49
  policies: ['admin::isAuthenticatedAdmin'],
50
50
  },
51
51
  },
52
- {
53
- method: 'GET',
54
- path: '/telemetry-properties',
55
- handler: 'admin.telemetryProperties',
56
- config: {
57
- auth: false,
58
- policies: ['admin::isTelemetryEnabled'],
59
- },
60
- },
61
52
  {
62
53
  method: 'GET',
63
54
  path: '/plugins',
@@ -5,7 +5,7 @@ const fse = require('fs-extra');
5
5
  const koaStatic = require('koa-static');
6
6
 
7
7
  const registerAdminPanelRoute = ({ strapi }) => {
8
- let buildDir = resolve(strapi.dirs.dist.root, 'build');
8
+ let buildDir = resolve(strapi.dirs.root, 'build');
9
9
 
10
10
  if (!fse.pathExistsSync(buildDir)) {
11
11
  buildDir = resolve(__dirname, '../../build');
package/webpack.alias.js CHANGED
@@ -2,18 +2,19 @@
2
2
 
3
3
  const path = require('path');
4
4
 
5
- const alias = [
6
- 'object-assign',
7
- 'whatwg-fetch',
5
+ const aliasExactMatch = [
6
+ '@strapi/design-system',
7
+ '@strapi/helper-plugin',
8
+ '@strapi/icons',
8
9
  '@fortawesome/fontawesome-svg-core',
9
10
  '@fortawesome/free-solid-svg-icons',
11
+ 'date-fns',
12
+ 'formik',
10
13
  'history',
11
- 'hoist-non-react-statics',
12
14
  'immer',
13
- 'invariant',
15
+ 'qs',
14
16
  'lodash',
15
17
  'moment',
16
- 'qs',
17
18
  'react',
18
19
  'react-copy-to-clipboard',
19
20
  'react-dnd',
@@ -24,6 +25,7 @@ const alias = [
24
25
  'react-helmet',
25
26
  'react-is',
26
27
  'react-intl',
28
+ 'react-query',
27
29
  'react-redux',
28
30
  'react-router',
29
31
  'react-router-dom',
@@ -32,20 +34,29 @@ const alias = [
32
34
  'redux',
33
35
  'reselect',
34
36
  'styled-components',
37
+ 'whatwg-fetch',
35
38
  'yup',
36
39
  ];
37
40
 
38
- module.exports = alias.reduce(
39
- (acc, curr) => {
40
- acc[`${curr}$`] = require.resolve(curr);
41
+ const alias = [
42
+ 'react-select/animated',
43
+ 'react-select/async',
44
+ 'react-select/async-creatable',
45
+ 'react-select/base',
46
+ 'react-select/creatable',
47
+ ];
48
+
49
+ // See https://webpack.js.org/configuration/resolve/
50
+ module.exports = {
51
+ ...alias.reduce((acc, name) => {
52
+ acc[name] = require.resolve(name);
41
53
  return acc;
42
- },
43
- {
44
- 'react-select/animated': require.resolve('react-select/animated'),
45
- 'react-select/async': require.resolve('react-select/async'),
46
- 'react-select/async-creatable': require.resolve('react-select/async-creatable'),
47
- 'react-select/base': require.resolve('react-select/base'),
48
- 'react-select/creatable': require.resolve('react-select/creatable'),
49
- ee_else_ce: path.resolve(__dirname),
50
- }
51
- );
54
+ }, {}),
55
+
56
+ ...aliasExactMatch.reduce((acc, name) => {
57
+ acc[`${name}$`] = require.resolve(name);
58
+ return acc;
59
+ }, {}),
60
+
61
+ ee_else_ce: path.resolve(__dirname),
62
+ };