tailwindcss-config 2.0.4 → 2.0.6

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/index.cjs CHANGED
@@ -27,10 +27,49 @@ let node_process = require("node:process");
27
27
  node_process = __toESM(node_process, 1);
28
28
  let jiti = require("jiti");
29
29
  let lilconfig = require("lilconfig");
30
+ let node_module = require("node:module");
30
31
  let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
32
+ //#region src/module-cache.ts
33
+ const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
34
+ /** 配置及本地辅助模块每次重新执行,已安装依赖继续复用原生缓存。 */
35
+ function clearConfigModuleCache(filename) {
36
+ const root = require$1.cache[filename] ?? require$1.cache[require$1.resolve(filename)];
37
+ const visited = /* @__PURE__ */ new Set();
38
+ const childrenByParent = /* @__PURE__ */ new Map();
39
+ if (root && "evalModule" in root.require) {
40
+ for (const module of Object.values(require$1.cache)) if (module?.parent?.filename) {
41
+ const children = childrenByParent.get(module.parent.filename) ?? [];
42
+ children.push(module);
43
+ childrenByParent.set(module.parent.filename, children);
44
+ }
45
+ }
46
+ function visit(module) {
47
+ if (visited.has(module)) return;
48
+ visited.add(module);
49
+ if (module !== root) {
50
+ let directory = node_path.default.dirname(module.filename);
51
+ while (node_path.default.dirname(directory) !== directory) {
52
+ if (node_path.default.basename(directory) === "node_modules") return;
53
+ directory = node_path.default.dirname(directory);
54
+ }
55
+ }
56
+ for (const child of [...module.children, ...childrenByParent.get(module.filename) ?? []]) visit(child);
57
+ if (module.parent) module.parent.children = module.parent.children.filter((child) => child !== module);
58
+ delete require$1.cache[module.filename];
59
+ }
60
+ if (root) visit(root);
61
+ }
62
+ //#endregion
31
63
  //#region src/index.ts
