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: add support to nx v20 #634

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion .github/workflows/backwards-compatibility-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ jobs:
node-version: 22
- nx-version: ''
node-version: 20
- nx-version: ''

- nx-version: 'previous'
node-version: 22
- nx-version: 'previous'
node-version: 20
- nx-version: 'previous'
node-version: 18

- nx-version: '18.3.5'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/basic-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node-version: [18, 20, 22]
node-version: [20, 22]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node-version: [18, 20, 22]
node-version: [20, 22]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18
20
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,14 @@ For testing: Run through without making any changes. Execute with `--dry-run`, a

## Compatibility overview with Nx

| Version | Nx Workspace Version |
| ------- | ------------------------------------------------ |
| v8.2.0 | `^19.0.0 \|\| ^18.0.0 \|\| ^17.0.0 \|\| ^16.0.0` |
| v8.1.0 | `^18.0.0 \|\| ^17.0.0 \|\| ^16.0.0` |
| v8.0.0 | `^17.0.0 \|\| ^16.0.0` |
| v7.1.0 | `^17.0.0 \|\| ^16.0.0` |
| v7.0.1 | `^16.0.0` |
| Version | Nx Workspace Version |
| ------- | ------------------------------------------------------------- |
| v8.3.0 | `^20.0.0 \|\| ^19.0.0 \|\| ^18.0.0 \|\| ^17.0.0 \|\| ^16.0.0` |
| v8.2.0 | `^19.0.0 \|\| ^18.0.0 \|\| ^17.0.0 \|\| ^16.0.0` |
| v8.1.0 | `^18.0.0 \|\| ^17.0.0 \|\| ^16.0.0` |
| v8.0.0 | `^17.0.0 \|\| ^16.0.0` |
| v7.1.0 | `^17.0.0 \|\| ^16.0.0` |
| v7.0.1 | `^16.0.0` |

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

Expand Down
29 changes: 8 additions & 21 deletions e2e/ngx-deploy-npm-e2e/tests/build.spec.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
import { checkFilesExist, runNxCommand } from '@nx/plugin/testing';
import {
generateLib,
initNgxDeployNPMProject,
installDependencies,
installNgxDeployNPMProject,
} from '../utils';
import { checkFilesExist, runNxCommand, uniq } from '@nx/plugin/testing';
import { setup } from '../utils';

describe('build', () => {
const publishableLib = 'basic-lib';
const nxPlugin = '@nx/node';
const buildSetUp = (libName: string) =>
setup([{ name: libName, generator: '@nx/node' }]);

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

generateLib(nxPlugin, publishableLib, `--dir="libs"`);

// Install the project
installNgxDeployNPMProject(
`--project="${publishableLib}" --distFolderPath="dist/libs/${publishableLib}"`
);

it('should build the lib due to the `dependsOn` option created on the target', () => {
runNxCommand(`deploy ${publishableLib} --dry-run`);
runNxCommand(`deploy ${lib.name} --dry-run`);

expect(() =>
checkFilesExist(`dist/libs/${publishableLib}/package.json`)
checkFilesExist(`dist/libs/${lib.name}/package.json`)
).not.toThrow();
}, 120000);
});
122 changes: 50 additions & 72 deletions e2e/ngx-deploy-npm-e2e/tests/install.spec.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,27 @@
import { ProjectConfiguration, TargetConfiguration } from '@nx/devkit';
import { readJson } from '@nx/plugin/testing';
import { TargetConfiguration } from '@nx/devkit';
import { uniq } from '@nx/plugin/testing';

import { DeployExecutorOptions } from '../../../packages/ngx-deploy-npm/src/executors/deploy/schema';
import { npmAccess } from '../../../packages/ngx-deploy-npm/src/core';
import {
generateLib,
initNgxDeployNPMProject,
installDependencies,
installNgxDeployNPMProject,
} from '../utils';
import { setup } from '../utils';

