├── .eslintignore ├── .eslintrc.json ├── .gitignore ├── .npmrc ├── .prettierrc ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── jest.config.cjs ├── package.json ├── rollup.config.js ├── src ├── __tests__ │ └── index.ts ├── env.d.ts └── index.ts └── tsconfig.json /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | dist 4 | *.d.ts 5 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "extends": ["eslint:recommended", "plugin:prettier/recommended", "prettier"], 4 | "parserOptions": { 5 | "ecmaVersion": 2017, 6 | "sourceType": "module" 7 | }, 8 | "env": { 9 | "node": true 10 | }, 11 | "rules": { 12 | "curly": ["error", "all"] 13 | }, 14 | "overrides": [ 15 | { 16 | "files": ["**/*.ts"], 17 | "extends": [ 18 | "plugin:@typescript-eslint/recommended", 19 | "plugin:@typescript-eslint/recommended-requiring-type-checking", 20 | "prettier/@typescript-eslint" 21 | ], 22 | "parserOptions": { 23 | "project": "./tsconfig.json" 24 | }, 25 | "rules": { 26 | "@typescript-eslint/explicit-function-return-type": "off", 27 | "@typescript-eslint/explicit-module-boundary-types": "off" 28 | } 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | coverage 4 | .vscode 5 | .code 6 | .DS_Store 7 | yarn.lock 8 | package-lock.json 9 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all", 4 | "printWidth": 100, 5 | "proseWrap": "preserve", 6 | "arrowParens": "avoid" 7 | } 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - lts/dubnium 4 | - lts/erbium 5 | - stable 6 | cache: npm 7 | script: 8 | - npm run typecheck 9 | - npm run lint 10 | - npm run test -- --runInBand --coverage 11 | after_success: cat coverage/lcov.info | npx coveralls 12 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 0.6.3 4 | 5 | - Fix ES module breaking due to not default-importing CommonJS modules 6 | - Add some warning messages 7 | 8 | ## 0.6.2 9 | 10 | - Fix issue with exports that prevented it from working in Node 13.0-13.6 11 | 12 | ## 0.6.1 13 | 14 | - Fix issue with conditional exports that prevented it from working in Node 13+ 15 | 16 | ## 0.6.0 17 | 18 | - Drop support for Node 8 19 | - Update dependencies 20 | - Publish ES module for Node 12+ using conditional exports 21 | 22 | ## 0.5.0 23 | 24 | - Drop support for Node < 8 and make use of ES2017 features 25 | - Switch from Babel to TypeScript 26 | - Remove `jsnext:main` field from package.json 27 | 28 | ## 0.4.2 29 | 30 | - Add the ability to override the `readFile` function 31 | - Switch to `babel-preset-env` 32 | 33 | ## 0.4.1 34 | 35 | - Add `module` field to package.json 36 | 37 | ## 0.4.0 38 | 39 | - Remove async functions, since they require `babel-runtime` on Node 4 40 | 41 | ## 0.3.7 42 | 43 | - Switch to `babel-preset-latest` 44 | 45 | ## 0.3.6 46 | 47 | - Switch to `babel-preset-es2015` 48 | 49 | ## 0.3.5 50 | 51 | - Upgrade internal build process 52 | 53 | ## 0.3.4 54 | 55 | - Add `name` property to plugin object 56 | 57 | ## 0.3.3 58 | 59 | - Change incorrect package.json property `js:main` to `jsnext:main` 60 | 61 | ## 0.3.2 62 | 63 | - Include `sourcesContent` in source map 64 | 65 | ## 0.3.1 66 | 67 | - Fix incorrect lowest compatible version of Rollup 68 | 69 | ## 0.3.0 70 | 71 | - Rename exported plugin function 72 | - Upgrade internal build process 73 | 74 | ## 0.2.0 75 | 76 | - Use `source-map-resolve` for extracting source maps 77 | 78 | ## 0.1.1 79 | 80 | - Fix inline source maps not being detected 81 | 82 | ## 0.1.0 83 | 84 | - First public release 🎉 85 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Max Davidson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rollup-plugin-sourcemaps 2 | 3 | [![npm](https://img.shields.io/npm/v/rollup-plugin-sourcemaps.svg)](https://www.npmjs.com/package/rollup-plugin-sourcemaps) 4 | [![Build Status](https://img.shields.io/travis/maxdavidson/rollup-plugin-sourcemaps/master.svg)](https://travis-ci.org/maxdavidson/rollup-plugin-sourcemaps) 5 | [![Coverage Status](https://img.shields.io/coveralls/maxdavidson/rollup-plugin-sourcemaps/master.svg)](https://coveralls.io/github/maxdavidson/rollup-plugin-sourcemaps?branch=master) 6 | 7 | 8 | [Rollup](https://rollupjs.org) plugin for loading files with existing source maps. 9 | Inspired by [webpack/source-map-loader](https://github.com/webpack/source-map-loader). 10 | 11 | Works with rollup 0.31.2 or later. 12 | 13 | If you use [rollup-plugin-babel](https://github.com/rollup/rollup-plugin-babel), 14 | you might be able to use the [`inputSourceMap`](https://babeljs.io/docs/en/options#inputsourcemap) option instead of this plugin. 15 | 16 | ## Why? 17 | 18 | - You transpile your files with source maps before bundling with rollup 19 | - You consume external modules with bundled source maps 20 | 21 | ## Usage 22 | 23 | ```javascript 24 | import sourcemaps from 'rollup-plugin-sourcemaps'; 25 | 26 | export default { 27 | input: 'src/index.js', 28 | plugins: [sourcemaps()], 29 | output: { 30 | sourcemap: true, 31 | file: 'dist/my-awesome-package.js', 32 | }, 33 | }; 34 | ``` 35 | -------------------------------------------------------------------------------- /jest.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | 'use strict'; 3 | 4 | module.exports = { 5 | preset: 'ts-jest', 6 | testEnvironment: 'node', 7 | modulePathIgnorePatterns: ['/dist'], 8 | }; 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rollup-plugin-sourcemaps", 3 | "version": "0.6.3", 4 | "description": "Rollup plugin for grabbing source maps from sourceMappingURLs", 5 | "author": "Max Davidson ", 6 | "license": "MIT", 7 | "type": "module", 8 | "main": "./dist/index.cjs", 9 | "module": "./dist/index.js", 10 | "types": "./dist/index.d.ts", 11 | "exports": { 12 | "import": "./dist/index.js", 13 | "require": "./dist/index.cjs", 14 | "default": "./dist/index.cjs" 15 | }, 16 | "sideEffects": false, 17 | "repository": { 18 | "type": "git", 19 | "url": "https://github.com/maxdavidson/rollup-plugin-sourcemaps" 20 | }, 21 | "engines": { 22 | "node": ">=10.0.0" 23 | }, 24 | "scripts": { 25 | "build": "rimraf dist && rollup --config", 26 | "test": "jest", 27 | "lint": "eslint .", 28 | "typecheck": "tsc --noEmit", 29 | "prepublishOnly": "npm run build", 30 | "preversion": "npm run test" 31 | }, 32 | "keywords": [ 33 | "rollup", 34 | "rollup-plugin", 35 | "sourcemap", 36 | "source-map", 37 | "sourceMappingURL" 38 | ], 39 | "files": [ 40 | "dist" 41 | ], 42 | "dependencies": { 43 | "@rollup/pluginutils": "^3.0.9", 44 | "source-map-resolve": "^0.6.0" 45 | }, 46 | "devDependencies": { 47 | "@rollup/plugin-typescript": "6.0.0", 48 | "@types/node": "^10.17.21", 49 | "@typescript-eslint/eslint-plugin": "^4.0.0", 50 | "@typescript-eslint/parser": "^4.0.0", 51 | "eslint": "^7.1.0", 52 | "eslint-config-prettier": "^6.9.0", 53 | "eslint-plugin-prettier": "^3.1.2", 54 | "jest": "^26.0.0", 55 | "prettier": "^2.0.5", 56 | "rimraf": "^3.0.0", 57 | "rollup": "^2.7.5", 58 | "ts-jest": "^26.0.0", 59 | "typescript": "~4.0.0" 60 | }, 61 | "peerDependencies": { 62 | "@types/node": ">=10.0.0", 63 | "rollup": ">=0.31.2" 64 | }, 65 | "peerDependenciesMeta": { 66 | "@types/node": { 67 | "optional": true 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | import typescript from '@rollup/plugin-typescript'; 3 | 4 | export default /** @type {import('rollup').RollupOptions} */ ({ 5 | input: 'src/index.ts', 6 | external: () => true, 7 | plugins: [typescript()], 8 | output: [ 9 | { 10 | dir: 'dist', 11 | format: 'es', 12 | sourcemap: true, 13 | entryFileNames: '[name].js', 14 | }, 15 | { 16 | dir: 'dist', 17 | format: 'cjs', 18 | sourcemap: true, 19 | entryFileNames: '[name].cjs', 20 | exports: 'default', 21 | }, 22 | ], 23 | }); 24 | -------------------------------------------------------------------------------- /src/__tests__/index.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/require-await, @typescript-eslint/no-non-null-assertion */ 2 | import fs from 'fs'; 3 | import path from 'path'; 4 | import util from 'util'; 5 | import ts from 'typescript'; 6 | import { rollup } from 'rollup'; 7 | import { describe, it, test, expect } from '@jest/globals'; 8 | 9 | import sourcemaps, { SourcemapsPluginOptions } from '..'; 10 | 11 | const inputPath = path.join(__dirname, '../index.ts'); 12 | const inputText = fs.readFileSync(inputPath, 'utf8'); 13 | 14 | const outputPath = path.format({ 15 | dir: path.dirname(inputPath), 16 | name: path.basename(inputPath, path.extname(inputPath)), 17 | ext: '.js', 18 | }); 19 | 20 | const sourceMapPath = path.format({ 21 | dir: path.dirname(inputPath), 22 | name: path.basename(inputPath, path.extname(inputPath)), 23 | ext: '.js.map', 24 | }); 25 | 26 | async function rollupBundle({ 27 | outputText, 28 | sourceMapText, 29 | pluginOptions, 30 | }: ts.TranspileOutput & { 31 | pluginOptions?: SourcemapsPluginOptions; 32 | }) { 33 | const load = async (path: string) => { 34 | switch (path) { 35 | case inputPath: 36 | return inputText; 37 | case outputPath: 38 | return outputText; 39 | case sourceMapPath: 40 | return sourceMapText!; 41 | default: 42 | throw new Error(`Unexpected path: ${path}`); 43 | } 44 | }; 45 | 46 | const { generate } = await rollup({ 47 | input: outputPath, 48 | external: () => true, 49 | plugins: [ 50 | { name: 'skip-checks', resolveId: path => path }, 51 | sourcemaps({ 52 | readFile: util.callbackify(load), 53 | ...pluginOptions, 54 | }), 55 | { name: 'fake-fs', load }, 56 | ], 57 | }); 58 | 59 | const { output } = await generate({ 60 | format: 'esm', 61 | sourcemap: true, 62 | sourcemapPathTransform(relativePath) { 63 | return path.resolve(__dirname, '..', '..', relativePath); 64 | }, 65 | }); 66 | 67 | return output[0]; 68 | } 69 | 70 | it('ignores files with no source maps', async () => { 71 | const { outputText, sourceMapText } = ts.transpileModule(inputText, { 72 | fileName: inputPath, 73 | compilerOptions: { 74 | target: ts.ScriptTarget.ES2017, 75 | sourceMap: false, 76 | inlineSourceMap: false, 77 | }, 78 | }); 79 | 80 | expect(sourceMapText).toBeUndefined(); 81 | 82 | const { map } = await rollupBundle({ outputText, sourceMapText }); 83 | 84 | expect(map).toBeDefined(); 85 | expect(map!.sources).toStrictEqual([outputPath]); 86 | expect(map!.sourcesContent).toStrictEqual([outputText]); 87 | }); 88 | 89 | describe('detects files with source maps', () => { 90 | test.each` 91 | sourceMap | inlineSourceMap | inlineSources 92 | ${true} | ${false} | ${false} 93 | ${false} | ${true} | ${false} 94 | ${true} | ${false} | ${true} 95 | ${false} | ${true} | ${true} 96 | `( 97 | 'sourceMap: $sourceMap, inlineSourceMap: $inlineSourceMap, inlineSources: $inlineSources', 98 | async ({ 99 | sourceMap, 100 | inlineSourceMap, 101 | inlineSources, 102 | }: { 103 | sourceMap: boolean; 104 | inlineSourceMap: boolean; 105 | inlineSources: boolean; 106 | }) => { 107 | const { outputText, sourceMapText } = ts.transpileModule(inputText, { 108 | fileName: inputPath, 109 | compilerOptions: { 110 | target: ts.ScriptTarget.ES2017, 111 | sourceMap, 112 | inlineSourceMap, 113 | inlineSources, 114 | }, 115 | }); 116 | 117 | if (sourceMap) { 118 | expect(sourceMapText).toBeDefined(); 119 | } else { 120 | expect(sourceMapText).toBeUndefined(); 121 | } 122 | 123 | const { map } = await rollupBundle({ outputText, sourceMapText }); 124 | 125 | expect(map).toBeDefined(); 126 | expect(map!.sources).toStrictEqual([inputPath]); 127 | expect(map!.sourcesContent).toStrictEqual([inputText]); 128 | }, 129 | ); 130 | }); 131 | 132 | describe('ignores filtered files', () => { 133 | test('included', async () => { 134 | const { outputText, sourceMapText } = ts.transpileModule(inputText, { 135 | fileName: inputPath, 136 | compilerOptions: { 137 | target: ts.ScriptTarget.ES2017, 138 | sourceMap: true, 139 | }, 140 | }); 141 | 142 | expect(sourceMapText).toBeDefined(); 143 | 144 | const { map } = await rollupBundle({ 145 | outputText, 146 | sourceMapText, 147 | pluginOptions: { 148 | include: ['dummy-file'], 149 | }, 150 | }); 151 | 152 | expect(map).toBeDefined(); 153 | expect(map!.sources).toStrictEqual([outputPath]); 154 | expect(map!.sourcesContent).toStrictEqual([outputText]); 155 | }); 156 | 157 | test('excluded', async () => { 158 | const { outputText, sourceMapText } = ts.transpileModule(inputText, { 159 | fileName: inputPath, 160 | compilerOptions: { 161 | target: ts.ScriptTarget.ES2017, 162 | sourceMap: true, 163 | }, 164 | }); 165 | 166 | expect(sourceMapText).toBeDefined(); 167 | 168 | const { map } = await rollupBundle({ 169 | outputText, 170 | sourceMapText, 171 | pluginOptions: { 172 | exclude: [path.relative(process.cwd(), outputPath)], 173 | }, 174 | }); 175 | 176 | expect(map).toBeDefined(); 177 | expect(map!.sources).toStrictEqual([outputPath]); 178 | expect(map!.sourcesContent).toStrictEqual([outputText]); 179 | }); 180 | }); 181 | 182 | it('delegates failing file reads to the next plugin', async () => { 183 | const { outputText, sourceMapText } = ts.transpileModule(inputText, { 184 | fileName: inputPath, 185 | compilerOptions: { 186 | target: ts.ScriptTarget.ES2017, 187 | sourceMap: true, 188 | }, 189 | }); 190 | 191 | expect(sourceMapText).toBeDefined(); 192 | 193 | const { map } = await rollupBundle({ 194 | outputText, 195 | sourceMapText, 196 | pluginOptions: { 197 | readFile(_path, cb) { 198 | cb(new Error('Failed!'), ''); 199 | }, 200 | }, 201 | }); 202 | 203 | expect(map).toBeDefined(); 204 | expect(map!.sources).toStrictEqual([outputPath]); 205 | expect(map!.sourcesContent).toStrictEqual([outputText]); 206 | }); 207 | 208 | it('handles failing source maps reads', async () => { 209 | const { outputText, sourceMapText } = ts.transpileModule(inputText, { 210 | fileName: inputPath, 211 | compilerOptions: { 212 | target: ts.ScriptTarget.ES2017, 213 | sourceMap: true, 214 | }, 215 | }); 216 | 217 | expect(sourceMapText).toBeDefined(); 218 | 219 | const { map } = await rollupBundle({ 220 | outputText, 221 | sourceMapText, 222 | pluginOptions: { 223 | readFile: util.callbackify(async (path: string) => { 224 | switch (path) { 225 | case inputPath: 226 | return inputText; 227 | case outputPath: 228 | return outputText; 229 | default: 230 | throw new Error(`Unexpected path: ${path}`); 231 | } 232 | }), 233 | }, 234 | }); 235 | 236 | expect(map).toBeDefined(); 237 | expect(map!.sources).toStrictEqual([outputPath]); 238 | expect(map!.sourcesContent).toStrictEqual([outputText]); 239 | }); 240 | -------------------------------------------------------------------------------- /src/env.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'source-map-resolve' { 2 | import fs from 'fs'; 3 | import { ExistingRawSourceMap } from 'rollup'; 4 | 5 | export interface ResolvedSourceMap { 6 | /** The source map for code, as an object */ 7 | map: ExistingRawSourceMap; 8 | /** The url to the source map. If the source map came from a data uri, this property is null, since then there is no url to it. */ 9 | url: string | null; 10 | /** 11 | * The url that the sources of the source map are relative to. 12 | * Since the sources are relative to the source map, and the url to the source map is provided as the url property, this property might seem superfluos. 13 | * However, remember that the url property can be null if the source map came from a data uri. 14 | * If so, the sources are relative to the file containing the data uri—codeUrl. 15 | * This property will be identical to the url property or codeUrl, whichever is appropriate. 16 | * This way you can conveniently resolve the sources without having to think about where the source map came from. 17 | */ 18 | sourcesRelativeTo: string; 19 | /** The url of the sourceMappingURL comment in code */ 20 | sourceMappingURL: string; 21 | } 22 | 23 | /** 24 | * 25 | * @param code A string of code that may or may not contain a sourceMappingURL comment. Such a comment is used to resolve the source map. 26 | * @param codeUrl The url to the file containing code. If the sourceMappingURL is relative, it is resolved against codeUrl. 27 | * @param read A function that reads url and responds using callback(error, content). 28 | * @param callback A function that is invoked with either an error or null and the result. 29 | */ 30 | export function resolveSourceMap( 31 | code: string, 32 | codeUrl: string, 33 | read: (path: string, callback: (error: Error | null, data: Buffer | string) => void) => void, 34 | callback: ( 35 | error: Error | null, 36 | /** If code contains no sourceMappingURL, the result is null. */ 37 | result: ResolvedSourceMap | null, 38 | ) => void, 39 | ): void; 40 | 41 | export interface ResolvedSources { 42 | /** The same as map.sources, except all the sources are fully resolved. */ 43 | sourcesResolved: string[]; 44 | /** 45 | * An array with the contents of all sources in map.sources, in the same order as map.sources. 46 | * If getting the contents of a source fails, an error object is put into the array instead. 47 | * */ 48 | sourcesContent: (string | Error)[]; 49 | } 50 | 51 | /** 52 | * 53 | * @param code A string of code that may or may not contain a sourceMappingURL comment. Such a comment is used to resolve the source map. 54 | * @param codeUrl The url to the file containing code. If the sourceMappingURL is relative, it is resolved against codeUrl. 55 | * @param read A function that reads url and responds using callback(error, content). 56 | * @param callback A function that is invoked with either an error or null and the result. 57 | */ 58 | export function resolveSources( 59 | map: ExistingRawSourceMap, 60 | mapUrl: string, 61 | read: (path: string, callback: (error: Error | null, data: Buffer | string) => void) => void, 62 | callback: (error: Error | null, result: ResolvedSources) => void, 63 | ): void; 64 | } 65 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import { promisify } from 'util'; 3 | import { Plugin, ExistingRawSourceMap } from 'rollup'; 4 | import pluginUtils, { CreateFilter } from '@rollup/pluginutils'; 5 | import sourceMapResolve from 'source-map-resolve'; 6 | 7 | const { createFilter } = pluginUtils; 8 | const { resolveSourceMap, resolveSources } = sourceMapResolve; 9 | 10 | const promisifiedResolveSourceMap = promisify(resolveSourceMap); 11 | const promisifiedResolveSources = promisify(resolveSources); 12 | 13 | export interface SourcemapsPluginOptions { 14 | include?: Parameters[0]; 15 | exclude?: Parameters[1]; 16 | readFile?(path: string, callback: (error: Error | null, data: Buffer | string) => void): void; 17 | } 18 | 19 | export default function sourcemaps({ 20 | include, 21 | exclude, 22 | readFile = fs.readFile, 23 | }: SourcemapsPluginOptions = {}): Plugin { 24 | const filter = createFilter(include, exclude); 25 | const promisifiedReadFile = promisify(readFile); 26 | 27 | return { 28 | name: 'sourcemaps', 29 | 30 | async load(id: string) { 31 | if (!filter(id)) { 32 | return null; 33 | } 34 | 35 | let code: string; 36 | try { 37 | code = (await promisifiedReadFile(id)).toString(); 38 | } catch { 39 | this.warn('Failed reading file'); 40 | return null; 41 | } 42 | 43 | let map: ExistingRawSourceMap; 44 | try { 45 | const result = await promisifiedResolveSourceMap(code, id, readFile); 46 | 47 | // The code contained no sourceMappingURL 48 | if (result === null) { 49 | return code; 50 | } 51 | 52 | map = result.map; 53 | } catch { 54 | this.warn('Failed resolving source map'); 55 | return code; 56 | } 57 | 58 | // Resolve sources if they're not included 59 | if (map.sourcesContent === undefined) { 60 | try { 61 | const { sourcesContent } = await promisifiedResolveSources(map, id, readFile); 62 | if (sourcesContent.every(item => typeof item === 'string')) { 63 | map.sourcesContent = sourcesContent as string[]; 64 | } 65 | } catch { 66 | this.warn('Failed resolving sources for source map'); 67 | } 68 | } 69 | 70 | return { code, map }; 71 | }, 72 | }; 73 | } 74 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2018", 4 | "module": "es2015", 5 | "moduleResolution": "node", 6 | "declarationDir": "dist", 7 | "rootDir": "src", 8 | "declaration": true, 9 | "sourceMap": true, 10 | "inlineSources": true, 11 | "strict": true, 12 | "esModuleInterop": true 13 | }, 14 | "include": ["src"], 15 | "exclude": ["node_modules"] 16 | } 17 | --------------------------------------------------------------------------------