tailwindcss-injector 0.1.0 → 0.1.2

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 CHANGED
@@ -223,6 +223,7 @@ var _tailwindcssconfig = require('tailwindcss-config');
223
223
 
224
224
  // src/utils.ts
225
225
  init_cjs_shims();
226
+ var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto);
226
227
  var _path = require('path'); var _path2 = _interopRequireDefault(_path);
227
228
 
228
229
  // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
@@ -314,6 +315,11 @@ var defuOverrideArray = createDefu((obj, key, value) => {
314
315
  return true;
315
316
  }
316
317
  });
318
+ function md5(input) {
319
+ const hash = _crypto2.default.createHash("md5");
320
+ hash.update(input);
321
+ return hash.digest("hex");
322
+ }
317
323
 
318
324
  // src/wxml.ts
319
325
  init_cjs_shims();
@@ -321,6 +327,8 @@ init_cjs_shims();
321
327
  var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
322
328
  var _htmlparser2 = require('htmlparser2');
323
329
  var _magicstring = require('magic-string'); var _magicstring2 = _interopRequireDefault(_magicstring);
330
+ var hashMap = /* @__PURE__ */ new Map();
331
+ var depsMap = /* @__PURE__ */ new Map();
324
332
  var srcImportTagsMap = {
325
333
  // audio: ['src', 'poster'],
326
334
  // video: ['src', 'poster'],
@@ -378,23 +386,34 @@ function processWxml(wxml) {
378
386
  parser.end();
379
387
  return deps;
380
388
  }
381
- async function getDepFiles(file) {
382
- const set2 = /* @__PURE__ */ new Set();
383
- async function getDep(filepath) {
384
- if (await _fsextra2.default.exists(filepath)) {
385
- const dirname = _path2.default.dirname(filepath);
386
- set2.add(filepath);
387
- const wxml = await _fsextra2.default.readFile(filepath, "utf8");
388
- const deps = await processWxml(wxml);
389
- for (const { value } of deps) {
390
- const p = _path2.default.resolve(dirname, value);
391
- if (!set2.has(p)) {
392
- await getDep(p);
393
- }
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);
394
410
  }
395
411
  }
396
412
  }
397
- await getDep(file);
413
+ }
414
+ async function getDepFiles(file) {
415
+ const set2 = /* @__PURE__ */ new Set();
416
+ await getDep(file, set2);
398
417
  return set2;
399
418
  }
400
419
 
@@ -415,11 +434,10 @@ var creator = (options) => {
415
434
  postcssPlugin: "post",
416
435
  async Once(root, helpers) {
417
436
  if (filter(_optionalChain([root, 'access', _ => _.source, 'optionalAccess', _2 => _2.input]))) {
418
- let _root = root;
419
437
  for (const params of directiveParams) {
420
438
  const node = root.nodes.find((x) => x.type === "atrule" && x.params === params);
421
439
  if (!node) {
422
- _root = _root.prepend(helpers.atRule({ name: "tailwind", params }));
440
+ root.prepend(helpers.atRule({ name: "tailwind", params }));
423
441
  }
424
442
  }
425
443
  const cfg = typeof config === "function" ? config(_optionalChain([root, 'access', _3 => _3.source, 'optionalAccess', _4 => _4.input])) : config;
@@ -446,10 +464,11 @@ var creator = (options) => {
446
464
  }
447
465
  }
448
466
  }
449
- const { root: newRoot } = await _postcss2.default.call(void 0, [
467
+ await _postcss2.default.call(void 0, [
450
468
  _tailwindcss2.default.call(void 0, tailwindcssConfig)
451
- ]).process(_root);
452
- root.replaceWith(newRoot);
469
+ ]).process(root, {
470
+ from: _optionalChain([root, 'access', _7 => _7.source, 'optionalAccess', _8 => _8.input, 'access', _9 => _9.file])
471
+ });
453
472
  }
454
473
  }
455
474
  }
package/dist/postcss.js CHANGED
@@ -223,6 +223,7 @@ import { loadConfig } from "tailwindcss-config";
223
223
 
224
224
  // src/utils.ts
225
225
  init_esm_shims();
226
+ import crypto from "node:crypto";
226
227
  import path from "node:path";
227
228
 
228
229
  // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
@@ -314,6 +315,11 @@ var defuOverrideArray = createDefu((obj, key, value) => {
314
315
  return true;
315
316
  }
316
317
  });
318
+ function md5(input) {
319
+ const hash = crypto.createHash("md5");
320
+ hash.update(input);
321
+ return hash.digest("hex");
322
+ }
317
323
 
318
324
  // src/wxml.ts
319
325
  init_esm_shims();
@@ -321,6 +327,8 @@ import path2 from "node:path";
321
327
  import fs from "fs-extra";
322
328
  import { Parser } from "htmlparser2";
323
329
  import MagicString from "magic-string";
330
+ var hashMap = /* @__PURE__ */ new Map();
331
+ var depsMap = /* @__PURE__ */ new Map();
324
332
  var srcImportTagsMap = {
325
333
  // audio: ['src', 'poster'],
326
334
  // video: ['src', 'poster'],
@@ -378,23 +386,34 @@ function processWxml(wxml) {
378
386
  parser.end();
379
387
  return deps;
380
388
  }
381
- async function getDepFiles(file) {
382
- const set2 = /* @__PURE__ */ new Set();
383
- async function getDep(filepath) {
384
- if (await fs.exists(filepath)) {
385
- const dirname = path2.dirname(filepath);
386
- set2.add(filepath);
387
- const wxml = await fs.readFile(filepath, "utf8");
388
- const deps = await processWxml(wxml);
389
- for (const { value } of deps) {
390
- const p = path2.resolve(dirname, value);
391
- if (!set2.has(p)) {
392
- await getDep(p);
393
- }
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);
394
410
  }
395
411
  }
396
412
  }
397
- await getDep(file);
413
+ }
414
+ async function getDepFiles(file) {
415
+ const set2 = /* @__PURE__ */ new Set();
416
+ await getDep(file, set2);
398
417
  return set2;
399
418
  }
400
419
 
@@ -415,11 +434,10 @@ var creator = (options) => {
415
434
  postcssPlugin: "post",
416
435
  async Once(root, helpers) {
417
436
  if (filter(root.source?.input)) {
418
- let _root = root;
419
437
  for (const params of directiveParams) {
420
438
  const node = root.nodes.find((x) => x.type === "atrule" && x.params === params);
421
439
  if (!node) {
422
- _root = _root.prepend(helpers.atRule({ name: "tailwind", params }));
440
+ root.prepend(helpers.atRule({ name: "tailwind", params }));
423
441
  }
424
442
  }
425
443
  const cfg = typeof config === "function" ? config(root.source?.input) : config;
@@ -446,10 +464,11 @@ var creator = (options) => {
446
464
  }
447
465
  }
448
466
  }
449
- const { root: newRoot } = await postcss([
467
+ await postcss([
450
468
  tailwindcss(tailwindcssConfig)
451
- ]).process(_root);
452
- root.replaceWith(newRoot);
469
+ ]).process(root, {
470
+ from: root.source?.input.file
471
+ });
453
472
  }
454
473
  }
455
474
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tailwindcss-injector",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "description": "tsup(esbuild) build package template",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",