Skip to content

Commit 41064ce

Browse files
authored
chore: Extract fs helpers into shared internal-helpers package (#11323)
1 parent ae3b096 commit 41064ce

File tree

6 files changed

+17
-11
lines changed

6 files changed

+17
-11
lines changed

.changeset/lovely-parents-attend.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@astrojs/vercel': patch
3+
'@astrojs/internal-helpers': patch
4+
---
5+
6+
Extracts fs helpers into shared internal-helpers module

packages/integrations/vercel/src/lib/nft.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { relative as relativePath } from 'node:path';
22
import { fileURLToPath } from 'node:url';
33
import type { AstroIntegrationLogger } from 'astro';
4-
import { copyFilesToFunction } from './fs.js';
4+
import { copyFilesToFolder } from '@astrojs/internal-helpers/fs';
55

66
export async function copyDependenciesToFunction(
77
{
@@ -72,7 +72,7 @@ export async function copyDependenciesToFunction(
7272
}
7373
}
7474

75-
const commonAncestor = await copyFilesToFunction(
75+
const commonAncestor = await copyFilesToFolder(
7676
[...result.fileList].map((file) => new URL(file, base)).concat(includeFiles),
7777
outDir,
7878
excludeFiles

packages/integrations/vercel/src/serverless/adapter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
getAstroImageConfig,
1717
getDefaultImageConfig,
1818
} from '../image/shared.js';
19-
import { removeDir, writeJson } from '../lib/fs.js';
19+
import { removeDir, writeJson } from '@astrojs/internal-helpers/fs';
2020
import { copyDependenciesToFunction } from '../lib/nft.js';
2121
import { escapeRegex, getRedirects } from '../lib/redirects.js';
2222
import {

packages/integrations/vercel/src/static/adapter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
getAstroImageConfig,
77
getDefaultImageConfig,
88
} from '../image/shared.js';
9-
import { emptyDir, writeJson } from '../lib/fs.js';
9+
import { emptyDir, writeJson } from '@astrojs/internal-helpers/fs';
1010
import { isServerLikeOutput } from '../lib/prerender.js';
1111
import { getRedirects } from '../lib/redirects.js';
1212
import {

packages/internal-helpers/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@
1212
},
1313
"bugs": "https://github.com/withastro/astro/issues",
1414
"exports": {
15-
"./path": "./dist/path.js"
15+
"./path": "./dist/path.js",
16+
"./fs": "./dist/fs.js"
1617
},
1718
"typesVersions": {
1819
"*": {
1920
"path": [
2021
"./dist/path.d.ts"
22+
],
23+
"fs": [
24+
"./dist/fs.d.ts"
2125
]
2226
}
2327
},

packages/integrations/vercel/src/lib/fs.ts packages/internal-helpers/src/fs.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ export async function getFilesFromFolder(dir: URL) {
4040
* @param {URL[]} [exclude] A list of files to exclude (absolute path).
4141
* @returns {Promise<string>} The common ancestor of the copied files.
4242
*/
43-
export async function copyFilesToFunction(
43+
export async function copyFilesToFolder(
4444
files: URL[],
4545
outDir: URL,
4646
exclude: URL[] = []
4747
): Promise<string> {
4848
const excludeList = exclude.map(fileURLToPath);
4949
const fileList = files.map(fileURLToPath).filter((f) => !excludeList.includes(f));
5050

51-
if (files.length === 0) throw new Error('[@astrojs/vercel] No files found to copy');
51+
if (files.length === 0) throw new Error('No files found to copy');
5252

5353
let commonAncestor = nodePath.dirname(fileList[0]);
5454
for (const file of fileList.slice(1)) {
@@ -87,7 +87,3 @@ export async function copyFilesToFunction(
8787

8888
return commonAncestor;
8989
}
90-
91-
export async function writeFile(path: PathLike, content: string) {
92-
await fs.writeFile(path, content, { encoding: 'utf-8' });
93-
}

0 commit comments

Comments
 (0)