How to use module-alias - 10 common examples

To help you get started, we’ve selected a few module-alias 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 uber-web / probe.gl / test / test-node-dist.js View on Github external
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

// require('../aliases');

// Enables ES2015 import/export in Node.js
require('reify');

const path = require('path');
const moduleAlias = require('module-alias');
moduleAlias.addAlias('probe.gl/test', path.resolve('./dist/test'));
moduleAlias.addAlias('probe.gl/bench', path.resolve('./dist/bench'));
moduleAlias.addAlias('probe.gl', path.resolve('./dist'));

// Run the tests
require('./test-index');
github ifanrx / hydrogen-js-sdk / test / web / index.js View on Github external
'use strict'

if (typeof require !== 'undefined') {
  // 为了兼容 webpack alias 与 DefinePlugin
  global.__VERSION_WEB__ = 'v1.0.0'
  const moduleAlias = require('module-alias')
  moduleAlias.addAlias('core-module', __dirname + '../../../core')

  global.window = require('./web-mock')
  let BaaS = require('../../sdk-file/src/web')
  global.BaaS = BaaS

  const sinon = require('sinon')
  const sinonStubPromise = require('sinon-stub-promise')
  sinonStubPromise(sinon)
  global.sinon = sinon
  global.expect = require('chai').expect
}

// BaaS 测试环境初始化设置(必须)
BaaS.test = {
  clientID: 'ClientID-v233',
}
github uber / xviz / test / start.js View on Github external
/* global process */
require('@babel/register')({
  configFile: resolve(__dirname, '../babel.config.js')
});

const {BrowserTestDriver} = require('@probe.gl/test-utils');

const mode = process.argv.length >= 3 ? process.argv[2] : 'default';

require('source-map-support').install();

// Registers aliases for virtual packages in this module
if (mode !== 'dist') {
  const moduleAlias = require('module-alias');
  moduleAlias.addAliases(ALIASES);
}

// Update JSON list of examples
require('./modules/update-test-cases');

