How to use is-builtin-module - 8 common examples

To help you get started, we’ve selected a few is-builtin-module 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 kentcdodds / asts-workshop / other / old-exercises / 08_codemod.js View on Github external
function isCommonJSModule(sourceString, filename) {
  if (isRelativePath(sourceString)) {
    const fullPath = nodePath.resolve(nodePath.dirname(filename), sourceString)
    return !exportsAsESModule(require.resolve(fullPath))
  } else if (nodePath.isAbsolute(sourceString)) {
    return !exportsAsESModule(require.resolve(sourceString))
  } else if (isBuiltinModule(sourceString)) {
    return true
  } else {
    // eslint-disable-next-line no-console
    console.warn(
      oneLine`
        import for "${sourceString}" was unable
        to be identified as commonJS or ESM
      `,
    )
    return false
  }
}
github kentcdodds / asts-workshop / other / old-exercises / exercises / 08_codemod.js View on Github external
function isCommonJSModule(sourceString, filename) {
  if (isRelativePath(sourceString)) {
    const fullPath = nodePath.resolve(nodePath.dirname(filename), sourceString)
    return !exportsAsESModule(require.resolve(fullPath))
  } else if (nodePath.isAbsolute(sourceString)) {
    return !exportsAsESModule(require.resolve(sourceString))
  } else if (isBuiltinModule(sourceString)) {
    return true
  } else {
    // eslint-disable-next-line no-console
    console.warn(
      oneLine`
        import for "${sourceString}" was unable
        to be identified as commonJS or ESM
      `,
    )
    return false
  }
}
github pikapkg / web / src / index.ts View on Github external
onwarn: ((warning, warn) => {
        if (warning.code === 'UNRESOLVED_IMPORT') {
          // If we're using remoteUrl, we should expect them to be unresolved. ("external" should handle this for us, but we're still seeing it)
          if (remoteUrl && warning.source.startsWith(remoteUrl)) {
            return;
          }
          logError(
            `'${warning.source}' is imported by '${warning.importer}', but could not be resolved.`,
          );
          if (isNodeBuiltin(warning.source)) {
            console.log(
              chalk.dim(
                `  '${
                  warning.source
                }' is a Node.js builtin module that won't exist on the web. You can find modern, web-ready packages at ${chalk.underline(
                  'https://www.pika.dev',
                )}`,
              ),
            );
          } else {
            console.log(
              chalk.dim(`  Make sure that the package is installed and that the file exists.`),
            );
          }
          return;
        }
github pikapkg / pack / src / util / normalize-manifest / validate.ts View on Github external
export default function(info: any, isRoot: boolean, reporter: Reporter, warn: WarnFunction) {
  if (isRoot) {
    for (const key in typos) {
      if (key in info) {
        warn(reporter.lang('manifestPotentialTypo', key, typos[key]));
      }
    }
  }

  // validate name
  const {name} = info;
  if (typeof name === 'string') {
    if (isRoot && isBuiltinModule(name)) {
      warn(reporter.lang('manifestBuiltinModule', name));
    }

    // cannot start with a dot
    if (name[0] === '.') {
      throw new MessageError(reporter.lang('manifestNameDot'));
    }

    // cannot contain the following characters
    if (!isValidPackageName(name)) {
      throw new MessageError(reporter.lang('manifestNameIllegalChars'));
    }

    // cannot equal node_modules or favicon.ico
    const lower = name.toLowerCase();
    if (lower === 'node_modules' || lower === 'favicon.ico') {
github u-wave / core / rollup.config.js View on Github external
  external: id => isBuiltinModule(id) || external.some(m => id.split('/')[0] === m),
  plugins: [
github bfncs / codemod-imports-sort / src / matchers.js View on Github external
export const isScopedExternalModule = path =>
  /^@(?:[\w-]+\/?[\w-])+$/.test(path) && !isBuiltinModule(path);
github bitinn / node-fetch / rollup.config.js View on Github external
external: function (id) {
    if (isBuiltin(id)) {
      return true;
    }
    id = id.split('/').slice(0, id[0] === '@' ? 2 : 1).join('/');
    return !!require('./package.json').dependencies[id];
  }
};
github shuidi-fed / vuese / rollup.config.js View on Github external
onwarn(warning, warn) {
    if (warning.code === 'UNRESOLVED_IMPORT' && isBuiltinModule(warning.source))
      return
    warn(warning)
  }
}

is-builtin-module

Check if a string matches the name of a Node.js builtin module

MIT
Latest version published 8 months ago

Package Health Score

76 / 100
Full package analysis

Popular is-builtin-module functions