UNPKG

1.71 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.createItemFromDescriptor = createItemFromDescriptor;
7exports.createConfigItem = createConfigItem;
8exports.getItemDescriptor = getItemDescriptor;
9
10var _configDescriptors = require("./config-descriptors");
11
12const path = require("path");
13
14function createItemFromDescriptor(desc) {
15 return new ConfigItem(desc);
16}
17
18function* createConfigItem(value, {
19 dirname = ".",
20 type
21} = {}) {
22 const descriptor = yield* (0, _configDescriptors.createDescriptor)(value, path.resolve(dirname), {
23 type,
24 alias: "programmatic item"
25 });
26 return createItemFromDescriptor(descriptor);
27}
28
29function getItemDescriptor(item) {
30 if (item != null && item[CONFIG_ITEM_BRAND]) {
31 return item._descriptor;
32 }
33
34 return undefined;
35}
36
37const CONFIG_ITEM_BRAND = Symbol.for("@babel/core@7 - ConfigItem");
38
39class ConfigItem {
40 constructor(descriptor) {
41 this._descriptor = void 0;
42 this[CONFIG_ITEM_BRAND] = true;
43 this.value = void 0;
44 this.options = void 0;
45 this.dirname = void 0;
46 this.name = void 0;
47 this.file = void 0;
48 this._descriptor = descriptor;
49 Object.defineProperty(this, "_descriptor", {
50 enumerable: false
51 });
52 Object.defineProperty(this, CONFIG_ITEM_BRAND, {
53 enumerable: false
54 });
55 this.value = this._descriptor.value;
56 this.options = this._descriptor.options;
57 this.dirname = this._descriptor.dirname;
58 this.name = this._descriptor.name;
59 this.file = this._descriptor.file ? {
60 request: this._descriptor.file.request,
61 resolved: this._descriptor.file.resolved
62 } : undefined;
63 Object.freeze(this);
64 }
65
66}
67
68Object.freeze(ConfigItem.prototype);
\No newline at end of file