tailwindcss-injector 0.0.2 → 0.1.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/dist/postcss.cjs +120 -50
- package/dist/postcss.js +117 -44
- package/package.json +6 -4
package/dist/postcss.cjs
CHANGED
|
@@ -28,12 +28,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
));
|
|
29
29
|
|
|
30
30
|
// ../../node_modules/.pnpm/tsup@8.3.5_jiti@2.4.1_postcss@8.4.49_tsx@4.19.2_typescript@5.7.2_yaml@2.6.1/node_modules/tsup/assets/cjs_shims.js
|
|
31
|
-
var getImportMetaUrl, importMetaUrl;
|
|
32
31
|
var init_cjs_shims = __esm({
|
|
33
32
|
"../../node_modules/.pnpm/tsup@8.3.5_jiti@2.4.1_postcss@8.4.49_tsx@4.19.2_typescript@5.7.2_yaml@2.6.1/node_modules/tsup/assets/cjs_shims.js"() {
|
|
34
33
|
"use strict";
|
|
35
|
-
getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
36
|
-
importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
37
34
|
}
|
|
38
35
|
});
|
|
39
36
|
|
|
@@ -222,17 +219,12 @@ var import_set_value = __toESM(require_set_value(), 1);
|
|
|
222
219
|
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
223
220
|
var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
|
|
224
221
|
var _tailwindcss = require('tailwindcss'); var _tailwindcss2 = _interopRequireDefault(_tailwindcss);
|
|
225
|
-
|
|
226
|
-
// src/config.ts
|
|
227
|
-
init_cjs_shims();
|
|
228
|
-
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
229
|
-
|
|
230
|
-
var _jiti = require('jiti');
|
|
231
|
-
var _lilconfig = require('lilconfig');
|
|
222
|
+
var _tailwindcssconfig = require('tailwindcss-config');
|
|
232
223
|
|
|
233
224
|
// src/utils.ts
|
|
234
225
|
init_cjs_shims();
|
|
235
|
-
|
|
226
|
+
var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto);
|
|
227
|
+
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
236
228
|
|
|
237
229
|
// ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
|
|
238
230
|
init_cjs_shims();
|
|
@@ -305,9 +297,14 @@ var defuArrayFn = createDefu((object, key, currentValue) => {
|
|
|
305
297
|
|
|
306
298
|
// src/utils.ts
|
|
307
299
|
function removeFileExtension(filePath) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
300
|
+
if (!filePath) {
|
|
301
|
+
return "";
|
|
302
|
+
}
|
|
303
|
+
let baseName = _path2.default.basename(filePath);
|
|
304
|
+
let ext = _path2.default.extname(baseName);
|
|
305
|
+
while (ext) {
|
|
306
|
+
baseName = baseName.slice(0, -ext.length);
|
|
307
|
+
ext = _path2.default.extname(baseName);
|
|
311
308
|
}
|
|
312
309
|
const dir = _path2.default.dirname(filePath);
|
|
313
310
|
return _path2.default.join(dir, baseName);
|
|
@@ -318,41 +315,107 @@ var defuOverrideArray = createDefu((obj, key, value) => {
|
|
|
318
315
|
return true;
|
|
319
316
|
}
|
|
320
317
|
});
|
|
318
|
+
function md5(input) {
|
|
319
|
+
const hash = _crypto2.default.createHash("md5");
|
|
320
|
+
hash.update(input);
|
|
321
|
+
return hash.digest("hex");
|
|
322
|
+
}
|
|
321
323
|
|
|
322
|
-
// src/
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
324
|
+
// src/wxml.ts
|
|
325
|
+
init_cjs_shims();
|
|
326
|
+
|
|
327
|
+
var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
|
|
328
|
+
var _htmlparser2 = require('htmlparser2');
|
|
329
|
+
var _magicstring = require('magic-string'); var _magicstring2 = _interopRequireDefault(_magicstring);
|
|
330
|
+
var hashMap = /* @__PURE__ */ new Map();
|
|
331
|
+
var depsMap = /* @__PURE__ */ new Map();
|
|
332
|
+
var srcImportTagsMap = {
|
|
333
|
+
// audio: ['src', 'poster'],
|
|
334
|
+
// video: ['src', 'poster'],
|
|
335
|
+
// image: ['src'],
|
|
336
|
+
// https://developers.weixin.qq.com/miniprogram/dev/reference/wxs/01wxs-module.html
|
|
337
|
+
// wxs: ['src'],
|
|
338
|
+
// https://developers.weixin.qq.com/miniprogram/dev/reference/wxml/import.html
|
|
339
|
+
import: ["src"],
|
|
340
|
+
include: ["src"]
|
|
341
|
+
};
|
|
342
|
+
function processWxml(wxml) {
|
|
343
|
+
const ms = new (0, _magicstring2.default)(wxml.toString());
|
|
344
|
+
const deps = [];
|
|
345
|
+
let currentTagName = "";
|
|
346
|
+
let importAttrs;
|
|
347
|
+
let attrs = {};
|
|
348
|
+
const parser = new (0, _htmlparser2.Parser)(
|
|
349
|
+
{
|
|
350
|
+
onopentagname(name) {
|
|
351
|
+
currentTagName = name;
|
|
352
|
+
importAttrs = srcImportTagsMap[currentTagName];
|
|
353
|
+
},
|
|
354
|
+
onattribute(name, value, quote) {
|
|
355
|
+
attrs[name] = value;
|
|
356
|
+
if (importAttrs) {
|
|
357
|
+
for (const attrName of importAttrs) {
|
|
358
|
+
if (attrName === name) {
|
|
359
|
+
deps.push({
|
|
360
|
+
name,
|
|
361
|
+
value,
|
|
362
|
+
quote,
|
|
363
|
+
tagName: currentTagName,
|
|
364
|
+
start: parser.startIndex,
|
|
365
|
+
end: parser.endIndex,
|
|
366
|
+
attrs
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
onclosetag() {
|
|
373
|
+
currentTagName = "";
|
|
374
|
+
attrs = {};
|
|
375
|
+
importAttrs = void 0;
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
lowerCaseTags: false,
|
|
380
|
+
xmlMode: true
|
|
381
|
+
}
|
|
382
|
+
);
|
|
383
|
+
parser.write(
|
|
384
|
+
ms.original
|
|
385
|
+
);
|
|
386
|
+
parser.end();
|
|
387
|
+
return deps;
|
|
388
|
+
}
|
|
389
|
+
async function getDep(filepath, set2) {
|
|
390
|
+
if (await _fsextra2.default.exists(filepath)) {
|
|
391
|
+
const dirname = _path2.default.dirname(filepath);
|
|
392
|
+
set2.add(filepath);
|
|
393
|
+
const wxml = await _fsextra2.default.readFile(filepath, "utf8");
|
|
394
|
+
const hash = md5(wxml);
|
|
395
|
+
const oldHash = hashMap.get(filepath);
|
|
396
|
+
const isChanged = hash !== oldHash;
|
|
397
|
+
let deps = [];
|
|
398
|
+
const cacheDeps = depsMap.get(filepath);
|
|
399
|
+
if (isChanged || !cacheDeps) {
|
|
400
|
+
hashMap.set(filepath, hash);
|
|
401
|
+
deps = await processWxml(wxml);
|
|
402
|
+
depsMap.set(filepath, deps);
|
|
403
|
+
} else {
|
|
404
|
+
deps = cacheDeps;
|
|
405
|
+
}
|
|
406
|
+
for (const { value } of deps) {
|
|
407
|
+
const p = _path2.default.resolve(dirname, value);
|
|
408
|
+
if (!set2.has(p)) {
|
|
409
|
+
await getDep(p, set2);
|
|
410
|
+
}
|
|
345
411
|
}
|
|
346
|
-
});
|
|
347
|
-
if (typeof config === "string" && config) {
|
|
348
|
-
const configPath = _path2.default.isAbsolute(config) ? config : _path2.default.resolve(cwd, config);
|
|
349
|
-
const result = await searcher.load(configPath);
|
|
350
|
-
return _optionalChain([result, 'optionalAccess', _ => _.config]);
|
|
351
|
-
} else {
|
|
352
|
-
const result = await searcher.search(cwd);
|
|
353
|
-
return _optionalChain([result, 'optionalAccess', _2 => _2.config]);
|
|
354
412
|
}
|
|
355
413
|
}
|
|
414
|
+
async function getDepFiles(file) {
|
|
415
|
+
const set2 = /* @__PURE__ */ new Set();
|
|
416
|
+
await getDep(file, set2);
|
|
417
|
+
return set2;
|
|
418
|
+
}
|
|
356
419
|
|
|
357
420
|
// src/postcss.ts
|
|
358
421
|
var creator = (options) => {
|
|
@@ -370,7 +433,7 @@ var creator = (options) => {
|
|
|
370
433
|
{
|
|
371
434
|
postcssPlugin: "post",
|
|
372
435
|
async Once(root, helpers) {
|
|
373
|
-
if (filter(_optionalChain([root, 'access',
|
|
436
|
+
if (filter(_optionalChain([root, 'access', _ => _.source, 'optionalAccess', _2 => _2.input]))) {
|
|
374
437
|
let _root = root;
|
|
375
438
|
for (const params of directiveParams) {
|
|
376
439
|
const node = root.nodes.find((x) => x.type === "atrule" && x.params === params);
|
|
@@ -378,10 +441,10 @@ var creator = (options) => {
|
|
|
378
441
|
_root = _root.prepend(helpers.atRule({ name: "tailwind", params }));
|
|
379
442
|
}
|
|
380
443
|
}
|
|
381
|
-
const cfg = typeof config === "function" ? config(_optionalChain([root, 'access',
|
|
444
|
+
const cfg = typeof config === "function" ? config(_optionalChain([root, 'access', _3 => _3.source, 'optionalAccess', _4 => _4.input])) : config;
|
|
382
445
|
let tailwindcssConfig;
|
|
383
446
|
if (typeof cfg === "string") {
|
|
384
|
-
tailwindcssConfig = await loadConfig({
|
|
447
|
+
tailwindcssConfig = await _tailwindcssconfig.loadConfig.call(void 0, {
|
|
385
448
|
cwd,
|
|
386
449
|
config: cfg
|
|
387
450
|
});
|
|
@@ -390,10 +453,17 @@ var creator = (options) => {
|
|
|
390
453
|
content: []
|
|
391
454
|
}));
|
|
392
455
|
}
|
|
393
|
-
if (tailwindcssConfig && _optionalChain([root, 'access',
|
|
456
|
+
if (tailwindcssConfig && _optionalChain([root, 'access', _5 => _5.source, 'optionalAccess', _6 => _6.input]) && root.source.input.file) {
|
|
457
|
+
const basename = removeFileExtension(root.source.input.file);
|
|
394
458
|
(0, import_set_value.default)(tailwindcssConfig, "content", [
|
|
395
|
-
`${
|
|
459
|
+
`${basename}.${extensionsGlob}`
|
|
396
460
|
]);
|
|
461
|
+
const deps = await getDepFiles(`${basename}.wxml`);
|
|
462
|
+
for (const dep of deps) {
|
|
463
|
+
if (Array.isArray(tailwindcssConfig.content)) {
|
|
464
|
+
tailwindcssConfig.content.push(`${removeFileExtension(dep)}.${extensionsGlob}`);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
397
467
|
}
|
|
398
468
|
const { root: newRoot } = await _postcss2.default.call(void 0, [
|
|
399
469
|
_tailwindcss2.default.call(void 0, tailwindcssConfig)
|
package/dist/postcss.js
CHANGED
|
@@ -216,19 +216,14 @@ var require_set_value = __commonJS({
|
|
|
216
216
|
// src/postcss.ts
|
|
217
217
|
init_esm_shims();
|
|
218
218
|
var import_set_value = __toESM(require_set_value(), 1);
|
|
219
|
-
import
|
|
219
|
+
import process from "node:process";
|
|
220
220
|
import postcss from "postcss";
|
|
221
221
|
import tailwindcss from "tailwindcss";
|
|
222
|
-
|
|
223
|
-
// src/config.ts
|
|
224
|
-
init_esm_shims();
|
|
225
|
-
import path2 from "node:path";
|
|
226
|
-
import process from "node:process";
|
|
227
|
-
import { createJiti } from "jiti";
|
|
228
|
-
import { lilconfig } from "lilconfig";
|
|
222
|
+
import { loadConfig } from "tailwindcss-config";
|
|
229
223
|
|
|
230
224
|
// src/utils.ts
|
|
231
225
|
init_esm_shims();
|
|
226
|
+
import crypto from "node:crypto";
|
|
232
227
|
import path from "node:path";
|
|
233
228
|
|
|
234
229
|
// ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
|
|
@@ -302,9 +297,14 @@ var defuArrayFn = createDefu((object, key, currentValue) => {
|
|
|
302
297
|
|
|
303
298
|
// src/utils.ts
|
|
304
299
|
function removeFileExtension(filePath) {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
300
|
+
if (!filePath) {
|
|
301
|
+
return "";
|
|
302
|
+
}
|
|
303
|
+
let baseName = path.basename(filePath);
|
|
304
|
+
let ext = path.extname(baseName);
|
|
305
|
+
while (ext) {
|
|
306
|
+
baseName = baseName.slice(0, -ext.length);
|
|
307
|
+
ext = path.extname(baseName);
|
|
308
308
|
}
|
|
309
309
|
const dir = path.dirname(filePath);
|
|
310
310
|
return path.join(dir, baseName);
|
|
@@ -315,41 +315,107 @@ var defuOverrideArray = createDefu((obj, key, value) => {
|
|
|
315
315
|
return true;
|
|
316
316
|
}
|
|
317
317
|
});
|
|
318
|
+
function md5(input) {
|
|
319
|
+
const hash = crypto.createHash("md5");
|
|
320
|
+
hash.update(input);
|
|
321
|
+
return hash.digest("hex");
|
|
322
|
+
}
|
|
318
323
|
|
|
319
|
-
// src/
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
324
|
+
// src/wxml.ts
|
|
325
|
+
init_esm_shims();
|
|
326
|
+
import path2 from "node:path";
|
|
327
|
+
import fs from "fs-extra";
|
|
328
|
+
import { Parser } from "htmlparser2";
|
|
329
|
+
import MagicString from "magic-string";
|
|
330
|
+
var hashMap = /* @__PURE__ */ new Map();
|
|
331
|
+
var depsMap = /* @__PURE__ */ new Map();
|
|
332
|
+
var srcImportTagsMap = {
|
|
333
|
+
// audio: ['src', 'poster'],
|
|
334
|
+
// video: ['src', 'poster'],
|
|
335
|
+
// image: ['src'],
|
|
336
|
+
// https://developers.weixin.qq.com/miniprogram/dev/reference/wxs/01wxs-module.html
|
|
337
|
+
// wxs: ['src'],
|
|
338
|
+
// https://developers.weixin.qq.com/miniprogram/dev/reference/wxml/import.html
|
|
339
|
+
import: ["src"],
|
|
340
|
+
include: ["src"]
|
|
341
|
+
};
|
|
342
|
+
function processWxml(wxml) {
|
|
343
|
+
const ms = new MagicString(wxml.toString());
|
|
344
|
+
const deps = [];
|
|
345
|
+
let currentTagName = "";
|
|
346
|
+
let importAttrs;
|
|
347
|
+
let attrs = {};
|
|
348
|
+
const parser = new Parser(
|
|
349
|
+
{
|
|
350
|
+
onopentagname(name) {
|
|
351
|
+
currentTagName = name;
|
|
352
|
+
importAttrs = srcImportTagsMap[currentTagName];
|
|
353
|
+
},
|
|
354
|
+
onattribute(name, value, quote) {
|
|
355
|
+
attrs[name] = value;
|
|
356
|
+
if (importAttrs) {
|
|
357
|
+
for (const attrName of importAttrs) {
|
|
358
|
+
if (attrName === name) {
|
|
359
|
+
deps.push({
|
|
360
|
+
name,
|
|
361
|
+
value,
|
|
362
|
+
quote,
|
|
363
|
+
tagName: currentTagName,
|
|
364
|
+
start: parser.startIndex,
|
|
365
|
+
end: parser.endIndex,
|
|
366
|
+
attrs
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
onclosetag() {
|
|
373
|
+
currentTagName = "";
|
|
374
|
+
attrs = {};
|
|
375
|
+
importAttrs = void 0;
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
lowerCaseTags: false,
|
|
380
|
+
xmlMode: true
|
|
381
|
+
}
|
|
382
|
+
);
|
|
383
|
+
parser.write(
|
|
384
|
+
ms.original
|
|
385
|
+
);
|
|
386
|
+
parser.end();
|
|
387
|
+
return deps;
|
|
388
|
+
}
|
|
389
|
+
async function getDep(filepath, set2) {
|
|
390
|
+
if (await fs.exists(filepath)) {
|
|
391
|
+
const dirname = path2.dirname(filepath);
|
|
392
|
+
set2.add(filepath);
|
|
393
|
+
const wxml = await fs.readFile(filepath, "utf8");
|
|
394
|
+
const hash = md5(wxml);
|
|
395
|
+
const oldHash = hashMap.get(filepath);
|
|
396
|
+
const isChanged = hash !== oldHash;
|
|
397
|
+
let deps = [];
|
|
398
|
+
const cacheDeps = depsMap.get(filepath);
|
|
399
|
+
if (isChanged || !cacheDeps) {
|
|
400
|
+
hashMap.set(filepath, hash);
|
|
401
|
+
deps = await processWxml(wxml);
|
|
402
|
+
depsMap.set(filepath, deps);
|
|
403
|
+
} else {
|
|
404
|
+
deps = cacheDeps;
|
|
405
|
+
}
|
|
406
|
+
for (const { value } of deps) {
|
|
407
|
+
const p = path2.resolve(dirname, value);
|
|
408
|
+
if (!set2.has(p)) {
|
|
409
|
+
await getDep(p, set2);
|
|
410
|
+
}
|
|
342
411
|
}
|
|
343
|
-
});
|
|
344
|
-
if (typeof config === "string" && config) {
|
|
345
|
-
const configPath = path2.isAbsolute(config) ? config : path2.resolve(cwd, config);
|
|
346
|
-
const result = await searcher.load(configPath);
|
|
347
|
-
return result?.config;
|
|
348
|
-
} else {
|
|
349
|
-
const result = await searcher.search(cwd);
|
|
350
|
-
return result?.config;
|
|
351
412
|
}
|
|
352
413
|
}
|
|
414
|
+
async function getDepFiles(file) {
|
|
415
|
+
const set2 = /* @__PURE__ */ new Set();
|
|
416
|
+
await getDep(file, set2);
|
|
417
|
+
return set2;
|
|
418
|
+
}
|
|
353
419
|
|
|
354
420
|
// src/postcss.ts
|
|
355
421
|
var creator = (options) => {
|
|
@@ -357,7 +423,7 @@ var creator = (options) => {
|
|
|
357
423
|
filter: () => true,
|
|
358
424
|
config: void 0,
|
|
359
425
|
directiveParams: ["utilities", "components"],
|
|
360
|
-
cwd:
|
|
426
|
+
cwd: process.cwd(),
|
|
361
427
|
extensions: ["wxml", "js", "ts"]
|
|
362
428
|
});
|
|
363
429
|
const extensionsGlob = `{${extensions.join(",")}}`;
|
|
@@ -388,9 +454,16 @@ var creator = (options) => {
|
|
|
388
454
|
};
|
|
389
455
|
}
|
|
390
456
|
if (tailwindcssConfig && root.source?.input && root.source.input.file) {
|
|
457
|
+
const basename = removeFileExtension(root.source.input.file);
|
|
391
458
|
(0, import_set_value.default)(tailwindcssConfig, "content", [
|
|
392
|
-
`${
|
|
459
|
+
`${basename}.${extensionsGlob}`
|
|
393
460
|
]);
|
|
461
|
+
const deps = await getDepFiles(`${basename}.wxml`);
|
|
462
|
+
for (const dep of deps) {
|
|
463
|
+
if (Array.isArray(tailwindcssConfig.content)) {
|
|
464
|
+
tailwindcssConfig.content.push(`${removeFileExtension(dep)}.${extensionsGlob}`);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
394
467
|
}
|
|
395
468
|
const { root: newRoot } = await postcss([
|
|
396
469
|
tailwindcss(tailwindcssConfig)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwindcss-injector",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.1.1",
|
|
5
5
|
"description": "tsup(esbuild) build package template",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -31,10 +31,12 @@
|
|
|
31
31
|
"dist"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"
|
|
35
|
-
"
|
|
34
|
+
"fs-extra": "^11.2.0",
|
|
35
|
+
"htmlparser2": "^9.1.0",
|
|
36
|
+
"magic-string": "^0.30.14",
|
|
36
37
|
"postcss": "^8.4.49",
|
|
37
|
-
"tailwindcss": "^3.4.
|
|
38
|
+
"tailwindcss": "^3.4.16",
|
|
39
|
+
"tailwindcss-config": "0.0.0"
|
|
38
40
|
},
|
|
39
41
|
"scripts": {
|
|
40
42
|
"dev": "tsup --watch --sourcemap",
|