Skip to content

Commit

Permalink
remove redundant env (#5614)
Browse files Browse the repository at this point in the history
* remove redundant env

* changeset

* add meatier description

* huh, cant use those in comments, they get replaced dangerously
  • Loading branch information
Rich-Harris authored Jul 19, 2022
1 parent c2bf638 commit aa2faf3
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 45 deletions.
5 changes: 5 additions & 0 deletions .changeset/thick-chicken-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[breaking] remove mode, prod and server from \$app/env
19 changes: 1 addition & 18 deletions packages/kit/src/runtime/app/env.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
/* global __SVELTEKIT_BUILD__ */

/**
* @type {import('$app/env').browser}
*/
export const browser = !import.meta.env.SSR;

/**
* @type {import('$app/env').server}
*/
export const server = !!import.meta.env.SSR;

/**
* @type {import('$app/env').dev}
*/
export const dev = !__SVELTEKIT_BUILD__;

/**
* @type {import('$app/env').prod}
*/
export const prod = __SVELTEKIT_BUILD__;

/**
* @type {import('$app/env').mode}
*/
export const mode = import.meta.env.MODE;
export const dev = __SVELTEKIT_DEV__;

export { prerendering } from '../env.js';
2 changes: 1 addition & 1 deletion packages/kit/src/vite/build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const get_default_config = function ({ config, input, ssr, outDir }) {
__SVELTEKIT_APP_VERSION__: JSON.stringify(config.kit.version.name),
__SVELTEKIT_APP_VERSION_FILE__: JSON.stringify(`${config.kit.appDir}/version.json`),
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: JSON.stringify(config.kit.version.pollInterval),
__SVELTEKIT_BUILD__: 'true'
__SVELTEKIT_DEV__: 'false'
},
// prevent Vite copying the contents of `config.kit.files.assets`,
// if it happens to be 'public' instead of 'static'
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function kit() {
}
},
define: {
__SVELTEKIT_BUILD__: 'false',
__SVELTEKIT_DEV__: 'true',
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: '0'
},
resolve: {
Expand Down
6 changes: 2 additions & 4 deletions packages/kit/test/apps/options/source/pages/mode/index.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<script>
import { dev, mode as mode_from_import } from '$app/env';
import { dev } from '$app/env';
/** @type {string} */
export let mode_from_endpoint;
</script>

<h2>
{mode_from_endpoint} === {mode_from_import} === {import.meta.env.MODE} === {dev
? 'development'
: 'custom'}
{mode_from_endpoint} === {import.meta.env.MODE} === {dev ? 'development' : 'custom'}
</h2>
2 changes: 1 addition & 1 deletion packages/kit/test/apps/options/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,6 @@ test.describe('Vite options', () => {
await page.goto('/path-base/mode');

const mode = process.env.DEV ? 'development' : 'custom';
expect(await page.textContent('h2')).toBe(`${mode} === ${mode} === ${mode} === ${mode}`);
expect(await page.textContent('h2')).toBe(`${mode} === ${mode} === ${mode}`);
});
});
21 changes: 2 additions & 19 deletions packages/kit/types/ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ declare namespace App {

/**
* ```ts
* import { browser, dev, mode, prerendering, prod, server } from '$app/env';
* import { browser, dev, prerendering } from '$app/env';
* ```
*/
declare module '$app/env' {
Expand All @@ -75,31 +75,14 @@ declare module '$app/env' {
export const browser: boolean;

/**
* `true` in development mode, `false` in production.
* Whether the dev server is running. This is not guaranteed to correspond to `NODE_ENV` or `MODE`.
*/
export const dev: boolean;

/**
* The Vite.js mode the app is running in. Configure in [`vite.config.js`](https://vitejs.dev/config/shared-options.html#mode).
* Vite.js loads the dotenv file associated with the provided mode, `.env.[mode]` or `.env.[mode].local`.
* By default, `vite dev` runs with `mode=development` and `vite build` runs with `mode=production`.
*/
export const mode: string;

/**
* `true` when prerendering, `false` otherwise.
*/
export const prerendering: boolean;

/**
* `true` in production mode, `false` in development.
*/
export const prod: boolean;

/**
* `true` if the app is running on the server.
*/
export const server: boolean;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/types/internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,5 +323,5 @@ declare global {
const __SVELTEKIT_APP_VERSION__: string;
const __SVELTEKIT_APP_VERSION_FILE__: string;
const __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: number;
const __SVELTEKIT_BUILD__: boolean;
const __SVELTEKIT_DEV__: boolean;
}

0 comments on commit aa2faf3

Please sign in to comment.