-
Notifications
You must be signed in to change notification settings - Fork 410
chore: remove unnecessary abstractions of filesystem functions #5320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,15 @@ | ||
import { appendFileSync, existsSync, promises, readFileSync, writeFileSync } from 'fs' | ||
import { appendFile, mkdtemp, readFile, rm, writeFile } from 'fs/promises' | ||
import { tmpdir } from 'os' | ||
import { join, sep } from 'path' | ||
import { cwd, env } from 'process' | ||
import { fileURLToPath } from 'url' | ||
|
||
import del from 'del' | ||
import execa from 'execa' | ||
import getPort from 'get-port' | ||
import verdaccio from 'verdaccio' | ||
|
||
// TODO: remove this once `../../src/lib/fs.js` is an esm module as well | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't know why we should wait, ESM can import commonjs |
||
const rmdirRecursiveAsync = async (path) => { | ||
await del(path, { force: true }) | ||
} | ||
|
||
const { mkdtemp } = promises | ||
import { fileExistsAsync } from '../../src/lib/fs.cjs' | ||
|
||
// eslint-disable-next-line no-magic-numbers | ||
const VERDACCIO_TIMEOUT_MILLISECONDS = 60 * 1000 | ||
const START_PORT_RANGE = 5000 | ||
const END_PORT_RANGE = 5000 | ||
|
@@ -70,7 +63,7 @@ export const startRegistry = async () => { | |
const storage = fileURLToPath(new URL('../../.verdaccio-storage', import.meta.url)) | ||
|
||
// Remove netlify-cli from the verdaccio storage because we are going to publish it in a second | ||
await rmdirRecursiveAsync(join(storage, 'netlify-cli')) | ||
await rm(join(storage, 'netlify-cli'), { force: true, recursive: true }) | ||
|
||
return new Promise((resolve, reject) => { | ||
setTimeout(() => { | ||
|
@@ -105,17 +98,17 @@ export const setup = async () => { | |
/** Cleans up everything */ | ||
const cleanup = async () => { | ||
// remote temp folders | ||
await rmdirRecursiveAsync(workspace) | ||
await rm(workspace, { force: true, recursive: true }) | ||
} | ||
|
||
env.npm_config_registry = url | ||
|
||
try { | ||
if (existsSync(npmrc)) { | ||
backupNpmrc = readFileSync(npmrc, 'utf-8') | ||
appendFileSync(npmrc, registryWithAuth) | ||
if (await fileExistsAsync(npmrc)) { | ||
backupNpmrc = await readFile(npmrc, 'utf-8') | ||
await appendFile(npmrc, registryWithAuth) | ||
} else { | ||
writeFileSync(npmrc, registryWithAuth, 'utf-8') | ||
await writeFile(npmrc, registryWithAuth, 'utf-8') | ||
} | ||
|
||
// publish the CLI package to our registry | ||
|
@@ -137,10 +130,11 @@ ${error_ instanceof Error ? error_.message : error_}`, | |
) | ||
} finally { | ||
// restore .npmrc | ||
// eslint-disable-next-line unicorn/prefer-ternary | ||
if (backupNpmrc) { | ||
writeFileSync(npmrc, backupNpmrc) | ||
await writeFile(npmrc, backupNpmrc) | ||
} else { | ||
await rmdirRecursiveAsync(npmrc) | ||
await rm(npmrc, { force: true, recursive: true }) | ||
} | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated this file to use async version of the fs functions.