rolldown-plugin-require-cjs 0.0.0 → 0.1.0

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/README.md CHANGED
@@ -18,6 +18,21 @@ See more: https://x.com/sanxiaozhizi/status/1968580207322808812
18
18
  npm i rolldown-plugin-require-cjs
19
19
  ```
20
20
 
21
+ ## Example
22
+
23
+ ```ts
24
+ RequireCJS({
25
+ shouldTransform(id, importer) {
26
+ // Force transformation for specific dependencies
27
+ if (id === 'typescript') return true
28
+ // Skip transformation for specific dependencies
29
+ if (id === 'esm-only') return false
30
+ // Auto-detect for other dependencies
31
+ return undefined
32
+ },
33
+ })
34
+ ```
35
+
21
36
  ## Sponsors
22
37
 
23
38
  <p align="center">
package/dist/index.d.ts CHANGED
@@ -16,7 +16,7 @@ interface Options {
16
16
  * @param importer The module ID (path) of the importer.
17
17
  * @returns A boolean or a promise that resolves to a boolean, or `undefined`.
18
18
  */
19
- shouldTransform?: (id: string, importer: string) => Awaitable<boolean | undefined>;
19
+ shouldTransform?: (id: string, importer: string) => Awaitable<boolean | undefined | void>;
20
20
  }
21
21
  type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
22
22
  type OptionsResolved = Overwrite<Required<Options>, Pick<Options, "order" | "shouldTransform">>;
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { readFile } from "node:fs/promises";
3
+ import path from "node:path";
3
4
  import { init, parse } from "cjs-module-lexer";
4
5
  import { up } from "empathic/package";
5
6
  import { MagicStringAST, generateTransform } from "magic-string-ast";
@@ -7794,14 +7795,14 @@ function asyncifyLoadSync(asyncify, buffer, imports) {
7794
7795
  function isPosixPathSeparator(code) {
7795
7796
  return code === CHAR_FORWARD_SLASH;
7796
7797
  }
7797
- function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
7798
+ function normalizeString(path$1, allowAboveRoot, separator, isPathSeparator) {
7798
7799
  let res = "";
7799
7800
  let lastSegmentLength = 0;
7800
7801
  let lastSlash = -1;
7801
7802
  let dots = 0;
7802
7803
  let code = 0;
7803
- for (let i = 0; i <= path.length; ++i) {
7804
- if (i < path.length) code = path.charCodeAt(i);
7804
+ for (let i = 0; i <= path$1.length; ++i) {
7805
+ if (i < path$1.length) code = path$1.charCodeAt(i);
7805
7806
  else if (isPathSeparator(code)) break;
7806
7807
  else code = CHAR_FORWARD_SLASH;
7807
7808
  if (isPathSeparator(code)) {
@@ -7833,8 +7834,8 @@ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
7833
7834
  lastSegmentLength = 2;
7834
7835
  }
7835
7836
  } else {
7836
- if (res.length > 0) res += `${separator}${path.slice(lastSlash + 1, i)}`;
7837
- else res = path.slice(lastSlash + 1, i);
7837
+ if (res.length > 0) res += `${separator}${path$1.slice(lastSlash + 1, i)}`;
7838
+ else res = path$1.slice(lastSlash + 1, i);
7838
7839
  lastSegmentLength = i - lastSlash - 1;
7839
7840
  }
7840
7841
  lastSlash = i;
@@ -7848,11 +7849,11 @@ function resolve(...args) {
7848
7849
  let resolvedPath = "";
7849
7850
  let resolvedAbsolute = false;
7850
7851
  for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
7851
- const path = i >= 0 ? args[i] : "/";
7852
- validateString(path, "path");
7853
- if (path.length === 0) continue;
7854
- resolvedPath = `${path}/${resolvedPath}`;
7855
- resolvedAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
7852
+ const path$1 = i >= 0 ? args[i] : "/";
7853
+ validateString(path$1, "path");
7854
+ if (path$1.length === 0) continue;
7855
+ resolvedPath = `${path$1}/${resolvedPath}`;
7856
+ resolvedAbsolute = path$1.charCodeAt(0) === CHAR_FORWARD_SLASH;
7856
7857
  }
7857
7858
  resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, "/", isPosixPathSeparator);
7858
7859
  if (resolvedAbsolute) return `/${resolvedPath}`;
@@ -8136,8 +8137,8 @@ function syscallWrap(self$1, name, f) {
8136
8137
  return tryCall(f, self$1, arguments);
8137
8138
  });
8138
8139
  }
8139
- function resolvePathSync$1(fs$1, fileDescriptor, path, flags) {
8140
- let resolvedPath = resolve(fileDescriptor.realPath, path);
8140
+ function resolvePathSync$1(fs$1, fileDescriptor, path$1, flags) {
8141
+ let resolvedPath = resolve(fileDescriptor.realPath, path$1);
8141
8142
  if ((flags & 1) === 1) try {
8142
8143
  resolvedPath = fs$1.readlinkSync(resolvedPath);
8143
8144
  } catch (err) {
@@ -8145,8 +8146,8 @@ function resolvePathSync$1(fs$1, fileDescriptor, path, flags) {
8145
8146
  }
8146
8147
  return resolvedPath;
8147
8148
  }
8148
- async function resolvePathAsync(fs$1, fileDescriptor, path, flags) {
8149
- let resolvedPath = resolve(fileDescriptor.realPath, path);
8149
+ async function resolvePathAsync(fs$1, fileDescriptor, path$1, flags) {
8150
+ let resolvedPath = resolve(fileDescriptor.realPath, path$1);
8150
8151
  if ((flags & 1) === 1) try {
8151
8152
  resolvedPath = await fs$1.promises.readlink(resolvedPath);
8152
8153
  } catch (err) {
@@ -8437,10 +8438,10 @@ var init_wasm_util_esm_bundler = __esm({ "../../node_modules/.pnpm/@tybys+wasm-u
8437
8438
  TTY_BASE = WasiRights.FD_READ | WasiRights.FD_FDSTAT_SET_FLAGS | WasiRights.FD_WRITE | WasiRights.FD_FILESTAT_GET | WasiRights.POLL_FD_READWRITE;
8438
8439
  TTY_INHERITING = /* @__PURE__ */ BigInt(0);
8439
8440
  FileDescriptor = class {
8440
- constructor(id, fd, path, realPath, type, rightsBase, rightsInheriting, preopen) {
8441
+ constructor(id, fd, path$1, realPath, type, rightsBase, rightsInheriting, preopen) {
8441
8442
  this.id = id;
8442
8443
  this.fd = fd;
8443
- this.path = path;
8444
+ this.path = path$1;
8444
8445
  this.realPath = realPath;
8445
8446
  this.type = type;
8446
8447
  this.rightsBase = rightsBase;
@@ -8458,8 +8459,8 @@ var init_wasm_util_esm_bundler = __esm({ "../../node_modules/.pnpm/@tybys+wasm-u
8458
8459
  }
8459
8460
  };
8460
8461
  StandardOutput = class extends FileDescriptor {
8461
- constructor(log, id, fd, path, realPath, type, rightsBase, rightsInheriting, preopen) {
8462
- super(id, fd, path, realPath, type, rightsBase, rightsInheriting, preopen);
8462
+ constructor(log, id, fd, path$1, realPath, type, rightsBase, rightsInheriting, preopen) {
8463
+ super(id, fd, path$1, realPath, type, rightsBase, rightsInheriting, preopen);
8463
8464
  this._log = log;
8464
8465
  this._buf = null;
8465
8466
  }
@@ -8779,16 +8780,16 @@ var init_wasm_util_esm_bundler = __esm({ "../../node_modules/.pnpm/@tybys+wasm-u
8779
8780
  view.setUint32(prestat + 4, encoder.encode(fileDescriptor.path).length, true);
8780
8781
  return 0;
8781
8782
  });
8782
- this.fd_prestat_dir_name = syscallWrap(this, "fd_prestat_dir_name", function(fd, path, path_len) {
8783
- path = Number(path);
8783
+ this.fd_prestat_dir_name = syscallWrap(this, "fd_prestat_dir_name", function(fd, path$1, path_len) {
8784
+ path$1 = Number(path$1);
8784
8785
  path_len = Number(path_len);
8785
- if (path === 0) return 28;
8786
+ if (path$1 === 0) return 28;
8786
8787
  const fileDescriptor = _wasi.get(this).fds.get(fd, BigInt(0), BigInt(0));
8787
8788
  if (fileDescriptor.preopen !== 1) return 8;
8788
8789
  const buffer = encoder.encode(fileDescriptor.path);
8789
8790
  if (buffer.length > path_len) return 42;
8790
8791
  const { HEAPU8 } = getMemory(this);
8791
- HEAPU8.set(buffer, path);
8792
+ HEAPU8.set(buffer, path$1);
8792
8793
  return 0;
8793
8794
  });
8794
8795
  this.fd_seek = syscallWrap(this, "fd_seek", function(fd, offset, whence, newOffset) {
@@ -9363,23 +9364,23 @@ var init_wasm_util_esm_bundler = __esm({ "../../node_modules/.pnpm/@tybys+wasm-u
9363
9364
  "i32",
9364
9365
  "i32"
9365
9366
  ], ["i32"]);
9366
- defineImport("path_create_directory", function path_create_directory(fd, path, path_len) {
9367
- path = Number(path);
9367
+ defineImport("path_create_directory", function path_create_directory(fd, path$1, path_len) {
9368
+ path$1 = Number(path$1);
9368
9369
  path_len = Number(path_len);
9369
- if (path === 0) return 28;
9370
+ if (path$1 === 0) return 28;
9370
9371
  const { HEAPU8 } = getMemory(this);
9371
9372
  const fileDescriptor = _wasi.get(this).fds.get(fd, WasiRights.PATH_CREATE_DIRECTORY, BigInt(0));
9372
- let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
9373
+ let pathString = decoder.decode(unsharedSlice(HEAPU8, path$1, path$1 + path_len));
9373
9374
  pathString = resolve(fileDescriptor.realPath, pathString);
9374
9375
  getFs(this).mkdirSync(pathString);
9375
9376
  return 0;
9376
- }, async function path_create_directory(fd, path, path_len) {
9377
- path = Number(path);
9377
+ }, async function path_create_directory(fd, path$1, path_len) {
9378
+ path$1 = Number(path$1);
9378
9379
  path_len = Number(path_len);
9379
- if (path === 0) return 28;
9380
+ if (path$1 === 0) return 28;
9380
9381
  const { HEAPU8 } = getMemory(this);
9381
9382
  const fileDescriptor = _wasi.get(this).fds.get(fd, WasiRights.PATH_CREATE_DIRECTORY, BigInt(0));
9382
- let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
9383
+ let pathString = decoder.decode(unsharedSlice(HEAPU8, path$1, path$1 + path_len));
9383
9384
  pathString = resolve(fileDescriptor.realPath, pathString);
9384
9385
  await getFs(this).promises.mkdir(pathString);
9385
9386
  return 0;
@@ -9388,14 +9389,14 @@ var init_wasm_util_esm_bundler = __esm({ "../../node_modules/.pnpm/@tybys+wasm-u
9388
9389
  "i32",
9389
9390
  "i32"
9390
9391
  ], ["i32"]);
9391
- defineImport("path_filestat_get", function path_filestat_get(fd, flags, path, path_len, filestat) {
9392
- path = Number(path);
9392
+ defineImport("path_filestat_get", function path_filestat_get(fd, flags, path$1, path_len, filestat) {
9393
+ path$1 = Number(path$1);
9393
9394
  path_len = Number(path_len);
9394
9395
  filestat = Number(filestat);
9395
- if (path === 0 || filestat === 0) return 28;
9396
+ if (path$1 === 0 || filestat === 0) return 28;
9396
9397
  const { HEAPU8, view } = getMemory(this);
9397
9398
  const fileDescriptor = _wasi.get(this).fds.get(fd, WasiRights.PATH_FILESTAT_GET, BigInt(0));
9398
- let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
9399
+ let pathString = decoder.decode(unsharedSlice(HEAPU8, path$1, path$1 + path_len));
9399
9400
  const fs$2 = getFs(this);
9400
9401
  pathString = resolve(fileDescriptor.realPath, pathString);
9401
9402
  let stat;
@@ -9403,14 +9404,14 @@ var init_wasm_util_esm_bundler = __esm({ "../../node_modules/.pnpm/@tybys+wasm-u
9403
9404
  else stat = fs$2.lstatSync(pathString, { bigint: true });
9404
9405
  toFileStat(view, filestat, stat);
9405
9406
  return 0;
9406
- }, async function path_filestat_get(fd, flags, path, path_len, filestat) {
9407
- path = Number(path);
9407
+ }, async function path_filestat_get(fd, flags, path$1, path_len, filestat) {
9408
+ path$1 = Number(path$1);
9408
9409
  path_len = Number(path_len);
9409
9410
  filestat = Number(filestat);
9410
- if (path === 0 || filestat === 0) return 28;
9411
+ if (path$1 === 0 || filestat === 0) return 28;
9411
9412
  const { HEAPU8, view } = getMemory(this);
9412
9413
  const fileDescriptor = _wasi.get(this).fds.get(fd, WasiRights.PATH_FILESTAT_GET, BigInt(0));
9413
- let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
9414
+ let pathString = decoder.decode(unsharedSlice(HEAPU8, path$1, path$1 + path_len));
9414
9415
  const fs$2 = getFs(this);
9415
9416
  pathString = resolve(fileDescriptor.realPath, pathString);
9416
9417
  let stat;
@@ -9425,28 +9426,28 @@ var init_wasm_util_esm_bundler = __esm({ "../../node_modules/.pnpm/@tybys+wasm-u
9425
9426
  "i32",
9426
9427
  "i32"
9427
9428
  ], ["i32"]);
9428
- defineImport("path_filestat_set_times", function path_filestat_set_times(fd, flags, path, path_len, atim, mtim, fst_flags) {
9429
- path = Number(path);
9429
+ defineImport("path_filestat_set_times", function path_filestat_set_times(fd, flags, path$1, path_len, atim, mtim, fst_flags) {
9430
+ path$1 = Number(path$1);
9430
9431
  path_len = Number(path_len);
9431
- if (path === 0) return 28;
9432
+ if (path$1 === 0) return 28;
9432
9433
  const { HEAPU8 } = getMemory(this);
9433
9434
  const fileDescriptor = _wasi.get(this).fds.get(fd, WasiRights.PATH_FILESTAT_SET_TIMES, BigInt(0));
9434
9435
  if (validateFstFlagsOrReturn(fst_flags)) return 28;
9435
9436
  const fs$2 = getFs(this);
9436
- const resolvedPath = resolvePathSync$1(fs$2, fileDescriptor, decoder.decode(unsharedSlice(HEAPU8, path, path + path_len)), flags);
9437
+ const resolvedPath = resolvePathSync$1(fs$2, fileDescriptor, decoder.decode(unsharedSlice(HEAPU8, path$1, path$1 + path_len)), flags);
9437
9438
  if ((fst_flags & 2) === 2) atim = BigInt(Date.now() * 1e6);
9438
9439
  if ((fst_flags & 8) === 8) mtim = BigInt(Date.now() * 1e6);
9439
9440
  fs$2.utimesSync(resolvedPath, Number(atim), Number(mtim));
9440
9441
  return 0;
9441
- }, async function path_filestat_set_times(fd, flags, path, path_len, atim, mtim, fst_flags) {
9442
- path = Number(path);
9442
+ }, async function path_filestat_set_times(fd, flags, path$1, path_len, atim, mtim, fst_flags) {
9443
+ path$1 = Number(path$1);
9443
9444
  path_len = Number(path_len);
9444
- if (path === 0) return 28;
9445
+ if (path$1 === 0) return 28;
9445
9446
  const { HEAPU8 } = getMemory(this);
9446
9447
  const fileDescriptor = _wasi.get(this).fds.get(fd, WasiRights.PATH_FILESTAT_SET_TIMES, BigInt(0));
9447
9448
  if (validateFstFlagsOrReturn(fst_flags)) return 28;
9448
9449
  const fs$2 = getFs(this);
9449
- const resolvedPath = await resolvePathAsync(fs$2, fileDescriptor, decoder.decode(unsharedSlice(HEAPU8, path, path + path_len)), flags);
9450
+ const resolvedPath = await resolvePathAsync(fs$2, fileDescriptor, decoder.decode(unsharedSlice(HEAPU8, path$1, path$1 + path_len)), flags);
9450
9451
  if ((fst_flags & 2) === 2) atim = BigInt(Date.now() * 1e6);
9451
9452
  if ((fst_flags & 8) === 8) mtim = BigInt(Date.now() * 1e6);
9452
9453
  await fs$2.promises.utimes(resolvedPath, Number(atim), Number(mtim));
@@ -9543,10 +9544,10 @@ var init_wasm_util_esm_bundler = __esm({ "../../node_modules/.pnpm/@tybys+wasm-u
9543
9544
  needed_inheriting
9544
9545
  };
9545
9546
  }
9546
- defineImport("path_open", function path_open(dirfd, dirflags, path, path_len, o_flags, fs_rights_base, fs_rights_inheriting, fs_flags, fd) {
9547
- path = Number(path);
9547
+ defineImport("path_open", function path_open(dirfd, dirflags, path$1, path_len, o_flags, fs_rights_base, fs_rights_inheriting, fs_flags, fd) {
9548
+ path$1 = Number(path$1);
9548
9549
  fd = Number(fd);
9549
- if (path === 0 || fd === 0) return 28;
9550
+ if (path$1 === 0 || fd === 0) return 28;
9550
9551
  path_len = Number(path_len);
9551
9552
  fs_rights_base = BigInt(fs_rights_base);
9552
9553
  fs_rights_inheriting = BigInt(fs_rights_inheriting);
@@ -9555,7 +9556,7 @@ var init_wasm_util_esm_bundler = __esm({ "../../node_modules/.pnpm/@tybys+wasm-u
9555
9556
  const fileDescriptor = wasi.fds.get(dirfd, neededBase, neededInheriting);
9556
9557
  const memory = getMemory(this);
9557
9558
  const HEAPU8 = memory.HEAPU8;
9558
- const pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
9559
+ const pathString = decoder.decode(unsharedSlice(HEAPU8, path$1, path$1 + path_len));
9559
9560
  const fs$2 = getFs(this);
9560
9561
  const resolved_path = resolvePathSync$1(fs$2, fileDescriptor, pathString, dirflags);
9561
9562
  const r = fs$2.openSync(resolved_path, flagsRes, 438);
@@ -9570,10 +9571,10 @@ var init_wasm_util_esm_bundler = __esm({ "../../node_modules/.pnpm/@tybys+wasm-u
9570
9571
  }
9571
9572
  memory.view.setInt32(fd, wrap$2.id, true);
9572
9573
  return 0;
9573
- }, async function path_open(dirfd, dirflags, path, path_len, o_flags, fs_rights_base, fs_rights_inheriting, fs_flags, fd) {
9574
- path = Number(path);
9574
+ }, async function path_open(dirfd, dirflags, path$1, path_len, o_flags, fs_rights_base, fs_rights_inheriting, fs_flags, fd) {
9575
+ path$1 = Number(path$1);
9575
9576
  fd = Number(fd);
9576
- if (path === 0 || fd === 0) return 28;
9577
+ if (path$1 === 0 || fd === 0) return 28;
9577
9578
  path_len = Number(path_len);
9578
9579
  fs_rights_base = BigInt(fs_rights_base);
9579
9580
  fs_rights_inheriting = BigInt(fs_rights_inheriting);
@@ -9582,7 +9583,7 @@ var init_wasm_util_esm_bundler = __esm({ "../../node_modules/.pnpm/@tybys+wasm-u
9582
9583
  const fileDescriptor = wasi.fds.get(dirfd, neededBase, neededInheriting);
9583
9584
  const memory = getMemory(this);
9584
9585
  const HEAPU8 = memory.HEAPU8;
9585
- const pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
9586
+ const pathString = decoder.decode(unsharedSlice(HEAPU8, path$1, path$1 + path_len));
9586
9587
  const fs$2 = getFs(this);
9587
9588
  const resolved_path = await resolvePathAsync(fs$2, fileDescriptor, pathString, dirflags);
9588
9589
  const r = await fs$2.promises.open(resolved_path, flagsRes, 438);
@@ -9608,16 +9609,16 @@ var init_wasm_util_esm_bundler = __esm({ "../../node_modules/.pnpm/@tybys+wasm-u
9608
9609
  "i32",
9609
9610
  "i32"
9610
9611
  ], ["i32"]);
9611
- defineImport("path_readlink", function path_readlink(fd, path, path_len, buf, buf_len, bufused) {
9612
- path = Number(path);
9612
+ defineImport("path_readlink", function path_readlink(fd, path$1, path_len, buf, buf_len, bufused) {
9613
+ path$1 = Number(path$1);
9613
9614
  path_len = Number(path_len);
9614
9615
  buf = Number(buf);
9615
9616
  buf_len = Number(buf_len);
9616
9617
  bufused = Number(bufused);
9617
- if (path === 0 || buf === 0 || bufused === 0) return 28;
9618
+ if (path$1 === 0 || buf === 0 || bufused === 0) return 28;
9618
9619
  const { HEAPU8, view } = getMemory(this);
9619
9620
  const fileDescriptor = _wasi.get(this).fds.get(fd, WasiRights.PATH_READLINK, BigInt(0));
9620
- let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
9621
+ let pathString = decoder.decode(unsharedSlice(HEAPU8, path$1, path$1 + path_len));
9621
9622
  pathString = resolve(fileDescriptor.realPath, pathString);
9622
9623
  const link = getFs(this).readlinkSync(pathString);
9623
9624
  const linkData = encoder.encode(link);
@@ -9627,16 +9628,16 @@ var init_wasm_util_esm_bundler = __esm({ "../../node_modules/.pnpm/@tybys+wasm-u
9627
9628
  HEAPU8[buf + len] = 0;
9628
9629
  view.setUint32(bufused, len, true);
9629
9630
  return 0;
9630
- }, async function path_readlink(fd, path, path_len, buf, buf_len, bufused) {
9631
- path = Number(path);
9631
+ }, async function path_readlink(fd, path$1, path_len, buf, buf_len, bufused) {
9632
+ path$1 = Number(path$1);
9632
9633
  path_len = Number(path_len);
9633
9634
  buf = Number(buf);
9634
9635
  buf_len = Number(buf_len);
9635
9636
  bufused = Number(bufused);
9636
- if (path === 0 || buf === 0 || bufused === 0) return 28;
9637
+ if (path$1 === 0 || buf === 0 || bufused === 0) return 28;
9637
9638
  const { HEAPU8, view } = getMemory(this);
9638
9639
  const fileDescriptor = _wasi.get(this).fds.get(fd, WasiRights.PATH_READLINK, BigInt(0));
9639
- let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
9640
+ let pathString = decoder.decode(unsharedSlice(HEAPU8, path$1, path$1 + path_len));
9640
9641
  pathString = resolve(fileDescriptor.realPath, pathString);
9641
9642
  const link = await getFs(this).promises.readlink(pathString);
9642
9643
  const linkData = encoder.encode(link);
@@ -9654,23 +9655,23 @@ var init_wasm_util_esm_bundler = __esm({ "../../node_modules/.pnpm/@tybys+wasm-u
9654
9655
  "i32",
9655
9656
  "i32"
9656
9657
  ], ["i32"]);
9657
- defineImport("path_remove_directory", function path_remove_directory(fd, path, path_len) {
9658
- path = Number(path);
9658
+ defineImport("path_remove_directory", function path_remove_directory(fd, path$1, path_len) {
9659
+ path$1 = Number(path$1);
9659
9660
  path_len = Number(path_len);
9660
- if (path === 0) return 28;
9661
+ if (path$1 === 0) return 28;
9661
9662
  const { HEAPU8 } = getMemory(this);
9662
9663
  const fileDescriptor = _wasi.get(this).fds.get(fd, WasiRights.PATH_REMOVE_DIRECTORY, BigInt(0));
9663
- let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
9664
+ let pathString = decoder.decode(unsharedSlice(HEAPU8, path$1, path$1 + path_len));
9664
9665
  pathString = resolve(fileDescriptor.realPath, pathString);
9665
9666
  getFs(this).rmdirSync(pathString);
9666
9667
  return 0;
9667
- }, async function path_remove_directory(fd, path, path_len) {
9668
- path = Number(path);
9668
+ }, async function path_remove_directory(fd, path$1, path_len) {
9669
+ path$1 = Number(path$1);
9669
9670
  path_len = Number(path_len);
9670
- if (path === 0) return 28;
9671
+ if (path$1 === 0) return 28;
9671
9672
  const { HEAPU8 } = getMemory(this);
9672
9673
  const fileDescriptor = _wasi.get(this).fds.get(fd, WasiRights.PATH_REMOVE_DIRECTORY, BigInt(0));
9673
- let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
9674
+ let pathString = decoder.decode(unsharedSlice(HEAPU8, path$1, path$1 + path_len));
9674
9675
  pathString = resolve(fileDescriptor.realPath, pathString);
9675
9676
  await getFs(this).promises.rmdir(pathString);
9676
9677
  return 0;
@@ -9759,23 +9760,23 @@ var init_wasm_util_esm_bundler = __esm({ "../../node_modules/.pnpm/@tybys+wasm-u
9759
9760
  "i32",
9760
9761
  "i32"
9761
9762
  ], ["i32"]);
9762
- defineImport("path_unlink_file", function path_unlink_file(fd, path, path_len) {
9763
- path = Number(path);
9763
+ defineImport("path_unlink_file", function path_unlink_file(fd, path$1, path_len) {
9764
+ path$1 = Number(path$1);
9764
9765
  path_len = Number(path_len);
9765
- if (path === 0) return 28;
9766
+ if (path$1 === 0) return 28;
9766
9767
  const { HEAPU8 } = getMemory(this);
9767
9768
  const fileDescriptor = _wasi.get(this).fds.get(fd, WasiRights.PATH_UNLINK_FILE, BigInt(0));
9768
- let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
9769
+ let pathString = decoder.decode(unsharedSlice(HEAPU8, path$1, path$1 + path_len));
9769
9770
  pathString = resolve(fileDescriptor.realPath, pathString);
9770
9771
  getFs(this).unlinkSync(pathString);
9771
9772
  return 0;
9772
- }, async function path_unlink_file(fd, path, path_len) {
9773
- path = Number(path);
9773
+ }, async function path_unlink_file(fd, path$1, path_len) {
9774
+ path$1 = Number(path$1);
9774
9775
  path_len = Number(path_len);
9775
- if (path === 0) return 28;
9776
+ if (path$1 === 0) return 28;
9776
9777
  const { HEAPU8 } = getMemory(this);
9777
9778
  const fileDescriptor = _wasi.get(this).fds.get(fd, WasiRights.PATH_UNLINK_FILE, BigInt(0));
9778
- let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
9779
+ let pathString = decoder.decode(unsharedSlice(HEAPU8, path$1, path$1 + path_len));
9779
9780
  pathString = resolve(fileDescriptor.realPath, pathString);
9780
9781
  await getFs(this).promises.unlink(pathString);
9781
9782
  return 0;
@@ -10863,7 +10864,7 @@ function parseAst(sourceText, options, filename) {
10863
10864
  function resolveOptions(options) {
10864
10865
  return {
10865
10866
  include: options.include || [/\.[cm]?[jt]sx?$/],
10866
- exclude: options.exclude || [/node_modules/],
10867
+ exclude: options.exclude || [/node_modules/, /\.d\.[cm]?ts$/],
10867
10868
  order: "order" in options ? options.order : "pre",
10868
10869
  shouldTransform: options.shouldTransform
10869
10870
  };
@@ -10872,7 +10873,7 @@ function resolveOptions(options) {
10872
10873
  //#endregion
10873
10874
  //#region src/index.ts
10874
10875
  function RequireCJS(userOptions = {}) {
10875
- const { include, exclude, order, shouldTransform: dependencies } = resolveOptions(userOptions);
10876
+ const { include, exclude, order, shouldTransform } = resolveOptions(userOptions);
10876
10877
  return {
10877
10878
  name: "rolldown-plugin-require-cjs",
10878
10879
  async buildStart() {
@@ -10892,13 +10893,13 @@ function RequireCJS(userOptions = {}) {
10892
10893
  } },
10893
10894
  order,
10894
10895
  async handler(code, id) {
10895
- const { body } = parseAst(code, {}, id);
10896
+ const { body } = parseAst(code, { lang: void 0 }, id);
10896
10897
  const s = new MagicStringAST(code);
10897
10898
  for (const stmt of body) if (stmt.type === "ImportDeclaration") {
10898
10899
  const source = stmt.source.value;
10899
10900
  const resolution = await this.resolve(source, id);
10900
10901
  if (resolution && resolution.external === false) continue;
10901
- if (!(await dependencies?.(source, id) ?? await isPureCJS(source, id))) continue;
10902
+ if (!(await shouldTransform?.(source, id) ?? await isPureCJS(source, id))) continue;
10902
10903
  if (stmt.specifiers.length === 0) s.overwriteNode(stmt, `require(${s.sliceNode(stmt.source)});`);
10903
10904
  else {
10904
10905
  const mapping = {};
@@ -10921,7 +10922,7 @@ async function isPureCJS(id, importer) {
10921
10922
  try {
10922
10923
  const importResolved = resolvePathSync(id, { url: importer });
10923
10924
  const requireResolved = __require$1.resolve(id, { paths: [importer] });
10924
- if (importResolved !== requireResolved) return false;
10925
+ if (path.resolve(importResolved) !== path.resolve(requireResolved)) return false;
10925
10926
  if (importResolved.endsWith(".cjs")) return true;
10926
10927
  else if (importResolved.endsWith(".js")) {
10927
10928
  const pkgJsonPath = up({ cwd: importResolved });
@@ -10939,8 +10940,8 @@ async function isPureCJS(id, importer) {
10939
10940
  } catch {}
10940
10941
  return false;
10941
10942
  }
10942
- async function getPackageType(path) {
10943
- const contents = await readFile(path, "utf8");
10943
+ async function getPackageType(path$1) {
10944
+ const contents = await readFile(path$1, "utf8");
10944
10945
  try {
10945
10946
  return JSON.parse(contents).type;
10946
10947
  } catch {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-plugin-require-cjs",
3
- "version": "0.0.0",
3
+ "version": "0.1.0",
4
4
  "description": "Transform ESM imports to CJS requires when the imported module is pure CJS.",
5
5
  "type": "module",
6
6
  "license": "MIT",