Skip to content

Commit

Permalink
refactor(jit): ♻️ update jit & patch
Browse files Browse the repository at this point in the history
  • Loading branch information
navin-moorthy committed Mar 31, 2021
1 parent f702e51 commit 4d86a65
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 40 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
"@storybook/addon-links": "^6.2.1",
"@storybook/addon-postcss": "^2.0.0",
"@storybook/react": "^6.2.1",
"@tailwindcss/jit": "^0.1.7",
"@testing-library/dom": "^7.30.2",
"@tailwindcss/jit": "^0.1.17",
"@testing-library/dom": "^7.30.3",
"@testing-library/jest-dom": "^5.11.10",
"@testing-library/react": "^11.2.6",
"@testing-library/react-hooks": "^5.1.1",
Expand Down Expand Up @@ -151,6 +151,9 @@
"react": "16.x || 17.x",
"react-dom": "16.x || 17.x"
},
"publishConfig": {
"access": "public"
},
"tsd": {
"directory": "src/theme"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/node_modules/@tailwindcss/jit/src/lib/generateRules.js b/node_modules/@tailwindcss/jit/src/lib/generateRules.js
index 7c98014..42a357f 100644
index fe48a0d..28abdf5 100644
--- a/node_modules/@tailwindcss/jit/src/lib/generateRules.js
+++ b/node_modules/@tailwindcss/jit/src/lib/generateRules.js
@@ -65,16 +65,21 @@ function applyPrefix(matches, context) {
@@ -94,12 +94,15 @@ function applyImportant(matches) {
// and `focus:hover:text-center` in the same project, but it doesn't feel
// worth the complexity for that case.

Expand All @@ -16,16 +16,10 @@ index 7c98014..42a357f 100644
+ let updateSort =
+ hasLibVariant &&
+ !['sm', 'md', 'lg', 'xl', '2xl', 'motion-safe', 'dark', 'motion-reduce'].includes(variant)
+
let [variantSort, applyThisVariant] = context.variantMap.get(variant)
let result = []

for (let [{ sort, layer, options }, rule] of matches) {
+
if (options.respectVariants === false) {
result.push([{ sort, layer, options }, rule])
continue
@@ -110,7 +115,10 @@ function applyVariant(variant, matches, context) {
@@ -139,7 +142,10 @@ function applyVariant(variant, matches, context) {
continue
}

Expand All @@ -37,15 +31,15 @@ index 7c98014..42a357f 100644
result.push(withOffset)
}

@@ -171,6 +179,7 @@ function sortAgainst(toSort, against) {
@@ -200,6 +206,7 @@ function sortAgainst(toSort, against) {
function* resolveMatches(candidate, context) {
let separator = context.tailwindConfig.separator
let [classCandidate, ...variants] = candidate.split(separator).reverse()
+ let hasLibVariant = variants.includes('lib')
let important = false

// Strip prefix
// md:hover:tw-bg-black
@@ -196,7 +205,14 @@ function* resolveMatches(candidate, context) {
if (classCandidate.startsWith('!')) {
@@ -231,7 +238,14 @@ function* resolveMatches(candidate, context) {
for (let ruleSet of [].concat(plugin(modifier, pluginHelpers))) {
let [rules, options] = parseRules(ruleSet, context.postCssNodeCache)
for (let rule of rules) {
Expand All @@ -61,24 +55,24 @@ index 7c98014..42a357f 100644
}
}
}
@@ -205,7 +221,14 @@ function* resolveMatches(candidate, context) {
@@ -240,7 +254,14 @@ function* resolveMatches(candidate, context) {
let ruleSet = plugin
let [rules, options] = parseRules(ruleSet, context.postCssNodeCache)
for (let rule of rules) {
- matches.push([{ ...sort, options: { ...sort.options, ...options } }, rule])
+ matches.push([
+ {
+ ...sort,
+ options: { ...sort.options, ...options },
+ sort: hasLibVariant ? 0n : sort.sort,
+ },
+ rule,
+ ])
+ {
+ ...sort,
+ options: { ...sort.options, ...options },
+ sort: hasLibVariant ? 0n : sort.sort,
+ },
+ rule,
+ ])
}
}
}
@@ -213,7 +236,7 @@ function* resolveMatches(candidate, context) {
matches = applyPrefix(matches, context)
@@ -252,7 +273,7 @@ function* resolveMatches(candidate, context) {
}

for (let variant of variants) {
- matches = applyVariant(variant, matches, context)
Expand All @@ -87,10 +81,10 @@ index 7c98014..42a357f 100644

for (let match of matches) {
diff --git a/node_modules/@tailwindcss/jit/src/lib/setupContext.js b/node_modules/@tailwindcss/jit/src/lib/setupContext.js
index c2a4133..68b3c9f 100644
index 65538d0..27c9c4b 100644
--- a/node_modules/@tailwindcss/jit/src/lib/setupContext.js
+++ b/node_modules/@tailwindcss/jit/src/lib/setupContext.js
@@ -559,10 +559,11 @@ function collectLayerPlugins(root) {
@@ -613,10 +613,11 @@ function collectLayerPlugins(root) {
function registerPlugins(tailwindConfig, plugins, context) {
let variantList = []
let variantMap = new Map()
Expand All @@ -105,7 +99,7 @@ index c2a4133..68b3c9f 100644
}

let pluginApi = buildPluginApi(tailwindConfig, context, {
@@ -586,7 +587,7 @@ function registerPlugins(tailwindConfig, plugins, context) {
@@ -640,7 +641,7 @@ function registerPlugins(tailwindConfig, plugins, context) {
offsets.components,
offsets.utilities,
])
Expand All @@ -114,7 +108,7 @@ index c2a4133..68b3c9f 100644

context.layerOrder = {
base: (1n << reservedBits) << 0n,
@@ -595,10 +596,10 @@ function registerPlugins(tailwindConfig, plugins, context) {
@@ -649,10 +650,10 @@ function registerPlugins(tailwindConfig, plugins, context) {
}

reservedBits += 3n
Expand All @@ -123,9 +117,9 @@ index c2a4133..68b3c9f 100644
- new Map()
- )
+ context.variantOrder = variantList.reduce((map, variant, i) => {
+ if (variant.includes('lib')) return map.set(variant, 1n)
+ return map.set(variant, (1n << BigInt(i)) << reservedBits)
+ }, new Map())
+ if (variant.includes('lib')) return map.set(variant, 1n)
+ return map.set(variant, (1n << BigInt(i)) << reservedBits)
+ }, new Map())

context.minimumScreen = [...context.variantOrder.values()].shift()

32 changes: 24 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2722,17 +2722,18 @@
dependencies:
defer-to-connect "^1.0.1"

"@tailwindcss/jit@^0.1.7":
version "0.1.7"
resolved "https://registry.yarnpkg.com/@tailwindcss/jit/-/jit-0.1.7.tgz#9916a53e13937346912285faaea05d151d12f1e2"
integrity sha512-v2TtFXvecPQ105ko2aaXp26VMtaBudpwB0039rxYy/yg6c34IX91HAmOEuotUwcwNvSW6I97YtzNg9ps3blr0A==
"@tailwindcss/jit@^0.1.17":
version "0.1.17"
resolved "https://registry.yarnpkg.com/@tailwindcss/jit/-/jit-0.1.17.tgz#0fe54a6bd9473c3c1a5cb622ba771d69117a3d49"
integrity sha512-Of3NbM2Peex6iPkOap5JBmAPq6oVjKEKMysy6iH/9Vl0TjuEuB094Uc7yzJz8q6j6AQEImlaOGxwF+sdBlG2pw==
dependencies:
chokidar "^3.5.1"
dlv "^1.1.3"
fast-glob "^3.2.5"
lodash.topath "^4.5.2"
normalize-path "^3.0.0"
object-hash "^2.1.1"
parse-glob "^3.0.4"
postcss-selector-parser "^6.0.4"
quick-lru "^5.1.1"

Expand All @@ -2750,10 +2751,10 @@
lz-string "^1.4.4"
pretty-format "^26.6.2"

"@testing-library/dom@^7.30.2":
version "7.30.2"
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-7.30.2.tgz#a63ae7078235ec6248a8a522b04e696ab49896cc"
integrity sha512-NJzHILb5De0J0varzT0W00qDTLcbF86etfAyx5ty7iJhpR6eCs+JR99Ls7AMSUG2bWRYIG0u4KTPH6PMcZhlWQ==
"@testing-library/dom@^7.30.3":
version "7.30.3"
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-7.30.3.tgz#779ea9bbb92d63302461800a388a5a890ac22519"
integrity sha512-7JhIg2MW6WPwyikH2iL3o7z+FTVgSOd2jqCwTAHqK7Qal2gRRYiUQyURAxtbK9VXm/UTyG9bRihv8C5Tznr2zw==
dependencies:
"@babel/code-frame" "^7.10.4"
"@babel/runtime" "^7.12.5"
Expand Down Expand Up @@ -8464,6 +8465,11 @@ is-dom@^1.0.0:
is-object "^1.0.1"
is-window "^1.0.2"

is-dotfile@^1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/is-dotfile/-/is-dotfile-1.0.3.tgz#a6a2f32ffd2dfb04f5ca25ecd0f6b83cf798a1e1"
integrity sha1-pqLzL/0t+wT1yiXs0Pa4PPeYoeE=

is-extendable@^0.1.0, is-extendable@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/is-extendable/-/is-extendable-0.1.1.tgz#62b110e289a471418e3ec36a617d472e301dfc89"
Expand Down Expand Up @@ -10940,6 +10946,16 @@ parse-github-repo-url@^1.3.0:
resolved "https://registry.yarnpkg.com/parse-github-repo-url/-/parse-github-repo-url-1.4.1.tgz#9e7d8bb252a6cb6ba42595060b7bf6df3dbc1f50"
integrity sha1-nn2LslKmy2ukJZUGC3v23z28H1A=

parse-glob@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/parse-glob/-/parse-glob-3.0.4.tgz#b2c376cfb11f35513badd173ef0bb6e3a388391c"
integrity sha1-ssN2z7EfNVE7rdFz7wu246OIORw=
dependencies:
glob-base "^0.3.0"
is-dotfile "^1.0.0"
is-extglob "^1.0.0"
is-glob "^2.0.0"

parse-json@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-2.2.0.tgz#f480f40434ef80741f8469099f8dea18f55a4dc9"
Expand Down

1 comment on commit 4d86a65

@vercel
Copy link

@vercel vercel bot commented on 4d86a65 Mar 31, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.