Skip to content
Open
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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Build artefacts
index.cjs

# Logs
logs
*.log
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: node_js
node_js:
- 10
- 12
- node
14 changes: 8 additions & 6 deletions geojson-rewind → geojson-rewind.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/usr/bin/env node

var rewind = require('./'),
getStream = require('get-stream'),
fs = require('fs'),
argv = require('minimist')(process.argv.slice(2), {
boolean: 'clockwise'
});
import rewind from "@mapbox/geojson-rewind";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not import local module?

Copy link
Copy Markdown
Author

@qubyte qubyte Aug 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the local module :)

This is a quirk/benefit of how the exports field in the package.json file works. It's a little safer because it allows the entry point to be renamed without breaking. I've done the same in the test module. Unfortunately import rewind from "./" doesn't seem to work, so the direct translation from CJS isn't an option (at least, I haven't managed to reproduce that behaviour).

The alternative is the direct local import, which would look like import rewind from "./index.js";. Happy to change to that if you prefer, though it is (very slightly) less robust.

import getStream from "get-stream";
import fs from "fs";
import minimist from "minimist";

const argv = minimist(process.argv.slice(2), {
boolean: 'clockwise'
});

const help = `
usage:
Expand Down
5 changes: 1 addition & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

module.exports = rewind;

function rewind(gj, outer) {
export default function rewind(gj, outer) {
var type = gj && gj.type, i;

if (type === 'FeatureCollection') {
Expand Down
51 changes: 49 additions & 2 deletions package-lock.json

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

19 changes: 15 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@
"name": "@mapbox/geojson-rewind",
"version": "0.5.2",
"description": "enforce winding order for geojson",
"main": "index.js",
"bin": "geojson-rewind",
"main": "index.cjs",
"type": "module",
"module": "index.js",
"bin": {
"geojson-rewind": "geojson-rewind.js"
},
"exports": {
"import": "./index.js",
"require": "./index.cjs"
},
"directories": {
"test": "test"
},
"scripts": {
"test": "tape test/rewind.js"
"test": "tape test/rewind.js",
"prepare": "rollup -c"
},
"files": [
"index.js",
"geojson-rewind"
"index.cjs",
"geojson-rewind.js"
],
"repository": {
"type": "git",
Expand All @@ -36,6 +46,7 @@
"minimist": "^1.2.7"
},
"devDependencies": {
"rollup": "^3.27.0",
"tape": "^5.5.3"
}
}
8 changes: 8 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
input: 'index.js',
output: {
file: 'index.cjs',
format: 'cjs',
exports: 'auto'
}
};
9 changes: 6 additions & 3 deletions test/rewind.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
var rewind = require('../'),
fs = require('fs'),
test = require('tape');
import rewind from "@mapbox/geojson-rewind";
import fs from 'fs';
import test from 'tape';
import { fileURLToPath } from 'url';

const __dirname = fileURLToPath(new URL('.', import.meta.url));

function f(_) {
return JSON.parse(fs.readFileSync(_, 'utf8'));
Expand Down