Repository navigation
Replace unreliable activation hook with default value for enabled modules #222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
338594a
Replace plugin activation hook with module settings default to be rel…
ebb5ba0
Implement script to automatically generate and update default-enabled…
5c398d3
Expand release instructions to include running command to refresh def…
df55cd7
Fix relevant load.php tests by updating expected default option.
8dce1e9
Simplify code by removing if clause.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| const path = require( 'path' ); | ||
| const fs = require( 'fs' ); | ||
| const { EOL } = require( 'os' ); | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| const { log, formats } = require( '../lib/logger' ); | ||
| const { getModuleData } = require( './common' ); | ||
|
|
||
| const TAB = '\t'; | ||
| const NEWLINE = EOL; | ||
| const FILE_HEADER = `<?php | ||
| /* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ | ||
| return array( | ||
| `; | ||
| const FILE_FOOTER = ` | ||
| ); | ||
| /* THIS IS THE END OF THE GENERATED FILE */ | ||
| `; | ||
|
|
||
| /** | ||
| * @typedef WPEnabledModulesCommandOptions | ||
| * | ||
| * @property {string=} directory Optional directory, default is the root `/modules` directory. | ||
| * @property {string=} output Optional output PHP file, default is the root `/default-enabled-modules.php` file. | ||
| */ | ||
|
|
||
| /** | ||
| * @typedef WPEnabledModulesSettings | ||
| * | ||
| * @property {string} directory Modules directory. | ||
| * @property {string} output Output PHP file. | ||
| */ | ||
|
|
||
| exports.options = [ | ||
| { | ||
| argname: '-d, --directory <directory>', | ||
| description: 'Modules directory', | ||
| }, | ||
| { | ||
| argname: '-d, --output <output>', | ||
| description: 'Output file', | ||
| }, | ||
| ]; | ||
|
|
||
| /** | ||
| * Command that generates a PHP file with non-experimental module slugs. | ||
| * | ||
| * @param {WPEnabledModulesCommandOptions} opt | ||
| */ | ||
| exports.handler = async ( opt ) => { | ||
| await createEnabledModules( { | ||
| directory: opt.directory || 'modules', | ||
| output: opt.output || 'default-enabled-modules.php', | ||
| } ); | ||
| }; | ||
|
|
||
| /** | ||
| * Gathers the non-experimental modules as the default enabled modules. | ||
| * | ||
| * @param {WPEnabledModulesSettings} settings Default enabled modules settings. | ||
| * | ||
| * @return {[]string} List of default enabled module paths relative to modules directory. | ||
| */ | ||
| async function getDefaultEnabledModules( settings ) { | ||
| const modulesData = await getModuleData( settings.directory ); | ||
| return modulesData | ||
| .filter( ( moduleData ) => ! moduleData.experimental ) | ||
| .map( ( moduleData ) => `${ moduleData.focus }/${ moduleData.slug }` ); | ||
| } | ||
|
|
||
| /** | ||
| * Creates PHP file with the given default enabled modules. | ||
| * | ||
| * @param {[]string} enabledModules List of default enabled module paths relative to modules directory. | ||
| * @param {WPEnabledModulesSettings} settings Default enabled modules settings. | ||
| */ | ||
| function createEnabledModulesPHPFile( enabledModules, settings ) { | ||
| const output = enabledModules.map( ( enabledModule ) => { | ||
| // Escape single quotes. | ||
| return `${ TAB }'${ enabledModule.replace( /'/g, "\\'" ) }',`; | ||
| } ); | ||
|
|
||
| const fileOutput = `${ FILE_HEADER }${ output.join( | ||
| NEWLINE | ||
| ) }${ FILE_FOOTER }`; | ||
| fs.writeFileSync( path.join( '.', settings.output ), fileOutput ); | ||
| } | ||
|
|
||
| /** | ||
| * Gathers non-experimental modules and generates a PHP file with them. | ||
| * | ||
| * @param {WPEnabledModulesSettings} settings Default enabled modules settings. | ||
| */ | ||
| async function createEnabledModules( settings ) { | ||
| log( | ||
| formats.title( | ||
| `\n💃Gathering non-experimental modules for "${ settings.directory }" in "${ settings.output }"\n\n` | ||
| ) | ||
| ); | ||
|
|
||
| try { | ||
| const enabledModules = await getDefaultEnabledModules( settings ); | ||
| createEnabledModulesPHPFile( enabledModules, settings ); | ||
| } catch ( error ) { | ||
| if ( error instanceof Error ) { | ||
| log( formats.error( error.stack ) ); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| log( | ||
| formats.success( | ||
| `\n💃Non-experimental modules successfully set in "${ settings.output }"\n\n` | ||
| ) | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <?php | ||
| /* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ | ||
| return array( | ||
| 'images/webp-uploads', | ||
| 'object-cache/persistent-object-cache-health-check', | ||
| 'site-health/webp-support', | ||
| ); | ||
| /* THIS IS THE END OF THE GENERATED FILE */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.