Skip to content

Commit

Permalink
Migrate to NX-based build (#151)
Browse files Browse the repository at this point in the history
## Description

Sets up the correct build pipeline for all parts of Playground and PHP.wasm. This enables a public release of the [Playground API](#149) npm package!

I've been [struggling](#146) with [this](#70) for [a while](#150) and couldn't understand what's so hard. NX made it apparent – look at this dependency graph!

<img width="1291" alt="CleanShot 2023-03-16 at 23 16 26@2x" src="https://user-images.githubusercontent.com/205419/225764795-7fa8e972-09f8-41ef-aac2-1c96bd100ea0.png">

No wonder it's been almost impossible to set everything up by hand!

## Usage

Start with `yarn install`

### Shortcuts

To start a copy of `wasm.wordpress.net` locally, run `yarn run dev`.
To build it, run `yarn run build`.

### Fully qualified commands

In reality, these `yarn run` commands are just triggering the underlying project's nx `dev` and `build` commands:

```bash
nx dev playground-website
nx build playground-website
```

Here's a few more interesting commands:

```bash
# Build and run PHP.wasm CLI
nx start php-wasm-cli

# Build latest WordPress releases
nx recompile-wordpress:all playground-remote

# Recompile PHP 5.6 - 8.2 releases to .wasm for web
nx recompile-php:all php-wasm-web

# Recompile PHP 5.6 - 8.2 releases to .wasm for node
nx recompile-php:all php-wasm-node

# Builds markdown files for readthedocs site
nx build docs-site

# Builds the Playground Client npm package
nx build playground-client
```

## NX is the tool Playground needed from the outset

It's ridiculous how many problems this solves:

* The build pipeline is explicitly defined and easy to modify
* Tasks only run once their dependencies are ready
* The dev mode works and is fast
* The build works and is fast
* We get CI checks to confirm the entire build process still works (which solves #150)
* Cross-package TypeScript just works
* There are linters and formatters (which solves #14)
* Documentation is correctly generated from the latest built artifacts
* There are nice generators for bootstraping new packages and moving the existing ones around
* There are checks to ensure the private `php-wasm-common` package is not imported by anything else than `php-wasm-web` and `php-wasm-node`

## Next steps

* Add Lerna to harness package publishing
* Additional developer documentation for the nx-based flow

Related to #148 and #147
  • Loading branch information
adamziel committed Mar 16, 2023
1 parent 5da9aa0 commit d676988
Show file tree
Hide file tree
Showing 1,069 changed files with 93,064 additions and 102,107 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false
14 changes: 10 additions & 4 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
node_modules/**/*
build/*
packages/*/build*/*
src/php-wasm/wasm/build-assets/*
node_modules
packages/php-wasm/node/public
packages/php-wasm/web/public
packages/php-wasm/compile/build-assets
packages/playground/compile-wordpress/build-assets
__pycache__
packages/playground/remote/src/wordpress
*.timestamp-1678999213403.mjs
.local
.vscode
46 changes: 0 additions & 46 deletions .eslintrc.js

This file was deleted.

51 changes: 51 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"root": true,
"ignorePatterns": ["**/*"],
"plugins": ["@nrwl/nx"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"@nrwl/nx/enforce-module-boundaries": [
"error",
{
"enforceBuildableLibDependency": true,
"allow": [],
"depConstraints": []
}
],
"no-inner-declarations": 0,
"no-use-before-define": "off",
"react/prop-types": 0,
"no-console": 0,
"no-empty": 0,
"no-async-promise-executor": 0,
"no-constant-condition": 0,
"no-nested-ternary": 0,
"jsx-a11y/click-events-have-key-events": 0,
"jsx-a11y/no-static-element-interactions": 0
}
},
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nrwl/nx/typescript"],
"rules": {
"@typescript-eslint/ban-ts-comment": 0,
"@typescript-eslint/ban-types": 0,
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/no-explicit-any": 0,
"no-constant-condition": 0
}
},
{
"files": ["*.js", "*.jsx"],
"extends": ["plugin:@nrwl/nx/javascript"],
"rules": {}
},
{
"files": "*.json",
"parser": "jsonc-eslint-parser",
"rules": {}
}
]
}
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: CI
on:
push:
branches:
- trunk
pull_request:

jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: nrwl/nx-set-shas@v3
with:
main-branch-name: 'trunk'
- run: npm install -g yarn nx
- run: yarn install --frozen-lockfile

- run: nx format:check
- run: nx affected --target=lint --parallel=3
# No test setup yet
# - run: nx affected --target=test --parallel=3 --configuration=ci
- run: nx affected --target=build --parallel=3
74 changes: 45 additions & 29 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,32 +1,48 @@
.DS_Store
.idea
.local
# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
dist
tmp
var
/out-tsc
.vitepress
.vite
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
.rollup.cache
__pycache__

# dependencies
node_modules
/live-code-example
/testwp
package-lock.json
packages/*/build
testwp
!build/wp-admin
!build/wp-content
!build/wp-includes
!build/php.wasm
!build/php.js
!build/wp.data
!build/wp.js
*.tsbuildinfo
*.d.ts
tsdoc-metadata.json
var
dist.zip

# IDEs and editors
/.idea
/.local
.vscode
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
yarn-error.log
testem.log
/typings
*.timestamp-1678999213403.mjs

# System Files
.DS_Store
Thumbs.db

# Playground artifacts
php.js.bak
11 changes: 11 additions & 0 deletions .nxignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules
dist
packages/php-wasm/node/public
packages/php-wasm/web/public
packages/php-wasm/compile/build-assets
packages/playground/compile-wordpress/build-assets
__pycache__
packages/playground/remote/src/wordpress
*.timestamp-1678999213403.mjs
.local
.vscode
16 changes: 13 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
node_modules/**/*
build/*
packages/*/build*/*
# Add files here to ignore them from prettier formatting
/dist
/coverage
/node_modules
/packages/php-wasm/node/public
/packages/php-wasm/web/public
/packages/php-wasm/compile/build-assets
/packages/playground/compile-wordpress/build-assets
/packages/playground/remote/src/wordpress
__pycache__
*.timestamp-1678999213403.mjs
.local
.vscode
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"useTabs": true,
"semi": true,
"singleQuote": true
}
8 changes: 0 additions & 8 deletions .prettierrc.json

This file was deleted.

7 changes: 3 additions & 4 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ version: 2
# python: "3.10"

mkdocs:
configuration: mkdocs.yml
configuration: mkdocs.yml

# Optionally declare the Python requirements required to build your docs
python:
install:
- requirements: docs/requirements.txt

install:
- requirements: docs/requirements.txt
28 changes: 0 additions & 28 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

This file was deleted.

873 changes: 0 additions & 873 deletions .yarn/releases/yarn-3.4.1.cjs

This file was deleted.

7 changes: 0 additions & 7 deletions .yarnrc.yml

This file was deleted.

4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# WordPress Playground

[Project Page](https://developer.wordpress.org/playground/) | [Live demo](https://wasm.wordpress.net/wordpress.html) | [Documentation and API Reference](https://wordpresswasm.readthedocs.io/en/latest/)
[Project Page](https://developer.wordpress.org/playground/) | [Live demo](https://wasm.wordpress.net/wordpress.html) | [Documentation and API Reference](https://wordpresswasm.readthedocs.io/en/latest/)

[WordPress Playground](https://github.com/WordPress/wordpress-playground) is an experimental in-browser WordPress that runs without a PHP server thanks to the magic of WebAssembly.

Expand Down Expand Up @@ -34,8 +34,6 @@ npm install -g yarn
git clone https://github.com/WordPress/wordpress-playground
cd wordpress-playground
yarn install
# An initial build is needed at the moment:
yarn run build
yarn run dev
```

Expand Down
6 changes: 0 additions & 6 deletions bin/build-api-docs.sh

This file was deleted.

Loading

0 comments on commit d676988

Please sign in to comment.