ember-cli / babel-plugin-ember-modules-api-polyfill Goto Github PK
View Code? Open in Web Editor NEWPolyfill for Ember JS API
License: MIT License
Polyfill for Ember JS API
License: MIT License
I was trying to install ember-cli-mirage
in an older ember app, and ran into some incorrectly transformed code which made my project unable to build.
import { capitalize, camelize, dasherize, underscore } from '@ember/string';
export { singularize, pluralize } from 'ember-inflector';
export { capitalize, camelize, dasherize, underscore };
Is transformed into something like this:
import Ember from 'ember';
export { singularize, pluralize } from 'ember-inflector';
export { Ember.String.capitalize as capitalize, Ember.String.camelize as camelize, Ember.String.dasherize as dasherize, Ember.String.underscore as underscore };
Which makes Babel throw this error:
SyntaxError: ember-cli-mirage/utils/inflector.js: Unexpected token (4:14)
.
pointing at the last line:
export { Ember.String.capitalize as capitalize, Ember.String.camelize as camelize, Ember.String.dasherize as dasherize, Ember.String.underscore as underscore };
I tried it out in the Babel playground just to verify that this wasn't because of an old Babel.
Now, this could easily only be a problem in my particular setup, but I thought it was worth bringing up just in case.
package.json
dev dependencies and bower.json
{
"devDependencies": {
"active-model-adapter": "1.13.6",
"broccoli-asset-rev": "^2.2.0",
"broccoli-csso": "~1.0.0",
"broccoli-merge-trees": "~0.2.3",
"broccoli-sass": "^0.6.7",
"broccoli-static-compiler": "^0.2.1",
"broccoli-yuidoc": "~1.2.1",
"ember-cli": "^1.13.15",
"ember-cli-app-version": "^1.0.0",
"ember-cli-autoprefixer": "0.4.1",
"ember-cli-babel": "^5.2.4",
"ember-cli-coffeescript": "^1.13.0",
"ember-cli-dependency-checker": "^1.1.0",
"ember-cli-document-title": "0.1.0",
"ember-cli-htmlbars": "^1.0.1",
"ember-cli-htmlbars-inline-precompile": "^0.3.1",
"ember-cli-ic-ajax": "0.2.4",
"ember-cli-inject-live-reload": "^1.3.1",
"ember-cli-pretender": "0.3.1",
"ember-cli-qunit": "^1.0.4",
"ember-cli-simple-auth": "0.8.0",
"ember-cli-simple-auth-oauth2": "0.8.0",
"ember-cli-simple-auth-testing": "^0.8.0",
"ember-cli-tooltipster": "0.0.9",
"ember-cli-uglify": "^1.0.1",
"ember-cli-zero-clipboard": "0.0.1",
"ember-data": "1.13.15",
"ember-suave": "^1.0.0",
"liquid-fire": "0.21.2",
"mkdirp": "~0.5.0"
}
}
{
"dependencies": {
"ember": "1.13.12",
"loader.js": "ember-cli/loader.js#3.4.0",
"ember-cli-shims": "0.0.6",
"ember-cli-test-loader": "0.2.1",
"ember-data": "1.13.15",
"ember-facebook": "*",
"ember-google-analytics": "0.0.1",
"ember-load-initializers": "0.1.7",
"ember-qunit": "0.4.16",
"ember-qunit-notifications": "0.1.0",
"ember-resolver": "~0.1.20",
"fastclick": "~1.0.1",
"fontawesome": "~4.2.0",
"foundation": "^5.5.1",
"i18n-js": "PAM-as/i18n-js#v2.1.2",
"jquery": "^2.1.4",
"jquery-hammerjs": "~1.1.3",
"ladda": "^0.9.8",
"modernizr": "~2.8.2",
"momentjs": "2.8.3",
"qunit": "~1.20.0",
"showdown": "~0.3.1",
"smooth-div-scroll": "0.0.1",
"velocity": "1.1.0",
"viewport-units-buggyfill": "0.4.1",
"wtf-forms": "~2.2.0",
"ember-simple-auth": "0.8.0",
"headroom.js": "~0.7.0",
"pretender": "0.6.0",
"raygun4js": "^1.18.0",
"tooltipster": "~3.3.0"
}
}
Hello! After a proposed renovatebot
bump to ember-cli-babel
7.20.3
(and thus 2.13.3
of babel-plugin-ember-modules-api-polyfill
) I am seeing the following error:
ERROR Summary:
- broccoliBuilderErrorStack: ReferenceError: /build/REDACTED/pods/socket/service.js: Container is falsy
at NodePath._replaceWith (/build/node_modules/ember-cli-babel/node_modules/@babel/traverse/lib/path/replacement.js:166:11)
at NodePath.replaceWith (/build/node_modules/ember-cli-babel/node_modules/@babel/traverse/lib/path/replacement.js:156:8)
at /build/node_modules/ember-cli-babel/node_modules/babel-plugin-ember-modules-api-polyfill/src/index.js:180:33
at Array.forEach (<anonymous>)
at /build/node_modules/ember-cli-babel/node_modules/babel-plugin-ember-modules-api-polyfill/src/index.js:178:38
at Array.forEach (<anonymous>)
at PluginPass.ImportDeclaration (/build/node_modules/ember-cli-babel/node_modules/babel-plugin-ember-modules-api-polyfill/src/index.js:113:22)
at newFn (/build/node_modules/ember-cli-babel/node_modules/@babel/traverse/lib/visitors.js:179:21)
at NodePath._call (/build/node_modules/ember-cli-babel/node_modules/@babel/traverse/lib/path/context.js:55:20)
at NodePath.call (/build/node_modules/ember-cli-babel/node_modules/@babel/traverse/lib/path/context.js:42:17)
- code: [undefined]
- codeFrame: /build/REDACTED/pods/socket/service.js: Container is falsy
- errorMessage: REDACTED/pods/socket/service.js: /build/REDACTED/pods/socket/service.js: Container is falsy
in /tmp/broccoli-19l10NBMMp20Pg/out-621-analyzer_ember_auto_import_analyzer
at broccoli-persistent-filter:Babel > [Babel: REDACTED] (Babel: REDACTED)
- errorType: Build Error
- location:
- column: [undefined]
- file: REDACTED/pods/socket/service.js
- line: [undefined]
- treeDir: /tmp/broccoli-19l10NBMMp20Pg/out-621-analyzer_ember_auto_import_analyzer
- message: REDACTED/pods/socket/service.js: /build/REDACTED/pods/socket/service.js: Container is falsy
in /tmp/broccoli-19l10NBMMp20Pg/out-621-analyzer_ember_auto_import_analyzer
at broccoli-persistent-filter:Babel > [Babel: REDACTED] (Babel: REDACTED)
- name: Error
- nodeAnnotation: Babel: REDACTED
- nodeName: broccoli-persistent-filter:Babel > [Babel: REDACTED]
- originalErrorMessage: /build/REDACTED/pods/socket/service.js: Container is falsy
- stack: ReferenceError: /build/REDACTED/pods/socket/service.js: Container is falsy
at NodePath._replaceWith (/build/node_modules/ember-cli-babel/node_modules/@babel/traverse/lib/path/replacement.js:166:11)
at NodePath.replaceWith (/build/node_modules/ember-cli-babel/node_modules/@babel/traverse/lib/path/replacement.js:156:8)
at /build/node_modules/ember-cli-babel/node_modules/babel-plugin-ember-modules-api-polyfill/src/index.js:180:33
at Array.forEach (<anonymous>)
at /build/node_modules/ember-cli-babel/node_modules/babel-plugin-ember-modules-api-polyfill/src/index.js:178:38
at Array.forEach (<anonymous>)
at PluginPass.ImportDeclaration (/build/node_modules/ember-cli-babel/node_modules/babel-plugin-ember-modules-api-polyfill/src/index.js:113:22)
at newFn (/build/node_modules/ember-cli-babel/node_modules/@babel/traverse/lib/visitors.js:179:21)
at NodePath._call (/build/node_modules/ember-cli-babel/node_modules/@babel/traverse/lib/path/context.js:55:20)
at NodePath.call (/build/node_modules/ember-cli-babel/node_modules/@babel/traverse/lib/path/context.js:42:17)
The project does not use TypeScript, and is otherwise an up-to-date Ember 3.19 app.
The imports in socket/service.js
are:
emberjs/ember-cli-babel#170 (comment)
The
import
statement supports importing all named exports into an object.For example, instead of this
import { alias as computedAlias, and as computedAnd, // ... } from '@ember/object/computed'; import { decoratedPropertyWithRequiredParams } from '../utils/decorator-macros'; export const alias = decoratedPropertyWithRequiredParams(computedAlias);you could just do this
import * as computed from '@ember/object/computed'; import { decoratedPropertyWithRequiredParams } from '../utils/decorator-macros'; export const alias = decoratedPropertyWithRequiredParams(computed.alias);But apparently, the latter does not work. π
Could not find module `@ember/object/computed` imported from `ember-decorators/object/computed`
emberjs/ember-cli-babel#170 (comment)
We would need to handle wildcard import in babel-plugin-ember-modules-API-polyfill. This seems reasonable to me though. We would need to check if the specified module contains only exports from a single namespace or multiple. If multiple namespaces we would have to build up the intermediate POJO that would be used.
Example:
export { capitalize } from '@ember/string';
I wanted to make sure this issue didn't fall in the cracks, as I believe it nuked almost an entire day of work for me yesterday, and the way it fails is veeery subtle and tricky.
See here for references to this issue:
In short, there are combinations of values in config/target.js
and the plugins added in @babel/[email protected]
that will cause things like import EmberObject from '@ember/object'
to be converted to an undefined _EmberObject
instead of Ember.Object
.
cc @chadhietala and @rwjblue
This likely can be its own function (independent of the babel plugin), which would make it easier to test and iterate on.
We can probably steal https://github.com/ember-cli/ember-modules-codemod/blob/master/config/mapping.json and invert it to get started...
I saw #112 in project
after updating to "babel-plugin-ember-modules-api-polyfill": "3.4.0" CI starts failing with:
warning Resolution field "[email protected]" is incompatible with requested version "babel-plugin-ember-modules-api-polyfill@^2.6.0"
+ ./node_modules/.bin/ember test
Build Error (broccoli-persistent-filter:Babel > [Babel: ember-test-helpers]) in @ember/test-helpers/setup-context.js
@ember/test-helpers/setup-context.js: Cannot read property 'get' of null
upgrading ember-cli-babel
to latest does not help, downgrading babel-plugin-ember-modules-api-polyfill
to [email protected]
solve problem.
package.json:
"ember-cli": "~3.22.0",
"ember-cli-babel": "7.24.0",
"ember-source": "3.24.0"
I tracked this down to this library. I think this particular export is missing?
Error:
Build Error (broccoli-persistent-filter:Babel) in ember-resolver/resolvers/classic/index.js
/home/gaurav/dev/emberjs/ember-twiddle/ember-resolver/resolvers/classic/index.js: @ember/debug does not have a deprecate export
2 |
3 | import Ember from 'ember';
> 4 | import { assert, deprecate, warn } from '@ember/debug';
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5 | import EmberObject, { get, computed } from '@ember/object';
6 | import { dasherize, classify, underscore } from '@ember/string';
7 | import { DEBUG } from '@glimmer/env';
Reproduction : https://github.com/Gaurav0/ember-twiddle/pull/new/update_ember_resolver
cc/ @rwjblue
π¨ You need to enable Continuous Integration on all branches of this repository. π¨
To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.
Since we did not receive a CI status on the greenkeeper/initial
branch, we assume that you still need to configure it.
If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you donβt want it to run on every branch, you can whitelist branches starting with greenkeeper/
.
We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.
SyntaxError: mweb/helpers/invoke.js: rsvp does not have a Promise import
2 | import { isArray as isEmberArray } from '@ember/array';
3 | import { tryInvoke } from '@ember/utils';
> 4 | import { Promise } from 'rsvp';
| ^
5 |
6 | export function invoke([methodName, ...args]) {
7 | let obj = args.pop();
https://github.com/ember-cli/babel-plugin-ember-modules-api-polyfill/blob/v1.4.2/src/index.js#L92
I think this should say "export", not "import", right?
Currently only an ignore
option is accepted, which allows to exempt certain imports from being rewritten, e.g. as used by https://github.com/babel/ember-cli-babel/blob/aa6b45cad241617279d24f96390f9ced3ff0e754/index.js#L610-L630.
It would be awesome, if we could expand this API to allow overriding / amending the standard mapping from ember-rfc176-data
.
During the implementation of the ember-cached-decorator-polyfill
, I had to do some crazy contortions (ember-polyfills/ember-cached-decorator-polyfill#12) to add new entries to the mapping. It would be great, if we could improve the infrastructure for future polyfills here. π
I guess this will also require some changes to ember-cli-babel
, but the more significant changes will happen here.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.