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

[breaking] remove warnings/errors about removed/changed APIs #8019

Merged
merged 5 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
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 @@ -30,6 +30,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 @@ -146,39 +163,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 @@ -74,9 +66,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