How to use @embroider/macros - 10 common examples

To help you get started, we’ve selected a few @embroider/macros 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 / moved-package-cache.ts View on Github external
MacrosConfig.shared().packageMoved(origApp.root, this.appDestDir);

    for (let originalPkg of movedSet.packages) {
      // Update our rootCache so we don't need to rediscover moved packages
      let movedPkg;
      if (originalPkg === origApp) {
        // this wraps the original app package with one that will use moved
        // dependencies. The app itself hasn't moved yet, which is why a proxy
        // is needed at this level.
        movedPkg = packageProxy(origApp, (pkg: Package) => this.moved.get(pkg) || pkg);
        this.app = movedPkg;
        rootCache.set(movedPkg.root, movedPkg);
      } else {
        movedPkg = this.movedPackage(originalPkg);
        this.moved.set(originalPkg, movedPkg);
        MacrosConfig.shared().packageMoved(originalPkg.root, movedPkg.root);
      }

      // Update our resolutionCache so we still know as much about the moved
      // packages as we did before we moved them, without redoing package
      // resolution.
      let resolutions = new Map();
      for (let dep of originalPkg.dependencies) {
        if (movedSet.packages.has(dep)) {
          resolutions.set(dep.name, this.movedPackage(dep));
        } else {
          resolutions.set(dep.name, dep);
        }
      }
      resolutionCache.set(movedPkg, resolutions);
    }
    this.rootCache = rootCache;
github embroider-build / embroider / packages / core / src / app.ts View on Github external
if (!babel.plugins) {
      babel.plugins = [];
    }

    // Our stage3 code is always allowed to use dynamic import. We may emit it
    // ourself when splitting routes.
    babel.plugins.push(
      require.resolve(
        this.adapter.babelMajorVersion() === 6
          ? 'babel-plugin-syntax-dynamic-import'
          : '@babel/plugin-syntax-dynamic-import'
      )
    );

    // this is @embroider/macros configured for full stage3 resolution
    babel.plugins.push(MacrosConfig.shared().babelPluginConfig());

    // this is our built-in support for the inline hbs macro
    babel.plugins.push([
      join(__dirname, 'babel-plugin-inline-hbs.js'),
      {
        templateCompiler,
        stage: 3,
      },
    ]);

    babel.plugins.push(this.adjustImportsPlugin(appFiles));

    return new PortableBabelConfig(babel, { basedir: this.root });
  }
github embroider-build / embroider / packages / compat / src / v1-addon.ts View on Github external
function babelPluginAllowedInStage1(plugin: PluginItem) {
  if (isEmbroiderMacrosPlugin(plugin)) {
    // the point of @embroider/macros is that it's allowed to stay in v2
    // addon publication format, so it doesn't need to run here in stage1.
    // We always run it in stage3.
    return false;
  }

  if (TemplateCompiler.isInlinePrecompilePlugin(plugin)) {
    // Similarly, the inline precompile plugin must not run in stage1. We
    // want all templates uncompiled. Instead, we will be adding our own
    // plugin that only runs custom AST transforms inside inline
    // templates.
    return false;
  }

  return true;
}
github embroider-build / embroider / packages / compat / src / v1-app.ts View on Github external
plugins = plugins.filter(p => {
      // even if the app was using @embroider/macros, we drop it from the config
      // here in favor of our globally-configured one.
      return (
        !isEmbroiderMacrosPlugin(p) &&
        // similarly, if the app was already using an inline template compiler
        // babel plugin, we remove it here because we have our own
        // always-installed version of that (v2 addons are allowed to assume it
        // will be present in the final app build, the app doesn't get to turn
        // that off or configure it.)
        !TemplateCompiler.isInlinePrecompilePlugin(p)
      );
    });
github embroider-build / embroider / test-packages / static-app / ember-cli-build.js View on Github external
module.exports = function(defaults) {
  let app = new EmberApp(defaults, {});

  MacrosConfig.shared().setOwnConfig(__filename, {
    isClassic: Boolean(process.env.CLASSIC),
  });

  if (process.env.CLASSIC) {
    return app.toTree();
  }

  const Webpack = require('@embroider/webpack').Webpack;
  return require('@embroider/compat').compatBuild(app, Webpack, {
    workspaceDir: process.env.WORKSPACE_DIR,
    staticAddonTestSupportTrees: true,
    staticAddonTrees: true,
    staticComponents: true,
    staticHelpers: true,
    packageRules: [
      {
github embroider-build / embroider / test-packages / support / build.ts View on Github external
static async build(project: Project, params: Partial) {
    MacrosConfig.reset();
    let paramsWithDefaults: BuildParams = Object.assign({}, params, defaultParams);
    project.writeSync();
    let instance;
    if (paramsWithDefaults.type === 'addon') {
      instance = emberAddon(project.baseDir, params.emberAppOptions);
    } else {
      instance = emberApp(project.baseDir, params.emberAppOptions);
    }
    let addons = new Addons(instance, params.embroiderOptions);
    let tree;
    if (params.stage === 1) {
      tree = addons.tree;
    } else {
      let compatApp = new App(instance, addons, params.embroiderOptions);
      tree = compatApp.tree;
    }
github embroider-build / embroider / packages / core / src / app.ts View on Github external
private templateCompiler(config: EmberENV) {
    let plugins = this.adapter.htmlbarsPlugins();
    if (!plugins.ast) {
      plugins.ast = [];
    }
    for (let macroPlugin of MacrosConfig.shared().astPlugins()) {
      plugins.ast.push(macroPlugin);
    }

    return new TemplateCompiler({
      plugins,
      compilerPath: resolve.sync(this.adapter.templateCompilerPath(), { basedir: this.root }),
      resolver: this.adapter.templateResolver(),
      EmberENV: config,
    });
  }
github embroider-build / embroider / packages / core / src / app.ts View on Github external
constructor(
    private root: string,
    private app: Package,
    private adapter: AppAdapter,
    private options: Required
  ) {
    MacrosConfig.shared().setOwnConfig(__filename, { active: true });
  }
github embroider-build / embroider / packages / compat / src / v1-app.ts View on Github external
      options.plugins.ast = options.plugins.ast.filter((p: any) => !isEmbroiderMacrosPlugin(p));
    }
github embroider-build / embroider / packages / compat / src / v1-addon.ts View on Github external
        options.plugins.ast = options.plugins.ast.filter((p: any) => !isEmbroiderMacrosPlugin(p));
        if (options.plugins.ast.length > 0) {

@embroider/macros

Standardized build-time macros for ember apps.

MIT
Latest version published 1 month ago

Package Health Score

83 / 100
Full package analysis