How to use the import-from function in import-from

To help you get started, we’ve selected a few import-from 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 dotansimha / graphql-code-generator / packages / utils / plugins-helpers / src / resolve-external-module-and-fn.ts View on Github external
export function resolveExternalModuleAndFn(pointer: any): any {
  if (typeof pointer === 'function') {
    return pointer;
  }

  const patternArr = pointer.split('#');
  const moduleName = patternArr[0];
  const functionName = patternArr[1];
  const localFilePath = path.resolve(process.cwd(), moduleName);
  const localFileExists = fs.existsSync(localFilePath);
  const loadedModule = localFileExists ? require(localFilePath) : importFrom(process.cwd(), moduleName);

  if (!(functionName in loadedModule)) {
    throw new Error(`${functionName} couldn't be found in module ${moduleName}!`);
  }

  return loadedModule[functionName];
}
github patternplate / patternplate / packages / patternplate-transform-styled-components / source.js View on Github external
function styledComponentsTransformFactory(app) {
  const importing = importFrom(process.cwd(), "styled-components");

  return async function(file) {
    const { ServerStyleSheet } = await importing;

    file.wrap = async (render, comp) => {
      const sheet = new ServerStyleSheet();
      const html = render(sheet.collectStyles(comp));
      const css = sheet.getStyleTags();

      app.resources = app.resources.filter(
        r => r.id !== `styled-components/${file.pattern.id}`
      );

      app.resources.push({
        id: `styled-components/${file.pattern.id}`,
        pattern: file.pattern.id,
github pikapkg / pack / src / config.ts View on Github external
async function cleanRawDistObject(rawVal, cwd, canBeFalsey): Promise {
      if (Array.isArray(rawVal)) {
        let importStr = (rawVal[0].startsWith('./') ||rawVal[0].startsWith('../')) ? path.join(cwd, rawVal[0]) : rawVal[0];
        return [{...importFrom(cwd, importStr), name: rawVal[0]}, rawVal[1] || {}];
      }
      if (typeof rawVal === 'string') {
        return [{build: ({cwd}) => {
          return executeLifecycleScript({
          config: this,
          cwd,
          cmd: rawVal,
          isInteractive: false});
        }}, {}];
      }
      if (!rawVal && !canBeFalsey) {
        throw new Error('Cannot be false');
      }
      return false;
    }
    return (await Promise.all([
github egoist / babel-plugin-markdown / src / index.js View on Github external
function importPlugin(name, file) {
  if (typeof name === 'string') {
    const cwd = file === 'unknown' ? process.cwd() : p.dirname(file)
    return importFrom(cwd, `markdown-it-${name}`)
  }
  return name
}
github pikapkg / pack / checkpoint / dist-src / config.js View on Github external
async function cleanRawDistObject(rawVal, cwd, canBeFalsey) {
            if (Array.isArray(rawVal)) {
                let importStr = (rawVal[0].startsWith('./') || rawVal[0].startsWith('../')) ? path.join(cwd, rawVal[0]) : rawVal[0];
                return [Object.assign({}, importFrom(cwd, importStr), { name: rawVal[0] }), rawVal[1] || {}];
            }
            if (typeof rawVal === 'string') {
                return [{ build: ({ cwd }) => {
                            return executeLifecycleScript({
                                config: this,
                                cwd,
                                cmd: rawVal,
                                isInteractive: false
                            });
                        } }, {}];
            }
            if (!rawVal && !canBeFalsey) {
                throw new Error('Cannot be false');
            }
            return false;
        }
github steelbrain / pundle / packages / pundle-transformer-babel / src / index.js View on Github external
async callback(context, options, file) {
      if (!shouldProcess(context.config.rootDirectory, file.filePath, options)) {
        return null
      }
      let babelCore
      try {
        babelCore = importFrom(context.config.rootDirectory, 'babel-core')
      } catch (error) {
        if (error && error.code === 'MODULE_NOT_FOUND') {
          throw new MessageIssue(
            `pundle-resolver-babel is to find 'babel-core' in Project root. Are you sure you installed it?`,
          )
        }
        throw error
      }

      const mergedConfigs = {
        babelrc: false,
        filename: file.filePath,
        sourceMap: true,
        highlightCode: false,
        sourceFileName: file.filePath,
      }
github steelbrain / pundle / packages / pundle-core-parse-config / src / load-config.js View on Github external
get(config, 'presets', []).forEach(function(entry) {
    const [entryPreset, options = {}] = Array.isArray(entry) ? entry : [entry]
    if (!options || typeof options !== 'object') {
      throw new Error(`Resolved config for component '${entryPreset}' referenced ${postfix} is invalid`)
    }

    let preset = entryPreset
    if (typeof preset === 'string') {
      try {
        preset = normalizeEsModules(importFrom(configDirectory, entryPreset))
      } catch (error) {
        error.message = `Error loading preset '${entryPreset}' referenced ${postfix}: ${error.message}`
        throw error
      }
    }
    if (typeof preset === 'function') {
      preset = preset(options)
    }
    if (!Array.isArray(preset)) {
      throw new Error(`Resolved value for preset '${entryPreset}' referenced ${postfix} is not an array`)
    }

    preset.forEach(function(presetEntry) {
      const [entryComponent, componentOptions = {}] = Array.isArray(presetEntry) ? presetEntry : [presetEntry]
      if (!componentOptions || typeof componentOptions !== 'object') {
        throw new Error(
github origami-cms / cms / packages / core-lib / src / requireLib.ts View on Github external
const load = async (ctx: string) => {
    try {
      if (typeof prefix === 'string' || !prefix) {
        return await importFrom(ctx, `${prefix || ''}${_lib}`);
      } else throw notFound;
    } catch {
      let loadLib;
      if (prefix instanceof Array) {
        for (const p of prefix) {
          try {
            loadLib = await importFrom(ctx, `${p}${_lib}`);
            break;
          } catch { continue; }
        }
        if (loadLib) return loadLib;
      } else throw notFound;
    }
  };

import-from

Import a module like with `require()` but from a given path

MIT
Latest version published 3 years ago

Package Health Score

70 / 100
Full package analysis

Popular import-from functions