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

Converting packages to type: module by default #2565

Merged
merged 13 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
32 changes: 16 additions & 16 deletions .monorepolint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,29 @@ export default {
packageEntry({
options: {
entries: {
type: "module",
main: "dist/cjs/index.cjs",
module: "dist/esm/index.mjs",
types: "dist/esm/index.d.ts",
sideEffects: false,
publishConfig: {
access: "public",
},
// @turf/turf is commonly consumed through CDNs, moving this output file is a breaking change for anyone
// who has a hardcoded reference to this specific file, instead of letting the CDN pick the path.
// Example of a URL that will break: https://unpkg.com/@turf/turf/dist/turf.min.js
// Example of a URL that will keep working: https://unpkg.com/@turf/turf
browser: "turf.min.js",
files: ["dist", "index.d.ts", "turf.min.js"],
files: ["dist", "turf.min.js"],
smallsaucepan marked this conversation as resolved.
Show resolved Hide resolved
exports: {
"./package.json": "./package.json",
".": {
import: {
types: "./dist/esm/index.d.mts",
types: "./dist/esm/index.d.ts",
default: "./dist/esm/index.mjs",
},
require: {
types: "./dist/cjs/index.d.ts",
types: "./dist/cjs/index.d.cts",
smallsaucepan marked this conversation as resolved.
Show resolved Hide resolved
default: "./dist/cjs/index.cjs",
},
},
Expand All @@ -115,9 +123,10 @@ export default {
packageEntry({
options: {
entries: {
type: "module",
main: "dist/cjs/index.cjs",
module: "dist/esm/index.mjs",
types: "dist/cjs/index.d.ts",
types: "dist/esm/index.d.ts",
sideEffects: false,
publishConfig: {
access: "public",
Expand All @@ -126,11 +135,11 @@ export default {
"./package.json": "./package.json",
".": {
import: {
types: "./dist/esm/index.d.mts",
types: "./dist/esm/index.d.ts",
default: "./dist/esm/index.mjs",
},
require: {
types: "./dist/cjs/index.d.ts",
types: "./dist/cjs/index.d.cts",
default: "./dist/cjs/index.cjs",
},
},
Expand All @@ -146,16 +155,7 @@ export default {
files: ["dist"],
},
},
includePackages: TS_PACKAGES,
}),

packageEntry({
options: {
entries: {
files: ["dist", "index.d.ts"],
},
},
includePackages: JS_PACKAGES,
includePackages: [...TS_PACKAGES, ...JS_PACKAGES],
}),

packageEntry({
Expand Down
8 changes: 4 additions & 4 deletions packages/turf-along/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
"turf",
"distance"
],
"type": "commonjs",
"type": "module",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
"types": "dist/cjs/index.d.ts",
"types": "dist/esm/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/esm/index.d.mts",
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.mjs"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"types": "./dist/cjs/index.d.cts",
"default": "./dist/cjs/index.cjs"
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/turf-along/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import path from "path";
import test from "tape";
import { loadJsonFileSync } from "load-json-file";
import { Units, featureCollection } from "@turf/helpers";
import { along } from "./index";
import { along } from "./index.js";
import { Feature, LineString } from "geojson";

const line: Feature<LineString> = loadJsonFileSync(
path.join(__dirname, "test", "fixtures", "dc-line.geojson")
path.join("test", "fixtures", "dc-line.geojson")
smallsaucepan marked this conversation as resolved.
Show resolved Hide resolved
);

test("turf-along", (t) => {
Expand Down
8 changes: 4 additions & 4 deletions packages/turf-angle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
"turf",
"angle"
],
"type": "commonjs",
"type": "module",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
"types": "dist/cjs/index.d.ts",
"types": "dist/esm/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/esm/index.d.mts",
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.mjs"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"types": "./dist/cjs/index.d.cts",
"default": "./dist/cjs/index.cjs"
}
}
Expand Down
144 changes: 71 additions & 73 deletions packages/turf-angle/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,83 +8,81 @@ import { bearing } from "@turf/bearing";
import { truncate } from "@turf/truncate";
import { distance } from "@turf/distance";
import { point, round, lineString, featureCollection } from "@turf/helpers";
import { angle } from "./index";
import { angle } from "./index.js";

test("turf-angle", (t) => {
glob
.sync(path.join(__dirname, "test", "in", "*.json"))
.forEach((filepath) => {
// Input
const { name } = path.parse(filepath);
const geojson = loadJsonFileSync(filepath);
const [start, mid, end] = geojson.features;
glob.sync(path.join("test", "in", "*.json")).forEach((filepath) => {
// Input
const { name } = path.parse(filepath);
const geojson = loadJsonFileSync(filepath);
const [start, mid, end] = geojson.features;

// Results
const angleProperties = {
interiorAngle: round(angle(start, mid, end), 6),
interiorMercatorAngle: round(
angle(start, mid, end, { mercator: true }),
6
),
explementary: false,
fill: "#F00",
stroke: "#F00",
"fill-opacity": 0.3,
};
const angleExplementaryProperties = {
explementaryAngle: round(
angle(start, mid, end, { explementary: true }),
6
),
explementaryMercatorAngle: round(
angle(start, mid, end, { explementary: true, mercator: true }),
6
),
explementary: true,
fill: "#00F",
stroke: "#00F",
"fill-opacity": 0.3,
};
const results = featureCollection([
truncate(
sector(
mid,
distance(mid, start) / 3,
bearing(mid, start),
bearing(mid, end),
{ properties: angleProperties }
)
),
truncate(
sector(
mid,
distance(mid, start) / 2,
bearing(mid, end),
bearing(mid, start),
{ properties: angleExplementaryProperties }
)
),
lineString(
[
start.geometry.coordinates,
mid.geometry.coordinates,
end.geometry.coordinates,
],
{ "stroke-width": 4, stroke: "#222" }
),
start,
mid,
end,
]);
// Results
const angleProperties = {
interiorAngle: round(angle(start, mid, end), 6),
interiorMercatorAngle: round(
angle(start, mid, end, { mercator: true }),
6
),
explementary: false,
fill: "#F00",
stroke: "#F00",
"fill-opacity": 0.3,
};
const angleExplementaryProperties = {
explementaryAngle: round(
angle(start, mid, end, { explementary: true }),
6
),
explementaryMercatorAngle: round(
angle(start, mid, end, { explementary: true, mercator: true }),
6
),
explementary: true,
fill: "#00F",
stroke: "#00F",
"fill-opacity": 0.3,
};
const results = featureCollection([
truncate(
sector(
mid,
distance(mid, start) / 3,
bearing(mid, start),
bearing(mid, end),
{ properties: angleProperties }
)
),
truncate(
sector(
mid,
distance(mid, start) / 2,
bearing(mid, end),
bearing(mid, start),
{ properties: angleExplementaryProperties }
)
),
lineString(
[
start.geometry.coordinates,
mid.geometry.coordinates,
end.geometry.coordinates,
],
{ "stroke-width": 4, stroke: "#222" }
),
start,
mid,
end,
]);

// Save results
const expected = filepath.replace(
path.join("test", "in"),
path.join("test", "out")
);
if (process.env.REGEN) writeJsonFileSync(expected, results);
t.deepEqual(results, loadJsonFileSync(expected), name);
});
// Save results
const expected = filepath.replace(
path.join("test", "in"),
path.join("test", "out")
);
if (process.env.REGEN) writeJsonFileSync(expected, results);
t.deepEqual(results, loadJsonFileSync(expected), name);
});
t.end();
});

Expand Down
8 changes: 4 additions & 4 deletions packages/turf-area/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
"polygon",
"multipolygon"
],
"type": "commonjs",
"type": "module",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
"types": "dist/cjs/index.d.ts",
"types": "dist/esm/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/esm/index.d.mts",
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.mjs"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"types": "./dist/cjs/index.d.cts",
"default": "./dist/cjs/index.cjs"
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/turf-area/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import test from "tape";
import path from "path";
import { loadJsonFileSync } from "load-json-file";
import { writeJsonFileSync } from "write-json-file";
import { area } from "./index";
import { area } from "./index.js";

const directories = {
in: path.join(__dirname, "test", "in") + path.sep,
out: path.join(__dirname, "test", "out") + path.sep,
in: path.join("test", "in") + path.sep,
out: path.join("test", "out") + path.sep,
};

const fixtures = fs.readdirSync(directories.in).map((filename) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/turf-bbox-clip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
polygon,
} from "@turf/helpers";
import { getGeom } from "@turf/invariant";
import { lineclip, polygonclip } from "./lib/lineclip";
import { lineclip, polygonclip } from "./lib/lineclip.js";

/**
* Takes a {@link Feature} and a bbox and clips the feature to the bbox using
Expand Down
8 changes: 4 additions & 4 deletions packages/turf-bbox-clip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@
"bbox",
"clip"
],
"type": "commonjs",
"type": "module",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
"types": "dist/cjs/index.d.ts",
"types": "dist/esm/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/esm/index.d.mts",
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.mjs"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"types": "./dist/cjs/index.d.cts",
"default": "./dist/cjs/index.cjs"
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/turf-bbox-clip/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { loadJsonFileSync } from "load-json-file";
import { writeJsonFileSync } from "write-json-file";
import { point, feature, featureCollection } from "@turf/helpers";
import { bbox as turfBBox } from "@turf/bbox";
import { bboxClip } from "./index";
import { bboxClip } from "./index.js";

const directories = {
in: path.join(__dirname, "test", "in") + path.sep,
out: path.join(__dirname, "test", "out") + path.sep,
in: path.join("test", "in") + path.sep,
out: path.join("test", "out") + path.sep,
};

const fixtures = fs.readdirSync(directories.in).map((filename) => {
Expand Down
Loading