Closed mixecan closed 5 years ago
I have not used realtime modules/scripts, I will look at it today. This branch seems to implement it, you can check out: https://github.com/alexhmelnoy/ts2gamesparks
Thanks! I tried that brach but the build fails...
I'm not sure if it works, because I'm not working on the GameSparks project and can't test it.
The changes you need to make are:
Please tell me any problem you found.
I had the time to have a look into your code but I don't understand the rationale behind you commit (except that it works). Can you explain?
I may have found an alternative solution that makes use of a single tsconfig and builds everything correctly but maybe I'm not completely catching all the steps of your code. I will do a PR so that you can have a look
In my guess, the GameSparks module rules are as follows:
(Create two tsconfig.json to avoid referencing the other's module)
Maybe my guess is wrong, I am looking at your submission. (If you are sure that these points are correct or not, please let me know.)
I just confirmed the point 2, but I can't confirm the point 1 at the moment because I don't know how to test a rtScript.
Regarding the two tsconfigs, I tried the following and it seems to work correctly: /tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": ["es5", "es2015"],
"forceConsistentCasingInFileNames": true,
"rootDir": "./src",
"outDir": "./dist/",
"baseUrl": "./src/",
"paths": {
"*": [
"./modules/*",
],
}
},
"include": [
"src/"
]
}
/src/rtScript/tsconfig.json
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"paths": {
"*": [
"./rtModules/*",
],
}
}
}
Thank you for confirming these points! Your idea of using "extends" is fine, I updated it in the example. In addition, I think you can replace "paths" with "baseUrl".
I have updated the readme, if there is still a problem, please install the latest version of ts2gamesparks, then follow the readme instructions.
Thanks for the update!
I see that you create the main tsconfig.json
under ./src/
but this could be wrong.
In fact if I try to build from the root of the project (I usually have a package script that run different commands along with yours) I get an error due to the missing tsconfig.json
.
/Users/user/project/ts2gs/node_modules/typescript/lib/typescript.js:1464
throw e;
^
Error: Debug Failure.
at Object.assertDefined (/Users/user/project/ts2gs/node_modules/typescript/lib/typescript.js:1469:24)
at /Users/user/project/ts2gs/node_modules/typescript/lib/typescript.js:14663:89
at String.replace (<anonymous>)
at formatStringFromArgs (/Users/user/project/ts2gs/node_modules/typescript/lib/typescript.js:14663:21)
at Object.createCompilerDiagnostic (/Users/user/project/ts2gs/node_modules/typescript/lib/typescript.js:14703:20)
at tryReadFile (/Users/user/project/ts2gs/node_modules/typescript/lib/typescript.js:24446:40)
at Object.readJsonConfigFile (/Users/user/project/ts2gs/node_modules/typescript/lib/typescript.js:24434:32)
at getTsConfig (/Users/user/project/ts2gs/node_modules/ts2gamesparks/lib/ts2gamesparks.js:12:21)
at build (/Users/user/project/ts2gs/node_modules/ts2gamesparks/lib/ts2gamesparks.js:198:20)
at Object.<anonymous> (/Users/user/project/ts2gs/node_modules/ts2gamesparks/lib/ts2gamesparks.js:243:5)
IMO the --init
flag should create the main tsconfig in the root directory
It is recommended to place tsconfig in the src directory, but it is not mandatory. You can try changing the ts2gs
of your package script to cd src && ts2gs
(Example)
In addition, this issue is a bit like the problem you mentioned. He is using an export error outside of modules and rtModules.
Sorry for the delay
The issue was caused by ts2gs not loading the tsconfig and thus having incorrect baseUrl and paths. A --project <tsconfig.json path>
option would be great (I will create an issue) so that cd src
is not required.
Currently your setup works fine for us. I will close the issue and reopen it if something occurs!
@mixecan I found that the realtime module conversion results of ts2gamesparks are inconsistent with the documentation of GameSparks. Can your realtime script work successfully?
ts2gamesparks conversion results:
function foo() {
return "foo";
}
exports.foo = foo;
GameSparks documentation:
module.exports.foo = function() {
return "foo";
}
We don't have any problem with the realtime scripts. Unless the result is something like
exports = function foo() {
return "foo";
}
exports
should be work exactly as module.exports
.
@mixecan I see, thank you.
Do you have any plan to support realtime modules/scripts?