Browse Source

Initial commit

master
Sven Slootweg 5 months ago
commit
2d7a573811
  1. 1
      .gitignore
  2. 33
      README.md
  3. 42
      index.js
  4. 15
      package.json
  5. 39
      yarn.lock

1
.gitignore

@ -0,0 +1 @@
node_modules

33
README.md

@ -0,0 +1,33 @@
# postcss-icss-find-imports
A PostCSS plugin for finding import statements in CSS that follows the ICSS specification, __but not removing them from the AST__, eg. for implementing dependency discovery.
This code was adapted from [css-loader](https://github.com/webpack-contrib/css-loader) and modified to work as a stand-alone plugin.
This documentation is rudimentary and will probably be improved at some point. Feel free to open an issue if something is unclear!
## License
```
This module is derived from: css-loader (https://github.com/webpack-contrib/css-loader)
(c) JS Foundation and other contributors
Modifications by:
(c) 2019, Sven Slootweg <admin@cryto.net>
Licensed under:
MIT (https://opensource.org/licenses/MIT)
```
## API
Exports a plugin that is compatible with PostCSS 8.
Takes no options upon initialization.
When applied, it will find import statements in the code, exposing them as the following types of `messages` (from plugin `postcss-icss-parser`):
- `import`: an import statement.
- `url`: The path/URL being imported from.
The import statements __are not removed__ from the AST.

42
index.js

@ -0,0 +1,42 @@
"use strict";
/*
This module is derived from: css-loader (https://github.com/webpack-contrib/css-loader)
(c) JS Foundation and other contributors
Modifications by:
(c) 2019, Sven Slootweg <admin@cryto.net>
Licensed under:
MIT (https://opensource.org/licenses/MIT)
*/
const icssUtils = require("icss-utils");
const loaderUtils = require("loader-utils");
const pluginName = 'postcss-icss-find-imports';
module.exports = function (_options = {}) {
return {
postcssPlugin: pluginName,
Once: (root, { result }) => {
let discoveredImports = new Set();
let { icssImports } = icssUtils.extractICSS(root, false);
for (let importUrl of Object.keys(icssImports)) {
discoveredImports.add(loaderUtils.parseString(importUrl));
}
for (let url of discoveredImports) {
result.messages.push({
pluginName: pluginName,
type: "import",
url: url
});
}
}
};
};
module.exports.postcss = true;

15
package.json

@ -0,0 +1,15 @@
{
"name": "postcss-icss-find-imports",
"version": "1.0.0",
"main": "index.js",
"repository": "https://git.cryto.net/joepie91/postcss-icss-find-imports.git",
"author": "Sven Slootweg <admin@cryto.net>",
"license": "MIT",
"dependencies": {
"icss-utils": "^5.1.0",
"loader-utils": "^2.0.0"
},
"peerDependencies": {
"postcss": "^8.2.6"
}
}

39
yarn.lock

@ -0,0 +1,39 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
big.js@^5.2.2:
version "5.2.2"
resolved "https://registry.yarnpkg.com/big.js/-/big.js-5.2.2.tgz#65f0af382f578bcdc742bd9c281e9cb2d7768328"
integrity sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==
emojis-list@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-3.0.0.tgz#5570662046ad29e2e916e71aae260abdff4f6a78"
integrity sha512-/kyM18EfinwXZbno9FyUGeFh87KC8HRQBQGildHZbEuRyWFOmv1U10o9BBp8XVZDVNNuQKyIGIu5ZYAAXJ0V2Q==
icss-utils@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/icss-utils/-/icss-utils-5.1.0.tgz#c6be6858abd013d768e98366ae47e25d5887b1ae"
integrity sha512-soFhflCVWLfRNOPU3iv5Z9VUdT44xFRbzjLsEzSr5AQmgqPMTHdU3PMT1Cf1ssx8fLNJDA1juftYl+PUcv3MqA==
json5@^2.1.2:
version "2.2.0"
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.0.tgz#2dfefe720c6ba525d9ebd909950f0515316c89a3"
integrity sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==
dependencies:
minimist "^1.2.5"
loader-utils@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.0.tgz#e4cace5b816d425a166b5f097e10cd12b36064b0"
integrity sha512-rP4F0h2RaWSvPEkD7BLDFQnvSf+nK+wr3ESUjNTyAGobqrijmW92zc+SO6d4p4B1wh7+B/Jg1mkQe5NYUEHtHQ==
dependencies:
big.js "^5.2.2"
emojis-list "^3.0.0"
json5 "^2.1.2"
minimist@^1.2.5:
version "1.2.5"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
Loading…
Cancel
Save