diff --git a/packages/js-sdk/src/template/index.ts b/packages/js-sdk/src/template/index.ts index d3c05f2d3f..219300dcb9 100644 --- a/packages/js-sdk/src/template/index.ts +++ b/packages/js-sdk/src/template/index.ts @@ -389,7 +389,7 @@ export class TemplateBase private async toJSON(): Promise { return JSON.stringify( - this.serialize(await this.calculateFilesHashes()), + this.serialize(this.calculateFilesHashes()), undefined, 2 ) @@ -451,7 +451,7 @@ export class TemplateBase ) ) - const instructionsWithHashes = await this.calculateFilesHashes() + const instructionsWithHashes = this.calculateFilesHashes() // Prepare file uploads const fileUploads = instructionsWithHashes @@ -523,12 +523,12 @@ export class TemplateBase } // We might no longer need this as we move the logic server-side - private async calculateFilesHashes(): Promise { + private calculateFilesHashes(): Instruction[] { const steps: Instruction[] = [] for (const instruction of this.instructions) { if (instruction.type === 'COPY') { - instruction.filesHash = await calculateFilesHash( + instruction.filesHash = calculateFilesHash( instruction.args[0], instruction.args[1], this.fileContextPath, diff --git a/packages/js-sdk/src/template/utils.ts b/packages/js-sdk/src/template/utils.ts index 7f35a89b9f..67b9a1de43 100644 --- a/packages/js-sdk/src/template/utils.ts +++ b/packages/js-sdk/src/template/utils.ts @@ -1,7 +1,7 @@ import crypto from 'node:crypto' import fs from 'node:fs' import path from 'node:path' -import { dynamicGlob, dynamicTar } from '../utils' +import { requireGlob, requireTar } from '../utils' export function readDockerignore(contextPath: string): string[] { const dockerignorePath = path.join(contextPath, '.dockerignore') @@ -16,13 +16,13 @@ export function readDockerignore(contextPath: string): string[] { .filter((line) => line && !line.startsWith('#')) } -export async function calculateFilesHash( +export function calculateFilesHash( src: string, dest: string, contextPath: string, ignorePatterns?: string[] -): Promise { - const { globSync } = await dynamicGlob() +): string { + const { globSync } = requireGlob() const srcPath = path.join(contextPath, src) const hash = crypto.createHash('sha256') const content = `COPY ${src} ${dest}` @@ -68,8 +68,8 @@ export function padOctal(mode: number): string { } export async function tarFileStream(fileName: string, fileContextPath: string) { - const { globSync } = await dynamicGlob() - const { create } = await dynamicTar() + const { globSync } = requireGlob() + const { create } = requireTar() const files = globSync(fileName, { cwd: fileContextPath, nodir: false }) return create( diff --git a/packages/js-sdk/src/utils.ts b/packages/js-sdk/src/utils.ts index 85ce5f3f5d..ea4198bf94 100644 --- a/packages/js-sdk/src/utils.ts +++ b/packages/js-sdk/src/utils.ts @@ -67,22 +67,20 @@ export function timeoutToSeconds(timeout: number): number { return Math.ceil(timeout / 1000) } -export async function dynamicGlob(): Promise { +export function requireGlob(): typeof import('glob') { if (runtime === 'browser') { throw new Error('Browser runtime is not supported for glob') } - // @ts-ignore - return await import('glob') + return require('glob') } -export async function dynamicTar(): Promise { +export function requireTar(): typeof import('tar') { if (runtime === 'browser') { throw new Error('Browser runtime is not supported for tar') } - // @ts-ignore - return await import('tar') + return require('tar') } // Source: https://github.com/chalk/ansi-regex/blob/main/index.js