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
10 changes: 5 additions & 5 deletions build.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { resolve, dirname } from 'path'
import { copy, copyFile, outputFile, readJSON, writeJSON } from 'fs-extra'
import { copy, outputFile } from 'fs-extra'
import ncc from '@vercel/ncc'

async function main() {
const rootDir = __dirname
const declarationFileName = 'jimp.d.ts'
const input = resolve(rootDir, 'src', 'jimp.ts')
const output = resolve(rootDir, 'dist', 'jimp.cjs')
const pkg = resolve(rootDir, 'package.json')
const declaration = resolve(rootDir, 'dist', declarationFileName)

const opts = {
cache: false,
Expand All @@ -15,11 +16,12 @@ async function main() {
}

// @ts-ignore
let { code } = await ncc(input, opts)
let { code, assets } = await ncc(input, opts)

code = code.replace(/new Buffer/g, 'new JIMPBUffer')

await outputFile(output, code)
await outputFile(declaration , assets[declarationFileName].source)

const jimpDir = dirname(require.resolve('jimp/package.json'))
// const { version } = await readJSON(resolve(jimpDir, 'package.json'))
Expand All @@ -28,8 +30,6 @@ async function main() {

await copy(resolve(jimpDir, 'fonts'), resolve(rootDir, 'fonts'))

await copyFile(resolve(jimpDir, 'types/ts3.1/index.d.ts'), resolve(rootDir, 'dist/jimp.d.ts'))

// console.log('jimp-compact@' + version)
}

Expand Down
4 changes: 2 additions & 2 deletions src/jimp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import jimp from 'jimp/es'
import jimp = require('jimp')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/es isn't actually ESM, it's still CJS. So loading the thing that doesn't try to pretend (too hard) it's ESM when it's not works out better 🙂


class JIMPBUffer {
constructor(data, ...args) {
Expand All @@ -16,4 +16,4 @@ class JIMPBUffer {

globalThis.JIMPBUffer = JIMPBUffer

module.exports = jimp
export = jimp
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"target": "ES6",
"module": "CommonJS",
"moduleResolution": "Node",
"esModuleInterop": true,
Copy link
Author

@SimenB SimenB Sep 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using this forces it on consumers as well (the types use export = https://www.runpkg.com/?jimp@0.16.1/types/ts3.1/index.d.ts#50)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a good idea 😊

"outDir": "dist",
"strict": false,
"declaration": true
Expand Down