Skip to content

Commit

Permalink
Merge branch 'develop' into v5/main
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaellis committed Jan 11, 2024
2 parents 55ed5ff + a3690b1 commit d402c40
Show file tree
Hide file tree
Showing 73 changed files with 1,600 additions and 569 deletions.
65 changes: 50 additions & 15 deletions .github/actions/yarn-nm-install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,40 @@
# - name: 📥 Monorepo install #
# uses: ./.github/actions/yarn-nm-install #
# with: #
# enable-corepack: false # (default) #
# cache-install-state: false # (default) #
# cache-node-modules: false # (default) #
# enable-corepack: false # (default = 'false') #
# cache-npm-cache: false # (default = 'true') #
# cwd: ${{ github.workspace }}/apps/my-app # (default = '.') #
# cache-prefix: add cache key prefix # (default = 'default') #
# cache-node-modules: false # (default = 'false') #
# cache-install-state: false # (default = 'false') #
# #
# Reference: #
# - latest: https://gist.github.com/belgattitude/042f9caf10d029badbde6cf9d43e400a #
# #
# Versions: #
# - 1.1.0 - 22-07-2023 - Option to enable npm global cache folder. #
# - 1.0.4 - 15-07-2023 - Fix corepack was always enabled. #
# - 1.0.3 - 05-07-2023 - YARN_ENABLE_MIRROR to false (speed up cold start) #
# - 1.0.2 - 02-06-2023 - install-state default to false #
# - 1.0.1 - 29-05-2023 - cache-prefix doc #
# - 1.0.0 - 27-05-2023 - new input: cache-prefix #
########################################################################################

name: 'Monorepo install (yarn)'
description: 'Run yarn install with node_modules linker and cache enabled'
inputs:
enable-corepack:
description: 'Enable corepack'
cwd:
description: "Changes node's process.cwd() if the project is not located on the root. Default to process.cwd()"
required: false
default: 'false'
default: '.'
cache-prefix:
description: 'Add a specific cache-prefix'
required: false
default: 'default'
cache-npm-cache:
description: 'Cache npm global cache folder often used by node-gyp, prebuild binaries (invalidated on lock/os/node-version)'
required: false
default: 'true'
cache-node-modules:
description: 'Cache node_modules, might speed up link step (invalidated lock/os/node-version/branch)'
required: false
Expand All @@ -31,58 +50,74 @@ inputs:
description: 'Cache yarn install state, might speed up resolution step when node-modules cache is activated (invalidated lock/os/node-version/branch)'
required: false
default: 'false'
enable-corepack:
description: 'Enable corepack'
required: false
default: 'true'

runs:
using: 'composite'

steps:
- name: ⚙️ Enable Corepack
if: ${{ inputs.enable-corepack }} == 'true'
if: inputs.enable-corepack == 'true'
shell: bash
working-directory: ${{ inputs.cwd }}
run: corepack enable

- name: ⚙️ Expose yarn config as "$GITHUB_OUTPUT"
id: yarn-config
shell: bash
working-directory: ${{ inputs.cwd }}
env:
YARN_ENABLE_GLOBAL_CACHE: 'false'
run: |
echo "CACHE_FOLDER=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
echo "CURRENT_NODE_VERSION="node-$(node --version)"" >> $GITHUB_OUTPUT
echo "CURRENT_BRANCH=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's,/,-,g')" >> $GITHUB_OUTPUT
echo "NPM_GLOBAL_CACHE_FOLDER=$(npm config get cache)" >> $GITHUB_OUTPUT
- name: ♻️ Restore yarn cache
uses: actions/cache@v3
id: yarn-download-cache
with:
path: ${{ steps.yarn-config.outputs.CACHE_FOLDER }}
key: yarn-download-cache-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}
key: yarn-download-cache-${{ inputs.cache-prefix }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}
restore-keys: |
yarn-download-cache-
yarn-download-cache-${{ inputs.cache-prefix }}-
- name: ♻️ Restore node_modules
if: inputs.cache-node-modules == 'true'
id: yarn-nm-cache
uses: actions/cache@v3
with:
path: '**/node_modules'
key: yarn-nm-cache-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ steps.yarn-config.outputs.CURRENT_BRANCH }}-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}
path: ${{ inputs.cwd }}/**/node_modules
key: yarn-nm-cache-${{ inputs.cache-prefix }}-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ steps.yarn-config.outputs.CURRENT_BRANCH }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}

- name: ♻️ Restore global npm cache folder
if: inputs.cache-npm-cache == 'true'
id: npm-global-cache
uses: actions/cache@v3
with:
path: ${{ steps.yarn-config.outputs.NPM_GLOBAL_CACHE_FOLDER }}
key: npm-global-cache-${{ inputs.cache-prefix }}-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}

