chore: import upstream snapshot with attribution
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
import { createRequire } from 'node:module';
|
||||
import { readFileSync } from 'fs';
|
||||
|
||||
import { defineConfig } from 'tsdown';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const semver = require('semver') as typeof import('semver');
|
||||
|
||||
// Read package.json for version constants
|
||||
const packageJson = JSON.parse(readFileSync('./package.json', 'utf8'));
|
||||
|
||||
// Normalize the package.json engines range into comparator sets that the zero-dependency
|
||||
// CLI entrypoint can evaluate before importing any other modules.
|
||||
const enginesNode: string = packageJson.engines?.node ?? '>=20.0.0';
|
||||
let nodeEngineComparatorSets: Array<
|
||||
Array<{ operator: '' | '=' | '>' | '>=' | '<' | '<='; version: string }>
|
||||
>;
|
||||
try {
|
||||
nodeEngineComparatorSets = new semver.Range(enginesNode).set.map((comparatorSet) =>
|
||||
comparatorSet.map((comparator) => ({
|
||||
operator: comparator.operator,
|
||||
version: comparator.semver.version,
|
||||
})),
|
||||
);
|
||||
} catch {
|
||||
console.warn(
|
||||
`[tsdown] Warning: Could not parse engines.node "${enginesNode}". Defaulting to >=20.0.0.`,
|
||||
);
|
||||
nodeEngineComparatorSets = [[{ operator: '>=', version: '20.0.0' }]];
|
||||
}
|
||||
|
||||
// Build-time constants injected into all builds
|
||||
// These replace the __PROMPTFOO_*__ placeholders in source files
|
||||
// Note: tsdown define requires all values to be strings
|
||||
const versionDefines = {
|
||||
__PROMPTFOO_VERSION__: JSON.stringify(packageJson.version),
|
||||
__PROMPTFOO_POSTHOG_KEY__: JSON.stringify(process.env.PROMPTFOO_POSTHOG_KEY || ''),
|
||||
__PROMPTFOO_NODE_ENGINE_RANGE__: JSON.stringify(enginesNode),
|
||||
__PROMPTFOO_NODE_ENGINE_COMPARATOR_SETS__: JSON.stringify(nodeEngineComparatorSets),
|
||||
};
|
||||
|
||||
// All configs use clean: false. Use `npm run build:clean` for explicit cleaning.
|
||||
// This prevents race conditions when multiple configs share the same outDir.
|
||||
export default defineConfig([
|
||||
// Server (ESM only) - stable path for workflows
|
||||
{
|
||||
entry: { 'server/index': 'src/server/index.ts' },
|
||||
format: ['esm'],
|
||||
target: 'node20',
|
||||
outDir: 'dist/src',
|
||||
shims: true,
|
||||
sourcemap: true,
|
||||
clean: false,
|
||||
fixedExtension: false, // Use .js extension for ESM since package.json has type: module
|
||||
inlineOnly: false, // Disable warning about bundling dependencies
|
||||
define: {
|
||||
...versionDefines,
|
||||
BUILD_FORMAT: '"esm"',
|
||||
'process.env.BUILD_FORMAT': '"esm"',
|
||||
},
|
||||
external: [
|
||||
// Externalize all bare module imports so Node resolves CJS deps natively
|
||||
/^[a-z@][^:]*/,
|
||||
],
|
||||
},
|
||||
// CLI binary (ESM only)
|
||||
{
|
||||
entry: ['src/entrypoint.ts', 'src/main.ts'],
|
||||
format: ['esm'],
|
||||
target: 'node20',
|
||||
outDir: 'dist/src',
|
||||
clean: false,
|
||||
shims: true, // Provides __dirname, __filename shims automatically
|
||||
sourcemap: true,
|
||||
fixedExtension: false, // Use .js extension for ESM since package.json has type: module
|
||||
inlineOnly: false, // Disable warning about bundling dependencies
|
||||
define: {
|
||||
...versionDefines,
|
||||
BUILD_FORMAT: '"esm"',
|
||||
'process.env.BUILD_FORMAT': '"esm"',
|
||||
},
|
||||
outputOptions: {
|
||||
banner: '#!/usr/bin/env node',
|
||||
},
|
||||
external: [
|
||||
// Externalize all bare module imports so Node resolves CJS deps natively
|
||||
/^[a-z@][^:]*/,
|
||||
// Ensure critical native deps remain external
|
||||
'@huggingface/transformers',
|
||||
'playwright',
|
||||
'sharp',
|
||||
'@swc/core',
|
||||
'esbuild',
|
||||
'fsevents',
|
||||
],
|
||||
},
|
||||
// Library ESM build
|
||||
{
|
||||
entry: {
|
||||
contracts: 'src/contracts.ts',
|
||||
index: 'src/index.ts',
|
||||
},
|
||||
format: ['esm'],
|
||||
target: 'node20',
|
||||
outDir: 'dist/src',
|
||||
treeshake: true,
|
||||
sourcemap: true,
|
||||
shims: true, // Ensure library ESM build has shims
|
||||
clean: false,
|
||||
fixedExtension: false, // Use .js extension for ESM since package.json has type: module
|
||||
inlineOnly: false, // Disable warning about bundling dependencies
|
||||
define: {
|
||||
...versionDefines,
|
||||
BUILD_FORMAT: '"esm"',
|
||||
'process.env.BUILD_FORMAT': '"esm"',
|
||||
},
|
||||
external: [
|
||||
// Externalize all bare module imports so Node resolves CJS deps natively
|
||||
/^[a-z@][^:]*/,
|
||||
],
|
||||
},
|
||||
// Library CJS build for compatibility
|
||||
{
|
||||
entry: {
|
||||
contracts: 'src/contracts.ts',
|
||||
index: 'src/index.ts',
|
||||
},
|
||||
format: ['cjs'],
|
||||
target: 'node20',
|
||||
outDir: 'dist/src',
|
||||
sourcemap: true,
|
||||
clean: false,
|
||||
fixedExtension: true, // Use .cjs extension for CJS output
|
||||
inlineOnly: false, // Disable warning about bundling dependencies
|
||||
define: {
|
||||
...versionDefines,
|
||||
BUILD_FORMAT: '"cjs"',
|
||||
'process.env.BUILD_FORMAT': '"cjs"',
|
||||
},
|
||||
external: [
|
||||
// Externalize all bare module imports so Node resolves CJS deps natively
|
||||
/^[a-z@][^:]*/,
|
||||
],
|
||||
},
|
||||
]);
|
||||
Reference in New Issue
Block a user