Skip to content

Commit

Permalink
Merge pull request #356 from algorandfoundation/fix/path_format
Browse files Browse the repository at this point in the history
fix: path format
  • Loading branch information
joe-p authored Jan 20, 2024
2 parents ddb0405 + 968465b commit fe6be84
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/win-smoketest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: TEALScript CI
on:
pull_request:
branches: [ main, dev ]
jobs:
windows-smoketest:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3

- name: Install tsx and dependencies
run: npm i -g tsx && npm i

- name: Compile all
env:
SKIP_ALGOD: 'true'
run: tsx scripts/compile_all.ts
5 changes: 4 additions & 1 deletion scripts/compile_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ async function main() {
cwd: process.cwd(),
project,
srcPath: file,
skipAlgod: process.env.SKIP_ALGOD === 'true',
};

const compilers = Compiler.compileAll(options);
Expand All @@ -45,6 +46,8 @@ async function main() {
compilers.forEach(async (compilerPromise) => {
const compiler = await compilerPromise;

if (process.env.SKIP_ALGOD === 'true') return;

const { name } = compiler;

const approvalPath = path.join(dir, `${name}.approval.teal`);
Expand Down Expand Up @@ -76,4 +79,4 @@ async function main() {
});
}

await main();
main();
18 changes: 14 additions & 4 deletions src/lib/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export type CompilerOptions = {
* This should only need to be provided when used in a browser.
*/
tealscriptTypesDir?: string;
/**
* Skip algod compilation. This results in no source mapping and no algod assebmler error checking.
*/
skipAlgod?: boolean;
};

export type SourceInfo = {
Expand Down Expand Up @@ -677,6 +681,8 @@ export default class Compiler {

project: Project;

skipAlgod: boolean;

/** Verifies ABI types are properly decoded for runtime usage */
private checkDecoding(node: ts.Node, type: TypeInfo) {
if (type.kind === 'base' && type.type === 'bool') {
Expand Down Expand Up @@ -1026,10 +1032,11 @@ export default class Compiler {

private getAliasedTypeNode(type: ts.Type<ts.ts.Type>): ts.TypeNode<ts.ts.TypeNode> | undefined {
const isUserTypeAlias = (d: ts.Node<ts.ts.Node> | undefined) => {
const sourcePath = path.format(path.posix.parse(d?.getSourceFile().getFilePath() ?? ''));
return (
d?.isKind(ts.SyntaxKind.TypeAliasDeclaration) &&
!d.getSourceFile().getFilePath().startsWith(this.typesDir) &&
!d.getSourceFile().getFilePath().startsWith(this.libDir)
!sourcePath.startsWith(this.typesDir) &&
!sourcePath.startsWith(this.libDir)
);
};

Expand Down Expand Up @@ -1840,6 +1847,7 @@ export default class Compiler {
this.srcPath = options.srcPath;
this.disableOverflowChecks = options.disableOverflowChecks || false;
this.disableTypeScript = options.disableTypeScript || false;
this.skipAlgod = options.skipAlgod || false;

this.libDir = options.tealscriptLibDir || __dirname;
this.typesDir = options.tealscriptTypesDir || path.join(__dirname, '..', '..', 'types');
Expand All @@ -1860,7 +1868,7 @@ export default class Compiler {

const compiler = new Compiler({ ...options, className: name });
await compiler.compile();
await compiler.algodCompile();
if (!options.skipAlgod) await compiler.algodCompile();

return compiler;
});
Expand Down Expand Up @@ -2004,6 +2012,7 @@ export default class Compiler {
disableTypeScript: this.disableTypeScript,
project: this.project,
cwd: this.cwd,
skipAlgod: this.skipAlgod,
};

return (
Expand Down Expand Up @@ -2035,7 +2044,7 @@ export default class Compiler {
}
}

if (tealLine.startsWith('PENDING_COMPILE')) {
if (tealLine.startsWith('PENDING_COMPILE') && !compilerOptions.skipAlgod) {
const className = tealLine.split(' ')[1];
const srcPath = this.importRegistry[className]?.getFilePath() || this.srcPath;

Expand Down Expand Up @@ -6144,6 +6153,7 @@ export default class Compiler {
}

async algodCompileProgram(program: 'approval' | 'clear' | 'lsig'): Promise<{ result: string; hash: string }> {
console.trace();
// Replace template variables
const body = this.teal[program]
.map((t) => t.teal)
Expand Down

0 comments on commit fe6be84

Please sign in to comment.