chore: extract exports path from package.json for rollup

Also sort eslint to lint JavaScript ESM files successfully.

Fixes #933
This commit is contained in:
fryorcraken.eth 2023-02-28 14:55:17 +11:00
parent 5381644606
commit 0b93fdd76d
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
26 changed files with 186 additions and 70 deletions

View File

@ -13,19 +13,23 @@
],
"globals": { "BigInt": true, "console": true, "WebAssembly": true },
"rules": {
"@typescript-eslint/explicit-function-return-type": [
"error",
{ "allowExpressions": true }
],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"eslint-comments/disable-enable-pair": [
"error",
{ "allowWholeFile": true }
{
"allowWholeFile": true
}
],
"eslint-comments/no-unused-disable": "error",
"import/order": [
"error",
{ "newlines-between": "always", "alphabetize": { "order": "asc" } }
{
"newlines-between": "always",
"alphabetize": {
"order": "asc"
}
}
],
"no-constant-condition": ["error", { "checkLoops": false }],
"import/no-extraneous-dependencies": [
@ -54,6 +58,17 @@
"@typescript-eslint/no-non-null-assertion": "off",
"no-console": "off"
}
},
{
"files": ["*.ts", "*.mts", "*.cts", "*.tsx"],
"rules": {
"@typescript-eslint/explicit-function-return-type": [
"error",
{
"allowExpressions": true
}
]
}
}
]
}

36
package-lock.json generated
View File

@ -15,7 +15,8 @@
"packages/dns-discovery",
"packages/message-encryption",
"packages/create",
"packages/tests"
"packages/tests",
"packages/build-utils"
],
"devDependencies": {
"@size-limit/preset-big-lib": "^8.2.4",
@ -7118,6 +7119,10 @@
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
"dev": true
},
"node_modules/build-utils": {
"resolved": "packages/build-utils",
"link": true
},
"node_modules/builtin-modules": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.3.0.tgz",
@ -27970,6 +27975,13 @@
"url": "https://github.com/sponsors/wooorm"
}
},
"packages/build-utils": {
"version": "1.0.0",
"license": "MIT OR Apache-2.0",
"devDependencies": {
"prettier": "^2.8.4"
}
},
"packages/core": {
"name": "@waku/core",
"version": "0.0.10",
@ -28005,6 +28017,7 @@
"@types/uuid": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.51.0",
"build-utils": "*",
"chai": "^4.3.7",
"cspell": "^6.26.3",
"eslint": "^8.35.0",
@ -28084,6 +28097,7 @@
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.51.0",
"@waku/interfaces": "*",
"build-utils": "*",
"cspell": "^6.26.3",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0",
@ -28158,6 +28172,7 @@
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.51.0",
"@waku/interfaces": "*",
"build-utils": "*",
"chai": "^4.3.7",
"cspell": "^6.26.3",
"eslint": "^8.35.0",
@ -28202,6 +28217,7 @@
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.51.0",
"@waku/interfaces": "*",
"build-utils": "*",
"chai": "^4.3.7",
"cspell": "^6.26.3",
"eslint": "^8.35.0",
@ -28285,6 +28301,7 @@
"@types/mocha": "^10.0.1",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.51.0",
"build-utils": "*",
"chai": "^4.3.7",
"cspell": "^6.26.3",
"eslint": "^8.35.0",
@ -28337,6 +28354,7 @@
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.51.0",
"@waku/interfaces": "*",
"build-utils": "*",
"chai": "^4.3.7",
"cspell": "^6.26.3",
"eslint": "^8.35.0",
@ -28369,6 +28387,7 @@
"@rollup/plugin-node-resolve": "^15.0.1",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.51.0",
"build-utils": "*",
"cspell": "^6.26.3",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0",
@ -28496,6 +28515,7 @@
"@rollup/plugin-node-resolve": "^15.0.1",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.51.0",
"build-utils": "*",
"cspell": "^6.26.3",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0",
@ -32704,6 +32724,7 @@
"@waku/interfaces": "*",
"@waku/proto": "*",
"@waku/utils": "*",
"build-utils": "*",
"chai": "^4.3.7",
"cspell": "^6.26.3",
"debug": "^4.3.4",
@ -32771,6 +32792,7 @@
"@waku/dns-discovery": "*",
"@waku/interfaces": "*",
"@waku/peer-exchange": "*",
"build-utils": "*",
"cspell": "^6.26.3",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0",
@ -32827,6 +32849,7 @@
"@waku/enr": "*",
"@waku/interfaces": "*",
"@waku/utils": "*",
"build-utils": "*",
"chai": "^4.3.7",
"cspell": "^6.26.3",
"debug": "^4.3.4",
@ -32866,6 +32889,7 @@
"@typescript-eslint/parser": "^5.51.0",
"@waku/interfaces": "*",
"@waku/utils": "*",
"build-utils": "*",
"chai": "^4.3.7",
"cspell": "^6.26.3",
"debug": "^4.3.4",
@ -32937,6 +32961,7 @@
"@waku/interfaces": "*",
"@waku/proto": "*",
"@waku/utils": "*",
"build-utils": "*",
"chai": "^4.3.7",
"cspell": "^6.26.3",
"debug": "^4.3.4",
@ -32980,6 +33005,7 @@
"@waku/enr": "*",
"@waku/interfaces": "*",
"@waku/proto": "*",
"build-utils": "*",
"chai": "^4.3.7",
"cspell": "^6.26.3",
"debug": "^4.3.4",
@ -33008,6 +33034,7 @@
"@rollup/plugin-node-resolve": "^15.0.1",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.51.0",
"build-utils": "*",
"cspell": "^6.26.3",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0",
@ -33107,6 +33134,7 @@
"@rollup/plugin-node-resolve": "^15.0.1",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.51.0",
"build-utils": "*",
"cspell": "^6.26.3",
"debug": "^4.3.4",
"eslint": "^8.35.0",
@ -34257,6 +34285,12 @@
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
"dev": true
},
"build-utils": {
"version": "file:packages/build-utils",
"requires": {
"prettier": "^2.8.4"
}
},
"builtin-modules": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.3.0.tgz",

