@eik/postcss-plugin 3.0.14 → 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,18 @@
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
+
1
16
  ## [3.0.14](https://github.com/eik-lib/postcss-import-map/compare/v3.0.13...v3.0.14) (2024-03-06)
2
17
 
3
18
 
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.14",
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 --disable-coverage --allow-empty-coverage",
13
- "test:snapshot": "TAP_SNAPSHOT=1 tap test/*.js --disable-coverage --allow-empty-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": "11.1.0",
37
- "@semantic-release/git": "10.0.1",
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
- "eslint-config-airbnb-base": "15.0.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
- },
51
- "dependencies": {
52
- "@eik/common-config-loader": "4.0.0-next.12",
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,8 +1,5 @@
1
- /* eslint-disable no-restricted-syntax, no-shadow */
2
-
3
- const parseCssUrls = require('css-url-parser');
4
- const { getDefaults } = require('@eik/common-config-loader');
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
 
@@ -18,12 +15,12 @@ async function fetchImportMaps(urls = []) {
18
15
  throw new Error('Server error');
19
16
  }
20
17
  return result.json();
21
- })
18
+ }),
22
19
  );
23
20
  return await Promise.all(maps);
24
21
  } catch (err) {
25
22
  throw new Error(
26
- `Unable to load import map file from server: ${err.message}`
23
+ `Unable to load import map file from server: ${err.message}`,
27
24
  );
28
25
  }
29
26
  }
@@ -34,14 +31,14 @@ const validate = (map) =>
34
31
 
35
32
  if (notUrl(value)) {
36
33
  throw Error(
37
- `Import specifier can NOT be mapped to a bare import statement. Import specifier "${key}" is being wrongly mapped to "${value}"`
34
+ `Import specifier can NOT be mapped to a bare import statement. Import specifier "${key}" is being wrongly mapped to "${value}"`,
38
35
  );
39
36
  }
40
37
 
41
38
  return { key, value };
42
39
  });
43
40
 
44
- module.exports = ({ path = process.cwd(), maps = [], urls = [] } = {}) => {
41
+ export default ({ path = process.cwd(), maps = [], urls = [] } = {}) => {
45
42
  const pMaps = Array.isArray(maps) ? maps : [maps];
46
43
  const pUrls = Array.isArray(urls) ? urls : [urls];
47
44
 
@@ -64,7 +61,6 @@ module.exports = ({ path = process.cwd(), maps = [], urls = [] } = {}) => {
64
61
  // First check if it's possibly using syntax like url()
65
62
  const parsedUrls = parseCssUrls(decl.params);
66
63
  if (parsedUrls.length > 0) {
67
- // eslint-disable-next-line prefer-destructuring
68
64
  key = parsedUrls[0];
69
65
  } else {
70
66
  // Handle the common cases where it's not wrapped in url() but may have quotes
@@ -77,7 +73,6 @@ module.exports = ({ path = process.cwd(), maps = [], urls = [] } = {}) => {
77
73
  if (replaced.has(key)) {
78
74
  decl.remove();
79
75
  } else if (mapping.has(key)) {
80
- // eslint-disable-next-line no-param-reassign
81
76
  decl.params = `'${mapping.get(key)}'`;
82
77
  replaced.add(key);
83
78
  }
@@ -121,5 +116,3 @@ module.exports = ({ path = process.cwd(), maps = [], urls = [] } = {}) => {
121
116
  },
122
117
  };
123
118
  };
124
-
125
- module.exports.postcss = true;