How to use @embroider/core - 10 common examples

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 ef4 / ember-auto-import / packages / ember-auto-import / ts / webpack.ts View on Github external
private babelRule(): webpack.Rule {
    let shouldTranspile = babelFilter(this.skipBabel);
    let stagingDir = this.stagingDir;
    return {
      test(filename: string) {
        // We don't apply babel to our own stagingDir (it contains only our own
        // entrypoints that we wrote, and it can use `import()`, which we want
        // to leave directly for webpack).
        //
        // And we otherwise defer to the `skipBabel` setting as implemented by
        // `@embroider/core`.
        return dirname(filename) !== stagingDir && shouldTranspile(filename);
      },
      use: {
        loader: 'babel-loader-8',
        options: {
          presets: [
            [
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 / dedupe / src / index.ts View on Github external
async function traverse(options: Options) {
  let packageCache = new PackageCache();
  let app = packageCache.getApp(options['project-dir']);
  let versionMap: Map> = new Map();
  let consumers: Map> = new Map();

  let packageFilter = makePackageFilter(options, consumers);

  recordConsumers(app, consumers);
  let deps = app.findDescendants(dep => {
    recordConsumers(dep, consumers);
    // for now we're limiting ourselves only to ember addons. We can relax this
    // to eventually also include things that are directly consumed by ember
    // addons, or even the entire node_modules graph.
    return packageFilter(dep);
  });

  for (let dep of deps) {
github embroider-build / embroider / packages / macros / src / macros-config.ts View on Github external
import { join } from 'path';
import { PluginItem } from '@babel/core';
import { PackageCache, getOrCreate } from '@embroider/core';
import { makeFirstTransform, makeSecondTransform } from './glimmer/ast-transform';

const packageCache = new PackageCache();

export type Merger = (configs: unknown[]) => unknown;

// Do not change the public signature of this class without pondering deeply the
// mysteries of being compatible with unwritten future versions of this library.
class GlobalSharedState {
  configs: Map = new Map();
  mergers: Map = new Map();
}

// this is a module-scoped cache. If multiple callers ask _this copy_ of
// @embroider/macros for the shared MacrosConfig, they'll all get the same one.
// And if somebody asks a *different* copy of @embroider/macros for the shared
// MacrosConfig, it will have its own instance with its own code, but will still
// share the GlobalSharedState beneath.
let localSharedState: MacrosConfig | undefined;
github embroider-build / embroider / packages / macros / src / glimmer / dependency-satisfies.ts View on Github external
import { satisfies, coerce } from 'semver';
import { PackageCache } from '@embroider/core';

let packageCache = PackageCache.shared('embroider-stage3');

export default function dependencySatisfies(
  node: any,
  // when we're running in traditional ember-cli, baseDir is configured and we
  // do all lookups relative to that (single) package. But when we're running in
  // embroider stage3 we process all packages simultaneously, so baseDir is left
  // unconfigured and moduleName will be the full path to the source file.
  baseDir: string | undefined,
  moduleName: string
) {
  if (node.params.length !== 2) {
    throw new Error(`macroDependencySatisfies requires two arguments, you passed ${node.params.length}`);
  }

  if (!node.params.every((p: any) => p.type === 'StringLiteral')) {
    throw new Error(`all arguments to macroDependencySatisfies must be string literals`);
github embroider-build / embroider / packages / macros / src / glimmer / get-config.ts View on Github external
import { PackageCache } from '@embroider/core';

let packageCache = PackageCache.shared('embroider-stage3');

export default function getConfig(
  node: any,
  userConfigs: { [packageRoot: string]: unknown },
  // when we're running in traditional ember-cli, baseDir is configured and we
  // do all lookups relative to that (single) package. But when we're running in
  // embroider stage3 we process all packages simultaneously, so baseDir is left
  // unconfigured and moduleName will be the full path to the source file.
  baseDir: string | undefined,
  moduleName: string,
  own: boolean
) {
  let targetConfig;
  let params = node.params.slice();
  if (!params.every((p: any) => p.type === 'StringLiteral')) {
    throw new Error(`all arguments to ${own ? 'macroGetOwnConfig' : 'macroGetConfig'} must be string literals`);
github embroider-build / embroider / packages / compat / src / v1-addon.ts View on Github external
protected treeForTestSupport(): Tree | undefined {
    if (this.customizes('treeForTestSupport')) {
      todo(`${this.name} has customized the test support tree`);
    } else if (this.hasStockTree('test-support')) {
      // this one doesn't go through transpile yet because it gets handled as
      // part of the consuming app. For example, imports should be relative to
      // the consuming app, not our own package. That is some of what is lame
      // about app trees and why they will go away once everyone is all MU.
      return new Funnel(this.stockTree('test-support'), {
        destDir: `${appPublicationDir}/tests`,
      });
    }
  }
github embroider-build / embroider / packages / compat / src / compat-app.ts View on Github external
private internalTemplateResolver(): CompatResolver {
    let resolver = new CompatResolver({
      root: this.root,
      modulePrefix: this.modulePrefix(),
      options: this.options,
      activePackageRules: this.activeRules(),
      resolvableExtensions: this.resolvableExtensions(),
    });
    // It's ok that this isn't a fully configured template compiler. We're only
    // using it to parse component snippets out of rules.
    resolver.astTransformer(
      new TemplateCompiler({
        compilerPath: resolveSync(this.templateCompilerPath(), { basedir: this.root }),
        EmberENV: {},
        plugins: {},
      })
    );
    return resolver;
  }
github embroider-build / embroider / packages / compat / src / v1-addon.ts View on Github external
private get templateCompiler(): TemplateCompiler | undefined {
    let htmlbars = this.addonInstance.addons.find((a: any) => a.name === 'ember-cli-htmlbars');
    if (htmlbars) {
      let options = htmlbars.htmlbarsOptions() as HTMLBarsOptions;
      if (options.plugins && options.plugins.ast) {
        // our macros don't run here in stage1
        options.plugins.ast = options.plugins.ast.filter((p: any) => !isEmbroiderMacrosPlugin(p));
        if (options.plugins.ast.length > 0) {
          return new TemplateCompiler({
            compilerPath: options.templateCompilerPath,
            EmberENV: {},
            plugins: options.plugins,
          });
        }
      }
    }
  }
github embroider-build / embroider / packages / compat / src / dummy-package.ts View on Github external
get dependencies(): Package[] {
    // we can't use this.owningAddon.dependencies because that won't include
    // devDeps. We need to construct a new temporary package with the
    // mayUseDevDeps flag to true.
    let upstream = new Package(this.owningAddon.root, this.packageCache, true).dependencies.slice();
    // the dummy app has a dependency on the owning addon
    upstream.unshift(this.owningAddon);
    return upstream;
  }
}