postcss-modules 9.1.2 → 9.1.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 9.1.4
4
+
5
+ ### Fixed
6
+
7
+ - Use synchronous Node module hooks where available so the CSS loader runs without the Node 26 `module.register` deprecation warning, while retaining support for Node 20.6.
8
+
9
+ ### Internal
10
+
11
+ - Update vulnerable and outdated development dependencies, and use Node 26 for the default Docker build.
12
+
13
+ ## 9.1.3
14
+
15
+ ### Fixed
16
+
17
+ - Reject circular `composes` and `@value` imports, including paths through directory symlinks, with an error naming the dependency chain instead of loading the files repeatedly. [#175](https://github.com/madyankin/postcss-modules/issues/175)
18
+
3
19
  ## 9.1.1
4
20
 
5
21
  ### Fixed
package/README.md CHANGED
@@ -185,7 +185,7 @@ declare module "*.css" {
185
185
  - **ESM only.** `require("./x.css")` is not supported; the underlying transform is async and cannot be expressed through `require.extensions`. Use a `.mjs` entrypoint, or `"type": "module"` in `package.json`.
186
186
  - **Tokens only, no CSS output.** The loader returns the class-name map but does not emit the transformed CSS. SSR setups that need the stylesheet should use a bundler or call `postcss([require("postcss-modules")(...)]).process(...)` directly to capture both.
187
187
  - **No HMR, no watch mode** — by design. Use a bundler for those.
188
- - **Node ≥ 20.6.** `module.register` stabilized there.
188
+ - **Node ≥ 20.6.** The loader uses `module.registerHooks` where available and falls back to `module.register` on older Node releases.
189
189
 
190
190
  ### Generating scoped names
191
191
 
@@ -31,14 +31,27 @@ class FileSystemLoader {
31
31
  this.#store = new _DependencyStore.default();
32
32
  this.#fileSystem = fileSystem;
33
33
  }
34
- async fetch(_request, relativeTo, _dependencyPath) {
34
+ async fetch(_request, relativeTo, _dependencyPath, ancestors = []) {
35
35
  const request = this.#normalizeRequest(_request);
36
36
  const dependencyPath = this.#getOrCreateDependencyPath(_dependencyPath);
37
37
  const { filePath, sourcePath } = await this.#resolvePaths(request, relativeTo);
38
+ const identity = await this.#fileIdentity(filePath);
39
+ if (ancestors.some((ancestor)=>ancestor.identity === identity)) {
40
+ throw new Error(`Circular dependency: ${[
41
+ ...ancestors.map((ancestor)=>ancestor.path),
42
+ filePath
43
+ ].join(" -> ")}`);
44
+ }
38
45
  const cachedTokens = this.#store.getTokens(filePath);
39
46
  if (cachedTokens) return cachedTokens;
40
47
  const source = await this.#readFile(filePath);
41
- const result = await this.#processSource(source, sourcePath, dependencyPath);
48
+ const result = await this.#processSource(source, sourcePath, dependencyPath, [
49
+ ...ancestors,
50
+ {
51
+ identity,
52
+ path: filePath
53
+ }
54
+ ]);
42
55
  this.#recordDependency(filePath, dependencyPath, result);
43
56
  const { exportTokens } = result;
44
57
  return exportTokens;
@@ -76,8 +89,19 @@ class FileSystemLoader {
76
89
  });
77
90
  });
78
91
  }
79
- #processSource(source, sourcePath, dependencyPath) {
80
- return this.#processImportedCSS(source, sourcePath, dependencyPath, this.fetch.bind(this));
92
+ #fileIdentity(filePath) {
93
+ if (typeof this.#fileSystem.realpath !== "function") return filePath;
94
+ return new Promise((resolve, reject)=>{
95
+ this.#fileSystem.realpath(filePath, (error, resolvedPath)=>{
96
+ if (error) reject(error);
97
+ else resolve(resolvedPath);
98
+ });
99
+ });
100
+ }
101
+ #processSource(source, sourcePath, dependencyPath, ancestors) {
102
+ // Keep ancestry per branch: concurrent imports may share an acyclic dependency.
103
+ const fetch = (request, relativeTo, childDependencyPath)=>this.fetch(request, relativeTo, childDependencyPath, ancestors);
104
+ return this.#processImportedCSS(source, sourcePath, dependencyPath, fetch);
81
105
  }
82
106
  #recordDependency(filePath, dependencyPath, { injectableSource, exportTokens }) {
83
107
  this.#store.record({
package/build/index.js CHANGED
@@ -6,6 +6,7 @@ const _fs = require("fs");
6
6
  const _pluginFactory = require("./pluginFactory");
7
7
  const fileSystem = {
8
8
  readFile: _fs.readFile,
9
+ realpath: _fs.realpath,
9
10
  writeFile: _fs.writeFile
10
11
  };
