fix: use NODE_PATH for resolution
This commit is contained in:
parent
61f258e414
commit
7b0f9f87fe
|
@ -53,7 +53,9 @@ module.exports = async function explicate(
|
|||
resolver.addAlias(join(submodules, 'webpack'), join(resolver.root, 'node_modules', 'webpack'));
|
||||
// Runtime NODE_PATH hacking.
|
||||
const {env} = process;
|
||||
env.NODE_PATH = (env.NODE_PATH || '') + delimiter + submodules;
|
||||
const nodePaths = env.NODE_PATH ? env.NODE_PATH.split(delimiter) : [];
|
||||
nodePaths.push(submodules);
|
||||
env.NODE_PATH = nodePaths.join(delimiter);
|
||||
// eslint-disable-next-line no-underscore-dangle
|
||||
Module._initPaths();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const {join} = require('path');
|
||||
const {delimiter, join} = require('path');
|
||||
|
||||
const D = require('@flecks/core/build/debug');
|
||||
const {CachedInputFileSystem, ResolverFactory} = require('enhanced-resolve');
|
||||
|
@ -28,6 +28,14 @@ module.exports = class Resolver {
|
|||
root = FLECKS_CORE_ROOT,
|
||||
...rest
|
||||
} = options;
|
||||
const {NODE_PATH} = process.env;
|
||||
if (NODE_PATH) {
|
||||
NODE_PATH.split(delimiter).forEach((path) => {
|
||||
if (!modules.includes(path)) {
|
||||
modules.push(path);
|
||||
}
|
||||
});
|
||||
}
|
||||
this.resolver = ResolverFactory.createResolver({
|
||||
conditionNames: ['node'],
|
||||
extensions: ['.js', '.json', '.node'],
|
||||
|
|
18
packages/build/test/server/resolver-node-path.js
Normal file
18
packages/build/test/server/resolver-node-path.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
import {writeFile} from 'fs/promises';
|
||||
import {join} from 'path';
|
||||
|
||||
import {createWorkspace} from '@flecks/core/build/testing';
|
||||
import {expect} from 'chai';
|
||||
|
||||
import Resolver from '@flecks/build/build/resolver';
|
||||
|
||||
it('uses NODE_PATH when resolving', async () => {
|
||||
const workspace = await createWorkspace();
|
||||
await writeFile(join(workspace, 'nothing'), '');
|
||||
const {NODE_PATH} = process.env;
|
||||
process.env.NODE_PATH = workspace;
|
||||
const resolver = new Resolver();
|
||||
expect(await resolver.resolve('nothing'))
|
||||
.to.not.be.undefined;
|
||||
process.env.NODE_PATH = NODE_PATH;
|
||||
});
|
|
@ -22,14 +22,15 @@ export async function buildChild(path, {args = [], opts = {}} = {}) {
|
|||
return spawnWith(
|
||||
[await binaryPath('flecks', '@flecks/build'), 'build', ...args],
|
||||
{
|
||||
stdio: 'ignore',
|
||||
...opts,
|
||||
env: {
|
||||
FLECKS_ENV__flecks_server__stats: '{"preset": "none"}',
|
||||
FLECKS_ENV__flecks_server__start: 0,
|
||||
FLECKS_CORE_ROOT: path,
|
||||
NODE_PATH: join(FLECKS_CORE_ROOT, '..', '..', 'node_modules'),
|
||||
...opts.env,
|
||||
},
|
||||
stdio: 'ignore',
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -46,6 +47,7 @@ export async function serverActions(path, actions) {
|
|||
{
|
||||
env: {
|
||||
FLECKS_SERVER_TEST_SOCKET: socketPath,
|
||||
NODE_PATH: join(FLECKS_CORE_ROOT, '..', '..', 'node_modules'),
|
||||
},
|
||||
stdio: 'ignore',
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue
Block a user