Skip to content

Commit

Permalink
move safe-sharp to gatsby/sharp when available
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed Jan 4, 2022
1 parent 40b5e89 commit 22d303a
Show file tree
Hide file tree
Showing 17 changed files with 197 additions and 207 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"npm-packlist": "^2.1.5",
"npm-run-all": "4.1.5",
"plop": "^1.9.1",
"prettier": "2.5.1",
"prettier": "^2.5.1",
"remark": "^13.0.0",
"remark-cli": "^9.0.0",
"remark-frontmatter": "^3.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-plugin-manifest/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from "fs"
import * as path from "path"
// TODO V5 use gatsby/sharp
import sharp from "./safe-sharp"
import { createContentDigest, slash } from "gatsby-core-utils"
import { defaultIcons, addDigestToPath, favicons } from "./common"
Expand Down
6 changes: 5 additions & 1 deletion packages/gatsby-plugin-manifest/src/safe-sharp.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ try {
originalConsoleError(msg, ...args)
handleMessage(msg)
}
sharp = require(`sharp`)
try {
sharp = require(`gatsby/sharp`)
} catch (e) {
sharp = require(`sharp`)
}
} catch (e) {
handleMessage(e.toString())
throw e
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-plugin-sharp/src/duotone.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO V5 use gatsby/sharp
const sharp = require(`./safe-sharp`)
const { reportError } = require(`./report-error`)

Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-plugin-sharp/src/image-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Reporter } from "gatsby/reporter"
import fs from "fs-extra"
import { rgbToHex, calculateImageSizes, getSrcSet, getSizes } from "./utils"
import { traceSVG, getImageSizeAsync, base64, batchQueueImageResizing } from "."
// TODO V5 use gatsby/sharp
import sharp from "./safe-sharp"
import {
createTransformObject,
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-plugin-sharp/src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO V5 use gatsby/sharp
const sharp = require(`./safe-sharp`)
const { generateImageData } = require(`./image-data`)
const imageSize = require(`probe-image-size`)
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-plugin-sharp/src/process-file.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO V5 use gatsby/sharp
const sharp = require(`./safe-sharp`)
const fs = require(`fs-extra`)
const path = require(`path`)
Expand Down
6 changes: 5 additions & 1 deletion packages/gatsby-plugin-sharp/src/safe-sharp.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ try {
originalConsoleError(msg, ...args)
handleMessage(msg)
}
sharp = require(`sharp`)
try {
sharp = require(`gatsby/sharp`)
} catch (e) {
sharp = require(`sharp`)
}
} catch (e) {
handleMessage(e.toString())
throw e
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-plugin-sharp/src/trace-svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const fs = require(`fs-extra`)
const _ = require(`lodash`)
const tmpDir = require(`os`).tmpdir()
const path = require(`path`)
// TODO V5 use gatsby/sharp
const sharp = require(`./safe-sharp`)
const filenamify = require(`filenamify`)
const duotone = require(`./duotone`)
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-plugin-sharp/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO V5 use gatsby/sharp
import sharp from "./safe-sharp"
import fs from "fs-extra"

Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-remark-images-contentful/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { selectAll } = require(`unist-util-select`)
// TODO V5 use gatsby/sharp
const sharp = require(`./safe-sharp`)
const axios = require(`axios`)
const _ = require(`lodash`)
Expand Down
6 changes: 5 additions & 1 deletion packages/gatsby-remark-images-contentful/src/safe-sharp.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ try {
originalConsoleError(msg, ...args)
handleMessage(msg)
}
sharp = require(`sharp`)
try {
sharp = require(`gatsby/sharp`)
} catch (e) {
sharp = require(`sharp`)
}
} catch (e) {
handleMessage(e.toString())
throw e
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-transformer-sharp/src/customize-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const {
traceSVG,
generateImageData,
} = require(`gatsby-plugin-sharp`)

// TODO V5 use gatsby/sharp
const sharp = require(`./safe-sharp`)
const fs = require(`fs-extra`)
const imageSize = require(`probe-image-size`)
Expand Down
6 changes: 5 additions & 1 deletion packages/gatsby-transformer-sharp/src/safe-sharp.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ try {
originalConsoleError(msg, ...args)
handleMessage(msg)
}
sharp = require(`sharp`)
try {
sharp = require(`gatsby/sharp`)
} catch (e) {
sharp = require(`sharp`)
}
} catch (e) {
handleMessage(e.toString())
throw e
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-transformer-sharp/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { Potrace } from "potrace"
import type Sharp from "sharp"

// TODO V5 use gatsby/sharp
const sharp: typeof Sharp = require(`./safe-sharp`)
const DEFAULT_PNG_COMPRESSION_SPEED = 4

Expand Down
4 changes: 4 additions & 0 deletions packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
"@types/reach__router": "^1.3.5",
"@types/react-dom": "^17.0.9",
"@types/semver": "^7.3.9",
"@types/sharp": "^0.29.5",
"@types/signal-exit": "^3.0.0",
"@types/string-similarity": "^4.0.0",
"@types/tmp": "^0.2.0",
Expand All @@ -188,6 +189,9 @@
"zipkin-javascript-opentracing": "^3.0.0",
"zipkin-transport-http": "^0.22.0"
},
"optionalDependencies": {
"gatsby-sharp": "^0.0.1-next.0"
},
"engines": {
"node": ">=14.15.0"
},
Expand Down
Loading

0 comments on commit 22d303a

Please sign in to comment.