Skip to content

Commit

Permalink
Change the main entrypoint to geotiff.js (#145)
Browse files Browse the repository at this point in the history
* fix: remove browser field from package.json and add module

* feat: parallel build of browser and node version

* chore: add files to package.json

* fix: remove threads/register that was breaking webpack builds

* feat: add jsdelivr for CDN usage

* chore: enhance README install and usage

* chore: add documentation about requirements for webpack if the worker Pool is used

* chore: fix typo in README.md

* fix: sync package-lock.json

* fix: change the main entrypoint of the package to geotiff.js instead of main.js

* chore: remove main.js

* fix: tests imports
  • Loading branch information
PacoDu committed Apr 14, 2020
1 parent 524894d commit 2ea5af8
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 15 deletions.
37 changes: 33 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,24 @@ npm run build

The output is written to `dist-browser/main.js` and `dist-node/main.js`.

## Install

You can install geotiff.js using npm:
```
npm install geotiff
```

or you can use the prebuilt version with a CDN:

```html
<script async src="https://cdn.jsdelivr.net/npm/geotiff"></script>
```
Note: Currently the CDN installation is not compatible with GeoTIFF workers pool `GeoTIFF.Pool`.


## Usage

geotiff.js works with both `require` and the global variable `GeoTIFF`:
geotiff.js works with both `require`, `import` and the global variable `GeoTIFF`:

```javascript
const GeoTIFF = require('geotiff');
Expand All @@ -121,9 +136,10 @@ import GeoTIFF from 'geotiff';
or:

```html
<script src="dist-browser/main.js"></script>
<script async src="https://cdn.jsdelivr.net/npm/geotiff"></script>
<script>
console.log(GeoTIFF);
// Note: GeoTIFF.Pool will not work
</script>
```

Expand Down Expand Up @@ -282,8 +298,21 @@ shared. But the benefits are two-fold. First: for larger image reads the overall
is still likely to be reduced and second: the main thread is relieved which helps to
uphold responsiveness.

Note: WebWorkers are only available in browsers. For node applications this feature
is not available out of the box.
If you want to use the Worker Pool in a project built with webpack (ex: VueJS or React) you have to install `threads-plugin` and add the plugin to your `webpack.config.js`:
```
npm install -D threads-plugin
```

```javascript
const ThreadsPlugin = require('threads-plugin')

module.exports = {
// ...
plugins: [
new ThreadsPlugin()
]
}
````

### Dealing with visual data

Expand Down
124 changes: 124 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
"image",
"raster"
],
"main": "dist-node/main.js",
"browser": "dist-browser/main.js",
"main": "dist-node/geotiff.js",
"module": "src/geotiff.js",
"jsdelivr": "dist-browser/geotiff.js",
"files": [
"src",
"dist-node",
"dist-browser"
],
"engines": {
"node": ">=10.19",
"browsers": "defaults"
Expand All @@ -37,14 +43,15 @@
"jsdoc-babel": "^0.5.0",
"jshint-stylish": "^2.2.1",
"mocha": "^7.1.0",
"npm-run-all": "^4.1.5",
"parcel-bundler": "^1.12.4",
"parcel-plugin-bundle-visualiser": "^1.2.0"
},
"scripts": {
"build": "npm run build:clean; npm run build:browser; npm run build:node;",
"build": "npm run build:clean; run-p build:browser build:node;",
"build:clean": "rm -rf dist-node/ dist-browser/",
"build:node": "parcel build src/main.js --target node --out-dir dist-node/",
"build:browser": "parcel build src/main.js --target browser --out-dir dist-browser/ --global GeoTIFF",
"build:node": "parcel build src/geotiff.js --target node --out-dir dist-node/",
"build:browser": "parcel build src/geotiff.js --target browser --out-dir dist-browser/ --global GeoTIFF",
"dev": "parcel serve test/data/** test/index.html --port 8090",
"dev:clean": "rm -rf dist/ .cache/",
"docs": "rm -rf docs/; jsdoc -c .jsdoc.json -r src README.md -d docs",
Expand Down
1 change: 0 additions & 1 deletion src/main.js

This file was deleted.

3 changes: 1 addition & 2 deletions src/pool.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'threads/register';
import { Pool as tPool, spawn } from 'threads';
import { Pool as tPool, spawn, Worker } from 'threads';

const defaultPoolSize = typeof navigator !== 'undefined' ? navigator.hardwareConcurrency : null;

Expand Down
2 changes: 1 addition & 1 deletion test/dev.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as GeoTIFF from '../src/main'
import GeoTIFF from '../src/geotiff'

const imageWindow = [0, 0, 500, 500];
const tiffs = [
Expand Down
2 changes: 1 addition & 1 deletion test/geotiff.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import isNode from 'detect-node';
import { expect } from 'chai';

import { GeoTIFF, fromArrayBuffer, writeArrayBuffer, Pool } from '../src/main';
import { GeoTIFF, fromArrayBuffer, writeArrayBuffer, Pool } from '../src/geotiff';
import { makeFetchSource, makeFileSource } from '../src/source';
import { chunk, toArray, toArrayRecursively, range } from '../src/utils';
import DataSlice from '../src/dataslice';
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';
import { makeFetchSource } from '../src/geotiff';

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

0 comments on commit 2ea5af8

Please sign in to comment.