@webiny/global-config 0.0.0-mt-2 β†’ 0.0.0-unstable.0156a4c312

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1 +1,11 @@
1
1
  # @webiny/global-config
2
+
3
+ > [!NOTE]
4
+ > This package is part of the [Webiny](https://www.webiny.com) monorepo.
5
+ > It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
6
+
7
+ πŸ“˜ **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
8
+
9
+ ---
10
+
11
+ _This README file is automatically generated during the publish process._
package/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ export interface GlobalConfig {
2
+ /**
3
+ * Returns the whole config, creating it with defaults if it is missing or
4
+ * has no `id`. `isEnabled()` in @webiny/telemetry already calls it this way;
5
+ * the overload was just missing from these types.
6
+ */
7
+ get(): Record<string, any>;
8
+ get(key: string): any;
9
+ set(key: string, value: any): void;
10
+ }
11
+
12
+ export declare const globalConfig: GlobalConfig;
package/index.js CHANGED
@@ -1,25 +1,48 @@
1
- const os = require("os");
2
- const path = require("path");
3
- const { v4: uuidv4 } = require("uuid");
4
- const readJson = require("load-json-file");
5
- const writeJson = require("write-json-file");
1
+ import os from "os";
2
+ import path from "path";
3
+ import { randomUUID } from "crypto";
4
+ import { loadJsonFileSync } from "load-json-file";
5
+ import { writeJsonFileSync } from "write-json-file";
6
+ import { isCI } from "ci-info";
6
7
 
7
8
  const GLOBAL_CONFIG_PATH = path.join(os.homedir(), ".webiny", "config");
8
9
 
9
- module.exports.globalConfig = {
10
+ export const globalConfig = {
10
11
  __globalConfig: null,
11
12
  get(key) {
12
13
  try {
13
14
  if (!this.__globalConfig) {
14
- this.__globalConfig = readJson.sync(GLOBAL_CONFIG_PATH);
15
+ this.__globalConfig = loadJsonFileSync(GLOBAL_CONFIG_PATH);
15
16
  if (!this.__globalConfig.id) {
16
17
  throw Error("Invalid Webiny config!");
17
18
  }
18
19
  }
19
- } catch (e) {
20
+ } catch {
20
21
  // A new config file is written if it doesn't exist or is invalid.
21
- this.__globalConfig = { id: uuidv4(), telemetry: true };
22
- writeJson.sync(GLOBAL_CONFIG_PATH, this.__globalConfig);
22
+ this.__globalConfig = {
23
+ // Node's own v4 UUID. This used to come from `@webiny/stdlib`, whose root entry is
24
+ // about 30 modules, loaded on every CLI command just to generate this one ID.
25
+ id: randomUUID(),
26
+ telemetry: true,
27
+
28
+ // This flag is set to `false` the moment user successfully
29
+ // deploys a Webiny project for the first time. Once they do,
30
+ // they're considered no longer a "new user".
31
+ // Also, in CI environments, we always set this to `false`.
32
+ newUser: isCI ? false : true
33
+ };
34
+ writeJsonFileSync(GLOBAL_CONFIG_PATH, this.__globalConfig);
35
+ }
36
+
37
+ // Backfill `newUser` on configs that predate it, or that were written by something
38
+ // that didn't set it. Absent is not the same as `false`: the only thing that writes
39
+ // `false` is the first successful deploy, so a missing key means that never happened
40
+ // and the user is still new. Reading it as `Boolean(undefined)` reported every one of
41
+ // them as returning. Persisted so the state stops being ambiguous, and so every reader
42
+ // agrees without repeating this rule.
43
+ if (!("newUser" in this.__globalConfig)) {
44
+ this.__globalConfig.newUser = isCI ? false : true;
45
+ writeJsonFileSync(GLOBAL_CONFIG_PATH, this.__globalConfig);
23
46
  }
24
47
 
25
48
  return key ? this.__globalConfig[key] : this.__globalConfig;
@@ -27,7 +50,7 @@ module.exports.globalConfig = {
27
50
  set(key, value) {
28
51
  const globalConfig = this.get();
29
52
  globalConfig[key] = value;
30
- writeJson.sync(GLOBAL_CONFIG_PATH, globalConfig);
53
+ writeJsonFileSync(GLOBAL_CONFIG_PATH, globalConfig);
31
54
  return globalConfig;
32
55
  }
33
56
  };
package/package.json CHANGED
@@ -1,16 +1,18 @@
1
1
  {
2
2
  "name": "@webiny/global-config",
3
- "version": "0.0.0-mt-2",
4
- "main": "index.js",
3
+ "version": "0.0.0-unstable.0156a4c312",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./index.js",
7
+ "./*": "./*"
8
+ },
5
9
  "license": "MIT",
6
10
  "dependencies": {
7
- "load-json-file": "6.2.0",
8
- "uuid": "8.3.2",
9
- "write-json-file": "4.3.0"
11
+ "ci-info": "4.4.0",
12
+ "load-json-file": "7.0.1",
13
+ "write-json-file": "7.0.0"
10
14
  },
11
15
  "publishConfig": {
12
- "access": "public",
13
- "directory": "."
14
- },
15
- "gitHead": "3c0dcfb3c22c9f83107fdb97b25014cd03d9db7d"
16
+ "access": "public"
17
+ }
16
18
  }
package/CHANGELOG.md DELETED
@@ -1,254 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- ## [5.18.1](https://github.com/webiny/webiny-js/compare/v5.18.1-beta.0...v5.18.1) (2021-11-25)
7
-
8
- **Note:** Version bump only for package @webiny/global-config
9
-
10
-
11
-
12
-
13
-
14
- ## [5.18.1-beta.0](https://github.com/webiny/webiny-js/compare/v5.18.0...v5.18.1-beta.0) (2021-11-25)
15
-
16
- **Note:** Version bump only for package @webiny/global-config
17
-
18
-
19
-
20
-
21
-
22
- # [5.18.0](https://github.com/webiny/webiny-js/compare/v5.18.0-beta.4...v5.18.0) (2021-11-24)
23
-
24
- **Note:** Version bump only for package @webiny/global-config
25
-
26
-
27
-
28
-
29
-
30
- # [5.18.0-beta.4](https://github.com/webiny/webiny-js/compare/v5.18.0-beta.3...v5.18.0-beta.4) (2021-11-23)
31
-
32
- **Note:** Version bump only for package @webiny/global-config
33
-
34
-
35
-
36
-
37
-
38
- # [5.18.0-beta.3](https://github.com/webiny/webiny-js/compare/v5.18.0-beta.2...v5.18.0-beta.3) (2021-11-22)
39
-
40
- **Note:** Version bump only for package @webiny/global-config
41
-
42
-
43
-
44
-
45
-
46
- # [5.18.0-beta.2](https://github.com/webiny/webiny-js/compare/v5.18.0-beta.1...v5.18.0-beta.2) (2021-11-21)
47
-
48
- **Note:** Version bump only for package @webiny/global-config
49
-
50
-
51
-
52
-
53
-
54
- # [5.18.0-beta.1](https://github.com/webiny/webiny-js/compare/v5.18.0-beta.0...v5.18.0-beta.1) (2021-11-19)
55
-
56
- **Note:** Version bump only for package @webiny/global-config
57
-
58
-
59
-
60
-
61
-
62
- # [5.18.0-beta.0](https://github.com/webiny/webiny-js/compare/v5.17.4...v5.18.0-beta.0) (2021-11-19)
63
-
64
- **Note:** Version bump only for package @webiny/global-config
65
-
66
-
67
-
68
-
69
-
70
- ## [5.17.4](https://github.com/webiny/webiny-js/compare/v5.17.4-beta.1...v5.17.4) (2021-11-19)
71
-
72
- **Note:** Version bump only for package @webiny/global-config
73
-
74
-
75
-
76
-
77
-
78
- ## [5.17.4-beta.1](https://github.com/webiny/webiny-js/compare/v5.17.4-beta.0...v5.17.4-beta.1) (2021-11-19)
79
-
80
- **Note:** Version bump only for package @webiny/global-config
81
-
82
-
83
-
84
-
85
-
86
- ## [5.17.4-beta.0](https://github.com/webiny/webiny-js/compare/v5.17.3...v5.17.4-beta.0) (2021-11-19)
87
-
88
- **Note:** Version bump only for package @webiny/global-config
89
-
90
-
91
-
92
-
93
-
94
- ## [5.17.3](https://github.com/webiny/webiny-js/compare/v5.17.3-beta.0...v5.17.3) (2021-11-15)
95
-
96
- **Note:** Version bump only for package @webiny/global-config
97
-
98
-
99
-
100
-
101
-
102
- ## [5.17.3-beta.0](https://github.com/webiny/webiny-js/compare/v5.17.2...v5.17.3-beta.0) (2021-11-12)
103
-
104
- **Note:** Version bump only for package @webiny/global-config
105
-
106
-
107
-
108
-
109
-
110
- ## [5.17.2](https://github.com/webiny/webiny-js/compare/v5.17.2-beta.0...v5.17.2) (2021-11-11)
111
-
112
- **Note:** Version bump only for package @webiny/global-config
113
-
114
-
115
-
116
-
117
-
118
- ## [5.17.2-beta.0](https://github.com/webiny/webiny-js/compare/v5.17.1...v5.17.2-beta.0) (2021-11-11)
119
-
120
-
121
- ### Bug Fixes
122
-
123
- * force same version on all packages ([9cbae8b](https://github.com/webiny/webiny-js/commit/9cbae8b050900546eb17932c23a609593211c1c8))
124
-
125
-
126
-
127
-
128
-
129
- # [5.17.0](https://github.com/webiny/webiny-js/compare/v5.17.0-beta.2...v5.17.0) (2021-11-08)
130
-
131
- **Note:** Version bump only for package @webiny/global-config
132
-
133
-
134
-
135
-
136
-
137
- # [5.17.0-beta.2](https://github.com/webiny/webiny-js/compare/v5.17.0-beta.1...v5.17.0-beta.2) (2021-11-08)
138
-
139
- **Note:** Version bump only for package @webiny/global-config
140
-
141
-
142
-
143
-
144
-
145
- # [5.17.0-beta.1](https://github.com/webiny/webiny-js/compare/v5.16.0...v5.17.0-beta.1) (2021-11-08)
146
-
147
- **Note:** Version bump only for package @webiny/global-config
148
-
149
-
150
-
151
-
152
-
153
- # [5.16.0](https://github.com/webiny/webiny-js/compare/v5.16.0-beta.4...v5.16.0) (2021-10-21)
154
-
155
- **Note:** Version bump only for package @webiny/global-config
156
-
157
-
158
-
159
-
160
-
161
- # [5.16.0-beta.4](https://github.com/webiny/webiny-js/compare/v5.16.0-beta.3...v5.16.0-beta.4) (2021-10-20)
162
-
163
- **Note:** Version bump only for package @webiny/global-config
164
-
165
-
166
-
167
-
168
-
169
- # [5.16.0-beta.3](https://github.com/webiny/webiny-js/compare/v5.16.0-beta.2...v5.16.0-beta.3) (2021-10-20)
170
-
171
- **Note:** Version bump only for package @webiny/global-config
172
-
173
-
174
-
175
-
176
-
177
- # [5.16.0-beta.2](https://github.com/webiny/webiny-js/compare/v5.16.0-beta.1...v5.16.0-beta.2) (2021-10-20)
178
-
179
- **Note:** Version bump only for package @webiny/global-config
180
-
181
-
182
-
183
-
184
-
185
- # [5.16.0-beta.1](https://github.com/webiny/webiny-js/compare/v5.16.0-beta.0...v5.16.0-beta.1) (2021-10-19)
186
-
187
- **Note:** Version bump only for package @webiny/global-config
188
-
189
-
190
-
191
-
192
-
193
- # [5.16.0-beta.0](https://github.com/webiny/webiny-js/compare/v5.17.0-beta.0...v5.16.0-beta.0) (2021-10-19)
194
-
195
- **Note:** Version bump only for package @webiny/global-config
196
-
197
-
198
-
199
-
200
-
201
- # [5.17.0-beta.0](https://github.com/webiny/webiny-js/compare/v5.15.0...v5.17.0-beta.0) (2021-10-18)
202
-
203
- **Note:** Version bump only for package @webiny/global-config
204
-
205
-
206
-
207
-
208
-
209
- # [5.15.0](https://github.com/webiny/webiny-js/compare/v5.15.0-beta.3...v5.15.0) (2021-09-30)
210
-
211
- **Note:** Version bump only for package @webiny/global-config
212
-
213
-
214
-
215
-
216
-
217
- # [5.15.0-beta.3](https://github.com/webiny/webiny-js/compare/v5.15.0-beta.2...v5.15.0-beta.3) (2021-09-30)
218
-
219
- **Note:** Version bump only for package @webiny/global-config
220
-
221
-
222
-
223
-
224
-
225
- # [5.15.0-beta.2](https://github.com/webiny/webiny-js/compare/v5.15.0-beta.1...v5.15.0-beta.2) (2021-09-29)
226
-
227
- **Note:** Version bump only for package @webiny/global-config
228
-
229
-
230
-
231
-
232
-
233
- # [5.15.0-beta.1](https://github.com/webiny/webiny-js/compare/v5.15.0-beta.0...v5.15.0-beta.1) (2021-09-28)
234
-
235
- **Note:** Version bump only for package @webiny/global-config
236
-
237
-
238
-
239
-
240
-
241
- # [5.15.0-beta.0](https://github.com/webiny/webiny-js/compare/v5.14.0...v5.15.0-beta.0) (2021-09-16)
242
-
243
-
244
- ### Bug Fixes
245
-
246
- * remove extra get function ([6aa6533](https://github.com/webiny/webiny-js/commit/6aa65333927284a354f2f79274dba3fc2ffd212a))
247
- * remove telemetry getter ([62630e8](https://github.com/webiny/webiny-js/commit/62630e87b20e5a408848ccb718e07409625e3bd2))
248
- * update dependencies ([fe2a736](https://github.com/webiny/webiny-js/commit/fe2a73694c14d3694ecc2117619f6907fa6d156a))
249
- * update dependencies ([37f2691](https://github.com/webiny/webiny-js/commit/37f2691f3cb615615a089d977f58a22a8bb21f50))
250
-
251
-
252
- ### Features
253
-
254
- * create webiny/global-config package ([efffba0](https://github.com/webiny/webiny-js/commit/efffba0ccaa89d6840e2170ba8aa69938967d282))