UNPKG

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