Skip to content

Commit

Permalink
refactor: emit NodeNext modules
Browse files Browse the repository at this point in the history
Emit ESM modules that are natively compatible with Node.js 12+ and deno
  • Loading branch information
urish committed Sep 28, 2023
1 parent f09b512 commit adec722
Show file tree
Hide file tree
Showing 58 changed files with 195 additions and 186 deletions.
14 changes: 5 additions & 9 deletions build-scripts/dist-package-json.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
const fs = require('fs');
const path = require('path');
import fs from 'fs';
import path from 'path';
import * as url from 'url';

const __dirname = url.fileURLToPath(new URL('.', import.meta.url));

fs.writeFileSync(
path.join(__dirname, '../dist/cjs/package.json'),
JSON.stringify({
type: 'commonjs',
}),
);

fs.writeFileSync(
path.join(__dirname, '../dist/esm/package.json'),
JSON.stringify({
type: 'module',
}),
);
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 19 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
],
"author": "Uri Shaked <[email protected]>",
"license": "MIT",
"type": "module",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"typings": "./dist/cjs/index.d.ts",
Expand All @@ -21,16 +22,28 @@
},
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
"import": {
"default": "./dist/esm/index.js",
"types": "./dist/esm/index.d.ts"
},
"require": {
"default": "./dist/cjs/index.js",
"types": "./dist/cjs/index.d.ts"
}
},
"./gdb-tcp-server": {
"import": "./dist/esm/gdb/gdb-tcp-server.js",
"require": "./dist/cjs/gdb/gdb-tcp-server.js"
"import": {
"default": "./dist/esm/gdb/gdb-tcp-server.js",
"types": "./dist/esm/gdb/gdb-tcp-server.d.ts"
},
"require": {
"default": "./dist/cjs/gdb/gdb-tcp-server.js",
"types": "./dist/cjs/gdb/gdb-tcp-server.d.ts"
}
}
},
"scripts": {
"build": "rimraf dist && tsc && tsc -p tsconfig.esm.json && node build-scripts/dist-package-json",
"build": "rimraf dist && tsc && tsc -p tsconfig.cjs.json && node build-scripts/dist-package-json",
"prepublish": "npm run build",
"prepare": "husky install",
"format:check": "prettier --check **/*.{ts,js} !**/dist/** !**/node_modules/**",
Expand All @@ -45,7 +58,7 @@
},
"devDependencies": {
"@types/minimist": "^1.2.2",
"@types/node": "^14.14.22",
"@types/node": "^16",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
"eslint": "^8.50.0",
Expand Down
2 changes: 1 addition & 1 deletion prettier.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
arrowParens: 'always',
printWidth: 100,
singleQuote: true,
Expand Down
2 changes: 1 addition & 1 deletion src/clock/mock-clock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IClock, IClockTimer } from './clock';
import { IClock, IClockTimer } from './clock.js';

export class MockClockTimer implements IClockTimer {
constructor(
Expand Down
4 changes: 2 additions & 2 deletions src/clock/realtime-clock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getCurrentMicroseconds } from '../utils/time';
import { IClock, IClockTimer } from './clock';
import { getCurrentMicroseconds } from '../utils/time.js';
import { IClock, IClockTimer } from './clock.js';

export class ClockTimer implements IClockTimer {
private jsTimer: NodeJS.Timeout | null = null;
Expand Down
4 changes: 2 additions & 2 deletions src/cortex-m0-core.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MAX_HARDWARE_IRQ } from './irq';
import { RP2040, APB_START_ADDRESS, SIO_START_ADDRESS } from './rp2040';
import { MAX_HARDWARE_IRQ } from './irq.js';
import { RP2040, APB_START_ADDRESS, SIO_START_ADDRESS } from './rp2040.js';

/* eslint-disable @typescript-eslint/no-unused-vars */
const EXC_RESET = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/gdb/gdb-connection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GDBServer, STOP_REPLY_SIGINT, STOP_REPLY_TRAP } from './gdb-server';
import { gdbChecksum, gdbMessage } from './gdb-utils';
import { GDBServer, STOP_REPLY_SIGINT, STOP_REPLY_TRAP } from './gdb-server.js';
import { gdbChecksum, gdbMessage } from './gdb-utils.js';

