iobroker.javascript 8.9.2 → 9.0.0
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 +7 -3
- package/admin/assets/{createSvgIcon-BdRvDw53.js → createSvgIcon-BQT-7-GS.js} +1 -1
- package/admin/assets/{docs-6na4NFtj.js → docs-BrInh2Pn.js} +2 -2
- package/admin/assets/index-B0RKH_iG.js +1329 -0
- package/admin/assets/index-CfuHVX2B.js +193 -0
- package/admin/assets/index-CuCs5aLs.js +5 -0
- package/admin/assets/index-tExaxF69.js +930 -0
- package/admin/assets/inheritsLoose--KnFDOw1.js +36 -0
- package/admin/assets/{useTheme-Cl1QmYFL.js → useTheme-DF6qfrtI.js} +1 -1
- package/admin/custom/assets/{Components-ChpTW7sE.js → Components-D9kRsHNY.js} +1 -1
- package/admin/custom/assets/{DefaultPropsProvider-CHpMCMgA.js → DefaultPropsProvider-9qubdy-V.js} +2 -2
- package/admin/custom/assets/{FilledInput-CtcQVKyj.js → FilledInput-BpuM_GyB.js} +1 -1
- package/admin/custom/assets/Tabs-CvEv0KOT.js +138 -0
- package/admin/custom/assets/ThemeProvider-DZTpMR8n.js +29 -0
- package/admin/custom/assets/{createSvgIcon-C_vAELFU.js → createSvgIcon-BQThUM-f.js} +1 -1
- package/admin/custom/assets/hostInit-CrAs5YZS.js +1 -1
- package/admin/custom/assets/{index-DwsbskQy.js → index-DIWNdd4a.js} +1 -1
- package/admin/custom/assets/index-DZqbj5K4.js +55 -0
- package/admin/custom/assets/{index-D5apCzjJ.js → index-Dbe-II7_.js} +6 -6
- package/admin/custom/assets/index-az76fZMP.js +904 -0
- package/admin/custom/assets/index-sawv1cUe.js +1399 -0
- package/admin/custom/assets/{virtualExposes-BPncCdUy.js → virtualExposes-BMKIjWrE.js} +2 -2
- package/admin/custom/customComponents.js +2 -2
- package/admin/custom/i18n/de.json +29 -29
- package/admin/custom/i18n/es.json +29 -29
- package/admin/custom/i18n/fr.json +29 -29
- package/admin/custom/i18n/it.json +29 -29
- package/admin/custom/i18n/nl.json +29 -29
- package/admin/custom/i18n/pl.json +29 -29
- package/admin/custom/i18n/pt.json +29 -29
- package/admin/custom/i18n/ru.json +29 -29
- package/admin/custom/i18n/uk.json +29 -29
- package/admin/custom/i18n/zh-cn.json +29 -29
- package/admin/google-blockly/blockly_compressed.js +875 -887
- package/admin/google-blockly/blocks_compressed.js +38 -41
- package/admin/google-blockly/javascript_compressed.js +19 -54
- package/admin/google-blockly/media/delete-icon.svg +1 -0
- package/admin/google-blockly/media/foldout-icon.svg +1 -0
- package/admin/google-blockly/media/resize-handle.svg +3 -0
- package/admin/jsonConfig.json +2 -0
- package/admin/mf-manifest.json +1 -1
- package/admin/remoteEntry.js +2 -2
- package/admin/tab.html +4 -4
- package/admin/vsFont/README.md +1 -1
- package/admin/vsFont/createJson.js +1 -1
- package/build-backend/lib/consts.js +346 -0
- package/build-backend/lib/consts.js.map +1 -0
- package/build-backend/lib/convert.js +120 -0
- package/build-backend/lib/convert.js.map +1 -0
- package/build-backend/lib/debug.js +163 -0
- package/build-backend/lib/debug.js.map +1 -0
- package/{lib → build-backend/lib}/debugger.js +261 -232
- package/build-backend/lib/debugger.js.map +1 -0
- package/build-backend/lib/eventObj.js +177 -0
- package/build-backend/lib/eventObj.js.map +1 -0
- package/build-backend/lib/inspect.js +728 -0
- package/build-backend/lib/inspect.js.map +1 -0
- package/build-backend/lib/javascript.d.ts +1972 -0
- package/{lib → build-backend/lib}/mirror.js +185 -182
- package/build-backend/lib/mirror.js.map +1 -0
- package/build-backend/lib/nodeModulesManagement.js +25 -0
- package/build-backend/lib/nodeModulesManagement.js.map +1 -0
- package/build-backend/lib/patternCompareFunctions.js +321 -0
- package/build-backend/lib/patternCompareFunctions.js.map +1 -0
- package/build-backend/lib/protectFs.js +477 -0
- package/build-backend/lib/protectFs.js.map +1 -0
- package/build-backend/lib/request.js +89 -0
- package/build-backend/lib/request.js.map +1 -0
- package/{lib → build-backend/lib}/sandbox.js +2046 -1852
- package/build-backend/lib/sandbox.js.map +1 -0
- package/build-backend/lib/scheduler.js +553 -0
- package/build-backend/lib/scheduler.js.map +1 -0
- package/build-backend/lib/tools.js +183 -0
- package/build-backend/lib/tools.js.map +1 -0
- package/build-backend/lib/typescriptSettings.js +39 -0
- package/build-backend/lib/typescriptSettings.js.map +1 -0
- package/build-backend/lib/typescriptTools.js +435 -0
- package/build-backend/lib/typescriptTools.js.map +1 -0
- package/build-backend/lib/utils.js +66 -0
- package/build-backend/lib/utils.js.map +1 -0
- package/{lib → build-backend/lib}/words.js +23 -30
- package/build-backend/lib/words.js.map +1 -0
- package/build-backend/main.js +2671 -0
- package/build-backend/main.js.map +1 -0
- package/build-backend/types.d.ts +742 -0
- package/docs/de/README.md +1 -1
- package/docs/en/README.md +1 -1
- package/docs/en/javascript.md +10 -6
- package/docs/ru/README.md +1 -1
- package/install/installTypings.js +34 -47
- package/io-package.json +14 -14
- package/package.json +14 -14
- package/admin/assets/index-DCkkMRRa.js +0 -1335
- package/admin/assets/index-DJfSBoBB.js +0 -192
- package/admin/assets/index-DTiA4WdK.js +0 -930
- package/admin/assets/index-qABB1JVe.js +0 -5
- package/admin/assets/inheritsLoose-BW-3V39H.js +0 -36
- package/admin/custom/assets/Tabs-C1KOyWRi.js +0 -137
- package/admin/custom/assets/ThemeProvider-Buvx5nSd.js +0 -29
- package/admin/custom/assets/index-BGCRznKh.js +0 -904
- package/admin/custom/assets/index-DfBPYXqA.js +0 -55
- package/admin/custom/assets/index-jIr6kOLK.js +0 -1398
- package/lib/adapter-config.d.ts +0 -16
- package/lib/consts.js +0 -83
- package/lib/convert.js +0 -106
- package/lib/debug.js +0 -154
- package/lib/eventObj.js +0 -201
- package/lib/inspect.js +0 -688
- package/lib/javascript.d.ts +0 -1858
- package/lib/nodeModulesManagement.js +0 -26
- package/lib/patternCompareFunctions.js +0 -391
- package/lib/protectFs.js +0 -401
- package/lib/request.js +0 -72
- package/lib/scheduler.js +0 -447
- package/lib/tools.js +0 -192
- package/lib/typescriptSettings.js +0 -44
- package/lib/typescriptTools.js +0 -529
- package/lib/utils.js +0 -87
- package/main.js +0 -2653
package/lib/typescriptTools.js
DELETED
|
@@ -1,529 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('node:fs');
|
|
4
|
-
const path = require('node:path');
|
|
5
|
-
const ts = require('typescript');
|
|
6
|
-
const { matchAll } = require('./tools');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Resolves all TypeScript lib files for the editor
|
|
10
|
-
* @param {string} targetLib The lib to target (e.g. es2017)
|
|
11
|
-
*/
|
|
12
|
-
function resolveTypescriptLibs(targetLib) {
|
|
13
|
-
const typescriptLibRoot = path.dirname(require.resolve(`typescript/lib/lib.d.ts`));
|
|
14
|
-
const ret = {};
|
|
15
|
-
|
|
16
|
-
const libReferenceRegex = /\/\/\/ <reference lib=["']([^"']+)["'] \/>/g;
|
|
17
|
-
const matchAllLibs = (string) => matchAll(libReferenceRegex, string).map(groups => groups[0]);
|
|
18
|
-
|
|
19
|
-
const libQueue = [targetLib];
|
|
20
|
-
while (libQueue.length > 0) {
|
|
21
|
-
const libName = libQueue.shift();
|
|
22
|
-
const filename = `lib.${libName}.d.ts`;
|
|
23
|
-
// Read the file and remember it in the return dictionary
|
|
24
|
-
const fileContent = fs.readFileSync(path.join(typescriptLibRoot, filename), 'utf8');
|
|
25
|
-
ret[filename] = fileContent;
|
|
26
|
-
// If this file references another lib file, we need to load that too
|
|
27
|
-
// A reference looks like this: /// <reference lib="es2015.core" />
|
|
28
|
-
// Find all libs we have not loaded yet
|
|
29
|
-
matchAllLibs(fileContent)
|
|
30
|
-
.filter(lib => !(`lib.${lib}.d.ts` in ret))
|
|
31
|
-
.forEach(lib => libQueue.push(lib));
|
|
32
|
-
}
|
|
33
|
-
return ret;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function normalizeDTSImport(filename) {
|
|
37
|
-
// An import is either...
|
|
38
|
-
// a normal import
|
|
39
|
-
if (filename.endsWith('.d.ts')) {
|
|
40
|
-
return filename;
|
|
41
|
-
}
|
|
42
|
-
// an extensionless import
|
|
43
|
-
if (fs.existsSync(`${filename}.d.ts`)) {
|
|
44
|
-
return `${filename}.d.ts`;
|
|
45
|
-
}
|
|
46
|
-
// or a directory import
|
|
47
|
-
return path.join(filename, 'index.d.ts');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Resolves the type declarations of a 3rd party package for the editor
|
|
52
|
-
* @param {string} pkg The package whose typings we're interested in
|
|
53
|
-
* @param {string} adapterScopedPackageName the package name on the system
|
|
54
|
-
* @param {boolean} [wrapInDeclareModule=false] Whether the root file should be wrapped in `declare module "<pkg>" { ... }`
|
|
55
|
-
* @returns {Record<string, string> | undefined} The found declarations or undefined if none were found
|
|
56
|
-
*/
|
|
57
|
-
function resolveTypings(pkg, adapterScopedPackageName, wrapInDeclareModule) {
|
|
58
|
-
let packageJsonPath;
|
|
59
|
-
let packageJson;
|
|
60
|
-
/** @type {string | undefined} */
|
|
61
|
-
let rootTypings;
|
|
62
|
-
let pkgIncludesTypings = true;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* @param {string} path
|
|
66
|
-
*/
|
|
67
|
-
function tryToLoadPackage(path) {
|
|
68
|
-
try {
|
|
69
|
-
packageJsonPath = require.resolve(path);
|
|
70
|
-
packageJson = require(packageJsonPath);
|
|
71
|
-
rootTypings = typeof packageJson.types === 'string' ? packageJson.types
|
|
72
|
-
: typeof packageJson.typings === 'string' ? packageJson.typings
|
|
73
|
-
: undefined;
|
|
74
|
-
} catch { /* ignore */ }
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// First, try to resolve the package itself in case it brings its own typings
|
|
78
|
-
tryToLoadPackage(`${adapterScopedPackageName}/package.json`);
|
|
79
|
-
// If that didn't work, try again with the @types version of the package
|
|
80
|
-
if (!rootTypings) {
|
|
81
|
-
tryToLoadPackage(`@types/${pkg}/package.json`);
|
|
82
|
-
pkgIncludesTypings = false;
|
|
83
|
-
}
|
|
84
|
-
// TODO: If that didn't work, download @types/<packagename> and retry the previous step
|
|
85
|
-
|
|
86
|
-
// Nothing to do here since we found no packages
|
|
87
|
-
if (!rootTypings) return undefined;
|
|
88
|
-
|
|
89
|
-
const packageRoot = path.dirname(packageJsonPath);
|
|
90
|
-
const normalizeImportPath = filename => path.normalize(
|
|
91
|
-
`node_modules/${pkgIncludesTypings ? adapterScopedPackageName : `@types/${pkg}`}/${path.relative(packageRoot, filename)}`
|
|
92
|
-
).replace(/\\/g, '/');
|
|
93
|
-
|
|
94
|
-
/** @type {Record<string, string>} */
|
|
95
|
-
const ret = {};
|
|
96
|
-
|
|
97
|
-
// We need to look at `import/export ... from 'modulename'` and `/// <reference path='...' />`
|
|
98
|
-
const importDtsRegex = /^\s*(?:import|export) .+ from ["'](\.+\/[^"']+)["']/g;
|
|
99
|
-
const pathReferenceRegex = /\/\/\/ <reference path=["']([^"']+)["'] \/>/g;
|
|
100
|
-
const matchAllImports = string => [
|
|
101
|
-
...matchAll(importDtsRegex, string),
|
|
102
|
-
...matchAll(pathReferenceRegex, string)
|
|
103
|
-
].map(groups => groups[0]);
|
|
104
|
-
|
|
105
|
-
// the paths are relative to the package.json - we need an absolute path to read the files
|
|
106
|
-
rootTypings = path.join(packageRoot, rootTypings);
|
|
107
|
-
// some @types packages specify `index` as their typings file instead of `index.d.ts`
|
|
108
|
-
rootTypings = normalizeDTSImport(rootTypings);
|
|
109
|
-
|
|
110
|
-
// include package.json in typings, so TypeScript can look up the correct entry point
|
|
111
|
-
const relativePath = `node_modules/${pkgIncludesTypings ? '' : '@types/'}${pkg}/package.json`.replace(/\\/g, '/');
|
|
112
|
-
ret[relativePath] = JSON.stringify(packageJson);
|
|
113
|
-
|
|
114
|
-
// Used to test whether a .d.ts file already uses "declare module" or not
|
|
115
|
-
const declareModuleRegex = /^\s*declare module/gm;
|
|
116
|
-
|
|
117
|
-
// recursively load all typings
|
|
118
|
-
const definitionQueue = [rootTypings];
|
|
119
|
-
while (definitionQueue.length > 0) {
|
|
120
|
-
const filename = definitionQueue.shift();
|
|
121
|
-
const dirName = path.dirname(filename);
|
|
122
|
-
// Read the file and remember it in the return dictionary
|
|
123
|
-
let fileContent;
|
|
124
|
-
try {
|
|
125
|
-
fileContent = fs.readFileSync(filename, 'utf8');
|
|
126
|
-
} catch (e) {
|
|
127
|
-
// The typings are malformed
|
|
128
|
-
console.error(`Failed to load definitions for ${pkg}: ${e}`);
|
|
129
|
-
// Since we cannot use them, return undefined
|
|
130
|
-
return undefined;
|
|
131
|
-
}
|
|
132
|
-
// We need to store the filename relative to the base dir
|
|
133
|
-
const relativePath = normalizeImportPath(filename);
|
|
134
|
-
// If necessary, wrap the root typings (only those!)
|
|
135
|
-
ret[relativePath] = wrapInDeclareModule && filename === rootTypings && !declareModuleRegex.test(fileContent)
|
|
136
|
-
? `declare module "${pkg}" { ${fileContent} }`
|
|
137
|
-
: fileContent;
|
|
138
|
-
// If this file references another .d.ts file, we need to load that too
|
|
139
|
-
matchAllImports(fileContent)
|
|
140
|
-
// resolve the file relative to the current directory
|
|
141
|
-
.map(file => path.join(dirName, file))
|
|
142
|
-
// find out the correct path of the file we want to import
|
|
143
|
-
.map(normalizeDTSImport)
|
|
144
|
-
// Find all libs we have not loaded yet
|
|
145
|
-
.filter(file => !(normalizeImportPath(file) in ret))
|
|
146
|
-
.forEach(file => definitionQueue.push(file));
|
|
147
|
-
}
|
|
148
|
-
// Avoid returning empty declarations
|
|
149
|
-
if (Object.keys(ret).length === 0) {
|
|
150
|
-
return undefined;
|
|
151
|
-
}
|
|
152
|
-
return ret;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* @param {import("typescript").Statement} s
|
|
157
|
-
* @param {boolean} isGlobal Whether this is a global script or a normal one
|
|
158
|
-
*/
|
|
159
|
-
function mustBeHoisted(s, isGlobal) {
|
|
160
|
-
return (
|
|
161
|
-
// Import/export statements must be moved to the top
|
|
162
|
-
ts.isImportDeclaration(s) ||
|
|
163
|
-
ts.isImportEqualsDeclaration(s) ||
|
|
164
|
-
ts.isExportDeclaration(s) ||
|
|
165
|
-
ts.isExportAssignment(s) ||
|
|
166
|
-
// as well as many declarations
|
|
167
|
-
ts.isTypeAliasDeclaration(s) ||
|
|
168
|
-
ts.isInterfaceDeclaration(s) ||
|
|
169
|
-
ts.isModuleDeclaration(s) ||
|
|
170
|
-
ts.isEnumDeclaration(s) ||
|
|
171
|
-
(isGlobal && (
|
|
172
|
-
// in global scripts we don't wrap classes and functions, so they can be accessed from non-global scripts
|
|
173
|
-
ts.isClassDeclaration(s) ||
|
|
174
|
-
ts.isFunctionDeclaration(s)
|
|
175
|
-
)) ||
|
|
176
|
-
// and declare ... / export ... statements
|
|
177
|
-
(s.modifiers &&
|
|
178
|
-
s.modifiers.some(
|
|
179
|
-
s => s.kind === ts.SyntaxKind.DeclareKeyword
|
|
180
|
-
|| s.kind === ts.SyntaxKind.ExportKeyword
|
|
181
|
-
))
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/** @param {import("typescript").Statement} s */
|
|
186
|
-
function canBeExported(s) {
|
|
187
|
-
return (
|
|
188
|
-
// const, let, var
|
|
189
|
-
ts.isVariableStatement(s) ||
|
|
190
|
-
// type, interface, enum, class, function
|
|
191
|
-
ts.isTypeAliasDeclaration(s) ||
|
|
192
|
-
ts.isInterfaceDeclaration(s) ||
|
|
193
|
-
ts.isEnumDeclaration(s) ||
|
|
194
|
-
ts.isClassDeclaration(s) ||
|
|
195
|
-
ts.isFunctionDeclaration(s)
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* @param {import("typescript").Statement} s
|
|
201
|
-
*/
|
|
202
|
-
function addExportModifier(s) {
|
|
203
|
-
/** @type {import("typescript").Modifier[]} */
|
|
204
|
-
let modifiers;
|
|
205
|
-
// Add export modifiers
|
|
206
|
-
if (!s.modifiers) {
|
|
207
|
-
modifiers = [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)];
|
|
208
|
-
} else if (!s.modifiers.some(m => m.kind === ts.SyntaxKind.ExportKeyword)) {
|
|
209
|
-
modifiers = [...s.modifiers, ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)];
|
|
210
|
-
} else {
|
|
211
|
-
return s;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (ts.isVariableStatement(s)) {
|
|
215
|
-
return ts.factory.updateVariableStatement(s, modifiers, s.declarationList);
|
|
216
|
-
}
|
|
217
|
-
if (ts.isTypeAliasDeclaration(s)) {
|
|
218
|
-
return ts.factory.updateTypeAliasDeclaration(s, modifiers, s.name, s.typeParameters, s.type);
|
|
219
|
-
}
|
|
220
|
-
if (ts.isInterfaceDeclaration(s)) {
|
|
221
|
-
return ts.factory.updateInterfaceDeclaration(s, modifiers, s.name, s.typeParameters, s.heritageClauses, s.members);
|
|
222
|
-
}
|
|
223
|
-
if (ts.isEnumDeclaration(s)) {
|
|
224
|
-
return ts.factory.updateEnumDeclaration(s, modifiers, s.name, s.members);
|
|
225
|
-
}
|
|
226
|
-
if (ts.isClassDeclaration(s)) {
|
|
227
|
-
return ts.factory.updateClassDeclaration(s, modifiers, s.name, s.typeParameters, s.heritageClauses, s.members);
|
|
228
|
-
}
|
|
229
|
-
if (ts.isFunctionDeclaration(s)) {
|
|
230
|
-
return ts.factory.updateFunctionDeclaration(s, modifiers, s.asteriskToken, s.name, s.typeParameters, s.parameters, s.type, s.body);
|
|
231
|
-
}
|
|
232
|
-
return s;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* @param {import("typescript").Statement} s
|
|
237
|
-
*/
|
|
238
|
-
function removeDeclareModifier(s) {
|
|
239
|
-
/** @type {import("typescript").Modifier[] | undefined} */
|
|
240
|
-
let modifiers;
|
|
241
|
-
// Remove declare modifiers
|
|
242
|
-
if (s.modifiers) {
|
|
243
|
-
modifiers = s.modifiers.filter(m => m.kind !== ts.SyntaxKind.DeclareKeyword);
|
|
244
|
-
} else {
|
|
245
|
-
return s;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if (ts.isVariableStatement(s)) {
|
|
249
|
-
return ts.factory.updateVariableStatement(s, modifiers, s.declarationList);
|
|
250
|
-
}
|
|
251
|
-
if (ts.isTypeAliasDeclaration(s)) {
|
|
252
|
-
return ts.factory.updateTypeAliasDeclaration(s, modifiers, s.name, s.typeParameters, s.type);
|
|
253
|
-
}
|
|
254
|
-
if (ts.isInterfaceDeclaration(s)) {
|
|
255
|
-
return ts.factory.updateInterfaceDeclaration(s, modifiers, s.name, s.typeParameters, s.heritageClauses, s.members);
|
|
256
|
-
}
|
|
257
|
-
if (ts.isEnumDeclaration(s)) {
|
|
258
|
-
return ts.factory.updateEnumDeclaration(s, modifiers, s.name, s.members);
|
|
259
|
-
}
|
|
260
|
-
if (ts.isClassDeclaration(s)) {
|
|
261
|
-
return ts.factory.updateClassDeclaration(s, modifiers, s.name, s.typeParameters, s.heritageClauses, s.members);
|
|
262
|
-
}
|
|
263
|
-
if (ts.isFunctionDeclaration(s)) {
|
|
264
|
-
return ts.factory.updateFunctionDeclaration(s, modifiers, s.asteriskToken, s.name, s.typeParameters, s.parameters, s.type, s.body);
|
|
265
|
-
}
|
|
266
|
-
return s;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// taken from node_modules\@types\node\globals.d.ts
|
|
270
|
-
// the globally available things must be wrapped in `declare global` if the user wants to augment them
|
|
271
|
-
const NodeJSGlobals = [
|
|
272
|
-
'Array',
|
|
273
|
-
'ArrayBuffer',
|
|
274
|
-
'Boolean',
|
|
275
|
-
'Buffer',
|
|
276
|
-
'DataView',
|
|
277
|
-
'Date',
|
|
278
|
-
'Error',
|
|
279
|
-
'EvalError',
|
|
280
|
-
'Float32Array',
|
|
281
|
-
'Float64Array',
|
|
282
|
-
'Function',
|
|
283
|
-
'GLOBAL',
|
|
284
|
-
'Infinity',
|
|
285
|
-
'Int16Array',
|
|
286
|
-
'Int32Array',
|
|
287
|
-
'Int8Array',
|
|
288
|
-
'Intl',
|
|
289
|
-
'JSON',
|
|
290
|
-
'Map',
|
|
291
|
-
'Math',
|
|
292
|
-
'NaN',
|
|
293
|
-
'Number',
|
|
294
|
-
'Object',
|
|
295
|
-
'Promise',
|
|
296
|
-
'RangeError',
|
|
297
|
-
'ReferenceError',
|
|
298
|
-
'RegExp',
|
|
299
|
-
'Set',
|
|
300
|
-
'String',
|
|
301
|
-
'Symbol',
|
|
302
|
-
'SyntaxError',
|
|
303
|
-
'TypeError',
|
|
304
|
-
'URIError',
|
|
305
|
-
'Uint16Array',
|
|
306
|
-
'Uint32Array',
|
|
307
|
-
'Uint8Array',
|
|
308
|
-
'Uint8ClampedArray',
|
|
309
|
-
'WeakMap',
|
|
310
|
-
'WeakSet',
|
|
311
|
-
'clearImmediate',
|
|
312
|
-
'clearInterval',
|
|
313
|
-
'clearTimeout',
|
|
314
|
-
'console',
|
|
315
|
-
'decodeURI',
|
|
316
|
-
'decodeURIComponent',
|
|
317
|
-
'encodeURI',
|
|
318
|
-
'encodeURIComponent',
|
|
319
|
-
'escape',
|
|
320
|
-
'eval',
|
|
321
|
-
'global',
|
|
322
|
-
'isFinite',
|
|
323
|
-
'isNaN',
|
|
324
|
-
'parseFloat',
|
|
325
|
-
'parseInt',
|
|
326
|
-
'process',
|
|
327
|
-
'root',
|
|
328
|
-
'setImmediate',
|
|
329
|
-
'setInterval',
|
|
330
|
-
'setTimeout',
|
|
331
|
-
'queueMicrotask',
|
|
332
|
-
'undefined',
|
|
333
|
-
'unescape',
|
|
334
|
-
'gc',
|
|
335
|
-
'v8debug',
|
|
336
|
-
];
|
|
337
|
-
|
|
338
|
-
/** @param {import("typescript").Statement} s */
|
|
339
|
-
function isGlobalAugmentation(s) {
|
|
340
|
-
return (
|
|
341
|
-
(ts.isInterfaceDeclaration(s) || ts.isClassDeclaration(s) || ts.isFunctionDeclaration(s))
|
|
342
|
-
&& s.name && NodeJSGlobals.includes(s.name.text)
|
|
343
|
-
);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/** @param {import("typescript").Statement[]} statements */
|
|
347
|
-
function wrapInDeclareGlobal(statements) {
|
|
348
|
-
return ts.factory.createModuleDeclaration(
|
|
349
|
-
[ts.factory.createModifier(ts.SyntaxKind.DeclareKeyword)],
|
|
350
|
-
ts.factory.createIdentifier('global'),
|
|
351
|
-
ts.factory.createModuleBlock(statements),
|
|
352
|
-
ts.NodeFlags.GlobalAugmentation
|
|
353
|
-
);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* Takes a TypeScript script and does the necessary transformations, so it can be compiled properly
|
|
358
|
-
* @param {string} source The original TypeScript source
|
|
359
|
-
* @param {boolean} isGlobal Whether the transformed script is a global script or not
|
|
360
|
-
* @returns {string}
|
|
361
|
-
*/
|
|
362
|
-
function transformScriptBeforeCompilation(source, isGlobal) {
|
|
363
|
-
/**
|
|
364
|
-
* @type {import("typescript").TransformerFactory<import("typescript").SourceFile>}
|
|
365
|
-
*/
|
|
366
|
-
// eslint-disable-next-line no-unused-vars
|
|
367
|
-
const transformer = _context => {
|
|
368
|
-
return sourceFile =>
|
|
369
|
-
ts.visitNode(sourceFile, node => {
|
|
370
|
-
if (ts.isSourceFile(node)) {
|
|
371
|
-
// Wrap all declarations that augment global interfaces in `declare global`
|
|
372
|
-
const augmentations = node.statements.filter((s) => isGlobalAugmentation(s));
|
|
373
|
-
const nonAugmentations = node.statements.filter((s) => !isGlobalAugmentation(s));
|
|
374
|
-
|
|
375
|
-
// If there is no top level await, don't move all the statements around
|
|
376
|
-
const hasTLA = node.statements.some(s => ts.isExpressionStatement(s) && s.expression.kind === ts.SyntaxKind.AwaitExpression);
|
|
377
|
-
// Move all statements to the top of the file that cannot appear in a function body
|
|
378
|
-
let hoistedStatements = hasTLA ? ts.factory.createNodeArray(nonAugmentations.filter((s) => mustBeHoisted(s, isGlobal))) : ts.factory.createNodeArray(nonAugmentations);
|
|
379
|
-
|
|
380
|
-
// The rest gets wrapped
|
|
381
|
-
const wrappedStatements = hasTLA ? nonAugmentations.filter(s => !mustBeHoisted(s, isGlobal)) : [];
|
|
382
|
-
|
|
383
|
-
// When transforming global scripts, we need to do a couple of things
|
|
384
|
-
if (isGlobal) {
|
|
385
|
-
// 1. We need to add an export modifier to everything on the top level that can be exported
|
|
386
|
-
hoistedStatements = ts.visitNodes(
|
|
387
|
-
hoistedStatements,
|
|
388
|
-
// @ts-expect-error s is definitely a statement
|
|
389
|
-
s => canBeExported(s) ? addExportModifier(s) : s,
|
|
390
|
-
);
|
|
391
|
-
// 3. We need to transform the generated declarations to use `declare global` (this will happen in transformGlobalDeclarations)
|
|
392
|
-
}
|
|
393
|
-
const needsEmptyExport =
|
|
394
|
-
// An empty export is needed when there is no import declaration
|
|
395
|
-
!node.statements.some(s => ts.isImportDeclaration(s) || ts.isImportEqualsDeclaration(s))
|
|
396
|
-
&& (
|
|
397
|
-
// And there is no statement in a global script which had an export modifier added
|
|
398
|
-
!(isGlobal && hoistedStatements.some(s => s.modifiers && s.modifiers.some(m => m.kind === ts.SyntaxKind.ExportKeyword)))
|
|
399
|
-
// Or if there is a `declare global` statement
|
|
400
|
-
|| !!augmentations
|
|
401
|
-
);
|
|
402
|
-
|
|
403
|
-
return ts.factory.updateSourceFile(node, [
|
|
404
|
-
// Put the hoisted statements at the top (or all of them if there's no top level await)
|
|
405
|
-
...hoistedStatements,
|
|
406
|
-
// Then add everything that augments the global scope
|
|
407
|
-
...(augmentations && augmentations.length ? [wrapInDeclareGlobal(augmentations)] : []),
|
|
408
|
-
...(hasTLA
|
|
409
|
-
? // If there is a top-level await, wrap all non-hoisted statements in (async () => { ... })();
|
|
410
|
-
[
|
|
411
|
-
ts.factory.createExpressionStatement(
|
|
412
|
-
ts.factory.createCallExpression(
|
|
413
|
-
ts.factory.createArrowFunction(
|
|
414
|
-
[
|
|
415
|
-
ts.factory.createModifier(
|
|
416
|
-
ts.SyntaxKind.AsyncKeyword
|
|
417
|
-
),
|
|
418
|
-
],
|
|
419
|
-
undefined,
|
|
420
|
-
[],
|
|
421
|
-
undefined,
|
|
422
|
-
undefined,
|
|
423
|
-
ts.factory.createBlock(wrappedStatements)
|
|
424
|
-
),
|
|
425
|
-
undefined,
|
|
426
|
-
undefined
|
|
427
|
-
)
|
|
428
|
-
),
|
|
429
|
-
]
|
|
430
|
-
: []),
|
|
431
|
-
...(needsEmptyExport
|
|
432
|
-
? [
|
|
433
|
-
// Put an empty export {}; at the bottom to force TypeScript to treat the script as a module
|
|
434
|
-
ts.factory.createExportDeclaration(
|
|
435
|
-
undefined,
|
|
436
|
-
undefined,
|
|
437
|
-
ts.factory.createNamedExports([]),
|
|
438
|
-
undefined,
|
|
439
|
-
undefined
|
|
440
|
-
),
|
|
441
|
-
]
|
|
442
|
-
: []),
|
|
443
|
-
]);
|
|
444
|
-
} else {
|
|
445
|
-
return node;
|
|
446
|
-
}
|
|
447
|
-
});
|
|
448
|
-
};
|
|
449
|
-
|
|
450
|
-
const sourceFile = ts.createSourceFile(
|
|
451
|
-
'index.ts',
|
|
452
|
-
source,
|
|
453
|
-
ts.ScriptTarget.ESNext,
|
|
454
|
-
/* setParentNodes */ true,
|
|
455
|
-
);
|
|
456
|
-
|
|
457
|
-
const result = ts.transform(sourceFile, [transformer]);
|
|
458
|
-
return ts.createPrinter().printNode(ts.EmitHint.Unspecified, result.transformed[0], sourceFile);
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* Takes the global declarations for a TypeScript and wraps export statements in `declare global`
|
|
463
|
-
* @param {string} decl The untransformed global declarations
|
|
464
|
-
* @returns {string}
|
|
465
|
-
*/
|
|
466
|
-
function transformGlobalDeclarations(decl) {
|
|
467
|
-
/**
|
|
468
|
-
* @type {import("typescript").TransformerFactory<import("typescript").SourceFile>}
|
|
469
|
-
*/
|
|
470
|
-
// eslint-disable-next-line no-unused-vars
|
|
471
|
-
const transformer = context => {
|
|
472
|
-
return sourceFile =>
|
|
473
|
-
ts.visitNode(sourceFile, (node) => {
|
|
474
|
-
if (ts.isSourceFile(node)) {
|
|
475
|
-
// All non-export-statements stay at the root level, the rest is wrapped in `declare global`
|
|
476
|
-
const exportStatements = node.statements.filter(s => s.modifiers && s.modifiers.some(m => m.kind === ts.SyntaxKind.ExportKeyword));
|
|
477
|
-
const otherStatements = node.statements.filter(s => !exportStatements.includes(s));
|
|
478
|
-
|
|
479
|
-
const hasExportStatements = exportStatements.length > 0;
|
|
480
|
-
const hasImport = otherStatements.some(s => ts.isImportDeclaration(s) || ts.isImportEqualsDeclaration(s));
|
|
481
|
-
|
|
482
|
-
return ts.factory.updateSourceFile(node, [
|
|
483
|
-
...otherStatements,
|
|
484
|
-
...(hasExportStatements ? [wrapInDeclareGlobal(exportStatements.map((s) => removeDeclareModifier(s)))] : []),
|
|
485
|
-
...(hasImport
|
|
486
|
-
? [] // If there is an import, the script is already treated as a module
|
|
487
|
-
: [
|
|
488
|
-
// Otherwise put an empty export {}; at the bottom to force TypeScript to treat the script as a module
|
|
489
|
-
ts.factory.createExportDeclaration(
|
|
490
|
-
undefined,
|
|
491
|
-
undefined,
|
|
492
|
-
ts.factory.createNamedExports([]),
|
|
493
|
-
undefined,
|
|
494
|
-
undefined,
|
|
495
|
-
),
|
|
496
|
-
]),
|
|
497
|
-
]);
|
|
498
|
-
} else {
|
|
499
|
-
return node;
|
|
500
|
-
}
|
|
501
|
-
});
|
|
502
|
-
};
|
|
503
|
-
|
|
504
|
-
const sourceFile = ts.createSourceFile(
|
|
505
|
-
'index.d.ts',
|
|
506
|
-
decl,
|
|
507
|
-
ts.ScriptTarget.ESNext,
|
|
508
|
-
/* setParentNodes */ true,
|
|
509
|
-
);
|
|
510
|
-
|
|
511
|
-
const result = ts.transform(sourceFile, [transformer]);
|
|
512
|
-
return ts.createPrinter().printNode(ts.EmitHint.Unspecified, result.transformed[0], sourceFile);
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
/**
|
|
516
|
-
* Translates a script ID to a filename for the compiler
|
|
517
|
-
* @param {string} scriptID The ID of the script
|
|
518
|
-
*/
|
|
519
|
-
function scriptIdToTSFilename(scriptID) {
|
|
520
|
-
return `${scriptID.replace(/^script.js./, '').replace(/\./g, '/')}.ts`;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
module.exports = {
|
|
524
|
-
scriptIdToTSFilename,
|
|
525
|
-
resolveTypescriptLibs,
|
|
526
|
-
resolveTypings,
|
|
527
|
-
transformScriptBeforeCompilation,
|
|
528
|
-
transformGlobalDeclarations,
|
|
529
|
-
};
|
package/lib/utils.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('node:fs');
|
|
4
|
-
const path = require('node:path');
|
|
5
|
-
|
|
6
|
-
const EXIT_CODES = {
|
|
7
|
-
NO_ERROR: 0,
|
|
8
|
-
CANNOT_FIND_ADAPTER_DIR: 10
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* returns application name
|
|
13
|
-
*
|
|
14
|
-
* The name of the application can be different, and this function finds it out.
|
|
15
|
-
*
|
|
16
|
-
* @returns {string}
|
|
17
|
-
*/
|
|
18
|
-
function getAppName() {
|
|
19
|
-
const parts = __dirname.replace(/\\/g, '/').split('/');
|
|
20
|
-
return parts[parts.length - 2].split('.')[0];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* looks for js-controller home folder
|
|
25
|
-
*
|
|
26
|
-
* @param {boolean} isInstall
|
|
27
|
-
* @returns {string}
|
|
28
|
-
*/
|
|
29
|
-
function getControllerDir(isInstall) {
|
|
30
|
-
// Find the js-controller location
|
|
31
|
-
const possibilities = [
|
|
32
|
-
'iobroker.js-controller',
|
|
33
|
-
'ioBroker.js-controller',
|
|
34
|
-
];
|
|
35
|
-
/** @type {string} */
|
|
36
|
-
let controllerPath;
|
|
37
|
-
for (const pkg of possibilities) {
|
|
38
|
-
try {
|
|
39
|
-
const possiblePath = require.resolve(pkg);
|
|
40
|
-
if (fs.existsSync(possiblePath)) {
|
|
41
|
-
controllerPath = possiblePath;
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
} catch (e) { /* not found */ }
|
|
45
|
-
}
|
|
46
|
-
if (!controllerPath) {
|
|
47
|
-
if (!isInstall) {
|
|
48
|
-
console.log('Cannot find js-controller');
|
|
49
|
-
process.exit(EXIT_CODES.CANNOT_FIND_ADAPTER_DIR);
|
|
50
|
-
} else {
|
|
51
|
-
process.exit(EXIT_CODES.NO_ERROR);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
// we found the controller
|
|
55
|
-
return path.dirname(controllerPath);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* reads controller base settings
|
|
60
|
-
*
|
|
61
|
-
* @alias getConfig
|
|
62
|
-
* @returns {object}
|
|
63
|
-
*/
|
|
64
|
-
function getConfig() {
|
|
65
|
-
let configPath;
|
|
66
|
-
if (fs.existsSync(
|
|
67
|
-
configPath = path.join(controllerDir, 'conf', `${appName}.json`)
|
|
68
|
-
)) {
|
|
69
|
-
return JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
70
|
-
} else if (fs.existsSync(
|
|
71
|
-
configPath = path.join(controllerDir, 'conf', `${+appName.toLowerCase()}.json`)
|
|
72
|
-
)) {
|
|
73
|
-
return JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
74
|
-
} else {
|
|
75
|
-
throw new Error(`Cannot find ${controllerDir}/conf/${appName}.json`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
const appName = getAppName();
|
|
79
|
-
const controllerDir = getControllerDir(typeof process !== 'undefined' && process.argv && process.argv.indexOf('--install') !== -1);
|
|
80
|
-
const Adapter = require(path.join(controllerDir, 'lib/adapter.js'));
|
|
81
|
-
|
|
82
|
-
module.exports = {
|
|
83
|
-
controllerDir,
|
|
84
|
-
getConfig,
|
|
85
|
-
Adapter,
|
|
86
|
-
appName
|
|
87
|
-
};
|