@parcel/utils 2.14.4 → 2.15.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/utils",
3
- "version": "2.14.4",
3
+ "version": "2.15.0",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -33,31 +33,31 @@
33
33
  }
34
34
  },
35
35
  "dependencies": {
36
- "@parcel/codeframe": "2.14.4",
37
- "@parcel/diagnostic": "2.14.4",
38
- "@parcel/logger": "2.14.4",
39
- "@parcel/markdown-ansi": "2.14.4",
40
- "@parcel/rust": "2.14.4",
36
+ "@parcel/codeframe": "2.15.0",
37
+ "@parcel/diagnostic": "2.15.0",
38
+ "@parcel/logger": "2.15.0",
39
+ "@parcel/markdown-ansi": "2.15.0",
40
+ "@parcel/rust": "2.15.0",
41
41
  "@parcel/source-map": "^2.1.1",
42
42
  "chalk": "^4.1.2",
43
43
  "nullthrows": "^1.1.1"
44
44
  },
45
45
  "devDependencies": {
46
- "@iarna/toml": "^2.2.0",
46
+ "@iarna/toml": "^2.2.5",
47
47
  "ansi-html-community": "0.0.8",
48
- "clone": "^2.1.1",
49
- "fast-glob": "^3.2.12",
48
+ "clone": "^2.1.2",
49
+ "fast-glob": "^3.3.3",
50
50
  "fastest-levenshtein": "^1.0.16",
51
- "is-glob": "^4.0.0",
52
- "is-url": "^1.2.2",
53
- "json5": "^2.2.0",
54
- "lru-cache": "^10.0.0",
55
- "micromatch": "^4.0.4",
56
- "node-forge": "^1.2.1",
51
+ "is-glob": "^4.0.3",
52
+ "is-url": "^1.2.4",
53
+ "json5": "^2.2.3",
54
+ "lru-cache": "^10.4.3",
55
+ "micromatch": "^4.0.8",
56
+ "node-forge": "^1.3.1",
57
57
  "nullthrows": "^1.1.1",
58
- "open": "^7.0.3",
58
+ "open": "^7.4.2",
59
59
  "snarkdown": "^2.0.0",
60
- "strip-ansi": "^6.0.0",
60
+ "strip-ansi": "^6.0.1",
61
61
  "terminal-link": "^2.1.1"
62
62
  },
63
63
  "browser": {
@@ -66,5 +66,5 @@
66
66
  "./src/openInBrowser.js": false,
67
67
  "@parcel/markdown-ansi": false
68
68
  },
69
- "gitHead": "c09fee751b61e2f9d52164f88248b9c668614134"
69
+ "gitHead": "99ada2e5258f6d4a2c6cdc366c12e4161b0161e6"
70
70
  }
package/src/index.js CHANGED
@@ -65,6 +65,7 @@ export {normalizePath, normalizeSeparators, relativePath} from './path';
65
65
  export {
66
66
  replaceURLReferences,
67
67
  replaceInlineReferences,
68
+ getURLReplacement,
68
69
  } from './replaceBundleReferences';
69
70
  export {
70
71
  measureStreamLength,
@@ -86,5 +87,5 @@ export {
86
87
  remapSourceLocation,
87
88
  } from './sourcemap';
88
89
  export {default as stripAnsi} from 'strip-ansi';
89
- export {detectSVGOVersion} from './svgo';
90
+ export {detectSVGOVersion, convertSVGOConfig} from './svgo';
90
91
  export {getImportMap} from './import-map';
package/src/svgo.js CHANGED
@@ -1,4 +1,10 @@
1
1
  // @flow
2
+ import type {FileSystem} from '@parcel/fs';
3
+ import ThrowableDiagnostic, {
4
+ generateJSONCodeHighlights,
5
+ } from '@parcel/diagnostic';
6
+ import path from 'path';
7
+
2
8
  export function detectSVGOVersion(
3
9
  config: any,
4
10
  ): {|version: 3|} | {|version: 2, path: string|} {
@@ -48,3 +54,105 @@ export function detectSVGOVersion(
48
54
 
49
55
  return {version: 3};
50
56
  }
57
+
58
+ export async function convertSVGOConfig(
59
+ config: any,
60
+ filePath: string,
61
+ jsonPath: string,
62
+ fs: FileSystem,
63
+ hint?: string,
64
+ ): Promise<any> {
65
+ if (typeof config === 'boolean') {
66
+ return {default: config};
67
+ }
68
+
69
+ if (!config || typeof config !== 'object') {
70
+ return {default: true};
71
+ }
72
+
73
+ let result = {
74
+ default: false,
75
+ };
76
+
77
+ if (Array.isArray(config.plugins)) {
78
+ for (let [i, plugin] of config.plugins.entries()) {
79
+ let name: string,
80
+ params = true;
81
+ if (typeof plugin === 'string') {
82
+ name = plugin;
83
+ } else if (
84
+ typeof plugin === 'object' &&
85
+ typeof plugin?.name === 'string'
86
+ ) {
87
+ name = plugin.name;
88
+ params = plugin.params ?? true;
89
+
90
+ if (typeof plugin.fn === 'function') {
91
+ await throwDiagnostic(
92
+ 'Unsupported custom SVGO plugin.',
93
+ filePath,
94
+ `${jsonPath}/plugins/${i}/fn`,
95
+ fs,
96
+ hint,
97
+ );
98
+ }
99
+ } else if (typeof plugin === 'function') {
100
+ await throwDiagnostic(
101
+ 'Unsupported custom SVGO plugin.',
102
+ filePath,
103
+ `${jsonPath}/plugins/${i}`,
104
+ fs,
105
+ hint,
106
+ );
107
+ } else {
108
+ continue;
109
+ }
110
+
111
+ if (name === 'cleanupIDs') {
112
+ name = 'cleanupIds';
113
+ }
114
+
115
+ if (name === 'preset-default') {
116
+ result.default = true;
117
+ if (
118
+ typeof params === 'object' &&
119
+ typeof params?.overrides === 'object' &&
120
+ params.overrides
121
+ ) {
122
+ for (let key in params.overrides) {
123
+ result[key] = params.overrides[key];
124
+ }
125
+ }
126
+ } else if (typeof name === 'string') {
127
+ result[(name: any)] = params || false;
128
+ }
129
+ }
130
+ }
131
+
132
+ return result;
133
+ }
134
+
135
+ async function throwDiagnostic(message, filePath, jsonPath, fs, hint) {
136
+ throw new ThrowableDiagnostic({
137
+ diagnostic: {
138
+ message: message,
139
+ codeFrames: [
140
+ {
141
+ filePath: filePath,
142
+ codeHighlights:
143
+ path.extname(filePath) === '' || path.extname(filePath) === '.json'
144
+ ? generateJSONCodeHighlights(
145
+ await fs.readFile(filePath, 'utf8'),
146
+ [
147
+ {
148
+ key: jsonPath,
149
+ },
150
+ ],
151
+ )
152
+ : [],
153
+ },
154
+ ],
155
+ hints: hint ? [hint] : [],
156
+ },
157
+ });
158
+ }