cspell-io 10.3.5 → 10.4.0-alpha.1

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
@@ -1,5 +1,4 @@
1
1
  import { isFileURL, isUrlLike, toFileURL, toURL, urlBasename, urlParent as urlDirname } from "@cspell/url";
2
- import { Buffer } from "node:buffer";
3
2
  import { ServiceBus } from "@cspell/cspell-service-bus";
4
3
  //#region src/async/asyncIterable.d.ts
5
4
  /**
@@ -502,6 +501,9 @@ interface RedirectOptions {
502
501
  * Create a provider that will redirect requests from the publicRoot to the privateRoot.
503
502
  * This is useful for creating a virtual file system that is a subset of another file system.
504
503
  *
504
+ * A request under the publicRoot is only passed on if it maps to a URL under the privateRoot.
505
+ * Other requests are rejected with a `VFSErrorUnsupportedRequest`.
506
+ *
505
507
  * Example:
506
508
  * ```ts
507
509
  * const vfs = createVirtualFS();
package/dist/index.js CHANGED
@@ -108,15 +108,17 @@ function assert$1(value, message) {
108
108
  if (!value) throw new AssertionError(message ?? "Assertion failed");
109
109
  }
110
110
  //#endregion
111
+ //#region src/common/nodeBuffer.ts
112
+ function arrayBufferViewToBuffer(data) {
113
+ if (data instanceof Buffer) return data;
114
+ return Buffer.from(data.buffer, data.byteOffset, data.byteLength);
115
+ }
116
+ //#endregion
111
117
  //#region src/common/arrayBuffers.ts
112
118
  function toUint8Array(data) {
113
119
  if (data instanceof Uint8Array) return data;
114
120
  return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
115
121
  }
116
- function arrayBufferViewToBuffer(data) {
117
- if (data instanceof Buffer) return data;
118
- return Buffer.from(data.buffer, data.byteOffset, data.byteLength);
119
- }
120
122
  function copyArrayBufferView(data) {
121
123
  return new Uint8Array(data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength));
122
124
  }
@@ -1492,6 +1494,9 @@ var RedirectProvider = class {
1492
1494
  * Create a provider that will redirect requests from the publicRoot to the privateRoot.
1493
1495
  * This is useful for creating a virtual file system that is a subset of another file system.
1494
1496
  *
1497
+ * A request under the publicRoot is only passed on if it maps to a URL under the privateRoot.
1498
+ * Other requests are rejected with a `VFSErrorUnsupportedRequest`.
1499
+ *
1495
1500
  * Example:
1496
1501
  * ```ts
1497
1502
  * const vfs = createVirtualFS();
@@ -1524,31 +1529,25 @@ function createRedirectProvider(name, publicRoot, privateRoot, options) {
1524
1529
  */
1525
1530
  function remapFS(name, fs, shadowFs, publicRoot, privateRoot, options) {
1526
1531
  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));
1532
+ const mapToPrivate = (url, request) => mapUrl(url, publicRoot, privateRoot, request);
1533
+ const mapToPublic = (url, request) => mapUrl(url, privateRoot, publicRoot, request);
1534
+ const mapFileReferenceToPrivate = (ref, request) => {
1535
+ return renameFileReference(ref, mapToPrivate(ref.url, request));
1537
1536
  };
