Skip to content

Commit d61ebd5

Browse files
authored
Merge pull request #10 from crystal-ball/feature/babel-inline-replace-variables
Use babel inline-replace-variables plugin
2 parents 5715b30 + a97851b commit d61ebd5

File tree

4 files changed

+133
-22
lines changed

4 files changed

+133
-22
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 1.5.0 Freerider
4+
5+
- 🔨 Improve inline replacement of global variables for addon options and
6+
environment variables.
7+
38
## 1.4.0 Stellar Spider Web
49

510
- ✨ Adds a custom `emberArray` type checking method to `PropTypes` [#6]

index.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,27 @@ module.exports = {
1313
compress: true,
1414
getDefaultProps: true
1515
},
16+
/**
17+
* Attach babel config options before the addon tree is transpiled. Use
18+
* babel plugin to replace inline variables to determine whether or not to
19+
* check prop types in development/production and support the getDefaultProps
20+
* function.
21+
* @param {String} type Type of tree
22+
* @param {Tree} tree Tree to process
23+
* @return {Tree} Processed tree
24+
*/
25+
preprocessTree(type, tree) {
26+
this.options.babel = {
27+
plugins: [
28+
['inline-replace-variables', {
29+
"NODE_ENV": this.env,
30+
"INCLUDE_GET_DEFAULT_PROPS": this.addonOptions.getDefaultProps
31+
}]
32+
]
33+
};
1634

35+
return tree;
36+
},
1737
/**
1838
* Import prop-types package from /vendor (See treeForVendor for package Funnel
1939
* details). Configure UglifyJS for prod builds.
@@ -86,21 +106,5 @@ module.exports = {
86106
}));
87107

88108
return mergeTrees(tree);
89-
},
90-
/**
91-
* In non-production builds (or always if code stripping has been disabled) the
92-
* global `process` is not defined by UglifyJS, prevent this from throwing an error
93-
* by attaching it as a global to the window.
94-
* @method contentFor
95-
* @param {string} type The outlet for the injected content
96-
* @returns {string} Content to inject into the outlet
97-
*/
98-
contentFor(type) {
99-
if (
100-
(this.env !== 'production' || this.addonOptions.compress === false)
101-
&& type === 'head'
102-
) {
103-
return `<script>window.NODE_ENV = "development"; window.INCLUDE_GET_DEFAULT_PROPS = ${this.addonOptions.getDefaultProps};</script>`;
104-
}
105109
}
106110
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ember-cli-prop-types",
3-
"version": "1.4.0",
3+
"version": "1.5.0",
44
"description": "Props validations for Ember applications using prop-types",
55
"keywords": [
66
"ember-addon",
@@ -28,6 +28,7 @@
2828
"test": "ember try:each"
2929
},
3030
"dependencies": {
31+
"babel-plugin-inline-replace-variables": "^1.3.1",
3132
"ember-cli-babel": "^6.0.0",
3233
"prop-types": "15.5.10"
3334
},

yarn.lock

Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ alter@~0.2.0:
144144
dependencies:
145145
stable "~0.1.3"
146146

147+
amd-name-resolver@0.0.5:
148+
version "0.0.5"
149+
resolved "https://registry.yarnpkg.com/amd-name-resolver/-/amd-name-resolver-0.0.5.tgz#76962dac876ed3311b05d29c6a58c14e1ef3304b"
150+
dependencies:
151+
ensure-posix-path "^1.0.1"
152+
147153
amd-name-resolver@0.0.6:
148154
version "0.0.6"
149155
resolved "https://registry.yarnpkg.com/amd-name-resolver/-/amd-name-resolver-0.0.6.tgz#d3e4ba2dfcaab1d820c1be9de947c67828cfe595"
@@ -558,6 +564,14 @@ babel-plugin-eval@^1.0.1:
558564
version "1.0.1"
559565
resolved "https://registry.yarnpkg.com/babel-plugin-eval/-/babel-plugin-eval-1.0.1.tgz#a2faed25ce6be69ade4bfec263f70169195950da"
560566

567+
babel-plugin-feature-flags@^0.3.1:
568+
version "0.3.1"
569+
resolved "https://registry.yarnpkg.com/babel-plugin-feature-flags/-/babel-plugin-feature-flags-0.3.1.tgz#9c827cf9a4eb9a19f725ccb239e85cab02036fc1"
570+
571+
babel-plugin-filter-imports@^0.3.1:
572+
version "0.3.1"
573+
resolved "https://registry.yarnpkg.com/babel-plugin-filter-imports/-/babel-plugin-filter-imports-0.3.1.tgz#e7859b56886b175dd2616425d277b219e209ea8b"
574+
561575
babel-plugin-htmlbars-inline-precompile@^0.2.3:
562576
version "0.2.3"
563577
resolved "https://registry.yarnpkg.com/babel-plugin-htmlbars-inline-precompile/-/babel-plugin-htmlbars-inline-precompile-0.2.3.tgz#cd365e278af409bfa6be7704c4354beee742446b"
@@ -566,6 +580,12 @@ babel-plugin-inline-environment-variables@^1.0.1:
566580
version "1.0.1"
567581
resolved "https://registry.yarnpkg.com/babel-plugin-inline-environment-variables/-/babel-plugin-inline-environment-variables-1.0.1.tgz#1f58ce91207ad6a826a8bf645fafe68ff5fe3ffe"
568582

583+
babel-plugin-inline-replace-variables@^1.3.1:
584+
version "1.3.1"
585+
resolved "https://registry.yarnpkg.com/babel-plugin-inline-replace-variables/-/babel-plugin-inline-replace-variables-1.3.1.tgz#9fbb8dd43229c777695e14ea0d3d781f048fdc0f"
586+
dependencies:
587+
babylon "^6.17.0"
588+
569589
babel-plugin-jscript@^1.0.4:
570590
version "1.0.4"
571591
resolved "https://registry.yarnpkg.com/babel-plugin-jscript/-/babel-plugin-jscript-1.0.4.tgz#8f342c38276e87a47d5fa0a8bd3d5eb6ccad8fcc"
@@ -917,6 +937,14 @@ babel-types@^6.19.0, babel-types@^6.23.0, babel-types@^6.24.1:
917937
lodash "^4.2.0"
918938
to-fast-properties "^1.0.1"
919939

940+
babel6-plugin-strip-class-callcheck@^6.0.0:
941+
version "6.0.0"
942+
resolved "https://registry.yarnpkg.com/babel6-plugin-strip-class-callcheck/-/babel6-plugin-strip-class-callcheck-6.0.0.tgz#de841c1abebbd39f78de0affb2c9a52ee228fddf"
943+
944+
babel6-plugin-strip-heimdall@^6.0.1:
945+
version "6.0.1"
946+
resolved "https://registry.yarnpkg.com/babel6-plugin-strip-heimdall/-/babel6-plugin-strip-heimdall-6.0.1.tgz#35f80eddec1f7fffdc009811dfbd46d9965072b6"
947+
920948
babylon@^5.8.38:
921949
version "5.8.38"
922950
resolved "https://registry.yarnpkg.com/babylon/-/babylon-5.8.38.tgz#ec9b120b11bf6ccd4173a18bf217e60b79859ffd"
@@ -1174,6 +1202,17 @@ broccoli-debug@^0.6.1:
11741202
sanitize-filename "^1.6.1"
11751203
tree-sync "^1.2.2"
11761204

1205+
broccoli-file-creator@^1.0.0:
1206+
version "1.1.1"
1207+
resolved "https://registry.yarnpkg.com/broccoli-file-creator/-/broccoli-file-creator-1.1.1.tgz#1b35b67d215abdfadd8d49eeb69493c39e6c3450"
1208+
dependencies:
1209+
broccoli-kitchen-sink-helpers "~0.2.0"
1210+
broccoli-plugin "^1.1.0"
1211+
broccoli-writer "~0.1.1"
1212+
mkdirp "^0.5.1"
1213+
rsvp "~3.0.6"
1214+
symlink-or-copy "^1.0.1"
1215+
11771216
broccoli-filter@^1.2.2, broccoli-filter@^1.2.3:
11781217
version "1.2.4"
11791218
resolved "https://registry.yarnpkg.com/broccoli-filter/-/broccoli-filter-1.2.4.tgz#409afb94b9a3a6da9fac8134e91e205f40cc7330"
@@ -1211,7 +1250,7 @@ broccoli-funnel@^1.0.0, broccoli-funnel@^1.0.1, broccoli-funnel@^1.0.6, broccoli
12111250
symlink-or-copy "^1.0.0"
12121251
walk-sync "^0.3.1"
12131252

1214-
broccoli-kitchen-sink-helpers@^0.2.5:
1253+
broccoli-kitchen-sink-helpers@^0.2.5, broccoli-kitchen-sink-helpers@~0.2.0:
12151254
version "0.2.9"
12161255
resolved "https://registry.yarnpkg.com/broccoli-kitchen-sink-helpers/-/broccoli-kitchen-sink-helpers-0.2.9.tgz#a5e0986ed8d76fb5984b68c3f0450d3a96e36ecc"
12171256
dependencies:
@@ -1291,7 +1330,7 @@ broccoli-plugin@1.1.0:
12911330
rimraf "^2.3.4"
12921331
symlink-or-copy "^1.0.1"
12931332

1294-
broccoli-plugin@^1.0.0, broccoli-plugin@^1.2.0, broccoli-plugin@^1.2.1, broccoli-plugin@^1.3.0:
1333+
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:
12951334
version "1.3.0"
12961335
resolved "https://registry.yarnpkg.com/broccoli-plugin/-/broccoli-plugin-1.3.0.tgz#bee704a8e42da08cb58e513aaa436efb7f0ef1ee"
12971336
dependencies:
@@ -1353,6 +1392,13 @@ broccoli-uglify-sourcemap@^1.0.0:
13531392
uglify-js "^2.7.0"
13541393
walk-sync "^0.1.3"
13551394

1395+
broccoli-writer@~0.1.1:
1396+
version "0.1.1"
1397+
resolved "https://registry.yarnpkg.com/broccoli-writer/-/broccoli-writer-0.1.1.tgz#d4d71aa8f2afbc67a3866b91a2da79084b96ab2d"
1398+
dependencies:
1399+
quick-temp "^0.1.0"
1400+
rsvp "^3.0.6"
1401+
13561402
browserslist@^1.4.0:
13571403
version "1.7.7"
13581404
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-1.7.7.tgz#0bd76704258be829b2398bb50e4b62d1a166b0b9"
@@ -2198,6 +2244,34 @@ ember-cli@2.13.1:
21982244
walk-sync "^0.3.0"
21992245
yam "0.0.22"
22002246

2247+
ember-data@^2.13.1:
2248+
version "2.13.1"
2249+
resolved "https://registry.yarnpkg.com/ember-data/-/ember-data-2.13.1.tgz#fd85daf3c4c7bfe6a0c2e42cedf72048979f94ae"
2250+
dependencies:
2251+
amd-name-resolver "0.0.5"
2252+
babel-plugin-feature-flags "^0.3.1"
2253+
babel-plugin-filter-imports "^0.3.1"
2254+
babel6-plugin-strip-class-callcheck "^6.0.0"
2255+
babel6-plugin-strip-heimdall "^6.0.1"
2256+
broccoli-babel-transpiler "^6.0.0"
2257+
broccoli-file-creator "^1.0.0"
2258+
broccoli-merge-trees "^1.0.0"
2259+
chalk "^1.1.1"
2260+
ember-cli-babel "^6.0.0-beta.7"
2261+
ember-cli-path-utils "^1.0.0"
2262+
ember-cli-string-utils "^1.0.0"
2263+
ember-cli-test-info "^1.0.0"
2264+
ember-cli-version-checker "^1.1.4"
2265+
ember-inflector "^2.0.0"
2266+
ember-runtime-enumerable-includes-polyfill "^2.0.0"
2267+
exists-sync "0.0.3"
2268+
git-repo-info "^1.1.2"
2269+
heimdalljs "^0.3.0"
2270+
inflection "^1.8.0"
2271+
npm-git-info "^1.0.0"
2272+
semver "^5.1.0"
2273+
silent-error "^1.0.0"
2274+
22012275
ember-disable-prototype-extensions@^1.1.0:
22022276
version "1.1.0"
22032277
resolved "https://registry.yarnpkg.com/ember-disable-prototype-extensions/-/ember-disable-prototype-extensions-1.1.0.tgz#86081c8cf6741f26e4b89e2b004f761174313e01"
@@ -2210,6 +2284,12 @@ ember-export-application-global@^2.0.0:
22102284
dependencies:
22112285
ember-cli-babel "^6.0.0-beta.7"
22122286

2287+
ember-inflector@^2.0.0:
2288+
version "2.0.1"
2289+
resolved "https://registry.yarnpkg.com/ember-inflector/-/ember-inflector-2.0.1.tgz#e9ac469ffa17992a43276bb1c9b8d87992b10d37"
2290+
dependencies:
2291+
ember-cli-babel "^6.0.0"
2292+
22132293
ember-load-initializers@^1.0.0:
22142294
version "1.0.0"
22152295
resolved "https://registry.yarnpkg.com/ember-load-initializers/-/ember-load-initializers-1.0.0.tgz#4919eaf06f6dfeca7e134633d8c05a6c9921e6e7"
@@ -2240,6 +2320,13 @@ ember-router-generator@^1.0.0:
22402320
dependencies:
22412321
recast "^0.11.3"
22422322

2323+
ember-runtime-enumerable-includes-polyfill@^2.0.0:
2324+
version "2.0.0"
2325+
resolved "https://registry.yarnpkg.com/ember-runtime-enumerable-includes-polyfill/-/ember-runtime-enumerable-includes-polyfill-2.0.0.tgz#6e9ba118bc909d1d7762de1b03a550d8955308a9"
2326+
dependencies:
2327+
ember-cli-babel "^6.0.0"
2328+
ember-cli-version-checker "^1.1.6"
2329+
22432330
ember-source@~2.13.0:
22442331
version "2.13.0"
22452332
resolved "https://registry.yarnpkg.com/ember-source/-/ember-source-2.13.0.tgz#82c47299beecee20b21c14404693f2dff32bbc07"
@@ -2945,7 +3032,7 @@ getpass@^0.1.1:
29453032
dependencies:
29463033
assert-plus "^1.0.0"
29473034

2948-
git-repo-info@^1.4.1:
3035+
git-repo-info@^1.1.2, git-repo-info@^1.4.1:
29493036
version "1.4.1"
29503037
resolved "https://registry.yarnpkg.com/git-repo-info/-/git-repo-info-1.4.1.tgz#2a072823254aaf62fcf0766007d7b6651bd41943"
29513038

@@ -3125,6 +3212,12 @@ heimdalljs@^0.2.0, heimdalljs@^0.2.1, heimdalljs@^0.2.3:
31253212
dependencies:
31263213
rsvp "~3.2.1"
31273214

3215+
heimdalljs@^0.3.0:
3216+
version "0.3.3"
3217+
resolved "https://registry.yarnpkg.com/heimdalljs/-/heimdalljs-0.3.3.tgz#e92d2c6f77fd46d5bf50b610d28ad31755054d0b"
3218+
dependencies:
3219+
rsvp "~3.2.1"
3220+
31283221
hoek@2.x.x:
31293222
version "2.16.3"
31303223
resolved "https://registry.yarnpkg.com/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed"
@@ -3193,7 +3286,7 @@ indexof@0.0.1:
31933286
version "0.0.1"
31943287
resolved "https://registry.yarnpkg.com/indexof/-/indexof-0.0.1.tgz#82dc336d232b9062179d05ab3293a66059fd435d"
31953288

3196-
inflection@^1.7.0, inflection@^1.7.1:
3289+
inflection@^1.7.0, inflection@^1.7.1, inflection@^1.8.0:
31973290
version "1.12.0"
31983291
resolved "https://registry.yarnpkg.com/inflection/-/inflection-1.12.0.tgz#a200935656d6f5f6bc4dc7502e1aecb703228416"
31993292

@@ -4104,6 +4197,10 @@ normalize-path@^2.0.1:
41044197
dependencies:
41054198
remove-trailing-separator "^1.0.1"
41064199

4200+
npm-git-info@^1.0.0:
4201+
version "1.0.3"
4202+
resolved "https://registry.yarnpkg.com/npm-git-info/-/npm-git-info-1.0.3.tgz#a933c42ec321e80d3646e0d6e844afe94630e1d5"
4203+
41074204
npm-package-arg@^4.1.1:
41084205
version "4.2.1"
41094206
resolved "https://registry.yarnpkg.com/npm-package-arg/-/npm-package-arg-4.2.1.tgz#593303fdea85f7c422775f17f9eb7670f680e3ec"
@@ -4420,7 +4517,7 @@ qs@6.4.0, qs@^6.4.0, qs@~6.4.0:
44204517
version "6.4.0"
44214518
resolved "https://registry.yarnpkg.com/qs/-/qs-6.4.0.tgz#13e26d28ad6b0ffaa91312cd3bf708ed351e7233"
44224519

4423-
quick-temp@^0.1.2, quick-temp@^0.1.3, quick-temp@^0.1.5, quick-temp@^0.1.8:
4520+
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:
44244521
version "0.1.8"
44254522
resolved "https://registry.yarnpkg.com/quick-temp/-/quick-temp-0.1.8.tgz#bab02a242ab8fb0dd758a3c9776b32f9a5d94408"
44264523
dependencies:
@@ -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.
47064803
version "3.5.0"
47074804
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-3.5.0.tgz#a62c573a4ae4e1dfd0697ebc6242e79c681eaa34"
47084805

4806+
rsvp@~3.0.6:
4807+
version "3.0.21"
4808+
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-3.0.21.tgz#49c588fe18ef293bcd0ab9f4e6756e6ac433359f"
4809+
47094810
rsvp@~3.2.1:
47104811
version "3.2.1"
47114812
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-3.2.1.tgz#07cb4a5df25add9e826ebc67dcc9fd89db27d84a"

0 commit comments

Comments
 (0)