mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
refactor(@jsdoc/core): replace yaioc with bottlejs
`bottlejs` does what we need and is much more widely used. Also, `bottlejs` doesn't do all the magic name extraction that `yaioc` does. That means less logic to reproduce in this facade if we change the underlying dependency later.
This commit is contained in:
parent
f611611b53
commit
ba74ec1d4f
@ -1,4 +1,4 @@
|
||||
const yaioc = require('yaioc');
|
||||
const Bottle = require('bottlejs');
|
||||
|
||||
/**
|
||||
* Container for JSDoc classes, objects, and values that can be injected into other modules.
|
||||
@ -7,12 +7,13 @@ const yaioc = require('yaioc');
|
||||
*/
|
||||
class Dependencies {
|
||||
constructor() {
|
||||
// This class provides a lightweight facade for the `yaioc` package.
|
||||
this._container = yaioc.container();
|
||||
// This class provides a lightweight facade for the `bottlejs` package.
|
||||
this._bottle = new Bottle();
|
||||
this._container = this._bottle.container;
|
||||
}
|
||||
|
||||
get(name) {
|
||||
const dep = this._container.get(name);
|
||||
const dep = this._container[name];
|
||||
|
||||
if (dep === undefined) {
|
||||
throw new Error(`No dependency registered for the name "${name}"`);
|
||||
@ -21,16 +22,12 @@ class Dependencies {
|
||||
return dep;
|
||||
}
|
||||
|
||||
registerClass(klass, opts = {}) {
|
||||
if (opts.singleton) {
|
||||
this._container.cache().register(klass);
|
||||
} else {
|
||||
this._container.register(klass);
|
||||
}
|
||||
registerClass(name, constructor, ...deps) {
|
||||
this._bottle.service(name, constructor, ...deps);
|
||||
}
|
||||
|
||||
registerValue(name, value) {
|
||||
this._container.register(name, value);
|
||||
this._bottle.constant(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
192
packages/jsdoc-core/package-lock.json
generated
192
packages/jsdoc-core/package-lock.json
generated
@ -9,12 +9,12 @@
|
||||
"version": "0.4.1",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"bottlejs": "^2.0.0",
|
||||
"cosmiconfig": "^7.0.1",
|
||||
"escape-string-regexp": "^4.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"strip-bom": "^4.0.0",
|
||||
"strip-json-comments": "^3.1.1",
|
||||
"yaioc": "^1.10.0"
|
||||
"strip-json-comments": "^3.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=v14.17.6"
|
||||
@ -68,19 +68,10 @@
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/balanced-match": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
||||
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
|
||||
},
|
||||
"node_modules/brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
||||
"dependencies": {
|
||||
"balanced-match": "^1.0.0",
|
||||
"concat-map": "0.0.1"
|
||||
}
|
||||
"node_modules/bottlejs": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/bottlejs/-/bottlejs-2.0.0.tgz",
|
||||
"integrity": "sha512-Qhz5dd1YPTOHw0gZ1a1WpJ/oEWsq09BMMbxczeAPgubISij+ZFfah7wfOlHFeFQpWLQkS9TGz5C54tV6v0BlFA=="
|
||||
},
|
||||
"node_modules/callsites": {
|
||||
"version": "3.1.0",
|
||||
@ -124,11 +115,6 @@
|
||||
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
|
||||
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
|
||||
},
|
||||
"node_modules/concat-map": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
|
||||
},
|
||||
"node_modules/cosmiconfig": {
|
||||
"version": "7.0.1",
|
||||
"resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.0.1.tgz",
|
||||
@ -163,30 +149,6 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/fs.realpath": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
||||
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
|
||||
},
|
||||
"node_modules/glob": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz",
|
||||
"integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==",
|
||||
"dependencies": {
|
||||
"fs.realpath": "^1.0.0",
|
||||
"inflight": "^1.0.4",
|
||||
"inherits": "2",
|
||||
"minimatch": "^3.0.4",
|
||||
"once": "^1.3.0",
|
||||
"path-is-absolute": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "*"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"node_modules/has-flag": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
|
||||
@ -210,20 +172,6 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/inflight": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
||||
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
|
||||
"dependencies": {
|
||||
"once": "^1.3.0",
|
||||
"wrappy": "1"
|
||||
}
|
||||
},
|
||||
"node_modules/inherits": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
||||
},
|
||||
"node_modules/is-arrayish": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz",
|
||||
@ -249,25 +197,6 @@
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
||||
},
|
||||
"node_modules/minimatch": {
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
||||
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
|
||||
"dependencies": {
|
||||
"brace-expansion": "^1.1.7"
|
||||
},
|
||||
"engines": {
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/once": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
||||
"dependencies": {
|
||||
"wrappy": "1"
|
||||
}
|
||||
},
|
||||
"node_modules/parent-module": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz",
|
||||
@ -296,14 +225,6 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/path-is-absolute": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
|
||||
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/path-type": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz",
|
||||
@ -350,19 +271,6 @@
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/wrappy": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
|
||||
},
|
||||
"node_modules/yaioc": {
|
||||
"version": "1.10.0",
|
||||
"resolved": "https://registry.npmjs.org/yaioc/-/yaioc-1.10.0.tgz",
|
||||
"integrity": "sha512-IyMkzCVmHX9Iw9ogVS3MRAMbPtYJmzG6/lQbILYmveDFBqtPakzUiKZnsv2DSHJqO0rR437LaDzaBrsM4L+7+w==",
|
||||
"dependencies": {
|
||||
"glob": "^7.1.2"
|
||||
}
|
||||
},
|
||||
"node_modules/yaml": {
|
||||
"version": "1.10.2",
|
||||
"resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz",
|
||||
@ -409,19 +317,10 @@
|
||||
"color-convert": "^1.9.0"
|
||||
}
|
||||
},
|
||||
"balanced-match": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
||||
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
|
||||
},
|
||||
"brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
||||
"requires": {
|
||||
"balanced-match": "^1.0.0",
|
||||
"concat-map": "0.0.1"
|
||||
}
|
||||
"bottlejs": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/bottlejs/-/bottlejs-2.0.0.tgz",
|
||||
"integrity": "sha512-Qhz5dd1YPTOHw0gZ1a1WpJ/oEWsq09BMMbxczeAPgubISij+ZFfah7wfOlHFeFQpWLQkS9TGz5C54tV6v0BlFA=="
|
||||
},
|
||||
"callsites": {
|
||||
"version": "3.1.0",
|
||||
@ -458,11 +357,6 @@
|
||||
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
|
||||
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
|
||||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
|
||||
},
|
||||
"cosmiconfig": {
|
||||
"version": "7.0.1",
|
||||
"resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.0.1.tgz",
|
||||
@ -488,24 +382,6 @@
|
||||
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz",
|
||||
"integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA=="
|
||||
},
|
||||
"fs.realpath": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
||||
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
|
||||
},
|
||||
"glob": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz",
|
||||
"integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==",
|
||||
"requires": {
|
||||
"fs.realpath": "^1.0.0",
|
||||
"inflight": "^1.0.4",
|
||||
"inherits": "2",
|
||||
"minimatch": "^3.0.4",
|
||||
"once": "^1.3.0",
|
||||
"path-is-absolute": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"has-flag": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
|
||||
@ -520,20 +396,6 @@
|
||||
"resolve-from": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"inflight": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
||||
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
|
||||
"requires": {
|
||||
"once": "^1.3.0",
|
||||
"wrappy": "1"
|
||||
}
|
||||
},
|
||||
"inherits": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
||||
},
|
||||
"is-arrayish": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz",
|
||||
@ -559,22 +421,6 @@
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
||||
},
|
||||
"minimatch": {
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
||||
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
|
||||
"requires": {
|
||||
"brace-expansion": "^1.1.7"
|
||||
}
|
||||
},
|
||||
"once": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
||||
"requires": {
|
||||
"wrappy": "1"
|
||||
}
|
||||
},
|
||||
"parent-module": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz",
|
||||
@ -594,11 +440,6 @@
|
||||
"lines-and-columns": "^1.1.6"
|
||||
}
|
||||
},
|
||||
"path-is-absolute": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
|
||||
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
|
||||
},
|
||||
"path-type": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz",
|
||||
@ -627,19 +468,6 @@
|
||||
"has-flag": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"wrappy": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
|
||||
},
|
||||
"yaioc": {
|
||||
"version": "1.10.0",
|
||||
"resolved": "https://registry.npmjs.org/yaioc/-/yaioc-1.10.0.tgz",
|
||||
"integrity": "sha512-IyMkzCVmHX9Iw9ogVS3MRAMbPtYJmzG6/lQbILYmveDFBqtPakzUiKZnsv2DSHJqO0rR437LaDzaBrsM4L+7+w==",
|
||||
"requires": {
|
||||
"glob": "^7.1.2"
|
||||
}
|
||||
},
|
||||
"yaml": {
|
||||
"version": "1.10.2",
|
||||
"resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz",
|
||||
|
||||
@ -22,12 +22,12 @@
|
||||
"url": "https://github.com/jsdoc/jsdoc/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"bottlejs": "^2.0.0",
|
||||
"cosmiconfig": "^7.0.1",
|
||||
"escape-string-regexp": "^4.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"strip-bom": "^4.0.0",
|
||||
"strip-json-comments": "^3.1.1",
|
||||
"yaioc": "^1.10.0"
|
||||
"strip-json-comments": "^3.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=v14.17.6"
|
||||
|
||||
@ -25,8 +25,8 @@ describe('@jsdoc/core/lib/dependencies', () => {
|
||||
|
||||
let instance;
|
||||
|
||||
container.registerClass(Foo);
|
||||
instance = container.get('foo');
|
||||
container.registerClass('Foo', Foo);
|
||||
instance = container.get('Foo');
|
||||
|
||||
expect(instance).toBeInstanceOf(Foo);
|
||||
});
|
||||
@ -42,22 +42,22 @@ describe('@jsdoc/core/lib/dependencies', () => {
|
||||
|
||||
let instance;
|
||||
|
||||
container.registerClass(Foo);
|
||||
container.registerClass(Bar);
|
||||
instance = container.get('foo');
|
||||
container.registerClass('Foo', Foo, 'Bar');
|
||||
container.registerClass('Bar', Bar);
|
||||
instance = container.get('Foo');
|
||||
|
||||
expect(instance.bar).toBeInstanceOf(Bar);
|
||||
});
|
||||
|
||||
it('returns the same instance every time for singletons', () => {
|
||||
it('returns the same instance every time', () => {
|
||||
class Foo {}
|
||||
|
||||
let instance1;
|
||||
let instance2;
|
||||
|
||||
container.registerClass(Foo, { singleton: true });
|
||||
instance1 = container.get('foo');
|
||||
instance2 = container.get('foo');
|
||||
container.registerClass('Foo', Foo);
|
||||
instance1 = container.get('Foo');
|
||||
instance2 = container.get('Foo');
|
||||
|
||||
expect(instance2).toBe(instance1);
|
||||
});
|
||||
@ -72,21 +72,16 @@ describe('@jsdoc/core/lib/dependencies', () => {
|
||||
});
|
||||
|
||||
describe('registerClass', () => {
|
||||
// The tests for `get()` also test the behavior of these methods more extensively.
|
||||
it('accepts a constructor', () => {
|
||||
// The tests for `get()` also test the behavior of this method more extensively.
|
||||
it('accepts a name and constructor', () => {
|
||||
class Foo {}
|
||||
|
||||
expect(() => container.registerClass(Foo)).not.toThrow();
|
||||
});
|
||||
|
||||
it('accepts a `singleton` option', () => {
|
||||
class Foo {}
|
||||
|
||||
expect(() => container.registerClass(Foo, { singleton: true })).not.toThrow();
|
||||
expect(() => container.registerClass('Foo', Foo)).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('registerValue', () => {
|
||||
// The tests for `get()` also test the behavior of this method more extensively.
|
||||
it('accepts a name and value', () => {
|
||||
expect(() => container.registerValue('name', new Set())).not.toThrow();
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user