tailwindcss-patch 1.2.7 → 2.0.0
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 +63 -6
- package/bin/tw-patch.js +3 -3
- package/dist/cli.cjs +115 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.mjs +107 -0
- package/dist/index.cjs +554 -0
- package/dist/index.d.ts +165 -0
- package/dist/index.mjs +519 -0
- package/package.json +34 -11
- package/dist/cli.js +0 -15
- package/dist/index.js +0 -191
- package/dist/patcher-a07f477f.js +0 -302
- package/dist/types/babel.d.ts +0 -3
- package/dist/types/cache.d.ts +0 -7
- package/dist/types/class.d.ts +0 -17
- package/dist/types/cli.d.ts +0 -1
- package/dist/types/constants.d.ts +0 -1
- package/dist/types/defaults.d.ts +0 -2
- package/dist/types/exposeContext.d.ts +0 -5
- package/dist/types/index.d.ts +0 -6
- package/dist/types/inspector.d.ts +0 -8
- package/dist/types/logger.d.ts +0 -1
- package/dist/types/patcher.d.ts +0 -9
- package/dist/types/type.d.ts +0 -72
- package/dist/types/utils.d.ts +0 -3
package/README.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
# tailwindcss-patch
|
|
2
2
|
|
|
3
|
-
get tailwindcss context at runtime!
|
|
3
|
+
get tailwindcss context at runtime ! extract all class to json file!
|
|
4
|
+
|
|
5
|
+
- [tailwindcss-patch](#tailwindcss-patch)
|
|
6
|
+
- [Setup](#setup)
|
|
7
|
+
- [Usage](#usage)
|
|
8
|
+
- [Cli](#cli)
|
|
9
|
+
- [Init Config File](#init-config-file)
|
|
10
|
+
- [Extract all class into a json](#extract-all-class-into-a-json)
|
|
11
|
+
- [Nodejs](#nodejs)
|
|
12
|
+
- [Migration form v1 to v2](#migration-form-v1-to-v2)
|
|
13
|
+
- [2. cli command change](#2-cli-command-change)
|
|
14
|
+
- [1. default remove `*` in json array result](#1-default-remove--in-json-array-result)
|
|
15
|
+
- [Notice](#notice)
|
|
4
16
|
|
|
5
17
|
## Setup
|
|
6
18
|
|
|
@@ -13,7 +25,7 @@ get tailwindcss context at runtime!
|
|
|
13
25
|
2. Patch tailwindcss
|
|
14
26
|
|
|
15
27
|
```sh
|
|
16
|
-
npx tw-patch
|
|
28
|
+
npx tw-patch install
|
|
17
29
|
```
|
|
18
30
|
|
|
19
31
|
3. Add `prepare` script (keeps patch persisted after npm install)
|
|
@@ -24,19 +36,64 @@ npx tw-patch
|
|
|
24
36
|
{
|
|
25
37
|
/* ... */
|
|
26
38
|
"scripts": {
|
|
27
|
-
"prepare": "tw-patch"
|
|
39
|
+
"prepare": "tw-patch install"
|
|
28
40
|
}
|
|
29
41
|
}
|
|
30
42
|
```
|
|
31
43
|
|
|
32
44
|
## Usage
|
|
33
45
|
|
|
46
|
+
## Cli
|
|
47
|
+
|
|
48
|
+
### Init Config File
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
tw-patch init
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Then there will be a ts file called `tailwindcss-patch.config.ts` exist in your `cwd`.
|
|
55
|
+
|
|
56
|
+
### Extract all class into a json
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
tw-patch extract
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
default there will be a json in `.tw-patch/tw-class-list.json` in your project.
|
|
63
|
+
|
|
64
|
+
you can custom this behavior by config `tailwindcss-patch.config.ts`
|
|
65
|
+
|
|
66
|
+
### Nodejs
|
|
67
|
+
|
|
34
68
|
```js
|
|
35
|
-
import {
|
|
69
|
+
import { TailwindcssPatcher } from 'tailwindcss-patch'
|
|
70
|
+
|
|
71
|
+
const twPatcher = new TailwindcssPatcher(/* options */)
|
|
36
72
|
// get all contexts at runtime
|
|
37
|
-
getContexts()
|
|
73
|
+
twPatcher.getContexts()
|
|
38
74
|
// get all class generated by tailwindcss utilities
|
|
39
|
-
|
|
75
|
+
twPatcher.getClassSet()
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Migration form v1 to v2
|
|
79
|
+
|
|
80
|
+
### 2. cli command change
|
|
81
|
+
|
|
82
|
+
```diff
|
|
83
|
+
{
|
|
84
|
+
- "tw-patch"
|
|
85
|
+
+ "tw-patch install"
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 1. default remove `*` in json array result
|
|
90
|
+
|
|
91
|
+
```diff
|
|
92
|
+
[
|
|
93
|
+
- "*",
|
|
94
|
+
"text-[99px]",
|
|
95
|
+
"text-[100px]"
|
|
96
|
+
]
|
|
40
97
|
```
|
|
41
98
|
|
|
42
99
|
## Notice
|
package/bin/tw-patch.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const fs = require('fs')
|
|
3
|
-
const path = require('path')
|
|
4
|
-
const cliPath = path.resolve(__dirname, '../dist/cli.
|
|
2
|
+
const fs = require('node:fs')
|
|
3
|
+
const path = require('node:path')
|
|
4
|
+
const cliPath = path.resolve(__dirname, '../dist/cli.cjs')
|
|
5
5
|
if (fs.existsSync(cliPath)) {
|
|
6
6
|
require(cliPath)
|
|
7
7
|
}
|
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const index = require('./index.cjs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
require('node:fs');
|
|
6
|
+
const fs = require('node:fs/promises');
|
|
7
|
+
require('resolve');
|
|
8
|
+
require('@babel/types');
|
|
9
|
+
require('@babel/generator');
|
|
10
|
+
require('@babel/traverse');
|
|
11
|
+
require('@babel/parser');
|
|
12
|
+
const cac = require('cac');
|
|
13
|
+
require('semver');
|
|
14
|
+
require('postcss');
|
|
15
|
+
require('postcss-load-config');
|
|
16
|
+
require('c12');
|
|
17
|
+
|
|
18
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
19
|
+
|
|
20
|
+
const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
21
|
+
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
22
|
+
const cac__default = /*#__PURE__*/_interopDefaultCompat(cac);
|
|
23
|
+
|
|
24
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
25
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
26
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
27
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
28
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
29
|
+
const dedent = createDedent({});
|
|
30
|
+
function createDedent(options) {
|
|
31
|
+
dedent.withOptions = newOptions => createDedent(_objectSpread(_objectSpread({}, options), newOptions));
|
|
32
|
+
return dedent;
|
|
33
|
+
function dedent(strings, ...values) {
|
|
34
|
+
const raw = typeof strings === "string" ? [strings] : strings.raw;
|
|
35
|
+
const {
|
|
36
|
+
escapeSpecialCharacters = Array.isArray(strings)
|
|
37
|
+
} = options;
|
|
38
|
+
|
|
39
|
+
// first, perform interpolation
|
|
40
|
+
let result = "";
|
|
41
|
+
for (let i = 0; i < raw.length; i++) {
|
|
42
|
+
let next = raw[i];
|
|
43
|
+
if (escapeSpecialCharacters) {
|
|
44
|
+
// handle escaped newlines, backticks, and interpolation characters
|
|
45
|
+
next = next.replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`").replace(/\\\$/g, "$").replace(/\\{/g, "{");
|
|
46
|
+
}
|
|
47
|
+
result += next;
|
|
48
|
+
if (i < values.length) {
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
50
|
+
result += values[i];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// now strip indentation
|
|
55
|
+
const lines = result.split("\n");
|
|
56
|
+
let mindent = null;
|
|
57
|
+
for (const l of lines) {
|
|
58
|
+
const m = l.match(/^(\s+)\S+/);
|
|
59
|
+
if (m) {
|
|
60
|
+
const indent = m[1].length;
|
|
61
|
+
if (!mindent) {
|
|
62
|
+
// this is the first indented line
|
|
63
|
+
mindent = indent;
|
|
64
|
+
} else {
|
|
65
|
+
mindent = Math.min(mindent, indent);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (mindent !== null) {
|
|
70
|
+
const m = mindent; // appease TypeScript
|
|
71
|
+
result = lines
|
|
72
|
+
// https://github.com/typescript-eslint/typescript-eslint/issues/7140
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
|
|
74
|
+
.map(l => l[0] === " " || l[0] === "\t" ? l.slice(m) : l).join("\n");
|
|
75
|
+
}
|
|
76
|
+
return result
|
|
77
|
+
// dedent eats leading and trailing whitespace too
|
|
78
|
+
.trim()
|
|
79
|
+
// handle escaped newlines at the end to ensure they don't get stripped too
|
|
80
|
+
.replace(/\\n/g, "\n");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function init() {
|
|
85
|
+
const cwd = process.cwd();
|
|
86
|
+
return fs__default.writeFile(
|
|
87
|
+
path__default.resolve(cwd, "tailwindcss-patch.config.ts"),
|
|
88
|
+
dedent`
|
|
89
|
+
import { defineConfig } from 'tailwindcss-patch'
|
|
90
|
+
|
|
91
|
+
export default defineConfig({})
|
|
92
|
+
`,
|
|
93
|
+
"utf8"
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
const cli = cac__default();
|
|
97
|
+
cli.command("install", "patch install").action(() => {
|
|
98
|
+
const opt = index.getPatchOptions();
|
|
99
|
+
const patch = index.createPatch(opt);
|
|
100
|
+
patch();
|
|
101
|
+
});
|
|
102
|
+
cli.command("init").action(async () => {
|
|
103
|
+
await init();
|
|
104
|
+
console.log("\u2728 tailwindcss-patch config initialized!");
|
|
105
|
+
});
|
|
106
|
+
cli.command("extract").action(async () => {
|
|
107
|
+
const { config } = await index.getConfig();
|
|
108
|
+
if (config) {
|
|
109
|
+
const twPatcher = new index.TailwindcssPatcher();
|
|
110
|
+
const p = await twPatcher.extract(config);
|
|
111
|
+
console.log("\u2728 tailwindcss-patch extract success! file path:\n" + p);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
cli.help();
|
|
115
|
+
cli.parse();
|
package/dist/cli.d.ts
ADDED
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { getPatchOptions, getConfig, TailwindcssPatcher, createPatch } from './index.mjs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import 'node:fs';
|
|
4
|
+
import fs from 'node:fs/promises';
|
|
5
|
+
import 'resolve';
|
|
6
|
+
import '@babel/types';
|
|
7
|
+
import '@babel/generator';
|
|
8
|
+
import '@babel/traverse';
|
|
9
|
+
import '@babel/parser';
|
|
10
|
+
import cac from 'cac';
|
|
11
|
+
import 'semver';
|
|
12
|
+
import 'postcss';
|
|
13
|
+
import 'postcss-load-config';
|
|
14
|
+
import 'c12';
|
|
15
|
+
|
|
16
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
17
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
18
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
19
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
20
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
21
|
+
const dedent = createDedent({});
|
|
22
|
+
function createDedent(options) {
|
|
23
|
+
dedent.withOptions = newOptions => createDedent(_objectSpread(_objectSpread({}, options), newOptions));
|
|
24
|
+
return dedent;
|
|
25
|
+
function dedent(strings, ...values) {
|
|
26
|
+
const raw = typeof strings === "string" ? [strings] : strings.raw;
|
|
27
|
+
const {
|
|
28
|
+
escapeSpecialCharacters = Array.isArray(strings)
|
|
29
|
+
} = options;
|
|
30
|
+
|
|
31
|
+
// first, perform interpolation
|
|
32
|
+
let result = "";
|
|
33
|
+
for (let i = 0; i < raw.length; i++) {
|
|
34
|
+
let next = raw[i];
|
|
35
|
+
if (escapeSpecialCharacters) {
|
|
36
|
+
// handle escaped newlines, backticks, and interpolation characters
|
|
37
|
+
next = next.replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`").replace(/\\\$/g, "$").replace(/\\{/g, "{");
|
|
38
|
+
}
|
|
39
|
+
result += next;
|
|
40
|
+
if (i < values.length) {
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
42
|
+
result += values[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// now strip indentation
|
|
47
|
+
const lines = result.split("\n");
|
|
48
|
+
let mindent = null;
|
|
49
|
+
for (const l of lines) {
|
|
50
|
+
const m = l.match(/^(\s+)\S+/);
|
|
51
|
+
if (m) {
|
|
52
|
+
const indent = m[1].length;
|
|
53
|
+
if (!mindent) {
|
|
54
|
+
// this is the first indented line
|
|
55
|
+
mindent = indent;
|
|
56
|
+
} else {
|
|
57
|
+
mindent = Math.min(mindent, indent);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (mindent !== null) {
|
|
62
|
+
const m = mindent; // appease TypeScript
|
|
63
|
+
result = lines
|
|
64
|
+
// https://github.com/typescript-eslint/typescript-eslint/issues/7140
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
|
|
66
|
+
.map(l => l[0] === " " || l[0] === "\t" ? l.slice(m) : l).join("\n");
|
|
67
|
+
}
|
|
68
|
+
return result
|
|
69
|
+
// dedent eats leading and trailing whitespace too
|
|
70
|
+
.trim()
|
|
71
|
+
// handle escaped newlines at the end to ensure they don't get stripped too
|
|
72
|
+
.replace(/\\n/g, "\n");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function init() {
|
|
77
|
+
const cwd = process.cwd();
|
|
78
|
+
return fs.writeFile(
|
|
79
|
+
path.resolve(cwd, "tailwindcss-patch.config.ts"),
|
|
80
|
+
dedent`
|
|
81
|
+
import { defineConfig } from 'tailwindcss-patch'
|
|
82
|
+
|
|
83
|
+
export default defineConfig({})
|
|
84
|
+
`,
|
|
85
|
+
"utf8"
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
const cli = cac();
|
|
89
|
+
cli.command("install", "patch install").action(() => {
|
|
90
|
+
const opt = getPatchOptions();
|
|
91
|
+
const patch = createPatch(opt);
|
|
92
|
+
patch();
|
|
93
|
+
});
|
|
94
|
+
cli.command("init").action(async () => {
|
|
95
|
+
await init();
|
|
96
|
+
console.log("\u2728 tailwindcss-patch config initialized!");
|
|
97
|
+
});
|
|
98
|
+
cli.command("extract").action(async () => {
|
|
99
|
+
const { config } = await getConfig();
|
|
100
|
+
if (config) {
|
|
101
|
+
const twPatcher = new TailwindcssPatcher();
|
|
102
|
+
const p = await twPatcher.extract(config);
|
|
103
|
+
console.log("\u2728 tailwindcss-patch extract success! file path:\n" + p);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
cli.help();
|
|
107
|
+
cli.parse();
|