@nx/devkit 0.0.0-pr-22179-271588f
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/LICENSE +22 -0
- package/README.md +68 -0
- package/index.d.ts +14 -0
- package/index.js +18 -0
- package/migrations.json +18 -0
- package/ngcli-adapter.d.ts +4 -0
- package/ngcli-adapter.js +11 -0
- package/nx.d.ts +1 -0
- package/nx.js +19 -0
- package/package.json +50 -0
- package/public-api.d.ts +78 -0
- package/public-api.js +100 -0
- package/src/executors/parse-target-string.d.ts +44 -0
- package/src/executors/parse-target-string.js +55 -0
- package/src/executors/read-target-options.d.ts +8 -0
- package/src/executors/read-target-options.js +38 -0
- package/src/generators/add-build-target-defaults.d.ts +2 -0
- package/src/generators/add-build-target-defaults.js +18 -0
- package/src/generators/artifact-name-and-directory-utils.d.ts +48 -0
- package/src/generators/artifact-name-and-directory-utils.js +239 -0
- package/src/generators/executor-options-utils.d.ts +21 -0
- package/src/generators/executor-options-utils.js +49 -0
- package/src/generators/format-files.d.ts +6 -0
- package/src/generators/format-files.js +91 -0
- package/src/generators/generate-files.d.ts +26 -0
- package/src/generators/generate-files.js +91 -0
- package/src/generators/project-name-and-root-utils.d.ts +47 -0
- package/src/generators/project-name-and-root-utils.js +298 -0
- package/src/generators/run-tasks-in-serial.d.ts +7 -0
- package/src/generators/run-tasks-in-serial.js +16 -0
- package/src/generators/to-js.d.ts +11 -0
- package/src/generators/to-js.js +24 -0
- package/src/generators/typescript/insert-import.d.ts +1 -0
- package/src/generators/typescript/insert-import.js +5 -0
- package/src/generators/typescript/insert-statement.d.ts +1 -0
- package/src/generators/typescript/insert-statement.js +5 -0
- package/src/generators/update-ts-configs-to-js.d.ts +4 -0
- package/src/generators/update-ts-configs-to-js.js +49 -0
- package/src/generators/visit-not-ignored-files.d.ts +5 -0
- package/src/generators/visit-not-ignored-files.js +41 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
- package/src/migrations/update-16-9-0/migrate-mf-util-usage.d.ts +4 -0
- package/src/migrations/update-16-9-0/migrate-mf-util-usage.js +201 -0
- package/src/tasks/install-packages-task.d.ts +10 -0
- package/src/tasks/install-packages-task.js +41 -0
- package/src/utils/async-iterable/combine-async-iterables.d.ts +3 -0
- package/src/utils/async-iterable/combine-async-iterables.js +58 -0
- package/src/utils/async-iterable/create-async-iterable.d.ts +6 -0
- package/src/utils/async-iterable/create-async-iterable.js +58 -0
- package/src/utils/async-iterable/index.d.ts +4 -0
- package/src/utils/async-iterable/index.js +7 -0
- package/src/utils/async-iterable/map-async-iteratable.d.ts +1 -0
- package/src/utils/async-iterable/map-async-iteratable.js +18 -0
- package/src/utils/async-iterable/tap-async-iteratable.d.ts +1 -0
- package/src/utils/async-iterable/tap-async-iteratable.js +11 -0
- package/src/utils/binary-extensions.d.ts +1 -0
- package/src/utils/binary-extensions.js +275 -0
- package/src/utils/calculate-hash-for-create-nodes.d.ts +2 -0
- package/src/utils/calculate-hash-for-create-nodes.js +16 -0
- package/src/utils/config-utils.d.ts +4 -0
- package/src/utils/config-utils.js +75 -0
- package/src/utils/convert-nx-executor.d.ts +7 -0
- package/src/utils/convert-nx-executor.js +89 -0
- package/src/utils/get-named-inputs.d.ts +8 -0
- package/src/utils/get-named-inputs.js +26 -0
- package/src/utils/get-workspace-layout.d.ts +24 -0
- package/src/utils/get-workspace-layout.js +52 -0
- package/src/utils/invoke-nx-generator.d.ts +6 -0
- package/src/utils/invoke-nx-generator.js +172 -0
- package/src/utils/log-show-project-command.d.ts +1 -0
- package/src/utils/log-show-project-command.js +14 -0
- package/src/utils/move-dir.d.ts +5 -0
- package/src/utils/move-dir.js +28 -0
- package/src/utils/names.d.ts +18 -0
- package/src/utils/names.js +63 -0
- package/src/utils/offset-from-root.d.ts +13 -0
- package/src/utils/offset-from-root.js +29 -0
- package/src/utils/package-json.d.ts +78 -0
- package/src/utils/package-json.js +375 -0
- package/src/utils/replace-package.d.ts +2 -0
- package/src/utils/replace-package.js +125 -0
- package/src/utils/replace-project-configuration-with-plugin.d.ts +3 -0
- package/src/utils/replace-project-configuration-with-plugin.js +136 -0
- package/src/utils/rxjs-for-await.d.ts +109 -0
- package/src/utils/rxjs-for-await.js +363 -0
- package/src/utils/semver.d.ts +1 -0
- package/src/utils/semver.js +18 -0
- package/src/utils/string-change.d.ts +62 -0
- package/src/utils/string-change.js +109 -0
- package/src/utils/string-utils.d.ts +95 -0
- package/src/utils/string-utils.js +147 -0
- package/src/utils/update-package-scripts.d.ts +3 -0
- package/src/utils/update-package-scripts.js +175 -0
- package/src/utils/versions.d.ts +1 -0
- package/src/utils/versions.js +4 -0
- package/testing.d.ts +1 -0
- package/testing.js +5 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const visit_not_ignored_files_1 = require("../../generators/visit-not-ignored-files");
|
|
4
|
+
const format_files_1 = require("../../generators/format-files");
|
|
5
|
+
const nx_1 = require("../../../nx");
|
|
6
|
+
const package_json_1 = require("../../utils/package-json");
|
|
7
|
+
const versions_1 = require("../../utils/versions");
|
|
8
|
+
const { readJson } = (0, nx_1.requireNx)();
|
|
9
|
+
let tsModule;
|
|
10
|
+
const MODULE_FEDERATION_PUBLIC_TOKENS = [
|
|
11
|
+
'AdditionalSharedConfig',
|
|
12
|
+
'ModuleFederationConfig',
|
|
13
|
+
'SharedLibraryConfig',
|
|
14
|
+
'SharedWorkspaceLibraryConfig',
|
|
15
|
+
'WorkspaceLibrary',
|
|
16
|
+
'SharedFunction',
|
|
17
|
+
'WorkspaceLibrarySecondaryEntryPoint',
|
|
18
|
+
'Remotes',
|
|
19
|
+
'ModuleFederationLibrary',
|
|
20
|
+
'applySharedFunction',
|
|
21
|
+
'applyAdditionalShared',
|
|
22
|
+
'getNpmPackageSharedConfig',
|
|
23
|
+
'shareWorkspaceLibraries',
|
|
24
|
+
'sharePackages',
|
|
25
|
+
'mapRemotes',
|
|
26
|
+
'mapRemotesForSSR',
|
|
27
|
+
'getDependentPackagesForProject',
|
|
28
|
+
'readRootPackageJson',
|
|
29
|
+
];
|
|
30
|
+
exports.default = async (tree) => {
|
|
31
|
+
let hasFileToMigrate = false;
|
|
32
|
+
(0, visit_not_ignored_files_1.visitNotIgnoredFiles)(tree, '/', (path) => {
|
|
33
|
+
if (!path.endsWith('.ts') && !path.endsWith('.js')) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
let fileContents = tree.read(path, 'utf-8');
|
|
37
|
+
if (MODULE_FEDERATION_PUBLIC_TOKENS.every((token) => !fileContents.includes(token))) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
hasFileToMigrate = true;
|
|
41
|
+
fileContents = replaceTSImports(tree, path, fileContents);
|
|
42
|
+
fileContents = replaceRequireCalls(tree, path, fileContents);
|
|
43
|
+
fileContents = replaceJSDoc(tree, path, fileContents);
|
|
44
|
+
tree.write(path, fileContents);
|
|
45
|
+
});
|
|
46
|
+
if (hasFileToMigrate) {
|
|
47
|
+
await (0, format_files_1.formatFiles)(tree);
|
|
48
|
+
const pkgJson = readJson(tree, 'package.json');
|
|
49
|
+
const nxVersion = pkgJson.devDependencies?.['nx'] ??
|
|
50
|
+
pkgJson.dependencies?.['nx'] ??
|
|
51
|
+
'17.0.0';
|
|
52
|
+
return (0, package_json_1.addDependenciesToPackageJson)(tree, {}, { '@nx/webpack': nxVersion });
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
function replaceJSDoc(tree, path, fileContents) {
|
|
56
|
+
let newFileContents = fileContents;
|
|
57
|
+
for (const token of MODULE_FEDERATION_PUBLIC_TOKENS) {
|
|
58
|
+
newFileContents = newFileContents.replaceAll(new RegExp(`(@type)+\\s({)+(\\s)*(import\\(('|")+@nx\/devkit('|")+\\)\.)+(${token})+\\s*(})+`, 'g'), `@type {import('@nx/webpack').${token}}`);
|
|
59
|
+
}
|
|
60
|
+
return newFileContents;
|
|
61
|
+
}
|
|
62
|
+
function replaceRequireCalls(tree, path, fileContents) {
|
|
63
|
+
if (!tsModule) {
|
|
64
|
+
tsModule = (0, package_json_1.ensurePackage)('typescript', versions_1.typescriptVersion);
|
|
65
|
+
}
|
|
66
|
+
const sourceFile = tsModule.createSourceFile(path, fileContents, tsModule.ScriptTarget.Latest, true);
|
|
67
|
+
const allDevkitRequires = findNodes(sourceFile, tsModule.SyntaxKind.VariableStatement)
|
|
68
|
+
.filter((node) => [`require("@nx/devkit")`, `require('@nx/devkit')`].some((r) => node.getText().includes(r)))
|
|
69
|
+
.filter((node) => findNodes(node, tsModule.SyntaxKind.ObjectBindingPattern).length);
|
|
70
|
+
const mfUtilRequires = allDevkitRequires.filter((node) => MODULE_FEDERATION_PUBLIC_TOKENS.some((token) => node.getText().includes(token)));
|
|
71
|
+
if (!mfUtilRequires.length) {
|
|
72
|
+
return fileContents;
|
|
73
|
+
}
|
|
74
|
+
const mfUtilTokens = mfUtilRequires.map((node) => {
|
|
75
|
+
const allTokens = findNodes(node, tsModule.SyntaxKind.BindingElement);
|
|
76
|
+
const mfTokens = allTokens.filter((node) => MODULE_FEDERATION_PUBLIC_TOKENS.some((token) => node.getText() === token));
|
|
77
|
+
return {
|
|
78
|
+
requireNode: node,
|
|
79
|
+
onlyMf: allTokens.length === mfTokens.length,
|
|
80
|
+
mfTokens,
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
const changes = [];
|
|
84
|
+
for (const mfUtilRequireData of mfUtilTokens) {
|
|
85
|
+
if (mfUtilRequireData.onlyMf) {
|
|
86
|
+
changes.push({
|
|
87
|
+
startPosition: mfUtilRequireData.requireNode.getStart(),
|
|
88
|
+
endPosition: mfUtilRequireData.requireNode.getEnd(),
|
|
89
|
+
content: '',
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
for (const mfToken of mfUtilRequireData.mfTokens) {
|
|
94
|
+
const replaceTrailingComma = mfToken.getText().charAt(mfToken.getEnd() + 1) === ',';
|
|
95
|
+
changes.push({
|
|
96
|
+
startPosition: mfToken.getStart(),
|
|
97
|
+
endPosition: replaceTrailingComma
|
|
98
|
+
? mfToken.getEnd() + 1
|
|
99
|
+
: mfToken.getEnd(),
|
|
100
|
+
content: '',
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
changes.push({
|
|
106
|
+
startPosition: mfUtilTokens[mfUtilTokens.length - 1].requireNode.getEnd(),
|
|
107
|
+
content: `\nconst { ${mfUtilTokens
|
|
108
|
+
.map((mfUtilToken) => mfUtilToken.mfTokens.map((node) => node.getText()))
|
|
109
|
+
.join(', ')} } = require('@nx/webpack');`,
|
|
110
|
+
});
|
|
111
|
+
let newFileContents = fileContents;
|
|
112
|
+
while (changes.length) {
|
|
113
|
+
const change = changes.pop();
|
|
114
|
+
newFileContents = `${newFileContents.substring(0, change.startPosition)}${change.content}${newFileContents.substring(change.endPosition ? change.endPosition : change.startPosition)}`;
|
|
115
|
+
}
|
|
116
|
+
return newFileContents;
|
|
117
|
+
}
|
|
118
|
+
function replaceTSImports(tree, path, fileContents) {
|
|
119
|
+
if (!tsModule) {
|
|
120
|
+
tsModule = (0, package_json_1.ensurePackage)('typescript', versions_1.typescriptVersion);
|
|
121
|
+
}
|
|
122
|
+
const sourceFile = tsModule.createSourceFile(path, fileContents, tsModule.ScriptTarget.Latest, true);
|
|
123
|
+
const allImports = findNodes(sourceFile, tsModule.SyntaxKind.ImportDeclaration);
|
|
124
|
+
const devkitImports = allImports.filter((i) => i.getText().includes(`'@nx/devkit';`));
|
|
125
|
+
const mfUtilsImports = devkitImports.filter((i) => MODULE_FEDERATION_PUBLIC_TOKENS.some((token) => i.getText().includes(token)));
|
|
126
|
+
if (!mfUtilsImports.length) {
|
|
127
|
+
return fileContents;
|
|
128
|
+
}
|
|
129
|
+
const mfUtilsWithMultipleImports = mfUtilsImports.map((i) => {
|
|
130
|
+
const importSpecifierNodes = findNodes(i, tsModule.SyntaxKind.ImportSpecifier);
|
|
131
|
+
const mfImportSpecifierNodes = importSpecifierNodes.filter((node) => MODULE_FEDERATION_PUBLIC_TOKENS.some((token) => node.getText().includes(token)));
|
|
132
|
+
return {
|
|
133
|
+
importDeclarationNode: i,
|
|
134
|
+
onlyMf: mfImportSpecifierNodes.length === importSpecifierNodes.length,
|
|
135
|
+
mfImportSpecifierNodes,
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
const changes = [];
|
|
139
|
+
for (const importDeclaration of mfUtilsWithMultipleImports) {
|
|
140
|
+
if (importDeclaration.onlyMf) {
|
|
141
|
+
changes.push({
|
|
142
|
+
startPosition: importDeclaration.importDeclarationNode.getStart(),
|
|
143
|
+
endPosition: importDeclaration.importDeclarationNode.getEnd(),
|
|
144
|
+
content: '',
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
for (const mfImportSpecifierNodes of importDeclaration.mfImportSpecifierNodes) {
|
|
149
|
+
const replaceTrailingComma = importDeclaration.importDeclarationNode
|
|
150
|
+
.getText()
|
|
151
|
+
.charAt(mfImportSpecifierNodes.getEnd() + 1) === ',';
|
|
152
|
+
changes.push({
|
|
153
|
+
startPosition: mfImportSpecifierNodes.getStart(),
|
|
154
|
+
endPosition: replaceTrailingComma
|
|
155
|
+
? mfImportSpecifierNodes.getEnd() + 1
|
|
156
|
+
: mfImportSpecifierNodes.getEnd(),
|
|
157
|
+
content: '',
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
changes.push({
|
|
163
|
+
startPosition: mfUtilsWithMultipleImports[mfUtilsWithMultipleImports.length - 1].importDeclarationNode.getEnd(),
|
|
164
|
+
content: `\nimport { ${mfUtilsWithMultipleImports
|
|
165
|
+
.map((importDeclaration) => importDeclaration.mfImportSpecifierNodes.map((node) => node.getText()))
|
|
166
|
+
.join(', ')} } from '@nx/webpack';`,
|
|
167
|
+
});
|
|
168
|
+
let newFileContents = fileContents;
|
|
169
|
+
while (changes.length) {
|
|
170
|
+
const change = changes.pop();
|
|
171
|
+
newFileContents = `${newFileContents.substring(0, change.startPosition)}${change.content}${newFileContents.substring(change.endPosition ? change.endPosition : change.startPosition)}`;
|
|
172
|
+
}
|
|
173
|
+
return newFileContents;
|
|
174
|
+
}
|
|
175
|
+
function findNodes(node, kind, max = Infinity) {
|
|
176
|
+
if (!node || max == 0) {
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
const arr = [];
|
|
180
|
+
const hasMatch = Array.isArray(kind)
|
|
181
|
+
? kind.includes(node.kind)
|
|
182
|
+
: node.kind === kind;
|
|
183
|
+
if (hasMatch) {
|
|
184
|
+
arr.push(node);
|
|
185
|
+
max--;
|
|
186
|
+
}
|
|
187
|
+
if (max > 0) {
|
|
188
|
+
for (const child of node.getChildren()) {
|
|
189
|
+
findNodes(child, kind, max).forEach((node) => {
|
|
190
|
+
if (max > 0) {
|
|
191
|
+
arr.push(node);
|
|
192
|
+
}
|
|
193
|
+
max--;
|
|
194
|
+
});
|
|
195
|
+
if (max <= 0) {
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return arr;
|
|
201
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Tree } from 'nx/src/generators/tree';
|
|
2
|
+
import type { PackageManager } from 'nx/src/utils/package-manager';
|
|
3
|
+
/**
|
|
4
|
+
* Runs `npm install` or `yarn install`. It will skip running the install if
|
|
5
|
+
* `package.json` hasn't changed at all or it hasn't changed since the last invocation.
|
|
6
|
+
*
|
|
7
|
+
* @param tree - the file system tree
|
|
8
|
+
* @param alwaysRun - always run the command even if `package.json` hasn't changed.
|
|
9
|
+
*/
|
|
10
|
+
export declare function installPackagesTask(tree: Tree, alwaysRun?: boolean, cwd?: string, packageManager?: PackageManager): void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installPackagesTask = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const nx_1 = require("../../nx");
|
|
7
|
+
const { detectPackageManager, getPackageManagerCommand, joinPathFragments } = (0, nx_1.requireNx)();
|
|
8
|
+
/**
|
|
9
|
+
* Runs `npm install` or `yarn install`. It will skip running the install if
|
|
10
|
+
* `package.json` hasn't changed at all or it hasn't changed since the last invocation.
|
|
11
|
+
*
|
|
12
|
+
* @param tree - the file system tree
|
|
13
|
+
* @param alwaysRun - always run the command even if `package.json` hasn't changed.
|
|
14
|
+
*/
|
|
15
|
+
function installPackagesTask(tree, alwaysRun = false, cwd = '', packageManager = detectPackageManager(cwd)) {
|
|
16
|
+
if (!tree
|
|
17
|
+
.listChanges()
|
|
18
|
+
.find((f) => f.path === joinPathFragments(cwd, 'package.json')) &&
|
|
19
|
+
!alwaysRun) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const packageJsonValue = tree.read(joinPathFragments(cwd, 'package.json'), 'utf-8');
|
|
23
|
+
let storedPackageJsonValue = global['__packageJsonInstallCache__'];
|
|
24
|
+
// Don't install again if install was already executed with package.json
|
|
25
|
+
if (storedPackageJsonValue != packageJsonValue || alwaysRun) {
|
|
26
|
+
global['__packageJsonInstallCache__'] = packageJsonValue;
|
|
27
|
+
const pmc = getPackageManagerCommand(packageManager);
|
|
28
|
+
const execSyncOptions = {
|
|
29
|
+
cwd: (0, path_1.join)(tree.root, cwd),
|
|
30
|
+
stdio: process.env.NX_GENERATE_QUIET === 'true' ? 'ignore' : 'inherit',
|
|
31
|
+
};
|
|
32
|
+
// ensure local registry from process is not interfering with the install
|
|
33
|
+
// when we start the process from temp folder the local registry would override the custom registry
|
|
34
|
+
if (process.env.npm_config_registry &&
|
|
35
|
+
process.env.npm_config_registry.match(/^https:\/\/registry\.(npmjs\.org|yarnpkg\.com)/)) {
|
|
36
|
+
delete process.env.npm_config_registry;
|
|
37
|
+
}
|
|
38
|
+
(0, child_process_1.execSync)(pmc.install, execSyncOptions);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.installPackagesTask = installPackagesTask;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.combineAsyncIterables = void 0;
|
|
4
|
+
async function* combineAsyncIterables(..._iterators) {
|
|
5
|
+
// Convert iterables into iterators with next, return, throws methods.
|
|
6
|
+
// If it's already an iterator, keep it.
|
|
7
|
+
const iterators = _iterators.map((it) => {
|
|
8
|
+
if (typeof it['next'] === 'function') {
|
|
9
|
+
return it;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return (async function* wrapped() {
|
|
13
|
+
for await (const val of it) {
|
|
14
|
+
yield val;
|
|
15
|
+
}
|
|
16
|
+
})();
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
let [options] = iterators;
|
|
20
|
+
if (typeof options.next === 'function') {
|
|
21
|
+
options = Object.create(null);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
iterators.shift();
|
|
25
|
+
}
|
|
26
|
+
const getNextAsyncIteratorValue = getNextAsyncIteratorFactory(options);
|
|
27
|
+
try {
|
|
28
|
+
const asyncIteratorsValues = new Map(iterators.map((it, idx) => [idx, getNextAsyncIteratorValue(it, idx)]));
|
|
29
|
+
do {
|
|
30
|
+
const { iterator, index } = await Promise.race(asyncIteratorsValues.values());
|
|
31
|
+
if (iterator.done) {
|
|
32
|
+
asyncIteratorsValues.delete(index);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
yield iterator.value;
|
|
36
|
+
asyncIteratorsValues.set(index, getNextAsyncIteratorValue(iterators[index], index));
|
|
37
|
+
}
|
|
38
|
+
} while (asyncIteratorsValues.size > 0);
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
await Promise.allSettled(iterators.map((it) => it['return']?.()));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.combineAsyncIterables = combineAsyncIterables;
|
|
45
|
+
function getNextAsyncIteratorFactory(options) {
|
|
46
|
+
return async (asyncIterator, index) => {
|
|
47
|
+
try {
|
|
48
|
+
const iterator = await asyncIterator.next();
|
|
49
|
+
return { index, iterator };
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
if (options.errorCallback) {
|
|
53
|
+
options.errorCallback(err, index);
|
|
54
|
+
}
|
|
55
|
+
return Promise.reject(err);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAsyncIterable = void 0;
|
|
4
|
+
function createAsyncIterable(listener) {
|
|
5
|
+
let done = false;
|
|
6
|
+
let error = null;
|
|
7
|
+
const pushQueue = [];
|
|
8
|
+
const pullQueue = [];
|
|
9
|
+
return {
|
|
10
|
+
[Symbol.asyncIterator]() {
|
|
11
|
+
listener({
|
|
12
|
+
next: (value) => {
|
|
13
|
+
if (done || error)
|
|
14
|
+
return;
|
|
15
|
+
if (pullQueue.length > 0) {
|
|
16
|
+
pullQueue.shift()?.[0]({ value, done: false });
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
pushQueue.push(value);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
error: (err) => {
|
|
23
|
+
if (done || error)
|
|
24
|
+
return;
|
|
25
|
+
if (pullQueue.length > 0) {
|
|
26
|
+
pullQueue.shift()?.[1](err);
|
|
27
|
+
}
|
|
28
|
+
error = err;
|
|
29
|
+
},
|
|
30
|
+
done: () => {
|
|
31
|
+
if (pullQueue.length > 0) {
|
|
32
|
+
pullQueue.shift()?.[0]({ value: undefined, done: true });
|
|
33
|
+
}
|
|
34
|
+
done = true;
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
next() {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
if (pushQueue.length > 0) {
|
|
41
|
+
resolve({ value: pushQueue.shift(), done: false });
|
|
42
|
+
}
|
|
43
|
+
else if (done) {
|
|
44
|
+
resolve({ value: undefined, done: true });
|
|
45
|
+
}
|
|
46
|
+
else if (error) {
|
|
47
|
+
reject(error);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
pullQueue.push([resolve, reject]);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
exports.createAsyncIterable = createAsyncIterable;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./create-async-iterable"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./combine-async-iterables"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./map-async-iteratable"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./tap-async-iteratable"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function mapAsyncIterable<T = any, I = any, O = any>(data: AsyncIterable<T> | AsyncIterableIterator<T>, transform: (input: I, index?: number, data?: AsyncIterable<T> | AsyncIterableIterator<T>) => O): AsyncIterable<O> | AsyncIterableIterator<O>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapAsyncIterable = void 0;
|
|
4
|
+
async function* mapAsyncIterable(data, transform) {
|
|
5
|
+
async function* f() {
|
|
6
|
+
const generator = data[Symbol.asyncIterator] || data[Symbol.iterator];
|
|
7
|
+
const iterator = generator.call(data);
|
|
8
|
+
let index = 0;
|
|
9
|
+
let item = await iterator.next();
|
|
10
|
+
while (!item.done) {
|
|
11
|
+
yield await transform(await item.value, index, data);
|
|
12
|
+
index++;
|
|
13
|
+
item = await iterator.next();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return yield* f();
|
|
17
|
+
}
|
|
18
|
+
exports.mapAsyncIterable = mapAsyncIterable;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function tapAsyncIterable<T = any, I = any, O = any>(data: AsyncIterable<T> | AsyncIterableIterator<T>, fn: (input: I) => void): AsyncIterable<T> | AsyncIterableIterator<T>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tapAsyncIterable = void 0;
|
|
4
|
+
const map_async_iteratable_1 = require("./map-async-iteratable");
|
|
5
|
+
async function* tapAsyncIterable(data, fn) {
|
|
6
|
+
return yield* (0, map_async_iteratable_1.mapAsyncIterable)(data, (x) => {
|
|
7
|
+
fn(x);
|
|
8
|
+
return x;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
exports.tapAsyncIterable = tapAsyncIterable;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isBinaryPath(path: string): boolean;
|