Skip to content
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

upgrade postcss #169

Merged
merged 3 commits into from
May 10, 2021
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
49 changes: 21 additions & 28 deletions packages/resolve-url-loader/lib/engine/postcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,12 @@ function process(sourceFile, sourceContent, params) {
sourceContent.replace(ORPHAN_CR_REGEX, ' $1') :
sourceContent;

// prepend file protocol to all sources to avoid problems with source map
return postcss([
postcss.plugin('postcss-resolve-url', postcssPlugin)
])
.process(correctedContent, {
from: fileProtocol.prepend(sourceFile),
map : params.outputSourceMap && {
prev : !!params.absSourceMap && fileProtocol.prepend(params.absSourceMap),
inline : false,
annotation : false,
sourcesContent: true // #98 sourcesContent missing from output map
}
})
.then(result => ({
content: result.css,
map : params.outputSourceMap ? fileProtocol.remove(result.map.toJSON()) : null
}));

/**
* Plugin for postcss that follows SASS transpilation.
*/
function postcssPlugin() {
return function applyPlugin(styles) {
styles.walkDecls(eachDeclaration);
};

/**
* Process a declaration from the syntax tree.
* @param declaration
*/
function eachDeclaration(declaration) {
const postcssPlugin = {
postcssPlugin: 'postcss-resolve-url',
Declaration: (declaration) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code has been locking up E2E tests. The test eventually crashes Node with "out of memory" error.

Finally worked out from this migration guide that...

plugins will re-visit all changed or added nodes. You should check if your transformations were already applied and if that is the case—ignore those nodes.

So here the code needs to somehow keep track of visited declarations.

() => {
  postcssPlugin: 'postcss-resolve-url',
  prepare: () => {
    const visited = new Set();
    return {
      Declaration: (declaration) => {
        ...
      }
    };
  }
};

I will fix this and make some other tweaks post-merge.

var prefix,
isValid = declaration.value && (declaration.value.indexOf('url') >= 0);
if (isValid) {
Expand Down Expand Up @@ -105,6 +80,24 @@ function process(sourceFile, sourceContent, params) {
}
}

// prepend file protocol to all sources to avoid problems with source map
return postcss([
postcssPlugin
])
.process(correctedContent, {
from: fileProtocol.prepend(sourceFile),
map : params.outputSourceMap && {
prev : !!params.absSourceMap && fileProtocol.prepend(params.absSourceMap),
inline : false,
annotation : false,
sourcesContent: true // #98 sourcesContent missing from output map
}
})
.then(result => ({
content: result.css,
map : params.outputSourceMap ? fileProtocol.remove(result.map.toJSON()) : null
}));

/**
* Given an apparent position find the directory of the original file.
*
Expand Down
4 changes: 2 additions & 2 deletions packages/resolve-url-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"homepage": "https://github.com/bholloway/resolve-url-loader/tree/master/packages/resolve-url-loader",
"engines": {
"node": ">=8.9"
"node": "^10 || ^12 || >=14"
},
"files": [
"index.js",
Expand All @@ -38,7 +38,7 @@
"adjust-sourcemap-loader": "^4.0.0",
"convert-source-map": "^1.7.0",
"loader-utils": "^2.0.0",
"postcss": "^7.0.35",
"postcss": "^8.1.9",
"source-map": "0.6.1"
},
"peerDependencies": {
Expand Down
79 changes: 24 additions & 55 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ ansi-styles@^2.2.1:
resolved "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
integrity sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=

ansi-styles@^3.2.1:
version "3.2.1"
resolved "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
integrity sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==
dependencies:
color-convert "^1.9.0"

argparse@^1.0.7:
version "1.0.10"
resolved "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
Expand Down Expand Up @@ -130,15 +123,6 @@ chalk@^1.1.1:
strip-ansi "^3.0.0"
supports-color "^2.0.0"

chalk@^2.4.2:
version "2.4.2"
resolved "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==
dependencies:
ansi-styles "^3.2.1"
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"

cli@~1.0.0:
version "1.0.1"
resolved "https://registry.npmjs.org/cli/-/cli-1.0.1.tgz#22817534f24bfa4950c34d532d48ecbc621b8c14"
Expand All @@ -147,17 +131,10 @@ cli@~1.0.0:
exit "0.1.2"
glob "^7.1.1"

color-convert@^1.9.0:
version "1.9.3"
resolved "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8"
integrity sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==
dependencies:
color-name "1.1.3"

color-name@1.1.3:
version "1.1.3"
resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=
colorette@^1.2.1:
version "1.2.1"
resolved "https://registry.npmjs.org/colorette/-/colorette-1.2.1.tgz#4d0b921325c14faf92633086a536db6e89564b1b"
integrity sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw==

compose-function@^3.0.3:
version "3.0.3"
Expand Down Expand Up @@ -464,11 +441,6 @@ has-ansi@^2.0.0:
dependencies:
ansi-regex "^2.0.0"

has-flag@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
integrity sha1-tdRU3CGZriJWmfNGfloH87lVuv0=

has-flag@^4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b"
Expand Down Expand Up @@ -639,9 +611,9 @@ json5@^2.1.2:
minimist "^1.2.5"

just-extend@^4.0.2:
version "4.1.1"
resolved "https://registry.npmjs.org/just-extend/-/just-extend-4.1.1.tgz#158f1fdb01f128c411dc8b286a7b4837b3545282"
integrity sha512-aWgeGFW67BP3e5181Ep1Fv2v8z//iBJfrvyTnq8wG86vEESwmonn1zPBJ0VfmT9CJq2FIT0VsETtrNFm2a+SHA==
version "4.1.0"
resolved "https://registry.npmjs.org/just-extend/-/just-extend-4.1.0.tgz#7278a4027d889601640ee0ce0e5a00b992467da4"
integrity sha512-ApcjaOdVTJ7y4r08xI5wIqpvwS48Q0PBG4DJROcEkH1f8MdAiNFyFxz3xoL0LWAVwjrwPYZdVHHxhRHcx/uGLA==

loader-utils@^2.0.0:
version "2.0.0"
Expand Down Expand Up @@ -706,6 +678,11 @@ ms@^2.1.2:
resolved "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==

nanoid@^3.1.18:
version "3.1.18"
resolved "https://registry.npmjs.org/nanoid/-/nanoid-3.1.18.tgz#0680db22ab01c372e89209f5d18283d98de3e96d"
integrity sha512-rndlDjbbHbcV3xi+R2fpJ+PbGMdfBxz5v1fATIQFq0DP64FsicQdwnKLy47K4kZHdRpmQXtz24eGsxQqamzYTA==

nise@^3.0.1:
version "3.0.1"
resolved "https://registry.npmjs.org/nise/-/nise-3.0.1.tgz#0659982af515e5aac15592226246243e8da0013d"
Expand Down Expand Up @@ -818,14 +795,15 @@ plur@^1.0.0:
resolved "https://registry.npmjs.org/plur/-/plur-1.0.0.tgz#db85c6814f5e5e5a3b49efc28d604fec62975156"
integrity sha1-24XGgU9eXlo7Se/CjWBP7GKXUVY=

postcss@^7.0.35:
version "7.0.35"
resolved "https://registry.npmjs.org/postcss/-/postcss-7.0.35.tgz#d2be00b998f7f211d8a276974079f2e92b970e24"
integrity sha512-3QT8bBJeX/S5zKTTjTCIjRF3If4avAT6kqxcASlTWEtAFCb9NH0OUxNDfgZSWdP5fJnBYCMEWkIFfWeugjzYMg==
postcss@^8.1.9:
version "8.1.9"
resolved "https://registry.npmjs.org/postcss/-/postcss-8.1.9.tgz#20ff4b598a6f5015c5f7fe524b8ed5313d7ecade"
integrity sha512-oWuBpEl1meaMKkQXn0ic78TUrgsMvrAZLE/6ZY0H3LTteq2O3L8PGWwMbPLctpksTJIHjQeossMUMNQW7qRIHQ==
dependencies:
chalk "^2.4.2"
colorette "^1.2.1"
nanoid "^3.1.18"
source-map "^0.6.1"
supports-color "^6.1.0"
vfile-location "^3.2.0"

pretty-ms@^2.1.0:
version "2.1.0"
Expand Down Expand Up @@ -1053,20 +1031,6 @@ supports-color@^2.0.0:
resolved "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
integrity sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=

supports-color@^5.3.0:
version "5.5.0"
resolved "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"
integrity sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==
dependencies:
has-flag "^3.0.0"

supports-color@^6.1.0:
version "6.1.0"
resolved "https://registry.npmjs.org/supports-color/-/supports-color-6.1.0.tgz#0764abc69c63d5ac842dd4867e8d025e880df8f3"
integrity sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==
dependencies:
has-flag "^3.0.0"

supports-color@^7.1.0:
version "7.2.0"
resolved "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da"
Expand Down Expand Up @@ -1161,6 +1125,11 @@ util-deprecate@~1.0.1:
resolved "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=

vfile-location@^3.2.0:
version "3.2.0"
resolved "https://registry.npmjs.org/vfile-location/-/vfile-location-3.2.0.tgz#d8e41fbcbd406063669ebf6c33d56ae8721d0f3c"
integrity sha512-aLEIZKv/oxuCDZ8lkJGhuhztf/BW4M+iHdCwglA/eWc+vtuRFJj8EtgceYFX4LRjOhCAAiNHsKGssC6onJ+jbA==

vlq@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/vlq/-/vlq-1.0.1.tgz#c003f6e7c0b4c1edd623fd6ee50bbc0d6a1de468"
Expand Down