Skip to content

Commit 98ac824

Browse files
authored
Merge pull request #13 from Automattic/update/dev-environment
Update Development environment
2 parents be303aa + 54bc73e commit 98ac824

16 files changed

+17084
-4561
lines changed

.editorconfig

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
# This file is for unifying the coding style for different editors and IDEs
3+
# editorconfig.org
4+
5+
# WordPress Coding Standards
6+
# https://make.wordpress.org/core/handbook/coding-standards/
7+
8+
root = true
9+
10+
[*]
11+
charset = utf-8
12+
end_of_line = lf
13+
insert_final_newline = true
14+
trim_trailing_whitespace = true
15+
indent_style = tab
16+
17+
[*.yml]
18+
indent_style = space
19+
indent_size = 2
20+
21+
[*.md]
22+
trim_trailing_whitespace = false
23+
24+
[*.txt]
25+
end_of_line = crlf

.eslintignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
**/*.min.js
2+
**/node_modules/**
3+
**/vendor/**
4+
**/dist/**
5+
**/tests/**
6+
bin/*

.eslintrc

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"ecmaVersion": 2020
1414
},
1515
"extends": [
16-
"eslint:recommended"
17-
],
18-
"ignorePatterns": [ "dist/**" ]
16+
"eslint:recommended",
17+
"plugin:@wordpress/eslint-plugin/recommended"
18+
]
1919
}
2020

bin/generate.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const puppeteer = require( 'puppeteer' );
2-
const { generateCriticalCSS, BrowserInterfacePuppeteer } = require( '../index' );
2+
const {
3+
generateCriticalCSS,
4+
BrowserInterfacePuppeteer,
5+
} = require( '../index' );
36

47
async function main() {
58
const urls = process.argv.slice( 2 );
@@ -20,15 +23,15 @@ async function main() {
2023

2124
console.log( 'Generating Critical CSS...' );
2225

23-
const [ css, warnings ] = await generateCriticalCSS({
26+
const [ css, warnings ] = await generateCriticalCSS( {
2427
urls,
2528
viewports: [
2629
{ width: 414, height: 896 },
2730
{ width: 1200, height: 800 },
2831
{ width: 1920, height: 1080 },
2932
],
3033
browserInterface: new BrowserInterfacePuppeteer( testPages ),
31-
});
34+
} );
3235

3336
if ( warnings.length ) {
3437
console.log( '\n\nwarnings => ' );
@@ -39,7 +42,9 @@ async function main() {
3942
console.log( css );
4043
}
4144

42-
main().catch( err => {
43-
console.error( err );
44-
process.exit( 1 );
45-
} ).then( () => process.exit( 0 ) );
45+
main()
46+
.catch( ( err ) => {
47+
console.error( err );
48+
process.exit( 1 );
49+
} )
50+
.then( () => process.exit( 0 ) );

jest.config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
2-
testMatch: ['**/?(*.)+(spec|test).js'],
3-
setupFilesAfterEnv: ['./tests/config/jest-setup.js'],
4-
collectCoverageFrom: ['lib/**/*.js', 'index.js'],
2+
testMatch: [ '**/?(*.)+(spec|test).js' ],
3+
setupFilesAfterEnv: [ './tests/config/jest-setup.js' ],
4+
collectCoverageFrom: [ 'lib/**/*.js', 'index.js' ],
55
globalSetup: 'jest-environment-puppeteer/setup',
66
globalTeardown: 'jest-environment-puppeteer/teardown',
77
testEnvironment: 'jest-environment-puppeteer',