11
12
  module.exports = (opts = {})=>(0, _pluginFactory.makePlugin)(opts, {
package/build/loader.mjs CHANGED
@@ -1,3 +1,8 @@
1
- import { register } from "node:module";
1
+ import * as nodeModule from "node:module";
2
+ import { load } from "./loaderHooksSync.mjs";
2
3
 
3
- register("./loaderHooks.mjs", import.meta.url);
4
+ if (typeof nodeModule.registerHooks === "function") {
5
+ nodeModule.registerHooks({ load });
6
+ } else {
7
+ nodeModule.register("./loaderHooks.mjs", import.meta.url);
8
+ }
@@ -1,22 +1,10 @@
1
- import { readFile } from "node:fs/promises";
2
- import { fileURLToPath } from "node:url";
3
- import { processCSS } from "./processCSS.js";
4
- import { loadConfig } from "./loadConfig.mjs";
5
-
6
- let configPromise;
7
- function getConfig() {
8
- if (!configPromise) configPromise = loadConfig();
9
- return configPromise;
10
- }
1
+ import { loadCSS } from "./loaderRuntime.mjs";
11
2
 
12
3
  export async function load(url, context, nextLoad) {
13
4
  if (!url.startsWith("file:") || !url.endsWith(".css")) {
14
5
  return nextLoad(url, context);
15
6
  }
16
- const filename = fileURLToPath(url);
17
- const source = await readFile(filename, "utf8");
18
- const opts = await getConfig();
19
- const tokens = await processCSS(source, filename, opts);
7
+ const tokens = await loadCSS(url);
20
8
  return {
21
9
  format: "module",
22
10
  source: `export default ${JSON.stringify(tokens)};\n`,
@@ -0,0 +1,12 @@
1
+ const runtimeUrl = new URL("./loaderRuntime.mjs", import.meta.url).href;
2
+
3
+ export function load(url, context, nextLoad) {
4
+ if (!url.startsWith("file:") || !url.endsWith(".css")) {
5
+ return nextLoad(url, context);
6
+ }
7
+ return {
8
+ format: "module",
9
+ source: `import { loadCSS } from ${JSON.stringify(runtimeUrl)};\nexport default await loadCSS(${JSON.stringify(url)});\n`,
10
+ shortCircuit: true,
11
+ };
12
+ }
@@ -0,0 +1,17 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { fileURLToPath } from "node:url";
3
+ import { processCSS } from "./processCSS.js";
4
+ import { loadConfig } from "./loadConfig.mjs";
5
+
6
+ let configPromise;
7
+ function getConfig() {
8
+ if (!configPromise) configPromise = loadConfig();
9
+ return configPromise;
10
+ }
11
+
12
+ export async function loadCSS(url) {
13
+ const filename = fileURLToPath(url);
14
+ const source = await readFile(filename, "utf8");
15
+ const opts = await getConfig();
16
+ return processCSS(source, filename, opts);
17
+ }
@@ -18,6 +18,7 @@ function _interop_require_default(obj) {
18
18
  }
19
19
  const fileSystem = {
20
20
  readFile: _fs.readFile,
21
+ realpath: _fs.realpath,
21
22
  writeFile: _fs.writeFile
22
23
  };
23
24
  async function processCSS(source, filename, opts = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-modules",
3
- "version": "9.1.2",
3
+ "version": "9.1.4",
4
4
  "description": "PostCSS plugin to use CSS Modules everywhere",
5
5
  "main": "build/index.js",
6
6
  "types": "index.d.ts",
@@ -43,20 +43,20 @@
43
43
  "postcss": "^8.0.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@eslint/js": "^9.39.4",
46
+ "@eslint/js": "^9.39.5",
47
47
  "@swc/cli": "^0.8.1",
48
- "@swc/core": "^1.15.43",
48
+ "@swc/core": "^1.16.22",
49
49
  "@swc/jest": "^0.2.39",
50
- "autoprefixer": "^10.5.2",
51
- "eslint": "^9.39.0",
50
+ "autoprefixer": "^10.7.0",
51
+ "eslint": "^9.39.5",
52
52
  "eslint-plugin-import": "^2.32.0",
53
- "eslint-plugin-jest": "^29.15.4",
54
- "globals": "^17.7.0",
53
+ "eslint-plugin-jest": "^29.17.1",
54
+ "globals": "^17.14.0",
55
55
  "husky": "^9.1.7",
56
- "jest": "^30.4.2",
57
- "lint-staged": "^17.0.8",
56
+ "jest": "30.4.2",
57
+ "lint-staged": "^17.6.2",
58
58
  "postcss": "^8.5.16",
59
- "prettier": "^3.9.4"
59
+ "prettier": "^3.10.1"
60
60
  },
61
61
  "engines": {
62
62
  "node": ">=20.6"
@@ -66,8 +66,11 @@
66
66
  "prepare": "husky || true"
67
67
  },
68
68
  "overrides": {
69
- "glob": "^12.0.0",
70
- "file-type": "^22.0.0"
69
+ "glob": "^14.0.6",
70
+ "file-type": "^22.0.0",
71
+ "@swc/cli": {
72
+ "minimatch": "^11.0.9"
73
+ }
71
74
  },
72
75
  "lint-staged": {
73
76
  "*.{json,md}": [