Skip to content
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

Merged
merged 1 commit into from
Nov 29, 2018

Conversation

bobisjan
Copy link
Contributor

@bobisjan bobisjan commented Oct 28, 2018

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)
  • and its scoped @ variants.

FastBoot's build system requires only dependency whitelisting,
thus looking only for the first part of module path.

closes #198

return require(nodeModulesPath);
} else {
// If it's not on disk, assume it's a built-in node package
return require(moduleName);
Copy link
Contributor Author

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.

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) {
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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...

Copy link
Contributor Author

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.

Copy link
Member

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];?

Copy link
Contributor Author

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

  1. https://github.com/ember-fastboot/ember-cli-fastboot/blob/master/lib/broccoli/fastboot-config.js#L86-L111
  2. 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 in dist/node_modules (also puts it into whitelist 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!

@stephankaag
Copy link

Any progress here? :-) I also ran into this issue recently.

@bobisjan
Copy link
Contributor Author

@stephankaag, I’m going to continue on this during this week.

@bobisjan bobisjan force-pushed the require-module-path branch 5 times, most recently from 1aea993 to fd642f3 Compare November 20, 2018 16:13
@bobisjan
Copy link
Contributor Author

@rwjblue, @xg-wang, I've updated PR with scoped packages and deprecation about whitelisting module paths, should be ready for review.

@rwjblue
Copy link
Member

rwjblue commented Nov 21, 2018

Looks like one of the other PRs I recently merged introduced conflicts, would you mind rebasing?

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
Copy link
Contributor

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.

Copy link
Contributor Author

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.");
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍, will update accordingly.

@bobisjan bobisjan force-pushed the require-module-path branch 2 times, most recently from 43c2444 to 6fcc407 Compare November 22, 2018 10:17
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.
@bobisjan
Copy link
Contributor Author

@kratiahuja, I've updated PR with new schema version and created follow up for ember-cli-fastboot ember-fastboot/ember-cli-fastboot#648.

Also added a test describing expected behaviour - whitelisting foo package and requiring both FastBoot.require('foo') and FastBoot.require('foo/bar') works (without adding foo/bar into fastbootDependencies).

@kratiahuja
Copy link
Contributor

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 kratiahuja merged commit 4516747 into ember-fastboot:master Nov 29, 2018
@rwjblue
Copy link
Member

rwjblue commented Nov 30, 2018

@kratiahuja - AFAICT this is not a breaking change (please double check my thinking), we should probably just release right away...

@rwjblue rwjblue added the bug label Dec 10, 2018
@kratiahuja
Copy link
Contributor

@rwjblue Yup this doesn't look like a breaking change any longer to me. I'll release it today.

@bobisjan bobisjan deleted the require-module-path branch February 16, 2019 20:20
xg-wang added a commit to ember-fastboot/ember-cli-fastboot that referenced this pull request Apr 7, 2021
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
xg-wang added a commit to ember-fastboot/ember-cli-fastboot that referenced this pull request Apr 7, 2021
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
xg-wang added a commit to ember-fastboot/ember-cli-fastboot that referenced this pull request Aug 6, 2021
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
xg-wang added a commit to ember-fastboot/ember-cli-fastboot that referenced this pull request Aug 6, 2021
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
xg-wang added a commit to ember-fastboot/ember-cli-fastboot that referenced this pull request Aug 8, 2021
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
xg-wang added a commit to ember-fastboot/ember-cli-fastboot that referenced this pull request Aug 22, 2021
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
xg-wang added a commit to ember-fastboot/ember-cli-fastboot that referenced this pull request Aug 23, 2021
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
xg-wang added a commit to ember-fastboot/ember-cli-fastboot that referenced this pull request Aug 23, 2021
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fastboot.require dist/node_modules
5 participants