Skip to content

Commit

Permalink
fix(core): add tmp tao path to node path (nrwl#4810)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored Feb 16, 2021
1 parent 785754e commit 11d27da
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/workspace/src/command-line/nx-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { runMany } from './run-many';
import { writeFileSync } from 'fs';
import { dirSync } from 'tmp';
import * as path from 'path';
import { removeSync } from 'fs-extra';

const noop = (yargs: yargs.Argv): yargs.Argv => yargs;

Expand Down Expand Up @@ -189,6 +190,8 @@ export const commandsObject = yargs
execSync(`${p} migrate ${process.argv.slice(3).join(' ')}`, {
stdio: ['inherit', 'inherit', 'inherit'],
});
// Clean up
removeSync(path.resolve(p, '../../..'));
} else {
const pmc = getPackageManagerCommand();
execSync(`${pmc.exec} tao migrate ${process.argv.slice(3).join(' ')}`, {
Expand Down Expand Up @@ -446,5 +449,24 @@ function taoPath() {
stdio: ['ignore', 'ignore', 'ignore'],
});

// Set NODE_PATH so that these modules can be used for module resolution
addToNodePath(path.join(tmpDir, 'node_modules'));

return path.join(tmpDir, `node_modules`, '.bin', 'tao');
}

function addToNodePath(dir: string) {
// NODE_PATH is a delimited list of paths.
// The delimiter is different for windows.
const delimiter = require('os').platform === 'win32' ? ';' : ':';

const paths = process.env.NODE_PATH
? process.env.NODE_PATH.split(delimiter)
: [];

// Add the tmp path
paths.push(dir);

// Update the env variable.
process.env.NODE_PATH = paths.join(delimiter);
}

0 comments on commit 11d27da

Please sign in to comment.