-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): better choice between builds
- Loading branch information
Showing
3 changed files
with
45 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,41 @@ | ||
let ttf2woff2: (input: Buffer) => Buffer; | ||
import { YError, printStackTrace } from 'yerror'; | ||
import debug from 'debug'; | ||
import { env } from 'node:process'; | ||
|
||
try { | ||
ttf2woff2 = (await import('bindings'))('addon.node').convert; | ||
} catch (err) { | ||
ttf2woff2 = (await import('../jssrc/index.js')).default; | ||
const doDebug = debug('ttf2woff2'); | ||
let ttf2woff2: undefined | ((input: Buffer) => Buffer) = undefined; | ||
|
||
if ( | ||
!env.TTF2WOFF2_VERSION || | ||
env.TTF2WOFF2_VERSION?.toLowerCase() === 'native' | ||
) { | ||
try { | ||
ttf2woff2 = (await import('bindings'))('addon.node').convert; | ||
doDebug('✅ Using native version.'); | ||
} catch (err) { | ||
doDebug( | ||
'❌ Could not load the native version.', | ||
printStackTrace(err as Error), | ||
); | ||
} | ||
} | ||
|
||
if (!env.TTF2WOFF2_VERSION || env.TTF2WOFF2_VERSION?.toLowerCase() === 'wasm') { | ||
if (!ttf2woff2) { | ||
try { | ||
ttf2woff2 = (await import('../jssrc/index.js')).default; | ||
doDebug('✅ Using WASM version.'); | ||
} catch (err) { | ||
doDebug( | ||
'❌ Could not load the WASM version.', | ||
printStackTrace(err as Error), | ||
); | ||
} | ||
} | ||
} | ||
|
||
if (!ttf2woff2) { | ||
throw new YError('E_UNABLE_TO_LOAD_TTF2WOFF2', env.TTF2WOFF2_VERSION); | ||
} | ||
|
||
export default ttf2woff2; | ||
export default ttf2woff2 as NonNullable<typeof ttf2woff2>; |