Skip to content

Commit 1c2f10d

Browse files
committed
build: ensure resolved source map url is absolute
- https://sourcemaps.info/spec.html Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent 2c26647 commit 1c2f10d

File tree

2 files changed

+5
-64
lines changed

2 files changed

+5
-64
lines changed

build.config.ts

+4-62
Original file line numberDiff line numberDiff line change
@@ -19,74 +19,16 @@ const config: Config = defineBuildConfig({
1919
charset: 'utf8',
2020
entries: [
2121
{ dts: 'only' },
22-
{ dts: false, pattern: ['**/index.ts', 'enums/*', 'internal/*'] },
22+
{ dts: false, pattern: ['(interfaces|types)/index.ts', 'enums/*'] },
2323
{
2424
dts: false,
25-
pattern: ['index.ts', 'utils/*'],
26-
sourceRoot: pathe.join(
27-
pkg.repository.replace(/\.git$/, pathe.sep + 'blob'),
28-
pkg.tagPrefix + pkg.version
29-
),
30-
sourcemap: true,
31-
sourcesContent: false
25+
pattern: ['index.ts', 'internal/*', 'utils/*'],
26+
sourceRoot: 'file' + pathe.delimiter + pathe.sep.repeat(2),
27+
sourcemap: true
3228
}
3329
],
3430
minifySyntax: true,
3531
plugins: [
36-
{
37-
name: 'fix-sourcemaps',
38-
39-
/**
40-
* Makes sourcemap files relative to [`sourceRoot`][1].
41-
*
42-
* [1]: https://esbuild.github.io/api/#source-root
43-
* [2]: https://esbuild.github.io/plugins
44-
*
45-
* @see https://github.com/evanw/esbuild/issues/2218
46-
*
47-
* @param {PluginBuild} build - [esbuild plugin api][2]
48-
* @param {PluginBuild['onEnd']} build.onEnd - Build end callback
49-
* @return {void} Nothing when complete
50-
*/
51-
setup({ initialOptions, onEnd }: PluginBuild): void {
52-
return void onEnd((result: BuildResult<{ write: false }>): void => {
53-
const { absWorkingDir = process.cwd() } = initialOptions
54-
55-
return void (result.outputFiles = result.outputFiles.map(output => {
56-
if (output.path.endsWith('.map')) {
57-
/**
58-
* Relative path to output file sourcemap is for.
59-
*
60-
* **Note**: Relative to {@linkcode absWorkingDir}.
61-
*
62-
* @const {string} outfile
63-
*/
64-
const outfile: string = output.path
65-
.replace(absWorkingDir, '')
66-
.replace(/^\//, '')
67-
.replace(/\.map$/, '')
68-
69-
/**
70-
* Parsed sourcemap object.
71-
*
72-
* @const {{ sources: string[] }}
73-
*/
74-
const map: { sources: string[] } = JSON.parse(output.text)
75-
76-
// reset sources to outfile entry point
77-
map.sources = [result.metafile!.outputs[outfile]!.entryPoint!]
78-
79-
// redefine outfile text
80-
Object.defineProperty(output, 'text', {
81-
get: (): string => JSON.stringify(map, null, 2)
82-
})
83-
}
84-
85-
return output
86-
}))
87-
})
88-
}
89-
},
9032
{
9133
name: 'ts-ignore-peers',
9234

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
"type": "module",
2525
"files": [
2626
"CHANGELOG.md",
27-
"dist",
28-
"src"
27+
"dist"
2928
],
3029
"exports": {
3130
".": "./dist/index.mjs",

0 commit comments

Comments
 (0)