@eik/postcss-plugin 3.0.13 → 3.0.14
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 +7 -0
- package/package.json +16 -16
- package/src/plugin.js +33 -29
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [3.0.14](https://github.com/eik-lib/postcss-import-map/compare/v3.0.13...v3.0.14) (2024-03-06)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update dependency @eik/common to v4.0.0-next.7 ([#299](https://github.com/eik-lib/postcss-import-map/issues/299)) ([23eaca9](https://github.com/eik-lib/postcss-import-map/commit/23eaca92e3d641f4d8a1ecd365f72e982b3495c9))
|
|
7
|
+
|
|
1
8
|
## [3.0.13](https://github.com/eik-lib/postcss-import-map/compare/v3.0.12...v3.0.13) (2023-08-23)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eik/postcss-plugin",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.14",
|
|
4
4
|
"description": "PostCSS plugin that uses Eik defined import map files to transform bare import specifiers to absolute URLs in @import rules",
|
|
5
5
|
"main": "src/plugin.js",
|
|
6
6
|
"files": [
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"src/"
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
|
-
"test": "tap test/*.js --
|
|
13
|
-
"test:snapshot": "TAP_SNAPSHOT=1 tap test/*.js --
|
|
12
|
+
"test": "tap test/*.js --disable-coverage --allow-empty-coverage",
|
|
13
|
+
"test:snapshot": "TAP_SNAPSHOT=1 tap test/*.js --disable-coverage --allow-empty-coverage",
|
|
14
14
|
"lint": "eslint .",
|
|
15
15
|
"lint:fix": "eslint . --fix"
|
|
16
16
|
},
|
|
@@ -33,23 +33,23 @@
|
|
|
33
33
|
"homepage": "https://github.com/eik-lib/postcss-import-map#readme",
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@semantic-release/changelog": "6.0.3",
|
|
36
|
-
"@semantic-release/commit-analyzer": "
|
|
36
|
+
"@semantic-release/commit-analyzer": "11.1.0",
|
|
37
37
|
"@semantic-release/git": "10.0.1",
|
|
38
|
-
"@semantic-release/github": "
|
|
39
|
-
"@semantic-release/npm": "
|
|
40
|
-
"@semantic-release/release-notes-generator": "
|
|
41
|
-
"eslint": "8.
|
|
38
|
+
"@semantic-release/github": "9.2.6",
|
|
39
|
+
"@semantic-release/npm": "11.0.3",
|
|
40
|
+
"@semantic-release/release-notes-generator": "12.1.0",
|
|
41
|
+
"eslint": "8.57.0",
|
|
42
42
|
"eslint-config-airbnb-base": "15.0.0",
|
|
43
|
-
"eslint-plugin-import": "2.
|
|
44
|
-
"eslint-config-prettier": "
|
|
45
|
-
"fastify": "4.
|
|
46
|
-
"postcss": "8.4.
|
|
47
|
-
"rollup": "
|
|
48
|
-
"semantic-release": "
|
|
49
|
-
"tap": "
|
|
43
|
+
"eslint-plugin-import": "2.29.1",
|
|
44
|
+
"eslint-config-prettier": "9.1.0",
|
|
45
|
+
"fastify": "4.26.2",
|
|
46
|
+
"postcss": "8.4.31",
|
|
47
|
+
"rollup": "4.12.1",
|
|
48
|
+
"semantic-release": "23.0.2",
|
|
49
|
+
"tap": "18.7.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@eik/common": "4.0.0-next.
|
|
52
|
+
"@eik/common-config-loader": "4.0.0-next.12",
|
|
53
53
|
"css-url-parser": "1.1.3",
|
|
54
54
|
"node-fetch": "2.7.0"
|
|
55
55
|
},
|
package/src/plugin.js
CHANGED
|
@@ -1,46 +1,47 @@
|
|
|
1
1
|
/* eslint-disable no-restricted-syntax, no-shadow */
|
|
2
2
|
|
|
3
3
|
const parseCssUrls = require('css-url-parser');
|
|
4
|
-
const {
|
|
4
|
+
const { getDefaults } = require('@eik/common-config-loader');
|
|
5
5
|
const fetch = require('node-fetch');
|
|
6
6
|
|
|
7
7
|
const notUrl = (url) => url.substr(0, 4) !== 'http';
|
|
8
8
|
|
|
9
9
|
async function fetchImportMaps(urls = []) {
|
|
10
10
|
try {
|
|
11
|
-
const maps = urls.map((map) =>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
const maps = urls.map((map) =>
|
|
12
|
+
fetch(map).then((result) => {
|
|
13
|
+
if (result.status === 404) {
|
|
14
|
+
throw new Error('Import map could not be found on server');
|
|
15
|
+
} else if (result.status >= 400 && result.status < 500) {
|
|
16
|
+
throw new Error('Server rejected client request');
|
|
17
|
+
} else if (result.status >= 500) {
|
|
18
|
+
throw new Error('Server error');
|
|
19
|
+
}
|
|
20
|
+
return result.json();
|
|
21
|
+
})
|
|
22
|
+
);
|
|
21
23
|
return await Promise.all(maps);
|
|
22
24
|
} catch (err) {
|
|
23
25
|
throw new Error(
|
|
24
|
-
`Unable to load import map file from server: ${err.message}
|
|
26
|
+
`Unable to load import map file from server: ${err.message}`
|
|
25
27
|
);
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
const validate = (map) =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (notUrl(value)) {
|
|
33
|
-
throw Error(`Import specifier can NOT be mapped to a bare import statement. Import specifier "${key}" is being wrongly mapped to "${value}"`);
|
|
34
|
-
}
|
|
31
|
+
const validate = (map) =>
|
|
32
|
+
Object.keys(map.imports).map((key) => {
|
|
33
|
+
const value = map.imports[key];
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
if (notUrl(value)) {
|
|
36
|
+
throw Error(
|
|
37
|
+
`Import specifier can NOT be mapped to a bare import statement. Import specifier "${key}" is being wrongly mapped to "${value}"`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
} = {}) => {
|
|
41
|
+
return { key, value };
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
module.exports = ({ path = process.cwd(), maps = [], urls = [] } = {}) => {
|
|
44
45
|
const pMaps = Array.isArray(maps) ? maps : [maps];
|
|
45
46
|
const pUrls = Array.isArray(urls) ? urls : [urls];
|
|
46
47
|
|
|
@@ -91,18 +92,21 @@ module.exports = ({
|
|
|
91
92
|
// Run initially once, this is to ensure it runs before postcss-import
|
|
92
93
|
async Once(root) {
|
|
93
94
|
// Load eik config from eik.json or package.json
|
|
94
|
-
const config = await
|
|
95
|
+
const config = await getDefaults(path);
|
|
95
96
|
|
|
96
97
|
// Fetch import maps from the server
|
|
97
|
-
const fetched = await fetchImportMaps([
|
|
98
|
-
|
|
98
|
+
const fetched = await fetchImportMaps([
|
|
99
|
+
...config.map,
|
|
100
|
+
...pUrls,
|
|
101
|
+
]);
|
|
102
|
+
|
|
99
103
|
const allImportMaps = [...fetched, ...pMaps];
|
|
100
104
|
allImportMaps.forEach((item) => {
|
|
101
105
|
const i = validate(item);
|
|
102
106
|
i.forEach((obj) => {
|
|
103
107
|
mapping.set(obj.key, obj.value);
|
|
104
108
|
});
|
|
105
|
-
})
|
|
109
|
+
});
|
|
106
110
|
|
|
107
111
|
root.walkAtRules('import', (decl) => {
|
|
108
112
|
applyImportMap(mapping, decl);
|