Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make package type module #131

Merged
merged 4 commits into from
Dec 18, 2023
Merged
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
7 changes: 2 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"plugins": [
"@typescript-eslint",
"header"
],
"plugins": ["@typescript-eslint", "header"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": [
Expand All @@ -24,7 +21,7 @@
"issue/*.ts",
"issue/*.js",
"tools/*.js",
"vite.config.mts"
"vite.config.ts"
],
"rules": {
"header/header": [
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 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 '../'; // Change to '@imagemagick/magick-wasm' when using this in your project.
import * as fs from 'fs';
} from '@imagemagick/magick-wasm';

// 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
2 changes: 1 addition & 1 deletion deno/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 4 additions & 8 deletions issue/issue.ts
Original file line number Diff line number Diff line change
@@ -1,18 +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 {
initializeImageMagick,
ImageMagick,
MagickFormat,
} from '../';
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
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -41,8 +42,8 @@
"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-dist": "cd tests/dist && node test-dist",
"test": "vitest run --poolOptions.threads.isolate false",
"test-dist": "node tests/dist/test-dist",
"update-index": "cd tools && tsc && node update-index.js ../src"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/drawables/drawable-text-interline-spacing.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/drawables/drawable-text-interword-spacing.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/enums/channels.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 { PixelChannel } from "./pixel-channel";
import { PixelChannel } from './pixel-channel';

/**
* Specifies channel types.
Expand Down
2 changes: 1 addition & 1 deletion src/events/progress-event.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 { Percentage } from "../types/percentage";
import { Percentage } from '../types/percentage';

/**
* Class for Progress events.
Expand Down
2 changes: 1 addition & 1 deletion src/events/warning-event.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 { MagickError } from "../magick-error";
import { MagickError } from '../magick-error';

/**
* Class for warning events.
Expand Down
12 changes: 6 additions & 6 deletions src/helpers/delegate-registry.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 { 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 {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/temporary-defines.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 { IMagickImage } from "../magick-image";
import { IMagickImage } from '../magick-image';

/** @internal */
export class TemporaryDefines {
Expand Down
6 changes: 3 additions & 3 deletions src/magick-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/types/point.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 { ImageMagick } from "../image-magick";
import { ImageMagick } from '../image-magick';

/**
* Class for a point with doubles.
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
12 changes: 12 additions & 0 deletions tests/dist/test-CJS.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
// Licensed under the Apache License, Version 2.0.

const { readFileSync } = require('node:fs');
const { initializeImageMagick, Magick } = require('@imagemagick/magick-wasm');

const wasmLocation = require.resolve('@imagemagick/magick-wasm/magick.wasm');
const wasmBytes = readFileSync(wasmLocation);

initializeImageMagick(wasmBytes).then(() => {
console.log(Magick.features);
});
12 changes: 0 additions & 12 deletions tests/dist/test-CJS.js

This file was deleted.

15 changes: 15 additions & 0 deletions tests/dist/test-ESM.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
// Licensed under the Apache License, Version 2.0.

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 = readFileSync(wasmLocation);

initializeImageMagick(wasmBytes).then(() => {
console.log(Magick.features);
});
12 changes: 0 additions & 12 deletions tests/dist/test-ESM.mjs

This file was deleted.

16 changes: 10 additions & 6 deletions tests/dist/test-dist.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
// 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 { 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);

const features = 'Cipher';

let foundError = false;

async function runTest(filename) {
try {
return await exec(`node ${filename}`);
return await exec(`node ${require.resolve(filename)}`);
} catch (error) {
return {
stdout: '',
Expand All @@ -22,7 +26,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`);
Expand All @@ -36,8 +40,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);
}
Expand Down
Loading