Skip to content

Commit

Permalink
Merge branch 'trunk' into update/full-screen-modal-pattern-grid
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskoster committed Apr 19, 2023
2 parents 0f93404 + f24c5b2 commit 4a9e2ec
Show file tree
Hide file tree
Showing 79 changed files with 1,766 additions and 742 deletions.
121 changes: 121 additions & 0 deletions bin/packages/check-build-type-declaration-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/**
* This script verifies the published index.d.ts file for every package which both
* builds types and also sets checkJs to false in its tsconfig.json. (This scenario
* can cause unchecked errors in JS files to be included in the compiled types.)
*
* We do so by running `tsc --noEmit` on the $package/build-types/index.d.ts file.
* This also verifies everything index.d.ts references, so it checks the entire
* public api of the type declarations for that package.
*
* @see https://github.com/WordPress/gutenberg/pull/49650 for more discussion.
*/

/**
* External dependencies
*/
const fs = require( 'fs' ).promises;
const path = require( 'path' );
const { exec } = require( 'child_process' );
const chalk = require( 'chalk' );

/**
* Returns whether a package needs its compiled types to be double-checked. This
* needs to happen when both of these are true:
* 1. The package compiles types. (It has a tsconfig file.)
* 2. The tsconfig sets checkJs to false.
*
* NOTE: In the future, if we run into issues parsing JSON, we should migrate to
* a proper json5 parser, such as the json5 npm package. The current regex just
* handles comments, which at the time is the only thing we use from JSON5.
*
* @param {string} packagePath Path to the package.
* @return {boolean} whether or not the package checksJs.
*/
async function packageNeedsExtraCheck( packagePath ) {
const configPath = path.join( packagePath, 'tsconfig.json' );

try {
const tsconfigRaw = await fs.readFile( configPath, 'utf-8' );
// Removes comments from the JSON5 string to convert it to plain JSON.
const jsonString = tsconfigRaw.replace( /\s+\/\/.*$/gm, '' );
const config = JSON.parse( jsonString );

// If checkJs both exists and is false, then we need the extra check.
return config.compilerOptions?.checkJs === false;
} catch ( e ) {
if ( e.code !== 'ENOENT' ) {
throw e;
}

// No tsconfig means no checkJs
return false;
}
}

// Returns the path to the build-types declaration file for a package if it exists.
// Throws an error and exits the script otherwise.
async function getDecFile( packagePath ) {
const decFile = path.join( packagePath, 'build-types', 'index.d.ts' );
try {
await fs.access( decFile );
return decFile;
} catch ( err ) {
console.error(
`Cannot access this declaration file. You may need to run tsc again: ${ decFile }`
);
process.exit( 1 );
}
}

async function typecheckDeclarations( file ) {
return new Promise( ( resolve, reject ) => {
exec( `npx tsc --noEmit ${ file }`, ( error, stdout, stderr ) => {
if ( error ) {
reject( { file, error, stderr, stdout } );
} else {
resolve( { file, stdout } );
}
} );
} );
}

async function checkUnverifiedDeclarationFiles() {
const packageDir = path.resolve( 'packages' );
const packageDirs = (
await fs.readdir( packageDir, { withFileTypes: true } )
)
.filter( ( dirent ) => dirent.isDirectory() )
.map( ( dirent ) => path.join( packageDir, dirent.name ) );

// Finds the compiled type declarations for each package which both checks
// types and has checkJs disabled.
const declarations = (
await Promise.all(
packageDirs.map( async ( pkg ) =>
( await packageNeedsExtraCheck( pkg ) )
? getDecFile( pkg )
: null
)
)
).filter( Boolean );

const tscResults = await Promise.allSettled(
declarations.map( typecheckDeclarations )
);

tscResults.forEach( ( { status, reason } ) => {
if ( status !== 'fulfilled' ) {
console.error(
chalk.red(
`Incorrect published types for ${ reason.file }:\n`
),
reason.stdout
);
}
} );

if ( tscResults.some( ( { status } ) => status !== 'fulfilled' ) ) {
process.exit( 1 );
}
}
checkUnverifiedDeclarationFiles();
25 changes: 25 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
== Changelog ==

