Skip to content

Commit 5897c0f

Browse files
author
Ives van Hoorne
committed
Fix css dependencies
1 parent 0111eff commit 5897c0f

File tree

3 files changed

+26
-30
lines changed

3 files changed

+26
-30
lines changed

src/sandbox/eval/js/babel-parser.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import decoratorsPlugin from 'babel-plugin-transform-decorators-legacy';
88

99
import evalModule from '../';
1010
import resolveDependency from './dependency-resolver';
11-
import DependencyNotFoundError from '../../errors/dependency-not-found-error';
1211

1312
const CUSTOM_BABEL_CONFIG_ENABLED = false;
1413

@@ -24,11 +23,11 @@ const DEFAULT_BABEL_CONFIG = {
2423
};
2524

2625
const resolvePlugin = (plugin: string, externals) => {
27-
const resolvedPlugin =
28-
resolveDependency(plugin, externals) ||
29-
resolveDependency(`babel-plugin-${plugin}`, externals);
30-
31-
if (!resolvedPlugin) throw new DependencyNotFoundError(plugin);
26+
try {
27+
return resolveDependency(plugin, externals)
28+
} catch (e) {
29+
return resolveDependency(`babel-plugin-${plugin}`, externals);
30+
}
3231
};
3332

3433
/**

src/sandbox/eval/js/dependency-resolver.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import DependencyNotFoundError from '../../errors/dependency-not-found-error';
2+
13
/**
24
* Converts a dependency string to an actual dependency, this can return null
35
* if the dependency is not found.
@@ -24,6 +26,5 @@ export default function getDependency(
2426
}
2527
}
2628
}
27-
28-
return null;
29+
throw new DependencyNotFoundError(dependencyPath);
2930
}

src/sandbox/eval/js/index.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type { Module, Directory } from 'common/types';
55

66
import evalModule from '../';
77
import resolveModule from '../../utils/resolve-module';
8-
import DependencyNotFoundError from '../../errors/dependency-not-found-error';
98
import resolveDependency from './dependency-resolver';
109
import getBabelConfig from './babel-parser';
1110

@@ -59,31 +58,28 @@ export default function evaluateJS(
5958
// eslint-disable-line no-unused-vars
6059
if (/^(\w|@)/.test(path)) {
6160
// So it must be a dependency
62-
const dependency = resolveDependency(path, externals);
63-
if (dependency) return dependency;
61+
return resolveDependency(path, externals);
62+
}
6463

65-
throw new DependencyNotFoundError(path);
66-
} else {
67-
const module = resolveModule(
68-
path,
69-
modules,
70-
directories,
71-
mainModule.directoryShortid,
72-
);
73-
if (mainModule === module) {
74-
throw new Error(`${mainModule.title} is importing itself`);
75-
}
64+
const module = resolveModule(
65+
path,
66+
modules,
67+
directories,
68+
mainModule.directoryShortid,
69+
);
70+
if (mainModule === module) {
71+
throw new Error(`${mainModule.title} is importing itself`);
72+
}
7673

77-
if (!module) throw new Error(`Cannot find module in path: ${path}`);
74+
if (!module) throw new Error(`Cannot find module in path: ${path}`);
7875

79-
requires.push(module.id);
80-
// Check if this module has been evaluated before, if so return that
81-
const cache = moduleCache.get(module.id);
76+
requires.push(module.id);
77+
// Check if this module has been evaluated before, if so return that
78+
const cache = moduleCache.get(module.id);
8279

83-
return cache
84-
? cache.exports
85-
: evalModule(module, modules, directories, externals, depth + 1);
86-
}
80+
return cache
81+
? cache.exports
82+
: evalModule(module, modules, directories, externals, depth + 1);
8783
};
8884

8985
const babelConfig = getBabelConfig(

0 commit comments

Comments
 (0)