Skip to content
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

chore: extract fs helpers into shared internal-helpers package #11323

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/lovely-parents-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@astrojs/vercel': patch
'@astrojs/internal-helpers': patch
---

Extracts fs helpers into shared internal-helpers module
4 changes: 2 additions & 2 deletions packages/integrations/vercel/src/lib/nft.ts
Original file line number Diff line number Diff line change
@@ -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(
{
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/vercel/src/serverless/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/vercel/src/static/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion packages/internal-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ 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[] = []
): Promise<string> {
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)) {
Expand Down Expand Up @@ -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