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

Overhaul build process #65

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data
test
src
1 change: 0 additions & 1 deletion dist/0.6000412d60ee3bcdd884.worker.worker.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/0.ce4fa17e796500cc1eca.worker.worker.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/0.georaster.browser.bundle.min.worker.js

This file was deleted.

112 changes: 0 additions & 112 deletions dist/0.georaster.browser.bundle.worker.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/0.georaster.bundle.min.worker.js

This file was deleted.

112 changes: 0 additions & 112 deletions dist/0.georaster.bundle.worker.js

This file was deleted.

112 changes: 0 additions & 112 deletions dist/1.08a977d792232ceaebd8.worker.worker.js

This file was deleted.

112 changes: 0 additions & 112 deletions dist/1.b8751dae0b6721cd3eef.worker.worker.js

This file was deleted.

371 changes: 371 additions & 0 deletions dist/es/georaster.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/es/georaster.js.map

Large diffs are not rendered by default.

2,078 changes: 512 additions & 1,566 deletions dist/georaster.browser.bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/georaster.browser.bundle.js.map

Large diffs are not rendered by default.

14 changes: 4 additions & 10 deletions dist/georaster.browser.bundle.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/georaster.browser.bundle.min.js.map

Large diffs are not rendered by default.

1,556 changes: 0 additions & 1,556 deletions dist/georaster.bundle.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/georaster.bundle.min.js

This file was deleted.

379 changes: 379 additions & 0 deletions dist/js/georaster.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/js/georaster.js.map

Large diffs are not rendered by default.

375 changes: 375 additions & 0 deletions dist/node/georaster.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/node/georaster.js.map

Large diffs are not rendered by default.

367 changes: 367 additions & 0 deletions dist/node/georaster.mjs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/node/georaster.mjs.map

Large diffs are not rendered by default.

53 changes: 25 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@
"name": "georaster",
"version": "1.5.6",
"description": "Wrapper around Georeferenced Rasters like GeoTIFF, NetCDF, JPG, and PNG that provides a standard interface",
"main": "dist/georaster.bundle.min.js",
"browser": "./dist/georaster.browser.bundle.min.js",
"unpkg": "./dist/georaster.browser.bundle.min.js",
"main": "dist/node/georaster.js",
"browser": "/dist/georaster.bundle.min.js",
"unpkg": "/dist/georaster.bundle.min.js",
"jsdelivr": "/dist/georaster.bundle.min.js",
"exports": {
".": {
"import": "./dist/es/georaster.js",
"require": "./dist/node/georaster.js",
"browser": "./dist/georaster.bundle.min.js"
}
},
"type": "module",
"scripts": {
"analyze": "ANALYZE_GEORASTER_BUNDLE=true npm run build",
"clean": "rm -f ./dist/*",
"eslint": "node ./node_modules/eslint/bin/eslint.js src",
"lint": "npm run eslint",
"fix": "node ./node_modules/eslint/bin/eslint.js src --fix",
"test": "npm run test-dev",
"test-all": "npm run test-dev && npm run test-prod",
"test-dev": "npm run dev && GEORASTER_TEST_BUNDLE_NAME='georaster.bundle.js' node ./node_modules/.bin/mocha --reporter spec",
"test-prod": "npm run build && GEORASTER_TEST_BUNDLE_NAME='georaster.bundle.min.js' node ./node_modules/.bin/mocha --reporter spec",
"dev": "webpack --mode development --target node && webpack --mode development --target web",
"build": "npm run build:prod",
"build:prod": "npm run build:prod:node && npm run build:prod:web",
"build:prod:node": "webpack --mode production --target node",
"build:prod:web": "webpack --mode production --target web"
"test": "mocha --reporter spec",
"build": "rollup -c"
},
"repository": {
"type": "git",
Expand All @@ -41,20 +43,16 @@
},
"homepage": "https://github.com/GeoTIFF/georaster#readme",
"dependencies": {
"cross-fetch": "^3.0.4",
"cross-fetch": "^3.1.5",
"georaster-to-canvas": "0.2.0",
"geotiff": "1.0.0-beta.13",
"geotiff-palette": "0.0.0",
"threads": "^1.4.0",
"tiny-worker": "^2.3.0",
"ts-node": "^8.8.2",
"txml": "3.1.2",
"underscore": "^1.8.3",
"worker-loader": "^2.0.0",
"xml-utils": "^0.2.0"
"geotiff": "^2.0.5",
"geotiff-palette": "0.0.0"
},
"devDependencies": {
"@babel/types": "^7.9.5",
"@rollup/plugin-alias": "^3.1.9",
"@rollup/plugin-commonjs": "^21.0.3",
"@rollup/plugin-node-resolve": "^13.2.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-plugin-transform-runtime": "^6.23.0",
Expand All @@ -64,11 +62,10 @@
"d3-require": "^1.2.4",
"eslint": "^5.7.0",
"eslint-config-google": "^0.11.0",
"mocha": "^6.2.0",
"null-loader": "^4.0.1",
"threads-plugin": "^1.3.1",
"webpack": "^4.12.0",
"webpack-bundle-analyzer": "^3.6.0",
"webpack-cli": "^3.0.8"
"mocha": "^7.2.0",
"rollup": "^2.70.1",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-web-worker-loader": "^1.6.1",
"xml-utils": "^0.2.0"
}
}
75 changes: 75 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import webWorkerLoader from 'rollup-plugin-web-worker-loader';
import commonjs from '@rollup/plugin-commonjs';
import nodeResolve from '@rollup/plugin-node-resolve';
import alias from '@rollup/plugin-alias';
import {terser} from 'rollup-plugin-terser';

