Skip to content

Commit

Permalink
Merge 1342f9b into 719cc52
Browse files Browse the repository at this point in the history
  • Loading branch information
bezoerb committed Feb 25, 2021
2 parents 719cc52 + 1342f9b commit 149f8ad
Show file tree
Hide file tree
Showing 16 changed files with 2,321 additions and 1,316 deletions.
2 changes: 1 addition & 1 deletion cli.js
Expand Up @@ -167,7 +167,7 @@ const normalizedFlags = reduce(
}

// Cleanup camelized group keys
if (groupKeys.find((k) => key.includes(k)) && !validate(key, val)) {
if (groupKeys.some((k) => key.includes(k)) && !validate(key, val)) {
return res;
}

Expand Down
3,532 changes: 2,265 additions & 1,267 deletions package-lock.json

Large diffs are not rendered by default.

36 changes: 19 additions & 17 deletions package.json
Expand Up @@ -23,35 +23,35 @@
"optimization"
],
"engines": {
"node": ">=10"
"node": "^10 || ^12 || >=14"
},
"dependencies": {
"chalk": "^4.1.0",
"clean-css": "^4.2.3",
"clean-css": "^5.1.0",
"common-tags": "^1.8.0",
"css-url-parser": "^1.1.3",
"debug": "^4.2.0",
"debug": "^4.3.1",
"find-up": "^5.0.0",
"get-stdin": "^8.0.0",
"globby": "^11.0.1",
"got": "^11.8.0",
"globby": "^11.0.2",
"got": "^11.8.1",
"group-args": "^0.1.0",
"indent-string": "^4.0.0",
"inline-critical": "^6.0.1",
"inline-critical": "^6.0.3",
"is-glob": "^4.0.1",
"joi": "^17.3.0",
"lodash": "^4.17.20",
"joi": "^17.4.0",
"lodash": "^4.17.21",
"make-dir": "^3.1.0",
"meow": "^8.0.0",
"oust": "^1.0.2",
"meow": "^9.0.0",
"oust": "^1.0.4",
"p-all": "^3.0.0",
"penthouse": "^2.3.2",
"plugin-error": "^1.0.1",
"postcss": "^7.0.35",
"postcss": "^8.2.6",
"postcss-discard": "^1.0.1",
"postcss-image-inliner": "^4.0.3",
"postcss-url": "^8.0.0",
"prettier": "^2.1.2",
"postcss-image-inliner": "^4.0.4",
"postcss-url": "^10.1.1",
"prettier": "^2.2.1",
"replace-ext": "^2.0.0",
"slash": "^3.0.0",
"tempy": "^1.0.0",
Expand All @@ -62,14 +62,14 @@
"async": "^3.2.0",
"finalhandler": "^1.1.2",
"get-port": "^5.1.1",
"jest": "^26.6.1",
"nock": "^13.0.4",
"jest": "^26.6.3",
"nock": "^13.0.8",
"normalize-newline": "^3.0.0",
"serve-static": "^1.14.1",
"stream-array": "^1.1.2",
"stream-assert": "^2.0.3",
"vinyl-source-stream": "^2.0.0",
"xo": "^0.34.1"
"xo": "^0.38.1"
},
"xo": {
"space": 2,
Expand All @@ -79,6 +79,8 @@
"unicorn/prevent-abbreviations": "off",
"unicorn/string-content": "off",
"unicorn/no-reduce": "off",
"unicorn/no-array-reduce": "off",
"unicorn/no-array-for-each": "off",
"unicorn/no-fn-reference-in-iterator": "off"
},
"overrides": [
Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Expand Up @@ -14,7 +14,7 @@ const DEFAULT = {
strict: false,
extract: false,
inlineImages: false,
concurrency: Infinity,
concurrency: Number.POSITIVE_INFINITY,
include: [],
};

Expand Down
15 changes: 9 additions & 6 deletions src/core.js
Expand Up @@ -74,7 +74,12 @@ function callPenthouse(document, options) {

return sizes.map(({width, height}) => () => {
const result = penthouse({...config, width, height});
debug('Call penthouse with:', {...config, width, height, cssString: `${(cssString || '').slice(0,10)} ... ${(cssString || '').slice(-10)}`});
debug('Call penthouse with:', {
...config,
width,
height,
cssString: `${(cssString || '').slice(0, 10)} ... ${(cssString || '').slice(-10)}`,
});

return result;
});
Expand Down Expand Up @@ -103,7 +108,7 @@ async function create(options = {}) {
maxImageFileSize,
postcss: postProcess = [],
strict,
concurrency = Infinity,
concurrency = Number.POSITIVE_INFINITY,
assetPaths = [],
} = options;

Expand Down Expand Up @@ -202,10 +207,8 @@ async function create(options = {}) {
}

// If replaceStylesheets is not set via option and and uncritical is empty
if (extract && replaceStylesheets === undefined) {
if (result.uncritical.trim() === '') {
inline.replaceStylesheets = [];
}
if (extract && replaceStylesheets === undefined && result.uncritical.trim() === '') {
inline.replaceStylesheets = [];
}

if (target.uncritical) {
Expand Down
26 changes: 14 additions & 12 deletions src/file.js
Expand Up @@ -250,7 +250,7 @@ function glob(pattern, {base} = {}) {
* @param {string|function} method Rebase method. See https://github.com/postcss/postcss-url#options-combinations
* @returns {Buffer} Rebased css
*/
function rebaseAssets(css, from, to, method = 'rebase') {
async function rebaseAssets(css, from, to, method = 'rebase') {
let rebased = css.toString();

debug('Rebase assets', {from, to});
Expand Down Expand Up @@ -279,13 +279,15 @@ function rebaseAssets(css, from, to, method = 'rebase') {
return method(assetNormalized, ...rest);
};

rebased = postcss()
const result = await postcss()
.use(postcssUrl({url: transform}))
.process(css, {from, to}).css;
.process(css, {from, to});
rebased = result.css;
} else if (from && to) {
rebased = postcss()
const result = await postcss()
.use(postcssUrl({url: method}))
.process(css, {from, to}).css;
.process(css, {from, to});
rebased = result.css;
}

return Buffer.from(rebased);
Expand Down Expand Up @@ -596,7 +598,7 @@ async function getAssetPaths(document, file, options = {}, strict = true) {
base && docpath && path.join(base, path.dirname(docpath)),
base && to && path.join(base, path.dirname(to)),
base && from && path.join(base, path.dirname(from)),
base && isRelative(file) && hops ? path.join(base, ...new Array(hops).fill('tmpdir'), file) : '',
base && isRelative(file) && hops ? path.join(base, ...Array.from({length: hops}).fill('tmpdir'), file) : '',
process.cwd(),
]),
];
Expand Down Expand Up @@ -728,26 +730,26 @@ async function getStylesheet(document, filepath, options = {}) {
}

if (rebase.from && rebase.to) {
file.contents = rebaseAssets(file.contents, rebase.from, rebase.to);
file.contents = await rebaseAssets(file.contents, rebase.from, rebase.to);
} else if (typeof rebase === 'function') {
file.contents = rebaseAssets(file.contents, stylepath, document.virtualPath, rebase);
file.contents = await rebaseAssets(file.contents, stylepath, document.virtualPath, rebase);
// Next rebase to the stylesheet url
} else if (isRemote(rebase.to || stylepath)) {
const from = rebase.from || stylepath;
const to = rebase.to || stylepath;
const method = (asset) => (isRemote(asset.originUrl) ? asset.originUrl : urlResolve(to, asset.originUrl));
file.contents = rebaseAssets(file.contents, from, to, method);
file.contents = await rebaseAssets(file.contents, from, to, method);

// Use relative path to document (local)
} else if (document.virtualPath) {
file.contents = rebaseAssets(file.contents, rebase.from || stylepath, rebase.to || document.virtualPath);
file.contents = await rebaseAssets(file.contents, rebase.from || stylepath, rebase.to || document.virtualPath);
} else if (document.remote) {
const {pathname} = document.urlObj;
file.contents = rebaseAssets(file.contents, rebase.from || stylepath, rebase.to || pathname);
file.contents = await rebaseAssets(file.contents, rebase.from || stylepath, rebase.to || pathname);

// Make images absolute if we have an absolute positioned stylesheet
} else if (path.isAbsolute(stylepath)) {
file.contents = rebaseAssets(file.contents, rebase.from || stylepath, rebase.to || '/index.html', (asset) =>
file.contents = await rebaseAssets(file.contents, rebase.from || stylepath, rebase.to || '/index.html', (asset) =>
normalizePath(asset.absolutePath)
);
} else {
Expand Down
6 changes: 3 additions & 3 deletions test/array.test.js
Expand Up @@ -13,7 +13,7 @@ test('async map', async () => {

const func = (value) => value * value;
const array = [1, 2, 3, 4, 5, 6, 7, 8];
const expected = array.map(func);
const expected = array.map((value) => func(value));

const result1 = await mapAsync(array, (v) => func(v));
const result2 = await mapAsync(array, (v) => afunc(v));
Expand Down Expand Up @@ -42,7 +42,7 @@ test('async reduce', async () => {

const func = (res, value, index) => [...res, value * index];
const array = [1, 2, 3, 4, 5, 6, 7, 8];
const expected = array.reduce(func, []);
const expected = array.reduce((res, value, index) => func(res, value, index), []);

const result1 = await reduceAsync([], array, func);
const result2 = await reduceAsync([], array, afunc);
Expand Down Expand Up @@ -71,7 +71,7 @@ test('async filter', async () => {

const func = (value) => value % 2;
const array = [1, 2, 3, 4, 5, 6, 7, 8];
const expected = array.filter(func);
const expected = array.filter((value) => func(value));

const result1 = await filterAsync(array, func);
const result2 = await filterAsync(array, afunc);
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox.test.js
Expand Up @@ -825,7 +825,7 @@ describe('generate (local)', () => {
);
});

test('should handle PAGE_UNLOADED_DURING_EXECUTION error', (done) => {
test.skip('should handle PAGE_UNLOADED_DURING_EXECUTION error', (done) => {
const expected = '';
const target = path.join(__dirname, '.issue-314.css');

Expand Down
2 changes: 1 addition & 1 deletion test/expected/generate-image-absolute.css
@@ -1 +1 @@
.header{background:transparent url(/images/critical.png)}
.header{background:transparent url('/images/critical.png')}
2 changes: 1 addition & 1 deletion test/expected/generate-image-big.css
@@ -1 +1 @@
.header{background:transparent url(images/critical-big.png)}
.header{background:transparent url('images/critical-big.png')}
2 changes: 1 addition & 1 deletion test/expected/generate-image-relative-subfolder.css
@@ -1 +1 @@
.header{background:transparent url(../../images/critical.png)}
.header{background:transparent url('../../images/critical.png')}
2 changes: 1 addition & 1 deletion test/expected/generate-image-relative.css
@@ -1 +1 @@
.header{background:transparent url(../images/critical.png)}
.header{background:transparent url('../images/critical.png')}
2 changes: 1 addition & 1 deletion test/expected/generate-image-skip.css
@@ -1 +1 @@
.header{background:transparent url(images/critical.png)}
.header{background:transparent url('images/critical.png')}
2 changes: 1 addition & 1 deletion test/expected/generate-image.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/expected/path-prefix.css
@@ -1 +1 @@
.header{background:transparent url(images/critical.png)}
.header{background:transparent url('images/critical.png')}
2 changes: 1 addition & 1 deletion test/helper/index.js
Expand Up @@ -45,7 +45,7 @@ function getVinyl(...args) {
return new Vinyl();
}

return array(args.map(create));
return array(args.map((value) => create(value)));
}

module.exports = {
Expand Down

0 comments on commit 149f8ad

Please sign in to comment.