Skip to content

Commit b69998c

Browse files
committed
feat: add support to nx v20
1 parent 952e16a commit b69998c

File tree

18 files changed

+506
-726
lines changed

18 files changed

+506
-726
lines changed

.github/workflows/backwards-compatibility-test.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ jobs:
1212
node-version: 22
1313
- nx-version: ''
1414
node-version: 20
15-
- nx-version: ''
15+
16+
- nx-version: 'previous'
17+
node-version: 22
18+
- nx-version: 'previous'
19+
node-version: 20
20+
- nx-version: 'previous'
1621
node-version: 18
1722

1823
- nx-version: '18.3.5'

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18
1+
20

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,14 @@ For testing: Run through without making any changes. Execute with `--dry-run`, a
227227

228228
## Compatibility overview with Nx
229229

230-
| Version | Nx Workspace Version |
231-
| ------- | ------------------------------------------------ |
232-
| v8.2.0 | `^19.0.0 \|\| ^18.0.0 \|\| ^17.0.0 \|\| ^16.0.0` |
233-
| v8.1.0 | `^18.0.0 \|\| ^17.0.0 \|\| ^16.0.0` |
234-
| v8.0.0 | `^17.0.0 \|\| ^16.0.0` |
235-
| v7.1.0 | `^17.0.0 \|\| ^16.0.0` |
236-
| v7.0.1 | `^16.0.0` |
230+
| Version | Nx Workspace Version |
231+
| ------- | ------------------------------------------------------------- |
232+
| v8.3.0 | `^20.0.0 \|\| ^19.0.0 \|\| ^18.0.0 \|\| ^17.0.0 \|\| ^16.0.0` |
233+
| v8.2.0 | `^19.0.0 \|\| ^18.0.0 \|\| ^17.0.0 \|\| ^16.0.0` |
234+
| v8.1.0 | `^18.0.0 \|\| ^17.0.0 \|\| ^16.0.0` |
235+
| v8.0.0 | `^17.0.0 \|\| ^16.0.0` |
236+
| v7.1.0 | `^17.0.0 \|\| ^16.0.0` |
237+
| v7.0.1 | `^16.0.0` |
237238

238239
## 📁 Configuration File <a name="configuration-file"></a>
239240

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
1-
import { checkFilesExist, runNxCommand } from '@nx/plugin/testing';
2-
import {
3-
generateLib,
4-
initNgxDeployNPMProject,
5-
installDependencies,
6-
installNgxDeployNPMProject,
7-
} from '../utils';
1+
import { checkFilesExist, runNxCommand, uniq } from '@nx/plugin/testing';
2+
import { setup } from '../utils';
83

