nx 21.5.1 → 21.5.3

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.
Files changed (38) hide show
  1. package/package.json +11 -11
  2. package/schemas/nx-schema.json +14 -0
  3. package/src/command-line/migrate/command-object.js +1 -1
  4. package/src/command-line/migrate/migrate.d.ts +2 -2
  5. package/src/command-line/migrate/migrate.d.ts.map +1 -1
  6. package/src/command-line/migrate/migrate.js +15 -6
  7. package/src/command-line/release/config/config.d.ts.map +1 -1
  8. package/src/command-line/release/config/config.js +3 -0
  9. package/src/command-line/release/version/release-group-processor.d.ts +1 -2
  10. package/src/command-line/release/version/release-group-processor.d.ts.map +1 -1
  11. package/src/command-line/release/version/release-group-processor.js +5 -47
  12. package/src/config/nx-json.d.ts +9 -0
  13. package/src/config/nx-json.d.ts.map +1 -1
  14. package/src/core/graph/main.js +1 -1
  15. package/src/daemon/client/client.d.ts.map +1 -1
  16. package/src/daemon/client/client.js +6 -4
  17. package/src/daemon/server/shutdown-utils.d.ts.map +1 -1
  18. package/src/daemon/server/shutdown-utils.js +6 -2
  19. package/src/executors/run-script/run-script.impl.d.ts.map +1 -1
  20. package/src/executors/run-script/run-script.impl.js +33 -8
  21. package/src/native/nx.wasi-browser.js +42 -39
  22. package/src/native/nx.wasm32-wasi.wasm +0 -0
  23. package/src/project-graph/build-project-graph.d.ts.map +1 -1
  24. package/src/project-graph/build-project-graph.js +10 -2
  25. package/src/project-graph/nx-deps-cache.d.ts +4 -3
  26. package/src/project-graph/nx-deps-cache.d.ts.map +1 -1
  27. package/src/project-graph/nx-deps-cache.js +7 -2
  28. package/src/tasks-runner/fork.js +31 -5
  29. package/src/tasks-runner/task-orchestrator.d.ts.map +1 -1
  30. package/src/tasks-runner/task-orchestrator.js +8 -5
  31. package/src/utils/nx-console-prompt.d.ts.map +1 -1
  32. package/src/utils/nx-console-prompt.js +8 -0
  33. package/src/utils/package-manager.d.ts +1 -0
  34. package/src/utils/package-manager.d.ts.map +1 -1
  35. package/src/utils/package-manager.js +6 -1
  36. package/src/utils/provenance.d.ts +48 -0
  37. package/src/utils/provenance.d.ts.map +1 -0
  38. package/src/utils/provenance.js +85 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provenance.d.ts","sourceRoot":"","sources":["../../../../../packages/nx/src/utils/provenance.ts"],"names":[],"mappings":"AAaA,wBAAsB,0BAA0B,CAC9C,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,IAAI,CAAC,CA+Gf;AAED,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;CAOxE;AAED,wBAAgB,iBAAiB,IAAI,MAAM,EAAE,CAa5C;AAoBD,MAAM,MAAM,yBAAyB,GAAG;IACtC,KAAK,EAAE,iCAAiC,CAAC;IACzC,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,aAAa,EAAE,gCAAgC,CAAC;IAChD,SAAS,EAAE;QACT,eAAe,EAAE;YACf,SAAS,EAAE,MAAM,CAAC;YAClB,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YACxC,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YACzC,oBAAoB,CAAC,EAAE,kBAAkB,EAAE,CAAC;SAC7C,CAAC;QACF,UAAU,EAAE;YACV,OAAO,EAAE;gBACP,EAAE,EAAE,MAAM,CAAC;gBACX,mBAAmB,CAAC,EAAE,kBAAkB,EAAE,CAAC;gBAC3C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;aAClC,CAAC;YACF,QAAQ,CAAC,EAAE;gBACT,YAAY,CAAC,EAAE,MAAM,CAAC;gBACtB,SAAS,CAAC,EAAE,MAAM,CAAC;gBACnB,UAAU,CAAC,EAAE,MAAM,CAAC;aACrB,CAAC;YACF,UAAU,CAAC,EAAE,kBAAkB,EAAE,CAAC;SACnC,CAAC;KACH,CAAC;CACH,CAAC;AAEF,MAAM,WAAW,kBAAkB;IACjC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE;QACP,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;KACnC,CAAC;IACF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE;QACZ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH"}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProvenanceError = void 0;
