Skip to content

Commit

Permalink
Merge pull request #10 from crystal-ball/feature/babel-inline-replace…
Browse files Browse the repository at this point in the history
…-variables

Use babel inline-replace-variables plugin
  • Loading branch information
bigmoves committed Jun 7, 2017
2 parents 5715b30 + a97851b commit d61ebd5
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.5.0 Freerider

- 🔨 Improve inline replacement of global variables for addon options and
environment variables.

## 1.4.0 Stellar Spider Web

- ✨ Adds a custom `emberArray` type checking method to `PropTypes` [#6]
Expand Down
36 changes: 20 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,27 @@ module.exports = {
compress: true,
getDefaultProps: true
},
/**
* Attach babel config options before the addon tree is transpiled. Use
* babel plugin to replace inline variables to determine whether or not to
* check prop types in development/production and support the getDefaultProps
* function.
* @param {String} type Type of tree
* @param {Tree} tree Tree to process
* @return {Tree} Processed tree
*/
preprocessTree(type, tree) {
this.options.babel = {
plugins: [
['inline-replace-variables', {
"NODE_ENV": this.env,
"INCLUDE_GET_DEFAULT_PROPS": this.addonOptions.getDefaultProps
}]
]
};

return tree;
},
/**
* Import prop-types package from /vendor (See treeForVendor for package Funnel
* details). Configure UglifyJS for prod builds.
Expand Down Expand Up @@ -86,21 +106,5 @@ module.exports = {
}));

return mergeTrees(tree);
},
/**
* In non-production builds (or always if code stripping has been disabled) the
* global `process` is not defined by UglifyJS, prevent this from throwing an error
* by attaching it as a global to the window.
* @method contentFor
* @param {string} type The outlet for the injected content
* @returns {string} Content to inject into the outlet
*/
contentFor(type) {
if (
(this.env !== 'production' || this.addonOptions.compress === false)
&& type === 'head'
) {
return `<script>window.NODE_ENV = "development"; window.INCLUDE_GET_DEFAULT_PROPS = ${this.addonOptions.getDefaultProps};</script>`;
}
}
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-cli-prop-types",
"version": "1.4.0",
"version": "1.5.0",
"description": "Props validations for Ember applications using prop-types",
"keywords": [
"ember-addon",
Expand Down Expand Up @@ -28,6 +28,7 @@
"test": "ember try:each"
},
"dependencies": {
"babel-plugin-inline-replace-variables": "^1.3.1",
"ember-cli-babel": "^6.0.0",
"prop-types": "15.5.10"
},
Expand Down
111 changes: 106 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ alter@~0.2.0:
dependencies:
stable "~0.1.3"

amd-name-resolver@0.0.5:
version "0.0.5"
resolved "https://registry.yarnpkg.com/amd-name-resolver/-/amd-name-resolver-0.0.5.tgz#76962dac876ed3311b05d29c6a58c14e1ef3304b"
dependencies:
ensure-posix-path "^1.0.1"

amd-name-resolver@0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/amd-name-resolver/-/amd-name-resolver-0.0.6.tgz#d3e4ba2dfcaab1d820c1be9de947c67828cfe595"
Expand Down Expand Up @@ -558,6 +564,14 @@ babel-plugin-eval@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/babel-plugin-eval/-/babel-plugin-eval-1.0.1.tgz#a2faed25ce6be69ade4bfec263f70169195950da"

babel-plugin-feature-flags@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/babel-plugin-feature-flags/-/babel-plugin-feature-flags-0.3.1.tgz#9c827cf9a4eb9a19f725ccb239e85cab02036fc1"

babel-plugin-filter-imports@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/babel-plugin-filter-imports/-/babel-plugin-filter-imports-0.3.1.tgz#e7859b56886b175dd2616425d277b219e209ea8b"

babel-plugin-htmlbars-inline-precompile@^0.2.3:
version "0.2.3"
resolved "https://registry.yarnpkg.com/babel-plugin-htmlbars-inline-precompile/-/babel-plugin-htmlbars-inline-precompile-0.2.3.tgz#cd365e278af409bfa6be7704c4354beee742446b"
Expand All @@ -566,6 +580,12 @@ babel-plugin-inline-environment-variables@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/babel-plugin-inline-environment-variables/-/babel-plugin-inline-environment-variables-1.0.1.tgz#1f58ce91207ad6a826a8bf645fafe68ff5fe3ffe"

babel-plugin-inline-replace-variables@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/babel-plugin-inline-replace-variables/-/babel-plugin-inline-replace-variables-1.3.1.tgz#9fbb8dd43229c777695e14ea0d3d781f048fdc0f"
dependencies:
babylon "^6.17.0"

babel-plugin-jscript@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/babel-plugin-jscript/-/babel-plugin-jscript-1.0.4.tgz#8f342c38276e87a47d5fa0a8bd3d5eb6ccad8fcc"
Expand Down Expand Up @@ -917,6 +937,14 @@ babel-types@^6.19.0, babel-types@^6.23.0, babel-types@^6.24.1:
lodash "^4.2.0"
to-fast-properties "^1.0.1"

babel6-plugin-strip-class-callcheck@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/babel6-plugin-strip-class-callcheck/-/babel6-plugin-strip-class-callcheck-6.0.0.tgz#de841c1abebbd39f78de0affb2c9a52ee228fddf"

babel6-plugin-strip-heimdall@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/babel6-plugin-strip-heimdall/-/babel6-plugin-strip-heimdall-6.0.1.tgz#35f80eddec1f7fffdc009811dfbd46d9965072b6"

babylon@^5.8.38:
version "5.8.38"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-5.8.38.tgz#ec9b120b11bf6ccd4173a18bf217e60b79859ffd"
Expand Down Expand Up @@ -1174,6 +1202,17 @@ broccoli-debug@^0.6.1:
sanitize-filename "^1.6.1"
tree-sync "^1.2.2"

broccoli-file-creator@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/broccoli-file-creator/-/broccoli-file-creator-1.1.1.tgz#1b35b67d215abdfadd8d49eeb69493c39e6c3450"
dependencies:
broccoli-kitchen-sink-helpers "~0.2.0"
broccoli-plugin "^1.1.0"
broccoli-writer "~0.1.1"
mkdirp "^0.5.1"
rsvp "~3.0.6"
symlink-or-copy "^1.0.1"

broccoli-filter@^1.2.2, broccoli-filter@^1.2.3:
version "1.2.4"
resolved "https://registry.yarnpkg.com/broccoli-filter/-/broccoli-filter-1.2.4.tgz#409afb94b9a3a6da9fac8134e91e205f40cc7330"
Expand Down Expand Up @@ -1211,7 +1250,7 @@ broccoli-funnel@^1.0.0, broccoli-funnel@^1.0.1, broccoli-funnel@^1.0.6, broccoli
symlink-or-copy "^1.0.0"
walk-sync "^0.3.1"

broccoli-kitchen-sink-helpers@^0.2.5:
broccoli-kitchen-sink-helpers@^0.2.5, broccoli-kitchen-sink-helpers@~0.2.0:
version "0.2.9"
resolved "https://registry.yarnpkg.com/broccoli-kitchen-sink-helpers/-/broccoli-kitchen-sink-helpers-0.2.9.tgz#a5e0986ed8d76fb5984b68c3f0450d3a96e36ecc"
dependencies:
Expand Down Expand Up @@ -1291,7 +1330,7 @@ broccoli-plugin@1.1.0:
rimraf "^2.3.4"
symlink-or-copy "^1.0.1"

broccoli-plugin@^1.0.0, broccoli-plugin@^1.2.0, broccoli-plugin@^1.2.1, broccoli-plugin@^1.3.0:
broccoli-plugin@^1.0.0, broccoli-plugin@^1.1.0, broccoli-plugin@^1.2.0, broccoli-plugin@^1.2.1, broccoli-plugin@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/broccoli-plugin/-/broccoli-plugin-1.3.0.tgz#bee704a8e42da08cb58e513aaa436efb7f0ef1ee"
dependencies:
Expand Down Expand Up @@ -1353,6 +1392,13 @@ broccoli-uglify-sourcemap@^1.0.0:
uglify-js "^2.7.0"
walk-sync "^0.1.3"

broccoli-writer@~0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/broccoli-writer/-/broccoli-writer-0.1.1.tgz#d4d71aa8f2afbc67a3866b91a2da79084b96ab2d"
dependencies:
quick-temp "^0.1.0"
rsvp "^3.0.6"

browserslist@^1.4.0:
version "1.7.7"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-1.7.7.tgz#0bd76704258be829b2398bb50e4b62d1a166b0b9"
Expand Down Expand Up @@ -2198,6 +2244,34 @@ ember-cli@2.13.1:
walk-sync "^0.3.0"
yam "0.0.22"

ember-data@^2.13.1:
version "2.13.1"
resolved "https://registry.yarnpkg.com/ember-data/-/ember-data-2.13.1.tgz#fd85daf3c4c7bfe6a0c2e42cedf72048979f94ae"
dependencies:
amd-name-resolver "0.0.5"
babel-plugin-feature-flags "^0.3.1"
babel-plugin-filter-imports "^0.3.1"
babel6-plugin-strip-class-callcheck "^6.0.0"
babel6-plugin-strip-heimdall "^6.0.1"
broccoli-babel-transpiler "^6.0.0"
broccoli-file-creator "^1.0.0"
broccoli-merge-trees "^1.0.0"
chalk "^1.1.1"
ember-cli-babel "^6.0.0-beta.7"
ember-cli-path-utils "^1.0.0"
ember-cli-string-utils "^1.0.0"
ember-cli-test-info "^1.0.0"
ember-cli-version-checker "^1.1.4"
ember-inflector "^2.0.0"
ember-runtime-enumerable-includes-polyfill "^2.0.0"
exists-sync "0.0.3"
git-repo-info "^1.1.2"
heimdalljs "^0.3.0"
inflection "^1.8.0"
npm-git-info "^1.0.0"
semver "^5.1.0"
silent-error "^1.0.0"

ember-disable-prototype-extensions@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/ember-disable-prototype-extensions/-/ember-disable-prototype-extensions-1.1.0.tgz#86081c8cf6741f26e4b89e2b004f761174313e01"
Expand All @@ -2210,6 +2284,12 @@ ember-export-application-global@^2.0.0:
dependencies:
ember-cli-babel "^6.0.0-beta.7"

ember-inflector@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/ember-inflector/-/ember-inflector-2.0.1.tgz#e9ac469ffa17992a43276bb1c9b8d87992b10d37"
dependencies:
ember-cli-babel "^6.0.0"

ember-load-initializers@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/ember-load-initializers/-/ember-load-initializers-1.0.0.tgz#4919eaf06f6dfeca7e134633d8c05a6c9921e6e7"
Expand Down Expand Up @@ -2240,6 +2320,13 @@ ember-router-generator@^1.0.0:
dependencies:
recast "^0.11.3"

ember-runtime-enumerable-includes-polyfill@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ember-runtime-enumerable-includes-polyfill/-/ember-runtime-enumerable-includes-polyfill-2.0.0.tgz#6e9ba118bc909d1d7762de1b03a550d8955308a9"
dependencies:
ember-cli-babel "^6.0.0"
ember-cli-version-checker "^1.1.6"

ember-source@~2.13.0:
version "2.13.0"
resolved "https://registry.yarnpkg.com/ember-source/-/ember-source-2.13.0.tgz#82c47299beecee20b21c14404693f2dff32bbc07"
Expand Down Expand Up @@ -2945,7 +3032,7 @@ getpass@^0.1.1:
dependencies:
assert-plus "^1.0.0"

git-repo-info@^1.4.1:
git-repo-info@^1.1.2, git-repo-info@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/git-repo-info/-/git-repo-info-1.4.1.tgz#2a072823254aaf62fcf0766007d7b6651bd41943"

Expand Down Expand Up @@ -3125,6 +3212,12 @@ heimdalljs@^0.2.0, heimdalljs@^0.2.1, heimdalljs@^0.2.3:
dependencies:
rsvp "~3.2.1"

heimdalljs@^0.3.0:
version "0.3.3"
resolved "https://registry.yarnpkg.com/heimdalljs/-/heimdalljs-0.3.3.tgz#e92d2c6f77fd46d5bf50b610d28ad31755054d0b"
dependencies:
rsvp "~3.2.1"

hoek@2.x.x:
version "2.16.3"
resolved "https://registry.yarnpkg.com/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed"
Expand Down Expand Up @@ -3193,7 +3286,7 @@ indexof@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/indexof/-/indexof-0.0.1.tgz#82dc336d232b9062179d05ab3293a66059fd435d"

inflection@^1.7.0, inflection@^1.7.1:
inflection@^1.7.0, inflection@^1.7.1, inflection@^1.8.0:
version "1.12.0"
resolved "https://registry.yarnpkg.com/inflection/-/inflection-1.12.0.tgz#a200935656d6f5f6bc4dc7502e1aecb703228416"

Expand Down Expand Up @@ -4104,6 +4197,10 @@ normalize-path@^2.0.1:
dependencies:
remove-trailing-separator "^1.0.1"

npm-git-info@^1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/npm-git-info/-/npm-git-info-1.0.3.tgz#a933c42ec321e80d3646e0d6e844afe94630e1d5"

npm-package-arg@^4.1.1:
version "4.2.1"
resolved "https://registry.yarnpkg.com/npm-package-arg/-/npm-package-arg-4.2.1.tgz#593303fdea85f7c422775f17f9eb7670f680e3ec"
Expand Down Expand Up @@ -4420,7 +4517,7 @@ qs@6.4.0, qs@^6.4.0, qs@~6.4.0:
version "6.4.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.4.0.tgz#13e26d28ad6b0ffaa91312cd3bf708ed351e7233"

quick-temp@^0.1.2, quick-temp@^0.1.3, quick-temp@^0.1.5, quick-temp@^0.1.8:
quick-temp@^0.1.0, quick-temp@^0.1.2, quick-temp@^0.1.3, quick-temp@^0.1.5, quick-temp@^0.1.8:
version "0.1.8"
resolved "https://registry.yarnpkg.com/quick-temp/-/quick-temp-0.1.8.tgz#bab02a242ab8fb0dd758a3c9776b32f9a5d94408"
dependencies:
Expand Down Expand Up @@ -4706,6 +4803,10 @@ rsvp@^3.0.14, rsvp@^3.0.16, rsvp@^3.0.17, rsvp@^3.0.18, rsvp@^3.0.21, rsvp@^3.0.
version "3.5.0"
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-3.5.0.tgz#a62c573a4ae4e1dfd0697ebc6242e79c681eaa34"

rsvp@~3.0.6:
version "3.0.21"
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-3.0.21.tgz#49c588fe18ef293bcd0ab9f4e6756e6ac433359f"

rsvp@~3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-3.2.1.tgz#07cb4a5df25add9e826ebc67dcc9fd89db27d84a"
Expand Down

0 comments on commit d61ebd5

Please sign in to comment.