laravel-workers 0.4.0 → 0.4.1

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.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 laravel-workers contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 laravel-workers contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,141 +1,141 @@
1
- #!/usr/bin/env node
2
- import { spawnSync } from 'node:child_process';
3
- import { existsSync, readFileSync } from 'node:fs';
4
- import { dirname, join } from 'node:path';
5
- import { fileURLToPath, pathToFileURL } from 'node:url';
6
-
7
- const pkgDir = dirname(dirname(fileURLToPath(import.meta.url)));
8
- const appDir = process.cwd();
9
- const cmd = process.argv[2] ?? 'test';
10
-
11
- const run = (command, args, options = {}) => {
12
- const { cwd = pkgDir, ...rest } = options;
13
- const res = spawnSync(command, args, { cwd, stdio: 'inherit', ...rest });
14
- if (res.error) {
15
- console.error(res.error.message);
16
- process.exit(1);
17
- }
18
- if (res.status !== 0) process.exit(res.status ?? 1);
19
- };
20
-
21
- if (cmd === 'test') {
22
- run(process.execPath, ['--test', 'kernel/tests/router.test.mjs', 'kernel/tests/db.test.mjs', 'kernel/tests/sqlite-integration.test.mjs', 'kernel/tests/hash.test.mjs', 'kernel/tests/encrypter.test.mjs', 'kernel/tests/validator.test.mjs', 'kernel/tests/services.test.mjs', 'kernel/tests/routes-json.test.mjs', 'kernel/tests/registry-json.test.mjs', 'kernel/tests/ports.test.mjs', 'kernel/tests/budget.test.mjs', 'compiler/tests/controller.test.mjs'], { cwd: pkgDir });
23
- } else if (cmd === 'test:db') {
24
- run(process.execPath, ['--test', 'kernel/tests/db.test.mjs'], { cwd: pkgDir });
25
- } else if (cmd === 'test:sqlite') {
26
- run(process.execPath, ['--test', 'kernel/tests/sqlite-integration.test.mjs'], { cwd: pkgDir });
27
- } else if (cmd === 'test:hash') {
28
- run(process.execPath, ['--test', 'kernel/tests/hash.test.mjs', 'kernel/tests/encrypter.test.mjs'], { cwd: pkgDir });
29
- } else if (cmd === 'test:validator') {
30
- run(process.execPath, ['--test', 'kernel/tests/validator.test.mjs'], { cwd: pkgDir });
31
- } else if (cmd === 'test:services') {
32
- run(process.execPath, ['--test', 'kernel/tests/services.test.mjs'], { cwd: pkgDir });
33
- } else if (cmd === 'test:budget') {
34
- run(process.execPath, ['--test', 'kernel/tests/budget.test.mjs'], { cwd: pkgDir });
35
- } else if (cmd === 'test:corpus') {
36
- run(process.execPath, ['compiler/tests/run-corpus.mjs'], { cwd: pkgDir });
37
- } else if (cmd === 'bench') {
38
- run(process.execPath, ['tools/bench.mjs'], { cwd: pkgDir });
39
- } else if (cmd === 'check:docs') {
40
- run(process.execPath, ['tools/docs-check.mjs'], { cwd: pkgDir });
41
- } else if (cmd === 'init') {
42
- const initPath = join(pkgDir, 'tools', 'init.mjs');
43
- if (!existsSync(initPath)) {
44
- console.error('laravel-workers init: tools/init.mjs not found in package — reinstall laravel-workers.');
45
- process.exit(1);
46
- }
47
- let cwd = appDir;
48
- if (!existsSync(join(appDir, 'artisan')) && existsSync(join(dirname(pkgDir), 'artisan'))) {
49
- cwd = dirname(pkgDir);
50
- }
51
- run(process.execPath, [initPath], { cwd });
52
- } else if (cmd === 'build') {
53
- const buildPath = join(pkgDir, 'build.mjs');
54
- if (!existsSync(buildPath)) {
55
- console.error('laravel-workers build: build.mjs not found in package — reinstall laravel-workers. Run from your Laravel app root via npx laravel-workers build.');
56
- process.exit(1);
57
- }
58
- let cwd = appDir;
59
- if (existsSync(join(appDir, 'artisan'))) {
60
- cwd = appDir;
61
- } else if (existsSync(join(dirname(pkgDir), 'artisan'))) {
62
- cwd = dirname(pkgDir);
63
- } else {
64
- cwd = appDir;
65
- }
66
- if (!existsSync(join(cwd, 'artisan'))) {
67
- console.error('laravel-workers build: artisan not found — run from your Laravel app root via npx laravel-workers build (cwd must contain artisan).');
68
- }
69
- run(process.execPath, [buildPath, '--strict', ...process.argv.slice(3)], { cwd });
70
- } else if (cmd === 'shadow') {
71
- // The shadow harness: the real app (PHP oracle) vs the compiled worker.
72
- const shadowPath = join(pkgDir, 'shadow', 'run.mjs');
73
- if (!existsSync(shadowPath)) {
74
- console.error('laravel-workers shadow: shadow/run.mjs not found in package - reinstall laravel-workers.');
75
- process.exit(1);
76
- }
77
- const args = process.argv.slice(3);
78
- if (!args.includes('--app') && !process.env.LW_SHADOW_APP) {
79
- console.error('laravel-workers shadow: --app <laravel-app-root> is required (or set LW_SHADOW_APP).');
80
- process.exit(2);
81
- }
82
- run(process.execPath, [shadowPath, ...args], { cwd: appDir });
83
- } else if (cmd === 'vendor:ensure') {
84
- // Build a (or reuse the cached) vendor tree the build needs to boot the app.
85
- // Content-addressed by composer.lock, so a second project with the same lock
86
- // costs nothing and a fresh clone never runs a full `composer install`.
87
- const litePath = join(pkgDir, 'tools', 'vendor-lite.mjs');
88
- if (!existsSync(litePath)) {
89
- console.error('laravel-workers vendor:ensure: tools/vendor-lite.mjs not found in package — reinstall laravel-workers.');
90
- process.exit(1);
91
- }
92
- run(process.execPath, [litePath, ...process.argv.slice(3)], { cwd: appDir });
93
- } else if (cmd === 'php:ensure') {
94
- // Resolve (or provision) the interpreter that can boot THIS app. The build
95
- // does this automatically; the explicit command exists for CI prewarming and
96
- // for operators who want the download to happen outside a build.
97
- const { resolvePhp } = await import(pathToFileURL(join(pkgDir, 'tools', 'php-runtime.mjs')).href);
98
- const { provisionPhp } = await import(pathToFileURL(join(pkgDir, 'tools', 'php-provision.mjs')).href);
99
- let requirement = null;
100
- try {
101
- requirement = JSON.parse(readFileSync(join(appDir, 'composer.json'), 'utf8')).require?.php || null;
102
- } catch {
103
- requirement = null;
104
- }
105
- try {
106
- const r = resolvePhp({ requirement });
107
- console.log(`PHP ${r.version} (${r.bin})${requirement ? ` — satisfies ${requirement}` : ''}`);
108
- } catch (e) {
109
- if (!requirement) {
110
- console.error(e.message);
111
- process.exit(1);
112
- }
113
- console.log(e.message.split('\n')[0]);
114
- console.log(`provisioning PHP ${requirement}...`);
115
- try {
116
- const p = await provisionPhp(requirement);
117
- console.log(`PHP ${p.version} at ${p.bin}${p.cached ? ' (cached)' : ' (downloaded, sha256 verified)'}`);
118
- console.log(` -> use it: PHP_BIN="${p.bin}" npx laravel-workers build --strict`);
119
- } catch (e2) {
120
- console.error(e2.message);
121
- process.exit(1);
122
- }
123
- }
124
- } else if (cmd === 'verify') {
125
- const php = process.env.PHP_BIN ?? 'php';
126
- const verifyPath = join(pkgDir, 'tools', 'verify-s0.php');
127
- if (!existsSync(verifyPath)) {
128
- console.error('laravel-workers verify: tools/verify-s0.php not found in package.');
129
- process.exit(1);
130
- }
131
- const vendorInApp = existsSync(join(appDir, 'vendor', 'autoload.php'));
132
- const vendorInParent = existsSync(join(dirname(pkgDir), 'vendor', 'autoload.php'));
133
- if (!vendorInApp && !vendorInParent) {
134
- console.log('VERIFY-S0: SKIP (no Laravel vendor/ found — run from your Laravel app root via npx laravel-workers verify).');
135
- process.exit(0);
136
- }
137
- run(php, [verifyPath], { cwd: appDir, env: { ...process.env, LW_APP_ROOT: appDir } });
138
- } else {
139
- console.error(`laravel-workers: unknown command "${cmd}". Try: test | test:db | test:sqlite | test:hash | test:validator | test:services | test:budget | test:corpus | bench | check:docs | init | build | verify | vendor:ensure | php:ensure`);
140
- process.exit(1);
141
- }
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from 'node:child_process';
3
+ import { existsSync, readFileSync } from 'node:fs';
4
+ import { dirname, join } from 'node:path';
5
+ import { fileURLToPath, pathToFileURL } from 'node:url';
6
+
7
+ const pkgDir = dirname(dirname(fileURLToPath(import.meta.url)));
8
+ const appDir = process.cwd();
9
+ const cmd = process.argv[2] ?? 'test';
10
+
11
+ const run = (command, args, options = {}) => {
12
+ const { cwd = pkgDir, ...rest } = options;
13
+ const res = spawnSync(command, args, { cwd, stdio: 'inherit', ...rest });
14
+ if (res.error) {
15
+ console.error(res.error.message);
16
+ process.exit(1);
17
+ }
18
+ if (res.status !== 0) process.exit(res.status ?? 1);
19
+ };
20
+
21
+ if (cmd === 'test') {
22
+ run(process.execPath, ['--test', 'kernel/tests/router.test.mjs', 'kernel/tests/db.test.mjs', 'kernel/tests/sqlite-integration.test.mjs', 'kernel/tests/hash.test.mjs', 'kernel/tests/encrypter.test.mjs', 'kernel/tests/validator.test.mjs', 'kernel/tests/services.test.mjs', 'kernel/tests/routes-json.test.mjs', 'kernel/tests/registry-json.test.mjs', 'kernel/tests/ports.test.mjs', 'kernel/tests/budget.test.mjs', 'compiler/tests/controller.test.mjs'], { cwd: pkgDir });
23
+ } else if (cmd === 'test:db') {
24
+ run(process.execPath, ['--test', 'kernel/tests/db.test.mjs'], { cwd: pkgDir });
25
+ } else if (cmd === 'test:sqlite') {
26
+ run(process.execPath, ['--test', 'kernel/tests/sqlite-integration.test.mjs'], { cwd: pkgDir });
27
+ } else if (cmd === 'test:hash') {
28
+ run(process.execPath, ['--test', 'kernel/tests/hash.test.mjs', 'kernel/tests/encrypter.test.mjs'], { cwd: pkgDir });
29
+ } else if (cmd === 'test:validator') {
30
+ run(process.execPath, ['--test', 'kernel/tests/validator.test.mjs'], { cwd: pkgDir });
31
+ } else if (cmd === 'test:services') {
32
+ run(process.execPath, ['--test', 'kernel/tests/services.test.mjs'], { cwd: pkgDir });
33
+ } else if (cmd === 'test:budget') {
34
+ run(process.execPath, ['--test', 'kernel/tests/budget.test.mjs'], { cwd: pkgDir });
35
+ } else if (cmd === 'test:corpus') {
36
+ run(process.execPath, ['compiler/tests/run-corpus.mjs'], { cwd: pkgDir });
37
+ } else if (cmd === 'bench') {
38
+ run(process.execPath, ['tools/bench.mjs'], { cwd: pkgDir });
39
+ } else if (cmd === 'check:docs') {
40
+ run(process.execPath, ['tools/docs-check.mjs'], { cwd: pkgDir });
41
+ } else if (cmd === 'init') {
42
+ const initPath = join(pkgDir, 'tools', 'init.mjs');
43
+ if (!existsSync(initPath)) {
44
+ console.error('laravel-workers init: tools/init.mjs not found in package — reinstall laravel-workers.');
45
+ process.exit(1);
46
+ }
47
+ let cwd = appDir;
48
+ if (!existsSync(join(appDir, 'artisan')) && existsSync(join(dirname(pkgDir), 'artisan'))) {
49
+ cwd = dirname(pkgDir);
50
+ }
51
+ run(process.execPath, [initPath], { cwd });
52
+ } else if (cmd === 'build') {
53
+ const buildPath = join(pkgDir, 'build.mjs');
54
+ if (!existsSync(buildPath)) {
55
+ console.error('laravel-workers build: build.mjs not found in package — reinstall laravel-workers. Run from your Laravel app root via npx laravel-workers build.');
56
+ process.exit(1);
57
+ }
58
+ let cwd = appDir;
59
+ if (existsSync(join(appDir, 'artisan'))) {
60
+ cwd = appDir;
61
+ } else if (existsSync(join(dirname(pkgDir), 'artisan'))) {
62
+ cwd = dirname(pkgDir);
63
+ } else {
64
+ cwd = appDir;
65
+ }
66
+ if (!existsSync(join(cwd, 'artisan'))) {
67
+ console.error('laravel-workers build: artisan not found — run from your Laravel app root via npx laravel-workers build (cwd must contain artisan).');
68
+ }
69
+ run(process.execPath, [buildPath, '--strict', ...process.argv.slice(3)], { cwd });
70
+ } else if (cmd === 'shadow') {
71
+ // The shadow harness: the real app (PHP oracle) vs the compiled worker.
72
+ const shadowPath = join(pkgDir, 'shadow', 'run.mjs');
73
+ if (!existsSync(shadowPath)) {
74
+ console.error('laravel-workers shadow: shadow/run.mjs not found in package - reinstall laravel-workers.');
75
+ process.exit(1);
76
+ }
77
+ const args = process.argv.slice(3);
78
+ if (!args.includes('--app') && !process.env.LW_SHADOW_APP) {
79
+ console.error('laravel-workers shadow: --app <laravel-app-root> is required (or set LW_SHADOW_APP).');
80
+ process.exit(2);
81
+ }
82
+ run(process.execPath, [shadowPath, ...args], { cwd: appDir });
83
+ } else if (cmd === 'vendor:ensure') {
84
+ // Build a (or reuse the cached) vendor tree the build needs to boot the app.
85
+ // Content-addressed by composer.lock, so a second project with the same lock
86
+ // costs nothing and a fresh clone never runs a full `composer install`.
87
+ const litePath = join(pkgDir, 'tools', 'vendor-lite.mjs');
88
+ if (!existsSync(litePath)) {
89
+ console.error('laravel-workers vendor:ensure: tools/vendor-lite.mjs not found in package — reinstall laravel-workers.');
90
+ process.exit(1);
91
+ }
92
+ run(process.execPath, [litePath, ...process.argv.slice(3)], { cwd: appDir });
93
+ } else if (cmd === 'php:ensure') {
94
+ // Resolve (or provision) the interpreter that can boot THIS app. The build
95
+ // does this automatically; the explicit command exists for CI prewarming and
96
+ // for operators who want the download to happen outside a build.
97
+ const { resolvePhp } = await import(pathToFileURL(join(pkgDir, 'tools', 'php-runtime.mjs')).href);
98
+ const { provisionPhp } = await import(pathToFileURL(join(pkgDir, 'tools', 'php-provision.mjs')).href);
99
+ let requirement = null;
100
+ try {
101
+ requirement = JSON.parse(readFileSync(join(appDir, 'composer.json'), 'utf8')).require?.php || null;
102
+ } catch {
103
+ requirement = null;
104
+ }
105
+ try {
106
+ const r = resolvePhp({ requirement });
107
+ console.log(`PHP ${r.version} (${r.bin})${requirement ? ` — satisfies ${requirement}` : ''}`);
108
+ } catch (e) {
109
+ if (!requirement) {
110
+ console.error(e.message);
111
+ process.exit(1);
112
+ }
113
+ console.log(e.message.split('\n')[0]);
114
+ console.log(`provisioning PHP ${requirement}...`);
115
+ try {
116
+ const p = await provisionPhp(requirement);
117
+ console.log(`PHP ${p.version} at ${p.bin}${p.cached ? ' (cached)' : ' (downloaded, sha256 verified)'}`);
118
+ console.log(` -> use it: PHP_BIN="${p.bin}" npx laravel-workers build --strict`);
119
+ } catch (e2) {
120
+ console.error(e2.message);
121
+ process.exit(1);
122
+ }
123
+ }
124
+ } else if (cmd === 'verify') {
125
+ const php = process.env.PHP_BIN ?? 'php';
126
+ const verifyPath = join(pkgDir, 'tools', 'verify-s0.php');
127
+ if (!existsSync(verifyPath)) {
128
+ console.error('laravel-workers verify: tools/verify-s0.php not found in package.');
129
+ process.exit(1);
130
+ }
131
+ const vendorInApp = existsSync(join(appDir, 'vendor', 'autoload.php'));
132
+ const vendorInParent = existsSync(join(dirname(pkgDir), 'vendor', 'autoload.php'));
133
+ if (!vendorInApp && !vendorInParent) {
134
+ console.log('VERIFY-S0: SKIP (no Laravel vendor/ found — run from your Laravel app root via npx laravel-workers verify).');
135
+ process.exit(0);
136
+ }
137
+ run(php, [verifyPath], { cwd: appDir, env: { ...process.env, LW_APP_ROOT: appDir } });
138
+ } else {
139
+ console.error(`laravel-workers: unknown command "${cmd}". Try: test | test:db | test:sqlite | test:hash | test:validator | test:services | test:budget | test:corpus | bench | check:docs | init | build | verify | vendor:ensure | php:ensure`);
140
+ process.exit(1);
141
+ }