@fullstacked/tailwindcss 4.3.2-patch.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/index.js +111 -0
- package/index.ts +173 -0
- package/package.json +17 -0
package/index.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import oxide, { extract } from "oxide-wasm";
|
|
4
|
+
import { compile } from "tailwindcss";
|
|
5
|
+
import lightningcss, { transform } from "lightningcss-wasm";
|
|
6
|
+
let init = null;
|
|
7
|
+
let initPromise = null;
|
|
8
|
+
export function initialize(opts) {
|
|
9
|
+
if (init === null) {
|
|
10
|
+
initPromise = new Promise(async (resolve) => {
|
|
11
|
+
const oxidePath = opts?.oxide || "node_modules/oxide-wasm/pkg/oxide_wasm_bg.wasm";
|
|
12
|
+
const lightningcssPath = opts?.lightningcss || "node_modules/lightningcss-wasm/lightningcss_node.wasm";
|
|
13
|
+
const tailwindcssPath = opts?.tailwindcss || "node_modules/tailwindcss";
|
|
14
|
+
const locations = {
|
|
15
|
+
oxide: oxide(fs.promises.readFile(oxidePath)),
|
|
16
|
+
lightningcss: lightningcss(lightningcssPath),
|
|
17
|
+
tailwindcss: tailwindcssPath,
|
|
18
|
+
baseDirectory: opts?.baseDirectory || process.cwd(),
|
|
19
|
+
skipLightning: opts?.skipLightning
|
|
20
|
+
};
|
|
21
|
+
await Promise.all([locations.oxide, locations.lightningcss]);
|
|
22
|
+
init = locations;
|
|
23
|
+
resolve();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return initPromise;
|
|
27
|
+
}
|
|
28
|
+
async function loadStylesheet(id, base) {
|
|
29
|
+
if (init === null) {
|
|
30
|
+
throw new Error("tailwindcss has not been initialized");
|
|
31
|
+
}
|
|
32
|
+
if (id === "tailwindcss") {
|
|
33
|
+
return {
|
|
34
|
+
path: "virtual:tailwindcss/index.css",
|
|
35
|
+
base,
|
|
36
|
+
content: await fs.promises.readFile(
|
|
37
|
+
path.join(init.tailwindcss, "index.css"),
|
|
38
|
+
"utf-8"
|
|
39
|
+
)
|
|
40
|
+
};
|
|
41
|
+
} else if (id === "tailwindcss/preflight" || id === "tailwindcss/preflight.css" || id === "./preflight.css") {
|
|
42
|
+
return {
|
|
43
|
+
path: "virtual:tailwindcss/preflight.css",
|
|
44
|
+
base,
|
|
45
|
+
content: await fs.promises.readFile(
|
|
46
|
+
path.join(init.tailwindcss, "preflight.css"),
|
|
47
|
+
"utf-8"
|
|
48
|
+
)
|
|
49
|
+
};
|
|
50
|
+
} else if (id === "tailwindcss/theme" || id === "tailwindcss/theme.css" || id === "./theme.css") {
|
|
51
|
+
return {
|
|
52
|
+
path: "virtual:tailwindcss/theme.css",
|
|
53
|
+
base,
|
|
54
|
+
content: await fs.promises.readFile(
|
|
55
|
+
path.join(init.tailwindcss, "theme.css"),
|
|
56
|
+
"utf-8"
|
|
57
|
+
)
|
|
58
|
+
};
|
|
59
|
+
} else if (id === "tailwindcss/utilities" || id === "tailwindcss/utilities.css" || id === "./utilities.css") {
|
|
60
|
+
return {
|
|
61
|
+
path: "virtual:tailwindcss/utilities.css",
|
|
62
|
+
base,
|
|
63
|
+
content: await fs.promises.readFile(
|
|
64
|
+
path.join(init.tailwindcss, "utilities.css"),
|
|
65
|
+
"utf-8"
|
|
66
|
+
)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
throw new Error(`The browser build does not support @import for "${id}"`);
|
|
70
|
+
}
|
|
71
|
+
async function compileTailwind(entryfile, files) {
|
|
72
|
+
entryfile = path.join(init.baseDirectory, entryfile);
|
|
73
|
+
const entry = await fs.promises.readFile(entryfile, "utf-8");
|
|
74
|
+
const contents = await Promise.all(
|
|
75
|
+
files.map(
|
|
76
|
+
(file) => fs.promises.readFile(path.join(init.baseDirectory, file), "utf-8")
|
|
77
|
+
)
|
|
78
|
+
);
|
|
79
|
+
const candidate = contents.map((content) => extract(content)).flat();
|
|
80
|
+
const compiler = await compile(entry, { loadStylesheet });
|
|
81
|
+
const css = compiler.build(candidate);
|
|
82
|
+
const result = init.skipLightning ? css : transform({
|
|
83
|
+
filename: "input.css",
|
|
84
|
+
code: new TextEncoder().encode(css)
|
|
85
|
+
}).code;
|
|
86
|
+
return typeof result === "string" ? result : new TextDecoder().decode(result);
|
|
87
|
+
}
|
|
88
|
+
async function tailwindBuilder(params) {
|
|
89
|
+
if (params.sources.length == 0 || params.resolved.length == 0) {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
const sources = params.sources.filter((s) => !s.endsWith(".css"));
|
|
93
|
+
await initialize(params.initializeOptions);
|
|
94
|
+
const css = await compileTailwind(params.resolved.at(0).importer, sources);
|
|
95
|
+
const basename = path.basename(params.resolved.at(0).importer);
|
|
96
|
+
return [
|
|
97
|
+
{
|
|
98
|
+
outputName: basename + ".tailwind.css",
|
|
99
|
+
contents: css
|
|
100
|
+
}
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
export const pluginTailwindcss = {
|
|
104
|
+
data: {
|
|
105
|
+
name: "tailwindcss",
|
|
106
|
+
filter: "tailwindcss",
|
|
107
|
+
ext: ["css"]
|
|
108
|
+
},
|
|
109
|
+
callback: tailwindBuilder
|
|
110
|
+
};
|
|
111
|
+
export default pluginTailwindcss;
|
package/index.ts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import oxide, { extract } from "oxide-wasm";
|
|
4
|
+
import { compile } from "tailwindcss";
|
|
5
|
+
import lightningcss, { transform } from "lightningcss-wasm";
|
|
6
|
+
|
|
7
|
+
let init: {
|
|
8
|
+
oxide: Promise<void>;
|
|
9
|
+
lightningcss: Promise<void>;
|
|
10
|
+
tailwindcss: string;
|
|
11
|
+
baseDirectory: string;
|
|
12
|
+
skipLightning: boolean;
|
|
13
|
+
} = null;
|
|
14
|
+
let initPromise: Promise<void> = null;
|
|
15
|
+
|
|
16
|
+
type InitializeOpts = {
|
|
17
|
+
oxide: string;
|
|
18
|
+
tailwindcss: string;
|
|
19
|
+
lightningcss: string;
|
|
20
|
+
baseDirectory?: string;
|
|
21
|
+
skipLightning?: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function initialize(opts?: InitializeOpts) {
|
|
25
|
+
if (init === null) {
|
|
26
|
+
initPromise = new Promise(async (resolve) => {
|
|
27
|
+
const oxidePath =
|
|
28
|
+
opts?.oxide || "node_modules/oxide-wasm/pkg/oxide_wasm_bg.wasm";
|
|
29
|
+
const lightningcssPath =
|
|
30
|
+
opts?.lightningcss ||
|
|
31
|
+
"node_modules/lightningcss-wasm/lightningcss_node.wasm";
|
|
32
|
+
const tailwindcssPath =
|
|
33
|
+
opts?.tailwindcss || "node_modules/tailwindcss";
|
|
34
|
+
|
|
35
|
+
const locations: typeof init = {
|
|
36
|
+
oxide: oxide(fs.promises.readFile(oxidePath)),
|
|
37
|
+
lightningcss: lightningcss(lightningcssPath),
|
|
38
|
+
tailwindcss: tailwindcssPath,
|
|
39
|
+
baseDirectory: opts?.baseDirectory || process.cwd(),
|
|
40
|
+
skipLightning: opts?.skipLightning
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
await Promise.all([locations.oxide, locations.lightningcss]);
|
|
44
|
+
|
|
45
|
+
init = locations;
|
|
46
|
+
resolve();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return initPromise;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function loadStylesheet(id: string, base: string) {
|
|
54
|
+
if (init === null) {
|
|
55
|
+
throw new Error("tailwindcss has not been initialized");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (id === "tailwindcss") {
|
|
59
|
+
return {
|
|
60
|
+
path: "virtual:tailwindcss/index.css",
|
|
61
|
+
base,
|
|
62
|
+
content: await fs.promises.readFile(
|
|
63
|
+
path.join(init.tailwindcss, "index.css"),
|
|
64
|
+
"utf-8"
|
|
65
|
+
)
|
|
66
|
+
};
|
|
67
|
+
} else if (
|
|
68
|
+
id === "tailwindcss/preflight" ||
|
|
69
|
+
id === "tailwindcss/preflight.css" ||
|
|
70
|
+
id === "./preflight.css"
|
|
71
|
+
) {
|
|
72
|
+
return {
|
|
73
|
+
path: "virtual:tailwindcss/preflight.css",
|
|
74
|
+
base,
|
|
75
|
+
content: await fs.promises.readFile(
|
|
76
|
+
path.join(init.tailwindcss, "preflight.css"),
|
|
77
|
+
"utf-8"
|
|
78
|
+
)
|
|
79
|
+
};
|
|
80
|
+
} else if (
|
|
81
|
+
id === "tailwindcss/theme" ||
|
|
82
|
+
id === "tailwindcss/theme.css" ||
|
|
83
|
+
id === "./theme.css"
|
|
84
|
+
) {
|
|
85
|
+
return {
|
|
86
|
+
path: "virtual:tailwindcss/theme.css",
|
|
87
|
+
base,
|
|
88
|
+
content: await fs.promises.readFile(
|
|
89
|
+
path.join(init.tailwindcss, "theme.css"),
|
|
90
|
+
"utf-8"
|
|
91
|
+
)
|
|
92
|
+
};
|
|
93
|
+
} else if (
|
|
94
|
+
id === "tailwindcss/utilities" ||
|
|
95
|
+
id === "tailwindcss/utilities.css" ||
|
|
96
|
+
id === "./utilities.css"
|
|
97
|
+
) {
|
|
98
|
+
return {
|
|
99
|
+
path: "virtual:tailwindcss/utilities.css",
|
|
100
|
+
base,
|
|
101
|
+
content: await fs.promises.readFile(
|
|
102
|
+
path.join(init.tailwindcss, "utilities.css"),
|
|
103
|
+
"utf-8"
|
|
104
|
+
)
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
throw new Error(`The browser build does not support @import for "${id}"`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function compileTailwind(
|
|
112
|
+
entryfile: string,
|
|
113
|
+
files: string[]
|
|
114
|
+
): Promise<string> {
|
|
115
|
+
entryfile = path.join(init.baseDirectory, entryfile);
|
|
116
|
+
|
|
117
|
+
const entry = await fs.promises.readFile(entryfile, "utf-8");
|
|
118
|
+
const contents = await Promise.all(
|
|
119
|
+
files.map((file) =>
|
|
120
|
+
fs.promises.readFile(path.join(init.baseDirectory, file), "utf-8")
|
|
121
|
+
)
|
|
122
|
+
);
|
|
123
|
+
const candidate = contents.map((content) => extract(content)).flat();
|
|
124
|
+
const compiler = await compile(entry, { loadStylesheet });
|
|
125
|
+
const css = compiler.build(candidate);
|
|
126
|
+
|
|
127
|
+
const result = init.skipLightning
|
|
128
|
+
? css
|
|
129
|
+
: transform({
|
|
130
|
+
filename: "input.css",
|
|
131
|
+
code: new TextEncoder().encode(css)
|
|
132
|
+
}).code;
|
|
133
|
+
|
|
134
|
+
return typeof result === "string"
|
|
135
|
+
? result
|
|
136
|
+
: new TextDecoder().decode(result);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function tailwindBuilder(params: {
|
|
140
|
+
resolved: {
|
|
141
|
+
importer: string;
|
|
142
|
+
}[];
|
|
143
|
+
sources: string[];
|
|
144
|
+
|
|
145
|
+
initializeOptions?: InitializeOpts;
|
|
146
|
+
}) {
|
|
147
|
+
if (params.sources.length == 0 || params.resolved.length == 0) {
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const sources = params.sources.filter((s) => !s.endsWith(".css"));
|
|
152
|
+
await initialize(params.initializeOptions);
|
|
153
|
+
const css = await compileTailwind(params.resolved.at(0).importer, sources);
|
|
154
|
+
const basename = path.basename(params.resolved.at(0).importer);
|
|
155
|
+
|
|
156
|
+
return [
|
|
157
|
+
{
|
|
158
|
+
outputName: basename + ".tailwind.css",
|
|
159
|
+
contents: css
|
|
160
|
+
}
|
|
161
|
+
];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export const pluginTailwindcss = {
|
|
165
|
+
data: {
|
|
166
|
+
name: "tailwindcss",
|
|
167
|
+
filter: "tailwindcss",
|
|
168
|
+
ext: ["css"]
|
|
169
|
+
},
|
|
170
|
+
callback: tailwindBuilder
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
export default pluginTailwindcss;
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fullstacked/tailwindcss",
|
|
3
|
+
"version": "4.3.2-patch.0",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "esbuild --outfile=index.js index.ts"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"lightningcss-wasm": "^1.32.0",
|
|
10
|
+
"oxide-wasm": "^0.1.1",
|
|
11
|
+
"tailwindcss": "^4.3.2"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"esbuild": "^0.28.1"
|
|
16
|
+
}
|
|
17
|
+
}
|