Skip to content

Conversation

@dselman
Copy link
Contributor

@dselman dselman commented Dec 17, 2025

Adds support for importing third-party modules in Template Logic code.

See test/archives/latedeliveryandpenalty-typescript/logic/logic.ts for an updated template logic archive that uses Dayjs and Decimal.

This PR refines the notion of the runtime that is required for an AP template archive. The runtime for the archive is specified in the package.json for the archive, under the accordproject.runtime key. Two values are currently supported:

  1. typescript : this is an uncompiled, source archive (TS)
  2. es6 : this is a compiled and bundled archive, ready for execution in any suitable JS environment (JS)

Static / Offline Compilation

Compilation of a TS archive to bundled JS archive (the logic is bundled into an ESM module) is best done offline and within your IDE, so you benefit from full type-checking and editor support.

For example, cd into test/archives/latedeliveryandpenalty-typescript and run npm run build which will compile the TypeScript logic for the template and create a bundled logic.js file inside the template logic directory using Webpack and tic (the Typescript compiler). You can then change the package.json from a TS archive:

    "accordproject": {
        "runtime": "typescript",
    },

To a JS archive:

    "accordproject": {
        "runtime": "es6",
    },

Just-In-Time Compilation

There is also experimental support for JIT compiling TS template archives to executable JS archives. If you attempt to trigger/init a TS archive it will be JIT compiled to a JS archive before execution.

WARNING: this currently only works from Node.js and inside a suitable project host (node_modules must contain Dayjs, Decimal and any other third-party dependencies). Compiler output is NOT cached so execution will be very slow compared to using a JS archive. JIT compilation is implemented using Typescript to JavaScript transpilation, so type-checking is not performed by the TypeScript compiler.

You can use the TemplateArchiveProcessor.transpileLogicToJavaScript to transpile and bundle the logic of a TS archive to JS. See the TemplateArchiveProcessor.test.ts file for details. Note that there is an option to save the output logic and updated package.json to disk.

Signed-off-by: dselman <danscode@selman.org>
Signed-off-by: dselman <danscode@selman.org>
@dselman dselman self-assigned this Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants