Skip to content

Commit

Permalink
refactor(cli): remove usage of @ionic/utils-fs (#7762)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Nov 20, 2024
1 parent e922e2b commit 0a0dd1a
Show file tree
Hide file tree
Showing 29 changed files with 68 additions and 31 deletions.
3 changes: 2 additions & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
},
"dependencies": {
"@ionic/cli-framework-output": "^2.2.5",
"@ionic/utils-fs": "^3.1.6",
"@ionic/utils-subprocess": "2.1.11",
"@ionic/utils-terminal": "^2.3.3",
"commander": "^9.3.0",
"debug": "^4.3.4",
"env-paths": "^2.2.0",
"fs-extra": "^11.2.0",
"kleur": "^4.1.4",
"native-run": "^2.0.0",
"open": "^8.4.0",
Expand All @@ -64,6 +64,7 @@
},
"devDependencies": {
"@types/debug": "^4.1.7",
"@types/fs-extra": "^11.0.4",
"@types/jest": "^29.5.0",
"@types/plist": "^3.0.2",
"@types/prompts": "^2.0.14",
Expand Down
2 changes: 1 addition & 1 deletion cli/src/android/add.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pathExists, writeFile } from '@ionic/utils-fs';
import { pathExists, writeFile } from 'fs-extra';
import { homedir } from 'os';
import { join } from 'path';

Expand Down
2 changes: 1 addition & 1 deletion cli/src/android/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { copy, remove, mkdirp, readFile, pathExists, writeFile } from '@ionic/utils-fs';
import { copy, remove, mkdirp, readFile, pathExists, writeFile } from 'fs-extra';
import { join, resolve } from 'path';

import { checkCapacitorPlatform } from '../common';
Expand Down
3 changes: 2 additions & 1 deletion cli/src/android/doctor.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { pathExists, readdirp, readFile } from '@ionic/utils-fs';
import { pathExists, readFile } from 'fs-extra';
import { join, extname, parse } from 'path';

import c from '../colors';
import { check } from '../common';
import type { Config } from '../definitions';
import { fatal, isFatal } from '../errors';
import { logSuccess } from '../log';
import { readdirp } from '../util/fs';
import { readXML } from '../util/xml';

export async function doctorAndroid(config: Config): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/android/open.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { pathExists } from '@ionic/utils-fs';
import Debug from 'debug';
import { pathExists } from 'fs-extra';
import open from 'open';

import c from '../colors';
Expand Down
4 changes: 2 additions & 2 deletions cli/src/android/update.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { copy, remove, pathExists, readdirp, readFile, writeFile, writeJSON } from '@ionic/utils-fs';
import Debug from 'debug';
import { copy, remove, pathExists, readFile, writeFile, writeJSON } from 'fs-extra';
import { dirname, extname, join, relative, resolve } from 'path';

import c from '../colors';
Expand All @@ -20,7 +20,7 @@ import {
import type { Plugin } from '../plugin';
import { copy as copyTask } from '../tasks/copy';
import { patchOldCapacitorPlugins } from '../tasks/migrate';
import { convertToUnixPath } from '../util/fs';
import { readdirp, convertToUnixPath } from '../util/fs';
import { resolveNode } from '../util/node';
import { extractTemplate } from '../util/template';

Expand Down
2 changes: 1 addition & 1 deletion cli/src/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readJSON, pathExists } from '@ionic/utils-fs';
import { prettyPath } from '@ionic/utils-terminal';
import { readJSON, pathExists } from 'fs-extra';
import { dirname, join } from 'path';

import c from './colors';
Expand Down
2 changes: 1 addition & 1 deletion cli/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { pathExists, readFile, readJSON, writeFile, writeJSON } from '@ionic/utils-fs';
import Debug from 'debug';
import { pathExists, readFile, readJSON, writeFile, writeJSON } from 'fs-extra';
import { dirname, extname, join, relative, resolve } from 'path';

