@eik/postcss-plugin 3.0.12 → 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.
Files changed (3) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/package.json +17 -17
  3. package/src/plugin.js +33 -29
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
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
+
8
+ ## [3.0.13](https://github.com/eik-lib/postcss-import-map/compare/v3.0.12...v3.0.13) (2023-08-23)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **deps:** update dependency node-fetch to v2.7.0 ([d208362](https://github.com/eik-lib/postcss-import-map/commit/d2083625d7ca75b93fde704e1c52bc3038d785fb))
14
+
1
15
  ## [3.0.12](https://github.com/eik-lib/postcss-import-map/compare/v3.0.11...v3.0.12) (2023-08-19)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eik/postcss-plugin",
3
- "version": "3.0.12",
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 --no-coverage",
13
- "test:snapshot": "TAP_SNAPSHOT=1 tap test/*.js --no-coverage",
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,25 +33,25 @@
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": "9.0.2",
36
+ "@semantic-release/commit-analyzer": "11.1.0",
37
37
  "@semantic-release/git": "10.0.1",
38
- "@semantic-release/github": "8.1.0",
39
- "@semantic-release/npm": "9.0.2",
40
- "@semantic-release/release-notes-generator": "10.0.3",
41
- "eslint": "8.45.0",
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.27.5",
44
- "eslint-config-prettier": "8.8.0",
45
- "fastify": "4.15.0",
46
- "postcss": "8.4.27",
47
- "rollup": "2.79.1",
48
- "semantic-release": "19.0.5",
49
- "tap": "14.11.0"
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.5",
52
+ "@eik/common-config-loader": "4.0.0-next.12",
53
53
  "css-url-parser": "1.1.3",
54
- "node-fetch": "2.6.13"
54
+ "node-fetch": "2.7.0"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "postcss": "^8.0.0"
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 { helpers } = require('@eik/common');
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) => fetch(map).then((result) => {
12
- if (result.status === 404) {
13
- throw new Error('Import map could not be found on server');
14
- } else if (result.status >= 400 && result.status < 500) {
15
- throw new Error('Server rejected client request');
16
- } else if (result.status >= 500) {
17
- throw new Error('Server error');
18
- }
19
- return result.json();
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) => Object.keys(map.imports).map((key) => {
30
- const value = map.imports[key];
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
- return { key, value };
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
- module.exports = ({
40
- path = process.cwd(),
41
- maps = [],
42
- urls = [],
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 helpers.getDefaults(path);
95
+ const config = await getDefaults(path);
95
96
 
96
97
  // Fetch import maps from the server
97
- const fetched = await fetchImportMaps([...config.map, ...pUrls]);
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);