Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference reactor-ts as module #1322

Merged
merged 25 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
dddc0bc
Work in progress toward linking reactor-ts as an npm module
lhstrh Aug 8, 2022
a6abfb7
Link to files rather than use npm link
lhstrh Aug 9, 2022
d58685e
work in progress
suyourice Aug 18, 2022
e8d43c4
Work around inability to use declaration files.
petervdonovan Aug 22, 2022
3eee04b
Copy reactor-ts freely.
petervdonovan Aug 23, 2022
e165600
Make build more portable.
petervdonovan Aug 23, 2022
664965e
Try again to run Babel.
petervdonovan Aug 23, 2022
2022f29
Handle ulog type declaration more portably.
petervdonovan Aug 24, 2022
0925573
Fix version due to bad typescript-eslint release.
petervdonovan Aug 24, 2022
03c239b
Fix broken references to declaration files.
petervdonovan Aug 24, 2022
bf5a4a1
Use pnpm instead of npm where possible.
petervdonovan Aug 26, 2022
86b14fa
Update submodule.
petervdonovan Aug 26, 2022
ce663f1
Merge branch 'master' into reactor-ts-npm
petervdonovan Aug 27, 2022
aa7b684
Address unresolved peer dep.
petervdonovan Aug 27, 2022
a02d616
Try again to resolve unresolved peer deps issue.
petervdonovan Aug 27, 2022
920be23
Address failing serialization tests.
petervdonovan Aug 27, 2022
49c2847
Update submodule.
petervdonovan Aug 27, 2022
6a60cb3
Clean up after previous commit.
petervdonovan Aug 27, 2022
1a9419c
Repair references to declaration files.
petervdonovan Aug 28, 2022
bed0944
Update submodule with changes from master.
petervdonovan Aug 28, 2022
c4de4de
Comments only.
petervdonovan Aug 28, 2022
69c8c8f
Update submodule.
petervdonovan Aug 28, 2022
c37fc18
Update submodule; keep TS and typedoc in sync.
petervdonovan Aug 28, 2022
fb838c6
Update submodule.
petervdonovan Aug 28, 2022
a1799aa
Update submodule.
petervdonovan Aug 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ buildNumber.properties
.flattened-pom.xml

