postcss-modules icon indicating copy to clipboard operation
postcss-modules copied to clipboard

Expose importer in resolve method

Open intrnl opened this issue 2 years ago • 2 comments

The resolve method should be given the filename that triggered the resolve, this is necessary especially for nested imports where the file could be located somewhere else.

postcssModules({
  resolve (id, from) {
    return path.resolve(from, id);
  },
});

intrnl avatar Mar 05 '22 08:03 intrnl

The resolver method should also be passed when resolving nested dependencies, currently the following case is impossible to do:

Let's say that the project root is also aliased to ~

/* styles/controls.css */
.control {
  border-radius: 4px;
  /* ... */
}

/* components/Button/Button.module.css */
.button {
  composes: control from '~/styles/controls.css';
  /* ... */
}

/* components/Menu/MenuItem.module.css */
.button {
  composes: button from '~/components/Button/Button.module.css';
  /* ... */
}

MenuItem.module.css succeeds in resolving Button.module.css, but because the resolve method isn't passed when parsing the source, it fails when trying to resolve its dependencies.

intrnl avatar Mar 05 '22 13:03 intrnl

@madyankin @intrnl created a PR for this: #142 which implements this behavior in a non-breaking way.

KingSora avatar Oct 11 '22 16:10 KingSora