Skip to content
Open
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
9 changes: 9 additions & 0 deletions .changeset/brown-bears-retire-adapters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@sveltejs/adapter-node': patch
'@sveltejs/adapter-static': patch
'@sveltejs/adapter-cloudflare': patch
'@sveltejs/adapter-netlify': patch
'@sveltejs/adapter-vercel': patch
---

chore: use `node:fs` instead of deprecated `builder.rimraf` and `builder.mkdirp`
5 changes: 5 additions & 0 deletions .changeset/brown-bears-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

chore: deprecate `builder.rimraf` and `builder.mkdirp` in favour of `node:fs` methods
5 changes: 5 additions & 0 deletions .changeset/package-fs-helpers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/package': patch
---

chore: replace private fs helpers with Node built-ins
12 changes: 6 additions & 6 deletions packages/adapter-cloudflare/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { copyFileSync, existsSync, readFileSync, writeFileSync } from 'node:fs';
import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
Expand Down Expand Up @@ -72,15 +72,15 @@ export default function (options = {}) {
const files = fileURLToPath(new URL('./files', import.meta.url).href);
const tmp = builder.getBuildDirectory('cloudflare-tmp');

builder.rimraf(dest);
builder.rimraf(worker_dest);
rmSync(dest, { force: true, recursive: true });
rmSync(worker_dest, { force: true, recursive: true });

builder.mkdirp(dest);
builder.mkdirp(tmp);
mkdirSync(dest, { recursive: true });
mkdirSync(tmp, { recursive: true });

// client assets and prerendered pages
const assets_dest = `${dest}${builder.config.kit.paths.base}`;
builder.mkdirp(assets_dest);
mkdirSync(assets_dest, { recursive: true });
if (
building_for_cloudflare_pages ||
wrangler_config.assets?.not_found_handling === '404-page'
Expand Down
26 changes: 13 additions & 13 deletions packages/adapter-netlify/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { join, posix } from 'node:path';
import { fileURLToPath } from 'node:url';
import { builtinModules } from 'node:module';
Expand Down Expand Up @@ -60,19 +60,19 @@ export default function ({ split = false, edge = edge_set_in_env_var } = {}) {
const publish = get_publish_directory(netlify_config, builder) || 'build';

// empty out existing build directories
builder.rimraf(publish);
builder.rimraf('.netlify/v1');
rmSync(publish, { force: true, recursive: true });
rmSync('.netlify/v1', { force: true, recursive: true });

// clean up legacy directories from older adapter versions to avoid
// gnarly edge cases when an existing project is upgraded to this version
builder.rimraf('.netlify/edge-functions');
builder.rimraf('.netlify/server');
builder.rimraf('.netlify/package.json');
builder.rimraf('.netlify/serverless.js');
rmSync('.netlify/edge-functions', { force: true, recursive: true });
rmSync('.netlify/server', { force: true, recursive: true });
rmSync('.netlify/package.json', { force: true, recursive: true });
rmSync('.netlify/serverless.js', { force: true, recursive: true });
if (existsSync('.netlify/functions-internal')) {
for (const file of readdirSync('.netlify/functions-internal')) {
if (file.startsWith(FUNCTION_PREFIX)) {
builder.rimraf(join('.netlify/functions-internal', file));
rmSync(join('.netlify/functions-internal', file), { force: true, recursive: true });
}
}
}
Expand Down Expand Up @@ -118,7 +118,7 @@ export default function ({ split = false, edge = edge_set_in_env_var } = {}) {
*/
function generate_serverless_functions({ builder, publish, split }) {
// https://docs.netlify.com/build/frameworks/frameworks-api/#netlifyv1functions
builder.mkdirp(netlify_framework_serverless_path);
mkdirSync(netlify_framework_serverless_path, { recursive: true });

builder.writeServer('.netlify/v1/server');

Expand Down Expand Up @@ -243,7 +243,7 @@ function write_frameworks_config({ builder }) {
]
};

builder.mkdirp('.netlify/v1');
mkdirSync('.netlify/v1', { recursive: true });
writeFileSync(netlify_framework_config_path, s(config));
}

Expand Down Expand Up @@ -354,11 +354,11 @@ const rolldown_config = {
*/
async function generate_edge_functions({ builder }) {
const tmp = builder.getBuildDirectory('netlify-tmp');
builder.rimraf(tmp);
builder.mkdirp(tmp);
rmSync(tmp, { force: true, recursive: true });
mkdirSync(tmp, { recursive: true });

// https://docs.netlify.com/build/frameworks/frameworks-api/#edge-functions
builder.mkdirp('.netlify/v1/edge-functions');
mkdirSync('.netlify/v1/edge-functions', { recursive: true });

builder.log.minor('Generating Edge Function...');
const relativePath = posix.relative(tmp, builder.getServerDirectory());
Expand Down
8 changes: 4 additions & 4 deletions packages/adapter-node/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFileSync, writeFileSync } from 'node:fs';
import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { extname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { rolldown } from 'rolldown';
Expand All @@ -19,9 +19,9 @@ export default function (opts = {}) {
async adapt(builder) {
const tmp = builder.getBuildDirectory('adapter-node');

builder.rimraf(out);
builder.rimraf(tmp);
builder.mkdirp(tmp);
rmSync(out, { force: true, recursive: true });
rmSync(tmp, { force: true, recursive: true });
mkdirSync(tmp, { recursive: true });

builder.log.minor('Copying assets');
const written = [
Expand Down
5 changes: 3 additions & 2 deletions packages/adapter-static/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { rmSync } from 'node:fs';
import path from 'node:path';
import { platforms } from './platforms.js';

Expand Down Expand Up @@ -72,8 +73,8 @@ ${dynamic_routes.map((route) => ` - ${path.posix.join(prefix, route.id)}`).join
precompress
} = options ?? platform?.defaults ?? /** @type {import('./index.js').AdapterOptions} */ ({});

builder.rimraf(assets);
builder.rimraf(pages);
rmSync(assets, { force: true, recursive: true });
rmSync(pages, { force: true, recursive: true });

builder.generateEnvModule();
builder.writeClient(assets);
Expand Down
10 changes: 5 additions & 5 deletions packages/adapter-vercel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const plugin = function (defaults = {}) {
const dir = '.vercel/output';
const tmp = builder.getBuildDirectory('vercel-tmp');

builder.rimraf(dir);
builder.rimraf(tmp);
fs.rmSync(dir, { force: true, recursive: true });
fs.rmSync(tmp, { force: true, recursive: true });

if (fs.existsSync('vercel.json')) {
const vercel_file = fs.readFileSync('vercel.json', 'utf-8');
Expand Down Expand Up @@ -215,7 +215,7 @@ const plugin = function (defaults = {}) {
const target = path.join(dirs.functions, INTERNAL, 'catchall.func');

// Ensure the parent directory exists before symlinking
builder.mkdirp(path.join(dirs.functions, app_path));
fs.mkdirSync(path.join(dirs.functions, app_path), { recursive: true });

const relative = path.relative(path.dirname(remote_symlink_path), target);

Expand All @@ -238,7 +238,7 @@ const plugin = function (defaults = {}) {
if (isr) {
const isr_name = route.id.slice(1) || '__root__'; // should we check that __root__ isn't a route?
const base = `${dirs.functions}/${isr_name}`;
builder.mkdirp(base);
fs.mkdirSync(base, { recursive: true });

const target = `${dirs.functions}/${name}.func`;
const relative = path.relative(path.dirname(base), target);
Expand Down Expand Up @@ -289,7 +289,7 @@ const plugin = function (defaults = {}) {
const target = path.join(dirs.functions, `${name}.func`); // The actual function directory e.g., .vercel/output/functions/![-].func

// Ensure the directory for the data endpoint symlink exists (e.g., functions/index/)
builder.mkdirp(base_dir);
fs.mkdirSync(base_dir, { recursive: true });

// Calculate relative paths FROM the directory containing the symlink TO the target
const relative_for_main = path.relative(path.dirname(main_symlink_path), target);
Expand Down
17 changes: 12 additions & 5 deletions packages/kit/src/core/adapt/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@
/** @import { RouteData, ValidatedConfig, BuildData, ServerMetadata, ServerMetadataRoute, Prerendered, PrerenderMap, Logger, RemoteChunk } from 'types' */
import { loadEnv } from 'vite';
import * as devalue from 'devalue';
import { createReadStream, createWriteStream, existsSync, statSync } from 'node:fs';
import {
createReadStream,
createWriteStream,
existsSync,
mkdirSync,
rmSync,
statSync
} from 'node:fs';
import { extname, resolve, join, dirname, relative } from 'node:path';
import { pipeline } from 'node:stream';
import { promisify } from 'node:util';
import zlib from 'node:zlib';
import { copy, rimraf, mkdirp } from '../../utils/filesystem.js';
import { copy } from '../../utils/filesystem.js';
import { posixify } from '../../utils/os.js';
import { generate_manifest } from '../generate_manifest/index.js';
import { get_route_segments } from '../../utils/routing.js';
Expand Down Expand Up @@ -99,8 +106,8 @@ export function create_builder({

return {
log,
rimraf,
mkdirp,
rimraf: (dir) => rmSync(dir, { force: true, recursive: true }),
mkdirp: (dir) => mkdirSync(dir, { recursive: true }),
copy,

config,
Expand Down Expand Up @@ -271,7 +278,7 @@ export function create_builder({
exports: module.exports
});

rimraf(entrypoint);
rmSync(entrypoint, { force: true, recursive: true });
write(entrypoint, facade);
}
};
Expand Down
10 changes: 5 additions & 5 deletions packages/kit/src/core/postbuild/prerender.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { existsSync, readFileSync, statSync, writeFileSync } from 'node:fs';
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { pathToFileURL } from 'node:url';
import { mkdirp, walk } from '../../utils/filesystem.js';
import { walk } from '../../utils/filesystem.js';
import { posixify } from '../../utils/os.js';
import { noop } from '../../utils/functions.js';
import { decode_uri, is_root_relative, resolve } from '../../utils/url.js';
Expand Down Expand Up @@ -157,7 +157,7 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env, vit
const file = output_filename('/', true);
const dest = `${config.outDir}/output/prerendered/pages/${file}`;

mkdirp(dirname(dest));
mkdirSync(dirname(dest), { recursive: true });
writeFileSync(dest, fallback);

prerendered.pages.set('/', { file });
Expand Down Expand Up @@ -476,7 +476,7 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env, vit
}

if (!headers['x-sveltekit-normalize']) {
mkdirp(dirname(dest));
mkdirSync(dirname(dest), { recursive: true });

writeFileSync(
dest,
Expand Down Expand Up @@ -522,7 +522,7 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env, vit
);
}

mkdirp(dir);
mkdirSync(dir, { recursive: true });

writeFileSync(dest, body);
written.add(file);
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/core/sync/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'node:fs';
import path from 'node:path';
import { styleText } from 'node:util';
import { mkdirp, resolve_entry } from '../../utils/filesystem.js';
import { resolve_entry } from '../../utils/filesystem.js';

/** @type {Map<string, string>} */
const previous_contents = new Map();
Expand All @@ -22,7 +22,7 @@ export function write_if_changed(file, code) {
*/
export function write(file, code) {
previous_contents.set(file, code);
mkdirp(path.dirname(file));
fs.mkdirSync(path.dirname(file), { recursive: true });
fs.writeFileSync(file, code);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/core/sync/write_types/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'node:fs';
import path from 'node:path';
import MagicString from 'magic-string';
import { rimraf, walk, resolve_entry } from '../../../utils/filesystem.js';
import { walk, resolve_entry } from '../../../utils/filesystem.js';
import { compact } from '../../../utils/array.js';
import { posixify } from '../../../utils/os.js';
import { ts } from '../ts.js';
Expand Down Expand Up @@ -49,7 +49,7 @@ export function write_all_types(config, manifest_data, root) {
for (const file of walk(types_dir)) {
const dir = path.dirname(file);
if (!expected_directories.has(dir)) {
rimraf(path.join(types_dir, file));
fs.rmSync(path.join(types_dir, file), { force: true, recursive: true });
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions packages/kit/src/core/sync/write_types/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import { assert, describe, expect, test } from 'vitest';
import { rimraf } from '../../../utils/filesystem.js';
import create_manifest_data from '../create_manifest_data/index.js';
import { tweak_types, write_all_types } from './index.js';
import { write_app_types } from '../write_app_types.js';
Expand All @@ -16,7 +15,7 @@ const cwd = path.join(import.meta.dirname, 'test');
* @param {string} dir
*/
function run_test(dir) {
rimraf(path.join(cwd, dir, '.svelte-kit'));
fs.rmSync(path.join(cwd, dir, '.svelte-kit'), { force: true, recursive: true });

const initial = validate_config({});

Expand Down
10 changes: 8 additions & 2 deletions packages/kit/src/exports/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,15 @@ type UnpackValidationError<T> =
export interface Builder {
/** Print messages to the console. `log.info` and `log.minor` are silent unless Vite's `logLevel` is `info`. */
log: Logger;
/** Remove `dir` and all its contents. */
/**
* Remove `dir` and all its contents.
* @deprecated Use `fs.rmSync(dir, { force: true, recursive: true })` instead
*/
rimraf: (dir: string) => void;
/** Create `dir` and any required parent directories. */
/**
* Create `dir` and any required parent directories.
* @deprecated Use `fs.mkdirSync(dir, { recursive: true })` instead
*/
mkdirp: (dir: string) => void;

/** The fully resolved SvelteKit config. */
Expand Down
5 changes: 2 additions & 3 deletions packages/kit/src/exports/vite/build/build_server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/** @import { AssetDependencies, ManifestData, SSRNode, ValidatedKitConfig } from 'types' */
/** @import { Manifest, Rolldown } from 'vite' */
import fs from 'node:fs';
import { mkdirp } from '../../../utils/filesystem.js';
import {
create_function_as_string,
filter_fonts,
Expand Down Expand Up @@ -36,8 +35,8 @@ export function build_server_nodes(
chunks,
root
) {
mkdirp(`${out}/server/nodes`);
mkdirp(`${out}/server/stylesheets`);
fs.mkdirSync(`${out}/server/nodes`, { recursive: true });
fs.mkdirSync(`${out}/server/stylesheets`, { recursive: true });

/**
* Stylesheet names and their contents which are below the inline threshold
Expand Down
6 changes: 3 additions & 3 deletions packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import MagicString from 'magic-string';
import { loadEnv } from 'vite';
import { exactRegex, prefixRegex } from 'rolldown/filter';

import { copy, mkdirp, read, resolve_entry, rimraf } from '../../utils/filesystem.js';
import { copy, read, resolve_entry } from '../../utils/filesystem.js';
import { posixify } from '../../utils/os.js';
import { to_fs } from '../../utils/vite.js';
import {
Expand Down Expand Up @@ -1551,9 +1551,9 @@ function kit({ svelte_config }) {
async buildApp(builder) {
// clears the output directories
if (!builder.config.build.watch) {
rimraf(out);
fs.rmSync(out, { force: true, recursive: true });
}
mkdirp(out);
fs.mkdirSync(out, { recursive: true });

await load_and_validate_params({
routes: manifest_data.routes,
Expand Down
Loading
Loading