Skip to content

Commit

Permalink
fix(rust): provide needed information to build the project graph
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli committed Nov 20, 2023
1 parent 7ad56a7 commit 35eba91
Show file tree
Hide file tree
Showing 25 changed files with 1,209 additions and 113 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ on:
- main
pull_request:
env:
node_version: 18
node_version: 20

jobs:
checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ./.github/workflows/setup
with:
node_version: ${{ env.node_version }}
- run: yarn nx affected --target=build --parallel --max-parallel=3
- run: yarn nx affected --target=test --parallel --max-parallel=3
- run: yarn nx affected --target=lint --parallel --max-parallel=3
- run: yarn nx affected --target=build,test,lint --parallel --max-parallel=3
- run: yarn nx affected --target=e2e --parallel
4 changes: 3 additions & 1 deletion .github/workflows/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ inputs:
node_version: # id of input
description: 'Version of node to use'
required: true
default: '18'
default: '20'

runs:
using: 'composite'
Expand All @@ -14,6 +14,8 @@ runs:
- uses: actions/setup-node@v1
with:
node-version: ${{ inputs.node_version}}
- name: Install
uses: dtolnay/rust-toolchain@stable
- uses: actions/cache@v2
id: workspace-cache
with:
Expand Down
47 changes: 47 additions & 0 deletions .verdaccio/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# path to a directory with all packages
storage: ../tmp/local-registry/storage

auth:
htpasswd:
file: ./htpasswd
algorithm: bcrypt

# a list of other known repositories we can talk to
uplinks:
npmjs:
url: https://registry.npmjs.org/
maxage: 60m
max_fails: 20
fail_timeout: 2m
yarn:
url: https://registry.yarnpkg.com
maxage: 60m
max_fails: 20
fail_timeout: 2

packages:
'@*/*':
# scoped packages
access: $all
publish: $all
unpublish: $all
proxy: npmjs

'**':
# give all users (including non-authenticated users) full access
# because it is a local registry
access: $all
publish: $all
unpublish: $all

# if package is not available locally, proxy requests to npm registry
proxy: npmjs

# log settings
logs:
type: stdout
format: pretty
level: warn

publish:
allow_offline: true # set offline to true to allow publish offline
1 change: 1 addition & 0 deletions .verdaccio/htpasswd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test:$2y$10$lVWrhBqHffH6dnroJWR.0ug.Zgehrsxdh0dRcrFSqdktWqf/sRk9S
18 changes: 18 additions & 0 deletions e2e/rust-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
15 changes: 0 additions & 15 deletions e2e/rust-e2e/jest.config.js

This file was deleted.

12 changes: 12 additions & 0 deletions e2e/rust-e2e/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable */
export default {
displayName: 'rust-e2e',
preset: '../../jest.preset.js',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/e2e/rust-e2e',
globalSetup: '../../tools/scripts/start-local-registry.ts',
globalTeardown: '../../tools/scripts/stop-local-registry.ts',
};
16 changes: 11 additions & 5 deletions e2e/rust-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@
"targets": {
"e2e": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "e2e/rust-e2e/jest.config.js",
"runInBand": true,
"passWithNoTests": false
"jestConfig": "e2e/rust-e2e/jest.config.ts",
"runInBand": true
},
"dependsOn": ["rust:build"]
"dependsOn": ["^build"]
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["e2e/rust-e2e/**/*.ts"]
}
}
},
"tags": [],
"implicitDependencies": ["rust"]
}
108 changes: 108 additions & 0 deletions e2e/rust-e2e/src/rust.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { ProjectGraph } from '@nx/devkit';
import { execSync } from 'child_process';
import { mkdirSync, readFileSync, rmSync } from 'fs';
import { dirname, join } from 'path';