94
describe('build', () => {
10-
const publishableLib = 'basic-lib';
11-
const nxPlugin = '@nx/node';
5+
const setUp = (libName: string) =>
6+
setup([{ name: libName, generator: '@nx/node' }]);
127

13-
initNgxDeployNPMProject();
14-
installDependencies(nxPlugin);
8+
it('should build the lib due to the `dependsOn` option created on the target', async () => {
9+
const [lib] = await setUp(uniq('basic-lib'));
1510

16-
generateLib(nxPlugin, publishableLib, `--dir="libs"`);
17-
18-
// Install the project
19-
installNgxDeployNPMProject(
20-
`--project="${publishableLib}" --distFolderPath="dist/libs/${publishableLib}"`
21-
);
22-
23-
it('should build the lib due to the `dependsOn` option created on the target', () => {
24-
runNxCommand(`deploy ${publishableLib} --dry-run`);
11+
runNxCommand(`deploy ${lib.name} --dry-run`);
2512

2613
expect(() =>
27-
checkFilesExist(`dist/libs/${publishableLib}/package.json`)
14+
checkFilesExist(`dist/libs/${lib.name}/package.json`)
2815
).not.toThrow();
2916
}, 120000);
3017
});
Lines changed: 50 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,27 @@
1-
import { ProjectConfiguration, TargetConfiguration } from '@nx/devkit';
2-
import { readJson } from '@nx/plugin/testing';
1+
import { TargetConfiguration } from '@nx/devkit';
2+
import { uniq } from '@nx/plugin/testing';
33

44
import { DeployExecutorOptions } from '../../../packages/ngx-deploy-npm/src/executors/deploy/schema';
55
import { npmAccess } from '../../../packages/ngx-deploy-npm/src/core';
6-
import {
7-
generateLib,
8-
initNgxDeployNPMProject,
9-
installDependencies,
10-
installNgxDeployNPMProject,
11-
} from '../utils';
6+
import { setup } from '../utils';
127

13-
// TODO, migrate to SIFERS
148
describe('install', () => {
15-
const publicLib = 'node-lib1';
16-
let projectWorkSpacePublicLib: ProjectConfiguration;
17-
18-
const publicLib2 = 'node-lib2';
19-
let projectWorkSpacePublicLib2: ProjectConfiguration;
20-
21-
const restrictedLib = 'node-resctricted';
22-
let projectWorkSpaceRestrictedLib: ProjectConfiguration;
23-
24-
const libNOTset = 'node-lib-not-set';
25-
let projectWorkSpaceLibNOTSet: ProjectConfiguration;
26-
27-
const expectedTarget = (
28-
projectName: string,
9+
const expectedTarget = ({
10+
projectName,
2911
isBuildable = true,
30-
access: npmAccess = npmAccess.public
31-
): TargetConfiguration<DeployExecutorOptions> => {
12+
access = npmAccess.public,
13+
customDistFolderPath,
14+
}: {
15+
projectName: string;
16+
isBuildable?: boolean;
17+
access?: npmAccess;
18+
customDistFolderPath?: string;
19+
}): TargetConfiguration<DeployExecutorOptions> => {
3220
const target: TargetConfiguration<DeployExecutorOptions> = {
3321
executor: 'ngx-deploy-npm:deploy',
3422
options: {
35-
distFolderPath: `dist/libs/${projectName}`,
36-
access: access,
23+
distFolderPath: customDistFolderPath || `dist/libs/${projectName}`,
24+
access,
3725
},
3826
};
3927

@@ -44,54 +32,44 @@ describe('install', () => {
4432
return target;
4533
};
4634

47-
initNgxDeployNPMProject();
48-
installDependencies('@nx/node');
49-
50-
// Init libs and projects
51-
generateLib('@nx/node', publicLib, `--dir="libs"`);
52-
generateLib('@nx/node', publicLib2, `--dir="libs"`);
53-
generateLib('@nx/node', restrictedLib, `--dir="libs"`);
54-
generateLib('@nx/node', libNOTset, `--dir="libs"`);
55-
56-
const buildMockDistPath = (projectName: string) => {
57-
return `dist/libs/${projectName}`;
58-
};
59-
60-
installNgxDeployNPMProject(
61-
`--project ${publicLib} --dist-folder-path="${buildMockDistPath(
62-
publicLib
63-
)}"`
64-
);
65-
installNgxDeployNPMProject(
66-
`--project ${publicLib2} --dist-folder-path="${buildMockDistPath(
67-
publicLib2
68-
)}"`
69-
);
70-
installNgxDeployNPMProject(
71-
`--project=${restrictedLib} --dist-folder-path="${buildMockDistPath(
72-
restrictedLib
73-
)}" --access ${npmAccess.restricted}`
74-
);
35+
it('should modify the workspace only for the indicated libs', async () => {
36+
const [publicLib, publicLib2, restrictedLib, libNOTSet, smallLib] =
37+
await setup([
38+
{ name: uniq('node-lib1'), generator: '@nx/node' },
39+
{ name: uniq('node-lib2'), generator: '@nx/node' },
40+
{
41+
name: uniq('node-resctricted'),
42+
access: npmAccess.restricted,
43+
generator: '@nx/node',
44+
},
45+
{
46+
name: uniq('node-lib-not-set'),
47+
skipInstall: true,
48+
generator: '@nx/node',
49+
},
50+
{ name: uniq('small-lib'), generator: 'minimal' },
51+
]);
7552

76-
beforeEach(() => {
77-
projectWorkSpacePublicLib = readJson(`libs/${publicLib}/project.json`);
78-
projectWorkSpacePublicLib2 = readJson(`libs/${publicLib2}/project.json`);
79-
projectWorkSpaceRestrictedLib = readJson(
80-
`libs/${restrictedLib}/project.json`
53+
expect(publicLib.workspace.targets?.deploy).toEqual(
54+
expectedTarget({ projectName: publicLib.name })
8155
);
82-
projectWorkSpaceLibNOTSet = readJson(`libs/${libNOTset}/project.json`);
83-
});
84-
85-
it('should modify the workspace for publishable libs', () => {
86-
expect(projectWorkSpacePublicLib.targets?.deploy).toEqual(
87-
expectedTarget(publicLib)
56+
expect(publicLib2.workspace.targets?.deploy).toEqual(
57+
expectedTarget({ projectName: publicLib2.name })
8858
);
89-
expect(projectWorkSpacePublicLib2.targets?.deploy).toEqual(
90-
expectedTarget(publicLib2)
59+
expect(restrictedLib.workspace.targets?.deploy).toEqual(
60+
expectedTarget({
61+
projectName: restrictedLib.name,
62+
access: npmAccess.restricted,
63+
})
9164
);
92-
expect(projectWorkSpaceRestrictedLib.targets?.deploy).toEqual(
93-
expectedTarget(restrictedLib, true, npmAccess.restricted)
65+
expect(libNOTSet.workspace.targets?.deploy).toEqual(undefined);
66+
67+
expect(smallLib.workspace.targets?.deploy).toEqual(
68+
expectedTarget({
69+
projectName: smallLib.name,
70+
customDistFolderPath: smallLib.workspace.sourceRoot,
71+
isBuildable: false,
72+
})
9473
);
95-
expect(projectWorkSpaceLibNOTSet.targets?.deploy).toEqual(undefined);
96-
});
74+
}, 120000);
9775
});
Lines changed: 6 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,14 @@
1-
import {
2-
ensureNxProject,
3-
runNxCommand,
4-
runPackageManagerInstall,
5-
uniq,
6-
} from '@nx/plugin/testing';
7-
import * as fs from 'fs';
1+
import { runNxCommand, uniq } from '@nx/plugin/testing';
2+
import { setup } from '../utils';
83

94
describe('Minimal Project', () => {
10-
const setup = async () => {
11-
ensureNxProject('ngx-deploy-npm', 'dist/packages/ngx-deploy-npm');
12-
runPackageManagerInstall();
13-
14-
const uniqLibName = uniq('minimal-lib');
15-
16-
const { libRoot } = await createMinimalLib(uniqLibName);
17-
18-
// Install the project
19-
runNxCommand(
20-
`generate ngx-deploy-npm:install --project="${uniqLibName}" --dist-folder-path="${libRoot}"`
21-
);
22-
23-
async function createMinimalLib(libName: string) {
24-
// Create Lib
25-
const libRoot = `libs/${libName}`;
26-
const libRootAbsolutePath = `./tmp/nx-e2e/proj/${libRoot}`;
27-
28-
// Create the lib folder
29-
await fs.promises.mkdir(libRootAbsolutePath, {
30-
recursive: true,
31-
});
32-
33-
const createProjectJsonPromise = fs.promises.writeFile(
34-
`${libRootAbsolutePath}/project.json`,
35-
generateProjectJSON(libName),
36-
'utf8'
37-
);
38-
const createPackageJsonPromise = fs.promises.writeFile(
39-
`${libRootAbsolutePath}/package.json`,
40-
generatePackageJSON(libName),
41-
'utf8'
42-
);
43-
const createUniqueFilePromise = fs.promises.writeFile(
44-
`${libRootAbsolutePath}/hello-world.js`,
45-
"console.log('Hello World!');",
46-
'utf8'
47-
);
48-
await Promise.all([
49-
createProjectJsonPromise,
50-
createPackageJsonPromise,
51-
createUniqueFilePromise,
52-
]);
53-
54-
return { libRoot };
55-
56-
function generateProjectJSON(projectName: string): string {
57-
const content = {
58-
name: projectName,
59-
$schema: '../../node_modules/nx/schemas/project-schema.json',
60-
projectType: 'library',
61-
};
62-
63-
return JSON.stringify(content, null, 2);
64-
}
65-
66-
function generatePackageJSON(projectName: string): string {
67-
const content = {
68-
name: `@mock-domain/${projectName}`,
69-
description: 'Minimal LIb',
70-
version: '1.0.0',
71-
};
72-
73-
return JSON.stringify(content, null, 2);
74-
}
75-
}
76-
77-
return {
78-
libRoot,
79-
uniqLibName,
80-
};
81-
};
82-
835
it('should publish the lib', async () => {
84-
const { uniqLibName } = await setup();
6+
const [uniqLibName] = await setup([
7+
{ name: uniq('minimal-lib'), generator: 'minimal' },
8+
]);
859

8610
expect(() => {
87-
runNxCommand(`deploy ${uniqLibName} --dry-run`);
11+
runNxCommand(`deploy ${uniqLibName.name} --dry-run`);
8812
}).not.toThrow();
8913
}, 120000);
9014
});
Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
1-
import { initNgxDeployNPMProject, basicSetTestForLibs } from '../utils';
1+
import { runNxCommand, uniq } from '@nx/plugin/testing';
2+
import { setup } from '../utils';
23

34
describe('Publish', () => {
4-
initNgxDeployNPMProject();
5+
it('should publish an Angular Lib', async () => {
6+
const [angularLib] = await setup([
7+
{
8+
name: uniq('angular-lib'),
9+
generator: '@nx/angular',
10+
extraOptions: '--style css',
11+
},
12+
]);
513

6-
describe('Basic deploy test for Angular Libs', () => {
7-
const libName = 'angular-lib';
8-
const nxPlugin = '@nx/angular';
14+
expect(() => {
15+
runNxCommand(`deploy ${angularLib.name} --dry-run`);
16+
}).not.toThrow();
17+
}, 120000);
918

10-
basicSetTestForLibs(libName, nxPlugin, {
11-
libGeneratorCommandOptions: '--style css --directory="libs"',
12-
});
13-
});
19+
it('should publish an Node Lib', async () => {
20+
const [angularLib] = await setup([
21+
{
22+
name: uniq('node-lib'),
23+
generator: '@nx/node',
24+
},
25+
]);
1426

15-
describe('Basic deploy test for Node Libs', () => {
16-
const libName = 'node-lib';
17-
const nxPlugin = '@nx/node';
18-
19-
basicSetTestForLibs(libName, nxPlugin);
20-
});
27+
expect(() => {
28+
runNxCommand(`deploy ${angularLib.name} --dry-run`);
29+
}).not.toThrow();
30+
}, 120000);
2131
});

0 commit comments

Comments
 (0)