Skip to content

Commit 4b84d20

Browse files
committed
chore: cloudcmd
1 parent 6e778a3 commit 4b84d20

17 files changed

Lines changed: 121 additions & 132 deletions

client/cloudcmd.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ const {initSortPanel, sortPanel} = require('./sort.mjs');
1212
const isDev = process.env.NODE_ENV === 'development';
1313

1414
module.exports = async (config) => {
15-
window.Util = require('../common/util');
16-
window.CloudFunc = require('../common/cloudfunc');
15+
globalThis.Util = require('../common/util');
16+
globalThis.CloudFunc = require('../common/cloudfunc');
1717

18-
window.DOM = require('./dom');
19-
window.CloudCmd = require('./client');
18+
globalThis.DOM = require('./dom');
19+
globalThis.CloudCmd = require('./client');
2020

2121
await register(config);
2222

@@ -29,13 +29,13 @@ module.exports = async (config) => {
2929

3030
globalThis.CloudCmd.init(prefix, config);
3131

32-
if (window.CloudCmd.config('menu') === 'aleman')
32+
if (globalThis.CloudCmd.config('menu') === 'aleman')
3333
setTimeout(() => {
3434
import('https://esm.sh/@putout/processor-html');
3535
import('https://esm.sh/@putout/bundle');
3636
}, 100);
3737
};
38-
window.CloudCmd = module.exports;
38+
globalThis.CloudCmd = module.exports;
3939

4040
function getPrefix(prefix) {
4141
if (!prefix)
@@ -51,7 +51,7 @@ const onUpdateFound = wraptile(async (config) => {
5151
if (isDev)
5252
return;
5353

54-
const {DOM} = window;
54+
const {DOM} = globalThis;
5555
const prefix = getPrefix(config.prefix);
5656

5757
await load.js(`${prefix}/dist/cloudcmd.common.js`);
@@ -60,7 +60,7 @@ const onUpdateFound = wraptile(async (config) => {
6060
console.log('cloudcmd: sw: updated');
6161

6262
DOM.Events.removeAll();
63-
window.CloudCmd(config);
63+
globalThis.CloudCmd(config);
6464
});
6565

6666
async function register(config) {

client/dom/current-file.spec.js

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ const returns = wraptile(id);
1111
const {_CURRENT_FILE} = currentFile;
1212

1313
test('current-file: setCurrentName: setAttribute', (t) => {
14-
const {DOM, CloudCmd} = global;
14+
const {DOM, CloudCmd} = globalThis;
1515

16-
global.DOM = getDOM();
17-
global.CloudCmd = getCloudCmd();
16+
globalThis.DOM = getDOM();
17+
globalThis.CloudCmd = getCloudCmd();
1818

1919
const current = create();
2020
const {setAttribute} = current;
@@ -23,17 +23,17 @@ test('current-file: setCurrentName: setAttribute', (t) => {
2323

2424
t.calledWith(setAttribute, ['data-name', 'js-file-aGVsbG8='], 'should call setAttribute');
2525

26-
global.DOM = DOM;
27-
global.CloudCmd = CloudCmd;
26+
globalThis.DOM = DOM;
27+
globalThis.CloudCmd = CloudCmd;
2828

2929
t.end();
3030
});
3131

3232
test('current-file: setCurrentName: setAttribute: cyrillic', (t) => {
33-
const {DOM, CloudCmd} = global;
33+
const {DOM, CloudCmd} = globalThis;
3434

35-
global.DOM = getDOM();
36-
global.CloudCmd = getCloudCmd();
35+
globalThis.DOM = getDOM();
36+
globalThis.CloudCmd = getCloudCmd();
3737

3838
const current = create();
3939
const {setAttribute} = current;
@@ -42,8 +42,8 @@ test('current-file: setCurrentName: setAttribute: cyrillic', (t) => {
4242

4343
t.calledWith(setAttribute, ['data-name', 'js-file-JUQwJUIwJUQwJUI5'], 'should call setAttribute');
4444

45-
global.DOM = DOM;
46-
global.CloudCmd = CloudCmd;
45+
globalThis.DOM = DOM;
46+
globalThis.CloudCmd = CloudCmd;
4747

4848
t.end();
4949
});
@@ -59,12 +59,12 @@ test('current-file: getCurrentName', (t) => {
5959
});
6060

6161
test('current-file: emit', (t) => {
62-
const {DOM, CloudCmd} = global;
62+
const {DOM, CloudCmd} = globalThis;
6363

6464
const emit = stub();
6565

66-
global.DOM = getDOM();
67-
global.CloudCmd = getCloudCmd({
66+
globalThis.DOM = getDOM();
67+
globalThis.CloudCmd = getCloudCmd({
6868
emit,
6969
});
7070

@@ -74,98 +74,98 @@ test('current-file: emit', (t) => {
7474

7575
t.calledWith(emit, ['current-file', current], 'should call emit');
7676

77-
global.DOM = DOM;
78-
global.CloudCmd = CloudCmd;
77+
globalThis.DOM = DOM;
78+
globalThis.CloudCmd = CloudCmd;
7979

8080
t.end();
8181
});
8282

8383
test('current-file: setCurrentName: return', (t) => {
84-
const {DOM, CloudCmd} = global;
84+
const {DOM, CloudCmd} = globalThis;
8585

8686
const link = {};
8787

88-
global.DOM = getDOM({
88+
globalThis.DOM = getDOM({
8989
link,
9090
});
9191

92-
global.CloudCmd = getCloudCmd();
92+
globalThis.CloudCmd = getCloudCmd();
9393

9494
const current = create();
9595

9696
const result = currentFile.setCurrentName('hello', current);
9797

9898
t.equal(result, link, 'should return link');
9999

100-
global.DOM = DOM;
101-
global.CloudCmd = CloudCmd;
100+
globalThis.DOM = DOM;
101+
globalThis.CloudCmd = CloudCmd;
102102

103103
t.end();
104104
});
105105

106106
test('current-file: getParentDirPath: result', (t) => {
107-
const {DOM} = global;
107+
const {DOM} = globalThis;
108108

109109
const getCurrentDirPath = returns('/D/Films/+++favorite films/');
110110
const getCurrentDirName = returns('+++favorite films');
111111

112-
global.DOM = getDOM({
112+
globalThis.DOM = getDOM({
113113
getCurrentDirPath,
114114
getCurrentDirName,
115115
});
116116

117117
const result = currentFile.getParentDirPath();
118118
const expected = '/D/Films/';
119119

120-
global.DOM = DOM;
120+
globalThis.DOM = DOM;
121121

122122
t.equal(result, expected, 'should return parent dir path');
123123
t.end();
124124
});
125125

126126
test('current-file: isCurrentFile: no', (t) => {
127-
const {DOM, CloudCmd} = global;
127+
const {DOM, CloudCmd} = globalThis;
128128

129-
global.DOM = getDOM();
130-
global.CloudCmd = getCloudCmd();
129+
globalThis.DOM = getDOM();
130+
globalThis.CloudCmd = getCloudCmd();
131131

132132
const result = currentFile.isCurrentFile();
133133

134-
global.DOM = DOM;
135-
global.CloudCmd = CloudCmd;
134+
globalThis.DOM = DOM;
135+
globalThis.CloudCmd = CloudCmd;
136136

137137
t.notOk(result);
138138
t.end();
139139
});
140140

141141
test('current-file: isCurrentFile', (t) => {
142-
const {DOM, CloudCmd} = global;
142+
const {DOM, CloudCmd} = globalThis;
143143

144144
const isContainClass = stub();
145145

146-
global.DOM = getDOM({
146+
globalThis.DOM = getDOM({
147147
isContainClass,
148148
});
149149

150-
global.CloudCmd = getCloudCmd();
150+
globalThis.CloudCmd = getCloudCmd();
151151

152152
const current = {};
153153
currentFile.isCurrentFile(current);
154154

155-
global.DOM = DOM;
156-
global.CloudCmd = CloudCmd;
155+
globalThis.DOM = DOM;
156+
globalThis.CloudCmd = CloudCmd;
157157

158158
t.calledWith(isContainClass, [current, _CURRENT_FILE], 'should call isContainClass');
159159
t.end();
160160
});
161161

162162
test('current-file: getCurrentType', (t) => {
163-
const {DOM, CloudCmd} = global;
163+
const {DOM, CloudCmd} = globalThis;
164164

165-
global.DOM = getDOM();
166-
global.CloudCmd = getCloudCmd();
165+
globalThis.DOM = getDOM();
166+
globalThis.CloudCmd = getCloudCmd();
167167

168-
const {getByDataName} = global.DOM;
168+
const {getByDataName} = globalThis.DOM;
169169

170170
getByDataName.returns({
171171
className: 'mini-icon directory',
@@ -175,87 +175,87 @@ test('current-file: getCurrentType', (t) => {
175175

176176
currentFile.getCurrentType(current);
177177

178-
global.DOM = DOM;
179-
global.CloudCmd = CloudCmd;
178+
globalThis.DOM = DOM;
179+
globalThis.CloudCmd = CloudCmd;
180180

181181
t.calledWith(getByDataName, ['js-type', current]);
182182
t.end();
183183
});
184184

185185
test('current-file: isCurrentIsDir: getCurrentType', (t) => {
186-
const {DOM, CloudCmd} = global;
186+
const {DOM, CloudCmd} = globalThis;
187187

188-
global.DOM = getDOM();
189-
global.CloudCmd = getCloudCmd();
188+
globalThis.DOM = getDOM();
189+
globalThis.CloudCmd = getCloudCmd();
190190

191-
const {getCurrentType} = global.DOM;
191+
const {getCurrentType} = globalThis.DOM;
192192

193193
const current = create();
194194

195195
currentFile.isCurrentIsDir(current);
196196

197-
global.DOM = DOM;
198-
global.CloudCmd = CloudCmd;
197+
globalThis.DOM = DOM;
198+
globalThis.CloudCmd = CloudCmd;
199199

200200
t.calledWith(getCurrentType, [current]);
201201
t.end();
202202
});
203203

204204
test('current-file: isCurrentIsDir: directory', (t) => {
205-
const {DOM, CloudCmd} = global;
205+
const {DOM, CloudCmd} = globalThis;
206206

207-
global.DOM = getDOM({
207+
globalThis.DOM = getDOM({
208208
getCurrentType: stub().returns('directory'),
209209
});
210210

211-
global.CloudCmd = getCloudCmd();
211+
globalThis.CloudCmd = getCloudCmd();
212212

213213
const current = create();
214214

215215
const result = currentFile.isCurrentIsDir(current);
216216

217-
global.DOM = DOM;
218-
global.CloudCmd = CloudCmd;
217+
globalThis.DOM = DOM;
218+
globalThis.CloudCmd = CloudCmd;
219219

220220
t.ok(result);
221221
t.end();
222222
});
223223

224224
test('current-file: isCurrentIsDir: directory-link', (t) => {
225-
const {DOM, CloudCmd} = global;
225+
const {DOM, CloudCmd} = globalThis;
226226

227-
global.DOM = getDOM({
227+
globalThis.DOM = getDOM({
228228
getCurrentType: stub().returns('directory-link'),
229229
});
230230

231-
global.CloudCmd = getCloudCmd();
231+
globalThis.CloudCmd = getCloudCmd();
232232

233233
const current = create();
234234

235235
const result = currentFile.isCurrentIsDir(current);
236236

237-
global.DOM = DOM;
238-
global.CloudCmd = CloudCmd;
237+
globalThis.DOM = DOM;
238+
globalThis.CloudCmd = CloudCmd;
239239

240240
t.ok(result);
241241
t.end();
242242
});
243243

244244
test('current-file: isCurrentIsDir: file', (t) => {
245-
const {DOM, CloudCmd} = global;
245+
const {DOM, CloudCmd} = globalThis;
246246

247-
global.DOM = getDOM({
247+
globalThis.DOM = getDOM({
248248
getCurrentType: stub().returns('file'),
249249
});
250250

251-
global.CloudCmd = getCloudCmd();
251+
globalThis.CloudCmd = getCloudCmd();
252252

253253
const current = create();
254254

255255
const result = currentFile.isCurrentIsDir(current);
256256

257-
global.DOM = DOM;
258-
global.CloudCmd = CloudCmd;
257+
globalThis.DOM = DOM;
258+
globalThis.CloudCmd = CloudCmd;
259259

260260
t.notOk(result);
261261
t.end();

client/dom/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ module.exports.shrinkSelection = () => {
416416
* setting history wrapper
417417
*/
418418
module.exports.setHistory = (data, title, url) => {
419-
const ret = window.history;
419+
const ret = globalThis.history;
420420
const {prefix} = CloudCmd;
421421

422422
url = prefix + url;
@@ -554,7 +554,7 @@ module.exports.getPanel = (options) => {
554554
* then always work with passive
555555
* panel
556556
*/
557-
if (window.innerWidth < CloudCmd.MIN_ONE_PANEL_WIDTH)
557+
if (globalThis.innerWidth < CloudCmd.MIN_ONE_PANEL_WIDTH)
558558
panel = DOM.getByDataName('js-left');
559559

560560
if (!panel)

0 commit comments

Comments
 (0)