Skip to content

Commit

Permalink
Standardize Typescript builds (#1849)
Browse files Browse the repository at this point in the history
* Standardize on a single tsconfig
* Standardize tsconfig output
- Move output of es5 code into dist/js (leaves room for dist/es for modules)
- Update references from ./index over to ./dist/js/index.js
- Seems like this will publish types for several new packages
- A few packages needed to be slightly modified to publish correctly to dist
- Small fixes to @turf/turf due to the file path changes
- Note: not currently using types.ts for testing (next commit)
* Re-enable testing using types.ts in packages where that exists
* Run packages/turf tests after everything else has built
* Enforce tsc before bench
* nearest-neighbor-analysis test updates from rowanwins
  • Loading branch information
mfedderly authored Mar 15, 2020
1 parent 233c464 commit b3b5284
Show file tree
Hide file tree
Showing 478 changed files with 1,459 additions and 3,646 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.rpt2_cache
dist
packages/*/dist
main.js
main.es.js
main.mjs
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"packages/*"
],
"scripts": {
"prelint": "tsc",
"lint": "echo 'eslint will be moved to TSLint'",
"postlint": "documentation lint packages/turf-*/index.js",
"pretest": "lerna bootstrap --use-workspaces && npm run lint",
"test": "lerna run test --use-workspaces",
"posttest": "lerna run --scope @turf/turf last-checks",
"docs": "node ./scripts/generate-readmes",
"postinstall": "opencollective postinstall"
},
Expand All @@ -26,6 +26,7 @@
"lerna": "2.8.0",
"load-json-file": "*",
"meow": "*",
"npm-run-all": "^4.1.5",
"progress": "*",
"rollup": "*",
"rollup-plugin-typescript": "*",
Expand Down
1 change: 0 additions & 1 deletion packages/turf-along/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion packages/turf-along/bench.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs');
const Benchmark = require('benchmark');
const along = require('./').default;
const along = require('./dist/js/index.js').default;

const line = {
type: "Feature",
Expand Down
22 changes: 0 additions & 22 deletions packages/turf-along/index.d.ts

This file was deleted.

10 changes: 5 additions & 5 deletions packages/turf-along/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"name": "@turf/along",
"version": "6.1.0",
"description": "turf along module",
"main": "index",
"types": "index.d.ts",
"main": "dist/js/index.js",
"types": "dist/js/index.d.ts",
"files": [
"index.js",
"index.d.ts"
"dist"
],
"scripts": {
"prepare": "tsc",
"pretest": "tsc",
"test": "node test.js",
"bench": "node bench.js",
"bench": "npm-run-all prepare bench:run",
"bench:run": "node bench.js",
"docs": "node ../../scripts/generate-readmes"
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/turf-along/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path');
const test = require('tape');
const load = require('load-json-file');
const { featureCollection } = require('@turf/helpers');
const along = require('./').default;
const along = require('./dist/js/index.js').default;

const line = load.sync(path.join(__dirname, 'test', 'fixtures', 'dc-line.geojson'));

Expand Down
19 changes: 6 additions & 13 deletions packages/turf-along/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */

/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */

/* Module Resolution Options */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
}
}
"extends": "../../tsconfig.shared.json",
"compilerOptions": {
"outDir": "dist/js"
},
"files": ["index.ts"],
}
1 change: 0 additions & 1 deletion packages/turf-angle/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion packages/turf-angle/bench.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path');
const Benchmark = require('benchmark');
const angle = require('./').default;
const angle = require('./dist/js/index.js').default;

/**
* Benchmark Results
Expand Down
22 changes: 0 additions & 22 deletions packages/turf-angle/index.d.ts

This file was deleted.

10 changes: 5 additions & 5 deletions packages/turf-angle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"name": "@turf/angle",
"version": "6.0.1",
"description": "turf angle module",
"main": "index",
"types": "index.d.ts",
"main": "dist/js/index.js",
"types": "dist/js/index.d.ts",
"files": [
"index.js",
"index.d.ts"
"dist"
],
"scripts": {
"prepare": "tsc",
"pretest": "tsc",
"test": "node test.js",
"bench": "node bench.js",
"bench": "npm-run-all prepare bench:run",
"bench:run": "node bench.js",
"docs": "node ../../scripts/generate-readmes"
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/turf-angle/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const bearing = require('@turf/bearing').default;
const truncate = require('@turf/truncate').default;
const distance = require('@turf/distance').default;
const { point, round, lineString, featureCollection } = require('@turf/helpers');
const angle = require('./').default;
const angle = require('./dist/js/index.js').default;

test('turf-angle', t => {
glob.sync(path.join(__dirname, 'test', 'in', '*.json')).forEach(filepath => {
Expand Down
19 changes: 6 additions & 13 deletions packages/turf-angle/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */

