mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-13 12:38:39 -09:00
handle undefined values in cli/api getPlugins
This commit is contained in:
parent
41d70c3a15
commit
86f70f1610
3 changed files with 28 additions and 16 deletions
25
cli/api.ts
25
cli/api.ts
|
|
@ -54,32 +54,27 @@ const getFileContents = memoize(() => {
|
|||
|
||||
const getParsedFile = memoize(() => recast.parse(getFileContents()!));
|
||||
|
||||
const getProperties = memoize(() => (getParsedFile().program.body as any[]).map(obj => obj));
|
||||
const getProperties = memoize(() => ((getParsedFile()?.program?.body as any[]) || []).map(obj => obj));
|
||||
|
||||
const getPlugins = memoize(() => {
|
||||
const getPluginsByKey = (key: string) => {
|
||||
const properties = getProperties();
|
||||
for (let i = 0; i < properties.length; i++) {
|
||||
const rightProperties = Object.values<any>(properties[i].expression.right.properties);
|
||||
const rightProperties = Object.values<any>(properties[i]?.expression?.right?.properties || {});
|
||||
for (let j = 0; j < rightProperties.length; j++) {
|
||||
const plugin = rightProperties[j];
|
||||
if (plugin.key.name === 'plugins') {
|
||||
return plugin.value.elements as any[];
|
||||
if (plugin?.key?.name === key) {
|
||||
return (plugin?.value?.elements as any[]) || [];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const getPlugins = memoize(() => {
|
||||
return getPluginsByKey('plugins');
|
||||
});
|
||||
|
||||
const getLocalPlugins = memoize(() => {
|
||||
const properties = getProperties();
|
||||
for (let i = 0; i < properties.length; i++) {
|
||||
const rightProperties = Object.values<any>(properties[i].expression.right.properties);
|
||||
for (let j = 0; j < rightProperties.length; j++) {
|
||||
const plugin = rightProperties[j];
|
||||
if (plugin.key.name === 'localPlugins') {
|
||||
return plugin.value.elements as any[];
|
||||
}
|
||||
}
|
||||
}
|
||||
return getPluginsByKey('localPlugins');
|
||||
});
|
||||
|
||||
function exists() {
|
||||
|
|
|
|||
|
|
@ -143,7 +143,8 @@
|
|||
],
|
||||
"@babel/plugin-proposal-numeric-separator",
|
||||
"@babel/proposal-class-properties",
|
||||
"@babel/proposal-object-rest-spread"
|
||||
"@babel/proposal-object-rest-spread",
|
||||
"@babel/plugin-proposal-optional-chaining"
|
||||
],
|
||||
"env": {
|
||||
"production": {
|
||||
|
|
@ -292,6 +293,7 @@
|
|||
"@babel/plugin-proposal-class-properties": "^7.7.4",
|
||||
"@babel/plugin-proposal-numeric-separator": "^7.7.4",
|
||||
"@babel/plugin-proposal-object-rest-spread": "^7.7.4",
|
||||
"@babel/plugin-proposal-optional-chaining": "7.7.5",
|
||||
"@babel/preset-react": "7.7.4",
|
||||
"@babel/preset-typescript": "7.7.4",
|
||||
"@types/args": "3.0.0",
|
||||
|
|
|
|||
15
yarn.lock
15
yarn.lock
|
|
@ -323,6 +323,14 @@
|
|||
"@babel/helper-plugin-utils" "^7.0.0"
|
||||
"@babel/plugin-syntax-optional-catch-binding" "^7.2.0"
|
||||
|
||||
"@babel/plugin-proposal-optional-chaining@7.7.5":
|
||||
version "7.7.5"
|
||||
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.7.5.tgz#f0835f044cef85b31071a924010a2a390add11d4"
|
||||
integrity sha512-sOwFqT8JSchtJeDD+CjmWCaiFoLxY4Ps7NjvwHC/U7l4e9i5pTRNt8nDMIFSOUL+ncFbYSwruHM8WknYItWdXw==
|
||||
dependencies:
|
||||
"@babel/helper-plugin-utils" "^7.0.0"
|
||||
"@babel/plugin-syntax-optional-chaining" "^7.7.4"
|
||||
|
||||
"@babel/plugin-syntax-async-generators@^7.2.0":
|
||||
version "7.2.0"
|
||||
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-async-generators/-/plugin-syntax-async-generators-7.2.0.tgz#69e1f0db34c6f5a0cf7e2b3323bf159a76c8cb7f"
|
||||
|
|
@ -365,6 +373,13 @@
|
|||
dependencies:
|
||||
"@babel/helper-plugin-utils" "^7.0.0"
|
||||
|
||||
"@babel/plugin-syntax-optional-chaining@^7.7.4":
|
||||
version "7.7.4"
|
||||
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-optional-chaining/-/plugin-syntax-optional-chaining-7.7.4.tgz#c91fdde6de85d2eb8906daea7b21944c3610c901"
|
||||
integrity sha512-2MqYD5WjZSbJdUagnJvIdSfkb/ucOC9/1fRJxm7GAxY6YQLWlUvkfxoNbUPcPLHJyetKUDQ4+yyuUyAoc0HriA==
|
||||
dependencies:
|
||||
"@babel/helper-plugin-utils" "^7.0.0"
|
||||
|
||||
"@babel/plugin-syntax-typescript@^7.7.4":
|
||||
version "7.7.4"
|
||||
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.7.4.tgz#5d037ffa10f3b25a16f32570ebbe7a8c2efa304b"
|
||||
|
|
|
|||
Loading…
Reference in a new issue