@optimizely/ocp-local-env 1.0.6 → 1.0.7
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/dist/package.json +2 -2
- package/dist/public/{bundle.a780925872f9c50199db.js → bundle.7d11f6ae797ed7f421b8.js} +3 -3
- package/dist/public/bundle.7d11f6ae797ed7f421b8.js.map +1 -0
- package/dist/public/index.html +1 -1
- package/dist/src/executor/watcher.js +2 -2
- package/dist/src/executor/watcher.js.map +1 -1
- package/dist/src/server/api/v2.d.ts +4 -0
- package/dist/src/server/api/v2.js +49 -0
- package/dist/src/server/api/v2.js.map +1 -0
- package/dist/src/server/config.js +9 -4
- package/dist/src/server/config.js.map +1 -1
- package/dist/src/server.js +12 -0
- package/dist/src/server.js.map +1 -1
- package/dist/src/ui/components/CmsExtensionDevPanel.js +4 -2
- package/dist/src/ui/components/CmsExtensionDevPanel.js.map +1 -1
- package/dist/src/ui/components/CmsUiExtensionsView.js +3 -2
- package/dist/src/ui/components/CmsUiExtensionsView.js.map +1 -1
- package/dist/src/utils/package-manager.d.ts +31 -0
- package/dist/src/utils/package-manager.js +129 -0
- package/dist/src/utils/package-manager.js.map +1 -0
- package/package.json +2 -2
- package/dist/public/bundle.a780925872f9c50199db.js.map +0 -1
- /package/dist/public/{bundle.a780925872f9c50199db.js.LICENSE.txt → bundle.7d11f6ae797ed7f421b8.js.LICENSE.txt} +0 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Resolving which package manager an OCP app builds with.
|
|
4
|
+
*
|
|
5
|
+
* When launched through `ocp dev`, the CLI has already worked this out and passes the
|
|
6
|
+
* resolved command in OCP_LOCAL_BUILD_COMMAND. This module is the fallback for
|
|
7
|
+
* standalone `ocp-local-env` runs, where nobody has told us. It deliberately stays
|
|
8
|
+
* simpler than the CLI's equivalent: there's no runtime manifest to validate against,
|
|
9
|
+
* and the yarn Classic/Berry distinction doesn't matter because both build the same
|
|
10
|
+
* way and this tool never runs install.
|
|
11
|
+
*/
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.detectPackageManager = detectPackageManager;
|
|
17
|
+
exports.getBuildCommand = getBuildCommand;
|
|
18
|
+
exports.getPackageManagerWarning = getPackageManagerWarning;
|
|
19
|
+
const fs_1 = __importDefault(require("fs"));
|
|
20
|
+
const path_1 = __importDefault(require("path"));
|
|
21
|
+
const SUPPORTED = ['yarn', 'npm', 'pnpm', 'bun'];
|
|
22
|
+
/**
|
|
23
|
+
* Lock files in priority order. This mirrors the CLI's LOCK_FILES, order included: an
|
|
24
|
+
* app carrying more than one lock file must resolve the same way here as it does in
|
|
25
|
+
* `ocp app prepare`, or a local build would quietly differ from the deployed one.
|
|
26
|
+
*/
|
|
27
|
+
const LOCK_FILES = [
|
|
28
|
+
['yarn.lock', 'yarn'],
|
|
29
|
+
['package-lock.json', 'npm'],
|
|
30
|
+
['pnpm-lock.yaml', 'pnpm'],
|
|
31
|
+
['bun.lockb', 'bun'],
|
|
32
|
+
['bun.lock', 'bun'],
|
|
33
|
+
];
|
|
34
|
+
/**
|
|
35
|
+
* Commands that run the app's `build` script. These mirror the CLI's
|
|
36
|
+
* runDirectCommand('build') exactly, so `ocp dev` and a standalone run never
|
|
37
|
+
* disagree about how the app gets built.
|
|
38
|
+
*/
|
|
39
|
+
const BUILD_COMMANDS = {
|
|
40
|
+
yarn: 'yarn build',
|
|
41
|
+
pnpm: 'pnpm build',
|
|
42
|
+
npm: 'npm run build',
|
|
43
|
+
bun: 'bun run build',
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Read the Corepack `packageManager` field from the app's package.json.
|
|
47
|
+
*
|
|
48
|
+
* Returns null when the field is absent, names something we don't know, or
|
|
49
|
+
* package.json is missing/unreadable/malformed — detection has to degrade quietly,
|
|
50
|
+
* since it runs while the server is starting up.
|
|
51
|
+
*/
|
|
52
|
+
function fromPackageManagerField(appDir) {
|
|
53
|
+
let field;
|
|
54
|
+
try {
|
|
55
|
+
const packageJson = JSON.parse(fs_1.default.readFileSync(path_1.default.join(appDir, 'package.json'), 'utf8'));
|
|
56
|
+
field = packageJson?.packageManager;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
if (typeof field !== 'string' || !field.trim()) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
// Corepack format is `name@version`, optionally with a `+sha224.<hash>` suffix.
|
|
65
|
+
// Tolerate a bare name too — we only care about the name here.
|
|
66
|
+
const spec = field.trim().split('+')[0];
|
|
67
|
+
const separator = spec.lastIndexOf('@');
|
|
68
|
+
const name = separator > 0 ? spec.slice(0, separator) : spec;
|
|
69
|
+
return SUPPORTED.includes(name) ? name : null;
|
|
70
|
+
}
|
|
71
|
+
function detect(appDir) {
|
|
72
|
+
const present = LOCK_FILES.filter(([lockFile]) => fs_1.default.existsSync(path_1.default.join(appDir, lockFile)));
|
|
73
|
+
const strayFor = (packageManager) => present.filter(([, pm]) => pm !== packageManager).map(([lockFile]) => lockFile);
|
|
74
|
+
const declared = fromPackageManagerField(appDir);
|
|
75
|
+
if (declared) {
|
|
76
|
+
return { packageManager: declared, source: 'field', strayLockFiles: strayFor(declared) };
|
|
77
|
+
}
|
|
78
|
+
if (present.length > 0) {
|
|
79
|
+
const [selectedBy, packageManager] = present[0];
|
|
80
|
+
return {
|
|
81
|
+
packageManager,
|
|
82
|
+
source: 'lockFile',
|
|
83
|
+
selectedBy,
|
|
84
|
+
strayLockFiles: strayFor(packageManager),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return { packageManager: 'yarn', source: 'default', strayLockFiles: [] };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Determine which package manager an app uses.
|
|
91
|
+
*
|
|
92
|
+
* The `packageManager` field wins over lock files because it's what Corepack
|
|
93
|
+
* enforces: an app declaring pnpm will refuse to build with yarn even if a stale
|
|
94
|
+
* yarn.lock is sitting next to it. Defaults to yarn when there's no signal either way.
|
|
95
|
+
*/
|
|
96
|
+
function detectPackageManager(appDir) {
|
|
97
|
+
return detect(appDir).packageManager;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get the command that runs the app's `build` script with its own package manager.
|
|
101
|
+
*/
|
|
102
|
+
function getBuildCommand(appDir) {
|
|
103
|
+
return BUILD_COMMANDS[detectPackageManager(appDir)];
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Describe any lock files that contradict the package manager we picked, so the
|
|
107
|
+
* developer hears about it rather than silently getting a build they didn't expect.
|
|
108
|
+
*
|
|
109
|
+
* We never delete or rewrite lock files — which one is stale is the app's call, not
|
|
110
|
+
* ours. Returns null when there's nothing ambiguous to report.
|
|
111
|
+
*/
|
|
112
|
+
function getPackageManagerWarning(appDir) {
|
|
113
|
+
const { packageManager, source, selectedBy, strayLockFiles } = detect(appDir);
|
|
114
|
+
if (strayLockFiles.length === 0) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
const stray = strayLockFiles.join(', ');
|
|
118
|
+
const plural = strayLockFiles.length > 1 ? 's' : '';
|
|
119
|
+
if (source === 'field') {
|
|
120
|
+
return (`Building with ${packageManager}, declared by the "packageManager" field in package.json, ` +
|
|
121
|
+
`but found ${stray} in the app directory. The lock file${plural} of another package ` +
|
|
122
|
+
`manager ${strayLockFiles.length > 1 ? 'are' : 'is'} ignored and may be stale — consider ` +
|
|
123
|
+
`removing ${strayLockFiles.length > 1 ? 'them' : 'it'} to keep local and deployed builds consistent.`);
|
|
124
|
+
}
|
|
125
|
+
return (`Found lock files for more than one package manager: ${selectedBy}, ${stray}. Building with ` +
|
|
126
|
+
`${packageManager} based on ${selectedBy}; the other${plural} ${strayLockFiles.length > 1 ? 'are' : 'is'} ` +
|
|
127
|
+
`ignored. Add a "packageManager" field to package.json to state which one this app really uses.`);
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=package-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-manager.js","sourceRoot":"","sources":["../../../src/utils/package-manager.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;AAuGH,oDAEC;AAKD,0CAEC;AASD,4DAuBC;AA9ID,4CAAoB;AACpB,gDAAwB;AAIxB,MAAM,SAAS,GAAqB,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AAEnE;;;;GAIG;AACH,MAAM,UAAU,GAAoC;IAClD,CAAC,WAAW,EAAE,MAAM,CAAC;IACrB,CAAC,mBAAmB,EAAE,KAAK,CAAC;IAC5B,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAC1B,CAAC,WAAW,EAAE,KAAK,CAAC;IACpB,CAAC,UAAU,EAAE,KAAK,CAAC;CACpB,CAAC;AAEF;;;;GAIG;AACH,MAAM,cAAc,GAAmC;IACrD,IAAI,EAAE,YAAY;IAClB,IAAI,EAAE,YAAY;IAClB,GAAG,EAAE,eAAe;IACpB,GAAG,EAAE,eAAe;CACrB,CAAC;AAEF;;;;;;GAMG;AACH,SAAS,uBAAuB,CAAC,MAAc;IAC7C,IAAI,KAAc,CAAC;IACnB,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,cAAI,CAAC,IAAI,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;QAC3F,KAAK,GAAG,WAAW,EAAE,cAAc,CAAC;IACtC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;QA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C,CAAC,CAAC,IAAI,gDAAgD,CACtG,CAAC;IACJ,CAAC;IAED,OAAO,CACL,uDAAuD,UAAU,KAAK,KAAK,kBAAkB;QAC7F,GAAG,cAAc,aAAa,UAAU,cAAc,MAAM,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,GAAG;QAC3G,gGAAgG,CACjG,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optimizely/ocp-local-env",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Local testing environment for Optimizely Connect Platform (OCP) applications",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@optiaxiom/icons": "^1.1.3",
|
|
66
|
-
"@optimizely/cms-extensibility-sdk": "^1.0.
|
|
66
|
+
"@optimizely/cms-extensibility-sdk": "^1.0.2",
|
|
67
67
|
"@playwright/test": "^1.40.0",
|
|
68
68
|
"@testing-library/dom": "^10.4.1",
|
|
69
69
|
"@testing-library/jest-dom": "^6.9.1",
|