Skip to content

Commit ea12123

Browse files
committed
chore: tailwindcss patch add 3.3.3 case
1 parent 9dec484 commit ea12123

File tree

8 files changed

+199
-23
lines changed

8 files changed

+199
-23
lines changed

.vscode/launch.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7+
{
8+
"command": "yarn patch",
9+
"name": "do tailwindcss-patch",
10+
"request": "launch",
11+
"type": "node-terminal",
12+
"cwd": "${workspaceFolder}/packages/tailwindcss-patch"
13+
},
714
{
815
"command": "npm run build",
916
"name": "Debug nuxt-app",

packages/tailwindcss-patch/src/patcher.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ export function monkeyPatchForExposingContext(twDir: string, opt: InternalPatchO
8080
return result
8181
}
8282

83+
8384
export function internalPatch(pkgJsonPath: string | undefined, options: InternalPatchOptions): any | undefined {
8485
if (pkgJsonPath) {
8586
const pkgJson = require(pkgJsonPath) as PackageJson
8687
const twDir = path.dirname(pkgJsonPath)
8788
if (gte(pkgJson.version!, '3.0.0')) {
89+
options.version = pkgJson.version
8890
const result = monkeyPatchForExposingContext(twDir, options)
8991
return result
9092
}

packages/tailwindcss-patch/src/type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface InternalPatchOptions {
2222
paths?: string[]
2323
basedir?: string
2424
custom?: (dir: string, ctx: Record<string, any>) => void
25+
version?: string
2526
}
2627

2728
export interface TailwindcssPatcherOptions {

packages/tailwindcss-patch/test/__snapshots__/index.test.ts.snap

Lines changed: 168 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = function tailwindcss(configOrPath) {
2626
console.log("\\n");
2727
console.time("JIT TOTAL");
2828
return root;
29-
}, function (root, result) {
29+
}, async function (root, result) {
3030
contextRef.value.length = 0;
3131
var _findAtConfigPath1;
3232
// Use the path for the \`@config\` directive if it exists, otherwise use the
@@ -37,12 +37,12 @@ module.exports = function tailwindcss(configOrPath) {
3737
let roots = root.nodes.filter(node => node.type === "root");
3838
for (const root of roots) {
3939
if (root.type === "root") {
40-
contextRef.value.push((0, _processTailwindFeatures.default)(context)(root, result));
40+
contextRef.value.push(await (0, _processTailwindFeatures.default)(context)(root, result));
4141
}
4242
}
4343
return;
4444
}
45-
contextRef.value.push((0, _processTailwindFeatures.default)(context)(root, result));
45+
contextRef.value.push(await (0, _processTailwindFeatures.default)(context)(root, result));
4646
}, false && function lightningCssPlugin(_root, result) {
4747
let postcss = require("postcss");
4848
let lightningcss = require("lightningcss");
@@ -120,7 +120,7 @@ function _interop_require_default(obj) {
120120
};
121121
}
122122
function processTailwindFeatures(setupContext) {
123-
return function (root, result) {
123+
return async function (root, result) {
124124
let {
125125
tailwindDirectives,
126126
applyDirectives
@@ -147,7 +147,7 @@ function processTailwindFeatures(setupContext) {
147147
throw new Error("The '-' character cannot be used as a custom separator in JIT mode due to parsing ambiguity. Please use another character like '_' instead.");
148148
}
149149
(0, _featureFlags.issueFlagNotices)(context.tailwindConfig);
150-
(0, _expandTailwindAtRules.default)(context)(root, result);
150+
await (0, _expandTailwindAtRules.default)(context)(root, result);
151151
// Partition apply rules that are generated by
152152
// addComponents, addUtilities and so on.
153153
(0, _partitionApplyAtRules.default)()(root, result);
@@ -1549,3 +1549,166 @@ function processTailwindFeatures(setupContext) {
15491549
}",
15501550
}
15511551
`;
1552+
1553+
exports[`versions-patch patch tailwindcss3.3.3 1`] = `
1554+
{
1555+
"plugin": ""use strict";
1556+
1557+
Object.defineProperty(exports, "__esModule", {
1558+
value: true
1559+
});
1560+
const _setupTrackingContext = /*#__PURE__*/_interop_require_default(require("./lib/setupTrackingContext"));
1561+
const _processTailwindFeatures = /*#__PURE__*/_interop_require_default(require("./processTailwindFeatures"));
1562+
const _sharedState = require("./lib/sharedState");
1563+
const _findAtConfigPath = require("./lib/findAtConfigPath");
1564+
function _interop_require_default(obj) {
1565+
return obj && obj.__esModule ? obj : {
1566+
default: obj
1567+
};
1568+
}
1569+
const contextRef = {
1570+
value: []
1571+
};
1572+
module.exports = function tailwindcss(configOrPath) {
1573+
return {
1574+
postcssPlugin: "tailwindcss",
1575+
plugins: [_sharedState.env.DEBUG && function (root) {
1576+
console.log("\\n");
1577+
console.time("JIT TOTAL");
1578+
return root;
1579+
}, async function (root, result) {
1580+
contextRef.value.length = 0;
1581+
var _findAtConfigPath1;
1582+
// Use the path for the \`@config\` directive if it exists, otherwise use the
1583+
// path for the file being processed
1584+
configOrPath = (_findAtConfigPath1 = (0, _findAtConfigPath.findAtConfigPath)(root, result)) !== null && _findAtConfigPath1 !== void 0 ? _findAtConfigPath1 : configOrPath;
1585+
let context = (0, _setupTrackingContext.default)(configOrPath);
1586+
if (root.type === "document") {
1587+
let roots = root.nodes.filter(node => node.type === "root");
1588+
for (const root of roots) {
1589+
if (root.type === "root") {
1590+
contextRef.value.push(await (0, _processTailwindFeatures.default)(context)(root, result));
1591+
}
1592+
}
1593+
return;
1594+
}
1595+
contextRef.value.push(await (0, _processTailwindFeatures.default)(context)(root, result));
1596+
}, false && function lightningCssPlugin(_root, result) {
1597+
let postcss = require("postcss");
1598+
let lightningcss = require("lightningcss");
1599+
let browserslist = require("browserslist");
1600+
try {
1601+
let transformed = lightningcss.transform({
1602+
filename: result.opts.from,
1603+
code: Buffer.from(result.root.toString()),
1604+
minify: false,
1605+
sourceMap: !!result.map,
1606+
inputSourceMap: result.map ? result.map.toString() : undefined,
1607+
targets: typeof process !== "undefined" && process.env.JEST_WORKER_ID ? {
1608+
chrome: 106 << 16
1609+
} : lightningcss.browserslistToTargets(browserslist(require("../package.json").browserslist)),
1610+
drafts: {
1611+
nesting: true,
1612+
customMedia: true
1613+
}
1614+
});
1615+
var _result_map;
1616+
result.map = Object.assign((_result_map = result.map) !== null && _result_map !== void 0 ? _result_map : {}, {
1617+
toJSON() {
1618+
return transformed.map.toJSON();
1619+
},
1620+
toString() {
1621+
return transformed.map.toString();
1622+
}
1623+
});
1624+
result.root = postcss.parse(transformed.code.toString("utf8"));
1625+
} catch (err) {
1626+
if (typeof process !== "undefined" && process.env.JEST_WORKER_ID) {
1627+
let lines = err.source.split("\\n");
1628+
err = new Error(["Error formatting using Lightning CSS:", "", ...["\`\`\`css", ...lines.slice(Math.max(err.loc.line - 3, 0), err.loc.line), " ".repeat(err.loc.column - 1) + "^-- " + err.toString(), ...lines.slice(err.loc.line, err.loc.line + 2), "\`\`\`"]].join("\\n"));
1629+
}
1630+
if (Error.captureStackTrace) {
1631+
Error.captureStackTrace(err, lightningCssPlugin);
1632+
}
1633+
throw err;
1634+
}
1635+
}, _sharedState.env.DEBUG && function (root) {
1636+
console.timeEnd("JIT TOTAL");
1637+
console.log("\\n");
1638+
return root;
1639+
}].filter(Boolean)
1640+
};
1641+
};
1642+
module.exports.postcss = true;
1643+
module.exports.contextRef = contextRef;",
1644+
"processTailwindFeatures": ""use strict";
1645+
1646+
Object.defineProperty(exports, "__esModule", {
1647+
value: true
1648+
});
1649+
Object.defineProperty(exports, "default", {
1650+
enumerable: true,
1651+
get: function () {
1652+
return processTailwindFeatures;
1653+
}
1654+
});
1655+
const _normalizeTailwindDirectives = /*#__PURE__*/_interop_require_default(require("./lib/normalizeTailwindDirectives"));
1656+
const _expandTailwindAtRules = /*#__PURE__*/_interop_require_default(require("./lib/expandTailwindAtRules"));
1657+
const _expandApplyAtRules = /*#__PURE__*/_interop_require_default(require("./lib/expandApplyAtRules"));
1658+
const _evaluateTailwindFunctions = /*#__PURE__*/_interop_require_default(require("./lib/evaluateTailwindFunctions"));
1659+
const _substituteScreenAtRules = /*#__PURE__*/_interop_require_default(require("./lib/substituteScreenAtRules"));
1660+
const _resolveDefaultsAtRules = /*#__PURE__*/_interop_require_default(require("./lib/resolveDefaultsAtRules"));
1661+
const _collapseAdjacentRules = /*#__PURE__*/_interop_require_default(require("./lib/collapseAdjacentRules"));
1662+
const _collapseDuplicateDeclarations = /*#__PURE__*/_interop_require_default(require("./lib/collapseDuplicateDeclarations"));
1663+
const _partitionApplyAtRules = /*#__PURE__*/_interop_require_default(require("./lib/partitionApplyAtRules"));
1664+
const _detectNesting = /*#__PURE__*/_interop_require_default(require("./lib/detectNesting"));
1665+
const _setupContextUtils = require("./lib/setupContextUtils");
1666+
const _featureFlags = require("./featureFlags");
1667+
function _interop_require_default(obj) {
1668+
return obj && obj.__esModule ? obj : {
1669+
default: obj
1670+
};
1671+
}
1672+
function processTailwindFeatures(setupContext) {
1673+
return async function (root, result) {
1674+
let {
1675+
tailwindDirectives,
1676+
applyDirectives
1677+
} = (0, _normalizeTailwindDirectives.default)(root);
1678+
(0, _detectNesting.default)()(root, result);
1679+
// Partition apply rules that are found in the css
1680+
// itself.
1681+
(0, _partitionApplyAtRules.default)()(root, result);
1682+
let context = setupContext({
1683+
tailwindDirectives,
1684+
applyDirectives,
1685+
registerDependency(dependency) {
1686+
result.messages.push({
1687+
plugin: "tailwindcss",
1688+
parent: result.opts.from,
1689+
...dependency
1690+
});
1691+
},
1692+
createContext(tailwindConfig, changedContent) {
1693+
return (0, _setupContextUtils.createContext)(tailwindConfig, changedContent, root);
1694+
}
1695+
})(root, result);
1696+
if (context.tailwindConfig.separator === "-") {
1697+
throw new Error("The '-' character cannot be used as a custom separator in JIT mode due to parsing ambiguity. Please use another character like '_' instead.");
1698+
}
1699+
(0, _featureFlags.issueFlagNotices)(context.tailwindConfig);
1700+
await (0, _expandTailwindAtRules.default)(context)(root, result);
1701+
// Partition apply rules that are generated by
1702+
// addComponents, addUtilities and so on.
1703+
(0, _partitionApplyAtRules.default)()(root, result);
1704+
(0, _expandApplyAtRules.default)(context)(root, result);
1705+
(0, _evaluateTailwindFunctions.default)(context)(root, result);
1706+
(0, _substituteScreenAtRules.default)(context)(root, result);
1707+
(0, _resolveDefaultsAtRules.default)(context)(root, result);
1708+
(0, _collapseAdjacentRules.default)(context)(root, result);
1709+
(0, _collapseDuplicateDeclarations.default)(context)(root, result);
1710+
return context;
1711+
};
1712+
}",
1713+
}
1714+
`;

packages/tailwindcss-patch/test/cache.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('cache', () => {
5858
expect(fs.existsSync(filepath)).toBe(false)
5959
})
6060

61-
it('multiple tw context merge cache', () => {
61+
it('multiple tw context merge cache', async () => {
6262
const dir = path.resolve(__dirname, './fixtures/cache')
6363
const twPatcher = new TailwindcssPatcher({
6464
cache: {
@@ -67,7 +67,7 @@ describe('cache', () => {
6767
}
6868
})
6969
twPatcher.setCache(new Set())
70-
getCss(['text-[100px]'])
70+
await getCss(['text-[100px]'])
7171
let ctxs = twPatcher.getContexts()
7272
expect(ctxs.length).toBe(1)
7373
let set = twPatcher.getClassSet()
@@ -77,7 +77,7 @@ describe('cache', () => {
7777

7878
// 2 times
7979
// 不累加
80-
getCss(['text-[99px]'])
80+
await getCss(['text-[99px]'])
8181
ctxs = twPatcher.getContexts()
8282
expect(ctxs.length).toBe(1)
8383
set = twPatcher.getClassSet()

packages/tailwindcss-patch/test/class.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ import { TailwindcssPatcher } from '../src/class'
22
import path from 'node:path'
33
import { getCss, getTestCase } from './utils'
44
describe('class', () => {
5-
it('default', () => {
5+
it('default', async () => {
66
// const dir = path.resolve(__dirname, './fixtures/cache')
77
const twPatcher = new TailwindcssPatcher()
88
expect(twPatcher.cacheOptions.enable).toBe(false)
99
twPatcher.patch()
10-
getCss([getTestCase('hello-world.html')])
10+
await getCss([getTestCase('hello-world.html')])
1111
const ctxs = twPatcher.getContexts()
1212
expect(ctxs.length).toBe(1)
1313
const set = twPatcher.getClassSet()
1414
expect(set.size).toBeGreaterThan(0)
1515
expect(set.size).toBe(4)
1616
})
1717

18-
it('cache option', () => {
18+
it('cache option', async () => {
1919
const dir = path.resolve(__dirname, './fixtures/cache')
2020
const twPatcher = new TailwindcssPatcher({
2121
cache: {
@@ -28,7 +28,7 @@ describe('class', () => {
2828
const p = twPatcher.setCache(new Set(['*', 'bg-[#123456]', 'font-bold', 'text-3xl', 'underline']))
2929
expect(p).toBe(path.resolve(dir, 'index.json'))
3030
twPatcher.patch()
31-
getCss([getTestCase('hello-world.html'), getTestCase('hello-world.js')])
31+
await getCss([getTestCase('hello-world.html'), getTestCase('hello-world.js')])
3232
const ctxs = twPatcher.getContexts()
3333
expect(ctxs.length).toBe(1)
3434
const set = twPatcher.getClassSet({
@@ -38,9 +38,9 @@ describe('class', () => {
3838
expect(set.size).toBe(5)
3939
})
4040

41-
it('multiple time process sources', () => {
41+
it('multiple time process sources', async () => {
4242
const twPatcher = new TailwindcssPatcher()
43-
getCss(['text-[100px]'])
43+
await getCss(['text-[100px]'])
4444
let ctxs = twPatcher.getContexts()
4545
expect(ctxs.length).toBe(1)
4646
let set = twPatcher.getClassSet()
@@ -50,7 +50,7 @@ describe('class', () => {
5050

5151
// 2 times
5252
// 不累加
53-
getCss(['text-[99px]'])
53+
await getCss(['text-[99px]'])
5454
ctxs = twPatcher.getContexts()
5555
expect(ctxs.length).toBe(1)
5656
set = twPatcher.getClassSet()

packages/tailwindcss-patch/test/context.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { getContexts, getClassCacheSet } from '../src'
22
import { getCss, getTestCase } from './utils'
33
describe('common usage', () => {
4-
it('hello-world', () => {
5-
const result = getCss(getTestCase('hello-world.html'))
4+
it('hello-world', async () => {
5+
const result = await getCss(getTestCase('hello-world.html'))
66
const ctxs = getContexts()
77
expect(ctxs.length).toBeTruthy()
88
const set = getClassCacheSet()
@@ -11,8 +11,8 @@ describe('common usage', () => {
1111
expect(result).toMatchSnapshot()
1212
})
1313

14-
it('hello-world with js', () => {
15-
const result = getCss([getTestCase('hello-world.html'), getTestCase('hello-world.js')])
14+
it('hello-world with js', async () => {
15+
const result = await getCss([getTestCase('hello-world.html'), getTestCase('hello-world.js')])
1616
const ctxs = getContexts()
1717
expect(ctxs.length).toBeTruthy()
1818
const set = getClassCacheSet()
@@ -22,8 +22,8 @@ describe('common usage', () => {
2222
})
2323

2424
// https://github.com/sonofmagic/weapp-tailwindcss-webpack-plugin/issues/158
25-
it("bg-[url('img_src')] lose efficacy", () => {
26-
getCss([getTestCase('img-url.jsx')])
25+
it("bg-[url('img_src')] lose efficacy", async () => {
26+
await getCss([getTestCase('img-url.jsx')])
2727
const ctxs = getContexts()
2828
expect(ctxs).toBeTruthy()
2929
const set = getClassCacheSet()
@@ -33,8 +33,8 @@ describe('common usage', () => {
3333
//
3434
})
3535

36-
it('trailing slash', () => {
37-
getCss([getTestCase('trailing-slash.vue')])
36+
it('trailing slash', async () => {
37+
await getCss([getTestCase('trailing-slash.vue')])
3838
const ctxs = getContexts()
3939
expect(ctxs).toBeTruthy()
4040
const set = getClassCacheSet()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# tailwindcss-versions
2+
3+
yarn add tailwindcss

0 commit comments

Comments
 (0)