Skip to content

Commit

Permalink
Ignore .gitkeep, remove deprecated url.resolve(), update dependencies (
Browse files Browse the repository at this point in the history
resolves #25).
  • Loading branch information
dscalzi committed Apr 6, 2021
1 parent 3f90a22 commit 362bbc1
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 110 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
14
246 changes: 166 additions & 80 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
},
"homepage": "https://github.com/dscalzi/Nebula#readme",
"devDependencies": {
"@types/fs-extra": "^9.0.8",
"@types/luxon": "^1.26.2",
"@types/minimatch": "^3.0.3",
"@types/node": "^14.14.35",
"@types/fs-extra": "^9.0.10",
"@types/luxon": "^1.26.3",
"@types/minimatch": "^3.0.4",
"@types/node": "^14.14.37",
"@types/triple-beam": "^1.3.2",
"@types/yargs": "^16.0.0",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"eslint": "^7.22.0",
"@types/yargs": "^16.0.1",
"@typescript-eslint/eslint-plugin": "^4.21.0",
"@typescript-eslint/parser": "^4.21.0",
"eslint": "^7.23.0",
"rimraf": "^3.0.2",
"typescript": "^4.2.3"
},
Expand All @@ -46,10 +46,10 @@
"helios-distribution-types": "^1.0.0-rc.1",
"luxon": "^1.26.0",
"minimatch": "^3.0.4",
"node-stream-zip": "^1.13.2",
"node-stream-zip": "^1.13.3",
"toml": "^3.0.0",
"triple-beam": "^1.3.0",
"ts-json-schema-generator": "^0.89.0",
"ts-json-schema-generator": "^0.89.2",
"winston": "^3.3.3",
"yargs": "^16.2.0"
}
Expand Down
10 changes: 5 additions & 5 deletions src/structure/repo/BaseMavenRepo.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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> {
Expand All @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/structure/repo/VersionRepo.struct.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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()
}

}
4 changes: 2 additions & 2 deletions src/structure/spec_model/Server.struct.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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()
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/structure/spec_model/module/File.struct.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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, '/')
Expand Down
4 changes: 2 additions & 2 deletions src/structure/spec_model/module/ForgeMod.struct.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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> {
Expand Down
4 changes: 2 additions & 2 deletions src/structure/spec_model/module/Library.struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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> {
Expand Down
4 changes: 2 additions & 2 deletions src/structure/spec_model/module/LiteMod.struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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> {
Expand Down
9 changes: 7 additions & 2 deletions src/structure/spec_model/module/Module.struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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})
}
}
}
}
Expand Down

0 comments on commit 362bbc1

Please sign in to comment.