@lowdefy/e2e-utils 5.5.0 → 5.6.0

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.
@@ -0,0 +1,61 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ /* eslint-disable no-console */ import fs from 'fs';
16
+ import path from 'path';
17
+ import yaml from 'js-yaml';
18
+ function findWorkspaceRoot(startDir) {
19
+ let dir = startDir;
20
+ while(dir !== path.dirname(dir)){
21
+ if (fs.existsSync(path.join(dir, 'pnpm-workspace.yaml'))) return dir;
22
+ dir = path.dirname(dir);
23
+ }
24
+ return null;
25
+ }
26
+ // pnpm no longer reads the "pnpm" field in package.json, and pnpm 11 fails installs
27
+ // with ERR_PNPM_IGNORED_BUILDS unless dependency build scripts are allowed in
28
+ // pnpm-workspace.yaml. The key differs by version:
29
+ // - packages is required by pnpm 9 and 10.0.
30
+ // - onlyBuiltDependencies is read by early pnpm 10 versions.
31
+ // - allowBuilds is read by pnpm >=10.29 and pnpm 11.
32
+ function allowDependencyBuild({ cwd, appPath, dependency }) {
33
+ const appDir = path.join(cwd, appPath);
34
+ const workspaceRoot = findWorkspaceRoot(appDir);
35
+ const targetDir = workspaceRoot ?? appDir;
36
+ const workspacePath = path.join(targetDir, 'pnpm-workspace.yaml');
37
+ const config = workspaceRoot ? yaml.load(fs.readFileSync(workspacePath, 'utf8')) ?? {} : {
38
+ packages: [
39
+ '.'
40
+ ]
41
+ };
42
+ const onlyBuiltDependencies = config.onlyBuiltDependencies ?? [];
43
+ const allowBuilds = config.allowBuilds ?? {};
44
+ if (onlyBuiltDependencies.includes(dependency) && allowBuilds[dependency] === true) {
45
+ return;
46
+ }
47
+ if (!onlyBuiltDependencies.includes(dependency)) {
48
+ config.onlyBuiltDependencies = [
49
+ ...onlyBuiltDependencies,
50
+ dependency
51
+ ];
52
+ }
53
+ config.allowBuilds = {
54
+ ...allowBuilds,
55
+ [dependency]: true
56
+ };
57
+ fs.writeFileSync(workspacePath, yaml.dump(config));
58
+ const label = workspaceRoot ? 'workspace root pnpm-workspace.yaml' : `${appPath}/pnpm-workspace.yaml`;
59
+ console.log(` ✓ Allowed ${dependency} build scripts in ${label}`);
60
+ }
61
+ export default allowDependencyBuild;
@@ -15,6 +15,7 @@
15
15
  */ /* eslint-disable no-console */ import fs from 'fs';
16
16
  import path from 'path';
17
17
  import { fileURLToPath } from 'url';
18
+ import allowDependencyBuild from './allowDependencyBuild.js';
18
19
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
19
20
  function copyTemplate(templateName, destPath) {
20
21
  const srcPath = path.join(__dirname, 'templates', templateName);
@@ -24,34 +25,6 @@ function copyTemplate(templateName, destPath) {
24
25
  }
25
26
  return false;
26
27
  }
27
- function findWorkspaceRoot(startDir) {
28
- let dir = startDir;
29
- while(dir !== path.dirname(dir)){
30
- if (fs.existsSync(path.join(dir, 'pnpm-workspace.yaml'))) return dir;
31
- dir = path.dirname(dir);
32
- }
33
- return null;
34
- }
35
- function addOnlyBuiltDependency({ cwd, appPath, dependency }) {
36
- const appDir = path.join(cwd, appPath);
37
- const workspaceRoot = findWorkspaceRoot(appDir);
38
- // In a pnpm workspace, onlyBuiltDependencies must be in the workspace root package.json
39
- const targetDir = workspaceRoot ?? path.join(cwd, appPath);
40
- const pkgPath = path.join(targetDir, 'package.json');
41
- if (!fs.existsSync(pkgPath)) return;
42
- const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
43
- const allowedBuilds = pkg.pnpm?.onlyBuiltDependencies ?? [];
44
- if (!allowedBuilds.includes(dependency)) {
45
- pkg.pnpm = pkg.pnpm || {};
46
- pkg.pnpm.onlyBuiltDependencies = [
47
- ...allowedBuilds,
48
- dependency
49
- ];
50
- fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
51
- const label = workspaceRoot ? 'workspace root package.json' : `${appPath}/package.json`;
52
- console.log(` ✓ Added ${dependency} to pnpm.onlyBuiltDependencies in ${label}`);
53
- }
54
- }
55
28
  function updatePackageJson({ appPath, cwd, useExperimental, useMongoDB }) {
56
29
  const pkgPath = path.join(cwd, appPath, 'package.json');
57
30
  if (!fs.existsSync(pkgPath)) {
@@ -97,9 +70,9 @@ function updatePackageJson({ appPath, cwd, useExperimental, useMongoDB }) {
97
70
  fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
98
71
  console.log(` ✓ Updated ${appPath}/package.json with e2e scripts and dependencies`);
99
72
  }
100
- // mongodb-memory-server needs onlyBuiltDependencies (workspace-aware)
73
+ // mongodb-memory-server downloads mongod binaries in a postinstall script
101
74
  if (useMongoDB) {
102
- addOnlyBuiltDependency({
75
+ allowDependencyBuild({
103
76
  cwd,
104
77
  appPath,
105
78
  dependency: 'mongodb-memory-server'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/e2e-utils",
3
- "version": "5.5.0",
3
+ "version": "5.6.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Lowdefy E2E Testing Utilities for Playwright",
6
6
  "homepage": "https://lowdefy.com",
@@ -36,7 +36,7 @@
36
36
  "dist/*"
37
37
  ],
38
38
  "dependencies": {
39
- "@lowdefy/helpers": "5.5.0",
39
+ "@lowdefy/helpers": "5.6.0",
40
40
  "js-yaml": "4.1.0",
41
41
  "prompts": "2.4.2"
42
42
  },