How to use the @embroider/core.PackageCache.shared 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 / 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 / resolver.ts View on Github external
absPathToRuntimeName(absPath: string) {
    let pkg = PackageCache.shared('embroider-stage3').ownerOfFile(absPath);
    if (pkg) {
      return join(pkg.name, relative(pkg.root, absPath))
        .replace(this.resolvableExtensionsPattern, '')
        .split(sep)
        .join('/');
    } else if (absPath.startsWith(this.params.root)) {
      return join(this.params.modulePrefix, relative(this.params.root, absPath))
        .replace(this.resolvableExtensionsPattern, '')
        .split(sep)
        .join('/');
    }
  }
github embroider-build / embroider / packages / macros / src / babel / macros-babel-plugin.ts View on Github external
import { NodePath } from '@babel/traverse';
import { ImportDeclaration, CallExpression, Identifier, memberExpression, identifier } from '@babel/types';
import { PackageCache } from '@embroider/core';
import State, { sourceFile } from './state';
import dependencySatisfies from './dependency-satisfies';
import getConfig from './get-config';
import macroIf from './macro-if';
import error from './error';
import failBuild from './fail-build';
import { bindState } from './visitor';

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

export default function main() {
  let visitor = {
    Program: {
      enter(_: NodePath, state: State) {
        state.removed = [];
        state.pendingTasks = [];
        state.generatedRequires = new Set();
      },
      exit(path: NodePath, state: State) {
        state.pendingTasks.forEach(task => task());
        pruneRemovedImports(state);
        pruneMacroImports(path);
      },
    },
    CallExpression(path: NodePath, state: State) {