js-build-tools 6.5.0 → 6.7.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/LICENSE +674 -674
- package/README.md +762 -692
- package/babel.config.js +28 -28
- package/dist/build.js +75 -75
- package/dist/bundle.js +19 -19
- package/dist/bundleMinify.js +7 -7
- package/dist/compileReadme.js +4 -4
- package/dist/copyFiles.js +17 -17
- package/dist/copyFonts.js +4 -4
- package/dist/default.js +5 -5
- package/dist/dist.js +4 -4
- package/dist/distMinify.js +4 -4
- package/dist/docs.js +7 -7
- package/dist/images.js +4 -4
- package/dist/jsdocDocs.js +6 -6
- package/dist/lint.js +16 -16
- package/dist/partials/addToReadme.js +9 -9
- package/dist/partials/beginWatcher.js +4 -4
- package/dist/partials/clean.js +5 -5
- package/dist/partials/copyFor.js +9 -9
- package/dist/partials/distFor.js +6 -6
- package/dist/partials/distForSrc.js +5 -5
- package/dist/partials/distSeries.js +7 -7
- package/dist/partials/imagesFor.js +93 -56
- package/dist/partials/jsdocDocsFor.js +46 -46
- package/dist/partials/lintSource.js +51 -51
- package/dist/partials/loadPeer.js +99 -99
- package/dist/partials/loadPlaywright.js +14 -14
- package/dist/partials/minifyFor.js +20 -20
- package/dist/partials/neostandardLint.js +175 -175
- package/dist/partials/readmeTemplate.js +4 -4
- package/dist/partials/removeDirectory.js +11 -11
- package/dist/partials/resolveDocsMethod.js +6 -6
- package/dist/partials/runOnChange.js +31 -31
- package/dist/partials/sassFor.js +6 -6
- package/dist/partials/serveStatic.js +9 -9
- package/dist/partials/tsFor.js +32 -32
- package/dist/partials/typeDocsFor.js +57 -51
- package/dist/partials.js +176 -176
- package/dist/sourceLint.js +18 -18
- package/dist/test-helpers/isolateGulpCache.js +24 -24
- package/dist/test-helpers/setUp.js +4 -4
- package/dist/testFull.js +5 -5
- package/dist/testQuick.js +5 -5
- package/dist/typeDocs.js +5 -5
- package/dist/typeScript.js +4 -4
- package/dist/utilities/convertMjsFilesForDocs.js +12 -12
- package/dist/utilities/dotGet.js +54 -54
- package/dist/utilities/dotNotate.js +79 -79
- package/dist/utilities/dotSet.js +45 -45
- package/dist/utilities/esmNamedExportsToCjs.js +15 -15
- package/dist/utilities/getBundleConfigs.js +9 -9
- package/dist/utilities/isObject.js +6 -6
- package/dist/utilities/strAfter.js +7 -7
- package/dist/utilities/strBefore.js +7 -7
- package/dist/watchFull.js +4 -4
- package/dist/watchTest.js +4 -4
- package/functions/build.mjs +72 -72
- package/functions/build.test.mjs +763 -759
- package/functions/bundle.mjs +44 -44
- package/functions/bundle.test.mjs +219 -219
- package/functions/bundleMinify.mjs +16 -16
- package/functions/bundleMinify.test.mjs +37 -37
- package/functions/compileReadme.mjs +9 -9
- package/functions/compileReadme.test.mjs +18 -18
- package/functions/copyFiles.mjs +32 -32
- package/functions/copyFiles.test.mjs +78 -78
- package/functions/copyFonts.mjs +9 -9
- package/functions/copyFonts.test.mjs +32 -32
- package/functions/default.mjs +12 -12
- package/functions/default.test.mjs +33 -33
- package/functions/dist.mjs +8 -8
- package/functions/dist.test.mjs +44 -44
- package/functions/distMinify.mjs +9 -9
- package/functions/distMinify.test.mjs +15 -15
- package/functions/docs.mjs +13 -13
- package/functions/docs.test.mjs +45 -45
- package/functions/gulpConfigEntries.test.mjs +23 -23
- package/functions/images.mjs +8 -8
- package/functions/images.test.mjs +142 -142
- package/functions/jsdocDocs.mjs +10 -10
- package/functions/jsdocEsmExports.test.mjs +24 -24
- package/functions/lint.mjs +9 -9
- package/functions/partials/addToReadme.mjs +25 -25
- package/functions/partials/addToReadme.test.mjs +34 -34
- package/functions/partials/beginWatcher.mjs +9 -9
- package/functions/partials/beginWatcher.test.mjs +19 -19
- package/functions/partials/clean.mjs +13 -13
- package/functions/partials/clean.test.mjs +22 -22
- package/functions/partials/copyFor.mjs +15 -15
- package/functions/partials/copyFor.test.mjs +53 -53
- package/functions/partials/distFor.mjs +22 -22
- package/functions/partials/distFor.test.mjs +195 -195
- package/functions/partials/distForSrc.mjs +11 -11
- package/functions/partials/distForSrc.test.mjs +18 -18
- package/functions/partials/distSeries.mjs +21 -21
- package/functions/partials/distSeries.test.mjs +34 -34
- package/functions/partials/imagesFor.mjs +83 -50
- package/functions/partials/imagesFor.test.mjs +287 -229
- package/functions/partials/jsdocDocsFor.mjs +163 -152
- package/functions/partials/jsdocDocsFor.test.mjs +182 -152
- package/functions/partials/lintSource.mjs +41 -41
- package/functions/partials/loadPeer.mjs +76 -76
- package/functions/partials/loadPeer.test.mjs +58 -58
- package/functions/partials/loadPlaywright.mjs +23 -23
- package/functions/partials/loadPlaywright.test.mjs +70 -70
- package/functions/partials/minifyFor.mjs +15 -15
- package/functions/partials/minifyFor.test.mjs +49 -49
- package/functions/partials/neostandardLint.mjs +142 -142
- package/functions/partials/neostandardLint.test.mjs +131 -131
- package/functions/partials/readmeTemplate.mjs +12 -12
- package/functions/partials/readmeTemplate.test.mjs +34 -34
- package/functions/partials/removeDirectory.mjs +34 -34
- package/functions/partials/removeDirectory.test.mjs +72 -72
- package/functions/partials/resolveDocsMethod.mjs +10 -10
- package/functions/partials/resolveDocsMethod.test.mjs +33 -33
- package/functions/partials/runOnChange.mjs +54 -54
- package/functions/partials/runOnChange.test.mjs +95 -95
- package/functions/partials/sassFor.mjs +25 -25
- package/functions/partials/sassFor.test.mjs +81 -81
- package/functions/partials/serveStatic.mjs +47 -47
- package/functions/partials/serveStatic.test.mjs +71 -71
- package/functions/partials/tsFor.mjs +92 -92
- package/functions/partials/tsFor.test.mjs +88 -88
- package/functions/partials/typeDocsFor.mjs +231 -227
- package/functions/partials/typeDocsFor.test.mjs +263 -252
- package/functions/partials.mjs +31 -31
- package/functions/partials.test.mjs +7 -7
- package/functions/sass.mjs +4 -4
- package/functions/sass.test.mjs +31 -31
- package/functions/sourceLint.mjs +13 -13
- package/functions/sourceLint.test.mjs +166 -166
- package/functions/test-helpers/isolateGulpCache.mjs +16 -16
- package/functions/test-helpers/neostandardLintWithRealNeostandard.mjs +40 -40
- package/functions/test-helpers/setUp.mjs +100 -100
- package/functions/test-helpers/setUp.test.mjs +19 -19
- package/functions/testFull.mjs +17 -17
- package/functions/testFull.test.mjs +17 -17
- package/functions/testHelpers.mjs +10 -10
- package/functions/testHelpers.test.mjs +7 -7
- package/functions/testQuick.mjs +17 -17
- package/functions/testQuick.test.mjs +17 -17
- package/functions/typeDocs.mjs +9 -9
- package/functions/typeDocs.test.mjs +11 -11
- package/functions/typeScript.mjs +8 -8
- package/functions/typeScript.test.mjs +11 -11
- package/functions/utilities/convertMjsFilesForDocs.mjs +34 -34
- package/functions/utilities/convertMjsFilesForDocs.test.mjs +58 -58
- package/functions/utilities/dotGet.mjs +49 -49
- package/functions/utilities/dotNotate.mjs +73 -73
- package/functions/utilities/dotNotate.test.mjs +41 -41
- package/functions/utilities/dotSet.mjs +40 -40
- package/functions/utilities/esmNamedExportsToCjs.mjs +30 -30
- package/functions/utilities/esmNamedExportsToCjs.test.mjs +47 -47
- package/functions/utilities/getBundleConfigs.mjs +30 -30
- package/functions/utilities/isObject.mjs +8 -8
- package/functions/utilities/strAfter.mjs +12 -12
- package/functions/utilities/strBefore.mjs +12 -12
- package/functions/watchFull.mjs +9 -9
- package/functions/watchFull.test.mjs +41 -41
- package/functions/watchTest.mjs +10 -10
- package/functions/watchTest.test.mjs +49 -49
- package/gulp.config.js +4 -4
- package/gulp.config.mjs +344 -327
- package/gulpfile.base.js +51 -51
- package/gulpfile.base.mjs +29 -29
- package/jsdoc.base.js +16 -16
- package/jsdoc.esmExports.js +17 -17
- package/package.json +146 -145
|
@@ -1,229 +1,287 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
'
|
|
16
|
-
'
|
|
17
|
-
'
|
|
18
|
-
' xmlns:
|
|
19
|
-
' xmlns:
|
|
20
|
-
' xmlns="http://www.w3.org/
|
|
21
|
-
' xmlns:
|
|
22
|
-
' xmlns
|
|
23
|
-
' xmlns:
|
|
24
|
-
'
|
|
25
|
-
'
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
'
|
|
32
|
-
'
|
|
33
|
-
'
|
|
34
|
-
'
|
|
35
|
-
'
|
|
36
|
-
'
|
|
37
|
-
'
|
|
38
|
-
'
|
|
39
|
-
' <dc:
|
|
40
|
-
'
|
|
41
|
-
'
|
|
42
|
-
'
|
|
43
|
-
'
|
|
44
|
-
'
|
|
45
|
-
' <
|
|
46
|
-
'
|
|
47
|
-
'
|
|
48
|
-
'
|
|
49
|
-
'
|
|
50
|
-
'
|
|
51
|
-
'
|
|
52
|
-
'
|
|
53
|
-
'
|
|
54
|
-
' inkscape:
|
|
55
|
-
' inkscape:
|
|
56
|
-
'
|
|
57
|
-
'
|
|
58
|
-
'
|
|
59
|
-
'
|
|
60
|
-
' inkscape:
|
|
61
|
-
' inkscape:
|
|
62
|
-
' inkscape:
|
|
63
|
-
' inkscape:window-
|
|
64
|
-
' inkscape:
|
|
65
|
-
'
|
|
66
|
-
'
|
|
67
|
-
'
|
|
68
|
-
'
|
|
69
|
-
'
|
|
70
|
-
'
|
|
71
|
-
'
|
|
72
|
-
'
|
|
73
|
-
'
|
|
74
|
-
'
|
|
75
|
-
'
|
|
76
|
-
'
|
|
77
|
-
'
|
|
78
|
-
'
|
|
79
|
-
'
|
|
80
|
-
'
|
|
81
|
-
'
|
|
82
|
-
'
|
|
83
|
-
'
|
|
84
|
-
'
|
|
85
|
-
'
|
|
86
|
-
'
|
|
87
|
-
'
|
|
88
|
-
'
|
|
89
|
-
'
|
|
90
|
-
'
|
|
91
|
-
'
|
|
92
|
-
'
|
|
93
|
-
'
|
|
94
|
-
'
|
|
95
|
-
'
|
|
96
|
-
'
|
|
97
|
-
'
|
|
98
|
-
'
|
|
99
|
-
'
|
|
100
|
-
'
|
|
101
|
-
'
|
|
102
|
-
'
|
|
103
|
-
'
|
|
104
|
-
'
|
|
105
|
-
'
|
|
106
|
-
'
|
|
107
|
-
'
|
|
108
|
-
'
|
|
109
|
-
'
|
|
110
|
-
'
|
|
111
|
-
'
|
|
112
|
-
'
|
|
113
|
-
'
|
|
114
|
-
'
|
|
115
|
-
'
|
|
116
|
-
'
|
|
117
|
-
'
|
|
118
|
-
'
|
|
119
|
-
'
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
header.
|
|
146
|
-
header.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
pngChunk('
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
test('
|
|
189
|
-
const srcPath = gulpConfig.get('srcPath')
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
expect(fs.existsSync(
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
1
|
+
import { execFileSync } from 'child_process'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import * as setUp from '../test-helpers/setUp.mjs'
|
|
4
|
+
import os from 'os'
|
|
5
|
+
import path from 'path'
|
|
6
|
+
import zlib from 'zlib'
|
|
7
|
+
import { imageminPlugins, imagesFor, loadImagemin } from './imagesFor.mjs'
|
|
8
|
+
import { isolateGulpCache } from '../test-helpers/isolateGulpCache.mjs'
|
|
9
|
+
|
|
10
|
+
setUp.setDefaults('test-images-for')
|
|
11
|
+
const clearImageCache = isolateGulpCache('images-for')
|
|
12
|
+
const gulpConfig = setUp.gulpConfig
|
|
13
|
+
|
|
14
|
+
const imageContents = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n' +
|
|
15
|
+
'<!-- Created with Inkscape (http://www.inkscape.org/) -->\n' +
|
|
16
|
+
'\n' +
|
|
17
|
+
'<svg\n' +
|
|
18
|
+
' xmlns:dc="http://purl.org/dc/elements/1.1/"\n' +
|
|
19
|
+
' xmlns:cc="http://creativecommons.org/ns#"\n' +
|
|
20
|
+
' xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\n' +
|
|
21
|
+
' xmlns:svg="http://www.w3.org/2000/svg"\n' +
|
|
22
|
+
' xmlns="http://www.w3.org/2000/svg"\n' +
|
|
23
|
+
' xmlns:xlink="http://www.w3.org/1999/xlink"\n' +
|
|
24
|
+
' xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"\n' +
|
|
25
|
+
' xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"\n' +
|
|
26
|
+
' id="svg2"\n' +
|
|
27
|
+
' version="1.1"\n' +
|
|
28
|
+
' inkscape:version="0.91 r13725"\n' +
|
|
29
|
+
' width="600"\n' +
|
|
30
|
+
' height="600"\n' +
|
|
31
|
+
' viewBox="0 0 600 600"\n' +
|
|
32
|
+
' sodipodi:docname="logo.svg">\n' +
|
|
33
|
+
' <metadata\n' +
|
|
34
|
+
' id="metadata8">\n' +
|
|
35
|
+
' <rdf:RDF>\n' +
|
|
36
|
+
' <cc:Work\n' +
|
|
37
|
+
' rdf:about="">\n' +
|
|
38
|
+
' <dc:format>image/svg+xml</dc:format>\n' +
|
|
39
|
+
' <dc:type\n' +
|
|
40
|
+
' rdf:resource="http://purl.org/dc/dcmitype/StillImage" />\n' +
|
|
41
|
+
' <dc:title></dc:title>\n' +
|
|
42
|
+
' </cc:Work>\n' +
|
|
43
|
+
' </rdf:RDF>\n' +
|
|
44
|
+
' </metadata>\n' +
|
|
45
|
+
' <defs\n' +
|
|
46
|
+
' id="defs6" />\n' +
|
|
47
|
+
' <sodipodi:namedview\n' +
|
|
48
|
+
' pagecolor="#ffffff"\n' +
|
|
49
|
+
' bordercolor="#666666"\n' +
|
|
50
|
+
' borderopacity="1"\n' +
|
|
51
|
+
' objecttolerance="10"\n' +
|
|
52
|
+
' gridtolerance="10"\n' +
|
|
53
|
+
' guidetolerance="10"\n' +
|
|
54
|
+
' inkscape:pageopacity="0"\n' +
|
|
55
|
+
' inkscape:pageshadow="2"\n' +
|
|
56
|
+
' inkscape:window-width="1280"\n' +
|
|
57
|
+
' inkscape:window-height="737"\n' +
|
|
58
|
+
' id="namedview4"\n' +
|
|
59
|
+
' showgrid="false"\n' +
|
|
60
|
+
' inkscape:zoom="0.39333333"\n' +
|
|
61
|
+
' inkscape:cx="300"\n' +
|
|
62
|
+
' inkscape:cy="300"\n' +
|
|
63
|
+
' inkscape:window-x="-8"\n' +
|
|
64
|
+
' inkscape:window-y="-8"\n' +
|
|
65
|
+
' inkscape:window-maximized="1"\n' +
|
|
66
|
+
' inkscape:current-layer="svg2" />\n' +
|
|
67
|
+
' <image\n' +
|
|
68
|
+
' width="600"\n' +
|
|
69
|
+
' height="600"\n' +
|
|
70
|
+
' preserveAspectRatio="none"\n' +
|
|
71
|
+
' xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKAAAACgCAYAAACLz2ctAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\n' +
|
|
72
|
+
'AAADsQAAA7EB9YPtSQAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAhrSURB\n' +
|
|
73
|
+
'VHic7d3fi1x3Gcfx97M7TdKYYNPYbLaxlVZrUaK1iviToiIpeNFIwQuLBW8UEQTv9C/wSvDS+yKo\n' +
|
|
74
|
+
'CFopiFe2QVpqMKVYf0DaRmibZnfTRpNs9lez+3hxzq7T3ZnZmXO+3/PMmf284DDJzJznPGfOZ79n\n' +
|
|
75
|
+
'zpmzs+buiESZim5A9jYFUEIpgBJKAZRQCqCEUgAllAIooRRACaUASigFUEIpgBJKAZRQCqCEUgAl\n' +
|
|
76
|
+
'lAIooRRACaUASigFUEIpgBKqU2dmM5spa2wAXk4bXf/vd7/3eQ6AbZumdvl/931T2+6b6rOODtzs\n' +
|
|
77
|
+
'00Ov3gY+7u5uZr2W36+33R6fBt509/XBW6A3M9sPHAPWh1ynXe/bZR0HbYN+6zwF3KgVQOBbwGzN\n' +
|
|
78
|
+
'Gq1XbJfkfgJcqTjvXcD3EvaSax2fr7sL3p+kDemlzmvblu2yXwEcX3Ve233JushLARxj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gZl9fsRlpLqy+DV3/1eiWjImut8DnqYY6QbpAI+a2eNmtn+34uWu+/4a/XXT6DeB\n' +
|
|
103
|
+
'OgDlZeKfG2G+B4ATZvZbdz/f6wlmdj/F7jyFl/otR9rN3B0z+z5wb8Ual4CzwBvAMsWVxg9S7HpT\n' +
|
|
104
|
+
'fPrxNvCzKgdAMv46Znac6uGD4tLu04n62e4m8ITCN7mmgLuimxjgyQpH3dIiHXZeqz8OHHjK3Z+P\n' +
|
|
105
|
+
'bkTy6pDuHF0qDvzG3c9GNyL5TQEXopvosg78QuHbOzrAq9FNlK4Cv3L3l6MbkeZ03P2qmV1mhC+U\n' +
|
|
106
|
+
'yeAcxQHHcmAPEmDzk5AzQcu/QXGa5ZcK395kxe9qg5mdAk41tNw14FngaXdfamiZMoa2AghgZl8H\n' +
|
|
107
|
+
'vphxee9Q/E7G0+6+mHE50hLbA2jA14CHSHt6Zg54EfiLu9f5ZRuZMO8K4NadxdeHPUzx7UZVP8+9\n' +
|
|
108
|
+
'TBG6F919vnKHMtF6BnDrQbNZ4LMU3yY1w84v7naKX6C+QXFRwhubk7vfyNGwTJaBAdzxZLMDwBGK\n' +
|
|
109
|
+
'g4glYMVHKSCyzUgBFEmtzd+OJRNAAZRQCqCEUgAllAIooRRACaUASigFUEIpgBJKAZRQCqCEUgAl\n' +
|
|
110
|
+
'lAIooRRACaUASigFUEIpgBJKAZRQCqCEUgAllAIooRRACaUASigFUEL9D1MqMi7YkUEVAAAAAElF\n' +
|
|
111
|
+
'TkSuQmCC\n' +
|
|
112
|
+
'"\n' +
|
|
113
|
+
' id="image10"\n' +
|
|
114
|
+
' x="0"\n' +
|
|
115
|
+
' y="0" />\n' +
|
|
116
|
+
' <path\n' +
|
|
117
|
+
' style="fill:#000000"\n' +
|
|
118
|
+
' d="M 19.039097,494.38241 C 2.0018627,482.75861 -2.8301068,468.02182 5.0071177,451.587 8.2776829,444.72855 15.162733,436.35919 20.307229,432.98839 c 8.904129,-5.83422 9.948263,-5.67522 21.727331,3.30915 28.014638,21.3678 44.091105,18.882 51.54879,-7.97059 C 99.533959,406.9008 98.83533,123.18555 92.8125,115.28305 90.196335,111.85041 81.496733,108.63382 73.125,108.00381 58.734191,106.92084 58.077731,106.30388 56.961131,92.8125 L 55.797259,78.75 l 163.053411,0 163.05342,0 2.57381,11.71845 c 2.93006,13.34047 -1.71086,18.13302 -17.64754,18.22413 C 347.54041,108.80285 345,115.82292 345,169.01786 l 0,48.48214 67.5,0 67.5,0 0,-48.1688 c 0,-41.90267 -0.89209,-48.97614 -6.85778,-54.37499 C 469.37044,111.54279 462.75847,108.75 458.44894,108.75 443.44309,108.75 438.75,104.6341 438.75,91.473791 l 0,-12.723791 80.85139,0 80.85135,0 -1.16385,14.0625 c -1.13201,13.67745 -1.60515,14.09431 -17.27948,15.22432 -13.44982,0.96964 -16.73767,2.79799 -19.87627,11.0531 -5.80185,15.26002 -2.83763,249.42009 3.25016,256.74719 2.61705,3.14985 11.47643,6.80123 19.6875,8.11425 14.52533,2.32268 14.9292,2.79386 14.9292,17.41755 l 0,15.03026 -79.6875,-1.01208 -79.6875,-1.01209 -1.1367,-13.60684 c -1.13565,-13.59401 -1.11975,-13.60939 16.875,-16.30515 9.90645,-1.4841 19.25149,-4.64227 20.76679,-7.01816 1.5153,-2.37593 2.78092,-30.05423 2.8125,-61.50735 L 480,258.75 l -67.59289,0 -67.5929,0 1.0304,60.9375 1.03039,60.9375 19.6875,3.3399 c 20.4921,3.4764 22.16576,5.78036 17.32391,23.8476 -2.25337,8.40847 -2.53065,8.4375 -80.57378,8.4375 l -78.31263,0 0,-14.95567 c 0,-14.53673 0.41823,-15.02258 14.9292,-17.34297 8.21107,-1.31302 17.07044,-4.96657 19.6875,-8.11909 3.63727,-4.38139 4.7583,-35.56081 4.7583,-132.34294 0,-69.63615 -1.23091,-127.84279 -2.73535,-129.3481 -9.73748,-9.7431 -68.9232,-8.34789 -79.15408,1.86593 -3.08612,3.08097 -4.99292,46.77065 -6.52417,149.48557 -1.45514,97.60931 -3.64592,149.67975 -6.6905,159.01994 -13.55129,41.57292 -61.40288,74.9124 -111.000242,77.33685 -22.754302,1.11229 -28.166407,0.0821 -39.231561,-7.46711 z"\n' +
|
|
119
|
+
' id="path3338"\n' +
|
|
120
|
+
' inkscape:connector-curvature="0" />\n' +
|
|
121
|
+
'</svg>\n'
|
|
122
|
+
|
|
123
|
+
const imageCompressed = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="600" height="600"><image width="600" height="600" preserveAspectRatio="none" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKAAAACgCAYAAACLz2ctAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz AAADsQAAA7EB9YPtSQAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAhrSURB VHic7d3fi1x3Gcfx97M7TdKYYNPYbLaxlVZrUaK1iviToiIpeNFIwQuLBW8UEQTv9C/wSvDS+yKo CFopiFe2QVpqMKVYf0DaRmibZnfTRpNs9lez+3hxzq7T3ZnZmXO+3/PMmf284DDJzJznPGfOZ79n zpmzs+buiESZim5A9jYFUEIpgBJKAZRQCqCEUgAllAIooRRACaUASigFUEIpgBJKAZRQCqCEUgAl lAIooRRACaUASigFUEIpgBKqU2dmM5spa2wAXk4bXf/vd7/3eQ6AbZumdvl/931T2+6b6rOODtzs 00Ov3gY+7u5uZr2W36+33R6fBt509/XBW6A3M9sPHAPWh1ynXe/bZR0HbYN+6zwF3KgVQOBbwGzN Gq1XbJfkfgJcqTjvXcD3EvaSax2fr7sL3p+kDemlzmvblu2yXwEcX3Ve233JushLARxjB2rMO/kB NLNpah7EyEB7YQQ8UGcE1OiXV50QtSWA+xTA8VUnRHV23026xap+N0y5Cz4GHAIO97i9GziYps+R rAGXgXlgobx9G1gtp0M9ej0M3EbRc9M/WOtd/W5Oc8Bld9+oUrBr2xwHZrpuj9L8hw9LwGvANeB6 17QIXKscwN2U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AIooRRACaUASigFUEIpgBJKAZRQCqCEUgAl lAIooRRACaUASigFUEIpgBJKAZRQCqCEUgAllAIooRRACaUASigFUEL9D1MqMi7YkUEVAAAAAElF TkSuQmCC"/><path style="fill:#000" d="M19.04 494.382C2.001 482.76-2.83 468.022 5.006 451.587c3.27-6.858 10.156-15.228 15.3-18.599 8.904-5.834 9.948-5.675 21.728 3.31 28.014 21.367 44.09 18.882 51.548-7.971 5.951-21.426 5.252-305.141-.77-313.044-2.617-3.433-11.316-6.65-19.688-7.28-14.39-1.082-15.047-1.7-16.164-15.19L55.797 78.75h326.107l2.574 11.718c2.93 13.34-1.711 18.133-17.648 18.225-19.29.11-21.83 7.13-21.83 60.325V217.5h135v-48.169c0-41.902-.892-48.976-6.858-54.375-3.772-3.413-10.384-6.206-14.693-6.206-15.006 0-19.699-4.116-19.699-17.276V78.75h161.703l-1.164 14.063c-1.132 13.677-1.605 14.094-17.28 15.224-13.45.97-16.737 2.798-19.876 11.053-5.802 15.26-2.837 249.42 3.25 256.747 2.617 3.15 11.477 6.801 19.688 8.114C599.596 386.274 600 386.745 600 401.37v15.03l-79.687-1.012-79.688-1.012-1.137-13.607c-1.135-13.594-1.12-13.61 16.875-16.305 9.907-1.484 19.252-4.642 20.767-7.018 1.515-2.376 2.781-30.054 2.813-61.508L480 258.75H344.814l1.03 60.938 1.031 60.937 19.688 3.34c20.492 3.476 22.165 5.78 17.323 23.848-2.253 8.408-2.53 8.437-80.573 8.437H225v-14.956c0-14.536.418-15.022 14.93-17.343 8.21-1.313 17.07-4.966 19.687-8.119 3.637-4.381 4.758-35.56 4.758-132.343 0-69.636-1.23-127.842-2.735-129.348-9.738-9.743-68.924-8.348-79.154 1.866-3.087 3.081-4.993 46.77-6.525 149.486-1.455 97.609-3.646 149.68-6.69 159.02-13.551 41.573-61.403 74.912-111 77.337-22.755 1.112-28.167.082-39.232-7.468z"/></svg>'
|
|
124
|
+
|
|
125
|
+
// Build a small but real PNG so the test exercises binary data (a text-only SVG hid Gulp 5's utf8 corruption of images).
|
|
126
|
+
const crc32 = buffer => {
|
|
127
|
+
let crc = 0xffffffff
|
|
128
|
+
for (const byte of buffer) {
|
|
129
|
+
crc ^= byte
|
|
130
|
+
for (let bit = 0; bit < 8; bit++) {
|
|
131
|
+
crc = (crc >>> 1) ^ (0xedb88320 & -(crc & 1))
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return (crc ^ 0xffffffff) >>> 0
|
|
135
|
+
}
|
|
136
|
+
const pngChunk = (type, data) => {
|
|
137
|
+
const length = Buffer.alloc(4)
|
|
138
|
+
length.writeUInt32BE(data.length)
|
|
139
|
+
const body = Buffer.concat([Buffer.from(type), data])
|
|
140
|
+
const crc = Buffer.alloc(4)
|
|
141
|
+
crc.writeUInt32BE(crc32(body))
|
|
142
|
+
return Buffer.concat([length, body, crc])
|
|
143
|
+
}
|
|
144
|
+
const makePng = (size = 32) => {
|
|
145
|
+
const header = Buffer.alloc(13)
|
|
146
|
+
header.writeUInt32BE(size, 0)
|
|
147
|
+
header.writeUInt32BE(size, 4)
|
|
148
|
+
header.set([8, 2, 0, 0, 0], 8) // 8-bit RGB
|
|
149
|
+
const rows = Buffer.alloc((size * 3 + 1) * size)
|
|
150
|
+
for (let y = 0; y < size; y++) {
|
|
151
|
+
for (let x = 0; x < size * 3; x++) {
|
|
152
|
+
rows[y * (size * 3 + 1) + 1 + x] = (x * 37 + y * 91) % 256 // bytes above 0x7f exercise utf8 corruption
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return Buffer.concat([
|
|
156
|
+
Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),
|
|
157
|
+
pngChunk('IHDR', header),
|
|
158
|
+
pngChunk('IDAT', zlib.deflateSync(rows)),
|
|
159
|
+
pngChunk('IEND', Buffer.alloc(0))
|
|
160
|
+
])
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// A JPEG at quality 100, encoded from a generated image by the cjpeg binary the mozjpeg dependency installs
|
|
164
|
+
const makeJpeg = (size = 64) => {
|
|
165
|
+
const pixels = Buffer.alloc(size * size * 3)
|
|
166
|
+
for (let i = 0; i < pixels.length; i++) {
|
|
167
|
+
pixels[i] = (i * 37 + Math.floor(i / (size * 3)) * 91) % 256
|
|
168
|
+
}
|
|
169
|
+
const ppm = Buffer.concat([Buffer.from(`P6\n${size} ${size}\n255\n`), pixels])
|
|
170
|
+
// mozjpeg's exports field hides its files, and Jest runs from the project root
|
|
171
|
+
const cjpeg = path.resolve('node_modules', 'mozjpeg', 'vendor', 'cjpeg')
|
|
172
|
+
return execFileSync(cjpeg, ['-quality', '100'], { input: ppm })
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Run imagesFor over one file and resolve with the written output
|
|
176
|
+
const optimize = (file, to) => new Promise((resolve, reject) => {
|
|
177
|
+
imagesFor(file, to)
|
|
178
|
+
.on('finish', () => resolve(fs.readFileSync(`${to}/${path.basename(file)}`)))
|
|
179
|
+
.on('error', reject)
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
// The cache outlives a run, so clear it or a stale result from an older imagemin can pass
|
|
183
|
+
beforeEach(() => clearImageCache().then(setUp.beforeEach))
|
|
184
|
+
|
|
185
|
+
afterEach(setUp.afterEach)
|
|
186
|
+
|
|
187
|
+
describe('imagesFor', () => {
|
|
188
|
+
test('copies the images directory and moves the optimized images', done => {
|
|
189
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
190
|
+
const imagesFile = `${srcPath}/imageToCopy.svg`
|
|
191
|
+
fs.writeFileSync(imagesFile, imageContents)
|
|
192
|
+
expect.assertions(3)
|
|
193
|
+
const oldContents = fs.readFileSync(imagesFile).toString()
|
|
194
|
+
expect(oldContents).toEqual(imageContents)
|
|
195
|
+
const browserPath = gulpConfig.get('browser.to')
|
|
196
|
+
imagesFor(imagesFile, browserPath)
|
|
197
|
+
.on('finish', () => {
|
|
198
|
+
expect(fs.existsSync(browserPath)).toBeTruthy()
|
|
199
|
+
const movedContents = fs.readFileSync(`${browserPath}/imageToCopy.svg`).toString()
|
|
200
|
+
expect(movedContents).toEqual(imageCompressed)
|
|
201
|
+
done()
|
|
202
|
+
})
|
|
203
|
+
.on('error', error => {
|
|
204
|
+
console.error('Encountered error', error)
|
|
205
|
+
done()
|
|
206
|
+
})
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
test('keeps binary images intact - Gulp 5 would otherwise decode them as utf8 text and corrupt or drop them', done => {
|
|
210
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
211
|
+
const pngFile = `${srcPath}/binary.png`
|
|
212
|
+
const original = makePng()
|
|
213
|
+
fs.writeFileSync(pngFile, original)
|
|
214
|
+
expect.assertions(4)
|
|
215
|
+
const browserPath = gulpConfig.get('browser.to')
|
|
216
|
+
imagesFor(pngFile, browserPath)
|
|
217
|
+
.on('finish', () => {
|
|
218
|
+
const outputPath = `${browserPath}/binary.png`
|
|
219
|
+
expect(fs.existsSync(outputPath)).toBeTruthy()
|
|
220
|
+
const optimized = fs.readFileSync(outputPath)
|
|
221
|
+
// Still a real PNG (signature and IEND intact) and never bigger than what went in.
|
|
222
|
+
expect(optimized.subarray(0, 8).equals(original.subarray(0, 8))).toBeTruthy()
|
|
223
|
+
expect(optimized.subarray(-12).equals(original.subarray(-12))).toBeTruthy()
|
|
224
|
+
expect(optimized.length).toBeLessThanOrEqual(original.length)
|
|
225
|
+
done()
|
|
226
|
+
})
|
|
227
|
+
.on('error', error => {
|
|
228
|
+
console.error('Encountered error', error)
|
|
229
|
+
done()
|
|
230
|
+
})
|
|
231
|
+
})
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
describe('images.jpegQuality', () => {
|
|
235
|
+
test('compresses JPEGs to the configured quality, never reusing another quality\'s cached result', async () => {
|
|
236
|
+
expect.assertions(4)
|
|
237
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
238
|
+
const jpegFile = `${srcPath}/photo.jpg`
|
|
239
|
+
fs.writeFileSync(jpegFile, makeJpeg())
|
|
240
|
+
const browserPath = gulpConfig.get('browser.to')
|
|
241
|
+
try {
|
|
242
|
+
const atDefault = await optimize(jpegFile, `${browserPath}/default`)
|
|
243
|
+
gulpConfig.set('images.jpegQuality', 95)
|
|
244
|
+
const at95 = await optimize(jpegFile, `${browserPath}/q95`)
|
|
245
|
+
// Both still JPEGs (start-of-image marker)
|
|
246
|
+
expect(atDefault.subarray(0, 2).equals(Buffer.from([0xff, 0xd8]))).toBeTruthy()
|
|
247
|
+
expect(at95.subarray(0, 2).equals(Buffer.from([0xff, 0xd8]))).toBeTruthy()
|
|
248
|
+
// Same input, so a shared cache entry would make these identical: 95 keeps more detail than mozjpeg's 75
|
|
249
|
+
expect(at95.equals(atDefault)).toBe(false)
|
|
250
|
+
expect(at95.length).toBeGreaterThan(atDefault.length)
|
|
251
|
+
} finally {
|
|
252
|
+
gulpConfig.set('images.jpegQuality', false)
|
|
253
|
+
}
|
|
254
|
+
}, 30000)
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
describe('imageminPlugins', () => {
|
|
258
|
+
test('builds imagemin\'s default plugins in order, passing the quality to mozjpeg only', async () => {
|
|
259
|
+
expect.assertions(2)
|
|
260
|
+
const calls = []
|
|
261
|
+
const factory = name => Promise.resolve((...args) => {
|
|
262
|
+
calls.push([name, ...args])
|
|
263
|
+
return name
|
|
264
|
+
})
|
|
265
|
+
const plugins = { gifsicle: factory('gifsicle'), mozjpeg: factory('mozjpeg'), optipng: factory('optipng'), svgo: factory('svgo') }
|
|
266
|
+
expect(await Promise.all(imageminPlugins(85, plugins))).toEqual(['gifsicle', 'mozjpeg', 'optipng', 'svgo'])
|
|
267
|
+
expect(calls).toEqual([['gifsicle'], ['mozjpeg', { quality: 85 }], ['optipng'], ['svgo']])
|
|
268
|
+
})
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
describe('loadImagemin', () => {
|
|
272
|
+
test('loads the gulp-imagemin plugin factory from the project directory', () => {
|
|
273
|
+
expect.assertions(1)
|
|
274
|
+
expect(typeof loadImagemin()).toBe('function')
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
test('throws a helpful error with install instructions when gulp-imagemin is not installed', () => {
|
|
278
|
+
expect.assertions(2)
|
|
279
|
+
const emptyProject = fs.mkdtempSync(`${os.tmpdir()}/no-imagemin-`)
|
|
280
|
+
try {
|
|
281
|
+
expect(() => loadImagemin(emptyProject)).toThrow(/optional peer dependency gulp-imagemin, which is not installed/)
|
|
282
|
+
expect(() => loadImagemin(emptyProject)).toThrow(/github:jheagle\/gulp-imagemin#common-js-compatibility/)
|
|
283
|
+
} finally {
|
|
284
|
+
fs.rmSync(emptyProject, { recursive: true })
|
|
285
|
+
}
|
|
286
|
+
})
|
|
287
|
+
})
|