Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@eik/postcss-import-map

Package Overview
Dependencies
Maintainers
4
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eik/postcss-import-map - npm Package Compare versions

Comparing version
2.0.2
to
2.0.3
+7
-0
CHANGELOG.md

@@ -0,1 +1,8 @@

## [2.0.3](https://github.com/eik-lib/postcss-import-map/compare/v2.0.2...v2.0.3) (2020-11-19)
### Bug Fixes
* better interop with postcss-import ([965d5f5](https://github.com/eik-lib/postcss-import-map/commit/965d5f52bc9585817c5c0b9fda0d1868df009a4a))
## [2.0.2](https://github.com/eik-lib/postcss-import-map/compare/v2.0.1...v2.0.2) (2020-11-19)

@@ -2,0 +9,0 @@

+34
-17

@@ -51,6 +51,2 @@ 'use strict';

// The resolve option in postcss-import doesn't support async functions or promises,
// thus we have to workaround it
const mapping = new Map();
// @TODO this could be a @eik/import-map-utils package

@@ -62,4 +58,3 @@ async function populateImportMap({

} = {}) {
// Reset the map to avoid pollution
mapping.clear();
const mapping = new Map();

@@ -87,12 +82,20 @@ const importmapUrls = await readEikJSONMaps(eikPath);

});
return mapping;
}
module.exports = ({ path, urls, imports } = {}) => {
// Eagerly start resolving
const mapFetch = populateImportMap({ path, urls, imports });
return {
postcssPlugin: '@eik/postcss-import-map',
AtRule: {
import: async (decl) => {
await mapFetch;
prepare() {
// Avoid parsing things more than necessary
const processed = new WeakMap();
// Eagerly start resolving
const mapFetch = populateImportMap({ path, urls, imports });
// Reused replace logic
const applyImportMap = (mapping, decl) => {
if (processed.has(decl)) {
return;
}
let key;

@@ -116,3 +119,22 @@ // First check if it's possibly using syntax like url()

}
},
// Cache we've processed this
processed.set(decl, true);
};
return {
// Run initially once, this is to ensure it runs before postcss-import
async Once(root) {
const mapping = await mapFetch;
root.walkAtRules('import', (decl) => {
applyImportMap(mapping, decl);
});
},
AtRule: {
import: async (decl) => {
const mapping = await mapFetch;
applyImportMap(mapping, decl);
},
},
};
},

@@ -122,7 +144,2 @@ };

// Useful for integrating with other plugins such as postcss-import
module.exports.filter = function filter(url) {
return !mapping.has(url);
};
module.exports.postcss = true;
{
"name": "@eik/postcss-import-map",
"version": "2.0.2",
"version": "2.0.3",
"description": "PostCSS plugin that uses Eik defined import map files to transform bare import specifiers to absolute URLs in @import rules",

@@ -5,0 +5,0 @@ "main": "dist/plugin.js",