Skip to content

Commit

Permalink
feat: ✨ add node support
Browse files Browse the repository at this point in the history
Add proper support to Node. Previously when importing with node/vite there were errors about importing a directory and relative files needed the .js extension explicitly listed. Now it works in both node and browser.
  • Loading branch information
thkruz committed Mar 24, 2024
1 parent 3563ae2 commit 12cce99
Show file tree
Hide file tree
Showing 92 changed files with 3,023 additions and 3,115 deletions.
7 changes: 6 additions & 1 deletion babel.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ module.exports = {
},
},
],
'@babel/preset-typescript',
[
'@babel/preset-typescript', {
'rewriteImportExtensions': true,
},
],
],
compact: 'auto',

};
11 changes: 11 additions & 0 deletions examples/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {Satellite} from '../dist/main.js';

const tle1 = '1 56006U 23042W 24012.45049317 .00000296 00000-0 36967-4 0 9992';
const tle2 = '2 56006 43.0043 13.3620 0001137 267.5965 92.4747 15.02542972 44491';
const satellite = new Satellite({
tle1,
tle2,
});

// eslint-disable-next-line no-console
console.log(satellite);
12 changes: 11 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
const jestConfig = {
testEnvironment: 'node',
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
'\\.(js|ts|jsx|tsx)$': 'babel-jest',
'^.+\\.jsx?$': 'babel-jest',
'^.+\\.tsx?$': [
'ts-jest',
{
useESM: true,
},
],
},
testMatch: ['**/test/**/?(*.)+(spec|test).?(m)[jt]s?(x)'],
moduleFileExtensions: ['js', 'mjs', 'ts'],
Expand Down
5,406 changes: 2,639 additions & 2,767 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"module": "dist/main.js",
"description": "Orbital Object Toolkit. A modern typed replacement for satellite.js including SGP4 propagation, TLE parsing, Sun and Moon calculations, and more.",
"scripts": {
"build": "npm run clean && npx tsc -p tsconfig.build.json -m esnext",
"build": "npm run clean && npx tsc -p tsconfig.build.json",
"clean": "node ./scripts/cleanup.mjs",
"lint": "npx eslint src",
"lint:fix": "npx eslint src --fix",
Expand Down Expand Up @@ -39,16 +39,19 @@
"@babel/preset-env": "^7.23.8",
"@babel/preset-typescript": "^7.23.3",
"@types/jest": "^29.5.11",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"auto-changelog": "^2.4.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^9.1.3",
"eslint": "^8.56.0",
"eslint-plugin-jsdoc": "^48.0.2",
"fix-esm-import-path": "^1.5.0",
"jest": "^28.1.3",
"tsx": "^4.7.0",
"typescript": "^4.9.5"
"ts-jest": "^28.0.8",
"ts-node": "^10.9.2",
"tsx": "^4.7.1",
"typescript": "^5.4.3"
},
"homepage": "https://github.com/thkruz/ootk-core"
}
2 changes: 1 addition & 1 deletion src/body/Celestial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* SOFTWARE.
*/

import { AzEl, Degrees, Kilometers, RAD2DEG, RaDec, Radians, Sun } from '../main';
import { AzEl, Degrees, Kilometers, RAD2DEG, RaDec, Radians, Sun } from '../main.js';

/**
* Celestial is a static class that provides methods for calculating the position of celestial objects such as the Sun,
Expand Down
6 changes: 3 additions & 3 deletions src/body/Earth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import {
TAU,
ttasec2rad,
Vector3D,
} from '../main';
import { NutationAngles } from './NutationAngles';
import { PrecessionAngles } from './PrecessionAngles';
} from '../main.js';
import { NutationAngles } from './NutationAngles.js';
import { PrecessionAngles } from './PrecessionAngles.js';

// / Earth metrics and operations.
export class Earth {
Expand Down
14 changes: 7 additions & 7 deletions src/body/Moon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
* moon calculations are based on formulas from this website
*/

