cspell-io 10.3.4 → 10.3.6

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/index.d.ts CHANGED
@@ -502,6 +502,9 @@ interface RedirectOptions {
502
502
  * Create a provider that will redirect requests from the publicRoot to the privateRoot.
503
503
  * This is useful for creating a virtual file system that is a subset of another file system.
504
504
  *
505
+ * A request under the publicRoot is only passed on if it maps to a URL under the privateRoot.
506
+ * Other requests are rejected with a `VFSErrorUnsupportedRequest`.
507
+ *
505
508
  * Example:
506
509
  * ```ts
507
510
  * const vfs = createVirtualFS();
package/dist/index.js CHANGED
@@ -1492,6 +1492,9 @@ var RedirectProvider = class {
1492
1492
  * Create a provider that will redirect requests from the publicRoot to the privateRoot.
1493
1493
  * This is useful for creating a virtual file system that is a subset of another file system.
1494
1494
  *
1495
+ * A request under the publicRoot is only passed on if it maps to a URL under the privateRoot.
1496
+ * Other requests are rejected with a `VFSErrorUnsupportedRequest`.
1497
+ *
1495
1498
  * Example:
1496
1499
  * ```ts
1497
1500
  * const vfs = createVirtualFS();
@@ -1524,31 +1527,25 @@ function createRedirectProvider(name, publicRoot, privateRoot, options) {
1524
1527
  */
1525
1528
  function remapFS(name, fs, shadowFs, publicRoot, privateRoot, options) {
1526
1529
  const { capabilitiesMask = -1, capabilities } = options;
1527
- function mapToPrivate(url) {
1528
- const relativePath = url.pathname.slice(publicRoot.pathname.length);
1529
- return new URL(relativePath, privateRoot);
1530
- }
1531
- function mapToPublic(url) {
1532
- const relativePath = url.pathname.slice(privateRoot.pathname.length);
1533
- return new URL(relativePath, publicRoot);
1534
- }
1535
- const mapFileReferenceToPrivate = (ref) => {
1536
- return renameFileReference(ref, mapToPrivate(ref.url));
1530
+ const mapToPrivate = (url, request) => mapUrl(url, publicRoot, privateRoot, request);
1531
+ const mapToPublic = (url, request) => mapUrl(url, privateRoot, publicRoot, request);
1532
+ const mapFileReferenceToPrivate = (ref, request) => {
1533
+ return renameFileReference(ref, mapToPrivate(ref.url, request));
1537
1534
  };
1538
- const mapFileReferenceToPublic = (ref) => {
1539
- return renameFileReference(ref, mapToPublic(ref.url));
1535
+ const mapFileReferenceToPublic = (ref, request) => {
1536
+ return renameFileReference(ref, mapToPublic(ref.url, request));
1540
1537
  };
1541
- const mapUrlOrReferenceToPrivate = (urlOrRef) => {
1542
- return urlOrRef instanceof URL ? mapToPrivate(urlOrRef) : mapFileReferenceToPrivate(urlOrRef);
1538
+ const mapUrlOrReferenceToPrivate = (urlOrRef, request) => {
1539
+ return urlOrRef instanceof URL ? mapToPrivate(urlOrRef, request) : mapFileReferenceToPrivate(urlOrRef, request);
1543
1540
  };
1544
- const mapFileResourceToPublic = (res) => {
1545
- return renameFileResource(res, mapToPublic(res.url));
1541
+ const mapFileResourceToPublic = (res, request) => {
1542
+ return renameFileResource(res, mapToPublic(res.url, request));
1546
1543
  };
1547
- const mapFileResourceToPrivate = (res) => {
1548
- return renameFileResource(res, mapToPrivate(res.url));
1544
+ const mapFileResourceToPrivate = (res, request) => {
1545
+ return renameFileResource(res, mapToPrivate(res.url, request));
1549
1546
  };
1550
- const mapDirEntryToPublic = (de) => {
1551
- const dir = mapToPublic(de.dir);
1547
+ const mapDirEntryToPublic = (de, request) => {
1548
+ const dir = mapToPublic(de.dir, request);
1552
1549
  return {
1553
1550
  ...de,
1554
1551
  dir
@@ -1557,22 +1554,22 @@ function remapFS(name, fs, shadowFs, publicRoot, privateRoot, options) {
1557
1554
  const dispose = () => fs.dispose();
1558
1555
  return fsPassThrough({
1559
1556
  stat: async (url) => {
1560
- const url2 = mapUrlOrReferenceToPrivate(url);
1557
+ const url2 = mapUrlOrReferenceToPrivate(url, "stat");
1561
1558
  return await fs.stat(url2);
1562
1559
  },
1563
1560
  readFile: async (url, options) => {
1564
- const url2 = mapUrlOrReferenceToPrivate(url);
1561
+ const url2 = mapUrlOrReferenceToPrivate(url, "readFile");
1565
1562
  const file = await fs.readFile(url2, options);
1566
- return mapFileResourceToPublic(file);
1563
+ return mapFileResourceToPublic(file, "readFile");
1567
1564
  },
1568
1565
  readDirectory: async (url) => {
1569
- const url2 = mapToPrivate(url);
1570
- return (await fs.readDirectory(url2)).map(mapDirEntryToPublic);
1566
+ const url2 = mapToPrivate(url, "readDirectory");
1567
+ return (await fs.readDirectory(url2)).map((de) => mapDirEntryToPublic(de, "readDirectory"));
1571
1568
  },
1572
1569
  writeFile: async (file) => {
1573
- const fileRef2 = mapFileResourceToPrivate(file);
1570
+ const fileRef2 = mapFileResourceToPrivate(file, "writeFile");
1574
1571
  const fileRef3 = await fs.writeFile(fileRef2);
1575
- return mapFileReferenceToPublic(fileRef3);
1572
+ return mapFileReferenceToPublic(fileRef3, "writeFile");
1576
1573
  },
1577
1574
  providerInfo: {
1578
1575
  ...fs.providerInfo,
@@ -1583,6 +1580,22 @@ function remapFS(name, fs, shadowFs, publicRoot, privateRoot, options) {
1583
1580
  [Symbol.dispose]: dispose
1584
1581
  }, shadowFs, publicRoot);
1585
1582
  }
1583
+ /**
1584
+ * Map a URL under `fromRoot` to the same relative path under `toRoot`.
1585
+ * Throws if the URL is not under `fromRoot` or the result is not under `toRoot`.
1586
+ */
1587
+ function mapUrl(url, fromRoot, toRoot, request) {
1588
+ const unsupported = () => new VFSErrorUnsupportedRequest(request, url);
1589
+ if (!isUrlUnderRoot(url, fromRoot)) throw unsupported();
1590
+ const relativePath = url.pathname.slice(fromRoot.pathname.length);
1591
+ if (/^(?:[/\\]|%2f|%5c)/i.test(relativePath)) throw unsupported();
1592
+ const mapped = new URL("./" + relativePath, toRoot);
1593
+ if (!isUrlUnderRoot(mapped, toRoot)) throw unsupported();
1594
+ return mapped;
1595
+ }
1596
+ function isUrlUnderRoot(url, root) {
1597
+ return url.protocol === root.protocol && url.host === root.host && url.pathname.startsWith(root.pathname);
1598
+ }
1586
1599
  function fsPassThrough(fs, shadowFs, root) {
1587
1600
  function gfs(ur, name) {
1588
1601
  const url = urlOrReferenceToUrl(ur);
package/package.json CHANGED
@@ -1,19 +1,33 @@
1
1
  {
2
2
  "name": "cspell-io",
3
+ "version": "10.3.6",
4
+ "description": "A library of useful I/O functions used across various cspell tools.",
3
5
  "publishConfig": {
4
6
  "access": "public",
5
7
  "provenance": true
6
8
  },
7
- "version": "10.3.4",
8
- "description": "A library of useful I/O functions used across various cspell tools.",
9
- "type": "module",
9
+ "homepage": "https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-io#readme",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/streetsidesoftware/cspell.git",
13
+ "directory": "packages/cspell-io"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/streetsidesoftware/cspell/issues?q=is%3Aissue%20state%3Aopen%20label%3Acspell-io"
17
+ },
18
+ "keywords": [
19
+ "cspell"
20
+ ],
21
+ "license": "MIT",
22
+ "author": "Jason Dent",
10
23
  "sideEffects": false,
11
- "module": "dist/index.js",
24
+ "type": "module",
12
25
  "exports": {
13
26
  ".": {
14
27
  "import": "./dist/index.js"
15
28
  }
16
29
  },
30
+ "module": "dist/index.js",
17
31
  "files": [
18
32
  "dist",
19
33
  "!**/*.tsbuildInfo",
@@ -26,38 +40,24 @@
26
40
  "build": "tsdown && pnpm build:tsc",
27
41
  "build:tsc": "tsc -p .",
28
42
  "build:watch": "tsdown --watch",
29
- "watch": "pnpm build:watch",
30
43
  "clean": "shx rm -rf dist temp coverage \"*.tsbuildInfo\"",
31
44
  "clean-build": "pnpm run clean && pnpm run build",
32
45
  "coverage": "vitest run --coverage --pool=forks",
46
+ "test": "vitest run --pool=forks",
33
47
  "test-watch": "vitest",
34
- "test": "vitest run --pool=forks"
48
+ "watch": "pnpm build:watch"
35
49
  },
36
- "repository": {
37
- "type": "git",
38
- "url": "https://github.com/streetsidesoftware/cspell.git",
39
- "directory": "packages/cspell-io"
40
- },
41
- "keywords": [
42
- "cspell"
43
- ],
44
- "author": "Jason Dent",
45
- "license": "MIT",
46
- "bugs": {
47
- "url": "https://github.com/streetsidesoftware/cspell/labels/cspell-io"
48
- },
49
- "homepage": "https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-io#readme",
50
- "engines": {
51
- "node": ">=22.18.0"
50
+ "dependencies": {
51
+ "@cspell/cspell-service-bus": "10.3.6",
52
+ "@cspell/url": "10.3.6"
52
53
  },
53
54
  "devDependencies": {
54
55
  "lorem-ipsum": "^3.0.0",
55
56
  "typescript": "~6.0.3",
56
57
  "vitest-fetch-mock": "^0.4.5"
57
58
  },
58
- "dependencies": {
59
- "@cspell/cspell-service-bus": "10.3.4",
60
- "@cspell/url": "10.3.4"
59
+ "engines": {
60
+ "node": ">=22.18.0"
61
61
  },
62
- "gitHead": "7bb5c4750ece7c732edbf920c0cea910d9b4d717"
62
+ "gitHead": "8559198ccfcac2f745911db1ffe2ee62c17cba49"
63
63
  }