- name: ♻️ Restore yarn install state
if: inputs.cache-install-state == 'true' && inputs.cache-node-modules == 'true'
id: yarn-install-state-cache
uses: actions/cache@v3
with:
path: .yarn/ci-cache
key: yarn-install-state-cache-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ steps.yarn-config.outputs.CURRENT_BRANCH }}-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}
path: ${{ inputs.cwd }}/.yarn/ci-cache
key: yarn-install-state-cache-${{ inputs.cache-prefix }}-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ steps.yarn-config.outputs.CURRENT_BRANCH }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}

- name: 📥 Install dependencies
shell: bash
working-directory: ${{ inputs.cwd }}
run: yarn install --immutable --inline-builds
env:
# Overrides/align yarnrc.yml options (v3, v4) for a CI context
YARN_ENABLE_GLOBAL_CACHE: 'false' # Use local cache folder to keep downloaded archives
YARN_ENABLE_MIRROR: 'false' # Prevent populating global cache for caches misses (local cache only)
YARN_NM_MODE: 'hardlinks-local' # Reduce node_modules size
YARN_INSTALL_STATE_PATH: '.yarn/ci-cache/install-state.gz' # Might speed up resolutions when node_modules present
YARN_INSTALL_STATE_PATH: '.yarn/ci-cache/install-state.gz' # Might speed up resolution step when node_modules present
# Other environment variables
HUSKY: '0' # By default do not run HUSKY install
2 changes: 1 addition & 1 deletion .github/workflows/contributor-doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Deploy contributor doc
on:
push:
branches:
- 'main'
- 'develop'
paths:
- 'docs/**'

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- develop
pull_request:
paths-ignore:
- 'docs/**'
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The Strapi core team will review your pull request and either merge it, request

**Before submitting your pull request** make sure the following requirements are fulfilled:

- Fork the repository and create your new branch from `main`.
- Fork the repository and create your new branch from `develop`.
- Run `yarn install` in the root of the repository.
- Run `yarn setup` in the root of the repository.
- If you've fixed a bug or added code that should be tested, please make sure to add tests
Expand Down Expand Up @@ -212,7 +212,7 @@ Examples:

