-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to require module path from whitelisted dependency #200
Conversation
return require(nodeModulesPath); | ||
} else { | ||
// If it's not on disk, assume it's a built-in node package | ||
return require(moduleName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This branch is not required since resolve.sync
will take care of it.
2518995
to
a8bea25
Compare
src/ember-app.js
Outdated
// If it's not on disk, assume it's a built-in node package | ||
return require(moduleName); | ||
} | ||
if (whitelist.indexOf(moduleName) > -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be a breaking change, can it be modulePath
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, FastBoot supports only dependencies to be whitelisted (eq. abortcontroller-polyfill
), not a path to module in dependency (eq. abortcontroller-polyfill/dist/cjs-ponyfill
), http://ember-fastboot.com/docs/user-guide#using-whitelisted-node-dependencies.
In ember-fetch
, whitelisting of abortcontroller-polyfill/dist/cjs-ponyfill
here, caused that the abortcontroller-polyfill
dependency was not added (and installed) into build and then requiring module at runtime caused this error ember-cli/ember-fetch#115.
This change allows to specify FastBoot dependency and then require any module from this dependency, so this should not be a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That ember-fetch issue is caused by node_modules
not inside dist/
. If you run the server at the path that has node_modules
the module can be installed.
If your change is whitelist.indexOf(moduleName)
whitelist.indexOf(modulePath)
, it will not be a breaking change for any app/addon who's requiring a specific file within a module.
I'm not sure what the official convention for Fastboot is. If users should whitelist a package rather than any subset of its file/module, we can make changes and document, but it's still a breaking change for current whitelisting a module's certain file...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That ember-fetch issue is caused by node_modules not inside dist/. If you run the server at the path that has node_modules the module can be installed.
After ember build
and before running server, it's required to cd dist
and npm install
to have FastBoot whitelisted dependencies available for running, which are part of dist/package.json
, eq. like fastboot-s3-downloader
does https://github.com/tomdale/fastboot-s3-downloader/blob/master/index.js#L110.
I'm not sure what the official convention for Fastboot is. If users should whitelist a package rather than any subset of its file/module, we can make changes and document, but it's still a breaking change for current whitelisting a module's certain file...
I hope that there is no need to make changes, because it's already said here, that fastbootDependencies
contains packages (and Node.js built-ins), based on that I believe that this PR is not introducing any breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation @bobisjan
Yep the dist/node_modules
are required, once it's done that issue won't happen.
Definition of "breaking change" is vague here, my argument above was referring to the actual implementation, yours was referring to the documentation. If it is considered wrong for addons/apps to implement based on the current fastboot I can totally accept, just want to point out it will break some addons/apps and they need to fix themselves.
And this PR also need to deal with the scoped package case in this line let moduleName = modulePath.split('/')[0];
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep the dist/node_modules are required, once it's done that issue won't happen.
🎉
Definition of "breaking change" is vague here, my argument above was referring to the actual implementation, yours was referring to the documentation. If it is considered wrong for addons/apps to implement based on the current fastboot I can totally accept, just want to point out it will break some addons/apps and they need to fix themselves.
I see, the current implementation (without this PR) based on
- https://github.com/ember-fastboot/ember-cli-fastboot/blob/master/lib/broccoli/fastboot-config.js#L86-L111
- https://github.com/ember-fastboot/fastboot/blob/master/src/ember-app.js#L117-L136
requires for FastBoot.require('abortcontroller-polyfill/dist/cjs-ponyfill')
to work to specify FastBoot dependencies like that
dependecies: {
'abortcontroller-polyfill': '^1.1.9'
},
fastbootDependencies: [
'abortcontroller-polyfill' // (a)
'abortcontroller-polyfill/dist/cjs-ponyfill' // (b)
]
- (a) ensures that package itself appears in
dist/package.json
(1) and will be installed indist/node_modules
(also puts it intowhitelist
and allows to require it), - (b) puts path into
whitelist
and allows to require it (2).
With this PR the (b) case will become unnecessary and can be removed, but current behaviour in apps/addons should be preserved.
Looking at https://emberobserver.com/code-search?codeQuery=fastbootDependencies, there are ember-fetch
a some firebase
related addons, which whitelists without package name.
To be honest I'm curious how these addons can work in FastBoot, because IMO based on our application running on AWS using FastBoot App Server and finding mainmatter/ember-simple-auth#1690, ember-cli/ember-fetch#115, apps/addons with just (b) and without (a) do not work in FastBoot App Server at all today regardless of this PR and need to be fixed anyway.
Maybe users don't use FastBoot App Server and only use ember serve
🤔? If it works (only having (b)) using ember serve
then it would break their apps like you mention, will try and report back.
I would like to get feedback from @kratiahuja / @tomdale / @rwjblue / @ember-fastboot on that
And this PR also need to deal with the scoped package case in this line
let moduleName = modulePath.split('/')[0];
?
👍 Good catch, will update, thanks!
Any progress here? :-) I also ran into this issue recently. |
@stephankaag, I’m going to continue on this during this week. |
1aea993
to
fd642f3
Compare
Looks like one of the other PRs I recently merged introduced conflicts, would you mind rebasing? |
fd642f3
to
41b058b
Compare
src/ember-app.js
Outdated
@@ -116,21 +118,34 @@ class EmberApp { | |||
buildWhitelistedRequire(whitelist, distPath) { | |||
whitelist.forEach(function(whitelistedModule) { | |||
debug("module whitelisted; module=%s", whitelistedModule); | |||
|
|||
// Remove after 2.0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious to understand, why are we removing this after 2.0? This may be a backward incompatible change for apps that are relying on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intended only for fastboot 1.x, with 2.0 all apps/addons should be using only package names in the whitelist, so it should be unnecessary here.
Do you think that schema version check should be used instead?
src/ember-app.js
Outdated
let packageName = getPackageName(whitelistedModule); | ||
|
||
if (packageName !== whitelistedModule) { | ||
console.warn("[DEPRECATION] Whitelisting module path '" + whitelistedModule + "' will not be supported after fastboot#2.0.0 and it should be removed from the whitelist."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in fastboot we have version maintainence between ember-cli-fastboot
and fastboot
. You can see here: https://github.com/ember-fastboot/fastboot/blob/master/src/fastboot-schema-versions.js. I think we should use that versus version of fastboot. This can be confusing as ember-cli-fastboot
is already on 2.0.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍, will update accordingly.
43c2444
to
6fcc407
Compare
Required module path can be one of - `fs` (built-in Node.js module), - `abortcontroller-polyfill` (external main module), - `abortcontroller-polyfill/dist/cjs-ponyfill` (external submodule). FastBoot's build system requires only dependency whitelisting, thus looking only for the first part of module path.
6fcc407
to
708e8da
Compare
@kratiahuja, I've updated PR with new schema version and created follow up for Also added a test describing expected behaviour - whitelisting |
Hi @bobisjan , I am very sorry I somehow missed reviewing the changes here. This looks good to me. I'll merge this. Please let me know when you want me to do a release. |
@kratiahuja - AFAICT this is not a breaking change (please double check my thinking), we should probably just release right away... |
@rwjblue Yup this doesn't look like a breaking change any longer to me. I'll release it today. |
html-oriented manifest format ----------------------------- In the new schema format, which is defined in ember-fastboot/fastboot@3fd5bc9 the manifest is written into HTML and later extracted by fastboot on server side instead of previously reading from dist/package.json Note: The new schema in fastboot does not handle fastboot config https://github.com/ember-fastboot/ember-cli-fastboot/tree/e4d0b7c7bcdf82def0dc8726835b49d707673f41#providing-additional-config This commit changes to read Fastboot.config from dist/package.json instead of ignoring it Allow to require module path from whitelisted dependency ------------------------------------------------------- Incrementing schema to 5 also included the changes in schema 4 strictWhitelist See ember-fastboot/fastboot#200
html-oriented manifest format ----------------------------- In the new schema format, which is defined in ember-fastboot/fastboot@3fd5bc9 the manifest is written into HTML and later extracted by fastboot on server side instead of previously reading from dist/package.json Note: The new schema in fastboot does not handle fastboot config https://github.com/ember-fastboot/ember-cli-fastboot/tree/e4d0b7c7bcdf82def0dc8726835b49d707673f41#providing-additional-config This commit changes to read Fastboot.config from dist/package.json instead of ignoring it Allow to require module path from whitelisted dependency ------------------------------------------------------- Incrementing schema to 5 also included the changes in schema 4 strictWhitelist See ember-fastboot/fastboot#200
html-oriented manifest format ----------------------------- In the new schema format, which is defined in ember-fastboot/fastboot@3fd5bc9 the manifest is written into HTML and later extracted by fastboot on server side instead of previously reading from dist/package.json Note: The new schema in fastboot does not handle fastboot config https://github.com/ember-fastboot/ember-cli-fastboot/tree/e4d0b7c7bcdf82def0dc8726835b49d707673f41#providing-additional-config This commit changes to read Fastboot.config from dist/package.json instead of ignoring it Allow to require module path from whitelisted dependency ------------------------------------------------------- Incrementing schema to 5 also included the changes in schema 4 strictWhitelist See ember-fastboot/fastboot#200 Revert back to put config in dist/package.json add data-fastboot-ignore to unexpected files properly ignore files that should not execute in fastboot
html-oriented manifest format ----------------------------- In the new schema format, which is defined in ember-fastboot/fastboot@3fd5bc9 the manifest is written into HTML and later extracted by fastboot on server side instead of previously reading from dist/package.json Note: The new schema in fastboot does not handle fastboot config https://github.com/ember-fastboot/ember-cli-fastboot/tree/e4d0b7c7bcdf82def0dc8726835b49d707673f41#providing-additional-config This commit changes to read Fastboot.config from dist/package.json instead of ignoring it Allow to require module path from whitelisted dependency ------------------------------------------------------- Incrementing schema to 5 also included the changes in schema 4 strictWhitelist See ember-fastboot/fastboot#200 Revert back to put config in dist/package.json add data-fastboot-ignore to unexpected files properly ignore files that should not execute in fastboot
html-oriented manifest format ----------------------------- In the new schema format, which is defined in ember-fastboot/fastboot@3fd5bc9 the manifest is written into HTML and later extracted by fastboot on server side instead of previously reading from dist/package.json Note: The new schema in fastboot does not handle fastboot config https://github.com/ember-fastboot/ember-cli-fastboot/tree/e4d0b7c7bcdf82def0dc8726835b49d707673f41#providing-additional-config This commit changes to read Fastboot.config from dist/package.json instead of ignoring it Allow to require module path from whitelisted dependency ------------------------------------------------------- Incrementing schema to 5 also included the changes in schema 4 strictWhitelist See ember-fastboot/fastboot#200 Revert back to put config in dist/package.json add data-fastboot-ignore to unexpected files properly ignore files that should not execute in fastboot
html-oriented manifest format ----------------------------- In the new schema format, which is defined in ember-fastboot/fastboot@3fd5bc9 the manifest is written into HTML and later extracted by fastboot on server side instead of previously reading from dist/package.json Note: The new schema in fastboot does not handle fastboot config https://github.com/ember-fastboot/ember-cli-fastboot/tree/e4d0b7c7bcdf82def0dc8726835b49d707673f41#providing-additional-config This commit changes to read Fastboot.config from dist/package.json instead of ignoring it Allow to require module path from whitelisted dependency ------------------------------------------------------- Incrementing schema to 5 also included the changes in schema 4 strictWhitelist See ember-fastboot/fastboot#200 Revert back to put config in dist/package.json add data-fastboot-ignore to unexpected files properly ignore files that should not execute in fastboot
html-oriented manifest format ----------------------------- In the new schema format, which is defined in ember-fastboot/fastboot@3fd5bc9 the manifest is written into HTML and later extracted by fastboot on server side instead of previously reading from dist/package.json Note: The new schema in fastboot does not handle fastboot config https://github.com/ember-fastboot/ember-cli-fastboot/tree/e4d0b7c7bcdf82def0dc8726835b49d707673f41#providing-additional-config The support is added in the #854. Allow to require module path from whitelisted dependency ------------------------------------------------------- Incrementing schema to 5 also included the changes in schema 4 strictWhitelist See ember-fastboot/fastboot#200 Revert back to put config in dist/package.json add data-fastboot-ignore to unexpected files properly ignore files that should not execute in fastboot
html-oriented manifest format ----------------------------- In the new schema format, which is defined in ember-fastboot/fastboot@3fd5bc9 the manifest is written into HTML and later extracted by fastboot on server side instead of previously reading from dist/package.json Note: The new schema in fastboot does not handle fastboot config https://github.com/ember-fastboot/ember-cli-fastboot/tree/e4d0b7c7bcdf82def0dc8726835b49d707673f41#providing-additional-config The support is added in the #854. Allow to require module path from whitelisted dependency ------------------------------------------------------- Incrementing schema to 5 also included the changes in schema 4 strictWhitelist See ember-fastboot/fastboot#200 Revert back to put config in dist/package.json add data-fastboot-ignore to unexpected files properly ignore files that should not execute in fastboot
Required module path can be one of
fs
(built-in Node.js module),abortcontroller-polyfill
(external main module),abortcontroller-polyfill/dist/cjs-ponyfill
(external submodule)@
variants.FastBoot's build system requires only dependency whitelisting,
thus looking only for the first part of module path.
closes #198