Skip to content

Conversation

@stefanpenner
Copy link
Contributor

@stefanpenner stefanpenner commented Sep 12, 2019

@stefanpenner stefanpenner force-pushed the fix-embroider branch 2 times, most recently from c5fff39 to 474a680 Compare September 12, 2019 05:01
@stefanpenner stefanpenner changed the title [Quick fix] embroider work does not currently support rebuilds, this … [WIP] embroider work does not currently support rebuilds, this … Sep 12, 2019
const fs = require('fs');
const findScriptSrcs = require('find-scripts-srcs-in-document');
// TODO: review this
const FILES_TO_SKIP = /vendor|vendor-static/gi;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

look at this

Copy link
Member

Choose a reason for hiding this comment

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

We cneed to have specific attributes we look for that indicate "vendor" vs "app code" vs "ignore this script".

Copy link
Contributor

Choose a reason for hiding this comment

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

Why does fastboot need to distinguish vendor vs app?

As far as "ignore this script", we already have the ability to put fastboot guards around any code that shouldn't run in fastboot. I would rather stick with one technique like that than add yet another API here. And guards are more like the proposed @embroider/macros, which has the nice property of letting us produce a single build that works in-browser and in-fastboot during development, while producing optimized separate builds in prod.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't dug in yet, still investigating this one. (This was a port of the existing code, with fixes and tests)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the "look at this" comment was more for myself, sorry I should have been clear.

const pkg = JSON.parse(fs.readFileSync(root + '/package.json', 'UTF8'));

// bail if not embroider (let's chat if this is appropriate);
if (!('version' in pkg['ember-addon'])) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ef4 / @rwjblue thoughts on a more explicit check?

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to continue to use any existing content in pkg.fastboot.manifest.appFiles (this supports non-embroider users) and only parse from index.html in Embroider builds. We can work towards removing that (conceptually), but it seems safer for now for existing consumers that are not experimenting with Embroider.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue is, we mutate said file' appFiles (and the build may choose to as well). So it's contents cannot be trusted.


// otherwise, we must parse the index.html file to figure out what's next
const indexHtml = fs.readFileSync(root + '/index.html', 'UTF8')
// TODO: fix simple-html-tokenizer: https://github.com/tildeio/simple-html-tokenizer/pulls
Copy link
Contributor Author

Choose a reason for hiding this comment

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

* ensure rebuilds work correctly
* use simple-html-tokenizer instead of cheerio (less dependencies, same parser as we use everywhere else, and faster)
* detect embroider usage more directly (we should discuss)
* tests

// otherwise, we must parse the index.html file to figure out what's next
const indexHtml = fs.readFileSync(root + '/index.html', 'UTF8')
// TODO: fix simple-html-tokenizer: https://github.com/tildeio/simple-html-tokenizer/pull/71
Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix simple-html-tokenizer: tildeio/simple-html-tokenizer#71


const appFiles = findScriptSrcs(indexHtml, findScriptSrcs.ignoreWithAttribute('data-embroider-ignore'))
// TODO: these FILES_TO_SKIP things seem over zealous
.filter( src => !FILES_TO_SKIP.test(src))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

feels overzealous

// TODO: these FILES_TO_SKIP things seem over zealous
.filter( src => !FILES_TO_SKIP.test(src))
// TODO: handle prefixed / custom origin paths / or files
.filter(src => fs.existsSync(`${root}/${src}`));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

handle prefixed/custom origin path etc.

.filter(src => fs.existsSync(`${root}/${src}`));

// TODO: this feels super janky, we need to figure out a better approach
const fastbootFile = pkg.fastboot.manifest.appFiles.find(x => /-fastboot.js$/.test(x))
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 feels risky, we should find a better approach

'use strict';

const fs = require('fs');
const findScriptSrcs = require('find-scripts-srcs-in-document');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

tested lib that uses simply-html-tokenizer

const fs = require('fs');
const updateManifestFromHtml = require('../../lib/embroider/update-manifest-from-html')

