Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"pegjs": "^0.10.0",
"prop-types": "^15.7.2",
"seedrandom": "^3.0.5",
"whatwg-url": "^7.1.0",
"yoga-layout-prebuilt": "^1.9.5"
},
"peerDependencies": {
Expand Down Expand Up @@ -84,13 +85,14 @@
"@skpm/test-runner": "^0.4.1",
"@types/airbnb-prop-types": "^2.13.1",
"@types/invariant": "^2.2.31",
"@types/node-fetch": "^2.5.4",
"@types/jest": "^25.2.1",
"@types/node": "^13.13.2",
"@types/node-fetch": "^2.5.4",
"@types/pegjs": "^0.10.1",
"@types/react": "^16.9.34",
"@types/react-test-renderer": "^16.9.2",
"@types/seedrandom": "^2.4.28",
"@types/whatwg-url": "^8.2.0",
"gitbook-cli": "^2.3.0",
"gitbook-plugin-anchorjs": "^2.1.0",
"gitbook-plugin-codeblock-disable-glossary": "0.0.1",
Expand Down
1 change: 1 addition & 0 deletions src/platformBridges/macos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { readFile as nodeReadFile } from 'fs';
const NodeMacOSBridge: PlatformBridge = {
createStringMeasurer,
findFontName,
URL,
fetch: fetch as any, // call signatures are not perfectly identical, but we'll make do
async readFile(path: string): Promise<Buffer> {
return new Promise((resolve, reject) => {
Expand Down
4 changes: 4 additions & 0 deletions src/platformBridges/sketch/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { URL } from 'whatwg-url';

import { PlatformBridge } from '../../types';
import { createStringMeasurer } from './createStringMeasurer';
import { findFontName } from './findFontName';
import readFile from './readFile';

const SketchBridge: PlatformBridge = {
// @ts-ignore – @types/whatwg-url doesn't match Node.js global.URL
URL,
createStringMeasurer,
findFontName,
fetch,
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export type ResizeConstraints = {

export type PlatformBridge = {
createStringMeasurer(textNodes: TextNode[], maxWidth: number): Size;
URL: typeof URL;
findFontName(style: TextStyle): string;
fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
readFile(path: string): Promise<Buffer>;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getImageDataFromURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const getImageDataFromURL = (bridge: PlatformBridge) => async (
}

try {
const parsedUrl = new URL(url);
const parsedUrl = new bridge.URL(url);

const buffer = await (parsedUrl.protocol === 'file:'
? bridge.readFile(parsedUrl.pathname)
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.module.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"target": "es5",
"target": "es2017",
"outDir": "lib/module",
"module": "esnext"
},
Expand Down