/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */

/* Module Resolution Options */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
}
}
"extends": "../../tsconfig.shared.json",
"compilerOptions": {
"outDir": "dist/js"
},
"files": ["index.ts"]
}
1 change: 0 additions & 1 deletion packages/turf-area/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion packages/turf-area/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const fs = require('fs');
const path = require('path');
const load = require('load-json-file');
const Benchmark = require('benchmark');
const area = require('./').default;
const area = require('./dist/js/index.js').default;

// Define fixtures
const directory = path.join(__dirname, 'test', 'in') + path.sep;
Expand Down
17 changes: 0 additions & 17 deletions packages/turf-area/index.d.ts

This file was deleted.

10 changes: 5 additions & 5 deletions packages/turf-area/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"name": "@turf/area",
"version": "6.0.1",
"description": "turf area module",
"main": "index",
"types": "index.d.ts",
"main": "dist/js/index.js",
"types": "dist/js/index.d.ts",
"files": [
"index.js",
"index.d.ts"
"dist"
],
"scripts": {
"prepare": "tsc",
"pretest": "tsc",
"test": "node test.js",
"bench": "node bench.js",
"bench": "npm-run-all prepare bench:run",
"bench:run": "node bench.js",
"docs": "node ../../scripts/generate-readmes"
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/turf-area/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const test = require('tape');
const path = require('path');
const load = require('load-json-file');
const write = require('write-json-file');
const area = require('./').default;
const area = require('./dist/js/index.js').default;

const directories = {
in: path.join(__dirname, 'test', 'in') + path.sep,
Expand Down
19 changes: 6 additions & 13 deletions packages/turf-area/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */

/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */

/* Module Resolution Options */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
}
}
"extends": "../../tsconfig.shared.json",
"compilerOptions": {
"outDir": "dist/js"
},
"files": ["index.ts"]
}
1 change: 0 additions & 1 deletion packages/turf-bbox-clip/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion packages/turf-bbox-clip/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');
const load = require('load-json-file');
const Benchmark = require('benchmark');
const bbox = require('@turf/bbox').default;
const bboxClip = require('./').default;
const bboxClip = require('./dist/js/index.js').default;

const directory = path.join(__dirname, 'test', 'in') + path.sep;
const fixtures = fs.readdirSync(directory).map(filename => {
Expand Down
20 changes: 0 additions & 20 deletions packages/turf-bbox-clip/index.d.ts

This file was deleted.

6 changes: 3 additions & 3 deletions packages/turf-bbox-clip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
multiLineString, MultiLineString, multiPolygon, MultiPolygon, polygon, Polygon, Properties,
} from "@turf/helpers";
import { getCoords, getGeom } from "@turf/invariant";
import * as lineclip from "./lib/lineclip";
import {lineclip, polygonclip} from "./lib/lineclip";

/**
* Takes a {@link Feature} and a bbox and clips the feature to the bbox using
Expand Down Expand Up @@ -38,7 +38,7 @@ export default function bboxClip<G extends Polygon | MultiPolygon | LineString |
const lines: any[] = [];
if (type === "LineString") { coords = [coords]; }
coords.forEach((line) => {
lineclip.polyline(line, bbox, lines);
lineclip(line, bbox, lines);
});
if (lines.length === 1) { return lineString(lines[0], properties); }
return multiLineString(lines, properties);
Expand All @@ -56,7 +56,7 @@ export default function bboxClip<G extends Polygon | MultiPolygon | LineString |
function clipPolygon(rings: any[], bbox: BBox) {
const outRings = [];
for (const ring of rings) {
const clipped: any = lineclip.polygon(ring, bbox);
const clipped: any = polygonclip(ring, bbox);
if (clipped.length > 0) {
if (clipped[0][0] !== clipped[clipped.length - 1][0] || clipped[0][1] !== clipped[clipped.length - 1][1]) {
clipped.push(clipped[0]);
Expand Down
3 changes: 0 additions & 3 deletions packages/turf-bbox-clip/lib/lineclip.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
'use strict';

module.exports = lineclip;
module.exports.default = lineclip;

lineclip.polyline = lineclip;
lineclip.polygon = polygonclip;


// Cohen-Sutherland line clippign algorithm, adapted to efficiently
// handle polylines rather than just segments

function lineclip(points, bbox, result) {
export function lineclip(points, bbox, result) {

var len = points.length,
codeA = bitCode(points[0], bbox),
Expand Down Expand Up @@ -64,7 +55,7 @@ function lineclip(points, bbox, result) {

// Sutherland-Hodgeman polygon clipping algorithm

function polygonclip(points, bbox) {
export function polygonclip(points, bbox) {

var result, edge, prev, prevInside, i, p, inside;

Expand Down
Loading

0 comments on commit b3b5284

Please sign in to comment.