describe('embroider/update-manifest-from-html', function() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: more tests

const addon = pkg['ember-addon'];

// bail if not embroider (let's chat if this is appropriate);
if (typeof addon !== 'object' || !('version' in addon)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am also, curious to know if there is a better option for the check regarding embroider or classic.

Copy link
Contributor

Choose a reason for hiding this comment

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

Addons doing different things under embroider is a bad idea.

The whole point of @embroider/compat is to support addons that don't know about embroider. If an addon wants to actually support embroider, it needs to ship as a v2 addon, thus avoiding @embroider/compat entirely and only using supported APIs in @embroider/core.

Copy link
Member

@rwjblue rwjblue Sep 19, 2019

Choose a reason for hiding this comment

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

If an addon wants to actually support embroider, it needs to ship as a v2 addon

Which is actually impossible since V2 isn't actually shipped yet 😉

Copy link
Contributor

Choose a reason for hiding this comment

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

. If an addon wants to actually support embroider, it needs to ship as a v2 addon, thus avoiding @embroider/compat entirely and only using supported APIs in @embroider/core

Could be a dumb question, but just curious - what can be done to use V2 but still be backward compatible. I think Updating ember-cli-fastboot AddOn to use V2 would need Major version bump. And have to maintain both versions. I don't think that is scalable.

@rwjblue please correct me if I am wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am very tempted to use process.env.EMBROIDER and update the documentation to indicate, if we have to use embroider with fastboot then run EMBROIDER=true ember s. And use that property to differentiate embroider and classic flow.

I am not happy with this approach but will cover our requirement and since embroider is an experimental build I think this will be ok.

Copy link
Contributor

Choose a reason for hiding this comment

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

any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I updated the PR - #729, with changes related to using process.env.EMBROIDER property to check if this is embroider flow or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

@dnalagatla it won't require a major bump, v2 addons can also be valid v1 addons because ember-cli respects the ember-addon.main key in package.json, which lets us distinguish the v1 entrypoint from the v2 build entrypoint (ember-addon.build) and the v2 runtime entrpoint (main).

@rwjblue there's nobody better positioned than the people in this thread to make v2 addons become fully implemented. There's not a lot of work required, since the whole system is already designed around their needs. But that is all beside my point: these changes aren't breaking as far as I know, if they're breaking show me how and we can adjust until they're not breaking. If you just want a feature flag inside ember-cli-fastboot to manage the rollout, fine, but don't name it "EMBROIDER" because that's just confusing. It's an ember-cli-fastboot specific feature flag.

Copy link
Contributor

@dnalagatla dnalagatla Sep 23, 2019

Choose a reason for hiding this comment

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

@ef4 There is a difference between the classic build and embroider build flow, as a result I was interested in having that flag:

In Classic build flow the following are the steps occurs in ember-cli-fastboot build -

  1. Ember-cli gives a flag to turn off autoBoot by setting this property app.options.autoRun and is set to false by default in include hook in ember-cli-fastboot - https://github.com/ember-fastboot/ember-cli-fastboot/blob/master/index.js#L73
  2. Then in contentFor hook app-boot type is used to define custom app-boot logic that can support Browser and Fastboot (using appFactory). - https://github.com/ember-fastboot/ember-cli-fastboot/blob/master/index.js#L110

Embroider build doesn't support app-boot hook in contentFor to include custom app-boot logic needed for ember-cli-fastboot. - embroider-build/embroider#183

As app-boot is not supported, we introduced a flag to disable-auto-boot in fastboot, but for that flag to be effective we would have to set app.options.autoRun to true. That change is only compatible with embroider flow but not with classic build flow of ember-cli-fastboot.

cc: @stefanpenner

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @ef4, are there any plans to support app-boot in embroider.

@dnalagatla
Copy link
Contributor

dnalagatla commented Sep 20, 2019

This PR can be closed as all the necessary changes for fixing embroider flow is in this PR - #729

Also, above PR fixes embroider related tests not running as part of yarn test and fixed tests based on the expected structure of the output directory.

@stefanpenner @rwjblue

@ef4
Copy link
Contributor

ef4 commented Sep 24, 2019 via email

@stefanpenner stefanpenner deleted the fix-embroider branch September 25, 2019 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants