Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Bundle nx-mesh with esbuild #153

Merged
merged 20 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions .changeset/mean-hats-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nx-mesh': minor
---

Bundle `nx-mesh` with vite and reduce dependency list
4 changes: 2 additions & 2 deletions .github/workflows/__build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
--configuration=production

- name: Create build artifact tar
if: inputs.node_version == 'lts'
if: inputs.node_version == 'lts/*'
shell: bash
run: |
cd dist/packages
Expand All @@ -94,7 +94,7 @@ jobs:

- name: Upload build artifact
uses: actions/upload-artifact@v3
if: inputs.node_version == 'lts'
if: inputs.node_version == 'lts/*'
with:
name: nx-mesh
retention-days: 2
Expand Down
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@graphql-mesh/soap": "0.17.20",
"@graphql-typed-document-node/core": "3.1.2",
"@nrwl/devkit": "15.7.1",
"@nrwl/esbuild": "15.7.1",
"@nrwl/next": "15.7.1",
"@swc/helpers": "0.4.14",
"fs-extra": "10.1.0",
Expand All @@ -49,6 +50,7 @@
"react-is": "18.2.0",
"styled-components": "5.3.6",
"tslib": "2.5.0",
"vite-plugin-static-copy": "^0.13.1",
"watchpack": "2.4.0"
},
"devDependencies": {
Expand All @@ -66,6 +68,7 @@
"@nrwl/nx-cloud": "15.2.1",
"@nrwl/nx-plugin": "15.7.1",
"@nrwl/react": "15.7.1",
"@nrwl/vite": "15.7.1",
"@nrwl/workspace": "15.7.1",
"@swc-node/register": "1.6.2",
"@swc/cli": "0.1.62",
Expand All @@ -82,6 +85,7 @@
"@types/watchpack": "2.4.0",
"@typescript-eslint/eslint-plugin": "5.56.0",
"@typescript-eslint/parser": "5.56.0",
"@vitest/ui": "^0.25.8",
"babel-jest": "28.1.1",
"babel-plugin-styled-components": "1.10.7",
"cypress": "^12.2.0",
Expand All @@ -96,6 +100,7 @@
"husky": "8.0.3",
"jest": "28.1.1",
"jest-environment-jsdom": "28.1.1",
"jsdom": "~20.0.3",
"jsonc-eslint-parser": "2.2.0",
"lint-staged": "13.2.0",
"nx": "15.7.1",
Expand All @@ -105,6 +110,11 @@
"ts-jest": "28.0.5",
"ts-node": "10.9.1",
"type-fest": "3.6.1",
"typescript": "4.8.4"
"typescript": "4.8.4",
"vite": "^4.0.1",
"vite-plugin-dts": "~1.7.1",
"vite-plugin-eslint": "^1.8.1",
"vite-tsconfig-paths": "^4.0.2",
"vitest": "^0.25.8"
}
}
16 changes: 8 additions & 8 deletions packages/nx-mesh/executors.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,43 @@
"$schema": "http://json-schema.org/schema",
"executors": {
"dev": {
"implementation": "./src/executors/dev/executor",
"implementation": "./src/executors/dev/dev",
"schema": "./src/executors/dev/schema.json",
"description": "Serves a GraphQL server with GraphQL interface by building artifacts on the fly",
"hasher": "./src/executors/validate/hasher"
"hasher": "./src/executors/dev/hasher"
},
"build": {
"implementation": "./src/executors/build/build.impl",
"implementation": "./src/executors/build/build",
"schema": "./src/executors/build/schema.json",
"description": "Builds artifacts",
"hasher": "./src/executors/build/hasher"
},
"build-gateway": {
"implementation": "./src/executors/build-gateway/build-gateway.impl",
"implementation": "./src/executors/build-gateway/build-gateway",
"schema": "./src/executors/build-gateway/schema.json",
"description": "Builds artifacts to be used as an API Gateway",
"hasher": "./src/executors/build-gateway/hasher"
},
"build-swc": {
"implementation": "./src/executors/build-swc/build-swc.impl",
"implementation": "./src/executors/build-swc/build-swc",
"schema": "./src/executors/build-swc/schema.json",
"description": "Builds artifacts using SWC.",
"hasher": "./src/executors/build-swc/hasher"
},
"serve": {
"implementation": "./src/executors/serve/serve.impl",
"implementation": "./src/executors/serve/serve",
"schema": "./src/executors/serve/schema.json",
"description": "Serves a GraphQL server.",
"hasher": "./src/executors/serve/hasher"
},
"start": {
"implementation": "./src/executors/start/start.impl",
"implementation": "./src/executors/start/start",
"schema": "./src/executors/start/schema.json",
"description": "Serves a GraphQL server with GraphQL interface based on your generated artifacts",
"hasher": "./src/executors/start/hasher"
},
"validate": {
"implementation": "./src/executors/validate/validate.impl",
"implementation": "./src/executors/validate/validate",
"schema": "./src/executors/validate/schema.json",
"description": "Validates artifacts"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-mesh/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "4.0.0",
"description": "Rename .lib.swcrc to .swcrc for better SWC support throughout the workspace",
"cli": "nx",
"implementation": "./src/migrations/4.0.0/rename-swcrc-config/rename-swcrc-config"
"implementation": "./src/migrations/4.0.0/rename-swcrc-config"
}
}
}
15 changes: 7 additions & 8 deletions packages/nx-mesh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@
"@nrwl/workspace": "^15.7.1",
"@swc-node/register": "^1.6.2",
"@swc/core": "^1.3.42",
"@swc/helpers": "^0.4.14",
"fs-extra": "^10.1.0",
"get-port": "5.1.1",
"tslib": "^2.5.0",
"type-fest": "^2.18.0",
"watchpack": "^2.4.0"
"@swc/helpers": "^0.4.14"
},
"keywords": [
"Monorepo",
Expand All @@ -36,7 +31,10 @@
"CLI",
"GraphQL",
"GraphQL-Mesh",
"Mesh"
"Mesh",
"Nx",
"nx-plugin",
"plugin"
],
"bugs": {
"url": "git://github.com/domjtalbot/nx-mesh/issues"
Expand All @@ -55,5 +53,6 @@
},
"exports": {
"./package.json": "./package.json"
}
},
"type": "commonjs"
}
122 changes: 102 additions & 20 deletions packages/nx-mesh/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,126 @@
"projectType": "library",
"targets": {
"build": {
"executor": "@nrwl/js:swc",
"outputs": ["{options.outputPath}"],
"executor": "nx:run-commands",
"options": {
"outputPath": "dist/packages/nx-mesh",
"command": "rm -rf dist/packages/nx-mesh/node_modules dist/packages/nx-mesh/src/package.json"
},
"dependsOn": ["build-bundle"]
},
"build-bundle": {
"executor": "@nrwl/esbuild:esbuild",
"outputs": ["dist/packages/nx-mesh"],
"options": {
"outputPath": "dist/packages/nx-mesh/src",
"main": "packages/nx-mesh/src/index.ts",
"tsConfig": "packages/nx-mesh/tsconfig.lib.json",
"updateBuildableProjectDepsInPackageJson": false,
"deleteOutputPath": false,
"format": ["esm", "cjs"],
"minify": true,
"additionalEntryPoints": [
"packages/nx-mesh/src/executors/build-gateway/build-gateway.ts",
"packages/nx-mesh/src/executors/build-gateway/hasher.ts",
"packages/nx-mesh/src/executors/build-swc/build-swc.ts",
"packages/nx-mesh/src/executors/build-swc/hasher.ts",
"packages/nx-mesh/src/executors/build/build.ts",
"packages/nx-mesh/src/executors/build/hasher.ts",
"packages/nx-mesh/src/executors/dev/dev.ts",
"packages/nx-mesh/src/executors/dev/hasher.ts",
"packages/nx-mesh/src/executors/serve/serve.ts",
"packages/nx-mesh/src/executors/serve/hasher.ts",
"packages/nx-mesh/src/executors/start/start.ts",
"packages/nx-mesh/src/executors/start/hasher.ts",
"packages/nx-mesh/src/executors/validate/validate.ts",
"packages/nx-mesh/src/executors/validate/hasher.ts",
"packages/nx-mesh/src/migrations/4.0.0/rename-swcrc-config"
],
"external": [
"@graphql-mesh/cli",
"@nrwl/cypress",
"@nrwl/devkit",
"@nrwl/js",
"@nrwl/linter",
"@nrwl/node",
"@nrwl/workspace",
"@swc-node/register",
"@swc/core",
"@swc/helpers",
"graphql",
"nx",
"tslib"
],
"assets": [
"README.md",
"CHANGELOG.md",
"LICENSE",
"packages/nx-mesh/*.md",
{
"input": "./packages/nx-mesh/src",
"glob": "**/!(*.ts)",
"output": "./src"
"input": ".",
"glob": "(README.md|CHANGELOG.md|LICENSE)",
"output": "../"
},
{
"input": "./packages/nx-mesh/src",
"glob": "**/*.d.ts",
"output": "./src"
"input": "packages/nx-mesh",
"glob": "*.md",
"output": "../"
},
{
"input": "./packages/nx-mesh",
"glob": "generators.json",
"input": "./packages/nx-mesh/src",
"glob": "**/!(*.ts|*.snap)",
"output": "."
},
{
"input": "./packages/nx-mesh",
"glob": "executors.json",
"input": "./packages/nx-mesh/src",
"glob": "**/*.d.ts",
"output": "."
},
{
"input": "./packages/nx-mesh",
"glob": "migrations.json",
"output": "."
"glob": "(generators|executors|migrations|package).json",
"output": "../"
}
]
},
"dependsOn": ["build-non-bundle-cleanup"]
},
"build-non-bundle-cleanup": {
"executor": "nx:run-commands",
"options": {
"command": "rm -rf dist/packages/nx-mesh/node_modules dist/packages/nx-mesh/src/executors dist/packages/nx-mesh/src/migrations dist/packages/nx-mesh/src/index.js dist/packages/nx-mesh/src/index.cjs"
},
"dependsOn": ["build-non-bundle"]
},
"build-non-bundle": {
"executor": "@nrwl/esbuild:esbuild",
"outputs": [
"dist/packages/nx-mesh/generators",
"dist/packages/nx-mesh/utils"
],
"options": {
"outputPath": "dist/packages/nx-mesh",
"main": "packages/nx-mesh/src/generators/index.ts",
"tsConfig": "packages/nx-mesh/tsconfig.lib.json",
"bundle": false,
"format": ["esm", "cjs"],
"minify": true,
"deleteOutputPath": false,
"additionalEntryPoints": [
"packages/nx-mesh/src/generators/application/index.ts",
"packages/nx-mesh/src/generators/base/index.ts",
"packages/nx-mesh/src/generators/preset/index.ts",
"packages/nx-mesh/src/generators/sdk/index.ts"
],
"external": [
"@graphql-mesh/cli",
"@nrwl/cypress",
"@nrwl/devkit",
"@nrwl/js",
"@nrwl/linter",
"@nrwl/node",
"@nrwl/workspace",
"@swc-node/register",
"@swc/core",
"@swc/helpers",
"graphql",
"nx",
"tslib"
]
}
},
"lint": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ExecutorContext } from '@nrwl/devkit';
import { logger } from '@nrwl/devkit';
import { directoryExists } from '@nrwl/workspace/src/utilities/fileutils';
import { copySync, mkdir } from 'fs-extra';
import { join, resolve } from 'path';
import { join, resolve } from 'node:path';

