pax_global_header00006660000000000000000000000064137374111120014512gustar00rootroot0000000000000052 comment=f3964bc3be2d2385b572bf0e0812f63374f076eb rollup-plugin-sourcemaps-0.6.3/000077500000000000000000000000001373741111200165105ustar00rootroot00000000000000rollup-plugin-sourcemaps-0.6.3/.eslintignore000066400000000000000000000000421373741111200212070ustar00rootroot00000000000000node_modules coverage dist *.d.ts rollup-plugin-sourcemaps-0.6.3/.eslintrc.json000066400000000000000000000013421373741111200213040ustar00rootroot00000000000000{ "root": true, "extends": ["eslint:recommended", "plugin:prettier/recommended", "prettier"], "parserOptions": { "ecmaVersion": 2017, "sourceType": "module" }, "env": { "node": true }, "rules": { "curly": ["error", "all"] }, "overrides": [ { "files": ["**/*.ts"], "extends": [ "plugin:@typescript-eslint/recommended", "plugin:@typescript-eslint/recommended-requiring-type-checking", "prettier/@typescript-eslint" ], "parserOptions": { "project": "./tsconfig.json" }, "rules": { "@typescript-eslint/explicit-function-return-type": "off", "@typescript-eslint/explicit-module-boundary-types": "off" } } ] } rollup-plugin-sourcemaps-0.6.3/.gitignore000066400000000000000000000001171373741111200204770ustar00rootroot00000000000000node_modules dist coverage .vscode .code .DS_Store yarn.lock package-lock.json rollup-plugin-sourcemaps-0.6.3/.npmrc000066400000000000000000000000231373741111200176230ustar00rootroot00000000000000package-lock=false rollup-plugin-sourcemaps-0.6.3/.prettierrc000066400000000000000000000001761373741111200207000ustar00rootroot00000000000000{ "singleQuote": true, "trailingComma": "all", "printWidth": 100, "proseWrap": "preserve", "arrowParens": "avoid" } rollup-plugin-sourcemaps-0.6.3/.travis.yml000066400000000000000000000003401373741111200206160ustar00rootroot00000000000000language: node_js node_js: - lts/dubnium - lts/erbium - stable cache: npm script: - npm run typecheck - npm run lint - npm run test -- --runInBand --coverage after_success: cat coverage/lcov.info | npx coveralls rollup-plugin-sourcemaps-0.6.3/CHANGELOG.md000066400000000000000000000026011373741111200203200ustar00rootroot00000000000000# Changelog ## 0.6.3 - Fix ES module breaking due to not default-importing CommonJS modules - Add some warning messages ## 0.6.2 - Fix issue with exports that prevented it from working in Node 13.0-13.6 ## 0.6.1 - Fix issue with conditional exports that prevented it from working in Node 13+ ## 0.6.0 - Drop support for Node 8 - Update dependencies - Publish ES module for Node 12+ using conditional exports ## 0.5.0 - Drop support for Node < 8 and make use of ES2017 features - Switch from Babel to TypeScript - Remove `jsnext:main` field from package.json ## 0.4.2 - Add the ability to override the `readFile` function - Switch to `babel-preset-env` ## 0.4.1 - Add `module` field to package.json ## 0.4.0 - Remove async functions, since they require `babel-runtime` on Node 4 ## 0.3.7 - Switch to `babel-preset-latest` ## 0.3.6 - Switch to `babel-preset-es2015` ## 0.3.5 - Upgrade internal build process ## 0.3.4 - Add `name` property to plugin object ## 0.3.3 - Change incorrect package.json property `js:main` to `jsnext:main` ## 0.3.2 - Include `sourcesContent` in source map ## 0.3.1 - Fix incorrect lowest compatible version of Rollup ## 0.3.0 - Rename exported plugin function - Upgrade internal build process ## 0.2.0 - Use `source-map-resolve` for extracting source maps ## 0.1.1 - Fix inline source maps not being detected ## 0.1.0 - First public release 🎉 rollup-plugin-sourcemaps-0.6.3/LICENSE000066400000000000000000000020671373741111200175220ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2020 Max Davidson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. rollup-plugin-sourcemaps-0.6.3/README.md000066400000000000000000000024011373741111200177640ustar00rootroot00000000000000# rollup-plugin-sourcemaps [![npm](https://img.shields.io/npm/v/rollup-plugin-sourcemaps.svg)](https://www.npmjs.com/package/rollup-plugin-sourcemaps) [![Build Status](https://img.shields.io/travis/maxdavidson/rollup-plugin-sourcemaps/master.svg)](https://travis-ci.org/maxdavidson/rollup-plugin-sourcemaps) [![Coverage Status](https://img.shields.io/coveralls/maxdavidson/rollup-plugin-sourcemaps/master.svg)](https://coveralls.io/github/maxdavidson/rollup-plugin-sourcemaps?branch=master) [Rollup](https://rollupjs.org) plugin for loading files with existing source maps. Inspired by [webpack/source-map-loader](https://github.com/webpack/source-map-loader). Works with rollup 0.31.2 or later. If you use [rollup-plugin-babel](https://github.com/rollup/rollup-plugin-babel), you might be able to use the [`inputSourceMap`](https://babeljs.io/docs/en/options#inputsourcemap) option instead of this plugin. ## Why? - You transpile your files with source maps before bundling with rollup - You consume external modules with bundled source maps ## Usage ```javascript import sourcemaps from 'rollup-plugin-sourcemaps'; export default { input: 'src/index.js', plugins: [sourcemaps()], output: { sourcemap: true, file: 'dist/my-awesome-package.js', }, }; ``` rollup-plugin-sourcemaps-0.6.3/jest.config.cjs000066400000000000000000000002331373741111200214200ustar00rootroot00000000000000/* eslint-env node */ 'use strict'; module.exports = { preset: 'ts-jest', testEnvironment: 'node', modulePathIgnorePatterns: ['/dist'], }; rollup-plugin-sourcemaps-0.6.3/package.json000066400000000000000000000032471373741111200210040ustar00rootroot00000000000000{ "name": "rollup-plugin-sourcemaps", "version": "0.6.3", "description": "Rollup plugin for grabbing source maps from sourceMappingURLs", "author": "Max Davidson ", "license": "MIT", "type": "module", "main": "./dist/index.cjs", "module": "./dist/index.js", "types": "./dist/index.d.ts", "exports": { "import": "./dist/index.js", "require": "./dist/index.cjs", "default": "./dist/index.cjs" }, "sideEffects": false, "repository": { "type": "git", "url": "https://github.com/maxdavidson/rollup-plugin-sourcemaps" }, "engines": { "node": ">=10.0.0" }, "scripts": { "build": "rimraf dist && rollup --config", "test": "jest", "lint": "eslint .", "typecheck": "tsc --noEmit", "prepublishOnly": "npm run build", "preversion": "npm run test" }, "keywords": [ "rollup", "rollup-plugin", "sourcemap", "source-map", "sourceMappingURL" ], "files": [ "dist" ], "dependencies": { "@rollup/pluginutils": "^3.0.9", "source-map-resolve": "^0.6.0" }, "devDependencies": { "@rollup/plugin-typescript": "6.0.0", "@types/node": "^10.17.21", "@typescript-eslint/eslint-plugin": "^4.0.0", "@typescript-eslint/parser": "^4.0.0", "eslint": "^7.1.0", "eslint-config-prettier": "^6.9.0", "eslint-plugin-prettier": "^3.1.2", "jest": "^26.0.0", "prettier": "^2.0.5", "rimraf": "^3.0.0", "rollup": "^2.7.5", "ts-jest": "^26.0.0", "typescript": "~4.0.0" }, "peerDependencies": { "@types/node": ">=10.0.0", "rollup": ">=0.31.2" }, "peerDependenciesMeta": { "@types/node": { "optional": true } } } rollup-plugin-sourcemaps-0.6.3/rollup.config.js000066400000000000000000000007331373741111200216320ustar00rootroot00000000000000// @ts-check import typescript from '@rollup/plugin-typescript'; export default /** @type {import('rollup').RollupOptions} */ ({ input: 'src/index.ts', external: () => true, plugins: [typescript()], output: [ { dir: 'dist', format: 'es', sourcemap: true, entryFileNames: '[name].js', }, { dir: 'dist', format: 'cjs', sourcemap: true, entryFileNames: '[name].cjs', exports: 'default', }, ], }); rollup-plugin-sourcemaps-0.6.3/src/000077500000000000000000000000001373741111200172775ustar00rootroot00000000000000rollup-plugin-sourcemaps-0.6.3/src/__tests__/000077500000000000000000000000001373741111200212355ustar00rootroot00000000000000rollup-plugin-sourcemaps-0.6.3/src/__tests__/index.ts000066400000000000000000000140671373741111200227240ustar00rootroot00000000000000/* eslint-disable @typescript-eslint/require-await, @typescript-eslint/no-non-null-assertion */ import fs from 'fs'; import path from 'path'; import util from 'util'; import ts from 'typescript'; import { rollup } from 'rollup'; import { describe, it, test, expect } from '@jest/globals'; import sourcemaps, { SourcemapsPluginOptions } from '..'; const inputPath = path.join(__dirname, '../index.ts'); const inputText = fs.readFileSync(inputPath, 'utf8'); const outputPath = path.format({ dir: path.dirname(inputPath), name: path.basename(inputPath, path.extname(inputPath)), ext: '.js', }); const sourceMapPath = path.format({ dir: path.dirname(inputPath), name: path.basename(inputPath, path.extname(inputPath)), ext: '.js.map', }); async function rollupBundle({ outputText, sourceMapText, pluginOptions, }: ts.TranspileOutput & { pluginOptions?: SourcemapsPluginOptions; }) { const load = async (path: string) => { switch (path) { case inputPath: return inputText; case outputPath: return outputText; case sourceMapPath: return sourceMapText!; default: throw new Error(`Unexpected path: ${path}`); } }; const { generate } = await rollup({ input: outputPath, external: () => true, plugins: [ { name: 'skip-checks', resolveId: path => path }, sourcemaps({ readFile: util.callbackify(load), ...pluginOptions, }), { name: 'fake-fs', load }, ], }); const { output } = await generate({ format: 'esm', sourcemap: true, sourcemapPathTransform(relativePath) { return path.resolve(__dirname, '..', '..', relativePath); }, }); return output[0]; } it('ignores files with no source maps', async () => { const { outputText, sourceMapText } = ts.transpileModule(inputText, { fileName: inputPath, compilerOptions: { target: ts.ScriptTarget.ES2017, sourceMap: false, inlineSourceMap: false, }, }); expect(sourceMapText).toBeUndefined(); const { map } = await rollupBundle({ outputText, sourceMapText }); expect(map).toBeDefined(); expect(map!.sources).toStrictEqual([outputPath]); expect(map!.sourcesContent).toStrictEqual([outputText]); }); describe('detects files with source maps', () => { test.each` sourceMap | inlineSourceMap | inlineSources ${true} | ${false} | ${false} ${false} | ${true} | ${false} ${true} | ${false} | ${true} ${false} | ${true} | ${true} `( 'sourceMap: $sourceMap, inlineSourceMap: $inlineSourceMap, inlineSources: $inlineSources', async ({ sourceMap, inlineSourceMap, inlineSources, }: { sourceMap: boolean; inlineSourceMap: boolean; inlineSources: boolean; }) => { const { outputText, sourceMapText } = ts.transpileModule(inputText, { fileName: inputPath, compilerOptions: { target: ts.ScriptTarget.ES2017, sourceMap, inlineSourceMap, inlineSources, }, }); if (sourceMap) { expect(sourceMapText).toBeDefined(); } else { expect(sourceMapText).toBeUndefined(); } const { map } = await rollupBundle({ outputText, sourceMapText }); expect(map).toBeDefined(); expect(map!.sources).toStrictEqual([inputPath]); expect(map!.sourcesContent).toStrictEqual([inputText]); }, ); }); describe('ignores filtered files', () => { test('included', async () => { const { outputText, sourceMapText } = ts.transpileModule(inputText, { fileName: inputPath, compilerOptions: { target: ts.ScriptTarget.ES2017, sourceMap: true, }, }); expect(sourceMapText).toBeDefined(); const { map } = await rollupBundle({ outputText, sourceMapText, pluginOptions: { include: ['dummy-file'], }, }); expect(map).toBeDefined(); expect(map!.sources).toStrictEqual([outputPath]); expect(map!.sourcesContent).toStrictEqual([outputText]); }); test('excluded', async () => { const { outputText, sourceMapText } = ts.transpileModule(inputText, { fileName: inputPath, compilerOptions: { target: ts.ScriptTarget.ES2017, sourceMap: true, }, }); expect(sourceMapText).toBeDefined(); const { map } = await rollupBundle({ outputText, sourceMapText, pluginOptions: { exclude: [path.relative(process.cwd(), outputPath)], }, }); expect(map).toBeDefined(); expect(map!.sources).toStrictEqual([outputPath]); expect(map!.sourcesContent).toStrictEqual([outputText]); }); }); it('delegates failing file reads to the next plugin', async () => { const { outputText, sourceMapText } = ts.transpileModule(inputText, { fileName: inputPath, compilerOptions: { target: ts.ScriptTarget.ES2017, sourceMap: true, }, }); expect(sourceMapText).toBeDefined(); const { map } = await rollupBundle({ outputText, sourceMapText, pluginOptions: { readFile(_path, cb) { cb(new Error('Failed!'), ''); }, }, }); expect(map).toBeDefined(); expect(map!.sources).toStrictEqual([outputPath]); expect(map!.sourcesContent).toStrictEqual([outputText]); }); it('handles failing source maps reads', async () => { const { outputText, sourceMapText } = ts.transpileModule(inputText, { fileName: inputPath, compilerOptions: { target: ts.ScriptTarget.ES2017, sourceMap: true, }, }); expect(sourceMapText).toBeDefined(); const { map } = await rollupBundle({ outputText, sourceMapText, pluginOptions: { readFile: util.callbackify(async (path: string) => { switch (path) { case inputPath: return inputText; case outputPath: return outputText; default: throw new Error(`Unexpected path: ${path}`); } }), }, }); expect(map).toBeDefined(); expect(map!.sources).toStrictEqual([outputPath]); expect(map!.sourcesContent).toStrictEqual([outputText]); }); rollup-plugin-sourcemaps-0.6.3/src/env.d.ts000066400000000000000000000060451373741111200206660ustar00rootroot00000000000000declare module 'source-map-resolve' { import fs from 'fs'; import { ExistingRawSourceMap } from 'rollup'; export interface ResolvedSourceMap { /** The source map for code, as an object */ map: ExistingRawSourceMap; /** 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. */ url: string | null; /** * The url that the sources of the source map are relative to. * 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. * However, remember that the url property can be null if the source map came from a data uri. * If so, the sources are relative to the file containing the data uri—codeUrl. * This property will be identical to the url property or codeUrl, whichever is appropriate. * This way you can conveniently resolve the sources without having to think about where the source map came from. */ sourcesRelativeTo: string; /** The url of the sourceMappingURL comment in code */ sourceMappingURL: string; } /** * * @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. * @param codeUrl The url to the file containing code. If the sourceMappingURL is relative, it is resolved against codeUrl. * @param read A function that reads url and responds using callback(error, content). * @param callback A function that is invoked with either an error or null and the result. */ export function resolveSourceMap( code: string, codeUrl: string, read: (path: string, callback: (error: Error | null, data: Buffer | string) => void) => void, callback: ( error: Error | null, /** If code contains no sourceMappingURL, the result is null. */ result: ResolvedSourceMap | null, ) => void, ): void; export interface ResolvedSources { /** The same as map.sources, except all the sources are fully resolved. */ sourcesResolved: string[]; /** * An array with the contents of all sources in map.sources, in the same order as map.sources. * If getting the contents of a source fails, an error object is put into the array instead. * */ sourcesContent: (string | Error)[]; } /** * * @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. * @param codeUrl The url to the file containing code. If the sourceMappingURL is relative, it is resolved against codeUrl. * @param read A function that reads url and responds using callback(error, content). * @param callback A function that is invoked with either an error or null and the result. */ export function resolveSources( map: ExistingRawSourceMap, mapUrl: string, read: (path: string, callback: (error: Error | null, data: Buffer | string) => void) => void, callback: (error: Error | null, result: ResolvedSources) => void, ): void; } rollup-plugin-sourcemaps-0.6.3/src/index.ts000066400000000000000000000040201373741111200207520ustar00rootroot00000000000000import fs from 'fs'; import { promisify } from 'util'; import { Plugin, ExistingRawSourceMap } from 'rollup'; import pluginUtils, { CreateFilter } from '@rollup/pluginutils'; import sourceMapResolve from 'source-map-resolve'; const { createFilter } = pluginUtils; const { resolveSourceMap, resolveSources } = sourceMapResolve; const promisifiedResolveSourceMap = promisify(resolveSourceMap); const promisifiedResolveSources = promisify(resolveSources); export interface SourcemapsPluginOptions { include?: Parameters[0]; exclude?: Parameters[1]; readFile?(path: string, callback: (error: Error | null, data: Buffer | string) => void): void; } export default function sourcemaps({ include, exclude, readFile = fs.readFile, }: SourcemapsPluginOptions = {}): Plugin { const filter = createFilter(include, exclude); const promisifiedReadFile = promisify(readFile); return { name: 'sourcemaps', async load(id: string) { if (!filter(id)) { return null; } let code: string; try { code = (await promisifiedReadFile(id)).toString(); } catch { this.warn('Failed reading file'); return null; } let map: ExistingRawSourceMap; try { const result = await promisifiedResolveSourceMap(code, id, readFile); // The code contained no sourceMappingURL if (result === null) { return code; } map = result.map; } catch { this.warn('Failed resolving source map'); return code; } // Resolve sources if they're not included if (map.sourcesContent === undefined) { try { const { sourcesContent } = await promisifiedResolveSources(map, id, readFile); if (sourcesContent.every(item => typeof item === 'string')) { map.sourcesContent = sourcesContent as string[]; } } catch { this.warn('Failed resolving sources for source map'); } } return { code, map }; }, }; } rollup-plugin-sourcemaps-0.6.3/tsconfig.json000066400000000000000000000005231373741111200212170ustar00rootroot00000000000000{ "compilerOptions": { "target": "es2018", "module": "es2015", "moduleResolution": "node", "declarationDir": "dist", "rootDir": "src", "declaration": true, "sourceMap": true, "inlineSources": true, "strict": true, "esModuleInterop": true }, "include": ["src"], "exclude": ["node_modules"] }