-
Notifications
You must be signed in to change notification settings - Fork 109
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
Infer bundle type (app vs test) by original tree if known. #329
Conversation
Thanks for working on this. Would this allow an addon to have some files of each kind? I was picturing an API more like: // my-addon/index.js
module.exports = {
name: 'my-addon',
options: {
autoImport:{
testsPattern: /\/custom-test-support\//
}
}
};
We already track which package goes with each tree that's being analyzed. |
Ya, if the import is in
Ya, I can do this also as a way to override completely, but I generally would prefer to default to not needing the custom test pattern (and instead infer if a given import should be vendor vs test-support based on the source tree). |
Ok, yeah, as long as you're fine requiring the ember-cli change we can stick with that plan and don't need to also introduce the option to override the pattern. |
Ya, I have a branch with the ember-cli changes required all queued up. However, it is also possible for individual addons to guarantee they are compatible without requiring the ember-cli change. For example this code in ember-qunit: treeForAddonTestSupport(tree) {
// intentionally not calling _super here
// so that can have our `import`'s be
// import { ... } from 'ember-qunit';
const Funnel = require('broccoli-funnel');
let scopedInputTree = new Funnel(tree, { destDir: 'ember-qunit' });
return this.preprocessJs(scopedInputTree, '/', this.name, {
annotation: `ember-qunit - treeForAddonTestSupport`,
registry: this.registry,
});
}, Will turn into: treeForAddonTestSupport(tree) {
// intentionally not calling _super here
// so that can have our `import`'s be
// import { ... } from 'ember-qunit';
const Funnel = require('broccoli-funnel');
let scopedInputTree = new Funnel(tree, { destDir: 'ember-qunit' });
return this.preprocessJs(scopedInputTree, '/', this.name, {
annotation: `ember-qunit - treeForAddonTestSupport`,
registry: this.registry,
treeType: 'addon-test-support'
});
}, |
c0c13aa
to
07ecb9a
Compare
Prior to these changes, we would decide what bundle a given file should end up in based on the modules relativePath that imported it. This worked generally for application level tests that import external packages, as well as for many addon-test-support imports. Unfortunately, this relative path analysis falls down in addons that intentionally customize their `treeForAddonTestSupport` so that the `addon-test-support/` folder contents are available **without** the `addon-name/test-support` suffix. This is done by a number of testing only addons, but the largest offenders are `ember-qunit` and `@ember/test-helpers`. This introduces a new (possibly undefined) value that can be passed into `preprocessJs` to specify the `treeType` being transpiled. ember-cli will update to pass this value by default, but any addons doing the sort of overrides mentioned above are _likely_ already doing a manual override and can easily pass in the treeType in their overrides.
07ecb9a
to
876cbed
Compare
@scalvert helped me track down the cause of the |
I think it may be nice to support both Nice work on this, @rwjblue. |
ember-cli/ember-cli#9411 adds the tree type option to all of ember-cli's invocations. |
@@ -6,7 +6,7 @@ import FSTree from 'fs-tree-diff'; | |||
import makeDebug from 'debug'; | |||
import { join, extname } from 'path'; | |||
import { isEqual, flatten } from 'lodash'; | |||
import Package from './package'; | |||
import type Package from './package'; |
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'm really glad typescript added this feature.
@@ -16,7 +17,7 @@ const debugTree = buildDebugCallback('ember-auto-import'); | |||
// what you're doing. | |||
export interface AutoImportSharedAPI { | |||
isPrimary(addonInstance: AddonInstance): boolean; | |||
analyze(tree: Node, addon: AddonInstance): Node; | |||
analyze(tree: Node, addon: AddonInstance, treeType?: TreeType): Node; |
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 area deserves extra scrutiny because different versions of ember-auto-import will call each other's copy of analyze
. But this looks safe to me -- older copies will not pass the optional argument, newer copies will pass the argument and it will be ignored.
Prior to these changes, we would decide what bundle a given file should end up in based on the modules relativePath that imported it. This worked generally for application level tests that import external packages, as well as for many addon-test-support imports.
Unfortunately, this relative path analysis falls down in addons that intentionally customize their
treeForAddonTestSupport
so that theaddon-test-support/
folder contents are available without theaddon-name/test-support
suffix. This is done by a number of testing only addons, but the largest offenders areember-qunit
and@ember/test-helpers
.This introduces a new (possibly undefined) value that can be passed into
preprocessJs
to specify thetreeType
being transpiled. ember-cli will update to pass this value by default, but any addons doing the sort of overrides mentioned above are likely already doing a manual override and can easily pass in the treeType in their overrides.Fixes #284