import { path } from '@servicenow/sdk-build-core' import type { DependencyNode, RepackOptions } from '@servicenow/sdk-repack' export async function checkModuleExists( module: string, logger: RepackOptions['logger'], fs: RepackOptions['fs'], workingDir: RepackOptions['workingDir'] ) { const repackService = await RepackService.create(logger, fs, workingDir) return repackService.checkModuleExists(module) } export async function resolveModule( module: string, logger: RepackOptions['logger'], fs: RepackOptions['fs'], workingDir: RepackOptions['workingDir'] ): Promise { const repackService = await RepackService.create(logger, fs, workingDir) return repackService.resolveModule(module) } export const REPACK_OUTPUT_DIR = path.join('.now', '.output') export class RepackService { private constructor( private repack: typeof import('@servicenow/sdk-repack'), private logger: RepackOptions['logger'], private fs: RepackOptions['fs'], private workingDir: RepackOptions['workingDir'] ) {} static async create( logger: RepackOptions['logger'], fs: RepackOptions['fs'], workingDir: RepackOptions['workingDir'] ) { const repack = await import('@servicenow/sdk-repack') return new RepackService(repack, logger, fs, workingDir) } async execute(input: Omit): Promise { return this.repack.build({ ...input, logger: this.logger!, fs: this.fs, workingDir: this.workingDir, outputDir: REPACK_OUTPUT_DIR, }) } async getResolvedDepDetails(dependency: string) { return this.repack.getPkgInfo({ dependencyName: dependency, workingDir: this.workingDir, fs: this.fs, logger: this.logger!, }) } async checkModuleExists(module: string) { return this.repack.checkModuleExists(module, this.fs, this.workingDir, this.logger!) } async resolveModule(module: string): Promise { return this.repack.resolveModule(module, this.fs, this.workingDir, this.logger) } }