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

Introduced new developer experience efficiencies #2702

Draft
wants to merge 14 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
187 changes: 57 additions & 130 deletions .monorepolint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
// @ts-check
import * as path from "node:path";
import { glob } from "glob";
import * as fs from "node:fs";
import {
alphabeticalDependencies,
alphabeticalScripts,
fileContents,
packageOrder,
packageEntry,
packageScript,
requireDependency,
} from "@monorepolint/rules";

const TS_PACKAGES = []; // projects that use typescript to build
const JS_PACKAGES = []; // projects that use javascript/rollup to build
const MAIN_PACKAGE = "@turf/turf";

const TAPE_PACKAGES = []; // projects that have tape tests
const TYPES_PACKAGES = []; // projects that have types tests
const BENCH_PACKAGES = []; // projects that have benchmarks

// iterate all the packages and figure out what buckets everything falls into
const __dirname = new URL(".", import.meta.url).pathname;
glob.sync(path.join(__dirname, "packages", "turf-*")).forEach((pk) => {
const name = JSON.parse(
fs.readFileSync(path.join(pk, "package.json"), "utf8")
).name;

if (fs.existsSync(path.join(pk, "index.ts"))) {
TS_PACKAGES.push(name);
} else {
JS_PACKAGES.push(name);
}

if (fs.existsSync(path.join(pk, "test.js"))) {
TAPE_PACKAGES.push(name);
}

if (fs.existsSync(path.join(pk, "types.ts"))) {
TYPES_PACKAGES.push(name);
}
});

const TS_TAPE_PACKAGES = TAPE_PACKAGES.filter(
(pkg) => -1 !== TS_PACKAGES.indexOf(pkg)
);
const JS_TAPE_PACKAGES = TAPE_PACKAGES.filter(
(pkg) => -1 !== JS_PACKAGES.indexOf(pkg)
);