lib/browser-interface-iframe.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class BrowserInterfaceIframe extends BrowserInterface {
2525
this.verifyPage = verifyPage;
2626

2727
// Default 'allowScripts' to true if not specified.
28-
allowScripts = ( allowScripts !== false );
28+
allowScripts = allowScripts !== false;
2929

3030
if ( ! verifyPage ) {
3131
throw new ConfigurationError( {
@@ -90,7 +90,10 @@ class BrowserInterfaceIframe extends BrowserInterface {
9090
const response = await fetch( url );
9191
if ( response.status === 200 ) {
9292
if ( response.redirected ) {
93-
return new RedirectError( { url, redirectUrl: response.url } )
93+
return new RedirectError( {
94+
url,
95+
redirectUrl: response.url,
96+
} );
9497
}
9598
return null;
9699
}

lib/browser-interface-puppeteer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const BrowserInterface = require( './browser-interface' );
2-
const { ConfigurationError } = require('./errors');
2+
const { ConfigurationError } = require( './errors' );
33

44
class BrowserInterfacePuppeteer extends BrowserInterface {
55
constructor( pages ) {
@@ -13,7 +13,7 @@ class BrowserInterfacePuppeteer extends BrowserInterface {
1313

1414
if ( ! page ) {
1515
throw new ConfigurationError( {
16-
message: `Puppeteer interface does not include URL ${ pageUrl }`
16+
message: `Puppeteer interface does not include URL ${ pageUrl }`,
1717
} );
1818
}
1919

lib/browser-interface.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class BrowserInterface {
44
// eslint-disable-next-line no-unused-vars
55
async runInPage( pageUrl, viewport, method, ...args ) {
66
throw new InternalError( {
7-
message: 'Undefined interface method: BrowserInterface.runInPage()'
7+
message: 'Undefined interface method: BrowserInterface.runInPage()',
88
} );
99
}
1010

@@ -23,7 +23,7 @@ class BrowserInterface {
2323
.filter( ( link ) => link.rel === 'stylesheet' )
2424
.reduce( ( set, link ) => {
2525
set[ link.href ] = {
26-
media: link.media || null
26+
media: link.media || null,
2727
};
2828

2929
return set;

lib/css-file-set.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { HttpError, GenericUrlError, CriticalCssError } = require('./errors');
1+
const { HttpError, GenericUrlError, CriticalCssError } = require( './errors' );
22
const StyleAST = require( './style-ast' );
33
const fetch =
44
( typeof window !== 'undefined' && window.fetch ) ||
@@ -27,8 +27,8 @@ class CSSFileSet {
2727
*/
2828
async addMultiple( page, cssIncludes ) {
2929
return Promise.all(
30-
Object.keys( cssIncludes ).map(
31-
( url ) => this.add( page, url, cssIncludes[ url ] )
30+
Object.keys( cssIncludes ).map( ( url ) =>
31+
this.add( page, url, cssIncludes[ url ] )
3232
)
3333
);
3434
}
@@ -38,6 +38,7 @@ class CSSFileSet {
3838
*
3939
* @param {string} page - URL of the page the CSS URL was found on.
4040
* @param {string} cssUrl - The CSS file URL.
41+
* @param {Object} settings
4142
*/
4243
async add( page, cssUrl, settings = {} ) {
4344
// Add by reference if we already know this file.
@@ -71,7 +72,10 @@ class CSSFileSet {
7172

7273
// Wrap any unfamiliar fetch errors in a generic url error.
7374
if ( ! ( err instanceof CriticalCssError ) ) {
74-
wrappedError = new GenericUrlError( { code: cssUrl, url: err.message } );
75+
wrappedError = new GenericUrlError( {
76+
code: cssUrl,
77+
url: err.message,
78+
} );
7579
}
7680

7781
this.storeError( cssUrl, wrappedError );
@@ -249,10 +253,7 @@ class CSSFileSet {
249253
return set;
250254
}, {} );
251255

252-
await cssFiles.addMultiple(
253-
url,
254-
absoluteIncludes
255-
);
256+
await cssFiles.addMultiple( url, absoluteIncludes );
256257
}
257258

258259
return cssFiles;

lib/errors.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@ class CriticalCssError extends Error {
3131

3232
/**
3333
* Returns true if this error object has the specified data value.
34+
*
35+
* @param {string} key
3436
*/
3537
has( key ) {
3638
return Object.prototype.hasOwnProperty.call( this.data, key );
3739
}
3840

3941
/**
4042
* Gets the data value with the specified key, or undefined if not defined.
43+
*
44+
* @param {string} key
4145
*/
4246
get( key ) {
4347
return this.data[ key ];
@@ -59,13 +63,13 @@ class CriticalCssError extends Error {
5963
* Reverse of toJSON; constructs a CriticalCssError object from
6064
* a previously serialized value.
6165
*
62-
* @param {object} jsonObject - JSON compatible object
66+
* @param {Object} jsonObject - JSON compatible object
6367
*/
6468
static fromJSON( jsonObject ) {
6569
const ErrorClass = CriticalCssErrorTypes[ jsonObject.type ];
6670
if ( ! ErrorClass ) {
6771
return new UnknownError( {
68-
message: jsonObject.message || jsonObject
72+
message: jsonObject.message || jsonObject,
6973
} );
7074
}
7175

lib/minify-css.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const CleanCSS = require( 'clean-css' );
88
*
99
* @param {string} css - CSS to minify.
1010
*
11-
* @return {[ string, string[] ]} - Minified CSS and a list of errors returned.
11+
* return {[ string, string[] ]} - Minified CSS and a list of errors returned.
1212
*/
1313
function minifyCss( css ) {
1414
const result = new CleanCSS().minify( css );

lib/style-ast.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,10 @@ class StyleAST {
232232
} );
233233

234234
// If there are no useful media query lists left, throw away the block.
235-
if ( atrule.prelude.children && atrule.prelude.children.isEmpty() ) {
235+
if (
236+
atrule.prelude.children &&
237+
atrule.prelude.children.isEmpty()
238+
) {
236239
atlist.remove( atitem );
237240
}
238241
},
@@ -336,7 +339,10 @@ class StyleAST {
336339
);
337340

338341
// If the selector list is empty, prune the whole rule.
339-
if ( rule.prelude.children && rule.prelude.children.isEmpty() ) {
342+
if (
343+
rule.prelude.children &&
344+
rule.prelude.children.isEmpty()
345+
) {
340346
list.remove( item );
341347
}
342348
},

0 commit comments

Comments
 (0)