chore: allow multiple entrypoints for both runify and the dev config (#4791)

This commit is contained in:
Laurin Quast 2024-05-21 11:39:37 +02:00 committed by GitHub
parent 290f5ae8c4
commit 3540722f29
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 4 deletions

View file

@ -1,3 +1,4 @@
import { parseArgs } from 'node:util';
import { defineConfig } from 'tsup';
import {
commonWatchList,
@ -6,7 +7,13 @@ import {
watchEntryPlugin,
} from './utils';
const entryPoints = parseArgs({
allowPositionals: true,
strict: false,
}).positionals;
export default defineConfig({
entryPoints: entryPoints.length ? entryPoints : ['src/index.ts'],
splitting: false,
sourcemap: true,
clean: true,

View file

@ -2,6 +2,7 @@
// The idea here is to compile a node service to a single file (not in case of next) and make it executable.
import { join, normalize, resolve, sep } from 'node:path';
import { fileURLToPath } from 'node:url';
import { parseArgs } from 'node:util';
import fs from 'fs-extra';
import { build as tsup } from 'tsup';
@ -9,7 +10,10 @@ const __dirname = fileURLToPath(new URL('.', import.meta.url));
const requireShim = fs.readFileSync(normalize(join(__dirname, './banner.js')), 'utf-8');
const [, , entryPoint] = process.argv;
const entryPoints = parseArgs({
allowPositionals: true,
strict: false,
}).positionals;
interface BuildOptions {
external?: string[];
@ -37,7 +41,7 @@ async function runify(packagePath: string) {
} else {
await compile(
cwd,
entryPoint ?? 'src/index.ts',
entryPoints?.length ? entryPoints : 'src/index.ts',
buildOptions,
Object.keys(pkg.dependencies ?? {}).concat(Object.keys(pkg.devDependencies ?? {})),
pkg.type === 'module',
@ -122,7 +126,7 @@ async function buildWithNext(cwd: string, additionalRequire: string | null) {
async function compile(
cwd: string,
entryPoint: string,
entryPoint: string | string[],
buildOptions: BuildOptions,
dependencies: string[],
useEsm = false,
@ -130,7 +134,9 @@ async function compile(
const out = normalize(join(cwd, 'dist'));
await tsup({
entryPoints: [normalize(join(cwd, entryPoint))],
entryPoints: (Array.isArray(entryPoint) ? entryPoint : [entryPoint]).map(entryPoint =>
normalize(join(cwd, entryPoint)),
),
outDir: out,
target: 'node21',
format: [useEsm ? 'esm' : 'cjs'],