@atlaspack/transformer-image 3.1.5-canary.3 → 3.1.5-canary.300

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,5 +1,344 @@
1
1
  # @atlaspack/transformer-image
2
2
 
3
+ ## 9.0.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`7dd5bd8`](https://github.com/atlassian-labs/atlaspack/commit/7dd5bd89ff60c7b324347d772729eb4c3314f01e), [`8eb84ee`](https://github.com/atlassian-labs/atlaspack/commit/8eb84ee61a42bfe87c58079b610802b07a6a13e4), [`73168c2`](https://github.com/atlassian-labs/atlaspack/commit/73168c275a5d9abff9907bcf536b340bca1ed5f0), [`617a318`](https://github.com/atlassian-labs/atlaspack/commit/617a318ddc9419b38360257353fec50b9051ee13)]:
8
+ - @atlaspack/core@2.28.0
9
+ - @atlaspack/utils@3.2.0
10
+ - @atlaspack/plugin@2.14.39
11
+ - @atlaspack/workers@2.14.39
12
+
13
+ ## 8.0.0
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [[`ec3abe4`](https://github.com/atlassian-labs/atlaspack/commit/ec3abe4dffc98560a850fd2f71fb566577e6c99c), [`cfb4707`](https://github.com/atlassian-labs/atlaspack/commit/cfb4707087498e4fa4dcf10753fe984a248d196b), [`33d4c26`](https://github.com/atlassian-labs/atlaspack/commit/33d4c261ceb8d585d56b0a446ed6e28cf7f1126d), [`f31b041`](https://github.com/atlassian-labs/atlaspack/commit/f31b04107e9077c9946aadb99f6f91bb69703bb7), [`8180981`](https://github.com/atlassian-labs/atlaspack/commit/8180981be14c00f9570adb70d3f350bd91d6ec0a), [`119210b`](https://github.com/atlassian-labs/atlaspack/commit/119210b597eb993c50445df87a36b70bd49cd414), [`7d7a55d`](https://github.com/atlassian-labs/atlaspack/commit/7d7a55dd6395ec391a2e4c33b3dec0d1ea477d4c)]:
18
+ - @atlaspack/core@2.27.0
19
+ - @atlaspack/utils@3.1.2
20
+ - @atlaspack/workers@2.14.38
21
+ - @atlaspack/plugin@2.14.38
22
+
23
+ ## 7.0.2
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies []:
28
+ - @atlaspack/core@2.26.2
29
+ - @atlaspack/utils@3.1.1
30
+ - @atlaspack/workers@2.14.37
31
+ - @atlaspack/plugin@2.14.37
32
+
33
+ ## 7.0.1
34
+
35
+ ### Patch Changes
36
+
37
+ - Updated dependencies [[`9cd9521`](https://github.com/atlassian-labs/atlaspack/commit/9cd9521978f783046e2ae4ce78f2de7aeb07d073), [`d0c7bea`](https://github.com/atlassian-labs/atlaspack/commit/d0c7bea04458255b4c5d4299600e734b5f919fe1), [`1086c6a`](https://github.com/atlassian-labs/atlaspack/commit/1086c6a2c59271b63b3fb78e6acdb9d3a0dbf354), [`5776be2`](https://github.com/atlassian-labs/atlaspack/commit/5776be21f70a3f2b9471ba33da3ba1a883f21f1a)]:
38
+ - @atlaspack/core@2.26.1
39
+ - @atlaspack/utils@3.1.0
40
+ - @atlaspack/workers@2.14.36
41
+ - @atlaspack/plugin@2.14.36
42
+
43
+ ## 7.0.0
44
+
45
+ ### Patch Changes
46
+
47
+ - Updated dependencies [[`ff8ac84`](https://github.com/atlassian-labs/atlaspack/commit/ff8ac84bd0be15caa7c7af21bf5b6e47b6d36438), [`3da8e69`](https://github.com/atlassian-labs/atlaspack/commit/3da8e690605472d81c531366b65fa9844f8ca337), [`c372f3f`](https://github.com/atlassian-labs/atlaspack/commit/c372f3fd6fce8200d5cf47f41bc7895c6cbb5558), [`17dfea9`](https://github.com/atlassian-labs/atlaspack/commit/17dfea9e9f3169807808520df9c09ebf70dc8b10), [`27fd73f`](https://github.com/atlassian-labs/atlaspack/commit/27fd73fa07d358653f1be6f2d15d72dc5d8fc2fd), [`3091fa3`](https://github.com/atlassian-labs/atlaspack/commit/3091fa36425ecffe3938e55247a035b08cda37a2)]:
48
+ - @atlaspack/core@2.26.0
49
+ - @atlaspack/utils@3.0.3
50
+ - @atlaspack/plugin@2.14.35
51
+ - @atlaspack/workers@2.14.35
52
+
53
+ ## 6.0.1
54
+
55
+ ### Patch Changes
56
+
57
+ - Updated dependencies [[`25cbee6`](https://github.com/atlassian-labs/atlaspack/commit/25cbee625fb47ac20423fe34ff37bc818a807245)]:
58
+ - @atlaspack/workers@2.14.34
59
+ - @atlaspack/core@2.25.1
60
+ - @atlaspack/utils@3.0.2
61
+ - @atlaspack/plugin@2.14.34
62
+
63
+ ## 6.0.0
64
+
65
+ ### Patch Changes
66
+
67
+ - Updated dependencies [[`236e546`](https://github.com/atlassian-labs/atlaspack/commit/236e5465863dca6044a7191e05260a5b924c342e), [`f07351a`](https://github.com/atlassian-labs/atlaspack/commit/f07351a2398b6a8e5155a2daad77e69b7dcb2b4b)]:
68
+ - @atlaspack/utils@3.0.1
69
+ - @atlaspack/core@2.25.0
70
+ - @atlaspack/workers@2.14.33
71
+ - @atlaspack/plugin@2.14.33
72
+
73
+ ## 5.0.2
74
+
75
+ ### Patch Changes
76
+
77
+ - Updated dependencies [[`10ee3fa`](https://github.com/atlassian-labs/atlaspack/commit/10ee3fa5b75a92acde8973673d9b3c5b6f3958e5), [`1180103`](https://github.com/atlassian-labs/atlaspack/commit/118010351ed444f8178988afb3f77807154dd933)]:
78
+ - @atlaspack/core@2.24.2
79
+ - @atlaspack/utils@3.0.0
80
+ - @atlaspack/workers@2.14.32
81
+ - @atlaspack/plugin@2.14.32
82
+
83
+ ## 5.0.1
84
+
85
+ ### Patch Changes
86
+
87
+ - [#785](https://github.com/atlassian-labs/atlaspack/pull/785) [`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922) Thanks [@matt-koko](https://github.com/matt-koko)! - We need to re-publish every package in Atlaspack with the corrected types field.
88
+
89
+ - Updated dependencies [[`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922), [`686a398`](https://github.com/atlassian-labs/atlaspack/commit/686a398faa1f9e19cbf9274add2c46e246bafba8)]:
90
+ - @atlaspack/core@2.24.1
91
+ - @atlaspack/plugin@2.14.31
92
+ - @atlaspack/utils@2.19.3
93
+ - @atlaspack/workers@2.14.31
94
+
95
+ ## 5.0.0
96
+
97
+ ### Patch Changes
98
+
99
+ - Updated dependencies [[`eedcbc4`](https://github.com/atlassian-labs/atlaspack/commit/eedcbc408fc1e86a2a8e25f1a41c57146d8529e1), [`5a0363f`](https://github.com/atlassian-labs/atlaspack/commit/5a0363f1086e81068959b87e92064bed5a11a9b4), [`038e87a`](https://github.com/atlassian-labs/atlaspack/commit/038e87a7858d39556d59d3a2d17db534d45f62c6), [`f6532d7`](https://github.com/atlassian-labs/atlaspack/commit/f6532d7a4f7f007bd4e5e36af04dd466f0b9f572), [`8604d2a`](https://github.com/atlassian-labs/atlaspack/commit/8604d2a49ace5e9194ec4f76e71f06b93610f6b4)]:
100
+ - @atlaspack/core@2.24.0
101
+ - @atlaspack/utils@2.19.2
102
+ - @atlaspack/plugin@2.14.30
103
+ - @atlaspack/workers@2.14.30
104
+
105
+ ## 4.0.5
106
+
107
+ ### Patch Changes
108
+
109
+ - Updated dependencies []:
110
+ - @atlaspack/core@2.23.5
111
+ - @atlaspack/utils@2.19.1
112
+ - @atlaspack/plugin@2.14.29
113
+ - @atlaspack/workers@2.14.29
114
+
115
+ ## 4.0.4
116
+
117
+ ### Patch Changes
118
+
119
+ - Updated dependencies [[`f0349a6`](https://github.com/atlassian-labs/atlaspack/commit/f0349a6b9b04755088f121095ca6301a2ada3767)]:
120
+ - @atlaspack/utils@2.19.0
121
+ - @atlaspack/core@2.23.4
122
+ - @atlaspack/workers@2.14.28
123
+ - @atlaspack/plugin@2.14.28
124
+
125
+ ## 4.0.3
126
+
127
+ ### Patch Changes
128
+
129
+ - Updated dependencies []:
130
+ - @atlaspack/core@2.23.3
131
+ - @atlaspack/utils@2.18.4
132
+ - @atlaspack/plugin@2.14.27
133
+ - @atlaspack/workers@2.14.27
134
+
135
+ ## 4.0.2
136
+
137
+ ### Patch Changes
138
+
139
+ - [#742](https://github.com/atlassian-labs/atlaspack/pull/742) [`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd) Thanks [@yamadapc](https://github.com/yamadapc)! - Internal changes and bug fixes to environmentDeduplication flag
140
+
141
+ - Updated dependencies [[`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd), [`889c65c`](https://github.com/atlassian-labs/atlaspack/commit/889c65cd25b811045e26a117e7404f694dde77a2), [`b6e72b6`](https://github.com/atlassian-labs/atlaspack/commit/b6e72b6dd2b517cbb0e700fa69e63332d3eacb1e)]:
142
+ - @atlaspack/workers@2.14.26
143
+ - @atlaspack/plugin@2.14.26
144
+ - @atlaspack/utils@2.18.3
145
+ - @atlaspack/core@2.23.2
146
+
147
+ ## 4.0.1
148
+
149
+ ### Patch Changes
150
+
151
+ - Updated dependencies []:
152
+ - @atlaspack/core@2.23.1
153
+ - @atlaspack/utils@2.18.2
154
+ - @atlaspack/plugin@2.14.25
155
+ - @atlaspack/workers@2.14.25
156
+
157
+ ## 4.0.0
158
+
159
+ ### Patch Changes
160
+
161
+ - Updated dependencies [[`7f5841c`](https://github.com/atlassian-labs/atlaspack/commit/7f5841c39df049f9546cccbeea2a7337e0337b45)]:
162
+ - @atlaspack/core@2.23.0
163
+ - @atlaspack/utils@2.18.1
164
+ - @atlaspack/plugin@2.14.24
165
+ - @atlaspack/workers@2.14.24
166
+
167
+ ## 3.1.23
168
+
169
+ ### Patch Changes
170
+
171
+ - Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
172
+ - @atlaspack/utils@2.18.0
173
+ - @atlaspack/workers@2.14.23
174
+ - @atlaspack/plugin@2.14.23
175
+
176
+ ## 3.1.22
177
+
178
+ ### Patch Changes
179
+
180
+ - [#720](https://github.com/atlassian-labs/atlaspack/pull/720) [`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94) Thanks [@alshdavid](https://github.com/alshdavid)! - Migrate to TypeScript
181
+
182
+ - Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94)]:
183
+ - @atlaspack/workers@2.14.22
184
+ - @atlaspack/plugin@2.14.22
185
+ - @atlaspack/utils@2.17.4
186
+
187
+ ## 3.1.21
188
+
189
+ ### Patch Changes
190
+
191
+ - Updated dependencies []:
192
+ - @atlaspack/workers@2.14.21
193
+ - @atlaspack/utils@2.17.3
194
+ - @atlaspack/plugin@2.14.21
195
+
196
+ ## 3.1.20
197
+
198
+ ### Patch Changes
199
+
200
+ - [#702](https://github.com/atlassian-labs/atlaspack/pull/702) [`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa) Thanks [@alshdavid](https://github.com/alshdavid)! - Fixes to Flow types
201
+
202
+ - Updated dependencies [[`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa)]:
203
+ - @atlaspack/plugin@2.14.20
204
+ - @atlaspack/utils@2.17.2
205
+ - @atlaspack/workers@2.14.20
206
+
207
+ ## 3.1.19
208
+
209
+ ### Patch Changes
210
+
211
+ - Updated dependencies []:
212
+ - @atlaspack/utils@2.17.1
213
+ - @atlaspack/workers@2.14.19
214
+ - @atlaspack/plugin@2.14.19
215
+
216
+ ## 3.1.18
217
+
218
+ ### Patch Changes
219
+
220
+ - Updated dependencies [[`dbb4072`](https://github.com/atlassian-labs/atlaspack/commit/dbb40721ebeb45990a14ba04e6b44e7f836fb32d), [`de23e0c`](https://github.com/atlassian-labs/atlaspack/commit/de23e0ce49d5504fe3947ac26640a3d951087da3), [`18a57cf`](https://github.com/atlassian-labs/atlaspack/commit/18a57cf8a4789b2de5ad8e2676f317a26cc91417), [`a5ed1b4`](https://github.com/atlassian-labs/atlaspack/commit/a5ed1b414498560f393ff491af4da25b6e8dde56)]:
221
+ - @atlaspack/utils@2.17.0
222
+ - @atlaspack/workers@2.14.18
223
+ - @atlaspack/plugin@2.14.18
224
+
225
+ ## 3.1.17
226
+
227
+ ### Patch Changes
228
+
229
+ - Updated dependencies []:
230
+ - @atlaspack/utils@2.16.1
231
+ - @atlaspack/workers@2.14.17
232
+ - @atlaspack/plugin@2.14.17
233
+
234
+ ## 3.1.16
235
+
236
+ ### Patch Changes
237
+
238
+ - Updated dependencies [[`30ee2cf`](https://github.com/atlassian-labs/atlaspack/commit/30ee2cfcd34cf2646ded0eda13fdb80a2a5de529)]:
239
+ - @atlaspack/utils@2.16.0
240
+ - @atlaspack/workers@2.14.16
241
+ - @atlaspack/plugin@2.14.16
242
+
243
+ ## 3.1.15
244
+
245
+ ### Patch Changes
246
+
247
+ - Updated dependencies []:
248
+ - @atlaspack/utils@2.15.3
249
+ - @atlaspack/workers@2.14.15
250
+ - @atlaspack/plugin@2.14.15
251
+
252
+ ## 3.1.14
253
+
254
+ ### Patch Changes
255
+
256
+ - Updated dependencies []:
257
+ - @atlaspack/utils@2.15.2
258
+ - @atlaspack/workers@2.14.14
259
+ - @atlaspack/plugin@2.14.14
260
+
261
+ ## 3.1.13
262
+
263
+ ### Patch Changes
264
+
265
+ - Updated dependencies [[`ef3d622`](https://github.com/atlassian-labs/atlaspack/commit/ef3d6228f4e006702198a19c61e051d194d325cb)]:
266
+ - @atlaspack/workers@2.14.13
267
+ - @atlaspack/utils@2.15.1
268
+ - @atlaspack/plugin@2.14.13
269
+
270
+ ## 3.1.12
271
+
272
+ ### Patch Changes
273
+
274
+ - Updated dependencies [[`e39c6cf`](https://github.com/atlassian-labs/atlaspack/commit/e39c6cf05f7e95ce5420dbcea66f401b1cbd397c)]:
275
+ - @atlaspack/utils@2.15.0
276
+ - @atlaspack/workers@2.14.12
277
+ - @atlaspack/plugin@2.14.12
278
+
279
+ ## 3.1.11
280
+
281
+ ### Patch Changes
282
+
283
+ - Updated dependencies []:
284
+ - @atlaspack/utils@2.14.11
285
+ - @atlaspack/workers@2.14.11
286
+ - @atlaspack/plugin@2.14.11
287
+
288
+ ## 3.1.10
289
+
290
+ ### Patch Changes
291
+
292
+ - Updated dependencies []:
293
+ - @atlaspack/workers@2.14.10
294
+ - @atlaspack/plugin@2.14.10
295
+ - @atlaspack/utils@2.14.10
296
+
297
+ ## 3.1.9
298
+
299
+ ### Patch Changes
300
+
301
+ - Updated dependencies []:
302
+ - @atlaspack/utils@2.14.9
303
+ - @atlaspack/workers@2.14.9
304
+ - @atlaspack/plugin@2.14.9
305
+
306
+ ## 3.1.8
307
+
308
+ ### Patch Changes
309
+
310
+ - Updated dependencies []:
311
+ - @atlaspack/utils@2.14.8
312
+ - @atlaspack/workers@2.14.8
313
+ - @atlaspack/plugin@2.14.8
314
+
315
+ ## 3.1.7
316
+
317
+ ### Patch Changes
318
+
319
+ - Updated dependencies []:
320
+ - @atlaspack/utils@2.14.7
321
+ - @atlaspack/workers@2.14.7
322
+ - @atlaspack/plugin@2.14.7
323
+
324
+ ## 3.1.6
325
+
326
+ ### Patch Changes
327
+
328
+ - Updated dependencies []:
329
+ - @atlaspack/utils@2.14.6
330
+ - @atlaspack/workers@2.14.6
331
+ - @atlaspack/plugin@2.14.6
332
+
333
+ ## 3.1.5
334
+
335
+ ### Patch Changes
336
+
337
+ - Updated dependencies []:
338
+ - @atlaspack/utils@2.14.5
339
+ - @atlaspack/workers@2.14.5
340
+ - @atlaspack/plugin@2.14.5
341
+
3
342
  ## 3.1.4
4
343
 
5
344
  ### Patch Changes
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const validateConfig_1 = require("./validateConfig");
7
+ const plugin_1 = require("@atlaspack/plugin");
8
+ const nullthrows_1 = __importDefault(require("nullthrows"));
9
+ const workers_1 = __importDefault(require("@atlaspack/workers"));
10
+ // @ts-expect-error TS1192
11
+ const loadSharp_1 = __importDefault(require("./loadSharp"));
12
+ // from https://github.com/lovell/sharp/blob/df7b8ba73808fc494be413e88cfb621b6279218c/lib/output.js#L6-L17
13
+ const FORMATS = new Map([
14
+ ['jpeg', 'jpeg'],
15
+ ['jpg', 'jpeg'],
16
+ ['png', 'png'],
17
+ ['webp', 'webp'],
18
+ ['gif', 'gif'],
19
+ ['tiff', 'tiff'],
20
+ ['avif', 'avif'],
21
+ ['heic', 'heif'],
22
+ ['heif', 'heif'],
23
+ ]);
24
+ let isSharpLoadedOnMainThread = false;
25
+ exports.default = new plugin_1.Transformer({
26
+ async loadConfig({ config }) {
27
+ let configFile = await config.getConfig(['sharp.config.json'], // '.sharprc', '.sharprc.json'
28
+ { packageKey: 'sharp' });
29
+ if (configFile?.contents) {
30
+ (0, validateConfig_1.validateConfig)(configFile.contents, configFile.filePath);
31
+ return configFile.contents;
32
+ }
33
+ else {
34
+ return {};
35
+ }
36
+ },
37
+ async transform({ config, asset, options }) {
38
+ asset.bundleBehavior = 'isolated';
39
+ const originalFormat = FORMATS.get(asset.type);
40
+ if (!originalFormat) {
41
+ throw new Error(`The image transformer does not support ${asset.type} images.`);
42
+ }
43
+ const width = asset.query.has('width')
44
+ ? // @ts-expect-error TS2345
45
+ parseInt(asset.query.get('width'), 10)
46
+ : null;
47
+ const height = asset.query.has('height')
48
+ ? // @ts-expect-error TS2345
49
+ parseInt(asset.query.get('height'), 10)
50
+ : null;
51
+ const quality = asset.query.has('quality')
52
+ ? // @ts-expect-error TS2345
53
+ parseInt(asset.query.get('quality'), 10)
54
+ : config.quality;
55
+ let targetFormat = asset.query.get('as')?.toLowerCase().trim();
56
+ if (targetFormat && !FORMATS.has(targetFormat)) {
57
+ throw new Error(`The image transformer does not support ${targetFormat} images.`);
58
+ }
59
+ const format = (0, nullthrows_1.default)(FORMATS.get(targetFormat || originalFormat));
60
+ const outputOptions = config[format];
61
+ if (width || height || quality || targetFormat || outputOptions) {
62
+ // Sharp must be required from the main thread as well to prevent errors when workers exit
63
+ // See https://sharp.pixelplumbing.com/install#worker-threads and https://github.com/lovell/sharp/issues/2263
64
+ if (workers_1.default.isWorker() && !isSharpLoadedOnMainThread) {
65
+ let api = workers_1.default.getWorkerApi();
66
+ await api.callMaster({
67
+ location: __dirname + '/loadSharp.js',
68
+ args: [
69
+ options.packageManager,
70
+ asset.filePath,
71
+ options.shouldAutoInstall,
72
+ ],
73
+ });
74
+ isSharpLoadedOnMainThread = true;
75
+ }
76
+ let inputBuffer = await asset.getBuffer();
77
+ let sharp = await (0, loadSharp_1.default)(options.packageManager, asset.filePath, options.shouldAutoInstall, true);
78
+ let imagePipeline = sharp(inputBuffer, { animated: true });
79
+ imagePipeline.withMetadata();
80
+ if (width || height) {
81
+ imagePipeline.resize(width, height);
82
+ }
83
+ imagePipeline.rotate();
84
+ const normalizedOutputOptions = outputOptions || {};
85
+ if (format === 'jpeg') {
86
+ normalizedOutputOptions.mozjpeg =
87
+ normalizedOutputOptions.mozjpeg ?? true;
88
+ }
89
+ imagePipeline[format]({
90
+ quality,
91
+ ...normalizedOutputOptions,
92
+ });
93
+ asset.type = format;
94
+ let buffer = await imagePipeline.toBuffer();
95
+ asset.setBuffer(buffer);
96
+ }
97
+ return [asset];
98
+ },
99
+ });
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const SHARP_RANGE = '^0.31.1';
4
+ // This is used to load sharp on the main thread, which prevents errors when worker threads exit
5
+ // See https://sharp.pixelplumbing.com/install#worker-threads and https://github.com/lovell/sharp/issues/2263
6
+ module.exports = async (packageManager, filePath, shouldAutoInstall, shouldReturn) => {
7
+ let sharp = await packageManager.require('sharp', filePath, {
8
+ range: SHARP_RANGE,
9
+ shouldAutoInstall: shouldAutoInstall,
10
+ });
11
+ if (shouldReturn) {
12
+ return sharp;
13
+ }
14
+ };
@@ -0,0 +1,247 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateConfig = validateConfig;
4
+ const utils_1 = require("@atlaspack/utils");
5
+ // https://sharp.pixelplumbing.com/api-output#jpeg
6
+ const JPEG_OUTPUT_SCHEMA = {
7
+ type: 'object',
8
+ properties: {
9
+ quality: {
10
+ type: 'number',
11
+ },
12
+ progressive: {
13
+ type: 'boolean',
14
+ },
15
+ chromaSubsampling: {
16
+ type: 'string',
17
+ },
18
+ optimiseCoding: {
19
+ type: 'boolean',
20
+ },
21
+ optimizeCoding: {
22
+ type: 'boolean',
23
+ },
24
+ mozjpeg: {
25
+ type: 'boolean',
26
+ },
27
+ trellisQuantisation: {
28
+ type: 'boolean',
29
+ },
30
+ overshootDeringing: {
31
+ type: 'boolean',
32
+ },
33
+ optimiseScans: {
34
+ type: 'boolean',
35
+ },
36
+ optimizeScans: {
37
+ type: 'boolean',
38
+ },
39
+ quantisationTable: {
40
+ type: 'number',
41
+ },
42
+ quantizationTable: {
43
+ type: 'number',
44
+ },
45
+ force: {
46
+ type: 'boolean',
47
+ },
48
+ },
49
+ additionalProperties: true,
50
+ };
51
+ // https://sharp.pixelplumbing.com/api-output#png
52
+ const PNG_OUTPUT_SCHEMA = {
53
+ type: 'object',
54
+ properties: {
55
+ quality: {
56
+ type: 'number',
57
+ },
58
+ progressive: {
59
+ type: 'boolean',
60
+ },
61
+ compressionLevel: {
62
+ type: 'number',
63
+ },
64
+ adaptiveFiltering: {
65
+ type: 'boolean',
66
+ },
67
+ palette: {
68
+ type: 'boolean',
69
+ },
70
+ colours: {
71
+ type: 'number',
72
+ },
73
+ colors: {
74
+ type: 'number',
75
+ },
76
+ dither: {
77
+ type: 'number',
78
+ },
79
+ force: {
80
+ type: 'boolean',
81
+ },
82
+ },
83
+ additionalProperties: true,
84
+ };
85
+ // https://sharp.pixelplumbing.com/api-output#webp
86
+ const WEBP_OUTPUT_SCHEMA = {
87
+ type: 'object',
88
+ properties: {
89
+ quality: {
90
+ type: 'number',
91
+ },
92
+ alphaQuality: {
93
+ type: 'number',
94
+ },
95
+ lossless: {
96
+ type: 'boolean',
97
+ },
98
+ nearLossless: {
99
+ type: 'boolean',
100
+ },
101
+ smartSubsample: {
102
+ type: 'boolean',
103
+ },
104
+ reductionEffort: {
105
+ type: 'number',
106
+ },
107
+ pageHeight: {
108
+ type: 'number',
109
+ },
110
+ loop: {
111
+ type: 'number',
112
+ },
113
+ delay: {
114
+ type: 'array',
115
+ items: {
116
+ type: 'number',
117
+ },
118
+ },
119
+ force: {
120
+ type: 'boolean',
121
+ },
122
+ },
123
+ additionalProperties: true,
124
+ };
125
+ // https://sharp.pixelplumbing.com/api-output#gif
126
+ const GIF_OUTPUT_SCHEMA = {
127
+ type: 'object',
128
+ properties: {
129
+ pageHeight: {
130
+ type: 'number',
131
+ },
132
+ loop: {
133
+ type: 'number',
134
+ },
135
+ delay: {
136
+ type: 'array',
137
+ items: {
138
+ type: 'number',
139
+ },
140
+ },
141
+ force: {
142
+ type: 'boolean',
143
+ },
144
+ },
145
+ additionalProperties: true,
146
+ };
147
+ // https://sharp.pixelplumbing.com/api-output#tiff
148
+ const TIFF_OUTPUT_SCHEMA = {
149
+ type: 'object',
150
+ properties: {
151
+ quality: {
152
+ type: 'number',
153
+ },
154
+ force: {
155
+ type: 'boolean',
156
+ },
157
+ compression: {
158
+ type: 'string',
159
+ },
160
+ predictor: {
161
+ type: 'string',
162
+ },
163
+ pyramid: {
164
+ type: 'boolean',
165
+ },
166
+ tile: {
167
+ type: 'boolean',
168
+ },
169
+ tileWidth: {
170
+ type: 'number',
171
+ },
172
+ tileHeight: {
173
+ type: 'number',
174
+ },
175
+ xres: {
176
+ type: 'number',
177
+ },
178
+ yres: {
179
+ type: 'number',
180
+ },
181
+ bitdepth: {
182
+ type: 'number',
183
+ },
184
+ },
185
+ additionalProperties: true,
186
+ };
187
+ // https://sharp.pixelplumbing.com/api-output#avif
188
+ const AVIF_OUTPUT_SCHEMA = {
189
+ type: 'object',
190
+ properties: {
191
+ quality: {
192
+ type: 'number',
193
+ },
194
+ lossless: {
195
+ type: 'boolean',
196
+ },
197
+ speed: {
198
+ type: 'number',
199
+ },
200
+ chromaSubsampling: {
201
+ type: 'string',
202
+ },
203
+ },
204
+ additionalProperties: true,
205
+ };
206
+ // https://sharp.pixelplumbing.com/api-output#heif
207
+ const HEIF_OUTPUT_SCHEMA = {
208
+ type: 'object',
209
+ properties: {
210
+ quality: {
211
+ type: 'number',
212
+ },
213
+ compression: {
214
+ type: 'string',
215
+ },
216
+ lossless: {
217
+ type: 'boolean',
218
+ },
219
+ speed: {
220
+ type: 'number',
221
+ },
222
+ chromaSubsampling: {
223
+ type: 'string',
224
+ },
225
+ },
226
+ additionalProperties: true,
227
+ };
228
+ const CONFIG_SCHEMA = {
229
+ type: 'object',
230
+ properties: {
231
+ // Fallback quality
232
+ quality: {
233
+ type: 'number',
234
+ },
235
+ jpeg: JPEG_OUTPUT_SCHEMA,
236
+ png: PNG_OUTPUT_SCHEMA,
237
+ webp: WEBP_OUTPUT_SCHEMA,
238
+ gif: GIF_OUTPUT_SCHEMA,
239
+ tiff: TIFF_OUTPUT_SCHEMA,
240
+ avif: AVIF_OUTPUT_SCHEMA,
241
+ heif: HEIF_OUTPUT_SCHEMA,
242
+ },
243
+ additionalProperties: false,
244
+ };
245
+ function validateConfig(data, filePath) {
246
+ utils_1.validateSchema.diagnostic(CONFIG_SCHEMA, { data, filePath }, '@atlaspack/transformer-image', 'Invalid sharp config');
247
+ }