View File

@ -12,7 +12,8 @@
"packages/dns-discovery",
"packages/message-encryption",
"packages/create",
"packages/tests"
"packages/tests",
"packages/build-utils"
],
"scripts": {
"prepare": "husky install",
@ -20,6 +21,7 @@
"build:esm": "npm run build:esm --workspaces --if-present",
"size": "npm run build && size-limit",
"fix": "npm run fix --workspaces --if-present",
"fix:lint": "npm run fix:lint --workspaces --if-present",
"check": "npm run check --workspaces --if-present",
"check:ws": "[ $(ls -1 ./packages|wc -l) -eq $(cat package.json | jq '.workspaces | length') ] || exit 1 # check no packages left behind",
"test": "npm run test --workspaces --if-present",
@ -41,7 +43,7 @@
"typedoc-plugin-resolve-crossmodule-references": "^0.3.3"
},
"lint-staged": {
"*.ts": [
"*.{ts,js}": [
"eslint --fix"
],
"*.{ts,json,js,md,cjs}": [

View File

@ -0,0 +1,21 @@
export function extractExports(packageJson) {
const exportsMap = packageJson.default.exports;
let input = {};
for (const exportPath in exportsMap) {
const filePath = exportsMap[exportPath].import;
let entry;
if (exportPath === ".") {
entry = "index";
} else {
if (!exportPath.startsWith("./")) {
throw `export path should start with \`./\` but starts with ${exportPath}`;
}
entry = exportPath.substring(2);
}
input[entry] = filePath;
}
return input;
}

View File

@ -0,0 +1,30 @@
{
"name": "build-utils",
"version": "1.0.0",
"description": "Build utilities for js-waku",
"main": "index.js",
"module": "index.js",
"type": "module",
"private": true,
"scripts": {
"fix": "run-s fix:*",
"fix:lint": "eslint . --fix",
"fix:prettier": "prettier . --write",
"check": "run-s check:*",
"check:lint": "eslint .",
"check:prettier": "prettier . --list-different"
},
"repository": {
"type": "git",
"url": "git+https://github.com/waku-org/js-waku.git"
},
"author": "Waku Team",
"license": "MIT OR Apache-2.0",
"bugs": {
"url": "https://github.com/waku-org/js-waku/issues"
},
"homepage": "https://github.com/waku-org/js-waku#readme",
"devDependencies": {
"prettier": "^2.8.4"
}
}

View File

@ -57,7 +57,7 @@
"build:bundle": "rollup --config rollup.config.js",
"fix": "run-s fix:*",
"fix:prettier": "prettier . --write",
"fix:lint": "eslint src --ext .ts --ext .cjs --fix",
"fix:lint": "eslint src *.js --fix",
"pretest": "run-s pretest:*",
"pretest:1-init-git-submodules": "[ -f '../../nwaku/build/wakunode2' ] || git submodule update --init --recursive",
"pretest:2-build-nwaku": "[ -f '../../nwaku/build/wakunode2' ] || run-s nwaku:build",
@ -65,7 +65,7 @@
"nwaku:force-build": "(cd ../../nwaku && rm -rf ./build/ ./vendor) && run-s nwaku:build",
"check": "run-s check:*",
"check:tsc": "tsc -p tsconfig.dev.json",
"check:lint": "eslint src --ext .ts",
"check:lint": "eslint src *.js",
"check:prettier": "prettier . --list-different",
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
"test": "run-s test:*",
@ -110,6 +110,7 @@
"@types/uuid": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.51.0",
"build-utils": "*",
"chai": "^4.3.7",
"cspell": "^6.26.3",
"eslint": "^8.35.0",

View File

@ -1,15 +1,14 @@
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import { extractExports } from "build-utils";
import * as packageJson from "./package.json" assert { type: "json" };
const input = extractExports(packageJson);
export default {
input: {
index: "dist/index.js",
"lib/predefined_bootstrap_nodes": "dist/lib/predefined_bootstrap_nodes.js",
"lib/message/version_0": "dist/lib/message/version_0.js",
"lib/message/topic_only_message": "dist/lib/message/topic_only_message.js",
"lib/base_protocol": "dist/lib/base_protocol.js",
},
input,
output: {
dir: "bundle",
format: "esm",

View File

@ -37,9 +37,9 @@
"build:bundle": "rollup --config rollup.config.js",
"fix": "run-s fix:*",
"fix:prettier": "prettier . --write",
"fix:lint": "eslint src --ext .ts --ext .cjs --fix",
"fix:lint": "eslint src *.js --fix",
"check": "run-s check:*",
"check:lint": "eslint src --ext .ts",
"check:lint": "eslint src *.js",
"check:prettier": "prettier . --list-different",
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
"check:tsc": "tsc -p tsconfig.dev.json",
@ -79,6 +79,7 @@
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.51.0",
"@waku/interfaces": "*",
"build-utils": "*",
"cspell": "^6.26.3",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0",

View File

@ -1,11 +1,14 @@
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import { extractExports } from "build-utils";
import * as packageJson from "./package.json" assert { type: "json" };
const input = extractExports(packageJson);
export default {
input: {
index: "dist/index.js",
},
input,
output: {
dir: "bundle",
format: "esm",

View File

@ -44,7 +44,7 @@
"build:bundle": "rollup --config rollup.config.js",
"fix": "run-s fix:*",
"fix:prettier": "prettier . --write",
"fix:lint": "eslint src --ext .ts --ext .cjs --fix",
"fix:lint": "eslint src *.js --fix",
"check": "run-s check:*",
"check:lint": "eslint src --ext .ts",
"check:prettier": "prettier . --list-different",
@ -81,6 +81,7 @@
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.51.0",
"@waku/interfaces": "*",
"build-utils": "*",
"chai": "^4.3.7",
"cspell": "^6.26.3",
"eslint": "^8.35.0",

View File

@ -1,11 +1,14 @@
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import { extractExports } from "build-utils";
import * as packageJson from "./package.json" assert { type: "json" };
const input = extractExports(packageJson);
export default {
input: {
index: "dist/index.js",
},
input,
output: {
dir: "bundle",
format: "esm",

View File

@ -37,7 +37,7 @@
"build:bundle": "rollup --config rollup.config.js",
"fix": "run-s fix:*",
"fix:prettier": "prettier . --write",
"fix:lint": "eslint src --ext .ts --ext .cjs --fix",
"fix:lint": "eslint src *.js --fix",
"check": "run-s check:*",
"check:lint": "eslint src --ext .ts",
"check:prettier": "prettier . --list-different",
@ -73,6 +73,7 @@
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.51.0",
"@waku/interfaces": "*",
"build-utils": "*",
"chai": "^4.3.7",
"cspell": "^6.26.3",
"eslint": "^8.35.0",

View File

@ -1,11 +1,14 @@
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import { extractExports } from "build-utils";
import * as packageJson from "./package.json" assert { type: "json" };
const input = extractExports(packageJson);
export default {
input: {
index: "dist/index.js",
},
input,
output: {
dir: "bundle",
format: "esm",

View File

@ -36,9 +36,9 @@
"build:esm": "tsc",
"fix": "run-s fix:*",
"fix:prettier": "prettier . --write",
"fix:lint": "eslint src --ext .ts --ext .cjs --fix",
"fix:lint": "eslint src --fix",
"check": "run-s check:*",
"check:lint": "eslint src --ext .ts",
"check:lint": "eslint src",
"check:prettier": "prettier . --list-different",
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
"check:tsc": "tsc -p tsconfig.dev.json",

View File

@ -54,9 +54,9 @@
"build:bundle": "rollup --config rollup.config.js",
"fix": "run-s fix:*",
"fix:prettier": "prettier . --write",
"fix:lint": "eslint src --ext .ts --ext .cjs --fix",
"fix:lint": "eslint src *.js --fix",
"check": "run-s check:*",
"check:lint": "eslint src --ext .ts",
"check:lint": "eslint src *.js",
"check:prettier": "prettier . --list-different",
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
"check:tsc": "tsc -p tsconfig.dev.json",
@ -95,6 +95,7 @@
"@types/mocha": "^10.0.1",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.51.0",
"build-utils": "*",
"chai": "^4.3.7",
"cspell": "^6.26.3",
"eslint": "^8.35.0",

View File

@ -1,13 +1,14 @@
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import { extractExports } from "build-utils";
import * as packageJson from "./package.json" assert { type: "json" };
const input = extractExports(packageJson);
export default {
input: {
index: "dist/index.js",
ecies: "dist/ecies.js",
symmetric: "dist/symmetric.js",
},
input,
output: {
dir: "bundle",
format: "esm",

View File

@ -37,9 +37,9 @@
"build:bundle": "rollup --config rollup.config.js",
"fix": "run-s fix:*",
"fix:prettier": "prettier . --write",
"fix:lint": "eslint src --ext .ts --ext .cjs --fix",
"fix:lint": "eslint src *.js --fix",
"check": "run-s check:*",
"check:lint": "eslint src --ext .ts",
"check:lint": "eslint src *.js",
"check:prettier": "prettier . --list-different",
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
"check:tsc": "tsc -p tsconfig.dev.json",
@ -71,6 +71,7 @@
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.51.0",
"@waku/interfaces": "*",
"build-utils": "*",
"chai": "^4.3.7",
"cspell": "^6.26.3",
"eslint": "^8.35.0",

View File

@ -1,11 +1,14 @@
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import { extractExports } from "build-utils";
import * as packageJson from "./package.json" assert { type: "json" };
const input = extractExports(packageJson);
export default {
input: {
index: "dist/index.js",
},
input,
output: {
dir: "bundle",
format: "esm",

View File

@ -1,8 +1,3 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"module": "esnext",
"noEmit": true
},
"exclude": []
"extends": "../../tsconfig.dev"
}

View File

@ -1,6 +0,0 @@
module.exports = {
parserOptions: {
tsconfigRootDir: __dirname,
project: "./tsconfig.dev.json",
},
};

View File

@ -40,8 +40,7 @@
"prepublish": "npm run build",
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build",
"fix": "run-s fix:*",
"fix:prettier": "prettier . --write",
"fix:lint": "eslint src/*.ts --fix"
"fix:prettier": "prettier . --write"
},
"engines": {
"node": ">=16"
@ -55,6 +54,7 @@
"@rollup/plugin-node-resolve": "^15.0.1",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.51.0",
"build-utils": "*",
"cspell": "^6.26.3",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0",

View File

@ -1,11 +1,14 @@
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import { extractExports } from "build-utils";
import * as packageJson from "./package.json" assert { type: "json" };
const input = extractExports(packageJson);
export default {
input: {
index: "dist/index.js",
},
input,
output: {
dir: "bundle",
format: "esm",

View File

@ -37,7 +37,7 @@
"build:esm": "tsc",
"fix": "run-s fix:*",
"fix:prettier": "prettier . --write",
"fix:lint": "eslint src tests --ext .ts --ext .cjs --fix",
"fix:lint": "eslint src tests --fix",
"pretest": "run-s pretest:*",
"pretest:1-init-git-submodules": "[ -f '../../nwaku/build/wakunode2' ] || git submodule update --init --recursive",
"pretest:2-build-nwaku": "[ -f '../../nwaku/build/wakunode2' ] || run-s nwaku:build",
@ -45,7 +45,7 @@
"nwaku:force-build": "(cd ../../nwaku && rm -rf ./build/ ./vendor) && run-s nwaku:build",
"check": "run-s check:*",
"check:prettier": "prettier . --list-different",
"check:lint": "eslint src tests --ext .ts",
"check:lint": "eslint src tests",
"check:spelling": "cspell \"{README.md,{tests,src}/**/*.ts}\"",
"check:tsc": "tsc -p tsconfig.dev.json",
"test": "run-s test:*",

View File

@ -37,9 +37,9 @@
"build:bundle": "rollup --config rollup.config.js",
"fix": "run-s fix:*",
"fix:prettier": "prettier . --write",
"fix:lint": "eslint src --ext .ts --ext .cjs --fix",
"fix:lint": "eslint src *.js --fix",
"check": "run-s check:*",
"check:lint": "eslint src --ext .ts",
"check:lint": "eslint src *.js",
"check:prettier": "prettier . --list-different",
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
"check:tsc": "tsc -p tsconfig.dev.json",
@ -65,6 +65,7 @@
"@rollup/plugin-node-resolve": "^15.0.1",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.51.0",
"build-utils": "*",
"cspell": "^6.26.3",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0",

View File

@ -1,11 +1,14 @@
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import { extractExports } from "build-utils";
import * as packageJson from "./package.json" assert { type: "json" };
const input = extractExports(packageJson);
export default {
input: {
index: "dist/index.js",
},
input,
output: {
dir: "bundle",
format: "esm",