export type GDBResponseHandler = (value: string) => void;

Expand Down
10 changes: 5 additions & 5 deletions src/gdb/gdb-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
* Copyright (C) 2021, Uri Shaked
*/

import { SYSM_CONTROL, SYSM_MSP, SYSM_PRIMASK, SYSM_PSP } from '../cortex-m0-core';
import { RP2040 } from '../rp2040';
import { ConsoleLogger, Logger, LogLevel } from '../utils/logging';
import { GDBConnection } from './gdb-connection';
import { SYSM_CONTROL, SYSM_MSP, SYSM_PRIMASK, SYSM_PSP } from '../cortex-m0-core.js';
import { RP2040 } from '../rp2040.js';
import { ConsoleLogger, Logger, LogLevel } from '../utils/logging.js';
import { GDBConnection } from './gdb-connection.js';
import {
decodeHexBuf,
encodeHexBuf,
encodeHexByte,
encodeHexUint32,
gdbMessage,
} from './gdb-utils';
} from './gdb-utils.js';

export const STOP_REPLY_SIGINT = 'S02';
export const STOP_REPLY_TRAP = 'S05';
Expand Down
6 changes: 3 additions & 3 deletions src/gdb/gdb-tcp-server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createServer, Socket } from 'net';
import { GDBConnection } from './gdb-connection';
import { GDBServer } from './gdb-server';
import { RP2040 } from '../rp2040';
import { GDBConnection } from './gdb-connection.js';
import { GDBServer } from './gdb-server.js';
import { RP2040 } from '../rp2040.js';

export class GDBTCPServer extends GDBServer {
private socketServer = createServer();
Expand Down
4 changes: 2 additions & 2 deletions src/gpio-pin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WaitType } from './peripherals/pio';
import { RP2040 } from './rp2040';
import { WaitType } from './peripherals/pio.js';
import { RP2040 } from './rp2040.js';

export enum GPIOPinState {
Low,
Expand Down
22 changes: 11 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
export { GDBConnection } from './gdb/gdb-connection';
export { GDBServer } from './gdb/gdb-server';
export { GPIOPin, GPIOPinState } from './gpio-pin';
export { BasePeripheral, Peripheral } from './peripherals/peripheral';
export { RPI2C, I2CSpeed, I2CMode } from './peripherals/i2c';
export { RPUSBController } from './peripherals/usb';
export { RP2040 } from './rp2040';
export { USBCDC } from './usb/cdc';
export { GDBConnection } from './gdb/gdb-connection.js';
export { GDBServer } from './gdb/gdb-server.js';
export { GPIOPin, GPIOPinState } from './gpio-pin.js';
export { BasePeripheral, Peripheral } from './peripherals/peripheral.js';
export { RPI2C, I2CSpeed, I2CMode } from './peripherals/i2c.js';
export { RPUSBController } from './peripherals/usb.js';
export { RP2040 } from './rp2040.js';
export { USBCDC } from './usb/cdc.js';
export {
DataDirection,
DescriptorType,
ISetupPacketParams,
SetupRecipient,
SetupRequest,
SetupType,
} from './usb/interfaces';
} from './usb/interfaces.js';
export {
createSetupPacket,
getDescriptorPacket,
setDeviceAddressPacket,
setDeviceConfigurationPacket,
} from './usb/setup';
export { ConsoleLogger, Logger, LogLevel } from './utils/logging';
} from './usb/setup.js';
export { ConsoleLogger, Logger, LogLevel } from './utils/logging.js';
10 changes: 5 additions & 5 deletions src/instructions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { createTestDriver } from '../test-utils/create-test-driver';
import { ICortexTestDriver } from '../test-utils/test-driver';
import { RP2040TestDriver } from '../test-utils/test-driver-rp2040';
import { RAM_START_ADDRESS, RP2040 } from './rp2040';
import { createTestDriver } from '../test-utils/create-test-driver.js';
import { ICortexTestDriver } from '../test-utils/test-driver.js';
import { RP2040TestDriver } from '../test-utils/test-driver-rp2040.js';
import { RAM_START_ADDRESS, RP2040 } from './rp2040.js';
import {
opcodeADCS,
opcodeADDS1,
Expand Down Expand Up @@ -83,7 +83,7 @@ import {
opcodeUXTH,
opcodeWFI,
opcodeYIELD,
} from './utils/assembler';
} from './utils/assembler.js';

