diff --git a/api-tests/core/admin/admin-permission.test.api.js b/api-tests/core/admin/admin-permission.test.api.js index 50e14a23ce..4f9e7d075a 100644 --- a/api-tests/core/admin/admin-permission.test.api.js +++ b/api-tests/core/admin/admin-permission.test.api.js @@ -34,7 +34,7 @@ describe('Role CRUD End to End', () => { sortedData.conditions = sortedData.conditions.sort(); // eslint-disable-next-line node/no-extraneous-require - const { features } = require('@strapi/strapi/dist/utils/ee').default; + const { features } = require('@strapi/strapi/dist/utils/ee'); const hasSSO = features.isEnabled('sso'); if (hasSSO) { diff --git a/api-tests/core/admin/ee/provider-login.test.api.js b/api-tests/core/admin/ee/provider-login.test.api.js index 01562080f1..34d82e44b1 100644 --- a/api-tests/core/admin/ee/provider-login.test.api.js +++ b/api-tests/core/admin/ee/provider-login.test.api.js @@ -54,7 +54,7 @@ describeOnCondition(edition === 'EE')('Provider Login', () => { strapi = await createStrapiInstance(); utils = createUtils(strapi); // eslint-disable-next-line node/no-extraneous-require - hasSSO = require('@strapi/strapi/dist/utils/ee').default.features.isEnabled('sso'); + hasSSO = require('@strapi/strapi/dist/utils/ee').features.isEnabled('sso'); await createFixtures(); diff --git a/api-tests/core/admin/ee/provider-options.test.api.js b/api-tests/core/admin/ee/provider-options.test.api.js index 249686bfcc..e1ae9200fe 100644 --- a/api-tests/core/admin/ee/provider-options.test.api.js +++ b/api-tests/core/admin/ee/provider-options.test.api.js @@ -54,7 +54,7 @@ describeOnCondition(edition === 'EE')('SSO Provider Options', () => { strapi = await createStrapiInstance(); utils = createUtils(strapi); // eslint-disable-next-line node/no-extraneous-require - hasSSO = require('@strapi/strapi/dist/utils/ee').default.features.isEnabled('sso'); + hasSSO = require('@strapi/strapi/dist/utils/ee').features.isEnabled('sso'); await createFixtures(); diff --git a/api-tests/core/admin/ee/review-workflows.test.api.js b/api-tests/core/admin/ee/review-workflows.test.api.js index 28ff3f6ceb..4a5b30c96a 100644 --- a/api-tests/core/admin/ee/review-workflows.test.api.js +++ b/api-tests/core/admin/ee/review-workflows.test.api.js @@ -95,7 +95,7 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { beforeAll(async () => { await builder.addContentTypes([model]).build(); // eslint-disable-next-line node/no-extraneous-require - hasRW = require('@strapi/strapi/dist/utils/ee').default.features.isEnabled('review-workflows'); + hasRW = require('@strapi/strapi/dist/utils/ee').features.isEnabled('review-workflows'); strapi = await createStrapiInstance({ bypassAuth: false }); requests.admin = await createAuthRequest({ strapi }); diff --git a/packages/core/admin/ee/server/bootstrap.js b/packages/core/admin/ee/server/bootstrap.js index 955015950b..8e4b0ad6cc 100644 --- a/packages/core/admin/ee/server/bootstrap.js +++ b/packages/core/admin/ee/server/bootstrap.js @@ -1,7 +1,7 @@ 'use strict'; // eslint-disable-next-line node/no-extraneous-require -const { features } = require('@strapi/strapi/dist/utils/ee').default; +const { features } = require('@strapi/strapi/dist/utils/ee'); const executeCEBootstrap = require('../../server/bootstrap'); const { getService } = require('../../server/utils'); const actions = require('./config/admin-actions'); diff --git a/packages/core/admin/ee/server/controllers/admin.js b/packages/core/admin/ee/server/controllers/admin.js index 594336772e..7d1ff987bd 100644 --- a/packages/core/admin/ee/server/controllers/admin.js +++ b/packages/core/admin/ee/server/controllers/admin.js @@ -2,7 +2,7 @@ const { isNil } = require('lodash/fp'); // eslint-disable-next-line node/no-extraneous-require -const ee = require('@strapi/strapi/dist/utils/ee').default; +const ee = require('@strapi/strapi/dist/utils/ee'); const { env } = require('@strapi/utils'); const { getService } = require('../../../server/utils'); diff --git a/packages/core/admin/ee/server/controllers/user.js b/packages/core/admin/ee/server/controllers/user.js index dcc5c385ff..1a5534cd82 100644 --- a/packages/core/admin/ee/server/controllers/user.js +++ b/packages/core/admin/ee/server/controllers/user.js @@ -1,7 +1,7 @@ 'use strict'; // eslint-disable-next-line node/no-extraneous-require -const ee = require('@strapi/strapi/dist/utils/ee').default; +const ee = require('@strapi/strapi/dist/utils/ee'); const _ = require('lodash'); const { pick, isNil } = require('lodash/fp'); const { ApplicationError, ForbiddenError } = require('@strapi/utils').errors; diff --git a/packages/core/admin/ee/server/destroy.js b/packages/core/admin/ee/server/destroy.js index a22196c974..9be8cce68f 100644 --- a/packages/core/admin/ee/server/destroy.js +++ b/packages/core/admin/ee/server/destroy.js @@ -1,6 +1,6 @@ 'use strict'; -const { features } = require('@strapi/strapi/dist/utils/ee').default; +const { features } = require('@strapi/strapi/dist/utils/ee'); const executeCEDestroy = require('../../server/destroy'); module.exports = async ({ strapi }) => { diff --git a/packages/core/admin/ee/server/register.js b/packages/core/admin/ee/server/register.js index 3bd4c8127b..d6e76ae057 100644 --- a/packages/core/admin/ee/server/register.js +++ b/packages/core/admin/ee/server/register.js @@ -1,6 +1,6 @@ 'use strict'; -const { features } = require('@strapi/strapi/dist/utils/ee').default; +const { features } = require('@strapi/strapi/dist/utils/ee'); const executeCERegister = require('../../server/register'); const migrateAuditLogsTable = require('./migrations/audit-logs-table'); const migrateReviewWorkflowStagesColor = require('./migrations/review-workflows-stages-color'); diff --git a/packages/core/admin/ee/server/routes/utils.js b/packages/core/admin/ee/server/routes/utils.js index 3fdb4aa963..4d0b89debe 100644 --- a/packages/core/admin/ee/server/routes/utils.js +++ b/packages/core/admin/ee/server/routes/utils.js @@ -1,6 +1,6 @@ 'use strict'; -const { features } = require('@strapi/strapi/dist/utils/ee').default; +const { features } = require('@strapi/strapi/dist/utils/ee'); const enableFeatureMiddleware = (featureName) => (ctx, next) => { if (features.isEnabled(featureName)) { diff --git a/packages/core/admin/ee/server/services/__tests__/assignees.test.js b/packages/core/admin/ee/server/services/__tests__/assignees.test.js index 593ec9769f..31ac6b2b42 100644 --- a/packages/core/admin/ee/server/services/__tests__/assignees.test.js +++ b/packages/core/admin/ee/server/services/__tests__/assignees.test.js @@ -4,14 +4,12 @@ jest.mock('@strapi/strapi/dist/utils/ee', () => { const eeModule = () => true; Object.assign(eeModule, { - default: { - features: { - isEnabled() { - return true; - }, - getEnabled() { - return ['review-workflows']; - }, + features: { + isEnabled() { + return true; + }, + getEnabled() { + return ['review-workflows']; }, }, }); diff --git a/packages/core/admin/ee/server/services/__tests__/audit-logs.test.js b/packages/core/admin/ee/server/services/__tests__/audit-logs.test.js index 9a2a1958b5..c34cdbd353 100644 --- a/packages/core/admin/ee/server/services/__tests__/audit-logs.test.js +++ b/packages/core/admin/ee/server/services/__tests__/audit-logs.test.js @@ -1,10 +1,10 @@ 'use strict'; -const { features } = require('@strapi/strapi/dist/utils/ee').default; +const { features } = require('@strapi/strapi/dist/utils/ee'); const { register } = require('@strapi/provider-audit-logs-local'); const { scheduleJob } = require('node-schedule'); const createAuditLogsService = require('../audit-logs'); -const createEventHub = require('../../../../../strapi/dist/services/event-hub').default; +const createEventHub = require('../../../../../strapi/dist/services/event-hub'); jest.mock('../../../../server/register'); @@ -13,11 +13,9 @@ jest.mock('../../utils', () => ({ })); jest.mock('@strapi/strapi/dist/utils/ee', () => ({ - default: { - features: { - isEnabled: jest.fn(), - get: jest.fn(), - }, + features: { + isEnabled: jest.fn(), + get: jest.fn(), }, })); diff --git a/packages/core/admin/ee/server/services/__tests__/passport.test.js b/packages/core/admin/ee/server/services/__tests__/passport.test.js index d128216980..5c85452c80 100644 --- a/packages/core/admin/ee/server/services/__tests__/passport.test.js +++ b/packages/core/admin/ee/server/services/__tests__/passport.test.js @@ -20,11 +20,9 @@ describe('Passport', () => { describe('Init (SSO disabled)', () => { beforeAll(() => { jest.mock('@strapi/strapi/dist/utils/ee', () => ({ - default: { - features: { - // Disable the SSO feature - isEnabled: (feature) => feature !== 'sso', - }, + features: { + // Disable the SSO feature + isEnabled: (feature) => feature !== 'sso', }, })); }); @@ -60,11 +58,9 @@ describe('Passport', () => { describe('Init (SSO enabled)', () => { beforeAll(() => { jest.mock('@strapi/strapi/dist/utils/ee', () => ({ - default: { - features: { - // Enable all the features (including SSO) - isEnabled: () => true, - }, + features: { + // Enable all the features (including SSO) + isEnabled: () => true, }, })); }); diff --git a/packages/core/admin/ee/server/services/__tests__/review-workflows-validation.test.js b/packages/core/admin/ee/server/services/__tests__/review-workflows-validation.test.js index a7b7038cd7..f8731e0a9e 100644 --- a/packages/core/admin/ee/server/services/__tests__/review-workflows-validation.test.js +++ b/packages/core/admin/ee/server/services/__tests__/review-workflows-validation.test.js @@ -4,14 +4,12 @@ jest.mock('@strapi/strapi/dist/utils/ee', () => { const eeModule = () => true; Object.assign(eeModule, { - default: { - features: { - isEnabled() { - return true; - }, - getEnabled() { - return ['review-workflows']; - }, + features: { + isEnabled() { + return true; + }, + getEnabled() { + return ['review-workflows']; }, }, }); diff --git a/packages/core/admin/ee/server/services/__tests__/sso.test.js b/packages/core/admin/ee/server/services/__tests__/sso.test.js index 2001e7d911..b8d80bda81 100644 --- a/packages/core/admin/ee/server/services/__tests__/sso.test.js +++ b/packages/core/admin/ee/server/services/__tests__/sso.test.js @@ -1,14 +1,12 @@ 'use strict'; jest.mock('@strapi/strapi/dist/utils/ee', () => ({ - default: { - features: { - isEnabled() { - return true; - }, - list() { - return [{ name: 'sso' }]; - }, + features: { + isEnabled() { + return true; + }, + list() { + return [{ name: 'sso' }]; }, }, })); diff --git a/packages/core/admin/ee/server/services/__tests__/stages.test.js b/packages/core/admin/ee/server/services/__tests__/stages.test.js index 0e6ba557f5..95a5eef29b 100644 --- a/packages/core/admin/ee/server/services/__tests__/stages.test.js +++ b/packages/core/admin/ee/server/services/__tests__/stages.test.js @@ -4,14 +4,12 @@ jest.mock('@strapi/strapi/dist/utils/ee', () => { const eeModule = () => true; Object.assign(eeModule, { - default: { - features: { - isEnabled() { - return true; - }, - getEnabled() { - return ['review-workflows']; - }, + features: { + isEnabled() { + return true; + }, + getEnabled() { + return ['review-workflows']; }, }, }); diff --git a/packages/core/admin/ee/server/services/__tests__/workflows.test.js b/packages/core/admin/ee/server/services/__tests__/workflows.test.js index 6764edf0b9..be776bb930 100644 --- a/packages/core/admin/ee/server/services/__tests__/workflows.test.js +++ b/packages/core/admin/ee/server/services/__tests__/workflows.test.js @@ -4,14 +4,12 @@ jest.mock('@strapi/strapi/dist/utils/ee', () => { const eeModule = () => true; Object.assign(eeModule, { - default: { - features: { - isEnabled() { - return true; - }, - getEnabled() { - return ['review-workflows']; - }, + features: { + isEnabled() { + return true; + }, + getEnabled() { + return ['review-workflows']; }, }, }); diff --git a/packages/core/admin/ee/server/services/audit-logs.js b/packages/core/admin/ee/server/services/audit-logs.js index 0aebc0292a..6e3b96a5a3 100644 --- a/packages/core/admin/ee/server/services/audit-logs.js +++ b/packages/core/admin/ee/server/services/audit-logs.js @@ -2,7 +2,7 @@ const localProvider = require('@strapi/provider-audit-logs-local'); const { scheduleJob } = require('node-schedule'); -const { features } = require('@strapi/strapi/dist/utils/ee').default; +const { features } = require('@strapi/strapi/dist/utils/ee'); const DEFAULT_RETENTION_DAYS = 90; diff --git a/packages/core/admin/ee/server/services/passport.js b/packages/core/admin/ee/server/services/passport.js index e5e6947fd7..881276481f 100644 --- a/packages/core/admin/ee/server/services/passport.js +++ b/packages/core/admin/ee/server/services/passport.js @@ -1,7 +1,7 @@ 'use strict'; // eslint-disable-next-line node/no-extraneous-require -const { features } = require('@strapi/strapi/dist/utils/ee').default; +const { features } = require('@strapi/strapi/dist/utils/ee'); const { UnauthorizedError } = require('@strapi/utils').errors; const createLocalStrategy = require('../../../server/services/passport/local-strategy'); diff --git a/packages/core/admin/ee/server/services/passport/sso.js b/packages/core/admin/ee/server/services/passport/sso.js index 8eb487f38b..a38c95e539 100644 --- a/packages/core/admin/ee/server/services/passport/sso.js +++ b/packages/core/admin/ee/server/services/passport/sso.js @@ -1,6 +1,6 @@ 'use strict'; -const ee = require('@strapi/strapi/dist/utils/ee').default; +const ee = require('@strapi/strapi/dist/utils/ee'); const { authEventsMapper } = require('../../../../server/services/passport'); const createProviderRegistry = require('./provider-registry'); diff --git a/packages/core/admin/ee/server/services/seat-enforcement.js b/packages/core/admin/ee/server/services/seat-enforcement.js index a5c690c430..e8fd99f277 100644 --- a/packages/core/admin/ee/server/services/seat-enforcement.js +++ b/packages/core/admin/ee/server/services/seat-enforcement.js @@ -1,7 +1,7 @@ 'use strict'; // eslint-disable-next-line node/no-extraneous-require -const ee = require('@strapi/strapi/dist/utils/ee').default; +const ee = require('@strapi/strapi/dist/utils/ee'); const { take, drop, map, prop, pick, reverse, isNil } = require('lodash/fp'); const { getService } = require('../../../server/utils'); const { SUPER_ADMIN_CODE } = require('../../../server/services/constants'); diff --git a/packages/core/admin/ee/server/utils/__tests__/sso-lock.test.js b/packages/core/admin/ee/server/utils/__tests__/sso-lock.test.js index 53f0e7b62b..55ea122e43 100644 --- a/packages/core/admin/ee/server/utils/__tests__/sso-lock.test.js +++ b/packages/core/admin/ee/server/utils/__tests__/sso-lock.test.js @@ -7,11 +7,9 @@ let ssoEnabled = true; jest.mock('@strapi/strapi/dist/utils/ee', () => { return { - default: { - features: { - isEnabled() { - return ssoEnabled; - }, + features: { + isEnabled() { + return ssoEnabled; }, }, }; diff --git a/packages/core/admin/ee/server/utils/sso-lock.js b/packages/core/admin/ee/server/utils/sso-lock.js index d92ab33043..88f7533c0f 100644 --- a/packages/core/admin/ee/server/utils/sso-lock.js +++ b/packages/core/admin/ee/server/utils/sso-lock.js @@ -1,6 +1,6 @@ 'use strict'; -const { features } = require('@strapi/strapi/dist/utils/ee').default; +const { features } = require('@strapi/strapi/dist/utils/ee'); const { isEmpty } = require('lodash/fp'); const isSsoLocked = async (user) => { diff --git a/packages/core/admin/ee/server/validation/role.js b/packages/core/admin/ee/server/validation/role.js index 2fcc98be04..2ed7fc231c 100644 --- a/packages/core/admin/ee/server/validation/role.js +++ b/packages/core/admin/ee/server/validation/role.js @@ -2,7 +2,7 @@ const { yup, validateYupSchema } = require('@strapi/utils'); // eslint-disable-next-line node/no-extraneous-require -const { features } = require('@strapi/strapi/dist/utils/ee').default; +const { features } = require('@strapi/strapi/dist/utils/ee'); const roleCreateSchema = yup .object() diff --git a/packages/core/admin/ee/server/validation/user.js b/packages/core/admin/ee/server/validation/user.js index 09d21d428b..9ea070c759 100644 --- a/packages/core/admin/ee/server/validation/user.js +++ b/packages/core/admin/ee/server/validation/user.js @@ -2,7 +2,7 @@ const { yup, validateYupSchema } = require('@strapi/utils'); // eslint-disable-next-line node/no-extraneous-require -const { features } = require('@strapi/strapi/dist/utils/ee').default; +const { features } = require('@strapi/strapi/dist/utils/ee'); const { schemas } = require('../../../server/validation/user'); const ssoUserCreationInputExtension = yup diff --git a/packages/core/admin/server/controllers/__tests__/admin.test.js b/packages/core/admin/server/controllers/__tests__/admin.test.js index 3314fdbe34..33afc62f10 100644 --- a/packages/core/admin/server/controllers/__tests__/admin.test.js +++ b/packages/core/admin/server/controllers/__tests__/admin.test.js @@ -4,14 +4,12 @@ jest.mock('@strapi/strapi/dist/utils/ee', () => { const eeModule = () => false; Object.assign(eeModule, { - default: { - features: { - isEnabled() { - return false; - }, - list() { - return []; - }, + features: { + isEnabled() { + return false; + }, + list() { + return []; }, }, }); diff --git a/packages/core/admin/server/controllers/admin.js b/packages/core/admin/server/controllers/admin.js index 273612a3ef..2c1beeae46 100644 --- a/packages/core/admin/server/controllers/admin.js +++ b/packages/core/admin/server/controllers/admin.js @@ -8,7 +8,7 @@ const { exists } = require('fs-extra'); const { env } = require('@strapi/utils'); const { isUsingTypeScript } = require('@strapi/typescript-utils'); // eslint-disable-next-line node/no-extraneous-require -const ee = require('@strapi/strapi/dist/utils/ee').default; +const ee = require('@strapi/strapi/dist/utils/ee'); const { validateUpdateProjectSettings, diff --git a/packages/core/admin/server/services/__tests__/permission.test.js b/packages/core/admin/server/services/__tests__/permission.test.js index 93878dd6d0..7a9d572f06 100644 --- a/packages/core/admin/server/services/__tests__/permission.test.js +++ b/packages/core/admin/server/services/__tests__/permission.test.js @@ -4,7 +4,7 @@ const _ = require('lodash'); const { merge } = require('lodash/fp'); const permissionService = require('../permission'); const { toPermission } = require('../../domain/permission'); -const createEventHub = require('../../../../strapi/dist/services/event-hub').default; +const createEventHub = require('../../../../strapi/dist/services/event-hub'); describe('Permission Service', () => { beforeEach(() => { diff --git a/packages/core/admin/server/services/__tests__/role.test.js b/packages/core/admin/server/services/__tests__/role.test.js index 56342aad33..0f7a9ea12f 100644 --- a/packages/core/admin/server/services/__tests__/role.test.js +++ b/packages/core/admin/server/services/__tests__/role.test.js @@ -4,7 +4,7 @@ const _ = require('lodash'); const roleService = require('../role'); const { SUPER_ADMIN_CODE } = require('../constants'); const { create: createPermission, toPermission } = require('../../domain/permission'); -const createEventHub = require('../../../../strapi/dist/services/event-hub').default; +const createEventHub = require('../../../../strapi/dist/services/event-hub'); describe('Role', () => { describe('create', () => { diff --git a/packages/core/strapi/bin/strapi.js b/packages/core/strapi/bin/strapi.js index 2901968816..d1c523a9a7 100755 --- a/packages/core/strapi/bin/strapi.js +++ b/packages/core/strapi/bin/strapi.js @@ -1,7 +1,2 @@ #!/usr/bin/env node - -'use strict'; - -const { runStrapiCommand } = require('../dist/commands'); - -runStrapiCommand(process.argv); +require('../dist/cli'); diff --git a/packages/core/strapi/index.js b/packages/core/strapi/index.js deleted file mode 100644 index be60030247..0000000000 --- a/packages/core/strapi/index.js +++ /dev/null @@ -1,5 +0,0 @@ -const strapi = require('./dist'); - -module.exports = strapi.default; -module.exports.factories = strapi.factories; -module.exports.compile = strapi.compile; diff --git a/packages/core/strapi/package.json b/packages/core/strapi/package.json index b01dcb650c..926763a3d7 100644 --- a/packages/core/strapi/package.json +++ b/packages/core/strapi/package.json @@ -64,7 +64,9 @@ "url": "https://strapi.io" } ], - "main": "./index.js", + "main": "./dist/index.js", + "module": "./dist/index.mjs", + "source": "./src/index.ts", "types": "./dist/index.d.ts", "bin": "./bin/strapi.js", "files": [ @@ -75,16 +77,14 @@ "index.js" ], "scripts": { - "build": "run -T tsc -p tsconfig.build.json && run copy-files", - "build:ts": "run build", - "clean": "run -T rimraf ./dist", + "build": "run pack-up build && run copy-files", "copy-files": "copyfiles -u 1 -a 'src/**/*.html' 'src/**/*.png' dist", "postinstall": "node ./scripts/postinstall.js", "lint": "run -T eslint .", "prepublishOnly": "yarn clean && yarn build", "test:unit": "run -T jest", "test:unit:watch": "run -T jest --watch", - "watch": "run -T tsc -p tsconfig.build.json -w --preserveWatchOutput" + "watch": "pack-up watch" }, "dependencies": { "@koa/cors": "3.4.3", @@ -142,7 +142,6 @@ "ora": "5.4.1", "package-json": "7.0.0", "qs": "6.11.1", - "resolve-cwd": "3.0.0", "semver": "7.5.4", "statuses": "2.0.1", "typescript": "5.2.2", @@ -150,6 +149,7 @@ "yup": "0.32.9" }, "devDependencies": { + "@strapi/pack-up": "workspace:*", "@strapi/ts-zen": "^0.2.0", "@types/bcryptjs": "2.4.3", "@types/configstore": "5.0.1", diff --git a/packages/core/strapi/packup.config.ts b/packages/core/strapi/packup.config.ts new file mode 100644 index 0000000000..e9d04140f4 --- /dev/null +++ b/packages/core/strapi/packup.config.ts @@ -0,0 +1,16 @@ +// eslint-disable-next-line import/no-extraneous-dependencies +import { defineConfig } from '@strapi/pack-up'; +import { builtinModules } from 'node:module'; + +export default defineConfig({ + bundles: [ + { + source: './src/cli.ts', + require: './dist/cli.js', + runtime: 'node', + }, + ], + externals: [...builtinModules], + preserveModules: true, + runtime: 'node', +}); diff --git a/packages/core/strapi/src/cli.ts b/packages/core/strapi/src/cli.ts new file mode 100644 index 0000000000..0e43d1e51b --- /dev/null +++ b/packages/core/strapi/src/cli.ts @@ -0,0 +1,3 @@ +import { runStrapiCommand } from './commands'; + +runStrapiCommand(process.argv); diff --git a/packages/core/strapi/src/commands/actions/admin/create-user/__tests__/admin.create-user.test.ts b/packages/core/strapi/src/commands/actions/admin/create-user/__tests__/admin.create-user.test.ts index 8c3b11fcec..ebd4c06669 100644 --- a/packages/core/strapi/src/commands/actions/admin/create-user/__tests__/admin.create-user.test.ts +++ b/packages/core/strapi/src/commands/actions/admin/create-user/__tests__/admin.create-user.test.ts @@ -25,7 +25,7 @@ const mock = { admin, }; -jest.mock('../../../../../index', () => { +jest.mock('../../../../../Strapi', () => { const impl: any = jest.fn(() => mock); impl.compile = jest.fn(); diff --git a/packages/core/strapi/src/commands/actions/admin/create-user/action.ts b/packages/core/strapi/src/commands/actions/admin/create-user/action.ts index a1df2caf68..8db49d8fa6 100644 --- a/packages/core/strapi/src/commands/actions/admin/create-user/action.ts +++ b/packages/core/strapi/src/commands/actions/admin/create-user/action.ts @@ -1,7 +1,7 @@ import { yup } from '@strapi/utils'; import _ from 'lodash'; import inquirer from 'inquirer'; -import strapi from '../../../../index'; +import strapi from '../../../../Strapi'; interface CmdOptions { email?: string; diff --git a/packages/core/strapi/src/commands/actions/admin/create-user/command.ts b/packages/core/strapi/src/commands/actions/admin/create-user/command.ts index 5c9da37d53..a6eaa2c172 100644 --- a/packages/core/strapi/src/commands/actions/admin/create-user/command.ts +++ b/packages/core/strapi/src/commands/actions/admin/create-user/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../../utils/helpers'; +import { runAction } from '../../../utils/helpers'; import type { StrapiCommand } from '../../../types'; +import action from './action'; /** * `$ strapi admin:create-user` @@ -13,7 +14,7 @@ const command: StrapiCommand = ({ command }) => { .option('-p, --password ', 'Password of the new admin') .option('-f, --firstname ', 'First name of the new admin') .option('-l, --lastname ', 'Last name of the new admin') - .action(getLocalScript('admin/create-user')); + .action(runAction('admin:create-user', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/admin/reset-user-password/__tests__/admin.reset-user-password.test.ts b/packages/core/strapi/src/commands/actions/admin/reset-user-password/__tests__/admin.reset-user-password.test.ts index 06c1aa93f7..bd8f049f84 100644 --- a/packages/core/strapi/src/commands/actions/admin/reset-user-password/__tests__/admin.reset-user-password.test.ts +++ b/packages/core/strapi/src/commands/actions/admin/reset-user-password/__tests__/admin.reset-user-password.test.ts @@ -16,7 +16,7 @@ const mock = { admin, }; -jest.mock('../../../../../index', () => { +jest.mock('../../../../../Strapi', () => { const impl = jest.fn(() => mock); Object.assign(impl, { diff --git a/packages/core/strapi/src/commands/actions/admin/reset-user-password/action.ts b/packages/core/strapi/src/commands/actions/admin/reset-user-password/action.ts index 8b2443fe32..b91a1a33d6 100644 --- a/packages/core/strapi/src/commands/actions/admin/reset-user-password/action.ts +++ b/packages/core/strapi/src/commands/actions/admin/reset-user-password/action.ts @@ -1,6 +1,6 @@ import _ from 'lodash'; import inquirer from 'inquirer'; -import strapi from '../../../../index'; +import strapi from '../../../../Strapi'; interface CmdOptions { email?: string; diff --git a/packages/core/strapi/src/commands/actions/admin/reset-user-password/command.ts b/packages/core/strapi/src/commands/actions/admin/reset-user-password/command.ts index c8e2ffb8e2..73168ebc4e 100644 --- a/packages/core/strapi/src/commands/actions/admin/reset-user-password/command.ts +++ b/packages/core/strapi/src/commands/actions/admin/reset-user-password/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../../utils/helpers'; import type { StrapiCommand } from '../../../types'; +import { runAction } from '../../../utils/helpers'; +import action from './action'; /** * `$ strapi admin:reset-user-password` @@ -11,7 +12,7 @@ const command: StrapiCommand = ({ command }) => { .description("Reset an admin user's password") .option('-e, --email ', 'The user email') .option('-p, --password ', 'New password for the user') - .action(getLocalScript('admin/reset-user-password')); + .action(runAction('admin:reset-user-password', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/build-command/action.ts b/packages/core/strapi/src/commands/actions/build-command/action.ts index 576ca525b0..d624062e97 100644 --- a/packages/core/strapi/src/commands/actions/build-command/action.ts +++ b/packages/core/strapi/src/commands/actions/build-command/action.ts @@ -1,4 +1,4 @@ -import strapi from '../../..'; +import strapi from '../../../Strapi'; import { buildAdmin } from '../../builders'; interface CmdOptions { diff --git a/packages/core/strapi/src/commands/actions/build-command/command.ts b/packages/core/strapi/src/commands/actions/build-command/command.ts index 2f49aaf65b..42e4cf5a05 100644 --- a/packages/core/strapi/src/commands/actions/build-command/command.ts +++ b/packages/core/strapi/src/commands/actions/build-command/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../utils/helpers'; import type { StrapiCommand } from '../../types'; +import { runAction } from '../../utils/helpers'; +import action from './action'; /** * `$ strapi build` @@ -9,7 +10,7 @@ const command: StrapiCommand = ({ command }) => { .command('build') .option('--no-optimization', 'Build the admin app without optimizing assets') .description('Build the strapi admin app') - .action(getLocalScript('build-command')); // build-command dir to avoid problems with 'build' being commonly ignored + .action(runAction('build', action)); // build-command dir to avoid problems with 'build' being commonly ignored }; export default command; diff --git a/packages/core/strapi/src/commands/actions/components/list/action.ts b/packages/core/strapi/src/commands/actions/components/list/action.ts index 2a818abfb5..70e16add53 100644 --- a/packages/core/strapi/src/commands/actions/components/list/action.ts +++ b/packages/core/strapi/src/commands/actions/components/list/action.ts @@ -1,7 +1,7 @@ import CLITable from 'cli-table3'; import chalk from 'chalk'; -import strapi from '../../../../index'; +import strapi from '../../../../Strapi'; export default async () => { const appContext = await strapi.compile(); diff --git a/packages/core/strapi/src/commands/actions/components/list/command.ts b/packages/core/strapi/src/commands/actions/components/list/command.ts index f6ae35eccf..3a6b36e46a 100644 --- a/packages/core/strapi/src/commands/actions/components/list/command.ts +++ b/packages/core/strapi/src/commands/actions/components/list/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../../utils/helpers'; import type { StrapiCommand } from '../../../types'; +import { runAction } from '../../../utils/helpers'; +import action from './action'; /** * `$ strapi components:list` @@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => { command .command('components:list') .description('List all the application components') - .action(getLocalScript('components/list')); + .action(runAction('components:list', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/configuration/dump/action.ts b/packages/core/strapi/src/commands/actions/configuration/dump/action.ts index db11571933..8916b2e306 100644 --- a/packages/core/strapi/src/commands/actions/configuration/dump/action.ts +++ b/packages/core/strapi/src/commands/actions/configuration/dump/action.ts @@ -1,5 +1,5 @@ import fs from 'fs'; -import strapi from '../../../../index'; +import strapi from '../../../../Strapi'; interface CmdOptions { file?: string; diff --git a/packages/core/strapi/src/commands/actions/configuration/dump/command.ts b/packages/core/strapi/src/commands/actions/configuration/dump/command.ts index d267abec6b..8a77f95c8c 100644 --- a/packages/core/strapi/src/commands/actions/configuration/dump/command.ts +++ b/packages/core/strapi/src/commands/actions/configuration/dump/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../../utils/helpers'; import type { StrapiCommand } from '../../../types'; +import { runAction } from '../../../utils/helpers'; +import action from './action'; /** * `$ strapi configuration:dump` @@ -11,7 +12,7 @@ const command: StrapiCommand = ({ command }) => { .description('Dump configurations of your application') .option('-f, --file ', 'Output file, default output is stdout') .option('-p, --pretty', 'Format the output JSON with indentation and line breaks', false) - .action(getLocalScript('configuration/dump')); + .action(runAction('configuration:dump', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/configuration/restore/action.ts b/packages/core/strapi/src/commands/actions/configuration/restore/action.ts index 7e340021fd..0224206703 100644 --- a/packages/core/strapi/src/commands/actions/configuration/restore/action.ts +++ b/packages/core/strapi/src/commands/actions/configuration/restore/action.ts @@ -2,7 +2,7 @@ import fs from 'fs'; import _ from 'lodash'; import type { Database } from '@strapi/database'; -import strapi from '../../../../index'; +import strapi from '../../../../Strapi'; type Strategy = 'replace' | 'merge' | 'keep'; diff --git a/packages/core/strapi/src/commands/actions/configuration/restore/command.ts b/packages/core/strapi/src/commands/actions/configuration/restore/command.ts index 2b376265d6..b1c7b2e6e3 100644 --- a/packages/core/strapi/src/commands/actions/configuration/restore/command.ts +++ b/packages/core/strapi/src/commands/actions/configuration/restore/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../../utils/helpers'; import type { StrapiCommand } from '../../../types'; +import { runAction } from '../../../utils/helpers'; +import action from './action'; /** * `$ strapi configuration:restore` @@ -11,7 +12,7 @@ const command: StrapiCommand = ({ command }) => { .description('Restore configurations of your application') .option('-f, --file ', 'Input file, default input is stdin') .option('-s, --strategy ', 'Strategy name, one of: "replace", "merge", "keep"') - .action(getLocalScript('configuration/restore')); + .action(runAction('configuration:restore', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/console/action.ts b/packages/core/strapi/src/commands/actions/console/action.ts index 4418ebd274..f3769e5a9a 100644 --- a/packages/core/strapi/src/commands/actions/console/action.ts +++ b/packages/core/strapi/src/commands/actions/console/action.ts @@ -1,5 +1,5 @@ import REPL from 'repl'; -import strapi from '../../../index'; +import strapi from '../../../Strapi'; /** * `$ strapi console` diff --git a/packages/core/strapi/src/commands/actions/console/command.ts b/packages/core/strapi/src/commands/actions/console/command.ts index 4d44791fee..7270710eaf 100644 --- a/packages/core/strapi/src/commands/actions/console/command.ts +++ b/packages/core/strapi/src/commands/actions/console/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../utils/helpers'; import type { StrapiCommand } from '../../types'; +import { runAction } from '../../utils/helpers'; +import action from './action'; /** * `$ strapi console` @@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => { command .command('console') .description('Open the Strapi framework console') - .action(getLocalScript('console')); + .action(runAction('console', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/content-types/list/action.ts b/packages/core/strapi/src/commands/actions/content-types/list/action.ts index e9448f2015..93e2f45fd1 100644 --- a/packages/core/strapi/src/commands/actions/content-types/list/action.ts +++ b/packages/core/strapi/src/commands/actions/content-types/list/action.ts @@ -1,7 +1,7 @@ import CLITable from 'cli-table3'; import chalk from 'chalk'; -import strapi from '../../../../index'; +import strapi from '../../../../Strapi'; export default async () => { const appContext = await strapi.compile(); diff --git a/packages/core/strapi/src/commands/actions/content-types/list/command.ts b/packages/core/strapi/src/commands/actions/content-types/list/command.ts index 4cb4d8b2c2..cabff81b49 100644 --- a/packages/core/strapi/src/commands/actions/content-types/list/command.ts +++ b/packages/core/strapi/src/commands/actions/content-types/list/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../../utils/helpers'; import type { StrapiCommand } from '../../../types'; +import { runAction } from '../../../utils/helpers'; +import action from './action'; /** * `$ strapi content-types:list` @@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => { command .command('content-types:list') .description('List all the application content-types') - .action(getLocalScript('content-types/list')); + .action(runAction('content-types:list', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/controllers/list/action.ts b/packages/core/strapi/src/commands/actions/controllers/list/action.ts index 9072d17c4a..5257b65eb8 100644 --- a/packages/core/strapi/src/commands/actions/controllers/list/action.ts +++ b/packages/core/strapi/src/commands/actions/controllers/list/action.ts @@ -1,7 +1,7 @@ import CLITable from 'cli-table3'; import chalk from 'chalk'; -import strapi from '../../../../index'; +import strapi from '../../../../Strapi'; export default async () => { const appContext = await strapi.compile(); diff --git a/packages/core/strapi/src/commands/actions/controllers/list/command.ts b/packages/core/strapi/src/commands/actions/controllers/list/command.ts index 497204ec9a..081a947013 100644 --- a/packages/core/strapi/src/commands/actions/controllers/list/command.ts +++ b/packages/core/strapi/src/commands/actions/controllers/list/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../../utils/helpers'; import type { StrapiCommand } from '../../../types'; +import { runAction } from '../../../utils/helpers'; +import action from './action'; /** * `$ strapi controllers:list` @@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => { command .command('controllers:list') .description('List all the application controllers') - .action(getLocalScript('controllers/list')); + .action(runAction('controllers:list', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/develop/action.ts b/packages/core/strapi/src/commands/actions/develop/action.ts index 5715d6eb05..d923c8993c 100644 --- a/packages/core/strapi/src/commands/actions/develop/action.ts +++ b/packages/core/strapi/src/commands/actions/develop/action.ts @@ -9,7 +9,7 @@ import tsUtils from '@strapi/typescript-utils'; import type { Strapi } from '@strapi/types'; import loadConfiguration from '../../../core/app-configuration'; -import strapi from '../../../index'; +import strapi from '../../../Strapi'; import { buildTypeScript, buildAdmin } from '../../builders'; interface CmdOptions { @@ -23,7 +23,7 @@ interface CmdOptions { * `$ strapi develop` * */ -export default async ({ build, watchAdmin, polling, browser }: CmdOptions) => { +export default async ({ build, watchAdmin, polling, browser }: CmdOptions): Promise => { const appDir = process.cwd(); const isTSProject = await tsUtils.isUsingTypeScript(appDir); @@ -183,7 +183,7 @@ const workerProcess = async ({ } }); - return strapiInstance.start(); + strapiInstance.start(); }; /** diff --git a/packages/core/strapi/src/commands/actions/develop/command.ts b/packages/core/strapi/src/commands/actions/develop/command.ts index 5c8bcfcf39..f585df98fd 100644 --- a/packages/core/strapi/src/commands/actions/develop/command.ts +++ b/packages/core/strapi/src/commands/actions/develop/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../utils/helpers'; import type { StrapiCommand } from '../../types'; +import { runAction } from '../../utils/helpers'; +import action from './action'; /** * `$ strapi develop` @@ -13,7 +14,7 @@ const command: StrapiCommand = ({ command }) => { .option('--polling', 'Watch for file changes in network directories', false) .option('--browser ', 'Open the browser', true) .description('Start your Strapi application in development mode') - .action(getLocalScript('develop')); + .action(runAction('develop', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/hooks/list/action.ts b/packages/core/strapi/src/commands/actions/hooks/list/action.ts index 98459387c8..3706341981 100644 --- a/packages/core/strapi/src/commands/actions/hooks/list/action.ts +++ b/packages/core/strapi/src/commands/actions/hooks/list/action.ts @@ -1,7 +1,7 @@ import CLITable from 'cli-table3'; import chalk from 'chalk'; -import strapi from '../../../../index'; +import strapi from '../../../../Strapi'; export default async () => { const appContext = await strapi.compile(); diff --git a/packages/core/strapi/src/commands/actions/hooks/list/command.ts b/packages/core/strapi/src/commands/actions/hooks/list/command.ts index 91631aac5d..38a24f66a2 100644 --- a/packages/core/strapi/src/commands/actions/hooks/list/command.ts +++ b/packages/core/strapi/src/commands/actions/hooks/list/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../../utils/helpers'; import type { StrapiCommand } from '../../../types'; +import { runAction } from '../../../utils/helpers'; +import action from './action'; /** * `$ strapi hooks:list` @@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => { command .command('hooks:list') .description('List all the application hooks') - .action(getLocalScript('hooks/list')); + .action(runAction('hooks:list', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/install/command.ts b/packages/core/strapi/src/commands/actions/install/command.ts index f1170e3b60..147d7005ed 100644 --- a/packages/core/strapi/src/commands/actions/install/command.ts +++ b/packages/core/strapi/src/commands/actions/install/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../utils/helpers'; import type { StrapiCommand } from '../../types'; +import { runAction } from '../../utils/helpers'; +import action from './action'; /** * `$ strapi install` @@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => { command .command('install [plugins...]') .description('Install a Strapi plugin') - .action(getLocalScript('install')); + .action(runAction('install', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/middlewares/list/action.ts b/packages/core/strapi/src/commands/actions/middlewares/list/action.ts index a5c9aaad42..30adc46d7d 100644 --- a/packages/core/strapi/src/commands/actions/middlewares/list/action.ts +++ b/packages/core/strapi/src/commands/actions/middlewares/list/action.ts @@ -1,7 +1,7 @@ import CLITable from 'cli-table3'; import chalk from 'chalk'; -import strapi from '../../../../index'; +import strapi from '../../../../Strapi'; export default async () => { const appContext = await strapi.compile(); diff --git a/packages/core/strapi/src/commands/actions/middlewares/list/command.ts b/packages/core/strapi/src/commands/actions/middlewares/list/command.ts index b14298eb76..24c0d9ee08 100644 --- a/packages/core/strapi/src/commands/actions/middlewares/list/command.ts +++ b/packages/core/strapi/src/commands/actions/middlewares/list/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../../utils/helpers'; import type { StrapiCommand } from '../../../types'; +import { runAction } from '../../../utils/helpers'; +import action from './action'; /** * `$ strapi middlewares:list` @@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => { command .command('middlewares:list') .description('List all the application middlewares') - .action(getLocalScript('middlewares/list')); + .action(runAction('middlewares:list', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/plugin/build-command/command.ts b/packages/core/strapi/src/commands/actions/plugin/build-command/command.ts index 1607cc5fb7..e5334c532c 100644 --- a/packages/core/strapi/src/commands/actions/plugin/build-command/command.ts +++ b/packages/core/strapi/src/commands/actions/plugin/build-command/command.ts @@ -1,6 +1,7 @@ import { forceOption } from '../../../utils/commander'; -import { getLocalScript } from '../../../utils/helpers'; import type { StrapiCommand } from '../../../types'; +import { runAction } from '../../../utils/helpers'; +import action from './action'; /** * `$ strapi plugin:build` @@ -11,7 +12,7 @@ const command: StrapiCommand = ({ command }) => { .description('Bundle your strapi plugin for publishing.') .addOption(forceOption) .option('-d, --debug', 'Enable debugging mode with verbose logs', false) - .action(getLocalScript('plugin/build-command')); + .action(runAction('plugin:build', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/policies/list/action.ts b/packages/core/strapi/src/commands/actions/policies/list/action.ts index d859c9fbe9..14a5104956 100644 --- a/packages/core/strapi/src/commands/actions/policies/list/action.ts +++ b/packages/core/strapi/src/commands/actions/policies/list/action.ts @@ -1,7 +1,7 @@ import CLITable from 'cli-table3'; import chalk from 'chalk'; -import strapi from '../../../../index'; +import strapi from '../../../../Strapi'; export default async () => { const appContext = await strapi.compile(); diff --git a/packages/core/strapi/src/commands/actions/policies/list/command.ts b/packages/core/strapi/src/commands/actions/policies/list/command.ts index e11b076489..9a22c5a768 100644 --- a/packages/core/strapi/src/commands/actions/policies/list/command.ts +++ b/packages/core/strapi/src/commands/actions/policies/list/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../../utils/helpers'; import type { StrapiCommand } from '../../../types'; +import { runAction } from '../../../utils/helpers'; +import action from './action'; /** * `$ strapi policies:list` @@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => { command .command('policies:list') .description('List all the application policies') - .action(getLocalScript('policies/list')); + .action(runAction('policies:list', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/report/action.ts b/packages/core/strapi/src/commands/actions/report/action.ts index 7e509adbf4..592cab2a72 100644 --- a/packages/core/strapi/src/commands/actions/report/action.ts +++ b/packages/core/strapi/src/commands/actions/report/action.ts @@ -1,5 +1,5 @@ import { EOL } from 'os'; -import strapi from '../../../index'; +import strapi from '../../../Strapi'; interface CmdOptions { uuid: boolean; diff --git a/packages/core/strapi/src/commands/actions/report/command.ts b/packages/core/strapi/src/commands/actions/report/command.ts index ee9ae7b0a6..836884fc53 100644 --- a/packages/core/strapi/src/commands/actions/report/command.ts +++ b/packages/core/strapi/src/commands/actions/report/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../utils/helpers'; import type { StrapiCommand } from '../../types'; +import { runAction } from '../../utils/helpers'; +import action from './action'; /** * `$ strapi report` @@ -11,7 +12,7 @@ const command: StrapiCommand = ({ command }) => { .option('-u, --uuid', 'Include Project UUID') .option('-d, --dependencies', 'Include Project Dependencies') .option('--all', 'Include All Information') - .action(getLocalScript('report')); + .action(runAction('report', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/routes/list/action.ts b/packages/core/strapi/src/commands/actions/routes/list/action.ts index 2d623fd359..eb7c883027 100644 --- a/packages/core/strapi/src/commands/actions/routes/list/action.ts +++ b/packages/core/strapi/src/commands/actions/routes/list/action.ts @@ -2,7 +2,7 @@ import CLITable from 'cli-table3'; import chalk from 'chalk'; import { toUpper } from 'lodash/fp'; -import strapi from '../../../../index'; +import strapi from '../../../../Strapi'; export default async () => { const appContext = await strapi.compile(); diff --git a/packages/core/strapi/src/commands/actions/routes/list/command.ts b/packages/core/strapi/src/commands/actions/routes/list/command.ts index a24b2bfba5..3f87cdf4fb 100644 --- a/packages/core/strapi/src/commands/actions/routes/list/command.ts +++ b/packages/core/strapi/src/commands/actions/routes/list/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../../utils/helpers'; import type { StrapiCommand } from '../../../types'; +import { runAction } from '../../../utils/helpers'; +import action from './action'; /** * `$ strapi routes:list`` @@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => { command .command('routes:list') .description('List all the application routes') - .action(getLocalScript('routes/list')); + .action(runAction('routes:list', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/services/list/action.ts b/packages/core/strapi/src/commands/actions/services/list/action.ts index 918532889b..09d7b0bae4 100644 --- a/packages/core/strapi/src/commands/actions/services/list/action.ts +++ b/packages/core/strapi/src/commands/actions/services/list/action.ts @@ -1,7 +1,7 @@ import CLITable from 'cli-table3'; import chalk from 'chalk'; -import strapi from '../../../../index'; +import strapi from '../../../../Strapi'; export default async () => { const appContext = await strapi.compile(); diff --git a/packages/core/strapi/src/commands/actions/services/list/command.ts b/packages/core/strapi/src/commands/actions/services/list/command.ts index 99024a77d7..edd2fc363e 100644 --- a/packages/core/strapi/src/commands/actions/services/list/command.ts +++ b/packages/core/strapi/src/commands/actions/services/list/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../../utils/helpers'; import type { StrapiCommand } from '../../../types'; +import { runAction } from '../../../utils/helpers'; +import action from './action'; /** * `$ strapi services:list` @@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => { command .command('services:list') .description('List all the application services') - .action(getLocalScript('services/list')); + .action(runAction('services:list', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/start/action.ts b/packages/core/strapi/src/commands/actions/start/action.ts index 863c0b8ea0..6b78414491 100644 --- a/packages/core/strapi/src/commands/actions/start/action.ts +++ b/packages/core/strapi/src/commands/actions/start/action.ts @@ -1,6 +1,6 @@ import fs from 'fs'; import tsUtils from '@strapi/typescript-utils'; -import strapi from '../../../index'; +import strapi from '../../../Strapi'; /** * `$ strapi start` @@ -19,5 +19,5 @@ export default async () => { `${outDir} directory not found. Please run the build command before starting your application` ); - return strapi({ appDir, distDir }).start(); + strapi({ appDir, distDir }).start(); }; diff --git a/packages/core/strapi/src/commands/actions/start/command.ts b/packages/core/strapi/src/commands/actions/start/command.ts index a221dfeea5..b8d34bf351 100644 --- a/packages/core/strapi/src/commands/actions/start/command.ts +++ b/packages/core/strapi/src/commands/actions/start/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../utils/helpers'; import type { StrapiCommand } from '../../types'; +import { runAction } from '../../utils/helpers'; +import action from './action'; /** * `$ strapi start` @@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => { command .command('start') .description('Start your Strapi application') - .action(getLocalScript('start')); + .action(runAction('start', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/telemetry/disable/command.ts b/packages/core/strapi/src/commands/actions/telemetry/disable/command.ts index 3f01a377c5..971c24319b 100644 --- a/packages/core/strapi/src/commands/actions/telemetry/disable/command.ts +++ b/packages/core/strapi/src/commands/actions/telemetry/disable/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../../utils/helpers'; import type { StrapiCommand } from '../../../types'; +import { runAction } from '../../../utils/helpers'; +import action from './action'; /** * `$ strapi telemetry:disable` @@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => { command .command('telemetry:disable') .description('Disable anonymous telemetry and metadata sending to Strapi analytics') - .action(getLocalScript('telemetry/disable')); + .action(runAction('telemetry:disable', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/telemetry/enable/command.ts b/packages/core/strapi/src/commands/actions/telemetry/enable/command.ts index c71d63d6a1..87342b3e22 100644 --- a/packages/core/strapi/src/commands/actions/telemetry/enable/command.ts +++ b/packages/core/strapi/src/commands/actions/telemetry/enable/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../../utils/helpers'; import type { StrapiCommand } from '../../../types'; +import { runAction } from '../../../utils/helpers'; +import action from './action'; /** * `$ strapi telemetry:enable` @@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => { command .command('telemetry:enable') .description('Enable anonymous telemetry and metadata sending to Strapi analytics') - .action(getLocalScript('telemetry/enable')); + .action(runAction('telemetry:enable', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/templates/generate/command.ts b/packages/core/strapi/src/commands/actions/templates/generate/command.ts index 150a53db07..cb2d03f60b 100644 --- a/packages/core/strapi/src/commands/actions/templates/generate/command.ts +++ b/packages/core/strapi/src/commands/actions/templates/generate/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../../utils/helpers'; import type { StrapiCommand } from '../../../types'; +import { runAction } from '../../../utils/helpers'; +import action from './action'; /** *`$ strapi templates:generate ` @@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => { command .command('templates:generate ') .description('Generate template from Strapi project') - .action(getLocalScript('templates/generate')); + .action(runAction('templates:generate', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/ts/generate-types/action.ts b/packages/core/strapi/src/commands/actions/ts/generate-types/action.ts index a993bb2fa6..28f23d9033 100644 --- a/packages/core/strapi/src/commands/actions/ts/generate-types/action.ts +++ b/packages/core/strapi/src/commands/actions/ts/generate-types/action.ts @@ -1,5 +1,5 @@ import tsUtils from '@strapi/typescript-utils'; -import strapi from '../../../../index'; +import strapi from '../../../../Strapi'; interface CmdOptions { debug?: boolean; diff --git a/packages/core/strapi/src/commands/actions/ts/generate-types/command.ts b/packages/core/strapi/src/commands/actions/ts/generate-types/command.ts index b394d58c4f..787110793f 100644 --- a/packages/core/strapi/src/commands/actions/ts/generate-types/command.ts +++ b/packages/core/strapi/src/commands/actions/ts/generate-types/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../../utils/helpers'; import type { StrapiCommand } from '../../../types'; +import { runAction } from '../../../utils/helpers'; +import action from './action'; /** * `$ strapi ts:generate-types` @@ -15,7 +16,7 @@ const command: StrapiCommand = ({ command }) => { '-o, --out-dir ', 'Specify a relative root directory in which the definitions will be generated. Changing this value might break types exposed by Strapi that relies on generated types.' ) - .action(getLocalScript('ts/generate-types')); + .action(runAction('ts:generate-types', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/uninstall/command.ts b/packages/core/strapi/src/commands/actions/uninstall/command.ts index 971c222cf2..b4a9cd3001 100644 --- a/packages/core/strapi/src/commands/actions/uninstall/command.ts +++ b/packages/core/strapi/src/commands/actions/uninstall/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../utils/helpers'; import type { StrapiCommand } from '../../types'; +import { runAction } from '../../utils/helpers'; +import action from './action'; /** * `$ strapi uninstall` @@ -9,7 +10,7 @@ const command: StrapiCommand = ({ command }) => { .command('uninstall [plugins...]') .description('Uninstall a Strapi plugin') .option('-d, --delete-files', 'Delete files', false) - .action(getLocalScript('uninstall')); + .action(runAction('uninstall', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/actions/watch-admin/action.ts b/packages/core/strapi/src/commands/actions/watch-admin/action.ts index a8b110686f..b9c88d66ad 100644 --- a/packages/core/strapi/src/commands/actions/watch-admin/action.ts +++ b/packages/core/strapi/src/commands/actions/watch-admin/action.ts @@ -3,7 +3,7 @@ import { getConfigUrls, getAbsoluteServerUrl } from '@strapi/utils'; import { getEnabledPlugins } from '../../../core/loaders/plugins/get-enabled-plugins'; import addSlash from '../../../utils/addSlash'; -import strapi from '../../../index'; +import strapi from '../../../Strapi'; export default async ({ browser }: { browser: boolean }) => { const appContext = await strapi.compile(); diff --git a/packages/core/strapi/src/commands/actions/watch-admin/command.ts b/packages/core/strapi/src/commands/actions/watch-admin/command.ts index 7ed66304d1..c1871f71af 100644 --- a/packages/core/strapi/src/commands/actions/watch-admin/command.ts +++ b/packages/core/strapi/src/commands/actions/watch-admin/command.ts @@ -1,5 +1,6 @@ -import { getLocalScript } from '../../utils/helpers'; import type { StrapiCommand } from '../../types'; +import { runAction } from '../../utils/helpers'; +import action from './action'; /** * `$ strapi watch-admin` @@ -9,7 +10,7 @@ const command: StrapiCommand = ({ command }) => { .command('watch-admin') .option('--browser ', 'Open the browser', true) .description('Start the admin development server') - .action(getLocalScript('watch-admin')); + .action(runAction('watch-admin', action)); }; export default command; diff --git a/packages/core/strapi/src/commands/builders/admin.ts b/packages/core/strapi/src/commands/builders/admin.ts index 55a80c1349..d44223f3e0 100644 --- a/packages/core/strapi/src/commands/builders/admin.ts +++ b/packages/core/strapi/src/commands/builders/admin.ts @@ -5,7 +5,7 @@ import { getConfigUrls } from '@strapi/utils'; import ee from '../../utils/ee'; import addSlash from '../../utils/addSlash'; -import strapi from '../../index'; +import strapi from '../../Strapi'; import { getEnabledPlugins } from '../../core/loaders/plugins/get-enabled-plugins'; export interface Options { diff --git a/packages/core/strapi/src/commands/utils/helpers.ts b/packages/core/strapi/src/commands/utils/helpers.ts index c66a3f4976..9a7a57e690 100644 --- a/packages/core/strapi/src/commands/utils/helpers.ts +++ b/packages/core/strapi/src/commands/utils/helpers.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-var-requires */ import chalk from 'chalk'; import { has, isString, isArray } from 'lodash/fp'; -import resolveCwd from 'resolve-cwd'; import { prompt } from 'inquirer'; import boxen from 'boxen'; import type { Command } from 'commander'; @@ -133,26 +132,14 @@ const assertCwdContainsStrapiProject = (name: string) => { } }; -const getLocalScript = - (name: string) => +const runAction = + (name: string, action: (...args: any[]) => Promise) => (...args: unknown[]) => { assertCwdContainsStrapiProject(name); - const cmdPath = resolveCwd.silent(`@strapi/strapi/dist/commands/actions/${name}/action`); - if (!cmdPath) { - console.log( - `Error loading the local ${chalk.yellow( - name - )} command. Strapi might not be installed in your "node_modules". You may need to run "yarn install".` - ); - process.exit(1); - } - - const script = require(cmdPath).default; - Promise.resolve() .then(() => { - return script(...args); + return action(...args); }) .catch((error) => { console.error(error); @@ -210,7 +197,7 @@ export { assertUrlHasProtocol, ifOptions, readableBytes, - getLocalScript, + runAction, assertCwdContainsStrapiProject, notifyExperimentalCommand, }; diff --git a/packages/core/strapi/src/index.ts b/packages/core/strapi/src/index.ts index e9c8a0342d..48f0e2d8f6 100644 --- a/packages/core/strapi/src/index.ts +++ b/packages/core/strapi/src/index.ts @@ -2,7 +2,4 @@ import strapiFactory from './Strapi'; export type * from '@strapi/types'; -export * as factories from './factories'; -export { default as compile } from './compile'; - export default strapiFactory; diff --git a/packages/core/strapi/tsconfig.eslint.json b/packages/core/strapi/tsconfig.eslint.json index b531808514..d0192f9ff6 100644 --- a/packages/core/strapi/tsconfig.eslint.json +++ b/packages/core/strapi/tsconfig.eslint.json @@ -3,6 +3,6 @@ "compilerOptions": { "noEmit": true }, - "include": ["src"], + "include": ["src", "packup.config.ts"], "exclude": ["node_modules"] } diff --git a/yarn.lock b/yarn.lock index 276a785a52..3ef4e5c601 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8262,6 +8262,7 @@ __metadata: "@strapi/generate-new": 4.14.4 "@strapi/generators": 4.14.4 "@strapi/logger": 4.14.4 + "@strapi/pack-up": "workspace:*" "@strapi/permissions": 4.14.4 "@strapi/plugin-content-manager": 4.14.4 "@strapi/plugin-content-type-builder": 4.14.4 @@ -8325,7 +8326,6 @@ __metadata: ora: 5.4.1 package-json: 7.0.0 qs: 6.11.1 - resolve-cwd: 3.0.0 semver: 7.5.4 statuses: 2.0.1 supertest: 6.3.3