@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
@@ -43,6 +43,6 @@ interface Router {
43
43
  routes: Route[];
44
44
  }
45
45
 
46
- export function createCoreRouter(uid: string, cfg: RouterConfig): () => Router;
47
- export function createCoreController(uid: string, cfg: ControllerConfig): () => Controller;
48
- export function createCoreService(uid: string, cfg: ServiceConfig): () => Service;
46
+ export function createCoreRouter(uid: string, cfg?: RouterConfig = {}): () => Router;
47
+ export function createCoreController(uid: string, cfg?: ControllerConfig = {}): () => Controller;
48
+ export function createCoreService(uid: string, cfg?: ServiceConfig = {}): () => Service;
package/lib/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import { EntityService } from './services/entity-service';
3
3
  import { Strapi as StrapiClass } from './Strapi';
4
4
 
5
5
  export * as factories from './factories';
6
- interface StrapiInterface extends StrapiClass {
6
+ export interface StrapiInterface extends StrapiClass {
7
7
  query: Database['query'];
8
8
  entityService: EntityService;
9
9
  }
@@ -3,6 +3,8 @@
3
3
  const path = require('path');
4
4
  const _ = require('lodash');
5
5
  const fse = require('fs-extra');
6
+
7
+ const { importDefault } = require('../utils');
6
8
  const glob = require('./glob');
7
9
  const filePathToPath = require('./filepath-to-prop-path');
8
10
 
@@ -34,7 +36,7 @@ const loadFiles = async (
34
36
  if (path.extname(absolutePath) === '.json') {
35
37
  mod = await fse.readJson(absolutePath);
36
38
  } else {
37
- mod = requireFn(absolutePath);
39
+ mod = importDefault(requireFn(absolutePath)).default;
38
40
  }
39
41
 
40
42
  Object.defineProperty(mod, '__filename__', {
@@ -15,5 +15,5 @@ const defaults = {
15
15
  module.exports = (config, { strapi }) => {
16
16
  const { maxAge, path: faviconPath } = defaultsDeep(defaults, config);
17
17
 
18
- return favicon(resolve(strapi.dirs.root, faviconPath), { maxAge });
18
+ return favicon(resolve(strapi.dirs.app.root, faviconPath), { maxAge });
19
19
  };
@@ -71,6 +71,7 @@ module.exports = (config, { strapi }) => {
71
71
  {
72
72
  method: 'GET',
73
73
  path: '/assets/images/(.*)',
74
+ // Why do we use the __dirname and not strapi.dirs here? @alexandrebodin
74
75
  handler: serveStatic(path.resolve(__dirname, 'assets/images'), {
75
76
  maxage: maxAge,
76
77
  defer: true,
@@ -80,7 +81,7 @@ module.exports = (config, { strapi }) => {
80
81
  {
81
82
  method: 'GET',
82
83
  path: '/(.*)',
83
- handler: koaStatic(strapi.dirs.public, {
84
+ handler: koaStatic(strapi.dirs.static.public, {
84
85
  maxage: maxAge,
85
86
  defer: true,
86
87
  }),
@@ -12,7 +12,7 @@ const defaults = {
12
12
  useDefaults: true,
13
13
  directives: {
14
14
  'connect-src': ["'self'", 'https:'],
15
- 'img-src': ["'self'", 'data:', 'blob:'],
15
+ 'img-src': ["'self'", 'data:', 'blob:', 'https://dl.airtable.com'],
16
16
  'media-src': ["'self'", 'data:', 'blob:'],
17
17
  upgradeInsecureRequests: null,
18
18
  },
@@ -19,7 +19,9 @@ const defaultConfig = {
19
19
  module.exports = (userConfig, { strapi }) => {
20
20
  const keys = strapi.server.app.keys;
21
21
  if (!isArray(keys) || isEmpty(keys) || keys.some(isEmpty)) {
22
- throw new Error(`App keys are required. Please set app.keys in config/server.js (ex: keys: ['myKeyA', 'myKeyB'])`);
22
+ throw new Error(
23
+ `App keys are required. Please set app.keys in config/server.js (ex: keys: ['myKeyA', 'myKeyB'])`
24
+ );
23
25
  }
24
26
 
25
27
  const config = defaultsDeep(defaultConfig, userConfig);
@@ -12,7 +12,7 @@ module.exports = strapi => {
12
12
 
13
13
  const normalizedPath = path.normalize(filePath).replace(/^\/?(\.\/|\.\.\/)+/, '');
14
14
 
15
- return path.resolve(strapi.dirs.root, normalizedPath);
15
+ return path.resolve(strapi.dirs.app.root, normalizedPath);
16
16
  }
17
17
 
18
18
  const strapiFS = {
@@ -24,13 +24,19 @@ const LIMITED_EVENTS = [
24
24
 
25
25
  const createTelemetryInstance = strapi => {
26
26
  const uuid = strapi.config.get('uuid');
27
- const isDisabled = !uuid || isTruthy(process.env.STRAPI_TELEMETRY_DISABLED);
27
+ const telemetryDisabled = strapi.config.get('packageJsonStrapi.telemetryDisabled');
28
+ const isDisabled =
29
+ !uuid || isTruthy(process.env.STRAPI_TELEMETRY_DISABLED) || isTruthy(telemetryDisabled);
28
30
 
29
31
  const crons = [];
30
32
  const sender = createSender(strapi);
31
33
  const sendEvent = wrapWithRateLimit(sender, { limitedEvents: LIMITED_EVENTS });
32
34
 
33
35
  return {
36
+ get isDisabled() {
37
+ return isDisabled;
38
+ },
39
+
34
40
  register() {
35
41
  if (!isDisabled) {
36
42
  const pingCron = scheduleJob('0 0 12 * * *', () => sendEvent('ping'));
@@ -90,7 +96,7 @@ const hashProject = strapi =>
90
96
 
91
97
  const hashDep = strapi => {
92
98
  const depStr = JSON.stringify(strapi.config.info.dependencies);
93
- const readmePath = path.join(strapi.dirs.root, 'README.md');
99
+ const readmePath = path.join(strapi.dirs.app.root, 'README.md');
94
100
 
95
101
  try {
96
102
  if (fs.existsSync(readmePath)) {
@@ -1,10 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  const os = require('os');
4
+ const path = require('path');
4
5
  const _ = require('lodash');
5
6
  const isDocker = require('is-docker');
6
7
  const fetch = require('node-fetch');
7
8
  const ciEnv = require('ci-info');
9
+ const { isUsingTypeScriptSync } = require('@strapi/typescript-utils');
8
10
  const ee = require('../../utils/ee');
9
11
  const machineID = require('../../utils/machine-id');
10
12
  const stringifyDeep = require('./stringify-deep');
@@ -36,6 +38,9 @@ module.exports = strapi => {
36
38
  const deviceId = machineID();
37
39
  const isEE = strapi.EE === true && ee.isEE === true;
38
40
 
41
+ const serverRootPath = strapi.dirs.app.root;
42
+ const adminRootPath = path.join(strapi.dirs.app.root, 'src', 'admin');
43
+
39
44
  const anonymous_metadata = {
40
45
  environment: strapi.config.environment,
41
46
  os: os.type(),
@@ -47,6 +52,8 @@ module.exports = strapi => {
47
52
  version: strapi.config.get('info.strapi'),
48
53
  strapiVersion: strapi.config.get('info.strapi'),
49
54
  projectType: isEE ? 'Enterprise' : 'Community',
55
+ useTypescriptOnServer: isUsingTypeScriptSync(serverRootPath),
56
+ useTypescriptOnAdmin: isUsingTypeScriptSync(adminRootPath),
50
57
  };
51
58
 
52
59
  addPackageJsonStrapiMetadata(anonymous_metadata, strapi);
@@ -30,7 +30,7 @@ const healthCheck = async ctx => {
30
30
  const createServer = strapi => {
31
31
  const app = createKoaApp({
32
32
  proxy: strapi.config.get('server.proxy'),
33
- keys: strapi.config.get('server.app.keys'),
33
+ keys: strapi.config.get('server.app.keys'),
34
34
  });
35
35
 
36
36
  const router = new Router();
@@ -112,7 +112,7 @@ const resolveCustomMiddleware = (resolve, strapi) => {
112
112
  modulePath = require.resolve(resolve);
113
113
  } catch (error) {
114
114
  if (error.code === 'MODULE_NOT_FOUND') {
115
- modulePath = path.resolve(strapi.dirs.root, resolve);
115
+ modulePath = path.resolve(strapi.dirs.dist.root, resolve);
116
116
  } else {
117
117
  throw error;
118
118
  }
@@ -1,17 +1,31 @@
1
1
  'use strict';
2
2
 
3
- const { join } = require('path');
3
+ const { join, resolve } = require('path');
4
4
 
5
- const getDirs = root => ({
6
- root,
7
- src: join(root, 'src'),
8
- api: join(root, 'src', 'api'),
9
- components: join(root, 'src', 'components'),
10
- extensions: join(root, 'src', 'extensions'),
11
- policies: join(root, 'src', 'policies'),
12
- middlewares: join(root, 'src', 'middlewares'),
13
- config: join(root, 'config'),
14
- public: join(root, 'public'),
5
+ const getDirs = ({ app: appDir, dist: distDir }, { strapi }) => ({
6
+ dist: {
7
+ root: distDir,
8
+ src: join(distDir, 'src'),
9
+ api: join(distDir, 'src', 'api'),
10
+ components: join(distDir, 'src', 'components'),
11
+ extensions: join(distDir, 'src', 'extensions'),
12
+ policies: join(distDir, 'src', 'policies'),
13
+ middlewares: join(distDir, 'src', 'middlewares'),
14
+ config: join(distDir, 'config'),
15
+ },
16
+ app: {
17
+ root: appDir,
18
+ src: join(appDir, 'src'),
19
+ api: join(appDir, 'src', 'api'),
20
+ components: join(appDir, 'src', 'components'),
21
+ extensions: join(appDir, 'src', 'extensions'),
22
+ policies: join(appDir, 'src', 'policies'),
23
+ middlewares: join(appDir, 'src', 'middlewares'),
24
+ config: join(appDir, 'config'),
25
+ },
26
+ static: {
27
+ public: resolve(appDir, strapi.config.get('server.dirs.public')),
28
+ },
15
29
  });
16
30
 
17
31
  module.exports = getDirs;
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ const __importDefault =
4
+ (this && this.__importDefault) ||
5
+ function(mod) {
6
+ return mod && mod.__esModule ? mod : { default: mod };
7
+ };
8
+
9
+ module.exports = __importDefault;
@@ -3,9 +3,11 @@
3
3
  const openBrowser = require('./open-browser');
4
4
  const isInitialized = require('./is-initialized');
5
5
  const getDirs = require('./get-dirs');
6
+ const importDefault = require('./import-default');
6
7
 
7
8
  module.exports = {
8
9
  isInitialized,
9
10
  openBrowser,
10
11
  getDirs,
12
+ importDefault,
11
13
  };
@@ -38,7 +38,7 @@ const createUpdateNotifier = strapi => {
38
38
  config = new Configstore(
39
39
  pkg.name,
40
40
  {},
41
- { configPath: path.join(strapi.dirs.root, '.strapi-updater.json') }
41
+ { configPath: path.join(strapi.dirs.app.root, '.strapi-updater.json') }
42
42
  );
43
43
  } catch {
44
44
  // we don't have write access to the file system
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/strapi",
3
- "version": "4.2.0-alpha.O",
3
+ "version": "4.2.0-beta.2",
4
4
  "description": "An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite",
5
5
  "keywords": [
6
6
  "strapi",
@@ -80,16 +80,17 @@
80
80
  "dependencies": {
81
81
  "@koa/cors": "3.1.0",
82
82
  "@koa/router": "10.1.1",
83
- "@strapi/admin": "4.2.0-alpha.O",
84
- "@strapi/database": "4.2.0-alpha.O",
85
- "@strapi/generate-new": "4.2.0-alpha.O",
86
- "@strapi/generators": "4.2.0-alpha.O",
87
- "@strapi/logger": "4.2.0-alpha.O",
88
- "@strapi/plugin-content-manager": "4.2.0-alpha.O",
89
- "@strapi/plugin-content-type-builder": "4.2.0-alpha.O",
90
- "@strapi/plugin-email": "4.2.0-alpha.O",
91
- "@strapi/plugin-upload": "4.2.0-alpha.O",
92
- "@strapi/utils": "4.2.0-alpha.O",
83
+ "@strapi/admin": "4.2.0-beta.2",
84
+ "@strapi/database": "4.2.0-beta.2",
85
+ "@strapi/generate-new": "4.2.0-beta.2",
86
+ "@strapi/generators": "4.2.0-beta.2",
87
+ "@strapi/logger": "4.2.0-beta.2",
88
+ "@strapi/plugin-content-manager": "4.2.0-beta.2",
89
+ "@strapi/plugin-content-type-builder": "4.2.0-beta.2",
90
+ "@strapi/plugin-email": "4.2.0-beta.2",
91
+ "@strapi/plugin-upload": "4.2.0-beta.2",
92
+ "@strapi/typescript-utils": "4.2.0-beta.2",
93
+ "@strapi/utils": "4.2.0-beta.2",
93
94
  "bcryptjs": "2.4.3",
94
95
  "boxen": "5.1.2",
95
96
  "chalk": "4.1.2",
@@ -130,11 +131,12 @@
130
131
  "uuid": "^3.3.2"
131
132
  },
132
133
  "devDependencies": {
133
- "supertest": "^6.1.6"
134
+ "supertest": "^6.1.6",
135
+ "typescript": "4.6.2"
134
136
  },
135
137
  "engines": {
136
138
  "node": ">=12.22.0 <=16.x.x",
137
139
  "npm": ">=6.0.0"
138
140
  },
139
- "gitHead": "0e1f1ae08565a5f2427753582f37645a43c00cb2"
141
+ "gitHead": "bff73257e7695d6f361c91dda8cc810a2bb70b6e"
140
142
  }