@@ -41,15 +41,23 @@ const runtimePlatformArch = () => `${process.platform}${runtimeLibc()}-${process
4141
4242/* istanbul ignore next */
4343const buildPlatformArch = ( ) => {
44+ if ( isEmscripten ( ) ) {
45+ return 'wasm32' ;
46+ }
4447 /* eslint camelcase: ["error", { allow: ["^npm_config_"] }] */
4548 const { npm_config_arch, npm_config_platform, npm_config_libc } = process . env ;
46- return `${ npm_config_platform || process . platform } ${ npm_config_libc || runtimeLibc ( ) } -${ npm_config_arch || process . arch } ` ;
49+ const libc = typeof npm_config_libc === 'string' ? npm_config_libc : runtimeLibc ( ) ;
50+ return `${ npm_config_platform || process . platform } ${ libc } -${ npm_config_arch || process . arch } ` ;
4751} ;
4852
4953const buildSharpLibvipsIncludeDir = ( ) => {
5054 try {
51- return require ( '@img/sharp-libvips-dev/include' ) ;
52- } catch { }
55+ return require ( `@img/sharp-libvips-dev-${ buildPlatformArch ( ) } /include` ) ;
56+ } catch {
57+ try {
58+ return require ( '@img/sharp-libvips-dev/include' ) ;
59+ } catch { }
60+ }
5361 /* istanbul ignore next */
5462 return '' ;
5563} ;
@@ -64,12 +72,22 @@ const buildSharpLibvipsCPlusPlusDir = () => {
6472
6573const buildSharpLibvipsLibDir = ( ) => {
6674 try {
67- return require ( `@img/sharp-libvips-${ buildPlatformArch ( ) } /lib` ) ;
68- } catch { }
75+ return require ( `@img/sharp-libvips-dev-${ buildPlatformArch ( ) } /lib` ) ;
76+ } catch {
77+ try {
78+ return require ( `@img/sharp-libvips-${ buildPlatformArch ( ) } /lib` ) ;
79+ } catch { }
80+ }
6981 /* istanbul ignore next */
7082 return '' ;
7183} ;
7284
85+ /* istanbul ignore next */
86+ const isEmscripten = ( ) => {
87+ const { CC } = process . env ;
88+ return Boolean ( CC && CC . endsWith ( '/emcc' ) ) ;
89+ } ;
90+
7391const isRosetta = ( ) => {
7492 /* istanbul ignore next */
7593 if ( process . platform === 'darwin' && process . arch === 'x64' ) {
@@ -81,7 +99,7 @@ const isRosetta = () => {
8199
82100/* istanbul ignore next */
83101const spawnRebuild = ( ) =>
84- spawnSync ( ' node-gyp rebuild --directory=src' , {
102+ spawnSync ( ` node-gyp rebuild --directory=src ${ isEmscripten ( ) ? '--nodedir=emscripten' : '' } ` , {
85103 ...spawnSyncOptions ,
86104 stdio : 'inherit'
87105 } ) . status ;
0 commit comments