Modules

Module structure usually looks as follows:

<project>
├── src/
│   ├── equations/
│   │   ├── __mod__.es
│   │   └── RungeKutta.es
│   ├── sat/
│   │   ├── __mod__.es
│   │   └── FineSAT.es
│   └── __mod__.es
└── zonegfx.toml

Given the project is a package identified as org.generalrelativity.foam and the source path is the default (src/), this results in three modules:

  • org.generalrelativity.foam - This would be src/__mod__.es
  • org.generalrelativity.foam.equations
  • org.generalrelativity.foam.sat

And two item-like modules:

  • org.generalrelativity.foam.equations::RungeKutta
  • org.generalrelativity.foam.sat::FineSAT

Further explanation:

  • The __mod__.es file is the entry point of a module.
  • The RungeKutta.es and FineSAT.es files are item-like modules.

A module source looks as follows:

// src/sat/__mod__.es
export * from "./FineSAT";

// src/sat/FineSAT.es
export class FineSAT {
    //
}

Imports

Here are some snippets on how import declarations look for importing items from a package:

// <source-path>/equations/__mod__.es
import * as equations from "org.generalrelativity.foam.equations";

// <source-path>/sat/__mod__.es
import { FineSAT } from "org.generalrelativity.foam.sat";

Internal imports

A package may import an item of itself in different ways. The most basic is using relative imports:

import { A } from "./A";
import { B } from "../B";

However, for convenience or for avoiding the ../../.. hell, you can use the actual package ID, and, if needing to resolve to an item-like module, use a trailing :: followed by the item name.

import { Account } from "com.ea.n4s.account::Account";

For example, this could be equivalent to importing from src/account/Account.es.