= 15.6.0-rc.3 =



## Changelog

### Bug Fixes

#### Site Editor
- Fix the site editor loading in multi-site installs. ([49861](https://github.com/WordPress/gutenberg/pull/49861))


## First time contributors

The following PRs were merged by first time contributors:



## Contributors

The following contributors merged PRs in this release:

@youknowriad


= 15.6.0-rc.2 =


Expand Down
Binary file removed docs/contributors/release-screenshot.png
Binary file not shown.
2 changes: 1 addition & 1 deletion gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Printing since 1440. This is the development plugin for the block editor, site editor, and other future WordPress core functionality.
* Requires at least: 6.0
* Requires PHP: 5.6
* Version: 15.6.0-rc.2
* Version: 15.6.0-rc.3
* Author: Gutenberg Team
* Text Domain: gutenberg
*
Expand Down
96 changes: 49 additions & 47 deletions lib/block-supports/duotone.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,41 @@
* @package gutenberg
*/

// Register duotone block supports.
WP_Block_Supports::get_instance()->register(
'duotone',
array(
'register_attribute' => array( 'WP_Duotone_Gutenberg', 'register_duotone_support' ),
)
);

// Set up metadata prior to rendering any blocks.
add_action( 'wp_loaded', array( 'WP_Duotone_Gutenberg', 'set_global_styles_presets' ), 10 );
add_action( 'wp_loaded', array( 'WP_Duotone_Gutenberg', 'set_global_style_block_names' ), 10 );

// Remove WordPress core filter to avoid rendering duplicate support elements.
remove_filter( 'render_block', 'wp_render_duotone_support', 10, 2 );
add_filter( 'render_block', array( 'WP_Duotone_Gutenberg', 'render_duotone_support' ), 10, 2 );

// Enqueue styles.
// Block styles (core-block-supports-inline-css) before the style engine (gutenberg_enqueue_stored_styles).
// Global styles (global-styles-inline-css) after the other global styles (gutenberg_enqueue_global_styles).
add_action( 'wp_enqueue_scripts', array( 'WP_Duotone_Gutenberg', 'output_block_styles' ), 9 );
add_action( 'wp_enqueue_scripts', array( 'WP_Duotone_Gutenberg', 'output_global_styles' ), 11 );

// Add SVG filters to the footer. Also, for classic themes, output block styles (core-block-supports-inline-css).
add_action( 'wp_footer', array( 'WP_Duotone_Gutenberg', 'output_footer_assets' ), 10 );

// Add styles and SVGs for use in the editor via the EditorStyles component.
add_filter( 'block_editor_settings_all', array( 'WP_Duotone_Gutenberg', 'add_editor_settings' ), 10 );

// Migrate the old experimental duotone support flag.
add_filter( 'block_type_metadata_settings', array( 'WP_Duotone_Gutenberg', 'migrate_experimental_duotone_support_flag' ), 10, 2 );

/*
* Deprecated functions below. All new functions should be added in class-wp-duotone-gutenberg.php.
*/

/**
* Direct port of tinycolor's bound01 function, lightly simplified to maintain
* consistency with tinycolor.
Expand Down Expand Up @@ -317,29 +352,27 @@ function gutenberg_tinycolor_string_to_rgb( $color_str ) {
/**
* Returns the prefixed id for the duotone filter for use as a CSS id.
*
* @deprecated 6.3.0
*
* @param array $preset Duotone preset value as seen in theme.json.
* @return string Duotone filter CSS id.
*/
function gutenberg_get_duotone_filter_id( $preset ) {
if ( ! isset( $preset['slug'] ) ) {
return '';
}

return 'wp-duotone-' . $preset['slug'];
_deprecated_function( __FUNCTION__, '6.3.0' );
return WP_Duotone_Gutenberg::get_filter_id_from_preset( $preset );
}

/**
* Returns the CSS filter property url to reference the rendered SVG.
*
* @deprecated 6.3.0
*
* @param array $preset Duotone preset value as seen in theme.json.
* @return string Duotone CSS filter property url value.
*/
function gutenberg_get_duotone_filter_property( $preset ) {
if ( isset( $preset['colors'] ) && is_string( $preset['colors'] ) ) {
return $preset['colors'];
}
$filter_id = gutenberg_get_duotone_filter_id( $preset );
return "url('#" . $filter_id . "')";
_deprecated_function( __FUNCTION__, '6.3.0' );
return WP_Duotone_Gutenberg::get_filter_css_property_value_from_preset( $preset );
}

/**
Expand All @@ -358,56 +391,25 @@ function gutenberg_get_duotone_filter_svg( $preset ) {
/**
* Registers the style and colors block attributes for block types that support it.
*
* @deprecated 6.3.0 Use WP_Duotone_Gutenberg::register_duotone_support() instead.
*
* @param WP_Block_Type $block_type Block Type.
*/
function gutenberg_register_duotone_support( $block_type ) {
$has_duotone_support = false;
if ( property_exists( $block_type, 'supports' ) ) {
// Previous `color.__experimentalDuotone` support flag is migrated
// to `filter.duotone` via `block_type_metadata_settings` filter.
$has_duotone_support = _wp_array_get( $block_type->supports, array( 'filter', 'duotone' ), null );
}

if ( $has_duotone_support ) {
if ( ! $block_type->attributes ) {
$block_type->attributes = array();
}

if ( ! array_key_exists( 'style', $block_type->attributes ) ) {
$block_type->attributes['style'] = array(
'type' => 'object',
);
}
}
_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Duotone_Gutenberg::register_duotone_support' );
return WP_Duotone_Gutenberg::register_duotone_support( $block_type );
}

/**
* Render out the duotone stylesheet and SVG.
*
* @deprecated 6.3.0 Use WP_Duotone_Gutenberg::render_duotone_support() instead.
*
* @param string $block_content Rendered block content.
* @param array $block Block object.
* @deprecated 6.3.0 Use WP_Duotone_Gutenberg::render_duotone_support() instead.
* @return string Filtered block content.
*/
function gutenberg_render_duotone_support( $block_content, $block ) {
_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Duotone_Gutenberg::render_duotone_support' );
return WP_Duotone_Gutenberg::render_duotone_support( $block_content, $block );
}

// Register the block support.
WP_Block_Supports::get_instance()->register(
'duotone',
array(
'register_attribute' => 'gutenberg_register_duotone_support',
)
);

add_action( 'wp_loaded', array( 'WP_Duotone_Gutenberg', 'set_global_styles_presets' ), 10 );
add_action( 'wp_loaded', array( 'WP_Duotone_Gutenberg', 'set_global_style_block_names' ), 10 );
// Remove WordPress core filter to avoid rendering duplicate support elements.
remove_filter( 'render_block', 'wp_render_duotone_support', 10, 2 );
add_filter( 'render_block', array( 'WP_Duotone_Gutenberg', 'render_duotone_support' ), 10, 2 );
add_action( 'wp_enqueue_scripts', array( 'WP_Duotone_Gutenberg', 'output_global_styles' ), 11 );
add_action( 'wp_footer', array( 'WP_Duotone_Gutenberg', 'output_footer_assets' ), 10 );
add_filter( 'block_editor_settings_all', array( 'WP_Duotone_Gutenberg', 'add_editor_settings' ), 10 );
add_filter( 'block_type_metadata_settings', array( 'WP_Duotone_Gutenberg', 'migrate_experimental_duotone_support_flag' ), 10, 2 );
Loading

0 comments on commit 4a9e2ec

Please sign in to comment.