Skip to content

Commit

Permalink
rename $app/env to $app/environment (#6334)
Browse files Browse the repository at this point in the history
* rename $app/env to $app/environment - closes #5715

* Update .changeset/two-kings-worry.md

* finish the job

* missed a spot

* oops, search filters
  • Loading branch information
Rich-Harris authored Aug 27, 2022
1 parent 660ee4e commit 9b50590
Show file tree
Hide file tree
Showing 28 changed files with 44 additions and 37 deletions.
6 changes: 6 additions & 0 deletions .changeset/two-kings-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sveltejs/kit': patch
'create-svelte': patch
---

[breaking] rename `$app/env` to `$app/environment`, to disambiguate with `$env/...`
2 changes: 1 addition & 1 deletion documentation/docs/80-migrating.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ declare module 'html-minifier';
// @filename: index.js
// ---cut---
import { minify } from 'html-minifier';
import { prerendering } from '$app/env';
import { prerendering } from '$app/environment';

const minification_options = {
collapseBooleanAttributes: true,
Expand Down
2 changes: 1 addition & 1 deletion documentation/faq/80-integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ If you need access to the `document` or `window` variables or otherwise need cod
```js
/// <reference types="@sveltejs/kit" />
// ---cut---
import { browser } from '$app/env';
import { browser } from '$app/environment';

if (browser) {
// client-only code here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { browser, dev } from '$app/env';
import { browser, dev } from '$app/environment';

// we don't need any JS on this page, though we'll load
// it in dev so that we get hot module replacement...
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/sync/write_root.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function write_root(manifest_data, output) {
<!-- This file is generated by @sveltejs/kit — do not edit it! -->
<script>
import { setContext, afterUpdate, onMount } from 'svelte';
import { browser } from '$app/env';
import { browser } from '$app/environment';
// stores
export let stores;
Expand Down
12 changes: 1 addition & 11 deletions packages/kit/src/runtime/app/env.js
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
/**
* @type {import('$app/env').browser}
*/
export const browser = !import.meta.env.SSR;

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

export { prerendering } from '../env.js';
throw new Error('$app/env has been renamed to $app/environment');
11 changes: 11 additions & 0 deletions packages/kit/src/runtime/app/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @type {import('$app/environment').browser}
*/
export const browser = !import.meta.env.SSR;

/**
* @type {import('$app/environment').dev}
*/
export const dev = __SVELTEKIT_DEV__;

export { prerendering } from '../env.js';
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/app/stores.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getContext } from 'svelte';
import { browser } from './env.js';
import { browser } from './environment.js';
import { stores as browser_stores } from '../client/singletons.js';

// TODO remove this (for 1.0? after 1.0?)
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/test/apps/amp/src/routes/valid/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { browser, dev } from '$app/env';
import { browser, dev } from '$app/environment';
/** @type {import('./$types').PageData} */
export let data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { browser } from '$app/env';
import { browser } from '$app/environment';
export let errors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { browser } from '$app/env';
import { browser } from '$app/environment';
if (browser) {
throw new Error('Crashing now');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { browser } from '$app/env';
import { browser } from '$app/environment';

/** @type {import('@sveltejs/kit').Load} */
export async function load() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script context="module">
import { browser } from '$app/env';
import { browser } from '$app/environment';
if (browser) {
throw new Error('Crashing now');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script context="module">
import { dev } from '$app/env';
import { dev } from '$app/environment';
if (dev) { // can't throw in prod, the app won't start at all
throw new Error('Crashing now');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { dev } from '$app/env';
import { dev } from '$app/environment';
if (dev) { // can't throw in prod, the app won't start at all
throw new Error('Crashing now');
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/test/apps/basics/src/routes/load/+page.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { browser } from '$app/env';
import { browser } from '$app/environment';

/** @type {import('@sveltejs/kit').Load} */
export function load(pageContext) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { browser } from '$app/env';
import { browser } from '$app/environment';

let count = 0;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { browser } from '$app/env';
import { browser } from '$app/environment';

/** @type {import('@sveltejs/kit').Load} */
export async function load({ fetch }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { redirect } from '@sveltejs/kit';
import { browser } from '$app/env';
import { browser } from '$app/environment';

export async function load() {
if (browser) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { browser } from '$app/env';
import { browser } from '$app/environment';

/** @type {import('@sveltejs/kit').Load} */
export async function load() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { browser, dev } from '$app/env';
import { browser, dev } from '$app/environment';
</script>

<p>Hello from the {browser ? 'client' : 'server'} in {dev ? 'dev' : 'prod'} mode!</p>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { dev } from '$app/env';
import { dev } from '$app/environment';
/** @type {import('./$types').PageData} */
export let data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script context="module">
import { browser } from '$app/env';
import { browser } from '$app/environment';
if (browser) {
window.mounted = window.mounted || 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/test/prerendering/basics/src/hooks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { prerendering } from '$app/env';
import { prerendering } from '$app/environment';

const initial_prerendering = prerendering;

Expand Down
4 changes: 2 additions & 2 deletions packages/kit/types/ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ declare namespace App {

/**
* ```ts
* import { browser, dev, prerendering } from '$app/env';
* import { browser, dev, prerendering } from '$app/environment';
* ```
*/
declare module '$app/env' {
declare module '$app/environment' {
/**
* `true` if the app is running in the browser.
*/
Expand Down
2 changes: 1 addition & 1 deletion sites/kit.svelte.dev/src/lib/search/Search.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { browser } from '$app/env';
import { browser } from '$app/environment';
import { searching, query } from './stores.js';
export let q = '';
Expand Down
2 changes: 1 addition & 1 deletion sites/kit.svelte.dev/src/routes/+error.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { dev } from '$app/env';
import { dev } from '$app/environment';
import { page } from '$app/stores';
// we don't want to use <svelte:window bind:online> here, because we only care about the online
Expand Down
2 changes: 1 addition & 1 deletion sites/kit.svelte.dev/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import '@sveltejs/site-kit/base.css';
import { browser } from '$app/env';
import { browser } from '$app/environment';
import { page, navigating } from '$app/stores';
import { Icon, Icons, Nav, NavItem, PreloadingIndicator, SkipLink } from '@sveltejs/site-kit';
import Search from '$lib/search/Search.svelte';
Expand Down

0 comments on commit 9b50590

Please sign in to comment.