32
- const jiti$1 = (0, jiti.createJiti)(require("url").pathToFileURL(__filename).href);
33
64
  async function loadConfig(options) {
65
+ const jiti$1 = (0, jiti.createJiti)(require("url").pathToFileURL(__filename).href, {
66
+ moduleCache: true,
67
+ fsCache: true
68
+ });
69
+ const load = (filename, source) => {
70
+ clearConfigModuleCache(filename);
71
+ return jiti$1.evalModule(source, { filename });
72
+ };
34
73
  const { config, cwd, moduleName } = (0, _weapp_tailwindcss_shared.defuOverrideArray)(options, {
35
74
  cwd: node_process.default.cwd(),
36
75
  moduleName: "tailwind"
@@ -45,12 +84,12 @@ async function loadConfig(options) {
45
84
  `${moduleName}.config.mts`
46
85
  ],
47
86
  loaders: {
48
- ".js": jiti$1,
49
- ".cjs": jiti$1,
50
- ".mjs": jiti$1,
51
- ".ts": jiti$1,
52
- ".cts": jiti$1,
53
- ".mts": jiti$1
87
+ ".js": load,
88
+ ".cjs": load,
89
+ ".mjs": load,
90
+ ".ts": load,
91
+ ".cts": load,
92
+ ".mts": load
54
93
  }
55
94
  });
56
95
  if (typeof config === "string" && config) {
package/dist/index.js CHANGED
@@ -1,11 +1,50 @@
1
+ import { createRequire } from "node:module";
1
2
  import path from "node:path";
2
3
  import process from "node:process";
3
4
  import { createJiti } from "jiti";
4
5
  import { lilconfig } from "lilconfig";
5
6
  import { defuOverrideArray } from "@weapp-tailwindcss/shared";
7
+ //#region src/module-cache.ts
8
+ const require = createRequire(import.meta.url);
9
+ /** 配置及本地辅助模块每次重新执行,已安装依赖继续复用原生缓存。 */
10
+ function clearConfigModuleCache(filename) {
11
+ const root = require.cache[filename] ?? require.cache[require.resolve(filename)];
12
+ const visited = /* @__PURE__ */ new Set();
13
+ const childrenByParent = /* @__PURE__ */ new Map();
14
+ if (root && "evalModule" in root.require) {
15
+ for (const module of Object.values(require.cache)) if (module?.parent?.filename) {
16
+ const children = childrenByParent.get(module.parent.filename) ?? [];
17
+ children.push(module);
18
+ childrenByParent.set(module.parent.filename, children);
19
+ }
20
+ }
21
+ function visit(module) {
22
+ if (visited.has(module)) return;
23
+ visited.add(module);
24
+ if (module !== root) {
25
+ let directory = path.dirname(module.filename);
26
+ while (path.dirname(directory) !== directory) {
27
+ if (path.basename(directory) === "node_modules") return;
28
+ directory = path.dirname(directory);
29
+ }
30
+ }
31
+ for (const child of [...module.children, ...childrenByParent.get(module.filename) ?? []]) visit(child);
32
+ if (module.parent) module.parent.children = module.parent.children.filter((child) => child !== module);
33
+ delete require.cache[module.filename];
34
+ }
35
+ if (root) visit(root);
36
+ }
37
+ //#endregion
6
38
  //#region src/index.ts
7
- const jiti = createJiti(import.meta.url);
8
39
  async function loadConfig(options) {
40
+ const jiti = createJiti(import.meta.url, {
41
+ moduleCache: true,
42
+ fsCache: true
43
+ });
44
+ const load = (filename, source) => {
45
+ clearConfigModuleCache(filename);
46
+ return jiti.evalModule(source, { filename });
47
+ };
9
48
  const { config, cwd, moduleName } = defuOverrideArray(options, {
10
49
  cwd: process.cwd(),
11
50
  moduleName: "tailwind"
@@ -20,12 +59,12 @@ async function loadConfig(options) {
20
59
  `${moduleName}.config.mts`
21
60
  ],
22
61
  loaders: {
23
- ".js": jiti,
24
- ".cjs": jiti,
25
- ".mjs": jiti,
26
- ".ts": jiti,
27
- ".cts": jiti,
28
- ".mts": jiti
62
+ ".js": load,
63
+ ".cjs": load,
64
+ ".mjs": load,
65
+ ".ts": load,
66
+ ".cts": load,
67
+ ".mts": load
29
68
  }
30
69
  });
31
70
  if (typeof config === "string" && config) {
@@ -0,0 +1,2 @@
1
+ /** 配置及本地辅助模块每次重新执行,已安装依赖继续复用原生缓存。 */
2
+ export declare function clearConfigModuleCache(filename: string): void;
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "tailwindcss-config",
3
3
  "type": "module",
4
- "version": "2.0.4",
4
+ "version": "2.0.6",
5
5
  "description": "Tailwind CSS configuration loader for cross-platform toolchains. 跨端工具链的 Tailwind CSS 配置加载器。",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
8
8
  "homepage": "https://tw.weapp.dev",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git+https://github.com/sonofmagic/weapp-tailwindcss.git",
11
+ "url": "git+https://github.com/weapp-tailwindcss/weapp-tailwindcss.git",
12
12
  "directory": "packages/tailwindcss-config"
13
13
  },
14
14
  "bugs": {
15
- "url": "https://github.com/sonofmagic/weapp-tailwindcss/issues"
15
+ "url": "https://github.com/weapp-tailwindcss/weapp-tailwindcss/issues"
16
16
  },
17
17
  "keywords": [
18
18
  "tailwindcss",
@@ -41,7 +41,7 @@
41
41
  "registry": "https://registry.npmjs.org"
42
42
  },
43
43
  "dependencies": {
44
- "@weapp-tailwindcss/shared": "2.0.3",
44
+ "@weapp-tailwindcss/shared": "2.0.4",
45
45
  "jiti": "2.7.0",
46
46
  "lilconfig": "^3.1.3"
47
47
  },