Repository navigation
Description
I know the title is a bit confusing, so take this example:
What's Wrong
I have an app with the isTypeScriptProject flag in .ember-cli set to true. I install addon-a. The install blueprint for addon-a installs addon-b via addAddonToProject, like so:
await this.addAddonToProject({
name: 'addon-b',
target: 'latest',
});Both addon-a and addon-b have files provided by the install blueprint in TypeScript (e.g., app/app.ts, app/routes/application.ts, etc.). Both addons also have shouldTransformTypeScript set to true. However, when the install blueprint for addon-a finishes, any TypeScript files provided by addon-b are actually created as transpiled JavaScript (e.g., app/app.js, app/routes/application.js, etc.). This usually results in new, conflicting files being created, since the project is configured for TypeScript already.
Trace
I've been able to trace the cause of this, so here are (most) of the steps taken, and why this happens:
- My addon's blueprint calls
this.addAddonToProject(...) - In
lib/models/blueprint.js, thetaskOptions.blueprintOptionsdefaults to an empty object (source) - The
addon-installtask is looked up and run with the emptyblueprintOptions(source) - The
addon-installtask calls its owninstallBlueprintmethod with the emptyblueprintOptions(source) - The
installBlueprintmethod merges the empty options before running thegenerate-from-blueprinttask (source) - Since
this._processOptionsinmodels/blueprint.js(called from theinstallhook) just copies values, theinstallhook just passes those options directly to the addon blueprint'sbeforeInstall,processFiles, andafterInstallhooks (source) - Eventually, the
processFileshook usesthis.shouldConvertToJSandthis.convertToJSto transpile the files (source) shouldConvertToJSchecks thetypescriptandisTypeScriptProjectproperties on theoptionsobject to determine whether or not to transpile the TS files (source)- Since the options passed in don't include either property, the files are always transpiled
Potential Solution
I'm not sure if this is the best place for this to go, but I believe the blueprint model should be modified to not use an empty object for the default value of blueprintOptions (source). Either that, or the addon-install task should provide better defaults for its options that should be merged with the given options.
Current Workaround
From the snippet above, this issue can be remediated by addon-a by manually providing the isTypeScriptProject (or typescript) option(s):
await this.addAddonToProject({
name: 'addon-b',
target: 'latest',
+ blueprintOptions: {
+ isTypeScriptProject: options.isTypeScriptProject,
+ typescript: options.typescript,
+ },
});
Activity