fix: resolution
This commit is contained in:
parent
ef693496ea
commit
2a67740911
|
@ -1,5 +1,5 @@
|
||||||
const {realpath} = require('fs/promises');
|
const {realpath} = require('fs/promises');
|
||||||
const {dirname, join} = require('path');
|
const {dirname, join, relative} = require('path');
|
||||||
|
|
||||||
const D = require('@flecks/core/build/debug');
|
const D = require('@flecks/core/build/debug');
|
||||||
const {Flecks} = require('@flecks/core/build/flecks');
|
const {Flecks} = require('@flecks/core/build/flecks');
|
||||||
|
@ -279,7 +279,7 @@ module.exports = class Build extends Flecks {
|
||||||
return this.resolver.resolve(join(fleck, 'build', config));
|
return this.resolver.resolve(join(fleck, 'build', config));
|
||||||
}
|
}
|
||||||
|
|
||||||
async runtimeCompiler(runtime, config, {allowlist = []} = {}) {
|
async runtimeCompiler(runtime, config, {additionalModuleDirs = [], allowlist = []} = {}) {
|
||||||
// Compile?
|
// Compile?
|
||||||
const needCompilation = Object.entries(this.compiled);
|
const needCompilation = Object.entries(this.compiled);
|
||||||
if (needCompilation.length > 0) {
|
if (needCompilation.length > 0) {
|
||||||
|
@ -300,13 +300,10 @@ module.exports = class Build extends Flecks {
|
||||||
// Alias.
|
// Alias.
|
||||||
config.resolve.alias[path] = source || path;
|
config.resolve.alias[path] = source || path;
|
||||||
// Root aliases.
|
// Root aliases.
|
||||||
if (root) {
|
config.resolve.fallback[path] = root;
|
||||||
config.resolve.alias[
|
config.resolve.modules.push(relative(FLECKS_CORE_ROOT, join(root, 'node_modules')));
|
||||||
join(root, 'node_modules')
|
additionalModuleDirs.push(relative(FLECKS_CORE_ROOT, join(root, 'node_modules')));
|
||||||
] = join(FLECKS_CORE_ROOT, 'node_modules');
|
includes.push(root);
|
||||||
config.resolve.fallback[path] = root;
|
|
||||||
}
|
|
||||||
includes.push(root || path);
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
// Compile.
|
// Compile.
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
const {join, relative, resolve} = require('path');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
join,
|
FLECKS_CORE_ROOT = process.cwd(),
|
||||||
resolve,
|
} = process.env;
|
||||||
} = require('path');
|
|
||||||
|
|
||||||
module.exports = async function explicate(
|
module.exports = async function explicate(
|
||||||
maybeAliasedPaths,
|
maybeAliasedPaths,
|
||||||
|
@ -83,8 +84,15 @@ module.exports = async function explicate(
|
||||||
if (resolved) {
|
if (resolved) {
|
||||||
await doExplication(descriptor);
|
await doExplication(descriptor);
|
||||||
}
|
}
|
||||||
|
let descriptorRequest = descriptor.request;
|
||||||
|
if (areDescriptorsTheSame) {
|
||||||
|
descriptorRequest = join(descriptorRequest, 'src');
|
||||||
|
}
|
||||||
if (descriptor.path !== descriptor.request) {
|
if (descriptor.path !== descriptor.request) {
|
||||||
resolver.addAlias(descriptor.path, descriptor.request);
|
resolver.addAlias(descriptor.path, descriptorRequest);
|
||||||
|
if (descriptorRequest !== descriptor.request) {
|
||||||
|
resolver.addFallback(descriptor.path, descriptor.request);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
platforms
|
platforms
|
||||||
|
@ -100,10 +108,10 @@ module.exports = async function explicate(
|
||||||
resolver.addAlias(path, request);
|
resolver.addAlias(path, request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (await resolver.resolve(join(descriptor.request, 'src', platform))) {
|
else if (await resolver.resolve(join(descriptorRequest, 'src', platform))) {
|
||||||
const [path, request] = [
|
const [path, request] = [
|
||||||
join(descriptor.path, platform),
|
join(descriptor.path, platform),
|
||||||
join(descriptor.request, 'src', platform),
|
join(descriptorRequest, 'src', platform),
|
||||||
];
|
];
|
||||||
await doExplication({path, request});
|
await doExplication({path, request});
|
||||||
if (path !== request) {
|
if (path !== request) {
|
||||||
|
@ -119,7 +127,10 @@ module.exports = async function explicate(
|
||||||
if (!rootDescriptor || roots[rootDescriptor.request]) {
|
if (!rootDescriptor || roots[rootDescriptor.request]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const {request} = rootDescriptor;
|
const {path, request} = rootDescriptor;
|
||||||
|
if (path !== request) {
|
||||||
|
resolver.addModules(relative(FLECKS_CORE_ROOT, join(request, 'node_modules')));
|
||||||
|
}
|
||||||
roots[request] = true;
|
roots[request] = true;
|
||||||
// Import bootstrap script.
|
// Import bootstrap script.
|
||||||
const bootstrapPath = await resolver.resolve(join(request, 'build', 'flecks.bootstrap'));
|
const bootstrapPath = await resolver.resolve(join(request, 'build', 'flecks.bootstrap'));
|
||||||
|
|
|
@ -4,6 +4,7 @@ const D = require('@flecks/core/build/debug');
|
||||||
const {CachedInputFileSystem, ResolverFactory} = require('enhanced-resolve');
|
const {CachedInputFileSystem, ResolverFactory} = require('enhanced-resolve');
|
||||||
const AppendPlugin = require('enhanced-resolve/lib/AppendPlugin');
|
const AppendPlugin = require('enhanced-resolve/lib/AppendPlugin');
|
||||||
const AliasPlugin = require('enhanced-resolve/lib/AliasPlugin');
|
const AliasPlugin = require('enhanced-resolve/lib/AliasPlugin');
|
||||||
|
const ModulesInHierarchicalDirectoriesPlugin = require('enhanced-resolve/lib/ModulesInHierarchicalDirectoriesPlugin');
|
||||||
const fs = require('graceful-fs');
|
const fs = require('graceful-fs');
|
||||||
|
|
||||||
const debug = D('@flecks/build/build/resolver');
|
const debug = D('@flecks/build/build/resolver');
|
||||||
|
@ -27,10 +28,7 @@ module.exports = class Resolver {
|
||||||
extensions: ['.js', '.json', '.node'],
|
extensions: ['.js', '.json', '.node'],
|
||||||
fileSystem: nodeFileSystem,
|
fileSystem: nodeFileSystem,
|
||||||
symlinks: false,
|
symlinks: false,
|
||||||
...{
|
...options,
|
||||||
modules: [join(FLECKS_CORE_ROOT, 'node_modules')],
|
|
||||||
...options,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +57,15 @@ module.exports = class Resolver {
|
||||||
).apply(this.resolver);
|
).apply(this.resolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addModules(path) {
|
||||||
|
debugSilly("adding modules: '%s'", path);
|
||||||
|
new ModulesInHierarchicalDirectoriesPlugin(
|
||||||
|
"raw-module",
|
||||||
|
path,
|
||||||
|
"module"
|
||||||
|
).apply(this.resolver);
|
||||||
|
}
|
||||||
|
|
||||||
static isResolutionError(error) {
|
static isResolutionError(error) {
|
||||||
return error.message.startsWith("Can't resolve");
|
return error.message.startsWith("Can't resolve");
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ exports.defaultConfig = (flecks, specializedConfig) => {
|
||||||
alias: {},
|
alias: {},
|
||||||
extensions,
|
extensions,
|
||||||
fallback: {},
|
fallback: {},
|
||||||
|
modules: ['node_modules'],
|
||||||
},
|
},
|
||||||
stats: {
|
stats: {
|
||||||
colors: true,
|
colors: true,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user