nx 19.8.0-beta.0 → 19.8.0-beta.1
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/nx-cloud.js +0 -0
- package/package.json +17 -17
- package/src/command-line/activate-powerpack/activate-powerpack.d.ts +2 -0
- package/src/command-line/activate-powerpack/activate-powerpack.js +32 -0
- package/src/command-line/activate-powerpack/command-object.d.ts +6 -0
- package/src/command-line/activate-powerpack/command-object.js +25 -0
- package/src/command-line/add/command-object.d.ts +1 -1
- package/src/command-line/format/format.js +24 -7
- package/src/command-line/list/list.js +2 -0
- package/src/command-line/nx-commands.d.ts +1 -1
- package/src/command-line/nx-commands.js +77 -57
- package/src/command-line/report/report.d.ts +3 -0
- package/src/command-line/report/report.js +27 -1
- package/src/core/graph/main.js +1 -1
- package/src/native/index.d.ts +2 -1
- package/src/native/nx.wasm32-wasi.wasm +0 -0
- package/src/tasks-runner/cache.d.ts +5 -1
- package/src/tasks-runner/cache.js +51 -5
- package/src/tasks-runner/run-command.js +2 -0
- package/src/utils/db-connection.d.ts +4 -1
- package/src/utils/db-connection.js +15 -4
- package/src/utils/plugins/output.d.ts +1 -0
- package/src/utils/plugins/output.js +7 -0
- package/src/utils/powerpack.d.ts +5 -0
- package/src/utils/powerpack.js +38 -0
package/src/native/index.d.ts
CHANGED
@@ -35,6 +35,7 @@ export declare class NxCache {
|
|
35
35
|
getTaskOutputsPath(hash: string): string
|
36
36
|
copyFilesFromCache(cachedResult: CachedResult, outputs: Array<string>): void
|
37
37
|
removeOldCacheRecords(): void
|
38
|
+
checkCacheFsInSync(): boolean
|
38
39
|
}
|
39
40
|
|
40
41
|
export declare class NxTaskHistory {
|
@@ -96,7 +97,7 @@ export interface CachedResult {
|
|
96
97
|
outputsPath: string
|
97
98
|
}
|
98
99
|
|
99
|
-
export declare export function connectToNxDb(cacheDir: string, nxVersion: string): ExternalObject<Connection>
|
100
|
+
export declare export function connectToNxDb(cacheDir: string, nxVersion: string, dbName?: string | undefined | null): ExternalObject<Connection>
|
100
101
|
|
101
102
|
export declare export function copy(src: string, dest: string): void
|
102
103
|
|
Binary file
|
@@ -16,10 +16,10 @@ export declare class DbCache {
|
|
16
16
|
private cache;
|
17
17
|
private remoteCache;
|
18
18
|
private remoteCachePromise;
|
19
|
-
setup(): Promise<void>;
|
20
19
|
constructor(options: {
|
21
20
|
nxCloudRemoteCache: RemoteCache;
|
22
21
|
});
|
22
|
+
init(): Promise<void>;
|
23
23
|
get(task: Task): Promise<CachedResult | null>;
|
24
24
|
private applyRemoteCacheResults;
|
25
25
|
put(task: Task, terminalOutput: string | null, outputs: string[], code: number): Promise<void>;
|
@@ -28,6 +28,10 @@ export declare class DbCache {
|
|
28
28
|
temporaryOutputPath(task: Task): string;
|
29
29
|
private getRemoteCache;
|
30
30
|
private _getRemoteCache;
|
31
|
+
private getPowerpackS3Cache;
|
32
|
+
private getPowerpackSharedCache;
|
33
|
+
private resolvePackage;
|
34
|
+
private assertCacheIsValid;
|
31
35
|
}
|
32
36
|
/**
|
33
37
|
* @deprecated Use the {@link DbCache} class instead. This will be removed in Nx 21.
|
@@ -16,6 +16,7 @@ const nx_cloud_utils_1 = require("../utils/nx-cloud-utils");
|
|
16
16
|
const nx_json_1 = require("../config/nx-json");
|
17
17
|
const update_manager_1 = require("../nx-cloud/update-manager");
|
18
18
|
const get_cloud_options_1 = require("../nx-cloud/utilities/get-cloud-options");
|
19
|
+
const is_ci_1 = require("../utils/is-ci");
|
19
20
|
function getCache(options) {
|
20
21
|
return process.env.NX_DISABLE_DB !== 'true' &&
|
21
22
|
process.env.NX_DB_CACHE === 'true'
|
@@ -28,13 +29,17 @@ function getCache(options) {
|
|
28
29
|
: new Cache(options);
|
29
30
|
}
|
30
31
|
class DbCache {
|
31
|
-
async setup() {
|
32
|
-
this.remoteCache = await this.getRemoteCache();
|
33
|
-
}
|
34
32
|
constructor(options) {
|
35
33
|
this.options = options;
|
36
34
|
this.cache = new native_1.NxCache(workspace_root_1.workspaceRoot, cache_directory_1.cacheDir, (0, db_connection_1.getDbConnection)());
|
37
35
|
}
|
36
|
+
async init() {
|
37
|
+
// This should be cheap because we've already loaded
|
38
|
+
this.remoteCache = await this.getRemoteCache();
|
39
|
+
if (!this.remoteCache) {
|
40
|
+
this.assertCacheIsValid();
|
41
|
+
}
|
42
|
+
}
|
38
43
|
async get(task) {
|
39
44
|
const res = this.cache.get(task.hash);
|
40
45
|
if (res) {
|
@@ -43,7 +48,6 @@ class DbCache {
|
|
43
48
|
remote: false,
|
44
49
|
};
|
45
50
|
}
|
46
|
-
await this.setup();
|
47
51
|
if (this.remoteCache) {
|
48
52
|
// didn't find it locally but we have a remote cache
|
49
53
|
// attempt remote cache
|
@@ -67,9 +71,9 @@ class DbCache {
|
|
67
71
|
return this.cache.applyRemoteCacheResults(hash, res);
|
68
72
|
}
|
69
73
|
async put(task, terminalOutput, outputs, code) {
|
74
|
+
await this.assertCacheIsValid();
|
70
75
|
return tryAndRetry(async () => {
|
71
76
|
this.cache.put(task.hash, terminalOutput, outputs, code);
|
72
|
-
await this.setup();
|
73
77
|
if (this.remoteCache) {
|
74
78
|
await this.remoteCache.store(task.hash, this.cache.cacheDirectory, terminalOutput, code);
|
75
79
|
}
|
@@ -105,9 +109,51 @@ class DbCache {
|
|
105
109
|
}
|
106
110
|
}
|
107
111
|
else {
|
112
|
+
return ((await this.getPowerpackS3Cache()) ??
|
113
|
+
(await this.getPowerpackSharedCache()) ??
|
114
|
+
null);
|
115
|
+
}
|
116
|
+
}
|
117
|
+
async getPowerpackS3Cache() {
|
118
|
+
try {
|
119
|
+
const { getRemoteCache } = await Promise.resolve(`${this.resolvePackage('@nx/powerpack-s3-cache')}`).then(s => require(s));
|
120
|
+
return getRemoteCache();
|
121
|
+
}
|
122
|
+
catch {
|
108
123
|
return null;
|
109
124
|
}
|
110
125
|
}
|
126
|
+
async getPowerpackSharedCache() {
|
127
|
+
try {
|
128
|
+
const { getRemoteCache } = await Promise.resolve(`${this.resolvePackage('@nx/powerpack-shared-cache')}`).then(s => require(s));
|
129
|
+
return getRemoteCache();
|
130
|
+
}
|
131
|
+
catch {
|
132
|
+
return null;
|
133
|
+
}
|
134
|
+
}
|
135
|
+
resolvePackage(pkg) {
|
136
|
+
return require.resolve(pkg, {
|
137
|
+
paths: [process.cwd(), workspace_root_1.workspaceRoot, __dirname],
|
138
|
+
});
|
139
|
+
}
|
140
|
+
assertCacheIsValid() {
|
141
|
+
// User has customized the cache directory - this could be because they
|
142
|
+
// are using a shared cache in the custom directory. The db cache is not
|
143
|
+
// stored in the cache directory, and is keyed by machine ID so they would
|
144
|
+
// hit issues. If we detect this, we can create a fallback db cache in the
|
145
|
+
// custom directory, and check if the entries are there when the main db
|
146
|
+
// cache misses.
|
147
|
+
if ((0, is_ci_1.isCI)() && !this.cache.checkCacheFsInSync()) {
|
148
|
+
const warning = [
|
149
|
+
`Nx found unrecognized artifacts in the cache directory and will not be able to use them.`,
|
150
|
+
`Nx can only restore artifacts it has metadata about.`,
|
151
|
+
`Read about this warning and how to address it here: https://nx.dev/troubleshooting/unknown-local-cache`,
|
152
|
+
``,
|
153
|
+
].join('\n');
|
154
|
+
console.warn(warning);
|
155
|
+
}
|
156
|
+
}
|
111
157
|
}
|
112
158
|
exports.DbCache = DbCache;
|
113
159
|
/**
|
@@ -36,6 +36,7 @@ const task_results_life_cycle_1 = require("./life-cycles/task-results-life-cycle
|
|
36
36
|
const task_graph_utils_1 = require("./task-graph-utils");
|
37
37
|
const utils_1 = require("./utils");
|
38
38
|
const chalk = require("chalk");
|
39
|
+
const powerpack_1 = require("../utils/powerpack");
|
39
40
|
async function getTerminalOutputLifeCycle(initiatingProject, projectNames, tasks, nxArgs, nxJson, overrides) {
|
40
41
|
const { runnerOptions } = getRunner(nxArgs, nxJson);
|
41
42
|
const isRunOne = initiatingProject != null;
|
@@ -124,6 +125,7 @@ async function runCommandForTasks(projectsToRun, currentProjectGraph, { nxJson }
|
|
124
125
|
initiatingProject,
|
125
126
|
});
|
126
127
|
await renderIsDone;
|
128
|
+
await (0, powerpack_1.printPowerpackLicense)();
|
127
129
|
return taskResults;
|
128
130
|
}
|
129
131
|
async function ensureWorkspaceIsInSyncAndGetGraphs(projectGraph, nxJson, projectNames, nxArgs, overrides, extraTargetDependencies, extraOptions) {
|
@@ -4,8 +4,19 @@ exports.getDbConnection = getDbConnection;
|
|
4
4
|
const native_1 = require("../native");
|
5
5
|
const cache_directory_1 = require("./cache-directory");
|
6
6
|
const package_json_1 = require("../../package.json");
|
7
|
-
|
8
|
-
function getDbConnection(
|
9
|
-
|
10
|
-
|
7
|
+
const dbConnectionMap = new Map();
|
8
|
+
function getDbConnection(opts = {}) {
|
9
|
+
opts.directory ??= cache_directory_1.workspaceDataDirectory;
|
10
|
+
const key = `${opts.directory}:${opts.dbName ?? 'default'}`;
|
11
|
+
const connection = getEntryOrSet(dbConnectionMap, key, () => (0, native_1.connectToNxDb)(opts.directory, package_json_1.version, opts.dbName));
|
12
|
+
return connection;
|
13
|
+
}
|
14
|
+
function getEntryOrSet(map, key, defaultValue) {
|
15
|
+
const existing = map.get(key);
|
16
|
+
if (existing) {
|
17
|
+
return existing;
|
18
|
+
}
|
19
|
+
const val = defaultValue();
|
20
|
+
map.set(key, val);
|
21
|
+
return val;
|
11
22
|
}
|
@@ -2,4 +2,5 @@ import { ProjectConfiguration } from '../../config/workspace-json-project-json';
|
|
2
2
|
import { PluginCapabilities } from './plugin-capabilities';
|
3
3
|
export declare function listPlugins(plugins: Map<string, PluginCapabilities>, title: string): void;
|
4
4
|
export declare function listAlsoAvailableCorePlugins(installedPlugins: Map<string, PluginCapabilities>): void;
|
5
|
+
export declare function listPowerpackPlugins(): void;
|
5
6
|
export declare function listPluginCapabilities(pluginName: string, projects: Record<string, ProjectConfiguration>): Promise<void>;
|
@@ -2,6 +2,7 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.listPlugins = listPlugins;
|
4
4
|
exports.listAlsoAvailableCorePlugins = listAlsoAvailableCorePlugins;
|
5
|
+
exports.listPowerpackPlugins = listPowerpackPlugins;
|
5
6
|
exports.listPluginCapabilities = listPluginCapabilities;
|
6
7
|
const chalk = require("chalk");
|
7
8
|
const output_1 = require("../output");
|
@@ -45,6 +46,12 @@ function listAlsoAvailableCorePlugins(installedPlugins) {
|
|
45
46
|
});
|
46
47
|
}
|
47
48
|
}
|
49
|
+
function listPowerpackPlugins() {
|
50
|
+
const powerpackLink = 'https://nx.dev/plugin-registry';
|
51
|
+
output_1.output.log({
|
52
|
+
title: `Available Powerpack Plugins: ${powerpackLink}`,
|
53
|
+
});
|
54
|
+
}
|
48
55
|
async function listPluginCapabilities(pluginName, projects) {
|
49
56
|
const plugin = await (0, plugin_capabilities_1.getPluginCapabilities)(workspace_root_1.workspaceRoot, pluginName, projects);
|
50
57
|
if (!plugin) {
|
@@ -0,0 +1,38 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.NxPowerpackNotInstalledError = void 0;
|
4
|
+
exports.printPowerpackLicense = printPowerpackLicense;
|
5
|
+
exports.getPowerpackLicenseInformation = getPowerpackLicenseInformation;
|
6
|
+
const logger_1 = require("./logger");
|
7
|
+
const package_manager_1 = require("./package-manager");
|
8
|
+
const workspace_root_1 = require("./workspace-root");
|
9
|
+
async function printPowerpackLicense() {
|
10
|
+
try {
|
11
|
+
const { organizationName, seatCount, workspaceCount } = await getPowerpackLicenseInformation();
|
12
|
+
logger_1.logger.log(`Nx Powerpack Licensed to ${organizationName} for ${seatCount} user${seatCount > 1 ? '' : 's'} in ${workspaceCount} workspace${workspaceCount > 1 ? '' : 's'}`);
|
13
|
+
}
|
14
|
+
catch { }
|
15
|
+
}
|
16
|
+
async function getPowerpackLicenseInformation() {
|
17
|
+
try {
|
18
|
+
const { getPowerpackLicenseInformation } = (await Promise.resolve().then(() => require(
|
19
|
+
// @ts-ignore
|
20
|
+
'@nx/powerpack-license'
|
21
|
+
// TODO(@FrozenPandaz): Provide the right type here.
|
22
|
+
)));
|
23
|
+
// )) as typeof import('@nx/powerpack-license');
|
24
|
+
return getPowerpackLicenseInformation(workspace_root_1.workspaceRoot);
|
25
|
+
}
|
26
|
+
catch (e) {
|
27
|
+
if ('code' in e && e.code === 'ERR_MODULE_NOT_FOUND') {
|
28
|
+
throw new NxPowerpackNotInstalledError(e);
|
29
|
+
}
|
30
|
+
throw e;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
class NxPowerpackNotInstalledError extends Error {
|
34
|
+
constructor(e) {
|
35
|
+
super(`The "@nx/powerpack-license" package is needed to use Nx Powerpack enabled features. Please install the @nx/powerpack-license with ${(0, package_manager_1.getPackageManagerCommand)().addDev} @nx/powerpack-license`, { cause: e });
|
36
|
+
}
|
37
|
+
}
|
38
|
+
exports.NxPowerpackNotInstalledError = NxPowerpackNotInstalledError;
|