Skip to content

Commit

Permalink
[breaking] remove warnings/errors about removed/changed APIs (#8019)
Browse files Browse the repository at this point in the history
* remove stuff

* missed a spot

* changeset

* oops
  • Loading branch information
Rich-Harris authored Dec 14, 2022
1 parent 0e76422 commit f42604a
Show file tree
Hide file tree
Showing 26 changed files with 53 additions and 798 deletions.
8 changes: 8 additions & 0 deletions .changeset/forty-apricots-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@sveltejs/adapter-cloudflare': patch
'@sveltejs/adapter-cloudflare-workers': patch
'@sveltejs/adapter-node': patch
'@sveltejs/kit': patch
---

[breaking] remove warnings/errors about removed/changed APIs
7 changes: 0 additions & 7 deletions packages/adapter-cloudflare-workers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ import { fileURLToPath } from 'url';

/** @type {import('.').default} */
export default function ({ config = 'wrangler.toml' } = {}) {
// TODO remove for 1.0
if (arguments.length > 0) {
throw new Error(
'esbuild options can no longer be passed to adapter-cloudflare-workers — see https://github.com/sveltejs/kit/pull/4639'
);
}

return {
name: '@sveltejs/adapter-cloudflare-workers',

Expand Down
7 changes: 0 additions & 7 deletions packages/adapter-cloudflare/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ import * as esbuild from 'esbuild';

/** @type {import('.').default} */
export default function () {
// TODO remove for 1.0
if (arguments.length > 0) {
throw new Error(
'esbuild options can no longer be passed to adapter-cloudflare — see https://github.com/sveltejs/kit/pull/4639'
);
}

return {
name: '@sveltejs/adapter-cloudflare',
async adapt(builder) {
Expand Down
8 changes: 0 additions & 8 deletions packages/adapter-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ const files = fileURLToPath(new URL('./files', import.meta.url).href);

/** @type {import('.').default} */
export default function (opts = {}) {
// TODO remove for 1.0
// @ts-expect-error
if (opts.env) {
throw new Error(
'options.env has been removed in favour of options.envPrefix. Consult the adapter-node README: https://github.com/sveltejs/kit/tree/master/packages/adapter-node'
);
}

const { out = 'build', precompress, envPrefix = '' } = opts;

return {
Expand Down
64 changes: 0 additions & 64 deletions packages/kit/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@ prog
.describe('Synchronise generated files')
.option('--mode', 'Specify a mode for loading environment variables', 'development')
.action(async ({ mode }) => {
const event = process.env.npm_lifecycle_event;

// TODO remove for 1.0
if (event === 'prepare') {
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
const message =
pkg.scripts.prepare === 'svelte-kit sync'
? `\`svelte-kit sync\` now runs on "postinstall" — please remove the "prepare" script from your package.json\n`
: `\`svelte-kit sync\` now runs on "postinstall" — please remove it from your "prepare" script\n`;

console.error(colors.bold().red(message));
return;
}

if (!fs.existsSync('svelte.config.js')) {
console.warn(`Missing ${path.resolve('svelte.config.js')} — skipping`);
return;
Expand All @@ -55,54 +41,4 @@ prog
}
});

// TODO remove for 1.0
replace('dev');
replace('build');
replace('preview');
prog
.command('package')
.describe('No longer available - use @sveltejs/package instead')
.action(() => {
console.error(
'svelte-kit package has been removed. It now lives in its own npm package. See the PR on how to migrate: https://github.com/sveltejs/kit/pull/5730'
);
});

prog.parse(process.argv, { unknown: (arg) => `Unknown option: ${arg}` });

/** @param {string} command */
function replace(command) {
prog
.command(command)
.describe(`No longer available — use vite ${command} instead`)
.action(async () => {
const message = `\n> svelte-kit ${command} is no longer available — use vite ${command} instead`;
console.error(colors.bold().red(message));

const steps = [
'Install vite as a devDependency with npm/pnpm/etc',
'Create a vite.config.js with the @sveltejs/kit/vite plugin (see below)',
`Update your package.json scripts to reference \`vite ${command}\` instead of \`svelte-kit ${command}\``
];

steps.forEach((step, i) => {
console.error(` ${i + 1}. ${colors.cyan(step)}`);
});

console.error(
`
${colors.grey('// vite.config.js')}
import { sveltekit } from '@sveltejs/kit/vite';
/** @type {import('vite').UserConfig} */
const config = {
plugins: [sveltekit()]
};
export default config;
`.replace(/^\t{4}/gm, '')
);
process.exit(1);
});
}
50 changes: 17 additions & 33 deletions packages/kit/src/core/adapt/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ export function create_builder({ config, build_data, routes, prerendered, log })
config,
prerendered,

async compress(directory) {
if (!existsSync(directory)) {
return;
}

const files = await glob('**/*.{html,js,json,css,svg,xml,wasm}', {
cwd: directory,
dot: true,
absolute: true,
filesOnly: true
});

await Promise.all(
files.map((file) => Promise.all([compress_file(file, 'gz'), compress_file(file, 'br')]))
);
},

async createEntries(fn) {
/** @type {import('types').RouteDefinition[]} */
const facades = routes.map((route) => {
Expand Down Expand Up @@ -177,39 +194,6 @@ export function create_builder({ config, build_data, routes, prerendered, log })

writeServer(dest) {
return copy(`${config.kit.outDir}/output/server`, dest);
},

// TODO remove these methods for 1.0
// @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'
}`
);
},

async compress(directory) {
if (!existsSync(directory)) {
return;
}

const files = await glob('**/*.{html,js,json,css,svg,xml,wasm}', {
cwd: directory,
dot: true,
absolute: true,
filesOnly: true
});

await Promise.all(
files.map((file) => Promise.all([compress_file(file, 'gz'), compress_file(file, 'br')]))
);
},

async prerender() {
throw new Error(
'builder.prerender() has been removed. Prerendering now takes place in the build phase — see builder.prerender and builder.writePrerendered'
);
}
};
}
Expand Down
11 changes: 0 additions & 11 deletions packages/kit/src/core/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ export function load_template(cwd, config) {
if (fs.existsSync(appTemplate)) {
const contents = fs.readFileSync(appTemplate, 'utf8');

// TODO remove this for 1.0
const match = /%svelte\.([a-z]+)%/.exec(contents);
if (match) {
throw new Error(
`%svelte.${match[1]}% in ${relative} should be replaced with %sveltekit.${match[1]}%`
);
}

const expected_tags = ['%sveltekit.head%', '%sveltekit.body%'];
expected_tags.forEach((tag) => {
if (contents.indexOf(tag) === -1) {
Expand Down Expand Up @@ -81,9 +73,6 @@ function process_config(config, { cwd = process.cwd() } = {}) {
validated.kit.outDir = path.resolve(cwd, validated.kit.outDir);

for (const key in validated.kit.files) {
// TODO remove for 1.0
if (key === 'template') continue;

if (key === 'hooks') {
validated.kit.files.hooks.client = path.resolve(cwd, validated.kit.files.hooks.client);
validated.kit.files.hooks.server = path.resolve(cwd, validated.kit.files.hooks.server);
Expand Down
32 changes: 3 additions & 29 deletions packages/kit/src/core/config/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,7 @@ const get_defaults = (prefix = '') => ({
kit: {
adapter: null,
alias: {},
amp: undefined,
appDir: '_app',
browser: {
hydrate: undefined,
router: undefined
},
csp: {
mode: 'auto',
directives: directive_defaults,
Expand All @@ -75,7 +70,6 @@ const get_defaults = (prefix = '') => ({
csrf: {
checkOrigin: true
},
endpointExtensions: undefined,
embedded: false,
env: {
dir: process.cwd(),
Expand All @@ -92,14 +86,9 @@ const get_defaults = (prefix = '') => ({
routes: join(prefix, 'src/routes'),
serviceWorker: join(prefix, 'src/service-worker'),
appTemplate: join(prefix, 'src/app.html'),
errorTemplate: join(prefix, 'src/error.html'),
template: undefined
errorTemplate: join(prefix, 'src/error.html')
},
headers: undefined,
host: undefined,
hydrate: undefined,
inlineStyleThreshold: 0,
methodOverride: undefined,
moduleExtensions: ['.js', '.ts'],
outDir: join(prefix, '.svelte-kit'),
serviceWorker: {
Expand All @@ -112,30 +101,15 @@ const get_defaults = (prefix = '') => ({
prerender: {
concurrency: 1,
crawl: true,
createIndexFiles: undefined,
default: undefined,
enabled: undefined,
entries: ['*'],
force: undefined,
handleHttpError: 'fail',
handleMissingId: 'fail',
onError: undefined,
origin: 'http://sveltekit-prerender',
pages: undefined
origin: 'http://sveltekit-prerender'
},
protocol: undefined,
router: undefined,
routes: undefined,
ssr: undefined,
target: undefined,
trailingSlash: undefined,
version: {
name: Date.now().toString(),
pollInterval: 0
},
// TODO cleanup for 1.0
vite: undefined,
package: undefined
}
}
});

Expand Down
Loading

0 comments on commit f42604a

Please sign in to comment.