-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #978 from embroider-build/revert-loose-ember-modules
backing out ember real-modules mode
- Loading branch information
Showing
7 changed files
with
51 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import V1Addon from '../../v1-addon'; | ||
import Plugin from 'broccoli-plugin'; | ||
import { join } from 'path'; | ||
import { outputFileSync, copyFileSync } from 'fs-extra'; | ||
|
||
/* | ||
@glimmer/tracking is a real package but it has no working implementation. The | ||
real implementation is in ember-source. | ||
Since embroider prioritizes real packages, it's best to provide a compat | ||
adapter here to make it into a valid package. It's easy enough for it to | ||
reexport the things from ember that are needed. | ||
*/ | ||
class RedirectToEmber extends Plugin { | ||
private didBuild = false; | ||
|
||
build() { | ||
if (!this.didBuild) { | ||
copyFileSync(join(this.inputPaths[0], 'package.json'), join(this.outputPath, 'package.json')); | ||
outputFileSync(join(this.outputPath, 'index.js'), `export { tracked } from '@ember/-internals/metal';`); | ||
outputFileSync( | ||
join(this.outputPath, 'primitives', 'cache.js'), | ||
`export { createCache, getValue, isConst } from "@ember/-internals/metal";` | ||
); | ||
this.didBuild = true; | ||
} | ||
} | ||
} | ||
|
||
export default class extends V1Addon { | ||
get v2Tree() { | ||
return new RedirectToEmber([super.v2Tree]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,9 @@ | ||
import V1Addon from '../v1-addon'; | ||
import buildFunnel from 'broccoli-funnel'; | ||
import mergeTrees from 'broccoli-merge-trees'; | ||
import AddToTree from '../add-to-tree'; | ||
import { outputFileSync, unlinkSync } from 'fs-extra'; | ||
import { join } from 'path'; | ||
import semver from 'semver'; | ||
|
||
export default class extends V1Addon { | ||
private useRealModules = semver.satisfies(this.packageJSON.version, '>=3.27.0-beta.0', { includePrerelease: true }); | ||
|
||
get v2Tree() { | ||
return mergeTrees([super.v2Tree, buildFunnel(this.rootTree, { include: ['dist/ember-template-compiler.js'] })]); | ||
} | ||
|
||
// when using real modules, we're replacing treeForAddon and treeForVendor | ||
customizes(treeName: string) { | ||
return ( | ||
(this.useRealModules && (treeName === 'treeForAddon' || treeName === 'treeForVendor')) || | ||
super.customizes(treeName) | ||
); | ||
} | ||
|
||
invokeOriginalTreeFor(name: string, opts: { neuterPreprocessors: boolean } = { neuterPreprocessors: false }) { | ||
if (this.useRealModules) { | ||
if (name === 'addon') { | ||
return this.customAddonTree(); | ||
} | ||
if (name === 'vendor') { | ||
return this.customVendorTree(); | ||
} | ||
} | ||
return super.invokeOriginalTreeFor(name, opts); | ||
} | ||
|
||
// Our addon tree is all of the "packages" we share. @embroider/compat already | ||
// supports that pattern of emitting modules into other package's namespaces. | ||
private customAddonTree() { | ||
return mergeTrees([ | ||
buildFunnel(this.rootTree, { | ||
srcDir: 'dist/packages', | ||
}), | ||
buildFunnel(this.rootTree, { | ||
srcDir: 'dist/dependencies', | ||
}), | ||
]); | ||
} | ||
|
||
// We're zeroing out these files in vendor rather than deleting them, because | ||
// we can't easily intercept the `app.import` that presumably exists for them, | ||
// so rather than error they will just be empty. | ||
// | ||
// The reason we're zeroing these out is that we're going to consume all our | ||
// modules directly out of treeForAddon instead, as real modules that webpack | ||
// can see. | ||
private customVendorTree() { | ||
return new AddToTree(this.addonInstance._treeFor('vendor'), outputPath => { | ||
unlinkSync(join(outputPath, 'ember', 'ember.js')); | ||
outputFileSync(join(outputPath, 'ember', 'ember.js'), ''); | ||
unlinkSync(join(outputPath, 'ember', 'ember-testing.js')); | ||
outputFileSync(join(outputPath, 'ember', 'ember-testing.js'), ''); | ||
}); | ||
} | ||
|
||
get packageMeta() { | ||
let meta = super.packageMeta; | ||
if (this.useRealModules) { | ||
if (!meta['implicit-modules']) { | ||
meta['implicit-modules'] = []; | ||
} | ||
meta['implicit-modules'].push('./ember/index.js'); | ||
|
||
if (!meta['implicit-test-modules']) { | ||
meta['implicit-test-modules'] = []; | ||
} | ||
meta['implicit-test-modules'].push('./ember-testing/index.js'); | ||
} | ||
return meta; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters