Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ jobs:
# Runs before the Docker suites for fast feedback. Needs the root
# dependencies, not the ones in test/.
- name: Install root dependencies
run: npm install
run: npm ci

- name: sqlite unit tests
# Serial: the test files share the plugin's hardcoded /tmp cache and
# etag paths, and node --test runs files in parallel processes.
run: node --test --test-concurrency=1 storage.test.js sqliteS3.concurrency.test.js sqliteVercelBlob.etag.test.js sqliteVercelBlob.auth.test.js sqliteVercelBlob.concurrency.test.js
run: node --test --test-concurrency=1 storage.test.js router-policy.test.js sqliteS3.concurrency.test.js sqliteVercelBlob.etag.test.js sqliteVercelBlob.auth.test.js sqliteVercelBlob.concurrency.test.js
working-directory: ./test

- run: ./run-db-test.sh
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/serverlesswp-stream-wrapper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Stream Wrapper Tests
on:
push:
paths:
- 'packages/serverlesswp-stream-wrapper/**'
- 'wp/wp-content/mu-plugins/serverlesswp-stream-wrapper**'
- '.github/workflows/serverlesswp-stream-wrapper.yml'
pull_request:
paths:
- 'packages/serverlesswp-stream-wrapper/**'
- 'wp/wp-content/mu-plugins/serverlesswp-stream-wrapper**'
- '.github/workflows/serverlesswp-stream-wrapper.yml'
jobs:
unit:
name: unit tests
runs-on: ubuntu-latest
if: github.repository_owner == 'mitchmac'
defaults:
run:
working-directory: ./packages/serverlesswp-stream-wrapper
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'

- name: Install dependencies
run: composer install --no-interaction --prefer-dist

- name: Run unit tests
run: vendor/bin/phpunit --testsuite unit

deployable-copy:
name: deployable copy is current
runs-on: ubuntu-latest
if: github.repository_owner == 'mitchmac'
defaults:
run:
working-directory: ./packages/serverlesswp-stream-wrapper
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Compare wp/wp-content/mu-plugins against the source
run: ./build-plugin.sh --check

e2e:
name: e2e tests
runs-on: ubuntu-latest
if: github.repository_owner == 'mitchmac'
needs: unit
defaults:
run:
working-directory: ./packages/serverlesswp-stream-wrapper
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install dependencies
run: docker run --rm -v "$PWD:/app" -w /app composer:2 install --no-interaction --prefer-dist

- name: Run E2E tests
run: ./run-tests.sh e2e
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
node_modules/
package-lock.json
.serverless
test/auth.json
test/screenshots/
test/test-results/
test/test-results/
# Bundled upstream theme build metadata is not used by this project.
wp/wp-content/themes/twentytwentyfive/package-lock.json
# Tarball packed by build-test.sh when SERVERLESSWP_LOCAL is set.
test/local-pkg/*.tgz
# Claude Code project memory and instructions.
memory/
CLAUDE.md
35 changes: 28 additions & 7 deletions api/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require('fs');
const serverlesswp = require('serverlesswp');

const { validate } = require('../util/install.js');
Expand All @@ -10,23 +11,35 @@ const pathToWP = '/tmp/wp';
const wpContentPath = pathToWP + '/wp-content';
const sqlitePluginPath = wpContentPath + '/plugins/sqlite-database-integration';

// Which database this deployment uses. See util/storage.js.
const database = storage.resolve();

// Load executable bootstrap only from the read-only bundle.
const streamWrapperPrepend = '/var/task/wp/wp-content/mu-plugins/serverlesswp-stream-wrapper/bootstrap/prepend.php';

const requestRouter = '/var/task/wp/router.php';

const streamWrapperActive = !!process.env['SERVERLESSWP_STREAM_PROVIDER']
&& fs.existsSync(streamWrapperPrepend);

if (streamWrapperActive && !process.env['SERVERLESSWP_STREAM_WP_CONTENT_DIR']) {
process.env['SERVERLESSWP_STREAM_WP_CONTENT_DIR'] = wpContentPath;
}

// Refuse to fall back to ephemeral writes.
if (streamWrapperActive && typeof serverlesswp.buildPhpArgs !== 'function') {
console.log('SERVERLESSWP_STREAM_PROVIDER is set but the installed serverlesswp package does not support autoPrependFile. Upgrade it, or wp-content writes will not reach object storage.');
}

const readOnlyActive = !!process.env['SERVERLESSWP_READ_ONLY_MODE']
&& !['false', '0', 'no'].includes(process.env['SERVERLESSWP_READ_ONLY_MODE'].toLowerCase());

let initDone = false;

// Move the /wp directory to /tmp/wp so that it is writeable.
setup();

// This is where all requests to WordPress are routed through.
// See vercel.json, netlify.toml, or serverless.yml for the redirection rules.
exports.handler = async function (event, context, callback) {
if (!initDone) {
// Register readOnly first so blocked mutations short-circuit before the
// sqlite plugin tries to hit storage.
// Block mutations before opening SQLite.
if (readOnlyActive) {
serverlesswp.registerPlugin(readOnly);
}
Expand All @@ -41,7 +54,15 @@ exports.handler = async function (event, context, callback) {
initDone = true;
}

const response = await serverlesswp({ docRoot: pathToWP, event: event });
const options = { docRoot: pathToWP, event: event };
if (fs.existsSync(requestRouter)) {
options.routerScript = requestRouter;
}
if (streamWrapperActive) {
options.autoPrependFile = streamWrapperPrepend;
}

const response = await serverlesswp(options);
const checkInstall = validate(response);
return checkInstall || response;
};
3 changes: 0 additions & 3 deletions api/vercel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Vercel entry point, referenced by vercel.json. No Vercel-specific setup left
// here - util/storage.js reads the VERCEL_* variables itself.

const core = require('./index.js');

module.exports = core.handler;
Expand Down
4 changes: 2 additions & 2 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
[headers.values]
Cache-Control = "max-age=864000, s-maxage=864000"
[build]
command = "rm -rf .git && npm install && mkdir -p wp-public && find wp -type f \\( -name '*.css' -o -name '*.js' -o -name '*.png' -o -name '*.jpg' -o -name '*.jpeg' -o -name '*.gif' -o -name '*.svg' -o -name '*.woff' -o -name '*.woff2' -o -name '*.ico' -o -name '*.otf' -o -name '*.webp' \\) -exec cp --parents {} wp-public/ \\;"
publish = "wp-public/wp"
command = "rm -rf .git && npm ci && mkdir -p wp-public && find wp -type f \\( -name '*.css' -o -name '*.js' -o -name '*.png' -o -name '*.jpg' -o -name '*.jpeg' -o -name '*.gif' -o -name '*.svg' -o -name '*.woff' -o -name '*.woff2' -o -name '*.ico' -o -name '*.otf' -o -name '*.webp' \\) -exec cp --parents {} wp-public/ \\;"
publish = "wp-public/wp"
Loading
Loading