From 7359b216a88d0064e69906f34d8b47c69d496237 Mon Sep 17 00:00:00 2001 From: Billow Z Date: Fri, 12 Jul 2019 16:30:46 +0800 Subject: [PATCH 1/4] Add getCombinedSourceMap in transform plugin context (#2983) --- docs/05-plugin-development.md | 4 + src/Chunk.ts | 2 +- src/utils/collapseSourcemaps.ts | 105 ++++++++++++------ src/utils/transform.ts | 26 ++++- .../combined-sourcemap-with-loader/_config.js | 97 ++++++++++++++++ .../combined-sourcemap-with-loader/foo.js | 1 + .../combined-sourcemap-with-loader/main.js | 3 + .../samples/combined-sourcemap/_config.js | 83 ++++++++++++++ .../samples/combined-sourcemap/foo.js | 1 + .../samples/combined-sourcemap/main.js | 3 + 10 files changed, 289 insertions(+), 36 deletions(-) create mode 100644 test/sourcemaps/samples/combined-sourcemap-with-loader/_config.js create mode 100644 test/sourcemaps/samples/combined-sourcemap-with-loader/foo.js create mode 100644 test/sourcemaps/samples/combined-sourcemap-with-loader/main.js create mode 100644 test/sourcemaps/samples/combined-sourcemap/_config.js create mode 100644 test/sourcemaps/samples/combined-sourcemap/foo.js create mode 100644 test/sourcemaps/samples/combined-sourcemap/main.js diff --git a/docs/05-plugin-development.md b/docs/05-plugin-development.md index a5698de22fb..6bebc8e5944 100644 --- a/docs/05-plugin-development.md +++ b/docs/05-plugin-development.md @@ -414,6 +414,10 @@ Use the second form if you need to add additional properties to your warning obj The `position` argument is a character index where the warning was raised. If present, Rollup will augment the warning object with `pos`, `loc` (a standard `{ file, line, column }` object) and `frame` (a snippet of code showing the error). +### `this.getCombinedSourceMap() => SourceMap` + +Get the combined source maps of all previous plugins. This context function can only be used in [`transform`](guide/en/#transform) plugin hook. + ### Deprecated Context Functions ☢️ These context utility functions have been deprecated and may be removed in a future Rollup version. diff --git a/src/Chunk.ts b/src/Chunk.ts index 04e3b0683f0..c7e7127d921 100644 --- a/src/Chunk.ts +++ b/src/Chunk.ts @@ -23,7 +23,7 @@ import { } from './rollup/types'; import { Addons } from './utils/addons'; import { toBase64 } from './utils/base64'; -import collapseSourcemaps from './utils/collapseSourcemaps'; +import { collapseSourcemaps } from './utils/collapseSourcemaps'; import { deconflictChunk } from './utils/deconflictChunk'; import { error } from './utils/error'; import { sortByExecutionOrder } from './utils/executionOrder'; diff --git a/src/utils/collapseSourcemaps.ts b/src/utils/collapseSourcemaps.ts index a240190b501..286784a3a6b 100644 --- a/src/utils/collapseSourcemaps.ts +++ b/src/utils/collapseSourcemaps.ts @@ -1,5 +1,6 @@ import { DecodedSourceMap, SourceMap } from 'magic-string'; import Chunk from '../Chunk'; +import Graph from '../Graph'; import Module from '../Module'; import { DecodedSourceMapOrMissing, @@ -145,20 +146,13 @@ class Link { } } -export default function collapseSourcemaps( - bundle: Chunk, - file: string, - map: DecodedSourceMap, - modules: Module[], - bundleSourcemapChain: DecodedSourceMapOrMissing[], - excludeContent: boolean -) { - function linkMap(source: Source | Link, map: DecodedSourceMapOrMissing) { +function linkMapper(graph: Graph) { + return function linkMap(source: Source | Link, map: DecodedSourceMapOrMissing) { if (map.mappings) { return new Link(map, [source]); } - bundle.graph.warn({ + graph.warn({ code: 'SOURCEMAP_BROKEN', message: `Sourcemap is likely to be incorrect: a plugin${ map.plugin ? ` ('${map.plugin}')` : `` @@ -174,34 +168,55 @@ export default function collapseSourcemaps( }, [source] ); + }; +} + +function unionSourcemaps( + id: string, + originalCode: string, + originalSourcemap: ExistingDecodedSourceMap | null, + sourcemapChain: DecodedSourceMapOrMissing[], + linkMap: (source: Source | Link, map: DecodedSourceMapOrMissing) => Link +) { + let source: Source | Link; + if (!originalSourcemap) { + source = new Source(id, originalCode); + } else { + const sources = originalSourcemap.sources; + const sourcesContent = originalSourcemap.sourcesContent || []; + + // TODO indiscriminately treating IDs and sources as normal paths is probably bad. + const directory = dirname(id) || '.'; + const sourceRoot = originalSourcemap.sourceRoot || '.'; + + const baseSources = sources.map( + (source, i) => new Source(resolve(directory, sourceRoot, source), sourcesContent[i]) + ); + source = new Link(originalSourcemap, baseSources); } + return sourcemapChain.reduce(linkMap, source); +} +export function collapseSourcemaps( + bundle: Chunk, + file: string, + map: DecodedSourceMap, + modules: Module[], + bundleSourcemapChain: DecodedSourceMapOrMissing[], + excludeContent: boolean +) { + const linkMap = linkMapper(bundle.graph); const moduleSources = modules .filter(module => !module.excludeFromSourcemap) - .map(module => { - let source: Source | Link; - const originalSourcemap = module.originalSourcemap; - if (!originalSourcemap) { - source = new Source(module.id, module.originalCode); - } else { - const sources = originalSourcemap.sources; - const sourcesContent = originalSourcemap.sourcesContent || []; - - // TODO indiscriminately treating IDs and sources as normal paths is probably bad. - const directory = dirname(module.id) || '.'; - const sourceRoot = originalSourcemap.sourceRoot || '.'; - - const baseSources = sources.map( - (source, i) => new Source(resolve(directory, sourceRoot, source), sourcesContent[i]) - ); - - source = new Link(originalSourcemap, baseSources); - } - - source = module.sourcemapChain.reduce(linkMap, source); - - return source; - }); + .map(module => + unionSourcemaps( + module.id, + module.originalCode, + module.originalSourcemap, + module.sourcemapChain, + linkMap + ) + ); // DecodedSourceMap (from magic-string) uses a number[] instead of the more // correct SourceMapSegment tuples. Cast it here to gain type safety. @@ -221,3 +236,25 @@ export default function collapseSourcemaps( return new SourceMap({ file, sources, sourcesContent, names, mappings }); } + +export function collapseSourcemap( + graph: Graph, + id: string, + originalCode: string, + originalSourcemap: ExistingDecodedSourceMap, + sourcemapChain: DecodedSourceMapOrMissing[] +) { + if (!sourcemapChain.length) { + return originalSourcemap; + } + + const source = unionSourcemaps( + id, + originalCode, + originalSourcemap, + sourcemapChain, + linkMapper(graph) + ) as Link; + + return source.traceMappings(); +} diff --git a/src/utils/transform.ts b/src/utils/transform.ts index 3bf570fbd6d..5afff4c27dc 100644 --- a/src/utils/transform.ts +++ b/src/utils/transform.ts @@ -1,3 +1,4 @@ +import MagicString, { DecodedSourceMap, SourceMap } from 'magic-string'; import Graph from '../Graph'; import Module from '../Module'; import { @@ -5,6 +6,7 @@ import { DecodedSourceMapOrMissing, EmitAsset, EmittedChunk, + ExistingDecodedSourceMap, Plugin, PluginCache, PluginContext, @@ -15,6 +17,7 @@ import { TransformSourceDescription } from '../rollup/types'; import { createTransformEmitAsset } from './assetHooks'; +import { collapseSourcemap } from './collapseSourcemaps'; import { decodedSourcemap } from './decodedSourcemap'; import { augmentCodeLocation, error } from './error'; import { dirname, resolve } from './path'; @@ -28,7 +31,7 @@ export default function transform( const id = module.id; const sourcemapChain: DecodedSourceMapOrMissing[] = []; - const originalSourcemap = source.map === null ? null : decodedSourcemap(source.map); + let originalSourcemap = source.map === null ? null : decodedSourcemap(source.map); const baseEmitAsset = graph.pluginDriver.emitAsset; const originalCode = source.code; let ast = source.ast; @@ -159,6 +162,27 @@ export default function transform( setAssetSourceErr = err; } } + }, + getCombinedSourceMap() { + const combinedMap = collapseSourcemap( + graph, + id, + originalCode, + originalSourcemap as ExistingDecodedSourceMap, + sourcemapChain + ); + if (!combinedMap) { + const magicString = new MagicString(originalCode); + return magicString.generateMap({ includeContent: true, hires: true, source: id }); + } + if (originalSourcemap !== combinedMap) { + originalSourcemap = { version: 3, ...combinedMap }; + sourcemapChain.length = 0; + } + return new SourceMap({ + ...combinedMap, + file: null as any + } as DecodedSourceMap); } }; } diff --git a/test/sourcemaps/samples/combined-sourcemap-with-loader/_config.js b/test/sourcemaps/samples/combined-sourcemap-with-loader/_config.js new file mode 100644 index 00000000000..895cd5c112c --- /dev/null +++ b/test/sourcemaps/samples/combined-sourcemap-with-loader/_config.js @@ -0,0 +1,97 @@ +const fs = require('fs'); +const buble = require('buble'); +const MagicString = require('magic-string'); +const assert = require('assert'); +const getLocation = require('../../getLocation'); +const SourceMapConsumer = require('source-map').SourceMapConsumer; + +module.exports = { + description: 'get combined sourcemap in transforming with loader', + options: { + plugins: [ + { + load(id) { + const code = fs.readFileSync(id, 'utf-8'); + const out = buble.transform(code, { + transforms: { modules: false }, + sourceMap: true, + source: id + }); + + return { code: out.code, map: out.map }; + } + }, + { + transform(code, id) { + const sourcemap = this.getCombinedSourceMap(); + const smc = new SourceMapConsumer(sourcemap); + const s = new MagicString(code); + + if (/foo.js$/.test(id)) { + testFoo(code, smc); + + s.prepend('console.log("foo start");\n\n'); + s.append('\nconsole.log("foo end");'); + } else { + testMain(code, smc); + + s.appendRight(code.indexOf('console'), 'console.log("main start");\n\n'); + s.append('\nconsole.log("main end");'); + } + + return { + code: s.toString(), + map: s.generateMap({ hires: true }) + }; + } + }, + { + transform(code, id) { + const sourcemap = this.getCombinedSourceMap(); + const smc = new SourceMapConsumer(sourcemap); + const s = new MagicString(code); + + if (/foo.js$/.test(id)) { + testFoo(code, smc); + + s.prepend('console.log("-- foo ---");\n\n'); + s.append('\nconsole.log("-----");'); + } else { + testMain(code, smc); + + s.appendRight(code.indexOf('console'), 'console.log("-- main ---");\n\n'); + s.append('\nconsole.log("-----");'); + } + + return { + code: s.toString(), + map: s.generateMap({ hires: true }) + }; + } + } + ] + }, + test(code, map) { + const smc = new SourceMapConsumer(map); + testFoo(code, smc); + testMain(code, smc); + } +}; + +function testFoo(code, smc) { + const generatedLoc = getLocation(code, code.indexOf(42)); + const originalLoc = smc.originalPositionFor(generatedLoc); + + assert.ok(/foo/.test(originalLoc.source)); + assert.equal(originalLoc.line, 1); + assert.equal(originalLoc.column, 25); +} + +function testMain(code, smc) { + const generatedLoc = getLocation(code, code.indexOf('info')); + const originalLoc = smc.originalPositionFor(generatedLoc); + + assert.ok(/main/.test(originalLoc.source)); + assert.equal(originalLoc.line, 3); + assert.equal(originalLoc.column, 8); +} diff --git a/test/sourcemaps/samples/combined-sourcemap-with-loader/foo.js b/test/sourcemaps/samples/combined-sourcemap-with-loader/foo.js new file mode 100644 index 00000000000..0cf01bec8da --- /dev/null +++ b/test/sourcemaps/samples/combined-sourcemap-with-loader/foo.js @@ -0,0 +1 @@ +export const foo = () => 42; diff --git a/test/sourcemaps/samples/combined-sourcemap-with-loader/main.js b/test/sourcemaps/samples/combined-sourcemap-with-loader/main.js new file mode 100644 index 00000000000..61b585e055c --- /dev/null +++ b/test/sourcemaps/samples/combined-sourcemap-with-loader/main.js @@ -0,0 +1,3 @@ +import { foo } from './foo'; + +console.info( `the answer is ${foo()}` ); diff --git a/test/sourcemaps/samples/combined-sourcemap/_config.js b/test/sourcemaps/samples/combined-sourcemap/_config.js new file mode 100644 index 00000000000..02c7ddee0bb --- /dev/null +++ b/test/sourcemaps/samples/combined-sourcemap/_config.js @@ -0,0 +1,83 @@ +const MagicString = require('magic-string'); +const assert = require('assert'); +const getLocation = require('../../getLocation'); +const SourceMapConsumer = require('source-map').SourceMapConsumer; + +module.exports = { + description: 'get combined sourcemap in transforming', + options: { + plugins: [ + { + transform(code, id) { + const sourcemap = this.getCombinedSourceMap(); + const smc = new SourceMapConsumer(sourcemap); + const s = new MagicString(code); + + if (/foo.js$/.test(id)) { + testFoo(code, smc); + + s.prepend('console.log("foo start");\n\n'); + s.append('\nconsole.log("foo end");'); + } else { + testMain(code, smc); + + s.appendRight(code.indexOf('console'), 'console.log("main start");\n\n'); + s.append('\nconsole.log("main end");'); + } + + return { + code: s.toString(), + map: s.generateMap({ hires: true }) + }; + } + }, + { + transform(code, id) { + const sourcemap = this.getCombinedSourceMap(); + const smc = new SourceMapConsumer(sourcemap); + const s = new MagicString(code); + + if (/foo.js$/.test(id)) { + testFoo(code, smc); + + s.prepend('console.log("-- foo ---");\n\n'); + s.append('\nconsole.log("-----");'); + } else { + testMain(code, smc); + + s.appendRight(code.indexOf('console'), 'console.log("-- main ---");\n\n'); + s.append('\nconsole.log("-----");'); + } + + return { + code: s.toString(), + map: s.generateMap({ hires: true }) + }; + } + } + ] + }, + test(code, map) { + const smc = new SourceMapConsumer(map); + testFoo(code, smc); + testMain(code, smc); + } +}; + +function testFoo(code, smc) { + const generatedLoc = getLocation(code, code.indexOf(42)); + const originalLoc = smc.originalPositionFor(generatedLoc); + + assert.ok(/foo/.test(originalLoc.source)); + assert.equal(originalLoc.line, 1); + assert.equal(originalLoc.column, 25); +} + +function testMain(code, smc) { + const generatedLoc = getLocation(code, code.indexOf('info')); + const originalLoc = smc.originalPositionFor(generatedLoc); + + assert.ok(/main/.test(originalLoc.source)); + assert.equal(originalLoc.line, 3); + assert.equal(originalLoc.column, 8); +} diff --git a/test/sourcemaps/samples/combined-sourcemap/foo.js b/test/sourcemaps/samples/combined-sourcemap/foo.js new file mode 100644 index 00000000000..0cf01bec8da --- /dev/null +++ b/test/sourcemaps/samples/combined-sourcemap/foo.js @@ -0,0 +1 @@ +export const foo = () => 42; diff --git a/test/sourcemaps/samples/combined-sourcemap/main.js b/test/sourcemaps/samples/combined-sourcemap/main.js new file mode 100644 index 00000000000..61b585e055c --- /dev/null +++ b/test/sourcemaps/samples/combined-sourcemap/main.js @@ -0,0 +1,3 @@ +import { foo } from './foo'; + +console.info( `the answer is ${foo()}` ); From c2afe8ad375fa984e7776b08b577c3540bb440a6 Mon Sep 17 00:00:00 2001 From: Billow Z Date: Sat, 13 Jul 2019 10:15:18 +0800 Subject: [PATCH 2/4] Update the code and doc style of combined sourcemap --- docs/05-plugin-development.md | 8 ++++---- src/utils/collapseSourcemaps.ts | 23 ++++++++++++----------- src/utils/transform.ts | 12 ++++++------ 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/docs/05-plugin-development.md b/docs/05-plugin-development.md index 6bebc8e5944..fd0cb163417 100644 --- a/docs/05-plugin-development.md +++ b/docs/05-plugin-development.md @@ -355,6 +355,10 @@ Get the file name of an asset, according to the `assetFileNames` output option p Get the file name of an emitted chunk. The file name will be relative to `outputOptions.dir`. +#### `this.getCombinedSourceMap() => SourceMap` + +Get the combined source maps of all previous plugins. This context function can only be used in [`transform`](guide/en/#transform) plugin hook. + #### `this.getModuleInfo(moduleId: string) => ModuleInfo` Returns additional information about the module in question in the form @@ -414,10 +418,6 @@ Use the second form if you need to add additional properties to your warning obj The `position` argument is a character index where the warning was raised. If present, Rollup will augment the warning object with `pos`, `loc` (a standard `{ file, line, column }` object) and `frame` (a snippet of code showing the error). -### `this.getCombinedSourceMap() => SourceMap` - -Get the combined source maps of all previous plugins. This context function can only be used in [`transform`](guide/en/#transform) plugin hook. - ### Deprecated Context Functions ☢️ These context utility functions have been deprecated and may be removed in a future Rollup version. diff --git a/src/utils/collapseSourcemaps.ts b/src/utils/collapseSourcemaps.ts index 286784a3a6b..c37b5f92aec 100644 --- a/src/utils/collapseSourcemaps.ts +++ b/src/utils/collapseSourcemaps.ts @@ -146,7 +146,7 @@ class Link { } } -function linkMapper(graph: Graph) { +function getLinkMap(graph: Graph) { return function linkMap(source: Source | Link, map: DecodedSourceMapOrMissing) { if (map.mappings) { return new Link(map, [source]); @@ -171,14 +171,15 @@ function linkMapper(graph: Graph) { }; } -function unionSourcemaps( +function getCollapsedSourcemap( id: string, originalCode: string, originalSourcemap: ExistingDecodedSourceMap | null, sourcemapChain: DecodedSourceMapOrMissing[], linkMap: (source: Source | Link, map: DecodedSourceMapOrMissing) => Link -) { +): Source | Link { let source: Source | Link; + if (!originalSourcemap) { source = new Source(id, originalCode); } else { @@ -205,11 +206,11 @@ export function collapseSourcemaps( bundleSourcemapChain: DecodedSourceMapOrMissing[], excludeContent: boolean ) { - const linkMap = linkMapper(bundle.graph); + const linkMap = getLinkMap(bundle.graph); const moduleSources = modules .filter(module => !module.excludeFromSourcemap) .map(module => - unionSourcemaps( + getCollapsedSourcemap( module.id, module.originalCode, module.originalSourcemap, @@ -241,20 +242,20 @@ export function collapseSourcemap( graph: Graph, id: string, originalCode: string, - originalSourcemap: ExistingDecodedSourceMap, + originalSourcemap: ExistingDecodedSourceMap | null, sourcemapChain: DecodedSourceMapOrMissing[] -) { +): ExistingDecodedSourceMap | null { if (!sourcemapChain.length) { return originalSourcemap; } - const source = unionSourcemaps( + const source = getCollapsedSourcemap( id, originalCode, originalSourcemap, sourcemapChain, - linkMapper(graph) + getLinkMap(graph) ) as Link; - - return source.traceMappings(); + const map = source.traceMappings(); + return { version: 3, ...map }; } diff --git a/src/utils/transform.ts b/src/utils/transform.ts index 5afff4c27dc..53a2823c3b3 100644 --- a/src/utils/transform.ts +++ b/src/utils/transform.ts @@ -1,4 +1,4 @@ -import MagicString, { DecodedSourceMap, SourceMap } from 'magic-string'; +import MagicString, { SourceMap } from 'magic-string'; import Graph from '../Graph'; import Module from '../Module'; import { @@ -6,7 +6,6 @@ import { DecodedSourceMapOrMissing, EmitAsset, EmittedChunk, - ExistingDecodedSourceMap, Plugin, PluginCache, PluginContext, @@ -168,7 +167,7 @@ export default function transform( graph, id, originalCode, - originalSourcemap as ExistingDecodedSourceMap, + originalSourcemap, sourcemapChain ); if (!combinedMap) { @@ -176,13 +175,14 @@ export default function transform( return magicString.generateMap({ includeContent: true, hires: true, source: id }); } if (originalSourcemap !== combinedMap) { - originalSourcemap = { version: 3, ...combinedMap }; + originalSourcemap = combinedMap; sourcemapChain.length = 0; } return new SourceMap({ ...combinedMap, - file: null as any - } as DecodedSourceMap); + file: null as any, + sourcesContent: combinedMap.sourcesContent as string[] + }); } }; } From b346928bcc6cf375ed7baa3625772b39b491b3c4 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sat, 13 Jul 2019 11:43:20 +0200 Subject: [PATCH 3/4] Update dependencies and fix security warnings --- package-lock.json | 186 +++++++++++++++++++++------------------------- package.json | 28 +++---- 2 files changed, 99 insertions(+), 115 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0d50c7d8759..1a53675ac18 100644 --- a/package-lock.json +++ b/package-lock.json @@ -101,9 +101,9 @@ "dev": true }, "@types/node": { - "version": "12.0.10", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.10.tgz", - "integrity": "sha512-LcsGbPomWsad6wmMNv7nBLw7YYYyfdYcz6xryKYQhx89c3XXan+8Q6AJ43G5XDIaklaVkK3mE4fCb0SBvMiPSQ==" + "version": "12.6.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.6.2.tgz", + "integrity": "sha512-gojym4tX0FWeV2gsW4Xmzo5wxGjXGm550oVUII7f7G5o4BV6c7DBdiG1RRQd+y1bvqRyYtPfMK85UM95vsapqQ==" }, "@types/normalize-package-data": { "version": "2.4.0", @@ -136,9 +136,9 @@ "integrity": "sha1-kbR5JYinc4wl813W9jdSovh3YTU=" }, "acorn": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz", - "integrity": "sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==" + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.2.0.tgz", + "integrity": "sha512-8oe72N3WPMjA+2zVG71Ia0nXZ8DpQH+QyyHO+p06jT8eg8FGG3FbcUIi8KziHlAfheJQZeoqbvq1mQSQHXKYLw==" }, "acorn-bigint": { "version": "0.4.0", @@ -165,9 +165,9 @@ "dev": true }, "acorn-walk": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-6.1.1.tgz", - "integrity": "sha512-OtUw6JUTgxA2QoqqmrmQ7F2NYqiBPi/L2jqHyFtllhOUvXYQXf0Z1CYUinIfyT4bTCGmrA7gX9FvHA81uzCoVw==", + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-6.2.0.tgz", + "integrity": "sha512-7evsyfH1cLOCdAzZAd43Cic04yKydNx0cF+7tiA19p1XnLLPU4dpCQOqpjqwokFe//vS0QqfqqjCS2JkiIs0cA==", "dev": true }, "ajv": { @@ -492,18 +492,18 @@ "dev": true }, "buble": { - "version": "0.19.7", - "resolved": "https://registry.npmjs.org/buble/-/buble-0.19.7.tgz", - "integrity": "sha512-YLgWxX/l+NnfotydBlxqCMPR4FREE4ubuHphALz0FxQ7u2hp3BzxTKQ4nKpapOaRJfEm1gukC68KnT2OymRK0g==", + "version": "0.19.8", + "resolved": "https://registry.npmjs.org/buble/-/buble-0.19.8.tgz", + "integrity": "sha512-IoGZzrUTY5fKXVkgGHw3QeXFMUNBFv+9l8a4QJKG1JhG3nCMHTdEX1DCOg8568E2Q9qvAQIiSokv6Jsgx8p2cA==", "dev": true, "requires": { "acorn": "^6.1.1", "acorn-dynamic-import": "^4.0.0", "acorn-jsx": "^5.0.1", "chalk": "^2.4.2", - "magic-string": "^0.25.2", + "magic-string": "^0.25.3", "minimist": "^1.2.0", - "os-homedir": "^1.0.1", + "os-homedir": "^2.0.0", "regexpu-core": "^4.5.4" }, "dependencies": { @@ -517,6 +517,12 @@ "escape-string-regexp": "^1.0.5", "supports-color": "^5.3.0" } + }, + "os-homedir": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-2.0.0.tgz", + "integrity": "sha512-saRNz0DSC5C/I++gFIaJTXoFJMRwiP5zHar5vV3xQ2TkgEw6hDCcU5F272JjUylpiVgBrZNQHnfjkLabTfb92Q==", + "dev": true } } }, @@ -1411,9 +1417,9 @@ "dev": true }, "execa": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/execa/-/execa-2.0.2.tgz", - "integrity": "sha512-CkFnhVuWj5stQUvRSeI+zAw0ME+Iprkew4HKSc491vOXLM+hKrDVn+QQoL2CIYy0CpvT0mY+MXlzPreNbuj/8A==", + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/execa/-/execa-2.0.3.tgz", + "integrity": "sha512-iM124nlyGSrXmuyZF1EMe83ESY2chIYVyDRZKgmcDynid2Q2v/+GuE7gNMl6Sy9Niwf4MC0DDxagOxeMPjuLsw==", "dev": true, "requires": { "cross-spawn": "^6.0.5", @@ -1427,12 +1433,6 @@ "strip-final-newline": "^2.0.0" }, "dependencies": { - "merge-stream": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", - "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", - "dev": true - }, "mimic-fn": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", @@ -2559,9 +2559,9 @@ } }, "is-path-cwd": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-2.1.0.tgz", - "integrity": "sha512-Sc5j3/YnM8tDeyCsVeKlm/0p95075DyLmDEIkSgQ7mXkrOX+uTCtmQFm0CYzVyJwcCCmO3k8qfJt17SxQwB5Zw==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-2.2.0.tgz", + "integrity": "sha512-w942bTcih8fdJPJmQHFzkS76NEP8Kzzvmw92cXsazb8intwLqPibPPdXf4ANdKV3rYMuuQYGIWtvz9JilB3NFQ==", "dev": true }, "is-path-in-cwd": { @@ -2598,9 +2598,9 @@ "dev": true }, "is-reference": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.1.2.tgz", - "integrity": "sha512-Kn5g8c7XHKejFOpTf2QN9YjiHHKl5xRj+2uAZf9iM2//nkBNi/NNeB5JMoun28nEaUVHyPUzqzhfRlfAirEjXg==", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.1.3.tgz", + "integrity": "sha512-W1iHHv/oyBb2pPxkBxtaewxa1BC58Pn5J0hogyCdefwUIvb6R+TGbAcIa4qPNYLqLhb3EnOgUf2MQkkF76BcKw==", "dev": true, "requires": { "@types/estree": "0.0.39" @@ -2734,6 +2734,15 @@ "supports-color": "^6.1.0" }, "dependencies": { + "merge-stream": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-1.0.1.tgz", + "integrity": "sha1-QEEgLVCKNCugAXQAjfDCUbjBNeE=", + "dev": true, + "requires": { + "readable-stream": "^2.0.1" + } + }, "supports-color": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.1.0.tgz", @@ -2829,9 +2838,9 @@ } }, "lint-staged": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-9.0.0.tgz", - "integrity": "sha512-32TJoaeyAaj3rvabaXWe0eOhAhnsYRixEmXuSxKbs0uczFbwVjoDhJ/s2g6r1v8jMTw7t5OzXlHR8iaKtz8nLQ==", + "version": "9.2.0", + "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-9.2.0.tgz", + "integrity": "sha512-K/CQWcxYunc8lGMNTFvtI4+ybJcHW3K4Ghudz2OrJhIWdW/i1WWu9rGiVj4yJ0+D/xh8a08kp5slt89VZC9Eqg==", "dev": true, "requires": { "chalk": "^2.4.2", @@ -3198,13 +3207,10 @@ } }, "merge-stream": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-1.0.1.tgz", - "integrity": "sha1-QEEgLVCKNCugAXQAjfDCUbjBNeE=", - "dev": true, - "requires": { - "readable-stream": "^2.0.1" - } + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", + "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", + "dev": true }, "micromatch": { "version": "4.0.2", @@ -3300,9 +3306,9 @@ } }, "mixin-deep": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.1.tgz", - "integrity": "sha512-8ZItLHeEgaqEvd5lYBXfm4EZSFCX29Jb9K+lAHhDKzReKBQKj3R+7NOF6tjqYi9t4oI8VUfaWITJQm86wnXGNQ==", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.2.tgz", + "integrity": "sha512-WRoDn//mXBiJ1H40rqa3vH0toePwSsGb45iInWlTySa+Uu4k3tYUSxa2v1KqAiLtvlrSzaExqS1gtk96A9zvEA==", "dev": true, "requires": { "for-in": "^1.0.2", @@ -4246,9 +4252,9 @@ "dev": true }, "regenerate-unicode-properties": { - "version": "8.0.2", - "resolved": "https://registry.npmjs.org/regenerate-unicode-properties/-/regenerate-unicode-properties-8.0.2.tgz", - "integrity": "sha512-SbA/iNrBUf6Pv2zU8Ekv1Qbhv92yxL4hiDa2siuxs4KKn4oOoMDHXjAf7+Nz9qinUQ46B1LcWEi/PhJfPWpZWQ==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/regenerate-unicode-properties/-/regenerate-unicode-properties-8.1.0.tgz", + "integrity": "sha512-LGZzkgtLY79GeXLm8Dp0BVLdQlWICzBnJz/ipWUgo59qBaZ+BHtq51P2q1uVZlppMuUAT37SDk39qUbjTWB7bA==", "dev": true, "requires": { "regenerate": "^1.4.0" @@ -4407,13 +4413,13 @@ } }, "rollup": { - "version": "1.16.3", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.16.3.tgz", - "integrity": "sha512-iXINUUEk2NTZXE3GcUtLQt2cvfQsAUXBQ8AFsDK8tg7Wp5bwTKdZXPdzB2IJQwHpdUNfsIgYMAfajurh7SVTnA==", + "version": "1.16.7", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.16.7.tgz", + "integrity": "sha512-P3GVcbVSLLjHWFLKGerYRe3Q/yggRXmTZFx/4WZf4wzGwO6hAg5jyMAFMQKc0dts8rFID4BQngfoz6yQbI7iMQ==", "dev": true, "requires": { "@types/estree": "0.0.39", - "@types/node": "^12.0.8", + "@types/node": "^12.0.10", "acorn": "^6.1.1" } }, @@ -4427,12 +4433,12 @@ } }, "rollup-plugin-buble": { - "version": "0.19.6", - "resolved": "https://registry.npmjs.org/rollup-plugin-buble/-/rollup-plugin-buble-0.19.6.tgz", - "integrity": "sha512-El5Fut4/wEO17ZN/n9BZvqd7DXXB2WbJr/DKvr89LXChC/cHllE0XwiUDeAalrTkgr0WrnyLDTCQvEv+cGywWQ==", + "version": "0.19.8", + "resolved": "https://registry.npmjs.org/rollup-plugin-buble/-/rollup-plugin-buble-0.19.8.tgz", + "integrity": "sha512-8J4zPk2DQdk3rxeZvxgzhHh/rm5nJkjwgcsUYisCQg1QbT5yagW+hehYEW7ZNns/NVbDCTv4JQ7h4fC8qKGOKw==", "dev": true, "requires": { - "buble": "^0.19.6", + "buble": "^0.19.8", "rollup-pluginutils": "^2.3.3" } }, @@ -4513,15 +4519,16 @@ } }, "rollup-plugin-terser": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/rollup-plugin-terser/-/rollup-plugin-terser-5.0.0.tgz", - "integrity": "sha512-W+jJ4opYnlmNyVW0vtRufs+EGf68BIJ7bnOazgz8mgz8pA9lUyrEifAhPs5y9M16wFeAyBGaRjKip4dnFBtXaw==", + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/rollup-plugin-terser/-/rollup-plugin-terser-5.1.1.tgz", + "integrity": "sha512-McIMCDEY8EU6Y839C09UopeRR56wXHGdvKKjlfiZG/GrP6wvZQ62u2ko/Xh1MNH2M9WDL+obAAHySljIZYCuPQ==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", "jest-worker": "^24.6.0", + "rollup-pluginutils": "^2.8.1", "serialize-javascript": "^1.7.0", - "terser": "^4.0.0" + "terser": "^4.1.0" } }, "rollup-plugin-typescript": { @@ -4642,9 +4649,9 @@ "dev": true }, "set-value": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-value/-/set-value-2.0.0.tgz", - "integrity": "sha512-hw0yxk9GT/Hr5yJEYnHNKYXkIA8mVJgd9ditYZCe16ZczcaELYYcfvaXesNACk2O8O0nTiPQcQhGUQj8JLzeeg==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/set-value/-/set-value-2.0.1.tgz", + "integrity": "sha512-JxHc1weCN68wRY0fhCoXpyK55m/XPHafOmK4UWD7m2CI14GMcFypt4w/0+NV5f/ZMby2F6S2wwA7fgynh9gWSw==", "dev": true, "requires": { "extend-shallow": "^2.0.1", @@ -4873,9 +4880,9 @@ "dev": true }, "sourcemap-codec": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.4.tgz", - "integrity": "sha512-CYAPYdBu34781kLHkaW3m6b/uUSyMOC2R61gcYMWooeuaGtjof86ZA/8T+qVPPt7np1085CR9hmMGrySwEc8Xg==", + "version": "1.4.6", + "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.6.tgz", + "integrity": "sha512-1ZooVLYFxC448piVLBbtOxFcXwnymH9oUF8nRd3CuYDVvkRBxRl6pB4Mtas5a4drtL+E8LDgFkQNcgIw6tc8Hg==", "dev": true }, "spdx-correct": { @@ -5031,9 +5038,9 @@ "dev": true }, "systemjs": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/systemjs/-/systemjs-4.0.0.tgz", - "integrity": "sha512-asE0z8PeNmCGEo6vxYYFvXTjUMnD3/CMoM8daFDNSI40y4CVm/Tc5pqF1c4uYqn0pREC6QQKxqRR1xHe+ckqsA==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/systemjs/-/systemjs-4.0.2.tgz", + "integrity": "sha512-pwVxyK545WKMi4Duw1LQprulXi1Z8/xiT8P4TkXAXd3oEsusOI2XFTSfldg+/NMfPC+CfQGI5B7MUpqdhflHpg==", "dev": true }, "table": { @@ -5093,14 +5100,14 @@ } }, "terser": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/terser/-/terser-4.0.2.tgz", - "integrity": "sha512-IWLuJqTvx97KP3uTYkFVn93cXO+EtlzJu8TdJylq+H0VBDlPMIfQA9MBS5Vc5t3xTEUG1q0hIfHMpAP2R+gWTw==", + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/terser/-/terser-4.1.2.tgz", + "integrity": "sha512-jvNoEQSPXJdssFwqPSgWjsOrb+ELoE+ILpHPKXC83tIxOlh2U75F1KuB2luLD/3a6/7K3Vw5pDn+hvu0C4AzSw==", "dev": true, "requires": { - "commander": "^2.19.0", + "commander": "^2.20.0", "source-map": "~0.6.1", - "source-map-support": "~0.5.10" + "source-map-support": "~0.5.12" } }, "text-table": { @@ -5248,9 +5255,9 @@ "dev": true }, "typescript": { - "version": "3.5.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.5.2.tgz", - "integrity": "sha512-7KxJovlYhTX5RaRbUdkAXN1KUZ8PwWlTzQdHV6xNqvuFOs7+WBo10TQUqT19Q/Jz2hk5v9TQDIhyLhhJY4p5AA==", + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.5.3.tgz", + "integrity": "sha512-ACzBtm/PhXBDId6a6sDJfroT2pOWt/oOnk4/dElG5G33ZL776N3Y6/6bKZJBFpd+b05F3Ct9qDjMeJmRWtE2/g==", "dev": true }, "uc.micro": { @@ -5299,38 +5306,15 @@ "dev": true }, "union-value": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.0.tgz", - "integrity": "sha1-XHHDTLW61dzr4+oM0IIHulqhrqQ=", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz", + "integrity": "sha512-tJfXmxMeWYnczCVs7XAEvIV7ieppALdyepWMkHkwciRpZraG/xwT+s2JN8+pr1+8jCRf80FFzvr+MpQeeoF4Xg==", "dev": true, "requires": { "arr-union": "^3.1.0", "get-value": "^2.0.6", "is-extendable": "^0.1.1", - "set-value": "^0.4.3" - }, - "dependencies": { - "extend-shallow": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", - "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", - "dev": true, - "requires": { - "is-extendable": "^0.1.0" - } - }, - "set-value": { - "version": "0.4.3", - "resolved": "https://registry.npmjs.org/set-value/-/set-value-0.4.3.tgz", - "integrity": "sha1-fbCPnT0i3H945Trzw79GZuzfzPE=", - "dev": true, - "requires": { - "extend-shallow": "^2.0.1", - "is-extendable": "^0.1.1", - "is-plain-object": "^2.0.1", - "to-object-path": "^0.3.0" - } - } + "set-value": "^2.0.1" } }, "universalify": { diff --git a/package.json b/package.json index 646d93fcc9a..bef69808d8b 100644 --- a/package.json +++ b/package.json @@ -61,8 +61,8 @@ "homepage": "https://github.com/rollup/rollup", "dependencies": { "@types/estree": "0.0.39", - "@types/node": "^12.0.10", - "acorn": "^6.1.1" + "@types/node": "^12.6.2", + "acorn": "^6.2.0" }, "devDependencies": { "@types/chokidar": "^2.1.3", @@ -72,8 +72,8 @@ "acorn-dynamic-import": "^4.0.0", "acorn-import-meta": "^1.0.0", "acorn-jsx": "^5.0.1", - "acorn-walk": "^6.1.1", - "buble": "^0.19.7", + "acorn-walk": "^6.2.0", + "buble": "^0.19.8", "chokidar": "^2.1.6", "console-group": "^0.3.3", "core-js": "^3.1.4", @@ -82,14 +82,14 @@ "es6-shim": "^0.35.5", "eslint": "^6.0.1", "eslint-plugin-import": "^2.18.0", - "execa": "^2.0.2", + "execa": "^2.0.3", "fixturify": "^1.2.0", "hash.js": "^1.1.7", "husky": "^3.0.0", "immutable": "^4.0.0-rc.12", - "is-reference": "^1.1.2", + "is-reference": "^1.1.3", "istanbul": "^0.4.5", - "lint-staged": "^9.0.0", + "lint-staged": "^9.2.0", "locate-character": "^2.0.5", "magic-string": "^0.25.3", "markdownlint-cli": "^0.17.0", @@ -102,15 +102,15 @@ "remap-istanbul": "^0.13.0", "require-relative": "^0.8.7", "requirejs": "^2.3.6", - "rollup": "^1.16.3", + "rollup": "^1.16.7", "rollup-plugin-alias": "^1.5.2", - "rollup-plugin-buble": "^0.19.6", + "rollup-plugin-buble": "^0.19.8", "rollup-plugin-commonjs": "^10.0.1", "rollup-plugin-json": "^4.0.0", "rollup-plugin-node-resolve": "^5.2.0", "rollup-plugin-replace": "^2.2.0", "rollup-plugin-string": "^3.0.0", - "rollup-plugin-terser": "^5.0.0", + "rollup-plugin-terser": "^5.1.1", "rollup-plugin-typescript": "^1.0.1", "rollup-pluginutils": "^2.8.1", "sander": "^0.6.0", @@ -118,13 +118,13 @@ "signal-exit": "^3.0.2", "source-map": "^0.6.1", "source-map-support": "^0.5.12", - "sourcemap-codec": "^1.4.4", - "systemjs": "^4.0.0", - "terser": "^4.0.2", + "sourcemap-codec": "^1.4.6", + "systemjs": "^4.0.2", + "terser": "^4.1.2", "tslib": "^1.10.0", "tslint": "^5.18.0", "turbocolor": "^2.6.1", - "typescript": "^3.5.2", + "typescript": "^3.5.3", "url-parse": "^1.4.7" }, "files": [ From ee82f06fa9c8e5d22b3e322a7b4c965caa79b1ed Mon Sep 17 00:00:00 2001 From: Billow Z Date: Sun, 14 Jul 2019 23:21:38 +0000 Subject: [PATCH 4/4] Rename getCombinedSourcemap --- docs/05-plugin-development.md | 2 +- src/utils/transform.ts | 2 +- .../samples/combined-sourcemap-with-loader/_config.js | 4 ++-- test/sourcemaps/samples/combined-sourcemap/_config.js | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/05-plugin-development.md b/docs/05-plugin-development.md index fd0cb163417..0abc711e461 100644 --- a/docs/05-plugin-development.md +++ b/docs/05-plugin-development.md @@ -355,7 +355,7 @@ Get the file name of an asset, according to the `assetFileNames` output option p Get the file name of an emitted chunk. The file name will be relative to `outputOptions.dir`. -#### `this.getCombinedSourceMap() => SourceMap` +#### `this.getCombinedSourcemap() => SourceMap` Get the combined source maps of all previous plugins. This context function can only be used in [`transform`](guide/en/#transform) plugin hook. diff --git a/src/utils/transform.ts b/src/utils/transform.ts index 53a2823c3b3..03185b922a7 100644 --- a/src/utils/transform.ts +++ b/src/utils/transform.ts @@ -162,7 +162,7 @@ export default function transform( } } }, - getCombinedSourceMap() { + getCombinedSourcemap() { const combinedMap = collapseSourcemap( graph, id, diff --git a/test/sourcemaps/samples/combined-sourcemap-with-loader/_config.js b/test/sourcemaps/samples/combined-sourcemap-with-loader/_config.js index 895cd5c112c..9fbc3df9b3e 100644 --- a/test/sourcemaps/samples/combined-sourcemap-with-loader/_config.js +++ b/test/sourcemaps/samples/combined-sourcemap-with-loader/_config.js @@ -23,7 +23,7 @@ module.exports = { }, { transform(code, id) { - const sourcemap = this.getCombinedSourceMap(); + const sourcemap = this.getCombinedSourcemap(); const smc = new SourceMapConsumer(sourcemap); const s = new MagicString(code); @@ -47,7 +47,7 @@ module.exports = { }, { transform(code, id) { - const sourcemap = this.getCombinedSourceMap(); + const sourcemap = this.getCombinedSourcemap(); const smc = new SourceMapConsumer(sourcemap); const s = new MagicString(code); diff --git a/test/sourcemaps/samples/combined-sourcemap/_config.js b/test/sourcemaps/samples/combined-sourcemap/_config.js index 02c7ddee0bb..184c9ec8902 100644 --- a/test/sourcemaps/samples/combined-sourcemap/_config.js +++ b/test/sourcemaps/samples/combined-sourcemap/_config.js @@ -9,7 +9,7 @@ module.exports = { plugins: [ { transform(code, id) { - const sourcemap = this.getCombinedSourceMap(); + const sourcemap = this.getCombinedSourcemap(); const smc = new SourceMapConsumer(sourcemap); const s = new MagicString(code); @@ -33,7 +33,7 @@ module.exports = { }, { transform(code, id) { - const sourcemap = this.getCombinedSourceMap(); + const sourcemap = this.getCombinedSourcemap(); const smc = new SourceMapConsumer(sourcemap); const s = new MagicString(code);