import { createPackageJson } from '../../utils';
import { runMeshCli } from '../../utils/mesh-cli';
Expand Down
3 changes: 3 additions & 0 deletions packages/nx-mesh/src/executors/build-gateway/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './build-gateway';
export * from './hasher';
export * from './schema';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ExecutorContext } from '@nrwl/devkit';

import { logger } from '@nrwl/devkit';
import { join, resolve } from 'path';
import { join, resolve } from 'node:path';

import { createPackageJson, watcher } from '../../utils';
import { runCodegenCli } from '../../utils/graphql-codegen-cli';
Expand Down
3 changes: 3 additions & 0 deletions packages/nx-mesh/src/executors/build-swc/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './build-swc';
export * from './hasher';
export * from './schema';
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// @ts-nocheck

import { cacheDir, ExecutorContext, logger } from '@nrwl/devkit';
import { exec, execSync } from 'child_process';
import { exec, execSync } from 'node:child_process';
import { removeSync } from 'fs-extra';
import { createAsyncIterable } from '@nrwl/devkit/src/utils/async-iterable';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* eslint-disable */

// Modifed version of Nx SWC executor
// https://github.com/nrwl/nx/blob/master/packages/js/src/executors/swc/swc.impl.ts
// https://github.com/nrwl/nx/blob/master/packages/js/src/executors/swc/swc.ts
// @ts-nocheck
import { ExecutorContext } from '@nrwl/devkit';
import {
assetGlobsToFiles,
FileInputOutput,
} from '@nrwl/workspace/src/utilities/assets';
import { removeSync } from 'fs-extra';
import { dirname, join, relative, resolve } from 'path';
import { dirname, join, relative, resolve } from 'node:path';
import { copyAssets } from '@nrwl/js/src/utils/assets';
import { checkDependencies } from '@nrwl/js/src/utils/check-dependencies';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ExecutorContext } from '@nrwl/devkit';

import { logger } from '@nrwl/devkit';
import { tscExecutor } from '@nrwl/js/src/executors/tsc/tsc.impl';
import { resolve } from 'path';
import { resolve } from 'node:path';

import { createPackageJson, watcher } from '../../utils';
import { runCodegenCli } from '../../utils/graphql-codegen-cli';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ExecutorContext } from '@nrwl/devkit';

import { logger } from '@nrwl/devkit';
import { resolve } from 'path';
import { resolve } from 'node:path';

import { childProcess, runMeshCli } from '../../utils/mesh-cli';
import getServeLocation from './lib/get-serve-location';
Expand Down
3 changes: 3 additions & 0 deletions packages/nx-mesh/src/executors/dev/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './dev';
export * from './hasher';
export * from './schema';
3 changes: 3 additions & 0 deletions packages/nx-mesh/src/executors/serve/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './serve';
export * from './hasher';
export * from './schema';
Loading