tailwindcss-patch 0.0.1 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -6
- package/dist/cli.js +2 -1
- package/dist/index.js +11 -3
- package/dist/{patcher-e9a851ca.js → patcher-7787d13f.js} +27 -20
- package/dist/types/exposeContext.d.ts +2 -1
- package/dist/types/type.d.ts +2 -0
- package/dist/types/utils.d.ts +2 -0
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -22,19 +22,27 @@ npx tw-patch
|
|
|
22
22
|
|
|
23
23
|
```json
|
|
24
24
|
{
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
/* ... */
|
|
26
|
+
"scripts": {
|
|
27
|
+
"prepare": "tw-patch"
|
|
28
|
+
}
|
|
29
29
|
}
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
## Usage
|
|
33
33
|
|
|
34
34
|
```js
|
|
35
|
-
import { getContexts
|
|
35
|
+
import { getContexts, getClassCacheSet } from 'tailwindcss-patch'
|
|
36
36
|
// get all contexts at runtime
|
|
37
|
-
getContexts()
|
|
37
|
+
getContexts()
|
|
38
38
|
// get all class generated by tailwindcss utilities
|
|
39
39
|
getClassCacheSet()
|
|
40
40
|
```
|
|
41
|
+
|
|
42
|
+
## Notice
|
|
43
|
+
|
|
44
|
+
`getContexts`,`getClassCacheSet` should be invoked after `postcss-loader`'s activation.
|
|
45
|
+
|
|
46
|
+
which means you may not get tailwindcss contexts at build start time.
|
|
47
|
+
|
|
48
|
+
you may call them at `generateBundle` lifetime hook in `vite/webpack plugin`.
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var patcher = require('./patcher-
|
|
3
|
+
var patcher = require('./patcher-7787d13f.js');
|
|
4
4
|
require('path');
|
|
5
5
|
require('fs');
|
|
6
6
|
require('semver');
|
|
@@ -8,6 +8,7 @@ require('@babel/types');
|
|
|
8
8
|
require('@babel/generator');
|
|
9
9
|
require('@babel/parser');
|
|
10
10
|
require('@babel/traverse');
|
|
11
|
+
require('resolve');
|
|
11
12
|
|
|
12
13
|
const patch = patcher.createPatch({});
|
|
13
14
|
patch();
|
package/dist/index.js
CHANGED
|
@@ -4,20 +4,27 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var path = require('path');
|
|
6
6
|
var fs = require('fs');
|
|
7
|
-
var patcher = require('./patcher-
|
|
7
|
+
var patcher = require('./patcher-7787d13f.js');
|
|
8
8
|
require('semver');
|
|
9
9
|
require('@babel/types');
|
|
10
10
|
require('@babel/generator');
|
|
11
11
|
require('@babel/parser');
|
|
12
12
|
require('@babel/traverse');
|
|
13
|
+
require('resolve');
|
|
13
14
|
|
|
14
15
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
16
|
|
|
16
17
|
var path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
17
18
|
var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
18
19
|
|
|
19
|
-
function
|
|
20
|
-
|
|
20
|
+
function getTailwindcssEntry(basedir = process.cwd()) {
|
|
21
|
+
return patcher.requireResolve('tailwindcss', {
|
|
22
|
+
basedir
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function getContexts(basedir) {
|
|
26
|
+
const twPath = getTailwindcssEntry(basedir);
|
|
27
|
+
const distPath = path__default["default"].dirname(twPath);
|
|
21
28
|
let injectFilePath = path__default["default"].join(distPath, 'plugin.js');
|
|
22
29
|
if (!fs__default["default"].existsSync(injectFilePath)) {
|
|
23
30
|
injectFilePath = path__default["default"].join(distPath, 'index.js');
|
|
@@ -54,3 +61,4 @@ exports.monkeyPatchForExposingContext = patcher.monkeyPatchForExposingContext;
|
|
|
54
61
|
exports.getClassCacheSet = getClassCacheSet;
|
|
55
62
|
exports.getClassCaches = getClassCaches;
|
|
56
63
|
exports.getContexts = getContexts;
|
|
64
|
+
exports.getTailwindcssEntry = getTailwindcssEntry;
|
|
@@ -7,6 +7,7 @@ var t = require('@babel/types');
|
|
|
7
7
|
var generate = require('@babel/generator');
|
|
8
8
|
var parser = require('@babel/parser');
|
|
9
9
|
var traverse = require('@babel/traverse');
|
|
10
|
+
var resolve = require('resolve');
|
|
10
11
|
|
|
11
12
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
13
|
|
|
@@ -34,6 +35,26 @@ var t__namespace = /*#__PURE__*/_interopNamespaceCompat(t);
|
|
|
34
35
|
var generate__default = /*#__PURE__*/_interopDefaultCompat(generate);
|
|
35
36
|
var traverse__default = /*#__PURE__*/_interopDefaultCompat(traverse);
|
|
36
37
|
|
|
38
|
+
function ensureFileContent(filepaths) {
|
|
39
|
+
if (typeof filepaths === 'string') {
|
|
40
|
+
filepaths = [filepaths];
|
|
41
|
+
}
|
|
42
|
+
let content;
|
|
43
|
+
for (let i = 0; i < filepaths.length; i++) {
|
|
44
|
+
const filepath = filepaths[i];
|
|
45
|
+
if (fs__default["default"].existsSync(filepath)) {
|
|
46
|
+
content = fs__default["default"].readFileSync(filepath, {
|
|
47
|
+
encoding: 'utf-8'
|
|
48
|
+
});
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return content;
|
|
53
|
+
}
|
|
54
|
+
function requireResolve(id, opts) {
|
|
55
|
+
return resolve.sync(id, opts);
|
|
56
|
+
}
|
|
57
|
+
|
|
37
58
|
function inspectProcessTailwindFeaturesReturnContext(content) {
|
|
38
59
|
const ast = parser.parse(content);
|
|
39
60
|
let hasPatched = false;
|
|
@@ -204,27 +225,12 @@ const defaultOptions = {
|
|
|
204
225
|
overwrite: true
|
|
205
226
|
};
|
|
206
227
|
|
|
207
|
-
function ensureFileContent(filepaths) {
|
|
208
|
-
if (typeof filepaths === 'string') {
|
|
209
|
-
filepaths = [filepaths];
|
|
210
|
-
}
|
|
211
|
-
let content;
|
|
212
|
-
for (let i = 0; i < filepaths.length; i++) {
|
|
213
|
-
const filepath = filepaths[i];
|
|
214
|
-
if (fs__default["default"].existsSync(filepath)) {
|
|
215
|
-
content = fs__default["default"].readFileSync(filepath, {
|
|
216
|
-
encoding: 'utf-8'
|
|
217
|
-
});
|
|
218
|
-
break;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return content;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
228
|
function getInstalledPkgJsonPath(options) {
|
|
229
|
+
var _a;
|
|
225
230
|
try {
|
|
226
|
-
const tmpJsonPath =
|
|
227
|
-
paths: options.paths
|
|
231
|
+
const tmpJsonPath = requireResolve(`tailwindcss/package.json`, {
|
|
232
|
+
paths: options.paths,
|
|
233
|
+
basedir: (_a = options.basedir) !== null && _a !== void 0 ? _a : process.cwd()
|
|
228
234
|
});
|
|
229
235
|
const pkgJson = require(tmpJsonPath);
|
|
230
236
|
if (semver.gte(pkgJson.version, '3.0.0')) {
|
|
@@ -233,7 +239,7 @@ function getInstalledPkgJsonPath(options) {
|
|
|
233
239
|
}
|
|
234
240
|
catch (error) {
|
|
235
241
|
if (error.code === 'MODULE_NOT_FOUND') {
|
|
236
|
-
console.warn('
|
|
242
|
+
console.warn('Can\'t find npm pkg: `tailwindcss`, Please ensure it has been installed!');
|
|
237
243
|
}
|
|
238
244
|
}
|
|
239
245
|
}
|
|
@@ -291,3 +297,4 @@ exports.inspectPostcssPlugin = inspectPostcssPlugin;
|
|
|
291
297
|
exports.inspectProcessTailwindFeaturesReturnContext = inspectProcessTailwindFeaturesReturnContext;
|
|
292
298
|
exports.internalPatch = internalPatch;
|
|
293
299
|
exports.monkeyPatchForExposingContext = monkeyPatchForExposingContext;
|
|
300
|
+
exports.requireResolve = requireResolve;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Rule } from 'postcss';
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function getTailwindcssEntry(basedir?: string): string;
|
|
3
|
+
export declare function getContexts(basedir?: string): any[];
|
|
3
4
|
export declare function getClassCaches(): Map<string, ({
|
|
4
5
|
layer: string;
|
|
5
6
|
options: Record<string, any>;
|
package/dist/types/type.d.ts
CHANGED
package/dist/types/utils.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwindcss-patch",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "patch tailwindcss for exposing context",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/babel__generator": "^7.6.4",
|
|
27
27
|
"@types/babel__traverse": "^7.18.3",
|
|
28
|
+
"@types/resolve": "^1.20.2",
|
|
28
29
|
"@types/semver": "^7.3.13",
|
|
29
30
|
"defu": "^6.1.2",
|
|
30
31
|
"pkg-types": "^1.0.2",
|
|
@@ -36,14 +37,20 @@
|
|
|
36
37
|
"@babel/parser": "^7.21.4",
|
|
37
38
|
"@babel/traverse": "^7.21.4",
|
|
38
39
|
"@babel/types": "^7.21.4",
|
|
39
|
-
"
|
|
40
|
+
"resolve": "^1.22.2",
|
|
41
|
+
"semver": "^7.4.0"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/sonofmagic/tailwindcss-mangle",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/sonofmagic/tailwindcss-mangle.git"
|
|
40
47
|
},
|
|
41
48
|
"scripts": {
|
|
42
49
|
"dev": "cross-env NODE_ENV=development rollup -cw",
|
|
43
50
|
"build": "cross-env NODE_ENV=production rollup -c",
|
|
44
51
|
"dev:tsc": "tsc -p tsconfig.json --sourceMap",
|
|
45
52
|
"build:tsc": "tsc -p tsconfig.json",
|
|
46
|
-
"test": "jest",
|
|
53
|
+
"test": "npm run patch && jest",
|
|
47
54
|
"postinstall": "echo postinstall",
|
|
48
55
|
"preinstall": "npx only-allow pnpm",
|
|
49
56
|
"patch": "ts-node src/cli.ts"
|