MCPcopy Index your code
hub / github.com/serverless/serverless / removeFileOrDirectory

Function removeFileOrDirectory

packages/sf-core/src/utils/fs/index.js:129–158  ·  view source on GitHub ↗
(targetPath)

Source from the content-addressed store, hash-verified

127 * @param targetPath The path to the file or directory to remove.
128 */
129const removeFileOrDirectory = async (targetPath) => {
130 try {
131 const stats = await fsp.lstat(targetPath)
132
133 // Fail silently if the file or directory does not exist
134 if (!stats) {
135 return
136 }
137
138 if (stats.isDirectory()) {
139 // If the target is a directory, recursively remove all its contents
140 const entries = await fsp.readdir(targetPath, { withFileTypes: true })
141 await Promise.all(
142 entries.map(async (entry) => {
143 const fullPath = path.join(targetPath, entry.name)
144 await removeFileOrDirectory(fullPath)
145 }),
146 )
147 await fsp.rmdir(targetPath)
148 } else {
149 // If the target is a file, delete it
150 await fsp.unlink(targetPath)
151 }
152 } catch (error) {
153 // Handle errors, such as 'ENOENT' (no such file or directory)
154 if (error.code !== 'ENOENT') {
155 throw error
156 }
157 }
158}
159
160/**
161 * Loads YAML content with specified options.

Callers 1

downloadTemplateFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…