@nx/js 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/babel.d.ts +13 -0
- package/babel.js +91 -0
- package/executors.json +32 -0
- package/generators.json +46 -0
- package/migrations.json +159 -0
- package/package.json +76 -0
- package/plugins/jest/local-registry.d.ts +1 -0
- package/plugins/jest/local-registry.js +4 -0
- package/src/executors/node/lib/kill-tree.d.ts +2 -0
- package/src/executors/node/lib/kill-tree.js +114 -0
- package/src/executors/node/node-with-require-overrides.d.ts +7 -0
- package/src/executors/node/node-with-require-overrides.js +21 -0
- package/src/executors/node/node.impl.d.ts +7 -0
- package/src/executors/node/node.impl.js +288 -0
- package/src/executors/node/schema.d.ts +18 -0
- package/src/executors/node/schema.json +92 -0
- package/src/executors/release-publish/format-bytes.d.ts +1 -0
- package/src/executors/release-publish/format-bytes.js +28 -0
- package/src/executors/release-publish/log-tar.d.ts +1 -0
- package/src/executors/release-publish/log-tar.js +68 -0
- package/src/executors/release-publish/release-publish.impl.d.ts +5 -0
- package/src/executors/release-publish/release-publish.impl.js +198 -0
- package/src/executors/release-publish/schema.d.ts +8 -0
- package/src/executors/release-publish/schema.json +26 -0
- package/src/executors/swc/schema.json +154 -0
- package/src/executors/swc/swc.impl.d.ts +10 -0
- package/src/executors/swc/swc.impl.js +149 -0
- package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.d.ts +5 -0
- package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.js +62 -0
- package/src/executors/tsc/lib/batch/index.d.ts +4 -0
- package/src/executors/tsc/lib/batch/index.js +7 -0
- package/src/executors/tsc/lib/batch/normalize-tasks-options.d.ts +3 -0
- package/src/executors/tsc/lib/batch/normalize-tasks-options.js +14 -0
- package/src/executors/tsc/lib/batch/types.d.ts +17 -0
- package/src/executors/tsc/lib/batch/types.js +2 -0
- package/src/executors/tsc/lib/batch/watch.d.ts +3 -0
- package/src/executors/tsc/lib/batch/watch.js +56 -0
- package/src/executors/tsc/lib/get-custom-transformers-factory.d.ts +3 -0
- package/src/executors/tsc/lib/get-custom-transformers-factory.js +13 -0
- package/src/executors/tsc/lib/get-task-options.d.ts +3 -0
- package/src/executors/tsc/lib/get-task-options.js +34 -0
- package/src/executors/tsc/lib/get-tsconfig.d.ts +4 -0
- package/src/executors/tsc/lib/get-tsconfig.js +86 -0
- package/src/executors/tsc/lib/index.d.ts +4 -0
- package/src/executors/tsc/lib/index.js +7 -0
- package/src/executors/tsc/lib/normalize-options.d.ts +2 -0
- package/src/executors/tsc/lib/normalize-options.js +39 -0
- package/src/executors/tsc/lib/typescript-compilation.d.ts +29 -0
- package/src/executors/tsc/lib/typescript-compilation.js +203 -0
- package/src/executors/tsc/lib/typescript-diagnostic-reporters.d.ts +3 -0
- package/src/executors/tsc/lib/typescript-diagnostic-reporters.js +37 -0
- package/src/executors/tsc/schema.json +163 -0
- package/src/executors/tsc/tsc.batch-impl.d.ts +5 -0
- package/src/executors/tsc/tsc.batch-impl.js +180 -0
- package/src/executors/tsc/tsc.impl.d.ts +7 -0
- package/src/executors/tsc/tsc.impl.js +97 -0
- package/src/executors/verdaccio/schema.d.ts +7 -0
- package/src/executors/verdaccio/schema.json +35 -0
- package/src/executors/verdaccio/verdaccio.impl.d.ts +12 -0
- package/src/executors/verdaccio/verdaccio.impl.js +220 -0
- package/src/generators/convert-to-swc/convert-to-swc.d.ts +4 -0
- package/src/generators/convert-to-swc/convert-to-swc.js +59 -0
- package/src/generators/convert-to-swc/schema.d.ts +4 -0
- package/src/generators/convert-to-swc/schema.json +36 -0
- package/src/generators/init/files/__fileName__ +20 -0
- package/src/generators/init/init.d.ts +4 -0
- package/src/generators/init/init.js +114 -0
- package/src/generators/init/schema.d.ts +7 -0
- package/src/generators/init/schema.json +36 -0
- package/src/generators/library/files/jest-config/jest.config.__ext__ +30 -0
- package/src/generators/library/files/lib/src/index.ts__tmpl__ +1 -0
- package/src/generators/library/files/lib/src/lib/__fileName__.spec.ts__tmpl__ +7 -0
- package/src/generators/library/files/lib/src/lib/__fileName__.ts__tmpl__ +3 -0
- package/src/generators/library/files/lib/tsconfig.lib.json__tmpl__ +14 -0
- package/src/generators/library/files/readme/README.md +19 -0
- package/src/generators/library/library.d.ts +16 -0
- package/src/generators/library/library.js +751 -0
- package/src/generators/library/schema.json +151 -0
- package/src/generators/release-version/release-version.d.ts +5 -0
- package/src/generators/release-version/release-version.js +390 -0
- package/src/generators/release-version/schema.d.ts +1 -0
- package/src/generators/release-version/schema.json +67 -0
- package/src/generators/release-version/test-utils/create-workspace-with-package-dependencies.d.ts +16 -0
- package/src/generators/release-version/test-utils/create-workspace-with-package-dependencies.js +40 -0
- package/src/generators/release-version/utils/package.d.ts +12 -0
- package/src/generators/release-version/utils/package.js +34 -0
- package/src/generators/release-version/utils/resolve-local-package-dependencies.d.ts +12 -0
- package/src/generators/release-version/utils/resolve-local-package-dependencies.js +78 -0
- package/src/generators/release-version/utils/resolve-version-spec.d.ts +1 -0
- package/src/generators/release-version/utils/resolve-version-spec.js +29 -0
- package/src/generators/release-version/utils/update-lock-file.d.ts +5 -0
- package/src/generators/release-version/utils/update-lock-file.js +105 -0
- package/src/generators/setup-build/generator.d.ts +4 -0
- package/src/generators/setup-build/generator.js +142 -0
- package/src/generators/setup-build/schema.d.ts +7 -0
- package/src/generators/setup-build/schema.json +42 -0
- package/src/generators/setup-verdaccio/files/config.yml +28 -0
- package/src/generators/setup-verdaccio/generator.d.ts +4 -0
- package/src/generators/setup-verdaccio/generator.js +56 -0
- package/src/generators/setup-verdaccio/schema.d.ts +3 -0
- package/src/generators/setup-verdaccio/schema.json +16 -0
- package/src/index.d.ts +17 -0
- package/src/index.js +28 -0
- package/src/internal.d.ts +4 -0
- package/src/internal.js +15 -0
- package/src/migrations/update-15-8-0/rename-swcrc-config.d.ts +2 -0
- package/src/migrations/update-15-8-0/rename-swcrc-config.js +77 -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-6-0/explicitly-set-projects-to-update-buildable-deps.d.ts +2 -0
- package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.js +34 -0
- package/src/migrations/update-16-8-2/update-swcrc.d.ts +2 -0
- package/src/migrations/update-16-8-2/update-swcrc.js +23 -0
- package/src/migrations/update-17-0-0/remove-deprecated-build-options.d.ts +6 -0
- package/src/migrations/update-17-0-0/remove-deprecated-build-options.js +30 -0
- package/src/plugins/jest/start-local-registry.d.ts +12 -0
- package/src/plugins/jest/start-local-registry.js +63 -0
- package/src/plugins/rollup/type-definitions.d.ts +8 -0
- package/src/plugins/rollup/type-definitions.js +48 -0
- package/src/utils/add-babel-inputs.d.ts +3 -0
- package/src/utils/add-babel-inputs.js +23 -0
- package/src/utils/add-local-registry-scripts.d.ts +5 -0
- package/src/utils/add-local-registry-scripts.js +77 -0
- package/src/utils/assets/assets.d.ts +10 -0
- package/src/utils/assets/assets.js +36 -0
- package/src/utils/assets/copy-assets-handler.d.ts +32 -0
- package/src/utils/assets/copy-assets-handler.js +154 -0
- package/src/utils/assets/index.d.ts +16 -0
- package/src/utils/assets/index.js +27 -0
- package/src/utils/buildable-libs-utils.d.ts +43 -0
- package/src/utils/buildable-libs-utils.js +375 -0
- package/src/utils/check-dependencies.d.ts +8 -0
- package/src/utils/check-dependencies.js +23 -0
- package/src/utils/code-frames/highlight.d.ts +1 -0
- package/src/utils/code-frames/highlight.js +86 -0
- package/src/utils/code-frames/identifiers.d.ts +5 -0
- package/src/utils/code-frames/identifiers.js +52 -0
- package/src/utils/compiler-helper-dependency.d.ts +18 -0
- package/src/utils/compiler-helper-dependency.js +120 -0
- package/src/utils/find-npm-dependencies.d.ts +9 -0
- package/src/utils/find-npm-dependencies.js +140 -0
- package/src/utils/generate-globs.d.ts +6 -0
- package/src/utils/generate-globs.js +80 -0
- package/src/utils/get-import-path.d.ts +5 -0
- package/src/utils/get-import-path.js +14 -0
- package/src/utils/get-main-file-dir.d.ts +1 -0
- package/src/utils/get-main-file-dir.js +11 -0
- package/src/utils/inline.d.ts +19 -0
- package/src/utils/inline.js +210 -0
- package/src/utils/package-json/create-entry-points.d.ts +1 -0
- package/src/utils/package-json/create-entry-points.js +23 -0
- package/src/utils/package-json/get-npm-scope.d.ts +5 -0
- package/src/utils/package-json/get-npm-scope.js +16 -0
- package/src/utils/package-json/index.d.ts +13 -0
- package/src/utils/package-json/index.js +30 -0
- package/src/utils/package-json/update-package-json.d.ts +30 -0
- package/src/utils/package-json/update-package-json.js +179 -0
- package/src/utils/prettier.d.ts +6 -0
- package/src/utils/prettier.js +34 -0
- package/src/utils/schema.d.ts +87 -0
- package/src/utils/swc/add-swc-config.d.ts +3 -0
- package/src/utils/swc/add-swc-config.js +41 -0
- package/src/utils/swc/add-swc-dependencies.d.ts +3 -0
- package/src/utils/swc/add-swc-dependencies.js +18 -0
- package/src/utils/swc/compile-swc.d.ts +13 -0
- package/src/utils/swc/compile-swc.js +160 -0
- package/src/utils/swc/get-swcrc-path.d.ts +5 -0
- package/src/utils/swc/get-swcrc-path.js +15 -0
- package/src/utils/swc/inline.d.ts +2 -0
- package/src/utils/swc/inline.js +11 -0
- package/src/utils/typescript/__mocks__/plugin-a.d.ts +1 -0
- package/src/utils/typescript/__mocks__/plugin-a.js +5 -0
- package/src/utils/typescript/__mocks__/plugin-b.d.ts +1 -0
- package/src/utils/typescript/__mocks__/plugin-b.js +5 -0
- package/src/utils/typescript/add-tslib-dependencies.d.ts +2 -0
- package/src/utils/typescript/add-tslib-dependencies.js +11 -0
- package/src/utils/typescript/ast-utils.d.ts +32 -0
- package/src/utils/typescript/ast-utils.js +266 -0
- package/src/utils/typescript/compile-typescript-files.d.ts +10 -0
- package/src/utils/typescript/compile-typescript-files.js +43 -0
- package/src/utils/typescript/create-ts-config.d.ts +18 -0
- package/src/utils/typescript/create-ts-config.js +48 -0
- package/src/utils/typescript/ensure-typescript.d.ts +1 -0
- package/src/utils/typescript/ensure-typescript.js +9 -0
- package/src/utils/typescript/get-source-nodes.d.ts +2 -0
- package/src/utils/typescript/get-source-nodes.js +18 -0
- package/src/utils/typescript/load-ts-transformers.d.ts +5 -0
- package/src/utils/typescript/load-ts-transformers.js +62 -0
- package/src/utils/typescript/print-diagnostics.d.ts +1 -0
- package/src/utils/typescript/print-diagnostics.js +18 -0
- package/src/utils/typescript/run-type-check.d.ts +32 -0
- package/src/utils/typescript/run-type-check.js +128 -0
- package/src/utils/typescript/ts-config.d.ts +9 -0
- package/src/utils/typescript/ts-config.js +85 -0
- package/src/utils/typescript/tsnode-register.d.ts +1 -0
- package/src/utils/typescript/tsnode-register.js +24 -0
- package/src/utils/typescript/types.d.ts +18 -0
- package/src/utils/typescript/types.js +2 -0
- package/src/utils/versions.d.ts +17 -0
- package/src/utils/versions.js +21 -0
- package/src/utils/watch-for-single-file-changes.d.ts +1 -0
- package/src/utils/watch-for-single-file-changes.js +22 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CopyAssetsHandler = exports.defaultFileEventHandler = void 0;
|
|
4
|
+
const minimatch_1 = require("minimatch");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const fse = require("fs-extra");
|
|
7
|
+
const ignore_1 = require("ignore");
|
|
8
|
+
const fg = require("fast-glob");
|
|
9
|
+
const devkit_1 = require("@nx/devkit");
|
|
10
|
+
const client_1 = require("nx/src/daemon/client/client");
|
|
11
|
+
const defaultFileEventHandler = (events) => {
|
|
12
|
+
const dirs = new Set(events.map((event) => path.dirname(event.dest)));
|
|
13
|
+
dirs.forEach((d) => fse.ensureDirSync(d));
|
|
14
|
+
events.forEach((event) => {
|
|
15
|
+
if (event.type === 'create' || event.type === 'update') {
|
|
16
|
+
if (fse.lstatSync(event.src).isFile()) {
|
|
17
|
+
fse.copyFileSync(event.src, event.dest);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else if (event.type === 'delete') {
|
|
21
|
+
fse.removeSync(event.dest);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
devkit_1.logger.error(`Unknown file event: ${event.type}`);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
exports.defaultFileEventHandler = defaultFileEventHandler;
|
|
29
|
+
class CopyAssetsHandler {
|
|
30
|
+
constructor(opts) {
|
|
31
|
+
this.rootDir = opts.rootDir;
|
|
32
|
+
this.projectDir = opts.projectDir;
|
|
33
|
+
this.outputDir = opts.outputDir;
|
|
34
|
+
this.callback = opts.callback ?? exports.defaultFileEventHandler;
|
|
35
|
+
// TODO(jack): Should handle nested .gitignore files
|
|
36
|
+
this.ignore = (0, ignore_1.default)();
|
|
37
|
+
const gitignore = path.join(opts.rootDir, '.gitignore');
|
|
38
|
+
const nxignore = path.join(opts.rootDir, '.nxignore');
|
|
39
|
+
if (fse.existsSync(gitignore))
|
|
40
|
+
this.ignore.add(fse.readFileSync(gitignore).toString());
|
|
41
|
+
if (fse.existsSync(nxignore))
|
|
42
|
+
this.ignore.add(fse.readFileSync(nxignore).toString());
|
|
43
|
+
this.assetGlobs = opts.assets.map((f) => {
|
|
44
|
+
let isGlob = false;
|
|
45
|
+
let pattern;
|
|
46
|
+
// Input and output directories are normalized to be relative to root
|
|
47
|
+
let input;
|
|
48
|
+
let output;
|
|
49
|
+
let ignore = null;
|
|
50
|
+
if (typeof f === 'string') {
|
|
51
|
+
pattern = f;
|
|
52
|
+
input = path.relative(opts.rootDir, opts.projectDir);
|
|
53
|
+
output = path.relative(opts.rootDir, opts.outputDir);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
isGlob = true;
|
|
57
|
+
pattern = path.join(f.input, f.glob);
|
|
58
|
+
input = f.input;
|
|
59
|
+
output = path.join(path.relative(opts.rootDir, opts.outputDir), f.output);
|
|
60
|
+
if (f.ignore)
|
|
61
|
+
ignore = f.ignore.map((ig) => path.join(f.input, ig));
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
isGlob,
|
|
65
|
+
input,
|
|
66
|
+
pattern,
|
|
67
|
+
ignore,
|
|
68
|
+
output,
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async processAllAssetsOnce() {
|
|
73
|
+
await Promise.all(this.assetGlobs.map(async (ag) => {
|
|
74
|
+
const pattern = this.normalizeAssetPattern(ag);
|
|
75
|
+
// fast-glob only supports Unix paths
|
|
76
|
+
const files = await fg(pattern.replace(/\\/g, '/'), {
|
|
77
|
+
cwd: this.rootDir,
|
|
78
|
+
dot: true, // enable hidden files
|
|
79
|
+
});
|
|
80
|
+
this.callback(this.filesToEvent(files, ag));
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
processAllAssetsOnceSync() {
|
|
84
|
+
this.assetGlobs.forEach((ag) => {
|
|
85
|
+
const pattern = this.normalizeAssetPattern(ag);
|
|
86
|
+
// fast-glob only supports Unix paths
|
|
87
|
+
const files = fg.sync(pattern.replace(/\\/g, '/'), {
|
|
88
|
+
cwd: this.rootDir,
|
|
89
|
+
dot: true, // enable hidden files
|
|
90
|
+
});
|
|
91
|
+
this.callback(this.filesToEvent(files, ag));
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async watchAndProcessOnAssetChange() {
|
|
95
|
+
const unregisterFileWatcher = await client_1.daemonClient.registerFileWatcher({
|
|
96
|
+
watchProjects: 'all',
|
|
97
|
+
includeGlobalWorkspaceFiles: true,
|
|
98
|
+
}, (err, data) => {
|
|
99
|
+
if (err === 'closed') {
|
|
100
|
+
devkit_1.logger.error(`Watch error: Daemon closed the connection`);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
else if (err) {
|
|
104
|
+
devkit_1.logger.error(`Watch error: ${err?.message ?? 'Unknown'}`);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
this.processWatchEvents(data.changedFiles);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
return () => unregisterFileWatcher();
|
|
111
|
+
}
|
|
112
|
+
async processWatchEvents(events) {
|
|
113
|
+
const fileEvents = [];
|
|
114
|
+
for (const event of events) {
|
|
115
|
+
const pathFromRoot = path.relative(this.rootDir, event.path);
|
|
116
|
+
for (const ag of this.assetGlobs) {
|
|
117
|
+
if ((0, minimatch_1.minimatch)(pathFromRoot, ag.pattern) &&
|
|
118
|
+
!ag.ignore?.some((ig) => (0, minimatch_1.minimatch)(pathFromRoot, ig)) &&
|
|
119
|
+
!this.ignore.ignores(pathFromRoot)) {
|
|
120
|
+
const relPath = path.relative(ag.input, pathFromRoot);
|
|
121
|
+
const destPath = relPath.startsWith('..') ? pathFromRoot : relPath;
|
|
122
|
+
fileEvents.push({
|
|
123
|
+
type: event.type,
|
|
124
|
+
src: path.join(this.rootDir, pathFromRoot),
|
|
125
|
+
dest: path.join(this.rootDir, ag.output, destPath),
|
|
126
|
+
});
|
|
127
|
+
// Match first entry and skip the rest for this file.
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (fileEvents.length > 0)
|
|
133
|
+
this.callback(fileEvents);
|
|
134
|
+
}
|
|
135
|
+
filesToEvent(files, assetGlob) {
|
|
136
|
+
return files.reduce((acc, src) => {
|
|
137
|
+
if (!assetGlob.ignore?.some((ig) => (0, minimatch_1.minimatch)(src, ig)) &&
|
|
138
|
+
!this.ignore.ignores(src)) {
|
|
139
|
+
const relPath = path.relative(assetGlob.input, src);
|
|
140
|
+
const dest = relPath.startsWith('..') ? src : relPath;
|
|
141
|
+
acc.push({
|
|
142
|
+
type: 'create',
|
|
143
|
+
src: path.join(this.rootDir, src),
|
|
144
|
+
dest: path.join(this.rootDir, assetGlob.output, dest),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return acc;
|
|
148
|
+
}, []);
|
|
149
|
+
}
|
|
150
|
+
normalizeAssetPattern(assetEntry) {
|
|
151
|
+
return typeof assetEntry === 'string' ? assetEntry : assetEntry.pattern;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.CopyAssetsHandler = CopyAssetsHandler;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AssetGlob } from './assets';
|
|
2
|
+
import { FileEvent } from './copy-assets-handler';
|
|
3
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
4
|
+
export interface CopyAssetsOptions {
|
|
5
|
+
outputPath: string;
|
|
6
|
+
assets: (string | AssetGlob)[];
|
|
7
|
+
watch?: boolean | WatchMode;
|
|
8
|
+
}
|
|
9
|
+
export interface CopyAssetsResult {
|
|
10
|
+
success?: boolean;
|
|
11
|
+
stop?: () => void;
|
|
12
|
+
}
|
|
13
|
+
export interface WatchMode {
|
|
14
|
+
onCopy?: (events: FileEvent[]) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare function copyAssets(options: CopyAssetsOptions, context: ExecutorContext): Promise<CopyAssetsResult>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.copyAssets = void 0;
|
|
4
|
+
const copy_assets_handler_1 = require("./copy-assets-handler");
|
|
5
|
+
async function copyAssets(options, context) {
|
|
6
|
+
const assetHandler = new copy_assets_handler_1.CopyAssetsHandler({
|
|
7
|
+
projectDir: context.projectsConfigurations.projects[context.projectName].root,
|
|
8
|
+
rootDir: context.root,
|
|
9
|
+
outputDir: options.outputPath,
|
|
10
|
+
assets: options.assets,
|
|
11
|
+
callback: typeof options?.watch === 'object' ? options.watch.onCopy : undefined,
|
|
12
|
+
});
|
|
13
|
+
const result = {
|
|
14
|
+
success: true,
|
|
15
|
+
};
|
|
16
|
+
if (options.watch) {
|
|
17
|
+
result.stop = await assetHandler.watchAndProcessOnAssetChange();
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
await assetHandler.processAllAssetsOnce();
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
result.success = false;
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
exports.copyAssets = copyAssets;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ProjectGraph, ProjectGraphExternalNode, ProjectGraphProjectNode, TaskGraph } from '@nx/devkit';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
|
+
export type DependentBuildableProjectNode = {
|
|
4
|
+
name: string;
|
|
5
|
+
outputs: string[];
|
|
6
|
+
node: ProjectGraphProjectNode | ProjectGraphExternalNode;
|
|
7
|
+
};
|
|
8
|
+
export declare function calculateProjectBuildableDependencies(taskGraph: TaskGraph | undefined, projGraph: ProjectGraph, root: string, projectName: string, targetName: string, configurationName: string, shallow?: boolean): {
|
|
9
|
+
target: ProjectGraphProjectNode;
|
|
10
|
+
dependencies: DependentBuildableProjectNode[];
|
|
11
|
+
nonBuildableDependencies: string[];
|
|
12
|
+
topLevelDependencies: DependentBuildableProjectNode[];
|
|
13
|
+
};
|
|
14
|
+
export declare function calculateProjectDependencies(projGraph: ProjectGraph, root: string, projectName: string, targetName: string, configurationName: string, shallow?: boolean): {
|
|
15
|
+
target: ProjectGraphProjectNode;
|
|
16
|
+
dependencies: DependentBuildableProjectNode[];
|
|
17
|
+
nonBuildableDependencies: string[];
|
|
18
|
+
topLevelDependencies: DependentBuildableProjectNode[];
|
|
19
|
+
};
|
|
20
|
+
export declare function calculateDependenciesFromTaskGraph(taskGraph: TaskGraph, projectGraph: ProjectGraph, root: string, projectName: string, targetName: string, configurationName: string, shallow?: boolean): {
|
|
21
|
+
target: ProjectGraphProjectNode;
|
|
22
|
+
dependencies: DependentBuildableProjectNode[];
|
|
23
|
+
nonBuildableDependencies: string[];
|
|
24
|
+
topLevelDependencies: DependentBuildableProjectNode[];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Util function to create tsconfig compilerOptions object with support for workspace libs paths.
|
|
28
|
+
*
|
|
29
|
+
*
|
|
30
|
+
*
|
|
31
|
+
* @param tsConfig String of config path or object parsed via ts.parseJsonConfigFileContent.
|
|
32
|
+
* @param dependencies Dependencies calculated by Nx.
|
|
33
|
+
*/
|
|
34
|
+
export declare function computeCompilerOptionsPaths(tsConfig: string | ts.ParsedCommandLine, dependencies: DependentBuildableProjectNode[]): ts.MapLike<string[]>;
|
|
35
|
+
export declare function createTmpTsConfig(tsconfigPath: string, workspaceRoot: string, projectRoot: string, dependencies: DependentBuildableProjectNode[]): string;
|
|
36
|
+
export declare function checkDependentProjectsHaveBeenBuilt(root: string, projectName: string, targetName: string, projectDependencies: DependentBuildableProjectNode[]): boolean;
|
|
37
|
+
export declare function findMissingBuildDependencies(root: string, projectName: string, targetName: string, projectDependencies: DependentBuildableProjectNode[]): DependentBuildableProjectNode[];
|
|
38
|
+
export declare function updatePaths(dependencies: DependentBuildableProjectNode[], paths: Record<string, string[]>): void;
|
|
39
|
+
/**
|
|
40
|
+
* Updates the peerDependencies section in the `dist/lib/xyz/package.json` with
|
|
41
|
+
* the proper dependency and version
|
|
42
|
+
*/
|
|
43
|
+
export declare function updateBuildableProjectPackageJsonDependencies(root: string, projectName: string, targetName: string, configurationName: string, node: ProjectGraphProjectNode, dependencies: DependentBuildableProjectNode[], typeOfDependency?: 'dependencies' | 'peerDependencies'): void;
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateBuildableProjectPackageJsonDependencies = exports.updatePaths = exports.findMissingBuildDependencies = exports.checkDependentProjectsHaveBeenBuilt = exports.createTmpTsConfig = exports.computeCompilerOptionsPaths = exports.calculateDependenciesFromTaskGraph = exports.calculateProjectDependencies = exports.calculateProjectBuildableDependencies = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const operators_1 = require("nx/src/project-graph/operators");
|
|
7
|
+
const fileutils_1 = require("nx/src/utils/fileutils");
|
|
8
|
+
const output_1 = require("nx/src/utils/output");
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const ts_config_1 = require("./typescript/ts-config");
|
|
11
|
+
function isBuildable(target, node) {
|
|
12
|
+
return (node.data.targets &&
|
|
13
|
+
node.data.targets[target] &&
|
|
14
|
+
node.data.targets[target].executor !== '');
|
|
15
|
+
}
|
|
16
|
+
function calculateProjectBuildableDependencies(taskGraph, projGraph, root, projectName, targetName, configurationName, shallow) {
|
|
17
|
+
if (process.env.NX_BUILDABLE_LIBRARIES_TASK_GRAPH === 'true' && taskGraph) {
|
|
18
|
+
return calculateDependenciesFromTaskGraph(taskGraph, projGraph, root, projectName, targetName, configurationName, shallow);
|
|
19
|
+
}
|
|
20
|
+
return calculateProjectDependencies(projGraph, root, projectName, targetName, configurationName, shallow);
|
|
21
|
+
}
|
|
22
|
+
exports.calculateProjectBuildableDependencies = calculateProjectBuildableDependencies;
|
|
23
|
+
function calculateProjectDependencies(projGraph, root, projectName, targetName, configurationName, shallow) {
|
|
24
|
+
const target = projGraph.nodes[projectName];
|
|
25
|
+
// gather the library dependencies
|
|
26
|
+
const nonBuildableDependencies = [];
|
|
27
|
+
const topLevelDependencies = [];
|
|
28
|
+
const collectedDeps = collectDependencies(projectName, projGraph, [], shallow);
|
|
29
|
+
const missing = collectedDeps.reduce((missing, { name: dep }) => {
|
|
30
|
+
const depNode = projGraph.nodes[dep] || projGraph.externalNodes[dep];
|
|
31
|
+
if (!depNode) {
|
|
32
|
+
missing = missing || [];
|
|
33
|
+
missing.push(dep);
|
|
34
|
+
}
|
|
35
|
+
return missing;
|
|
36
|
+
}, null);
|
|
37
|
+
if (missing) {
|
|
38
|
+
throw new Error(`Unable to find ${missing.join(', ')} in project graph.`);
|
|
39
|
+
}
|
|
40
|
+
const dependencies = collectedDeps
|
|
41
|
+
.map(({ name: dep, isTopLevel }) => {
|
|
42
|
+
let project = null;
|
|
43
|
+
const depNode = projGraph.nodes[dep] || projGraph.externalNodes[dep];
|
|
44
|
+
if (depNode.type === 'lib') {
|
|
45
|
+
if (isBuildable(targetName, depNode)) {
|
|
46
|
+
const libPackageJsonPath = (0, path_1.join)(root, depNode.data.root, 'package.json');
|
|
47
|
+
project = {
|
|
48
|
+
name: (0, fileutils_1.fileExists)(libPackageJsonPath)
|
|
49
|
+
? (0, devkit_1.readJsonFile)(libPackageJsonPath).name // i.e. @workspace/mylib
|
|
50
|
+
: dep,
|
|
51
|
+
outputs: (0, devkit_1.getOutputsForTargetAndConfiguration)({
|
|
52
|
+
project: projectName,
|
|
53
|
+
target: targetName,
|
|
54
|
+
configuration: configurationName,
|
|
55
|
+
}, {}, depNode),
|
|
56
|
+
node: depNode,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
nonBuildableDependencies.push(dep);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else if (depNode.type === 'npm') {
|
|
64
|
+
project = {
|
|
65
|
+
name: depNode.data.packageName,
|
|
66
|
+
outputs: [],
|
|
67
|
+
node: depNode,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (project && isTopLevel) {
|
|
71
|
+
topLevelDependencies.push(project);
|
|
72
|
+
}
|
|
73
|
+
return project;
|
|
74
|
+
})
|
|
75
|
+
.filter((x) => !!x);
|
|
76
|
+
dependencies.sort((a, b) => (a.name > b.name ? 1 : b.name > a.name ? -1 : 0));
|
|
77
|
+
return {
|
|
78
|
+
target,
|
|
79
|
+
dependencies,
|
|
80
|
+
nonBuildableDependencies,
|
|
81
|
+
topLevelDependencies,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
exports.calculateProjectDependencies = calculateProjectDependencies;
|
|
85
|
+
function collectDependencies(project, projGraph, acc, shallow, areTopLevelDeps = true) {
|
|
86
|
+
(projGraph.dependencies[project] || []).forEach((dependency) => {
|
|
87
|
+
const existingEntry = acc.find((dep) => dep.name === dependency.target);
|
|
88
|
+
if (!existingEntry) {
|
|
89
|
+
// Temporary skip this. Currently the set of external nodes is built from package.json, not lock file.
|
|
90
|
+
// As a result, some nodes might be missing. This should not cause any issues, we can just skip them.
|
|
91
|
+
if (dependency.target.startsWith('npm:') &&
|
|
92
|
+
!projGraph.externalNodes[dependency.target])
|
|
93
|
+
return;
|
|
94
|
+
acc.push({ name: dependency.target, isTopLevel: areTopLevelDeps });
|
|
95
|
+
const isInternalTarget = projGraph.nodes[dependency.target];
|
|
96
|
+
if (!shallow && isInternalTarget) {
|
|
97
|
+
collectDependencies(dependency.target, projGraph, acc, shallow, false);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if (areTopLevelDeps && !existingEntry.isTopLevel) {
|
|
101
|
+
existingEntry.isTopLevel = true;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return acc;
|
|
105
|
+
}
|
|
106
|
+
function readTsConfigWithRemappedPaths(tsConfig, generatedTsConfigPath, dependencies) {
|
|
107
|
+
const generatedTsConfig = { compilerOptions: {} };
|
|
108
|
+
generatedTsConfig.extends = (0, path_1.relative)((0, path_1.dirname)(generatedTsConfigPath), tsConfig);
|
|
109
|
+
generatedTsConfig.compilerOptions.paths = computeCompilerOptionsPaths(tsConfig, dependencies);
|
|
110
|
+
if (process.env.NX_VERBOSE_LOGGING_PATH_MAPPINGS === 'true') {
|
|
111
|
+
output_1.output.log({
|
|
112
|
+
title: 'TypeScript path mappings have been rewritten.',
|
|
113
|
+
});
|
|
114
|
+
console.log(JSON.stringify(generatedTsConfig.compilerOptions.paths, null, 2));
|
|
115
|
+
}
|
|
116
|
+
return generatedTsConfig;
|
|
117
|
+
}
|
|
118
|
+
function calculateDependenciesFromTaskGraph(taskGraph, projectGraph, root, projectName, targetName, configurationName, shallow) {
|
|
119
|
+
const target = projectGraph.nodes[projectName];
|
|
120
|
+
const nonBuildableDependencies = [];
|
|
121
|
+
const topLevelDependencies = [];
|
|
122
|
+
const dependentTasks = collectDependentTasks(projectName, `${projectName}:${targetName}${configurationName ? `:${configurationName}` : ''}`, taskGraph, projectGraph, shallow);
|
|
123
|
+
const npmDependencies = collectNpmDependencies(projectName, projectGraph, !shallow ? dependentTasks : undefined);
|
|
124
|
+
const dependencies = [];
|
|
125
|
+
for (const [taskName, { isTopLevel }] of dependentTasks) {
|
|
126
|
+
let project = null;
|
|
127
|
+
const depTask = taskGraph.tasks[taskName];
|
|
128
|
+
const depProjectNode = projectGraph.nodes?.[depTask.target.project];
|
|
129
|
+
if (depProjectNode?.type !== 'lib') {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
let outputs = (0, devkit_1.getOutputsForTargetAndConfiguration)(depTask.target, depTask.overrides, depProjectNode);
|
|
133
|
+
if (outputs.length === 0) {
|
|
134
|
+
nonBuildableDependencies.push(depTask.target.project);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const libPackageJsonPath = (0, path_1.join)(root, depProjectNode.data.root, 'package.json');
|
|
138
|
+
project = {
|
|
139
|
+
name: (0, fileutils_1.fileExists)(libPackageJsonPath)
|
|
140
|
+
? (0, devkit_1.readJsonFile)(libPackageJsonPath).name // i.e. @workspace/mylib
|
|
141
|
+
: depTask.target.project,
|
|
142
|
+
outputs,
|
|
143
|
+
node: depProjectNode,
|
|
144
|
+
};
|
|
145
|
+
if (isTopLevel) {
|
|
146
|
+
topLevelDependencies.push(project);
|
|
147
|
+
}
|
|
148
|
+
dependencies.push(project);
|
|
149
|
+
}
|
|
150
|
+
for (const { project, isTopLevel } of npmDependencies) {
|
|
151
|
+
if (isTopLevel) {
|
|
152
|
+
topLevelDependencies.push(project);
|
|
153
|
+
}
|
|
154
|
+
dependencies.push(project);
|
|
155
|
+
}
|
|
156
|
+
dependencies.sort((a, b) => (a.name > b.name ? 1 : b.name > a.name ? -1 : 0));
|
|
157
|
+
return {
|
|
158
|
+
target,
|
|
159
|
+
dependencies,
|
|
160
|
+
nonBuildableDependencies,
|
|
161
|
+
topLevelDependencies,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
exports.calculateDependenciesFromTaskGraph = calculateDependenciesFromTaskGraph;
|
|
165
|
+
function collectNpmDependencies(projectName, projectGraph, dependentTasks, collectedPackages = new Set(), isTopLevel = true) {
|
|
166
|
+
const dependencies = projectGraph.dependencies[projectName]
|
|
167
|
+
.map((dep) => {
|
|
168
|
+
const projectNode = projectGraph.nodes?.[dep.target] ??
|
|
169
|
+
projectGraph.externalNodes?.[dep.target];
|
|
170
|
+
if (projectNode?.type !== 'npm' ||
|
|
171
|
+
collectedPackages.has(projectNode.data.packageName)) {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
const project = {
|
|
175
|
+
name: projectNode.data.packageName,
|
|
176
|
+
outputs: [],
|
|
177
|
+
node: projectNode,
|
|
178
|
+
};
|
|
179
|
+
collectedPackages.add(project.name);
|
|
180
|
+
return { project, isTopLevel };
|
|
181
|
+
})
|
|
182
|
+
.filter((x) => !!x);
|
|
183
|
+
if (dependentTasks?.size) {
|
|
184
|
+
for (const [, { project: projectName }] of dependentTasks) {
|
|
185
|
+
dependencies.push(...collectNpmDependencies(projectName, projectGraph, undefined, collectedPackages, false));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return dependencies;
|
|
189
|
+
}
|
|
190
|
+
function collectDependentTasks(project, task, taskGraph, projectGraph, shallow, areTopLevelDeps = true, dependentTasks = new Map()) {
|
|
191
|
+
for (const depTask of taskGraph.dependencies[task] ?? []) {
|
|
192
|
+
if (dependentTasks.has(depTask)) {
|
|
193
|
+
if (!dependentTasks.get(depTask).isTopLevel && areTopLevelDeps) {
|
|
194
|
+
dependentTasks.get(depTask).isTopLevel = true;
|
|
195
|
+
}
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const { project: depTaskProject } = (0, devkit_1.parseTargetString)(depTask, projectGraph);
|
|
199
|
+
if (depTaskProject !== project) {
|
|
200
|
+
dependentTasks.set(depTask, {
|
|
201
|
+
project: depTaskProject,
|
|
202
|
+
isTopLevel: areTopLevelDeps,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
if (!shallow) {
|
|
206
|
+
collectDependentTasks(depTaskProject, depTask, taskGraph, projectGraph, shallow, depTaskProject === project && areTopLevelDeps, dependentTasks);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return dependentTasks;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Util function to create tsconfig compilerOptions object with support for workspace libs paths.
|
|
213
|
+
*
|
|
214
|
+
*
|
|
215
|
+
*
|
|
216
|
+
* @param tsConfig String of config path or object parsed via ts.parseJsonConfigFileContent.
|
|
217
|
+
* @param dependencies Dependencies calculated by Nx.
|
|
218
|
+
*/
|
|
219
|
+
function computeCompilerOptionsPaths(tsConfig, dependencies) {
|
|
220
|
+
const paths = (0, ts_config_1.readTsConfigPaths)(tsConfig) || {};
|
|
221
|
+
updatePaths(dependencies, paths);
|
|
222
|
+
return paths;
|
|
223
|
+
}
|
|
224
|
+
exports.computeCompilerOptionsPaths = computeCompilerOptionsPaths;
|
|
225
|
+
function createTmpTsConfig(tsconfigPath, workspaceRoot, projectRoot, dependencies) {
|
|
226
|
+
const tmpTsConfigPath = (0, path_1.join)(workspaceRoot, 'tmp', projectRoot, 'tsconfig.generated.json');
|
|
227
|
+
const parsedTSConfig = readTsConfigWithRemappedPaths(tsconfigPath, tmpTsConfigPath, dependencies);
|
|
228
|
+
process.on('exit', () => cleanupTmpTsConfigFile(tmpTsConfigPath));
|
|
229
|
+
(0, devkit_1.writeJsonFile)(tmpTsConfigPath, parsedTSConfig);
|
|
230
|
+
return (0, path_1.join)(tmpTsConfigPath);
|
|
231
|
+
}
|
|
232
|
+
exports.createTmpTsConfig = createTmpTsConfig;
|
|
233
|
+
function cleanupTmpTsConfigFile(tmpTsConfigPath) {
|
|
234
|
+
try {
|
|
235
|
+
if (tmpTsConfigPath) {
|
|
236
|
+
(0, fs_1.unlinkSync)(tmpTsConfigPath);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
catch (e) { }
|
|
240
|
+
}
|
|
241
|
+
function checkDependentProjectsHaveBeenBuilt(root, projectName, targetName, projectDependencies) {
|
|
242
|
+
const missing = findMissingBuildDependencies(root, projectName, targetName, projectDependencies);
|
|
243
|
+
if (missing.length > 0) {
|
|
244
|
+
console.error((0, devkit_1.stripIndents) `
|
|
245
|
+
It looks like all of ${projectName}'s dependencies have not been built yet:
|
|
246
|
+
${missing.map((x) => ` - ${x.node.name}`).join('\n')}
|
|
247
|
+
|
|
248
|
+
You might be missing a "targetDefaults" configuration in your root nx.json (https://nx.dev/reference/project-configuration#target-defaults),
|
|
249
|
+
or "dependsOn" configured in ${projectName}'s project.json (https://nx.dev/reference/project-configuration#dependson)
|
|
250
|
+
`);
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
exports.checkDependentProjectsHaveBeenBuilt = checkDependentProjectsHaveBeenBuilt;
|
|
258
|
+
function findMissingBuildDependencies(root, projectName, targetName, projectDependencies) {
|
|
259
|
+
const depLibsToBuildFirst = [];
|
|
260
|
+
// verify whether all dependent libraries have been built
|
|
261
|
+
projectDependencies.forEach((dep) => {
|
|
262
|
+
if (dep.node.type !== 'lib') {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const paths = dep.outputs.map((p) => (0, path_1.join)(root, p));
|
|
266
|
+
if (!paths.some(fileutils_1.directoryExists)) {
|
|
267
|
+
depLibsToBuildFirst.push(dep);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
return depLibsToBuildFirst;
|
|
271
|
+
}
|
|
272
|
+
exports.findMissingBuildDependencies = findMissingBuildDependencies;
|
|
273
|
+
function updatePaths(dependencies, paths) {
|
|
274
|
+
const pathsKeys = Object.keys(paths);
|
|
275
|
+
// For each registered dependency
|
|
276
|
+
dependencies.forEach((dep) => {
|
|
277
|
+
// If there are outputs
|
|
278
|
+
if (dep.outputs && dep.outputs.length > 0) {
|
|
279
|
+
// Directly map the dependency name to the output paths (dist/packages/..., etc.)
|
|
280
|
+
paths[dep.name] = dep.outputs;
|
|
281
|
+
// check for secondary entrypoints
|
|
282
|
+
// For each registered path
|
|
283
|
+
for (const path of pathsKeys) {
|
|
284
|
+
const nestedName = `${dep.name}/`;
|
|
285
|
+
// If the path points to the current dependency and is nested (/)
|
|
286
|
+
if (path.startsWith(nestedName)) {
|
|
287
|
+
const nestedPart = path.slice(nestedName.length);
|
|
288
|
+
// Bind secondary endpoints for ng-packagr projects
|
|
289
|
+
let mappedPaths = dep.outputs.map((output) => `${output}/${nestedPart}`);
|
|
290
|
+
// Get the dependency's package name
|
|
291
|
+
const { root } = (dep.node?.data || {});
|
|
292
|
+
if (root) {
|
|
293
|
+
// Update nested mappings to point to the dependency's output paths
|
|
294
|
+
mappedPaths = mappedPaths.concat(paths[path].flatMap((path) => dep.outputs.map((output) => path.replace(root, output))));
|
|
295
|
+
}
|
|
296
|
+
paths[path] = mappedPaths;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
exports.updatePaths = updatePaths;
|
|
303
|
+
/**
|
|
304
|
+
* Updates the peerDependencies section in the `dist/lib/xyz/package.json` with
|
|
305
|
+
* the proper dependency and version
|
|
306
|
+
*/
|
|
307
|
+
function updateBuildableProjectPackageJsonDependencies(root, projectName, targetName, configurationName, node, dependencies, typeOfDependency = 'dependencies') {
|
|
308
|
+
const outputs = (0, devkit_1.getOutputsForTargetAndConfiguration)({
|
|
309
|
+
project: projectName,
|
|
310
|
+
target: targetName,
|
|
311
|
+
configuration: configurationName,
|
|
312
|
+
}, {}, node);
|
|
313
|
+
const packageJsonPath = `${outputs[0]}/package.json`;
|
|
314
|
+
let packageJson;
|
|
315
|
+
let workspacePackageJson;
|
|
316
|
+
try {
|
|
317
|
+
packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
318
|
+
workspacePackageJson = (0, devkit_1.readJsonFile)(`${root}/package.json`);
|
|
319
|
+
}
|
|
320
|
+
catch (e) {
|
|
321
|
+
// cannot find or invalid package.json
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
packageJson.dependencies = packageJson.dependencies || {};
|
|
325
|
+
packageJson.peerDependencies = packageJson.peerDependencies || {};
|
|
326
|
+
let updatePackageJson = false;
|
|
327
|
+
dependencies.forEach((entry) => {
|
|
328
|
+
const packageName = (0, operators_1.isNpmProject)(entry.node)
|
|
329
|
+
? entry.node.data.packageName
|
|
330
|
+
: entry.name;
|
|
331
|
+
if (!hasDependency(packageJson, 'dependencies', packageName) &&
|
|
332
|
+
!hasDependency(packageJson, 'devDependencies', packageName) &&
|
|
333
|
+
!hasDependency(packageJson, 'peerDependencies', packageName)) {
|
|
334
|
+
try {
|
|
335
|
+
let depVersion;
|
|
336
|
+
if (entry.node.type === 'lib') {
|
|
337
|
+
const outputs = (0, devkit_1.getOutputsForTargetAndConfiguration)({
|
|
338
|
+
project: projectName,
|
|
339
|
+
target: targetName,
|
|
340
|
+
configuration: configurationName,
|
|
341
|
+
}, {}, entry.node);
|
|
342
|
+
const depPackageJsonPath = (0, path_1.join)(root, outputs[0], 'package.json');
|
|
343
|
+
depVersion = (0, devkit_1.readJsonFile)(depPackageJsonPath).version;
|
|
344
|
+
packageJson[typeOfDependency][packageName] = depVersion;
|
|
345
|
+
}
|
|
346
|
+
else if ((0, operators_1.isNpmProject)(entry.node)) {
|
|
347
|
+
// If an npm dep is part of the workspace devDependencies, do not include it the library
|
|
348
|
+
if (!!workspacePackageJson.devDependencies?.[entry.node.data.packageName]) {
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
depVersion = entry.node.data.version;
|
|
352
|
+
packageJson[typeOfDependency][entry.node.data.packageName] =
|
|
353
|
+
depVersion;
|
|
354
|
+
}
|
|
355
|
+
updatePackageJson = true;
|
|
356
|
+
}
|
|
357
|
+
catch (e) {
|
|
358
|
+
// skip if cannot find package.json
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
if (updatePackageJson) {
|
|
363
|
+
(0, devkit_1.writeJsonFile)(packageJsonPath, packageJson);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
exports.updateBuildableProjectPackageJsonDependencies = updateBuildableProjectPackageJsonDependencies;
|
|
367
|
+
// verify whether the package.json already specifies the dep
|
|
368
|
+
function hasDependency(outputJson, depConfigName, packageName) {
|
|
369
|
+
if (outputJson[depConfigName]) {
|
|
370
|
+
return outputJson[depConfigName][packageName];
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ExecutorContext, ProjectGraphProjectNode } from '@nx/devkit';
|
|
2
|
+
import { DependentBuildableProjectNode } from './buildable-libs-utils';
|
|
3
|
+
export declare function checkDependencies(context: ExecutorContext, tsConfigPath: string): {
|
|
4
|
+
tmpTsConfig: string | null;
|
|
5
|
+
projectRoot: string;
|
|
6
|
+
target: ProjectGraphProjectNode;
|
|
7
|
+
dependencies: DependentBuildableProjectNode[];
|
|
8
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkDependencies = void 0;
|
|
4
|
+
const buildable_libs_utils_1 = require("./buildable-libs-utils");
|
|
5
|
+
function checkDependencies(context, tsConfigPath) {
|
|
6
|
+
const { target, dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.projectName, context.targetName, context.configurationName);
|
|
7
|
+
const projectRoot = target.data.root;
|
|
8
|
+
if (dependencies.length > 0) {
|
|
9
|
+
return {
|
|
10
|
+
tmpTsConfig: (0, buildable_libs_utils_1.createTmpTsConfig)(tsConfigPath, context.root, projectRoot, dependencies),
|
|
11
|
+
projectRoot,
|
|
12
|
+
target,
|
|
13
|
+
dependencies,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
tmpTsConfig: null,
|
|
18
|
+
projectRoot,
|
|
19
|
+
target,
|
|
20
|
+
dependencies,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
exports.checkDependencies = checkDependencies;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function highlight(code: string): string;
|