How to use import-cwd - 10 common examples

To help you get started, we’ve selected a few import-cwd 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 intuit / auto / packages / core / src / utils / try-require.ts View on Github external
export default function tryRequire(tryPath: string) {
  try {
    // Require from CWD
    return importCwd(tryPath);
  } catch (error) {
    // if we try to actually require npm we will import something that is the actual npm API
    // not the plugin that we want
    if (tryPath === 'npm') {
      return;
    }

    try {
      // Require from __dirname. Needed for npx and global installs
      return require(tryPath);
    } catch (error) {}
  }
}
github EdgeApp / edge-login-ui / packages / edge-login-ui-react / sass-loader.js View on Github external
return new Promise((resolve, reject) => {
      const sass = importCwd.silent('node-sass') || importCwd.silent('sass')
      if (!sass) {
        throw new Error(
          `You need to install either node-sass or sass in order to process Sass files`
        )
      }
      const render = pify(sass.render.bind(sass))
      return workQueue.add(() =>
        render({
          ...this.options,
          file: this.id,
          data: `@import "${injectFile.replace(/\\/g, '\\\\')}";` + code,
          indentedSyntax: /\.sass$/.test(this.id),
          sourceMap: this.sourceMap,
          importer: [
            (url, importer, done) => {
              if (!moduleRe.test(url)) return done({ file: url })
github egoist / rollup-plugin-postcss / src / sass-loader.js View on Github external
return new Promise((resolve, reject) => {
      const sass = importCwd.silent('node-sass') || importCwd.silent('sass')
      if (!sass) {
        throw new Error(`You need to install either node-sass or sass in order to process Sass files`)
      }
      const render = pify(sass.render.bind(sass))
      return workQueue.add(() =>
        render({
          ...this.options,
          file: this.id,
          data: code,
          indentedSyntax: /\.sass$/.test(this.id),
          sourceMap: this.sourceMap,
          importer: [
            (url, importer, done) => {
              if (!moduleRe.test(url)) return done({ file: url })

              const moduleUrl = url.slice(1)
github qlik-oss / after-work.js / plugins / preset-plugin / src / index.js View on Github external
const safeGetModule = name => {
  let found = importCwd.silent(name);
  if (!found) {
    try {
      found = require(name);
    } catch (err) {
      found = null;
    }
  }
  return found;
};
github qlik-oss / after-work.js / src / transform.js View on Github external
function tryRequire(name) {
  const found = importCwd.silent(name);
  if (!found) {
    return require(`${name}`);
  }
  return found;
}
github qlik-oss / after-work.js / packages / utils / src / index.js View on Github external
const safeGetModule = name => {
  let found = importCwd.silent(name);
  if (!found) {
    try {
      found = require(name);
    } catch (err) {
      found = null;
    }
  }
  return found;
};
github egoist / rollup-plugin-postcss / src / postcss-loader.js View on Github external
function ensurePostCSSOption(option) {
  return typeof option === 'string' ? importCwd(option) : option
}

import-cwd

Import a module like with `require()` but from the current working directory

MIT
Latest version published 5 years ago

Package Health Score

70 / 100
Full package analysis

Popular import-cwd functions