tailwindcss-injector 0.1.0 → 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 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
 
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
 
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.1",
5
5
  "description": "tsup(esbuild) build package template",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",