From 0f91388f3da45f9435e4bd0b3a5e79023419020f Mon Sep 17 00:00:00 2001 From: Fran Dios Date: Mon, 8 Jul 2024 17:46:16 +0900 Subject: [PATCH] Remove usage of fs-extra (#2304) --- package-lock.json | 156 ++++-------------- packages/cli/package.json | 2 - .../cli/src/commands/hydrogen/setup.test.ts | 6 +- packages/cli/src/lib/onboarding/local.ts | 4 +- .../lib/onboarding/setup-template.mocks.ts | 10 +- packages/cli/src/lib/template-diff.ts | 13 +- packages/cli/tsup.config.ts | 20 ++- packages/mini-oxygen/package.json | 2 - packages/mini-oxygen/src/node/e2e.test.ts | 10 +- packages/mini-oxygen/src/worker/e2e.test.ts | 13 +- packages/mini-oxygen/tsup.config.ts | 4 +- 11 files changed, 82 insertions(+), 158 deletions(-) diff --git a/package-lock.json b/package-lock.json index 545bd22033..65f82cfd75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4742,9 +4742,9 @@ } }, "node_modules/@inquirer/core/node_modules/@types/node": { - "version": "20.14.9", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.9.tgz", - "integrity": "sha512-06OCtnTXtWOZBJlRApleWndH4JsRVs1pDCc8dLSQp+7PpUpX3ePdHyeNSFTeSe7FtKyQkrlPvHwJOW3SLd8Oyg==", + "version": "20.14.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.10.tgz", + "integrity": "sha512-MdiXf+nDuMvY0gJKxyfZ7/6UFsETO7mGKF54MVD/ekJS6HdFtpZFBgrh6Pseu64XTb2MLyFPlbW6hj8HYRQNOQ==", "dev": true, "dependencies": { "undici-types": "~5.26.4" @@ -5544,9 +5544,9 @@ } }, "node_modules/@npmcli/package-json/node_modules/glob": { - "version": "10.4.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.2.tgz", - "integrity": "sha512-GwMlUF6PkPo3Gk21UxkCohOv0PLcIXVtKyLlpEI28R/cO/4eNOdmLk3CMW1wROV/WR/EsZOWAfBbBOqYvs88/w==", + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.3.tgz", + "integrity": "sha512-Q38SGlYRpVtDBPSWEylRyctn7uDeTp4NQERTLiCT1FqA9JXPYWqAVmQU6qh4r/zMM5ehxTcbaO8EjhWnvEhmyg==", "dev": true, "dependencies": { "foreground-child": "^3.1.0", @@ -5560,7 +5560,7 @@ "glob": "dist/esm/bin.mjs" }, "engines": { - "node": ">=16 || 14 >=14.18" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -8991,15 +8991,6 @@ "@types/send": "*" } }, - "node_modules/@types/fs-extra": { - "version": "11.0.1", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/jsonfile": "*", - "@types/node": "*" - } - }, "node_modules/@types/gtag.js": { "version": "0.0.18", "resolved": "https://registry.npmjs.org/@types/gtag.js/-/gtag.js-0.0.18.tgz", @@ -9144,14 +9135,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/jsonfile": { - "version": "6.1.1", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/node": "*" - } - }, "node_modules/@types/lodash": { "version": "4.14.202", "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.202.tgz", @@ -10970,9 +10953,9 @@ } }, "node_modules/cacache/node_modules/glob": { - "version": "10.4.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.2.tgz", - "integrity": "sha512-GwMlUF6PkPo3Gk21UxkCohOv0PLcIXVtKyLlpEI28R/cO/4eNOdmLk3CMW1wROV/WR/EsZOWAfBbBOqYvs88/w==", + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.3.tgz", + "integrity": "sha512-Q38SGlYRpVtDBPSWEylRyctn7uDeTp4NQERTLiCT1FqA9JXPYWqAVmQU6qh4r/zMM5ehxTcbaO8EjhWnvEhmyg==", "dev": true, "dependencies": { "foreground-child": "^3.1.0", @@ -10986,7 +10969,7 @@ "glob": "dist/esm/bin.mjs" }, "engines": { - "node": ">=16 || 14 >=14.18" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -23096,12 +23079,12 @@ } }, "node_modules/path-scurry/node_modules/lru-cache": { - "version": "10.3.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.3.0.tgz", - "integrity": "sha512-CQl19J/g+Hbjbv4Y3mFNNXFEL/5t/KCg8POCuUqd4rMKjGG+j1ybER83hxV58zL+dFI1PTkt3GNFSHRt+d8qEQ==", + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.0.tgz", + "integrity": "sha512-bfJaPTuEiTYBu+ulDaeQ0F+uLmlfFkMgXj4cbwfuMSjgObGMzb55FMMbDvbRU0fAHZ4sLGkz2mKwcMg8Dvm8Ww==", "dev": true, "engines": { - "node": "14 || >=16.14" + "node": ">=18" } }, "node_modules/path-to-regexp": { @@ -26421,9 +26404,9 @@ } }, "node_modules/sucrase/node_modules/glob": { - "version": "10.4.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.2.tgz", - "integrity": "sha512-GwMlUF6PkPo3Gk21UxkCohOv0PLcIXVtKyLlpEI28R/cO/4eNOdmLk3CMW1wROV/WR/EsZOWAfBbBOqYvs88/w==", + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.3.tgz", + "integrity": "sha512-Q38SGlYRpVtDBPSWEylRyctn7uDeTp4NQERTLiCT1FqA9JXPYWqAVmQU6qh4r/zMM5ehxTcbaO8EjhWnvEhmyg==", "dev": true, "dependencies": { "foreground-child": "^3.1.0", @@ -26437,7 +26420,7 @@ "glob": "dist/esm/bin.mjs" }, "engines": { - "node": ">=16 || 14 >=14.18" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -29664,7 +29647,6 @@ "chokidar": "3.5.3", "cli-truncate": "^4.0.0", "diff": "^5.1.0", - "fs-extra": "^11.1.0", "get-port": "^7.0.0", "gunzip-maybe": "^1.4.2", "prettier": "^2.8.4", @@ -29682,7 +29664,6 @@ "devDependencies": { "@remix-run/dev": "^2.10.1", "@types/diff": "^5.0.2", - "@types/fs-extra": "^11.0.1", "@types/gunzip-maybe": "^1.4.0", "@types/prettier": "^2.7.2", "@types/source-map-support": "^0.5.10", @@ -29807,19 +29788,6 @@ "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.3.0.tgz", "integrity": "sha512-QpLs9D9v9kArv4lfDEgg1X/gN5XLnf/A6l9cs8SPZLRZR3ZkY9+kwIQTxm+fsSej5UMYGE8fdoaZVIBlqG0XTw==" }, - "packages/cli/node_modules/fs-extra": { - "version": "11.2.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", - "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", - "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - }, - "engines": { - "node": ">=14.14" - } - }, "packages/cli/node_modules/get-port": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/get-port/-/get-port-7.1.0.tgz", @@ -32243,14 +32211,12 @@ "@types/body-parser": "1.19.3", "@types/connect": "^3.4.35", "@types/eventsource": "^1.1.10", - "@types/fs-extra": "^11.0.1", "@types/node": "^18.7.0", "@types/source-map-support": "^0.5.10", "@types/stack-trace": "^0.0.33", "@types/ws": "^8.5.3", "devtools-protocol": "^0.0.1177611", "eventsource": "^2.0.2", - "fs-extra": "^11.1.0", "tempy": "3.0.0", "vitest": "^1.0.4" }, @@ -32272,20 +32238,6 @@ "integrity": "sha512-O7in6531Bbvlb2KEsJ0dq0CHZvc3iWSR5ZYMtvGgnHA56VgriAN/AU2LorfmcvAl2xc9N5fbCTRyMRRl8nd74g==", "dev": true }, - "packages/mini-oxygen/node_modules/fs-extra": { - "version": "11.2.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", - "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", - "dev": true, - "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - }, - "engines": { - "node": ">=14.14" - } - }, "packages/mini-oxygen/node_modules/get-port": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/get-port/-/get-port-7.1.0.tgz", @@ -35565,9 +35517,9 @@ }, "dependencies": { "@types/node": { - "version": "20.14.9", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.9.tgz", - "integrity": "sha512-06OCtnTXtWOZBJlRApleWndH4JsRVs1pDCc8dLSQp+7PpUpX3ePdHyeNSFTeSe7FtKyQkrlPvHwJOW3SLd8Oyg==", + "version": "20.14.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.10.tgz", + "integrity": "sha512-MdiXf+nDuMvY0gJKxyfZ7/6UFsETO7mGKF54MVD/ekJS6HdFtpZFBgrh6Pseu64XTb2MLyFPlbW6hj8HYRQNOQ==", "dev": true, "requires": { "undici-types": "~5.26.4" @@ -36159,9 +36111,9 @@ } }, "glob": { - "version": "10.4.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.2.tgz", - "integrity": "sha512-GwMlUF6PkPo3Gk21UxkCohOv0PLcIXVtKyLlpEI28R/cO/4eNOdmLk3CMW1wROV/WR/EsZOWAfBbBOqYvs88/w==", + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.3.tgz", + "integrity": "sha512-Q38SGlYRpVtDBPSWEylRyctn7uDeTp4NQERTLiCT1FqA9JXPYWqAVmQU6qh4r/zMM5ehxTcbaO8EjhWnvEhmyg==", "dev": true, "requires": { "foreground-child": "^3.1.0", @@ -37447,7 +37399,6 @@ "@shopify/oxygen-cli": "4.4.9", "@shopify/plugin-cloudflare": "3.61.2", "@types/diff": "^5.0.2", - "@types/fs-extra": "^11.0.1", "@types/gunzip-maybe": "^1.4.0", "@types/prettier": "^2.7.2", "@types/source-map-support": "^0.5.10", @@ -37460,7 +37411,6 @@ "diff": "^5.1.0", "fast-glob": "^3.2.12", "flame-chart-js": "2.3.2", - "fs-extra": "^11.1.0", "get-port": "^7.0.0", "gunzip-maybe": "^1.4.2", "prettier": "^2.8.4", @@ -37520,16 +37470,6 @@ "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.3.0.tgz", "integrity": "sha512-QpLs9D9v9kArv4lfDEgg1X/gN5XLnf/A6l9cs8SPZLRZR3ZkY9+kwIQTxm+fsSej5UMYGE8fdoaZVIBlqG0XTw==" }, - "fs-extra": { - "version": "11.2.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", - "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", - "requires": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - } - }, "get-port": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/get-port/-/get-port-7.1.0.tgz", @@ -39401,7 +39341,6 @@ "@types/body-parser": "1.19.3", "@types/connect": "^3.4.35", "@types/eventsource": "^1.1.10", - "@types/fs-extra": "^11.0.1", "@types/node": "^18.7.0", "@types/source-map-support": "^0.5.10", "@types/stack-trace": "^0.0.33", @@ -39410,7 +39349,6 @@ "connect": "^3.7.0", "devtools-protocol": "^0.0.1177611", "eventsource": "^2.0.2", - "fs-extra": "^11.1.0", "get-port": "^7.0.0", "miniflare": "3.20240304.2", "mrmime": "1.0.1", @@ -39429,17 +39367,6 @@ "integrity": "sha512-O7in6531Bbvlb2KEsJ0dq0CHZvc3iWSR5ZYMtvGgnHA56VgriAN/AU2LorfmcvAl2xc9N5fbCTRyMRRl8nd74g==", "dev": true }, - "fs-extra": { - "version": "11.2.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", - "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", - "dev": true, - "requires": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - } - }, "get-port": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/get-port/-/get-port-7.1.0.tgz", @@ -40068,14 +39995,6 @@ "@types/send": "*" } }, - "@types/fs-extra": { - "version": "11.0.1", - "dev": true, - "requires": { - "@types/jsonfile": "*", - "@types/node": "*" - } - }, "@types/gtag.js": { "version": "0.0.18", "resolved": "https://registry.npmjs.org/@types/gtag.js/-/gtag.js-0.0.18.tgz", @@ -40197,13 +40116,6 @@ "version": "0.0.29", "dev": true }, - "@types/jsonfile": { - "version": "6.1.1", - "dev": true, - "requires": { - "@types/node": "*" - } - }, "@types/lodash": { "version": "4.14.202", "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.202.tgz", @@ -41499,9 +41411,9 @@ } }, "glob": { - "version": "10.4.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.2.tgz", - "integrity": "sha512-GwMlUF6PkPo3Gk21UxkCohOv0PLcIXVtKyLlpEI28R/cO/4eNOdmLk3CMW1wROV/WR/EsZOWAfBbBOqYvs88/w==", + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.3.tgz", + "integrity": "sha512-Q38SGlYRpVtDBPSWEylRyctn7uDeTp4NQERTLiCT1FqA9JXPYWqAVmQU6qh4r/zMM5ehxTcbaO8EjhWnvEhmyg==", "dev": true, "requires": { "foreground-child": "^3.1.0", @@ -49484,9 +49396,9 @@ }, "dependencies": { "lru-cache": { - "version": "10.3.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.3.0.tgz", - "integrity": "sha512-CQl19J/g+Hbjbv4Y3mFNNXFEL/5t/KCg8POCuUqd4rMKjGG+j1ybER83hxV58zL+dFI1PTkt3GNFSHRt+d8qEQ==", + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.0.tgz", + "integrity": "sha512-bfJaPTuEiTYBu+ulDaeQ0F+uLmlfFkMgXj4cbwfuMSjgObGMzb55FMMbDvbRU0fAHZ4sLGkz2mKwcMg8Dvm8Ww==", "dev": true } } @@ -51810,9 +51722,9 @@ "dev": true }, "glob": { - "version": "10.4.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.2.tgz", - "integrity": "sha512-GwMlUF6PkPo3Gk21UxkCohOv0PLcIXVtKyLlpEI28R/cO/4eNOdmLk3CMW1wROV/WR/EsZOWAfBbBOqYvs88/w==", + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.3.tgz", + "integrity": "sha512-Q38SGlYRpVtDBPSWEylRyctn7uDeTp4NQERTLiCT1FqA9JXPYWqAVmQU6qh4r/zMM5ehxTcbaO8EjhWnvEhmyg==", "dev": true, "requires": { "foreground-child": "^3.1.0", diff --git a/packages/cli/package.json b/packages/cli/package.json index a4ab8942e5..336aa34250 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -18,7 +18,6 @@ "devDependencies": { "@remix-run/dev": "^2.10.1", "@types/diff": "^5.0.2", - "@types/fs-extra": "^11.0.1", "@types/gunzip-maybe": "^1.4.0", "@types/prettier": "^2.7.2", "@types/source-map-support": "^0.5.10", @@ -42,7 +41,6 @@ "chokidar": "3.5.3", "cli-truncate": "^4.0.0", "diff": "^5.1.0", - "fs-extra": "^11.1.0", "get-port": "^7.0.0", "gunzip-maybe": "^1.4.2", "prettier": "^2.8.4", diff --git a/packages/cli/src/commands/hydrogen/setup.test.ts b/packages/cli/src/commands/hydrogen/setup.test.ts index b762e7e1f2..1943bf588d 100644 --- a/packages/cli/src/commands/hydrogen/setup.test.ts +++ b/packages/cli/src/commands/hydrogen/setup.test.ts @@ -1,5 +1,5 @@ +import {symlink, cp as copyWithFilter} from 'node:fs/promises'; import {describe, it, expect, vi, beforeEach} from 'vitest'; -import {copy as copyWithFilter, createSymlink} from 'fs-extra/esm'; import { inTemporaryDirectory, fileExists, @@ -41,6 +41,8 @@ describe('setup', () => { it('sets up an i18n strategy and generates routes', async () => { await inTemporaryDirectory(async (tmpDir) => { await copyWithFilter(getSkeletonSourceDir(), tmpDir, { + force: true, + recursive: true, filter: (src) => !src.includes('node_modules') && !src.includes('routes'), }); @@ -49,7 +51,7 @@ describe('setup', () => { fileExists(joinPath(tmpDir, 'app/routes/_index.tsx')), ).resolves.toBeFalsy(); - await createSymlink( + await symlink( await getRepoNodeModules(), joinPath(tmpDir, 'node_modules'), ); diff --git a/packages/cli/src/lib/onboarding/local.ts b/packages/cli/src/lib/onboarding/local.ts index ced479c3a6..a4268bb0fa 100644 --- a/packages/cli/src/lib/onboarding/local.ts +++ b/packages/cli/src/lib/onboarding/local.ts @@ -1,4 +1,4 @@ -import {copy as copyWithFilter} from 'fs-extra/esm'; +import {cp as copyWithFilter} from 'node:fs/promises'; import {AbortError} from '@shopify/cli-kit/node/error'; import {AbortController} from '@shopify/cli-kit/node/abort'; import {writeFile} from '@shopify/cli-kit/node/fs'; @@ -92,6 +92,8 @@ export async function setupLocalStarterTemplate( project.directory, // Filter out the `app` directory and server.ts, which will be generated later { + force: true, + recursive: true, filter: (filepath: string) => !/^(app\/|dist\/|node_modules\/|server\.ts)/i.test( relativePath(templateDir, filepath), diff --git a/packages/cli/src/lib/onboarding/setup-template.mocks.ts b/packages/cli/src/lib/onboarding/setup-template.mocks.ts index f22b678daf..4626c0645a 100644 --- a/packages/cli/src/lib/onboarding/setup-template.mocks.ts +++ b/packages/cli/src/lib/onboarding/setup-template.mocks.ts @@ -1,5 +1,5 @@ +import {symlink, rm as rmdir} from 'node:fs/promises'; import {vi} from 'vitest'; -import {createSymlink, remove as rmdir} from 'fs-extra/esm'; import {writeFile} from '@shopify/cli-kit/node/fs'; import {dirname, joinPath} from '@shopify/cli-kit/node/path'; import {getRepoNodeModules, getSkeletonSourceDir} from '../build.js'; @@ -57,8 +57,12 @@ vi.mock( }); // "Install" dependencies by linking to monorepo's node_modules - await rmdir(joinPath(directory, 'node_modules')).catch(() => {}); - await createSymlink( + await rmdir(joinPath(directory, 'node_modules'), { + force: true, + recursive: true, + }).catch(() => {}); + + await symlink( await getRepoNodeModules(), joinPath(directory, 'node_modules'), ); diff --git a/packages/cli/src/lib/template-diff.ts b/packages/cli/src/lib/template-diff.ts index e6220d6df2..b2f5228bc7 100644 --- a/packages/cli/src/lib/template-diff.ts +++ b/packages/cli/src/lib/template-diff.ts @@ -1,5 +1,5 @@ +import {symlink, cp as copyDirectory} from 'node:fs/promises'; import {temporaryDirectory} from 'tempy'; -import {createSymlink, copy as copyDirectory} from 'fs-extra/esm'; import { copyFile, fileExists, @@ -44,7 +44,7 @@ export async function prepareDiffDirectory( const templateDirectory = await getStarterDir(isHydrogenMonorepo); await applyTemplateDiff(targetDirectory, diffDirectory, templateDirectory); - await createSymlink( + await symlink( await getRepoNodeModules(), joinPath(targetDirectory, 'node_modules'), ); @@ -162,7 +162,7 @@ export async function prepareDiffDirectory( const target = joinPath(diffDirectory, '.shopify'); await remove(target); - await copyDirectory(source, target, {overwrite: true}); + await copyDirectory(source, target, {recursive: true, force: true}); }, /** * Brings the `dist` directory back to the original project. @@ -173,7 +173,8 @@ export async function prepareDiffDirectory( await remove(target); await Promise.all([ copyDirectory(joinPath(targetDirectory, 'dist'), target, { - overwrite: true, + force: true, + recursive: true, }), copyFile( joinPath(targetDirectory, '.env'), @@ -209,6 +210,8 @@ export async function applyTemplateDiff( }; await copyDirectory(templateDir, targetDirectory, { + force: true, + recursive: true, filter: createFilter( // Do not copy .shopify from skeleton to avoid linking in examples inadvertedly /(^|\/|\\)(dist|node_modules|\.cache|\.turbo|\.shopify|CHANGELOG\.md)(\/|\\|$)/i, @@ -216,6 +219,8 @@ export async function applyTemplateDiff( ), }); await copyDirectory(diffDirectory, targetDirectory, { + force: true, + recursive: true, filter: createFilter( /(^|\/|\\)(dist|node_modules|\.cache|.turbo|package\.json|tsconfig\.json)(\/|\\|$)/i, ), diff --git a/packages/cli/tsup.config.ts b/packages/cli/tsup.config.ts index e7a47d41de..e7c71b2078 100644 --- a/packages/cli/tsup.config.ts +++ b/packages/cli/tsup.config.ts @@ -1,6 +1,7 @@ import path from 'node:path'; +import {rmSync} from 'node:fs'; +import {cp as copy} from 'node:fs/promises'; import {defineConfig} from 'tsup'; -import fs from 'fs-extra'; import {execAsync} from './src/lib/process'; import { ASSETS_DIR_PREFIX, @@ -10,7 +11,7 @@ import { import {replaceFileContent} from './src/lib/file'; // Cleanup dist folder before buid/dev. -fs.removeSync('./dist'); +rmSync('./dist', {recursive: true, force: true}); const commonConfig = defineConfig({ format: 'esm', @@ -33,10 +34,10 @@ export default defineConfig([ dts: {entry: ['src/index.ts', 'src/commands/hydrogen/init.ts']}, async onSuccess() { // Copy assets templates - await fs.copy( - path.resolve('assets'), - path.join(outDir, ASSETS_DIR_PREFIX), - ); + await copy(path.resolve('assets'), path.join(outDir, ASSETS_DIR_PREFIX), { + recursive: true, + force: true, + }); // These files need to be packaged/distributed with the CLI // so that we can use them in the `generate` command. @@ -46,7 +47,9 @@ export default defineConfig([ ASSETS_STARTER_DIR, ); - await fs.copy(getSkeletonSourceDir(), starterOutDir, { + await copy(getSkeletonSourceDir(), starterOutDir, { + force: true, + recursive: true, filter: (filepath: string) => !/node_modules|\.shopify|\.cache|\.turbo|build|dist/gi.test(filepath), }); @@ -79,9 +82,10 @@ export default defineConfig([ async onSuccess() { // For some reason, it seems that publicDir => outDir might be skipped on CI, // so ensure here that asset files are copied: - await fs.copy( + await copy( '../hydrogen/src/vite/virtual-routes/assets', `${outDir}/${ASSETS_DIR_PREFIX}/virtual-routes/assets`, + {recursive: true, force: true}, ); console.log('\n', 'Copied virtual route assets to build directory', '\n'); diff --git a/packages/mini-oxygen/package.json b/packages/mini-oxygen/package.json index f8faed865f..20ceee0efd 100644 --- a/packages/mini-oxygen/package.json +++ b/packages/mini-oxygen/package.json @@ -65,14 +65,12 @@ "@types/body-parser": "1.19.3", "@types/connect": "^3.4.35", "@types/eventsource": "^1.1.10", - "@types/fs-extra": "^11.0.1", "@types/node": "^18.7.0", "@types/source-map-support": "^0.5.10", "@types/stack-trace": "^0.0.33", "@types/ws": "^8.5.3", "devtools-protocol": "^0.0.1177611", "eventsource": "^2.0.2", - "fs-extra": "^11.1.0", "tempy": "3.0.0", "vitest": "^1.0.4" }, diff --git a/packages/mini-oxygen/src/node/e2e.test.ts b/packages/mini-oxygen/src/node/e2e.test.ts index 44a1d4183b..ffb90f46b0 100644 --- a/packages/mini-oxygen/src/node/e2e.test.ts +++ b/packages/mini-oxygen/src/node/e2e.test.ts @@ -1,7 +1,7 @@ -import {join, resolve} from 'node:path'; +import {join} from 'node:path'; +import {writeFile, rm as remove, mkdir} from 'node:fs/promises'; import http, {type IncomingMessage} from 'node:http'; -import {writeFile, ensureDir, remove} from 'fs-extra'; import {temporaryDirectory} from 'tempy'; import {it, vi, describe, beforeEach, expect, afterEach} from 'vitest'; import EventSource from 'eventsource'; @@ -324,7 +324,7 @@ async function createFixture(name: string): Promise { assets: join(directory, 'assets'), }; - await ensureDir(paths.assets); + await mkdir(paths.assets, {recursive: true}); await writeFile(join(directory, '.gitignore'), '*'); await writeFile( @@ -370,8 +370,8 @@ export default { return { paths, destroy: async () => { - await remove(paths.assets); - await remove(directory); + await remove(paths.assets, {force: true, recursive: true}); + await remove(directory, {force: true, recursive: true}); }, updateWorker: () => { return writeFile( diff --git a/packages/mini-oxygen/src/worker/e2e.test.ts b/packages/mini-oxygen/src/worker/e2e.test.ts index 603b52ead8..ce60c3cc14 100644 --- a/packages/mini-oxygen/src/worker/e2e.test.ts +++ b/packages/mini-oxygen/src/worker/e2e.test.ts @@ -1,6 +1,5 @@ import path from 'node:path'; -import fs from 'node:fs/promises'; -import {ensureFile as touchFile, remove as removeFile} from 'fs-extra/esm'; +import {mkdir, writeFile, readFile, rm as remove} from 'node:fs/promises'; import {temporaryDirectoryTask} from 'tempy'; import {it, vi, describe, expect} from 'vitest'; import {transformWithEsbuild} from 'vite'; @@ -174,7 +173,7 @@ describe('MiniOxygen Worker Runtime', () => { // -- Test without sourcemaps: - await removeFile(miniOxygenOptions.sourceMapPath!); + await remove(miniOxygenOptions.sourceMapPath!, {force: true}); await reloadMiniOxygen(); await fetch('/'); @@ -245,8 +244,8 @@ function withFixtures( const writeFixture: WriteFixture = async (filename, content) => { const filepath = path.join(tmpDir, filename); - await touchFile(filepath); - await fs.writeFile(filepath, content, 'utf-8'); + await mkdir(path.dirname(filepath), {recursive: true}); + await writeFile(filepath, content, 'utf-8'); }; const writeAsset: WriteFixture = (filepath, content) => writeFixture(path.join(relativeDistClient, filepath), content); @@ -294,7 +293,7 @@ function withFixtures( { type: 'ESModule', path: absoluteBundlePath, - contents: await fs.readFile(absoluteBundlePath, 'utf-8'), + contents: await readFile(absoluteBundlePath, 'utf-8'), }, ], bindings: {...optionsFromSetup?.bindings}, @@ -314,7 +313,7 @@ function withFixtures( if (Array.isArray(testWorker.modules)) { // Reload contents - testWorker.modules[0].contents = await fs.readFile( + testWorker.modules[0].contents = await readFile( absoluteBundlePath, 'utf-8', ); diff --git a/packages/mini-oxygen/tsup.config.ts b/packages/mini-oxygen/tsup.config.ts index f2443a9678..a729a05e26 100644 --- a/packages/mini-oxygen/tsup.config.ts +++ b/packages/mini-oxygen/tsup.config.ts @@ -1,8 +1,8 @@ +import {rmSync} from 'node:fs'; import {defineConfig} from 'tsup'; -import fs from 'fs-extra'; // Cleanup dist folder before buid/dev. -fs.removeSync('./dist'); +rmSync('./dist', {recursive: true, force: true}); export default defineConfig([ {