sb-mig 6.0.0-beta.1 → 6.0.0-beta.2

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.
@@ -1,5 +1,5 @@
1
1
  import { readdir, stat, readFile, realpath } from "fs/promises";
2
- import { join, resolve } from "path";
2
+ import { join, resolve, sep } from "path";
3
3
  import { pathToFileURL } from "url";
4
4
  /**
5
5
  * Load the content of a resource file (.sb.js, .datasource.js, etc.)
@@ -81,8 +81,8 @@ async function isWithinProject(targetPath, projectRoot) {
81
81
  // Resolve both paths to handle symlinks
82
82
  const resolvedTarget = await realpath(targetPath);
83
83
  const resolvedRoot = await realpath(projectRoot);
84
- // Check if target is within project root
85
- return (resolvedTarget.startsWith(resolvedRoot + "/") ||
84
+ // Use the platform separator so this works on Windows (`\`) and POSIX (`/`).
85
+ return (resolvedTarget.startsWith(resolvedRoot + sep) ||
86
86
  resolvedTarget === resolvedRoot);
87
87
  }
88
88
  catch {
@@ -26,8 +26,12 @@ export interface PrecompileResult {
26
26
  }>;
27
27
  }
28
28
  /**
29
- * Extract the component name from a file path
29
+ * Extract the component name from a file path.
30
+ * Handles both POSIX (`/`) and Windows (`\`) separators because glob v11
31
+ * and node's `fs` APIs return native paths on Windows.
32
+ *
30
33
  * e.g., "/path/to/my-component.sb.ts" -> "my-component.sb"
34
+ * "C:\\path\\to\\my-component.sb.ts" -> "my-component.sb"
31
35
  */
32
36
  export declare const extractComponentName: (filePath: string) => string;
33
37
  /**
@@ -3,13 +3,16 @@ import path from "path";
3
3
  import rollupSwc from "@rollup/plugin-swc";
4
4
  import { rollup } from "rollup";
5
5
  /**
6
- * Extract the component name from a file path
6
+ * Extract the component name from a file path.
7
+ * Handles both POSIX (`/`) and Windows (`\`) separators because glob v11
8
+ * and node's `fs` APIs return native paths on Windows.
9
+ *
7
10
  * e.g., "/path/to/my-component.sb.ts" -> "my-component.sb"
11
+ * "C:\\path\\to\\my-component.sb.ts" -> "my-component.sb"
8
12
  */
9
13
  export const extractComponentName = (filePath) => {
10
- const separator = "/";
11
- const parts = filePath.split(separator);
12
- const lastElement = parts[parts.length - 1];
14
+ const normalized = filePath.replace(/\\/g, "/");
15
+ const lastElement = normalized.substring(normalized.lastIndexOf("/") + 1);
13
16
  return lastElement.replace(/\.ts$/, "");
14
17
  };
15
18
  /**
@@ -5,12 +5,15 @@
5
5
  * Extracts the component name from a file path.
6
6
  * Used for naming compiled output files from TypeScript sources.
7
7
  *
8
- * @param filePath - Full path to the component file (always uses Unix-style separators from glob)
9
- * @returns Component name without the .ts extension
8
+ * Handles both POSIX (`/`) and Windows (`\`) separators because glob v11
9
+ * returns native paths on Windows.
10
+ *
11
+ * @param filePath - Full path to the component file
12
+ * @returns Component name without the trailing .ts extension
10
13
  *
11
14
  * @example
12
- * _extractComponentName("/Users/project/src/hero.sb.ts") // => "hero.sb"
13
- * _extractComponentName("C:/Users/project/src/card.sb.ts") // => "card.sb"
15
+ * extractComponentName("/Users/project/src/hero.sb.ts") // => "hero.sb"
16
+ * extractComponentName("C:\\Users\\project\\src\\card.sb.ts") // => "card.sb"
14
17
  */
15
18
  export declare const extractComponentName: (filePath: string) => string;
16
19
  /**
@@ -6,18 +6,21 @@ import path from "path";
6
6
  * Extracts the component name from a file path.
7
7
  * Used for naming compiled output files from TypeScript sources.
8
8
  *
9
- * @param filePath - Full path to the component file (always uses Unix-style separators from glob)
10
- * @returns Component name without the .ts extension
9
+ * Handles both POSIX (`/`) and Windows (`\`) separators because glob v11
10
+ * returns native paths on Windows.
11
+ *
12
+ * @param filePath - Full path to the component file
13
+ * @returns Component name without the trailing .ts extension
11
14
  *
12
15
  * @example
13
- * _extractComponentName("/Users/project/src/hero.sb.ts") // => "hero.sb"
14
- * _extractComponentName("C:/Users/project/src/card.sb.ts") // => "card.sb"
16
+ * extractComponentName("/Users/project/src/hero.sb.ts") // => "hero.sb"
17
+ * extractComponentName("C:\\Users\\project\\src\\card.sb.ts") // => "card.sb"
15
18
  */
