From d9620d1772450895067d536e1dd79475542234b8 Mon Sep 17 00:00:00 2001 From: Pepijn Peeters Date: Mon, 18 Dec 2023 15:58:54 +0100 Subject: [PATCH 1/4] Restore test environment reuse --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3bee8549..43e1d4f9 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "lint": "eslint --max-warnings=0 .", "issue": "cd issue && tsc && node issue.js", "prepare": "copyfiles -f ./node_modules/@dlemstra/magick-native/NOTICE . && copyfiles -f ./node_modules/@dlemstra/magick-native/magick.wasm dist", - "test": "vitest run", + "test": "vitest run --poolOptions.threads.isolate false", "test-dist": "cd tests/dist && node test-dist", "update-index": "cd tools && tsc && node update-index.js ../src" }, From 689377bb4a25b4e5bc099f8c173a4aa87168b21a Mon Sep 17 00:00:00 2001 From: Pepijn Peeters Date: Mon, 18 Dec 2023 16:07:36 +0100 Subject: [PATCH 2/4] Use single quotes --- .../drawable-text-interline-spacing.ts | 4 +- .../drawable-text-interword-spacing.ts | 4 +- src/enums/channels.ts | 2 +- src/events/progress-event.ts | 2 +- src/events/warning-event.ts | 2 +- src/helpers/delegate-registry.ts | 12 +++--- src/helpers/temporary-defines.ts | 2 +- src/magick-image.ts | 6 +-- src/types/point.ts | 2 +- .../drawables/drawable-text-alignment.spec.ts | 32 +++++++------- .../drawables/drawable-text-antialias.spec.ts | 26 ++++++------ .../drawable-text-decoration.spec.ts | 28 ++++++------- .../drawable-text-interline-spacing.spec.ts | 42 +++++++++---------- .../drawable-text-interword-spacing.spec.ts | 28 ++++++------- tests/drawables/drawable-text-kerning.spec.ts | 34 +++++++-------- .../drawable-text-under-color.spec.ts | 36 ++++++++-------- tests/magick-image/motion-blur.spec.ts | 2 +- 17 files changed, 132 insertions(+), 132 deletions(-) diff --git a/src/drawables/drawable-text-interline-spacing.ts b/src/drawables/drawable-text-interline-spacing.ts index 031b3e9d..c53ebad8 100644 --- a/src/drawables/drawable-text-interline-spacing.ts +++ b/src/drawables/drawable-text-interline-spacing.ts @@ -1,8 +1,8 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import { IDrawable } from "./drawable"; -import { IDrawingWand } from "./drawing-wand"; +import { IDrawable } from './drawable'; +import { IDrawingWand } from './drawing-wand'; /** * Sets the spacing between line in text. diff --git a/src/drawables/drawable-text-interword-spacing.ts b/src/drawables/drawable-text-interword-spacing.ts index 30be3f79..48d06f5e 100644 --- a/src/drawables/drawable-text-interword-spacing.ts +++ b/src/drawables/drawable-text-interword-spacing.ts @@ -1,8 +1,8 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import { IDrawable } from "./drawable"; -import { IDrawingWand } from "./drawing-wand"; +import { IDrawable } from './drawable'; +import { IDrawingWand } from './drawing-wand'; /** * Sets the spacing between words in text. diff --git a/src/enums/channels.ts b/src/enums/channels.ts index 944240cd..8a6beb32 100644 --- a/src/enums/channels.ts +++ b/src/enums/channels.ts @@ -1,7 +1,7 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import { PixelChannel } from "./pixel-channel"; +import { PixelChannel } from './pixel-channel'; /** * Specifies channel types. diff --git a/src/events/progress-event.ts b/src/events/progress-event.ts index 0fb966b5..911e2bda 100644 --- a/src/events/progress-event.ts +++ b/src/events/progress-event.ts @@ -1,7 +1,7 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import { Percentage } from "../types/percentage"; +import { Percentage } from '../types/percentage'; /** * Class for Progress events. diff --git a/src/events/warning-event.ts b/src/events/warning-event.ts index cdb3c2e6..5ce3b384 100644 --- a/src/events/warning-event.ts +++ b/src/events/warning-event.ts @@ -1,7 +1,7 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import { MagickError } from "../magick-error"; +import { MagickError } from '../magick-error'; /** * Class for warning events. diff --git a/src/helpers/delegate-registry.ts b/src/helpers/delegate-registry.ts index 6e8de26c..46ae6751 100644 --- a/src/helpers/delegate-registry.ts +++ b/src/helpers/delegate-registry.ts @@ -1,12 +1,12 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import { LogEvent } from "../events/log-event"; -import { LogEventTypes } from "../enums/log-event-types"; -import { IMagickImage } from "../magick-image"; -import { ImageMagick } from "../image-magick"; -import { ProgressEvent } from "../events/progress-event"; -import { _createString } from "../internal/native/string"; +import { LogEvent } from '../events/log-event'; +import { LogEventTypes } from '../enums/log-event-types'; +import { IMagickImage } from '../magick-image'; +import { ImageMagick } from '../image-magick'; +import { ProgressEvent } from '../events/progress-event'; +import { _createString } from '../internal/native/string'; /** @internal */ export class DelegateRegistry { diff --git a/src/helpers/temporary-defines.ts b/src/helpers/temporary-defines.ts index 7c4d145a..c898830c 100644 --- a/src/helpers/temporary-defines.ts +++ b/src/helpers/temporary-defines.ts @@ -1,7 +1,7 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import { IMagickImage } from "../magick-image"; +import { IMagickImage } from '../magick-image'; /** @internal */ export class TemporaryDefines { diff --git a/src/magick-image.ts b/src/magick-image.ts index 5b1db0c6..d12cc746 100644 --- a/src/magick-image.ts +++ b/src/magick-image.ts @@ -2253,7 +2253,7 @@ export class MagickImage extends NativeInstance implements IMagickImage { deskew(threshold: Percentage, autoCrop?: boolean): number { return TemporaryDefines.use(this, temporaryDefines => { if (autoCrop !== undefined) { - temporaryDefines.setArtifact("deskew:auto-crop", autoCrop); + temporaryDefines.setArtifact('deskew:auto-crop', autoCrop); } this.useException(exception => { @@ -2279,11 +2279,11 @@ export class MagickImage extends NativeInstance implements IMagickImage { bestFit = methodOrSettings.bestFit ? 1 : 0; if (methodOrSettings.scale !== undefined) { - temporaryDefines.setArtifact("distort:scale", methodOrSettings.scale.toString()); + temporaryDefines.setArtifact('distort:scale', methodOrSettings.scale.toString()); } if (methodOrSettings.viewport !== undefined) { - temporaryDefines.setArtifact("distort:viewport", methodOrSettings.viewport.toString()); + temporaryDefines.setArtifact('distort:viewport', methodOrSettings.viewport.toString()); } } diff --git a/src/types/point.ts b/src/types/point.ts index c63f29ae..7a948b1e 100644 --- a/src/types/point.ts +++ b/src/types/point.ts @@ -1,7 +1,7 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import { ImageMagick } from "../image-magick"; +import { ImageMagick } from '../image-magick'; /** * Class for a point with doubles. diff --git a/tests/drawables/drawable-text-alignment.spec.ts b/tests/drawables/drawable-text-alignment.spec.ts index 4aab412e..cfc937c5 100644 --- a/tests/drawables/drawable-text-alignment.spec.ts +++ b/tests/drawables/drawable-text-alignment.spec.ts @@ -1,39 +1,39 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import { DrawableFont } from "@src/drawables/drawable-font"; -import { DrawableFontPointSize } from "@src/drawables/drawable-font-point-size"; -import { DrawableText } from "@src/drawables/drawable-text"; -import { DrawableTextAlignment } from "@src/drawables/drawable-text-alignment"; -import { TestFonts } from "@test/test-fonts"; -import { TestImages } from "@test/test-images"; -import { TextAlignment } from "@src/enums/text-alignment"; +import { DrawableFont } from '@src/drawables/drawable-font'; +import { DrawableFontPointSize } from '@src/drawables/drawable-font-point-size'; +import { DrawableText } from '@src/drawables/drawable-text'; +import { DrawableTextAlignment } from '@src/drawables/drawable-text-alignment'; +import { TestFonts } from '@test/test-fonts'; +import { TestImages } from '@test/test-images'; +import { TextAlignment } from '@src/enums/text-alignment'; -describe("DrawableTextAlignment", () => { - it("should write text without alignment to the image", () => { +describe('DrawableTextAlignment', () => { + it('should write text without alignment to the image', () => { TestImages.empty150x150Canvas.use((image) => { image.draw([ new DrawableFont(TestFonts.kaushanScriptRegularTtf.name), new DrawableFontPointSize(80), - new DrawableText(0, 100, "Test"), + new DrawableText(0, 100, 'Test'), ]); - expect(image).toHavePixelWithColor(126, 75, "#000000ff"); - expect(image).toHavePixelWithColor(49, 79, "#ffffffff"); + expect(image).toHavePixelWithColor(126, 75, '#000000ff'); + expect(image).toHavePixelWithColor(49, 79, '#ffffffff'); }); }); - it("should write text with alignment to the image", () => { + it('should write text with alignment to the image', () => { TestImages.empty150x150Canvas.use((image) => { image.draw([ new DrawableFont(TestFonts.kaushanScriptRegularTtf.name), new DrawableFontPointSize(80), new DrawableTextAlignment(TextAlignment.Center), - new DrawableText(0, 100, "Test"), + new DrawableText(0, 100, 'Test'), ]); - expect(image).toHavePixelWithColor(126, 75, "#ffffffff"); - expect(image).toHavePixelWithColor(49, 79, "#000000ff"); + expect(image).toHavePixelWithColor(126, 75, '#ffffffff'); + expect(image).toHavePixelWithColor(49, 79, '#000000ff'); }); }); }); diff --git a/tests/drawables/drawable-text-antialias.spec.ts b/tests/drawables/drawable-text-antialias.spec.ts index a2368e11..4506fa57 100644 --- a/tests/drawables/drawable-text-antialias.spec.ts +++ b/tests/drawables/drawable-text-antialias.spec.ts @@ -1,36 +1,36 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import { DrawableFont } from "../../src/drawables/drawable-font"; -import { DrawableFontPointSize } from "../../src/drawables/drawable-font-point-size"; -import { DrawableText } from "../../src/drawables/drawable-text"; -import { DrawableTextAntialias } from "../../src/drawables/drawable-text-antialias"; -import { TestFonts } from "../test-fonts"; -import { TestImages } from "../test-images"; +import { DrawableFont } from '../../src/drawables/drawable-font'; +import { DrawableFontPointSize } from '../../src/drawables/drawable-font-point-size'; +import { DrawableText } from '../../src/drawables/drawable-text'; +import { DrawableTextAntialias } from '../../src/drawables/drawable-text-antialias'; +import { TestFonts } from '../test-fonts'; +import { TestImages } from '../test-images'; -describe("DrawableTextAntialias", () => { - it("should write text with antialias to the image", () => { +describe('DrawableTextAntialias', () => { + it('should write text with antialias to the image', () => { TestImages.empty150x150Canvas.use((image) => { image.draw([ new DrawableFont(TestFonts.kaushanScriptRegularTtf.name), new DrawableFontPointSize(80), - new DrawableText(0, 100, "Test"), + new DrawableText(0, 100, 'Test'), ]); - expect(image).toHavePixelWithColor(95, 67, "#b1b1b1ff"); + expect(image).toHavePixelWithColor(95, 67, '#b1b1b1ff'); }); }); - it("should write text without antialias to the image", () => { + it('should write text without antialias to the image', () => { TestImages.empty150x150Canvas.use((image) => { image.draw([ new DrawableFont(TestFonts.kaushanScriptRegularTtf.name), new DrawableFontPointSize(80), DrawableTextAntialias.Disabled, - new DrawableText(0, 100, "Test"), + new DrawableText(0, 100, 'Test'), ]); - expect(image).toHavePixelWithColor(95, 67, "#000000ff"); + expect(image).toHavePixelWithColor(95, 67, '#000000ff'); }); }); }); diff --git a/tests/drawables/drawable-text-decoration.spec.ts b/tests/drawables/drawable-text-decoration.spec.ts index 0f8b2938..26d9dad9 100644 --- a/tests/drawables/drawable-text-decoration.spec.ts +++ b/tests/drawables/drawable-text-decoration.spec.ts @@ -1,37 +1,37 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import { DrawableFont } from "../../src/drawables/drawable-font"; -import { DrawableFontPointSize } from "../../src/drawables/drawable-font-point-size"; -import { DrawableText } from "../../src/drawables/drawable-text"; -import { DrawableTextDecoration } from "../../src/drawables/drawable-text-decoration"; -import { TestFonts } from "../test-fonts"; -import { TestImages } from "../test-images"; -import { TextDecoration } from "../../src/enums/text-decoration"; +import { DrawableFont } from '../../src/drawables/drawable-font'; +import { DrawableFontPointSize } from '../../src/drawables/drawable-font-point-size'; +import { DrawableText } from '../../src/drawables/drawable-text'; +import { DrawableTextDecoration } from '../../src/drawables/drawable-text-decoration'; +import { TestFonts } from '../test-fonts'; +import { TestImages } from '../test-images'; +import { TextDecoration } from '../../src/enums/text-decoration'; -describe("DrawableTextDecoration", () => { - it("should write text without decoration to the image", () => { +describe('DrawableTextDecoration', () => { + it('should write text without decoration to the image', () => { TestImages.empty150x150Canvas.use((image) => { image.draw([ new DrawableFont(TestFonts.kaushanScriptRegularTtf.name), new DrawableFontPointSize(80), - new DrawableText(0, 100, "Test"), + new DrawableText(0, 100, 'Test'), ]); - expect(image).toHavePixelWithColor(88, 109, "#ffffffff"); + expect(image).toHavePixelWithColor(88, 109, '#ffffffff'); }); }); - it("should write text with decoration to the image", () => { + it('should write text with decoration to the image', () => { TestImages.empty150x150Canvas.use((image) => { image.draw([ new DrawableFont(TestFonts.kaushanScriptRegularTtf.name), new DrawableFontPointSize(80), new DrawableTextDecoration(TextDecoration.Underline), - new DrawableText(0, 100, "Test"), + new DrawableText(0, 100, 'Test'), ]); - expect(image).toHavePixelWithColor(88, 109, "#000000ff"); + expect(image).toHavePixelWithColor(88, 109, '#000000ff'); }); }); }); diff --git a/tests/drawables/drawable-text-interline-spacing.spec.ts b/tests/drawables/drawable-text-interline-spacing.spec.ts index c57d0c74..d9c399a0 100644 --- a/tests/drawables/drawable-text-interline-spacing.spec.ts +++ b/tests/drawables/drawable-text-interline-spacing.spec.ts @@ -1,54 +1,54 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import { DrawableFillColor } from "../../src/drawables/drawable-fill-color"; -import { DrawableFont } from "../../src/drawables/drawable-font"; -import { DrawableFontPointSize } from "../../src/drawables/drawable-font-point-size"; -import { DrawableText } from "../../src/drawables/drawable-text"; -import { DrawableTextInterlineSpacing } from "../../src/drawables/drawable-text-interline-spacing"; -import { MagickColor } from "../../src/magick-color"; -import { TestFonts } from "../test-fonts"; -import { TestImages } from "../test-images"; +import { DrawableFillColor } from '../../src/drawables/drawable-fill-color'; +import { DrawableFont } from '../../src/drawables/drawable-font'; +import { DrawableFontPointSize } from '../../src/drawables/drawable-font-point-size'; +import { DrawableText } from '../../src/drawables/drawable-text'; +import { DrawableTextInterlineSpacing } from '../../src/drawables/drawable-text-interline-spacing'; +import { MagickColor } from '../../src/magick-color'; +import { TestFonts } from '../test-fonts'; +import { TestImages } from '../test-images'; -describe("DrawableTextInterlineSpacing", () => { - it("should write text with default interline spacing", () => { +describe('DrawableTextInterlineSpacing', () => { + it('should write text with default interline spacing', () => { TestImages.empty150x150Canvas.use((image) => { image.draw([ new DrawableFont(TestFonts.kaushanScriptRegularTtf.name), new DrawableFontPointSize(50), - new DrawableFillColor(new MagickColor("pink")), - new DrawableText(50, 50, "I\nI"), + new DrawableFillColor(new MagickColor('pink')), + new DrawableText(50, 50, 'I\nI'), ]); - expect(image).toHavePixelWithColor(60, 131, "#ffffffff"); + expect(image).toHavePixelWithColor(60, 131, '#ffffffff'); }); }); - it("should write text with increased interline spacing", () => { + it('should write text with increased interline spacing', () => { TestImages.empty150x150Canvas.use((image) => { image.draw([ new DrawableFont(TestFonts.kaushanScriptRegularTtf.name), new DrawableFontPointSize(50), - new DrawableFillColor(new MagickColor("pink")), + new DrawableFillColor(new MagickColor('pink')), new DrawableTextInterlineSpacing(10), - new DrawableText(50, 50, "I\nI"), + new DrawableText(50, 50, 'I\nI'), ]); - expect(image).toHavePixelWithColor(60, 131, "#ffc0cbff"); + expect(image).toHavePixelWithColor(60, 131, '#ffc0cbff'); }); }); - it("should write text with negative interline spacing", () => { + it('should write text with negative interline spacing', () => { TestImages.empty150x150Canvas.use((image) => { image.draw([ new DrawableFont(TestFonts.kaushanScriptRegularTtf.name), new DrawableFontPointSize(50), - new DrawableFillColor(new MagickColor("pink")), + new DrawableFillColor(new MagickColor('pink')), new DrawableTextInterlineSpacing(-30), - new DrawableText(50, 50, "I\nI"), + new DrawableText(50, 50, 'I\nI'), ]); - expect(image).toHavePixelWithColor(68, 59, "#ffc0cbff"); + expect(image).toHavePixelWithColor(68, 59, '#ffc0cbff'); }); }); }); diff --git a/tests/drawables/drawable-text-interword-spacing.spec.ts b/tests/drawables/drawable-text-interword-spacing.spec.ts index 16f9c301..0475be46 100644 --- a/tests/drawables/drawable-text-interword-spacing.spec.ts +++ b/tests/drawables/drawable-text-interword-spacing.spec.ts @@ -1,20 +1,20 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import { DrawableFont } from "../../src/drawables/drawable-font"; -import { DrawableFontPointSize } from "../../src/drawables/drawable-font-point-size"; -import { DrawableText } from "../../src/drawables/drawable-text"; -import { DrawableTextInterwordSpacing } from "../../src/drawables/drawable-text-interword-spacing"; -import { TestFonts } from "../test-fonts"; -import { TestImages } from "../test-images"; - -describe("DrawableTextInterwordSpacing", () => { - it("should write text with default interword spacing", () => { +import { DrawableFont } from '../../src/drawables/drawable-font'; +import { DrawableFontPointSize } from '../../src/drawables/drawable-font-point-size'; +import { DrawableText } from '../../src/drawables/drawable-text'; +import { DrawableTextInterwordSpacing } from '../../src/drawables/drawable-text-interword-spacing'; +import { TestFonts } from '../test-fonts'; +import { TestImages } from '../test-images'; + +describe('DrawableTextInterwordSpacing', () => { + it('should write text with default interword spacing', () => { TestImages.empty150x150Canvas.use((image) => { image.draw([ new DrawableFont(TestFonts.kaushanScriptRegularTtf.name), new DrawableFontPointSize(50), - new DrawableText(50, 50, "I I"), + new DrawableText(50, 50, 'I I'), ]); image.trim(); @@ -24,13 +24,13 @@ describe("DrawableTextInterwordSpacing", () => { }); }); - it("should write text with increased interword spacing", () => { + it('should write text with increased interword spacing', () => { TestImages.empty150x150Canvas.use((image) => { image.draw([ new DrawableFont(TestFonts.kaushanScriptRegularTtf.name), new DrawableFontPointSize(50), new DrawableTextInterwordSpacing(40), - new DrawableText(50, 50, "I I"), + new DrawableText(50, 50, 'I I'), ]); image.trim(); @@ -40,13 +40,13 @@ describe("DrawableTextInterwordSpacing", () => { }); }); - it("should write text with negative interword spacing", () => { + it('should write text with negative interword spacing', () => { TestImages.empty150x150Canvas.use((image) => { image.draw([ new DrawableFont(TestFonts.kaushanScriptRegularTtf.name), new DrawableFontPointSize(50), new DrawableTextInterwordSpacing(-10), - new DrawableText(50, 50, "I I"), + new DrawableText(50, 50, 'I I'), ]); image.trim(); diff --git a/tests/drawables/drawable-text-kerning.spec.ts b/tests/drawables/drawable-text-kerning.spec.ts index b46009bf..917c74a4 100644 --- a/tests/drawables/drawable-text-kerning.spec.ts +++ b/tests/drawables/drawable-text-kerning.spec.ts @@ -1,40 +1,40 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import { DrawableFillColor } from "../../src/drawables/drawable-fill-color"; -import { DrawableFont } from "../../src/drawables/drawable-font"; -import { DrawableFontPointSize } from "../../src/drawables/drawable-font-point-size"; -import { DrawableText } from "../../src/drawables/drawable-text"; -import { DrawableTextKerning } from "../../src/drawables/drawable-text-kerning"; -import { MagickColor } from "../../src/magick-color"; -import { TestFonts } from "../test-fonts"; -import { TestImages } from "../test-images"; +import { DrawableFillColor } from '../../src/drawables/drawable-fill-color'; +import { DrawableFont } from '../../src/drawables/drawable-font'; +import { DrawableFontPointSize } from '../../src/drawables/drawable-font-point-size'; +import { DrawableText } from '../../src/drawables/drawable-text'; +import { DrawableTextKerning } from '../../src/drawables/drawable-text-kerning'; +import { MagickColor } from '../../src/magick-color'; +import { TestFonts } from '../test-fonts'; +import { TestImages } from '../test-images'; -describe("DrawableTextKerning", () => { - it("should write text with kerning to the image", () => { +describe('DrawableTextKerning', () => { + it('should write text with kerning to the image', () => { TestImages.empty150x150Canvas.use((image) => { image.draw([ new DrawableFont(TestFonts.kaushanScriptRegularTtf.name), new DrawableFontPointSize(100), - new DrawableFillColor(new MagickColor("pink")), + new DrawableFillColor(new MagickColor('pink')), new DrawableTextKerning(10), - new DrawableText(0, 109, "I I"), + new DrawableText(0, 109, 'I I'), ]); - expect(image).toHavePixelWithColor(100, 80, "#ffc0cbff"); + expect(image).toHavePixelWithColor(100, 80, '#ffc0cbff'); }); }); - it("should write text without kerning to the image", () => { + it('should write text without kerning to the image', () => { TestImages.empty150x150Canvas.use((image) => { image.draw([ new DrawableFont(TestFonts.kaushanScriptRegularTtf.name), new DrawableFontPointSize(100), - new DrawableFillColor(new MagickColor("pink")), - new DrawableText(0, 109, "I I"), + new DrawableFillColor(new MagickColor('pink')), + new DrawableText(0, 109, 'I I'), ]); - expect(image).toHavePixelWithColor(100, 80, "#ffffffff"); + expect(image).toHavePixelWithColor(100, 80, '#ffffffff'); }); }); }); diff --git a/tests/drawables/drawable-text-under-color.spec.ts b/tests/drawables/drawable-text-under-color.spec.ts index f73eba3b..241973eb 100644 --- a/tests/drawables/drawable-text-under-color.spec.ts +++ b/tests/drawables/drawable-text-under-color.spec.ts @@ -1,41 +1,41 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import { DrawableFont } from "../../src/drawables/drawable-font"; -import { DrawableFontPointSize } from "../../src/drawables/drawable-font-point-size"; -import { DrawableText } from "../../src/drawables/drawable-text"; -import { DrawableTextUnderColor } from "../../src/drawables/drawable-text-under-color"; -import { MagickColors } from "../../src/magick-colors"; -import { TestFonts } from "../test-fonts"; -import { TestImages } from "../test-images"; +import { DrawableFont } from '../../src/drawables/drawable-font'; +import { DrawableFontPointSize } from '../../src/drawables/drawable-font-point-size'; +import { DrawableText } from '../../src/drawables/drawable-text'; +import { DrawableTextUnderColor } from '../../src/drawables/drawable-text-under-color'; +import { MagickColors } from '../../src/magick-colors'; +import { TestFonts } from '../test-fonts'; +import { TestImages } from '../test-images'; -describe("DrawableTextUnderColor", () => { - it("should write text without text under color to the image", () => { +describe('DrawableTextUnderColor', () => { + it('should write text without text under color to the image', () => { TestImages.empty150x150Canvas.use((image) => { image.draw([ new DrawableFont(TestFonts.kaushanScriptRegularTtf.name), new DrawableFontPointSize(80), - new DrawableText(0, 100, "I"), + new DrawableText(0, 100, 'I'), ]); - expect(image).toHavePixelWithColor(37, 50, "#ffffffff"); - expect(image).toHavePixelWithColor(38, 50, "#ffffffff"); - expect(image).toHavePixelWithColor(39, 50, "#ffffffff"); + expect(image).toHavePixelWithColor(37, 50, '#ffffffff'); + expect(image).toHavePixelWithColor(38, 50, '#ffffffff'); + expect(image).toHavePixelWithColor(39, 50, '#ffffffff'); }); }); - it("should write text with text under color to the image", () => { + it('should write text with text under color to the image', () => { TestImages.empty150x150Canvas.use((image) => { image.draw([ new DrawableFont(TestFonts.kaushanScriptRegularTtf.name), new DrawableFontPointSize(80), new DrawableTextUnderColor(MagickColors.Pink), - new DrawableText(0, 100, "I"), + new DrawableText(0, 100, 'I'), ]); - expect(image).toHavePixelWithColor(37, 50, "#ffc0cbff"); - expect(image).toHavePixelWithColor(38, 50, "#fffcfdff"); - expect(image).toHavePixelWithColor(39, 50, "#ffffffff"); + expect(image).toHavePixelWithColor(37, 50, '#ffc0cbff'); + expect(image).toHavePixelWithColor(38, 50, '#fffcfdff'); + expect(image).toHavePixelWithColor(39, 50, '#ffffffff'); }); }); }); diff --git a/tests/magick-image/motion-blur.spec.ts b/tests/magick-image/motion-blur.spec.ts index 534dc769..e3100b0c 100644 --- a/tests/magick-image/motion-blur.spec.ts +++ b/tests/magick-image/motion-blur.spec.ts @@ -1,7 +1,7 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import { TestImages } from "../test-images"; +import { TestImages } from '../test-images'; describe('MagickImage#motionBlur', () => { it('should change pixels of the image', () => { From 8859fd2778e13a51b3521b38dd84d6692d8c4bc8 Mon Sep 17 00:00:00 2001 From: Pepijn Peeters Date: Mon, 18 Dec 2023 16:17:09 +0100 Subject: [PATCH 3/4] Make package type module --- .eslintrc.json | 7 ++----- .github/workflows/main.yml | 4 +++- demo/demo.ts | 2 +- deno/example.ts | 2 +- issue/issue.ts | 6 +----- package.json | 11 ++++++----- tests/dist/{test-CJS.js => test-CJS.cjs} | 6 +++--- tests/dist/test-ESM.js | 14 ++++++++++++++ tests/dist/test-ESM.mjs | 12 ------------ tests/dist/test-dist.js | 15 +++++++++------ tests/magick-image/on-warning.spec.ts | 2 +- vite.config.mts => vite.config.ts | 0 12 files changed, 41 insertions(+), 40 deletions(-) rename tests/dist/{test-CJS.js => test-CJS.cjs} (57%) create mode 100644 tests/dist/test-ESM.js delete mode 100644 tests/dist/test-ESM.mjs rename vite.config.mts => vite.config.ts (100%) diff --git a/.eslintrc.json b/.eslintrc.json index db16d0d1..6a0c417f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,8 +1,5 @@ { - "plugins": [ - "@typescript-eslint", - "header" - ], + "plugins": ["@typescript-eslint", "header"], "parser": "@typescript-eslint/parser", "parserOptions": { "project": [ @@ -24,7 +21,7 @@ "issue/*.ts", "issue/*.js", "tools/*.js", - "vite.config.mts" + "vite.config.ts" ], "rules": { "header/header": [ diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 04c9f6e6..cfa87d15 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,9 +39,11 @@ jobs: - run: npm run update-index + - run: npm run test + - run: npm run build - - run: npm run test + - run: npm run prepare - run: npm run test-dist diff --git a/demo/demo.ts b/demo/demo.ts index c38fab9a..7f41bdb6 100644 --- a/demo/demo.ts +++ b/demo/demo.ts @@ -7,7 +7,7 @@ import { Magick, MagickFormat, Quantum, -} from '../'; // Change to '@imagemagick/magick-wasm' when using this in your project. +} from '@imagemagick/magick-wasm'; import * as fs from 'fs'; // Remove '../' and use '@imagemagick/magick-wasm' when using this in your project. diff --git a/deno/example.ts b/deno/example.ts index aaf68790..fda876d0 100644 --- a/deno/example.ts +++ b/deno/example.ts @@ -3,7 +3,7 @@ import { initializeImageMagick, ImageMagick, MagickFormat -} from '../dist/index.mjs' +} from '../dist/index.js' const wasm = await Deno.readFile('../dist/magick.wasm'); await initializeImageMagick(wasm); diff --git a/issue/issue.ts b/issue/issue.ts index 078dc68d..de1b8d29 100644 --- a/issue/issue.ts +++ b/issue/issue.ts @@ -2,11 +2,7 @@ // Licensed under the Apache License, Version 2.0. import * as fs from 'fs'; -import { - initializeImageMagick, - ImageMagick, - MagickFormat, -} from '../'; +import { initializeImageMagick, ImageMagick } from '@imagemagick/magick-wasm'; const inputFile = ''; const bytes = fs.readFileSync(inputFile); diff --git a/package.json b/package.json index 43e1d4f9..7993b646 100644 --- a/package.json +++ b/package.json @@ -20,16 +20,17 @@ }, "license": "Apache-2.0", "author": "Dirk Lemstra", + "type": "module", "exports": { ".": { - "import": "./dist/index.mjs", - "require": "./dist/index.umd.js", + "import": "./dist/index.js", + "require": "./dist/index.umd.cjs", "types": "./dist/index.d.ts" }, "./magick.wasm": "./dist/magick.wasm" }, - "main": "./dist/index.umd.js", - "module": "./dist/index.mjs", + "main": "./dist/index.umd.cjs", + "module": "./dist/index.js", "types": "./dist/index.d.ts", "files": [ "dist", @@ -42,7 +43,7 @@ "issue": "cd issue && tsc && node issue.js", "prepare": "copyfiles -f ./node_modules/@dlemstra/magick-native/NOTICE . && copyfiles -f ./node_modules/@dlemstra/magick-native/magick.wasm dist", "test": "vitest run --poolOptions.threads.isolate false", - "test-dist": "cd tests/dist && node test-dist", + "test-dist": "node tests/dist/test-dist", "update-index": "cd tools && tsc && node update-index.js ../src" }, "devDependencies": { diff --git a/tests/dist/test-CJS.js b/tests/dist/test-CJS.cjs similarity index 57% rename from tests/dist/test-CJS.js rename to tests/dist/test-CJS.cjs index f9d9002f..74c6311e 100644 --- a/tests/dist/test-CJS.js +++ b/tests/dist/test-CJS.cjs @@ -1,10 +1,10 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -const { initializeImageMagick, Magick } = require('../../dist/index.umd.js'); -const fs = require('fs'); +const fs = require('node:fs'); +const { initializeImageMagick, Magick } = require('@imagemagick/magick-wasm'); -const wasmLocation = '../../node_modules/@dlemstra/magick-native/magick.wasm'; +const wasmLocation = require.resolve('@imagemagick/magick-wasm/magick.wasm'); const wasmBytes = fs.readFileSync(wasmLocation); initializeImageMagick(wasmBytes).then(() => { diff --git a/tests/dist/test-ESM.js b/tests/dist/test-ESM.js new file mode 100644 index 00000000..ef05a7a6 --- /dev/null +++ b/tests/dist/test-ESM.js @@ -0,0 +1,14 @@ +// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. +// Licensed under the Apache License, Version 2.0. + +import fs from 'node:fs'; +import { createRequire } from 'node:module'; +import { initializeImageMagick, Magick } from '@imagemagick/magick-wasm'; +const require = createRequire(import.meta.url); + +const wasmLocation = require.resolve('@imagemagick/magick-wasm/magick.wasm'); +const wasmBytes = fs.readFileSync(wasmLocation); + +initializeImageMagick(wasmBytes).then(() => { + console.log(Magick.features); +}); diff --git a/tests/dist/test-ESM.mjs b/tests/dist/test-ESM.mjs deleted file mode 100644 index bad0cbf2..00000000 --- a/tests/dist/test-ESM.mjs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. -// Licensed under the Apache License, Version 2.0. - -import { initializeImageMagick, Magick } from '../../dist/index.mjs'; -import fs from 'fs'; - -const wasmLocation = '../../node_modules/@dlemstra/magick-native/magick.wasm'; -const wasmBytes = fs.readFileSync(wasmLocation); - -initializeImageMagick(wasmBytes).then(() => { - console.log(Magick.features); -}); diff --git a/tests/dist/test-dist.js b/tests/dist/test-dist.js index 3041f280..66893ad4 100644 --- a/tests/dist/test-dist.js +++ b/tests/dist/test-dist.js @@ -1,8 +1,11 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -const util = require('node:util'); -const exec = util.promisify(require('node:child_process').exec); +import { promisify } from 'node:util'; +import { exec as execWithCallback } from 'node:child_process'; +import { createRequire } from 'node:module'; +const exec = promisify(execWithCallback); +const require = createRequire(import.meta.url); const features = 'Cipher'; @@ -10,7 +13,7 @@ let foundError = false; async function runTest(filename) { try { - return await exec(`node ${filename}`); + return await exec(`node ${require.resolve(filename)}`); } catch (error) { return { stdout: '', @@ -22,7 +25,7 @@ async function runTest(filename) { async function testDistFile(filename) { const { stdout, stderr } = await runTest(filename); - const name = filename.substring(5, 8); + const name = filename.substring(7, 10); if (stdout.trim() === features) { console.log(`${name} build passed`); @@ -36,8 +39,8 @@ async function testDistFile(filename) { } async function testDist() { - await testDistFile('test-ESM.mjs'); - await testDistFile('test-CJS.js'); + await testDistFile('./test-ESM.js'); + await testDistFile('./test-CJS.cjs'); if (foundError) process.exit(1); } diff --git a/tests/magick-image/on-warning.spec.ts b/tests/magick-image/on-warning.spec.ts index 4f9c4f2e..12f9c495 100644 --- a/tests/magick-image/on-warning.spec.ts +++ b/tests/magick-image/on-warning.spec.ts @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. import { TestImages } from '@test/test-images'; -import { MagickErrorSeverity } from '../../dist/index.mjs'; +import { MagickErrorSeverity } from '@src/enums/magick-error-severity'; describe('MagickImage#onWarning', () => { it('should be called when ImageMagick raises a warning.', () => { diff --git a/vite.config.mts b/vite.config.ts similarity index 100% rename from vite.config.mts rename to vite.config.ts From ae8106cb929008304792d4ba5cb33f81c11cc656 Mon Sep 17 00:00:00 2001 From: Pepijn Peeters Date: Mon, 18 Dec 2023 20:15:20 +0100 Subject: [PATCH 4/4] Consistenly start with and mark internal node modules as such --- demo/demo.ts | 4 ++-- issue/issue.ts | 6 +++--- tests/custom-environment.ts | 4 ++-- tests/dist/test-CJS.cjs | 4 ++-- tests/dist/test-ESM.js | 5 +++-- tests/dist/test-dist.js | 3 ++- tests/save-image.ts | 4 ++-- tests/test-fonts.ts | 4 ++-- tests/test-images.ts | 6 +++--- tools/update-index.ts | 2 +- vite.config.ts | 7 +++---- 11 files changed, 25 insertions(+), 24 deletions(-) diff --git a/demo/demo.ts b/demo/demo.ts index 7f41bdb6..86651a10 100644 --- a/demo/demo.ts +++ b/demo/demo.ts @@ -1,6 +1,7 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. +import { readFileSync } from 'node:fs'; import { initializeImageMagick, ImageMagick, @@ -8,11 +9,10 @@ import { MagickFormat, Quantum, } from '@imagemagick/magick-wasm'; -import * as fs from 'fs'; // Remove '../' and use '@imagemagick/magick-wasm' when using this in your project. const wasmLocation = '../node_modules/@dlemstra/magick-native/magick.wasm'; -const wasmBytes = fs.readFileSync(wasmLocation); +const wasmBytes = readFileSync(wasmLocation); initializeImageMagick(wasmBytes).then(() => { console.log(Magick.imageMagickVersion); console.log('Delegates:', Magick.delegates); diff --git a/issue/issue.ts b/issue/issue.ts index de1b8d29..6a3e562a 100644 --- a/issue/issue.ts +++ b/issue/issue.ts @@ -1,14 +1,14 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import * as fs from 'fs'; +import { readFileSync } from 'node:fs'; import { initializeImageMagick, ImageMagick } from '@imagemagick/magick-wasm'; const inputFile = ''; -const bytes = fs.readFileSync(inputFile); +const bytes = readFileSync(inputFile); const wasmLocation = '../node_modules/@dlemstra/magick-native/magick.wasm'; -const wasmBytes = fs.readFileSync(wasmLocation); +const wasmBytes = readFileSync(wasmLocation); initializeImageMagick(wasmBytes).then(() => { ImageMagick.read(bytes, (image) => { }); diff --git a/tests/custom-environment.ts b/tests/custom-environment.ts index 828508f6..1df2d97f 100644 --- a/tests/custom-environment.ts +++ b/tests/custom-environment.ts @@ -1,12 +1,12 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. +import { readFileSync } from 'node:fs'; import { CustomMatchers, ICustomMatchers } from './custom-matcher'; import { ImageMagick, initializeImageMagick } from '@src/image-magick'; import { ImageMagickApi } from '@dlemstra/magick-native'; import { Magick } from '@src/magick'; import { TestFonts } from './test-fonts'; -import * as fs from 'fs'; declare global { var native: ImageMagickApi; /* eslint-disable-line no-var */ @@ -31,7 +31,7 @@ if (!global.native) { if (exceptionRaised === false) throw new Error('The initializeImageMagick method should have thrown an exception.'); - const bytes = fs.readFileSync('node_modules/@dlemstra/magick-native/magick.wasm'); + const bytes = readFileSync('node_modules/@dlemstra/magick-native/magick.wasm'); await initializeImageMagick(bytes); const font = TestFonts.kaushanScriptRegularTtf; diff --git a/tests/dist/test-CJS.cjs b/tests/dist/test-CJS.cjs index 74c6311e..59aca5f7 100644 --- a/tests/dist/test-CJS.cjs +++ b/tests/dist/test-CJS.cjs @@ -1,11 +1,11 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -const fs = require('node:fs'); +const { readFileSync } = require('node:fs'); const { initializeImageMagick, Magick } = require('@imagemagick/magick-wasm'); const wasmLocation = require.resolve('@imagemagick/magick-wasm/magick.wasm'); -const wasmBytes = fs.readFileSync(wasmLocation); +const wasmBytes = readFileSync(wasmLocation); initializeImageMagick(wasmBytes).then(() => { console.log(Magick.features); diff --git a/tests/dist/test-ESM.js b/tests/dist/test-ESM.js index ef05a7a6..36a2eacd 100644 --- a/tests/dist/test-ESM.js +++ b/tests/dist/test-ESM.js @@ -1,13 +1,14 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import fs from 'node:fs'; +import { readFileSync } from 'node:fs'; import { createRequire } from 'node:module'; import { initializeImageMagick, Magick } from '@imagemagick/magick-wasm'; + const require = createRequire(import.meta.url); const wasmLocation = require.resolve('@imagemagick/magick-wasm/magick.wasm'); -const wasmBytes = fs.readFileSync(wasmLocation); +const wasmBytes = readFileSync(wasmLocation); initializeImageMagick(wasmBytes).then(() => { console.log(Magick.features); diff --git a/tests/dist/test-dist.js b/tests/dist/test-dist.js index 66893ad4..0de52493 100644 --- a/tests/dist/test-dist.js +++ b/tests/dist/test-dist.js @@ -1,9 +1,10 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import { promisify } from 'node:util'; import { exec as execWithCallback } from 'node:child_process'; import { createRequire } from 'node:module'; +import { promisify } from 'node:util'; + const exec = promisify(execWithCallback); const require = createRequire(import.meta.url); diff --git a/tests/save-image.ts b/tests/save-image.ts index 047fcea5..1b4ea2e0 100644 --- a/tests/save-image.ts +++ b/tests/save-image.ts @@ -1,14 +1,14 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. +import { writeFileSync } from 'node:fs'; import { IMagickImage } from '@src/magick-image'; import { MagickFormat } from '@src/enums/magick-format'; -import * as fs from 'fs'; export function saveImage(image: IMagickImage, fileName: string): void { const info = fileName.split('.'); const format = info[info.length - 1].toUpperCase() as MagickFormat; image.write(format, data => { - fs.writeFileSync(fileName, data); + writeFileSync(fileName, data); }); } diff --git a/tests/test-fonts.ts b/tests/test-fonts.ts index fe5b8c1f..19336900 100644 --- a/tests/test-fonts.ts +++ b/tests/test-fonts.ts @@ -1,7 +1,7 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import * as fs from 'fs'; +import { readFileSync } from 'node:fs'; export class TestFont { readonly name: string; @@ -9,7 +9,7 @@ export class TestFont { constructor(name: string, fileName: string) { this.name = name; - this.data = fs.readFileSync(fileName); + this.data = readFileSync(fileName); } } diff --git a/tests/test-images.ts b/tests/test-images.ts index ea2ede17..0caf1c8a 100644 --- a/tests/test-images.ts +++ b/tests/test-images.ts @@ -1,11 +1,11 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. +import { readFileSync } from 'node:fs'; import { IMagickColor } from '@src/magick-color'; import { MagickColors } from '@src/magick-colors'; import { MagickImage, IMagickImage } from '@src/magick-image'; import { MagickImageCollection, IMagickImageCollection } from '@src/magick-image-collection'; -import * as fs from 'fs'; interface Cloneable { clone(func: (clone: T) => TReturnType): TReturnType; @@ -49,7 +49,7 @@ class TestImage extends TestImageBase { constructor(fileName: string) { super(); - this.data = fs.readFileSync(fileName); + this.data = readFileSync(fileName); } load() { @@ -63,7 +63,7 @@ class TestImageCollection extends TestImageBase { constructor(fileName: string) { super(); - this.data = fs.readFileSync(fileName); + this.data = readFileSync(fileName); } load() { diff --git a/tools/update-index.ts b/tools/update-index.ts index 96297940..467cdca9 100644 --- a/tools/update-index.ts +++ b/tools/update-index.ts @@ -1,7 +1,7 @@ // Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. // Licensed under the Apache License, Version 2.0. -import * as fs from 'fs'; +import fs from 'node:fs'; function fileHasExports(fileName: string): boolean { const lines = fs.readFileSync(fileName, 'utf-8').split(/\r?\n/); diff --git a/vite.config.ts b/vite.config.ts index d0f50640..795975de 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,6 +1,5 @@ -import { builtinModules } from 'module'; +import { resolve } from 'node:path'; import { defineConfig } from 'vitest/config'; -import path from 'path'; export default defineConfig({ build: { @@ -18,8 +17,8 @@ export default defineConfig({ }, resolve: { alias: { - '@src': path.resolve(__dirname, './src'), - '@test': path.resolve(__dirname, './tests'), + '@src': resolve(__dirname, './src'), + '@test': resolve(__dirname, './tests'), }, }, });