diff --git a/.eslintrc.js b/.eslintrc.js index b5c735ca8b029b..9f7da03674a7df 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -14,7 +14,8 @@ const { version } = require( './package' ); * * @type {string} */ -const majorMinorRegExp = escapeRegExp( version.replace( /\.\d+$/, '' ) ) + '(\\.\\d+)?'; +const majorMinorRegExp = + escapeRegExp( version.replace( /\.\d+$/, '' ) ) + '(\\.\\d+)?'; /** * The list of patterns matching files used only for development purposes. @@ -29,7 +30,10 @@ const developmentFiles = [ module.exports = { root: true, - extends: [ 'plugin:@wordpress/eslint-plugin/recommended', 'plugin:eslint-comments/recommended' ], + extends: [ + 'plugin:@wordpress/eslint-plugin/recommended', + 'plugin:eslint-comments/recommended', + ], plugins: [ 'import' ], globals: { wp: 'off', @@ -44,37 +48,46 @@ module.exports = { // we'll get a `SyntaxError` (Invalid regular expression: \ at end of pattern) // here. That's why we use \\u002F in the regexes below. { - selector: 'ImportDeclaration[source.value=/^@wordpress\\u002F.+\\u002F/]', - message: 'Path access on WordPress dependencies is not allowed.', + selector: + 'ImportDeclaration[source.value=/^@wordpress\\u002F.+\\u002F/]', + message: + 'Path access on WordPress dependencies is not allowed.', }, { - selector: 'ImportDeclaration[source.value=/^react-spring(?!\\u002Fweb.cjs)/]', - message: 'The react-spring dependency must specify CommonJS bundle: react-spring/web.cjs', + selector: + 'ImportDeclaration[source.value=/^react-spring(?!\\u002Fweb.cjs)/]', + message: + 'The react-spring dependency must specify CommonJS bundle: react-spring/web.cjs', }, { selector: 'CallExpression[callee.name="deprecated"] Property[key.name="version"][value.value=/' + majorMinorRegExp + '/]', - message: 'Deprecated functions must be removed before releasing this version.', + message: + 'Deprecated functions must be removed before releasing this version.', }, { selector: 'CallExpression[callee.name=/^(__|_n|_nx|_x)$/]:not([arguments.0.type=/^Literal|BinaryExpression$/])', - message: 'Translate function arguments must be string literals.', + message: + 'Translate function arguments must be string literals.', }, { selector: 'CallExpression[callee.name=/^(_n|_nx|_x)$/]:not([arguments.1.type=/^Literal|BinaryExpression$/])', - message: 'Translate function arguments must be string literals.', + message: + 'Translate function arguments must be string literals.', }, { selector: 'CallExpression[callee.name=_nx]:not([arguments.3.type=/^Literal|BinaryExpression$/])', - message: 'Translate function arguments must be string literals.', + message: + 'Translate function arguments must be string literals.', }, { - selector: 'CallExpression[callee.name=/^(__|_x|_n|_nx)$/] Literal[value=/\\.{3}/]', + selector: + 'CallExpression[callee.name=/^(__|_x|_n|_nx)$/] Literal[value=/\\.{3}/]', message: 'Use ellipsis character (โฆ) in place of three dots', }, { @@ -83,22 +96,26 @@ module.exports = { message: 'Use `combineReducers` from `@wordpress/data`', }, { - selector: 'ImportDeclaration[source.value="lodash"] Identifier.imported[name="memoize"]', + selector: + 'ImportDeclaration[source.value="lodash"] Identifier.imported[name="memoize"]', message: 'Use memize instead of Lodashโs memoize', }, { - selector: 'CallExpression[callee.object.name="page"][callee.property.name="waitFor"]', + selector: + 'CallExpression[callee.object.name="page"][callee.property.name="waitFor"]', message: 'Prefer page.waitForSelector instead.', }, { selector: 'JSXAttribute[name.name="id"][value.type="Literal"]', - message: 'Do not use string literals for IDs; use withInstanceId instead.', + message: + 'Do not use string literals for IDs; use withInstanceId instead.', }, { // Discourage the usage of `Math.random()` as it's a code smell // for UUID generation, for which we already have a higher-order // component: `withInstanceId`. - selector: 'CallExpression[callee.object.name="Math"][callee.property.name="random"]', + selector: + 'CallExpression[callee.object.name="Math"][callee.property.name="random"]', message: 'Do not use Math.random() to generate unique IDs; use withInstanceId instead. (If youโre not generating unique IDs: ignore this message.)', }, @@ -119,14 +136,20 @@ module.exports = { overrides: [ { files: [ 'packages/**/*.js' ], - excludedFiles: [ '**/*.@(android|ios|native).js', ...developmentFiles ], + excludedFiles: [ + '**/*.@(android|ios|native).js', + ...developmentFiles, + ], rules: { 'import/no-extraneous-dependencies': 'error', }, }, { files: [ 'packages/**/*.js' ], - excludedFiles: [ 'packages/block-library/src/*/save.js', ...developmentFiles ], + excludedFiles: [ + 'packages/block-library/src/*/save.js', + ...developmentFiles, + ], rules: { 'react/forbid-elements': [ 'error', diff --git a/bin/api-docs/are-readmes-unstaged.js b/bin/api-docs/are-readmes-unstaged.js index b3f5c36e9e9b0e..c466d55bfb2e03 100644 --- a/bin/api-docs/are-readmes-unstaged.js +++ b/bin/api-docs/are-readmes-unstaged.js @@ -19,7 +19,9 @@ const getUnstagedFiles = () => const readmeFiles = getPackages().map( ( [ packageName ] ) => join( 'packages', packageName, 'README.md' ) ); -const unstagedReadmes = getUnstagedFiles().filter( ( element ) => readmeFiles.includes( element ) ); +const unstagedReadmes = getUnstagedFiles().filter( ( element ) => + readmeFiles.includes( element ) +); if ( unstagedReadmes.length > 0 ) { process.exitCode = 1; diff --git a/bin/api-docs/update-readmes.js b/bin/api-docs/update-readmes.js index 98a7a491619e34..ab1805c3fdeccd 100755 --- a/bin/api-docs/update-readmes.js +++ b/bin/api-docs/update-readmes.js @@ -16,7 +16,14 @@ getPackages().forEach( ( entry ) => { // Each target operates over the same file, so it needs to be processed synchronously, // as to make sure the processes don't overwrite each other. const { status, stderr } = spawnSync( - join( __dirname, '..', '..', 'node_modules', '.bin', 'docgen' ).replace( / /g, '\\ ' ), + join( + __dirname, + '..', + '..', + 'node_modules', + '.bin', + 'docgen' + ).replace( / /g, '\\ ' ), [ join( 'packages', packageName, path ), `--output packages/${ packageName }/README.md`, diff --git a/bin/commander.js b/bin/commander.js index b532ee1d865226..788019da2148b8 100755 --- a/bin/commander.js +++ b/bin/commander.js @@ -22,7 +22,8 @@ const uuid = require( 'uuid/v4' ); const gitRepoOwner = 'WordPress'; const gitRepoURL = 'https://github.com/' + gitRepoOwner + '/gutenberg.git'; const svnRepoURL = 'https://plugins.svn.wordpress.org/gutenberg'; -const releasePageURLPrefix = 'https://github.com/WordPress/gutenberg/releases/tag/'; +const releasePageURLPrefix = + 'https://github.com/WordPress/gutenberg/releases/tag/'; // Working Directories const gitWorkingDirectoryPath = path.join( os.tmpdir(), uuid() ); @@ -86,7 +87,11 @@ async function runStep( name, abortMessage, handler ) { await handler(); } catch ( exception ) { console.log( - error( 'The following error happened during the "' + warning( name ) + '" step:' ) + '\n\n', + error( + 'The following error happened during the "' + + warning( name ) + + '" step:' + ) + '\n\n', exception, error( '\n\n' + abortMessage ) ); @@ -142,7 +147,9 @@ async function runSvnRepositoryCloneStep( abortMessage ) { // Cloning the repository await runStep( 'Fetching the SVN repository', abortMessage, async () => { console.log( '>> Fetching the SVN repository' ); - runShellScript( 'svn checkout ' + svnRepoURL + '/trunk ' + svnWorkingDirectoryPath ); + runShellScript( + 'svn checkout ' + svnRepoURL + '/trunk ' + svnWorkingDirectoryPath + ); console.log( '>> The Gutenberg SVN repository has been successfully fetched in the following temporary folder: ' + success( svnWorkingDirectoryPath ) @@ -165,7 +172,9 @@ async function runUpdateTrunkContentStep( version, changelog, abortMessage ) { const readmePath = svnWorkingDirectoryPath + '/readme.txt'; const previousReadmeFileContent = fs.readFileSync( readmePath, 'utf8' ); - const stableTag = previousReadmeFileContent.match( STABLE_TAG_REGEX )[ 0 ]; + const stableTag = previousReadmeFileContent.match( + STABLE_TAG_REGEX + )[ 0 ]; // Delete everything runShellScript( @@ -175,7 +184,9 @@ async function runUpdateTrunkContentStep( version, changelog, abortMessage ) { // Update the content using the plugin ZIP const gutenbergZipPath = gitWorkingDirectoryPath + '/gutenberg.zip'; - runShellScript( 'unzip ' + gutenbergZipPath + ' -d ' + svnWorkingDirectoryPath ); + runShellScript( + 'unzip ' + gutenbergZipPath + ' -d ' + svnWorkingDirectoryPath + ); // Replace the stable tag placeholder with the existing stable tag on the SVN repository. const newReadmeFileContent = fs.readFileSync( readmePath, 'utf8' ); @@ -233,7 +244,11 @@ async function runSvnTagStep( version, abortMessage ) { '"' ); - console.log( '>> The SVN ' + success( version ) + ' tag has been successfully created' ); + console.log( + '>> The SVN ' + + success( version ) + + ' tag has been successfully created' + ); } ); } @@ -245,29 +260,33 @@ async function runSvnTagStep( version, abortMessage ) { */ async function updateThePluginStableVersion( version, abortMessage ) { // Updating the content of the svn - await runStep( "Updating the plugin's stable version", abortMessage, async () => { - const readmePath = svnWorkingDirectoryPath + '/readme.txt'; - const readmeFileContent = fs.readFileSync( readmePath, 'utf8' ); - const newReadmeContent = readmeFileContent.replace( - STABLE_TAG_REGEX, - 'Stable tag: ' + version + '\n' - ); - fs.writeFileSync( readmePath, newReadmeContent ); + await runStep( + "Updating the plugin's stable version", + abortMessage, + async () => { + const readmePath = svnWorkingDirectoryPath + '/readme.txt'; + const readmeFileContent = fs.readFileSync( readmePath, 'utf8' ); + const newReadmeContent = readmeFileContent.replace( + STABLE_TAG_REGEX, + 'Stable tag: ' + version + '\n' + ); + fs.writeFileSync( readmePath, newReadmeContent ); - // Commit the content changes - await askForConfirmationToContinue( - 'The stable version is updated in the readme.txt file. Commit the changes?', - true, - abortMessage - ); + // Commit the content changes + await askForConfirmationToContinue( + 'The stable version is updated in the readme.txt file. Commit the changes?', + true, + abortMessage + ); - runShellScript( - 'svn commit -m "Releasing Gutenberg version ' + version + '"', - svnWorkingDirectoryPath - ); + runShellScript( + 'svn commit -m "Releasing Gutenberg version ' + version + '"', + svnWorkingDirectoryPath + ); - console.log( '>> Stable version updated successfully' ); - } ); + console.log( '>> Stable version updated successfully' ); + } + ); } /** @@ -278,15 +297,17 @@ async function updateThePluginStableVersion( version, abortMessage ) { async function runCleanLocalCloneStep( abortMessage ) { await runStep( 'Cleaning the temporary folder', abortMessage, async () => { await Promise.all( - [ gitWorkingDirectoryPath, svnWorkingDirectoryPath ].map( async ( directoryPath ) => { - if ( fs.existsSync( directoryPath ) ) { - await rimraf( directoryPath, ( err ) => { - if ( err ) { - throw err; - } - } ); + [ gitWorkingDirectoryPath, svnWorkingDirectoryPath ].map( + async ( directoryPath ) => { + if ( fs.existsSync( directoryPath ) ) { + await rimraf( directoryPath, ( err ) => { + if ( err ) { + throw err; + } + } ); + } } - } ) + ) ); } ); } @@ -314,9 +335,21 @@ async function runReleaseBranchCreationStep( abortMessage ) { releaseBranch = 'release/' + ( parsedVersion.major + 1 ) + '.0'; versionLabel = parsedVersion.major + 1 + '.0.0 RC1'; } else { - version = parsedVersion.major + '.' + ( parsedVersion.minor + 1 ) + '.0-rc.1'; - releaseBranch = 'release/' + parsedVersion.major + '.' + ( parsedVersion.minor + 1 ); - versionLabel = parsedVersion.major + '.' + ( parsedVersion.minor + 1 ) + '.0 RC1'; + version = + parsedVersion.major + + '.' + + ( parsedVersion.minor + 1 ) + + '.0-rc.1'; + releaseBranch = + 'release/' + + parsedVersion.major + + '.' + + ( parsedVersion.minor + 1 ); + versionLabel = + parsedVersion.major + + '.' + + ( parsedVersion.minor + 1 ) + + '.0 RC1'; } await askForConfirmationToContinue( 'The Plugin version to be used is ' + @@ -329,7 +362,9 @@ async function runReleaseBranchCreationStep( abortMessage ) { // Creating the release branch await simpleGit.checkoutLocalBranch( releaseBranch ); console.log( - '>> The local release branch ' + success( releaseBranch ) + ' has been successfully created.' + '>> The local release branch ' + + success( releaseBranch ) + + ' has been successfully created.' ); } ); @@ -352,7 +387,9 @@ const findReleaseBranchName = ( packageJsonPath ) => { const masterPackageJson = readJSONFile( packageJsonPath ); const masterParsedVersion = semver.parse( masterPackageJson.version ); - return 'release/' + masterParsedVersion.major + '.' + masterParsedVersion.minor; + return ( + 'release/' + masterParsedVersion.major + '.' + masterParsedVersion.minor + ); }; /** @@ -364,44 +401,55 @@ const findReleaseBranchName = ( packageJsonPath ) => { */ async function runReleaseBranchCheckoutStep( abortMessage ) { let releaseBranch, version; - await runStep( 'Getting into the release branch', abortMessage, async () => { - const simpleGit = SimpleGit( gitWorkingDirectoryPath ); - const packageJsonPath = gitWorkingDirectoryPath + '/package.json'; - releaseBranch = findReleaseBranchName( packageJsonPath ); + await runStep( + 'Getting into the release branch', + abortMessage, + async () => { + const simpleGit = SimpleGit( gitWorkingDirectoryPath ); + const packageJsonPath = gitWorkingDirectoryPath + '/package.json'; + releaseBranch = findReleaseBranchName( packageJsonPath ); + + // Creating the release branch + await simpleGit.checkout( releaseBranch ); + console.log( + '>> The local release branch ' + + success( releaseBranch ) + + ' has been successfully checked out.' + ); - // Creating the release branch - await simpleGit.checkout( releaseBranch ); - console.log( - '>> The local release branch ' + - success( releaseBranch ) + - ' has been successfully checked out.' - ); + const releaseBranchPackageJson = readJSONFile( packageJsonPath ); + const releaseBranchParsedVersion = semver.parse( + releaseBranchPackageJson.version + ); - const releaseBranchPackageJson = readJSONFile( packageJsonPath ); - const releaseBranchParsedVersion = semver.parse( releaseBranchPackageJson.version ); + if ( + releaseBranchParsedVersion.prerelease && + releaseBranchParsedVersion.prerelease.length + ) { + version = + releaseBranchParsedVersion.major + + '.' + + releaseBranchParsedVersion.minor + + '.' + + releaseBranchParsedVersion.patch; + } else { + version = + releaseBranchParsedVersion.major + + '.' + + releaseBranchParsedVersion.minor + + '.' + + ( releaseBranchParsedVersion.patch + 1 ); + } - if ( releaseBranchParsedVersion.prerelease && releaseBranchParsedVersion.prerelease.length ) { - version = - releaseBranchParsedVersion.major + - '.' + - releaseBranchParsedVersion.minor + - '.' + - releaseBranchParsedVersion.patch; - } else { - version = - releaseBranchParsedVersion.major + - '.' + - releaseBranchParsedVersion.minor + - '.' + - ( releaseBranchParsedVersion.patch + 1 ); + await askForConfirmationToContinue( + 'The Version to release is ' + + success( version ) + + '. Proceed?', + true, + abortMessage + ); } - - await askForConfirmationToContinue( - 'The Version to release is ' + success( version ) + '. Proceed?', - true, - abortMessage - ); - } ); + ); return { version, @@ -420,7 +468,11 @@ async function runReleaseBranchCheckoutStep( abortMessage ) { * * @return {string} hash of the version bump commit. */ -async function runBumpPluginVersionAndCommitStep( version, changelog, abortMessage ) { +async function runBumpPluginVersionAndCommitStep( + version, + changelog, + abortMessage +) { let commitHash; await runStep( 'Updating the plugin version', abortMessage, async () => { const simpleGit = SimpleGit( gitWorkingDirectoryPath ); @@ -433,16 +485,25 @@ async function runBumpPluginVersionAndCommitStep( version, changelog, abortMessa ...packageJson, version, }; - fs.writeFileSync( packageJsonPath, JSON.stringify( newPackageJson, null, '\t' ) + '\n' ); + fs.writeFileSync( + packageJsonPath, + JSON.stringify( newPackageJson, null, '\t' ) + '\n' + ); const newPackageLock = { ...packageLock, version, }; - fs.writeFileSync( packageLockPath, JSON.stringify( newPackageLock, null, '\t' ) + '\n' ); + fs.writeFileSync( + packageLockPath, + JSON.stringify( newPackageLock, null, '\t' ) + '\n' + ); const content = fs.readFileSync( pluginFilePath, 'utf8' ); fs.writeFileSync( pluginFilePath, - content.replace( ' * Version: ' + packageJson.version, ' * Version: ' + version ) + content.replace( + ' * Version: ' + packageJson.version, + ' * Version: ' + version + ) ); console.log( '>> The plugin version has been updated successfully.' ); @@ -450,7 +511,10 @@ async function runBumpPluginVersionAndCommitStep( version, changelog, abortMessa const readmePath = gitWorkingDirectoryPath + '/readme.txt'; const readmeFileContent = fs.readFileSync( readmePath, 'utf8' ); const newReadmeContent = - readmeFileContent.substr( 0, readmeFileContent.indexOf( '== Changelog ==' ) ) + + readmeFileContent.substr( + 0, + readmeFileContent.indexOf( '== Changelog ==' ) + ) + '== Changelog ==\n\n' + `To read the changelog for Gutenberg ${ version }, please navigate to the release page.` + '\n'; @@ -462,9 +526,13 @@ async function runBumpPluginVersionAndCommitStep( version, changelog, abortMessa const changelogFileContent = fs.readFileSync( changelogPath, 'utf8' ); const versionHeader = '= ' + version + ' =\n\n'; const regexToSearch = /=\s([0-9]+\.[0-9]+\.[0-9]+)(-rc\.[0-9]+)?\s=\n\n/g; - let lastDifferentVersionMatch = regexToSearch.exec( changelogFileContent ); + let lastDifferentVersionMatch = regexToSearch.exec( + changelogFileContent + ); if ( lastDifferentVersionMatch[ 1 ] === stableVersion ) { - lastDifferentVersionMatch = regexToSearch.exec( changelogFileContent ); + lastDifferentVersionMatch = regexToSearch.exec( + changelogFileContent + ); } const newChangelogContent = '== Changelog ==\n\n' + @@ -487,9 +555,13 @@ async function runBumpPluginVersionAndCommitStep( version, changelog, abortMessa readmePath, changelogPath, ] ); - const commitData = await simpleGit.commit( 'Bump plugin version to ' + version ); + const commitData = await simpleGit.commit( + 'Bump plugin version to ' + version + ); commitHash = commitData.commit; - console.log( '>> The plugin version bump has been committed successfully.' ); + console.log( + '>> The plugin version bump has been committed successfully.' + ); } ); return commitHash; @@ -508,10 +580,14 @@ async function runPluginZIPCreationStep( abortMessage ) { true, abortMessage ); - runShellScript( '/bin/bash bin/build-plugin-zip.sh', gitWorkingDirectoryPath ); + runShellScript( + '/bin/bash bin/build-plugin-zip.sh', + gitWorkingDirectoryPath + ); console.log( - '>> The plugin ZIP has been built successfully. Path: ' + success( gutenbergZipPath ) + '>> The plugin ZIP has been built successfully. Path: ' + + success( gutenbergZipPath ) ); } ); } @@ -531,7 +607,11 @@ async function runCreateGitTagStep( version, abortMessage ) { abortMessage ); await simpleGit.addTag( 'v' + version ); - console.log( '>> The ' + success( 'v' + version ) + ' tag has been created successfully.' ); + console.log( + '>> The ' + + success( 'v' + version ) + + ' tag has been created successfully.' + ); } ); } @@ -542,16 +622,20 @@ async function runCreateGitTagStep( version, abortMessage ) { * @param {string} abortMessage Abort message. */ async function runPushGitChangesStep( releaseBranch, abortMessage ) { - await runStep( 'Pushing the release branch and the tag', abortMessage, async () => { - const simpleGit = SimpleGit( gitWorkingDirectoryPath ); - await askForConfirmationToContinue( - 'The release branch and the tag are going to be pushed to the remote repository. Continue?', - true, - abortMessage - ); - await simpleGit.push( 'origin', releaseBranch ); - await simpleGit.pushTags( 'origin' ); - } ); + await runStep( + 'Pushing the release branch and the tag', + abortMessage, + async () => { + const simpleGit = SimpleGit( gitWorkingDirectoryPath ); + await askForConfirmationToContinue( + 'The release branch and the tag are going to be pushed to the remote repository. Continue?', + true, + abortMessage + ); + await simpleGit.push( 'origin', releaseBranch ); + await simpleGit.pushTags( 'origin' ); + } + ); } /** @@ -587,7 +671,9 @@ async function runGithubReleaseStep( name: 'token', message: 'Please provide a GitHub personal authentication token. Navigate to ' + - success( 'https://github.com/settings/tokens/new?scopes=repo,admin:org,write:packages' ) + + success( + 'https://github.com/settings/tokens/new?scopes=repo,admin:org,write:packages' + ) + ' to create one.', }, ] ); @@ -608,7 +694,8 @@ async function runGithubReleaseStep( console.log( '>> The GitHub release has been created.' ); } ); - abortMessage = abortMessage + ' Make sure to remove the the GitHub release as well.'; + abortMessage = + abortMessage + ' Make sure to remove the the GitHub release as well.'; // Uploading the Gutenberg Zip to the release await runStep( 'Uploading the plugin ZIP', abortMessage, async () => { @@ -626,7 +713,10 @@ async function runGithubReleaseStep( console.log( '>> The plugin ZIP has been successfully uploaded.' ); } ); - console.log( '>> The GitHub release is available here: ' + success( release.html_url ) ); + console.log( + '>> The GitHub release is available here: ' + + success( release.html_url ) + ); return release; } @@ -637,21 +727,28 @@ async function runGithubReleaseStep( * @param {string} commitHash Commit to cherry-pick. * @param {string} abortMessage Abort message. */ -async function runCherrypickBumpCommitIntoMasterStep( commitHash, abortMessage ) { - await runStep( 'Cherry-picking the bump commit into master', abortMessage, async () => { - const simpleGit = SimpleGit( gitWorkingDirectoryPath ); - await askForConfirmationToContinue( - 'The plugin is now released. Proceed with the version bump in the master branch?', - true, - abortMessage - ); - await simpleGit.fetch(); - await simpleGit.reset( 'hard' ); - await simpleGit.checkout( 'master' ); - await simpleGit.pull( 'origin', 'master' ); - await simpleGit.raw( [ 'cherry-pick', commitHash ] ); - await simpleGit.push( 'origin', 'master' ); - } ); +async function runCherrypickBumpCommitIntoMasterStep( + commitHash, + abortMessage +) { + await runStep( + 'Cherry-picking the bump commit into master', + abortMessage, + async () => { + const simpleGit = SimpleGit( gitWorkingDirectoryPath ); + await askForConfirmationToContinue( + 'The plugin is now released. Proceed with the version bump in the master branch?', + true, + abortMessage + ); + await simpleGit.fetch(); + await simpleGit.reset( 'hard' ); + await simpleGit.checkout( 'master' ); + await simpleGit.pull( 'origin', 'master' ); + await simpleGit.raw( [ 'cherry-pick', commitHash ] ); + await simpleGit.push( 'origin', 'master' ); + } + ); } /** @@ -683,7 +780,11 @@ async function releasePlugin( isRC = true ) { : await runReleaseBranchCheckoutStep( abortMessage ); // Bumping the version and commit. - const commitHash = await runBumpPluginVersionAndCommitStep( version, changelog, abortMessage ); + const commitHash = await runBumpPluginVersionAndCommitStep( + version, + changelog, + abortMessage + ); // Plugin ZIP creation await runPluginZIPCreationStep(); @@ -711,7 +812,8 @@ async function releasePlugin( isRC = true ) { success( commitHash ) + ' commit to the master branch.'; if ( ! isRC ) { - abortMessage += ' Make sure to perform the SVN release manually as well.'; + abortMessage += + ' Make sure to perform the SVN release manually as well.'; } // Cherry-picking the bump commit into master @@ -750,7 +852,9 @@ async function releasePlugin( isRC = true ) { program .command( 'release-plugin-rc' ) .alias( 'rc' ) - .description( 'Release an RC version of the plugin (supports only rc.1 for now)' ) + .description( + 'Release an RC version of the plugin (supports only rc.1 for now)' + ) .action( async () => { console.log( chalk.bold( '๐ Time to release Gutenberg ๐บ\n\n' ), @@ -765,7 +869,9 @@ program '\n>> ๐ The Gutenberg version ' + success( release.name ) + ' has been successfully released.\n', - 'You can access the GitHub release here: ' + success( release.html_url ) + '\n', + 'You can access the GitHub release here: ' + + success( release.html_url ) + + '\n', 'Thanks for performing the release!' ); } ); @@ -785,8 +891,12 @@ program const release = await releasePlugin( false ); console.log( - '\n>> ๐ The Gutenberg ' + success( release.name ) + ' has been successfully released.\n', - 'You can access the GitHub release here: ' + success( release.html_url ) + '\n', + '\n>> ๐ The Gutenberg ' + + success( release.name ) + + ' has been successfully released.\n', + 'You can access the GitHub release here: ' + + success( release.html_url ) + + '\n', "In a few minutes, you'll be able to update the plugin from the WordPress repository.\n", "Thanks for performing the release! and don't forget to publish the release post." ); @@ -800,36 +910,47 @@ program */ async function runWordPressReleaseBranchSyncStep( abortMessage ) { const wordpressReleaseBranch = 'wp/trunk'; - await runStep( 'Getting into the WordPress release branch', abortMessage, async () => { - const simpleGit = SimpleGit( gitWorkingDirectoryPath ); - const packageJsonPath = gitWorkingDirectoryPath + '/package.json'; - const pluginReleaseBranch = findReleaseBranchName( packageJsonPath ); + await runStep( + 'Getting into the WordPress release branch', + abortMessage, + async () => { + const simpleGit = SimpleGit( gitWorkingDirectoryPath ); + const packageJsonPath = gitWorkingDirectoryPath + '/package.json'; + const pluginReleaseBranch = findReleaseBranchName( + packageJsonPath + ); - // Creating the release branch - await simpleGit.checkout( wordpressReleaseBranch ); - console.log( - '>> The local release branch ' + - success( wordpressReleaseBranch ) + - ' has been successfully checked out.' - ); + // Creating the release branch + await simpleGit.checkout( wordpressReleaseBranch ); + console.log( + '>> The local release branch ' + + success( wordpressReleaseBranch ) + + ' has been successfully checked out.' + ); - await askForConfirmationToContinue( - `The branch is ready for sync with the latest plugin release changes applied to "${ pluginReleaseBranch }". Proceed?`, - true, - abortMessage - ); + await askForConfirmationToContinue( + `The branch is ready for sync with the latest plugin release changes applied to "${ pluginReleaseBranch }". Proceed?`, + true, + abortMessage + ); - await simpleGit.raw( [ 'rm', '-r', '.' ] ); - await simpleGit.raw( [ 'checkout', `origin/${ pluginReleaseBranch }`, '--', '.' ] ); - await simpleGit.commit( - `Merge changes published in the Gutenberg plugin "${ pluginReleaseBranch }" branch` - ); - console.log( - '>> The local WordPress release branch ' + - success( wordpressReleaseBranch ) + - ' has been successfully synced.' - ); - } ); + await simpleGit.raw( [ 'rm', '-r', '.' ] ); + await simpleGit.raw( [ + 'checkout', + `origin/${ pluginReleaseBranch }`, + '--', + '.', + ] ); + await simpleGit.commit( + `Merge changes published in the Gutenberg plugin "${ pluginReleaseBranch }" branch` + ); + console.log( + '>> The local WordPress release branch ' + + success( wordpressReleaseBranch ) + + ' has been successfully synced.' + ); + } + ); return { releaseBranch: wordpressReleaseBranch, @@ -881,7 +1002,10 @@ async function updatePackageChangelogs( minimumVersionBump, abortMessage ) { } // A minor version bump required. Proceed to the next line. - if ( line.startsWith( '### New Feature' ) || line.startsWith( '### Deprecation' ) ) { + if ( + line.startsWith( '### New Feature' ) || + line.startsWith( '### Deprecation' ) + ) { versionBump = 'minor'; continue; } @@ -891,9 +1015,16 @@ async function updatePackageChangelogs( minimumVersionBump, abortMessage ) { versionBump = minimumVersionBump; } } - const packageName = `@wordpress/${ changelogFile.split( '/' ).reverse()[ 1 ] }`; - const { version } = readJSONFile( changelogFile.replace( 'CHANGELOG.md', 'package.json' ) ); - const nextVersion = versionBump !== null ? semver.inc( version, versionBump ) : null; + const packageName = `@wordpress/${ + changelogFile.split( '/' ).reverse()[ 1 ] + }`; + const { version } = readJSONFile( + changelogFile.replace( 'CHANGELOG.md', 'package.json' ) + ); + const nextVersion = + versionBump !== null + ? semver.inc( version, versionBump ) + : null; return { changelogFile, @@ -904,25 +1035,39 @@ async function updatePackageChangelogs( minimumVersionBump, abortMessage ) { } ) ); - const changelogsToUpdate = processedPackages.filter( ( { nextVersion } ) => nextVersion ); + const changelogsToUpdate = processedPackages.filter( + ( { nextVersion } ) => nextVersion + ); if ( changelogsToUpdate.length === 0 ) { console.log( '>> No changes in CHANGELOG files detected.' ); return; } - console.log( '>> Recommended version bumps based on the changes detected in CHANGELOG files:' ); + console.log( + '>> Recommended version bumps based on the changes detected in CHANGELOG files:' + ); const publishDate = new Date().toISOString().split( 'T' )[ 0 ]; await Promise.all( - changelogsToUpdate.map( async ( { changelogFile, packageName, nextVersion, version } ) => { - const content = await fs.promises.readFile( changelogFile, 'utf8' ); - await fs.promises.writeFile( - changelogFile, - content.replace( '## Master', `## Master\n\n## ${ nextVersion } (${ publishDate })` ) - ); - console.log( ` - ${ packageName }: ${ version } -> ${ nextVersion }` ); - } ) + changelogsToUpdate.map( + async ( { changelogFile, packageName, nextVersion, version } ) => { + const content = await fs.promises.readFile( + changelogFile, + 'utf8' + ); + await fs.promises.writeFile( + changelogFile, + content.replace( + '## Master', + `## Master\n\n## ${ nextVersion } (${ publishDate })` + ) + ); + console.log( + ` - ${ packageName }: ${ version } -> ${ nextVersion }` + ); + } + ) ); await askForConfirmationToContinue( @@ -933,7 +1078,9 @@ async function updatePackageChangelogs( minimumVersionBump, abortMessage ) { const simpleGit = SimpleGit( gitWorkingDirectoryPath ); await simpleGit.add( './*' ); await simpleGit.commit( 'Update changelog files' ); - console.log( '>> Changelog files changes have been committed successfully.' ); + console.log( + '>> Changelog files changes have been committed successfully.' + ); } /** @@ -952,7 +1099,9 @@ async function prepublishPackages( minimumVersionBump ) { await runGitRepositoryCloneStep( abortMessage ); // Checking out the WordPress release branch and doing sync with the last plugin release. - const { releaseBranch } = await runWordPressReleaseBranchSyncStep( abortMessage ); + const { releaseBranch } = await runWordPressReleaseBranchSyncStep( + abortMessage + ); await updatePackageChangelogs( minimumVersionBump, abortMessage ); @@ -967,7 +1116,9 @@ async function prepublishPackages( minimumVersionBump ) { program .command( 'prepublish-packages-stable' ) .alias( 'npm-stable' ) - .description( 'Prepublish to npm steps for the next stable version of WordPress packages' ) + .description( + 'Prepublish to npm steps for the next stable version of WordPress packages' + ) .action( async () => { console.log( chalk.bold( '๐ Time to publish WordPress packages to npm ๐บ\n\n' ), diff --git a/bin/generate-public-grammar.js b/bin/generate-public-grammar.js index 28f8b43859a988..0c2bc74fc42241 100755 --- a/bin/generate-public-grammar.js +++ b/bin/generate-public-grammar.js @@ -18,7 +18,11 @@ function escape( text ) { } function isGroup( expression ) { - return [ 'choice', 'action', 'labeled', 'sequence' ].indexOf( expression.type ) >= 0; + return ( + [ 'choice', 'action', 'labeled', 'sequence' ].indexOf( + expression.type + ) >= 0 + ); } function flattenUnary( expression ) { @@ -41,7 +45,11 @@ function flatten( expression ) { '[' + ( expression.inverted ? '^' : '' ) + expression.parts - .map( ( part ) => escape( Array.isArray( part ) ? part.join( '-' ) : part ) ) + .map( ( part ) => + escape( + Array.isArray( part ) ? part.join( '-' ) : part + ) + ) .join( '' ) + ']' + ( expression.ignoreCase ? 'i' : '' ) @@ -80,7 +88,10 @@ function flatten( expression ) { return `
${ expression.name } = ` + diff --git a/bin/packages/build-worker.js b/bin/packages/build-worker.js index 622b712a97f3f0..e7f2b6f058fbda 100644 --- a/bin/packages/build-worker.js +++ b/bin/packages/build-worker.js @@ -84,8 +84,14 @@ function getBuildPath( file, buildFolder ) { */ const BUILD_TASK_BY_EXTENSION = { async '.scss'( file ) { - const outputFile = getBuildPath( file.replace( '.scss', '.css' ), 'build-style' ); - const outputFileRTL = getBuildPath( file.replace( '.scss', '-rtl.css' ), 'build-style' ); + const outputFile = getBuildPath( + file.replace( '.scss', '.css' ), + 'build-style' + ); + const outputFileRTL = getBuildPath( + file.replace( '.scss', '-rtl.css' ), + 'build-style' + ); const [ , contents ] = await Promise.all( [ makeDir( path.dirname( outputFile ) ), @@ -96,20 +102,33 @@ const BUILD_TASK_BY_EXTENSION = { file, includePaths: [ path.join( PACKAGES_DIR, 'base-styles' ) ], data: - [ 'colors', 'breakpoints', 'variables', 'mixins', 'animations', 'z-index' ] + [ + 'colors', + 'breakpoints', + 'variables', + 'mixins', + 'animations', + 'z-index', + ] .map( ( imported ) => `@import "${ imported }";` ) .join( ' ' ) + contents, } ); - const result = await postcss( require( './post-css-config' ) ).process( builtSass.css, { - from: 'src/app.css', - to: 'dest/app.css', - } ); - - const resultRTL = await postcss( [ require( 'rtlcss' )() ] ).process( result.css, { - from: 'src/app.css', - to: 'dest/app.css', - } ); + const result = await postcss( require( './post-css-config' ) ).process( + builtSass.css, + { + from: 'src/app.css', + to: 'dest/app.css', + } + ); + + const resultRTL = await postcss( [ require( 'rtlcss' )() ] ).process( + result.css, + { + from: 'src/app.css', + to: 'dest/app.css', + } + ); await Promise.all( [ writeFile( outputFile, result.css ), @@ -118,7 +137,9 @@ const BUILD_TASK_BY_EXTENSION = { }, async '.js'( file ) { - for ( const [ environment, buildDir ] of Object.entries( JS_ENVIRONMENTS ) ) { + for ( const [ environment, buildDir ] of Object.entries( + JS_ENVIRONMENTS + ) ) { const destPath = getBuildPath( file, buildDir ); const babelOptions = getBabelConfig( environment, @@ -131,10 +152,16 @@ const BUILD_TASK_BY_EXTENSION = { ] ); await Promise.all( [ - writeFile( destPath + '.map', JSON.stringify( transformed.map ) ), + writeFile( + destPath + '.map', + JSON.stringify( transformed.map ) + ), writeFile( destPath, - transformed.code + '\n//# sourceMappingURL=' + path.basename( destPath ) + '.map' + transformed.code + + '\n//# sourceMappingURL=' + + path.basename( destPath ) + + '.map' ), ] ); } diff --git a/bin/packages/build.js b/bin/packages/build.js index 8eceb6c6dbbe59..8d1a0c9cc17875 100755 --- a/bin/packages/build.js +++ b/bin/packages/build.js @@ -57,7 +57,9 @@ function createStyleEntryTransform() { } packages.add( packageName ); - const entries = await glob( path.resolve( PACKAGES_DIR, packageName, 'src/*.scss' ) ); + const entries = await glob( + path.resolve( PACKAGES_DIR, packageName, 'src/*.scss' ) + ); entries.forEach( ( entry ) => this.push( entry ) ); callback(); }, @@ -78,7 +80,9 @@ function createBlockJsonEntryTransform() { return new Transform( { objectMode: true, async transform( file, encoding, callback ) { - const matches = /block-library[\/\\]src[\/\\](.*)[\/\\]block.json$/.exec( file ); + const matches = /block-library[\/\\]src[\/\\](.*)[\/\\]block.json$/.exec( + file + ); const blockName = matches ? matches[ 1 ] : undefined; // Only block.json files in the block-library folder are subject to this transform. @@ -109,7 +113,9 @@ if ( files.length ) { stream = new Readable( { encoding: 'utf8' } ); files.forEach( ( file ) => stream.push( file ) ); stream.push( null ); - stream = stream.pipe( createStyleEntryTransform() ).pipe( createBlockJsonEntryTransform() ); + stream = stream + .pipe( createStyleEntryTransform() ) + .pipe( createBlockJsonEntryTransform() ); } else { const bar = new ProgressBar( 'Build Progress: [:bar] :percent', { width: 30, @@ -119,10 +125,17 @@ if ( files.length ) { bar.tick( 0 ); - stream = glob.stream( [ `${ PACKAGES_DIR }/*/src/**/*.js`, `${ PACKAGES_DIR }/*/src/*.scss` ], { - ignore: [ `**/benchmark/**`, `**/{__mocks__,__tests__,test}/**`, `**/{storybook,stories}/**` ], - onlyFiles: true, - } ); + stream = glob.stream( + [ `${ PACKAGES_DIR }/*/src/**/*.js`, `${ PACKAGES_DIR }/*/src/*.scss` ], + { + ignore: [ + `**/benchmark/**`, + `**/{__mocks__,__tests__,test}/**`, + `**/{storybook,stories}/**`, + ], + onlyFiles: true, + } + ); // Pause to avoid data flow which would begin on the `data` event binding, // but should wait until worker processing below. diff --git a/bin/packages/watch.js b/bin/packages/watch.js index 8518e66f3a2a83..8d5e650f6bac3c 100644 --- a/bin/packages/watch.js +++ b/bin/packages/watch.js @@ -31,7 +31,8 @@ const isSourceFile = ( filename ) => { ! [ /\/(benchmark|__mocks__|__tests__|test|storybook|stories)\/.+.js$/, /.\.(spec|test)\.js$/, - ].some( ( regex ) => regex.test( filename ) ) && /.\.(js|json|scss)$/.test( filename ) + ].some( ( regex ) => regex.test( filename ) ) && + /.\.(js|json|scss)$/.test( filename ) ); }; @@ -41,29 +42,44 @@ getPackages().forEach( ( p ) => { const srcDir = path.resolve( p, 'src' ); try { fs.accessSync( srcDir, fs.F_OK ); - watch( path.resolve( p, 'src' ), { recursive: true }, ( event, filename ) => { - if ( ! isSourceFile( filename ) ) { - return; - } + watch( + path.resolve( p, 'src' ), + { recursive: true }, + ( event, filename ) => { + if ( ! isSourceFile( filename ) ) { + return; + } - const filePath = path.resolve( srcDir, filename ); - if ( event === 'update' && exists( filePath ) ) { - // eslint-disable-next-line no-console - console.log( chalk.green( '->' ), `${ event }: ${ filename }` ); - rebuild( filePath ); - } else { - const buildFile = path.resolve( srcDir, '..', 'build', filename ); - try { - fs.unlinkSync( buildFile ); - process.stdout.write( - chalk.red( ' \u2022 ' ) + - path.relative( path.resolve( srcDir, '..', '..' ), buildFile ) + - ' (deleted)' + - '\n' + const filePath = path.resolve( srcDir, filename ); + if ( event === 'update' && exists( filePath ) ) { + // eslint-disable-next-line no-console + console.log( + chalk.green( '->' ), + `${ event }: ${ filename }` + ); + rebuild( filePath ); + } else { + const buildFile = path.resolve( + srcDir, + '..', + 'build', + filename ); - } catch ( e ) {} + try { + fs.unlinkSync( buildFile ); + process.stdout.write( + chalk.red( ' \u2022 ' ) + + path.relative( + path.resolve( srcDir, '..', '..' ), + buildFile + ) + + ' (deleted)' + + '\n' + ); + } catch ( e ) {} + } } - } ); + ); } catch ( e ) { // doesn't exist } diff --git a/docs/tool/are-data-files-unstaged.js b/docs/tool/are-data-files-unstaged.js index 14e91df6038c03..38f659ec9bb0c7 100644 --- a/docs/tool/are-data-files-unstaged.js +++ b/docs/tool/are-data-files-unstaged.js @@ -17,9 +17,14 @@ const getUnstagedFiles = () => .filter( ( element ) => '' !== element ); const readmeFiles = getPackages().map( ( [ packageName ] ) => - `docs/designers-developers/developers/data/data-${ packageName.replace( '/', '-' ) }.md` + `docs/designers-developers/developers/data/data-${ packageName.replace( + '/', + '-' + ) }.md` +); +const unstagedReadmes = getUnstagedFiles().filter( ( element ) => + readmeFiles.includes( element ) ); -const unstagedReadmes = getUnstagedFiles().filter( ( element ) => readmeFiles.includes( element ) ); if ( unstagedReadmes.length > 0 ) { process.exitCode = 1; diff --git a/docs/tool/manifest.js b/docs/tool/manifest.js index adf9ff6488ff51..90c050388a0c50 100644 --- a/docs/tool/manifest.js +++ b/docs/tool/manifest.js @@ -85,9 +85,13 @@ function generateRootManifestFromTOCItems( items, parent = null ) { parent, } ); if ( Array.isArray( children ) && children.length ) { - pageItems = pageItems.concat( generateRootManifestFromTOCItems( children, slug ) ); + pageItems = pageItems.concat( + generateRootManifestFromTOCItems( children, slug ) + ); } else if ( children === '{{components}}' ) { - pageItems = pageItems.concat( getComponentManifest( componentPaths ) ); + pageItems = pageItems.concat( + getComponentManifest( componentPaths ) + ); } else if ( children === '{{packages}}' ) { pageItems = pageItems.concat( getPackageManifest( packagePaths ) ); } diff --git a/docs/tool/update-data.js b/docs/tool/update-data.js index 63b66bbfe8fc76..89f0fc614f1c50 100644 --- a/docs/tool/update-data.js +++ b/docs/tool/update-data.js @@ -17,7 +17,14 @@ getPackages().forEach( ( entry ) => { // until docgen provides a way to update many tokens at once, we need to make sure // the output file is updated before starting the second pass for the next token. const { status, stderr } = spawnSync( - join( __dirname, '..', '..', 'node_modules', '.bin', 'docgen' ).replace( / /g, '\\ ' ), + join( + __dirname, + '..', + '..', + 'node_modules', + '.bin', + 'docgen' + ).replace( / /g, '\\ ' ), [ target, `--output docs/designers-developers/developers/data/data-${ packageName.replace( diff --git a/packages/a11y/src/index.js b/packages/a11y/src/index.js index cb79e767bb9c36..97d10c65920202 100644 --- a/packages/a11y/src/index.js +++ b/packages/a11y/src/index.js @@ -15,7 +15,9 @@ import filterMessage from './filterMessage'; */ export const setup = function() { const containerPolite = document.getElementById( 'a11y-speak-polite' ); - const containerAssertive = document.getElementById( 'a11y-speak-assertive' ); + const containerAssertive = document.getElementById( + 'a11y-speak-assertive' + ); if ( containerPolite === null ) { addContainer( 'polite' ); @@ -56,7 +58,9 @@ export const speak = function( message, ariaLive ) { message = filterMessage( message ); const containerPolite = document.getElementById( 'a11y-speak-polite' ); - const containerAssertive = document.getElementById( 'a11y-speak-assertive' ); + const containerAssertive = document.getElementById( + 'a11y-speak-assertive' + ); if ( containerAssertive && 'assertive' === ariaLive ) { containerAssertive.textContent = message; diff --git a/packages/a11y/src/test/addContainer.test.js b/packages/a11y/src/test/addContainer.test.js index e6c722078f74f3..6ebf062237c9c0 100644 --- a/packages/a11y/src/test/addContainer.test.js +++ b/packages/a11y/src/test/addContainer.test.js @@ -13,7 +13,9 @@ describe( 'addContainer', () => { expect( container.id ).toBe( 'a11y-speak-polite' ); expect( container.getAttribute( 'style' ) ).not.toBeNull(); expect( container.getAttribute( 'aria-live' ) ).toBe( 'polite' ); - expect( container.getAttribute( 'aria-relevant' ) ).toBe( 'additions text' ); + expect( container.getAttribute( 'aria-relevant' ) ).toBe( + 'additions text' + ); expect( container.getAttribute( 'aria-atomic' ) ).toBe( 'true' ); } ); } ); @@ -27,7 +29,9 @@ describe( 'addContainer', () => { expect( container.id ).toBe( 'a11y-speak-assertive' ); expect( container.getAttribute( 'style' ) ).not.toBeNull(); expect( container.getAttribute( 'aria-live' ) ).toBe( 'assertive' ); - expect( container.getAttribute( 'aria-relevant' ) ).toBe( 'additions text' ); + expect( container.getAttribute( 'aria-relevant' ) ).toBe( + 'additions text' + ); expect( container.getAttribute( 'aria-atomic' ) ).toBe( 'true' ); } ); } ); @@ -41,7 +45,9 @@ describe( 'addContainer', () => { expect( container.id ).toBe( 'a11y-speak-polite' ); expect( container.getAttribute( 'style' ) ).not.toBeNull(); expect( container.getAttribute( 'aria-live' ) ).toBe( 'polite' ); - expect( container.getAttribute( 'aria-relevant' ) ).toBe( 'additions text' ); + expect( container.getAttribute( 'aria-relevant' ) ).toBe( + 'additions text' + ); expect( container.getAttribute( 'aria-atomic' ) ).toBe( 'true' ); } ); } ); diff --git a/packages/a11y/src/test/index.test.js b/packages/a11y/src/test/index.test.js index 08c9489bed2ae3..9888f9adb3a145 100644 --- a/packages/a11y/src/test/index.test.js +++ b/packages/a11y/src/test/index.test.js @@ -53,7 +53,9 @@ describe( 'speak', () => { it( 'should set the textcontent of the assertive aria-live region', () => { speak( 'assertive message', 'assertive' ); expect( containerPolite.textContent ).toBe( '' ); - expect( containerAssertive.textContent ).toBe( 'assertive message' ); + expect( containerAssertive.textContent ).toBe( + 'assertive message' + ); } ); } ); @@ -72,13 +74,17 @@ describe( 'speak', () => { afterEach( () => { setup(); - containerAssertive = document.getElementById( 'a11y-speak-assertive' ); + containerAssertive = document.getElementById( + 'a11y-speak-assertive' + ); } ); it( 'should set the textcontent of the polite aria-live region', () => { speak( 'message', 'assertive' ); expect( containerPolite.textContent ).toBe( 'message' ); - expect( document.getElementById( 'a11y-speak-assertive' ) ).toBe( null ); + expect( document.getElementById( 'a11y-speak-assertive' ) ).toBe( + null + ); } ); } ); @@ -91,20 +97,29 @@ describe( 'speak', () => { afterEach( () => { setup(); containerPolite = document.getElementById( 'a11y-speak-polite' ); - containerAssertive = document.getElementById( 'a11y-speak-assertive' ); + containerAssertive = document.getElementById( + 'a11y-speak-assertive' + ); } ); it( 'should set the textcontent of the polite aria-live region', () => { - expect( document.getElementById( 'a11y-speak-polite' ) ).toBe( null ); - expect( document.getElementById( 'a11y-speak-assertive' ) ).toBe( null ); + expect( document.getElementById( 'a11y-speak-polite' ) ).toBe( + null + ); + expect( document.getElementById( 'a11y-speak-assertive' ) ).toBe( + null + ); } ); } ); describe( 'setup when the elements already exist', () => { it( 'should not create the aria live regions again', () => { - const before = document.getElementsByClassName( 'a11y-speak-region' ).length; + const before = document.getElementsByClassName( + 'a11y-speak-region' + ).length; setup(); - const after = document.getElementsByClassName( 'a11y-speak-region' ).length; + const after = document.getElementsByClassName( 'a11y-speak-region' ) + .length; expect( before ).toBe( after ); } ); diff --git a/packages/annotations/src/block/index.js b/packages/annotations/src/block/index.js index 31c1a57e261ab1..c27c170b2d64a1 100644 --- a/packages/annotations/src/block/index.js +++ b/packages/annotations/src/block/index.js @@ -12,9 +12,9 @@ import { withSelect } from '@wordpress/data'; */ const addAnnotationClassName = ( OriginalComponent ) => { return withSelect( ( select, { clientId } ) => { - const annotations = select( 'core/annotations' ).__experimentalGetAnnotationsForBlock( - clientId - ); + const annotations = select( + 'core/annotations' + ).__experimentalGetAnnotationsForBlock( clientId ); return { className: annotations @@ -26,4 +26,8 @@ const addAnnotationClassName = ( OriginalComponent ) => { } )( OriginalComponent ); }; -addFilter( 'editor.BlockListBlock', 'core/annotations', addAnnotationClassName ); +addFilter( + 'editor.BlockListBlock', + 'core/annotations', + addAnnotationClassName +); diff --git a/packages/annotations/src/format/annotation.js b/packages/annotations/src/format/annotation.js index ba9a39633d84e4..9ce2a2bd6d456f 100644 --- a/packages/annotations/src/format/annotation.js +++ b/packages/annotations/src/format/annotation.js @@ -69,7 +69,9 @@ function retrieveAnnotationPositions( formats ) { formats.forEach( ( characterFormats, i ) => { characterFormats = characterFormats || []; - characterFormats = characterFormats.filter( ( format ) => format.type === FORMAT_NAME ); + characterFormats = characterFormats.filter( + ( format ) => format.type === FORMAT_NAME + ); characterFormats.forEach( ( format ) => { let { id } = format.attributes; id = id.replace( ANNOTATION_ATTRIBUTE_PREFIX, '' ); @@ -116,7 +118,11 @@ function updateAnnotationsWithPositions( const { start, end } = currentAnnotation; if ( start !== position.start || end !== position.end ) { - updateAnnotationRange( currentAnnotation.id, position.start, position.end ); + updateAnnotationRange( + currentAnnotation.id, + position.start, + position.end + ); } } ); } @@ -138,7 +144,9 @@ export const annotation = { { richTextIdentifier, blockClientId } ) { return { - annotations: select( STORE_KEY ).__experimentalGetAnnotationsForRichText( + annotations: select( + STORE_KEY + ).__experimentalGetAnnotationsForRichText( blockClientId, richTextIdentifier ), @@ -157,14 +165,20 @@ export const annotation = { }, __experimentalGetPropsForEditableTreeChangeHandler( dispatch ) { return { - removeAnnotation: dispatch( STORE_KEY ).__experimentalRemoveAnnotation, - updateAnnotationRange: dispatch( STORE_KEY ).__experimentalUpdateAnnotationRange, + removeAnnotation: dispatch( STORE_KEY ) + .__experimentalRemoveAnnotation, + updateAnnotationRange: dispatch( STORE_KEY ) + .__experimentalUpdateAnnotationRange, }; }, __experimentalCreateOnChangeEditableValue( props ) { return ( formats ) => { const positions = retrieveAnnotationPositions( formats ); - const { removeAnnotation, updateAnnotationRange, annotations } = props; + const { + removeAnnotation, + updateAnnotationRange, + annotations, + } = props; updateAnnotationsWithPositions( annotations, positions, { removeAnnotation, diff --git a/packages/annotations/src/store/actions.js b/packages/annotations/src/store/actions.js index 7ad35afa99b295..f5d5b8cf208e55 100644 --- a/packages/annotations/src/store/actions.js +++ b/packages/annotations/src/store/actions.js @@ -72,7 +72,11 @@ export function __experimentalRemoveAnnotation( annotationId ) { * * @return {Object} Action object. */ -export function __experimentalUpdateAnnotationRange( annotationId, start, end ) { +export function __experimentalUpdateAnnotationRange( + annotationId, + start, + end +) { return { type: 'ANNOTATION_UPDATE_RANGE', annotationId, diff --git a/packages/annotations/src/store/reducer.js b/packages/annotations/src/store/reducer.js index 2fcd95118e45b4..0756c3f3d8eac5 100644 --- a/packages/annotations/src/store/reducer.js +++ b/packages/annotations/src/store/reducer.js @@ -15,7 +15,9 @@ import { get, isNumber, mapValues } from 'lodash'; function filterWithReference( collection, predicate ) { const filteredCollection = collection.filter( predicate ); - return collection.length === filteredCollection.length ? collection : filteredCollection; + return collection.length === filteredCollection.length + ? collection + : filteredCollection; } /** @@ -26,7 +28,9 @@ function filterWithReference( collection, predicate ) { */ function isValidAnnotationRange( annotation ) { return ( - isNumber( annotation.start ) && isNumber( annotation.end ) && annotation.start <= annotation.end + isNumber( annotation.start ) && + isNumber( annotation.end ) && + annotation.start <= annotation.end ); } @@ -51,7 +55,10 @@ export function annotations( state = {}, action ) { range: action.range, }; - if ( newAnnotation.selector === 'range' && ! isValidAnnotationRange( newAnnotation.range ) ) { + if ( + newAnnotation.selector === 'range' && + ! isValidAnnotationRange( newAnnotation.range ) + ) { return state; } @@ -59,43 +66,54 @@ export function annotations( state = {}, action ) { return { ...state, - [ blockClientId ]: [ ...previousAnnotationsForBlock, newAnnotation ], + [ blockClientId ]: [ + ...previousAnnotationsForBlock, + newAnnotation, + ], }; case 'ANNOTATION_REMOVE': return mapValues( state, ( annotationsForBlock ) => { - return filterWithReference( annotationsForBlock, ( annotation ) => { - return annotation.id !== action.annotationId; - } ); + return filterWithReference( + annotationsForBlock, + ( annotation ) => { + return annotation.id !== action.annotationId; + } + ); } ); case 'ANNOTATION_UPDATE_RANGE': return mapValues( state, ( annotationsForBlock ) => { let hasChangedRange = false; - const newAnnotations = annotationsForBlock.map( ( annotation ) => { - if ( annotation.id === action.annotationId ) { - hasChangedRange = true; - return { - ...annotation, - range: { - start: action.start, - end: action.end, - }, - }; - } + const newAnnotations = annotationsForBlock.map( + ( annotation ) => { + if ( annotation.id === action.annotationId ) { + hasChangedRange = true; + return { + ...annotation, + range: { + start: action.start, + end: action.end, + }, + }; + } - return annotation; - } ); + return annotation; + } + ); return hasChangedRange ? newAnnotations : annotationsForBlock; } ); case 'ANNOTATION_REMOVE_SOURCE': return mapValues( state, ( annotationsForBlock ) => { - return filterWithReference( annotationsForBlock, ( annotation ) => { - return annotation.source !== action.source; - } ); + return filterWithReference( + annotationsForBlock, + ( annotation ) => { + return annotation.source !== action.source; + } + ); } ); } diff --git a/packages/annotations/src/store/selectors.js b/packages/annotations/src/store/selectors.js index 8a3a34715a6310..fa7b97e259ab77 100644 --- a/packages/annotations/src/store/selectors.js +++ b/packages/annotations/src/store/selectors.js @@ -32,7 +32,10 @@ export const __experimentalGetAnnotationsForBlock = createSelector( ( state, blockClientId ) => [ get( state, blockClientId, EMPTY_ARRAY ) ] ); -export const __experimentalGetAllAnnotationsForBlock = function( state, blockClientId ) { +export const __experimentalGetAllAnnotationsForBlock = function( + state, + blockClientId +) { return get( state, blockClientId, EMPTY_ARRAY ); }; @@ -53,7 +56,8 @@ export const __experimentalGetAnnotationsForRichText = createSelector( return get( state, blockClientId, [] ) .filter( ( annotation ) => { return ( - annotation.selector === 'range' && richTextIdentifier === annotation.richTextIdentifier + annotation.selector === 'range' && + richTextIdentifier === annotation.richTextIdentifier ); } ) .map( ( annotation ) => { diff --git a/packages/api-fetch/src/index.js b/packages/api-fetch/src/index.js index a25ec7992ff948..9e7edc985709ed 100644 --- a/packages/api-fetch/src/index.js +++ b/packages/api-fetch/src/index.js @@ -14,7 +14,10 @@ import namespaceEndpointMiddleware from './middlewares/namespace-endpoint'; import httpV1Middleware from './middlewares/http-v1'; import userLocaleMiddleware from './middlewares/user-locale'; import mediaUploadMiddleware from './middlewares/media-upload'; -import { parseResponseAndNormalizeError, parseAndThrowError } from './utils/response'; +import { + parseResponseAndNormalizeError, + parseAndThrowError, +} from './utils/response'; /** * Default set of header values which should be sent with every request unless @@ -88,8 +91,12 @@ const defaultFetchHandler = ( nextOptions ) => { ( value ) => Promise.resolve( value ) .then( checkStatus ) - .catch( ( response ) => parseAndThrowError( response, parse ) ) - .then( ( response ) => parseResponseAndNormalizeError( response, parse ) ), + .catch( ( response ) => + parseAndThrowError( response, parse ) + ) + .then( ( response ) => + parseResponseAndNormalizeError( response, parse ) + ), () => { throw { code: 'fetch_error', diff --git a/packages/api-fetch/src/middlewares/fetch-all-middleware.js b/packages/api-fetch/src/middlewares/fetch-all-middleware.js index f0ef36977d6c2c..2fa1b3b3629aab 100644 --- a/packages/api-fetch/src/middlewares/fetch-all-middleware.js +++ b/packages/api-fetch/src/middlewares/fetch-all-middleware.js @@ -32,8 +32,10 @@ const getNextPageUrl = ( response ) => { }; const requestContainsUnboundedQuery = ( options ) => { - const pathIsUnbounded = options.path && options.path.indexOf( 'per_page=-1' ) !== -1; - const urlIsUnbounded = options.url && options.url.indexOf( 'per_page=-1' ) !== -1; + const pathIsUnbounded = + options.path && options.path.indexOf( 'per_page=-1' ) !== -1; + const urlIsUnbounded = + options.url && options.url.indexOf( 'per_page=-1' ) !== -1; return pathIsUnbounded || urlIsUnbounded; }; diff --git a/packages/api-fetch/src/middlewares/media-upload.js b/packages/api-fetch/src/middlewares/media-upload.js index 4d617cd0683c5d..5668c18cfbd792 100644 --- a/packages/api-fetch/src/middlewares/media-upload.js +++ b/packages/api-fetch/src/middlewares/media-upload.js @@ -6,7 +6,10 @@ import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ -import { parseAndThrowError, parseResponseAndNormalizeError } from '../utils/response'; +import { + parseAndThrowError, + parseResponseAndNormalizeError, +} from '../utils/response'; /** * Middleware handling media upload failures and retries. @@ -49,8 +52,14 @@ function mediaUploadMiddleware( options, next ) { return next( { ...options, parse: false } ) .catch( ( response ) => { - const attachmentId = response.headers.get( 'x-wp-upload-attachment-id' ); - if ( response.status >= 500 && response.status < 600 && attachmentId ) { + const attachmentId = response.headers.get( + 'x-wp-upload-attachment-id' + ); + if ( + response.status >= 500 && + response.status < 600 && + attachmentId + ) { return postProcess( attachmentId ).catch( () => { if ( options.parse !== false ) { return Promise.reject( { @@ -66,7 +75,9 @@ function mediaUploadMiddleware( options, next ) { } return parseAndThrowError( response, options.parse ); } ) - .then( ( response ) => parseResponseAndNormalizeError( response, options.parse ) ); + .then( ( response ) => + parseResponseAndNormalizeError( response, options.parse ) + ); } export default mediaUploadMiddleware; diff --git a/packages/api-fetch/src/middlewares/namespace-endpoint.js b/packages/api-fetch/src/middlewares/namespace-endpoint.js index ef24a3dea93120..406c12926dd976 100644 --- a/packages/api-fetch/src/middlewares/namespace-endpoint.js +++ b/packages/api-fetch/src/middlewares/namespace-endpoint.js @@ -2,7 +2,10 @@ const namespaceAndEndpointMiddleware = ( options, next ) => { let path = options.path; let namespaceTrimmed, endpointTrimmed; - if ( typeof options.namespace === 'string' && typeof options.endpoint === 'string' ) { + if ( + typeof options.namespace === 'string' && + typeof options.endpoint === 'string' + ) { namespaceTrimmed = options.namespace.replace( /^\/|\/$/g, '' ); endpointTrimmed = options.endpoint.replace( /^\//, '' ); if ( endpointTrimmed ) { diff --git a/packages/api-fetch/src/middlewares/preloading.js b/packages/api-fetch/src/middlewares/preloading.js index 5a141c81413047..573a6c80b384ea 100644 --- a/packages/api-fetch/src/middlewares/preloading.js +++ b/packages/api-fetch/src/middlewares/preloading.js @@ -53,7 +53,11 @@ function createPreloadingMiddleware( preloadedData ) { if ( parse && 'GET' === method && cache[ path ] ) { return Promise.resolve( cache[ path ].body ); - } else if ( 'OPTIONS' === method && cache[ method ] && cache[ method ][ path ] ) { + } else if ( + 'OPTIONS' === method && + cache[ method ] && + cache[ method ][ path ] + ) { return Promise.resolve( cache[ method ][ path ] ); } } diff --git a/packages/api-fetch/src/middlewares/root-url.js b/packages/api-fetch/src/middlewares/root-url.js index 92b50523642fcc..8d2ad636285476 100644 --- a/packages/api-fetch/src/middlewares/root-url.js +++ b/packages/api-fetch/src/middlewares/root-url.js @@ -20,7 +20,10 @@ const createRootURLMiddleware = ( rootURL ) => ( options, next ) => { // API root may already include query parameter prefix if site is // configured to use plain permalinks. - if ( 'string' === typeof apiRoot && -1 !== apiRoot.indexOf( '?' ) ) { + if ( + 'string' === typeof apiRoot && + -1 !== apiRoot.indexOf( '?' ) + ) { path = path.replace( '?', '&' ); } diff --git a/packages/api-fetch/src/middlewares/test/preloading.js b/packages/api-fetch/src/middlewares/test/preloading.js index 42c00696e1849d..167e2e4eb32d65 100644 --- a/packages/api-fetch/src/middlewares/test/preloading.js +++ b/packages/api-fetch/src/middlewares/test/preloading.js @@ -36,7 +36,9 @@ describe( 'Preloading Middleware', () => { body, }, }; - const preloadingMiddleware = createPreloadingMiddleware( preloadedData ); + const preloadingMiddleware = createPreloadingMiddleware( + preloadedData + ); const requestOptions = { method: 'GET', path: 'wp/v2/posts', @@ -54,7 +56,9 @@ describe( 'Preloading Middleware', () => { 'wp/v2/demo-reverse-alphabetical?foo=bar&baz=quux': { body }, 'wp/v2/demo-alphabetical?baz=quux&foo=bar': { body }, }; - const preloadingMiddleware = createPreloadingMiddleware( preloadedData ); + const preloadingMiddleware = createPreloadingMiddleware( + preloadedData + ); let requestOptions = { method: 'GET', @@ -79,7 +83,9 @@ describe( 'Preloading Middleware', () => { [ 'method empty', { [ method ]: {} } ], ] )( '%s', ( label, preloadedData ) => { it( 'should move to the next middleware if no preloaded data', () => { - const prelooadingMiddleware = createPreloadingMiddleware( preloadedData ); + const prelooadingMiddleware = createPreloadingMiddleware( + preloadedData + ); const requestOptions = { method, path: 'wp/v2/posts', diff --git a/packages/api-fetch/src/middlewares/test/root-url.js b/packages/api-fetch/src/middlewares/test/root-url.js index 3480cddc532b06..921e6af8bb01e9 100644 --- a/packages/api-fetch/src/middlewares/test/root-url.js +++ b/packages/api-fetch/src/middlewares/test/root-url.js @@ -14,7 +14,9 @@ describe( 'Root URL middleware', () => { path: '/wp/v2/posts', }; const callback = ( options ) => { - expect( options.url ).toBe( 'http://wp.org/wp-admin/rest/wp/v2/posts' ); + expect( options.url ).toBe( + 'http://wp.org/wp-admin/rest/wp/v2/posts' + ); }; rootURLMiddleware( requestOptions, callback ); diff --git a/packages/api-fetch/src/middlewares/test/user-locale.js b/packages/api-fetch/src/middlewares/test/user-locale.js index 03dc9136ee20e0..9626819f3e0860 100644 --- a/packages/api-fetch/src/middlewares/test/user-locale.js +++ b/packages/api-fetch/src/middlewares/test/user-locale.js @@ -73,7 +73,9 @@ describe( 'User locale middleware', () => { }; const callback = ( options ) => { - expect( options.url ).toBe( 'http://wp.org/wp-json/wp/v2/posts?_locale=user' ); + expect( options.url ).toBe( + 'http://wp.org/wp-json/wp/v2/posts?_locale=user' + ); }; userLocaleMiddleware( requestOptions, callback ); @@ -88,7 +90,9 @@ describe( 'User locale middleware', () => { }; const callback = ( options ) => { - expect( options.url ).toBe( 'http://wp.org/wp-json/wp/v2/posts?foo=bar&_locale=user' ); + expect( options.url ).toBe( + 'http://wp.org/wp-json/wp/v2/posts?foo=bar&_locale=user' + ); }; userLocaleMiddleware( requestOptions, callback ); @@ -103,7 +107,9 @@ describe( 'User locale middleware', () => { }; const callback = ( options ) => { - expect( options.url ).toBe( 'http://wp.org/wp-json/wp/v2/posts?_locale=foo' ); + expect( options.url ).toBe( + 'http://wp.org/wp-json/wp/v2/posts?_locale=foo' + ); }; userLocaleMiddleware( requestOptions, callback ); @@ -118,7 +124,9 @@ describe( 'User locale middleware', () => { }; const callback = ( options ) => { - expect( options.url ).toBe( 'http://wp.org/wp-json/wp/v2/posts?foo=bar&_locale=foo' ); + expect( options.url ).toBe( + 'http://wp.org/wp-json/wp/v2/posts?foo=bar&_locale=foo' + ); }; userLocaleMiddleware( requestOptions, callback ); diff --git a/packages/api-fetch/src/middlewares/user-locale.js b/packages/api-fetch/src/middlewares/user-locale.js index 22fd232caf91b1..8debbde8d994a7 100644 --- a/packages/api-fetch/src/middlewares/user-locale.js +++ b/packages/api-fetch/src/middlewares/user-locale.js @@ -4,11 +4,17 @@ import { addQueryArgs, hasQueryArg } from '@wordpress/url'; function userLocaleMiddleware( options, next ) { - if ( typeof options.url === 'string' && ! hasQueryArg( options.url, '_locale' ) ) { + if ( + typeof options.url === 'string' && + ! hasQueryArg( options.url, '_locale' ) + ) { options.url = addQueryArgs( options.url, { _locale: 'user' } ); } - if ( typeof options.path === 'string' && ! hasQueryArg( options.path, '_locale' ) ) { + if ( + typeof options.path === 'string' && + ! hasQueryArg( options.path, '_locale' ) + ) { options.path = addQueryArgs( options.path, { _locale: 'user' } ); } diff --git a/packages/api-fetch/src/test/index.js b/packages/api-fetch/src/test/index.js index 05c327da6ee6f8..26431fb69a5937 100644 --- a/packages/api-fetch/src/test/index.js +++ b/packages/api-fetch/src/test/index.js @@ -50,14 +50,17 @@ describe( 'apiFetch', () => { body, } ); - expect( window.fetch ).toHaveBeenCalledWith( '/wp/v2/media?_locale=user', { - credentials: 'include', - headers: { - Accept: 'application/json, */*;q=0.1', - }, - method: 'POST', - body, - } ); + expect( window.fetch ).toHaveBeenCalledWith( + '/wp/v2/media?_locale=user', + { + credentials: 'include', + headers: { + Accept: 'application/json, */*;q=0.1', + }, + method: 'POST', + body, + } + ); } ); it( 'should fetch with a JSON body', () => { @@ -72,15 +75,18 @@ describe( 'apiFetch', () => { data: {}, } ); - expect( window.fetch ).toHaveBeenCalledWith( '/wp/v2/posts?_locale=user', { - body: '{}', - credentials: 'include', - headers: { - Accept: 'application/json, */*;q=0.1', - 'Content-Type': 'application/json', - }, - method: 'POST', - } ); + expect( window.fetch ).toHaveBeenCalledWith( + '/wp/v2/posts?_locale=user', + { + body: '{}', + credentials: 'include', + headers: { + Accept: 'application/json, */*;q=0.1', + 'Content-Type': 'application/json', + }, + method: 'POST', + } + ); } ); it( 'should respect developer-provided options', () => { @@ -93,15 +99,18 @@ describe( 'apiFetch', () => { credentials: 'omit', } ); - expect( window.fetch ).toHaveBeenCalledWith( '/wp/v2/posts?_locale=user', { - body: '{}', - credentials: 'omit', - headers: { - Accept: 'application/json, */*;q=0.1', - 'Content-Type': 'application/json', - }, - method: 'POST', - } ); + expect( window.fetch ).toHaveBeenCalledWith( + '/wp/v2/posts?_locale=user', + { + body: '{}', + credentials: 'omit', + headers: { + Accept: 'application/json, */*;q=0.1', + 'Content-Type': 'application/json', + }, + method: 'POST', + } + ); } ); it( 'should return the error message properly', () => { @@ -188,11 +197,13 @@ describe( 'apiFetch', () => { } ) ); - return apiFetch( { path: '/random', parse: false } ).then( ( response ) => { - expect( response ).toEqual( { - status: 200, - } ); - } ); + return apiFetch( { path: '/random', parse: false } ).then( + ( response ) => { + expect( response ).toEqual( { + status: 200, + } ); + } + ); } ); it( 'should not try to parse the error', () => { @@ -202,11 +213,13 @@ describe( 'apiFetch', () => { } ) ); - return apiFetch( { path: '/random', parse: false } ).catch( ( response ) => { - expect( response ).toEqual( { - status: 400, - } ); - } ); + return apiFetch( { path: '/random', parse: false } ).catch( + ( response ) => { + expect( response ).toEqual( { + status: 400, + } ); + } + ); } ); it( 'should not use the default fetch handler when using a custom fetch handler', () => { diff --git a/packages/api-fetch/src/utils/response.js b/packages/api-fetch/src/utils/response.js index 518a7fd5e66f81..d28413862b6c63 100644 --- a/packages/api-fetch/src/utils/response.js +++ b/packages/api-fetch/src/utils/response.js @@ -46,10 +46,13 @@ const parseJsonAndNormalizeError = ( response ) => { * * @return {Promise} Parsed response. */ -export const parseResponseAndNormalizeError = ( response, shouldParseResponse = true ) => { - return Promise.resolve( parseResponse( response, shouldParseResponse ) ).catch( ( res ) => - parseAndThrowError( res, shouldParseResponse ) - ); +export const parseResponseAndNormalizeError = ( + response, + shouldParseResponse = true +) => { + return Promise.resolve( + parseResponse( response, shouldParseResponse ) + ).catch( ( res ) => parseAndThrowError( res, shouldParseResponse ) ); }; export function parseAndThrowError( response, shouldParseResponse = true ) { diff --git a/packages/autop/src/index.js b/packages/autop/src/index.js index 32512f62094eca..3a0fc7fa73600e 100644 --- a/packages/autop/src/index.js +++ b/packages/autop/src/index.js @@ -92,7 +92,10 @@ function replaceInHtmlTags( haystack, replacePairs ) { for ( let j = 0; j < needles.length; j++ ) { const needle = needles[ j ]; if ( -1 !== textArr[ i ].indexOf( needle ) ) { - textArr[ i ] = textArr[ i ].replace( new RegExp( needle, 'g' ), replacePairs[ needle ] ); + textArr[ i ] = textArr[ i ].replace( + new RegExp( needle, 'g' ), + replacePairs[ needle ] + ); changed = true; // After one strtr() break out of the foreach loop and look at next element. break; @@ -170,10 +173,16 @@ export function autop( text, br = true ) { '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)'; // Add a double line break above block-level opening tags. - text = text.replace( new RegExp( '(<' + allBlocks + '[\\s/>])', 'g' ), '\n\n$1' ); + text = text.replace( + new RegExp( '(<' + allBlocks + '[\\s/>])', 'g' ), + '\n\n$1' + ); // Add a double line break below block-level closing tags. - text = text.replace( new RegExp( '(' + allBlocks + '>)', 'g' ), '$1\n\n' ); + text = text.replace( + new RegExp( '(' + allBlocks + '>)', 'g' ), + '$1\n\n' + ); // Standardize newline characters to "\n". text = text.replace( /\r\n|\r/g, '\n' ); @@ -231,10 +240,16 @@ export function autop( text, br = true ) { text = text.replace( /\s*<\/p>/g, '' ); // Add a closing
inside
, , or