How to use the module-alias.addPath function in module-alias

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 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
        process.env.NODE_ENV = NODE_ENV
github Casa / Casa-Node-Manager / app.js View on Github external
require('module-alias/register');
require('module-alias').addPath('.');
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const passport = require('passport');
const cors = require('cors');

// Keep requestCorrelationId middleware as the first middleware. Otherwise we risk losing logs.
const requestCorrelationMiddleware = require('middlewares/requestCorrelationId.js'); // eslint-disable-line id-length
const errorHandleMiddleware = require('middlewares/errorHandling.js');
const onionOriginMiddleware = require('middlewares/onionOrigin.js');
const corsOptions = require('middlewares/cors.js').corsOptions;
require('middlewares/auth.js');

const logger = require('utils/logger.js');
const applicationLogic = require('logic/application.js');
github Casa / Casa-Node-API / app.js View on Github external
require('module-alias/register');
require('module-alias').addPath('.');
const express = require('express');
const path = require('path');
const morgan = require('morgan');
const bodyParser = require('body-parser');
const passport = require('passport');
const cors = require('cors');

// Keep requestCorrelationId middleware as the first middleware. Otherwise we risk losing logs.
const requestCorrelationMiddleware = require('middlewares/requestCorrelationId.js'); // eslint-disable-line id-length
const camelCaseReqMiddleware = require('middlewares/camelCaseRequest.js').camelCaseRequest;
const onionOriginMiddleware = require('middlewares/onionOrigin.js');
const corsOptions = require('middlewares/cors.js').corsOptions;
const errorHandleMiddleware = require('middlewares/errorHandling.js');
require('middlewares/auth.js');

const logger = require('utils/logger.js');
github wintercounter / mhy / src / resources / nodeProcessSetup.js View on Github external
import babelConfig from '@/configs/babel'
import register from '@babel/register'

babelConfig.presets.find(p => p[0].includes('preset-env'))[1] = {
    modules: 'commonjs',
    targets: {
        node: true,
        browsers: false,
        esmodules: true
    }
}
babelConfig.extensions = ['.es6', '.es', '.jsx', '.js', '.mjs', '.ts', '.tsx']
babelConfig.cache = false

register(babelConfig)
addPath(path.resolve(process.cwd(), 'node_modules'))
addPath(path.resolve(__dirname, '../../node_modules'))

const alias = { ...mhyConfig.defaultAliases }
for (const [key, entry] of Object.entries(alias)) {
    if (!fs.existsSync(entry)) {
        alias[key] = path.resolve(process.cwd(), entry)
    } else {
        // Make sure it's a resolved path indeed
        alias[key] = path.resolve(entry)
    }
}
addAliases(alias)

const scriptKey = '--mhy-script'
const scriptIndex = process.argv.findIndex(v => v.includes(scriptKey))
const scriptValue = process.argv[scriptIndex]
github wintercounter / mhy / src / bin / index.js View on Github external
#!/usr/bin/env node
import path from 'path'
import yargs from 'yargs'
import { loadCommands } from '@/processes'
import { addPath, addAlias } from 'module-alias'

// 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_LOCAL_DIR = '.mhy'

global.MHY_UI_ACTION = 'action'
global.MHY_UI_ACTION_CLEAR = 'clear'
global.MHY_UI_ACTION_DATA = 'data'
global.MHY_UI_ACTION_UPDATE = 'update'
global.MHY_UI_ACTION_FUNCTION = 'function'

if (process.argv.includes('--mhy-prod')) {
    process.env.NODE_ENV = 'production'
}

if (process.argv.includes('--mhy-verbose')) {
github SolidZORO / leaa / packages / leaa-api / index.js View on Github external
const moduleAlias = require('module-alias');

moduleAlias.addPath(__dirname);
moduleAlias.addAliases({
  '@leaa/common': '_dist/_leaa-common',
  '@leaa/api': '_dist/leaa-api',
});

moduleAlias({});

console.log('\n\n\n\n---- hello, leaa-api-server. ----\n\n');

require('./_dist/leaa-api/src/main');
github SolidZORO / leaa / packages / leaa-www / index.js View on Github external
const moduleAlias = require('module-alias');

moduleAlias.addPath(__dirname);
moduleAlias.addAliases({
  '@leaa/common': '_dist/_leaa-common',
  '@leaa/www': '_dist/leaa-www',
});

moduleAlias({});

require('./_dist/leaa-www/server');

module-alias

Create aliases of directories and register custom module paths

MIT
Latest version published 2 years ago

Package Health Score

74 / 100
Full package analysis