From 57335171c106219f99c5cadfeb13c8695479dc97 Mon Sep 17 00:00:00 2001 From: Andre-John Mas Date: Mon, 17 Oct 2022 21:00:16 -0400 Subject: [PATCH] remove dependency on fs-extra and now target >= 10.12 --- README.md | 7 +++++++ package-lock.json | 31 +------------------------------ package.json | 3 +-- src/index.ts | 18 +++++++----------- test/index.ts | 2 +- tsconfig.json | 5 ++--- 6 files changed, 19 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 1b2e33e..b5d4ce4 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,13 @@ export GOOGLE_PRIVATE_KEY="xxxxxx" ./node_modules/.bin/sync-gdrive "filefolderid" "dest_folder" ``` +### Targeted environments + +This project will not work in the browser, due to dependencies on the +file system. + +Targeted node.js versions are 10.12+ + ## Contributions & Feedback Contributions and feedback is welcome. Please open diff --git a/package-lock.json b/package-lock.json index 6565555..006e429 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "sync-gdrive", - "version": "0.9.5", + "version": "1.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1098,16 +1098,6 @@ "integrity": "sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==", "dev": true }, - "fs-extra": { - "version": "10.1.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", - "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", - "requires": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - } - }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -1288,11 +1278,6 @@ "uuid": "^9.0.0" } }, - "graceful-fs": { - "version": "4.2.10", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz", - "integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==" - }, "grapheme-splitter": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/grapheme-splitter/-/grapheme-splitter-1.0.4.tgz", @@ -1623,15 +1608,6 @@ "minimist": "^1.2.0" } }, - "jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "requires": { - "graceful-fs": "^4.1.6", - "universalify": "^2.0.0" - } - }, "jwa": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/jwa/-/jwa-2.0.0.tgz", @@ -2564,11 +2540,6 @@ "which-boxed-primitive": "^1.0.2" } }, - "universalify": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", - "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==" - }, "uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", diff --git a/package.json b/package.json index e13adf9..40ada1f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "sync-gdrive": "dist/cli.js" }, "engines": { - "node": ">=10.0.0" + "node": ">=10.12.0" }, "scripts": { "sync-gdrive": "ts-node src/cli.ts", @@ -26,7 +26,6 @@ "author": "Andre John Mas", "license": "MIT", "dependencies": { - "fs-extra": "^10.1.0", "googleapis": "^108.0.0", "mime": "^3.0.0" }, diff --git a/src/index.ts b/src/index.ts index 9d23b13..0954caf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,5 @@ -/* eslint-disable no-console */ -import fs from 'fs-extra'; +import { utimesSync, createWriteStream, promises as fs} from 'fs'; import path from 'path'; -import { promisify } from 'util'; import { google, drive_v3 } from 'googleapis'; import mime from 'mime'; @@ -13,8 +11,6 @@ import ISyncState from './interfaces/ISyncState'; type Drive = drive_v3.Drive; type File = drive_v3.Schema$File; -const fsStat = promisify(fs.stat); - function sleep(timeout: number = 1000, value?: any) { return new Promise(function (resolve, reject) { setTimeout(function() { @@ -120,7 +116,7 @@ function timeAsSeconds(datetime: string | number | Date): number { */ async function isGDriveFileNewer(gDriveFile: File, filePath: string) { try { - const stats = await fsStat(filePath); + const stats = await fs.stat(filePath); const fsModifiedTime = timeAsSeconds(stats.mtime); const driveModifiedTime = timeAsSeconds(gDriveFile.modifiedTime); return (driveModifiedTime > fsModifiedTime); @@ -140,7 +136,7 @@ async function downloadFile (drive: Drive, file, destFolder: string, options: IO options.logger.debug('downloading newer: ', filePath); options.logger.debug('creating file: ', filePath); } - const dest = fs.createWriteStream(filePath); + const dest = createWriteStream(filePath); let fileId = file.id; if (file.shortcutDetails) { @@ -161,7 +157,7 @@ async function downloadFile (drive: Drive, file, destFolder: string, options: IO .on('error', reject) .on('finish', () => { // apply time stamp from the drive - fs.utimesSync( + utimesSync( filePath, timeAsSeconds(file.createdTime), timeAsSeconds(file.modifiedTime) @@ -190,7 +186,7 @@ async function exportFile (drive: Drive, file: File, destFolder: string, mimeTyp options.logger.debug('exporting to file: ', filePath); } - const dest = fs.createWriteStream(filePath); + const dest = createWriteStream(filePath); let fileId = file.id; if (file.shortcutDetails) { @@ -211,7 +207,7 @@ async function exportFile (drive: Drive, file: File, destFolder: string, mimeTyp .on('error', reject) .on('finish', () => { // apply time stamp from the drive - fs.utimesSync( + utimesSync( filePath, timeAsSeconds(file.createdTime), timeAsSeconds(file.modifiedTime) @@ -293,7 +289,7 @@ async function visitDirectory (drive: Drive, fileId: string, folderPath: string, options.logger.debug('DIR', file.id, childFolderPath, file.name) } - await fs.mkdirp(childFolderPath); + await fs.mkdir(childFolderPath, { recursive: true }); if (options.sleepTime) { await sleep(options.sleepTime); } diff --git a/test/index.ts b/test/index.ts index a86ac89..d2bf032 100644 --- a/test/index.ts +++ b/test/index.ts @@ -14,7 +14,7 @@ import syncGDrive, { IKeyConfig } from '../src'; interface BasicFileInfo { path: string, size: number -}; +} const fsMkdtemp = promisify(fs.mkdtemp); const fsReaddir = promisify(fs.readdir); diff --git a/tsconfig.json b/tsconfig.json index f341ab4..3883ec5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,7 +15,7 @@ "typeRoots": [ "node_modules/@types" ], - "rootDir": "src", + "rootDirs": ["src"], "outDir": "dist", "esModuleInterop": true, "resolveJsonModule": true @@ -28,7 +28,6 @@ ] }, "include": [ - "src/", - "test/" + "src/" ] } \ No newline at end of file