Skip to content

Commit

Permalink
get bundle working
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Apr 9, 2024
1 parent bd2dd8b commit 09e08f8
Show file tree
Hide file tree
Showing 35 changed files with 2,066 additions and 203 deletions.
18 changes: 0 additions & 18 deletions packages/docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,6 @@ import path from "path";
import { NodeGlobalsPolyfillPlugin } from "@esbuild-plugins/node-globals-polyfill";

export default defineConfig({
vite: {
optimizeDeps: {
// Only needed for this repo
include: [
"@jimp/core",
"@jimp/plugin-print",
"@jimp/plugin-print/load-font",
],
// Needed for anyone using the browser
// Mainly just for Buffer
esbuildOptions: {
define: {
global: "globalThis",
},
plugins: [NodeGlobalsPolyfillPlugin({ buffer: true })],
},
},
},
integrations: [
react(),
starlight({
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/components/grayscale-example.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from "react";
import { Jimp } from "jimp";
import { Jimp } from "jimp/browser";

export function GrayscaleExample() {
const [selectedFile, setSelectedFile] = useState("");
Expand Down
5 changes: 0 additions & 5 deletions packages/jimp/.eslintrc copy.cjs

This file was deleted.

2 changes: 2 additions & 0 deletions packages/jimp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
browser.js
browser.js.map
42 changes: 31 additions & 11 deletions packages/jimp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "jimp",
"version": "1.0.0",
"sideEffects": false,
"description": "An image processing library written entirely in JavaScript.",
"files": [
"browser",
Expand All @@ -16,6 +17,7 @@
"test": "vitest",
"test:browser": "vitest --config vitest.config.browser.ts",
"build": "tshy",
"build:browser": "rollup -c",
"dev": "tshy --watch",
"clean": "rm -rf node_modules .tshy .tshy-build dist"
},
Expand All @@ -34,7 +36,13 @@
"author": "Andrew Lisowski <lisowski54@gmail.com>",
"license": "MIT",
"dependencies": {
"@jimp/core": "workspace:*",
"@jimp/diff": "workspace:*",
"@jimp/js-bmp": "workspace:*",
"@jimp/js-gif": "workspace:*",
"@jimp/js-jpeg": "workspace:*",
"@jimp/js-png": "workspace:*",
"@jimp/js-tiff": "workspace:*",
"@jimp/plugin-blit": "workspace:*",
"@jimp/plugin-blur": "workspace:*",
"@jimp/plugin-circle": "workspace:*",
Expand All @@ -52,26 +60,30 @@
"@jimp/plugin-resize": "workspace:*",
"@jimp/plugin-rotate": "workspace:*",
"@jimp/plugin-threshold": "workspace:*",
"@jimp/js-bmp": "workspace:*",
"@jimp/js-gif": "workspace:*",
"@jimp/js-jpeg": "workspace:*",
"@jimp/js-png": "workspace:*",
"@jimp/js-tiff": "workspace:*",
"@jimp/core": "workspace:*",
"@jimp/types": "workspace:*",
"@jimp/utils": "workspace:*"
"@jimp/utils": "workspace:*",
"@rspack/cli": "^0.5.9"
},
"devDependencies": {
"@jimp/config-eslint": "workspace:*",
"@jimp/config-typescript": "workspace:*",
"@jimp/config-vitest": "workspace:*",
"@jimp/test-utils": "workspace:*",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-inject": "^5.0.5",
"@rollup/plugin-node-resolve": "^15.2.3",
"@vitest/browser": "^1.4.0",
"eslint": "^8.57.0",
"path-browserify": "^1.0.1",
"rollup": "^4.14.1",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-esbuild": "^6.1.1",
"rollup-plugin-polyfill-node": "^0.13.0",
"tshy": "^1.12.0",
"typescript": "^5.4.2",
"@vitest/browser": "^1.4.0",
"vitest": "^1.4.0",
"vite-plugin-node-polyfills": "^0.21.0"
"vite-plugin-node-polyfills": "^0.21.0",
"vitest": "^1.4.0"
},
"tshy": {
"exclude": [
Expand All @@ -80,7 +92,11 @@
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts",
"./fonts": "./src/fonts.ts"
"./fonts": "./src/fonts.ts",
"./browser": {
"types": "./dist/esm/index.d.ts",
"import": "./browser.js"
}
}
},
"exports": {
Expand All @@ -104,6 +120,10 @@
"types": "./dist/commonjs/fonts.d.ts",
"default": "./dist/commonjs/fonts.js"
}
},
"./browser": {
"types": "./dist/esm/index.d.ts",
"import": "./browser.js"
}
},
"main": "./dist/commonjs/index.js",
Expand Down
32 changes: 32 additions & 0 deletions packages/jimp/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import esbuild from "rollup-plugin-esbuild";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import alias from "@rollup/plugin-alias";
import nodePolyfills from "rollup-plugin-polyfill-node";
import inject from "@rollup/plugin-inject";

export default [
{
input: `src/index.ts`,
plugins: [
esbuild(),
alias({
// Use the browser version of pngjs
entries: [{ find: "pngjs", replacement: "pngjs/browser" }],
}),
// Polyfill Node.js builtins
nodeResolve({ preferBuiltins: false, browser: true }),
// Polyfill Node.js globals
inject({ Buffer: ["buffer", "Buffer"] }),
commonjs(),
nodePolyfills(),
],
output: [
{
file: `browser.js`,
format: "es",
sourcemap: true,
},
],
},
];
9 changes: 9 additions & 0 deletions packages/jimp/scripts/generate-dts-bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createBundle } from "dts-buddy";

await createBundle({
project: "tsconfig.json",
output: "browser.d.ts",
modules: {
jimp: "dist/esm/index.ts",
},
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions plugins/plugin-print/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@jimp/plugin-print",
"version": "1.0.0",
"repository": "jimp-dev/jimp",
"sideEffects": false,
"scripts": {
"lint": "eslint .",
"test": "vitest",
Expand Down
22 changes: 19 additions & 3 deletions plugins/plugin-resize/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,26 @@ import { ResizeStrategy } from "./constants.js";
import { z } from "zod";

import Resize from "./modules/resize.js";
import Resize2 from "./modules/resize2.js";
import { operations as Resize2 } from "./modules/resize2.js";

export * from "./constants.js";

interface ResizeClass {
// eslint-disable-next-line @typescript-eslint/no-misused-new
new (
widthOriginal: number,
heightOriginal: number,
targetWidth: number,
targetHeight: number,
blendAlpha: boolean,
interpolationPass: boolean,
resizeCallback: (buffer: Buffer) => void
): ResizeClass;
resize(buffer: Buffer): void;
}

type Constructable<T> = new (...args: any[]) => T;

const ResizeOptionsSchema = z.union([
z.object({
/** the width to resize the image to */
Expand Down Expand Up @@ -92,14 +108,14 @@ export const methods = {
Resize2[mode](image.bitmap, dst);
image.bitmap = dst;
} else {
const resize = new Resize(
const resize = new (Resize as unknown as Constructable<ResizeClass>)(
image.bitmap.width,
image.bitmap.height,
w,
h,
true,
true,
(buffer) => {
(buffer: Buffer) => {
image.bitmap.data = Buffer.from(buffer);
image.bitmap.width = w;
image.bitmap.height = h;
Expand Down
12 changes: 0 additions & 12 deletions plugins/plugin-resize/src/modules/resize.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-nocheck

// JavaScript Image Resizer (c) 2012 - Grant Galitz
// Released to public domain 29 July 2013: https://github.com/grantgalitz/JS-Image-Resizer/issues/4

Expand Down
9 changes: 0 additions & 9 deletions plugins/plugin-resize/src/modules/resize2.d.ts

This file was deleted.

0 comments on commit 09e08f8

Please sign in to comment.