diff --git a/.changeset/angular-table-no-source-map-comment.md b/.changeset/angular-table-no-source-map-comment.md new file mode 100644 index 0000000000..1a4f47aeab --- /dev/null +++ b/.changeset/angular-table-no-source-map-comment.md @@ -0,0 +1,5 @@ +--- +'@tanstack/angular-table': patch +--- + +Remove the `sourceMappingURL` comment from the published `tanstack-angular-table.mjs` bundle. The package ships no source maps, so tools such as the Vite dev server failed to load the referenced `.map` file. diff --git a/packages/angular-table/package.json b/packages/angular-table/package.json index 43d7d9ee3e..c67154d794 100644 --- a/packages/angular-table/package.json +++ b/packages/angular-table/package.json @@ -54,7 +54,7 @@ "skills" ], "scripts": { - "build": "ng-packagr -p ng-package.json -c tsconfig.build.json && rimraf ./dist/package.json && find dist -name '*.map' -delete", + "build": "ng-packagr -p ng-package.json -c tsconfig.build.json && node ./scripts/postbuild.js", "build:types": "tsc --emitDeclarationOnly", "bench:flex-render": "vitest bench --run tests/flex-render/flex-render.bench.ts", "clean": "rimraf ./build && rimraf ./dist", diff --git a/packages/angular-table/scripts/postbuild.js b/packages/angular-table/scripts/postbuild.js new file mode 100644 index 0000000000..349fdc287a --- /dev/null +++ b/packages/angular-table/scripts/postbuild.js @@ -0,0 +1,37 @@ +import { readFile, readdir, rm, writeFile } from 'node:fs/promises' +import { join } from 'node:path' +import { fileURLToPath } from 'node:url' + +const distDir = fileURLToPath(new URL('../dist/', import.meta.url)) +const sourceMappingUrlComment = /\s*\/\/# sourceMappingURL=\S+\.map\s*$/ + +async function listDistFiles() { + const entries = await readdir(distDir, { + recursive: true, + withFileTypes: true, + }) + + return entries + .filter((entry) => entry.isFile()) + .map((entry) => join(entry.parentPath, entry.name)) +} + +async function removeSourceMappingUrlComment(file) { + const content = await readFile(file, 'utf8') + const contentWithoutComment = content.replace(sourceMappingUrlComment, '\n') + + if (contentWithoutComment !== content) { + await writeFile(file, contentWithoutComment) + } +} + +await rm(join(distDir, 'package.json'), { force: true }) + +const files = await listDistFiles() +const sourceMaps = files.filter((file) => file.endsWith('.map')) +const bundles = files.filter((file) => file.endsWith('.mjs')) + +await Promise.all([ + ...sourceMaps.map((file) => rm(file)), + ...bundles.map((file) => removeSourceMappingUrlComment(file)), +])