chore: use rollup

chore: fetch template only if name matches name convention

chore: linting

chore: fix tests

chore: fix npm scripts

test: try to fix test
This commit is contained in:
Alexandre Bodin 2025-01-16 09:05:49 +01:00
parent fe4cd196c9
commit 92055a7fb1
337 changed files with 2209 additions and 1603 deletions

View File

@ -14,4 +14,4 @@ runs:
- if: ${{ steps.yarn-build-cache.outputs.cache-hit != 'true' }}
name: 📥 Run build
shell: bash
run: yarn nx run-many --target=build --nx-ignore-cycles --skip-nx-cache
run: yarn nx run-many --targets build --nx-ignore-cycles --skip-nx-cache

1
.gitignore vendored
View File

@ -157,6 +157,7 @@ tests/cli/.env
############################
examples/**/types/generated
.nx/cache
.nx/workspace-data
# Ignore yarn.lock inside templates
templates/yarn.lock

View File

@ -1 +1,7 @@
examples/**
.gitignore
.gitattributes
LICENSE
README.md
.npmignore
dist/

View File

@ -4,3 +4,5 @@ dist
build
.strapi
/.nx/cache
/.nx/workspace-data

View File

@ -1,33 +0,0 @@
---
title: Introduction
tags:
- pack-up
- bundling
- packages
---
## What is pack-up?
Pack-Up is primarily a CLI interface to develop & build CJS/ESM interopable (meaning you can import your library in either environment with little effort)
packages. It's built on top of [vite](https://vitejs.dev/), but also utilises [esbuild](https://esbuild.github.io/) for certain parts. It also offers a
node API that can be used to build other tools on top of it.
It's designed to have as little dependencies as possible making it easier to react to changes in the ecosystem as and when we need too.
The configuration format at present is limited and is expected to grow with real-world requirements.
## Why do we need it?
Creating packages that work in both CJS and ESM environments is a pain. This tooling library aims to make it easier for _all_ developers,
if you're creating _any_ new project you should bundle your code and therefore use this tool to initialise / build & check the project.
We use internally to bundle all our libraries. Strapi also has it's own plugin system that realistically benefits from having the code bundled
for both the client and server packages of said plugins. Initially we wanted to keep this inside the `@strapi/strapi` package but realised
soon after that this package was required to be more low level than the former.
## Further reading
import DocCardList from '@theme/DocCardList';
import { useCurrentSidebarCategory } from '@docusaurus/theme-common';
<DocCardList
items={useCurrentSidebarCategory().items.filter((item) => item.label !== 'Introduction')}
/>

View File

@ -1,17 +0,0 @@
---
title: Overview
tags:
- pack-up
- CLI
---
Each command has a `node` api equivalent. This is useful if you want to use `pack-up` in your own scripts.
## Commands
import DocCardList from '@theme/DocCardList';
import { useCurrentSidebarCategory } from '@docusaurus/theme-common';
<DocCardList
items={useCurrentSidebarCategory().items.filter((item) => item.label !== 'Overview')}
/>

View File

@ -1,48 +0,0 @@
---
title: Init
tags:
- pack-up
- CLI
---
## Usage
```bash
$ npx @strapi/pack-up init my-package
```
Creates a new package at the given path, by default uses the inbuilt template sensible options for your package to choose from.
### Options
- `--template [path]` path to a custom template of type `TemplateOrTemplateResolver`.
## API
### Usage
```ts
import { init } from '@strapi/pack-up';
init({
path: 'my-package',
});
```
## Typescript
```ts
interface InitOptions {
cwd?: string;
debug?: boolean;
path: string;
silent?: boolean;
template?: TemplateOrTemplateResolver | string;
}
type Init = (options: InitOptions) => Promise<void>;
type TemplateOrTemplateResolver = Template | TemplateResolver;
```
You can see `Template` and `TemplateResolver` in on [Templates](/docs/utils/pack-up/templates#template)

View File

@ -1,45 +0,0 @@
---
title: Build
tags:
- pack-up
- CLI
---
## Usage
```bash
$ yarn pack-up build
```
Builds your current package based on the configuration in your `package.json` and `package.config.ts` (if applicable).
### Options
- `--minify` minifies the output (default `false`).
- `--sourcemap` generates sourcemaps for the output (default `true`).
## API
### Usage
```ts
import { build } from '@strapi/pack-up';
build();
```
## Typescript
```ts
interface BuildOptions {
configFile: false;
config?: Config;
cwd?: string;
debug?: boolean;
minify?: boolean;
silent?: boolean;
sourcemap?: boolean;
}
type Build = (options?: BuildOptions) => Promise<void>;
```

View File

@ -1,37 +0,0 @@
---
title: Check
tags:
- pack-up
- CLI
---
## Usage
```bash
$ yarn pack-up check
```
Checks your current package to ensure it's interoperable in the real world. In short, validates the files
in your dist have been produced as we expect & then `esbuild` can actually build, using your exported code.
## API
### Usage
```ts
import { check } from '@strapi/pack-up';
check();
```
## Typescript
```ts
interface CheckOptions {
cwd?: string;
debug?: boolean;
silent?: boolean;
}
type Check = (options?: CheckOptions) => Promise<void>;
```

View File

@ -1,38 +0,0 @@
---
title: Watch
tags:
- pack-up
- CLI
---
## Usage
```bash
$ yarn pack-up watch
```
Watches your current package for changes and rebuilds when necessary.
## API
### Usage
```ts
import { watch } from '@strapi/pack-up';
watch();
```
## Typescript
```ts
interface WatchOptions {
configFile: false;
config?: Config;
cwd?: string;
debug?: boolean;
silent?: boolean;
}
type Watch = (options?: WatchOptions) => Promise<void>;
```

View File

@ -1,6 +0,0 @@
{
"position": 1,
"label": "Commands",
"collapsible": true,
"collapsed": true
}

View File

@ -1,87 +0,0 @@
---
title: Configuration
tags:
- pack-up
- configuration
- configs
---
# Configuring pack-up
By default, `pack-up` is designed to use the `package.json` as a source of truth to bundle your package.
This creates a seemless alignment between the bundling & publishing process. However, if you require more
flexibility, `pack-up` also supports a configuration file `packup.config.[mtj]s`.
## Usage
```ts
// package.config.ts
import { defineConfig } from '@strapi/pack-up';
export default defineConfig({
minify: true,
sourcemap: false,
externals: ['path', 'fs'],
});
```
## Interface
```ts
interface Config {
/**
* An array of entry points to bundle. This is useful if you want to bundle something that should not
* be exported by the package, e.g. CLI scripts or Node.js workers.
*/
bundles?: ConfigBundle[];
/**
* The directory to output the bundle to.
*/
dist?: string;
/**
* A list of external dependencies to exclude from the bundle.
* We already collect the dependencies & peerDeps from the package.json.
*/
externals?: string[];
/**
* Whether to minify the output or not.
*/
minify?: boolean;
/**
* An array of Vite plugins to use when bundling.
*/
plugins?: PluginOption[] | (({ runtime }: { runtime: Runtime }) => PluginOption[]);
/**
* @alpha
*
* @description Instead of creating as few chunks as possible, this mode
* will create separate chunks for all modules using the original module
* names as file names
*/
preserveModules?: boolean;
/**
* Whether to generate sourcemaps for the output or not.
*/
sourcemap?: boolean;
/**
* The transpilation target of the bundle. This is useful if you're bundling many different CLIs or
* Node.js workers and you want them to be transpiled for the node environment.
*/
runtime?: Runtime;
/**
* Path to the tsconfig file to use for the bundle.
*/
tsconfig?: string;
}
interface ConfigBundle {
source: string;
import?: string;
require?: string;
runtime?: Runtime;
tsconfig?: string;
types?: string;
}
type Runtime = '*' | 'node' | 'web';
```

View File

@ -1,81 +0,0 @@
---
title: Templates
tags:
- pack-up
- generating
- template
---
Templates are only used for the `init` api. You can either pass a path to the file containing your template (it's expected to be
a default export) if you're using the CLI. Or alternatively, if you're using the node functions then you can directly pass your template.
A template can either be an object (defined below) or a function returning said object. The function recieves an initiatialisation context
to be utilised at the discretion of the template author.
## Interfaces
### Template
```ts
interface Template {
/**
* If you're not using a template in a CLI environment,
* it's not recommended to use prompts. Instead, you should
* just return all the files your template needs in from the
* `getFiles` function.
*/
prompts?: Array<TemplateFeature | TemplateOption>;
/**
* A dictionary of the files that will be created in the
* new package. The key is the file name and the value is
* the file contents, we prettify the contents before writing
* using a default config if there's not one in the package.
*/
getFiles: (answers?: Array<{ name: string; answer: string }>) => Promise<Array<TemplateFile>>;
}
interface TemplateContext {
cwd: string;
logger: Logger;
packagePath: string;
}
type TemplateResolver = (ctx: TemplateContext) => Promise<Template>;
```
### Template Features & Options
Features & options are restricted just [prompts](https://github.com/terkelg/prompts). All features are boolean
answers using the `confirm` type. Options have a lot more flexibility and can be used to capture information.
```ts
interface TemplateFeature<T extends string = string>
extends Pick<prompts.PromptObject<T>, 'initial'> {
/**
* Name of the feature you want to add to your package.
* This must be identical to the name of the feature on npm.
*/
name: string;
/**
* @default true
*/
optional?: boolean;
}
interface TemplateOption<T extends string = string>
extends Omit<prompts.PromptObject<T>, 'onState' | 'onRender' | 'stdout' | 'stdin' | 'name'> {
name: string;
}
```
### Template file
Files are just objects with a name and contents. It's advised to use a library like `outdent` to handle indentation in
your file contents. Although the API will try to prettyify your files before writing them.
```ts
interface TemplateFile {
name: string;
contents: string;
}
```

View File

@ -1,6 +0,0 @@
{
"position": 1,
"label": "Pack-Up",
"collapsible": true,
"collapsed": true
}

16
nx.json
View File

@ -2,7 +2,6 @@
"namedInputs": {
"default": ["{projectRoot}/**/*"],
"production": [
"default",
"!{projectRoot}/**/*.test.ts",
"!{projectRoot}/**/*.test.js",
"!{projectRoot}/**/*.test.api.js",
@ -21,10 +20,22 @@
},
"targetDefaults": {
"build": {
"inputs": ["production", "^production"],
"inputs": ["default", "^production"],
"outputs": ["{projectRoot}/dist"],
"dependsOn": ["^build"],
"cache": true
},
"build:code": {
"inputs": ["default", "^production"],
"outputs": ["{projectRoot}/dist"],
"cache": true
},
"build:types": {
"inputs": ["default", "^production"],
"outputs": ["{projectRoot}/dist"],
"dependsOn": ["^build:types"],
"cache": true
},
"test:unit": {
"inputs": ["default", "{workspaceRoot}/jest-preset.unit.js"],
"cache": true
@ -46,6 +57,7 @@
}
},
"useInferencePlugins": false,
"parallel": 8,
"pluginsConfig": {
"@nx/js": {
"analyzeSourceFiles": false

View File

@ -31,7 +31,10 @@
"scripts/*"
],
"scripts": {
"build": "nx run-many --target=build --nx-ignore-cycles",
"build": "nx run-many --targets build:code,build:types --nx-ignore-cycles",
"build:code": "nx run-many --target=build:code --nx-ignore-cycles",
"build:types": "nx run-many --target=build:types --nx-ignore-cycles",
"watch": "nx watch --all -- 'nx run-many --targets build:code,build:types --projects $NX_PROJECT_NAME'",
"build:size": "cd examples/getstarted && yarn build",
"build:ts": "nx run-many --target=build:ts --nx-ignore-cycles",
"build:watch": "nx watch --all --nx-ignore-cycles -- nx run \\$NX_PROJECT_NAME:build --nx-ignore-cycles",
@ -90,6 +93,12 @@
"@commitlint/prompt-cli": "19.2.0",
"@nx/js": "20.1.0",
"@playwright/test": "1.48.2",
"@rollup/plugin-commonjs": "28.0.1",
"@rollup/plugin-dynamic-import-vars": "2.1.5",
"@rollup/plugin-image": "3.0.3",
"@rollup/plugin-json": "6.1.0",
"@rollup/plugin-node-resolve": "15.3.0",
"@rollup/plugin-swc": "0.4.0",
"@strapi/admin-test-utils": "workspace:*",
"@strapi/eslint-config": "0.2.0",
"@swc-node/register": "~1.9.1",
@ -142,19 +151,22 @@
"lerna": "8.1.2",
"lint-staged": "15.2.10",
"lodash": "4.17.21",
"nx": "20.1.0",
"npm-run-all": "4.1.5",
"nx": "20.2.1",
"plop": "4.0.1",
"prettier": "3.3.3",
"prettier-2": "npm:prettier@^2",
"qs": "6.11.1",
"rimraf": "5.0.5",
"rollup": "4.27.4",
"rollup-plugin-html": "0.2.1",
"semver": "7.5.4",
"stream-chain": "2.2.5",
"stream-json": "1.8.0",
"supertest": "6.3.3",
"tar": "6.2.1",
"ts-jest": "29.1.0",
"typescript": "5.3.2",
"typescript": "5.4.4",
"yalc": "1.0.0-pre.53",
"yargs": "17.7.2"
},

View File

@ -1,3 +1,4 @@
node_modules/
dist/
.eslintrc.js
rollup.config.mjs

View File

@ -66,11 +66,15 @@
"source": "./src/index.ts",
"types": "./dist/index.d.ts",
"scripts": {
"build": "pack-up build",
"build": "run -T run-p build:code build:types",
"build:code": "run -T rollup -c",
"build:types": "run -T tsc -p tsconfig.build.json --emitDeclarationOnly",
"watch": "run -T run-p watch:code watch:types",
"watch:code": "run -T rollup -c -w",
"watch:types": "run -T tsc -p tsconfig.build.json --emitDeclarationOnly -w",
"clean": "run -T rimraf ./dist",
"lint": "run -T eslint .",
"test:ts": "run -T tsc --noEmit",
"watch": "pack-up watch"
"test:ts": "run -T tsc --noEmit"
},
"dependencies": {
"@juggle/resize-observer": "3.4.0",
@ -79,7 +83,6 @@
},
"devDependencies": {
"@reduxjs/toolkit": "1.9.7",
"@strapi/pack-up": "5.0.2",
"@testing-library/jest-dom": "6.4.5",
"eslint-config-custom": "5.8.1",
"jest-environment-jsdom": "29.6.1",

View File

@ -0,0 +1,14 @@
import { defineConfig } from 'rollup';
import { baseConfig } from '../../rollup.utils.mjs';
export default defineConfig({
...baseConfig(import.meta.dirname),
input: {
index: import.meta.dirname + '/src/index.ts',
'after-env': import.meta.dirname + '/src/after-env.ts',
environment: import.meta.dirname + '/src/environment.ts',
'file-mock': import.meta.dirname + '/src/file-mock.ts',
'global-setup': import.meta.dirname + '/src/global-setup.ts',
setup: import.meta.dirname + '/src/setup.ts',
},
});

View File

@ -1,12 +1,12 @@
import JSDOMEnvironment from 'jest-environment-jsdom';
import { TestEnvironment } from 'jest-environment-jsdom';
/* -------------------------------------------------------------------------------------------------
* JSDOM env
* -----------------------------------------------------------------------------------------------*/
// https://github.com/facebook/jest/blob/v29.4.3/website/versioned_docs/version-29.4/Configuration.md#testenvironment-string
export default class CustomJSDOMEnvironment extends JSDOMEnvironment {
constructor(...args: ConstructorParameters<typeof JSDOMEnvironment>) {
export default class CustomJSDOMEnvironment extends TestEnvironment {
constructor(...args: ConstructorParameters<typeof TestEnvironment>) {
super(...args);
// TODO: remove once https://github.com/jsdom/jsdom/issues/3363 is closed.

View File

@ -1,6 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": false,
"outDir": "dist"
},
"include": ["src", "custom.d.ts"],

View File

@ -2,4 +2,5 @@ node_modules/
.eslintrc.js
dist/
bin/
jest.config.js
jest.config.js
rollup.config.mjs

View File

@ -38,11 +38,13 @@
"./bin"
],
"scripts": {
"build": "pack-up build",
"build": "run -T npm-run-all clean --parallel build:code build:types",
"build:code": "run -T rollup -c",
"build:types": "run -T tsc -p tsconfig.build.json --emitDeclarationOnly",
"clean": "run -T rimraf ./dist",
"lint": "run -T eslint .",
"test:unit": "run -T jest",
"watch": "pack-up watch"
"watch": "run -T rollup -c -w"
},
"dependencies": {
"@strapi/utils": "5.8.1",
@ -67,7 +69,6 @@
"yup": "0.32.9"
},
"devDependencies": {
"@strapi/pack-up": "5.0.2",
"@types/cli-progress": "3.11.5",
"@types/eventsource": "1.1.15",
"@types/lodash": "^4.14.191",

View File

@ -1,20 +0,0 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineConfig } from '@strapi/pack-up';
export default defineConfig({
bundles: [
{
source: './src/index.ts',
import: './dist/index.js',
require: './dist/index.js',
types: './dist/index.d.ts',
runtime: 'node',
},
{
source: './src/bin.ts',
require: './dist/bin.js',
runtime: 'node',
},
],
dist: './dist',
});

View File

@ -0,0 +1,10 @@
import { defineConfig } from 'rollup';
import { baseConfig } from '../../../rollup.utils.mjs';
export default defineConfig({
...baseConfig(import.meta.dirname),
input: {
index: './src/index.ts',
bin: './src/bin.ts',
},
});

View File

@ -1,5 +1,5 @@
{
"extends": "tsconfig/base.json",
"include": ["src", "packup.config.ts"],
"include": ["src"],
"exclude": ["node_modules"]
}

View File

@ -3,3 +3,4 @@ node_modules/
dist/
bin/
templates/
rollup.config.mjs

View File

@ -41,11 +41,13 @@
"templates/"
],
"scripts": {
"build": "pack-up build",
"build": "run -T npm-run-all clean --parallel build:code build:types",
"build:code": "run -T rollup -c",
"build:types": "run -T tsc -p tsconfig.build.json --emitDeclarationOnly",
"clean": "run -T rimraf ./dist",
"lint": "run -T eslint .",
"test:ts": "run -T tsc --noEmit",
"watch": "pack-up watch"
"watch": "run -T rollup -c -w"
},
"dependencies": {
"@strapi/cloud-cli": "5.8.1",
@ -64,7 +66,6 @@
"tar": "7.4.3"
},
"devDependencies": {
"@strapi/pack-up": "5.0.2",
"@types/async-retry": "^1",
"@types/fs-extra": "11.0.4",
"@types/inquirer": "8.2.5",

View File

@ -1,15 +0,0 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineConfig } from '@strapi/pack-up';
export default defineConfig({
bundles: [
{
source: './src/index.ts',
import: './dist/index.mjs',
require: './dist/index.js',
types: './dist/index.d.ts',
runtime: 'node',
},
],
dist: './dist',
});

View File

@ -0,0 +1,3 @@
import { baseConfig } from '../../../rollup.utils.mjs';
export default baseConfig(import.meta.dirname);

View File

@ -209,8 +209,10 @@ function isValidUrl(value: string) {
}
}
const OFFICIAL_NAME_REGEX = /^[a-zA-Z]*$/;
async function isOfficialTemplate(template: string, branch: string | undefined) {
if (isValidUrl(template)) {
if (isValidUrl(template) || !OFFICIAL_NAME_REGEX.test(template)) {
return false;
}

View File

@ -1,5 +1,5 @@
{
"extends": "./tsconfig.json",
"include": ["src", "packup.config.ts", "package.json"],
"include": ["src", "package.json"],
"exclude": ["node_modules"]
}

View File

@ -1 +1,2 @@
dist
dist
rollup.config.mjs

View File

@ -10,4 +10,4 @@ npm-debug.log
.idea
.env
admin/src/plugins-dev.js
admin/src/plugins.js
admin/src/plugins.js

View File

@ -1,10 +0,0 @@
/* eslint-disable import/no-default-export */
declare module '*.png' {
const value: any;
export default value;
}
declare module '*.svg' {
const value: any;
export default value;
}

View File

@ -23,15 +23,16 @@ function createContext<ContextValueType extends object | null>(
return <Context.Provider value={value}>{children}</Context.Provider>;
};
const useContext = <Selected,>(
function useContext<Selected>(
consumerName: string,
selector: (value: ContextValueType) => Selected
): Selected =>
ContextSelector.useContextSelector(Context, (ctx) => {
): Selected {
return ContextSelector.useContextSelector(Context, (ctx) => {
if (ctx) return selector(ctx);
// it's a required context.
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
});
}
Provider.displayName = rootComponentName + 'Provider';

View File

@ -2,7 +2,6 @@ import * as React from 'react';
import { Box, Button, Flex, Popover, Tag } from '@strapi/design-system';
import { Plus, Filter as FilterIcon, Cross } from '@strapi/icons';
import { Schema } from '@strapi/types';
import { useIntl } from 'react-intl';
import {
@ -21,6 +20,8 @@ import { createContext } from './Context';
import { Form, InputProps } from './Form';
import { InputRenderer } from './FormInputs/Renderer';
import type { Schema } from '@strapi/types';
/* -------------------------------------------------------------------------------------------------
* Root
* -----------------------------------------------------------------------------------------------*/

View File

@ -677,7 +677,7 @@ interface FieldValue<TValue = any> {
rawError?: any;
}
const useField = <TValue = any,>(path: string): FieldValue<TValue | undefined> => {
function useField<TValue = any>(path: string): FieldValue<TValue | undefined> {
const { formatMessage } = useIntl();
const initialValue = useForm(
@ -726,7 +726,7 @@ const useField = <TValue = any,>(path: string): FieldValue<TValue | undefined> =
onChange: handleChange,
value: value,
};
};
}
const isErrorMessageDescriptor = (object?: object): object is TranslationMessage => {
return (

View File

@ -2,26 +2,11 @@ import * as React from 'react';
import { IntlFormatters, useIntl } from 'react-intl';
import { FetchError } from '../utils/getFetchClient';
import { FetchError, ApiError } from '../utils/getFetchClient';
import { getPrefixedId } from '../utils/getPrefixedId';
import { NormalizeErrorOptions, normalizeAPIError } from '../utils/normalizeAPIError';
import { setIn } from '../utils/objects';
import type { errors } from '@strapi/utils';
type ApiError =
| errors.ApplicationError
| errors.ForbiddenError
| errors.NotFoundError
| errors.NotImplementedError
| errors.PaginationError
| errors.PayloadTooLargeError
| errors.PolicyError
| errors.RateLimitError
| errors.UnauthorizedError
| errors.ValidationError
| errors.YupValidationError;
interface UnknownApiError {
/**
* The name of the ApiError, is always a static value.

View File

@ -47,7 +47,7 @@ export { useAPIErrorHandler, type ApiError } from './hooks/useAPIErrorHandler';
export { useQueryParams } from './hooks/useQueryParams';
export { useFetchClient } from './hooks/useFetchClient';
export { useFocusInputField } from './hooks/useFocusInputField';
export { useRBAC } from './hooks/useRBAC';
export { useRBAC, type AllowedActions } from './hooks/useRBAC';
export { useClipboard } from './hooks/useClipboard';
export { useAdminUsers } from './services/users';
@ -71,7 +71,14 @@ export type { RBACContext, RBACMiddleware } from './core/apis/rbac';
* Utils
*/
export { translatedErrors } from './utils/translatedErrors';
export * from './utils/getFetchClient';
export { getFetchClient, isFetchError, FetchError } from './utils/getFetchClient';
export type {
ErrorResponse,
FetchClient,
FetchConfig,
FetchOptions,
FetchResponse,
} from './utils/getFetchClient';
export * from './utils/baseQuery';
export * from './services/api';
export type { CMAdminConfiguration } from './types/adminConfiguration';

View File

@ -1,5 +1,3 @@
import React from 'react';
import { Box, BoxComponent, Flex, Typography } from '@strapi/design-system';
import map from 'lodash/map';
import tail from 'lodash/tail';

View File

@ -3,7 +3,6 @@ import * as React from 'react';
import { EmptyStateLayout, LinkButton } from '@strapi/design-system';
import { Plus } from '@strapi/icons';
import { EmptyDocuments } from '@strapi/icons/symbols';
import { Data } from '@strapi/types';
import * as qs from 'qs';
import { useIntl } from 'react-intl';
import { Link, useNavigate } from 'react-router-dom';
@ -21,6 +20,8 @@ import { useDeleteAPITokenMutation, useGetAPITokensQuery } from '../../../../ser
import { API_TOKEN_TYPE } from '../../components/Tokens/constants';
import { Table } from '../../components/Tokens/Table';
import type { Data } from '@strapi/types';
const TABLE_HEADERS = [
{
name: 'name',

View File

@ -3,7 +3,6 @@ import * as React from 'react';
import { EmptyStateLayout, LinkButton } from '@strapi/design-system';
import { Plus } from '@strapi/icons';
import { EmptyDocuments } from '@strapi/icons/symbols';
import { Data } from '@strapi/types';
import * as qs from 'qs';
import { useIntl } from 'react-intl';
import { Link, useNavigate } from 'react-router-dom';
@ -23,6 +22,8 @@ import {
import { TRANSFER_TOKEN_TYPE } from '../../components/Tokens/constants';
import { Table } from '../../components/Tokens/Table';
import type { Data } from '@strapi/types';
const tableHeaders = [
{
name: 'name',

View File

@ -1,7 +1,6 @@
import * as React from 'react';
import { Main } from '@strapi/design-system';
import { Modules } from '@strapi/types';
import { useIntl } from 'react-intl';
import { useNavigate, useMatch } from 'react-router-dom';
@ -16,6 +15,8 @@ import { isBaseQueryError } from '../../../../utils/baseQuery';
import { WebhookForm, WebhookFormProps, WebhookFormValues } from './components/WebhookForm';
import { useWebhooks } from './hooks/useWebhooks';
import type { Modules } from '@strapi/types';
/* -------------------------------------------------------------------------------------------------
* EditView
* -----------------------------------------------------------------------------------------------*/

View File

@ -48,7 +48,7 @@ const admin = adminApi
url: '/admin/telemetry-properties',
method: 'GET',
config: {
validateStatus: (status) => status < 500,
validateStatus: (status: number) => status < 500,
},
}),
transformResponse(res: TelemetryProperties.Response) {

View File

@ -1,13 +1,20 @@
import { render } from '@testing-library/react';
import { render, waitFor } from '@testing-library/react';
import { StrapiApp } from '../StrapiApp';
describe('ADMIN | new StrapiApp', () => {
it('should render the app without plugins', async () => {
const app = new StrapiApp();
const { findByRole } = render(app.render());
const { getByRole } = render(app.render());
await findByRole('combobox');
await waitFor(
() => {
expect(getByRole('combobox')).toBeInTheDocument();
},
{
timeout: 60000,
}
);
});
describe('Hook api', () => {

View File

@ -1,9 +1,7 @@
import { SerializedError } from '@reduxjs/toolkit';
import { BaseQueryFn } from '@reduxjs/toolkit/query';
import { getFetchClient, isFetchError, type FetchOptions } from '../utils/getFetchClient';
import type { ApiError } from '../hooks/useAPIErrorHandler';
import { getFetchClient, type FetchOptions, ApiError, isFetchError } from '../utils/getFetchClient';
interface QueryArguments {
url: string;
@ -21,88 +19,91 @@ interface UnknownApiError {
type BaseQueryError = ApiError | UnknownApiError;
const fetchBaseQuery =
(): BaseQueryFn<string | QueryArguments, unknown, BaseQueryError> =>
async (query, { signal }) => {
try {
const { get, post, del, put } = getFetchClient();
const simpleQuery: BaseQueryFn<string | QueryArguments, unknown, BaseQueryError> = async (
query,
{ signal }
) => {
try {
const { get, post, del, put } = getFetchClient();
if (typeof query === 'string') {
const result = await get(query, { signal });
return { data: result.data };
} else {
const { url, method = 'GET', data, config } = query;
if (typeof query === 'string') {
const result = await get(query, { signal });
return { data: result.data };
} else {
const { url, method = 'GET', data, config } = query;
if (method === 'POST') {
const result = await post(url, data, {
...config,
signal,
});
return { data: result.data };
}
if (method === 'DELETE') {
const result = await del(url, {
...config,
signal,
});
return { data: result.data };
}
if (method === 'PUT') {
const result = await put(url, data, {
...config,
signal,
});
return { data: result.data };
}
/**
* Default is GET.
*/
const result = await get(url, {
if (method === 'POST') {
const result = await post(url, data, {
...config,
signal,
});
return { data: result.data };
}
} catch (err) {
// Handle error of type FetchError
if (isFetchError(err)) {
if (
typeof err.response?.data === 'object' &&
err.response?.data !== null &&
'error' in err.response?.data
) {
/**
* This will most likely be ApiError
*/
return { data: undefined, error: err.response?.data.error as any };
} else {
return {
data: undefined,
error: {
name: 'UnknownError',
message: err.message,
details: err.response,
status: err.status,
} as UnknownApiError,
};
}
if (method === 'DELETE') {
const result = await del(url, {
...config,
signal,
});
return { data: result.data };
}
const error = err as Error;
return {
data: undefined,
error: {
name: error.name,
message: error.message,
stack: error.stack,
} satisfies SerializedError,
};
if (method === 'PUT') {
const result = await put(url, data, {
...config,
signal,
});
return { data: result.data };
}
/**
* Default is GET.
*/
const result = await get(url, {
...config,
signal,
});
return { data: result.data };
}
};
} catch (err) {
// Handle error of type FetchError
if (isFetchError(err)) {
if (
typeof err.response?.data === 'object' &&
err.response?.data !== null &&
'error' in err.response?.data
) {
/**
* This will most likely be ApiError
*/
return { data: undefined, error: err.response?.data.error as any };
} else {
return {
data: undefined,
error: {
name: 'UnknownError',
message: err.message,
details: err.response,
status: err.status,
} as UnknownApiError,
};
}
}
const error = err as Error;
return {
data: undefined,
error: {
name: error.name,
message: error.message,
stack: error.stack,
} satisfies SerializedError,
};
}
};
const fetchBaseQuery = () => simpleQuery;
const isBaseQueryError = (error: BaseQueryError | SerializedError): error is BaseQueryError => {
return error.name !== undefined;

View File

@ -1,7 +1,20 @@
import pipe from 'lodash/fp/pipe';
import qs from 'qs';
import type { ApiError } from '../hooks/useAPIErrorHandler';
import type { errors } from '@strapi/utils';
export type ApiError =
| errors.ApplicationError
| errors.ForbiddenError
| errors.NotFoundError
| errors.NotImplementedError
| errors.PaginationError
| errors.PayloadTooLargeError
| errors.PolicyError
| errors.RateLimitError
| errors.UnauthorizedError
| errors.ValidationError
| errors.YupValidationError;
const STORAGE_KEYS = {
TOKEN: 'jwtToken',

View File

@ -17,7 +17,7 @@ import {
RenderHookResult,
Queries,
} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { userEvent } from '@testing-library/user-event';
import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';
import { QueryClient, QueryClientProvider, setLogger } from 'react-query';

View File

@ -3,17 +3,10 @@
"compilerOptions": {
"rootDir": "../",
"baseUrl": ".",
"outDir": "./dist"
"outDir": "../dist",
"noEmit": false
},
"include": [
"./src",
"./custom.d.ts",
"../shared",
"./module.d.ts",
"../ee/admin",
"../package.json",
"./tests"
],
"include": ["./src", "./custom.d.ts", "../shared", "../ee/admin", "../package.json", "./tests"],
"exclude": [
"**/__mocks__",
"./src/**/tests",

View File

@ -7,5 +7,5 @@
"@tests/*": ["./tests/*"]
}
},
"include": ["../package.json", "./src", "../shared", "./tests", "./custom.d.ts", "./module.d.ts"]
"include": ["../package.json", "./src", "../shared", "./tests", "./custom.d.ts"]
}

View File

@ -1,5 +1,5 @@
import { createAuditLogsLifecycleService } from '../lifecycles';
import createEventHub from '../../../../../../../core/dist/services/event-hub';
import createEventHub from '../../../../../../../core/src/services/event-hub';
import { scheduleJob } from 'node-schedule';
import '@strapi/types';

View File

@ -10,7 +10,7 @@ import auditLogsController from './audit-logs/controllers/audit-logs';
import { createAuditLogsService } from './audit-logs/services/audit-logs';
import { createAuditLogsLifecycleService } from './audit-logs/services/lifecycles';
import { auditLog } from './audit-logs/content-types/audit-log';
import { Core } from '@strapi/types';
import type { Core } from '@strapi/types';
const getAdminEE = () => {
const eeAdmin = {

View File

@ -58,11 +58,15 @@
"./package.json": "./package.json"
},
"files": [
"dist/",
"strapi-server.js"
"dist/"
],
"scripts": {
"build": "pack-up build && vite build",
"build": "run -T npm-run-all clean --parallel build:code build:types",
"build:code": "run -T rollup -c",
"build:types": "run -T run-p build:types:server build:types:admin build:types:internals",
"build:types:internals": "run -T tsc -p tsconfig.build.json --emitDeclarationOnly",
"build:types:server": "run -T tsc -p server/tsconfig.build.json --emitDeclarationOnly",
"build:types:admin": "run -T tsc -p admin/tsconfig.build.json --emitDeclarationOnly",
"clean": "run -T rimraf ./dist",
"lint": "run -T eslint .",
"test:front": "run -T cross-env IS_EE=true jest --config ./jest.config.front.js",
@ -72,7 +76,7 @@
"test:ts:front": "run -T tsc -p admin/tsconfig.json && run -T tsc -p ee/admin/tsconfig.json",
"test:unit": "run -T jest",
"test:unit:watch": "run -T jest --watch",
"watch": "pack-up watch"
"watch": "run -T rollup -c -w"
},
"dependencies": {
"@casl/ability": "6.5.0",
@ -133,7 +137,7 @@
"scheduler": "0.23.0",
"semver": "7.5.4",
"sift": "16.0.1",
"typescript": "5.3.2",
"typescript": "5.4.4",
"use-context-selector": "1.4.1",
"yup": "0.32.9",
"zod": "^3.22.4"
@ -141,7 +145,6 @@
"devDependencies": {
"@strapi/admin-test-utils": "5.8.1",
"@strapi/data-transfer": "5.8.1",
"@strapi/pack-up": "5.0.2",
"@types/codemirror5": "npm:@types/codemirror@^5.60.15",
"@types/fs-extra": "11.0.4",
"@types/invariant": "2.2.36",

View File

@ -1,32 +0,0 @@
import { Config, defineConfig } from '@strapi/pack-up';
const config: Config = defineConfig({
bundles: [
{
source: './_internal/index.ts',
import: './dist/_internal.mjs',
require: './dist/_internal.js',
types: './dist/_internal/index.d.ts',
runtime: 'web',
},
{
source: './server/src/index.ts',
import: './dist/server/index.mjs',
require: './dist/server/index.js',
types: './dist/server/src/index.d.ts',
tsconfig: './server/tsconfig.build.json',
runtime: 'node',
},
],
dist: './dist',
/**
* Because we're exporting a server & client package
* which have different runtimes we want to ignore
* what they look like in the package.json
*/
exports: {},
// If you don't include this, it seems to think vite needs to be bundled, which isn't true.
externals: ['vite'],
});
export default config;

View File

@ -0,0 +1,90 @@
import { defineConfig } from 'rollup';
import path from 'path';
import { basePlugins } from '../../../rollup.utils.mjs';
export default defineConfig([
{
input: path.join(import.meta.dirname, 'server/src/index.ts'),
external: (id) => !path.isAbsolute(id) && !id.startsWith('.'),
output: [
{
dir: path.join(import.meta.dirname, 'dist/server'),
entryFileNames: '[name].js',
chunkFileNames: 'chunks/[name]-[hash].js',
exports: 'auto',
format: 'cjs',
sourcemap: true,
},
{
dir: path.join(import.meta.dirname, 'dist/server'),
entryFileNames: '[name].mjs',
chunkFileNames: 'chunks/[name]-[hash].js',
exports: 'auto',
format: 'esm',
sourcemap: true,
},
],
plugins: [...basePlugins(import.meta.dirname)],
},
{
input: {
_internal: path.join(import.meta.dirname, '/_internal/index.ts'),
},
external: (id) => !path.isAbsolute(id) && !id.startsWith('.'),
output: [
{
dir: path.join(import.meta.dirname, 'dist'),
entryFileNames: '[name].js',
chunkFileNames: 'chunks/[name]-[hash].js',
exports: 'auto',
format: 'cjs',
sourcemap: true,
},
{
dir: path.join(import.meta.dirname, 'dist'),
entryFileNames: '[name].mjs',
chunkFileNames: 'chunks/[name]-[hash].js',
exports: 'auto',
format: 'esm',
sourcemap: true,
},
],
plugins: [...basePlugins(import.meta.dirname)],
},
{
input: {
index: './admin/src/index.ts',
ee: './admin/src/ee.ts',
test: './admin/tests/index.ts',
},
external: (id) => !path.isAbsolute(id) && !id.startsWith('.'),
output: [
{
dir: path.join(import.meta.dirname, 'dist/admin'),
entryFileNames: '[name].js',
chunkFileNames: 'chunks/[name]-[hash].js',
exports: 'auto',
format: 'cjs',
sourcemap: true,
},
{
dir: path.join(import.meta.dirname, 'dist/admin'),
entryFileNames: '[name].mjs',
chunkFileNames: 'chunks/[name]-[hash].js',
exports: 'auto',
format: 'esm',
sourcemap: true,
},
],
onwarn(warning, warn) {
// Suppress the "default is never used" warning for React
if (warning.code === 'UNUSED_EXTERNAL_IMPORT' && warning.exporter === 'react') {
return;
}
warn(warning); // Log other warnings
},
plugins: [...basePlugins(import.meta.dirname)],
},
]);

View File

@ -3,7 +3,8 @@
"compilerOptions": {
"rootDir": "../",
"baseUrl": ".",
"outDir": "./dist"
"outDir": "../dist",
"noEmit": false
},
"include": ["src", "../shared"],
"exclude": ["**/*.test.*"]

View File

@ -1,7 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./dist"
"outDir": "./dist",
"noEmit": false
},
"include": ["_internal"]
}

View File

@ -1,67 +0,0 @@
/* eslint-disable import/no-extraneous-dependencies */
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react-swc';
import { builtinModules } from 'node:module';
import dts from 'vite-plugin-dts';
import pkg from './package.json';
/**
* TODO: we should have `pack-up` handle this for us, but time constaints
* have meant i've fallen back to vite or a fast solution.
*
* https://strapi-inc.atlassian.net/browse/CONTENT-2341
*/
export default defineConfig({
build: {
emptyOutDir: false,
target: 'esnext',
outDir: 'dist/admin',
sourcemap: true,
minify: false,
lib: {
// Could also be a dictionary or array of multiple entry points
entry: {
index: './admin/src/index.ts',
ee: './admin/src/ee.ts',
test: './admin/tests/index.ts',
},
},
rollupOptions: {
external(id) {
const external = [
...(pkg.dependencies ? Object.keys(pkg.dependencies) : []),
...(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : []),
];
const idParts = id.split('/');
const name = idParts[0].startsWith('@') ? `${idParts[0]}/${idParts[1]}` : idParts[0];
const builtinModulesWithNodePrefix = [
...builtinModules,
...builtinModules.map((modName) => `node:${modName}`),
];
if (
(name && external.includes(name)) ||
(name && builtinModulesWithNodePrefix.includes(name))
) {
return true;
}
return false;
},
output: {
interop: 'auto',
},
},
},
plugins: [
dts({
outDir: './dist',
tsconfigPath: './admin/tsconfig.build.json',
}),
react(),
],
});

View File

@ -1 +1,2 @@
dist
dist
rollup.config.mjs

View File

@ -1,10 +0,0 @@
/* eslint-disable import/no-default-export */
declare module '*.png' {
const value: any;
export default value;
}
declare module '*.svg' {
const value: any;
export default value;
}

View File

@ -2,7 +2,6 @@ import * as React from 'react';
import { Form, Layouts } from '@strapi/admin/strapi-admin';
import { Box, Divider, Flex, Grid, Typography } from '@strapi/design-system';
import { Schema } from '@strapi/types';
import pipe from 'lodash/fp/pipe';
import { useIntl } from 'react-intl';
@ -20,6 +19,7 @@ import type { Metadatas } from '../../../../shared/contracts/content-types';
import type { GetInitData } from '../../../../shared/contracts/init';
import type { ComponentsDictionary, Document } from '../../hooks/useDocument';
import type { EditFieldLayout } from '../../hooks/useDocumentLayout';
import type { Schema } from '@strapi/types';
const createLayoutFromFields = <T extends EditFieldLayout | UnknownField>(fields: T[]) => {
return (

View File

@ -10,7 +10,6 @@ import {
} from '@strapi/admin/strapi-admin';
import { Button, Typography, Flex, Link, Dialog } from '@strapi/design-system';
import { ArrowLeft, WarningCircle } from '@strapi/icons';
import { UID } from '@strapi/types';
import { stringify } from 'qs';
import { useIntl } from 'react-intl';
import { NavLink, useNavigate, useParams, type To } from 'react-router-dom';
@ -19,6 +18,8 @@ import { PERMISSIONS } from '../../constants/plugin';
import { useHistoryContext } from '../pages/History';
import { useRestoreVersionMutation } from '../services/historyVersion';
import type { UID } from '@strapi/types';
interface VersionHeaderProps {
headerId: string;
}

View File

@ -1,5 +1,3 @@
import { Data } from '@strapi/types';
import {
GetHistoryVersions,
RestoreHistoryVersion,
@ -7,6 +5,8 @@ import {
import { COLLECTION_TYPES } from '../../constants/collections';
import { contentManagerApi } from '../../services/api';
import type { Data } from '@strapi/types';
interface RestoreVersion extends RestoreHistoryVersion.Request {
documentId: Data.ID;
collectionType?: string;

View File

@ -14,7 +14,6 @@ import {
getYupValidationErrors,
useForm,
} from '@strapi/admin/strapi-admin';
import { Modules } from '@strapi/types';
import { useIntl } from 'react-intl';
import { useParams } from 'react-router-dom';
import { ValidationError } from 'yup';
@ -31,6 +30,7 @@ import { useDocumentLayout } from './useDocumentLayout';
import type { FindOne } from '../../../shared/contracts/collection-types';
import type { ContentType } from '../../../shared/contracts/content-types';
import type { Modules } from '@strapi/types';
interface UseDocumentArgs {
collectionType: string;
@ -292,7 +292,7 @@ const useContentManagerContext = () => {
const layout = useDocumentLayout(model);
const form = useForm('useContentManagerContext', (state) => state);
const form = useForm<unknown>('useContentManagerContext', (state) => state);
const isSingleType = collectionType === SINGLE_TYPES;
const slug = model;

View File

@ -68,7 +68,7 @@ const TableActions = ({ document }: TableActionsProps) => {
actions={tableRowActions}
label={formatMessage({
id: 'content-manager.containers.list.table.row-actions',
defaultMessage: 'Row action',
defaultMessage: 'Row actions',
})}
variant="ghost"
/>

View File

@ -2,7 +2,6 @@ import * as React from 'react';
import { useQueryParams, useTracking, useForm } from '@strapi/admin/strapi-admin';
import { Box, Button, Tooltip, type TooltipProps } from '@strapi/design-system';
import { UID } from '@strapi/types';
import { stringify } from 'qs';
import { useIntl } from 'react-intl';
import { Link, useLocation } from 'react-router-dom';
@ -10,6 +9,7 @@ import { Link, useLocation } from 'react-router-dom';
import { useGetPreviewUrlQuery } from '../services/preview';
import type { PanelComponent } from '@strapi/content-manager/strapi-admin';
import type { UID } from '@strapi/types';
interface ConditionalTooltipProps {
isShown: boolean;

View File

@ -5,13 +5,13 @@ import { PreviewSidePanel } from './components/PreviewSidePanel';
import type { ContentManagerPlugin } from '../content-manager';
import type { PluginDefinition } from '@strapi/admin/strapi-admin';
const previewAdmin = {
const previewAdmin: Partial<PluginDefinition> = {
bootstrap(app) {
const contentManagerPluginApis = app.getPlugin('content-manager')
.apis as ContentManagerPlugin['config']['apis'];
contentManagerPluginApis.addEditViewSidePanel([PreviewSidePanel]);
},
} satisfies Partial<PluginDefinition>;
};
export { previewAdmin };

View File

@ -1,10 +1,11 @@
{
"extends": "tsconfig/client.json",
"extends": "./tsconfig",
"compilerOptions": {
"rootDir": "../",
"baseUrl": ".",
"outDir": "./dist"
"outDir": "../dist",
"noEmit": false
},
"include": ["./src", "./custom.d.ts", "../shared", "./module.d.ts", "../package.json"],
"exclude": ["**/__mocks__", "./src/**/tests", "**/*.test.*"]
"include": ["./src", "./custom.d.ts", "../shared"],
"exclude": ["node_modules", "**/__mocks__", "./src/**/tests", "**/*.test.*"]
}

View File

@ -7,5 +7,5 @@
"@tests/*": ["./tests/*"]
}
},
"include": ["../package.json", "./src", "../shared", "./tests", "./custom.d.ts", "./module.d.ts"]
"include": ["./src", "../shared", "./tests", "./custom.d.ts"]
}

View File

@ -43,18 +43,22 @@
"./package.json": "./package.json"
},
"files": [
"dist/",
"strapi-server.js"
"dist/"
],
"scripts": {
"build": "pack-up build",
"build": "run -T npm-run-all clean --parallel build:code build:types",
"build:code": "run -T rollup -c",
"build:types": "run -T run-p build:types:server build:types:admin",
"build:types:server": "run -T tsc -p server/tsconfig.build.json --emitDeclarationOnly",
"build:types:admin": "run -T tsc -p admin/tsconfig.build.json --emitDeclarationOnly",
"clean": "run -T rimraf ./dist",
"lint": "run -T eslint .",
"test:front": "run -T cross-env IS_EE=true jest --config ./jest.config.front.js",
"test:ts:back": "run -T tsc --noEmit -p server/tsconfig.json",
"test:ts:front": "run -T tsc -p admin/tsconfig.json",
"test:unit": "run -T jest",
"test:unit:watch": "run -T jest --watch",
"watch": "pack-up watch"
"watch": "run -T rollup -c -w"
},
"dependencies": {
"@radix-ui/react-toolbar": "1.0.4",
@ -100,7 +104,6 @@
"devDependencies": {
"@strapi/admin": "5.8.1",
"@strapi/database": "5.8.1",
"@strapi/pack-up": "5.0.2",
"@testing-library/react": "15.0.7",
"@types/jest": "29.5.2",
"@types/lodash": "^4.14.191",

View File

@ -1,39 +0,0 @@
import { Config, defineConfig } from '@strapi/pack-up';
const config: Config = defineConfig({
bundles: [
{
types: './dist/admin/src/index.d.ts',
source: './admin/src/index.ts',
import: './dist/admin/index.mjs',
require: './dist/admin/index.js',
tsconfig: './admin/tsconfig.build.json',
runtime: 'web',
},
{
types: './dist/shared/index.d.ts',
source: './shared/index.ts',
import: './dist/shared/index.mjs',
require: './dist/shared/index.js',
tsconfig: './server/tsconfig.build.json',
runtime: 'node',
},
{
source: './server/src/index.ts',
import: './dist/server/index.mjs',
require: './dist/server/index.js',
types: './dist/server/src/index.d.ts',
tsconfig: './server/tsconfig.build.json',
runtime: 'node',
},
],
dist: './dist',
/**
* Because we're exporting a server & client package
* which have different runtimes we want to ignore
* what they look like in the package.json
*/
exports: {},
});
export default config;

View File

@ -0,0 +1,75 @@
import { defineConfig } from 'rollup';
import path from 'path';
import { basePlugins } from '../../../rollup.utils.mjs';
export default defineConfig([
{
input: path.join(import.meta.dirname, 'server/src/index.ts'),
external: (id) => !path.isAbsolute(id) && !id.startsWith('.'),
output: [
{
dir: path.join(import.meta.dirname, 'dist/server'),
entryFileNames: '[name].js',
chunkFileNames: 'chunks/[name]-[hash].js',
exports: 'auto',
format: 'cjs',
sourcemap: true,
},
{
dir: path.join(import.meta.dirname, 'dist/server'),
entryFileNames: '[name].mjs',
chunkFileNames: 'chunks/[name]-[hash].js',
exports: 'auto',
format: 'esm',
sourcemap: true,
},
],
plugins: [...basePlugins(import.meta.dirname)],
},
{
input: path.join(import.meta.dirname, 'admin/src/index.ts'),
external: (id) => !path.isAbsolute(id) && !id.startsWith('.'),
output: [
{
dir: path.join(import.meta.dirname, 'dist/admin'),
entryFileNames: '[name].js',
chunkFileNames: 'chunks/[name]-[hash].js',
exports: 'named',
format: 'cjs',
sourcemap: true,
},
{
dir: path.join(import.meta.dirname, 'dist/admin'),
entryFileNames: '[name].mjs',
chunkFileNames: 'chunks/[name]-[hash].js',
exports: 'named',
format: 'esm',
sourcemap: true,
},
],
plugins: [...basePlugins(import.meta.dirname)],
},
{
input: path.join(import.meta.dirname, 'shared/index.ts'),
external: (id) => !path.isAbsolute(id) && !id.startsWith('.'),
output: [
{
dir: path.join(import.meta.dirname, 'dist/shared'),
entryFileNames: '[name].js',
chunkFileNames: 'chunks/[name]-[hash].js',
exports: 'auto',
format: 'cjs',
sourcemap: true,
},
{
dir: path.join(import.meta.dirname, 'dist/shared'),
entryFileNames: '[name].mjs',
chunkFileNames: 'chunks/[name]-[hash].js',
exports: 'auto',
format: 'esm',
sourcemap: true,
},
],
plugins: [...basePlugins(import.meta.dirname)],
},
]);

View File

@ -1,4 +1,4 @@
import { UID } from '@strapi/types';
import type { UID } from '@strapi/types';
import { async } from '@strapi/utils';
import { getService } from '../../utils';

View File

@ -1,9 +1,9 @@
import { difference, omit } from 'lodash/fp';
import type { Core, Modules, Schema, Data, Struct, UID } from '@strapi/types';
import { contentTypes } from '@strapi/utils';
import type { CreateHistoryVersion } from '../../../../shared/contracts/history-versions';
import type { Core, Modules, Schema, Data, Struct, UID } from '@strapi/types';
import { FIELDS_TO_IGNORE } from '../constants';
import type { CreateHistoryVersion } from '../../../../shared/contracts/history-versions';
import type { HistoryVersions } from '../../../../shared/contracts';
import type { RelationResult } from '../../../../shared/contracts/relations';

View File

@ -1,4 +1,4 @@
import { UID, Schema } from '@strapi/types';
import type { UID, Schema } from '@strapi/types';
import { contentTypes } from '@strapi/utils';
import type { Document } from '../document-manager';

View File

@ -1,6 +1,6 @@
import { merge, isEmpty, set, propEq } from 'lodash/fp';
import strapiUtils from '@strapi/utils';
import { UID, Schema, Modules } from '@strapi/types';
import type { UID, Schema, Modules } from '@strapi/types';
import { getService } from '../../utils';
const { isVisibleAttribute, isScalarAttribute, getDoesAttributeRequireValidation } =

View File

@ -3,8 +3,9 @@
"compilerOptions": {
"rootDir": "../",
"baseUrl": ".",
"outDir": "./dist"
"outDir": "../dist",
"noEmit": false
},
"include": ["./src", "../shared"],
"exclude": ["**/*.test.*"]
"exclude": ["node_modules", "**/*.test.*"]
}

View File

@ -1,4 +1,4 @@
import { Modules, Data } from '@strapi/types';
import type { Modules, Data } from '@strapi/types';
import { errors } from '@strapi/utils';
type PaginationQuery = Modules.EntityService.Params.Pagination.PageNotation;

View File

@ -1,3 +1,4 @@
node_modules/
.eslintrc.js
dist/
rollup.config.mjs

View File

@ -16,7 +16,6 @@ import {
Modal,
Field,
} from '@strapi/design-system';
import { UID } from '@strapi/types';
import { Formik, Form } from 'formik';
import { useIntl } from 'react-intl';
@ -33,6 +32,7 @@ import {
import { ReleaseActionOptions } from './ReleaseActionOptions';
import type { BulkActionComponent } from '@strapi/content-manager/strapi-admin';
import type { UID } from '@strapi/types';
const getContentPermissions = (subject: string) => {
const permissions = {

View File

@ -4,11 +4,12 @@ import { useTable, useQueryParams } from '@strapi/admin/strapi-admin';
import { ListFieldLayout, ListLayout } from '@strapi/content-manager/strapi-admin';
import { Box, Popover, Typography, Button, Link } from '@strapi/design-system';
import { CaretDown } from '@strapi/icons';
import { Modules, UID } from '@strapi/types';
import { useIntl } from 'react-intl';
import { useGetMappedEntriesInReleasesQuery } from '../services/release';
import type { Modules, UID } from '@strapi/types';
/* -------------------------------------------------------------------------------------------------
* useReleasesList
* -----------------------------------------------------------------------------------------------*/

View File

@ -1,10 +1,11 @@
{
"extends": "./tsconfig.json",
"include": ["./src", "./custom.d.ts", "../shared"],
"exclude": ["tests", "**/*.test.*"],
"compilerOptions": {
"rootDir": "../",
"baseUrl": ".",
"outDir": "./dist"
}
"outDir": "../dist",
"noEmit": false
},
"include": ["./src", "./custom.d.ts", "../shared"],
"exclude": ["node_modules", "tests", "**/*.test.*"]
}

View File

@ -41,7 +41,11 @@
"strapi-server.js"
],
"scripts": {
"build": "pack-up build",
"build": "run -T npm-run-all clean --parallel build:code build:types",
"build:code": "run -T rollup -c",
"build:types": "run -T run-p build:types:server build:types:admin",
"build:types:server": "run -T tsc -p server/tsconfig.build.json --emitDeclarationOnly",
"build:types:admin": "run -T tsc -p admin/tsconfig.build.json --emitDeclarationOnly",
"clean": "run -T rimraf ./dist",
"lint": "run -T eslint .",
"test:front": "run -T cross-env IS_EE=true jest --config ./jest.config.front.js",
@ -51,7 +55,7 @@
"test:ts:front": "run -T tsc -p admin/tsconfig.json",
"test:unit": "run -T jest",
"test:unit:watch": "run -T jest --watch",
"watch": "pack-up watch"
"watch": "run -T rollup -c -w"
},
"dependencies": {
"@reduxjs/toolkit": "1.9.7",
@ -74,7 +78,6 @@
"@strapi/admin": "5.8.1",
"@strapi/admin-test-utils": "5.8.1",
"@strapi/content-manager": "5.8.1",
"@strapi/pack-up": "5.0.2",
"@testing-library/dom": "10.1.0",
"@testing-library/react": "15.0.7",
"@testing-library/user-event": "14.5.2",
@ -86,7 +89,7 @@
"react-query": "3.39.3",
"react-router-dom": "6.22.3",
"styled-components": "6.1.8",
"typescript": "5.3.2"
"typescript": "5.4.4"
},
"peerDependencies": {
"@strapi/admin": "^5.0.0",

View File

@ -1,29 +0,0 @@
import { defineConfig } from '@strapi/pack-up';
export default defineConfig({
bundles: [
{
source: './admin/src/index.ts',
import: './dist/admin/index.mjs',
require: './dist/admin/index.js',
types: './dist/admin/src/index.d.ts',
tsconfig: './admin/tsconfig.build.json',
runtime: 'web',
},
{
source: './server/src/index.ts',
import: './dist/server/index.mjs',
require: './dist/server/index.js',
types: './dist/server/src/index.d.ts',
tsconfig: './server/tsconfig.build.json',
runtime: 'node',
},
],
dist: './dist',
/**
* Because we're exporting a server & client package
* which have different runtimes we want to ignore
* what they look like in the package.json
*/
exports: {},
});

View File

@ -0,0 +1,52 @@
import { defineConfig } from 'rollup';
import path from 'path';
import { basePlugins } from '../../../rollup.utils.mjs';
export default defineConfig([
{
input: path.join(import.meta.dirname, 'server/src/index.ts'),
external: (id) => !path.isAbsolute(id) && !id.startsWith('.'),
output: [
{
dir: path.join(import.meta.dirname, 'dist/server'),
entryFileNames: '[name].js',
chunkFileNames: 'chunks/[name]-[hash].js',
exports: 'auto',
format: 'cjs',
sourcemap: true,
},
{
dir: path.join(import.meta.dirname, 'dist/server'),
entryFileNames: '[name].mjs',
chunkFileNames: 'chunks/[name]-[hash].js',
exports: 'auto',
format: 'esm',
sourcemap: true,
},
],
plugins: [...basePlugins(import.meta.dirname)],
},
{
input: path.join(import.meta.dirname, 'admin/src/index.ts'),
external: (id) => !path.isAbsolute(id) && !id.startsWith('.'),
output: [
{
dir: path.join(import.meta.dirname, 'dist/admin'),
entryFileNames: '[name].js',
chunkFileNames: 'chunks/[name]-[hash].js',
exports: 'auto',
format: 'cjs',
sourcemap: true,
},
{
dir: path.join(import.meta.dirname, 'dist/admin'),
entryFileNames: '[name].mjs',
chunkFileNames: 'chunks/[name]-[hash].js',
exports: 'auto',
format: 'esm',
sourcemap: true,
},
],
plugins: [...basePlugins(import.meta.dirname)],
},
]);

View File

@ -1,5 +1,5 @@
import { Job } from 'node-schedule';
import { Core } from '@strapi/types';
import type { Core } from '@strapi/types';
import { Release } from '../../shared/contracts/releases';
import { getService } from './utils';

View File

@ -1,4 +1,4 @@
import { Modules, UID } from '@strapi/types';
import type { Modules, UID } from '@strapi/types';
import { contentTypes } from '@strapi/utils';
import { RELEASE_MODEL_UID, RELEASE_ACTION_MODEL_UID } from '../constants';
import { getService, isEntryValid } from '../utils';

View File

@ -1,5 +1,5 @@
import { scheduleJob, Job } from 'node-schedule';
import { Core } from '@strapi/types';
import type { Core } from '@strapi/types';
import { errors } from '@strapi/utils';
import { Release } from '../../../shared/contracts/releases';

View File

@ -1,5 +1,5 @@
import { errors, contentTypes } from '@strapi/utils';
import { Core, UID } from '@strapi/types';
import type { Core, UID } from '@strapi/types';
import type { Release, CreateRelease, UpdateRelease } from '../../../shared/contracts/releases';
import type { CreateReleaseAction } from '../../../shared/contracts/release-actions';
import { RELEASE_MODEL_UID } from '../constants';

View File

@ -1,10 +1,11 @@
{
"extends": "./tsconfig.json",
"include": ["./src", "./custom.d.ts", "../shared"],
"exclude": ["**/*.test.ts"],
"compilerOptions": {
"rootDir": "../",
"baseUrl": ".",
"outDir": "./dist"
}
"outDir": "../dist",
"noEmit": false
},
"include": ["./src", "./custom.d.ts", "../shared"],
"exclude": ["node_modules", "**/*.test.ts"]
}

View File

@ -4,7 +4,7 @@
*/
import { errors } from '@strapi/utils';
import { Utils } from '@strapi/types';
import type { Utils } from '@strapi/types';
export interface Settings {
defaultTimezone: string | null | undefined;

View File

@ -1 +1,2 @@
dist/
rollup.config.mjs

View File

@ -19,7 +19,7 @@ export default {
icon: Layout,
intlLabel: {
id: `${pluginId}.plugin.name`,
defaultMessage: 'Content Types Builder',
defaultMessage: 'Content-Type Builder',
},
permissions: PERMISSIONS.main,
Component: () => import('./pages/App'),

View File

@ -1,10 +1,11 @@
{
"extends": "./tsconfig.json",
"include": ["./src"],
"exclude": ["**/tests/**"],
"compilerOptions": {
"rootDir": "../",
"baseUrl": ".",
"outDir": "./dist"
}
"outDir": "../dist",
"noEmit": false
},
"include": ["./src"],
"exclude": ["node_modules", "**/tests/**"]
}

View File

@ -42,7 +42,11 @@
"strapi-server.js"
],
"scripts": {
"build": "pack-up build",
"build": "run -T npm-run-all clean --parallel build:code build:types",
"build:code": "run -T rollup -c",
"build:types": "run -T run-p build:types:server build:types:admin",
"build:types:server": "run -T tsc -p server/tsconfig.build.json --emitDeclarationOnly",
"build:types:admin": "run -T tsc -p admin/tsconfig.build.json --emitDeclarationOnly",
"clean": "run -T rimraf ./dist",
"lint": "run -T eslint .",
"test:front": "run -T cross-env IS_EE=true jest --config ./jest.config.front.js",
@ -53,7 +57,7 @@
"test:ts:front": "run -T tsc -p admin/tsconfig.json",
"test:unit": "run -T jest",
"test:unit:watch": "run -T jest --watch",
"watch": "pack-up watch"
"watch": "run -T rollup -c -w"
},
"dependencies": {
"@reduxjs/toolkit": "1.9.7",
@ -74,7 +78,6 @@
},
"devDependencies": {
"@strapi/admin": "5.8.1",
"@strapi/pack-up": "5.0.2",
"@strapi/types": "5.8.1",
"@testing-library/dom": "10.1.0",
"@testing-library/react": "15.0.7",

View File

@ -1,33 +0,0 @@
import { defineConfig, Config } from '@strapi/pack-up';
const config: Config = defineConfig({
bundles: [
{
source: './admin/src/index.ts',
import: './dist/admin/index.mjs',
require: './dist/admin/index.js',
types: './dist/admin/src/index.d.ts',
tsconfig: './admin/tsconfig.build.json',
runtime: 'web',
},
{
source: './server/src/index.ts',
import: './dist/server/index.mjs',
require: './dist/server/index.js',
types: './dist/server/src/index.d.ts',
tsconfig: './server/tsconfig.build.json',
runtime: 'node',
},
],
externals: ['path'],
dist: './dist',
/**
* Because we're exporting a server & client package
* which have different runtimes we want to ignore
* what they look like in the package.json
*/
exports: {},
});
export default config;

View File

@ -0,0 +1,52 @@
import { defineConfig } from 'rollup';
import path from 'path';
import { basePlugins } from '../../../rollup.utils.mjs';
export default defineConfig([
{
input: path.join(import.meta.dirname, 'server/src/index.ts'),
external: (id) => !path.isAbsolute(id) && !id.startsWith('.'),
output: [
{
dir: path.join(import.meta.dirname, 'dist/server'),
entryFileNames: '[name].js',
chunkFileNames: 'chunks/[name]-[hash].js',
exports: 'auto',
format: 'cjs',
sourcemap: true,
},
{
dir: path.join(import.meta.dirname, 'dist/server'),
entryFileNames: '[name].mjs',
chunkFileNames: 'chunks/[name]-[hash].js',
exports: 'auto',
format: 'esm',
sourcemap: true,
},
],
plugins: [...basePlugins(import.meta.dirname)],
},
{
input: path.join(import.meta.dirname, 'admin/src/index.ts'),
external: (id) => !path.isAbsolute(id) && !id.startsWith('.'),
output: [
{
dir: path.join(import.meta.dirname, 'dist/admin'),
entryFileNames: '[name].js',
chunkFileNames: 'chunks/[name]-[hash].js',
exports: 'auto',
format: 'cjs',
sourcemap: true,
},
{
dir: path.join(import.meta.dirname, 'dist/admin'),
entryFileNames: '[name].mjs',
chunkFileNames: 'chunks/[name]-[hash].js',
exports: 'auto',
format: 'esm',
sourcemap: true,
},
],
plugins: [...basePlugins(import.meta.dirname)],
},
]);

View File

@ -1,10 +1,11 @@
{
"extends": "./tsconfig.json",
"include": ["./src"],
"exclude": ["node_modules", "**/__tests__/**"],
"compilerOptions": {
"rootDir": "../",
"baseUrl": ".",
"outDir": "./dist"
}
"outDir": "../dist",
"noEmit": false
},
"include": ["./src"],
"exclude": ["node_modules", "**/__tests__/**"]
}

View File

@ -3,3 +3,5 @@ node_modules/
jest.config.js
dist/
scripts/
rollup.config.mjs

Some files were not shown because too many files have changed in this diff Show More