@elementor/wp-lite-env 0.0.18 → 0.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ name: Release
3
3
  on:
4
4
  push:
5
5
  branches:
6
- - initial
6
+ - main
7
7
 
8
8
  concurrency:
9
9
  group: ${{ github.workflow }}-${{ github.ref }}
@@ -10,7 +10,7 @@ on:
10
10
  - edited
11
11
  - synchronize
12
12
  branches:
13
- - initial
13
+ - main
14
14
 
15
15
  concurrency:
16
16
  group: ${{ github.workflow }}-${{ github.ref }}
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # wp-lite-env
2
2
 
3
+ ## 0.0.20
4
+
5
+ ### Patch Changes
6
+
7
+ - 27e57a1: use a proper logger
8
+
9
+ ## 0.0.19
10
+
11
+ ### Patch Changes
12
+
13
+ - 6f6b9ac: put retries-- in finally block, or theres a condition where it runs forever
14
+ - 6f6b9ac: add test for template generation
15
+ - 6f6b9ac: add a bin test
16
+
3
17
  ## 0.0.18
4
18
 
5
19
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`templates compose file generation snapshot test 1`] = `
3
+ exports[`templates compose file generation compose generated with correct empty values 1`] = `
4
4
  "services:
5
5
  mysql:
6
6
  image: mariadb:lts
@@ -57,6 +57,71 @@ volumes:
57
57
  "
58
58
  `;
59
59
 
60
+ exports[`templates compose file generation compose generated with correct values 1`] = `
61
+ "services:
62
+ mysql:
63
+ image: mariadb:lts
64
+ ports:
65
+ - \${WP_ENV_MYSQL_PORT:-}:3306
66
+ environment:
67
+ MYSQL_ROOT_HOST: '%'
68
+ MYSQL_ROOT_PASSWORD: password
69
+ MYSQL_DATABASE: wordpress
70
+ volumes:
71
+ - mysql:/var/lib/mysql
72
+ wordpress:
73
+ depends_on:
74
+ - mysql
75
+ build:
76
+ context: .
77
+ dockerfile: WordPress.Dockerfile
78
+ no_cache: true
79
+ args: &ref_0
80
+ HOST_USERNAME: someuser
81
+ HOST_UID: '502'
82
+ HOST_GID: '20'
83
+ ports:
84
+ - \${WP_ENV_PORT:-1234}:80
85
+ environment:
86
+ APACHE_RUN_USER: '#502'
87
+ APACHE_RUN_GROUP: '#20'
88
+ WORDPRESS_DB_USER: root
89
+ WORDPRESS_DB_PASSWORD: password
90
+ WORDPRESS_DB_NAME: wordpress
91
+ volumes: &ref_1
92
+ - /some/base/path/some/container/path:/var/www/html/some/host/path
93
+ - >-
94
+ /some/base/path/some/other/container/path:/var/www/html/some/other/host/path
95
+ - /some/base/some/plugin/path:/var/www/html/wp-content/plugins/plugin1
96
+ - >-
97
+ /some/base/some/other/plugin/path:/var/www/html/wp-content/plugins/plugin2
98
+ - /some/base/some/theme/path:/var/www/html/wp-content/themes/theme1
99
+ - /some/base/some/other/theme/path:/var/www/html/wp-content/themes/theme2
100
+ - wpcontent:/var/www/html
101
+ - /some/wp-config/path:/var/www/html/wp-config
102
+ extra_hosts:
103
+ - host.docker.internal:host-gateway
104
+ cli:
105
+ depends_on:
106
+ - wordpress
107
+ build:
108
+ context: .
109
+ dockerfile: CLI.Dockerfile
110
+ args: *ref_0
111
+ volumes: *ref_1
112
+ user: '502:20'
113
+ environment:
114
+ WORDPRESS_DB_USER: root
115
+ WORDPRESS_DB_PASSWORD: password
116
+ WORDPRESS_DB_NAME: wordpress
117
+ extra_hosts:
118
+ - host.docker.internal:host-gateway
119
+ volumes:
120
+ mysql: {}
121
+ wpcontent: {}
122
+ "
123
+ `;
124
+
60
125
  exports[`templates configuration file generation config file is generated with the correct values 1`] = `
