Skip to content

Conversation

@TheAlexLichter
Copy link
Contributor

Resolves #146

I've used tsdown as fast builder which will dual-build the library, generate .d.ts files, generates exports for the package.json and eventually runs publint.

Generated types were manually checked by me via attw

Copy link
Contributor

@SuperchupuDev SuperchupuDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a great size improvement!! it looks really good
image

however, fdir is currently compatible with at least node 12 (and probably even node 10 but i'm not sure i haven't checked), and this is currently breaking that compatibility due an import at the top of the file with the node: protocol

image

i've suggested a tiny config change that should ensure compatibility

@SuperchupuDev
Copy link
Contributor

SuperchupuDev commented May 28, 2025

it looks like removeNodeProtocol doesn't remove the node protocol import created by rolldown:runtime after testing manually by changing the config, breaking compatibility. let's hope tsdown fixes this quickly 🙏 i've opened a tsdown bug report rolldown/tsdown#276

Co-authored-by: Superchupu <53496941+SuperchupuDev@users.noreply.github.com>
@magic-akari
Copy link

however, fdir is currently compatible with at least node 12 (and probably even node 10 but i'm not sure i haven't checked), and this is currently breaking that compatibility due an import at the top of the file with the node: protocol

However, createRequire was added in node@12.2.0. Even if the node: protocol is removed, there would still be an API compatibility issue for versions below Node 12.2.0

@TheAlexLichter
Copy link
Contributor Author

Regarding node compat in general: There is no note in the docs (besides "any version") nor the engine field. This would be good to document 🤔

@SuperchupuDev
Copy link
Contributor

@TheAlexLichter tsdown 0.12.5 seems to have fixed the node: protocol issue, can you update the pr to use it?

@TheAlexLichter
Copy link
Contributor Author

@SuperchupuDev Done!

Copy link
Contributor

@SuperchupuDev SuperchupuDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something should probably be done for createRequire only being on node 12.2 and up and not 12.0.0, but i don't really think anyone is running strictly node 12.0.0. (also the fact that latest version started using a node 14 api breaking compat anyways). thank you!

@SuperchupuDev
Copy link
Contributor

wait, as much as i love pnpm you should probably remove the pnpm lockfile added in your last commit (i suppose by accident?) since this repo is configured to use npm

@TheAlexLichter
Copy link
Contributor Author

wait, as much as i love pnpm you should probably remove the pnpm lockfile added in your last commit (i suppose by accident?) since this repo is configured to use npm

Sorry, yes by accident. Muscle memory was too strong here :D

@TheAlexLichter TheAlexLichter force-pushed the build/dual-publishing branch from e201b78 to 3a80f5f Compare May 31, 2025 21:18
@sxzz
Copy link
Contributor

sxzz commented Jun 2, 2025

After building with tsdown dual format, the import time for fdir decreased from 9~10 ms to ~6 ms.

Co-Authored-By: sxzz <sxzz@sxzz.moe>
@SuperchupuDev
Copy link
Contributor

@thecodrr do you mind taking a look at this and releasing a new version afterwards? (which would include a fix in main that hasn't been released yet) 🙏

@TheAlexLichter TheAlexLichter requested a review from thecodrr June 11, 2025 17:03
Co-authored-by: Superchupu <53496941+SuperchupuDev@users.noreply.github.com>
@TheAlexLichter
Copy link
Contributor Author

@thecodrr Hey! 👋 Is there anything missing or something that is blocking the PR?

@SuperchupuDev
Copy link
Contributor

it looks like tsdown's usage of createRequire won't affect compatibility, as the very old node versions that support esm but not createRequire (node 12.0 and 12.1, back when esm was flagged) will use the cjs version anyways (the exports field wasn't a thing back then) 👍

unrelated, do you mind setting the engines.node field to >=12.0.0 instead of using the tsdown target field? tsdown can read from it plus it also resolves #116

i've just locally tested node 10-12 in main and 12 is definitely the minimum version as everything else below breaks due to class initialization stuff

@thecodrr
Copy link
Owner

thecodrr commented Jul 7, 2025

This is ready for merge. I think the engines.node field should be set in a separate PR.

@thecodrr thecodrr merged commit e7d6042 into thecodrr:master Jul 7, 2025
8 checks passed
@TheAlexLichter TheAlexLichter deleted the build/dual-publishing branch July 7, 2025 09:57
@Jason3S
Copy link

Jason3S commented Aug 19, 2025

I'm seeing an issue when fdir@6.5.0 is bundled using esbuild.

Generated code:

// ../../../../node_modules/.pnpm/fdir@6.5.0_picomatch@4.0.3/node_modules/fdir/dist/index.mjs
var import_module = require("module");
var import_path2 = require("path");
var nativeFs = __toESM(require("fs"), 1);
var import_meta2 = {};
var __require = /* @__PURE__ */ (0, import_module.createRequire)(import_meta2.url);
function cleanPath(path14) {
  let normalized = (0, import_path2.normalize)(path14);
  if (normalized.length > 1 && normalized[normalized.length - 1] === import_path2.sep) normalized = normalized.substring(0, normalized.length - 1);
  return normalized;
}

error:

node:internal/modules/cjs/loader:1895
    throw new ERR_INVALID_ARG_VALUE('filename', filename, createRequireError);
          ^

TypeError [ERR_INVALID_ARG_VALUE]: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received undefined
    at createRequire (node:internal/modules/cjs/loader:1895:11)
    at Object.<anonymous> (/Users/jason/projects/cspell/test-packages/cspell/test-cspell-esbuild-cjs/bin/dist/index.cjs:42093:65)
    at Module._compile (node:internal/modules/cjs/loader:1692:14)
    at Object..js (node:internal/modules/cjs/loader:1824:10)
    at Module.load (node:internal/modules/cjs/loader:1427:32)
    at Module._load (node:internal/modules/cjs/loader:1250:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
    at Module.require (node:internal/modules/cjs/loader:1449:12)
    at require (node:internal/modules/helpers:135:16) {
  code: 'ERR_INVALID_ARG_VALUE'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dual Publishing / ESM support

6 participants