Ben Irvin 82460d7ac3
release: 5.5.0 (#22340)
* feat: use mux player for video

Signed-off-by: Sora Morimoto <sora@morimoto.io>

* chore(deps): bump @strapi/design-system from 2.0.0-rc.13 to 2.0.0-rc.14 (#22274)

* enhancement: disable preview link when changes are not saved (#22275)

* feat: send diagnostic messages from remote strapi (#22214)

* chore: re-add some controls

* chore: test-snapshots

* ci: use correct fetch-depth (#22288)

* test(front): update snapshots

* ci: use correct fetch-depth

* Chore: setting up nx releases (#22264)

* chore(deps): update @strapi/pack-up to v5.0.2 (#22261)

---------

Co-authored-by: Ben Irvin <ben@innerdvations.com>

* Fix: move msw to devDeps and change koa range (#22129)

---------

Co-authored-by: Ben Irvin <ben.irvin@strapi.io>

* chore: remove yarn.lock from templates/website (#22294)

* fix: turn on and update i18n settings.spec.ts (#22282)

* chore: use "workspace:*" for internal dependencies (#22303)

* chore: use "workspace:*" for internal dependencies

* chore: update yarn lock

* ci: fix docs_build (#22304)

* ci: fix docs_build

* ci: run docs_build on global changes

* chore: upgrade vite-plugin-dts (#22297)

* fix: document actions being rendered multiple times (#22283)

* chore: update sdk-plugin and dedupe yarn.lock (#22296)

* chore: cleanup removing support for assets without metadata (#22215)

* Update: Purchase Page links + Add Content History menu link (#21531)

* Update: Purchase Page links + Add Content History menu link

* enhancement:Update Purchase Page links + Add Content History menu link

* enhancement: update purchase page links

* chore: update links

---------

Co-authored-by: Simone <startae14@gmail.com>

* fix: add documentId to `me` graphql query (#22321)

* fix(preview): page title and disabled link (#22324)

* fix: add preview title tag to get browser tooltip

* fix: same header title as edit view

* fix: disabled preview button

* chore: remove useless variable

* fix: broken hover in e2e tests

* fix: prevent flaky iframe src check

* release: 5.5.0

* release: update missed version numbers

* release: update yarn.lock

* release: use workspace for internal packages

* release: update yarn.lock

---------

Signed-off-by: Sora Morimoto <sora@morimoto.io>
Co-authored-by: Sora Morimoto <sora@morimoto.io>
Co-authored-by: markkaylor <mark.kaylor@strapi.io>
Co-authored-by: Rémi de Juvigny <8087692+remidej@users.noreply.github.com>
Co-authored-by: Bassel Kanso <basselkanso82@gmail.com>
Co-authored-by: Alexandre Bodin <bodin.alex@gmail.com>
Co-authored-by: Rémi de Juvigny <remi.dejuvigny@strapi.io>
Co-authored-by: Jonas Thelemann <e-mail@jonas-thelemann.de>
Co-authored-by: Adrien Foulon <6115458+Tofandel@users.noreply.github.com>
Co-authored-by: Maxime Castres <17828745+Mcastres@users.noreply.github.com>
Co-authored-by: Simone <startae14@gmail.com>
Co-authored-by: Laurens Kling <laurens@goedideemedia.nl>
Co-authored-by: Alexandre BODIN <alexandrebodin@users.noreply.github.com>
2024-12-04 16:15:06 +01:00
..
2024-10-16 12:33:32 +02:00
2024-12-04 16:15:06 +01:00

Strapi Upgrade Tool

Description

The Strapi Upgrade Tool is the CLI for facilitating upgrades between Strapi versions.

It handles updating a project's package.json with the correct version of Strapi, running the package installer, and running suggested code transforms for breaking changes (in major versions).

Once released, it will be the recommended way to update to any major, minor, and patch versions of Strapi instead of manually modifying package.json files.

The tool offers the following commands:

  major [options]     Upgrade to the next available major version of Strapi
  minor [options]     Upgrade to the latest minor and patch version of Strapi for the
                      current major
  patch [options]     Upgrade to latest patch version of Strapi for the current major
                      and minor
  codemods [options]  Run a set of available codemods for the selected target version
                      without updating the Strapi dependencies

What's a codemod / code transform?

Codemods are a scripted way to refactor code. Here we are providing and running these scripts for users for any changes necessary in user code between Strapi versions.

For example, if we need to rename a package used by Strapi projects, instead of instructing users to change the import, we provide a script that searches through the user's project and does the replacement for them.

Types of Transforms

The upgrade tool provides two types of transforms:

  • json: for updating a project's .json files, primarily intended for the package.json
  • code: codemods; for updating a project's .js and .ts files

Data Migrations

Data migrations are not handled by the upgrade tool.

For Strapi v4, no data migrations will be allowed and no support is planned (except in extenuating circumstances eg, a critical security issue somehow relating to the database shape)

For Strapi v5, automated data migrations can be added in the packages/core/database package of the develop branch of this repo.

Usage

This package is not yet released, so currently it can be run on a project in the monorepo /examples directory with the following command:

../../packages/utils/upgrade/bin/upgrade

Run the command with the --help option to see all the available options.

[Coming Soon] The Strapi Upgrade tool will be available using npx @strapi/upgrade and an alias for that within a project using strapi upgrade

Writing a code transforms

To begin your code transform script, create a file upgrade/resources/codemods/{X.X.X}/{short-description-of-action}.{code|json}.ts where X.X.X is the target version of Strapi the codemod will be run for.

For example, all breaking changes for the initial release of Strapi v5 will go in upgrade/resources/codemods/5.0.0

Note that "short-description-of-action" will be converted to text displayed to the user with hyphens converted to spaces, for example: "short description of action"

'json' transforms

Your transform will be called for every json file in a user's project, and you must return the json object (modified or not) at the end to be passed to the next transform.

Here is an example JSON Transform script:

import path from 'node:path';

import type { JSONTransform } from '../../..';

const transform: JSONTransform = (file, params) => {
  // Extract the json api and the cwd so we can target specific files
  const { cwd, json } = params;

  // To target only a root level package.json file:
  const rootPackageJsonPath = path.join(cwd, 'package.json');
  if (file.path !== rootPackageJsonPath) {
    // Return the json object unmodified to pass it to the next transform
    return file.json;
  }

  // Use json() to get useful helpers for performing your transform
  const j = json(file.json);

  const strapiDepAddress = 'dependencies.@strapi/strapi';

  // if this file contains a value at dependencies.@strapi/strapi
  if (j.has(strapiDepAddress)) {
    // we set the value to 5.0.0
    j.set(strapiDepAddress, '5.0.0');
  }

  // at the end we must return the modified json object
  return j.root();
};

export default transform;

For reference, these are the types for the relevant objects, which can be found in packages/utils/upgrade/src/modules/json/types.ts:

export interface JSONTransformParams {
  cwd: string;
  json: (object: Utils.JSONObject) => JSONTransformAPI;
}

export interface JSONTransformAPI {
  get<T extends Utils.JSONValue>(path?: string, defaultValue?: T): T | undefined;
  has(path: string): boolean;
  set(path: string, value: Utils.JSONValue): this;
  merge(other: Utils.JSONObject): this;
  root(): Utils.JSONObject;
  remove(path: string): this;
}

export type JSONTransform = (file: JSONSourceFile, params: JSONTransformParams) => Utils.JSONObject;

The methods available from json() are wrappers for the lodash methods of the same name:

  • get(path, default): get path or default if not found
  • set(path, value): set path (such as 'engines.node', 'dependencies', 'author.name') to value
  • has(path): checks if path exists
  • merge(obj): merges two json objects
  • root(): returns the whole json object
  • remove(path): removes the attribute given the path (such as 'dependencies.strapi')

'code' codemod transforms

Codemod transforms use the jscodeshift library to modify code passed in. Please see their documentation for advanced details.

The file and api parameters come directly from the jsoncodeshift arguments of the same name.

import type { Transform } from 'jscodeshift';

const transform: Transform = (file, api) => {
  // Extract the jscodeshift API
  const { j } = api;
  // Parse the file content
  const root = j(file.source);

  root
    // Find console.log calls expressions
    .find(j.CallExpression, {
      callee: { object: { name: 'console' }, property: { name: 'log' } },
    })
    // For each call expression
    .forEach((path) => {
      const { callee } = path.node;

      if (
        // Make sure the callee is a member expression (object/property)
        j.MemberExpression.check(callee) &&
        // Make sure the property is an actual identifier (contains a name property)
        j.Identifier.check(callee.property)
      ) {
        // Update the property's identifier name
        callee.property.name = 'info';
      }
    });

  // Return the updated file content
  return root.toSource();
};

export default transform;