Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/js-sdk/src/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ export class TemplateBase

private async toJSON(): Promise<string> {
return JSON.stringify(
this.serialize(await this.calculateFilesHashes()),
this.serialize(this.calculateFilesHashes()),
undefined,
2
)
Expand Down Expand Up @@ -451,7 +451,7 @@ export class TemplateBase
)
)

const instructionsWithHashes = await this.calculateFilesHashes()
const instructionsWithHashes = this.calculateFilesHashes()

// Prepare file uploads
const fileUploads = instructionsWithHashes
Expand Down Expand Up @@ -523,12 +523,12 @@ export class TemplateBase
}

// We might no longer need this as we move the logic server-side
private async calculateFilesHashes(): Promise<Instruction[]> {
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,
Expand Down
12 changes: 6 additions & 6 deletions packages/js-sdk/src/template/utils.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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<string> {
const { globSync } = await dynamicGlob()
): string {
const { globSync } = requireGlob()
const srcPath = path.join(contextPath, src)
const hash = crypto.createHash('sha256')
const content = `COPY ${src} ${dest}`
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 4 additions & 6 deletions packages/js-sdk/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,20 @@ export function timeoutToSeconds(timeout: number): number {
return Math.ceil(timeout / 1000)
}

export async function dynamicGlob(): Promise<typeof import('glob')> {
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<typeof import('tar')> {
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
Expand Down