From 6275e3242da2da01b71d32a5b79aa71ea4df1c29 Mon Sep 17 00:00:00 2001 From: Wes Biggs Date: Fri, 10 Nov 2023 17:43:13 -0600 Subject: [PATCH] Packaging tweaks --- package.json | 7 ++++--- scripts/package.js | 27 +++++++++++++++++++++++++++ tsconfig.json | 5 +++-- 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 scripts/package.js diff --git a/package.json b/package.json index 4d94af8..a96d3a7 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,13 @@ "name": "@dsnp/did-resolver", "version": "0.0.0", "description": "A DSNP DID resolver", - "main": "dist/index.js", - "types": "dist/index.d.ts", "type": "module", "scripts": { - "build": "tsc", + "build": "npm run clean && tsc", + "postbuild": "npm run package", + "clean": "rm -Rf dist", "prepackage": "cp CONTRIBUTING.md README.md LICENSE ./dist", + "package": "node --no-warnings scripts/package.js", "test": "jest", "format": "tsc --noEmit --pretty && eslint --fix \"**/*.ts\"", "lint": "tsc --noEmit --pretty && eslint \"**/*.ts\"" diff --git a/scripts/package.js b/scripts/package.js new file mode 100644 index 0000000..458e2aa --- /dev/null +++ b/scripts/package.js @@ -0,0 +1,27 @@ +/** + * Build the package.json for the actual publishing + */ +// eslint-disable-next-line +import fs from "fs"; +import path from "path"; +import * as url from 'url'; +const __filename = url.fileURLToPath(import.meta.url); +const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); + +// eslint-disable-next-line +import rootPackage from "../package.json" assert { type: "json" }; + +// Don't keep scripts +delete rootPackage["scripts"]; + +// Don't keep dev dependencies +delete rootPackage["devDependencies"]; + +// Setup the main and types correctly +rootPackage["module"] = "./index.js"; +rootPackage["types"] = "index.d.ts"; + +// Write it out +fs.writeFileSync(`${path.join(__dirname, "../dist", "package.json")}`, JSON.stringify(rootPackage, null, 2), (err) => { + if (err) throw new Error(err); +}); diff --git a/tsconfig.json b/tsconfig.json index 56ae2b0..0c519ef 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,8 @@ "declaration": true, "esModuleInterop": true, "strict": true, - "skipLibCheck": true + "skipLibCheck": true, + "sourceMap": false }, - "exclude": ["node_modules/**", "./test/**", "**/*.test.ts", "./dist/**"] + "exclude": ["node_modules/**", "jest.config.*", "**/*.test.ts", "./dist/**"] }