Closed websharik closed 3 years ago
Fix for me. But its start new problem... noside files can be contain server/client imports - deep check required.
// Remove imports => remove lua 'requires'
if (anti_import_1.isImportNode(node)) {
if (props.side != undefined) return undefined;
}
IS_CLIENT = _G.addBan == nil
if (IS_CLIENT) then
...
else
,,,
end
b. Separated files for client- and server-side c. Something else :)
@Toliak, 1. b :)
@Toliak, 2. Yes I try and it's working. I'm add check to utils - if side not detected then don't remove require.
Fix for me. But its start new problem... noside files can be contain server/client imports - deep check required.
// Remove imports => remove lua 'requires' if (anti_import_1.isImportNode(node)) { if (props.side != undefined) return undefined; }
The issue about creating multiple resources in the same boilerplate should be mentioned here.
So, for multiple resources the utils should generate bundled client.lua
and server.lua
for each resource.
What can I suggest (and, I believe, implement :D) as a solution:
meta.yml
(because we store data in meta, not a markup)
It will look like:
info:
name: My Resource 1
type: script
oop: true
scripts:
info: name: My Resource 2 type: script oop: true
scripts:
bundledScripts:
2. Write compiler wrapper (like you did [here](https://github.com/mtasa-typescript/mtasa-lua-utils/issues/24#issue-962798698))
3. Produce `meta.xml` files, based on `meta.yml` for each resources
Example for the `meta.yml` above:
```xml
<meta>
<info name="My Resource 1" type="script" />
<oop>true</oop>
<script src="something.lua" type="server" />
</meta>
<meta>
<info name="My Resource 2" type="script" />
<oop>true</oop>
<script src="another.lua" type="client" />
<script src="entrypoint.lua" type="server" />
</meta>
In the result we will receive:
@Toliak Its good. But problem is another or im not understand suggest solution... just look code. Original (left) works, after utils (right) not works.
Its becouse modules is table with functions, and when "require" called function from table, it start work.
Utils cut all requires inside modules. Module src.example.separatedFile
never called and
_G.msg = ____exports.msg
never working. So msg
in src.example.test_ts
is undefined
My resolve: if required module not from mtasa
then allow import them (my upper comment). But add recursive check inside this module to check his requires to can warning "Dont mix server/client side".
My suggest: Utils config.
"plugins": [
{
"transform": "mtasa-lua-utils/transformer",
"after": false,
"allowImports": true, //disable remove non `mtasa` imports
"globalExports": false //disable writing exports to _G
}
],
@Toliak Can your release it, pls ?
@websharik Yes, I'm going to release it as v0.2.3
v0.2 is still unstable, because I haven't tested all features yet, so, if you'll find any bugs -- feel free to comment here, or create a new issue
Here We Go Again...
Module SandBox.server
dont know Test
because it import was removed. I was clone your repo and try upgrade to latest TSTL + some paths. All done without that bug. server.ts - main bundeled entry point for server. Test.ts - some external-file self resource class.
How i can disable 'removing require from self resource in bundle mode' now ?
UPD: Solved... add to prepareGlobalImports
(in prepareImports.ts
)
if (isLocalImport(node, context)) {
return context.superTransformStatements(node);
}
I try make bundle with low level TSTL API:
test_ts.ts
separatedFile.ts
result:
src.example.separatedFile
never called andmsg
is stayundefined
Mb add plugins option to disable remove imports ? Or else solution...