From 771c7419fe821c693dc7325d4dd277d47fd322df Mon Sep 17 00:00:00 2001 From: Matt Hillsdon Date: Mon, 27 Jan 2025 13:10:56 +0000 Subject: [PATCH] Older style build This seems to be the simplest way to get ESM and CJS without throwing up issues due to the intel hex library. It's more similar to microbit-fs. --- .npmignore | 3 +++ lib/usb-partial-flashing.ts | 10 +++------- package.json | 16 ++++++++++------ tsconfig.json | 7 ++----- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.npmignore b/.npmignore index c82eb43..ca26432 100644 --- a/.npmignore +++ b/.npmignore @@ -22,3 +22,6 @@ examples/ ## this is generated by `npm pack` *.tgz package + +dist/ +vite.config.* diff --git a/lib/usb-partial-flashing.ts b/lib/usb-partial-flashing.ts index 3000cb5..20610c1 100644 --- a/lib/usb-partial-flashing.ts +++ b/lib/usb-partial-flashing.ts @@ -56,11 +56,7 @@ import { read32FromUInt8Array, } from "./usb-partial-flashing-utils.js"; import { BoardVersion } from "./device.js"; - -// Workaround for packaging issues -import * as Hex from "nrf-intel-hex"; -const MemoryMapClass = (Hex.default as any).default ?? Hex.default; -type MemoryMap = Hex.default; +import MemoryMap from "nrf-intel-hex"; type ProgressCallback = (n: number, partial: boolean) => void; @@ -349,12 +345,12 @@ export class PartialFlashing { } private hexStringToPaddedBytes(hex: string): Uint8Array { - const m = MemoryMapClass.fromHex(hex); + const m = MemoryMap.fromHex(hex); return this.memoryMapToPaddedBytes(m); } private paddedBytesToHexString(data: Uint8Array): string { - return MemoryMapClass.fromPaddedUint8Array(data).asHexString(); + return MemoryMap.fromPaddedUint8Array(data).asHexString(); } private memoryMapToPaddedBytes(memoryMap: MemoryMap): Uint8Array { diff --git a/package.json b/package.json index 5f4add5..82e16e0 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,25 @@ { "name": "@microbit/microbit-connection", "version": "0.0.0", - "type": "module", "main": "./build/cjs/index.js", "module": "./build/esm/index.js", "types": "./build/esm/index.d.ts", "exports": { ".": { - "import": "./build/esm/index.js", - "require": "./build/cjs/index.js", - "types": "./build/esm/index.d.ts" + "import": { + "types": "./build/esm/index.d.js", + "default": "./build/esm/index.js" + }, + "require": { + "types": "./build/cjs/index.d.js", + "default": "./build/cjs/index.js" + } } }, "scripts": { "dev": "vite", - "build:esm": "tsc -p tsconfig.json", - "build:cjs": "tsc -p tsconfig.cjs.json", + "build:esm": "tsc -p tsconfig.json && echo '{\"type\": \"module\"}' > build/esm/package.json", + "build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > build/cjs/package.json", "build:lib": "npm run build:esm && npm run build:cjs", "build:demo": "vite build --mode=demo", "ci": "npm run build:lib && npm run test && npx prettier --check lib src", diff --git a/tsconfig.json b/tsconfig.json index f974a20..3f7f3f1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,18 +2,15 @@ "compilerOptions": { "target": "ES2021", "useDefineForClassFields": true, - "module": "NodeNext", + "module": "ESNext", "lib": ["ES2020", "DOM", "DOM.Iterable"], "skipLibCheck": true, - - /* Bundler mode */ - "moduleResolution": "NodeNext", + "moduleResolution": "node10", "isolatedModules": true, "moduleDetection": "force", "outDir": "build/esm", "sourceMap": true, "declaration": true, - /* Linting */ "strict": true, "noUnusedLocals": true,