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(Bun): creation of bun library with Bun Test support #405

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
18 changes: 18 additions & 0 deletions e2e/bun-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": {}
}
]
}
12 changes: 12 additions & 0 deletions e2e/bun-e2e/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable */
export default {
displayName: 'bun-e2e',
preset: '../../jest.preset.js',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/e2e/bun-e2e',
globalSetup: '../../tools/scripts/start-local-registry.ts',
globalTeardown: '../../tools/scripts/stop-local-registry.ts',
};
21 changes: 21 additions & 0 deletions e2e/bun-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "bun-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"sourceRoot": "e2e/bun-e2e/src",
"implicitDependencies": ["bun"],
"targets": {
"e2e": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "e2e/bun-e2e/jest.config.ts",
"runInBand": true
},
"dependsOn": ["^build"]
},
"lint": {
"executor": "@nx/eslint:lint"
}
}
}
65 changes: 65 additions & 0 deletions e2e/bun-e2e/src/bun.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { execSync } from 'child_process';
import { mkdirSync, rmSync } from 'fs';
import { dirname, join } from 'path';

describe('bun', () => {
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 @nx/bun@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 @nx/bun', {
cwd: projectDirectory,
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 --nxCloud=skip --no-interactive`,
{
cwd: dirname(projectDirectory),
stdio: 'inherit',
env: process.env,
}
);
console.log(`Created test project in "${projectDirectory}"`);

return projectDirectory;
}
10 changes: 10 additions & 0 deletions e2e/bun-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.spec.json"
}
]
}
14 changes: 14 additions & 0 deletions e2e/bun-e2e/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
12 changes: 11 additions & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,18 @@
"@nx/eslint:lint": {
"inputs": ["default", "{workspaceRoot}/.eslintrc.json"],
"cache": true
},
"@nx/js:tsc": {
"cache": true,
"dependsOn": ["^build"],
"inputs": ["default", "^default"]
}
},
"nxCloudAccessToken": "MDRmYzUxMmYtNTQwZi00MjZkLTg0ZTYtMzc5Y2RhOTE4YTc2fHJlYWQtd3JpdGU=",
"defaultBase": "main"
"defaultBase": "main",
"release": {
"version": {
"preVersionCommand": "yarn nx run-many -t build"
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@rspack/plugin-minify": "^0.5.6",
"@rspack/plugin-react-refresh": "^0.5.6",
"@swc-node/register": "1.8.0",
"@types/bun": "^1.1.3",
"@types/fs-extra": "^11.0.1",
"@types/jest": "29.4.0",
"@types/node": "18.16.9",
Expand Down Expand Up @@ -73,4 +74,3 @@
"verdaccio": "^5.0.4"
}
}

32 changes: 32 additions & 0 deletions packages/bun/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": "error"
}
},
{
"files": ["./package.json", "./executors.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/nx-plugin-checks": "error"
}
}
]
}
53 changes: 53 additions & 0 deletions packages/bun/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<p style="text-align: center;"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx.png" width="600" alt="Nx - Smart, Fast and Extensible Build System"></p>

<hr>

# Nx: Smart, Fast and Extensible Build System

Nx is a next generation build system with first class monorepo support and powerful integrations.

This package is a Bun plugin for Nx.

## Getting Started

Use `--preset=@nx/bun` when creating new workspace.

e.g.

```bash
npx create-nx-workspace@latest bun-demo --preset=@nx/bun
```

Now, you can go into the `bun-demo` folder and start development.

```bash
cd bun-demo
npm start
```

You can also run lint, test, and e2e scripts for the project.

```bash
npm run lint
npm run test
npm run e2e
```

## Existing workspaces

You can add Bun to any existing Nx workspace.

First, install the plugin:

```bash
npm install --save-dev @nx/bun
```

Then, run the `bun-project` generator:

```bash
npx nx g @nx/bun:bun-project --skipValidation
```

**Note:** The `--skipValidation` option allows you to overwrite existing build targets.

9 changes: 9 additions & 0 deletions packages/bun/executors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"executors": {
"test": {
"implementation": "./src/executors/test/executor",
"schema": "./src/executors/test/schema.json",
"description": "Test with Bun test"
}
}
}
10 changes: 10 additions & 0 deletions packages/bun/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */
export default {
displayName: 'bun',
preset: '../../jest.preset.js',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/packages/bun',
};
13 changes: 13 additions & 0 deletions packages/bun/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@nx/bun",
"version": "0.0.1",
"dependencies": {
"@nx/js": "~19.1.0",
"@nx/devkit": "~19.1.0",
"tslib": "^2.3.0"
},
"type": "commonjs",
"main": "./src/index.js",
"typings": "./src/index.d.ts",
"executors": "./executors.json"
}
64 changes: 64 additions & 0 deletions packages/bun/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "bun",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/bun/src",
"projectType": "library",
"release": {
"version": {
"generatorOptions": {
"packageRoot": "dist/{projectRoot}",
"currentVersionResolver": "git-tag"
}
}
},
"tags": [],
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/bun",
"main": "packages/bun/src/index.ts",
"tsConfig": "packages/bun/tsconfig.lib.json",
"assets": [
"packages/bun/*.md",
{
"input": "./packages/bun/src",
"glob": "**/!(*.ts)",
"output": "./src"
},
{
"input": "./packages/bun/src",
"glob": "**/*.d.ts",
"output": "./src"
},
{
"input": "./packages/bun",
"glob": "generators.json",
"output": "."
},
{
"input": "./packages/bun",
"glob": "executors.json",
"output": "."
}
]
}
},
"nx-release-publish": {
"options": {
"packageRoot": "dist/{projectRoot}"
}
},
"lint": {
"executor": "@nx/eslint:lint"
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "packages/bun/jest.config.ts"
}
}
}
}
Empty file.
11 changes: 11 additions & 0 deletions packages/bun/src/executors/test/executor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import executor from './executor';
import { TestExecutorSchema } from './schema';

const options: TestExecutorSchema = {};

describe('Test Executor', () => {
it('can run', async () => {
const output = await executor(options);
expect(output.success).toBe(true);
});
});
Loading