const output = (input, file, format, plugins) => ({
input,
output: {
name: 'GeoRaster',
sourcemap: true,
format,
file,
},
plugins,
});

export default [
output('src/index.node.js', 'dist/node/georaster.mjs', 'es', [
commonjs(),
webWorkerLoader({
targetPlatform: 'node',
inline: true,
}),
]),
output('src/index.node.js', 'dist/node/georaster.js', 'cjs', [
commonjs(),
webWorkerLoader({
targetPlatform: 'node',
inline: true,
}),
]),
output('src/index.js', 'dist/js/georaster.js', 'cjs', [
commonjs(),
webWorkerLoader({
targetPlatform: 'browser',
inline: true,
}),
]),
output('src/index.js', 'dist/es/georaster.js', 'es', [
commonjs(),
webWorkerLoader({
targetPlatform: 'browser',
inline: true,
}),
]),
output('src/index.js', 'dist/georaster.browser.bundle.js', 'umd', [
alias({
entries: [
{ find: 'geotiff', replacement: 'node_modules/geotiff/dist-browser/geotiff.js' }
]
}),
nodeResolve(),
commonjs(),
webWorkerLoader({
targetPlatform: 'browser',
inline: true,
}),
]),
output('src/index.js', 'dist/georaster.browser.bundle.min.js', 'umd', [
alias({
entries: [
{ find: 'geotiff', replacement: 'node_modules/geotiff/dist-browser/geotiff.js' }
]
}),
nodeResolve(),
commonjs(),
webWorkerLoader({
targetPlatform: 'browser',
inline: true,
}),
terser()
]),
];

18 changes: 2 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
/* global Blob */
/* global URL */

import fetch from 'cross-fetch';
import Worker from './worker.js';
import Worker from 'web-worker:./worker.js';
import parseData from './parseData.js';
import {unflatten} from './utils.js';
import {fromUrl, fromUrls} from 'geotiff';
Expand Down Expand Up @@ -175,7 +174,7 @@ class GeoRaster {
}
}

const parseGeoraster = (input, metadata, debug) => {
export const parseGeoraster = (input, metadata, debug) => {
if (debug) console.log('starting parseGeoraster with ', input, metadata);

if (input === undefined) {
Expand All @@ -185,16 +184,3 @@ const parseGeoraster = (input, metadata, debug) => {

return new GeoRaster(input, metadata, debug).initialize(debug);
};

if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = parseGeoraster;
}

/*
The following code allows you to use GeoRaster without requiring
*/
if (typeof window !== 'undefined') {
window['parseGeoraster'] = parseGeoraster;
} else if (typeof self !== 'undefined') {
self['parseGeoraster'] = parseGeoraster; // jshint ignore:line
}
4 changes: 4 additions & 0 deletions src/index.node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable no-unused-vars */
import 'cross-fetch/dist/node-polyfill.js';
export * from './index.js';

2 changes: 1 addition & 1 deletion src/parseData.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {fromArrayBuffer, fromUrl, fromBlob} from 'geotiff';
import {getPalette} from 'geotiff-palette';
import {unflatten} from './utils.js';

function processResult(result, debug) {
export function processResult(result, debug) {
const noDataValue = result.noDataValue;
const height = result.height;
const width = result.width;
Expand Down
6 changes: 0 additions & 6 deletions src/parse_tiff.js

This file was deleted.

8 changes: 3 additions & 5 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function countIn1D(array) {
export function countIn1D(array) {
return array.reduce((counts, value) => {
if (counts[value] === undefined) {
counts[value] = 1;
Expand All @@ -9,7 +9,7 @@ function countIn1D(array) {
}, {});
}

function countIn2D(rows) {
export function countIn2D(rows) {
return rows.reduce((counts, values) => {
values.forEach(value => {
if (counts[value] === undefined) {
Expand All @@ -27,7 +27,7 @@ Takes in a flattened one dimensional array
representing two-dimensional pixel values
and returns an array of arrays.
*/
function unflatten(valuesInOneDimension, size) {
export function unflatten(valuesInOneDimension, size) {
const {height, width} = size;
const valuesInTwoDimensions = [];
for (let y = 0; y < height; y++) {
Expand All @@ -37,5 +37,3 @@ function unflatten(valuesInOneDimension, size) {
}
return valuesInTwoDimensions;
}

module.exports = {countIn1D, countIn2D, unflatten};
4 changes: 0 additions & 4 deletions src/worker.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import parseData from './parseData.js';

// this is a bit of a hack to trick geotiff to work with web worker
// eslint-disable-next-line no-unused-vars
const window = self;

onmessage = e => {
const data = e.data;
parseData(data).then(result => {
Expand Down
9 changes: 2 additions & 7 deletions src/parse_metadata.js → test/parse_metadata.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const findTagByPath = require('xml-utils/src/find-tag-by-path');
import findTagByPath from 'xml-utils/src/find-tag-by-path.js';


const parseISO = metadata => {
export default function parseISO(metadata) {
const results = {};

try {
Expand All @@ -21,7 +20,3 @@ const parseISO = metadata => {

return results;
};

module.exports = {
parseISO,
};
Loading