Skip to content

Commit 1dc020a

Browse files
Update rollup to version > 1 (#252)
* Update rollup to version > 1 * require node >= 10
1 parent 0e39242 commit 1dc020a

18 files changed

+48
-101
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"author": "The AMP HTML Authors",
1515
"engines": {
16-
"node": ">=12"
16+
"node": ">=10"
1717
},
1818
"keywords": [
1919
"rollup-plugin"
@@ -32,7 +32,7 @@
3232
"prepublishOnly": "npm-run-all build"
3333
},
3434
"peerDependencies": {
35-
"rollup": ">= 0.67.4"
35+
"rollup": ">=1.27"
3636
},
3737
"dependencies": {
3838
"acorn": "7.1.0",
@@ -57,7 +57,7 @@
5757
"npm-run-all": "4.1.5",
5858
"prettier": "1.19.1",
5959
"rimraf": "3.0.0",
60-
"rollup": "0.67.4",
60+
"rollup": "1.27.13",
6161
"sirv-cli": "0.4.5",
6262
"tslint": "5.20.1",
6363
"typescript": "3.7.3"

src/index.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import { CompileOptions } from 'google-closure-compiler';
1818
import { promises as fsPromises } from 'fs';
1919
import {
2020
OutputOptions,
21-
RawSourceMap,
2221
Plugin,
2322
InputOptions,
2423
PluginContext,
2524
RenderedChunk,
25+
SourceMapInput,
2626
} from 'rollup';
2727
import compiler from './compiler';
2828
import options from './options';
@@ -42,7 +42,7 @@ const renderChunk = async (
4242
requestedCompileOptions: CompileOptions = {},
4343
sourceCode: string,
4444
outputOptions: OutputOptions,
45-
): Promise<{ code: string; map: RawSourceMap } | void> => {
45+
): Promise<{ code: string; map: SourceMapInput } | void> => {
4646
const code = await preCompilation(sourceCode, outputOptions, transforms);
4747
const [compileOptions, mapFile] = options(
4848
requestedCompileOptions,
@@ -51,14 +51,14 @@ const renderChunk = async (
5151
transforms,
5252
);
5353

54-
return compiler(compileOptions, transforms).then(
55-
async code => {
56-
return { code, map: JSON.parse(await fsPromises.readFile(mapFile, 'utf8')) };
57-
},
58-
(error: Error) => {
59-
throw error;
60-
},
61-
);
54+
try {
55+
return {
56+
code: await compiler(compileOptions, transforms),
57+
map: JSON.parse(await fsPromises.readFile(mapFile, 'utf8')),
58+
};
59+
} catch (error) {
60+
throw error;
61+
}
6262
};
6363

6464
export default function closureCompiler(requestedCompileOptions: CompileOptions = {}): Plugin {
@@ -73,16 +73,17 @@ export default function closureCompiler(requestedCompileOptions: CompileOptions
7373
if (
7474
'compilation_level' in requestedCompileOptions &&
7575
requestedCompileOptions.compilation_level === 'ADVANCED_OPTIMIZATIONS' &&
76-
inputOptions.experimentalCodeSplitting
76+
Array.isArray(inputOptions.input)
7777
) {
7878
context.warn(
79-
'Rollup experimentalCodeSplitting with Closure Compiler ADVANCED_OPTIMIZATIONS is not currently supported.',
79+
'Code Splitting with Closure Compiler ADVANCED_OPTIMIZATIONS is not currently supported.',
8080
);
8181
}
8282
},
8383
renderChunk: async (code: string, chunk: RenderedChunk, outputOptions: OutputOptions) => {
8484
const transforms = createTransforms(context, inputOptions);
85-
return await renderChunk(transforms, requestedCompileOptions, code, outputOptions);
85+
const output = await renderChunk(transforms, requestedCompileOptions, code, outputOptions);
86+
return output || null;
8687
},
8788
};
8889
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
var foo=1;var bar=function(){console.log(1)};export{foo,bar};
1+
var bar=function(){console.log(1)};var foo=1;export{bar,foo};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
var foo=1;var bar=function(){console.log(1)};export{foo,bar};
1+
var bar=function(){console.log(1)};var foo=1;export{bar,foo};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
var foo=1;var bar=function(){console.log(1)};export{foo,bar};
1+
var bar=function(){console.log(1)};var foo=1;export{bar,foo};

test/generator.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const fixtureLocation = (category, name, format, optionsKey, minified = false) =
5050
: `${name}.js`
5151
}`;
5252

53-
async function compile(category, name, codeSplit, closureFlags, optionKey, format) {
53+
async function compile(category, name, codeSplit, closureFlags, optionKey, format, wrapper) {
5454
const bundle = await rollup.rollup({
5555
input: fixtureLocation(category, name, format, optionKey, false),
5656
plugins: [compiler(closureFlags[optionKey])],
@@ -61,6 +61,7 @@ async function compile(category, name, codeSplit, closureFlags, optionKey, forma
6161

6262
const bundles = await bundle.generate({
6363
format,
64+
name: wrapper,
6465
sourcemap: true,
6566
});
6667

@@ -100,7 +101,7 @@ async function compile(category, name, codeSplit, closureFlags, optionKey, forma
100101
return output;
101102
}
102103

103-
function generate(shouldFail, category, name, codeSplit, formats, closureFlags) {
104+
function generate(shouldFail, category, name, codeSplit, formats, closureFlags, wrapper) {
104105
const targetLength = longest(formats);
105106
const optionLength = longest(Object.keys(closureFlags));
106107

@@ -110,7 +111,7 @@ function generate(shouldFail, category, name, codeSplit, formats, closureFlags)
110111
method(
111112
`${name}${format.padEnd(targetLength)}${optionKey.padEnd(optionLength)}`,
112113
async t => {
113-
const output = await compile(category, name, codeSplit, closureFlags, optionKey, format);
114+
const output = await compile(category, name, codeSplit, closureFlags, optionKey, format, wrapper);
114115

115116
t.plan(output.length);
116117
for (result of output) {
@@ -128,8 +129,9 @@ function failureGenerator(
128129
codeSplit = false,
129130
formats = [ESM_OUTPUT],
130131
closureFlags = defaultClosureFlags,
132+
wrapper = null,
131133
) {
132-
generate(true, category, name, codeSplit, formats, closureFlags);
134+
generate(true, category, name, codeSplit, formats, closureFlags, wrapper);
133135
}
134136

135137
function generator(
@@ -138,8 +140,9 @@ function generator(
138140
codeSplit = false,
139141
formats = [ESM_OUTPUT],
140142
closureFlags = defaultClosureFlags,
143+
wrapper = null,
141144
) {
142-
generate(false, category, name, codeSplit, formats, closureFlags);
145+
generate(false, category, name, codeSplit, formats, closureFlags, wrapper);
143146
}
144147

145148
module.exports = {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function greeting(name) {
2+
document.body.innerHTML = 'hello ' + name;
3+
}

0 commit comments

Comments
 (0)