@strapi/strapi 4.2.0-alpha.O → 4.2.0-beta.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 (45) hide show
  1. package/README.md +2 -3
  2. package/bin/strapi.js +18 -1
  3. package/lib/Strapi.js +38 -4
  4. package/lib/commands/admin-create.js +122 -0
  5. package/lib/commands/admin-reset.js +8 -1
  6. package/lib/commands/build.js +18 -44
  7. package/lib/commands/builders/admin.js +59 -0
  8. package/lib/commands/builders/index.js +9 -0
  9. package/lib/commands/builders/typescript.js +32 -0
  10. package/lib/commands/configurationDump.js +8 -1
  11. package/lib/commands/configurationRestore.js +9 -1
  12. package/lib/commands/console.js +10 -2
  13. package/lib/commands/develop.js +113 -71
  14. package/lib/commands/opt-out-telemetry.js +83 -0
  15. package/lib/commands/routes/list.js +8 -1
  16. package/lib/commands/start.js +8 -2
  17. package/lib/commands/watchAdmin.js +10 -10
  18. package/lib/core/app-configuration/index.js +5 -3
  19. package/lib/core/app-configuration/load-config-file.js +3 -1
  20. package/lib/core/bootstrap.js +9 -1
  21. package/lib/core/loaders/apis.js +6 -5
  22. package/lib/core/loaders/components.js +5 -4
  23. package/lib/core/loaders/middlewares.js +5 -3
  24. package/lib/core/loaders/plugins/get-enabled-plugins.js +6 -2
  25. package/lib/core/loaders/plugins/get-user-plugins-config.js +2 -2
  26. package/lib/core/loaders/plugins/index.js +1 -1
  27. package/lib/core/loaders/policies.js +4 -2
  28. package/lib/core/loaders/src-index.js +6 -4
  29. package/lib/factories.d.ts +3 -3
  30. package/lib/index.d.ts +1 -1
  31. package/lib/load/load-files.js +3 -1
  32. package/lib/middlewares/favicon.js +1 -1
  33. package/lib/middlewares/public/index.js +2 -1
  34. package/lib/middlewares/security.js +1 -1
  35. package/lib/middlewares/session.js +3 -1
  36. package/lib/services/fs.js +1 -1
  37. package/lib/services/metrics/index.js +8 -2
  38. package/lib/services/metrics/sender.js +7 -0
  39. package/lib/services/server/index.js +1 -1
  40. package/lib/services/server/middleware.js +1 -1
  41. package/lib/utils/get-dirs.js +25 -11
  42. package/lib/utils/import-default.js +9 -0
  43. package/lib/utils/index.js +2 -0
  44. package/lib/utils/update-notifier/index.js +1 -1
  45. package/package.json +15 -13
@@ -6,114 +6,150 @@ const fs = require('fs-extra');
6
6
  const chokidar = require('chokidar');
7
7
  const execa = require('execa');
8
8
  const { getOr } = require('lodash/fp');
9
+ const { joinBy } = require('@strapi/utils');
10
+ const tsUtils = require('@strapi/typescript-utils');
9
11
 
10
- const { createLogger } = require('@strapi/logger');
11
12
  const loadConfiguration = require('../core/app-configuration');
12
13
  const strapi = require('../index');
13
- const buildAdmin = require('./build');
14
+ const { buildTypeScript, buildAdmin } = require('./builders');
14
15
 
15
16
  /**
16
17
  * `$ strapi develop`
17
18
  *
18
19
  */
