@lwrjs/shared-utils 0.16.1 → 0.16.3

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/build/cjs/env.cjs CHANGED
@@ -13,7 +13,9 @@ __export(exports, {
13
13
  buildEnvironmentContext: () => buildEnvironmentContext,
14
14
  getFeatureFlags: () => getFeatureFlags,
15
15
  isLambdaEnv: () => isLambdaEnv,
16
+ isLocalAuthEnabled: () => isLocalAuthEnabled,
16
17
  isLocalDev: () => isLocalDev,
18
+ isLocalPreview: () => isLocalPreview,
17
19
  parseRequestDepth: () => parseRequestDepth
18
20
  });
19
21
  if (getFeatureFlags().REEVALUATE_MODULES && !getFeatureFlags().LEGACY_LOADER) {
@@ -53,6 +55,12 @@ function isLambdaEnv() {
53
55
  function isLocalDev() {
54
56
  return process.env.MRT_HMR === "true";
55
57
  }
58
+ function isLocalPreview() {
59
+ return process.env.LOCAL_PREVIEW_MODE === "true";
60
+ }
61
+ function isLocalAuthEnabled() {
62
+ return process.env.AUTH_TOKEN !== void 0;
63
+ }
56
64
  function buildEnvironmentContext(runtimeParams) {
57
65
  const basePath = runtimeParams.basePath;
58
66
  const locale = runtimeParams.locale;
@@ -27,7 +27,7 @@ __export(exports, {
27
27
  launch: () => launch
28
28
  });
29
29
  var import_os = __toModule(require("os"));
30
- async function launch(port, https) {
30
+ async function launch(port, https, path) {
31
31
  const {exec} = await Promise.resolve().then(() => __toModule(require("child_process")));
32
32
  let cmd = "open";
33
33
  if (process.platform == "win32") {
@@ -39,5 +39,9 @@ async function launch(port, https) {
39
39
  cmd = "xdg-open";
40
40
  }
41
41
  }
42
- exec(`${cmd} ${https ? "https" : "http"}://localhost:${port}`);
42
+ const finalPath = path ? path.startsWith("/") ? path : `/${path}` : "";
43
+ const protocol = https ? "https" : "http";
44
+ const url = `${protocol}://localhost:${port}${finalPath}/`;
45
+ exec(`${cmd} ${url}`);
46
+ return url;
43
47
  }
package/build/es/env.d.ts CHANGED
@@ -12,6 +12,18 @@ export declare function isLambdaEnv(): boolean;
12
12
  * @returns true if running in localdev mode
13
13
  */
14
14
  export declare function isLocalDev(): boolean;
15
+ /**
16
+ * This function is used to determine if lwr is running in the context of local preview.
17
+ *
18
+ * @returns true if running in preview mode
19
+ */
20
+ export declare function isLocalPreview(): boolean;
21
+ /**
22
+ * This function is used to determine if lwr is running with an authenticated context locally
23
+ *
24
+ * @returns true if local dev/preview authentication is enabled
25
+ */
26
+ export declare function isLocalAuthEnabled(): boolean;
15
27
  /**
16
28
  * Create a serializable context for user-land exposed environment variables
17
29
  */
package/build/es/env.js CHANGED
@@ -72,6 +72,22 @@ export function isLocalDev() {
72
72
  // TODO still need to formalize environment variable names
73
73
  return process.env.MRT_HMR === 'true';
74
74
  }
75
+ /**
76
+ * This function is used to determine if lwr is running in the context of local preview.
77
+ *
78
+ * @returns true if running in preview mode
79
+ */
80
+ export function isLocalPreview() {
81
+ return process.env.LOCAL_PREVIEW_MODE === 'true';
82
+ }
83
+ /**
84
+ * This function is used to determine if lwr is running with an authenticated context locally
85
+ *
86
+ * @returns true if local dev/preview authentication is enabled
87
+ */
88
+ export function isLocalAuthEnabled() {
89
+ return process.env.AUTH_TOKEN !== undefined;
90
+ }
75
91
  /**
76
92
  * Create a serializable context for user-land exposed environment variables
77
93
  */
@@ -4,5 +4,5 @@
4
4
  * @param port - the port number
5
5
  * @param https - if true, use https
6
6
  */
7
- export declare function launch(port: number, https?: boolean): Promise<void>;
7
+ export declare function launch(port: number, https?: boolean, path?: string): Promise<string>;
8
8
  //# sourceMappingURL=launch.d.ts.map
@@ -5,7 +5,7 @@ import { release } from 'os';
5
5
  * @param port - the port number
6
6
  * @param https - if true, use https
7
7
  */
8
- export async function launch(port, https) {
8
+ export async function launch(port, https, path) {
9
9
  const { exec } = await import('child_process');
10
10
  let cmd = 'open';
11
11
  if (process.platform == 'win32') {
@@ -19,6 +19,11 @@ export async function launch(port, https) {
19
19
  cmd = 'xdg-open';
20
20
  }
21
21
  }
22
- exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
22
+ // Ensure the path begins with '/' if provided
23
+ const finalPath = path ? (path.startsWith('/') ? path : `/${path}`) : '';
24
+ const protocol = https ? 'https' : 'http';
25
+ const url = `${protocol}://localhost:${port}${finalPath}/`;
26
+ exec(`${cmd} ${url}`);
27
+ return url;
23
28
  }
24
29
  //# sourceMappingURL=launch.js.map
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.16.1",
7
+ "version": "0.16.3",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -37,7 +37,7 @@
37
37
  "build/**/*.d.ts"
38
38
  ],
39
39
  "dependencies": {
40
- "@lwrjs/diagnostics": "0.16.1",
40
+ "@lwrjs/diagnostics": "0.16.3",
41
41
  "es-module-lexer": "^1.5.4",
42
42
  "fast-json-stable-stringify": "^2.1.0",
43
43
  "magic-string": "^0.30.9",
@@ -50,7 +50,7 @@
50
50
  "slugify": "^1.4.5"
51
51
  },
52
52
  "devDependencies": {
53
- "@lwrjs/types": "0.16.1",
53
+ "@lwrjs/types": "0.16.3",
54
54
  "@types/mime-types": "2.1.4",
55
55
  "@types/path-to-regexp": "^1.7.0",
56
56
  "memfs": "^4.13.0"
@@ -58,5 +58,5 @@
58
58
  "engines": {
59
59
  "node": ">=18.0.0"
60
60
  },
61
- "gitHead": "6a23d20417e4e5608ad18e0a5752bb3655a76fbf"
61
+ "gitHead": "91bc46c88ff7201851f02fc4a3d38d39e81885c6"
62
62
  }