4
+ exports.ensurePackageHasProvenance = ensurePackageHasProvenance;
5
+ exports.getNxPackageGroup = getNxPackageGroup;
6
+ const child_process_1 = require("child_process");
7
+ const path_1 = require("path");
8
+ const util_1 = require("util");
9
+ const fileutils_1 = require("./fileutils");
10
+ const os_1 = require("os");
11
+ /*
12
+ * Verifies that the given npm package has provenance attestations
13
+ * generated by the GitHub Actions workflow at .github/workflows/publish.yml
14
+ * in the nrwl/nx repository.
15
+ *
16
+ * Will throw if the package does not have valid provenance.
17
+ */
18
+ async function ensurePackageHasProvenance(packageName, packageVersion) {
19
+ // this is used for locally released versions without provenance
20
+ // do not set this for other reasons or you might be exposed to security risks
21
+ if (process.env.NX_SKIP_PROVENANCE_CHECK) {
22
+ return;
23
+ }
24
+ const execFileAsync = (0, util_1.promisify)(child_process_1.execFile);
25
+ try {
26
+ const result = await execFileAsync((0, os_1.platform)() === 'win32' ? 'npm.cmd' : 'npm', ['view', `${packageName}@${packageVersion}`, '--json', '--silent'], {
27
+ timeout: 20000,
28
+ });
29
+ const npmViewResult = JSON.parse(result.stdout.trim());
30
+ const attURL = npmViewResult.dist?.attestations?.url;
31
+ if (!attURL)
32
+ throw new ProvenanceError(packageName, packageVersion, 'No attestation URL found');
33
+ const response = await fetch(attURL);
34
+ if (!response.ok) {
35
+ throw new ProvenanceError(packageName, packageVersion, `HTTP ${response.status}: ${response.statusText}`);
36
+ }
37
+ const attestations = (await response.json());
38
+ const provenanceAttestation = attestations?.attestations?.find((a) => a.predicateType === 'https://slsa.dev/provenance/v1');
39
+ const dsseEnvelopePayload = JSON.parse(Buffer.from(provenanceAttestation.bundle.dsseEnvelope.payload, 'base64').toString());
40
+ const workflowParameters = dsseEnvelopePayload?.predicate?.buildDefinition?.externalParameters
41
+ ?.workflow;
42
+ // verify that provenance was actually generated from the right publishing workflow
43
+ if (!workflowParameters) {
44
+ throw new ProvenanceError(packageName, packageVersion, 'Missing workflow parameters in attestation');
45
+ }
46
+ if (workflowParameters.repository !== 'https://github.com/nrwl/nx') {
47
+ throw new ProvenanceError(packageName, packageVersion, 'Repository does not match nrwl/nx');
48
+ }
49
+ if (workflowParameters.path !== '.github/workflows/publish.yml') {
50
+ throw new ProvenanceError(packageName, packageVersion, 'Publishing workflow does not match .github/workflows/publish.yml');
51
+ }
52
+ if (workflowParameters.ref !== `refs/tags/${npmViewResult.version}`) {
53
+ throw new ProvenanceError(packageName, packageVersion, `Version ref does not match refs/tags/${npmViewResult.version}`);
54
+ }
55
+ // verify that provenance was generated from the exact same artifact as the one we are installing
56
+ const distSha = Buffer.from(npmViewResult.dist.integrity.replace('sha512-', ''), 'base64').toString('hex');
57
+ const attestationSha = dsseEnvelopePayload.subject[0].digest.sha512;
58
+ if (distSha !== attestationSha) {
59
+ throw new ProvenanceError(packageName, packageVersion, 'Integrity hash does not match attestation hash');
60
+ }
61
+ return;
62
+ }
63
+ catch (error) {
64
+ if (error instanceof ProvenanceError) {
65
+ throw error;
66
+ }
67
+ throw new ProvenanceError(packageName, packageVersion, error.message || error);
68
+ }
69
+ }
70
+ class ProvenanceError extends Error {
71
+ constructor(packageName, packageVersion, error) {
72
+ super(`An error occurred while checking the provenance of ${packageName}@${packageVersion}. This could indicate a security risk. Please double check https://www.npmjs.com/package/${packageName} to see if the package is published correctly or file an issue at https://github.com/nrwl/nx/issues. To disable this check at your own risk, you can set the NX_SKIP_PROVENANCE_CHECK environment variable to true. \n Error: ${error ?? ''}`);
73
+ }
74
+ }
75
+ exports.ProvenanceError = ProvenanceError;
76
+ function getNxPackageGroup() {
77
+ const packageJsonPath = (0, path_1.join)(__dirname, '../../package.json');
78
+ const packageJson = (0, fileutils_1.readJsonFile)(packageJsonPath);
79
+ if (!packageJson['nx-migrations']?.packageGroup) {
80
+ return ['nx'];
81
+ }
82
+ const packages = packageJson['nx-migrations'].packageGroup.filter((dep) => typeof dep === 'string' && dep.startsWith('@nx/'));
83
+ packages.push('nx');
84
+ return packages;
85
+ }