const r0 = 0;
const r1 = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/interpolator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { s32, u32 } from './utils/bit';
import { s32, u32 } from './utils/bit.js';

export class InterpolatorConfig {
shift = 0;
Expand Down
10 changes: 5 additions & 5 deletions src/peripherals/adc.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IRQ } from '../irq';
import { RP2040 } from '../rp2040';
import { FIFO } from '../utils/fifo';
import { DREQChannel } from './dma';
import { BasePeripheral, Peripheral } from './peripheral';
import { IRQ } from '../irq.js';
import { RP2040 } from '../rp2040.js';
import { FIFO } from '../utils/fifo.js';
import { DREQChannel } from './dma.js';
import { BasePeripheral, Peripheral } from './peripheral.js';

const CS = 0x00; // ADC Control and Status
const RESULT = 0x04; // Result of most recent ADC conversion
Expand Down
4 changes: 2 additions & 2 deletions src/peripherals/busctrl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RP2040 } from '../rp2040';
import { BasePeripheral, Peripheral } from './peripheral';
import { RP2040 } from '../rp2040.js';
import { BasePeripheral, Peripheral } from './peripheral.js';

/** Bus priority acknowledge */
const BUS_PRIORITY_ACK = 0x004;
Expand Down
4 changes: 2 additions & 2 deletions src/peripherals/clocks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RP2040 } from '../rp2040';
import { BasePeripheral, Peripheral } from './peripheral';
import { RP2040 } from '../rp2040.js';
import { BasePeripheral, Peripheral } from './peripheral.js';

const CLK_REF_CTRL = 0x30;
const CLK_REF_SELECTED = 0x38;
Expand Down
6 changes: 3 additions & 3 deletions src/peripherals/dma.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest';
import { RP2040 } from '..';
import { MockClock } from '../clock/mock-clock';
import { bit } from '../utils/bit';
import { RP2040 } from '../rp2040.js';
import { MockClock } from '../clock/mock-clock.js';
import { bit } from '../utils/bit.js';

const CH2_WRITE_ADDR = 0x50000084;
const CH2_TRANS_COUNT = 0x50000088;
Expand Down
8 changes: 4 additions & 4 deletions src/peripherals/dma.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IClockTimer } from '../clock/clock';
import { IRQ } from '../irq';
import { RP2040 } from '../rp2040';
import { BasePeripheral, Peripheral } from './peripheral';
import { IClockTimer } from '../clock/clock.js';
import { IRQ } from '../irq.js';
import { RP2040 } from '../rp2040.js';
import { BasePeripheral, Peripheral } from './peripheral.js';

export enum DREQChannel {
DREQ_PIO0_TX0,
Expand Down
6 changes: 3 additions & 3 deletions src/peripherals/i2c.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RP2040 } from '../rp2040';
import { FIFO } from '../utils/fifo';
import { BasePeripheral, Peripheral } from './peripheral';
import { RP2040 } from '../rp2040.js';
import { FIFO } from '../utils/fifo.js';
import { BasePeripheral, Peripheral } from './peripheral.js';

const IC_CON = 0x00; // I2C Control Register
const IC_TAR = 0x04; // I2C Target Address Register
Expand Down
4 changes: 2 additions & 2 deletions src/peripherals/io.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RP2040 } from '../rp2040';
import { BasePeripheral, Peripheral } from './peripheral';
import { RP2040 } from '../rp2040.js';
import { BasePeripheral, Peripheral } from './peripheral.js';