61
126
  "#!/bin/bash
62
127
  set -eox pipefail
package/__tests__/e2e.ts CHANGED
@@ -1,19 +1,26 @@
1
- import {afterEach, beforeAll, describe, expect, test} from "@jest/globals";
1
+ import {describe, expect, test} from "@jest/globals";
2
2
  import {generateFiles, getConfigFilePath, start, stop} from "../src/run";
3
+ import {execSync} from "node:child_process";
3
4
 
4
5
  const port = 1234;
5
6
 
6
7
  describe('end to end tests', () => {
7
- beforeAll(async () => {
8
- await generateFiles(port, getConfigFilePath(['', '', '', 'config=./__tests__/.wp-lite-env.json']));
9
- })
10
- afterEach(async () => {
11
- await stop(port);
12
- }, 30000);
13
8
  test('WordPress is up and running', async () => {
14
- await start( port );
9
+ await generateFiles(port, getConfigFilePath(['', '', '', 'config=./__tests__/.wp-lite-env.json']));
10
+ try {
11
+ await start(port);
12
+ const response = await fetch(`http://localhost:${port}`);
13
+ expect(response.ok).toBe(true);
14
+ expect(await response.text()).toContain('Welcome to WordPress');
15
+ } finally {
16
+ await stop(port);
17
+ }
18
+ }, 60000);
19
+ test('WordPress is up and running using binary (requires building the library!)', async () => {
20
+ execSync('npx wp-lite-env start --config=./__tests__/.wp-lite-env.json --port=1234');
15
21
  const response = await fetch(`http://localhost:${port}`);
16
22
  expect(response.ok).toBe(true);
17
23
  expect(await response.text()).toContain('Welcome to WordPress');
24
+ execSync('npx wp-lite-env stop --config=./__tests__/.wp-lite-env.json --port=1234');
18
25
  }, 60000);
19
26
  });
@@ -36,7 +36,7 @@ describe('templates', () => {
36
36
  });
37
37
 
