Ignore .gitkeep, remove deprecated url.resolve(), update dependencies (resolves #25).

This commit is contained in:
Daniel Scalzi
2021-04-06 17:34:06 -04:00
parent 3f90a22972
commit 362bbc1d83
11 changed files with 204 additions and 110 deletions

View File

@@ -1,7 +1,7 @@
import got from 'got'
import { createWriteStream, mkdirs, pathExists } from 'fs-extra'
import { dirname, join, resolve } from 'path'
import { resolve as resolveURL } from 'url'
import { URL } from 'url'
import { MavenUtil } from '../../util/maven'
import { BaseFileStructure } from '../BaseFileStructure'
import { LoggerUtil } from '../../util/LoggerUtil'
@@ -32,8 +32,8 @@ export abstract class BaseMavenRepo extends BaseFileStructure {
public getArtifactUrlByComponents(
baseURL: string, group: string, artifact: string, version: string, classifier?: string, extension = 'jar'
): string {
return resolveURL(baseURL, join(this.relativeRoot,
MavenUtil.mavenComponentsToString(group, artifact, version, classifier, extension)))
return new URL(join(this.relativeRoot,
MavenUtil.mavenComponentsToString(group, artifact, version, classifier, extension)), baseURL).toString()
}
public async artifactExists(path: string): Promise<boolean> {
@@ -52,7 +52,7 @@ export abstract class BaseMavenRepo extends BaseFileStructure {
}
private async downloadArtifactBase(url: string, relative: string): Promise<void> {
const resolvedURL = resolveURL(url, relative).toString()
const resolvedURL = new URL(relative, url).toString()
return this.downloadArtifactDirect(resolvedURL, relative)
}
@@ -85,7 +85,7 @@ export abstract class BaseMavenRepo extends BaseFileStructure {
}
private async headArtifactBase(url: string, relative: string): Promise<boolean> {
const resolvedURL = resolveURL(url, relative).toString()
const resolvedURL = new URL(relative, url).toString()
try {
const response = await got.head({
url: resolvedURL

View File

@@ -1,5 +1,5 @@
import { join } from 'path'
import { resolve as resolveURL } from 'url'
import { URL } from 'url'
import { BaseFileStructure } from '../BaseFileStructure'
import { MinecraftVersion } from '../../util/MinecraftVersion'
@@ -27,7 +27,7 @@ export class VersionRepoStructure extends BaseFileStructure {
public getVersionManifestURL(url: string, minecraftVersion: MinecraftVersion, forgeVersion: string): string {
const fileName = this.getFileName(minecraftVersion, forgeVersion)
return resolveURL(url, join(this.relativeRoot, fileName, `${fileName}.json`))
return new URL(join(this.relativeRoot, fileName, `${fileName}.json`), url).toString()
}
}

View File

@@ -1,7 +1,7 @@
import { lstat, mkdirs, pathExists, readdir, readFile, writeFile } from 'fs-extra'
import { Server, Module } from 'helios-distribution-types'
import { dirname, join, resolve as resolvePath } from 'path'
import { resolve as resolveUrl } from 'url'
import { URL } from 'url'
import { VersionSegmentedRegistry } from '../../util/VersionSegmentedRegistry'
import { ServerMeta, getDefaultServerMeta, ServerMetaOptions, UntrackedFilesOption } from '../../model/nebula/servermeta'
import { BaseModelStructure } from './BaseModel.struct'
@@ -114,7 +114,7 @@ export class ServerStructure extends BaseModelStructure<Server> {
for (const subFile of subFiles) {
const caseInsensitive = subFile.toLowerCase()
if (caseInsensitive.endsWith('.jpg') || caseInsensitive.endsWith('.png')) {
iconUrl = resolveUrl(this.baseUrl, join(relativeServerRoot, subFile))
iconUrl = new URL(join(relativeServerRoot, subFile), this.baseUrl).toString()
}
}

View File

@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { Stats } from 'fs'
import { Type, Module } from 'helios-distribution-types'
import { resolve as resolveURL } from 'url'
import { URL } from 'url'
import { ModuleStructure } from './Module.struct'
import { readdir, stat } from 'fs-extra'
import { join, resolve, sep } from 'path'
@@ -41,7 +41,9 @@ export class MiscFileStructure extends ModuleStructure {
if (stats.isDirectory()) {
acc = acc.concat(await this.recursiveModuleScan(filePath))
} else {
acc.push(await this.parseModule(file, filePath, stats))
if(!this.FILE_NAME_BLACKLIST.includes(file)) {
acc.push(await this.parseModule(file, filePath, stats))
}
}
}
return acc
@@ -54,7 +56,7 @@ export class MiscFileStructure extends ModuleStructure {
return name
}
protected async getModuleUrl(name: string, path: string, stats: Stats): Promise<string> {
return resolveURL(this.baseUrl, join(this.relativeRoot, ...path.substr(this.containerDirectory.length+1).split(sep)))
return new URL(join(this.relativeRoot, ...path.substr(this.containerDirectory.length+1).split(sep)), this.baseUrl).toString()
}
protected async getModulePath(name: string, path: string, stats: Stats): Promise<string | null> {
return path.substr(this.containerDirectory.length+1).replace(/\\/g, '/')

View File

@@ -1,7 +1,7 @@
import { Stats } from 'fs-extra'
import { Type, Module } from 'helios-distribution-types'
import { join } from 'path'
import { resolve } from 'url'
import { URL } from 'url'
import { VersionSegmented } from '../../../util/VersionSegmented'
import { MinecraftVersion } from '../../../util/MinecraftVersion'
import { ToggleableModuleStructure } from './ToggleableModule.struct'
@@ -36,7 +36,7 @@ export abstract class BaseForgeModStructure extends ToggleableModuleStructure im
// eslint-disable-next-line @typescript-eslint/no-unused-vars
protected async getModuleUrl(name: string, path: string, stats: Stats): Promise<string> {
return resolve(this.baseUrl, join(this.relativeRoot, this.getActiveNamespace(), name))
return new URL(join(this.relativeRoot, this.getActiveNamespace(), name), this.baseUrl).toString()
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
protected async getModulePath(name: string, path: string, stats: Stats): Promise<string | null> {

View File

@@ -2,7 +2,7 @@ import { ModuleStructure } from './Module.struct'
import { Type, TypeMetadata } from 'helios-distribution-types'
import { Stats } from 'fs-extra'
import { join } from 'path'
import { resolve } from 'url'
import { URL } from 'url'
import { MinecraftVersion } from '../../../util/MinecraftVersion'
import { UntrackedFilesOption } from '../../../model/nebula/servermeta'
@@ -36,7 +36,7 @@ export class LibraryStructure extends ModuleStructure {
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
protected async getModuleUrl(name: string, path: string, stats: Stats): Promise<string> {
return resolve(this.baseUrl, join(this.relativeRoot, name))
return new URL(join(this.relativeRoot, name), this.baseUrl).toString()
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
protected async getModulePath(name: string, path: string, stats: Stats): Promise<string | null> {

View File

@@ -2,7 +2,7 @@ import StreamZip from 'node-stream-zip'
import { Stats } from 'fs-extra'
import { Type } from 'helios-distribution-types'
import { join } from 'path'
import { resolve } from 'url'
import { URL } from 'url'
import { capitalize } from '../../../util/stringutils'
import { LiteMod } from '../../../model/liteloader/litemod'
import { ToggleableModuleStructure } from './ToggleableModule.struct'
@@ -39,7 +39,7 @@ export class LiteModStructure extends ToggleableModuleStructure {
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
protected async getModuleUrl(name: string, path: string, stats: Stats): Promise<string> {
return resolve(this.baseUrl, join(this.relativeRoot, this.getActiveNamespace(), name))
return new URL(join(this.relativeRoot, this.getActiveNamespace(), name), this.baseUrl).toString()
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
protected async getModulePath(name: string, path: string, stats: Stats): Promise<string | null> {

View File

@@ -25,6 +25,9 @@ export abstract class ModuleStructure extends BaseModelStructure<Module> {
private readonly crudeRegex = /(.+?)-(.+).[jJ][aA][rR]/
protected readonly DEFAULT_VERSION = '0.0.0'
protected readonly FILE_NAME_BLACKLIST = [
'.gitkeep'
]
protected untrackedFilePatterns: string[] // List of glob patterns.
protected claritasResult!: ClaritasResult
@@ -130,8 +133,10 @@ export abstract class ModuleStructure extends BaseModelStructure<Module> {
const filePath = resolve(scanDirectory, file)
const stats = await lstat(filePath)
if (stats.isFile()) {
if(this.filter == null || this.filter(file, filePath, stats)) {
moduleCandidates.push({file, filePath, stats})
if(!this.FILE_NAME_BLACKLIST.includes(file)) {
if(this.filter == null || this.filter(file, filePath, stats)) {
moduleCandidates.push({file, filePath, stats})
}
}
}
}