const GPIO_CTRL_LAST = 0x0ec;
const INTR0 = 0xf0;
Expand Down
4 changes: 2 additions & 2 deletions src/peripherals/pads.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RP2040 } from '../rp2040';
import { BasePeripheral, Peripheral } from './peripheral';
import { RP2040 } from '../rp2040.js';
import { BasePeripheral, Peripheral } from './peripheral.js';

const VOLTAGE_SELECT = 0;
const GPIO_FIRST = 0x4;
Expand Down
2 changes: 1 addition & 1 deletion src/peripherals/peripheral.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RP2040 } from '../rp2040';
import { RP2040 } from '../rp2040.js';

const ATOMIC_NORMAL = 0;
const ATOMIC_XOR = 1;
Expand Down
6 changes: 3 additions & 3 deletions src/peripherals/pio.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { createTestDriver } from '../../test-utils/create-test-driver';
import { ICortexTestDriver } from '../../test-utils/test-driver';
import { createTestDriver } from '../../test-utils/create-test-driver.js';
import { ICortexTestDriver } from '../../test-utils/test-driver.js';
import {
PIO_COND_ALWAYS,
PIO_COND_NOTEMPTYOSR,
Expand Down Expand Up @@ -37,7 +37,7 @@ import {
pioPUSH,
pioSET,
pioWAIT,
} from '../utils/pio-assembler';
} from '../utils/pio-assembler.js';

const CTRL = 0x50200000;
const FLEVEL = 0x5020000c;
Expand Down
8 changes: 4 additions & 4 deletions src/peripherals/pio.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RP2040 } from '../rp2040';
import { FIFO } from '../utils/fifo';
import { DREQChannel } from './dma';
import { BasePeripheral, Peripheral } from './peripheral';
import { RP2040 } from '../rp2040.js';
import { FIFO } from '../utils/fifo.js';
import { DREQChannel } from './dma.js';
import { BasePeripheral, Peripheral } from './peripheral.js';

// Generic registers
const CTRL = 0x000;
Expand Down
8 changes: 4 additions & 4 deletions src/peripherals/ppb.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MAX_HARDWARE_IRQ } from '../irq';
import { RP2040 } from '../rp2040';
import { Timer32, Timer32PeriodicAlarm, TimerMode } from '../utils/timer32';
import { BasePeripheral, Peripheral } from './peripheral';
import { MAX_HARDWARE_IRQ } from '../irq.js';
import { RP2040 } from '../rp2040.js';
import { Timer32, Timer32PeriodicAlarm, TimerMode } from '../utils/timer32.js';
import { BasePeripheral, Peripheral } from './peripheral.js';

export const CPUID = 0xd00;
export const ICSR = 0xd04;
Expand Down
10 changes: 5 additions & 5 deletions src/peripherals/pwm.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IClock } from '../clock/clock';
import { IRQ } from '../irq';
import { Timer32, Timer32PeriodicAlarm, TimerMode } from '../utils/timer32';
import { DREQChannel } from './dma';
import { BasePeripheral, Peripheral } from './peripheral';
import { IClock } from '../clock/clock.js';
import { IRQ } from '../irq.js';
import { Timer32, Timer32PeriodicAlarm, TimerMode } from '../utils/timer32.js';
import { DREQChannel } from './dma.js';
import { BasePeripheral, Peripheral } from './peripheral.js';

/** Control and status register */
const CHn_CSR = 0x00;
Expand Down
2 changes: 1 addition & 1 deletion src/peripherals/reset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BasePeripheral, Peripheral } from './peripheral';
import { BasePeripheral, Peripheral } from './peripheral.js';

const RESET = 0x0; //Reset control.
const WDSEL = 0x4; //Watchdog select.
Expand Down
Loading

0 comments on commit adec722

Please sign in to comment.