chore: build strapi permissions with pack-up (#18309)

This commit is contained in:
Josh 2023-10-05 18:13:45 +01:00 committed by GitHub
parent 3a1cb32f56
commit 82035f18c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 53 additions and 28 deletions

View File

@ -121,7 +121,7 @@ jobs:
- uses: nrwl/nx-set-shas@v3
- name: Monorepo install
uses: ./.github/actions/yarn-nm-install
- name: Run build for admin-test-utils
- name: Run build:ts for admin-test-utils & helper-plugin
run: yarn build --projects=@strapi/admin-test-utils,@strapi/helper-plugin --skip-nx-cache
- name: Run test
run: yarn nx affected --target=test:front --nx-ignore-cycles

View File

@ -1,6 +0,0 @@
export interface Permission {
action: string;
subject?: string | object | null;
properties?: object;
conditions?: string[];
}

View File

@ -8,7 +8,9 @@ import { hasPermissions } from '../utils/hasPermissions';
import { LoadingIndicatorPage } from './LoadingIndicatorPage';
import type { Permission } from '@strapi/permissions';
import type { domain } from '@strapi/permissions';
type Permission = domain.permission.Permission;
export interface CheckPagePermissions {
children: React.ReactNode;

View File

@ -4,7 +4,9 @@ import { useNotification } from '../features/Notifications';
import { useRBACProvider } from '../features/RBAC';
import { hasPermissions } from '../utils/hasPermissions';
import type { Permission } from '@strapi/permissions';
import type { domain } from '@strapi/permissions';
type Permission = domain.permission.Permission;
// NOTE: this component is very similar to the CheckPagePermissions
// except that it does not handle redirections nor loading state

View File

@ -1,8 +1,10 @@
import * as React from 'react';
import type { Permission } from '@strapi/permissions';
import type { domain } from '@strapi/permissions';
import type { QueryObserverBaseResult } from 'react-query';
type Permission = domain.permission.Permission;
/* -------------------------------------------------------------------------------------------------
* Context
* -----------------------------------------------------------------------------------------------*/

View File

@ -2,7 +2,9 @@ import * as React from 'react';
import { TranslationMessage } from '../types';
import type { Permission } from '@strapi/permissions';
import type { domain } from '@strapi/permissions';
type Permission = domain.permission.Permission;
interface MenuItem {
to: string;

View File

@ -1,6 +1,6 @@
import { useCallback, useMemo } from 'react';
import { parse, ParsedQs, stringify } from 'qs';
import { parse, stringify } from 'qs';
import { useHistory, useLocation } from 'react-router-dom';
const useQueryParams = <TQuery extends Record<string, unknown>>(initialParams?: TQuery) => {

View File

@ -6,9 +6,11 @@ import { useRBACProvider } from '../features/RBAC';
import { useFetchClient } from './useFetchClient';
import type { Permission } from '@strapi/permissions';
import type { domain } from '@strapi/permissions';
import type { AxiosResponse } from 'axios';
type Permission = domain.permission.Permission;
type AllowedActions = Record<string, boolean>;
export const useRBAC = (

View File

@ -1,8 +1,10 @@
import { getFetchClient } from './getFetchClient';
import type { Permission } from '@strapi/permissions';
import type { domain } from '@strapi/permissions';
import type { GenericAbortSignal } from 'axios';
type Permission = domain.permission.Permission;
const findMatchingPermissions = (userPermissions: Permission[], permissions: Permission[]) =>
userPermissions.reduce<Permission[]>((acc, curr) => {
const associatedPermission = permissions.find(

View File

@ -1,5 +1,3 @@
import { Permission } from '@strapi/permissions';
import {
hasPermissions,
findMatchingPermissions,
@ -7,6 +5,10 @@ import {
shouldCheckPermissions,
} from '../hasPermissions';
import type { domain } from '@strapi/permissions';
type Permission = domain.permission.Permission;
const hasPermissionsTestData: Record<string, Record<string, Permission[]>> = {
userPermissions: {
user1: [

View File

@ -19,20 +19,22 @@
"url": "https://strapi.io"
}
],
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"source": "./src/index.ts",
"types": "./dist/index.d.ts",
"files": [
"./dist"
],
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "run -T tsc",
"build:ts": "run build",
"watch": "run -T tsc -w --preserveWatchOutput",
"build": "pack-up build",
"clean": "run -T rimraf ./dist",
"lint": "run -T eslint .",
"prepublishOnly": "yarn clean && yarn build",
"test:ts": "run -T tsc --noEmit",
"test:unit": "run -T jest",
"test:unit:watch": "run -T jest --watch",
"lint": "run -T eslint ."
"watch": "pack-up watch"
},
"dependencies": {
"@casl/ability": "6.5.0",
@ -42,6 +44,7 @@
"sift": "16.0.1"
},
"devDependencies": {
"@strapi/pack-up": "workspace:*",
"eslint-config-custom": "4.14.3",
"tsconfig": "4.14.3"
},

View File

@ -0,0 +1,6 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineConfig } from '@strapi/pack-up';
export default defineConfig({
runtime: 'node',
});

View File

@ -1,7 +1,7 @@
import _ from 'lodash';
import { subject } from '@casl/ability';
import { providerFactory } from '@strapi/utils';
import permissions from '..';
import * as permissions from '../index';
import type { HookName } from '../engine/hooks';
import type { Permission } from '../domain/permission';

View File

@ -1,7 +1,4 @@
import * as domain from './domain';
import * as engine from './engine';
export = {
domain,
engine,
};
export { domain, engine };

View File

@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"include": ["src"],
"exclude": ["**/__tests__/**"]
}

View File

@ -3,6 +3,6 @@
"compilerOptions": {
"noEmit": true
},
"include": ["src"],
"include": ["src", "packup.config.ts"],
"exclude": ["node_modules"]
}

View File

@ -39,6 +39,7 @@
"clean": "run -T rimraf ./dist",
"lint": "run -T eslint .",
"prepublishOnly": "yarn clean && yarn build",
"test:ts": "run -T tsc --noEmit",
"test:unit": "run -T jest",
"test:unit:watch": "run -T jest --watch",
"watch": "run -T pack-up watch"

View File

@ -7817,6 +7817,7 @@ __metadata:
resolution: "@strapi/permissions@workspace:packages/core/permissions"
dependencies:
"@casl/ability": 6.5.0
"@strapi/pack-up": "workspace:*"
"@strapi/utils": 4.14.3
eslint-config-custom: 4.14.3
lodash: 4.17.21