How to use the @embroider/core.getOrCreate function in @embroider/core

To help you get started, we’ve selected a few @embroider/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github embroider-build / embroider / packages / compat / src / dependency-rules.ts View on Github external
export function activePackageRules(packageRules: PackageRules[], activePackages: Package[]): ActivePackageRules[] {
  // rule order implies precedence. The first rule that matches a given package
  // applies to that package, and no other rule does.
  let rootsPerRule = new Map();
  for (let pkg of activePackages) {
    for (let rule of packageRules) {
      if (rule.package === pkg.name && (!rule.semverRange || satisfies(pkg.version, rule.semverRange))) {
        let roots = getOrCreate(rootsPerRule, rule, () => []);
        roots.push(pkg.root);
        break;
      }
    }
  }
  let output = [];
  for (let [rule, roots] of rootsPerRule) {
    output.push(Object.assign({ roots }, rule));
  }
  return output;
}
github embroider-build / embroider / packages / macros / src / macros-config.ts View on Github external
private internalSetConfig(fromPath: string, packageName: string | undefined, config: unknown) {
    if (this.cachedUserConfigs) {
      throw new Error(`attempted to set config after we have already emitted our config`);
    }
    let targetPackage = this.resolvePackage(fromPath, packageName);
    let peers = getOrCreate(this.configs, targetPackage.root, () => []);
    peers.push(config);
  }
github embroider-build / embroider / packages / compat / src / v1-instance-cache.ts View on Github external
private addAddon(addonInstance: any) {
    let Klass = this.adapterClass(addonInstance.pkg.name);
    let v1Addon = new Klass(addonInstance, this.options, this.app);
    let pkgs = getOrCreate(this.addons, v1Addon.root, () => []);
    pkgs.push(v1Addon);
    (addonInstance.addons as any[]).forEach(a => this.addAddon(a));
  }
github embroider-build / embroider / packages / compat / src / v1-instance-cache.ts View on Github external
static forApp(emberApp: object, options: Required): V1InstanceCache {
    let instance = getOrCreate(this.caches, emberApp, () => new this(emberApp, options));
    if (options && !isEqual(instance.options, options)) {
      throw new Error(`attempted double set of app Options`);
    }
    return instance;
  }