// TODO, migrate to SIFERS
describe('install', () => {
const publicLib = 'node-lib1';
let projectWorkSpacePublicLib: ProjectConfiguration;

const publicLib2 = 'node-lib2';
let projectWorkSpacePublicLib2: ProjectConfiguration;

const restrictedLib = 'node-resctricted';
let projectWorkSpaceRestrictedLib: ProjectConfiguration;

const libNOTset = 'node-lib-not-set';
let projectWorkSpaceLibNOTSet: ProjectConfiguration;

const expectedTarget = (
projectName: string,
const expectedTarget = ({
projectName,
isBuildable = true,
access: npmAccess = npmAccess.public
): TargetConfiguration<DeployExecutorOptions> => {
access = npmAccess.public,
customDistFolderPath,
}: {
projectName: string;
isBuildable?: boolean;
access?: npmAccess;
customDistFolderPath?: string;
}): TargetConfiguration<DeployExecutorOptions> => {
const target: TargetConfiguration<DeployExecutorOptions> = {
executor: 'ngx-deploy-npm:deploy',
options: {
distFolderPath: `dist/libs/${projectName}`,
access: access,
distFolderPath: customDistFolderPath || `dist/libs/${projectName}`,
access,
},
};

Expand All @@ -44,54 +32,44 @@ describe('install', () => {
return target;
};

initNgxDeployNPMProject();
installDependencies('@nx/node');

// Init libs and projects
generateLib('@nx/node', publicLib, `--dir="libs"`);
generateLib('@nx/node', publicLib2, `--dir="libs"`);
generateLib('@nx/node', restrictedLib, `--dir="libs"`);
generateLib('@nx/node', libNOTset, `--dir="libs"`);

const buildMockDistPath = (projectName: string) => {
return `dist/libs/${projectName}`;
};

installNgxDeployNPMProject(
`--project ${publicLib} --dist-folder-path="${buildMockDistPath(
publicLib
)}"`
);
installNgxDeployNPMProject(
`--project ${publicLib2} --dist-folder-path="${buildMockDistPath(
publicLib2
)}"`
);
installNgxDeployNPMProject(
`--project=${restrictedLib} --dist-folder-path="${buildMockDistPath(
restrictedLib
)}" --access ${npmAccess.restricted}`
);
it('should modify the workspace only for the indicated libs', async () => {
const [publicLib, publicLib2, restrictedLib, libNOTSet, smallLib] =
await setup([
{ name: uniq('node-lib1'), generator: '@nx/node' },
{ name: uniq('node-lib2'), generator: '@nx/node' },
{
name: uniq('node-resctricted'),
access: npmAccess.restricted,
generator: '@nx/node',
},
{
name: uniq('node-lib-not-set'),
skipInstall: true,
generator: '@nx/node',
},
{ name: uniq('small-lib'), generator: 'minimal' },
]);

beforeEach(() => {
projectWorkSpacePublicLib = readJson(`libs/${publicLib}/project.json`);
projectWorkSpacePublicLib2 = readJson(`libs/${publicLib2}/project.json`);
projectWorkSpaceRestrictedLib = readJson(
`libs/${restrictedLib}/project.json`
expect(publicLib.workspace.targets?.deploy).toEqual(
expectedTarget({ projectName: publicLib.name })
);
projectWorkSpaceLibNOTSet = readJson(`libs/${libNOTset}/project.json`);
});

it('should modify the workspace for publishable libs', () => {
expect(projectWorkSpacePublicLib.targets?.deploy).toEqual(
expectedTarget(publicLib)
expect(publicLib2.workspace.targets?.deploy).toEqual(
expectedTarget({ projectName: publicLib2.name })
);
expect(projectWorkSpacePublicLib2.targets?.deploy).toEqual(
expectedTarget(publicLib2)
expect(restrictedLib.workspace.targets?.deploy).toEqual(
expectedTarget({
projectName: restrictedLib.name,
access: npmAccess.restricted,
})
);
expect(projectWorkSpaceRestrictedLib.targets?.deploy).toEqual(
expectedTarget(restrictedLib, true, npmAccess.restricted)
expect(libNOTSet.workspace.targets?.deploy).toEqual(undefined);

expect(smallLib.workspace.targets?.deploy).toEqual(
expectedTarget({
projectName: smallLib.name,
customDistFolderPath: smallLib.workspace.sourceRoot,
isBuildable: false,
})
);
expect(projectWorkSpaceLibNOTSet.targets?.deploy).toEqual(undefined);
});
}, 120000);
});
88 changes: 6 additions & 82 deletions e2e/ngx-deploy-npm-e2e/tests/minimal.spec.ts
Original file line number Diff line number Diff line change
@@ -1,90 +1,14 @@
import {
ensureNxProject,
runNxCommand,
runPackageManagerInstall,
uniq,
} from '@nx/plugin/testing';
import * as fs from 'fs';
import { runNxCommand, uniq } from '@nx/plugin/testing';
import { setup } from '../utils';

describe('Minimal Project', () => {
const setup = async () => {
ensureNxProject('ngx-deploy-npm', 'dist/packages/ngx-deploy-npm');
runPackageManagerInstall();

const uniqLibName = uniq('minimal-lib');

const { libRoot } = await createMinimalLib(uniqLibName);

// Install the project
runNxCommand(
`generate ngx-deploy-npm:install --project="${uniqLibName}" --dist-folder-path="${libRoot}"`
);

async function createMinimalLib(libName: string) {
// Create Lib
const libRoot = `libs/${libName}`;
const libRootAbsolutePath = `./tmp/nx-e2e/proj/${libRoot}`;

// Create the lib folder
await fs.promises.mkdir(libRootAbsolutePath, {
recursive: true,
});

const createProjectJsonPromise = fs.promises.writeFile(
`${libRootAbsolutePath}/project.json`,
generateProjectJSON(libName),
'utf8'
);
const createPackageJsonPromise = fs.promises.writeFile(
`${libRootAbsolutePath}/package.json`,
generatePackageJSON(libName),
'utf8'
);
const createUniqueFilePromise = fs.promises.writeFile(
`${libRootAbsolutePath}/hello-world.js`,
"console.log('Hello World!');",
'utf8'
);
await Promise.all([
createProjectJsonPromise,
createPackageJsonPromise,
createUniqueFilePromise,
]);

return { libRoot };

function generateProjectJSON(projectName: string): string {
const content = {
name: projectName,
$schema: '../../node_modules/nx/schemas/project-schema.json',
projectType: 'library',
};

return JSON.stringify(content, null, 2);
}

function generatePackageJSON(projectName: string): string {
const content = {
name: `@mock-domain/${projectName}`,
description: 'Minimal LIb',
version: '1.0.0',
};

return JSON.stringify(content, null, 2);
}
}

return {
libRoot,
uniqLibName,
};
};

it('should publish the lib', async () => {
const { uniqLibName } = await setup();
const [uniqLibName] = await setup([
{ name: uniq('minimal-lib'), generator: 'minimal' },
]);

expect(() => {
runNxCommand(`deploy ${uniqLibName} --dry-run`);
runNxCommand(`deploy ${uniqLibName.name} --dry-run`);
}).not.toThrow();
}, 120000);
});
40 changes: 25 additions & 15 deletions e2e/ngx-deploy-npm-e2e/tests/publish.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
import { initNgxDeployNPMProject, basicSetTestForLibs } from '../utils';
import { runNxCommand, uniq } from '@nx/plugin/testing';
import { setup } from '../utils';

describe('Publish', () => {
initNgxDeployNPMProject();
it('should publish an Angular Lib', async () => {
const [angularLib] = await setup([
{
name: uniq('angular-lib'),
generator: '@nx/angular',
extraOptions: '--style css',
},
]);

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

basicSetTestForLibs(libName, nxPlugin, {
libGeneratorCommandOptions: '--style css --directory="libs"',
});
});
it('should publish an Node Lib', async () => {
const [angularLib] = await setup([
{
name: uniq('node-lib'),
generator: '@nx/node',
},
]);

describe('Basic deploy test for Node Libs', () => {
const libName = 'node-lib';
const nxPlugin = '@nx/node';

basicSetTestForLibs(libName, nxPlugin);
});
expect(() => {
runNxCommand(`deploy ${angularLib.name} --dry-run`);
}).not.toThrow();
}, 120000);
});
Loading
Loading