### VisualStudioCode ###
.vscode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
Expand Down
23 changes: 11 additions & 12 deletions org.lflang/src/lib/ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@
"name": "LinguaFrancaDefault",
"version": "0.0.1",
"description": "A default Lingua Franca project for the TypeScript target",
"type": "commonjs",
lhstrh marked this conversation as resolved.
Show resolved Hide resolved
"repository": {
"type": "git",
"url": "https://github.com/icyphy/lingua-franca"
},
"license": "BSD-2-Clause",
"dependencies": {
"command-line-args": "^5.1.1",
"command-line-usage": "^6.1.0",
"microtime": "^3.0.0",
"ulog": "^2.0.0-beta.7",
"google-protobuf": "^3.7.4",
"uuid": "^8.3.2"
},
"devDependencies": {
"reactor-ts": "file:./reactor-ts",
"@types/reactor-ts": "file:./reactor-ts",
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.7",
"@babel/node": "^7.8.7",
Expand All @@ -25,18 +20,22 @@
"@babel/plugin-transform-modules-commonjs": "^7.8.3",
"@babel/preset-env": "^7.8.7",
"@babel/preset-typescript": "^7.8.3",
"command-line-usage": "^6.1.0",
"command-line-args": "^5.1.1",
"rimraf": "^3.0.2"
},
"devDependencies": {
"@types/google-protobuf": "^3.7.4",
"@types/node": "^13.9.2",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.8.1",
"@typescript-eslint/eslint-plugin": "5.33.0",
"@typescript-eslint/parser": "^5.8.1",
"eslint": "^8.5.0",
"rimraf": "^3.0.2",
"typescript": "^3.8.3",
"typescript": "~4.8.2",
"ts-protoc-gen": "^0.12.0"
},
"scripts": {
"check-types": "tsc",
"build": "rimraf dist && babel src --out-dir dist --extensions .ts,.js"
"build": "npx rimraf dist && npx babel src --out-dir dist --extensions .ts,.js"
}
}
4 changes: 3 additions & 1 deletion org.lflang/src/lib/ts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"allowJs": true,
"noEmit": true,
"target": "esnext",
"types": ["node", "reactor-ts", "ulog", "microtime", "command-line-args", "command-line-usage"],
"esModuleInterop": true,
"isolatedModules": true,
"lib": ["esnext", "dom"],
Expand All @@ -12,8 +13,9 @@
"strictBindCallApply": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"typeRoots": ["./node_modules/@types/", "./node_modules/reactor-ts/src/core/@types/"]
},
"include": [
"src/**/*",
"src/**/*"
]
}
8 changes: 4 additions & 4 deletions org.lflang/src/org/lflang/generator/ts/TSFileConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ class TSFileConfig(
/**
* Path to TypeScript core source code.
*/
fun tsCoreGenPath(): Path = tsSrcGenPath().resolve("core")
fun reactorTsPath(): Path = srcGenPath.resolve("reactor-ts")

/**
* Path to the generated docker file
*/
fun tsDockerFilePath(tsFileName: String): Path {
return srcGenPath.resolve(tsFileName + ".Dockerfile")
return srcGenPath.resolve("$tsFileName.Dockerfile")
}

/**
* Path to the generated docker compose file
*/
fun tsDockerComposeFilePath(): Path {
return srcGenPath.resolve("docker-compose.yml")
}
}
}
38 changes: 17 additions & 21 deletions org.lflang/src/org/lflang/generator/ts/TSGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class TSGenerator(
) : GeneratorBase(tsFileConfig, errorReporter) {

companion object {
/** Path to the Cpp lib directory (relative to class path) */
/** Path to the TS lib directory (relative to class path) */
const val LIB_PATH = "/lib/ts"

/**
Expand All @@ -91,14 +91,7 @@ class TSGenerator(
*/
val CONFIG_FILES = arrayOf("package.json", "tsconfig.json", "babel.config.js", ".eslintrc.json")

/**
* Files to be copied from the reactor-ts submodule into the generated
* source directory.
*/
val RUNTIME_FILES = arrayOf("action.ts", "bank.ts", "cli.ts", "command-line-args.d.ts",
"command-line-usage.d.ts", "component.ts", "event.ts", "federation.ts", "internal.ts",
"reaction.ts", "reactor.ts", "microtime.d.ts", "multiport.ts", "nanotimer.d.ts", "port.ts",
"state.ts", "strings.ts", "time.ts", "trigger.ts", "types.ts", "ulog.d.ts", "util.ts")
val RT_CONFIG_FILES = arrayOf("package.json", "package-lock.json", "tsconfig.json", ".babelrc")

private val VG =
ExpressionGenerator(::timeInTargetLanguage) { param -> "this.${param.name}.get()" }
Expand Down Expand Up @@ -155,6 +148,7 @@ class TSGenerator(

clean(context)
copyRuntime()
collectDependencies(resource, context, tsFileConfig.reactorTsPath(), true)
copyConfigFiles()

val codeMaps = HashMap<Path, CodeMap>()
Expand All @@ -172,7 +166,7 @@ class TSGenerator(
context.reportProgress(
"Code generation complete. Collecting dependencies...", IntegratedBuilder.GENERATED_PERCENT_PROGRESS
)
if (shouldCollectDependencies(context)) collectDependencies(resource, context)
if (shouldCollectDependencies(context)) collectDependencies(resource, context, tsFileConfig.srcGenPkgPath, false)
if (errorsOccurred()) {
context.unsuccessfulFinish();
return;
Expand Down Expand Up @@ -213,10 +207,15 @@ class TSGenerator(
* Copy the TypeScript runtime so that it is accessible to the generated code.
*/
private fun copyRuntime() {
for (runtimeFile in RUNTIME_FILES) {
FileUtil.copyDirectoryFromClassPath(
"$LIB_PATH/reactor-ts/src/core",
lhstrh marked this conversation as resolved.
Show resolved Hide resolved
tsFileConfig.reactorTsPath().resolve("src").resolve("core"),
true
)
for (configFile in RT_CONFIG_FILES) {
FileUtil.copyFileFromClassPath(
"$LIB_PATH/reactor-ts/src/core/$runtimeFile",
tsFileConfig.tsCoreGenPath().resolve(runtimeFile)
"$LIB_PATH/reactor-ts/$configFile",
tsFileConfig.reactorTsPath().resolve(configFile)
)
}
}
Expand Down Expand Up @@ -356,17 +355,14 @@ class TSGenerator(
* @param resource The Lingua Franca source file at
* which to report any errors
* @param context The context of this build.
* @param path The directory for which to get dependencies.
* @param production Whether to get production dependencies only.
*/
private fun collectDependencies(resource: Resource, context: LFGeneratorContext) {
private fun collectDependencies(resource: Resource, context: LFGeneratorContext, path: Path, production: Boolean) {

Files.createDirectories(fileConfig.srcGenPkgPath) // may throw

val pnpmInstall = commandFactory.createCommand(
"pnpm",
listOf("install"),
fileConfig.srcGenPkgPath,
false // only produce a warning if command is not found
)
val pnpmInstall = commandFactory.createCommand("pnpm", if (production) listOf("install", "--prod") else listOf("install"), path, false)

// Attempt to use pnpm, but fall back on npm if it is not available.
if (pnpmInstall != null) {
Expand All @@ -381,7 +377,7 @@ class TSGenerator(
errorReporter.reportWarning(
"Falling back on npm. To prevent an accumulation of replicated dependencies, " +
"it is highly recommended to install pnpm globally (npm install -g pnpm).")
val npmInstall = commandFactory.createCommand("npm", listOf("install"), fileConfig.srcGenPkgPath)
val npmInstall = commandFactory.createCommand("npm", if (production) listOf("install", "--production") else listOf("install"), path)

if (npmInstall == null) {
errorReporter.reportError(NO_NPM_MESSAGE)
Expand Down
24 changes: 12 additions & 12 deletions org.lflang/src/org/lflang/generator/ts/TSImportPreambleGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ class TSImportPreambleGenerator(
const val DEFAULT_IMPORTS = """
|import commandLineArgs from 'command-line-args'
|import commandLineUsage from 'command-line-usage'
|import {Parameter as __Parameter, Timer as __Timer, Reactor as __Reactor, App as __App} from './core/reactor'
|import {Action as __Action, Startup as __Startup, FederatePortAction as __FederatePortAction} from './core/action'
|import {Bank as __Bank} from './core/bank'
|import {FederatedApp as __FederatedApp} from './core/federation'
|import {InPort as __InPort, OutPort as __OutPort, Port as __Port} from './core/port'
|import {InMultiPort as __InMultiPort, OutMultiPort as __OutMultiPort} from './core/multiport'
|import {Reaction as __Reaction} from './core/reaction'
|import {State as __State} from './core/state'
|import {TimeUnit, TimeValue, Tag as __Tag, Origin as __Origin} from './core/time'
|import {Args as __Args, Variable as __Variable, Triggers as __Triggers, Present, Read, Write, ReadWrite, MultiReadWrite, Sched} from './core/types'
|import {Log} from './core/util'
|import {ProcessedCommandLineArgs as __ProcessedCommandLineArgs, CommandLineOptionDefs as __CommandLineOptionDefs, CommandLineUsageDefs as __CommandLineUsageDefs, CommandLineOptionSpec as __CommandLineOptionSpec, unitBasedTimeValueCLAType as __unitBasedTimeValueCLAType, booleanCLAType as __booleanCLAType} from './core/cli'
|import {Parameter as __Parameter, Timer as __Timer, Reactor as __Reactor, App as __App} from 'reactor-ts'
|import {Action as __Action, Startup as __Startup, FederatePortAction as __FederatePortAction} from 'reactor-ts'
|import {Bank as __Bank} from 'reactor-ts'
|import {FederatedApp as __FederatedApp} from 'reactor-ts'
|import {InPort as __InPort, OutPort as __OutPort, Port as __Port} from 'reactor-ts'
|import {InMultiPort as __InMultiPort, OutMultiPort as __OutMultiPort} from 'reactor-ts'
|import {Reaction as __Reaction} from 'reactor-ts'
|import {State as __State} from 'reactor-ts'
|import {TimeUnit, TimeValue, Tag as __Tag, Origin as __Origin} from 'reactor-ts'
|import {Args as __Args, Variable as __Variable, Triggers as __Triggers, Present, Read, Write, ReadWrite, MultiReadWrite, Sched} from 'reactor-ts'
|import {Log} from 'reactor-ts'
|import {ProcessedCommandLineArgs as __ProcessedCommandLineArgs, CommandLineOptionDefs as __CommandLineOptionDefs, CommandLineUsageDefs as __CommandLineUsageDefs, CommandLineOptionSpec as __CommandLineOptionSpec, unitBasedTimeValueCLAType as __unitBasedTimeValueCLAType, booleanCLAType as __booleanCLAType} from 'reactor-ts'
|"""
}

Expand Down
2 changes: 1 addition & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The simplest way to run the regression tests is to use a Bash script called `run
run-lf-tests C
run-lf-tests Cpp
run-lf-tests Python
run-lf-tests TS
run-lf-tests TypeScript
```

You can also selectively run just some of the tests. For example, to run the system tests for an individual target language, do this:
Expand Down