Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module.exports = {
root: true,
env: {
es6: true,
node: true
node: true,
},
extends: 'plugin:@wordpress/eslint-plugin/recommended',
rules: {
'one-var': [ 'error', 'never' ],
'prefer-arrow-callback': [ 'error' ]
}
'prefer-arrow-callback': [ 'error' ],
},
};
35 changes: 35 additions & 0 deletions .npmpackagejsonlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"extends": "@wordpress/npm-package-json-lint-config",
"rules": {
"valid-values-license": [ "error", [ "MIT" ] ],
"description-format": [
"error",
{
"requireCapitalFirstLetter": true,
"requireEndingPeriod": true
}
],
"prefer-no-devDependencies": "error",
"require-publishConfig": "error",
"require-repository-directory": "error",
"valid-values-author": [ "error", [ "The WordPress Contributors" ] ],
"valid-values-publishConfig": [
"error",
[
{
"access": "public"
}
]
]
},
"overrides": [
{
"patterns": [ "./package.json" ],
"rules": {
"require-publishConfig": "off",
"require-repository-directory": "off",
"prefer-no-devDependencies": "off"
}
}
]
}
3 changes: 3 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Import the default config file and expose it in the project root.
// Useful for editor integrations.
module.exports = require('@wordpress/prettier-config');
18 changes: 15 additions & 3 deletions lib/map_old_to_new_file_path.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ function mapOldToNewFilePath( filePath, fileMappings ) {
}

// Regex to match the second filename of the diff header.
const headerRegex = new RegExp( '((diff \\-\\-git .* )(' + oldPath + ')(\\n))', 'ig' );
const headerRegex = new RegExp(
'((diff \\-\\-git .* )(' + oldPath + ')(\\n))',
'ig'
);

// Regex to match the old and new file name of the chunks within the diff.
const chunkFilenameRegex = new RegExp( '((-{3}|\\+{3})( ' + oldPath + '))', 'ig' );
const chunkFilenameRegex = new RegExp(
'((-{3}|\\+{3})( ' + oldPath + '))',
'ig'
);

if ( ! body.match( chunkFilenameRegex ) ) {
continue;
Expand All @@ -35,7 +41,13 @@ function mapOldToNewFilePath( filePath, fileMappings ) {

// Logs the mapping.
if ( body !== newBody ) {
grunt.log.writeln( 'Old file path ' + oldPath + ' found in patch. This path has been automatically replaced by ' + newPath + '.' );
grunt.log.writeln(
'Old file path ' +
oldPath +
' found in patch. This path has been automatically replaced by ' +
newPath +
'.'
);
}
}

Expand Down
14 changes: 8 additions & 6 deletions lib/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ module.exports = {
try {
diff.split( '\n' ).forEach( ( line ) => {
// these are often the first line
if ( startsWith( line, 'Index: src/' ) ||
if (
startsWith( line, 'Index: src/' ) ||
startsWith( line, 'Index: tests/' ) ||
startsWith( line, 'Index: tools/' ) ||
startsWith( line, 'diff --git src' ) ||
Expand All @@ -61,13 +62,13 @@ module.exports = {
startsWith( line, 'diff --git a/src' ) ||
startsWith( line, 'diff --git a/test' ) ||
startsWith( line, 'diff --git a/tools' )

) {
throw false;
}

wpDashExceptions.forEach( ( exception ) => {
if ( startsWith( line, 'Index: ' + exception ) ||
if (
startsWith( line, 'Index: ' + exception ) ||
startsWith( line, 'diff --git ' + exception ) ||
startsWith( line, 'diff --git a/' + exception )
) {
Expand All @@ -76,15 +77,17 @@ module.exports = {
} );

noWpDashExceptions.forEach( ( exception ) => {
if ( startsWith( line, 'Index: ' + exception ) ||
if (
startsWith( line, 'Index: ' + exception ) ||
startsWith( line, 'diff --git ' + exception ) ||
startsWith( line, 'diff --git a/' + exception )
) {
throw true;
}
} );

if ( startsWith( line, 'Index: wp-' ) ||
if (
startsWith( line, 'Index: wp-' ) ||
startsWith( line, 'Index: trunk/wp-' ) ||
startsWith( line, 'diff --git wp-' ) ||
startsWith( line, 'diff --git a/wp-' )
Expand All @@ -98,5 +101,4 @@ module.exports = {
}
return src;
},

};
19 changes: 11 additions & 8 deletions lib/regex.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module.exports = {
patchAttachments( html ) {
return html.match( /<dt>\s*<a\s+href="([^"]+?)(diff|patch)"\s+title="View attachment">([^<]+)/g );
return html.match(
/<dt>\s*<a\s+href="([^"]+?)(diff|patch)"\s+title="View attachment">([^<]+)/g
);
},

urlsFromAttachmentList( html ) {
Expand All @@ -15,12 +17,14 @@ module.exports = {
return longMatches
.map( ( match ) => {
if ( match.match( /(patch|diff)"/ ) ) {
return match
// Remove any HTML tags.
.replace( /<\/?[^>]+>/g, '' )
// Collapse consecutive whitespace characters into one space.
.replace( /\s+/g, ' ' )
.trim();
return (
match
// Remove any HTML tags.
.replace( /<\/?[^>]+>/g, '' )
// Collapse consecutive whitespace characters into one space.
.replace( /\s+/g, ' ' )
.trim()
);
}
return false;
} )
Expand All @@ -30,5 +34,4 @@ module.exports = {
localFileClean( file ) {
return file.replace( '?', '' ).replace( /\s/g, '' );
},

};
6 changes: 4 additions & 2 deletions lib/trac.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ const grunt = require( 'grunt' );
module.exports = {
convertToRaw( parsedUrl ) {
grunt.log.debug( 'convertToRaw: ' + JSON.stringify( parsedUrl ) );
parsedUrl.pathname = parsedUrl.pathname.replace( /attachment/, 'raw-attachment' );
parsedUrl.pathname = parsedUrl.pathname.replace(
/attachment/,
'raw-attachment'
);
grunt.log.debug( 'converted_from_raw: ' + url.format( parsedUrl ) );
return url.format( parsedUrl );
},

};
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
{
"name": "grunt-patch-wordpress",
"version": "2.0.0",
"description": "Patch your core WordPress",
"author": {
"name": "Aaron Jorbin",
"email": "aaron@jorb.in",
"url": "http://aaron.jorb.in"
},
"description": "Patch your core WordPress.",
"author": "The WordPress Contributors",
"license": "MIT",
"keywords": [
"gruntplugin"
Expand Down
Loading