export default {
rules: [
fileContents({
Copy link
Collaborator

Choose a reason for hiding this comment

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

https://monorepolint.com/docs/rules/standard-tsconfig/ maybe we should use standardTsconfig now instead of fileContents. My biggest issue with the current monorepolint is that we've got hand-managed lists of files. Although most of our packages only use a single file, its definitely unexpected if I add another file and the import doesn't work until it gets added in here (and further extends the proliferation of special cases in this file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we can get away with something like this and be a little more forgiving of adding extra files.

{
  "include": ["index.js", "index.ts", "lib/*", "*.d.ts"],
  "exclude": ["index.d.ts"]
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Will check this idea out. Thanks 👍

options: {
file: "tsconfig.json",
template: `{
"extends": "../../tsconfig.shared.json"
}
`,
},
excludePackages: ["@turf/isobands", "@turf/isolines", "@turf/tesselate"],
}),

// Special treatment for three packages with locally defined .d.ts files for
// untyped Javascript dependencies. Might be possible to remove should those
// libraries be retired / types added to DefinitelyTyped.
fileContents({
options: {
file: "tsconfig.json",
template: `{
"extends": "../../tsconfig.shared.json",
"files": ["index.ts", "marchingsquares.d.ts"]
}
`,
},
includePackages: ["@turf/isobands", "@turf/isolines"],
}),
fileContents({
options: {
file: "tsconfig.json",
template: `{
"extends": "../../tsconfig.shared.json",
"files": ["index.ts", "earcut.d.ts"]
}
`,
},
includePackages: ["@turf/tesselate"],
}),

packageOrder({
options: {
order: [
Expand Down Expand Up @@ -86,41 +86,8 @@ export default {
}),
alphabeticalDependencies({ includeWorkspaceRoot: true }),
alphabeticalScripts({ includeWorkspaceRoot: true }),
packageEntry({
options: {
entries: {
type: "module",
main: "dist/cjs/index.cjs",
module: "dist/esm/index.js",
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", "turf.min.js"],
exports: {
"./package.json": "./package.json",
".": {
import: {
types: "./dist/esm/index.d.ts",
default: "./dist/esm/index.js",
},
require: {
types: "./dist/cjs/index.d.cts",
default: "./dist/cjs/index.cjs",
},
},
},
},
},
includePackages: [MAIN_PACKAGE],
}),

// All packages ...
packageEntry({
options: {
entries: {
Expand All @@ -129,6 +96,7 @@ export default {
module: "dist/esm/index.js",
types: "dist/esm/index.d.ts",
sideEffects: false,
funding: "https://opencollective.com/turf",
publishConfig: {
access: "public",
},
Expand All @@ -147,31 +115,38 @@ export default {
},
},
},
includePackages: [...TS_PACKAGES, ...JS_PACKAGES],
}),

// All except @turf/turf
packageEntry({
options: {
entries: {
files: ["dist"],
},
},
includePackages: [...TS_PACKAGES, ...JS_PACKAGES],
excludePackages: [MAIN_PACKAGE],
}),

// @turf/turf only
packageEntry({
options: {
entries: {
funding: "https://opencollective.com/turf",
// @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", "turf.min.js"],
},
},
includePackages: [MAIN_PACKAGE],
}),

packageScript({
options: {
scripts: {
docs: "tsx ../../scripts/generate-readmes.ts",
test: "npm-run-all --npm-path npm test:*",
"test:tape": "tsx test.ts",
"test:types": "tsc --noEmit",
},
},
excludePackages: [MAIN_PACKAGE],
Expand All @@ -183,63 +158,24 @@ export default {
build: "tsup --config ../../tsup.config.ts",
},
},
includePackages: [...TS_PACKAGES, ...JS_PACKAGES],
}),

packageScript({
options: {
scripts: {
build:
"tsup --config ../../tsup.config.ts && rollup -c rollup.config.js",
},
},
includePackages: [MAIN_PACKAGE],
}),

packageScript({
options: {
scripts: {
bench: "tsx bench.ts",
"test:tape": "tsx test.ts",
},
},
includePackages: [...TS_TAPE_PACKAGES, ...JS_TAPE_PACKAGES],
}),

packageScript({
options: {
scripts: {
"test:types":
"tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts",
},
},
includePackages: TYPES_PACKAGES,
}),

requireDependency({
options: {
devDependencies: {
benchmark: "^2.1.4",
"npm-run-all": "^4.1.5",
tape: "^5.7.2",
tsx: "^4.6.2",
},
},
includePackages: [...TS_PACKAGES, ...JS_PACKAGES],
}),

requireDependency({
options: {
dependencies: {
"@types/geojson": "^7946.0.10",
tslib: "^2.6.2",
},
devDependencies: {
"@types/benchmark": "^2.1.5",
"@types/tape": "^4.2.32",
benchmark: "^2.1.4",
"npm-run-all": "^4.1.5",
tape: "^5.7.2",
tsx: "^4.6.2",
typescript: "^5.5.4",
},
},
includePackages: TS_PACKAGES,
}),

requireDependency({
Expand All @@ -250,14 +186,5 @@ export default {
},
includePackages: [MAIN_PACKAGE],
}),

requireDependency({
options: {
dependencies: {
"@types/geojson": "^7946.0.10",
},
},
includePackages: [MAIN_PACKAGE, ...TS_PACKAGES, ...JS_PACKAGES],
}),
],
};
2 changes: 1 addition & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"{projectRoot}/test/**",
"{projectRoot}/types.ts"
],
"dependsOn": ["build"],
"dependsOn": [],
"cache": true
},
"last-checks": {
Expand Down
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
"funding": "https://opencollective.com/turf",
"scripts": {
"docs": "tsx ./scripts/generate-readmes.ts",
"escheck": "npm-run-all escheck:*",
"escheck:cjs": "es-check es8 packages/*/dist/cjs/index.cjs packages/turf/turf.min.js",
"escheck:esm": "es-check --module es8 packages/*/dist/esm/index.js",
"escheck:web": "es-check es5 packages/turf/turf.min.js",
"lint": "npm-run-all lint:*",
"lint:docs": "documentation lint packages/turf-*/index.js",
"lint:escheck-cjs": "es-check es8 packages/*/dist/cjs/index.cjs packages/turf/turf.min.js",
"lint:escheck-esm": "es-check --module es8 packages/*/dist/esm/index.js",
"lint:escheck-web": "es-check es5 packages/turf/turf.min.js",
"lint:eslint": "eslint packages",
"lint:mrl": "mrl check",
"lint:prettier": "prettier --check .",
"postinstall": "husky install",
"preinstall": "npx only-allow pnpm",
"prepare": "husky && lerna run build",
"test": "pnpm run lint && lerna run test && lerna run --scope @turf/turf last-checks"
"prepublishOnly": "lerna run build && lerna run --scope @turf/turf cdnBundle && pnpm run escheck",
"test": "pnpm run lint && lerna run test"
},
"lint-staged": {
"package.json": [
Expand All @@ -34,16 +36,16 @@
"@monorepolint/core": "0.5.0-alpha.132",
"@monorepolint/rules": "0.5.0-alpha.132",
"@types/node": "18.11.9",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"@typescript-eslint/eslint-plugin": "^8.2.0",
"@typescript-eslint/parser": "^8.2.0",
"acorn": "^7.4.1",
"camelcase": "^8.0.0",
"d3-queue": "*",
"decamelize": "^6.0.0",
"dependency-tree": "^11.0.0",
"documentation": "^14.0.3",
"es-check": "^7.1.1",
"eslint": "^8.53.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.1",
"esm": "^3.2.25",
Expand Down
3 changes: 2 additions & 1 deletion packages/turf-along/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"build": "tsup --config ../../tsup.config.ts",
"docs": "tsx ../../scripts/generate-readmes.ts",
"test": "npm-run-all --npm-path npm test:*",
"test:tape": "tsx test.ts"
"test:tape": "tsx test.ts",
"test:types": "tsc --noEmit"
},
"devDependencies": {
"@types/benchmark": "^2.1.5",
Expand Down
3 changes: 2 additions & 1 deletion packages/turf-angle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"build": "tsup --config ../../tsup.config.ts",
"docs": "tsx ../../scripts/generate-readmes.ts",
"test": "npm-run-all --npm-path npm test:*",
"test:tape": "tsx test.ts"
"test:tape": "tsx test.ts",
"test:types": "tsc --noEmit"
},
"devDependencies": {
"@turf/distance": "workspace:^",
Expand Down
3 changes: 2 additions & 1 deletion packages/turf-area/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"build": "tsup --config ../../tsup.config.ts",
"docs": "tsx ../../scripts/generate-readmes.ts",
"test": "npm-run-all --npm-path npm test:*",
"test:tape": "tsx test.ts"
"test:tape": "tsx test.ts",
"test:types": "tsc --noEmit"
},
"devDependencies": {
"@types/benchmark": "^2.1.5",
Expand Down
3 changes: 2 additions & 1 deletion packages/turf-bbox-clip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"build": "tsup --config ../../tsup.config.ts",
"docs": "tsx ../../scripts/generate-readmes.ts",
"test": "npm-run-all --npm-path npm test:*",
"test:tape": "tsx test.ts"
"test:tape": "tsx test.ts",
"test:types": "tsc --noEmit"
},
"devDependencies": {
"@turf/bbox": "workspace:^",
Expand Down
3 changes: 2 additions & 1 deletion packages/turf-bbox-polygon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"build": "tsup --config ../../tsup.config.ts",
"docs": "tsx ../../scripts/generate-readmes.ts",
"test": "npm-run-all --npm-path npm test:*",
"test:tape": "tsx test.ts"
"test:tape": "tsx test.ts",
"test:types": "tsc --noEmit"
},
"devDependencies": {
"@types/benchmark": "^2.1.5",
Expand Down
3 changes: 2 additions & 1 deletion packages/turf-bbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"build": "tsup --config ../../tsup.config.ts",
"docs": "tsx ../../scripts/generate-readmes.ts",
"test": "npm-run-all --npm-path npm test:*",
"test:tape": "tsx test.ts"
"test:tape": "tsx test.ts",
"test:types": "tsc --noEmit"
},
"devDependencies": {
"@types/benchmark": "^2.1.5",
Expand Down
3 changes: 2 additions & 1 deletion packages/turf-bearing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"build": "tsup --config ../../tsup.config.ts",
"docs": "tsx ../../scripts/generate-readmes.ts",
"test": "npm-run-all --npm-path npm test:*",
"test:tape": "tsx test.ts"
"test:tape": "tsx test.ts",
"test:types": "tsc --noEmit"
},
"devDependencies": {
"@turf/destination": "workspace:^",
Expand Down
Loading