Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): map lock file data to external dependencies #12185

Merged
merged 23 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d50c628
feat(core): use lock file for graph external deps generation
meeroslav Sep 28, 2022
69a24a0
feat(core): add lock file to external nodes mapper
meeroslav Sep 29, 2022
d4f9ff4
cleanup(core): improve lockfile mapping performace
meeroslav Sep 29, 2022
1bf565b
fix(core): ensure lock file exists before running the parse and hash
meeroslav Sep 29, 2022
2d29daf
feat(core): include lock file external deps in graph
meeroslav Sep 29, 2022
cd93909
fix(core): skip mapping of missing peer dependencies
meeroslav Sep 30, 2022
c524c6d
fix(core): remove hasher ref to lock files
meeroslav Sep 30, 2022
50aad3b
fix(core): remove lock implicits from hasher test
meeroslav Sep 30, 2022
da3e4cc
fix(repo): make e2e tests more version resilient
meeroslav Sep 30, 2022
55ea384
cleanup(core): improve hashExternalDependency comment
meeroslav Sep 30, 2022
6a9d7c2
feat(core): change mapper to map also dependencies
meeroslav Sep 30, 2022
d9d0172
feat(core): add hashing of target
meeroslav Sep 30, 2022
fcaab3d
fix(core): remove external dependencies from print affected
meeroslav Oct 2, 2022
ac8181b
fix(js): keep swc helpers version in sync with package.json
meeroslav Oct 2, 2022
5e14e75
fix(js): keep swc helpers version in sync with package.json
meeroslav Oct 2, 2022
0fbff69
cleanup(js): revert the test checks
meeroslav Oct 3, 2022
b0b8234
docs(core): add comment to print affected change;
meeroslav Oct 3, 2022
aefe03b
fix(core): hash only @nrwl executors in depth
meeroslav Oct 3, 2022
638812a
feat(core): preserve the external nodes hash in project graph
meeroslav Oct 4, 2022
9ef577a
feat(core): mark root packages to separate them from nested ones
meeroslav Oct 4, 2022
6845d2a
fix(core): remove package.json from explicit touched projects
meeroslav Oct 4, 2022
7da42ee
cleanup(core): cleanup lock file functions
meeroslav Oct 5, 2022
2bd13ad
fix(core): move hashing to parsing time
meeroslav Oct 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions e2e/js/src/js.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { satisfies } from 'semver';
import {
checkFilesDoNotExist,
checkFilesExist,
Expand Down Expand Up @@ -150,10 +151,12 @@ describe('js e2e', () => {

const rootPackageJson = readJson(`package.json`);

expect(readJson(`dist/libs/${lib}/package.json`)).toHaveProperty(
'peerDependencies.tslib',
rootPackageJson.dependencies.tslib
);
expect(
satisfies(
readJson(`dist/libs/${lib}/package.json`).peerDependencies.tslib,
rootPackageJson.dependencies.tslib
)
).toBeTruthy();

updateJson(`libs/${lib}/tsconfig.json`, (json) => {
json.compilerOptions = { ...json.compilerOptions, importHelpers: false };
Expand Down Expand Up @@ -232,12 +235,12 @@ describe('js e2e', () => {

runCLI(`build ${lib}`);

const rootPackageJson = readJson(`package.json`);
const swcHelpersFromRoot =
readJson(`package.json`).dependencies['@swc/helpers'];
const swcHelpersFromDist = readJson(`dist/libs/${lib}/package.json`)
.peerDependencies['@swc/helpers'];

expect(readJson(`dist/libs/${lib}/package.json`)).toHaveProperty(
'peerDependencies.@swc/helpers',
rootPackageJson.dependencies['@swc/helpers']
);
expect(satisfies(swcHelpersFromDist, swcHelpersFromRoot)).toBeTruthy();

updateJson(`libs/${lib}/.lib.swcrc`, (json) => {
json.jsc.externalHelpers = false;
Expand Down
24 changes: 15 additions & 9 deletions e2e/node/src/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
packageInstall,
promisifiedTreeKill,
readFile,
removeFile,
runCLI,
runCLIAsync,
runCommandUntil,
Expand All @@ -21,6 +20,7 @@ import {
} from '@nrwl/e2e/utils';
import { exec, execSync } from 'child_process';
import * as http from 'http';
import { satisfies } from 'semver';

function getData(port): Promise<any> {
return new Promise((resolve) => {
Expand Down Expand Up @@ -276,19 +276,25 @@ describe('Build Node apps', () => {
);
expect(packageJson).toEqual(
expect.objectContaining({
dependencies: {
'@nestjs/common': '^9.0.0',
'@nestjs/core': '^9.0.0',
'@nestjs/platform-express': '^9.0.0',
'reflect-metadata': '^0.1.13',
rxjs: '^7.0.0',
tslib: '^2.3.0',
},
main: 'main.js',
name: expect.any(String),
version: '0.0.1',
})
);
expect(
satisfies(packageJson.dependencies['@nestjs/common'], '^9.0.0')
).toBeTruthy();
expect(
satisfies(packageJson.dependencies['@nestjs/core'], '^9.0.0')
).toBeTruthy();
expect(
satisfies(packageJson.dependencies['@nestjs/platform-express'], '^9.0.0')
).toBeTruthy();
expect(
satisfies(packageJson.dependencies['reflect-metadata'], '^0.1.13')
).toBeTruthy();
expect(satisfies(packageJson.dependencies['rxjs'], '^7.0.0')).toBeTruthy();
expect(satisfies(packageJson.dependencies['tslib'], '^2.3.0')).toBeTruthy();

const nodeapp = uniq('nodeapp');
runCLI(`generate @nrwl/node:app ${nodeapp}`);
Expand Down
2 changes: 1 addition & 1 deletion packages/js/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export const nxVersion = require('../../package.json').version;

export const esbuildVersion = '^0.15.7';
export const swcCliVersion = '~0.1.55';
export const swcHelpersVersion = '~0.3.3';
export const swcHelpersVersion = '~0.4.11';
export const typesNodeVersion = '18.7.1';
10 changes: 9 additions & 1 deletion packages/nx/src/command-line/print-affected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,15 @@ async function createTasks(

function serializeProjectGraph(projectGraph: ProjectGraph) {
const nodes = Object.values(projectGraph.nodes).map((n) => n.name);
return { nodes, dependencies: projectGraph.dependencies };
const dependencies = {};
// we don't need external dependencies' dependencies for print-affected
// having them included makes the output unreadable
Object.keys(projectGraph.dependencies).forEach((key) => {
if (!key.startsWith('npm:')) {
dependencies[key] = projectGraph.dependencies[key];
}
});
return { nodes, dependencies };
}

export function selectPrintAffected(wholeJson: any, wholeSelect: string) {
Expand Down
8 changes: 8 additions & 0 deletions packages/nx/src/config/project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,21 @@ export interface ProjectGraphProjectNode<T = any> {

/**
* A node describing an external dependency
* `name` has as form of:
* - `npm:packageName` for root dependencies or
* - `npm:packageName@version` for nested transitive dependencies
*
* This is vital for our node discovery to always point to root dependencies,
* while allowing tracking of the full tree of different nested versions
*
*/
export interface ProjectGraphExternalNode {
type: 'npm';
name: `npm:${string}`;
data: {
version: string;
packageName: string;
hash?: string;
};
}

Expand Down
39 changes: 20 additions & 19 deletions packages/nx/src/hasher/hasher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe('Hasher', () => {
root: 'libs/parent',
targets: {
build: {
executor: 'unknown',
inputs: [
'default',
'^default',
Expand All @@ -95,6 +96,7 @@ describe('Hasher', () => {
dependencies: {
parent: [],
},
externalNodes: {},
allWorkspaceFiles,
},
{} as any,
Expand All @@ -110,7 +112,6 @@ describe('Hasher', () => {
overrides: { prop: 'prop-value' },
});

expect(hash.value).toContain('yarn.lock.hash'); //implicits
expect(hash.value).toContain('file.hash'); //project files
expect(hash.value).toContain('prop-value'); //overrides
expect(hash.value).toContain('parent'); //project
Expand All @@ -122,10 +123,8 @@ describe('Hasher', () => {
expect(hash.details.command).toEqual('parent|build||{"prop":"prop-value"}');
expect(hash.details.nodes).toEqual({
'parent:{projectRoot}/**/*':
'/file|file.hash|{"root":"libs/parent","targets":{"build":{"inputs":["default","^default",{"runtime":"echo runtime123"},{"env":"TESTENV"},{"env":"NONEXISTENTENV"}]}}}|{"compilerOptions":{"paths":{"@nrwl/parent":["libs/parent/src/index.ts"],"@nrwl/child":["libs/child/src/index.ts"]}}}',
'{workspaceRoot}/yarn.lock': 'yarn.lock.hash',
'{workspaceRoot}/package-lock.json': 'package-lock.json.hash',
'{workspaceRoot}/pnpm-lock.yaml': 'pnpm-lock.yaml.hash',
'/file|file.hash|{"root":"libs/parent","targets":{"build":{"executor":"unknown","inputs":["default","^default",{"runtime":"echo runtime123"},{"env":"TESTENV"},{"env":"NONEXISTENTENV"}]}}}|{"compilerOptions":{"paths":{"@nrwl/parent":["libs/parent/src/index.ts"],"@nrwl/child":["libs/child/src/index.ts"]}}}',
parent: 'unknown',
'{workspaceRoot}/nx.json': 'nx.json.hash',
'{workspaceRoot}/.gitignore': '',
'{workspaceRoot}/.nxignore': '',
Expand All @@ -145,7 +144,7 @@ describe('Hasher', () => {
type: 'lib',
data: {
root: 'libs/parent',
targets: { build: {} },
targets: { build: { executor: 'unknown' } },
files: [
{ file: '/filea.ts', hash: 'a.hash' },
{ file: '/filea.spec.ts', hash: 'a.spec.hash' },
Expand Down Expand Up @@ -205,6 +204,7 @@ describe('Hasher', () => {
targets: {
build: {
inputs: ['prod', '^prod'],
executor: 'unknown',
},
},
files: [
Expand All @@ -221,7 +221,7 @@ describe('Hasher', () => {
namedInputs: {
prod: ['default'],
},
targets: { build: {} },
targets: { build: { executor: 'unknown' } },
files: [
{ file: 'libs/child/fileb.ts', hash: 'b.hash' },
{ file: 'libs/child/fileb.spec.ts', hash: 'b.spec.hash' },
Expand Down Expand Up @@ -273,10 +273,12 @@ describe('Hasher', () => {
targets: {
build: {
inputs: ['prod'],
executor: 'unknown',
},
test: {
inputs: ['default'],
dependsOn: ['build'],
executor: 'unknown',
},
},
files: [
Expand Down Expand Up @@ -339,6 +341,7 @@ describe('Hasher', () => {
targets: {
test: {
inputs: ['default', '^prod'],
executor: 'unknown',
},
},
files: [
Expand All @@ -362,6 +365,7 @@ describe('Hasher', () => {
targets: {
test: {
inputs: ['default'],
executor: 'unknown',
},
},
files: [
Expand Down Expand Up @@ -440,7 +444,7 @@ describe('Hasher', () => {
data: {
root: 'libs/parent',
targets: {
build: {},
build: { executor: '@nrwl/workspace:run-commands' },
},
files: [
{ file: 'libs/parent/filea.ts', hash: 'a.hash' },
Expand All @@ -453,7 +457,7 @@ describe('Hasher', () => {
type: 'lib',
data: {
root: 'libs/child',
targets: { build: {} },
targets: { build: { executor: '@nrwl/workspace:run-commands' } },
files: [
{ file: 'libs/child/fileb.ts', hash: 'b.hash' },
{ file: 'libs/child/fileb.spec.ts', hash: 'b.spec.hash' },
Expand Down Expand Up @@ -507,7 +511,7 @@ describe('Hasher', () => {
type: 'lib',
data: {
root: 'libs/parent',
targets: { build: {} },
targets: { build: { executor: '@nrwl/workspace:run-commands' } },
files: [{ file: '/file', hash: 'file.hash' }],
},
},
Expand All @@ -531,7 +535,6 @@ describe('Hasher', () => {
overrides: { prop: 'prop-value' },
});

expect(hash.value).toContain('yarn.lock.hash'); //implicits
expect(hash.value).toContain('file.hash'); //project files
expect(hash.value).toContain('prop-value'); //overrides
expect(hash.value).toContain('parent'); //project
Expand All @@ -557,7 +560,7 @@ describe('Hasher', () => {
type: 'lib',
data: {
root: 'libs/parent',
targets: { build: {} },
targets: { build: { executor: '@nrwl/workspace:run-commands' } },
files: [{ file: '/filea.ts', hash: 'a.hash' }],
},
},
Expand All @@ -566,7 +569,7 @@ describe('Hasher', () => {
type: 'lib',
data: {
root: 'libs/child',
targets: { build: {} },
targets: { build: { executor: '@nrwl/workspace:run-commands' } },
files: [{ file: '/fileb.ts', hash: 'b.hash' }],
},
},
Expand All @@ -588,7 +591,6 @@ describe('Hasher', () => {
overrides: { prop: 'prop-value' },
});

expect(tasksHash.value).toContain('yarn.lock.hash'); //implicits
expect(tasksHash.value).toContain('a.hash'); //project files
expect(tasksHash.value).toContain('b.hash'); //project files
expect(tasksHash.value).toContain('prop-value'); //overrides
Expand All @@ -612,7 +614,6 @@ describe('Hasher', () => {
overrides: { prop: 'prop-value' },
});

expect(hashb.value).toContain('yarn.lock.hash'); //implicits
expect(hashb.value).toContain('a.hash'); //project files
expect(hashb.value).toContain('b.hash'); //project files
expect(hashb.value).toContain('prop-value'); //overrides
Expand Down Expand Up @@ -640,7 +641,7 @@ describe('Hasher', () => {
type: 'lib',
data: {
root: 'libs/parent',
targets: { build: {} },
targets: { build: { executor: '@nrwl/workspace:run-commands' } },
files: [{ file: '/file', hash: 'some-hash' }],
},
},
Expand Down Expand Up @@ -682,7 +683,7 @@ describe('Hasher', () => {
type: 'lib',
data: {
root: 'libs/parents',
targets: { build: {} },
targets: { build: { executor: '@nrwl/workspace:run-commands' } },
files: [],
},
},
Expand Down Expand Up @@ -718,7 +719,7 @@ describe('Hasher', () => {
type: 'app',
data: {
root: 'apps/app',
targets: { build: {} },
targets: { build: { executor: '@nrwl/workspace:run-commands' } },
files: [{ file: '/filea.ts', hash: 'a.hash' }],
},
},
Expand Down Expand Up @@ -767,7 +768,7 @@ describe('Hasher', () => {
type: 'app',
data: {
root: 'apps/app',
targets: { build: {} },
targets: { build: { executor: '@nrwl/workspace:run-commands' } },
files: [{ file: '/filea.ts', hash: 'a.hash' }],
},
},
Expand Down
Loading