Skip to content

Commit

Permalink
Merge pull request #125 from xg-wang/rollup_iife
Browse files Browse the repository at this point in the history
Rollup dependencies
  • Loading branch information
xg-wang authored Aug 23, 2018
2 parents 6fd5bda + d7a7789 commit 7199051
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 13 deletions.
43 changes: 36 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ const path = require('path');
// * find - finds files in a tree based on a glob pattern
// * map - map content of files in a tree
//
// broccoli-rollup: rollup dependencies to expected module format
//
const stew = require('broccoli-stew');
const Template = require('broccoli-templater');
const MergeTrees = require('broccoli-merge-trees');
const concat = require('broccoli-concat');
const map = stew.map;
const Rollup = require('broccoli-rollup');
const babel = require('rollup-plugin-babel');

/*
* The `index.js` file is the main entry point for all Ember CLI addons. The
Expand Down Expand Up @@ -121,26 +125,51 @@ module.exports = {
}
};

// Path to the template that contains the shim wrapper around the browser
// polyfill
// Path to the template that contains the shim wrapper around the browser polyfill
const templatePath = path.resolve(__dirname + '/assets/browser-fetch.js.t');


// Returns a tree containing the browser polyfill (from `whatwg-fetch` and `abortcontroller-polyfill`),
// wrapped in a shim that stops it from exporting a global and instead turns it into a module
// that can be used by the Ember app.
function treeForBrowserFetch() {
const abortcontrollerNode = new Rollup(path.dirname(path.dirname(require.resolve('abortcontroller-polyfill'))), {
rollup: {
input: 'src/abortcontroller-polyfill.js',
output: {
file: 'abortcontroller.js',
// abortcontroller is polyfill only, the name is only required by rollup iife
name: 'AbortController',
format: 'iife'
},
plugins: [
babel({
babelrc: false,
presets: [['env', { modules: false }]]
})
]
}
});
// Fork whatwg-fetch to provide umd build before official release, no extra change made.
// We will get back to the official one when new version released.
const fetchTree = path.dirname(require.resolve('@xg-wang/whatwg-fetch'));
const abortcontrollerTree = path.dirname(require.resolve('abortcontroller-polyfill'));
const polyfillTree = concat(new MergeTrees([abortcontrollerTree, fetchTree]), {
inputFiles: ['abortcontroller-polyfill-only.js', 'fetch.umd.js'],
const fetchNode = new Rollup(path.dirname(path.dirname(require.resolve('@xg-wang/whatwg-fetch'))), {
rollup: {
input: 'fetch.js',
output: {
file: 'fetch.js',
name: 'WHATWGFetch',
format: 'iife'
}
}
});

const polyfillNode = concat(new MergeTrees([abortcontrollerNode, fetchNode]), {
inputFiles: ['abortcontroller.js', 'fetch.js'],
outputFile: 'ember-fetch.js',
sourceMapConfig: { enabled: false }
});

return new Template(polyfillTree, templatePath, function(content) {
return new Template(polyfillNode, templatePath, function(content) {
return {
moduleBody: content
};
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@
"dependencies": {
"@xg-wang/whatwg-fetch": "^3.0.0",
"abortcontroller-polyfill": "^1.1.9",
"babel-preset-env": "^1.7.0",
"broccoli-concat": "^3.2.2",
"broccoli-merge-trees": "^3.0.0",
"broccoli-rollup": "^2.1.1",
"broccoli-stew": "^2.0.0",
"broccoli-templater": "^2.0.1",
"ember-cli-babel": "^6.8.2",
"node-fetch": "^2.0.0-alpha.9"
"node-fetch": "^2.0.0-alpha.9",
"rollup-plugin-babel": "^3.0.7"
},
"devDependencies": {
"broccoli-asset-rev": "^2.4.5",
Expand Down
2 changes: 0 additions & 2 deletions test/prefer-native-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ const expect = require('chai').expect;
const helpers = require('broccoli-test-helper');
const vm = require('vm');
const fs = require('fs');
const path = require('path');
const templatePath = path.resolve(__dirname + '/assets/browser-fetch.js.t');
const RSVP = require('rsvp');

const testCode = `
Expand Down
134 changes: 131 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@
version "0.7.0"
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.7.0.tgz#9a06f4f137ee84d7df0460c1fdb1135ffa6c50fd"

"@types/acorn@^4.0.3":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@types/acorn/-/acorn-4.0.3.tgz#d1f3e738dde52536f9aad3d3380d14e448820afd"
dependencies:
"@types/estree" "*"

"@types/estree@*":
version "0.0.39"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"

"@types/estree@0.0.38":
version "0.0.38"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.38.tgz#c1be40aa933723c608820a99a373a16d215a1ca2"

"@types/node@^9.6.0":
version "9.6.28"
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.6.28.tgz#198927ce0786106ec2a7c8652d46d5f8b87bfc5f"

"@xg-wang/whatwg-fetch@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@xg-wang/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz#f7b222c012a238e7d6e89ed3d72a1e0edb58453d"
Expand All @@ -43,6 +61,12 @@ accepts@~1.3.4, accepts@~1.3.5:
mime-types "~2.1.18"
negotiator "0.6.1"

acorn-dynamic-import@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/acorn-dynamic-import/-/acorn-dynamic-import-3.0.0.tgz#901ceee4c7faaef7e07ad2a47e890675da50a278"
dependencies:
acorn "^5.0.0"

acorn-jsx@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-3.0.1.tgz#afdf9488fb1ecefc8348f6fb22f464e32a58b36b"
Expand All @@ -53,7 +77,7 @@ acorn@^3.0.4:
version "3.3.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a"

acorn@^5.5.0:
acorn@^5.0.0, acorn@^5.5.0, acorn@^5.5.3:
version "5.7.1"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.1.tgz#f095829297706a7c9776958c0afc8930a9b9d9d8"

Expand Down Expand Up @@ -94,7 +118,7 @@ amd-name-resolver@1.0.0:
dependencies:
ensure-posix-path "^1.0.1"

amd-name-resolver@1.2.0:
amd-name-resolver@1.2.0, amd-name-resolver@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/amd-name-resolver/-/amd-name-resolver-1.2.0.tgz#fc41b3848824b557313897d71f8d5a0184fbe679"
dependencies:
Expand Down Expand Up @@ -1201,6 +1225,22 @@ broccoli-rollup@^1.2.0:
symlink-or-copy "^1.1.8"
walk-sync "^0.3.1"

broccoli-rollup@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/broccoli-rollup/-/broccoli-rollup-2.1.1.tgz#0b77dc4b7560a53e998ea85f3b56772612d4988d"
dependencies:
"@types/node" "^9.6.0"
amd-name-resolver "^1.2.0"
broccoli-plugin "^1.2.1"
fs-tree-diff "^0.5.2"
heimdalljs "^0.2.1"
heimdalljs-logger "^0.1.7"
magic-string "^0.24.0"
node-modules-path "^1.0.1"
rollup "^0.57.1"
symlink-or-copy "^1.1.8"
walk-sync "^0.3.1"

broccoli-slow-trees@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/broccoli-slow-trees/-/broccoli-slow-trees-2.0.0.tgz#9741afe992787add64aec7f7c8211dfcc058278d"
Expand Down Expand Up @@ -1821,6 +1861,12 @@ dag-map@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/dag-map/-/dag-map-2.0.2.tgz#9714b472de82a1843de2fba9b6876938cab44c68"

date-time@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/date-time/-/date-time-2.1.0.tgz#0286d1b4c769633b3ca13e1e62558d2dbdc2eba2"
dependencies:
time-zone "^1.0.0"

debug@2.6.9, debug@^2.1.0, debug@^2.1.1, debug@^2.1.2, debug@^2.1.3, debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
Expand Down Expand Up @@ -2615,6 +2661,14 @@ estraverse@^4.0.0, estraverse@^4.1.0, estraverse@^4.1.1:
version "4.2.0"
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.2.0.tgz#0dee3fed31fcd469618ce7342099fc1afa0bdb13"

estree-walker@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.2.1.tgz#bdafe8095383d8414d5dc2ecf4c9173b6db9412e"

estree-walker@^0.5.2:
version "0.5.2"
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.5.2.tgz#d3850be7529c9580d815600b53126515e146dd39"

esutils@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b"
Expand Down Expand Up @@ -3776,6 +3830,12 @@ is-promise@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/is-promise/-/is-promise-2.1.0.tgz#79a2a9ece7f096e80f36d2b2f3bc16c1ff4bf3fa"

is-reference@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-reference/-/is-reference-1.1.0.tgz#50e6ef3f64c361e2c53c0416cdc9420037f2685b"
dependencies:
"@types/estree" "0.0.38"

is-resolvable@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-resolvable/-/is-resolvable-1.1.0.tgz#fb18f87ce1feb925169c9a407c19318a3206ed88"
Expand Down Expand Up @@ -4003,6 +4063,10 @@ loader.js@^4.2.3:
version "4.7.0"
resolved "https://registry.yarnpkg.com/loader.js/-/loader.js-4.7.0.tgz#a1a52902001c83631efde9688b8ab3799325ef1f"

locate-character@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/locate-character/-/locate-character-2.0.5.tgz#f2d2614d49820ecb3c92d80d193b8db755f74c0f"

locate-path@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"
Expand Down Expand Up @@ -4379,6 +4443,12 @@ lru-cache@^4.0.1:
pseudomap "^1.0.2"
yallist "^2.1.2"

magic-string@^0.24.0:
version "0.24.1"
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.24.1.tgz#7e38e5f126cae9f15e71f0cf8e450818ca7d5a8f"
dependencies:
sourcemap-codec "^1.4.1"

make-array@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/make-array/-/make-array-0.1.2.tgz#335e36ebb0c5a43154d21213a1ecaeae2a1bb3ef"
Expand Down Expand Up @@ -4514,7 +4584,7 @@ methods@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"

micromatch@^2.1.5, micromatch@^2.3.7:
micromatch@^2.1.5, micromatch@^2.3.11, micromatch@^2.3.7:
version "2.3.11"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565"
dependencies:
Expand Down Expand Up @@ -5014,6 +5084,10 @@ parse-json@^2.2.0:
dependencies:
error-ex "^1.2.0"

parse-ms@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/parse-ms/-/parse-ms-1.0.1.tgz#56346d4749d78f23430ca0c713850aef91aa361d"

parse-passwd@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6"
Expand Down Expand Up @@ -5144,6 +5218,12 @@ pretender@^2.1.0:
fake-xml-http-request "^2.0.0"
route-recognizer "^0.3.3"

pretty-ms@^3.1.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/pretty-ms/-/pretty-ms-3.2.0.tgz#87a8feaf27fc18414d75441467d411d6e6098a25"
dependencies:
parse-ms "^1.0.0"

printf@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/printf/-/printf-0.3.0.tgz#6918ca5237c047e19cf004b69e6bcfafbef1ce82"
Expand Down Expand Up @@ -5400,6 +5480,10 @@ repeating@^2.0.0:
dependencies:
is-finite "^1.0.0"

require-relative@^0.8.7:
version "0.8.7"
resolved "https://registry.yarnpkg.com/require-relative/-/require-relative-0.8.7.tgz#7999539fc9e047a37928fa196f8e1563dabd36de"

require-uncached@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/require-uncached/-/require-uncached-1.0.3.tgz#4e0d56d6c9662fd31e43011c4b95aa49955421d3"
Expand Down Expand Up @@ -5485,12 +5569,48 @@ rimraf@~2.2.6:
version "2.2.8"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.2.8.tgz#e439be2aaee327321952730f99a8929e4fc50582"

rollup-plugin-babel@^3.0.7:
version "3.0.7"
resolved "https://registry.yarnpkg.com/rollup-plugin-babel/-/rollup-plugin-babel-3.0.7.tgz#5b13611f1ab8922497e9d15197ae5d8a23fe3b1e"
dependencies:
rollup-pluginutils "^1.5.0"

rollup-pluginutils@^1.5.0:
version "1.5.2"
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-1.5.2.tgz#1e156e778f94b7255bfa1b3d0178be8f5c552408"
dependencies:
estree-walker "^0.2.1"
minimatch "^3.0.2"

rollup-pluginutils@^2.0.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.3.1.tgz#760d185ccc237dedc12d7ae48c6bcd127b4892d0"
dependencies:
estree-walker "^0.5.2"
micromatch "^2.3.11"

rollup@^0.41.4:
version "0.41.6"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.41.6.tgz#e0d05497877a398c104d816d2733a718a7a94e2a"
dependencies:
source-map-support "^0.4.0"

rollup@^0.57.1:
version "0.57.1"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.57.1.tgz#0bb28be6151d253f67cf4a00fea48fb823c74027"
dependencies:
"@types/acorn" "^4.0.3"
acorn "^5.5.3"
acorn-dynamic-import "^3.0.0"
date-time "^2.1.0"
is-reference "^1.1.0"
locate-character "^2.0.5"
pretty-ms "^3.1.0"
require-relative "^0.8.7"
rollup-pluginutils "^2.0.1"
signal-exit "^3.0.2"
sourcemap-codec "^1.4.1"

route-recognizer@^0.3.3:
version "0.3.3"
resolved "https://registry.yarnpkg.com/route-recognizer/-/route-recognizer-0.3.3.tgz#1d365e27fa6995e091675f7dc940a8c00353bd29"
Expand Down Expand Up @@ -5826,6 +5946,10 @@ source-map@~0.1.x:
dependencies:
amdefine ">=0.0.4"

sourcemap-codec@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.1.tgz#c8fd92d91889e902a07aee392bdd2c5863958ba2"

sourcemap-validator@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/sourcemap-validator/-/sourcemap-validator-1.1.0.tgz#00454547d1682186e1498a7208e022e8dfa8738f"
Expand Down Expand Up @@ -6088,6 +6212,10 @@ through@^2.3.6, through@^2.3.8:
version "2.3.8"
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"

time-zone@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/time-zone/-/time-zone-1.0.0.tgz#99c5bf55958966af6d06d83bdf3800dc82faec5d"

timed-out@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-4.0.1.tgz#f32eacac5a175bea25d7fab565ab3ed8741ef56f"
Expand Down

0 comments on commit 7199051

Please sign in to comment.