We chose to use a monorepo design using [Yarn Workspaces](https://yarnpkg.com/en/docs/workspaces) in the way [React](https://github.com/facebook/react/tree/master/packages) or [Babel](https://github.com/babel/babel/tree/master/packages) does. This allows us to maintain the whole ecosystem keep it up-to-date and consistent.

We do our best to keep the master branch as clean as possible, with tests passing at all times. However, the master branch can move faster than the release cycle. Therefore check the [releases on npm](https://www.npmjs.com/package/@strapi/strapi) so that you are always up-to-date with the latest stable version.
We do our best to keep the develop branch as clean as possible, with tests passing at all times. However, the develop branch can move faster than the release cycle. Therefore check the [releases on npm](https://www.npmjs.com/package/@strapi/strapi) so that you are always up-to-date with the latest stable version.

### Reporting an issue

Expand Down
2 changes: 1 addition & 1 deletion examples/getstarted/config/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = () => ({
},
myplugin: {
enabled: true,
resolve: `./src/plugins/myplugin`, // From the root of the project
resolve: `./src/plugins/local-plugin`, // From the root of the project
config: {
testConf: 3,
},
Expand Down
1 change: 1 addition & 0 deletions examples/getstarted/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"react-dom": "^18.2.0",
"react-intl": "6.4.1",
"react-router-dom": "5.3.4",
"strapi-plugin-workspace-plugin": "workspace:*",
"styled-components": "5.3.3"
},
"engines": {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "strapi-plugin-my-plugin",
"name": "strapi-plugin-local-plugin",
"version": "0.0.0",
"private": true,
"description": "This is the description of my plugin.",
"strapi": {
"name": "my-plugin",
"description": "Description of my plugin.",
"name": "local-plugin",
"description": "This plugin is linked as a local plugin",
"kind": "plugin"
}
}
3 changes: 3 additions & 0 deletions examples/getstarted/src/plugins/local-plugin/strapi-admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import admin from './admin/src';

export default admin;
1 change: 0 additions & 1 deletion examples/getstarted/src/plugins/myplugin/strapi-admin.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
*
* PluginIcon
*
*/

import React from 'react';
import { Puzzle } from '@strapi/icons';

const PluginIcon = () => <Puzzle />;

export default PluginIcon;
29 changes: 29 additions & 0 deletions examples/plugins/workspace-plugin/admin/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import PluginIcon from './components/PluginIcon';
import pluginPkg from '../../package.json';
import pluginId from './pluginId';

const name = pluginPkg.strapi.name;

export default {
register(app) {
app.addMenuLink({
to: `/plugins/${pluginId}`,
icon: PluginIcon,
intlLabel: {
id: `${pluginId}.plugin.name`,
defaultMessage: 'My plugin',
},
Component: async () => {
const component = await import('./pages/App');

return component;
},
permissions: [],
});

app.registerPlugin({
id: pluginId,
name,
});
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const App = () => {
return 'I am a workspace plugin, imported via node_modules.';
};

export default App;
5 changes: 5 additions & 0 deletions examples/plugins/workspace-plugin/admin/src/pluginId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import pluginPkg from '../../package.json';

const pluginId = pluginPkg.name.replace(/^strapi-plugin-/i, '');

export default pluginId;
24 changes: 24 additions & 0 deletions examples/plugins/workspace-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "strapi-plugin-workspace-plugin",
"version": "0.0.0",
"private": true,
"description": "This is the description of my plugin.",
"exports": {
"./strapi-admin": {
"source": "./admin/src/index.js",
"require": "./admin/src/index.js",
"default": "./admin/src/index.js"
},
"./strapi-server": {
"source": "./strapi-server.js",
"require": "./strapi-server.js",
"default": "./strapi-server.js"
},
"./package.json": "./package.json"
},
"strapi": {
"name": "my-plugin",
"description": "This plugin is used as an npm module and linked that way.",
"kind": "plugin"
}
}
12 changes: 12 additions & 0 deletions examples/plugins/workspace-plugin/server/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

module.exports = {
default: {
testConf: 1,
},
validator: (config) => {
if (typeof config.testConf !== 'number') {
throw new Error('testConfig has to be a number');
}
},
};
3 changes: 3 additions & 0 deletions examples/plugins/workspace-plugin/server/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = ({ strapi }) => {};
10 changes: 10 additions & 0 deletions examples/plugins/workspace-plugin/strapi-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

const config = require('./server/config');
const register = require('./server/register');
module.exports = () => {
return {
register,
config,
};
};
5 changes: 4 additions & 1 deletion jest-preset.front.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const moduleNameMapper = {
'^styled-components$': path.join(__dirname, 'node_modules/styled-components'),
};

/**
* @type {import('jest').Config}
*/
module.exports = {
rootDir: __dirname,
moduleNameMapper,
Expand Down Expand Up @@ -76,7 +79,7 @@ module.exports = {
path.join(__dirname, 'fileTransformer.js'),
},
transformIgnorePatterns: [
'node_modules/(?!(react-dnd|dnd-core|react-dnd-html5-backend|@strapi/design-system|@strapi/icons|fractional-indexing)/)',
'node_modules/(?!(react-dnd|dnd-core|react-dnd-html5-backend|@react-dnd|fractional-indexing)/)',
],
testMatch: ['**/tests/**/?(*.)+(spec|test).[jt]s?(x)'],
testEnvironmentOptions: {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"packages/*",
"packages/*/*",
"examples/*",
"examples/plugins/*",
".github/actions/*",
"scripts/*"
],
Expand Down
2 changes: 2 additions & 0 deletions packages/core/admin/admin/custom.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference types="vite/client" />

import { type StrapiTheme } from '@strapi/design-system';
import { type Attribute, type FeaturesService } from '@strapi/types';
import { type BaseEditor } from 'slate';
Expand Down
7 changes: 6 additions & 1 deletion packages/core/admin/admin/src/components/DefaultDocument.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ const globalStyles = `
}
`;

interface DefaultDocumentProps {
entryPath?: string;
}

/**
* @internal
*/
const DefaultDocument = () => {
const DefaultDocument = ({ entryPath }: DefaultDocumentProps) => {
return (
<html lang="en">
<head>
Expand All @@ -34,6 +38,7 @@ const DefaultDocument = () => {
<body>
<div id="strapi" />
<NoJavascript />
{entryPath ? <script type="module" src={entryPath} /> : null}
</body>
</html>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ import sub from 'markdown-it-sub';
// @ts-expect-error - library does not export types
import sup from 'markdown-it-sup';

const loadCss = async () => {
// @ts-expect-error – idm
await import('highlight.js/styles/solarized-dark.css');
};

loadCss();
import 'highlight.js/styles/solarized-dark.css';

const md: Markdown = new Markdown({
html: true, // Enable HTML tags in source
Expand Down
4 changes: 4 additions & 0 deletions packages/core/admin/admin/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ const renderAdmin = async (
) {
module.hot.accept();
}

if (typeof import.meta.hot?.accept === 'function') {
import.meta.hot.accept();
}
};

export { renderAdmin };
Expand Down
Loading

0 comments on commit d402c40

Please sign in to comment.