diff --git a/.github/workflows/manual-deprecate-versions.yml b/.github/workflows/manual-deprecate-versions.yml new file mode 100644 index 0000000..522deef --- /dev/null +++ b/.github/workflows/manual-deprecate-versions.yml @@ -0,0 +1,31 @@ +--- +name: Deprecate versions + +on: + workflow_dispatch: + inputs: + version-expression: + description: version number (semver format) or range to deprecate + required: true + type: string + rationale: + description: explain why this version is deprecated. No message content will un-deprecate the version + type: string + +jobs: + deprecate: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: 18 + registry-url: "https://registry.npmjs.org" + + - name: Change version + run: npm deprecate xml2json-disassembler@$"${{ github.event.inputs.version-expression }}" "${{ github.event.inputs.rationale }}" + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/package.json b/package.json index 81ff474..5d4967c 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ }, "dependencies": { "tslib": "^2.6.2", - "xml-disassembler": "^1.3.10" + "xml-disassembler": "^1.3.11" }, "repository": { "type": "git", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ecae277..5fbd8b5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ dependencies: specifier: ^2.6.2 version: 2.8.1 xml-disassembler: - specifier: ^1.3.10 - version: 1.3.10 + specifier: ^1.3.11 + version: 1.3.11 devDependencies: "@rollup/plugin-terser": @@ -4660,10 +4660,10 @@ packages: signal-exit: 3.0.7 dev: true - /xml-disassembler@1.3.10: + /xml-disassembler@1.3.11: resolution: { - integrity: sha512-NqL1FdKI5c7d7fkB69VDFOMlRspX7u5D7fEpNWgXn9F8PIlyInHWYisBqSsmTk3YUZaJdM54VCMI92d+rFEYvQ==, + integrity: sha512-SK20Co9nxwnQIDh7qlSX9lPsp4Zho+ysMXulsUmDhEAYLe57WHaBfi0DcdgTrB9cWBgjrM8TtipK7FZ81rzCag==, } engines: { node: ">=18", pnpm: ">=8" } dependencies: diff --git a/src/service/deleteReassembledXML.ts b/src/service/deleteReassembledXML.ts index 2a3febe..be1a6f8 100644 --- a/src/service/deleteReassembledXML.ts +++ b/src/service/deleteReassembledXML.ts @@ -1,27 +1,19 @@ "use strict"; -import { readdir, rm } from "node:fs/promises"; +import { stat, readdir, rm } from "node:fs/promises"; import { join } from "node:path/posix"; -import { - getConcurrencyThreshold, - withConcurrencyLimit, -} from "xml-disassembler"; export async function deleteReassembledXML( disassembledPath: string, ): Promise { - const tasks: (() => Promise)[] = []; - const files = await readdir(disassembledPath, { withFileTypes: true }); - const concurrencyLimit = getConcurrencyThreshold(); - + const files = await readdir(disassembledPath); for (const file of files) { - const subFilePath = join(disassembledPath, file.name); - - if (file.isFile() && subFilePath.endsWith(".xml")) { - tasks.push(() => rm(subFilePath)); - } else if (file.isDirectory()) { - tasks.push(() => deleteReassembledXML(subFilePath)); + const filePath = join(disassembledPath, file); + const fileStat = await stat(filePath); + if (fileStat.isFile() && filePath.endsWith(".xml")) { + await rm(filePath); + } else if (fileStat.isDirectory()) { + await deleteReassembledXML(filePath); } } - await withConcurrencyLimit(tasks, concurrencyLimit); } diff --git a/src/service/json2xmlReassembler.ts b/src/service/json2xmlReassembler.ts index 61e6f66..1d116e6 100644 --- a/src/service/json2xmlReassembler.ts +++ b/src/service/json2xmlReassembler.ts @@ -2,10 +2,6 @@ import { stat, readdir } from "node:fs/promises"; import { join } from "node:path/posix"; -import { - getConcurrencyThreshold, - withConcurrencyLimit, -} from "xml-disassembler"; import { logger } from "@src/index"; import { reassembleHandler } from "@src/service/reassembleHandler"; @@ -38,19 +34,15 @@ export class JsonToXmlReassembler { } async processFile(filePath: string): Promise { - const tasks: (() => Promise)[] = []; - const files = await readdir(filePath, { withFileTypes: true }); - const concurrencyLimit = getConcurrencyThreshold(); - + const files = await readdir(filePath); for (const file of files) { - const subFilePath = join(filePath, file.name); - - if (file.isFile() && subFilePath.endsWith(".json")) { - tasks.push(() => transform2XML(subFilePath)); - } else if (file.isDirectory()) { - tasks.push(() => this.processFile(subFilePath)); + const subFilePath = join(filePath, file); + const subFileStat = await stat(subFilePath); + if (subFileStat.isFile() && subFilePath.endsWith(".json")) { + await transform2XML(subFilePath); + } else if (subFileStat.isDirectory()) { + await this.processFile(subFilePath); } } - await withConcurrencyLimit(tasks, concurrencyLimit); } } diff --git a/src/service/transform2JSON.ts b/src/service/transform2JSON.ts index 9ffa322..b7aa4f3 100644 --- a/src/service/transform2JSON.ts +++ b/src/service/transform2JSON.ts @@ -1,33 +1,25 @@ "use strict"; -import { readdir, rm, writeFile } from "node:fs/promises"; +import { readdir, rm, stat, writeFile } from "node:fs/promises"; import { join } from "node:path/posix"; -import { - parseXML, - getConcurrencyThreshold, - withConcurrencyLimit, -} from "xml-disassembler"; +import { parseXML } from "xml-disassembler"; import { logger } from "@src/index"; export async function transform2JSON(xmlPath: string): Promise { - const tasks: (() => Promise)[] = []; - const files = await readdir(xmlPath, { withFileTypes: true }); - const concurrencyLimit = getConcurrencyThreshold(); - const foldersToRemote = []; - - for (const subFile of files) { - const subFilePath = join(xmlPath, subFile.name); - if (subFile.isDirectory()) { - tasks.push(() => transform2JSON(subFilePath)); - } else if (subFile.isFile() && subFilePath.endsWith(".xml")) { - tasks.push(() => writeJSON(subFilePath)); - foldersToRemote.push(subFilePath); + const subFiles = await readdir(xmlPath); + for (const subFile of subFiles) { + const subFilePath = join(xmlPath, subFile); + if ((await stat(subFilePath)).isDirectory()) { + await transform2JSON(subFilePath); + } else if ( + (await stat(subFilePath)).isFile() && + subFilePath.endsWith(".xml") + ) { + await writeJSON(subFilePath); + await rm(subFilePath); } } - await withConcurrencyLimit(tasks, concurrencyLimit); - const deleteTasks = foldersToRemote.map((filePath) => () => rm(filePath)); - await withConcurrencyLimit(deleteTasks, concurrencyLimit); } async function writeJSON(xmlPath: string): Promise { diff --git a/src/service/xml2jsonDisassembler.ts b/src/service/xml2jsonDisassembler.ts index bf75b0d..1446adb 100644 --- a/src/service/xml2jsonDisassembler.ts +++ b/src/service/xml2jsonDisassembler.ts @@ -3,10 +3,6 @@ import { existsSync } from "node:fs"; import { stat, readdir } from "node:fs/promises"; import { resolve, join, basename, dirname, extname } from "node:path/posix"; -import { - getConcurrencyThreshold, - withConcurrencyLimit, -} from "xml-disassembler"; import { logger } from "@src/index"; import { disassembleHandler } from "@src/service/disassembleHandler"; @@ -27,44 +23,36 @@ export class XmlToJsonDisassembler { postPurge = false, ignorePath = ".xmldisassemblerignore", } = xmlAttributes; - const concurrencyLimit = getConcurrencyThreshold(); - const tasks = []; const fileStat = await stat(filePath); if (fileStat.isFile()) { const resolvedPath = resolve(filePath); if (!resolvedPath.endsWith(".xml")) { - logger.error(`The file path is not an XML file: ${resolvedPath}`); + logger.error(`The file path is not an XML file: ${resolvedPath}`); return; } - tasks.push(() => - this.processFile({ - filePath: resolvedPath, - uniqueIdElements, - prePurge, - postPurge, - ignorePath, - }), - ); + await this.processFile({ + filePath: resolvedPath, + uniqueIdElements, + prePurge, + postPurge, + ignorePath, + }); } else if (fileStat.isDirectory()) { const subFiles = await readdir(filePath); for (const subFile of subFiles) { const subFilePath = join(filePath, subFile); if (subFilePath.endsWith(".xml")) { - tasks.push(() => - this.processFile({ - filePath: subFilePath, - uniqueIdElements, - prePurge, - postPurge, - ignorePath, - }), - ); + await this.processFile({ + filePath: subFilePath, + uniqueIdElements, + prePurge, + postPurge, + ignorePath, + }); } } } - - await withConcurrencyLimit(tasks, concurrencyLimit); } async processFile(xmlAttributes: {