Skip to content

Commit

Permalink
Older style build
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
microbit-matt-hillsdon committed Jan 27, 2025
1 parent e068597 commit 771c741
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ examples/
## this is generated by `npm pack`
*.tgz
package

dist/
vite.config.*
10 changes: 3 additions & 7 deletions lib/usb-partial-flashing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 2 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 771c741

Please sign in to comment.