16
19
  export const extractComponentName = (filePath) => {
17
- const separator = "/"; // glob always returns unix-style paths
18
- const sP = filePath.split(separator);
19
- const lastElement = sP[sP.length - 1];
20
- return lastElement.replaceAll(".ts", "");
20
+ // Normalize to forward slashes so basename works regardless of platform.
21
+ const normalized = filePath.replace(/\\/g, "/");
22
+ const lastElement = normalized.substring(normalized.lastIndexOf("/") + 1);
23
+ return lastElement.replace(/\.ts$/, "");
21
24
  };
22
25
  /**
23
26
  * Normalizes an array of directory segments for glob pattern usage.
@@ -121,8 +121,8 @@ async function isWithinProject(targetPath, projectRoot) {
121
121
  // Resolve both paths to handle symlinks
122
122
  const resolvedTarget = await (0, promises_1.realpath)(targetPath);
123
123
  const resolvedRoot = await (0, promises_1.realpath)(projectRoot);
124
- // Check if target is within project root
125
- return (resolvedTarget.startsWith(resolvedRoot + "/") ||
124
+ // Use the platform separator so this works on Windows (`\`) and POSIX (`/`).
125
+ return (resolvedTarget.startsWith(resolvedRoot + path_1.sep) ||
126
126
  resolvedTarget === resolvedRoot);
127
127
  }
128
128
  catch {
@@ -11,13 +11,16 @@ const path_1 = __importDefault(require("path"));
11
11
  const plugin_swc_1 = __importDefault(require("@rollup/plugin-swc"));
12
12
  const rollup_1 = require("rollup");
13
13
  /**
14
- * Extract the component name from a file path
14
+ * Extract the component name from a file path.
15
+ * Handles both POSIX (`/`) and Windows (`\`) separators because glob v11
16
+ * and node's `fs` APIs return native paths on Windows.
17
+ *
15
18
  * e.g., "/path/to/my-component.sb.ts" -> "my-component.sb"
19
+ * "C:\\path\\to\\my-component.sb.ts" -> "my-component.sb"
16
20
  */
17
21
  const extractComponentName = (filePath) => {
18
- const separator = "/";
19
- const parts = filePath.split(separator);
20
- const lastElement = parts[parts.length - 1];
22
+ const normalized = filePath.replace(/\\/g, "/");
23
+ const lastElement = normalized.substring(normalized.lastIndexOf("/") + 1);
21
24
  return lastElement.replace(/\.ts$/, "");
22
25
  };
23
26
  exports.extractComponentName = extractComponentName;
@@ -12,18 +12,21 @@ const path_1 = __importDefault(require("path"));
12
12
  * Extracts the component name from a file path.
13
13
  * Used for naming compiled output files from TypeScript sources.
14
14
  *
15
- * @param filePath - Full path to the component file (always uses Unix-style separators from glob)
16
- * @returns Component name without the .ts extension
15
+ * Handles both POSIX (`/`) and Windows (`\`) separators because glob v11
16
+ * returns native paths on Windows.
17
+ *
18
+ * @param filePath - Full path to the component file
19
+ * @returns Component name without the trailing .ts extension
17
20
  *
18
21
  * @example
19
- * _extractComponentName("/Users/project/src/hero.sb.ts") // => "hero.sb"
20
- * _extractComponentName("C:/Users/project/src/card.sb.ts") // => "card.sb"
22
+ * extractComponentName("/Users/project/src/hero.sb.ts") // => "hero.sb"
23
+ * extractComponentName("C:\\Users\\project\\src\\card.sb.ts") // => "card.sb"
21
24
  */
22
25
  const extractComponentName = (filePath) => {
23
- const separator = "/"; // glob always returns unix-style paths
24
- const sP = filePath.split(separator);
25
- const lastElement = sP[sP.length - 1];
26
- return lastElement.replaceAll(".ts", "");
26
+ // Normalize to forward slashes so basename works regardless of platform.
27
+ const normalized = filePath.replace(/\\/g, "/");
28
+ const lastElement = normalized.substring(normalized.lastIndexOf("/") + 1);
29
+ return lastElement.replace(/\.ts$/, "");
27
30
  };
28
31
  exports.extractComponentName = extractComponentName;
29
32
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sb-mig",
3
- "version": "6.0.0-beta.1",
3
+ "version": "6.0.0-beta.2",
4
4
  "description": "CLI to rule the world. (and handle stuff related to Storyblok CMS)",
5
5
  "author": "Marcin Krawczyk <marckraw@icloud.com>",
6
6
  "license": "MIT",