How to use esm - 9 common examples

To help you get started, we’ve selected a few esm 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 nuxt / nuxt.js / packages / cli / src / utils / config.js View on Github external
try {
    nuxtConfigFile = require.resolve(path.resolve(rootDir, argv['config-file']))
  } catch (e) {
    if (e.code !== 'MODULE_NOT_FOUND') {
      throw (e)
    } else if (argv['config-file'] !== defaultNuxtConfigFile) {
      consola.fatal('Could not load config file: ' + argv['config-file'])
    }
  }

  if (nuxtConfigFile) {
    // Clear cache
    clearRequireCache(nuxtConfigFile)

    options = esm(module)(nuxtConfigFile) || {}

    if (options.default) {
      options = options.default
    }

    if (typeof options === 'function') {
      try {
        options = await options()
        if (options.default) {
          options = options.default
        }
      } catch (error) {
        consola.error(error)
        consola.fatal('Error while fetching async configuration')
      }
    }
github remaxjs / remax / packages / remax-cli / src / getConfig.ts View on Github external
function readJavascriptConfig(path: string) {
  // eslint-disable-next-line
  require = esm(module, {
    cjs: {
      dedefault: true,
    },
  });
  delete require.cache[require.resolve(path)];
  const config = require(path);

  return config || {};
}
github remaxjs / remax / packages / remax-cli / src / readManifest.ts View on Github external
function readJavascriptManifest(path: string, target: string) {
  // eslint-disable-next-line
  require = esm(module, {
    cjs: {
      dedefault: true,
    },
  });

  delete require.cache[require.resolve(path)];
  const config =
    require(path)[target] || require(path).default || require(path);

  return config;
}
github nuxt / nuxt.js / lib / core / nuxt.js View on Github external
this._hooks = {}
    this.hook = this.hook.bind(this)

    // Create instance of core components
    this.moduleContainer = new ModuleContainer(this)
    this.renderer = new Renderer(this)

    // Backward compatibility
    this.render = this.renderer.app
    this.renderRoute = this.renderer.renderRoute.bind(this.renderer)
    this.renderAndGetWindow = this.renderer.renderAndGetWindow.bind(
      this.renderer
    )

    // ESM Loader
    this.esm = esm(module, {})

    this._ready = this.ready().catch(err => {
      consola.fatal(err)
    })
  }
github remaxjs / remax / packages / remax-cli / src / readManifest.ts View on Github external
function readTypescriptManifest(path: string, target: string) {
  require('@babel/register')({
    presets: [
      ['@babel/preset-env', { modules: 'commonjs' }],
      '@babel/preset-typescript',
    ],
    extensions: ['.ts'],
    cache: false,
  });
  // eslint-disable-next-line
  require = esm(module, {
    cjs: {
      dedefault: true,
    },
  });
  delete require.cache[require.resolve(path)];
  const config =
    require(path)[target] || require(path).default || require(path);

  return config;
}
github nuxt / nuxt.js / packages / core / src / resolver.js View on Github external
constructor (nuxt) {
    this.nuxt = nuxt
    this.options = this.nuxt.options

    // Binds
    this.resolvePath = this.resolvePath.bind(this)
    this.resolveAlias = this.resolveAlias.bind(this)
    this.resolveModule = this.resolveModule.bind(this)
    this.requireModule = this.requireModule.bind(this)

    // ESM Loader
    this.esm = esm(module)

    this._resolve = require.resolve
  }
github mAAdhaTTah / brookjs / packages / brookjs-cli / src / cli / App.tsx View on Github external
import React from 'react';
import { cosmiconfig, defaultLoaders } from 'cosmiconfig';
import { render } from 'ink';
import esm from 'esm';
import { Maybe } from 'brookjs-types';
import { RC, RCError, RCResult } from '../RC';
import { Command } from './Command';
import Commands from './Commands';
import ErrorBoundary, {
  CommandValidationError,
  LoadDirError,
  Root
} from './components';

const loadEsm = esm(module);

const loaders = {
  ...defaultLoaders,
  '.js': (filename: string) => loadEsm(filename)
};

export class App {
  static create(name: string, commands?: Commands) {
    return new App(name, commands);
  }

  private constructor(
    private name: string,
    private commands: Commands = new Commands(),
    private errors: JSX.Element[] = []
  ) {}
github mAAdhaTTah / brookjs / packages / brookjs-cli / src / main.js View on Github external
export default R.curry(function main (name, args, options, logger) {
    const store = createStore(
        combineReducers({ app, command, env, mocha, webpack }),
        applyMiddleware(observeDelta(
            envDelta({ process, require: loader(module, { mode: 'auto', cjs: true }) }),
            scaffoldDelta({ logger }),
            terminalDelta({ ui: ui(logger) }),
            testRunnerDelta({ glob }),
            webpackDelta({ webpack: WebpackService })
        ))
    );

    store.dispatch(run(name, args, options));
});

esm

Tomorrow's ECMAScript modules today!

MIT
Latest version published 6 years ago

Package Health Score

63 / 100
Full package analysis

Popular esm functions