{"id":19652989,"url":"https://github.com/csstools/css-import-resolve","last_synced_at":"2025-04-28T17:31:06.393Z","repository":{"id":66028387,"uuid":"101770863","full_name":"csstools/css-import-resolve","owner":"csstools","description":"An algorithm for resolving imports in CSS","archived":false,"fork":false,"pushed_at":"2020-06-09T19:13:07.000Z","size":86,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-30T00:30:38.386Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://csstools.github.io/css-import-resolve/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/csstools.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-08-29T14:32:03.000Z","updated_at":"2023-07-24T21:11:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"f8d3b0e9-4443-4e1c-b33a-a97372976e20","html_url":"https://github.com/csstools/css-import-resolve","commit_stats":{"total_commits":11,"total_committers":1,"mean_commits":11.0,"dds":0.0,"last_synced_commit":"ced35539cc165650a973c85d18573396dc81ac92"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csstools%2Fcss-import-resolve","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csstools%2Fcss-import-resolve/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csstools%2Fcss-import-resolve/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csstools%2Fcss-import-resolve/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/csstools","download_url":"https://codeload.github.com/csstools/css-import-resolve/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223793929,"owners_count":17203893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T15:12:50.790Z","updated_at":"2024-11-11T15:12:51.636Z","avatar_url":"https://github.com/csstools.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CSS Import Resolve [\u003cimg src=\"https://jonneal.dev/css-logo.svg\" alt=\"CSS Logo\" width=\"90\" height=\"90\" align=\"right\"\u003e][css import resolve]\n\n[\u003cimg alt=\"NPM Version\" src=\"https://img.shields.io/npm/v/css-import-resolve.svg\" height=\"20\"\u003e][npm-url]\n[\u003cimg alt=\"Build Status\" src=\"https://img.shields.io/travis/csstools/css-import-resolve/master.svg\" height=\"20\"\u003e][cli-url]\n[\u003cimg alt=\"Support Chat\" src=\"https://img.shields.io/badge/chat-gitter-blue.svg\" height=\"20\"\u003e][git-url]\n\n[CSS Import Resolve] is an algorithm for resolving imports in CSS.\n\nSee the [CSS Import Resolve specification] for more details.\n\n```bash\nnpm install css-import-resolve\n```\n\n```js\nimport { resolveAsync } from 'css-import-resolve'\n\n// where `id` is location stylesheet you are resolving, and\nconst id = 'path/to/css'\n\n// where `cwd` is the current working directory\nconst cwd = process.cwd()\n\nresolveAsync(id, cwd).then(file =\u003e { /* file is an absolute path */ })\n```\n\n## Resolve Algorithm\n\nWhen `@import` is called, the following high-level algorithm is used to resolve\nthe location of the CSS file, found within `url(id)` from `cwd`:\n\n1. if `id` begins with `/`\n   1. `cwd` is the filesystem root\n2. resolve [as a file](#resolve-as-a-file) using `cwd/id` as `file`\n3. otherwise, resolve [as a directory](#resolve-as-a-directory) using `cwd/id`\n   as `dir`\n4. otherwise, if `id` does not begin with `/`, `./`, or `../`\n   1. resolve [as a module](#resolve-as-a-module) using `cwd` and `id`\n5. otherwise, throw `\"CSS Module not found\"`\n\n### Resolve as a File\n\n1. resolve `file` as the file\n2. otherwise, resolve `file.css` as the file\n\n### Resolve as a Directory\n\n1. resolve the JSON contents of `dir/package.json` as `pkg`\n   1. if `pkg` has an `exports.css.import` field\n      1. resolve `dir/pkg.exports.css.import` as the file\n   2. if `pkg` has an `exports.css.default` field\n      1. resolve `dir/pkg.exports.css.default` as the file\n   3. if `pkg` has an `exports.css` field\n      1. resolve `dir/pkg.exports.css` as the file\n   4. if `pkg` has a `style` field\n      1. resolve `dir/pkg.style` as the file\n   5. otherwise, resolve `dir/index.css` as the file\n\n### Resolve as a Module\n\n1. for each `dir` in the [node modules directory](#node-modules-directory)\n   using `cwd`\n   1. resolve [as a file](#resolve-as-a-file) using `dir/id` as `file`\n   2. otherwise, resolve [as a directory](#resolve-as-a-directory) using\n      `dir/id` as `dir`\n\n### Node Modules Directory\n\n1. `segments` is `cwd` split by `/`\n2. `count` is the length of `segments`\n3. `dirs` is an empty list\n4. while `count` is greater than `0`\n   1. if `segments[count]` is not `node_modules`\n      1. push a new item to `dirs` as the `/`-joined `segments[0 - count]` and\n         `node_modules`\n   2. `count` is `count` minus `1`\n5. return `dirs`\n\n## resolveSync\n\n```js\nimport { resolveSync } from 'css-import-resolve'\n\nconst fileOrNull = resolveSync('path/to/css', process.cwd())\n```\n\n## Options\n\n```js\nimport { resolveSync } from 'css-import-resolve'\n\nconst id = 'path/to/css'\nconst cwd = process.cwd()\n\n// resolve files as css modules\nconst opts = {\n  extensions: ['module.css'],\n  indexes: ['index.module.css'],\n  packageProps: ['exports.icss.import', 'exports.icss.default', 'exports.icss']\n}\n\nresolveSync(id, cwd, opts)\n```\n\n#### baseUrl\n\nThe `baseUrl` parameter sets the base directory used by non-relative paths during resolution.\n\n#### extensions\n\nThe `extensions` parameter sets the list of file extensions checked during resolution. Its default value is `[\"css\"]`.\n\n#### indexes\n\nThe `index` parameter sets the list of index files in a directory that are checked during resolution. Its default value is `[\"index.css\"]`.\n\n#### packageProps\n\nThe `packageProps` parameter sets the list of fields in a `package.json` that are checked during resolution. Its default value is `[\"exports.css.import\", \"exports.css.default\", \"exports.css\", \"style\"]`.\n\n#### fileResolverAsyncCache\n\nThe `fileResolverAsyncCache` parameter sets the object used to cache asynchronous results during resolution, allowing duplicate checks to resolve without revisiting a file system.\n\n#### fileResolverSyncCache\n\nThe `fileResolverSyncCache` parameter sets the object used to cache asynchronous results during resolution, allowing duplicate checks to resolve without revisiting a file system.\n\n[css import resolve]: https://github.com/csstools/css-import-resolve\n[css import resolve specification]: https://csstools.github.io/css-import-resolve/\n[cli-url]: https://travis-ci.org/csstools/css-import-resolve\n[git-url]: https://gitter.im/postcss/postcss\n[npm-url]: https://www.npmjs.com/package/css-import-resolve\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsstools%2Fcss-import-resolve","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcsstools%2Fcss-import-resolve","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsstools%2Fcss-import-resolve/lists"}