Skip to content

Commit

Permalink
refactor: remove fs-extra (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperchupuDev authored Oct 16, 2024
1 parent cba291e commit c726221
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 33 deletions.
2 changes: 1 addition & 1 deletion lib/chmod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { chmod, stat } from 'fs-extra';
import { chmod, stat } from 'fs/promises';

export async function plusx(file: string) {
const s = await stat(file);
Expand Down
18 changes: 5 additions & 13 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
/* eslint-disable require-atomic-updates */

import assert from 'assert';
import {
existsSync,
mkdirp,
readFile,
remove,
stat,
readFileSync,
writeFileSync,
copyFileSync,
} from 'fs-extra';
import { existsSync, readFileSync, writeFileSync, copyFileSync } from 'fs';
import { mkdir, readFile, rm, stat } from 'fs/promises';
import minimist from 'minimist';
import { need, system } from '@yao-pkg/pkg-fetch';
import path from 'path';
Expand Down Expand Up @@ -574,7 +566,7 @@ export async function exec(argv2: string[]) {
// ad-hoc sign the base binary temporarily to generate bytecode
// due to the new mandatory signing requirement
const signedBinaryPath = `${f.binaryPath}-signed`;
await remove(signedBinaryPath);
await rm(signedBinaryPath, { recursive: true, force: true });
copyFileSync(f.binaryPath, signedBinaryPath);
try {
signMachOExecutable(signedBinaryPath);
Expand Down Expand Up @@ -665,14 +657,14 @@ export async function exec(argv2: string[]) {
for (const target of targets) {
if (target.output && existsSync(target.output)) {
if ((await stat(target.output)).isFile()) {
await remove(target.output);
await rm(target.output, { recursive: true, force: true });
} else {
throw wasReported('Refusing to overwrite non-file output', [
target.output,
]);
}
} else if (target.output) {
await mkdirp(path.dirname(target.output));
await mkdir(path.dirname(target.output), { recursive: true });
}

await producer({
Expand Down
15 changes: 8 additions & 7 deletions lib/packer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable complexity */

import assert from 'assert';
import fs from 'fs-extra';
import { readFileSync } from 'fs';
import path from 'path';

import {
Expand All @@ -17,16 +17,17 @@ import { log, wasReported } from './log';
import { FileRecord, FileRecords, SymLinks } from './types';

const { version } = JSON.parse(
fs.readFileSync(path.join(__dirname, '../package.json'), 'utf-8'),
readFileSync(path.join(__dirname, '../package.json'), 'utf-8'),
);

const bootstrapText = fs
.readFileSync(require.resolve('../prelude/bootstrap.js'), 'utf8')
.replace('%VERSION%', version);
const bootstrapText = readFileSync(
require.resolve('../prelude/bootstrap.js'),
'utf8',
).replace('%VERSION%', version);

const commonText = fs.readFileSync(require.resolve('./common'), 'utf8');
const commonText = readFileSync(require.resolve('./common'), 'utf8');

const diagnosticText = fs.readFileSync(
const diagnosticText = readFileSync(
require.resolve('../prelude/diagnostic.js'),
'utf8',
);
Expand Down
4 changes: 2 additions & 2 deletions lib/producer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createBrotliCompress, createGzip } from 'zlib';
import Multistream from 'multistream';
import assert from 'assert';
import { execFileSync } from 'child_process';
import fs from 'fs-extra';
import fs from 'fs';
import intoStream from 'into-stream';
import path from 'path';
import streamMeter from 'stream-meter';
Expand Down Expand Up @@ -291,7 +291,7 @@ function nativePrebuildInstall(target: Target, nodeFile: string) {
fs.copyFileSync(nodeFile, nativeFile);

// put the backed up file back
fs.moveSync(`${nodeFile}.bak`, nodeFile, { overwrite: true });
fs.renameSync(`${nodeFile}.bak`, nodeFile);

return nativeFile;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/walker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable require-atomic-updates */

import assert from 'assert';
import fs from 'fs-extra';
import fs from 'fs/promises';
import globby from 'globby';
import path from 'path';
import { builtinModules } from 'module';
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"@babel/parser": "7.23.0",
"@babel/types": "7.23.0",
"@yao-pkg/pkg-fetch": "3.5.13",
"fs-extra": "^9.1.0",
"globby": "^11.1.0",
"into-stream": "^6.0.0",
"minimist": "^1.2.6",
Expand All @@ -41,7 +40,6 @@
"@babel/core": "7.23.0",
"@release-it/conventional-changelog": "7.0.2",
"@types/babel__generator": "7.6.5",
"@types/fs-extra": "9.0.13",
"@types/minimist": "1.2.2",
"@types/multistream": "4.1.0",
"@types/node": "14.18.20",
Expand Down
7 changes: 0 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -504,13 +504,6 @@
dependencies:
"@babel/types" "^7.0.0"

"@types/[email protected]":
version "9.0.13"
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-9.0.13.tgz#7594fbae04fe7f1918ce8b3d213f74ff44ac1f45"
integrity sha512-nEnwB++1u5lVDM2UI4c1+5R+FYaKfaAzS4OococimjVm3nQw3TuzH5UNsocrcTBbhnerblyHj4A49qXbIiZdpA==
dependencies:
"@types/node" "*"

"@types/http-cache-semantics@^4.0.2":
version "4.0.4"
resolved "https://registry.yarnpkg.com/@types/http-cache-semantics/-/http-cache-semantics-4.0.4.tgz#b979ebad3919799c979b17c72621c0bc0a31c6c4"
Expand Down

0 comments on commit c726221

Please sign in to comment.