@untool/core
Advanced tools
Comparing version 0.24.0 to 0.25.0
@@ -6,2 +6,15 @@ # Change Log | ||
<a name="0.25.0"></a> | ||
# [0.25.0](https://github.com/untool/untool/compare/v0.24.1...v0.25.0) (2018-09-28) | ||
### Features | ||
* **core:** add internal exports ([061c541](https://github.com/untool/untool/commit/061c541)) | ||
* **core:** make mixin types configurable ([c1df54a](https://github.com/untool/untool/commit/c1df54a)) | ||
<a name="0.24.0"></a> | ||
@@ -8,0 +21,0 @@ # [0.24.0](https://github.com/untool/untool/compare/v0.23.0...v0.24.0) (2018-09-26) |
@@ -29,1 +29,8 @@ 'use strict'; | ||
}; | ||
exports.internal = { | ||
getConfig(...args) { | ||
return environmentalize(getConfig(...args)); | ||
}, | ||
environmentalize, | ||
}; |
@@ -20,2 +20,7 @@ 'use strict'; | ||
const defaultNamespace = process.env.UNTOOL_NSP || 'untool'; | ||
const defaultMixinTypes = { | ||
core: ['core'], | ||
browser: ['browser', 'runtime'], | ||
server: ['server', 'runtime'], | ||
}; | ||
@@ -37,56 +42,35 @@ const merge = (...args) => | ||
const resolveCoreMixin = createResolver({ | ||
mainFiles: ['mixin.core', 'mixin'], | ||
mainFields: ['mixin:core', 'mixin'], | ||
}); | ||
const resolveServerMixin = createResolver({ | ||
mainFiles: ['mixin.server', 'mixin.runtime', 'mixin'], | ||
mainFields: ['mixin:server', 'mixin:runtime', 'mixin'], | ||
}); | ||
const resolveBrowserMixin = createResolver({ | ||
mainFiles: ['mixin.browser', 'mixin.runtime', 'mixin'], | ||
mainFields: ['mixin:browser', 'mixin:runtime', 'mixin'], | ||
}); | ||
const isResolveError = (error) => | ||
error && error.message && error.message.startsWith("Can't resolve"); | ||
const resolveMixin = (context, mixin, target) => { | ||
const resolveMixin = (types, ...args) => { | ||
try { | ||
switch (target) { | ||
case 'core': | ||
return resolveCoreMixin(context, mixin); | ||
case 'server': | ||
return resolveServerMixin(context, mixin); | ||
case 'browser': | ||
return resolveBrowserMixin(context, mixin); | ||
} | ||
} catch (_) { | ||
return; | ||
return createResolver({ | ||
mainFiles: [...types.map((type) => `mixin.${type}`), 'mixin'], | ||
mainFields: [...types.map((type) => `mixin:${type}`), 'mixin'], | ||
})(...args); | ||
} catch (error) { | ||
return null; | ||
} | ||
}; | ||
const resolveMixins = (context, mixins) => | ||
mixins.reduce( | ||
(result, mixin) => { | ||
let found = false; | ||
Object.keys(result).forEach((target) => { | ||
const targetMixin = resolveMixin(context, mixin, target); | ||
if (targetMixin) { | ||
if (!result[target].includes(targetMixin)) { | ||
result[target].push(targetMixin); | ||
} | ||
found = true; | ||
const resolveMixins = (context, mixins, types) => | ||
mixins.reduce((result, mixin) => { | ||
let found = false; | ||
Object.keys(types).forEach((type) => { | ||
const typeMixin = resolveMixin(types[type], context, mixin); | ||
if (typeMixin) { | ||
result[type] = result[type] || []; | ||
if (!result[type].includes(typeMixin)) { | ||
result[type].push(typeMixin); | ||
} | ||
}); | ||
if (!found) { | ||
throw new Error(`Can't find mixin '${mixin}'`); | ||
found = true; | ||
} | ||
return result; | ||
}, | ||
{ core: [], server: [], browser: [] } | ||
); | ||
}); | ||
if (!found) { | ||
throw new Error(`Can't find mixin '${mixin}'`); | ||
} | ||
return result; | ||
}, {}); | ||
const isResolveError = (error) => | ||
error && error.message && error.message.startsWith("Can't resolve"); | ||
const placeholdify = (config) => { | ||
@@ -116,3 +100,7 @@ const flatConfig = flatten(config); | ||
exports.getConfig = ({ configNamespace = defaultNamespace, ...overrides }) => { | ||
exports.getConfig = ({ | ||
untoolNamespace: namespace = defaultNamespace, | ||
untoolMixinTypes: mixinTypes = defaultMixinTypes, | ||
...overrides | ||
}) => { | ||
const pkgFile = findUp('package.json'); | ||
@@ -133,3 +121,3 @@ const pkgData = require(pkgFile); | ||
const loadConfig = (context, config) => { | ||
const { loadSync, searchSync } = cosmiconfig(configNamespace, { | ||
const { loadSync, searchSync } = cosmiconfig(namespace, { | ||
stopDir: context, | ||
@@ -205,3 +193,3 @@ }); | ||
...placeholdify(rawConfig), | ||
mixins: resolveMixins(rootDir, rawConfig.mixins), | ||
mixins: resolveMixins(rootDir, rawConfig.mixins, mixinTypes), | ||
}; | ||
@@ -208,0 +196,0 @@ debug(config); |
{ | ||
"name": "@untool/core", | ||
"version": "0.24.0", | ||
"version": "0.25.0", | ||
"description": "untool core", | ||
"jsnext": "lib/runtime.js", | ||
"scripts": { | ||
@@ -38,3 +37,3 @@ "test": "echo \"Error: no test specified\"" | ||
}, | ||
"gitHead": "8dbacec7c4782ee828b24832da7985924eda532f" | ||
"gitHead": "c96f56ed744d48bbcea539b453433206c9e1106f" | ||
} |
@@ -172,3 +172,3 @@ # `@untool/core` | ||
This function, that you are expected to call in your applications main entry file, is essentialy a shorthand: it creates and bootstraps a core mixin container and calls its `render` method. | ||
This function only exists if [`@untool/webpack`](https://github.com/untool/untool/blob/master/packages/webpack/README.md) is installed and active. You are expected to call it in your applications main entry file and it is essentialy a shorthand: it creates and bootstraps a core mixin container and calls its `render` method. | ||
@@ -189,3 +189,3 @@ Whatever arguments it receives are being passed along to its container's mixins' constructors. For it to work, you need to register at least one mixin implementing the `render` method. The default render mixin is [`@untool/react`](https://github.com/untool/untool/blob/master/packages/react/README.md). | ||
### `bootstrap([configOverrides], [options])` (build only) | ||
### `bootstrap([configOverrides], [options])` | ||
@@ -192,0 +192,0 @@ This is a semi-private function that is mainly being used internally, for example by [`@untool/yargs`](https://github.com/untool/untool/blob/master/packages/yargs/README.md). It returns the core mixin container - this allows you to call all defined mixin methods. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24685
7
226