0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-20 22:12:38 -05:00

chore: Extract fs helpers into shared internal-helpers package (#11323)

This commit is contained in:
Matt Kane 2024-06-24 10:12:14 +01:00 committed by GitHub
parent ae3b096892
commit 41064cee78
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 17 additions and 11 deletions

View file

@ -0,0 +1,6 @@
---
'@astrojs/vercel': patch
'@astrojs/internal-helpers': patch
---
Extracts fs helpers into shared internal-helpers module

View file

@ -1,7 +1,7 @@
import { relative as relativePath } from 'node:path';
import { fileURLToPath } from 'node:url';
import type { AstroIntegrationLogger } from 'astro';
import { copyFilesToFunction } from './fs.js';
import { copyFilesToFolder } from '@astrojs/internal-helpers/fs';
export async function copyDependenciesToFunction(
{
@ -72,7 +72,7 @@ export async function copyDependenciesToFunction(
}
}
const commonAncestor = await copyFilesToFunction(
const commonAncestor = await copyFilesToFolder(
[...result.fileList].map((file) => new URL(file, base)).concat(includeFiles),
outDir,
excludeFiles

View file

@ -16,7 +16,7 @@ import {
getAstroImageConfig,
getDefaultImageConfig,
} from '../image/shared.js';
import { removeDir, writeJson } from '../lib/fs.js';
import { removeDir, writeJson } from '@astrojs/internal-helpers/fs';
import { copyDependenciesToFunction } from '../lib/nft.js';
import { escapeRegex, getRedirects } from '../lib/redirects.js';
import {

View file

@ -6,7 +6,7 @@ import {
getAstroImageConfig,
getDefaultImageConfig,
} from '../image/shared.js';
import { emptyDir, writeJson } from '../lib/fs.js';
import { emptyDir, writeJson } from '@astrojs/internal-helpers/fs';
import { isServerLikeOutput } from '../lib/prerender.js';
import { getRedirects } from '../lib/redirects.js';
import {

View file

@ -12,12 +12,16 @@
},
"bugs": "https://github.com/withastro/astro/issues",
"exports": {
"./path": "./dist/path.js"
"./path": "./dist/path.js",
"./fs": "./dist/fs.js"
},
"typesVersions": {
"*": {
"path": [
"./dist/path.d.ts"
],
"fs": [
"./dist/fs.d.ts"
]
}
},

View file

@ -40,7 +40,7 @@ export async function getFilesFromFolder(dir: URL) {
* @param {URL[]} [exclude] A list of files to exclude (absolute path).
* @returns {Promise<string>} The common ancestor of the copied files.
*/
export async function copyFilesToFunction(
export async function copyFilesToFolder(
files: URL[],
outDir: URL,
exclude: URL[] = []
@ -48,7 +48,7 @@ export async function copyFilesToFunction(
const excludeList = exclude.map(fileURLToPath);
const fileList = files.map(fileURLToPath).filter((f) => !excludeList.includes(f));
if (files.length === 0) throw new Error('[@astrojs/vercel] No files found to copy');
if (files.length === 0) throw new Error('No files found to copy');
let commonAncestor = nodePath.dirname(fileList[0]);
for (const file of fileList.slice(1)) {
@ -87,7 +87,3 @@ export async function copyFilesToFunction(
return commonAncestor;
}
export async function writeFile(path: PathLike, content: string) {
await fs.writeFile(path, content, { encoding: 'utf-8' });
}