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

fix: mark ScanEnvironment internal #18008

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 9 additions & 5 deletions packages/vite/rollup.dts.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,15 @@ function removeInternal(s: MagicString, node: any): boolean {
})
) {
// Examples:
// function a(foo: string, /* @internal */ bar: number)
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^
// strip trailing comma
const end = s.original[node.end] === ',' ? node.end + 1 : node.end
s.remove(node.leadingComments[0].start, end)
// function a(foo: string, /* @internal */ bar: number, baz: boolean)
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// type Enum = Foo | /* @internal */ Bar | Baz
// ^^^^^^^^^^^^^^^^^^^^^
// strip trailing comma or pipe
const trailingRe = /\s*[,|]/y
trailingRe.lastIndex = node.end
const trailingStr = trailingRe.exec(s.original)?.[0] ?? ''
s.remove(node.leadingComments[0].start, node.end + trailingStr.length)
return true
}
return false
Expand Down
30 changes: 19 additions & 11 deletions packages/vite/src/node/baseEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import type { Logger } from './logger'
import type { ResolvedConfig, ResolvedEnvironmentOptions } from './config'
import type { Plugin } from './plugin'

const environmentColors = [
colors.blue,
colors.magenta,
colors.green,
colors.gray,
]

export class PartialEnvironment {
name: string
getTopLevelConfig(): ResolvedConfig {
Expand Down Expand Up @@ -122,16 +129,17 @@ export class BaseEnvironment extends PartialEnvironment {
}

/**
* This is used both to avoid users to hardcode conditions like
* !scan && !build => dev
* This class discourages users from inversely checking the `mode`
* to determine the type of environment, e.g.
*
* ```js
* const isDev = environment.mode !== 'build' // bad
* const isDev = environment.mode === 'dev' // good
* ```
*
* You should also not check against `"unknown"` specfically. It's
* a placeholder for more possible environment types.
*/
export class FutureCompatEnvironment extends BaseEnvironment {
mode = 'futureCompat' as const
export class UnknownEnvironment extends BaseEnvironment {
mode = 'unknown' as const
}

const environmentColors = [
colors.blue,
colors.magenta,
colors.green,
colors.gray,
]
6 changes: 3 additions & 3 deletions packages/vite/src/node/environment.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { DevEnvironment } from './server/environment'
import type { BuildEnvironment } from './build'
import type { ScanEnvironment } from './optimizer/scan'
import type { FutureCompatEnvironment } from './baseEnvironment'
import type { UnknownEnvironment } from './baseEnvironment'
import type { PluginContext } from './plugin'

export type Environment =
| DevEnvironment
| BuildEnvironment
| ScanEnvironment
| FutureCompatEnvironment
| /** @internal */ ScanEnvironment
| UnknownEnvironment

/**
* Creates a function that hides the complexities of a WeakMap with an initial value
Expand Down