Open kenashcraft opened 3 years ago
Hey @kenashcraft I noticed this too! I found that if you create a globals.ts
file to export single instance of thisLayer
, you can use it in any number of additional files:
// globals.ts
import { Layer } from 'expression-globals-typescript';
const thisLayer = new Layer();
export { thisLayer };
// layer.ts
import { thisLayer } from './globals';
function colorDepth(): number {
return thisLayer.colorDepth;
}
export { colorDepth };
// index.ts
import { thisLayer } from './globals';
import { colorDepth } from './layer';
function layerName(): string {
return thisLayer.name;
}
export { layerName, colorDepth };
Output:
// ./dist/script.jsx
{
colorDepth() {
return thisLayer.colorDepth;
},
layerName() {
return thisLayer.name;
},
}
Update: as I was chuggin' along the $1
suffix started up again for some reason, but extending the @rollup/plugin-replace
options in the rollup.config.js
file seemed to do the trick (there's probably a smarter fix):
// rollup.config.js
plugins: [
replace({
preventAssignment: true,
values: {
_npmVersion: pkg.version,
thisComp$1: 'thisComp',
thisLayer$1: 'thisLayer',
},
}),
// ...
]
Hey @kenashcraft I noticed this too! I found that if you create a
globals.ts
file to export single instance ofthisLayer
, you can use it in any number of additional files:// globals.ts import { Layer } from 'expression-globals-typescript'; const thisLayer = new Layer(); export { thisLayer };
// layer.ts import { thisLayer } from './globals'; function colorDepth(): number { return thisLayer.colorDepth; } export { colorDepth };
// index.ts import { thisLayer } from './globals'; import { colorDepth } from './layer'; function layerName(): string { return thisLayer.name; } export { layerName, colorDepth };
Output:
// ./dist/script.jsx { colorDepth() { return thisLayer.colorDepth; }, layerName() { return thisLayer.name; }, }
Update: as I was chuggin' along the
$1
suffix started up again for some reason, but extending the@rollup/plugin-replace
options in therollup.config.js
file seemed to do the trick (there's probably a smarter fix):// rollup.config.js plugins: [ replace({ preventAssignment: true, values: { _npmVersion: pkg.version, thisComp$1: 'thisComp', thisLayer$1: 'thisLayer', }, }), // ... ]
It's work! But still cannot import below code from globals.ts
const ease = thisLayer.ease;
const easeIn = thisLayer.easeIn;
const easeOut = thisLayer.easeOut;
const timeToFrames = thisLayer.timeToFrames;
const time = thisLayer.time;
I'm just getting started with this setup, and it looks amazing! Unfortunately, I quickly ran into a problem when trying to decompose my code into multiple files. I created a new repo using
create-expression-lib
and left everything as it was. Then I added a new file insrc/
for my function. Here is a simplified example:layer.ts
I modified
index.ts
to import this:The generated code includes
thisLayer$1
and After Effects obviously chokes on that.If I import another file that defines
thisLayer
, the generated code will end up withthisLayer
,thisLayer$1
, andthisLayer$2
.The workaround is to keep all of my code in
index.ts
.