Skip to content

Commit

Permalink
Demonstrate simpler way to access @glimmer/runtime (#13)
Browse files Browse the repository at this point in the history
* Demonstrate simpler way to access @glimmer/runtime

This is an alternative to #12.

V2 addons automatically have direct access to all the imports provided by Ember. The challenge here is that `@glimmer/runtime` is private API that isn't in Embroider's supported list, so we need to configure it explicitly.

* Add changeset

---------

Co-authored-by: Kevin Kucharczyk <[email protected]>
  • Loading branch information
ef4 and kevinkucharczyk authored Jan 16, 2024
1 parent f59c432 commit 6b0b498
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-pots-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ember-provide-consume-context": minor
---

Access @glimmer/runtime with simple import, instead of loader.require
1 change: 1 addition & 0 deletions ember-provide-consume-context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"version": 2,
"type": "addon",
"main": "addon-main.cjs",
"externals": ["@glimmer/runtime"],
"app-js": {
"./components/context-consumer.js": "./dist/_app_/components/context-consumer.js",
"./components/context-provider.js": "./dist/_app_/components/context-provider.js",
Expand Down
2 changes: 2 additions & 0 deletions ember-provide-consume-context/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export default {
// You can augment this if you need to.
output: addon.output(),

external: ['@glimmer/runtime'],

plugins: [
// These are the modules that users should be able to import from your
// addon. Anything not listed here may get optimized away.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import Ember from 'ember';
import { overrideGlimmerRuntime } from '../-private/override-glimmer-runtime-classes';
import * as glimmerRuntime from '@glimmer/runtime';

export function initialize() {
if ((Ember as any).__loader?.require == null) {
return;
}

const glimmerRuntime = (Ember as any).__loader.require('@glimmer/runtime');
if (glimmerRuntime == null) {
return;
}

overrideGlimmerRuntime(glimmerRuntime);
}

Expand Down

0 comments on commit 6b0b498

Please sign in to comment.