import c from './colors';
Expand Down
2 changes: 1 addition & 1 deletion cli/src/cordova.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { copy, ensureDir, mkdirp, pathExists, readFile, remove, writeFile } from '@ionic/utils-fs';
import { copy, ensureDir, mkdirp, pathExists, readFile, remove, writeFile } from 'fs-extra';
import { basename, extname, join, resolve } from 'path';
import plist from 'plist';
import type { PlistObject } from 'plist';
Expand Down
2 changes: 1 addition & 1 deletion cli/src/ios/build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writeFileSync, unlinkSync } from '@ionic/utils-fs';
import { writeFileSync, unlinkSync } from 'fs-extra';
import { basename, join } from 'path';
import rimraf from 'rimraf';

Expand Down
2 changes: 1 addition & 1 deletion cli/src/ios/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFile, writeFile } from '@ionic/utils-fs';
import { execSync } from 'child_process';
import { readFile, writeFile } from 'fs-extra';
import { resolve } from 'path';

import c from '../colors';
Expand Down
2 changes: 1 addition & 1 deletion cli/src/ios/update.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { copy, remove, pathExists, readFile, realpath, writeFile } from '@ionic/utils-fs';
import { copy, remove, pathExists, readFile, realpath, writeFile } from 'fs-extra';
import { basename, dirname, join, relative } from 'path';

import c from '../colors';
Expand Down
2 changes: 1 addition & 1 deletion cli/src/ipc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { open, mkdirp } from '@ionic/utils-fs';
import { fork } from '@ionic/utils-subprocess';
import Debug from 'debug';
import { open, mkdirp } from 'fs-extra';
import { request } from 'https';
import { resolve } from 'path';

Expand Down
2 changes: 1 addition & 1 deletion cli/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readJSON } from '@ionic/utils-fs';
import { readJSON } from 'fs-extra';
import { dirname, join } from 'path';

import c from './colors';
Expand Down
2 changes: 1 addition & 1 deletion cli/src/sysconfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readJSON, writeJSON, mkdirp } from '@ionic/utils-fs';
import Debug from 'debug';
import { readJSON, writeJSON, mkdirp } from 'fs-extra';
import { dirname, resolve } from 'path';

import { ENV_PATHS } from './util/cli';
Expand Down
2 changes: 1 addition & 1 deletion cli/src/tasks/add.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { pathExists } from '@ionic/utils-fs';
import { prettyPath } from '@ionic/utils-terminal';
import { pathExists } from 'fs-extra';

import { addAndroid, createLocalProperties } from '../android/add';
import { editProjectSettingsAndroid, checkAndroidPackage } from '../android/common';
Expand Down
2 changes: 1 addition & 1 deletion cli/src/tasks/copy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { copy as fsCopy, pathExists, remove, writeJSON } from '@ionic/utils-fs';
import { copy as fsCopy, pathExists, remove, writeJSON } from 'fs-extra';
import { basename, join, relative, resolve } from 'path';

import c from '../colors';
Expand Down
2 changes: 1 addition & 1 deletion cli/src/tasks/doctor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readJSON } from '@ionic/utils-fs';
import { readJSON } from 'fs-extra';

import { doctorAndroid } from '../android/doctor';
import c from '../colors';
Expand Down
2 changes: 1 addition & 1 deletion cli/src/tasks/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writeFileSync, readFileSync, existsSync } from '@ionic/utils-fs';
import { writeFileSync, readFileSync, existsSync } from 'fs-extra';
import { join } from 'path';
import rimraf from 'rimraf';
import { coerce, gt, gte, lt } from 'semver';
Expand Down
2 changes: 1 addition & 1 deletion cli/src/tasks/sourcemaps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readdirSync, existsSync, readFileSync, writeFileSync, unlinkSync, lstatSync } from '@ionic/utils-fs';
import { readdirSync, existsSync, readFileSync, writeFileSync, unlinkSync, lstatSync } from 'fs-extra';
import { join, extname } from 'path';

