From d6c9733e114755b08e6b11cd09914c5dfdaae2cc Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 30 Dec 2015 16:07:27 -0500 Subject: [PATCH] Revert "Add transformBundle plugin hook" --- package.json | 3 +- src/Bundle.js | 7 +-- src/utils/transformBundle.js | 39 --------------- test/form/transform-bundle-plugin/_config.js | 17 ------- .../transform-bundle-plugin/_expected/amd.js | 2 - .../transform-bundle-plugin/_expected/cjs.js | 2 - .../transform-bundle-plugin/_expected/es6.js | 2 - .../transform-bundle-plugin/_expected/iife.js | 2 - .../transform-bundle-plugin/_expected/umd.js | 2 - test/form/transform-bundle-plugin/main.js | 1 - test/sourcemaps/transform-bundle/_config.js | 47 ------------------- test/sourcemaps/transform-bundle/main.js | 1 - 12 files changed, 2 insertions(+), 123 deletions(-) delete mode 100644 src/utils/transformBundle.js delete mode 100644 test/form/transform-bundle-plugin/_config.js delete mode 100644 test/form/transform-bundle-plugin/_expected/amd.js delete mode 100644 test/form/transform-bundle-plugin/_expected/cjs.js delete mode 100644 test/form/transform-bundle-plugin/_expected/es6.js delete mode 100644 test/form/transform-bundle-plugin/_expected/iife.js delete mode 100644 test/form/transform-bundle-plugin/_expected/umd.js delete mode 100644 test/form/transform-bundle-plugin/main.js delete mode 100644 test/sourcemaps/transform-bundle/_config.js delete mode 100644 test/sourcemaps/transform-bundle/main.js diff --git a/package.json b/package.json index eaea497..67b1596 100644 --- a/package.json +++ b/package.json @@ -57,8 +57,7 @@ "rollup-plugin-replace": "^1.0.1", "sander": "^0.4.0", "source-map": "^0.5.3", - "sourcemap-codec": "^1.2.1", - "uglify-js": "^2.6.1" + "sourcemap-codec": "^1.2.1" }, "dependencies": { "chalk": "^1.1.1", diff --git a/src/Bundle.js b/src/Bundle.js index d224bef..950ae9c 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -11,7 +11,6 @@ import getExportMode from './utils/getExportMode.js'; import getIndentString from './utils/getIndentString.js'; import { unixizePath } from './utils/normalizePlatform.js'; import transform from './utils/transform.js'; -import transformBundle from './utils/transformBundle.js'; import collapseSourcemaps from './utils/collapseSourcemaps.js'; import callIfFunction from './utils/callIfFunction.js'; import { isRelative } from './utils/path.js'; @@ -47,10 +46,6 @@ export default class Bundle { .map( plugin => plugin.transform ) .filter( Boolean ); - this.bundleTransformers = this.plugins - .map( plugin => plugin.transformBundle ) - .filter( Boolean ); - this.moduleById = blank(); this.modules = []; @@ -262,7 +257,7 @@ export default class Bundle { map.sources = map.sources.map( unixizePath ); } - return transformBundle( { code, map }, this.bundleTransformers ); + return { code, map }; } sort () { diff --git a/src/utils/transformBundle.js b/src/utils/transformBundle.js deleted file mode 100644 index efbe3a1..0000000 --- a/src/utils/transformBundle.js +++ /dev/null @@ -1,39 +0,0 @@ -import MagicString from 'magic-string'; - -export default function transformBundle ( source, transformers ) { - if ( typeof source === 'string' ) { - source = { - code: source, - map: null - }; - } - - return transformers.reduce( ( previous, transformer ) => { - let result = transformer( previous.code, previous.map ); - - if ( result == null ) return previous; - - if ( typeof result === 'string' ) { - result = { - code: result, - map: null - }; - } - // `result.map` can only be a string if `result` isn't - else if ( typeof result.map === 'string' ) { - result.map = JSON.parse( result.map ); - } - - if (result.map != null) { - let map = new MagicString.Bundle().generateMap({}); - map.file = result.map.file; - map.sources = result.map.sources; - map.sourcesContent = result.map.sourcesContent; - map.names = result.map.names; - map.mappings = result.map.mappings; - result.map = map; - } - - return result; - }, source ); -} diff --git a/test/form/transform-bundle-plugin/_config.js b/test/form/transform-bundle-plugin/_config.js deleted file mode 100644 index 6b54ad3..0000000 --- a/test/form/transform-bundle-plugin/_config.js +++ /dev/null @@ -1,17 +0,0 @@ -module.exports = { - description: 'allows plugins to transform bundle', - options: { - plugins: [ - { - transformBundle: function (code) { - return '/* first plugin */'; - } - }, - { - transformBundle: function (code) { - return code + '\n/* second plugin */'; - } - } - ] - } -} diff --git a/test/form/transform-bundle-plugin/_expected/amd.js b/test/form/transform-bundle-plugin/_expected/amd.js deleted file mode 100644 index f783236..0000000 --- a/test/form/transform-bundle-plugin/_expected/amd.js +++ /dev/null @@ -1,2 +0,0 @@ -/* first plugin */ -/* second plugin */ \ No newline at end of file diff --git a/test/form/transform-bundle-plugin/_expected/cjs.js b/test/form/transform-bundle-plugin/_expected/cjs.js deleted file mode 100644 index f783236..0000000 --- a/test/form/transform-bundle-plugin/_expected/cjs.js +++ /dev/null @@ -1,2 +0,0 @@ -/* first plugin */ -/* second plugin */ \ No newline at end of file diff --git a/test/form/transform-bundle-plugin/_expected/es6.js b/test/form/transform-bundle-plugin/_expected/es6.js deleted file mode 100644 index f783236..0000000 --- a/test/form/transform-bundle-plugin/_expected/es6.js +++ /dev/null @@ -1,2 +0,0 @@ -/* first plugin */ -/* second plugin */ \ No newline at end of file diff --git a/test/form/transform-bundle-plugin/_expected/iife.js b/test/form/transform-bundle-plugin/_expected/iife.js deleted file mode 100644 index f783236..0000000 --- a/test/form/transform-bundle-plugin/_expected/iife.js +++ /dev/null @@ -1,2 +0,0 @@ -/* first plugin */ -/* second plugin */ \ No newline at end of file diff --git a/test/form/transform-bundle-plugin/_expected/umd.js b/test/form/transform-bundle-plugin/_expected/umd.js deleted file mode 100644 index f783236..0000000 --- a/test/form/transform-bundle-plugin/_expected/umd.js +++ /dev/null @@ -1,2 +0,0 @@ -/* first plugin */ -/* second plugin */ \ No newline at end of file diff --git a/test/form/transform-bundle-plugin/main.js b/test/form/transform-bundle-plugin/main.js deleted file mode 100644 index 934dee7..0000000 --- a/test/form/transform-bundle-plugin/main.js +++ /dev/null @@ -1 +0,0 @@ -console.log( 1 + 1 ); diff --git a/test/sourcemaps/transform-bundle/_config.js b/test/sourcemaps/transform-bundle/_config.js deleted file mode 100644 index abb986d..0000000 --- a/test/sourcemaps/transform-bundle/_config.js +++ /dev/null @@ -1,47 +0,0 @@ -var uglify = require( 'uglify-js' ); -var MagicString = require( 'magic-string' ); -var assert = require( 'assert' ); -var getLocation = require( '../../utils/getLocation' ); -var SourceMapConsumer = require( 'source-map' ).SourceMapConsumer; - -module.exports = { - description: 'preserves sourcemap chains when transforming', - options: { - plugins: [ - { - transformBundle: function ( code, map ) { - var options = { fromString: true }; - - if ( map != null ) { - options.inSourceMap = map; - options.outSourceMap = "out"; - } - - var result = uglify.minify( code, options ); - - if ( map != null ) { - result.code = result.code.slice( 0, -25 ); - } - - return result; - } - } - ] - }, - test: function ( code, map ) { - var smc = new SourceMapConsumer( map ); - - var generatedLoc = getLocation( code, code.indexOf( '42' ) ); - var originalLoc = smc.originalPositionFor( generatedLoc ); - - assert.ok( /main/.test( originalLoc.source ) ); - assert.equal( originalLoc.line, 1 ); - assert.equal( originalLoc.column, 13 ); - - generatedLoc = getLocation( code, code.indexOf( 'log' ) ); - originalLoc = smc.originalPositionFor( generatedLoc ); - - assert.equal( originalLoc.line, 1 ); - assert.equal( originalLoc.column, 8 ); - } -}; diff --git a/test/sourcemaps/transform-bundle/main.js b/test/sourcemaps/transform-bundle/main.js deleted file mode 100644 index 5c72ff3..0000000 --- a/test/sourcemaps/transform-bundle/main.js +++ /dev/null @@ -1 +0,0 @@ -console.log( 42 );