From 28d6b83b56c1c54e9a925b98b406701cd5c2686e Mon Sep 17 00:00:00 2001 From: Espen Hovlandsdal Date: Tue, 24 Sep 2024 09:25:46 -0700 Subject: [PATCH] chore: enable source maps for package bundles --- .../@repo/package.bundle/src/package.bundle.ts | 1 + scripts/uploadBundles.ts | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/@repo/package.bundle/src/package.bundle.ts b/packages/@repo/package.bundle/src/package.bundle.ts index 764ac5f344c..b2279926495 100644 --- a/packages/@repo/package.bundle/src/package.bundle.ts +++ b/packages/@repo/package.bundle/src/package.bundle.ts @@ -15,6 +15,7 @@ export const defaultConfig: UserConfig = { plugins: [react(), tsconfigPaths()], build: { emptyOutDir: true, + sourcemap: true, lib: { entry: {}, formats: ['es'], diff --git a/scripts/uploadBundles.ts b/scripts/uploadBundles.ts index de62852561f..89464a09e0d 100644 --- a/scripts/uploadBundles.ts +++ b/scripts/uploadBundles.ts @@ -19,6 +19,11 @@ const corePkgs = ['sanity', '@sanity/vision'] as const const appVersion = 'v1' +const mimeTypes: Record = { + '.mjs': 'application/javascript', + '.map': 'application/json', +} + /** * Replaces all slashes with double underscores */ @@ -60,16 +65,22 @@ async function copyPackages() { packageVersions.set(pkg, version) // Convert slashes to double underscores - // Needed for `@sanity/vision` + // Needed for `@sanity/vision` and other scoped packages const cleanDir = cleanDirName(pkg) for await (const filePath of getFiles(`packages/${pkg}/dist`)) { try { const fileName = path.basename(filePath) + const ext = path.extname(fileName) + const contentType = mimeTypes[ext] + if (!contentType) { + throw new Error(`Unknown content type for file ${filePath}`) + } + const options: UploadOptions = { destination: `modules/${appVersion}/${cleanDir}/${version}/bare/${fileName}`, gzip: true, - contentType: 'application/javascript', + contentType, metadata: { // 1 year cache cacheControl: 'public, max-age=31536000, immutable',