describe('rust', () => {
let projectDirectory: string;

beforeAll(() => {
projectDirectory = createTestProject();

// The plugin has been built and published to a local registry in the jest globalSetup
// Install the plugin built with the latest source code into the test repo
execSync(`npm install @monodon/rust@e2e`, {
cwd: projectDirectory,
stdio: 'inherit',
env: process.env,
});
});

afterAll(() => {
// Cleanup the test project
rmSync(projectDirectory, {
recursive: true,
force: true,
});
});

it('should be installed', () => {
// npm ls will fail if the package is not installed properly
execSync('npm ls @monodon/rust', {
cwd: projectDirectory,
stdio: 'inherit',
});
});

it('should generate a cargo project and update the project graph', () => {
runNxCommand(`generate @monodon/rust:bin hello-world`, projectDirectory);
runNxCommand(`generate @monodon/rust:lib lib1`, projectDirectory);

execSync('cargo add itertools -p lib1', { cwd: projectDirectory });
execSync(`cargo add lib1 --path ./lib1 -p hello_world`, {
cwd: projectDirectory,
});
expect(() =>
runNxCommand(`build hello_world`, projectDirectory)
).not.toThrow();

const projectGraph: ProjectGraph = JSON.parse(
readFileSync(
join(projectDirectory, '.nx/cache/project-graph.json')
).toString()
);

expect(projectGraph.dependencies['hello_world']).toMatchInlineSnapshot(`
Array [
Object {
"source": "hello_world",
"target": "lib1",
"type": "static",
},
]
`);
expect(projectGraph.dependencies['lib1']).toMatchInlineSnapshot(`
Array [
Object {
"source": "lib1",
"target": "cargo:itertools",
"type": "static",
},
]
`);
});
});

function runNxCommand(command: string, projectDir: string) {
execSync(`npx nx ${command}`, { cwd: projectDir, stdio: 'inherit' });
}

/**
* Creates a test project with create-nx-workspace and installs the plugin
* @returns The directory where the test project was created
*/
function createTestProject() {
const projectName = 'test-project';
const projectDirectory = join(process.cwd(), 'tmp', projectName);

// Ensure projectDirectory is empty
rmSync(projectDirectory, {
recursive: true,
force: true,
});
mkdirSync(dirname(projectDirectory), {
recursive: true,
});

execSync(
`npx --yes create-nx-workspace@latest ${projectName} --preset apps --no-nxCloud --no-interactive`,
{
cwd: dirname(projectDirectory),
stdio: 'inherit',
env: process.env,
}
);
console.log(`Created test project in "${projectDirectory}"`);

return projectDirectory;
}
42 changes: 0 additions & 42 deletions e2e/rust-e2e/tests/rust.spec.ts

This file was deleted.

3 changes: 0 additions & 3 deletions e2e/rust-e2e/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.e2e.json"
},
{
"path": "./tsconfig.spec.json"
}
Expand Down
7 changes: 6 additions & 1 deletion e2e/rust-e2e/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["**/*.spec.ts", "**/*.d.ts"]
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getJestProjects } = require('@nx/jest');
import { getJestProjects } from '@nx/jest';

export default {
projects: getJestProjects(),
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@
"@ltd/j-toml": "1.38.0",
"@nx/devkit": "17.1.2",
"@nx/js": "17.1.2",
"@swc/helpers": "~0.5.2",
"chalk": "^4.1.2",
"tslib": "^2.0.0"
},
"devDependencies": {
"@commitlint/cli": "17.3.0",
"@commitlint/config-conventional": "17.3.0",
"@jscutlery/semver": "^2.29.0",
"@nx/eslint": "17.1.2",
"@nx/eslint-plugin": "17.1.2",
"@nx/jest": "17.1.2",
"@nx/node": "17.1.2",
"@nx/plugin": "17.1.2",
"@nx/workspace": "17.1.2",
"@swc-node/register": "1.6.8",
"@swc/cli": "~0.1.62",
"@swc/core": "1.3.96",
"@types/jest": "29.4.0",
"@types/node": "18.7.1",
Expand All @@ -36,14 +39,14 @@
"eslint-config-prettier": "9.0.0",
"husky": "^8.0.0",
"jest": "29.4.3",
"jest-environment-jsdom": "^29.4.1",
"jsonc-eslint-parser": "^2.1.0",
"nx": "17.1.2",
"prettier": "2.8.0",
"ts-jest": "29.1.0",
"ts-node": "10.9.1",
"tslib": "^2.0.0",
"tslib": "^2.3.0",
"typescript": "5.2.2",
"verdaccio": "^5.25.0",
"@nx/eslint": "17.1.2"
"verdaccio": "^5.25.0"
}
}
4 changes: 4 additions & 0 deletions packages/rust/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
"preset": "conventional",
"postTargets": ["rust:build"]
}
},
"publish": {
"command": "node tools/scripts/publish.mjs rust {args.ver} {args.tag}",
"dependsOn": ["build"]
}
},
"tags": []
Expand Down
Loading

0 comments on commit 35eba91

Please sign in to comment.