import { AngularDiameterMethod, Celestial, Degrees, Kilometers, RaDec, Radians } from '../main';
import { Vector3D } from '../operations/Vector3D';
import { EpochUTC } from '../time/EpochUTC';
import { DEG2RAD, MS_PER_DAY } from '../utils/constants';
import { angularDiameter } from '../utils/functions';
import { Earth } from './Earth';
import { Sun } from './Sun';
import { AngularDiameterMethod, Celestial, Degrees, Kilometers, RaDec, Radians } from '../main.js';
import { Vector3D } from '../operations/Vector3D.js';
import { EpochUTC } from '../time/EpochUTC.js';
import { DEG2RAD, MS_PER_DAY } from '../utils/constants.js';
import { angularDiameter } from '../utils/functions.js';
import { Earth } from './Earth.js';
import { Sun } from './Sun.js';

type MoonIlluminationData = {
fraction: number;
Expand Down
2 changes: 1 addition & 1 deletion src/body/NutationAngles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* SOFTWARE.
*/

import { Radians } from '../main';
import { Radians } from '../main.js';

/** Represents the nutation angles. */
export type NutationAngles = {
Expand Down
2 changes: 1 addition & 1 deletion src/body/PrecessionAngles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* SOFTWARE.
*/

import { Radians } from '../main';
import { Radians } from '../main.js';

/** Represents the precession angles in radians. */
export type PrecessionAngles = {
Expand Down
2 changes: 1 addition & 1 deletion src/body/Sun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import {
SunTime,
TAU,
Vector3D,
} from '../main';
} from '../main.js';

/**
* Sun metrics and operations.
Expand Down
8 changes: 4 additions & 4 deletions src/body/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* SOFTWARE.
*/

export { Celestial } from './Celestial';
export { Earth } from './Earth';
export { Moon } from './Moon';
export { Sun } from './Sun';
export { Celestial } from './Celestial.js';
export { Earth } from './Earth.js';
export { Moon } from './Moon.js';
export { Sun } from './Sun.js';
18 changes: 9 additions & 9 deletions src/coordinate/ClassicalElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
* SOFTWARE.
*/

import { Minutes, PositionVelocity, Degrees, Kilometers, Radians, Seconds, KilometersPerSecond } from '../main';
import { Vector3D } from '../operations/Vector3D';
import { EpochUTC } from '../time/EpochUTC';
import { earthGravityParam, MINUTES_PER_DAY, RAD2DEG, sec2min, TAU } from '../utils/constants';
import { clamp, matchHalfPlane, newtonNu } from '../utils/functions';
import { EquinoctialElements } from './EquinoctialElements';
import { OrbitRegime } from '../enums/OrbitRegime';
import { StateVector } from './StateVector';
import { ClassicalElementsParams } from '../interfaces/ClassicalElementsParams';
import { Minutes, PositionVelocity, Degrees, Kilometers, Radians, Seconds, KilometersPerSecond } from '../main.js';
import { Vector3D } from '../operations/Vector3D.js';
import { EpochUTC } from '../time/EpochUTC.js';
import { earthGravityParam, MINUTES_PER_DAY, RAD2DEG, sec2min, TAU } from '../utils/constants.js';
import { clamp, matchHalfPlane, newtonNu } from '../utils/functions.js';
import { EquinoctialElements } from './EquinoctialElements.js';
import { OrbitRegime } from '../enums/OrbitRegime.js';
import { StateVector } from './StateVector.js';
import { ClassicalElementsParams } from '../interfaces/ClassicalElementsParams.js';

/**
* The ClassicalElements class represents the classical orbital elements of an object.
Expand Down
12 changes: 6 additions & 6 deletions src/coordinate/EquinoctialElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
* SOFTWARE.
*/

import { Minutes, PositionVelocity, Kilometers, Radians, Seconds } from '../main';
import { EpochUTC } from '../time/EpochUTC';
import { earthGravityParam, MINUTES_PER_DAY, TAU } from '../utils/constants';
import { newtonM } from '../utils/functions';
import { ClassicalElements } from './ClassicalElements';
import { EquinoctialElementsParams } from '../interfaces/EquinoctialElementsParams';
import { Minutes, PositionVelocity, Kilometers, Radians, Seconds } from '../main.js';
import { EpochUTC } from '../time/EpochUTC.js';
import { earthGravityParam, MINUTES_PER_DAY, TAU } from '../utils/constants.js';
import { newtonM } from '../utils/functions.js';
import { ClassicalElements } from './ClassicalElements.js';
import { EquinoctialElementsParams } from '../interfaces/EquinoctialElementsParams.js';

/**
* Equinoctial elements are a set of orbital elements used to describe the
Expand Down
2 changes: 1 addition & 1 deletion src/coordinate/FormatTle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* SOFTWARE.
*/

import { Tle, StringifiedNumber, TleParams, TleLine1, TleLine2 } from '../main';
import { Tle, StringifiedNumber, TleParams, TleLine1, TleLine2 } from '../main.js';

/**
* A class containing static methods for formatting TLEs (Two-Line Elements).
Expand Down
14 changes: 7 additions & 7 deletions src/coordinate/Geodetic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
* SOFTWARE.
*/

import { Earth } from '../body/Earth';
import { AngularDistanceMethod, Degrees, GroundObject, Kilometers, KilometersPerSecond, Radians } from '../main';
import { Vector3D } from '../operations/Vector3D';
import { EpochUTC } from '../time/EpochUTC';
import { DEG2RAD, RAD2DEG } from '../utils/constants';
import { angularDistance } from '../utils/functions';
import { ITRF } from './ITRF';
import { Earth } from '../body/Earth.js';
import { AngularDistanceMethod, Degrees, GroundObject, Kilometers, KilometersPerSecond, Radians } from '../main.js';
import { Vector3D } from '../operations/Vector3D.js';
import { EpochUTC } from '../time/EpochUTC.js';
import { DEG2RAD, RAD2DEG } from '../utils/constants.js';
import { angularDistance } from '../utils/functions.js';
import { ITRF } from './ITRF.js';

/**
* This Geodetic class represents a geodetic coordinate in three-dimensional
Expand Down
10 changes: 5 additions & 5 deletions src/coordinate/ITRF.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
*/

/* eslint-disable class-methods-use-this */
import { Kilometers, KilometersPerSecond, Radians, Vector3D } from '../main';
import { Earth } from '../body/Earth';
import { Geodetic } from './Geodetic';
import { J2000 } from './J2000';
import { StateVector } from './StateVector';
import { Kilometers, KilometersPerSecond, Radians, Vector3D } from '../main.js';
import { Earth } from '../body/Earth.js';
import { Geodetic } from './Geodetic.js';
import { J2000 } from './J2000.js';
import { StateVector } from './StateVector.js';

/**
* The International Terrestrial Reference Frame (ITRF) is a geocentric reference frame for the Earth. It is the
Expand Down
12 changes: 6 additions & 6 deletions src/coordinate/J2000.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
* SOFTWARE.
*/

import { Kilometers, KilometersPerSecond, Radians, Vector3D } from '../main';
import { Earth } from '../body/Earth';
import { ClassicalElements } from './ClassicalElements';
import { ITRF } from './ITRF';
import { StateVector } from './StateVector';
import { TEME } from './TEME';
import { Kilometers, KilometersPerSecond, Radians, Vector3D } from '../main.js';
import { Earth } from '../body/Earth.js';
import { ClassicalElements } from './ClassicalElements.js';
import { ITRF } from './ITRF.js';
import { StateVector } from './StateVector.js';
import { TEME } from './TEME.js';

/**
* Represents a position and velocity in the J2000 coordinate system. This is an Earth-centered inertial (ECI)
Expand Down
6 changes: 3 additions & 3 deletions src/coordinate/RIC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
* SOFTWARE.
*/

import { Matrix } from '../operations/Matrix';
import { J2000 } from './J2000';
import { RelativeState } from './RelativeState';
import { Matrix } from '../operations/Matrix.js';
import { J2000 } from './J2000.js';
import { RelativeState } from './RelativeState.js';

/**
* Represents a Radial-Intrack-Crosstrack (RIC) coordinates.
Expand Down
8 changes: 4 additions & 4 deletions src/coordinate/RelativeState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
* SOFTWARE.
*/

import { Kilometers, KilometersPerSecond } from '../main';
import { Matrix } from '../operations/Matrix';
import { Vector3D } from '../operations/Vector3D';
import { J2000 } from './J2000';
import { Kilometers, KilometersPerSecond } from '../main.js';
import { Matrix } from '../operations/Matrix.js';
import { Vector3D } from '../operations/Vector3D.js';
import { J2000 } from './J2000.js';

/**
* Represents the relative state of an object in 3D space.
Expand Down
2 changes: 1 addition & 1 deletion src/coordinate/StateVector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* SOFTWARE.
*/

import { ClassicalElements, TAU, Earth, Kilometers, KilometersPerSecond, Minutes, EpochUTC, Vector3D } from '../main';
import { ClassicalElements, TAU, Earth, Kilometers, KilometersPerSecond, Minutes, EpochUTC, Vector3D } from '../main.js';

Check failure on line 24 in src/coordinate/StateVector.ts

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 121. Maximum allowed is 120

/**
* A state vector is a set of coordinates used to specify the position and
Expand Down
10 changes: 5 additions & 5 deletions src/coordinate/TEME.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
* SOFTWARE.
*/

import { Kilometers, KilometersPerSecond, Radians, Vector3D } from '../main';
import { Earth } from '../body/Earth';
import type { ClassicalElements } from './ClassicalElements';
import { J2000 } from './J2000';
import { StateVector } from './StateVector';
import { Kilometers, KilometersPerSecond, Radians, Vector3D } from '../main.js';
import { Earth } from '../body/Earth.js';
import type { ClassicalElements } from './ClassicalElements.js';
import { J2000 } from './J2000.js';
import { StateVector } from './StateVector.js';

/**
* True Equator Mean Equinox (TEME) is a coordinate system commonly used in satellite tracking and orbit prediction. It
Expand Down
18 changes: 9 additions & 9 deletions src/coordinate/Tle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
* SOFTWARE.
*/

import { ClassicalElements, FormatTle, TEME } from '.';
import { Sgp4OpsMode } from '../enums/Sgp4OpsMode';
import { Sgp4, Vector3D } from '../main';
import { Sgp4GravConstants } from '../sgp4/sgp4';
import { EpochUTC } from '../time/EpochUTC';
import { ClassicalElements, FormatTle, TEME } from './index.js';
import { Sgp4OpsMode } from '../enums/Sgp4OpsMode.js';
import { Sgp4, Vector3D } from '../main.js';
import { Sgp4GravConstants } from '../sgp4/sgp4.js';
import { EpochUTC } from '../time/EpochUTC.js';
import {
Degrees,
EciVec3,
Expand All @@ -41,10 +41,10 @@ import {
TleDataFull,
TleLine1,
TleLine2,
} from '../types/types';
import { DEG2RAD, earthGravityParam, RAD2DEG, secondsPerDay, TAU } from '../utils/constants';
import { newtonNu, toPrecision } from '../utils/functions';
import { TleFormatData } from './tle-format-data';
} from '../types/types.js';
import { DEG2RAD, earthGravityParam, RAD2DEG, secondsPerDay, TAU } from '../utils/constants.js';
import { newtonNu, toPrecision } from '../utils/functions.js';
import { TleFormatData } from './tle-format-data.js';

/**
* Tle is a static class with a collection of methods for working with TLEs.
Expand Down
24 changes: 12 additions & 12 deletions src/coordinate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
* SOFTWARE.
*/

export * from './ClassicalElements';
export * from './EquinoctialElements';
export * from './FormatTle';
export * from './Geodetic';
export * from './ITRF';
export * from './J2000';
export * from '../enums/OrbitRegime';
export * from './RelativeState';
export * from './RIC';
export * from './StateVector';
export * from './TEME';
export * from './Tle';
export * from './ClassicalElements.js';
export * from './EquinoctialElements.js';
export * from './FormatTle.js';
export * from './Geodetic.js';
export * from './ITRF.js';
export * from './J2000.js';
export * from '../enums/OrbitRegime.js';
export * from './RelativeState.js';
export * from './RIC.js';
export * from './StateVector.js';
export * from './TEME.js';
export * from './Tle.js';
Loading

0 comments on commit 12cce99

Please sign in to comment.