38
38
  describe('compose file generation', () => {
39
- test('snapshot test', () => {
39
+ test('compose generated with correct empty values', () => {
40
40
  const config = {
41
41
  mappings: {},
42
42
  plugins: {},
@@ -45,6 +45,24 @@ describe('templates', () => {
45
45
  const composeYml = generateDockerComposeYmlTemplate( config, '/some/base/path', 1234, '/some/wp-config/path' );
46
46
  expect(composeYml).toMatchSnapshot();
47
47
  });
48
+ test('compose generated with correct values', () => {
49
+ const config = {
50
+ mappings: {
51
+ 'some/host/path': 'some/container/path',
52
+ 'some/other/host/path': 'some/other/container/path',
53
+ },
54
+ plugins: {
55
+ 'plugin1': '../some/plugin/path',
56
+ 'plugin2': '../some/other/plugin/path',
57
+ },
58
+ themes: {
59
+ 'theme1': '../some/theme/path',
60
+ 'theme2': '../some/other/theme/path',
61
+ },
62
+ }
63
+ const composeYml = generateDockerComposeYmlTemplate( config, '/some/base/path', 1234, '/some/wp-config/path' );
64
+ expect(composeYml).toMatchSnapshot();
65
+ });
48
66
  test('mappings are mounted correctly', () => {
49
67
  const config = {
50
68
  mappings: {
package/dist/bin.cjs CHANGED
@@ -186,6 +186,8 @@ set -eox pipefail
186
186
  // src/run.ts
187
187
  var import_crypto = require("crypto");
188
188
  var import_node_os = __toESM(require("os"), 1);
189
+ var import_pino = __toESM(require("pino"), 1);
190
+ var logger = (0, import_pino.default)();
189
191
  var waitForServer = async (url, timeoutMs) => {
190
192
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
191
193
  const pollEveryMs = 100;
@@ -198,14 +200,15 @@ var waitForServer = async (url, timeoutMs) => {
198
200
  }
199
201
  } catch (e) {
200
202
  if ("ECONNREFUSED" !== e.cause?.code) {
201
- console.warn(`Encountered an error while waiting for server to start: ${e.message}
203
+ logger.warn(`Encountered an error while waiting for server to start: ${e.message}
202
204
  Trying to reach server again.`);
203
205
  }
206
+ } finally {
207
+ retries--;
204
208
  }
205
209
  await sleep(pollEveryMs);
206
- retries--;
207
210
  }
208
- console.error(`Server did not start within ${timeoutMs}ms`);
211
+ logger.error(`Server did not start within ${timeoutMs}ms`);
209
212
  return false;
210
213
  };
211
214
  var getRunPath = (port2) => import_path2.default.resolve(import_node_os.default.tmpdir(), `${port2}`);
@@ -258,7 +261,7 @@ var generateFiles = async (port2, configFilePath2) => {
258
261
  hash.update(dockerComposeYmlTemplate + wordPressDockerfileTemplate + cliDockerfileTemplate + port2);
259
262
  const runPath = getRunPath(port2);
260
263
  await import_promises.default.mkdir(runPath, { recursive: true });
261
- console.log(`writing files to run path: ${runPath}`);
264
+ logger.debug(`writing files to run path: ${runPath}`);
262
265
  await import_promises.default.writeFile(import_path2.default.resolve(runPath, "docker-compose.yml"), dockerComposeYmlTemplate);
263
266
  await import_promises.default.writeFile(import_path2.default.resolve(runPath, "WordPress.Dockerfile"), wordPressDockerfileTemplate);
264
267
  await import_promises.default.writeFile(import_path2.default.resolve(runPath, "CLI.Dockerfile"), cliDockerfileTemplate);
package/dist/bin.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  commandMap,
4
4
  generateFiles
5
- } from "./chunk-FNPCY3S6.js";
5
+ } from "./chunk-POVI6WIB.js";
6
6
 
7
7
  // src/bin.ts
8
8
  import commandLineArgs from "command-line-args";
@@ -159,6 +159,8 @@ set -eox pipefail
159
159
  // src/run.ts
160
160
  import { createHash } from "crypto";
161
161
  import os from "node:os";
162
+ import { default as pino } from "pino";
163
+ var logger = pino();
162
164
  var waitForServer = async (url, timeoutMs) => {
163
165
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
164
166
  const pollEveryMs = 100;
@@ -171,14 +173,15 @@ var waitForServer = async (url, timeoutMs) => {
171
173
  }
172
174
  } catch (e) {
173
175
  if ("ECONNREFUSED" !== e.cause?.code) {
174
- console.warn(`Encountered an error while waiting for server to start: ${e.message}
176
+ logger.warn(`Encountered an error while waiting for server to start: ${e.message}
175
177
  Trying to reach server again.`);
176
178
  }
179
+ } finally {
180
+ retries--;
177
181
  }
178
182
  await sleep(pollEveryMs);
179
- retries--;
180
183
  }
181
- console.error(`Server did not start within ${timeoutMs}ms`);
184
+ logger.error(`Server did not start within ${timeoutMs}ms`);
182
185
  return false;
183
186
  };
184
187
  var getRunPath = (port) => path2.resolve(os.tmpdir(), `${port}`);
@@ -231,7 +234,7 @@ var generateFiles = async (port, configFilePath) => {
231
234
  hash.update(dockerComposeYmlTemplate + wordPressDockerfileTemplate + cliDockerfileTemplate + port);
232
235
  const runPath = getRunPath(port);
233
236
  await fs2.mkdir(runPath, { recursive: true });
234
- console.log(`writing files to run path: ${runPath}`);
237
+ logger.debug(`writing files to run path: ${runPath}`);
235
238
  await fs2.writeFile(path2.resolve(runPath, "docker-compose.yml"), dockerComposeYmlTemplate);
236
239
  await fs2.writeFile(path2.resolve(runPath, "WordPress.Dockerfile"), wordPressDockerfileTemplate);
237
240
  await fs2.writeFile(path2.resolve(runPath, "CLI.Dockerfile"), cliDockerfileTemplate);
@@ -250,4 +253,4 @@ export {
250
253
  commandMap,
251
254
  generateFiles
252
255
  };
253
- //# sourceMappingURL=chunk-FNPCY3S6.js.map
256
+ //# sourceMappingURL=chunk-POVI6WIB.js.map
package/dist/index.cjs CHANGED
@@ -45,6 +45,8 @@ var import_js_yaml = require("js-yaml");
45
45
 
46
46
  // src/run.ts
47
47
  var import_node_os = __toESM(require("os"), 1);
48
+ var import_pino = __toESM(require("pino"), 1);
49
+ var logger = (0, import_pino.default)();
48
50
  var waitForServer = async (url, timeoutMs) => {
49
51
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
50
52
  const pollEveryMs = 100;
@@ -57,14 +59,15 @@ var waitForServer = async (url, timeoutMs) => {
57
59
  }
58
60
  } catch (e) {
59
61
  if ("ECONNREFUSED" !== e.cause?.code) {
60
- console.warn(`Encountered an error while waiting for server to start: ${e.message}
62
+ logger.warn(`Encountered an error while waiting for server to start: ${e.message}
61
63
  Trying to reach server again.`);
62
64
  }
65
+ } finally {
66
+ retries--;
63
67
  }
64
68
  await sleep(pollEveryMs);
65
- retries--;
66
69
  }
67
- console.error(`Server did not start within ${timeoutMs}ms`);
70
+ logger.error(`Server did not start within ${timeoutMs}ms`);
68
71
  return false;
69
72
  };
70
73
  var getRunPath = (port) => import_path.default.resolve(import_node_os.default.tmpdir(), `${port}`);
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  cli,
3
3
  start,
4
4
  stop
5
- } from "./chunk-FNPCY3S6.js";
5
+ } from "./chunk-POVI6WIB.js";
6
6
  export {
7
7
  cli,
8
8
  start,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementor/wp-lite-env",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "private": false,
5
5
  "description": "A simple, lightweight, docker-based WordPress environment",
6
6
  "main": "dist/index.cjs",
@@ -33,7 +33,8 @@
33
33
  "dependencies": {
34
34
  "command-line-args": "^6.0.1",
35
35
  "docker-compose": "^1.1.0",
36
- "js-yaml": "^4.1.0"
36
+ "js-yaml": "^4.1.0",
37
+ "pino": "^9.5.0"
37
38
  },
38
39
  "devDependencies": {
39
40
  "@changesets/cli": "^2.27.9",
package/src/run.ts CHANGED
@@ -10,7 +10,9 @@ import {
10
10
  } from "./templates";
11
11
  import {createHash} from "crypto";
12
12
  import os from "node:os";
13
+ import { default as pino } from "pino";
13
14
 
15
+ const logger = pino();
14
16
  const waitForServer = async ( url: string, timeoutMs: number ) => {
15
17
  const sleep = ( ms: number ) => new Promise( ( r ) => setTimeout( r, ms ) );
16
18
 
@@ -25,13 +27,14 @@ const waitForServer = async ( url: string, timeoutMs: number ) => {
25
27
  }
26
28
  } catch ( e ) {
27
29
  if ( 'ECONNREFUSED' !== e.cause?.code ) {
28
- console.warn( `Encountered an error while waiting for server to start: ${ e.message }\nTrying to reach server again.` );
30
+ logger.warn( `Encountered an error while waiting for server to start: ${ e.message }\nTrying to reach server again.` );
29
31
  }
32
+ } finally {
33
+ retries--;
30
34
  }
31
35
  await sleep (pollEveryMs);
32
- retries--;
33
36
  }
34
- console.error( `Server did not start within ${ timeoutMs }ms` );
37
+ logger.error( `Server did not start within ${ timeoutMs }ms` );
35
38
  return false;
36
39
  };
37
40
 
@@ -96,7 +99,7 @@ export const generateFiles = async ( port: number, configFilePath: string ) => {
96
99
  const runPath = getRunPath( port );
97
100
  await fs.mkdir( runPath, { recursive: true } );
98
101
 
99
- console.log( `writing files to run path: ${ runPath }` );
102
+ logger.debug( `writing files to run path: ${ runPath }` );
100
103
  await fs.writeFile( path.resolve( runPath, 'docker-compose.yml' ), dockerComposeYmlTemplate );
101
104
  await fs.writeFile( path.resolve( runPath, 'WordPress.Dockerfile' ), wordPressDockerfileTemplate );
102
105
  await fs.writeFile( path.resolve( runPath, 'CLI.Dockerfile' ), cliDockerfileTemplate );