ceres-wc3 / ceres-ts-template

A template repository for setting up TypeScript with Ceres
3 stars 1 forks source link

How to use NPM dependencies? #3

Open WriteCoin opened 1 year ago

WriteCoin commented 1 year ago

I have seen that when installing cerrie, compiled lua scripts lying next to ts appear immediately. How is this done and why? Compiled scripts could be stored in a separate folder, but then there is a problem with their assembly with Ceres. There is still a problem with this when I want to use the dependency as a reference: npm link my_package. Even if all scripts are compiled automatically when the package is published. I tried to use another way, by creating a killer configuration:

{
    "compilerOptions": {
        "target": "es6",
        "removeComments": true,
        "lib": ["es6"],
        "strict": false,
        "types": [
            "lua-types/core/coroutine",
            "lua-types/core/global",
            "lua-types/core/math",
            "lua-types/core/metatable",
            "lua-types/core/modules",
            "lua-types/core/string",
            "lua-types/core/table",
            "lua-types/core/os",
            "lua-types/special/5.3",
            "lua-types/5.3",
            "ceres-decl/ceres",
            // "war3-types/core/compat",
            // "war3-types/core/common",
            // "war3-types/core/blizzard",
            // "war3-types/core/commonai",
            // "war3-types/core/polyfill",
            // "war3-types/special/w3ts",
            "./src/ts/war3map",
            "./src/ts/decl"
        ],
        "allowJs": true,
        "alwaysStrict": true,
        "checkJs": false,
        "moduleResolution": "node",
        "outDir": "target/compiled",
        "rootDir": "./",
        "baseUrl": "node_modules",
        "paths": {
            "*": ["./*/src/index", "./*/lib/index", "./*/index", "./*"]
        },
        "declaration": false
    },
    "include": [
        "./src",
        "main.ts",
        "node_modules/cerrie",
        "node_modules/new_package"
    ],
    "tstl": {
        "luaTarget": "5.3",
        "noHeader": true,
        "luaLibImport": "require",
        "noImplicitSelf": true
    }
}

In this case, however, cerrie does not compile. I also can't use another ceres-ts-template as a dependency. I get the following error when building:

 > Received build command
>     Input: map.w3x
>     Retain map script: true
>     Output type: mpq
> Loaded map map.w3x
> Loaded map script from map.w3x
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { depth: 10, inner: Io { path: None, err: Os { code: 3, kind: NotFound, message: "Системе не удается найти указанный путь." } } }', ceres-core/src/compiler.rs:50:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
WriteCoin commented 1 year ago

The error when using another template as a dependency occurs due to the pnpm package manager. https://pnpm.io/ This is a package manager to save disk space. It creates hard links to already installed dependencies. I would like to use it instead of the classic bulky npm, but in conjunction with Ceres I don't see it working yet. The only thing I've tried so far: `pnpm install --shamefully-hoist'.

WriteCoin commented 1 year ago

Let's say the ts source code is compiled into an intermediate folder, for example, dist. There you also need to add the ts scripts themselves, and this should be done not only to search for lua files of the same name, but also to parse the ts files themselves. The so-called object interface preprocessor. For example:

declare class Timer {
    getElapsed(): number
    getRemaining(): number
    getTimeout(): number
    destroy(): this
    pause(): this
    resume(): this
    start(timeout: number, periodic: boolean, handlerFunc: () => void): this
}

Such a code:

const timer = new Timer()
timer.start(1., false, () => {
    print("Hello")
})
timer.destroy()

In this intermediate folder will turn into:

const timer = CreateTimer()
TimerStart(timer, 1., false, () => {
    print("Hello")
})
DestroyTimer(timer)

API syntax similar to the Wurst language.