refactor: platform exclusion
This commit is contained in:
parent
5e802f9a0d
commit
7ccda9fb3c
4
TODO.md
4
TODO.md
|
@ -10,8 +10,7 @@
|
|||
- [x] flecks aliasing must ensure webpack aliasing and de-externalization into bundles
|
||||
- [x] `flecks.invokeMiddleware()` should not build every invocation
|
||||
- [x] `flecks.invokeComposed()` and `flecks.invokeMiddleware()` should not fatal on a missed lookup
|
||||
- [x] flecks should have a `platforms` setting, so auto-lookups of `/client`, `/server` are less
|
||||
magical
|
||||
- [x] flecks should have a `platforms` setting, so auto-lookups of `/client`, `/server` are less magical
|
||||
- [x] `flecks.expandedFlecks()` should use `platforms`
|
||||
- [ ] config validation
|
||||
- [ ] hints for hook types
|
||||
|
@ -24,3 +23,4 @@
|
|||
- [x] Specialize `invokeReduce()` with `invokeMerge()`.
|
||||
- [x] Rename all hooks to dot-first notation; rewrite `lookupFlecks()`.
|
||||
- [ ] ensureUniqueReduction moved into invokeMerge
|
||||
- [x] `bootstrap({without: ['badplatform']})` should be handled by passing `{platforms: ['!badplatform']}`
|
|
@ -68,7 +68,6 @@ export default class ServerFlecks extends Flecks {
|
|||
config,
|
||||
platforms = ['server'],
|
||||
root = FLECKS_CORE_ROOT,
|
||||
without = [],
|
||||
} = {},
|
||||
) {
|
||||
// Load or use parameterized configuration.
|
||||
|
@ -85,6 +84,10 @@ export default class ServerFlecks extends Flecks {
|
|||
const resolvedRoot = resolve(FLECKS_CORE_ROOT, root);
|
||||
const resolver = {};
|
||||
const keys = Object.keys(config);
|
||||
// `!platform` excludes that platform.
|
||||
const without = platforms
|
||||
.filter((platform) => '!'.charCodeAt(0) === platform.charCodeAt(0))
|
||||
.map((platform) => platform.slice(1));
|
||||
for (let i = 0; i < keys.length; ++i) {
|
||||
const key = keys[i];
|
||||
// Parse the alias (if any).
|
||||
|
|
20
packages/core/test/platforms/server/bootstrap.js
vendored
20
packages/core/test/platforms/server/bootstrap.js
vendored
|
@ -1,6 +1,6 @@
|
|||
import {expect} from 'chai';
|
||||
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
// eslint-disable-next-line import/no-unresolved, import/no-extraneous-dependencies
|
||||
import {Flecks} from '@flecks/core/server';
|
||||
|
||||
it('bootstraps FLECKS_CORE_ROOT by default', () => {
|
||||
|
@ -14,27 +14,37 @@ it('bootstraps server platform by default', () => {
|
|||
});
|
||||
|
||||
it('can bootstrap from a foreign root', () => {
|
||||
const flecks = Flecks.bootstrap({root: './test'});
|
||||
const flecks = Flecks.bootstrap({
|
||||
root: './test',
|
||||
});
|
||||
expect(flecks.fleck('@flecks/core/one')).to.not.equal(undefined);
|
||||
expect(flecks.fleck('@flecks/core/two')).to.not.equal(undefined);
|
||||
});
|
||||
|
||||
it('can bootstrap other platforms', () => {
|
||||
const flecks = Flecks.bootstrap({platforms: ['client'], root: './test'});
|
||||
const flecks = Flecks.bootstrap({
|
||||
platforms: ['client'],
|
||||
root: './test',
|
||||
});
|
||||
expect(flecks.fleck('@flecks/core/one')).to.not.equal(undefined);
|
||||
expect(flecks.fleck('@flecks/core/one/client')).to.not.equal(undefined);
|
||||
expect(flecks.fleck('@flecks/core/one/server')).to.not.equal(undefined);
|
||||
});
|
||||
|
||||
it('can exclude platforms', () => {
|
||||
const flecks = Flecks.bootstrap({platforms: ['client'], root: './test', without: ['server']});
|
||||
const flecks = Flecks.bootstrap({
|
||||
platforms: ['client', '!server'],
|
||||
root: './test',
|
||||
});
|
||||
expect(flecks.fleck('@flecks/core/one')).to.not.equal(undefined);
|
||||
expect(flecks.fleck('@flecks/core/one/client')).to.not.equal(undefined);
|
||||
expect(flecks.fleck('@flecks/core/one/server')).to.equal(undefined);
|
||||
});
|
||||
|
||||
it('provides webpack goodies in nodespace', () => {
|
||||
const flecks = Flecks.bootstrap({root: './test'});
|
||||
const flecks = Flecks.bootstrap({
|
||||
root: './test',
|
||||
});
|
||||
flecks.fleck('@flecks/core/one').testNodespace().forEach((result) => {
|
||||
expect(result).to.not.equal('undefined');
|
||||
});
|
||||
|
|
|
@ -12,7 +12,9 @@ const debug = D('@flecks/http/runtime');
|
|||
|
||||
module.exports = async (flecks) => {
|
||||
debug('bootstrapping flecks...');
|
||||
const httpFlecks = Flecks.bootstrap({platforms: ['client'], without: ['server']});
|
||||
const httpFlecks = Flecks.bootstrap({
|
||||
platforms: ['client', '!server'],
|
||||
});
|
||||
debug('bootstrapped');
|
||||
const runtime = await realpath(R.resolve(join(flecks.resolve('@flecks/http'), 'runtime')));
|
||||
const fullresolve = (fleck, path) => realpath(R.resolve(join(flecks.resolve(fleck), path)));
|
||||
|
|
|
@ -84,8 +84,7 @@ export default {
|
|||
debug('bootstrapping flecks...');
|
||||
const httpFlecks = Flecks.bootstrap({
|
||||
config: flecks.config,
|
||||
platforms: ['client'],
|
||||
without: ['server'],
|
||||
platforms: ['client', '!server'],
|
||||
});
|
||||
debug('bootstrapped');
|
||||
flecks.set('$flecks/http.flecks', httpFlecks);
|
||||
|
|
Loading…
Reference in New Issue
Block a user