diff --git a/packages/postcss-linaria/src/stringify.ts b/packages/postcss-linaria/src/stringify.ts index 215e027ca..e0a5ba005 100644 --- a/packages/postcss-linaria/src/stringify.ts +++ b/packages/postcss-linaria/src/stringify.ts @@ -384,7 +384,11 @@ class LinariaStringifier extends Stringifier { ) { return node.raws.linariaBetween; } - return super.raw(node, own, detect); + // postcss 8.5 declares the result as `boolean | string`, 8.4 as `string`. + // At runtime it is a boolean for the `semicolon` raw that the inherited + // `body` reads, so `string` is only the signature that the calls in this + // class rely on. The base result is returned unchanged. + return super.raw(node, own, detect) as string; } /** @inheritdoc */ @@ -400,7 +404,10 @@ class LinariaStringifier extends Stringifier { return `${node.raws[linariaProp]}`; } - return super.rawValue(node, prop); + // postcss 8.5 declares the result as `number | string`, 8.4 as `string`. + // The base result is returned unchanged; the fields read through + // `rawValue` (`params`, `value` and `selector`) are strings. + return super.rawValue(node, prop) as string; } /** @inheritdoc */ diff --git a/packages/server/src/collect.ts b/packages/server/src/collect.ts index ef24619f8..aabcb4e9b 100644 --- a/packages/server/src/collect.ts +++ b/packages/server/src/collect.ts @@ -93,7 +93,7 @@ export default function collect( let removedNodesFromOther = 0; criticalRule.each((childRule: ChildNode, index: number) => { if (isCritical(childRule)) { - otherRule.nodes[index - removedNodesFromOther]?.remove(); + otherRule.nodes?.[index - removedNodesFromOther]?.remove(); removedNodesFromOther += 1; } else { childRule.remove(); @@ -102,10 +102,10 @@ export default function collect( rule.remove(); - if (criticalRule.nodes.length > 0) { + if (criticalRule.nodes?.length) { critical.append(criticalRule); } - if (otherRule.nodes.length > 0) { + if (otherRule.nodes?.length) { other.append(otherRule); } }; diff --git a/scripts/typecheck-postcss-8-5.sh b/scripts/typecheck-postcss-8-5.sh new file mode 100755 index 000000000..53c7e8962 --- /dev/null +++ b/scripts/typecheck-postcss-8-5.sh @@ -0,0 +1,56 @@ +#!/bin/sh +# Typechecks the workspace packages that use postcss (@linaria/server, +# @linaria/postcss-linaria and @linaria/atomic) against postcss 8.5.23. +# +# The committed manifests and lockfile still resolve postcss to 8.4.31, so the +# script swaps in the ones of the dependabot update to 8.5.23, installs with +# --ignore-scripts, runs `typecheck` of the three packages (`tsc --noEmit +# --composite false`, after the declarations of their dependencies are built) +# and puts the committed manifests, lockfile and install back on exit. +# +# Exit code: 0 when the packages typecheck, non-zero otherwise. +set -eu + +# The head of the dependabot pull request that updates postcss to 8.5.23. +update=05b0d4ca86d3cd33a46425ad124c6308be3531e0 +files="pnpm-lock.yaml packages/atomic/package.json packages/postcss-linaria/package.json packages/server/package.json" + +cd "$(dirname "$0")/.." + +git cat-file -e "$update^{commit}" || { + echo "commit $update is not in this repository" >&2 + exit 2 +} + +# Plain output: the failure signature is matched against it. +export NO_COLOR=1 FORCE_COLOR=0 + +backup=$(mktemp -d) + +restore() { + status=$? + trap - EXIT + for file in $files; do + cp "$backup/$(echo "$file" | tr / _)" "$file" + done + rm -rf "$backup" + pnpm install --frozen-lockfile --ignore-scripts >/dev/null 2>&1 || true + exit "$status" +} +trap restore EXIT + +for file in $files; do + cp "$file" "$backup/$(echo "$file" | tr / _)" + git show "$update:$file" >"$file" +done + +pnpm install --frozen-lockfile --ignore-scripts + +pnpm --filter ./packages/atomic --filter ./packages/postcss-linaria --filter ./packages/server list postcss --depth 0 + +# --continue: report the errors of every package, not only of the first one +# that fails. +pnpm exec turbo run typecheck --force --continue \ + --filter=@linaria/atomic \ + --filter=@linaria/postcss-linaria \ + --filter=@linaria/server