@nx/devkit 16.0.0-beta.1
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/CHANGELOG.md +8 -0
- package/LICENSE +22 -0
- package/README.md +63 -0
- package/index.d.ts +19 -0
- package/index.js +27 -0
- package/migrations.json +12 -0
- package/ngcli-adapter.d.ts +4 -0
- package/ngcli-adapter.js +13 -0
- package/ngcli-adapter.js.map +1 -0
- package/nx-reexports-pre16.d.ts +127 -0
- package/nx-reexports-pre16.js +141 -0
- package/nx-reexports-pre16.js.map +1 -0
- package/nx.d.ts +1 -0
- package/nx.js +13 -0
- package/nx.js.map +1 -0
- package/package.json +49 -0
- package/public-api.d.ts +82 -0
- package/public-api.js +114 -0
- package/public-api.js.map +1 -0
- package/src/executors/parse-target-string.d.ts +31 -0
- package/src/executors/parse-target-string.js +36 -0
- package/src/executors/parse-target-string.js.map +1 -0
- package/src/executors/read-target-options.d.ts +8 -0
- package/src/executors/read-target-options.js +24 -0
- package/src/executors/read-target-options.js.map +1 -0
- package/src/generators/executor-options-utils.d.ts +21 -0
- package/src/generators/executor-options-utils.js +50 -0
- package/src/generators/executor-options-utils.js.map +1 -0
- package/src/generators/format-files.d.ts +6 -0
- package/src/generators/format-files.js +75 -0
- package/src/generators/format-files.js.map +1 -0
- package/src/generators/generate-files.d.ts +26 -0
- package/src/generators/generate-files.js +120 -0
- package/src/generators/generate-files.js.map +1 -0
- package/src/generators/run-tasks-in-serial.d.ts +7 -0
- package/src/generators/run-tasks-in-serial.js +18 -0
- package/src/generators/run-tasks-in-serial.js.map +1 -0
- package/src/generators/to-js.d.ts +5 -0
- package/src/generators/to-js.js +25 -0
- package/src/generators/to-js.js.map +1 -0
- package/src/generators/typescript/insert-import.d.ts +1 -0
- package/src/generators/typescript/insert-import.js +6 -0
- package/src/generators/typescript/insert-import.js.map +1 -0
- package/src/generators/typescript/insert-statement.d.ts +1 -0
- package/src/generators/typescript/insert-statement.js +6 -0
- package/src/generators/typescript/insert-statement.js.map +1 -0
- package/src/generators/update-ts-configs-to-js.d.ts +4 -0
- package/src/generators/update-ts-configs-to-js.js +50 -0
- package/src/generators/update-ts-configs-to-js.js.map +1 -0
- package/src/generators/visit-not-ignored-files.d.ts +5 -0
- package/src/generators/visit-not-ignored-files.js +37 -0
- package/src/generators/visit-not-ignored-files.js.map +1 -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 +13 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js.map +1 -0
- package/src/tasks/install-packages-task.d.ts +10 -0
- package/src/tasks/install-packages-task.js +35 -0
- package/src/tasks/install-packages-task.js.map +1 -0
- package/src/utils/async-iterable/combine-async-iterables.d.ts +3 -0
- package/src/utils/async-iterable/combine-async-iterables.js +82 -0
- package/src/utils/async-iterable/combine-async-iterables.js.map +1 -0
- package/src/utils/async-iterable/create-async-iterable.d.ts +6 -0
- package/src/utils/async-iterable/create-async-iterable.js +62 -0
- package/src/utils/async-iterable/create-async-iterable.js.map +1 -0
- package/src/utils/async-iterable/index.d.ts +4 -0
- package/src/utils/async-iterable/index.js +8 -0
- package/src/utils/async-iterable/index.js.map +1 -0
- package/src/utils/async-iterable/map-async-iteratable.d.ts +1 -0
- package/src/utils/async-iterable/map-async-iteratable.js +24 -0
- package/src/utils/async-iterable/map-async-iteratable.js.map +1 -0
- package/src/utils/async-iterable/tap-async-iteratable.d.ts +1 -0
- package/src/utils/async-iterable/tap-async-iteratable.js +15 -0
- package/src/utils/async-iterable/tap-async-iteratable.js.map +1 -0
- package/src/utils/convert-nx-executor.d.ts +7 -0
- package/src/utils/convert-nx-executor.js +88 -0
- package/src/utils/convert-nx-executor.js.map +1 -0
- package/src/utils/get-workspace-layout.d.ts +25 -0
- package/src/utils/get-workspace-layout.js +53 -0
- package/src/utils/get-workspace-layout.js.map +1 -0
- package/src/utils/invoke-nx-generator.d.ts +6 -0
- package/src/utils/invoke-nx-generator.js +174 -0
- package/src/utils/invoke-nx-generator.js.map +1 -0
- package/src/utils/module-federation/dependencies.d.ts +6 -0
- package/src/utils/module-federation/dependencies.js +47 -0
- package/src/utils/module-federation/dependencies.js.map +1 -0
- package/src/utils/module-federation/index.d.ts +5 -0
- package/src/utils/module-federation/index.js +9 -0
- package/src/utils/module-federation/index.js.map +1 -0
- package/src/utils/module-federation/models/index.d.ts +39 -0
- package/src/utils/module-federation/models/index.js +3 -0
- package/src/utils/module-federation/models/index.js.map +1 -0
- package/src/utils/module-federation/package-json.d.ts +8 -0
- package/src/utils/module-federation/package-json.js +15 -0
- package/src/utils/module-federation/package-json.js.map +1 -0
- package/src/utils/module-federation/remotes.d.ts +19 -0
- package/src/utils/module-federation/remotes.js +59 -0
- package/src/utils/module-federation/remotes.js.map +1 -0
- package/src/utils/module-federation/secondary-entry-points.d.ts +12 -0
- package/src/utils/module-federation/secondary-entry-points.js +106 -0
- package/src/utils/module-federation/secondary-entry-points.js.map +1 -0
- package/src/utils/module-federation/share.d.ts +48 -0
- package/src/utils/module-federation/share.js +187 -0
- package/src/utils/module-federation/share.js.map +1 -0
- package/src/utils/module-federation/typescript.d.ts +3 -0
- package/src/utils/module-federation/typescript.js +39 -0
- package/src/utils/module-federation/typescript.js.map +1 -0
- package/src/utils/move-dir.d.ts +5 -0
- package/src/utils/move-dir.js +29 -0
- package/src/utils/move-dir.js.map +1 -0
- package/src/utils/names.d.ts +18 -0
- package/src/utils/names.js +63 -0
- package/src/utils/names.js.map +1 -0
- package/src/utils/offset-from-root.d.ts +13 -0
- package/src/utils/offset-from-root.js +30 -0
- package/src/utils/offset-from-root.js.map +1 -0
- package/src/utils/package-json.d.ts +74 -0
- package/src/utils/package-json.js +305 -0
- package/src/utils/package-json.js.map +1 -0
- package/src/utils/replace-package.d.ts +2 -0
- package/src/utils/replace-package.js +107 -0
- package/src/utils/replace-package.js.map +1 -0
- package/src/utils/rxjs-for-await.d.ts +109 -0
- package/src/utils/rxjs-for-await.js +373 -0
- package/src/utils/rxjs-for-await.js.map +1 -0
- package/src/utils/semver.d.ts +1 -0
- package/src/utils/semver.js +19 -0
- package/src/utils/semver.js.map +1 -0
- package/src/utils/string-change.d.ts +62 -0
- package/src/utils/string-change.js +110 -0
- package/src/utils/string-change.js.map +1 -0
- package/src/utils/string-utils.d.ts +95 -0
- package/src/utils/string-utils.js +148 -0
- package/src/utils/string-utils.js.map +1 -0
- package/testing-pre16.d.ts +2 -0
- package/testing-pre16.js +10 -0
- package/testing-pre16.js.map +1 -0
- package/testing.d.ts +2 -0
- package/testing.js +9 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Generator } from 'nx/src/config/misc-interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* Convert an Nx Generator into an Angular Devkit Schematic.
|
|
4
|
+
* @param generator The Nx generator to convert to an Angular Devkit Schematic.
|
|
5
|
+
*/
|
|
6
|
+
export declare function convertNxGenerator<T = any>(generator: Generator<T>, skipWritingConfigInOldFormat?: boolean): (generatorOptions: T) => (tree: any, context: any) => Promise<any>;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertNxGenerator = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
6
|
+
const logger_1 = require("nx/src/utils/logger");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const nx_1 = require("../../nx");
|
|
9
|
+
const { logger } = (0, nx_1.requireNx)();
|
|
10
|
+
class RunCallbackTask {
|
|
11
|
+
constructor(callback) {
|
|
12
|
+
this.callback = callback;
|
|
13
|
+
}
|
|
14
|
+
toConfiguration() {
|
|
15
|
+
return {
|
|
16
|
+
name: 'RunCallback',
|
|
17
|
+
options: {
|
|
18
|
+
callback: this.callback,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function createRunCallbackTask() {
|
|
24
|
+
return {
|
|
25
|
+
name: 'RunCallback',
|
|
26
|
+
create: () => {
|
|
27
|
+
return Promise.resolve(({ callback }) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
yield callback();
|
|
29
|
+
}));
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Convert an Nx Generator into an Angular Devkit Schematic.
|
|
35
|
+
* @param generator The Nx generator to convert to an Angular Devkit Schematic.
|
|
36
|
+
*/
|
|
37
|
+
function convertNxGenerator(generator, skipWritingConfigInOldFormat = false) {
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
39
|
+
return (generatorOptions) => invokeNxGenerator(generator, generatorOptions);
|
|
40
|
+
}
|
|
41
|
+
exports.convertNxGenerator = convertNxGenerator;
|
|
42
|
+
/**
|
|
43
|
+
* Create a Rule to invoke an Nx Generator
|
|
44
|
+
*/
|
|
45
|
+
function invokeNxGenerator(generator, options, skipWritingConfigInOldFormat) {
|
|
46
|
+
return (tree, context) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
if (context.engine.workflow) {
|
|
48
|
+
const engineHost = context.engine.workflow.engineHost;
|
|
49
|
+
engineHost.registerTaskExecutor(createRunCallbackTask());
|
|
50
|
+
}
|
|
51
|
+
const root = context.engine.workflow && context.engine.workflow.engineHost.paths
|
|
52
|
+
? context.engine.workflow.engineHost.paths[1]
|
|
53
|
+
: tree.root.path;
|
|
54
|
+
const adapterTree = new DevkitTreeFromAngularDevkitTree(tree, root, skipWritingConfigInOldFormat);
|
|
55
|
+
const result = yield generator(adapterTree, options);
|
|
56
|
+
if (!result) {
|
|
57
|
+
return adapterTree['tree'];
|
|
58
|
+
}
|
|
59
|
+
if (typeof result === 'function') {
|
|
60
|
+
if (context.engine.workflow) {
|
|
61
|
+
context.addTask(new RunCallbackTask(result));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const actionToFileChangeMap = {
|
|
67
|
+
c: 'CREATE',
|
|
68
|
+
o: 'UPDATE',
|
|
69
|
+
d: 'DELETE',
|
|
70
|
+
};
|
|
71
|
+
class DevkitTreeFromAngularDevkitTree {
|
|
72
|
+
constructor(tree, _root, skipWritingConfigInOldFormat) {
|
|
73
|
+
this.tree = tree;
|
|
74
|
+
this._root = _root;
|
|
75
|
+
this.skipWritingConfigInOldFormat = skipWritingConfigInOldFormat;
|
|
76
|
+
/**
|
|
77
|
+
* When using the UnitTestTree from @angular-devkit/schematics/testing, the root is just `/`.
|
|
78
|
+
* This causes a massive issue if `getProjects()` is used in the underlying generator because it
|
|
79
|
+
* causes fast-glob to be set to work on the user's entire file system.
|
|
80
|
+
*
|
|
81
|
+
* Therefore, in this case, patch the root to match what Nx Devkit does and use /virtual instead.
|
|
82
|
+
*/
|
|
83
|
+
try {
|
|
84
|
+
const { UnitTestTree } = require('@angular-devkit/schematics/testing');
|
|
85
|
+
if (tree instanceof UnitTestTree && _root === '/') {
|
|
86
|
+
this._root = '/virtual';
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (_a) { }
|
|
90
|
+
}
|
|
91
|
+
get root() {
|
|
92
|
+
return this._root;
|
|
93
|
+
}
|
|
94
|
+
children(dirPath) {
|
|
95
|
+
const { subdirs, subfiles } = this.tree.getDir(dirPath);
|
|
96
|
+
return [...subdirs, ...subfiles];
|
|
97
|
+
}
|
|
98
|
+
delete(filePath) {
|
|
99
|
+
this.tree.delete(filePath);
|
|
100
|
+
}
|
|
101
|
+
exists(filePath) {
|
|
102
|
+
if (this.isFile(filePath)) {
|
|
103
|
+
return this.tree.exists(filePath);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return this.children(filePath).length > 0;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
isFile(filePath) {
|
|
110
|
+
return this.tree.exists(filePath) && !!this.tree.read(filePath);
|
|
111
|
+
}
|
|
112
|
+
listChanges() {
|
|
113
|
+
const fileChanges = [];
|
|
114
|
+
for (const action of this.tree.actions) {
|
|
115
|
+
if (action.kind === 'r') {
|
|
116
|
+
fileChanges.push({
|
|
117
|
+
path: this.normalize(action.to),
|
|
118
|
+
type: 'CREATE',
|
|
119
|
+
content: this.read(action.to),
|
|
120
|
+
});
|
|
121
|
+
fileChanges.push({
|
|
122
|
+
path: this.normalize(action.path),
|
|
123
|
+
type: 'DELETE',
|
|
124
|
+
content: null,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
else if (action.kind === 'c' || action.kind === 'o') {
|
|
128
|
+
fileChanges.push({
|
|
129
|
+
path: this.normalize(action.path),
|
|
130
|
+
type: actionToFileChangeMap[action.kind],
|
|
131
|
+
content: action.content,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
fileChanges.push({
|
|
136
|
+
path: this.normalize(action.path),
|
|
137
|
+
type: 'DELETE',
|
|
138
|
+
content: null,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return fileChanges;
|
|
143
|
+
}
|
|
144
|
+
normalize(path) {
|
|
145
|
+
return (0, path_1.relative)(this.root, (0, path_1.join)(this.root, path));
|
|
146
|
+
}
|
|
147
|
+
read(filePath, encoding) {
|
|
148
|
+
return encoding
|
|
149
|
+
? this.tree.read(filePath).toString(encoding)
|
|
150
|
+
: this.tree.read(filePath);
|
|
151
|
+
}
|
|
152
|
+
rename(from, to) {
|
|
153
|
+
this.tree.rename(from, to);
|
|
154
|
+
}
|
|
155
|
+
write(filePath, content, options) {
|
|
156
|
+
if (options === null || options === void 0 ? void 0 : options.mode) {
|
|
157
|
+
this.warnUnsupportedFilePermissionsChange(filePath, options.mode);
|
|
158
|
+
}
|
|
159
|
+
if (this.tree.exists(filePath)) {
|
|
160
|
+
this.tree.overwrite(filePath, content);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
this.tree.create(filePath, content);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
changePermissions(filePath, mode) {
|
|
167
|
+
this.warnUnsupportedFilePermissionsChange(filePath, mode);
|
|
168
|
+
}
|
|
169
|
+
warnUnsupportedFilePermissionsChange(filePath, mode) {
|
|
170
|
+
logger.warn((0, logger_1.stripIndent)(`The Angular DevKit tree does not support changing a file permissions.
|
|
171
|
+
Ignoring changing ${filePath} permissions to ${mode}.`));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=invoke-nx-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoke-nx-generator.js","sourceRoot":"","sources":["../../../../../packages/devkit/src/utils/invoke-nx-generator.ts"],"names":[],"mappings":";;;;AAAA,oEAAoE;AACpE,gDAAkD;AAUlD,+BAAsC;AAEtC,iCAAqC;AAErC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,cAAS,GAAE,CAAC;AAE/B,MAAM,eAAe;IACnB,YAAoB,QAA2B;QAA3B,aAAQ,GAAR,QAAQ,CAAmB;IAAG,CAAC;IAEnD,eAAe;QACb,OAAO;YACL,IAAI,EAAE,aAAa;YACnB,OAAO,EAAE;gBACP,QAAQ,EAAE,IAAI,CAAC,QAAQ;aACxB;SACF,CAAC;IACJ,CAAC;CACF;AAED,SAAS,qBAAqB;IAC5B,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,MAAM,EAAE,GAAG,EAAE;YACX,OAAO,OAAO,CAAC,OAAO,CACpB,CAAO,EAAE,QAAQ,EAAmC,EAAE,EAAE;gBACtD,MAAM,QAAQ,EAAE,CAAC;YACnB,CAAC,CAAA,CACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAgB,kBAAkB,CAChC,SAAuB,EACvB,+BAAwC,KAAK;IAE7C,6EAA6E;IA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AE,QAAyB;QAC9C,OAAO,QAAQ;YACb,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAC7C,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,IAAY,EAAE,EAAU;QAC7B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED,KAAK,CACH,QAAgB,EAChB,OAAwB,EACxB,OAA0B;QAE1B,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,EAAE;YACjB,IAAI,CAAC,oCAAoC,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;SACnE;QAED,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE;YAC9B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;SACxC;aAAM;YACL,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;SACrC;IACH,CAAC;IAED,iBAAiB,CAAC,QAAgB,EAAE,IAAU;QAC5C,IAAI,CAAC,oCAAoC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC5D,CAAC;IAEO,oCAAoC,CAAC,QAAgB,EAAE,IAAU;QACvE,MAAM,CAAC,IAAI,CACT,IAAA,oBAAW,EAAC;sCACoB,QAAQ,mBAAmB,IAAI,GAAG,CAAC,CACpE,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ProjectGraph } from 'nx/src/config/project-graph';
|
|
2
|
+
import type { WorkspaceLibrary } from './models';
|
|
3
|
+
export declare function getDependentPackagesForProject(projectGraph: ProjectGraph, name: string): {
|
|
4
|
+
workspaceLibraries: WorkspaceLibrary[];
|
|
5
|
+
npmPackages: string[];
|
|
6
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDependentPackagesForProject = void 0;
|
|
4
|
+
const typescript_1 = require("./typescript");
|
|
5
|
+
function getDependentPackagesForProject(projectGraph, name) {
|
|
6
|
+
const { npmPackages, workspaceLibraries } = collectDependencies(projectGraph, name);
|
|
7
|
+
return {
|
|
8
|
+
workspaceLibraries: [...workspaceLibraries.values()],
|
|
9
|
+
npmPackages: [...npmPackages],
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
exports.getDependentPackagesForProject = getDependentPackagesForProject;
|
|
13
|
+
function collectDependencies(projectGraph, name, dependencies = {
|
|
14
|
+
workspaceLibraries: new Map(),
|
|
15
|
+
npmPackages: new Set(),
|
|
16
|
+
}, seen = new Set()) {
|
|
17
|
+
var _a;
|
|
18
|
+
if (seen.has(name)) {
|
|
19
|
+
return dependencies;
|
|
20
|
+
}
|
|
21
|
+
seen.add(name);
|
|
22
|
+
((_a = projectGraph.dependencies[name]) !== null && _a !== void 0 ? _a : []).forEach((dependency) => {
|
|
23
|
+
if (dependency.target.startsWith('npm:')) {
|
|
24
|
+
dependencies.npmPackages.add(dependency.target.replace('npm:', ''));
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
dependencies.workspaceLibraries.set(dependency.target, {
|
|
28
|
+
name: dependency.target,
|
|
29
|
+
root: projectGraph.nodes[dependency.target].data.root,
|
|
30
|
+
importKey: getLibraryImportPath(dependency.target, projectGraph),
|
|
31
|
+
});
|
|
32
|
+
collectDependencies(projectGraph, dependency.target, dependencies, seen);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return dependencies;
|
|
36
|
+
}
|
|
37
|
+
function getLibraryImportPath(library, projectGraph) {
|
|
38
|
+
const tsConfigPathMappings = (0, typescript_1.readTsPathMappings)();
|
|
39
|
+
const sourceRoot = projectGraph.nodes[library].data.sourceRoot;
|
|
40
|
+
for (const [key, value] of Object.entries(tsConfigPathMappings)) {
|
|
41
|
+
if (value.find((path) => path.startsWith(sourceRoot))) {
|
|
42
|
+
return key;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=dependencies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../../../../../../packages/devkit/src/utils/module-federation/dependencies.ts"],"names":[],"mappings":";;;AAEA,6CAAkD;AAElD,SAAgB,8BAA8B,CAC5C,YAA0B,EAC1B,IAAY;IAKZ,MAAM,EAAE,WAAW,EAAE,kBAAkB,EAAE,GAAG,mBAAmB,CAC7D,YAAY,EACZ,IAAI,CACL,CAAC;IAEF,OAAO;QACL,kBAAkB,EAAE,CAAC,GAAG,kBAAkB,CAAC,MAAM,EAAE,CAAC;QACpD,WAAW,EAAE,CAAC,GAAG,WAAW,CAAC;KAC9B,CAAC;AACJ,CAAC;AAhBD,wEAgBC;AAED,SAAS,mBAAmB,CAC1B,YAA0B,EAC1B,IAAY,EACZ,eAAe;IACb,kBAAkB,EAAE,IAAI,GAAG,EAA4B;IACvD,WAAW,EAAE,IAAI,GAAG,EAAU;CAC/B,EACD,OAAoB,IAAI,GAAG,EAAE;;IAK7B,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QAClB,OAAO,YAAY,CAAC;KACrB;IACD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAEf,CAAC,MAAA,YAAY,CAAC,YAAY,CAAC,IAAI,CAAC,mCAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QAC7D,IAAI,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;YACxC,YAAY,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC;SACrE;aAAM;YACL,YAAY,CAAC,kBAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,EAAE;gBACrD,IAAI,EAAE,UAAU,CAAC,MAAM;gBACvB,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI;gBACrD,SAAS,EAAE,oBAAoB,CAAC,UAAU,CAAC,MAAM,EAAE,YAAY,CAAC;aACjE,CAAC,CAAC;YACH,mBAAmB,CAAC,YAAY,EAAE,UAAU,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;SAC1E;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,oBAAoB,CAC3B,OAAe,EACf,YAA0B;IAE1B,MAAM,oBAAoB,GAAG,IAAA,+BAAkB,GAAE,CAAC;IAElD,MAAM,UAAU,GAAG,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC;IAC/D,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE;QAC/D,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,EAAE;YACrD,OAAO,GAAG,CAAC;SACZ;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./share"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./dependencies"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./package-json"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./remotes"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./models"), exports);
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/devkit/src/utils/module-federation/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB;AACxB,yDAA+B;AAC/B,yDAA+B;AAC/B,oDAA0B;AAC1B,mDAAyB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { NormalModuleReplacementPlugin } from 'webpack';
|
|
2
|
+
export type ModuleFederationLibrary = {
|
|
3
|
+
type: string;
|
|
4
|
+
name: string;
|
|
5
|
+
};
|
|
6
|
+
export type WorkspaceLibrary = {
|
|
7
|
+
name: string;
|
|
8
|
+
root: string;
|
|
9
|
+
importKey: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
export type SharedWorkspaceLibraryConfig = {
|
|
12
|
+
getAliases: () => Record<string, string>;
|
|
13
|
+
getLibraries: (eager?: boolean) => Record<string, SharedLibraryConfig>;
|
|
14
|
+
getReplacementPlugin: () => NormalModuleReplacementPlugin;
|
|
15
|
+
};
|
|
16
|
+
export type Remotes = string[] | [remoteName: string, remoteUrl: string][];
|
|
17
|
+
export interface SharedLibraryConfig {
|
|
18
|
+
singleton?: boolean;
|
|
19
|
+
strictVersion?: boolean;
|
|
20
|
+
requiredVersion?: false | string;
|
|
21
|
+
eager?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export type SharedFunction = (libraryName: string, sharedConfig: SharedLibraryConfig) => undefined | false | SharedLibraryConfig;
|
|
24
|
+
export type AdditionalSharedConfig = Array<string | [libraryName: string, sharedConfig: SharedLibraryConfig] | {
|
|
25
|
+
libraryName: string;
|
|
26
|
+
sharedConfig: SharedLibraryConfig;
|
|
27
|
+
}>;
|
|
28
|
+
export interface ModuleFederationConfig {
|
|
29
|
+
name: string;
|
|
30
|
+
remotes?: Remotes;
|
|
31
|
+
library?: ModuleFederationLibrary;
|
|
32
|
+
exposes?: Record<string, string>;
|
|
33
|
+
shared?: SharedFunction;
|
|
34
|
+
additionalShared?: AdditionalSharedConfig;
|
|
35
|
+
}
|
|
36
|
+
export type WorkspaceLibrarySecondaryEntryPoint = {
|
|
37
|
+
name: string;
|
|
38
|
+
path: string;
|
|
39
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/devkit/src/utils/module-federation/models/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readRootPackageJson = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const nx_1 = require("../../../nx");
|
|
6
|
+
const { workspaceRoot, readJsonFile, joinPathFragments } = (0, nx_1.requireNx)();
|
|
7
|
+
function readRootPackageJson() {
|
|
8
|
+
const pkgJsonPath = joinPathFragments(workspaceRoot, 'package.json');
|
|
9
|
+
if (!(0, fs_1.existsSync)(pkgJsonPath)) {
|
|
10
|
+
throw new Error('NX MF: Could not find root package.json to determine dependency versions.');
|
|
11
|
+
}
|
|
12
|
+
return readJsonFile(pkgJsonPath);
|
|
13
|
+
}
|
|
14
|
+
exports.readRootPackageJson = readRootPackageJson;
|
|
15
|
+
//# sourceMappingURL=package-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-json.js","sourceRoot":"","sources":["../../../../../../packages/devkit/src/utils/module-federation/package-json.ts"],"names":[],"mappings":";;;AAAA,2BAAgC;AAChC,oCAAwC;AAExC,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EAAE,GAAG,IAAA,cAAS,GAAE,CAAC;AAEvE,SAAgB,mBAAmB;IAIjC,MAAM,WAAW,GAAG,iBAAiB,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;IACrE,IAAI,CAAC,IAAA,eAAU,EAAC,WAAW,CAAC,EAAE;QAC5B,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;KACH;IAED,OAAO,YAAY,CAAC,WAAW,CAAC,CAAC;AACnC,CAAC;AAZD,kDAYC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Remotes } from './models';
|
|
2
|
+
/**
|
|
3
|
+
* Map remote names to a format that can be understood and used by Module
|
|
4
|
+
* Federation.
|
|
5
|
+
*
|
|
6
|
+
* @param remotes - The remotes to map
|
|
7
|
+
* @param remoteEntryExt - The file extension of the remoteEntry file
|
|
8
|
+
* @param determineRemoteUrl - The function used to lookup the URL of the served remote
|
|
9
|
+
*/
|
|
10
|
+
export declare function mapRemotes(remotes: Remotes, remoteEntryExt: 'js' | 'mjs', determineRemoteUrl: (remote: string) => string): Record<string, string>;
|
|
11
|
+
/**
|
|
12
|
+
* Map remote names to a format that can be understood and used by Module
|
|
13
|
+
* Federation.
|
|
14
|
+
*
|
|
15
|
+
* @param remotes - The remotes to map
|
|
16
|
+
* @param remoteEntryExt - The file extension of the remoteEntry file
|
|
17
|
+
* @param determineRemoteUrl - The function used to lookup the URL of the served remote
|
|
18
|
+
*/
|
|
19
|
+
export declare function mapRemotesForSSR(remotes: Remotes, remoteEntryExt: 'js' | 'mjs', determineRemoteUrl: (remote: string) => string): Record<string, string>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapRemotesForSSR = exports.mapRemotes = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
/**
|
|
6
|
+
* Map remote names to a format that can be understood and used by Module
|
|
7
|
+
* Federation.
|
|
8
|
+
*
|
|
9
|
+
* @param remotes - The remotes to map
|
|
10
|
+
* @param remoteEntryExt - The file extension of the remoteEntry file
|
|
11
|
+
* @param determineRemoteUrl - The function used to lookup the URL of the served remote
|
|
12
|
+
*/
|
|
13
|
+
function mapRemotes(remotes, remoteEntryExt, determineRemoteUrl) {
|
|
14
|
+
const mappedRemotes = {};
|
|
15
|
+
for (const remote of remotes) {
|
|
16
|
+
if (Array.isArray(remote)) {
|
|
17
|
+
const [remoteName, remoteLocation] = remote;
|
|
18
|
+
const remoteLocationExt = (0, path_1.extname)(remoteLocation);
|
|
19
|
+
mappedRemotes[remoteName] = ['.js', '.mjs'].includes(remoteLocationExt)
|
|
20
|
+
? remoteLocation
|
|
21
|
+
: `${remoteLocation.endsWith('/')
|
|
22
|
+
? remoteLocation.slice(0, -1)
|
|
23
|
+
: remoteLocation}/remoteEntry.${remoteEntryExt}`;
|
|
24
|
+
}
|
|
25
|
+
else if (typeof remote === 'string') {
|
|
26
|
+
mappedRemotes[remote] = determineRemoteUrl(remote);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return mappedRemotes;
|
|
30
|
+
}
|
|
31
|
+
exports.mapRemotes = mapRemotes;
|
|
32
|
+
/**
|
|
33
|
+
* Map remote names to a format that can be understood and used by Module
|
|
34
|
+
* Federation.
|
|
35
|
+
*
|
|
36
|
+
* @param remotes - The remotes to map
|
|
37
|
+
* @param remoteEntryExt - The file extension of the remoteEntry file
|
|
38
|
+
* @param determineRemoteUrl - The function used to lookup the URL of the served remote
|
|
39
|
+
*/
|
|
40
|
+
function mapRemotesForSSR(remotes, remoteEntryExt, determineRemoteUrl) {
|
|
41
|
+
const mappedRemotes = {};
|
|
42
|
+
for (const remote of remotes) {
|
|
43
|
+
if (Array.isArray(remote)) {
|
|
44
|
+
const [remoteName, remoteLocation] = remote;
|
|
45
|
+
const remoteLocationExt = (0, path_1.extname)(remoteLocation);
|
|
46
|
+
mappedRemotes[remoteName] = `${remoteName}@${['.js', '.mjs'].includes(remoteLocationExt)
|
|
47
|
+
? remoteLocation
|
|
48
|
+
: `${remoteLocation.endsWith('/')
|
|
49
|
+
? remoteLocation.slice(0, -1)
|
|
50
|
+
: remoteLocation}/remoteEntry.${remoteEntryExt}`}`;
|
|
51
|
+
}
|
|
52
|
+
else if (typeof remote === 'string') {
|
|
53
|
+
mappedRemotes[remote] = `${remote}@${determineRemoteUrl(remote)}`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return mappedRemotes;
|
|
57
|
+
}
|
|
58
|
+
exports.mapRemotesForSSR = mapRemotesForSSR;
|
|
59
|
+
//# sourceMappingURL=remotes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remotes.js","sourceRoot":"","sources":["../../../../../../packages/devkit/src/utils/module-federation/remotes.ts"],"names":[],"mappings":";;;AACA,+BAA+B;AAE/B;;;;;;;GAOG;AACH,SAAgB,UAAU,CACxB,OAAgB,EAChB,cAA4B,EAC5B,kBAA8C;IAE9C,MAAM,aAAa,GAAG,EAAE,CAAC;IAEzB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;QAC5B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YACzB,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,GAAG,MAAM,CAAC;YAC5C,MAAM,iBAAiB,GAAG,IAAA,cAAO,EAAC,cAAc,CAAC,CAAC;YAClD,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,iBAAiB,CAAC;gBACrE,CAAC,CAAC,cAAc;gBAChB,CAAC,CAAC,GACE,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC;oBAC1B,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;oBAC7B,CAAC,CAAC,cACN,gBAAgB,cAAc,EAAE,CAAC;SACtC;aAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YACrC,aAAa,CAAC,MAAM,CAAC,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;SACpD;KACF;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AAxBD,gCAwBC;AAED;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAC9B,OAAgB,EAChB,cAA4B,EAC5B,kBAA8C;IAE9C,MAAM,aAAa,GAAG,EAAE,CAAC;IAEzB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;QAC5B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YACzB,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,GAAG,MAAM,CAAC;YAC5C,MAAM,iBAAiB,GAAG,IAAA,cAAO,EAAC,cAAc,CAAC,CAAC;YAClD,aAAa,CAAC,UAAU,CAAC,GAAG,GAAG,UAAU,IACvC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,iBAAiB,CAAC;gBACzC,CAAC,CAAC,cAAc;gBAChB,CAAC,CAAC,GACE,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC;oBAC1B,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;oBAC7B,CAAC,CAAC,cACN,gBAAgB,cAAc,EACpC,EAAE,CAAC;SACJ;aAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YACrC,aAAa,CAAC,MAAM,CAAC,GAAG,GAAG,MAAM,IAAI,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC;SACnE;KACF;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AA1BD,4CA0BC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { WorkspaceLibrary } from './models';
|
|
2
|
+
import { WorkspaceLibrarySecondaryEntryPoint } from './models';
|
|
3
|
+
export declare function collectWorkspaceLibrarySecondaryEntryPoints(library: WorkspaceLibrary, tsconfigPathAliases: Record<string, string[]>): WorkspaceLibrarySecondaryEntryPoint[];
|
|
4
|
+
export declare function getNonNodeModulesSubDirs(directory: string): string[];
|
|
5
|
+
export declare function recursivelyCollectSecondaryEntryPointsFromDirectory(pkgName: string, pkgVersion: string, pkgRoot: string, mainEntryPointExports: any | undefined, directories: string[], collectedPackages: {
|
|
6
|
+
name: string;
|
|
7
|
+
version: string;
|
|
8
|
+
}[]): void;
|
|
9
|
+
export declare function collectPackageSecondaryEntryPoints(pkgName: string, pkgVersion: string, collectedPackages: {
|
|
10
|
+
name: string;
|
|
11
|
+
version: string;
|
|
12
|
+
}[]): void;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collectPackageSecondaryEntryPoints = exports.recursivelyCollectSecondaryEntryPointsFromDirectory = exports.getNonNodeModulesSubDirs = exports.collectWorkspaceLibrarySecondaryEntryPoints = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
7
|
+
const package_json_1 = require("nx/src/utils/package-json");
|
|
8
|
+
const nx_1 = require("../../../nx");
|
|
9
|
+
const { readJsonFile, joinPathFragments, workspaceRoot } = (0, nx_1.requireNx)();
|
|
10
|
+
function collectWorkspaceLibrarySecondaryEntryPoints(library, tsconfigPathAliases) {
|
|
11
|
+
const libraryRoot = (0, path_1.join)(workspaceRoot, library.root);
|
|
12
|
+
const needsSecondaryEntryPointsCollected = (0, fs_1.existsSync)((0, path_1.join)(libraryRoot, 'ng-package.json'));
|
|
13
|
+
const secondaryEntryPoints = [];
|
|
14
|
+
if (needsSecondaryEntryPointsCollected) {
|
|
15
|
+
const tsConfigAliasesForLibWithSecondaryEntryPoints = Object.entries(tsconfigPathAliases).reduce((acc, [tsKey, tsPaths]) => {
|
|
16
|
+
if (!tsKey.startsWith(library.importKey)) {
|
|
17
|
+
return Object.assign({}, acc);
|
|
18
|
+
}
|
|
19
|
+
if (tsPaths.some((path) => path.startsWith(`${library.root}/`))) {
|
|
20
|
+
acc = Object.assign(Object.assign({}, acc), { [tsKey]: tsPaths });
|
|
21
|
+
}
|
|
22
|
+
return acc;
|
|
23
|
+
}, {});
|
|
24
|
+
for (const [alias] of Object.entries(tsConfigAliasesForLibWithSecondaryEntryPoints)) {
|
|
25
|
+
const pathToLib = (0, path_1.dirname)((0, path_1.join)(workspaceRoot, tsconfigPathAliases[alias][0]));
|
|
26
|
+
let searchDir = pathToLib;
|
|
27
|
+
while (searchDir !== libraryRoot) {
|
|
28
|
+
if ((0, fs_1.existsSync)((0, path_1.join)(searchDir, 'ng-package.json'))) {
|
|
29
|
+
secondaryEntryPoints.push({ name: alias, path: pathToLib });
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
searchDir = (0, path_1.dirname)(searchDir);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return secondaryEntryPoints;
|
|
37
|
+
}
|
|
38
|
+
exports.collectWorkspaceLibrarySecondaryEntryPoints = collectWorkspaceLibrarySecondaryEntryPoints;
|
|
39
|
+
function getNonNodeModulesSubDirs(directory) {
|
|
40
|
+
return (0, fs_1.readdirSync)(directory)
|
|
41
|
+
.filter((file) => file !== 'node_modules')
|
|
42
|
+
.map((file) => (0, path_1.join)(directory, file))
|
|
43
|
+
.filter((file) => (0, fs_1.lstatSync)(file).isDirectory());
|
|
44
|
+
}
|
|
45
|
+
exports.getNonNodeModulesSubDirs = getNonNodeModulesSubDirs;
|
|
46
|
+
function recursivelyCollectSecondaryEntryPointsFromDirectory(pkgName, pkgVersion, pkgRoot, mainEntryPointExports, directories, collectedPackages) {
|
|
47
|
+
for (const directory of directories) {
|
|
48
|
+
const packageJsonPath = (0, path_1.join)(directory, 'package.json');
|
|
49
|
+
const relativeEntryPointPath = (0, path_1.relative)(pkgRoot, directory);
|
|
50
|
+
const entryPointName = joinPathFragments(pkgName, relativeEntryPointPath);
|
|
51
|
+
if ((0, fs_1.existsSync)(packageJsonPath)) {
|
|
52
|
+
try {
|
|
53
|
+
// require the secondary entry point to try to rule out sample code
|
|
54
|
+
require.resolve(entryPointName, { paths: [workspaceRoot] });
|
|
55
|
+
const { name } = readJsonFile(packageJsonPath);
|
|
56
|
+
// further check to make sure what we were able to require is the
|
|
57
|
+
// same as the package name
|
|
58
|
+
if (name === entryPointName) {
|
|
59
|
+
collectedPackages.push({ name, version: pkgVersion });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (_a) { }
|
|
63
|
+
}
|
|
64
|
+
else if (mainEntryPointExports) {
|
|
65
|
+
// if the package.json doesn't exist, check if the directory is
|
|
66
|
+
// exported by the main entry point
|
|
67
|
+
const entryPointExportKey = `./${relativeEntryPointPath}`;
|
|
68
|
+
const entryPointInfo = mainEntryPointExports[entryPointExportKey];
|
|
69
|
+
if (entryPointInfo) {
|
|
70
|
+
collectedPackages.push({
|
|
71
|
+
name: entryPointName,
|
|
72
|
+
version: pkgVersion,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const subDirs = getNonNodeModulesSubDirs(directory);
|
|
77
|
+
recursivelyCollectSecondaryEntryPointsFromDirectory(pkgName, pkgVersion, pkgRoot, mainEntryPointExports, subDirs, collectedPackages);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.recursivelyCollectSecondaryEntryPointsFromDirectory = recursivelyCollectSecondaryEntryPointsFromDirectory;
|
|
81
|
+
function collectPackageSecondaryEntryPoints(pkgName, pkgVersion, collectedPackages) {
|
|
82
|
+
let pathToPackage;
|
|
83
|
+
let packageJsonPath;
|
|
84
|
+
let packageJson;
|
|
85
|
+
try {
|
|
86
|
+
({ path: packageJsonPath, packageJson } = (0, package_json_1.readModulePackageJson)(pkgName));
|
|
87
|
+
pathToPackage = (0, path_1.dirname)(packageJsonPath);
|
|
88
|
+
}
|
|
89
|
+
catch (_a) {
|
|
90
|
+
// the package.json might not resolve if the package has the "exports"
|
|
91
|
+
// entry and is not exporting the package.json file, fall back to trying
|
|
92
|
+
// to find it from the top-level node_modules
|
|
93
|
+
pathToPackage = (0, path_1.join)(workspaceRoot, 'node_modules', pkgName);
|
|
94
|
+
packageJsonPath = (0, path_1.join)(pathToPackage, 'package.json');
|
|
95
|
+
if (!(0, fs_1.existsSync)(packageJsonPath)) {
|
|
96
|
+
// might not exist if it's nested in another package, just return here
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
packageJson = readJsonFile(packageJsonPath);
|
|
100
|
+
}
|
|
101
|
+
const { exports } = packageJson;
|
|
102
|
+
const subDirs = getNonNodeModulesSubDirs(pathToPackage);
|
|
103
|
+
recursivelyCollectSecondaryEntryPointsFromDirectory(pkgName, pkgVersion, pathToPackage, exports, subDirs, collectedPackages);
|
|
104
|
+
}
|
|
105
|
+
exports.collectPackageSecondaryEntryPoints = collectPackageSecondaryEntryPoints;
|
|
106
|
+
//# sourceMappingURL=secondary-entry-points.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secondary-entry-points.js","sourceRoot":"","sources":["../../../../../../packages/devkit/src/utils/module-federation/secondary-entry-points.ts"],"names":[],"mappings":";;;AAEA,+BAA+C;AAC/C,2BAAwD;AAExD,oEAAoE;AACpE,4DAA+E;AAC/E,oCAAwC;AAExC,MAAM,EAAE,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,GAAG,IAAA,cAAS,GAAE,CAAC;AAEvE,SAAgB,2CAA2C,CACzD,OAAyB,EACzB,mBAA6C;IAE7C,MAAM,WAAW,GAAG,IAAA,WAAI,EAAC,aAAa,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,MAAM,kCAAkC,GAAG,IAAA,eAAU,EACnD,IAAA,WAAI,EAAC,WAAW,EAAE,iBAAiB,CAAC,CACrC,CAAC;IAEF,MAAM,oBAAoB,GAA0C,EAAE,CAAC;IACvE,IAAI,kCAAkC,EAAE;QACtC,MAAM,6CAA6C,GAAG,MAAM,CAAC,OAAO,CAClE,mBAAmB,CACpB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,OAAO,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ditionalSharedConfig, SharedFunction } from './models';
|
|
3
|
+
import type { ProjectGraph } from 'nx/src/config/project-graph';
|
|
4
|
+
/**
|
|
5
|
+
* Build an object of functions to be used with the ModuleFederationPlugin to
|
|
6
|
+
* share Nx Workspace Libraries between Hosts and Remotes.
|
|
7
|
+
*
|
|
8
|
+
* @param libraries - The Nx Workspace Libraries to share
|
|
9
|
+
* @param tsConfigPath - The path to TS Config File that contains the Path Mappings for the Libraries
|
|
10
|
+
*/
|
|
11
|
+
export declare function shareWorkspaceLibraries(libraries: WorkspaceLibrary[], tsConfigPath?: string): SharedWorkspaceLibraryConfig;
|
|
12
|
+
/**
|
|
13
|
+
* Build the Module Federation Share Config for a specific package and the
|
|
14
|
+
* specified version of that package.
|
|
15
|
+
* @param pkgName - Name of the package to share
|
|
16
|
+
* @param version - Version of the package to require by other apps in the Module Federation setup
|
|
17
|
+
*/
|
|
18
|
+
export declare function getNpmPackageSharedConfig(pkgName: string, version: string): SharedLibraryConfig | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Create a dictionary of packages and their Module Federation Shared Config
|
|
21
|
+
* from an array of package names.
|
|
22
|
+
*
|
|
23
|
+
* Lookup the versions of the packages from the root package.json file in the
|
|
24
|
+
* workspace.
|
|
25
|
+
* @param packages - Array of package names as strings
|
|
26
|
+
*/
|
|
27
|
+
export declare function sharePackages(packages: string[]): Record<string, SharedLibraryConfig>;
|
|
28
|
+
/**
|
|
29
|
+
* Apply a custom function provided by the user that will modify the Shared Config
|
|
30
|
+
* of the dependencies for the Module Federation build.
|
|
31
|
+
*
|
|
32
|
+
* @param sharedConfig - The original Shared Config to be modified
|
|
33
|
+
* @param sharedFn - The custom function to run
|
|
34
|
+
*/
|
|
35
|
+
export declare function applySharedFunction(sharedConfig: Record<string, SharedLibraryConfig>, sharedFn: SharedFunction | undefined): void;
|
|
36
|
+
/**
|
|
37
|
+
* Add additional dependencies to the shared package that may not have been
|
|
38
|
+
* discovered by the project graph.
|
|
39
|
+
*
|
|
40
|
+
* This can be useful for applications that use a Dependency Injection system
|
|
41
|
+
* that expects certain Singleton values to be present in the shared injection
|
|
42
|
+
* hierarchy.
|
|
43
|
+
*
|
|
44
|
+
* @param sharedConfig - The original Shared Config
|
|
45
|
+
* @param additionalShared - The additional dependencies to add
|
|
46
|
+
* @param projectGraph - The Nx project graph
|
|
47
|
+
*/
|
|
48
|
+
export declare function applyAdditionalShared(sharedConfig: Record<string, SharedLibraryConfig>, additionalShared: AdditionalSharedConfig | undefined, projectGraph: ProjectGraph): void;
|