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 sources and package ES module compliant #269

Merged
merged 1 commit into from
Jan 14, 2022
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
1 change: 1 addition & 0 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports = {
'max-classes-per-file': 0,
'max-len': ['error', { code: 130 }],
'import/prefer-default-export': 0,
'import/extensions': ['error', 'always'],
'prefer-default-export': 0,
'func-names': 0,
'arrow-body-style': 0,
Expand Down
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@
"image",
"raster"
],
"type": "module",
"main": "dist-node/geotiff.js",
"module": "src/geotiff.js",
"jsdelivr": "dist-browser/geotiff.js",
"exports": {
".": {
"import": "./src/geotiff.js",
"require": "./dist-node/geotiff.js",
"browser": "./dist-browser/geotiff.js"
}
},
"files": [
"src",
"dist-node",
Expand Down Expand Up @@ -64,7 +72,7 @@
"dev": "parcel serve test/data/** test/index.html src/ --port 8090",
"dev:clean": "rm -rf dist/ .cache/",
"docs": "rm -rf docs/; jsdoc -c .jsdoc.json -r src README.md -d docs",
"lint": "eslint src test *.js",
"lint": "eslint src test .eslintrc.cjs",
"lint:fix": "npm run lint -- --fix",
"prepare": "npm run build",
"pretest": "npm run lint",
Expand Down
2 changes: 1 addition & 1 deletion src/compression/basedecoder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { applyPredictor } from '../predictor';
import { applyPredictor } from '../predictor.js';

export default class BaseDecoder {
async decode(fileDirectory, buffer) {
Expand Down
2 changes: 1 addition & 1 deletion src/compression/deflate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inflate } from 'pako';
import BaseDecoder from './basedecoder';
import BaseDecoder from './basedecoder.js';

export default class DeflateDecoder extends BaseDecoder {
decodeBlock(buffer) {
Expand Down
12 changes: 6 additions & 6 deletions src/compression/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export async function getDecoder(fileDirectory) {
}

// Add default decoders to registry (end-user may override with other implementations)
addDecoder([undefined, 1], () => import('./raw').then((m) => m.default));
addDecoder(5, () => import('./lzw').then((m) => m.default));
addDecoder([undefined, 1], () => import('./raw.js').then((m) => m.default));
addDecoder(5, () => import('./lzw.js').then((m) => m.default));
addDecoder(6, () => {
throw new Error('old style JPEG compression is not supported.');
});
addDecoder(7, () => import('./jpeg').then((m) => m.default));
addDecoder([8, 32946], () => import('./deflate').then((m) => m.default));
addDecoder(32773, () => import('./packbits').then((m) => m.default));
addDecoder(34887, () => import('./lerc').then((m) => m.default));
addDecoder(7, () => import('./jpeg.js').then((m) => m.default));
addDecoder([8, 32946], () => import('./deflate.js').then((m) => m.default));
addDecoder(32773, () => import('./packbits.js').then((m) => m.default));
addDecoder(34887, () => import('./lerc.js').then((m) => m.default));
2 changes: 1 addition & 1 deletion src/compression/jpeg.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import BaseDecoder from './basedecoder';
import BaseDecoder from './basedecoder.js';

/* -*- tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
Expand Down
4 changes: 2 additions & 2 deletions src/compression/lerc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { inflate } from 'pako';
import Lerc from 'lerc';
import BaseDecoder from './basedecoder';
import { LercParameters, LercAddCompression } from '../globals';
import BaseDecoder from './basedecoder.js';
import { LercParameters, LercAddCompression } from '../globals.js';

export default class LercDecoder extends BaseDecoder {
constructor(fileDirectory) {
Expand Down
2 changes: 1 addition & 1 deletion src/compression/lzw.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import BaseDecoder from './basedecoder';
import BaseDecoder from './basedecoder.js';

const MIN_BITS = 9;
const CLEAR_CODE = 256; // clear code
Expand Down
2 changes: 1 addition & 1 deletion src/compression/packbits.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import BaseDecoder from './basedecoder';
import BaseDecoder from './basedecoder.js';

export default class PackbitsDecoder extends BaseDecoder {
decodeBlock(buffer) {
Expand Down
2 changes: 1 addition & 1 deletion src/compression/raw.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import BaseDecoder from './basedecoder';
import BaseDecoder from './basedecoder.js';

export default class RawDecoder extends BaseDecoder {
decodeBlock(buffer) {
Expand Down
4 changes: 2 additions & 2 deletions src/decoder.worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expose, Transfer } from 'threads/worker';
import { getDecoder } from './compression';
import { expose, Transfer } from 'threads/worker.mjs';
import { getDecoder } from './compression/index.js';

async function decode(fileDirectory, buffer) {
const decoder = await getDecoder(fileDirectory);
Expand Down
32 changes: 16 additions & 16 deletions src/geotiff.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import GeoTIFFImage from './geotiffimage';
import DataView64 from './dataview64';
import DataSlice from './dataslice';
import Pool from './pool';

import { makeRemoteSource } from './source/remote';
import { makeBufferSource } from './source/arraybuffer';
import { makeFileReaderSource } from './source/filereader';
import { makeFileSource } from './source/file';

import { fieldTypes, fieldTagNames, arrayFields, geoKeyNames } from './globals';
import { writeGeotiff } from './geotiffwriter';
import * as globals from './globals';
import * as rgb from './rgb';
import { getDecoder, addDecoder } from './compression';
import { setLogger } from './logging';
import GeoTIFFImage from './geotiffimage.js';
import DataView64 from './dataview64.js';
import DataSlice from './dataslice.js';
import Pool from './pool.js';

import { makeRemoteSource } from './source/remote.js';
import { makeBufferSource } from './source/arraybuffer.js';
import { makeFileReaderSource } from './source/filereader.js';
import { makeFileSource } from './source/file.js';

import { fieldTypes, fieldTagNames, arrayFields, geoKeyNames } from './globals.js';
import { writeGeotiff } from './geotiffwriter.js';
import * as globals from './globals.js';
import * as rgb from './rgb.js';
import { getDecoder, addDecoder } from './compression/index.js';
import { setLogger } from './logging.js';

export { globals };
export { rgb };
Expand Down
12 changes: 6 additions & 6 deletions src/geotiffimage.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getFloat16 } from '@petamoriken/float16';
import getAttribute from 'xml-utils/get-attribute';
import findTagsByName from 'xml-utils/find-tags-by-name';
import getAttribute from 'xml-utils/get-attribute.js';
import findTagsByName from 'xml-utils/find-tags-by-name.js';

import { photometricInterpretations, ExtraSamplesValues } from './globals';
import { fromWhiteIsZero, fromBlackIsZero, fromPalette, fromCMYK, fromYCbCr, fromCIELab } from './rgb';
import { getDecoder } from './compression';
import { resample, resampleInterleaved } from './resample';
import { photometricInterpretations, ExtraSamplesValues } from './globals.js';
import { fromWhiteIsZero, fromBlackIsZero, fromPalette, fromCMYK, fromYCbCr, fromCIELab } from './rgb.js';
import { getDecoder } from './compression/index.js';
import { resample, resampleInterleaved } from './resample.js';

function sum(array, start, end) {
let s = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/geotiffwriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
You can view that here:
https://github.com/photopea/UTIF.js/blob/master/LICENSE
*/
import { fieldTagNames, fieldTagTypes, fieldTypeNames, geoKeyNames } from './globals';
import { assign, endsWith, forEach, invert, times } from './utils';
import { fieldTagNames, fieldTagTypes, fieldTypeNames, geoKeyNames } from './globals.js';
import { assign, endsWith, forEach, invert, times } from './utils.js';

const tagName2Code = invert(fieldTagNames);
const geoKeyName2Code = invert(geoKeyNames);
Expand Down
4 changes: 2 additions & 2 deletions src/source/arraybuffer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseSource } from './basesource';
import { AbortError } from '../utils';
import { BaseSource } from './basesource.js';
import { AbortError } from '../utils.js';

class ArrayBufferSource extends BaseSource {
constructor(arrayBuffer) {
Expand Down
4 changes: 2 additions & 2 deletions src/source/blockedsource.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import LRUCache from 'lru-cache';
import { BaseSource } from './basesource';
import { AbortError, AggregateError, wait, zip } from '../utils';
import { BaseSource } from './basesource.js';
import { AbortError, AggregateError, wait, zip } from '../utils.js';

class Block {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/source/client/fetch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseClient, BaseResponse } from './base';
import { BaseClient, BaseResponse } from './base.js';

class FetchResponse extends BaseResponse {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/source/client/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import http from 'http';
import https from 'https';
import urlMod from 'url';

import { BaseClient, BaseResponse } from './base';
import { AbortError } from '../../utils';
import { BaseClient, BaseResponse } from './base.js';
import { AbortError } from '../../utils.js';

class HttpResponse extends BaseResponse {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/source/client/xhr.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseClient, BaseResponse } from './base';
import { AbortError } from '../../utils';
import { BaseClient, BaseResponse } from './base.js';
import { AbortError } from '../../utils.js';

class XHRResponse extends BaseResponse {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/source/file.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs';
import { BaseSource } from './basesource';
import { BaseSource } from './basesource.js';

function closeAsync(fd) {
return new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion src/source/filereader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseSource } from './basesource';
import { BaseSource } from './basesource.js';

class FileReaderSource extends BaseSource {
constructor(file) {
Expand Down
Empty file removed src/source/index.js
Empty file.
12 changes: 6 additions & 6 deletions src/source/remote.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { parseByteRanges, parseContentRange, parseContentType } from './httputils';
import { BaseSource } from './basesource';
import { BlockedSource } from './blockedsource';
import { parseByteRanges, parseContentRange, parseContentType } from './httputils.js';
import { BaseSource } from './basesource.js';
import { BlockedSource } from './blockedsource.js';

import { FetchClient } from './client/fetch';
import { XHRClient } from './client/xhr';
import { HttpClient } from './client/http';
import { FetchClient } from './client/fetch.js';
import { XHRClient } from './client/xhr.js';
import { HttpClient } from './client/http.js';

class RemoteSource extends BaseSource {
/**
Expand Down
2 changes: 1 addition & 1 deletion test/dev.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global plotty:false */
import { Pool, fromUrl } from '../src/geotiff';
import { Pool, fromUrl } from '../src/geotiff.js';

const imageWindow = [0, 0, 500, 500];
const tiffs = [
Expand Down
17 changes: 10 additions & 7 deletions test/geotiff.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import serveStatic from 'serve-static';
import finalhandler from 'finalhandler';
import 'isomorphic-fetch';
import AbortController from 'node-abort-controller';
import { dirname } from 'path';

import { GeoTIFF, fromArrayBuffer, writeArrayBuffer, fromUrls } from '../src/geotiff';
import { makeFetchSource } from '../src/source/remote';
import { makeFileSource } from '../src/source/file';
import { BlockedSource } from '../src/source/blockedsource';
import { chunk, toArray, toArrayRecursively, range } from '../src/utils';
import DataSlice from '../src/dataslice';
import DataView64 from '../src/dataview64';
import { GeoTIFF, fromArrayBuffer, writeArrayBuffer, fromUrls } from '../src/geotiff.js';
import { makeFetchSource } from '../src/source/remote.js';
import { makeFileSource } from '../src/source/file.js';
import { BlockedSource } from '../src/source/blockedsource.js';
import { chunk, toArray, toArrayRecursively, range } from '../src/utils.js';
import DataSlice from '../src/dataslice.js';
import DataView64 from '../src/dataview64.js';

const __dirname = dirname(new URL(import.meta.url).pathname);

// Set up a node server to make tiffs available at localhost:3000/test/data
let server = null;
Expand Down
2 changes: 1 addition & 1 deletion test/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import isNode from 'detect-node';
import 'isomorphic-fetch';
import { expect } from 'chai';

import { makeFetchSource } from '../src/source/remote';
import { makeFetchSource } from '../src/source/remote.js';

const port = 9999;
let server = null;
Expand Down