@tolgee/cli 1.1.0 → 1.1.2
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 +11 -8
- package/dist/client/errors.js +1 -5
- package/dist/client/export.js +1 -4
- package/dist/client/import.js +5 -11
- package/dist/client/index.js +17 -23
- package/dist/client/internal/requester.js +14 -20
- package/dist/client/internal/schema.generated.js +1 -2
- package/dist/client/internal/schema.utils.js +1 -2
- package/dist/client/languages.js +1 -4
- package/dist/client/project.js +1 -4
- package/dist/commands/extract/check.js +11 -13
- package/dist/commands/extract/print.js +10 -12
- package/dist/commands/extract.js +8 -13
- package/dist/commands/login.js +16 -22
- package/dist/commands/pull.js +12 -14
- package/dist/commands/push.js +28 -30
- package/dist/commands/sync/compare.js +18 -23
- package/dist/commands/sync/sync.js +34 -39
- package/dist/commands/sync/syncUtils.js +10 -18
- package/dist/config/credentials.js +16 -25
- package/dist/config/tolgeerc.js +11 -14
- package/dist/constants.js +11 -18
- package/dist/extractor/extractor.js +13 -19
- package/dist/extractor/index.js +1 -2
- package/dist/extractor/machines/comments.js +10 -15
- package/dist/extractor/machines/react.js +36 -41
- package/dist/extractor/machines/shared/comments.js +3 -6
- package/dist/extractor/machines/shared/properties.js +13 -15
- package/dist/extractor/machines/svelte.js +43 -48
- package/dist/extractor/runner.js +8 -16
- package/dist/extractor/tokenizer.js +20 -21
- package/dist/extractor/warnings.js +9 -14
- package/dist/extractor/worker.js +23 -28
- package/dist/index.js +53 -58
- package/dist/options.js +14 -17
- package/dist/utils/ask.js +4 -12
- package/dist/utils/configPath.js +10 -10
- package/dist/utils/deferred.js +1 -5
- package/dist/utils/logger.js +8 -19
- package/dist/utils/moduleLoader.js +7 -15
- package/dist/utils/overwriteDir.js +13 -17
- package/dist/utils/zip.js +11 -16
- package/package.json +33 -30
@@ -1,13 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
const xstate_1 = require("xstate");
|
7
|
-
const properties_1 = __importDefault(require("./shared/properties"));
|
8
|
-
const comments_1 = __importDefault(require("./shared/comments"));
|
1
|
+
import { createMachine, assign, send, forwardTo } from 'xstate';
|
2
|
+
import propertiesMachine from './shared/properties.js';
|
3
|
+
import commentsService from './shared/comments.js';
|
9
4
|
const VOID_KEY = { keyName: '', line: -1 };
|
10
|
-
|
5
|
+
export default createMachine({
|
11
6
|
predictableActionArguments: true,
|
12
7
|
id: 'svelteExtractor',
|
13
8
|
type: 'parallel',
|
@@ -15,7 +10,7 @@ exports.default = (0, xstate_1.createMachine)({
|
|
15
10
|
children: '',
|
16
11
|
line: 0,
|
17
12
|
key: VOID_KEY,
|
18
|
-
|
13
|
+
getTranslate: null,
|
19
14
|
ignore: null,
|
20
15
|
keys: [],
|
21
16
|
warnings: [],
|
@@ -24,7 +19,7 @@ exports.default = (0, xstate_1.createMachine)({
|
|
24
19
|
comments: {
|
25
20
|
invoke: {
|
26
21
|
id: 'comments',
|
27
|
-
src: () =>
|
22
|
+
src: () => commentsService,
|
28
23
|
},
|
29
24
|
on: {
|
30
25
|
// Service messages
|
@@ -43,21 +38,21 @@ exports.default = (0, xstate_1.createMachine)({
|
|
43
38
|
},
|
44
39
|
// Code messages
|
45
40
|
'comment.line.double-slash.ts': {
|
46
|
-
actions:
|
41
|
+
actions: send((_ctx, evt) => ({
|
47
42
|
type: 'COMMENT',
|
48
43
|
data: evt.token,
|
49
44
|
line: evt.line,
|
50
45
|
}), { to: 'comments' }),
|
51
46
|
},
|
52
47
|
'comment.block.ts': {
|
53
|
-
actions:
|
48
|
+
actions: send((_ctx, evt) => ({
|
54
49
|
type: 'COMMENT',
|
55
50
|
data: evt.token,
|
56
51
|
line: evt.line,
|
57
52
|
}), { to: 'comments' }),
|
58
53
|
},
|
59
54
|
'comment.block.svelte': {
|
60
|
-
actions:
|
55
|
+
actions: send((_ctx, evt) => ({
|
61
56
|
type: 'COMMENT',
|
62
57
|
data: evt.token,
|
63
58
|
line: evt.line,
|
@@ -69,7 +64,7 @@ exports.default = (0, xstate_1.createMachine)({
|
|
69
64
|
},
|
70
65
|
},
|
71
66
|
},
|
72
|
-
|
67
|
+
getTranslate: {
|
73
68
|
initial: 'idle',
|
74
69
|
states: {
|
75
70
|
idle: {
|
@@ -77,7 +72,7 @@ exports.default = (0, xstate_1.createMachine)({
|
|
77
72
|
'entity.name.function.ts': {
|
78
73
|
target: 'func',
|
79
74
|
actions: 'storeLine',
|
80
|
-
cond: (_ctx, evt) => evt.token === '
|
75
|
+
cond: (_ctx, evt) => evt.token === 'getTranslate',
|
81
76
|
},
|
82
77
|
},
|
83
78
|
},
|
@@ -108,12 +103,12 @@ exports.default = (0, xstate_1.createMachine)({
|
|
108
103
|
'punctuation.definition.string.template.begin.ts': 'namespace',
|
109
104
|
'variable.other.readwrite.ts': {
|
110
105
|
target: 'idle',
|
111
|
-
actions: ['
|
106
|
+
actions: ['storeGetTranslate', 'markGetTranslateAsDynamic'],
|
112
107
|
},
|
113
108
|
'meta.brace.round.ts': {
|
114
109
|
target: 'idle',
|
115
110
|
cond: (_ctx, evt) => evt.token === ')',
|
116
|
-
actions: '
|
111
|
+
actions: 'storeGetTranslate',
|
117
112
|
},
|
118
113
|
},
|
119
114
|
},
|
@@ -121,7 +116,7 @@ exports.default = (0, xstate_1.createMachine)({
|
|
121
116
|
on: {
|
122
117
|
'*': {
|
123
118
|
target: 'namespace_end',
|
124
|
-
actions: '
|
119
|
+
actions: 'storeNamespacedGetTranslate',
|
125
120
|
},
|
126
121
|
},
|
127
122
|
},
|
@@ -131,11 +126,11 @@ exports.default = (0, xstate_1.createMachine)({
|
|
131
126
|
'meta.brace.round.ts': 'idle',
|
132
127
|
'punctuation.definition.template-expression.begin.ts': {
|
133
128
|
target: 'idle',
|
134
|
-
actions: '
|
129
|
+
actions: 'markGetTranslateAsDynamic',
|
135
130
|
},
|
136
131
|
'keyword.operator.arithmetic.ts': {
|
137
132
|
target: 'idle',
|
138
|
-
actions: '
|
133
|
+
actions: 'markGetTranslateAsDynamic',
|
139
134
|
},
|
140
135
|
},
|
141
136
|
},
|
@@ -174,7 +169,7 @@ exports.default = (0, xstate_1.createMachine)({
|
|
174
169
|
props: {
|
175
170
|
invoke: {
|
176
171
|
id: 'propertiesMachine',
|
177
|
-
src:
|
172
|
+
src: propertiesMachine,
|
178
173
|
onDone: [
|
179
174
|
{
|
180
175
|
target: 'idle',
|
@@ -196,7 +191,7 @@ exports.default = (0, xstate_1.createMachine)({
|
|
196
191
|
},
|
197
192
|
on: {
|
198
193
|
'*': {
|
199
|
-
actions:
|
194
|
+
actions: forwardTo('propertiesMachine'),
|
200
195
|
},
|
201
196
|
},
|
202
197
|
},
|
@@ -209,7 +204,7 @@ exports.default = (0, xstate_1.createMachine)({
|
|
209
204
|
on: {
|
210
205
|
'punctuation.definition.variable.svelte': {
|
211
206
|
target: 'dollar',
|
212
|
-
cond: (ctx, evt) => ctx.
|
207
|
+
cond: (ctx, evt) => ctx.getTranslate !== null && evt.token === '$',
|
213
208
|
},
|
214
209
|
},
|
215
210
|
},
|
@@ -328,7 +323,7 @@ exports.default = (0, xstate_1.createMachine)({
|
|
328
323
|
param_object: {
|
329
324
|
invoke: {
|
330
325
|
id: 'propertiesMachine',
|
331
|
-
src:
|
326
|
+
src: propertiesMachine,
|
332
327
|
data: {
|
333
328
|
depth: 1,
|
334
329
|
},
|
@@ -346,7 +341,7 @@ exports.default = (0, xstate_1.createMachine)({
|
|
346
341
|
},
|
347
342
|
on: {
|
348
343
|
'*': {
|
349
|
-
actions:
|
344
|
+
actions: forwardTo('propertiesMachine'),
|
350
345
|
},
|
351
346
|
},
|
352
347
|
},
|
@@ -358,35 +353,35 @@ exports.default = (0, xstate_1.createMachine)({
|
|
358
353
|
isPropertiesDataDynamic: (_ctx, evt) => evt.data.keyName === false || evt.data.namespace === false,
|
359
354
|
},
|
360
355
|
actions: {
|
361
|
-
storeLine:
|
356
|
+
storeLine: assign({
|
362
357
|
line: (_ctx, evt) => evt.line,
|
363
358
|
}),
|
364
|
-
ignoreNextLine:
|
359
|
+
ignoreNextLine: assign({
|
365
360
|
ignore: (_ctx, evt) => ({ type: 'ignore', line: evt.line + 1 }),
|
366
361
|
}),
|
367
|
-
consumeIgnoredLine:
|
362
|
+
consumeIgnoredLine: assign({
|
368
363
|
ignore: (_ctx, _evt) => null,
|
369
364
|
}),
|
370
|
-
warnUnusedIgnore:
|
365
|
+
warnUnusedIgnore: assign({
|
371
366
|
warnings: (ctx, evt) => [
|
372
367
|
...ctx.warnings,
|
373
368
|
{ warning: 'W_UNUSED_IGNORE', line: evt.line - 1 },
|
374
369
|
],
|
375
370
|
}),
|
376
|
-
|
377
|
-
|
371
|
+
storeGetTranslate: assign({
|
372
|
+
getTranslate: (_ctx, _evt) => '',
|
378
373
|
}),
|
379
|
-
|
380
|
-
|
374
|
+
storeNamespacedGetTranslate: assign({
|
375
|
+
getTranslate: (_ctx, evt) => evt.token,
|
381
376
|
}),
|
382
|
-
|
383
|
-
|
377
|
+
markGetTranslateAsDynamic: assign({
|
378
|
+
getTranslate: (_ctx, _evt) => false,
|
384
379
|
warnings: (ctx, _evt) => [
|
385
380
|
...ctx.warnings,
|
386
381
|
{ warning: 'W_DYNAMIC_NAMESPACE', line: ctx.line },
|
387
382
|
],
|
388
383
|
}),
|
389
|
-
consumeParameters:
|
384
|
+
consumeParameters: assign({
|
390
385
|
key: (ctx, evt) => ({
|
391
386
|
keyName: ctx.key.keyName || evt.data.keyName,
|
392
387
|
defaultValue: ctx.key.defaultValue || evt.data.defaultValue || undefined,
|
@@ -402,7 +397,7 @@ exports.default = (0, xstate_1.createMachine)({
|
|
402
397
|
];
|
403
398
|
},
|
404
399
|
}),
|
405
|
-
emitWarningFromParameters:
|
400
|
+
emitWarningFromParameters: assign({
|
406
401
|
warnings: (ctx, evt) => [
|
407
402
|
...ctx.warnings,
|
408
403
|
{
|
@@ -414,40 +409,40 @@ exports.default = (0, xstate_1.createMachine)({
|
|
414
409
|
],
|
415
410
|
key: (_ctx, _evt) => VOID_KEY,
|
416
411
|
}),
|
417
|
-
storeKeyName:
|
412
|
+
storeKeyName: assign({
|
418
413
|
key: (ctx, evt) => ({ ...ctx.key, keyName: evt.token }),
|
419
414
|
}),
|
420
|
-
storeKeyDefault:
|
415
|
+
storeKeyDefault: assign({
|
421
416
|
key: (ctx, evt) => ({ ...ctx.key, defaultValue: evt.token }),
|
422
417
|
}),
|
423
|
-
storeKeyCurrentNamespace:
|
418
|
+
storeKeyCurrentNamespace: assign({
|
424
419
|
key: (ctx, _evt) => ({
|
425
420
|
...ctx.key,
|
426
|
-
namespace: ctx.
|
421
|
+
namespace: ctx.getTranslate !== null ? ctx.getTranslate : undefined,
|
427
422
|
}),
|
428
423
|
}),
|
429
|
-
dynamicKeyName:
|
424
|
+
dynamicKeyName: assign({
|
430
425
|
warnings: (ctx, _evt) => [
|
431
426
|
...ctx.warnings,
|
432
427
|
{ warning: 'W_DYNAMIC_KEY', line: ctx.line },
|
433
428
|
],
|
434
429
|
key: (_ctx, _evt) => VOID_KEY,
|
435
430
|
}),
|
436
|
-
dynamicKeyDefault:
|
431
|
+
dynamicKeyDefault: assign({
|
437
432
|
key: (ctx, _evt) => ({ ...ctx.key, defaultValue: undefined }),
|
438
433
|
warnings: (ctx, _evt) => [
|
439
434
|
...ctx.warnings,
|
440
435
|
{ warning: 'W_DYNAMIC_DEFAULT_VALUE', line: ctx.line },
|
441
436
|
],
|
442
437
|
}),
|
443
|
-
dynamicOptions:
|
438
|
+
dynamicOptions: assign({
|
444
439
|
key: (_ctx, _evt) => VOID_KEY,
|
445
440
|
warnings: (ctx, _evt) => [
|
446
441
|
...ctx.warnings,
|
447
442
|
{ warning: 'W_DYNAMIC_OPTIONS', line: ctx.line },
|
448
443
|
],
|
449
444
|
}),
|
450
|
-
pushKey:
|
445
|
+
pushKey: assign({
|
451
446
|
warnings: (ctx, _evt) => {
|
452
447
|
if (!ctx.key.keyName || ctx.key.namespace !== false)
|
453
448
|
return ctx.warnings;
|
@@ -473,7 +468,7 @@ exports.default = (0, xstate_1.createMachine)({
|
|
473
468
|
},
|
474
469
|
key: (_ctx, _evt) => ({ keyName: '', line: 0 }),
|
475
470
|
}),
|
476
|
-
pushImmediateKey:
|
471
|
+
pushImmediateKey: assign({
|
477
472
|
ignore: (_ctx, evt) => ({ type: 'key', line: evt.line + 1 }),
|
478
473
|
keys: (ctx, evt) => [
|
479
474
|
...ctx.keys,
|
@@ -485,7 +480,7 @@ exports.default = (0, xstate_1.createMachine)({
|
|
485
480
|
},
|
486
481
|
],
|
487
482
|
}),
|
488
|
-
pushWarning:
|
483
|
+
pushWarning: assign({
|
489
484
|
warnings: (ctx, evt) => [
|
490
485
|
...ctx.warnings,
|
491
486
|
{ warning: evt.kind, line: evt.line },
|
package/dist/extractor/runner.js
CHANGED
@@ -1,19 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
const util_1 = require("util");
|
7
|
-
const glob = (0, util_1.promisify)(glob_1.glob);
|
8
|
-
exports.NullNamespace = Symbol('namespace.null');
|
9
|
-
async function extractKeysFromFile(file, extractor) {
|
10
|
-
return (0, worker_1.callWorker)({
|
1
|
+
import { glob } from 'glob';
|
2
|
+
import { callWorker } from './worker.js';
|
3
|
+
export const NullNamespace = Symbol('namespace.null');
|
4
|
+
export async function extractKeysFromFile(file, extractor) {
|
5
|
+
return callWorker({
|
11
6
|
extractor: extractor,
|
12
7
|
file: file,
|
13
8
|
});
|
14
9
|
}
|
15
|
-
|
16
|
-
async function extractKeysOfFiles(filesPattern, extractor) {
|
10
|
+
export async function extractKeysOfFiles(filesPattern, extractor) {
|
17
11
|
const files = await glob(filesPattern, { nodir: true });
|
18
12
|
const result = new Map();
|
19
13
|
await Promise.all(files.map(async (file) => {
|
@@ -22,12 +16,11 @@ async function extractKeysOfFiles(filesPattern, extractor) {
|
|
22
16
|
}));
|
23
17
|
return result;
|
24
18
|
}
|
25
|
-
|
26
|
-
function filterExtractionResult(data) {
|
19
|
+
export function filterExtractionResult(data) {
|
27
20
|
const result = Object.create(null);
|
28
21
|
for (const { keys } of data.values()) {
|
29
22
|
for (const key of keys) {
|
30
|
-
const namespace = key.namespace ||
|
23
|
+
const namespace = key.namespace || NullNamespace;
|
31
24
|
if (!(namespace in result)) {
|
32
25
|
result[namespace] = new Map();
|
33
26
|
}
|
@@ -36,4 +29,3 @@ function filterExtractionResult(data) {
|
|
36
29
|
}
|
37
30
|
return result;
|
38
31
|
}
|
39
|
-
exports.filterExtractionResult = filterExtractionResult;
|
@@ -1,36 +1,36 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
const
|
7
|
-
const GRAMMAR_PATH = (0, path_1.join)(__dirname, '..', '..', 'textmate');
|
1
|
+
import { extname } from 'path';
|
2
|
+
import { readFile } from 'fs/promises';
|
3
|
+
import { createRequire } from 'module';
|
4
|
+
import TextMate from 'vscode-textmate';
|
5
|
+
import Oniguruma from 'vscode-oniguruma';
|
6
|
+
const GRAMMAR_PATH = new URL('../../textmate/', import.meta.url);
|
8
7
|
const GrammarFiles = {
|
9
|
-
["source.ts" /* Grammar.TYPESCRIPT */]:
|
10
|
-
["source.tsx" /* Grammar.TYPESCRIPT_TSX */]:
|
11
|
-
["source.svelte" /* Grammar.SVELTE */]:
|
8
|
+
["source.ts" /* Grammar.TYPESCRIPT */]: new URL('TypeScript.tmLanguage', GRAMMAR_PATH),
|
9
|
+
["source.tsx" /* Grammar.TYPESCRIPT_TSX */]: new URL('TypeScriptReact.tmLanguage', GRAMMAR_PATH),
|
10
|
+
["source.svelte" /* Grammar.SVELTE */]: new URL('Svelte.tmLanguage', GRAMMAR_PATH),
|
12
11
|
};
|
13
12
|
let oniguruma;
|
14
13
|
let registry;
|
15
14
|
async function initializeOniguruma() {
|
15
|
+
const require = createRequire(import.meta.url);
|
16
16
|
const wasmBlobPath = require
|
17
17
|
.resolve('vscode-oniguruma')
|
18
18
|
.replace('main.js', 'onig.wasm');
|
19
|
-
const wasmBlob = await
|
20
|
-
await
|
19
|
+
const wasmBlob = await readFile(wasmBlobPath);
|
20
|
+
await Oniguruma.loadWASM(wasmBlob);
|
21
21
|
return {
|
22
|
-
createOnigScanner: (patterns) => new
|
23
|
-
createOnigString: (s) => new
|
22
|
+
createOnigScanner: (patterns) => new Oniguruma.OnigScanner(patterns),
|
23
|
+
createOnigString: (s) => new Oniguruma.OnigString(s),
|
24
24
|
};
|
25
25
|
}
|
26
26
|
async function loadGrammar(scope) {
|
27
27
|
const file = GrammarFiles[scope];
|
28
28
|
if (!file)
|
29
29
|
return null;
|
30
|
-
const grammar = await
|
30
|
+
const grammar = await readFile(file, 'utf8');
|
31
31
|
return grammar.startsWith('{')
|
32
32
|
? JSON.parse(grammar)
|
33
|
-
:
|
33
|
+
: TextMate.parseRawGrammar(grammar);
|
34
34
|
}
|
35
35
|
function extnameToGrammar(extname) {
|
36
36
|
switch (extname) {
|
@@ -49,7 +49,7 @@ function extnameToGrammar(extname) {
|
|
49
49
|
}
|
50
50
|
}
|
51
51
|
function tokenize(code, grammar) {
|
52
|
-
let stack =
|
52
|
+
let stack = TextMate.INITIAL;
|
53
53
|
let linePtr = 0;
|
54
54
|
const lines = code.split('\n');
|
55
55
|
const tokens = [];
|
@@ -84,16 +84,16 @@ function tokenize(code, grammar) {
|
|
84
84
|
}
|
85
85
|
return tokens;
|
86
86
|
}
|
87
|
-
async function
|
87
|
+
export default async function (code, fileName) {
|
88
88
|
if (!oniguruma) {
|
89
89
|
// Lazily initialize the WebAssembly runtime
|
90
90
|
oniguruma = initializeOniguruma();
|
91
|
-
registry = new
|
91
|
+
registry = new TextMate.Registry({
|
92
92
|
onigLib: oniguruma,
|
93
93
|
loadGrammar: loadGrammar,
|
94
94
|
});
|
95
95
|
}
|
96
|
-
const fileType =
|
96
|
+
const fileType = extname(fileName);
|
97
97
|
const grammarName = extnameToGrammar(fileType);
|
98
98
|
if (!grammarName) {
|
99
99
|
throw new Error(`Cannot find grammar for file type ${fileType}`);
|
@@ -104,4 +104,3 @@ async function default_1(code, fileName) {
|
|
104
104
|
}
|
105
105
|
return tokenize(code, grammar);
|
106
106
|
}
|
107
|
-
exports.default = default_1;
|
@@ -1,8 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
exports.emitGitHubWarning = exports.dumpWarnings = exports.WarningMessages = void 0;
|
4
|
-
const path_1 = require("path");
|
5
|
-
exports.WarningMessages = {
|
1
|
+
import { relative } from 'path';
|
2
|
+
export const WarningMessages = {
|
6
3
|
W_DYNAMIC_KEY: {
|
7
4
|
name: 'Dynamic key',
|
8
5
|
description: 'The key not static and cannot be extracted automatically. This key will be ignored.\n\nUse @tolgee-key or @tolgee-ignore to suppress this warning.',
|
@@ -42,7 +39,7 @@ exports.WarningMessages = {
|
|
42
39
|
* @param extractionResult Extraction result to dump warnings from.
|
43
40
|
* @returns Count of emitted warnings in the extraction.
|
44
41
|
*/
|
45
|
-
function dumpWarnings(extractionResult) {
|
42
|
+
export function dumpWarnings(extractionResult) {
|
46
43
|
let warningCount = 0;
|
47
44
|
for (const [file, { warnings }] of extractionResult.entries()) {
|
48
45
|
if (warnings.length) {
|
@@ -51,8 +48,8 @@ function dumpWarnings(extractionResult) {
|
|
51
48
|
}
|
52
49
|
console.error(file);
|
53
50
|
for (const warning of warnings) {
|
54
|
-
const warnText = warning.warning in
|
55
|
-
?
|
51
|
+
const warnText = warning.warning in WarningMessages
|
52
|
+
? WarningMessages[warning.warning].name
|
56
53
|
: warning.warning;
|
57
54
|
console.error('\tline %d: %s', warning.line, warnText);
|
58
55
|
emitGitHubWarning(warning.warning, file, warning.line);
|
@@ -65,13 +62,12 @@ function dumpWarnings(extractionResult) {
|
|
65
62
|
}
|
66
63
|
return warningCount;
|
67
64
|
}
|
68
|
-
|
69
|
-
function emitGitHubWarning(warning, file, line) {
|
65
|
+
export function emitGitHubWarning(warning, file, line) {
|
70
66
|
if (!process.env.GITHUB_ACTIONS)
|
71
67
|
return;
|
72
|
-
file =
|
73
|
-
if (warning in
|
74
|
-
const { name, description } =
|
68
|
+
file = relative(process.env.GITHUB_WORKSPACE ?? process.cwd(), file);
|
69
|
+
if (warning in WarningMessages) {
|
70
|
+
const { name, description } = WarningMessages[warning];
|
75
71
|
const encodedDescription = description
|
76
72
|
.replaceAll('%', '%25')
|
77
73
|
.replaceAll('\r', '%0D')
|
@@ -84,4 +80,3 @@ function emitGitHubWarning(warning, file, line) {
|
|
84
80
|
}
|
85
81
|
console.log(`::warning file=${file},line=${line}::${warning}`);
|
86
82
|
}
|
87
|
-
exports.emitGitHubWarning = emitGitHubWarning;
|
package/dist/extractor/worker.js
CHANGED
@@ -1,16 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
const
|
8
|
-
const worker_threads_1 = require("worker_threads");
|
9
|
-
const promises_1 = require("fs/promises");
|
10
|
-
const extractor_1 = __importDefault(require("./extractor"));
|
11
|
-
const moduleLoader_1 = require("../utils/moduleLoader");
|
12
|
-
const deferred_1 = require("../utils/deferred");
|
13
|
-
const IS_TS_NODE = (0, path_1.extname)(__filename) === '.ts';
|
1
|
+
import { resolve, extname } from 'path';
|
2
|
+
import { Worker, isMainThread, parentPort } from 'worker_threads';
|
3
|
+
import { readFile } from 'fs/promises';
|
4
|
+
import internalExtractor from './extractor.js';
|
5
|
+
import { loadModule } from '../utils/moduleLoader.js';
|
6
|
+
import { createDeferred } from '../utils/deferred.js';
|
7
|
+
const IS_TS_NODE = extname(import.meta.url) === '.ts';
|
14
8
|
// --- Worker functions
|
15
9
|
let loadedExtractor = Symbol('unloaded');
|
16
10
|
let extractor;
|
@@ -18,30 +12,32 @@ async function handleJob(args) {
|
|
18
12
|
if (loadedExtractor !== args.extractor) {
|
19
13
|
loadedExtractor = args.extractor;
|
20
14
|
extractor = args.extractor
|
21
|
-
? await
|
22
|
-
:
|
15
|
+
? await loadModule(args.extractor).then((mdl) => mdl.default)
|
16
|
+
: internalExtractor;
|
23
17
|
}
|
24
|
-
const file =
|
25
|
-
const code = await
|
18
|
+
const file = resolve(args.file);
|
19
|
+
const code = await readFile(file, 'utf8');
|
26
20
|
return extractor(code, file);
|
27
21
|
}
|
28
22
|
async function workerInit() {
|
29
|
-
|
23
|
+
parentPort.on('message', (params) => {
|
30
24
|
handleJob(params)
|
31
|
-
.then((res) =>
|
32
|
-
.catch((e) =>
|
25
|
+
.then((res) => parentPort.postMessage({ data: res }))
|
26
|
+
.catch((e) => parentPort.postMessage({ err: e }));
|
33
27
|
});
|
34
28
|
}
|
35
|
-
if (!
|
29
|
+
if (!isMainThread)
|
36
30
|
workerInit();
|
37
31
|
// --- Main thread functions
|
38
32
|
let worker;
|
39
33
|
const jobQueue = [];
|
40
34
|
function createWorker() {
|
41
|
-
const worker =
|
42
|
-
|
43
|
-
|
44
|
-
|
35
|
+
const worker = IS_TS_NODE
|
36
|
+
? new Worker(new URL(import.meta.url).pathname.replace('.ts', '.js'), {
|
37
|
+
// ts-node workaround
|
38
|
+
execArgv: ['--require', 'ts-node/register'],
|
39
|
+
})
|
40
|
+
: new Worker(new URL(import.meta.url).pathname);
|
45
41
|
let timeout;
|
46
42
|
let currentDeferred;
|
47
43
|
function workOrDie() {
|
@@ -70,12 +66,11 @@ function createWorker() {
|
|
70
66
|
workOrDie();
|
71
67
|
return worker;
|
72
68
|
}
|
73
|
-
async function callWorker(params) {
|
74
|
-
const deferred =
|
69
|
+
export async function callWorker(params) {
|
70
|
+
const deferred = createDeferred();
|
75
71
|
jobQueue.push([params, deferred]);
|
76
72
|
if (!worker) {
|
77
73
|
worker = createWorker();
|
78
74
|
}
|
79
75
|
return deferred.promise;
|
80
76
|
}
|
81
|
-
exports.callWorker = callWorker;
|