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:
parent
ae3b096892
commit
41064cee78
6 changed files with 17 additions and 11 deletions
6
.changeset/lovely-parents-attend.md
Normal file
6
.changeset/lovely-parents-attend.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
'@astrojs/vercel': patch
|
||||
'@astrojs/internal-helpers': patch
|
||||
---
|
||||
|
||||
Extracts fs helpers into shared internal-helpers module
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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' });
|
||||
}
|
Loading…
Add table
Reference in a new issue