switch (mode) {
  case 'test':
  case 'src':
  case 'dist':
    require('./index');
    break;

  case 'bench':
    require('./bench');
    break;
github NativeScript / NativeScript / unit-tests / runtime.ts View on Github external
import "tslib";

import * as moduleAlias from "module-alias";
import * as path from "path";

const tnsCoreModules = path.resolve(__dirname, "..", "nativescript-core");

moduleAlias.addPath(tnsCoreModules);
moduleAlias.addAliases({
    // NOTE: require("@nativescript/core/platform") with these aliases will work in node but fail in Angular AoT
    "@nativescript/core/platform": path.resolve(__dirname, "polyfills", "platform"),
    "@nativescript/core/file-system/file-system-access": path.resolve(__dirname, "polyfills", "file-system-access"),
    "@nativescript/core/utils/utils": path.resolve(tnsCoreModules, "utils/utils-common"),
    "./mainthread-helper": path.resolve(__dirname, "polyfills", "mainthread-helper"),
    "@nativescript/core/color": path.resolve(tnsCoreModules, "color/color-common"),
    "@nativescript/core/ui/styling/font": path.resolve(tnsCoreModules, "ui/styling/font-common"),
    "@nativescript/core/ui/styling/background": path.resolve(tnsCoreModules, "ui/styling/background-common"),

    "@nativescript/core": tnsCoreModules,
    "~": __dirname
});
github Casa / Casa-Node-Manager / test / global.js View on Github external
const chai = require('chai');
const chaiHttp = require('chai-http');
const sinon = require('sinon');
var path = require('path');

// manager startup mocks
require('module-alias/register');
require('module-alias').addPath('.');

// For mocking all dates established at manager boot time. Specifically lastImagePulled in logic/application.js.
// Clock mock must be before applicationStartup mock.
global.clock = sinon.useFakeTimers({
  now: 1546329600000, // January 1, 2019 Midnight PST
  shouldAdvanceTime: false,
});

global.uuidSerialId = sinon.stub(require('../utils/UUID.js'), 'fetchSerial')
  .resolves('fake_serial_id');
global.applicationStartup = sinon.stub(require('../logic/application.js'), 'startup')
  .resolves({});
global.uuidBootId = sinon.stub(require('../utils/UUID.js'), 'fetchBootUUID')
  .returns('fake_boot_id');
global.appRoot = path.resolve(__dirname);
github wintercounter / mhy / src / utils / globals.js View on Github external
;(() => {
    if (SETUP_DONE) return

    // Let's save us from the work ASAP
    const [, ...mhyIfStr] = (process.argv.find(a => a.startsWith('--mhy-if')) || '').split('=')

    if (mhyIfStr.length && !eval(mhyIfStr.join('='))) {
        console.info(`Skipping command due to falsy expression: ${mhyIfStr.join('=')}`)
        process.exit(0)
    }

    // Register dist with alias and mhy's node_modules as module source so custom JS files can use it loaded through mhy
    addAlias('@/mhy', path.resolve(__dirname, '../'))
    addPath(path.resolve(__dirname, '../../node_modules'))

    process.env.NODE_ENV = process.env.NODE_ENV || 'development'
    process.env.MHY_ENV = 'cli'
    process.env.MHY_ENVS = [process.env.NODE_ENV]
    process.env.MHY_LOCAL_DIR = '.mhy'

    const envsMap = {
        prod: 'production',
        dev: 'development'
    }
    const [, mhyEnvsStr = ''] = (process.argv.find(a => a.startsWith('--mhy-env')) || '').split('=')
    const mhyEnvsList = mhyEnvsStr.split(':').filter(a => a)
    if (mhyEnvsList.length) {
        const NODE_ENV = (mhyEnvsList[0] = envsMap[mhyEnvsList[0]] || mhyEnvsList[0])
        process.env.MHY_ENVS = mhyEnvsList
github intuit / auto / packages / cli / src / bin / auto.ts View on Github external
#!/usr/bin/env node

import moduleAlias from 'module-alias';
import path from 'path';

try {
  // eslint-disable-next-line
  const json = require(path.join(__dirname, '../../package.json'));

  if (json.name.startsWith('@auto-canary')) {
    moduleAlias.addAliases({
      '@auto-it': (fromPath: string, request: string) =>
        request.startsWith('@auto-it') ? '@auto-canary' : '@auto-it'
    });
  }
} catch (error) {}

import chalk from 'chalk';
import parseArgs from '../parse-args';
import run from '../run';

const [command, args] = parseArgs();

if (command && args) {
  run(command, args).catch((e: Error) => {
    console.error(chalk.redBright('Error: '), e.message);
    process.exit(1);
github wintercounter / mhy / src / utils / globals.js View on Github external
;(() => {
    if (SETUP_DONE) return

    // Let's save us from the work ASAP
    const [, ...mhyIfStr] = (process.argv.find(a => a.startsWith('--mhy-if')) || '').split('=')

    if (mhyIfStr.length && !eval(mhyIfStr.join('='))) {
        console.info(`Skipping command due to falsy expression: ${mhyIfStr.join('=')}`)
        process.exit(0)
    }

    // Register dist with alias and mhy's node_modules as module source so custom JS files can use it loaded through mhy
    addAlias('@/mhy', path.resolve(__dirname, '../'))
    addPath(path.resolve(__dirname, '../../node_modules'))

    process.env.NODE_ENV = process.env.NODE_ENV || 'development'
    process.env.MHY_ENV = 'cli'
    process.env.MHY_ENVS = [process.env.NODE_ENV]
    process.env.MHY_LOCAL_DIR = '.mhy'

    const envsMap = {
        prod: 'production',
        dev: 'development'
    }
    const [, mhyEnvsStr = ''] = (process.argv.find(a => a.startsWith('--mhy-env')) || '').split('=')
    const mhyEnvsList = mhyEnvsStr.split(':').filter(a => a)
    if (mhyEnvsList.length) {
        const NODE_ENV = (mhyEnvsList[0] = envsMap[mhyEnvsList[0]] || mhyEnvsList[0])
        process.env.MHY_ENVS = mhyEnvsList
        process.env.NODE_ENV = NODE_ENV
github humanmade / linter-bot / src / linters / eslint / index.js View on Github external
try {
			output = run( engine, codepath );
		} catch ( err ) {
			if ( err.messageTemplate === 'no-config-found' ) {
				// Try with default configuration.
				const engine = new CLIEngine( { ...options, configFile: `${ standardPath }/index.js` } );
				console.log( 'Running eslint with default config on path', codepath );
				output = run( engine, codepath );
			} else {
				console.log( err );
				throw err;
			}
		}

		// Reset path loader.
		moduleAlias.reset();
		Module._findPath = origFindPath;

		resolve( formatOutput( output, codepath ) );
	} );
};
github zeit / next.js / examples / using-inferno / server.js View on Github external
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const moduleAlias = require('module-alias')
const path = require('path')

// For the development version, we'll use React.
// Because, it support react hot loading and so on.
if (!dev) {
  moduleAlias.addAlias('react', path.resolve('./lib/inferno-compat.js'))
  moduleAlias.addAlias('react-dom/server', 'inferno-server')
  moduleAlias.addAlias('react-dom', path.resolve('./lib/inferno-compat.js'))
}

const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')

const app = next({ dev })
const handle = app.getRequestHandler()

app.prepare().then(() => {
  createServer((req, res) => {
    const parsedUrl = parse(req.url, true)
    handle(req, res, parsedUrl)
  }).listen(port, err => {

module-alias

Create aliases of directories and register custom module paths

MIT
Latest version published 11 months ago

Package Health Score

75 / 100
Full package analysis