20
+
19
21
  module.exports = async function({ build, watchAdmin, polling, browser }) {
20
- const dir = process.cwd();
21
- const config = loadConfiguration(dir);
22
- const logger = createLogger(config.logger, {});
22
+ const appDir = process.cwd();
23
+
24
+ const isTSProject = await tsUtils.isUsingTypeScript(appDir);
25
+ const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
23
26
 
24
27
  try {
25
28
  if (cluster.isMaster || cluster.isPrimary) {
26
- const serveAdminPanel = getOr(true, 'admin.serveAdminPanel')(config);
27
-
28
- const buildExists = fs.existsSync(path.join(dir, 'build'));
29
- // Don't run the build process if the admin is in watch mode
30
- if (build && !watchAdmin && serveAdminPanel && !buildExists) {
31
- try {
32
- await buildAdmin({ optimization: false, forceBuild: false });
33
- } catch (err) {
34
- process.exit(1);
35
- }
36
- }
37
-
38
- if (watchAdmin) {
39
- try {
40
- execa('npm', ['run', '-s', 'strapi', 'watch-admin', '--', '--browser', browser], {
41
- stdio: 'inherit',
42
- });
43
- } catch (err) {
44
- process.exit(1);
45
- }
46
- }
47
-
48
- cluster.on('message', (worker, message) => {
49
- switch (message) {
50
- case 'reload':
51
- logger.info('The server is restarting\n');
52
- worker.send('kill');
53
- break;
54
- case 'killed':
55
- cluster.fork();
56
- break;
57
- case 'stop':
58
- process.exit(1);
59
- default:
60
- return;
61
- }
29
+ return primaryProcess({
30
+ distDir,
31
+ appDir,
32
+ build,
33
+ browser,
34
+ isTSProject,
35
+ watchAdmin,
62
36
  });
63
-
64
- cluster.fork();
65
37
  }
66
38
 
67
39
  if (cluster.isWorker) {
68
- const strapiInstance = strapi({
69
- dir,
70
- autoReload: true,
71
- serveAdminPanel: watchAdmin ? false : true,
40
+ return workerProcess({ appDir, distDir, watchAdmin, polling, isTSProject });
41
+ }
42
+ } catch (e) {
43
+ console.error(e);
44
+ process.exit(1);
45
+ }
46
+ };
47
+
48
+ const primaryProcess = async ({ distDir, appDir, build, isTSProject, watchAdmin, browser }) => {
49
+ if (isTSProject) {
50
+ await buildTypeScript({ srcDir: appDir, distDir, watch: false });
51
+ }
52
+
53
+ const config = loadConfiguration({ appDir, distDir });
54
+ const serveAdminPanel = getOr(true, 'admin.serveAdminPanel')(config);
55
+
56
+ const buildExists = fs.existsSync(path.join(distDir, 'build'));
57
+
58
+ // Don't run the build process if the admin is in watch mode
59
+ if (build && !watchAdmin && serveAdminPanel && !buildExists) {
60
+ try {
61
+ await buildAdmin({
62
+ buildDestDir: distDir,
63
+ forceBuild: false,
64
+ optimization: false,
65
+ srcDir: appDir,
72
66
  });
67
+ } catch (err) {
68
+ process.exit(1);
69
+ }
70
+ }
73
71
 
74
- const adminWatchIgnoreFiles = getOr([], 'admin.watchIgnoreFiles')(config);
75
- watchFileChanges({
76
- dir,
77
- strapiInstance,
78
- watchIgnoreFiles: adminWatchIgnoreFiles,
79
- polling,
72
+ if (watchAdmin) {
73
+ try {
74
+ execa('npm', ['run', '-s', 'strapi', 'watch-admin', '--', '--browser', browser], {
75
+ stdio: 'inherit',
80
76
  });
77
+ } catch (err) {
78
+ process.exit(1);
79
+ }
80
+ }
81
81
 
82
- process.on('message', async message => {
83
- switch (message) {
84
- case 'kill':
85
- await strapiInstance.destroy();
86
- process.send('killed');
87
- process.exit();
88
- default:
89
- // Do nothing.
82
+ cluster.on('message', async (worker, message) => {
83
+ switch (message) {
84
+ case 'reload':
85
+ if (isTSProject) {
86
+ await buildTypeScript({ srcDir: appDir, distDir, watch: false });
90
87
  }
91
- });
92
88
 
93
- return strapiInstance.start();
89
+ console.info('The server is restarting\n');
90
+
91
+ worker.send('kill');
92
+ break;
93
+ case 'killed':
94
+ cluster.fork();
95
+ break;
96
+ case 'stop':
97
+ process.exit(1);
98
+ default:
99
+ return;
94
100
  }
95
- } catch (e) {
96
- logger.error(e);
97
- process.exit(1);
98
- }
101
+ });
102
+
103
+ cluster.fork();
104
+ };
105
+
106
+ const workerProcess = ({ appDir, distDir, watchAdmin, polling, isTSProject }) => {
107
+ const strapiInstance = strapi({
108
+ distDir,
109
+ autoReload: true,
110
+ serveAdminPanel: watchAdmin ? false : true,
111
+ });
112
+
113
+ const adminWatchIgnoreFiles = strapiInstance.config.get('admin.watchIgnoreFiles', []);
114
+ watchFileChanges({
115
+ appDir,
116
+ strapiInstance,
117
+ watchIgnoreFiles: adminWatchIgnoreFiles,
118
+ polling,
119
+ isTSProject,
120
+ });
121
+
122
+ process.on('message', async message => {
123
+ switch (message) {
124
+ case 'kill':
125
+ await strapiInstance.destroy();
126
+ process.send('killed');
127
+ process.exit();
128
+ default:
129
+ // Do nothing.
130
+ }
131
+ });
132
+
133
+ return strapiInstance.start();
99
134
  };
100
135
 
101
136
  /**
102
137
  * Init file watching to auto restart strapi app
103
138
  * @param {Object} options - Options object
104
- * @param {string} options.dir - This is the path where the app is located, the watcher will watch the files under this folder
139
+ * @param {string} options.appDir - This is the path where the app is located, the watcher will watch the files under this folder
105
140
  * @param {Strapi} options.strapi - Strapi instance
106
141
  * @param {array} options.watchIgnoreFiles - Array of custom file paths that should not be watched
107
142
  */
108
- function watchFileChanges({ dir, strapiInstance, watchIgnoreFiles, polling }) {
109
- const restart = () => {
143
+ function watchFileChanges({ appDir, strapiInstance, watchIgnoreFiles, polling }) {
144
+ const restart = async () => {
110
145
  if (strapiInstance.reload.isWatching && !strapiInstance.reload.isReloading) {
111
146
  strapiInstance.reload.isReloading = true;
112
147
  strapiInstance.reload();
113
148
  }
114
149
  };
115
150
 
116
- const watcher = chokidar.watch(dir, {
151
+ // @soupette should we keep watching the dist dir (for the watch admin?)
152
+ const watcher = chokidar.watch(appDir, {
117
153
  ignoreInitial: true,
118
154
  usePolling: polling,
119
155
  ignored: [
@@ -121,6 +157,9 @@ function watchFileChanges({ dir, strapiInstance, watchIgnoreFiles, polling }) {
121
157
  /tmp/,
122
158
  '**/src/admin/**',
123
159
  '**/src/plugins/**/admin/**',
160
+ // FIXME pass the plugin path to the strapiAdmin.build and strapiAdmin.watch in order to stop copying
161
+ // the FE files when using TS
162
+ '**/dist/src/plugins/test/admin/**',
124
163
  '**/documentation',
125
164
  '**/documentation/**',
126
165
  '**/node_modules',
@@ -131,8 +170,11 @@ function watchFileChanges({ dir, strapiInstance, watchIgnoreFiles, polling }) {
131
170
  '**/index.html',
132
171
  '**/public',
133
172
  '**/public/**',
173
+ strapiInstance.dirs.static.public,
174
+ joinBy('/', strapiInstance.dirs.static.public, '**'),
134
175
  '**/*.db*',
135
176
  '**/exports/**',
177
+ '**/dist/**',
136
178
  ...watchIgnoreFiles,
137
179
  ],
138
180
  });
@@ -0,0 +1,83 @@
1
+ 'use strict';
2
+
3
+ const { resolve } = require('path');
4
+ const fse = require('fs-extra');
5
+ const chalk = require('chalk');
6
+ const fetch = require('node-fetch');
7
+ const machineID = require('../utils/machine-id');
8
+
9
+ const readPackageJSON = async path => {
10
+ try {
11
+ const packageObj = await fse.readJson(path);
12
+ const uuid = packageObj.strapi ? packageObj.strapi.uuid : null;
13
+
14
+ return { uuid, packageObj };
15
+ } catch (err) {
16
+ console.error(`${chalk.red('Error')}: ${err.message}`);
17
+ }
18
+ };
19
+
20
+ const writePackageJSON = async (path, file, spacing) => {
21
+ try {
22
+ await fse.writeJson(path, file, { spaces: spacing });
23
+ return true;
24
+ } catch (err) {
25
+ console.error(`${chalk.red('Error')}: ${err.message}`);
26
+ }
27
+ };
28
+
29
+ const sendEvent = async uuid => {
30
+ try {
31
+ await fetch('https://analytics.strapi.io/track', {
32
+ method: 'POST',
33
+ body: JSON.stringify({
34
+ event: 'didOptOutTelemetry',
35
+ uuid,
36
+ deviceId: machineID(),
37
+ }),
38
+ headers: { 'Content-Type': 'application/json' },
39
+ });
40
+ } catch (e) {
41
+ //...
42
+ }
43
+ };
44
+
45
+ module.exports = async function optOutTelemetry() {
46
+ const packageJSONPath = resolve(process.cwd(), 'package.json');
47
+ const exists = await fse.pathExists(packageJSONPath);
48
+
49
+ if (!exists) {
50
+ console.log(`${chalk.yellow('Warning')}: could not find package.json`);
51
+ process.exit(0);
52
+ }
53
+
54
+ const { uuid, packageObj } = await readPackageJSON(packageJSONPath);
55
+
56
+ if ((packageObj.strapi && packageObj.strapi.telemetryDisabled) || !uuid) {
57
+ console.log(`${chalk.yellow('Warning:')} telemetry is already disabled`);
58
+ process.exit(0);
59
+ }
60
+
61
+ const updatedPackageJSON = {
62
+ ...packageObj,
63
+ strapi: {
64
+ ...packageObj.strapi,
65
+ telemetryDisabled: true,
66
+ },
67
+ };
68
+
69
+ const write = await writePackageJSON(packageJSONPath, updatedPackageJSON, 2);
70
+
71
+ if (!write) {
72
+ console.log(
73
+ `${chalk.yellow(
74
+ 'Warning'
75
+ )}: There has been an error, please set "telemetryDisabled": true in the "strapi" object of your package.json manually.`
76
+ );
77
+ process.exit(0);
78
+ }
79
+
80
+ await sendEvent(uuid);
81
+ console.log(`${chalk.green('Successfully opted out of Strapi telemetry')}`);
82
+ process.exit(0);
83
+ };
@@ -1,13 +1,20 @@
1
1
  'use strict';
2
2
 
3
+ const path = require('path');
3
4
  const CLITable = require('cli-table3');
4
5
  const chalk = require('chalk');
5
6
  const { toUpper } = require('lodash/fp');
7
+ const tsUtils = require('@strapi/typescript-utils');
6
8
 
7
9
  const strapi = require('../../index');
8
10
 
9
11
  module.exports = async function() {
10
- const app = await strapi().load();
12
+ const appDir = process.cwd();
13
+
14
+ const isTSProject = await tsUtils.isUsingTypeScript(appDir);
15
+ const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
16
+
17
+ const app = await strapi({ appDir, distDir }).load();
11
18
 
12
19
  const list = app.server.listRoutes();
13
20
 
@@ -1,8 +1,14 @@
1
1
  'use strict';
2
-
2
+ const tsUtils = require('@strapi/typescript-utils')
3
3
  const strapi = require('../index');
4
4
 
5
5
  /**
6
6
  * `$ strapi start`
7
7
  */
8
- module.exports = () => strapi().start();
8
+ module.exports = async specifiedDir => {
9
+ const appDir = process.cwd();
10
+ const isTSProject = await tsUtils.isUsingTypeScript(appDir)
11
+ const distDir = isTSProject && !specifiedDir ? 'dist' : specifiedDir;
12
+
13
+ strapi({ distDir }).start()
14
+ };
@@ -1,18 +1,22 @@
1
1
  'use strict';
2
2
 
3
+ const path = require('path');
3
4
  const strapiAdmin = require('@strapi/admin');
5
+ const tsUtils = require('@strapi/typescript-utils');
4
6
  const { getConfigUrls, getAbsoluteServerUrl } = require('@strapi/utils');
5
7
 
6
- const ee = require('../utils/ee');
8
+ const getEnabledPlugins = require('../core/loaders/plugins/get-enabled-plugins');
7
9
  const addSlash = require('../utils/addSlash');
8
10
  const strapi = require('../index');
9
- const getEnabledPlugins = require('../core/loaders/plugins/get-enabled-plugins');
10
11
 
11
12
  module.exports = async function({ browser }) {
12
- const dir = process.cwd();
13
+ const currentDirectory = process.cwd();
14
+
15
+ const isTSProject = await tsUtils.isUsingTypeScript(currentDirectory);
16
+ const buildDestDir = isTSProject ? path.join(currentDirectory, 'dist') : currentDirectory;
13
17
 
14
18
  const strapiInstance = strapi({
15
- dir,
19
+ distDir: buildDestDir,
16
20
  autoReload: true,
17
21
  serveAdminPanel: false,
18
22
  });
@@ -23,14 +27,12 @@ module.exports = async function({ browser }) {
23
27
 
24
28
  const adminPort = strapiInstance.config.get('admin.port', 8000);
25
29
  const adminHost = strapiInstance.config.get('admin.host', 'localhost');
26
- const adminWatchIgnoreFiles = strapiInstance.config.get('admin.watchIgnoreFiles', []);
27
30
 
28
31
  const backendURL = getAbsoluteServerUrl(strapiInstance.config, true);
29
32
 
30
- ee({ dir });
31
-
32
33
  strapiAdmin.watchAdmin({
33
- dir,
34
+ appDir: currentDirectory,
35
+ buildDestDir,
34
36
  plugins,
35
37
  port: adminPort,
36
38
  host: adminHost,
@@ -38,8 +40,6 @@ module.exports = async function({ browser }) {
38
40
  options: {
39
41
  backend: backendURL,
40
42
  adminPath: addSlash(adminPath),
41
- watchIgnoreFiles: adminWatchIgnoreFiles,
42
- features: ee.isEE ? ee.features.getEnabled() : [],
43
43
  },
44
44
  });
45
45
  };
@@ -21,6 +21,7 @@ const defaultConfig = {
21
21
  proxy: false,
22
22
  cron: { enabled: false },
23
23
  admin: { autoOpen: false },
24
+ dirs: { public: './public' },
24
25
  },
25
26
  admin: {},
26
27
  api: {
@@ -30,12 +31,13 @@ const defaultConfig = {
30
31
  },
31
32
  };
32
33
 
33
- module.exports = (dir, initialConfig = {}) => {
34
+ module.exports = (dirs, initialConfig = {}) => {
35
+ const { appDir, distDir } = dirs;
34
36
  const { autoReload = false, serveAdminPanel = true } = initialConfig;
35
37
 
36
- const pkgJSON = require(path.resolve(dir, 'package.json'));
38
+ const pkgJSON = require(path.resolve(appDir, 'package.json'));
37
39
 
38
- const configDir = path.resolve(dir || process.cwd(), 'config');
40
+ const configDir = path.resolve(distDir || process.cwd(), 'config');
39
41
 
40
42
  const rootConfig = {
41
43
  launchedAt: Date.now(),
@@ -4,9 +4,11 @@ const path = require('path');
4
4
  const fs = require('fs');
5
5
  const { templateConfiguration, env } = require('@strapi/utils');
6
6
 
7
+ const __importDefault = require('../../utils/import-default');
8
+
7
9
  const loadJsFile = file => {
8
10
  try {
9
- const jsModule = require(file);
11
+ const jsModule = __importDefault(require(file)).default;
10
12
 
11
13
  // call if function
12
14
  if (typeof jsModule === 'function') {
@@ -1,8 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  const { getConfigUrls } = require('@strapi/utils');
4
+ const fse = require('fs-extra');
4
5
 
5
- module.exports = function({ strapi }) {
6
+ module.exports = async function({ strapi }) {
6
7
  strapi.config.port = strapi.config.get('server.port') || strapi.config.port;
7
8
  strapi.config.host = strapi.config.get('server.host') || strapi.config.host;
8
9
 
@@ -22,4 +23,11 @@ module.exports = function({ strapi }) {
22
23
  if (!shouldServeAdmin) {
23
24
  strapi.config.serveAdminPanel = false;
24
25
  }
26
+
27
+ // ensure public repository exists
28
+ if (!(await fse.pathExists(strapi.dirs.static.public))) {
29
+ throw new Error(
30
+ `The public folder (${strapi.dirs.static.public}) doesn't exist or is not accessible. Please make sure it exists.`
31
+ );
32
+ }
25
33
  };
@@ -5,6 +5,7 @@ const { existsSync } = require('fs-extra');
5
5
  const _ = require('lodash');
6
6
  const fse = require('fs-extra');
7
7
  const { isKebabCase } = require('@strapi/utils');
8
+ const { importDefault } = require('../../utils');
8
9
 
9
10
  // to handle names with numbers in it we first check if it is already in kebabCase
10
11
  const normalizeName = name => (isKebabCase(name) ? name : _.kebabCase(name));
@@ -16,18 +17,18 @@ const DEFAULT_CONTENT_TYPE = {
16
17
  };
17
18
 
18
19
  module.exports = async strapi => {
19
- if (!existsSync(strapi.dirs.api)) {
20
- throw new Error('Missing api folder. Please create one at `./src/api`');
20
+ if (!existsSync(strapi.dirs.dist.api)) {
21
+ return;
21
22
  }
22
23
 
23
- const apisFDs = await fse.readdir(strapi.dirs.api, { withFileTypes: true });
24
+ const apisFDs = await fse.readdir(strapi.dirs.dist.api, { withFileTypes: true });
24
25
  const apis = {};
25
26
 
26
27
  // only load folders
27
28
  for (const apiFD of apisFDs) {
28
29
  if (apiFD.isDirectory()) {
29
30
  const apiName = normalizeName(apiFD.name);
30
- const api = await loadAPI(join(strapi.dirs.api, apiFD.name));
31
+ const api = await loadAPI(join(strapi.dirs.dist.api, apiFD.name));
31
32
 
32
33
  apis[apiName] = api;
33
34
  }
@@ -150,7 +151,7 @@ const loadFile = file => {
150
151
 
151
152
  switch (ext) {
152
153
  case '.js':
153
- return require(file);
154
+ return importDefault(require(file)).default;
154
155
  case '.json':
155
156
  return fse.readJSON(file);
156
157
  default:
@@ -6,19 +6,20 @@ const { pathExists } = require('fs-extra');
6
6
  const loadFiles = require('../../load/load-files');
7
7
 
8
8
  module.exports = async strapi => {
9
- if (!(await pathExists(strapi.dirs.components))) {
9
+ if (!(await pathExists(strapi.dirs.dist.components))) {
10
10
  return {};
11
11
  }
12
12
 
13
- const map = await loadFiles(strapi.dirs.components, '*/*.*(js|json)');
13
+ const map = await loadFiles(strapi.dirs.dist.components, '*/*.*(js|json)');
14
14
 
15
15
  return Object.keys(map).reduce((acc, category) => {
16
16
  Object.keys(map[category]).forEach(key => {
17
17
  const schema = map[category][key];
18
18
 
19
- const filePath = join(strapi.dirs.components, category, schema.__filename__);
20
-
21
19
  if (!schema.collectionName) {
20
+ // NOTE: We're using the filepath from the app directory instead of the dist for information purpose
21
+ const filePath = join(strapi.dirs.app.components, category, schema.__filename__);
22
+
22
23
  return strapi.stopWithError(
23
24
  `Component ${key} is missing a "collectionName" property.\nVerify file ${filePath}.`
24
25
  );
@@ -3,17 +3,19 @@
3
3
  const { join, extname, basename } = require('path');
4
4
  const fse = require('fs-extra');
5
5
 
6
+ const { importDefault } = require('../../utils');
7
+
6
8
  // TODO:: allow folders with index.js inside for bigger policies
7
9
  module.exports = async function loadMiddlewares(strapi) {
8
10
  const localMiddlewares = await loadLocalMiddlewares(strapi);
9
- const internalMiddlewares = require('../../middlewares');
11
+ const internalMiddlewares = importDefault(require('../../middlewares')).default;
10
12
 
11
13
  strapi.container.get('middlewares').add(`global::`, localMiddlewares);
12
14
  strapi.container.get('middlewares').add(`strapi::`, internalMiddlewares);
13
15
  };
14
16
 
15
17
  const loadLocalMiddlewares = async strapi => {
16
- const dir = strapi.dirs.middlewares;
18
+ const dir = strapi.dirs.dist.middlewares;
17
19
 
18
20
  if (!(await fse.pathExists(dir))) {
19
21
  return {};
@@ -28,7 +30,7 @@ const loadLocalMiddlewares = async strapi => {
28
30
 
29
31
  if (fd.isFile() && extname(name) === '.js') {
30
32
  const key = basename(name, '.js');
31
- middlewares[key] = require(fullPath);
33
+ middlewares[key] = importDefault(require(fullPath)).default;
32
34
  }
33
35
  }
34
36
 
@@ -29,10 +29,11 @@ const toDetailedDeclaration = declaration => {
29
29
  let detailedDeclaration = pick(['enabled'], declaration);
30
30
  if (has('resolve', declaration)) {
31
31
  let pathToPlugin = '';
32
+
32
33
  try {
33
34
  pathToPlugin = dirname(require.resolve(declaration.resolve));
34
35
  } catch (e) {
35
- pathToPlugin = resolve(strapi.dirs.root, declaration.resolve);
36
+ pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);
36
37
 
37
38
  if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {
38
39
  throw new Error(`${declaration.resolve} couldn't be resolved`);
@@ -71,7 +72,10 @@ const getEnabledPlugins = async strapi => {
71
72
  validatePluginName(packageInfo.strapi.name);
72
73
  installedPlugins[packageInfo.strapi.name] = {
73
74
  ...toDetailedDeclaration({ enabled: true, resolve: packagePath }),
74
- info: packageInfo.strapi,
75
+ info: {
76
+ ...packageInfo.strapi,
77
+ packageName: packageInfo.name,
78
+ },
75
79
  };
76
80
  }
77
81
  }
@@ -12,9 +12,9 @@ const loadConfigFile = require('../../app-configuration/load-config-file');
12
12
  * @return {Promise<{}>}
13
13
  */
14
14
  const getUserPluginsConfig = async () => {
15
- const globalUserConfigPath = join(strapi.dirs.config, 'plugins.js');
15
+ const globalUserConfigPath = join(strapi.dirs.dist.config, 'plugins.js');
16
16
  const currentEnvUserConfigPath = join(
17
- strapi.dirs.config,
17
+ strapi.dirs.dist.config,
18
18
  'env',
19
19
  process.env.NODE_ENV,
20
20
  'plugins.js'
@@ -26,7 +26,7 @@ const defaultPlugin = {
26
26
  };
27
27
 
28
28
  const applyUserExtension = async plugins => {
29
- const extensionsDir = strapi.dirs.extensions;
29
+ const extensionsDir = strapi.dirs.dist.extensions;
30
30
  if (!(await fse.pathExists(extensionsDir))) {
31
31
  return;
32
32
  }
@@ -3,9 +3,11 @@
3
3
  const { join, extname, basename } = require('path');
4
4
  const fse = require('fs-extra');
5
5
 
6
+ const { importDefault } = require('../../utils');
7
+
6
8
  // TODO:: allow folders with index.js inside for bigger policies
7
9
  module.exports = async function loadPolicies(strapi) {
8
- const dir = strapi.dirs.policies;
10
+ const dir = strapi.dirs.dist.policies;
9
11
 
10
12
  if (!(await fse.pathExists(dir))) {
11
13
  return;
@@ -20,7 +22,7 @@ module.exports = async function loadPolicies(strapi) {
20
22
 
21
23
  if (fd.isFile() && extname(name) === '.js') {
22
24
  const key = basename(name, '.js');
23
- policies[key] = require(fullPath);
25
+ policies[key] = importDefault(require(fullPath)).default;
24
26
  }
25
27
  }
26
28
 
@@ -4,6 +4,8 @@ const { resolve } = require('path');
4
4
  const { statSync, existsSync } = require('fs');
5
5
  const { yup } = require('@strapi/utils');
6
6
 
7
+ const { importDefault } = require('../../utils');
8
+
7
9
  const srcSchema = yup
8
10
  .object()
9
11
  .shape({
@@ -18,16 +20,16 @@ const validateSrcIndex = srcIndex => {
18
20
  };
19
21
 
20
22
  module.exports = strapi => {
21
- if (!existsSync(strapi.dirs.src)) {
22
- throw new Error('Missing src folder. Please create one at `./src`');
23
+ if (!existsSync(strapi.dirs.dist.src)) {
24
+ return;
23
25
  }
24
26
 
25
- const pathToSrcIndex = resolve(strapi.dirs.src, 'index.js');
27
+ const pathToSrcIndex = resolve(strapi.dirs.dist.src, 'index.js');
26
28
  if (!existsSync(pathToSrcIndex) || statSync(pathToSrcIndex).isDirectory()) {
27
29
  return {};
28
30
  }
29
31
 
30
- const srcIndex = require(pathToSrcIndex);
32
+ const srcIndex = importDefault(require(pathToSrcIndex)).default;
31
33
 
32
34
  try {
33
35
  validateSrcIndex(srcIndex);