broken build for node
jfgodoy opened this issue · comments
Hi @tmcw, I got here after deprecation of @mapbox/geojsonhint, so thank you for creating this replacement.
I tried this very basic example in node, but it throws invalid_type
.
const {check} = require('@placemarkio/check-geojson');
const examplePoint = {
type: 'Point',
coordinates: [0, 1],
};
check(JSON.stringify(examplePoint));
The example works perfectly fine in your tests, so I tracked the problem and found that the typescript build generates an invalid code.
look at this:
in file dist/type.d.ts
import { GeoJSON } from 'geojson';
export declare type GeoJSONTypeSet = Set<GeoJSON['type']>;
export declare const GEOJSON_FEATURE_TYPE: Set<"Point" | "MultiPoint" | "LineString" | "MultiLineString" | "Polygon" | "MultiPolygon" | "GeometryCollection" | "Feature" | "FeatureCollection">;
export declare const GEOJSON_GEOMETRY_TYPES: Set<"Point" | "MultiPoint" | "LineString" | "MultiLineString" | "Polygon" | "MultiPolygon" | "GeometryCollection" | "Feature" | "FeatureCollection">;
export declare const GEOJSON_GEOMETRY_TYPES_EX_GEOMETRY_COLLECTION: Set<"Point" | "MultiPoint" | "LineString" | "MultiLineString" | "Polygon" | "MultiPolygon" | "GeometryCollection" | "Feature" | "FeatureCollection">;
export declare const GEOJSON_TYPES: Set<"Point" | "MultiPoint" | "LineString" | "MultiLineString" | "Polygon" | "MultiPolygon" | "GeometryCollection" | "Feature" | "FeatureCollection">;
in file dist/check-geojson.cjs.development.js
var GEOJSON_FEATURE_TYPE = /*#__PURE__*/new Set(['Feature']);
var GEOJSON_GEOMETRY_TYPES = /*#__PURE__*/new Set(['Point', 'MultiPoint', 'Polygon', 'MultiPolygon', 'LineString', 'MultiLineString', 'GeometryCollection']);
var GEOJSON_GEOMETRY_TYPES_EX_GEOMETRY_COLLECTION = /*#__PURE__*/new Set(['Point', 'MultiPoint', 'Polygon', 'MultiPolygon', 'LineString', 'MultiLineString']);
var GEOJSON_TYPES = /*#__PURE__*/new Set( /*#__PURE__*/[].concat(GEOJSON_GEOMETRY_TYPES, ['Feature', 'FeatureCollection']));
The variable GEOJSON_TYPES
concats a Set and an Array, which causes the variable to not hold the expected values.
> console.log(GEOJSON_TYPES)
Set(3) {
Set(7) {
'Point',
'MultiPoint',
'Polygon',
'MultiPolygon',
'LineString',
'MultiLineString',
'GeometryCollection'
},
'Feature',
'FeatureCollection'
}
I only know basic stuff in typescript, so I don't know if this is a config problem
Odd! Thanks, I'll look into it.
Okay! This is a oft-reported issue in tsdx's Babel configuration. They have a recommended workaround, compiling for node, which also removes all fo the annoying Babel transform stuff.