@eik/postcss-plugin 3.0.13 → 4.0.0

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 CHANGED
@@ -1,3 +1,25 @@
1
+ # [4.0.0](https://github.com/eik-lib/postcss-import-map/compare/v3.0.14...v4.0.0) (2024-07-29)
2
+
3
+
4
+ ### Code Refactoring
5
+
6
+ * migrate to esm ([4e8bc12](https://github.com/eik-lib/postcss-import-map/commit/4e8bc1299323afb2ee7e74eb4d97d85869f5c904))
7
+ * remove node-fetch dependency ([8113805](https://github.com/eik-lib/postcss-import-map/commit/81138057c767bdecfeec96db017ddf25942e8458))
8
+
9
+
10
+ ### BREAKING CHANGES
11
+
12
+ * this requires using Node 18 or newer without the
13
+ --no-experimental-fetch flag.
14
+ * module is now ESM
15
+
16
+ ## [3.0.14](https://github.com/eik-lib/postcss-import-map/compare/v3.0.13...v3.0.14) (2024-03-06)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * **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))
22
+
1
23
  ## [3.0.13](https://github.com/eik-lib/postcss-import-map/compare/v3.0.12...v3.0.13) (2023-08-23)
2
24
 
3
25
 
package/README.md CHANGED
@@ -19,9 +19,7 @@ const fs = require('fs');
19
19
  const css = fs.readFileSync('css/input.css', 'utf8');
20
20
 
21
21
  postcss()
22
- .use(
23
- plugin()
24
- )
22
+ .use(plugin())
25
23
  .process(css, {
26
24
  // `from` option is needed here
27
25
  from: 'css/input.css',
@@ -55,8 +53,8 @@ when applaying the following Import Map:
55
53
  ```json
56
54
  {
57
55
  "imports": {
58
- "normalize.css": "https://cdn.eik.dev/normalize.css@8/normalize.css",
59
- },
56
+ "normalize.css": "https://cdn.eik.dev/normalize.css@8/normalize.css"
57
+ }
60
58
  }
61
59
  ```
62
60
 
@@ -74,11 +72,11 @@ body {
74
72
 
75
73
  This plugin takes the following as options:
76
74
 
77
- | option | default | type | required | details |
78
- | ------- | --------------- | -------- | -------- | ----------------------------------------------------------------------------- |
79
- | path | `process.cwd()` | `string` | `false` | Path to directory containing a eik.json file or package.json with eik config. |
80
- | urls | `[]` | `array` | `false` | Array of import map URLs to fetch from. |
81
- | maps | `[]` | `array` | `false` | Array of import map as objects. |
75
+ | option | default | type | required | details |
76
+ | ------ | --------------- | -------- | -------- | ----------------------------------------------------------------------------- |
77
+ | path | `process.cwd()` | `string` | `false` | Path to directory containing a eik.json file or package.json with eik config. |
78
+ | urls | `[]` | `array` | `false` | Array of import map URLs to fetch from. |
79
+ | maps | `[]` | `array` | `false` | Array of import map as objects. |
82
80
 
83
81
  The plugin will attempt to read import map URLs from [`eik.json` or `package.json`](https://eik.dev/docs/overview_eik_json) files in the root of the current working directory if present.
84
82
 
package/package.json CHANGED
@@ -1,63 +1,60 @@
1
1
  {
2
- "name": "@eik/postcss-plugin",
3
- "version": "3.0.13",
4
- "description": "PostCSS plugin that uses Eik defined import map files to transform bare import specifiers to absolute URLs in @import rules",
5
- "main": "src/plugin.js",
6
- "files": [
7
- "CHANGELOG.md",
8
- "package.json",
9
- "src/"
10
- ],
11
- "scripts": {
12
- "test": "tap test/*.js --no-coverage",
13
- "test:snapshot": "TAP_SNAPSHOT=1 tap test/*.js --no-coverage",
14
- "lint": "eslint .",
15
- "lint:fix": "eslint . --fix"
16
- },
17
- "repository": {
18
- "type": "git",
19
- "url": "git+https://github.com/eik-lib/postcss-import-map.git"
20
- },
21
- "keywords": [
22
- "css",
23
- "postcss",
24
- "postcss-plugin",
25
- "import",
26
- "url"
27
- ],
28
- "author": "Finn.no",
29
- "license": "MIT",
30
- "bugs": {
31
- "url": "https://github.com/eik-lib/postcss-import-map/issues"
32
- },
33
- "homepage": "https://github.com/eik-lib/postcss-import-map#readme",
34
- "devDependencies": {
35
- "@semantic-release/changelog": "6.0.3",
36
- "@semantic-release/commit-analyzer": "9.0.2",
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.47.0",
42
- "eslint-config-airbnb-base": "15.0.0",
43
- "eslint-plugin-import": "2.28.1",
44
- "eslint-config-prettier": "8.10.0",
45
- "fastify": "4.15.0",
46
- "postcss": "8.4.28",
47
- "rollup": "2.79.1",
48
- "semantic-release": "19.0.5",
49
- "tap": "14.11.0"
50
- },
51
- "dependencies": {
52
- "@eik/common": "4.0.0-next.5",
53
- "css-url-parser": "1.1.3",
54
- "node-fetch": "2.7.0"
55
- },
56
- "peerDependencies": {
57
- "postcss": "^8.0.0"
58
- },
59
- "prettier": {
60
- "singleQuote": true,
61
- "tabWidth": 4
62
- }
2
+ "name": "@eik/postcss-plugin",
3
+ "version": "4.0.0",
4
+ "description": "PostCSS plugin that uses Eik defined import map files to transform bare import specifiers to absolute URLs in @import rules",
5
+ "main": "src/plugin.js",
6
+ "type": "module",
7
+ "files": [
8
+ "CHANGELOG.md",
9
+ "package.json",
10
+ "src/"
11
+ ],
12
+ "scripts": {
13
+ "test": "tap test/*.js --disable-coverage --allow-empty-coverage",
14
+ "test:snapshot": "TAP_SNAPSHOT=1 tap test/*.js --disable-coverage --allow-empty-coverage",
15
+ "lint": "eslint .",
16
+ "lint:fix": "eslint . --fix"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/eik-lib/postcss-import-map.git"
21
+ },
22
+ "keywords": [
23
+ "css",
24
+ "postcss",
25
+ "postcss-plugin",
26
+ "import",
27
+ "url"
28
+ ],
29
+ "author": "Finn.no",
30
+ "license": "MIT",
31
+ "bugs": {
32
+ "url": "https://github.com/eik-lib/postcss-import-map/issues"
33
+ },
34
+ "homepage": "https://github.com/eik-lib/postcss-import-map#readme",
35
+ "devDependencies": {
36
+ "@semantic-release/changelog": "6.0.3",
37
+ "@semantic-release/commit-analyzer": "13.0.0",
38
+ "@semantic-release/git": "10.0.1",
39
+ "@semantic-release/github": "10.1.3",
40
+ "@semantic-release/npm": "12.0.1",
41
+ "@semantic-release/release-notes-generator": "14.0.1",
42
+ "eslint": "9.8.0",
43
+ "eslint-config-prettier": "9.1.0",
44
+ "eslint-plugin-prettier": "5.2.1",
45
+ "fastify": "4.28.1",
46
+ "globals": "15.8.0",
47
+ "postcss": "8.4.40",
48
+ "rollup": "4.19.1",
49
+ "semantic-release": "24.0.0",
50
+ "prettier": "3.3.3",
51
+ "tap": "20.0.3"
52
+ },
53
+ "dependencies": {
54
+ "@eik/common-config-loader": "4.0.0-next.12",
55
+ "css-url-parser": "1.1.3"
56
+ },
57
+ "peerDependencies": {
58
+ "postcss": "^8.0.0"
59
+ }
63
60
  }
package/src/plugin.js CHANGED
@@ -1,23 +1,22 @@
1
- /* eslint-disable no-restricted-syntax, no-shadow */
2
-
3
- const parseCssUrls = require('css-url-parser');
4
- const { helpers } = require('@eik/common');
5
- const fetch = require('node-fetch');
1
+ import parseCssUrls from 'css-url-parser';
2
+ import { getDefaults } from '@eik/common-config-loader';
6
3
 
7
4
  const notUrl = (url) => url.substr(0, 4) !== 'http';
8
5
 
9
6
  async function fetchImportMaps(urls = []) {
10
7
  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
- }));
8
+ const maps = urls.map((map) =>
9
+ fetch(map).then((result) => {
10
+ if (result.status === 404) {
11
+ throw new Error('Import map could not be found on server');
12
+ } else if (result.status >= 400 && result.status < 500) {
13
+ throw new Error('Server rejected client request');
14
+ } else if (result.status >= 500) {
15
+ throw new Error('Server error');
16
+ }
17
+ return result.json();
18
+ }),
19
+ );
21
20
  return await Promise.all(maps);
22
21
  } catch (err) {
23
22
  throw new Error(
@@ -26,21 +25,20 @@ async function fetchImportMaps(urls = []) {
26
25
  }
27
26
  }
28
27
 
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
- }
28
+ const validate = (map) =>
29
+ Object.keys(map.imports).map((key) => {
30
+ const value = map.imports[key];
35
31
 
36
- return { key, value };
37
- });
32
+ if (notUrl(value)) {
33
+ throw Error(
34
+ `Import specifier can NOT be mapped to a bare import statement. Import specifier "${key}" is being wrongly mapped to "${value}"`,
35
+ );
36
+ }
38
37
 
39
- module.exports = ({
40
- path = process.cwd(),
41
- maps = [],
42
- urls = [],
43
- } = {}) => {
38
+ return { key, value };
39
+ });
40
+
41
+ export default ({ path = process.cwd(), maps = [], urls = [] } = {}) => {
44
42
  const pMaps = Array.isArray(maps) ? maps : [maps];
45
43
  const pUrls = Array.isArray(urls) ? urls : [urls];
46
44
 
@@ -63,7 +61,6 @@ module.exports = ({
63
61
  // First check if it's possibly using syntax like url()
64
62
  const parsedUrls = parseCssUrls(decl.params);
65
63
  if (parsedUrls.length > 0) {
66
- // eslint-disable-next-line prefer-destructuring
67
64
  key = parsedUrls[0];
68
65
  } else {
69
66
  // Handle the common cases where it's not wrapped in url() but may have quotes
@@ -76,7 +73,6 @@ module.exports = ({
76
73
  if (replaced.has(key)) {
77
74
  decl.remove();
78
75
  } else if (mapping.has(key)) {
79
- // eslint-disable-next-line no-param-reassign
80
76
  decl.params = `'${mapping.get(key)}'`;
81
77
  replaced.add(key);
82
78
  }
@@ -91,18 +87,21 @@ module.exports = ({
91
87
  // Run initially once, this is to ensure it runs before postcss-import
92
88
  async Once(root) {
93
89
  // Load eik config from eik.json or package.json
94
- const config = await helpers.getDefaults(path);
90
+ const config = await getDefaults(path);
95
91
 
96
92
  // Fetch import maps from the server
97
- const fetched = await fetchImportMaps([...config.map, ...pUrls]);
98
-
93
+ const fetched = await fetchImportMaps([
94
+ ...config.map,
95
+ ...pUrls,
96
+ ]);
97
+
99
98
  const allImportMaps = [...fetched, ...pMaps];
100
99
  allImportMaps.forEach((item) => {
101
100
  const i = validate(item);
102
101
  i.forEach((obj) => {
103
102
  mapping.set(obj.key, obj.value);
104
103
  });
105
- });;
104
+ });
106
105
 
107
106
  root.walkAtRules('import', (decl) => {
108
107
  applyImportMap(mapping, decl);
@@ -117,5 +116,3 @@ module.exports = ({
117
116
  },
118
117
  };
119
118
  };
120
-
121
- module.exports.postcss = true;