Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/open-oranges-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/rspeedy": patch
---

Support cli option `--no-env` to disable loading of .env files
2 changes: 1 addition & 1 deletion .github/actions/setup-playwright/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ runs:
echo "version=$(pnpm ls @playwright/test --depth=0 --parseable | grep @playwright | sed -E 's/.*@([0-9]+\.[0-9]+\.[0-9]+).*/\1/')" >> "$GITHUB_OUTPUT"
shell: bash
- name: Cache Playwright
uses: lynx-infra/cache@ad9f115f5b15348eb208a52ec6f7ffa82e8108df
uses: lynx-infra/cache@558d7c999f9f97ac02ed7e711503bb81d82ff8ee
id: playwright-cache
with:
path: ${{ (runner.os == 'Linux' && '~/.cache/ms-playwright') || '~/Library/Caches/ms-playwright' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"groupSlug": "typia",
"matchPackageNames": [
"typia",
"rspack-plugin-typia",
"typia-rspack-plugin",
"@samchon/openapi",
],
"automerge": false,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/workflow-bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
corepack enable
pnpm install --frozen-lockfile
- name: TurboCache
uses: lynx-infra/cache@ad9f115f5b15348eb208a52ec6f7ffa82e8108df
uses: lynx-infra/cache@558d7c999f9f97ac02ed7e711503bb81d82ff8ee
with:
path: .turbo
# We have to be strict here to make sure getting the cache of build-all
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/workflow-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
with:
node-version: "22"
- name: TurboCache
uses: lynx-infra/cache@ad9f115f5b15348eb208a52ec6f7ffa82e8108df
uses: lynx-infra/cache@558d7c999f9f97ac02ed7e711503bb81d82ff8ee
with:
path: .turbo
key: turbo-v3-${{ hashFiles('**/packages/**/src/**/*.rs') }}-${{ github.sha }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/workflow-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
with:
node-version: "22"
- name: TurboCache
uses: lynx-infra/cache@ad9f115f5b15348eb208a52ec6f7ffa82e8108df
uses: lynx-infra/cache@558d7c999f9f97ac02ed7e711503bb81d82ff8ee
with:
path: .turbo
# We have to be strict here to make sure getting the cache of build-all
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/workflow-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
node-version: "22"
- name: TurboCache
uses: lynx-infra/cache@ad9f115f5b15348eb208a52ec6f7ffa82e8108df
uses: lynx-infra/cache@558d7c999f9f97ac02ed7e711503bb81d82ff8ee
with:
path: .turbo
key: turbo-v3-${{ hashFiles('**/packages/**/src/**/*.rs') }}-${{ github.sha }}
Expand Down
4 changes: 3 additions & 1 deletion packages/rspeedy/core/src/cli/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export async function build(
rspeedyConfig,
}

if (buildOptions.envMode) {
if (buildOptions.noEnv) {
options.loadEnv = false
} else if (buildOptions.envMode) {
options.loadEnv = { mode: buildOptions.envMode }
}

Expand Down
7 changes: 6 additions & 1 deletion packages/rspeedy/core/src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { version } from '../version.js'
export interface CommonOptions {
config?: string
envMode?: string
noEnv?: boolean
}

function applyCommonOptions(command: Command) {
Expand All @@ -23,7 +24,11 @@ function applyCommonOptions(command: Command) {
)
.option(
'--env-mode <mode>',
'specify the env mode to load the .env.[mode] file"',
'specify the env mode to load the .env.[mode] file',
)
.option(
'--no-env',
'disable loading `.env` files"',
)
}

Expand Down
4 changes: 3 additions & 1 deletion packages/rspeedy/core/src/cli/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ export async function dev(
rspeedyConfig,
}

if (devOptions.envMode) {
if (devOptions.noEnv) {
options.loadEnv = false
} else if (devOptions.envMode) {
options.loadEnv = { mode: devOptions.envMode }
}

Expand Down
16 changes: 11 additions & 5 deletions packages/rspeedy/core/src/cli/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { CommonOptions } from './commands.js'
import { exit } from './exit.js'
import { loadConfig } from '../config/loadConfig.js'
import { createRspeedy } from '../create-rspeedy.js'
import type { CreateRspeedyOptions } from '../create-rspeedy.js'

export interface InspectOptions extends CommonOptions {
mode?: 'production' | 'development' | undefined
Expand All @@ -28,13 +29,18 @@ export async function inspect(
configPath: inspectOptions.config,
})

const rspeedy = await createRspeedy({
const options: CreateRspeedyOptions = {
cwd,
rspeedyConfig,
...(inspectOptions.envMode
? { loadEnv: { mode: inspectOptions.envMode } }
: {}),
})
}

if (inspectOptions.noEnv) {
options.loadEnv = false
} else if (inspectOptions.envMode) {
options.loadEnv = { mode: inspectOptions.envMode }
}

const rspeedy = await createRspeedy(options)

await rspeedy.inspectConfig({
mode: inspectOptions.mode
Expand Down
16 changes: 11 additions & 5 deletions packages/rspeedy/core/src/cli/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { CommonOptions } from './commands.js'
import { exit } from './exit.js'
import { loadConfig, resolveConfigPath } from '../config/loadConfig.js'
import { createRspeedy } from '../create-rspeedy.js'
import type { CreateRspeedyOptions } from '../create-rspeedy.js'

export interface PreviewOptions extends CommonOptions {
base?: string | undefined
Expand All @@ -34,13 +35,18 @@ export async function preview(
rspeedyConfig.server.base = previewOptions.base
}

const rspeedy = await createRspeedy({
const options: CreateRspeedyOptions = {
cwd,
rspeedyConfig,
...(previewOptions.envMode
? { loadEnv: { mode: previewOptions.envMode } }
: {}),
})
}

if (previewOptions.noEnv) {
options.loadEnv = false
} else if (previewOptions.envMode) {
options.loadEnv = { mode: previewOptions.envMode }
}

const rspeedy = await createRspeedy(options)

await rspeedy.initConfigs()

Expand Down
30 changes: 30 additions & 0 deletions packages/rspeedy/core/test/cli/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,36 @@ describe('rspeedy config test', () => {
}),
)
})

test('createRspeedy with no-env ', async () => {
const root = join(fixturesRoot, 'project-with-env')
const rsbuild = await createRspeedy({
cwd: root,
loadEnv: false,
})
const configs = await rsbuild.initConfigs()
const maybeDefinePluginInstance = configs[0]?.plugins?.filter((plugin) => {
if (plugin) {
return plugin.name === 'DefinePlugin'
} else {
return false
}
})

expect(maybeDefinePluginInstance).toHaveLength(1)
const defineInstance = maybeDefinePluginInstance![0]

expect(defineInstance!).toMatchObject(
expect.objectContaining({
_args: [
expect.not.objectContaining({
'process.env.PUBLIC_FOO': '"BAR"',
'process.env.PUBLIC_TEST': '"TEST"',
}),
],
}),
)
})
})

describe('rspeedy environment test', () => {
Expand Down
Loading