Housekeeping

This commit is contained in:
SukkaW 2024-09-06 16:43:28 +08:00
parent 32a5276ddb
commit 6ee83f6691
3 changed files with 27 additions and 114 deletions

View File

@ -1,7 +1,6 @@
// @ts-check
import * as path from 'node:path';
import fsp from 'node:fs/promises';
import { readFileByLine } from './lib/fetch-text-by-line';
import { processLine } from './lib/process-line';
import { createRuleset } from './lib/create-file';
@ -11,6 +10,7 @@ import { task } from './trace';
import { SHARED_DESCRIPTION } from './lib/constants';
import { fdir as Fdir } from 'fdir';
import { appendArrayInPlace } from './lib/append-array-in-place';
import { removeFiles } from './lib/misc';
const MAGIC_COMMAND_SKIP = '# $ custom_build_script';
const MAGIC_COMMAND_RM = '# $ custom_no_output';
@ -126,11 +126,11 @@ function transformDomainset(parentSpan: Span, sourcePath: string, relativePath:
const clashFileBasename = relativePath.slice(0, -path.extname(relativePath).length);
if (res === $rm) {
return Promise.all([
return removeFiles([
path.resolve(outputSurgeDir, relativePath),
path.resolve(outputClashDir, `${clashFileBasename}.txt`),
path.resolve(outputSingboxDir, `${clashFileBasename}.json`)
].map(f => fsp.rm(f, { force: true })));
]);
}
const [title, descriptions, lines] = res;
@ -175,11 +175,11 @@ async function transformRuleset(parentSpan: Span, sourcePath: string, relativePa
const clashFileBasename = relativePath.slice(0, -path.extname(relativePath).length);
if (res === $rm) {
return Promise.all([
return removeFiles([
path.resolve(outputSurgeDir, relativePath),
path.resolve(outputClashDir, `${clashFileBasename}.txt`),
path.resolve(outputSingboxDir, `${clashFileBasename}.json`)
].map(f => fsp.rm(f, { force: true })));
]);
}
const [title, descriptions, lines] = res;

View File

@ -29,6 +29,8 @@ export const writeFile: Write = async (destination: string, input, dir = dirname
return fsp.writeFile(destination, input, { encoding: 'utf-8' });
};
export const removeFiles = async (files: string[]) => Promise.all(files.map((file) => fsp.rm(file, { force: true })));
export const domainWildCardToRegex = (domain: string) => {
let result = '^';
for (let i = 0, len = domain.length; i < len; i++) {

129
pnpm-lock.yaml generated
View File

@ -459,10 +459,6 @@ packages:
typescript:
optional: true
'@typescript-eslint/scope-manager@8.3.0':
resolution: {integrity: sha512-mz2X8WcN2nVu5Hodku+IR8GgCOl4C0G/Z1ruaWN4dgec64kDBabuXyPAr+/RgJtumv8EEkqIzf3X2U5DUKB2eg==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
'@typescript-eslint/scope-manager@8.4.0':
resolution: {integrity: sha512-n2jFxLeY0JmKfUqy3P70rs6vdoPjHK8P/w+zJcV3fk0b0BwRXC/zxRTEnAsgYT7MwdQDt/ZEbtdzdVC+hcpF0A==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
@ -476,23 +472,10 @@ packages:
typescript:
optional: true
'@typescript-eslint/types@8.3.0':
resolution: {integrity: sha512-y6sSEeK+facMaAyixM36dQ5NVXTnKWunfD1Ft4xraYqxP0lC0POJmIaL/mw72CUMqjY9qfyVfXafMeaUj0noWw==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
'@typescript-eslint/types@8.4.0':
resolution: {integrity: sha512-T1RB3KQdskh9t3v/qv7niK6P8yvn7ja1mS7QK7XfRVL6wtZ8/mFs/FHf4fKvTA0rKnqnYxl/uHFNbnEt0phgbw==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
'@typescript-eslint/typescript-estree@8.3.0':
resolution: {integrity: sha512-Mq7FTHl0R36EmWlCJWojIC1qn/ZWo2YiWYc1XVtasJ7FIgjo0MVv9rZWXEE7IK2CGrtwe1dVOxWwqXUdNgfRCA==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
peerDependencies:
typescript: '*'
peerDependenciesMeta:
typescript:
optional: true
'@typescript-eslint/typescript-estree@8.4.0':
resolution: {integrity: sha512-kJ2OIP4dQw5gdI4uXsaxUZHRwWAGpREJ9Zq6D5L0BweyOrWsL6Sz0YcAZGWhvKnH7fm1J5YFE1JrQL0c9dd53A==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
@ -502,22 +485,12 @@ packages:
typescript:
optional: true
'@typescript-eslint/utils@8.3.0':
resolution: {integrity: sha512-F77WwqxIi/qGkIGOGXNBLV7nykwfjLsdauRB/DOFPdv6LTF3BHHkBpq81/b5iMPSF055oO2BiivDJV4ChvNtXA==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
peerDependencies:
eslint: ^8.57.0 || ^9.0.0
'@typescript-eslint/utils@8.4.0':
resolution: {integrity: sha512-swULW8n1IKLjRAgciCkTCafyTHHfwVQFt8DovmaF69sKbOxTSFMmIZaSHjqO9i/RV0wIblaawhzvtva8Nmm7lQ==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
peerDependencies:
eslint: ^8.57.0 || ^9.0.0
'@typescript-eslint/visitor-keys@8.3.0':
resolution: {integrity: sha512-RmZwrTbQ9QveF15m/Cl28n0LXD6ea2CjkhH5rQ55ewz3H24w+AMCJHPVYaZ8/0HoG8Z3cLLFFycRXxeO2tz9FA==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
'@typescript-eslint/visitor-keys@8.4.0':
resolution: {integrity: sha512-zTQD6WLNTre1hj5wp09nBIDiOc2U5r/qmzo7wxPn4ZgAjHql09EofqhF9WF+fZHzL5aCyaIpPcT2hyxl73kr9A==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
@ -688,15 +661,6 @@ packages:
supports-color:
optional: true
debug@4.3.5:
resolution: {integrity: sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==}
engines: {node: '>=6.0'}
peerDependencies:
supports-color: '*'
peerDependenciesMeta:
supports-color:
optional: true
debug@4.3.6:
resolution: {integrity: sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==}
engines: {node: '>=6.0'}
@ -1021,10 +985,6 @@ packages:
ieee754@1.2.1:
resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==}
ignore@5.3.1:
resolution: {integrity: sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==}
engines: {node: '>= 4'}
ignore@5.3.2:
resolution: {integrity: sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==}
engines: {node: '>= 4'}
@ -1475,9 +1435,6 @@ packages:
peerDependencies:
typescript: '>=4.2.0'
tslib@2.6.3:
resolution: {integrity: sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==}
tslib@2.7.0:
resolution: {integrity: sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==}
@ -1590,17 +1547,17 @@ snapshots:
'@emnapi/core@1.2.0':
dependencies:
'@emnapi/wasi-threads': 1.0.1
tslib: 2.6.3
tslib: 2.7.0
optional: true
'@emnapi/runtime@1.2.0':
dependencies:
tslib: 2.6.3
tslib: 2.7.0
optional: true
'@emnapi/wasi-threads@1.0.1':
dependencies:
tslib: 2.6.3
tslib: 2.7.0
optional: true
'@eslint-community/eslint-plugin-eslint-comments@4.4.0(eslint@9.9.1)':
@ -1640,7 +1597,7 @@ snapshots:
'@eslint/config-array@0.18.0':
dependencies:
'@eslint/object-schema': 2.1.4
debug: 4.3.5(supports-color@8.1.1)
debug: 4.3.6(supports-color@8.1.1)
minimatch: 3.1.2
transitivePeerDependencies:
- supports-color
@ -1648,10 +1605,10 @@ snapshots:
'@eslint/eslintrc@3.1.0':
dependencies:
ajv: 6.12.6
debug: 4.3.5(supports-color@8.1.1)
debug: 4.3.6(supports-color@8.1.1)
espree: 10.1.0
globals: 14.0.0
ignore: 5.3.1
ignore: 5.3.2
import-fresh: 3.3.0
js-yaml: 4.1.0
minimatch: 3.1.2
@ -1760,7 +1717,7 @@ snapshots:
'@stylistic/eslint-plugin-ts@2.7.2(eslint@9.9.1)(typescript@5.5.4)':
dependencies:
'@types/eslint': 9.6.1
'@typescript-eslint/utils': 8.3.0(eslint@9.9.1)(typescript@5.5.4)
'@typescript-eslint/utils': 8.4.0(eslint@9.9.1)(typescript@5.5.4)
eslint: 9.9.1
eslint-visitor-keys: 4.0.0
espree: 10.1.0
@ -1779,10 +1736,10 @@ snapshots:
'@swc-node/sourcemap-support': 0.5.1
'@swc/core': 1.7.23
colorette: 2.0.20
debug: 4.3.5(supports-color@8.1.1)
debug: 4.3.6(supports-color@8.1.1)
oxc-resolver: 1.10.2
pirates: 4.0.6
tslib: 2.6.3
tslib: 2.7.0
typescript: 5.5.4
transitivePeerDependencies:
- '@swc/types'
@ -1791,7 +1748,7 @@ snapshots:
'@swc-node/sourcemap-support@0.5.1':
dependencies:
source-map-support: 0.5.21
tslib: 2.6.3
tslib: 2.7.0
'@swc/core-darwin-arm64@1.7.23':
optional: true
@ -1847,7 +1804,7 @@ snapshots:
'@tybys/wasm-util@0.9.0':
dependencies:
tslib: 2.6.3
tslib: 2.7.0
optional: true
'@types/async-retry@1.4.8':
@ -1922,18 +1879,13 @@ snapshots:
'@typescript-eslint/types': 8.4.0
'@typescript-eslint/typescript-estree': 8.4.0(typescript@5.5.4)
'@typescript-eslint/visitor-keys': 8.4.0
debug: 4.3.6
debug: 4.3.6(supports-color@8.1.1)
eslint: 9.9.1
optionalDependencies:
typescript: 5.5.4
transitivePeerDependencies:
- supports-color
'@typescript-eslint/scope-manager@8.3.0':
dependencies:
'@typescript-eslint/types': 8.3.0
'@typescript-eslint/visitor-keys': 8.3.0
'@typescript-eslint/scope-manager@8.4.0':
dependencies:
'@typescript-eslint/types': 8.4.0
@ -1943,7 +1895,7 @@ snapshots:
dependencies:
'@typescript-eslint/typescript-estree': 8.4.0(typescript@5.5.4)
'@typescript-eslint/utils': 8.4.0(eslint@9.9.1)(typescript@5.5.4)
debug: 4.3.6
debug: 4.3.6(supports-color@8.1.1)
ts-api-utils: 1.3.0(typescript@5.5.4)
optionalDependencies:
typescript: 5.5.4
@ -1951,30 +1903,13 @@ snapshots:
- eslint
- supports-color
'@typescript-eslint/types@8.3.0': {}
'@typescript-eslint/types@8.4.0': {}
'@typescript-eslint/typescript-estree@8.3.0(typescript@5.5.4)':
dependencies:
'@typescript-eslint/types': 8.3.0
'@typescript-eslint/visitor-keys': 8.3.0
debug: 4.3.6
fast-glob: 3.3.2
is-glob: 4.0.3
minimatch: 9.0.5
semver: 7.6.3
ts-api-utils: 1.3.0(typescript@5.5.4)
optionalDependencies:
typescript: 5.5.4
transitivePeerDependencies:
- supports-color
'@typescript-eslint/typescript-estree@8.4.0(typescript@5.5.4)':
dependencies:
'@typescript-eslint/types': 8.4.0
'@typescript-eslint/visitor-keys': 8.4.0
debug: 4.3.6
debug: 4.3.6(supports-color@8.1.1)
fast-glob: 3.3.2
is-glob: 4.0.3
minimatch: 9.0.5
@ -1985,17 +1920,6 @@ snapshots:
transitivePeerDependencies:
- supports-color
'@typescript-eslint/utils@8.3.0(eslint@9.9.1)(typescript@5.5.4)':
dependencies:
'@eslint-community/eslint-utils': 4.4.0(eslint@9.9.1)
'@typescript-eslint/scope-manager': 8.3.0
'@typescript-eslint/types': 8.3.0
'@typescript-eslint/typescript-estree': 8.3.0(typescript@5.5.4)
eslint: 9.9.1
transitivePeerDependencies:
- supports-color
- typescript
'@typescript-eslint/utils@8.4.0(eslint@9.9.1)(typescript@5.5.4)':
dependencies:
'@eslint-community/eslint-utils': 4.4.0(eslint@9.9.1)
@ -2007,11 +1931,6 @@ snapshots:
- supports-color
- typescript
'@typescript-eslint/visitor-keys@8.3.0':
dependencies:
'@typescript-eslint/types': 8.3.0
eslint-visitor-keys: 3.4.3
'@typescript-eslint/visitor-keys@8.4.0':
dependencies:
'@typescript-eslint/types': 8.4.0
@ -2185,16 +2104,12 @@ snapshots:
dependencies:
ms: 2.1.3
debug@4.3.5(supports-color@8.1.1):
debug@4.3.6(supports-color@8.1.1):
dependencies:
ms: 2.1.2
optionalDependencies:
supports-color: 8.1.1
debug@4.3.6:
dependencies:
ms: 2.1.2
decamelize@4.0.0: {}
decompress-response@6.0.0:
@ -2302,8 +2217,8 @@ snapshots:
eslint-plugin-import-x@4.2.1(eslint@9.9.1)(typescript@5.5.4):
dependencies:
'@typescript-eslint/utils': 8.3.0(eslint@9.9.1)(typescript@5.5.4)
debug: 4.3.6
'@typescript-eslint/utils': 8.4.0(eslint@9.9.1)(typescript@5.5.4)
debug: 4.3.6(supports-color@8.1.1)
doctrine: 3.0.0
eslint: 9.9.1
eslint-import-resolver-node: 0.3.9
@ -2395,7 +2310,7 @@ snapshots:
ajv: 6.12.6
chalk: 4.1.2
cross-spawn: 7.0.3
debug: 4.3.5(supports-color@8.1.1)
debug: 4.3.6(supports-color@8.1.1)
escape-string-regexp: 4.0.0
eslint-scope: 8.0.2
eslint-visitor-keys: 4.0.0
@ -2406,7 +2321,7 @@ snapshots:
file-entry-cache: 8.0.0
find-up: 5.0.0
glob-parent: 6.0.2
ignore: 5.3.1
ignore: 5.3.2
imurmurhash: 0.1.4
is-glob: 4.0.3
is-path-inside: 3.0.3
@ -2557,8 +2472,6 @@ snapshots:
ieee754@1.2.1: {}
ignore@5.3.1: {}
ignore@5.3.2: {}
import-fresh@3.3.0:
@ -2700,7 +2613,7 @@ snapshots:
ansi-colors: 4.1.3
browser-stdout: 1.3.1
chokidar: 3.6.0
debug: 4.3.5(supports-color@8.1.1)
debug: 4.3.6(supports-color@8.1.1)
diff: 5.2.0
escape-string-regexp: 4.0.0
find-up: 5.0.0
@ -3022,8 +2935,6 @@ snapshots:
dependencies:
typescript: 5.5.4
tslib@2.6.3: {}
tslib@2.7.0: {}
tunnel-agent@0.6.0: