feat: webpack typescript logic to support imports #50
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds support for importing third-party modules in Template Logic code.
See
test/archives/latedeliveryandpenalty-typescript/logic/logic.tsfor 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.runtimekey. Two values are currently supported: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-typescriptand runnpm run buildwhich 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:To a JS archive:
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.
You can use the
TemplateArchiveProcessor.transpileLogicToJavaScriptto transpile and bundle the logic of a TS archive to JS. See theTemplateArchiveProcessor.test.tsfile for details. Note that there is an option to save the output logic and updated package.json to disk.