From cfe44a84914a90045b8ac6ba3ce7ebcc13c7908f Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Tue, 19 Jul 2022 09:52:12 -0700 Subject: [PATCH 1/2] [breaking] remove writeStatic to align with Vite --- .changeset/smooth-cars-reflect.md | 11 +++++++++++ packages/adapter-cloudflare-workers/index.js | 1 - packages/adapter-cloudflare/index.js | 1 - packages/adapter-netlify/index.js | 3 +-- packages/adapter-node/index.js | 1 - packages/adapter-static/index.js | 1 - packages/adapter-vercel/index.js | 1 - packages/kit/src/core/adapt/builder.js | 12 ++++++++++-- packages/kit/src/core/adapt/builder.spec.js | 19 +++++++------------ packages/kit/types/index.d.ts | 5 ----- 10 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 .changeset/smooth-cars-reflect.md diff --git a/.changeset/smooth-cars-reflect.md b/.changeset/smooth-cars-reflect.md new file mode 100644 index 000000000000..b1b905cb59ce --- /dev/null +++ b/.changeset/smooth-cars-reflect.md @@ -0,0 +1,11 @@ +--- +'@sveltejs/adapter-cloudflare': patch +'@sveltejs/adapter-cloudflare-workers': patch +'@sveltejs/adapter-netlify': patch +'@sveltejs/adapter-node': patch +'@sveltejs/adapter-static': patch +'@sveltejs/adapter-vercel': patch +'@sveltejs/kit': patch +--- + +[breaking] remove writeStatic to align with Vite diff --git a/packages/adapter-cloudflare-workers/index.js b/packages/adapter-cloudflare-workers/index.js index 7bfd7634828a..c8830c12bfa7 100644 --- a/packages/adapter-cloudflare-workers/index.js +++ b/packages/adapter-cloudflare-workers/index.js @@ -74,7 +74,6 @@ export default function () { builder.log.minor('Copying assets...'); builder.writeClient(site.bucket); - builder.writeStatic(site.bucket); builder.writePrerendered(site.bucket); } }; diff --git a/packages/adapter-cloudflare/index.js b/packages/adapter-cloudflare/index.js index 41c4f2477f68..bfb9d968aa1f 100644 --- a/packages/adapter-cloudflare/index.js +++ b/packages/adapter-cloudflare/index.js @@ -23,7 +23,6 @@ export default function () { builder.rimraf(tmp); builder.mkdirp(tmp); - builder.writeStatic(dest); builder.writeClient(dest); builder.writePrerendered(dest); diff --git a/packages/adapter-netlify/index.js b/packages/adapter-netlify/index.js index f1fbf9b94185..39bc32738954 100644 --- a/packages/adapter-netlify/index.js +++ b/packages/adapter-netlify/index.js @@ -55,7 +55,6 @@ export default function ({ split = false, edge = edge_set_in_env_var } = {}) { builder.log.minor(`Publishing to "${publish}"`); builder.log.minor('Copying assets...'); - builder.writeStatic(publish); builder.writeClient(publish); builder.writePrerendered(publish); @@ -232,7 +231,7 @@ async function generate_lambda_functions({ builder, publish, split, esm }) { redirects.push('* /.netlify/functions/render 200'); } - // this should happen at the end, after builder.writeStatic(...), + // this should happen at the end, after builder.writeClient(...), // so that generated redirects are appended to custom redirects // rather than replaced by them builder.log.minor('Writing redirects...'); diff --git a/packages/adapter-node/index.js b/packages/adapter-node/index.js index baccdcbb2a6c..ec1d53eeccfe 100644 --- a/packages/adapter-node/index.js +++ b/packages/adapter-node/index.js @@ -30,7 +30,6 @@ export default function (opts = {}) { builder.log.minor('Copying assets'); builder.writeClient(`${out}/client`); builder.writeServer(`${out}/server`); - builder.writeStatic(`${out}/static`); builder.writePrerendered(`${out}/prerendered`); writeFileSync( diff --git a/packages/adapter-static/index.js b/packages/adapter-static/index.js index 3d5d3d3aac98..6120ff5f712c 100644 --- a/packages/adapter-static/index.js +++ b/packages/adapter-static/index.js @@ -43,7 +43,6 @@ export default function (options) { builder.rimraf(assets); builder.rimraf(pages); - builder.writeStatic(assets); builder.writeClient(assets); builder.writePrerendered(pages, { fallback }); diff --git a/packages/adapter-vercel/index.js b/packages/adapter-vercel/index.js index b8ea4f9d9e21..fc55c079f45d 100644 --- a/packages/adapter-vercel/index.js +++ b/packages/adapter-vercel/index.js @@ -236,7 +236,6 @@ export default function ({ external = [], edge, split } = {}) { builder.log.minor('Copying assets...'); - builder.writeStatic(dirs.static); builder.writeClient(dirs.static); builder.writePrerendered(dirs.static); diff --git a/packages/kit/src/core/adapt/builder.js b/packages/kit/src/core/adapt/builder.js index 7490e48342ae..2e79129391ab 100644 --- a/packages/kit/src/core/adapt/builder.js +++ b/packages/kit/src/core/adapt/builder.js @@ -122,7 +122,10 @@ export function create_builder({ config, build_data, prerendered, log }) { }, writeClient(dest) { - return copy(`${config.kit.outDir}/output/client`, dest); + return [ + ...copy(`${config.kit.outDir}/output/client`, dest), + ...copy(config.kit.files.assets, dest) + ]; }, writePrerendered(dest, { fallback } = {}) { @@ -141,8 +144,13 @@ export function create_builder({ config, build_data, prerendered, log }) { return copy(`${config.kit.outDir}/output/server`, dest); }, + // TODO remove these methods for 1.0 writeStatic(dest) { - return copy(config.kit.files.assets, dest); + throw new Error( + `writeStatic has been removed. Please ensure you are using the latest version of ${ + config.kit.adapter.name || 'your adapter' + }` + ); }, // @ts-expect-error diff --git a/packages/kit/src/core/adapt/builder.spec.js b/packages/kit/src/core/adapt/builder.spec.js index 2b05b1107317..0af84ddec6c5 100644 --- a/packages/kit/src/core/adapt/builder.spec.js +++ b/packages/kit/src/core/adapt/builder.spec.js @@ -39,22 +39,17 @@ test('copy files', () => { const dest = join(__dirname, 'output'); - rmSync(dest, { recursive: true, force: true }); - builder.writeStatic(dest); - - assert.equal( - glob('**', { - cwd: /** @type {import('types').ValidatedConfig} */ (mocked).kit.files.assets, - dot: true - }), - glob('**', { cwd: dest, dot: true }) - ); - rmSync(dest, { recursive: true, force: true }); builder.writeClient(dest); assert.equal( - glob('**', { cwd: `${outDir}/output/client`, dot: true }), + [ + ...glob('**', { + cwd: /** @type {import('types').ValidatedConfig} */ (mocked).kit.files.assets, + dot: true + }), + ...glob('**', { cwd: `${outDir}/output/client`, dot: true }) + ], glob('**', { cwd: dest, dot: true }) ); diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 97ff605ca3ec..b06f2b444917 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -65,11 +65,6 @@ export interface Builder { * @returns an array of paths corresponding to the files that have been created by the copy */ writeServer(dest: string): string[]; - /** - * @param dest the destination folder to which files should be copied - * @returns an array of paths corresponding to the files that have been created by the copy - */ - writeStatic(dest: string): string[]; /** * @param from the source file or folder * @param to the destination file or folder From b37d98e9f2e32363b59a1491921b0ea53ce595d8 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Tue, 19 Jul 2022 10:03:05 -0700 Subject: [PATCH 2/2] check --- packages/kit/src/core/adapt/builder.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/kit/src/core/adapt/builder.js b/packages/kit/src/core/adapt/builder.js index 2e79129391ab..b2e52c86aebc 100644 --- a/packages/kit/src/core/adapt/builder.js +++ b/packages/kit/src/core/adapt/builder.js @@ -145,7 +145,8 @@ export function create_builder({ config, build_data, prerendered, log }) { }, // TODO remove these methods for 1.0 - writeStatic(dest) { + // @ts-expect-error + writeStatic() { throw new Error( `writeStatic has been removed. Please ensure you are using the latest version of ${ config.kit.adapter.name || 'your adapter' @@ -153,7 +154,6 @@ export function create_builder({ config, build_data, prerendered, log }) { ); }, - // @ts-expect-error async prerender() { throw new Error( 'builder.prerender() has been removed. Prerendering now takes place in the build phase — see builder.prerender and builder.writePrerendered'