1538
- const mapFileReferenceToPublic = (ref) => {
1539
- return renameFileReference(ref, mapToPublic(ref.url));
1537
+ const mapFileReferenceToPublic = (ref, request) => {
1538
+ return renameFileReference(ref, mapToPublic(ref.url, request));
1540
1539
  };
1541
- const mapUrlOrReferenceToPrivate = (urlOrRef) => {
1542
- return urlOrRef instanceof URL ? mapToPrivate(urlOrRef) : mapFileReferenceToPrivate(urlOrRef);
1540
+ const mapUrlOrReferenceToPrivate = (urlOrRef, request) => {
1541
+ return urlOrRef instanceof URL ? mapToPrivate(urlOrRef, request) : mapFileReferenceToPrivate(urlOrRef, request);
1543
1542
  };
1544
- const mapFileResourceToPublic = (res) => {
1545
- return renameFileResource(res, mapToPublic(res.url));
1543
+ const mapFileResourceToPublic = (res, request) => {
1544
+ return renameFileResource(res, mapToPublic(res.url, request));
1546
1545
  };
1547
- const mapFileResourceToPrivate = (res) => {
1548
- return renameFileResource(res, mapToPrivate(res.url));
1546
+ const mapFileResourceToPrivate = (res, request) => {
1547
+ return renameFileResource(res, mapToPrivate(res.url, request));
1549
1548
  };
1550
- const mapDirEntryToPublic = (de) => {
1551
- const dir = mapToPublic(de.dir);
1549
+ const mapDirEntryToPublic = (de, request) => {
1550
+ const dir = mapToPublic(de.dir, request);
1552
1551
  return {
1553
1552
  ...de,
1554
1553
  dir
@@ -1557,22 +1556,22 @@ function remapFS(name, fs, shadowFs, publicRoot, privateRoot, options) {
1557
1556
  const dispose = () => fs.dispose();
1558
1557
  return fsPassThrough({
1559
1558
  stat: async (url) => {
1560
- const url2 = mapUrlOrReferenceToPrivate(url);
1559
+ const url2 = mapUrlOrReferenceToPrivate(url, "stat");
1561
1560
  return await fs.stat(url2);
1562
1561
  },
1563
1562
  readFile: async (url, options) => {
1564
- const url2 = mapUrlOrReferenceToPrivate(url);
1563
+ const url2 = mapUrlOrReferenceToPrivate(url, "readFile");
1565
1564
  const file = await fs.readFile(url2, options);
1566
- return mapFileResourceToPublic(file);
1565
+ return mapFileResourceToPublic(file, "readFile");
1567
1566
  },
1568
1567
  readDirectory: async (url) => {
1569
- const url2 = mapToPrivate(url);
1570
- return (await fs.readDirectory(url2)).map(mapDirEntryToPublic);
1568
+ const url2 = mapToPrivate(url, "readDirectory");
1569
+ return (await fs.readDirectory(url2)).map((de) => mapDirEntryToPublic(de, "readDirectory"));
1571
1570
  },
1572
1571
  writeFile: async (file) => {
1573
- const fileRef2 = mapFileResourceToPrivate(file);
1572
+ const fileRef2 = mapFileResourceToPrivate(file, "writeFile");
1574
1573
  const fileRef3 = await fs.writeFile(fileRef2);
1575
- return mapFileReferenceToPublic(fileRef3);
1574
+ return mapFileReferenceToPublic(fileRef3, "writeFile");
1576
1575
  },
1577
1576
  providerInfo: {
1578
1577
  ...fs.providerInfo,
@@ -1583,6 +1582,22 @@ function remapFS(name, fs, shadowFs, publicRoot, privateRoot, options) {
1583
1582
  [Symbol.dispose]: dispose
1584
1583
  }, shadowFs, publicRoot);
1585
1584
  }
1585
+ /**
1586
+ * Map a URL under `fromRoot` to the same relative path under `toRoot`.
1587
+ * Throws if the URL is not under `fromRoot` or the result is not under `toRoot`.
1588
+ */
1589
+ function mapUrl(url, fromRoot, toRoot, request) {
1590
+ const unsupported = () => new VFSErrorUnsupportedRequest(request, url);
1591
+ if (!isUrlUnderRoot(url, fromRoot)) throw unsupported();
1592
+ const relativePath = url.pathname.slice(fromRoot.pathname.length);
1593
+ if (/^(?:[/\\]|%2f|%5c)/i.test(relativePath)) throw unsupported();
1594
+ const mapped = new URL("./" + relativePath, toRoot);
1595
+ if (!isUrlUnderRoot(mapped, toRoot)) throw unsupported();
1596
+ return mapped;
1597
+ }
1598
+ function isUrlUnderRoot(url, root) {
1599
+ return url.protocol === root.protocol && url.host === root.host && url.pathname.startsWith(root.pathname);
1600
+ }
1586
1601
  function fsPassThrough(fs, shadowFs, root) {
1587
1602
  function gfs(ur, name) {
1588
1603
  const url = urlOrReferenceToUrl(ur);
package/package.json CHANGED
@@ -1,19 +1,33 @@
1
1
  {
2
2
  "name": "cspell-io",
3
+ "version": "10.4.0-alpha.1",
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.5",
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.4.0-alpha.1",
52
+ "@cspell/url": "10.4.0-alpha.1"
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.5",
60
- "@cspell/url": "10.3.5"
59
+ "engines": {
60
+ "node": ">=22.18.0"
61
61
  },
62
- "gitHead": "f37a244a54b686fc1ac11272d6019b9a059b062a"
62
+ "gitHead": "628768a6e62b792e628189b41e63e12e5d3d8fe3"
63
63
  }