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
4 changes: 4 additions & 0 deletions .github/workflows/reusable-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ jobs:
if: ${{ steps.changes.outputs.changed == 'true' && inputs.task == 'integration' }}
run: pnpm run test:integration

- name: Integration Test For Executable (Rstest)
if: ${{ steps.changes.outputs.changed == 'true' && inputs.task == 'integration-exe' }}
run: pnpm run test:integration:exe

- name: E2E Test (Playwright)
if: ${{ steps.changes.outputs.changed == 'true' && inputs.task == 'e2e' }}
run: pnpm run test:e2e
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ jobs:
node-version: ${{ matrix.node-version }}
task: integration

integration-exe:
strategy:
matrix:
runner: [ubuntu-latest, windows-latest]
node-version: ['25']

uses: ./.github/workflows/reusable-test.yml
with:
runner: ${{ matrix.runner }}
node-version: ${{ matrix.node-version }}
task: integration-exe

e2e:
strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v24.5.0
v25.9.0
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"test:e2e": "pnpm run build:examples && cd tests && pnpm run test:e2e",
"test:ecosystem-ci": "pnpm run test:unit && cross-env ECO_CI=1 pnpm run test:integration && pnpm run test:e2e",
"test:integration": "rstest run --project integration",
"test:integration:exe": "rstest run --project integration-exe",
"test:unit": "rstest run --project unit*",
"testu": "pnpm run test:unit -u && pnpm run test:integration -u",
"type-check": "pnpm -r run type-check",
Expand Down
24 changes: 17 additions & 7 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
RSLIB_CSS_ENTRY_FLAG,
} from './css/cssConfig';
import { type CssLoaderOptionsAuto, isCssGlobalFile } from './css/utils';
import { composeExeConfig } from './exe';
import { composeEntryChunkConfig } from './plugins/EntryChunkPlugin';
import { pluginCjsShims, pluginEsmRequireShim } from './plugins/shims';
import type {
Expand Down Expand Up @@ -1726,7 +1727,9 @@ async function composeLibRsbuildConfig(
externalHelpers = false,
redirect = {},
umdName,
experiments = {},
} = config;
const hasExe = Boolean(experiments.exe);
const { rsbuildConfig: bundleConfig } = composeBundleConfig(bundle);
const { rsbuildConfig: shimsConfig, enabledShims } = composeShimsConfig(
format,
Expand All @@ -1747,14 +1750,12 @@ async function composeLibRsbuildConfig(
multiCompilerIndex,
sourceEntry: config.source?.entry,
});
const userExternals = hasExe ? undefined : config.output?.externals;
const externalHelpersConfig = composeExternalHelpersConfig(
externalHelpers,
hasExe ? false : externalHelpers,
pkgJson,
);
const userExternalsConfig = composeExternalsConfig(
format,
config.output?.externals,
);
const userExternalsConfig = composeExternalsConfig(format, userExternals);
const {
config: outputFilenameConfig,
jsExtension,
Expand All @@ -1774,6 +1775,14 @@ async function composeLibRsbuildConfig(
cssModulesAuto,
config.outBase,
);
const { config: exeConfig } = composeExeConfig({
bundle,
exe: experiments.exe,
format,
root,
sourceEntry: entryConfig.source?.entry,
target,
});

const { config: bundlelessExternalConfig } = composeBundlelessExternalConfig(
jsExtension,
Expand All @@ -1786,9 +1795,9 @@ async function composeLibRsbuildConfig(
const autoExternalConfig = composeAutoExternalConfig({
bundle,
format,
autoExternal,
autoExternal: hasExe ? false : autoExternal,
pkgJson,
userExternals: config.output?.externals,
userExternals,
});
const cssConfig = composeCssConfig(
outBase,
Expand Down Expand Up @@ -1848,6 +1857,7 @@ async function composeLibRsbuildConfig(
bannerFooterConfig,
decoratorsConfig,
printFileSizeConfig,
exeConfig,
);
}

Expand Down
74 changes: 74 additions & 0 deletions packages/core/src/exe/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import fs from 'node:fs';
import os from 'node:os';
import path, { dirname, join } from 'node:path';
import type { Format, SeaOptions } from '../types';
import type { ExePlatform } from '../types';
import { maybeSignMacBinary, runCommand } from './utils';

export const buildExecutable = async ({
builderBinaryPath,
executablePath,
executableBinaryPath,
mainFile,
format,
root,
seaOptions,
targetPlatform,
}: {
builderBinaryPath: string;
executablePath: string;
executableBinaryPath: string;
mainFile: string;
format: Extract<Format, 'esm' | 'cjs'>;
root: string;
seaOptions: SeaOptions;
targetPlatform: ExePlatform;
}): Promise<void> => {
const tempDir = await fs.promises.mkdtemp(join(os.tmpdir(), 'rslib-sea-'));

try {
await fs.promises.mkdir(dirname(executablePath), { recursive: true });

const seaConfigPath = join(tempDir, 'sea-config.json');
const seaConfig = {
main: mainFile,
mainFormat: format === 'esm' ? 'module' : 'commonjs',
output: executablePath,
executable: executableBinaryPath,
disableExperimentalSEAWarning:
seaOptions.disableExperimentalSEAWarning ?? true,
...(seaOptions.useSnapshot ? { useSnapshot: true } : {}),
...(seaOptions.useCodeCache ? { useCodeCache: true } : {}),
...(seaOptions.execArgv ? { execArgv: seaOptions.execArgv } : {}),
...(seaOptions.execArgvExtension
? { execArgvExtension: seaOptions.execArgvExtension }
: {}),
...(seaOptions.assets
? {
assets: Object.fromEntries(
Object.entries(seaOptions.assets).map(([key, value]) => [
key,
path.resolve(root, value),
]),
),
}
: {}),
};

await fs.promises.writeFile(
seaConfigPath,
`${JSON.stringify(seaConfig, null, 2)}\n`,
);

await runCommand(builderBinaryPath, ['--build-sea', seaConfigPath]);

if (targetPlatform === 'darwin') {
await maybeSignMacBinary(executablePath);
}
} finally {
await fs.promises.rm(tempDir, {
recursive: true,
force: true,
});
}
};
Loading