Skip to content

Commit

Permalink
Consistenly start with and mark internal node modules as such
Browse files Browse the repository at this point in the history
  • Loading branch information
Peeterush authored and dlemstra committed Dec 18, 2023
1 parent affd42e commit 0bc805a
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 24 deletions.
4 changes: 2 additions & 2 deletions demo/demo.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// 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,
Magick,
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);
Expand Down
6 changes: 3 additions & 3 deletions issue/issue.ts
Original file line number Diff line number Diff line change
@@ -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) => {
});
Expand Down
4 changes: 2 additions & 2 deletions tests/custom-environment.ts
Original file line number Diff line number Diff line change
@@ -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 */
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/dist/test-CJS.cjs
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
5 changes: 3 additions & 2 deletions tests/dist/test-ESM.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
3 changes: 2 additions & 1 deletion tests/dist/test-dist.js
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
4 changes: 2 additions & 2 deletions tests/save-image.ts
Original file line number Diff line number Diff line change
@@ -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);
});
}
4 changes: 2 additions & 2 deletions tests/test-fonts.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// 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;
readonly data: Buffer;

constructor(name: string, fileName: string) {
this.name = name;
this.data = fs.readFileSync(fileName);
this.data = readFileSync(fileName);
}
}

Expand Down
6 changes: 3 additions & 3 deletions tests/test-images.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
clone<TReturnType>(func: (clone: T) => TReturnType): TReturnType;
Expand Down Expand Up @@ -49,7 +49,7 @@ class TestImage extends TestImageBase<IMagickImage> {
constructor(fileName: string) {
super();

this.data = fs.readFileSync(fileName);
this.data = readFileSync(fileName);
}

load() {
Expand All @@ -63,7 +63,7 @@ class TestImageCollection extends TestImageBase<IMagickImageCollection> {
constructor(fileName: string) {
super();

this.data = fs.readFileSync(fileName);
this.data = readFileSync(fileName);
}

load() {
Expand Down
2 changes: 1 addition & 1 deletion tools/update-index.ts
Original file line number Diff line number Diff line change
@@ -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/);
Expand Down
7 changes: 3 additions & 4 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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'),
},
},
});

0 comments on commit 0bc805a

Please sign in to comment.