Skip to content

Commit

Permalink
feat: enable sourcemap support
Browse files Browse the repository at this point in the history
The adapter-vercel package were not generating sourcemaps. Therefore, it was impossible to correctly use any bug tracking tool.
  • Loading branch information
ACHP committed Jun 22, 2022
1 parent a922095 commit 401036d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
6 changes: 5 additions & 1 deletion packages/adapter-vercel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export default {

// if true, will split your app into multiple functions
// instead of creating a single one for the entire app
split: false
split: false,

// same as esbuild sourcemap option
// https://esbuild.github.io/api/#sourcemap
sourcemap: false
})
}
};
Expand Down
2 changes: 2 additions & 0 deletions packages/adapter-vercel/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Adapter } from '@sveltejs/kit';
import type { BuildOptions } from 'esbuild';

type Options = {
edge?: boolean;
external?: string[];
split?: boolean;
sourcemap?: BuildOptions['sourcemap'];
};

export default function plugin(options?: Options): Adapter;
18 changes: 11 additions & 7 deletions packages/adapter-vercel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@ const redirects = {
const files = fileURLToPath(new URL('./files', import.meta.url).href);

/** @type {import('.').default} **/
export default function ({ external = [], edge, split } = {}) {
export default function ({ external = [], edge, split, sourcemap = false } = {}) {
return {
name: '@sveltejs/adapter-vercel',

async adapt(builder) {
if (process.env.ENABLE_VC_BUILD) {
await v3(builder, external, edge, split);
await v3(builder, external, edge, split, sourcemap);
} else {
if (edge || split) {
throw new Error('`edge` and `split` options can only be used with ENABLE_VC_BUILD');
}

await v1(builder, external);
await v1(builder, external, sourcemap);
}
}
};
Expand All @@ -105,8 +105,9 @@ export default function ({ external = [], edge, split } = {}) {
/**
* @param {import('@sveltejs/kit').Builder} builder
* @param {string[]} external
* @param {import('esbuild').BuildOptions['sourcemap']} sourcemap
*/
async function v1(builder, external) {
async function v1(builder, external, sourcemap) {
const node_version = get_node_version();

const dir = '.vercel_build_output';
Expand Down Expand Up @@ -146,7 +147,8 @@ async function v1(builder, external) {
bundle: true,
platform: 'node',
external,
format: 'cjs'
format: 'cjs',
sourcemap
});

fs.writeFileSync(`${dirs.lambda}/package.json`, JSON.stringify({ type: 'commonjs' }));
Expand Down Expand Up @@ -202,8 +204,9 @@ async function v1(builder, external) {
* @param {string[]} external
* @param {boolean} edge
* @param {boolean} split
* @param {import('esbuild').BuildOptions['sourcemap']} sourcemap
*/
async function v3(builder, external, edge, split) {
async function v3(builder, external, edge, split, sourcemap) {
const node_version = get_node_version();

const dir = '.vercel/output';
Expand Down Expand Up @@ -302,7 +305,8 @@ async function v3(builder, external, edge, split) {
bundle: true,
platform: 'node',
format: 'esm',
external
external,
sourcemap
});

write(
Expand Down

0 comments on commit 401036d

Please sign in to comment.