How to use the @kosko/require.requireDefault function in @kosko/require

To help you get started, we’ve selected a few @kosko/require 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 tommy351 / kosko / packages / cli / src / commands / generate.ts View on Github external
async function localRequire(id: string, cwd: string): Promise {
  debug("Finding module %s in %s", id, cwd);
  const path = await resolve(id, { basedir: cwd });
  debug("Importing %s from %s", id, path);
  return requireDefault(path);
}
github tommy351 / kosko / packages / cli / src / commands / new.ts View on Github external
async exec(ctx, argv) {
    const { args, options, detail } = parse(argv, this, {
      "halt-at-non-option": true
    } as any);

    if (args.template) {
      const cwd = getCWD(options);
      const extensions = Object.keys(require.extensions);
      const path = await resolve(args.template, {
        basedir: cwd,
        extensions: extensions.length ? extensions : [".js"]
      });
      debug("Template path", path);

      const template = requireDefault(path);
      const cmd = buildTemplateCommand(args.template, template);
      return cmd.exec(ctx, unparse(detail).slice(1));
    }

    return help(this);
  }
};
github tommy351 / kosko / packages / env / src / environment.ts View on Github external
function tryRequire(id: string): any {
  try {
    return requireDefault(id);
  } catch (err) {
    if (err.code === "MODULE_NOT_FOUND") {
      debug("Module not found:", id);
      return {};
    }

    throw err;
  }
}
github tommy351 / kosko / packages / generate / src / generate.ts View on Github external
async function getComponentValue(id: string): Promise {
  const mod = requireDefault(id);

  if (typeof mod === "function") {
    return await mod();
  }

  return mod;
}

@kosko/require

Import and resolve modules.

MIT
Latest version published 13 days ago

Package Health Score

75 / 100
Full package analysis