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'), }, }, });