Skip to content

Commit

Permalink
experimental source maps
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoobes committed Aug 3, 2024
1 parent 70886c2 commit 24e97a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ type BuildOptions = {
* default to .env.
*/
env?: string;
/**
* flag: default false
*/
sourcemap?: boolean;

};

const CommandHandlerPlugin = (buildConfig: Partial<BuildOptions>, ambientFilePath: string, sernTsConfigPath: string) => {
Expand Down Expand Up @@ -76,6 +81,7 @@ export async function build(options: Record<string, any>) {
if (!options.supressWarnings) {
console.info(`${magentaBright('EXPERIMENTAL')}: This API has not been stabilized. add -W or --suppress-warnings flag to suppress`);
}
console.log(options)
const sernConfig = await getConfig();
let buildConfig: BuildOptions;
const buildConfigPath = p.resolve(options.project ?? 'sern.build.js');
Expand All @@ -85,6 +91,7 @@ export async function build(options: Record<string, any>) {
format: options.format ?? 'esm',
mode: options.mode ?? 'development',
dropLabels: [],
sourcemap: options.sourceMaps,
tsconfig: resolveBuildConfig(options.tsconfig, sernConfig.language),
env: options.env ?? '.env',
include: []
Expand Down Expand Up @@ -120,6 +127,7 @@ export async function build(options: Record<string, any>) {
console.log(' ', magentaBright('mode'), buildConfig.mode);
console.log(' ', magentaBright('tsconfig'), buildConfig.tsconfig);
console.log(' ', magentaBright('env'), buildConfig.env);
console.log(' ', magentaBright('sourceMaps'), buildConfig.sourcemap);

const sernDir = p.resolve('.sern'),
[ambientFilePath, sernTsConfigPath, genDir] =
Expand All @@ -139,6 +147,7 @@ export async function build(options: Record<string, any>) {
const ctx = await esbuild.context({
entryPoints,
plugins: [CommandHandlerPlugin(buildConfig, ambientFilePath, sernTsConfigPath)],
sourcemap: buildConfig.sourcemap,
...defaultEsbuild(buildConfig.format!, buildConfig.tsconfig),
dropLabels: [buildConfig.mode === 'production' ? '__DEV__' : '__PROD__', ...buildConfig.dropLabels!],
});
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ program
.option('-W --suppress-warnings', 'suppress experimental warning')
.option('-p --project [filePath]', 'build with the provided sern.build file')
.option('-e --env', 'path to .env file')
.option('--source-maps', 'Whether to add source-maps to configuration', false)
.option('--tsconfig [filePath]', 'Use this tsconfig')
.action(async (...args) => importDynamic('build.js').then((m) => m.build(...args)));

Expand Down

0 comments on commit 24e97a3

Please sign in to comment.