import type { Config } from '../definitions';
Expand Down
35 changes: 34 additions & 1 deletion cli/src/util/fs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { existsSync, lstatSync, readdirSync, rmdirSync, unlinkSync } from '@ionic/utils-fs';
import { statSync, type Stats } from 'fs';
import { readdir } from 'fs/promises';
import { existsSync, lstatSync, readdirSync, rmdirSync, unlinkSync } from 'fs-extra';
import { join } from 'path';

export const convertToUnixPath = (path: string): string => {
Expand All @@ -18,3 +20,34 @@ export const deleteFolderRecursive = (directoryPath: any): void => {
rmdirSync(directoryPath);
}
};

export interface ReaddirPOptions {
/**
* Filter out items from the walk process from the final result.
*
* @return `true` to keep, otherwise the item is filtered out
*/
readonly filter: (item: WalkerItem) => boolean;
}

export interface WalkerItem {
path: string;
stats: Stats;
}

export async function readdirp(dir: string, { filter }: ReaddirPOptions): Promise<string[]> {
const dirContent = await readdir(dir, { recursive: true });
const dirContentWalker: WalkerItem[] = [];
const filteredContent: string[] = [];
dirContent.forEach((element) => {
const path = join(dir, element);
const stats = statSync(path);
dirContentWalker.push({ path, stats });
});
dirContentWalker.forEach((element) => {
if (filter(element)) {
filteredContent.push(element.path);
}
});
return filteredContent;
}
6 changes: 4 additions & 2 deletions cli/src/util/iosplugin.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type { ReaddirPOptions } from '@ionic/utils-fs';
import { readFileSync, readdirp, readJSONSync, writeJSONSync } from '@ionic/utils-fs';
import { readFileSync, readJSONSync, writeJSONSync } from 'fs-extra';
import { resolve } from 'path';

import { getCordovaPlugins } from '../cordova';
import type { Config } from '../definitions';
import type { Plugin } from '../plugin';
import { getPluginType, PluginType } from '../plugin';

import type { ReaddirPOptions } from './fs';
import { readdirp } from './fs';

export async function getPluginFiles(plugins: Plugin[]): Promise<string[]> {
let filenameList: string[] = [];

Expand Down
2 changes: 1 addition & 1 deletion cli/src/util/livereload.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readJSONSync, writeJSONSync } from '@ionic/utils-fs';
import { readJSONSync, writeJSONSync } from 'fs-extra';
import { networkInterfaces } from 'os';
import { join } from 'path';

Expand Down
2 changes: 1 addition & 1 deletion cli/src/util/node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFileSync } from '@ionic/utils-fs';
import { existsSync } from 'fs';
import { readFileSync } from 'fs-extra';
import { resolve } from 'path';
import type typescript from 'typescript';

Expand Down
2 changes: 1 addition & 1 deletion cli/src/util/spm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync, readFileSync, writeFileSync } from '@ionic/utils-fs';
import { existsSync, readFileSync, writeFileSync } from 'fs-extra';
import { join, relative, resolve } from 'path';

import type { Config } from '../definitions';
Expand Down
2 changes: 1 addition & 1 deletion cli/src/util/template.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mkdirp } from '@ionic/utils-fs';
import { mkdirp } from 'fs-extra';
import tar from 'tar';

export async function extractTemplate(src: string, dir: string): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/util/xml.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFile } from '@ionic/utils-fs';
import { readFile } from 'fs-extra';
import xml2js from 'xml2js';

export async function readXML(path: string): Promise<any> {
Expand Down
2 changes: 1 addition & 1 deletion cli/test/init.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mkdir } from '@ionic/utils-fs';
import { mkdir } from 'fs-extra';
import { join } from 'path';

import { APP_ID, APP_NAME, run, mktmp, MappedFS } from './util';
Expand Down
2 changes: 1 addition & 1 deletion cli/test/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mkdir, mkdirp, readFile, pathExists, writeFile } from '@ionic/utils-fs';
import { exec } from 'child_process';
import { mkdir, mkdirp, readFile, pathExists, writeFile } from 'fs-extra';
import { join, resolve } from 'path';
import tmp from 'tmp';
import type { DirCallback } from 'tmp';
Expand Down

0 comments on commit 0a0dd1a

Please sign in to comment.