sharp 0.32.6 → 0.33.0-alpha.10

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.
@@ -1,40 +0,0 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- 'use strict';
5
-
6
- const fs = require('fs');
7
- const path = require('path');
8
-
9
- const libvips = require('../lib/libvips');
10
- const platform = require('../lib/platform');
11
-
12
- const minimumLibvipsVersion = libvips.minimumLibvipsVersion;
13
-
14
- const platformAndArch = platform();
15
-
16
- if (platformAndArch.startsWith('win32')) {
17
- const buildReleaseDir = path.join(__dirname, '..', 'build', 'Release');
18
- libvips.log(`Creating ${buildReleaseDir}`);
19
- try {
20
- libvips.mkdirSync(buildReleaseDir);
21
- } catch (err) {}
22
- const vendorLibDir = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion, platformAndArch, 'lib');
23
- libvips.log(`Copying DLLs from ${vendorLibDir} to ${buildReleaseDir}`);
24
- try {
25
- fs
26
- .readdirSync(vendorLibDir)
27
- .filter(function (filename) {
28
- return /\.dll$/.test(filename);
29
- })
30
- .forEach(function (filename) {
31
- fs.copyFileSync(
32
- path.join(vendorLibDir, filename),
33
- path.join(buildReleaseDir, filename)
34
- );
35
- });
36
- } catch (err) {
37
- libvips.log(err);
38
- process.exit(1);
39
- }
40
- }
@@ -1,222 +0,0 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- 'use strict';
5
-
6
- const fs = require('fs');
7
- const os = require('os');
8
- const path = require('path');
9
- const stream = require('stream');
10
- const zlib = require('zlib');
11
- const { createHash } = require('crypto');
12
-
13
- const detectLibc = require('detect-libc');
14
- const semverCoerce = require('semver/functions/coerce');
15
- const semverLessThan = require('semver/functions/lt');
16
- const semverSatisfies = require('semver/functions/satisfies');
17
- const simpleGet = require('simple-get');
18
- const tarFs = require('tar-fs');
19
-
20
- const agent = require('../lib/agent');
21
- const libvips = require('../lib/libvips');
22
- const platform = require('../lib/platform');
23
-
24
- const minimumGlibcVersionByArch = {
25
- arm: '2.28',
26
- arm64: '2.17',
27
- x64: '2.17'
28
- };
29
-
30
- const hasSharpPrebuild = [
31
- 'darwin-x64',
32
- 'darwin-arm64',
33
- 'linux-arm64',
34
- 'linux-x64',
35
- 'linuxmusl-x64',
36
- 'linuxmusl-arm64',
37
- 'win32-ia32',
38
- 'win32-x64'
39
- ];
40
-
41
- const { minimumLibvipsVersion, minimumLibvipsVersionLabelled } = libvips;
42
- const localLibvipsDir = process.env.npm_config_sharp_libvips_local_prebuilds || '';
43
- const distHost = process.env.npm_config_sharp_libvips_binary_host || 'https://github.com/lovell/sharp-libvips/releases/download';
44
- const distBaseUrl = process.env.npm_config_sharp_dist_base_url || process.env.SHARP_DIST_BASE_URL || `${distHost}/v${minimumLibvipsVersionLabelled}/`;
45
- const installationForced = !!(process.env.npm_config_sharp_install_force || process.env.SHARP_INSTALL_FORCE);
46
-
47
- const fail = function (err) {
48
- libvips.log(err);
49
- if (err.code === 'EACCES') {
50
- libvips.log('Are you trying to install as a root or sudo user?');
51
- libvips.log('- For npm <= v6, try again with the "--unsafe-perm" flag');
52
- libvips.log('- For npm >= v8, the user must own the directory "npm install" is run in');
53
- }
54
- libvips.log('Please see https://sharp.pixelplumbing.com/install for required dependencies');
55
- process.exit(1);
56
- };
57
-
58
- const handleError = function (err) {
59
- if (installationForced) {
60
- libvips.log(`Installation warning: ${err.message}`);
61
- } else {
62
- throw err;
63
- }
64
- };
65
-
66
- const verifyIntegrity = function (platformAndArch) {
67
- const expected = libvips.integrity(platformAndArch);
68
- if (installationForced || !expected) {
69
- libvips.log(`Integrity check skipped for ${platformAndArch}`);
70
- return new stream.PassThrough();
71
- }
72
- const hash = createHash('sha512');
73
- return new stream.Transform({
74
- transform: function (chunk, _encoding, done) {
75
- hash.update(chunk);
76
- done(null, chunk);
77
- },
78
- flush: function (done) {
79
- const digest = `sha512-${hash.digest('base64')}`;
80
- if (expected !== digest) {
81
- try {
82
- libvips.removeVendoredLibvips();
83
- } catch (err) {
84
- libvips.log(err.message);
85
- }
86
- libvips.log(`Integrity expected: ${expected}`);
87
- libvips.log(`Integrity received: ${digest}`);
88
- done(new Error(`Integrity check failed for ${platformAndArch}`));
89
- } else {
90
- libvips.log(`Integrity check passed for ${platformAndArch}`);
91
- done();
92
- }
93
- }
94
- });
95
- };
96
-
97
- const extractTarball = function (tarPath, platformAndArch) {
98
- const versionedVendorPath = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion, platformAndArch);
99
- libvips.mkdirSync(versionedVendorPath);
100
-
101
- const ignoreVendorInclude = hasSharpPrebuild.includes(platformAndArch) && !process.env.npm_config_build_from_source;
102
- const ignore = function (name) {
103
- return ignoreVendorInclude && name.includes('include/');
104
- };
105
-
106
- stream.pipeline(
107
- fs.createReadStream(tarPath),
108
- verifyIntegrity(platformAndArch),
109
- new zlib.BrotliDecompress(),
110
- tarFs.extract(versionedVendorPath, { ignore }),
111
- function (err) {
112
- if (err) {
113
- if (/unexpected end of file/.test(err.message)) {
114
- fail(new Error(`Please delete ${tarPath} as it is not a valid tarball`));
115
- }
116
- fail(err);
117
- }
118
- }
119
- );
120
- };
121
-
122
- try {
123
- const useGlobalLibvips = libvips.useGlobalLibvips();
124
-
125
- if (useGlobalLibvips) {
126
- const globalLibvipsVersion = libvips.globalLibvipsVersion();
127
- libvips.log(`Detected globally-installed libvips v${globalLibvipsVersion}`);
128
- libvips.log('Building from source via node-gyp');
129
- process.exit(1);
130
- } else if (libvips.hasVendoredLibvips()) {
131
- libvips.log(`Using existing vendored libvips v${minimumLibvipsVersion}`);
132
- } else {
133
- // Is this arch/platform supported?
134
- const arch = process.env.npm_config_arch || process.arch;
135
- const platformAndArch = platform();
136
- if (arch === 'ia32' && !platformAndArch.startsWith('win32')) {
137
- throw new Error(`Intel Architecture 32-bit systems require manual installation of libvips >= ${minimumLibvipsVersion}`);
138
- }
139
- if (platformAndArch === 'freebsd-x64' || platformAndArch === 'openbsd-x64' || platformAndArch === 'sunos-x64') {
140
- throw new Error(`BSD/SunOS systems require manual installation of libvips >= ${minimumLibvipsVersion}`);
141
- }
142
- // Linux libc version check
143
- const libcVersionRaw = detectLibc.versionSync();
144
- if (libcVersionRaw) {
145
- const libcFamily = detectLibc.familySync();
146
- const libcVersion = semverCoerce(libcVersionRaw).version;
147
- if (libcFamily === detectLibc.GLIBC && minimumGlibcVersionByArch[arch]) {
148
- if (semverLessThan(libcVersion, semverCoerce(minimumGlibcVersionByArch[arch]).version)) {
149
- handleError(new Error(`Use with glibc ${libcVersionRaw} requires manual installation of libvips >= ${minimumLibvipsVersion}`));
150
- }
151
- }
152
- if (libcFamily === detectLibc.MUSL) {
153
- if (semverLessThan(libcVersion, '1.1.24')) {
154
- handleError(new Error(`Use with musl ${libcVersionRaw} requires manual installation of libvips >= ${minimumLibvipsVersion}`));
155
- }
156
- }
157
- }
158
- // Node.js minimum version check
159
- const supportedNodeVersion = process.env.npm_package_engines_node || require('../package.json').engines.node;
160
- if (!semverSatisfies(process.versions.node, supportedNodeVersion)) {
161
- handleError(new Error(`Expected Node.js version ${supportedNodeVersion} but found ${process.versions.node}`));
162
- }
163
- // Download to per-process temporary file
164
- const tarFilename = ['libvips', minimumLibvipsVersionLabelled, platformAndArch].join('-') + '.tar.br';
165
- const tarPathCache = path.join(libvips.cachePath(), tarFilename);
166
- if (fs.existsSync(tarPathCache)) {
167
- libvips.log(`Using cached ${tarPathCache}`);
168
- extractTarball(tarPathCache, platformAndArch);
169
- } else if (localLibvipsDir) {
170
- // If localLibvipsDir is given try to use binaries from local directory
171
- const tarPathLocal = path.join(path.resolve(localLibvipsDir), `v${minimumLibvipsVersionLabelled}`, tarFilename);
172
- libvips.log(`Using local libvips from ${tarPathLocal}`);
173
- extractTarball(tarPathLocal, platformAndArch);
174
- } else {
175
- const url = distBaseUrl + tarFilename;
176
- libvips.log(`Downloading ${url}`);
177
- simpleGet({ url: url, agent: agent(libvips.log) }, function (err, response) {
178
- if (err) {
179
- fail(err);
180
- } else if (response.statusCode === 404) {
181
- fail(new Error(`Prebuilt libvips ${minimumLibvipsVersion} binaries are not yet available for ${platformAndArch}`));
182
- } else if (response.statusCode !== 200) {
183
- fail(new Error(`Status ${response.statusCode} ${response.statusMessage}`));
184
- } else {
185
- const tarPathTemp = path.join(os.tmpdir(), `${process.pid}-${tarFilename}`);
186
- const tmpFileStream = fs.createWriteStream(tarPathTemp);
187
- response
188
- .on('error', function (err) {
189
- tmpFileStream.destroy(err);
190
- })
191
- .on('close', function () {
192
- if (!response.complete) {
193
- tmpFileStream.destroy(new Error('Download incomplete (connection was terminated)'));
194
- }
195
- })
196
- .pipe(tmpFileStream);
197
- tmpFileStream
198
- .on('error', function (err) {
199
- // Clean up temporary file
200
- try {
201
- fs.unlinkSync(tarPathTemp);
202
- } catch (e) {}
203
- fail(err);
204
- })
205
- .on('close', function () {
206
- try {
207
- // Attempt to rename
208
- fs.renameSync(tarPathTemp, tarPathCache);
209
- } catch (err) {
210
- // Fall back to copy and unlink
211
- fs.copyFileSync(tarPathTemp, tarPathCache);
212
- fs.unlinkSync(tarPathTemp);
213
- }
214
- extractTarball(tarPathCache, platformAndArch);
215
- });
216
- }
217
- });
218
- }
219
- }
220
- } catch (err) {
221
- fail(err);
222
- }
package/lib/agent.js DELETED
@@ -1,44 +0,0 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- 'use strict';
5
-
6
- const url = require('url');
7
- const tunnelAgent = require('tunnel-agent');
8
-
9
- const is = require('./is');
10
-
11
- const proxies = [
12
- 'HTTPS_PROXY',
13
- 'https_proxy',
14
- 'HTTP_PROXY',
15
- 'http_proxy',
16
- 'npm_config_https_proxy',
17
- 'npm_config_proxy'
18
- ];
19
-
20
- function env (key) {
21
- return process.env[key];
22
- }
23
-
24
- module.exports = function (log) {
25
- try {
26
- const proxy = new url.URL(proxies.map(env).find(is.string));
27
- const tunnel = proxy.protocol === 'https:'
28
- ? tunnelAgent.httpsOverHttps
29
- : tunnelAgent.httpsOverHttp;
30
- const proxyAuth = proxy.username && proxy.password
31
- ? `${decodeURIComponent(proxy.username)}:${decodeURIComponent(proxy.password)}`
32
- : null;
33
- log(`Via proxy ${proxy.protocol}//${proxy.hostname}:${proxy.port} ${proxyAuth ? 'with' : 'no'} credentials`);
34
- return tunnel({
35
- proxy: {
36
- port: Number(proxy.port),
37
- host: proxy.hostname,
38
- proxyAuth
39
- }
40
- });
41
- } catch (err) {
42
- return null;
43
- }
44
- };
package/lib/platform.js DELETED
@@ -1,30 +0,0 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- 'use strict';
5
-
6
- const detectLibc = require('detect-libc');
7
-
8
- const env = process.env;
9
-
10
- module.exports = function () {
11
- const arch = env.npm_config_arch || process.arch;
12
- const platform = env.npm_config_platform || process.platform;
13
- const libc = process.env.npm_config_libc ||
14
- /* istanbul ignore next */
15
- (detectLibc.isNonGlibcLinuxSync() ? detectLibc.familySync() : '');
16
- const libcId = platform !== 'linux' || libc === detectLibc.GLIBC ? '' : libc;
17
-
18
- const platformId = [`${platform}${libcId}`];
19
-
20
- if (arch === 'arm') {
21
- const fallback = process.versions.electron ? '7' : '6';
22
- platformId.push(`armv${env.npm_config_arm_version || process.config.variables.arm_version || fallback}`);
23
- } else if (arch === 'arm64') {
24
- platformId.push(`arm64v${env.npm_config_arm_version || '8'}`);
25
- } else {
26
- platformId.push(arch);
27
- }
28
-
29
- return platformId.join('-');
30
- };
@@ -1,151 +0,0 @@
1
- /* Object part of the VSource and VTarget class
2
- */
3
-
4
- /*
5
-
6
- Copyright (C) 1991-2001 The National Gallery
7
-
8
- This program is free software; you can redistribute it and/or modify
9
- it under the terms of the GNU Lesser General Public License as published by
10
- the Free Software Foundation; either version 2 of the License, or
11
- (at your option) any later version.
12
-
13
- This program is distributed in the hope that it will be useful,
14
- but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- GNU Lesser General Public License for more details.
17
-
18
- You should have received a copy of the GNU Lesser General Public License
19
- along with this program; if not, write to the Free Software
20
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
- 02110-1301 USA
22
-
23
- */
24
-
25
- /*
26
-
27
- These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
28
-
29
- */
30
-
31
- #ifdef HAVE_CONFIG_H
32
- #include <config.h>
33
- #endif /*HAVE_CONFIG_H*/
34
-
35
- #include <vips/vips8>
36
-
37
- #include <vips/debug.h>
38
-
39
- /*
40
- #define VIPS_DEBUG
41
- #define VIPS_DEBUG_VERBOSE
42
- */
43
-
44
- VIPS_NAMESPACE_START
45
-
46
- VSource
47
- VSource::new_from_descriptor( int descriptor )
48
- {
49
- VipsSource *input;
50
-
51
- if( !(input = vips_source_new_from_descriptor( descriptor )) )
52
- throw VError();
53
-
54
- VSource out( input );
55
-
56
- return( out );
57
- }
58
-
59
- VSource
60
- VSource::new_from_file( const char *filename )
61
- {
62
- VipsSource *input;
63
-
64
- if( !(input = vips_source_new_from_file( filename )) )
65
- throw VError();
66
-
67
- VSource out( input );
68
-
69
- return( out );
70
- }
71
-
72
- VSource
73
- VSource::new_from_blob( VipsBlob *blob )
74
- {
75
- VipsSource *input;
76
-
77
- if( !(input = vips_source_new_from_blob( blob )) )
78
- throw VError();
79
-
80
- VSource out( input );
81
-
82
- return( out );
83
- }
84
-
85
- VSource
86
- VSource::new_from_memory( const void *data,
87
- size_t size )
88
- {
89
- VipsSource *input;
90
-
91
- if( !(input = vips_source_new_from_memory( data, size )) )
92
- throw VError();
93
-
94
- VSource out( input );
95
-
96
- return( out );
97
- }
98
-
99
- VSource
100
- VSource::new_from_options( const char *options )
101
- {
102
- VipsSource *input;
103
-
104
- if( !(input = vips_source_new_from_options( options )) )
105
- throw VError();
106
-
107
- VSource out( input );
108
-
109
- return( out );
110
- }
111
-
112
- VTarget
113
- VTarget::new_to_descriptor( int descriptor )
114
- {
115
- VipsTarget *output;
116
-
117
- if( !(output = vips_target_new_to_descriptor( descriptor )) )
118
- throw VError();
119
-
120
- VTarget out( output );
121
-
122
- return( out );
123
- }
124
-
125
- VTarget
126
- VTarget::new_to_file( const char *filename )
127
- {
128
- VipsTarget *output;
129
-
130
- if( !(output = vips_target_new_to_file( filename )) )
131
- throw VError();
132
-
133
- VTarget out( output );
134
-
135
- return( out );
136
- }
137
-
138
- VTarget
139
- VTarget::new_to_memory()
140
- {
141
- VipsTarget *output;
142
-
143
- if( !(output = vips_target_new_to_memory()) )
144
- throw VError();
145
-
146
- VTarget out( output );
147
-
148
- return( out );
149
- }
150
-
151
- VIPS_NAMESPACE_END
@@ -1,49 +0,0 @@
1
- // Code for error type
2
-
3
- /*
4
-
5
- Copyright (C) 1991-2001 The National Gallery
6
-
7
- This program is free software; you can redistribute it and/or modify
8
- it under the terms of the GNU Lesser General Public License as published by
9
- the Free Software Foundation; either version 2 of the License, or
10
- (at your option) any later version.
11
-
12
- This program is distributed in the hope that it will be useful,
13
- but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- GNU Lesser General Public License for more details.
16
-
17
- You should have received a copy of the GNU Lesser General Public License
18
- along with this program; if not, write to the Free Software
19
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20
- 02110-1301 USA
21
-
22
- */
23
-
24
- /*
25
-
26
- These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
27
-
28
- */
29
-
30
- #ifdef HAVE_CONFIG_H
31
- #include <config.h>
32
- #endif /*HAVE_CONFIG_H*/
33
-
34
- #include <vips/vips8>
35
-
36
- VIPS_NAMESPACE_START
37
-
38
- std::ostream &operator<<( std::ostream &file, const VError &err )
39
- {
40
- err.ostream_print( file );
41
- return( file );
42
- }
43
-
44
- void VError::ostream_print( std::ostream &file ) const
45
- {
46
- file << _what;
47
- }
48
-
49
- VIPS_NAMESPACE_END