@platforma-sdk/tengo-builder 1.17.5 → 1.17.7
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/dist/commands/build.d.ts +4 -4
- package/dist/commands/build.d.ts.map +1 -1
- package/dist/commands/check.d.ts +1 -1
- package/dist/commands/dump/all.d.ts.map +1 -1
- package/dist/commands/dump/assets.d.ts.map +1 -1
- package/dist/commands/dump/libs.d.ts.map +1 -1
- package/dist/commands/dump/software.d.ts.map +1 -1
- package/dist/commands/dump/templates.d.ts.map +1 -1
- package/dist/commands/dump/tests.d.ts.map +1 -1
- package/dist/commands/test.d.ts +1 -1
- package/dist/compiler/artifactset.d.ts.map +1 -1
- package/dist/compiler/compiler.d.ts.map +1 -1
- package/dist/compiler/compileroptions.d.ts.map +1 -1
- package/dist/compiler/main.d.ts.map +1 -1
- package/dist/compiler/source.d.ts.map +1 -1
- package/dist/compiler/test.artifacts.d.ts.map +1 -1
- package/dist/compiler/util.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -47
- package/dist/index.mjs.map +1 -1
- package/dist/shared/basecmd.d.ts +4 -4
- package/dist/shared/basecmd.d.ts.map +1 -1
- package/dist/shared/dump.d.ts.map +1 -1
- package/dist/shared/proc.d.ts +2 -2
- package/dist/shared/proc.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/commands/build.ts +12 -11
- package/src/commands/check.ts +2 -2
- package/src/commands/dump/all.ts +8 -8
- package/src/commands/dump/assets.ts +8 -8
- package/src/commands/dump/libs.ts +11 -12
- package/src/commands/dump/software.ts +8 -8
- package/src/commands/dump/templates.ts +8 -9
- package/src/commands/dump/tests.ts +8 -8
- package/src/commands/test.ts +1 -1
- package/src/compiler/artifactset.ts +14 -13
- package/src/compiler/compiler.ts +62 -56
- package/src/compiler/compileroptions.ts +12 -12
- package/src/compiler/main.ts +29 -27
- package/src/compiler/package.ts +1 -1
- package/src/compiler/source.ts +53 -51
- package/src/compiler/test.artifacts.ts +24 -24
- package/src/compiler/util.ts +7 -5
- package/src/shared/basecmd.ts +16 -16
- package/src/shared/dump.ts +22 -21
- package/src/shared/proc.ts +6 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TemplateData, TemplateLibData } from '@milaboratories/pl-model-backend';
|
|
2
|
-
import { CompilerOption } from './package';
|
|
1
|
+
import type { TemplateData, TemplateLibData } from '@milaboratories/pl-model-backend';
|
|
2
|
+
import type { CompilerOption } from './package';
|
|
3
3
|
import * as util from './util';
|
|
4
4
|
|
|
5
5
|
export function applyTemplateCompilerOptions(opts: CompilerOption[], tpl: TemplateData) {
|
|
@@ -18,10 +18,10 @@ export function applyLibraryCompilerOptions(opts: CompilerOption[], lib: Templat
|
|
|
18
18
|
switch (opt.name) {
|
|
19
19
|
case 'hash_override': {
|
|
20
20
|
throw new Error(
|
|
21
|
-
`hash_override compiler option can be used ONLY on template level. Even in templates it is already dangerous enough`
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
`hash_override compiler option can be used ONLY on template level. Even in templates it is already dangerous enough`
|
|
22
|
+
+ ` to potentially break everything in Platforma Backend. In libraries with the transitive dependencies`
|
|
23
|
+
+ ` resolution and flattening of libraries list on template level, it becomes so unpredictibally disasterous, that`
|
|
24
|
+
+ ` we are doomed to never find the ends of a knot if anything goes wrong.`,
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -31,7 +31,7 @@ export function applyLibraryCompilerOptions(opts: CompilerOption[], lib: Templat
|
|
|
31
31
|
export function hashOverride(args: string[]): string {
|
|
32
32
|
if (args.length != 1) {
|
|
33
33
|
throw new Error(
|
|
34
|
-
'hash_override compiler option expects exactly one argument: hash_override <some string>. Note, you can use only UUID as a value.'
|
|
34
|
+
'hash_override compiler option expects exactly one argument: hash_override <some string>. Note, you can use only UUID as a value.',
|
|
35
35
|
);
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -39,11 +39,11 @@ export function hashOverride(args: string[]): string {
|
|
|
39
39
|
|
|
40
40
|
if (!util.isUUID(override)) {
|
|
41
41
|
throw new Error(
|
|
42
|
-
'hash_override must contain valid UUID as an override. As hash_override affects deduplication,'
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
'hash_override must contain valid UUID as an override. As hash_override affects deduplication,'
|
|
43
|
+
+ ' it becomes completely not possible to distinguish several different templates from each other on backend\'s side.'
|
|
44
|
+
+ ' This means, if you set hash_override to a simple value (say, letter "a") on two completely different templates,'
|
|
45
|
+
+ ' they will be marked as interchangeable on backend\'s side with unpredictable consequences.'
|
|
46
|
+
+ ' UUID looks like a safe enough tradeoff between the feature usage simplicity and duplication safety',
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
49
|
|
package/src/compiler/main.ts
CHANGED
|
@@ -3,17 +3,19 @@
|
|
|
3
3
|
import * as path from 'node:path';
|
|
4
4
|
import * as fs from 'node:fs';
|
|
5
5
|
import { findNodeModules, pathType } from './util';
|
|
6
|
-
import { TemplatesAndLibs
|
|
6
|
+
import type { TemplatesAndLibs } from './compiler';
|
|
7
|
+
import { TengoTemplateCompiler } from './compiler';
|
|
8
|
+
import type {
|
|
9
|
+
CompileMode,
|
|
10
|
+
FullArtifactName } from './package';
|
|
7
11
|
import {
|
|
8
12
|
artifactNameToString,
|
|
9
|
-
CompileMode,
|
|
10
|
-
FullArtifactName,
|
|
11
13
|
fullNameToString,
|
|
12
|
-
typedArtifactNameToString
|
|
14
|
+
typedArtifactNameToString,
|
|
13
15
|
} from './package';
|
|
14
16
|
import { ArtifactSource, parseSourceFile } from './source';
|
|
15
17
|
import { Template } from './template';
|
|
16
|
-
import winston from 'winston';
|
|
18
|
+
import type winston from 'winston';
|
|
17
19
|
|
|
18
20
|
interface PackageJson {
|
|
19
21
|
name: string;
|
|
@@ -38,7 +40,7 @@ const srcAssetSuffix = '.as.json';
|
|
|
38
40
|
const compilableSuffixes = [srcLibSuffix, srcTplSuffix, srcSoftwareSuffix, srcAssetSuffix];
|
|
39
41
|
|
|
40
42
|
export function getPackageInfo(): PackageJson {
|
|
41
|
-
const packageInfo: PackageJson = JSON.parse(fs.readFileSync('package.json').toString());
|
|
43
|
+
const packageInfo: PackageJson = JSON.parse(fs.readFileSync('package.json').toString()) as PackageJson;
|
|
42
44
|
return packageInfo;
|
|
43
45
|
}
|
|
44
46
|
|
|
@@ -63,7 +65,7 @@ function loadDependencies(
|
|
|
63
65
|
compiler: TengoTemplateCompiler,
|
|
64
66
|
packageInfo: PackageJson,
|
|
65
67
|
searchIn: string,
|
|
66
|
-
isLink: boolean = false
|
|
68
|
+
isLink: boolean = false,
|
|
67
69
|
): void {
|
|
68
70
|
const packageJsonPath = path.resolve(searchIn, 'package.json');
|
|
69
71
|
|
|
@@ -98,14 +100,14 @@ function loadDependencies(
|
|
|
98
100
|
return;
|
|
99
101
|
|
|
100
102
|
// we are in tengo dependency folder
|
|
101
|
-
const packageJson: PackageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString());
|
|
103
|
+
const packageJson: PackageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString()) as PackageJson;
|
|
102
104
|
|
|
103
105
|
// in a workspace we will find ourselves in node_modules, ignoring
|
|
104
106
|
if (packageJson.name === packageInfo.name) return;
|
|
105
107
|
|
|
106
108
|
if (pathType(path.resolve(searchIn, 'node_modules')) === 'dir' && isLink)
|
|
107
109
|
throw new Error(
|
|
108
|
-
`nested node_modules is a sign of library dependencies version incompatibility in ${searchIn}
|
|
110
|
+
`nested node_modules is a sign of library dependencies version incompatibility in ${searchIn}`,
|
|
109
111
|
);
|
|
110
112
|
|
|
111
113
|
if (libDistExists) {
|
|
@@ -130,7 +132,7 @@ function loadLibsFromDir(
|
|
|
130
132
|
packageJson: PackageJson,
|
|
131
133
|
mode: CompileMode,
|
|
132
134
|
folder: string,
|
|
133
|
-
compiler: TengoTemplateCompiler
|
|
135
|
+
compiler: TengoTemplateCompiler,
|
|
134
136
|
) {
|
|
135
137
|
for (const f of fs.readdirSync(folder)) {
|
|
136
138
|
const file = path.resolve(folder, f);
|
|
@@ -139,7 +141,7 @@ function loadLibsFromDir(
|
|
|
139
141
|
type: 'library',
|
|
140
142
|
pkg: packageJson.name,
|
|
141
143
|
id: f.slice(0, f.length - compiledLibSuffix.length),
|
|
142
|
-
version: packageJson.version
|
|
144
|
+
version: packageJson.version,
|
|
143
145
|
};
|
|
144
146
|
const src = parseSourceFile(logger, mode, file, fullName, true);
|
|
145
147
|
compiler.addLib(src);
|
|
@@ -156,7 +158,7 @@ function loadTemplatesFromDir(
|
|
|
156
158
|
packageJson: PackageJson,
|
|
157
159
|
mode: CompileMode,
|
|
158
160
|
folder: string,
|
|
159
|
-
compiler: TengoTemplateCompiler
|
|
161
|
+
compiler: TengoTemplateCompiler,
|
|
160
162
|
) {
|
|
161
163
|
// adding templates
|
|
162
164
|
for (const f of fs.readdirSync(folder)) {
|
|
@@ -166,7 +168,7 @@ function loadTemplatesFromDir(
|
|
|
166
168
|
type: 'template',
|
|
167
169
|
pkg: packageJson.name,
|
|
168
170
|
id: f.slice(0, f.length - compiledTplSuffix.length),
|
|
169
|
-
version: packageJson.version
|
|
171
|
+
version: packageJson.version,
|
|
170
172
|
};
|
|
171
173
|
const tpl = new Template(mode, fullName, { content: fs.readFileSync(file) });
|
|
172
174
|
compiler.addTemplate(tpl);
|
|
@@ -179,7 +181,7 @@ function loadSoftwareFromDir(
|
|
|
179
181
|
packageJson: PackageJson,
|
|
180
182
|
mode: CompileMode,
|
|
181
183
|
folder: string,
|
|
182
|
-
compiler: TengoTemplateCompiler
|
|
184
|
+
compiler: TengoTemplateCompiler,
|
|
183
185
|
) {
|
|
184
186
|
for (const f of fs.readdirSync(folder)) {
|
|
185
187
|
const file = path.resolve(folder, f);
|
|
@@ -189,7 +191,7 @@ function loadSoftwareFromDir(
|
|
|
189
191
|
type: 'software',
|
|
190
192
|
pkg: packageJson.name,
|
|
191
193
|
id: f.slice(0, f.length - compiledSoftwareSuffix.length),
|
|
192
|
-
version: packageJson.version
|
|
194
|
+
version: packageJson.version,
|
|
193
195
|
};
|
|
194
196
|
|
|
195
197
|
const software = new ArtifactSource(mode, fullName, fs.readFileSync(file).toString(), file, [], []);
|
|
@@ -204,7 +206,7 @@ function loadAssetsFromDir(
|
|
|
204
206
|
packageJson: PackageJson,
|
|
205
207
|
mode: CompileMode,
|
|
206
208
|
folder: string,
|
|
207
|
-
compiler: TengoTemplateCompiler
|
|
209
|
+
compiler: TengoTemplateCompiler,
|
|
208
210
|
) {
|
|
209
211
|
for (const f of fs.readdirSync(folder)) {
|
|
210
212
|
const file = path.resolve(folder, f);
|
|
@@ -214,7 +216,7 @@ function loadAssetsFromDir(
|
|
|
214
216
|
type: 'asset',
|
|
215
217
|
pkg: packageJson.name,
|
|
216
218
|
id: f.slice(0, f.length - compiledAssetSuffix.length),
|
|
217
|
-
version: packageJson.version
|
|
219
|
+
version: packageJson.version,
|
|
218
220
|
};
|
|
219
221
|
|
|
220
222
|
const asset = new ArtifactSource(mode, fullName, fs.readFileSync(file).toString(), file, [], []);
|
|
@@ -229,7 +231,7 @@ export function parseSources(
|
|
|
229
231
|
packageInfo: PackageJson,
|
|
230
232
|
mode: CompileMode,
|
|
231
233
|
root: string,
|
|
232
|
-
subdir: string
|
|
234
|
+
subdir: string,
|
|
233
235
|
): ArtifactSource[] {
|
|
234
236
|
const sources: ArtifactSource[] = [];
|
|
235
237
|
|
|
@@ -243,8 +245,8 @@ export function parseSources(
|
|
|
243
245
|
continue;
|
|
244
246
|
}
|
|
245
247
|
|
|
246
|
-
const artifactName
|
|
247
|
-
f === 'index.lib.tengo' ? `${path.dirname(inRootPath)}.lib.tengo` : inRootPath;
|
|
248
|
+
const artifactName
|
|
249
|
+
= f === 'index.lib.tengo' ? `${path.dirname(inRootPath)}.lib.tengo` : inRootPath;
|
|
248
250
|
|
|
249
251
|
const fullName = fullNameFromFileName(packageInfo, artifactName.replaceAll(path.sep, '.'));
|
|
250
252
|
if (!fullName) {
|
|
@@ -275,7 +277,7 @@ export function parseSources(
|
|
|
275
277
|
export function newCompiler(
|
|
276
278
|
logger: winston.Logger,
|
|
277
279
|
packageInfo: PackageJson,
|
|
278
|
-
mode: CompileMode
|
|
280
|
+
mode: CompileMode,
|
|
279
281
|
): TengoTemplateCompiler {
|
|
280
282
|
const compiler = new TengoTemplateCompiler(mode);
|
|
281
283
|
|
|
@@ -287,14 +289,14 @@ export function newCompiler(
|
|
|
287
289
|
|
|
288
290
|
function fullNameFromFileName(
|
|
289
291
|
packageJson: PackageJson,
|
|
290
|
-
artifactName: string
|
|
292
|
+
artifactName: string,
|
|
291
293
|
): FullArtifactName | null {
|
|
292
294
|
const pkgAndVersion = { pkg: packageJson.name, version: packageJson.version };
|
|
293
295
|
if (artifactName.endsWith(srcLibSuffix)) {
|
|
294
296
|
return {
|
|
295
297
|
...pkgAndVersion,
|
|
296
298
|
id: artifactName.substring(0, artifactName.length - srcLibSuffix.length),
|
|
297
|
-
type: 'library'
|
|
299
|
+
type: 'library',
|
|
298
300
|
};
|
|
299
301
|
}
|
|
300
302
|
|
|
@@ -302,7 +304,7 @@ function fullNameFromFileName(
|
|
|
302
304
|
return {
|
|
303
305
|
...pkgAndVersion,
|
|
304
306
|
id: artifactName.substring(0, artifactName.length - srcTplSuffix.length),
|
|
305
|
-
type: 'template'
|
|
307
|
+
type: 'template',
|
|
306
308
|
};
|
|
307
309
|
}
|
|
308
310
|
|
|
@@ -310,7 +312,7 @@ function fullNameFromFileName(
|
|
|
310
312
|
return {
|
|
311
313
|
...pkgAndVersion,
|
|
312
314
|
id: artifactName.substring(0, artifactName.length - srcSoftwareSuffix.length),
|
|
313
|
-
type: 'software'
|
|
315
|
+
type: 'software',
|
|
314
316
|
};
|
|
315
317
|
}
|
|
316
318
|
|
|
@@ -318,7 +320,7 @@ function fullNameFromFileName(
|
|
|
318
320
|
return {
|
|
319
321
|
...pkgAndVersion,
|
|
320
322
|
id: artifactName.substring(0, artifactName.length - srcAssetSuffix.length),
|
|
321
|
-
type: 'asset'
|
|
323
|
+
type: 'asset',
|
|
322
324
|
};
|
|
323
325
|
}
|
|
324
326
|
|
|
@@ -326,7 +328,7 @@ function fullNameFromFileName(
|
|
|
326
328
|
return {
|
|
327
329
|
...pkgAndVersion,
|
|
328
330
|
id: artifactName.substring(0, artifactName.length - srcTestSuffix.length),
|
|
329
|
-
type: 'test'
|
|
331
|
+
type: 'test',
|
|
330
332
|
};
|
|
331
333
|
}
|
|
332
334
|
|
package/src/compiler/package.ts
CHANGED
|
@@ -67,7 +67,7 @@ export function typedArtifactNameToString(name: TypedArtifactName): string {
|
|
|
67
67
|
|
|
68
68
|
export function typedArtifactNamesEquals(
|
|
69
69
|
name1: TypedArtifactName,
|
|
70
|
-
name2: TypedArtifactName
|
|
70
|
+
name2: TypedArtifactName,
|
|
71
71
|
): boolean {
|
|
72
72
|
return name1.type == name2.type && name1.pkg == name2.pkg && name1.id == name2.id;
|
|
73
73
|
}
|
package/src/compiler/source.ts
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
|
-
import winston from 'winston';
|
|
3
|
-
import {
|
|
2
|
+
import type winston from 'winston';
|
|
3
|
+
import type {
|
|
4
4
|
TypedArtifactName,
|
|
5
5
|
FullArtifactName,
|
|
6
6
|
ArtifactType,
|
|
7
7
|
CompileMode,
|
|
8
|
-
CompilerOption
|
|
8
|
+
CompilerOption,
|
|
9
9
|
} from './package';
|
|
10
|
-
import { ArtifactMap
|
|
10
|
+
import type { ArtifactMap } from './artifactset';
|
|
11
|
+
import { createArtifactNameSet } from './artifactset';
|
|
11
12
|
|
|
12
13
|
// matches any valid name in tengo. Don't forget to use '\b' when needed to limit the boundaries!
|
|
13
14
|
const namePattern = '[_a-zA-Z][_a-zA-Z0-9]*';
|
|
14
15
|
|
|
15
16
|
const functionCallRE = (moduleName: string, fnName: string) => {
|
|
16
17
|
return new RegExp(
|
|
17
|
-
`\\b${moduleName}\\.(?<fnCall>(?<fnName>`
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
`\\b${moduleName}\\.(?<fnCall>(?<fnName>`
|
|
19
|
+
+ fnName
|
|
20
|
+
+ `)\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))`,
|
|
20
21
|
);
|
|
21
22
|
};
|
|
22
23
|
|
|
@@ -45,7 +46,7 @@ const multilineCommentStartRE = /^\s*\/\*/;
|
|
|
45
46
|
const multilineCommentEndRE = /\*\//;
|
|
46
47
|
const importRE = /\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/;
|
|
47
48
|
const importNameRE = new RegExp(
|
|
48
|
-
`\\b(?<importName>${namePattern}(\\.${namePattern})*)${importRE.source}
|
|
49
|
+
`\\b(?<importName>${namePattern}(\\.${namePattern})*)${importRE.source}`,
|
|
49
50
|
);
|
|
50
51
|
const dependencyRE = /(?<pkgName>[^"]+)?:(?<depID>[^"]+)/; // use it to parse <moduleName> from importPattern or <templateName> акщь getTemplateID
|
|
51
52
|
|
|
@@ -62,14 +63,14 @@ const parseComplierOption = (opt: string): CompilerOption => {
|
|
|
62
63
|
const namePart = parts[0].split(':');
|
|
63
64
|
if (namePart.length != 2) {
|
|
64
65
|
throw new Error(
|
|
65
|
-
|
|
66
|
+
'compiler option format is wrong: expect to have option name after \'tengo:\' prefix, like \'tengo:MyOption\'',
|
|
66
67
|
);
|
|
67
68
|
}
|
|
68
69
|
const optName = namePart[1];
|
|
69
70
|
|
|
70
71
|
return {
|
|
71
72
|
name: optName,
|
|
72
|
-
args: parts.slice(1)
|
|
73
|
+
args: parts.slice(1),
|
|
73
74
|
};
|
|
74
75
|
};
|
|
75
76
|
|
|
@@ -86,7 +87,7 @@ export class ArtifactSource {
|
|
|
86
87
|
/** List of dependencies */
|
|
87
88
|
public readonly dependencies: TypedArtifactName[],
|
|
88
89
|
/** Additional compiler options detected in source code */
|
|
89
|
-
public readonly compilerOptions: CompilerOption[]
|
|
90
|
+
public readonly compilerOptions: CompilerOption[],
|
|
90
91
|
) {}
|
|
91
92
|
}
|
|
92
93
|
|
|
@@ -95,7 +96,7 @@ export function parseSourceFile(
|
|
|
95
96
|
mode: CompileMode,
|
|
96
97
|
srcFile: string,
|
|
97
98
|
fullSourceName: FullArtifactName,
|
|
98
|
-
normalize: boolean
|
|
99
|
+
normalize: boolean,
|
|
99
100
|
): ArtifactSource {
|
|
100
101
|
const src = readFileSync(srcFile).toString();
|
|
101
102
|
const { deps, normalized, opts } = parseSourceData(logger, src, fullSourceName, normalize);
|
|
@@ -108,7 +109,7 @@ export function parseSource(
|
|
|
108
109
|
mode: CompileMode,
|
|
109
110
|
src: string,
|
|
110
111
|
fullSourceName: FullArtifactName,
|
|
111
|
-
normalize: boolean
|
|
112
|
+
normalize: boolean,
|
|
112
113
|
): ArtifactSource {
|
|
113
114
|
const { deps, normalized, opts } = parseSourceData(logger, src, fullSourceName, normalize);
|
|
114
115
|
|
|
@@ -119,12 +120,12 @@ function parseSourceData(
|
|
|
119
120
|
logger: winston.Logger,
|
|
120
121
|
src: string,
|
|
121
122
|
fullSourceName: FullArtifactName,
|
|
122
|
-
globalizeImports: boolean
|
|
123
|
+
globalizeImports: boolean,
|
|
123
124
|
): {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
} {
|
|
125
|
+
normalized: string;
|
|
126
|
+
deps: ArtifactMap<TypedArtifactName>;
|
|
127
|
+
opts: CompilerOption[];
|
|
128
|
+
} {
|
|
128
129
|
const dependencySet = createArtifactNameSet();
|
|
129
130
|
const optionList: CompilerOption[] = [];
|
|
130
131
|
|
|
@@ -140,7 +141,7 @@ function parseSourceData(
|
|
|
140
141
|
isInCommentBlock: false,
|
|
141
142
|
canDetectOptions: true,
|
|
142
143
|
tplDepREs: new Map<string, [ArtifactType, RegExp][]>(),
|
|
143
|
-
lineNo: 0
|
|
144
|
+
lineNo: 0,
|
|
144
145
|
};
|
|
145
146
|
|
|
146
147
|
for (const line of lines) {
|
|
@@ -152,7 +153,7 @@ function parseSourceData(
|
|
|
152
153
|
line,
|
|
153
154
|
parserContext,
|
|
154
155
|
fullSourceName.pkg,
|
|
155
|
-
globalizeImports
|
|
156
|
+
globalizeImports,
|
|
156
157
|
);
|
|
157
158
|
processedLines.push(result.line);
|
|
158
159
|
parserContext = result.context;
|
|
@@ -163,15 +164,16 @@ function parseSourceData(
|
|
|
163
164
|
if (result.option) {
|
|
164
165
|
optionList.push(result.option);
|
|
165
166
|
}
|
|
166
|
-
} catch (error:
|
|
167
|
-
|
|
167
|
+
} catch (error: unknown) {
|
|
168
|
+
const err = error as Error;
|
|
169
|
+
throw new Error(`[line ${parserContext.lineNo}]: ${err.message}\n\t${line}`);
|
|
168
170
|
}
|
|
169
171
|
}
|
|
170
172
|
|
|
171
173
|
return {
|
|
172
174
|
normalized: processedLines.join('\n'),
|
|
173
175
|
deps: dependencySet,
|
|
174
|
-
opts: optionList
|
|
176
|
+
opts: optionList,
|
|
175
177
|
};
|
|
176
178
|
}
|
|
177
179
|
|
|
@@ -187,13 +189,13 @@ function parseSingleSourceLine(
|
|
|
187
189
|
line: string,
|
|
188
190
|
context: sourceParserContext,
|
|
189
191
|
localPackageName: string,
|
|
190
|
-
globalizeImports?: boolean
|
|
192
|
+
globalizeImports?: boolean,
|
|
191
193
|
): {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
} {
|
|
194
|
+
line: string;
|
|
195
|
+
context: sourceParserContext;
|
|
196
|
+
artifact: TypedArtifactName | undefined;
|
|
197
|
+
option: CompilerOption | undefined;
|
|
198
|
+
} {
|
|
197
199
|
if (context.isInCommentBlock) {
|
|
198
200
|
if (multilineCommentEndRE.exec(line)) {
|
|
199
201
|
context.isInCommentBlock = false;
|
|
@@ -204,16 +206,16 @@ function parseSingleSourceLine(
|
|
|
204
206
|
if (compilerOptionRE.exec(line)) {
|
|
205
207
|
if (!context.canDetectOptions) {
|
|
206
208
|
logger.error(
|
|
207
|
-
`[line ${context.lineNo}]: compiler option '//tengo:' was detected, but it cannot be applied as compiler options can be set only at the file header, before any code line'
|
|
209
|
+
`[line ${context.lineNo}]: compiler option '//tengo:' was detected, but it cannot be applied as compiler options can be set only at the file header, before any code line'`,
|
|
208
210
|
);
|
|
209
|
-
throw new Error(
|
|
211
|
+
throw new Error('tengo compiler options (\'//tengo:\' comments) can be set only in file header');
|
|
210
212
|
}
|
|
211
213
|
return { line, context, artifact: undefined, option: parseComplierOption(line) };
|
|
212
214
|
}
|
|
213
215
|
|
|
214
216
|
if (wrongCompilerOptionRE.exec(line) && context.canDetectOptions) {
|
|
215
217
|
logger.warn(
|
|
216
|
-
`[line ${context.lineNo}]: text simillar to compiler option ('//tengo:...') was detected, but it has wrong format. Leave it as is, if you did not mean to use a line as compiler option. Or format it to '//tengo:<option>' otherwise (no spaces between '//' and 'tengo', no spaces between ':' and option name)
|
|
218
|
+
`[line ${context.lineNo}]: text simillar to compiler option ('//tengo:...') was detected, but it has wrong format. Leave it as is, if you did not mean to use a line as compiler option. Or format it to '//tengo:<option>' otherwise (no spaces between '//' and 'tengo', no spaces between ':' and option name)`,
|
|
217
219
|
);
|
|
218
220
|
return { line, context, artifact: undefined, option: undefined };
|
|
219
221
|
}
|
|
@@ -242,39 +244,39 @@ function parseSingleSourceLine(
|
|
|
242
244
|
if (!context.tplDepREs.has(iInfo.module)) {
|
|
243
245
|
context.tplDepREs.set(iInfo.module, [
|
|
244
246
|
['template', newGetTemplateIdRE(iInfo.alias)],
|
|
245
|
-
['software', newGetSoftwareInfoRE(iInfo.alias)]
|
|
247
|
+
['software', newGetSoftwareInfoRE(iInfo.alias)],
|
|
246
248
|
]);
|
|
247
249
|
}
|
|
248
250
|
return { line, context, artifact: undefined, option: undefined };
|
|
249
251
|
}
|
|
250
252
|
|
|
251
253
|
if (
|
|
252
|
-
iInfo.module === '@milaboratory/tengo-sdk:ll'
|
|
253
|
-
iInfo.module === '@platforma-sdk/workflow-tengo:ll'
|
|
254
|
-
((localPackageName === '@milaboratory/tengo-sdk'
|
|
255
|
-
localPackageName === '@platforma-sdk/workflow-tengo')
|
|
256
|
-
|
|
254
|
+
iInfo.module === '@milaboratory/tengo-sdk:ll'
|
|
255
|
+
|| iInfo.module === '@platforma-sdk/workflow-tengo:ll'
|
|
256
|
+
|| ((localPackageName === '@milaboratory/tengo-sdk'
|
|
257
|
+
|| localPackageName === '@platforma-sdk/workflow-tengo')
|
|
258
|
+
&& iInfo.module === ':ll')
|
|
257
259
|
) {
|
|
258
260
|
if (!context.tplDepREs.has(iInfo.module)) {
|
|
259
261
|
context.tplDepREs.set(iInfo.module, [
|
|
260
262
|
['template', newImportTemplateRE(iInfo.alias)],
|
|
261
|
-
['software', newImportSoftwareRE(iInfo.alias)]
|
|
263
|
+
['software', newImportSoftwareRE(iInfo.alias)],
|
|
262
264
|
]);
|
|
263
265
|
}
|
|
264
266
|
}
|
|
265
267
|
|
|
266
268
|
if (
|
|
267
|
-
iInfo.module === '@milaboratory/tengo-sdk:assets'
|
|
268
|
-
iInfo.module === '@platforma-sdk/workflow-tengo:assets'
|
|
269
|
-
((localPackageName === '@milaboratory/tengo-sdk'
|
|
270
|
-
localPackageName === '@platforma-sdk/workflow-tengo')
|
|
271
|
-
|
|
269
|
+
iInfo.module === '@milaboratory/tengo-sdk:assets'
|
|
270
|
+
|| iInfo.module === '@platforma-sdk/workflow-tengo:assets'
|
|
271
|
+
|| ((localPackageName === '@milaboratory/tengo-sdk'
|
|
272
|
+
|| localPackageName === '@platforma-sdk/workflow-tengo')
|
|
273
|
+
&& iInfo.module === ':assets')
|
|
272
274
|
) {
|
|
273
275
|
if (!context.tplDepREs.has(iInfo.module)) {
|
|
274
276
|
context.tplDepREs.set(iInfo.module, [
|
|
275
277
|
['template', newImportTemplateRE(iInfo.alias)],
|
|
276
278
|
['software', newImportSoftwareRE(iInfo.alias)],
|
|
277
|
-
['asset', newImportAssetRE(iInfo.alias)]
|
|
279
|
+
['asset', newImportAssetRE(iInfo.alias)],
|
|
278
280
|
]);
|
|
279
281
|
}
|
|
280
282
|
}
|
|
@@ -342,14 +344,14 @@ function parseImport(line: string): ImportInfo {
|
|
|
342
344
|
|
|
343
345
|
return {
|
|
344
346
|
module: moduleName,
|
|
345
|
-
alias: importName
|
|
347
|
+
alias: importName,
|
|
346
348
|
};
|
|
347
349
|
}
|
|
348
350
|
|
|
349
351
|
function parseArtifactName(
|
|
350
352
|
moduleName: string,
|
|
351
353
|
aType: ArtifactType,
|
|
352
|
-
localPackageName: string
|
|
354
|
+
localPackageName: string,
|
|
353
355
|
): TypedArtifactName | undefined {
|
|
354
356
|
const depInfo = dependencyRE.exec(moduleName);
|
|
355
357
|
if (!depInfo) {
|
|
@@ -358,14 +360,14 @@ function parseArtifactName(
|
|
|
358
360
|
|
|
359
361
|
if (!depInfo.groups) {
|
|
360
362
|
throw Error(
|
|
361
|
-
`failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'
|
|
363
|
+
`failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'`,
|
|
362
364
|
);
|
|
363
365
|
}
|
|
364
366
|
|
|
365
367
|
const { pkgName, depID } = depInfo.groups;
|
|
366
368
|
if (!depID) {
|
|
367
369
|
throw Error(
|
|
368
|
-
`failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'
|
|
370
|
+
`failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'`,
|
|
369
371
|
);
|
|
370
372
|
}
|
|
371
373
|
|
|
@@ -382,14 +384,14 @@ function parseTemplateUse(match: RegExpExecArray, localPackageName: string): Typ
|
|
|
382
384
|
const depInfo = dependencyRE.exec(templateName);
|
|
383
385
|
if (!depInfo || !depInfo.groups) {
|
|
384
386
|
throw Error(
|
|
385
|
-
`failed to parse dependency name inside 'getTemplateId' statement. The dependency name should have format '<package>:<templateName>'
|
|
387
|
+
`failed to parse dependency name inside 'getTemplateId' statement. The dependency name should have format '<package>:<templateName>'`,
|
|
386
388
|
);
|
|
387
389
|
}
|
|
388
390
|
|
|
389
391
|
const { pkgName, depID } = depInfo.groups;
|
|
390
392
|
if (!pkgName || !depID) {
|
|
391
393
|
throw Error(
|
|
392
|
-
`failed to parse dependency name inside 'getTemplateId' statement. The dependency name should have format '<package>:<templateName>'
|
|
394
|
+
`failed to parse dependency name inside 'getTemplateId' statement. The dependency name should have format '<package>:<templateName>'`,
|
|
393
395
|
);
|
|
394
396
|
}
|
|
395
397
|
|