istextorbinary icon indicating copy to clipboard operation
istextorbinary copied to clipboard

Can't set edition

Open phil294 opened this issue 1 year ago • 6 comments

I'm developing a VSCode extension, this means CJS Node v18.

Running without any build step normally with const xyz = require('istextorbinary') works fine.

But when building with esbuild and running the resulting bundle, I get

editions-autoloader-package: Unable to determine a suitable edition for the package [/home/phi/b/search++/package.json] and entry [index.js] ↪editions-autoloader-editions-missing: No editions were specified.

so I thought it had to do with the exotic setup, so I changed it to require('istextorbinary/edition-es2022') instead. But this also doesn't work (at all):

Package subpath './edition-es2022' is not defined by "exports" in /home/phi/b/search++/node_modules/istextorbinary/package.json.

Well yes... it is, said file includes

"exports": {
  "node": {
    "require": "./edition-es2022/index.js"
    ...

I'm not familiar with neither npm's exports nor your editions tool, but something's not right here.

I also tried require('istextorbinary/require') but that yields the same output error (and the import is shown as invalid by tsserver).

So I went ahead and just deleted the entire "exports" section from your package.json locally. Now the sub-import works, but with ESBuild, the same error as before. The autoloader fails to determine a suitable edition. This makes no sense yet again, as I have already specified one, why is it still doing that?

And what do I do?

phil294 avatar Jun 18 '24 18:06 phil294

Change your require or import statement to whichever entry in the editions section of the readme that you wish to require: https://github.com/bevry/istextorbinary#Editions

eg. require('istextorbinary/edition-es2022/index.js')

balupton avatar Jun 18 '24 19:06 balupton

I did that, this doesn't work as described. The extra /index.js doesn't change anything :/

phil294 avatar Jun 18 '24 19:06 phil294

In fact, this is the require chain in my esbuild output:

var { isBinary } = require_edition_es2022();

in there, there's a

var textextensions_1 = __importDefault(require_textextensions());

which has a

module2.exports = require_edition_es52().requirePackage(...)

which runs the solicitEdition and fails. So I guess the problem is that textextensions doesn't inherit the selected edition?

Edit: Indeed, I have changed the requires inside isextorbinary/edition-es2022/index.js to

const textextensions_1 = __importDefault(require("textextensions/edition-es2022/index.js"));
// same for binaryextensions

and removed the exports fields from textextensions and binaryextensions... now it works in all scenarios. Pretty crazy workaround though

phil294 avatar Jun 18 '24 19:06 phil294

And again, getting this far is only possible because I have removed the exports field from your package.json, without doing that it already fails at

Package subpath './edition-es2022/index.js' is not defined by "exports"

so this seems like two separate problems to me

phil294 avatar Jun 18 '24 19:06 phil294

Hrmm, yeah, seems then specifying which edition you want depends upon loader support, which CI coverage is for Node.js's loader and direct URL/path support (Deno, Browsers, etc). So this seems to be an issue with the bundler/loader of VSCode. Or could be that the module specs have changed once again...

Perhaps the best way to workaround this, besides your hack in the OP. Is to update https://github.com/bevry/boundation to generate npm scripts and github actions to publish npm version tags for each edition, where it is the only edition in the bundle. Eg. textextensions@es2022 — this would also allow nested dep overrides.

The ideal resolution of course would be if the bundlers and loaders adopt/support the editions spec, as the Editions spec is superior, as detailed on https://github.com/bevry/editions

Might be best to continue here: https://github.com/bevry/editions/issues/24

balupton avatar Jun 19 '24 05:06 balupton

While bundling with ESBuild works with the above hacks, packaging with npx vsce package doesn't because

 ERROR  Error occurred while scanning secrets (files): TypeError: textExtensions.indexOf is not a function
    at isText (file:///b/s/node_modules/istextorbinary/edition-es2017-esm/index.js:21:32)
    at isBinary (file:///b/s/node_modules/istextorbinary/edition-es2017-esm/index.js:46:18)
    at detectContentType (file:///b/s/node_modules/@secretlint/source-creator/module/index.js:5:9)
    at createRawSource (file:///b/s/node_modules/@secretlint/source-creator/module/index.js:17:25)
    at async lintFile (file:///b/s/node_modules/@secretlint/node/module/index.js:15:23)
    at async mapper (file:///b/s/node_modules/@secretlint/node/module/index.js:63:24)
    at async file:///b/s/node_modules/@secretlint/node/node_modules/p-map/index.js:121:20

What's even crazier, even after removing with npm uninstall istextorbinary, the error persists, and

npm ls istextorbinary
[email protected] /b/s
└─┬ [email protected]
  └─┬ @vscode/[email protected]
    └─┬ @secretlint/[email protected]
      └─┬ @secretlint/[email protected]
           [email protected]

as if it's a subdependency of vsce itself?!

Seems like your package and/or the Editions production scheme isn't compatible with other tooling?

Hrmm, yeah, seems then specifying which edition you want depends upon loader support, which CI coverage is for Node.js's loader and direct URL/path support (Deno, Browsers, etc). So this seems to be an issue with the bundler/loader of VSCode. Or could be that the module specs have changed once again...

The previous errors haven't been about VSCode. It's been plain ESBuild / CJS / Node.

The ideal resolution of course would be if the bundlers and loaders adopt/support the editions spec, as the Editions spec is superior, as detailed on https://github.com/bevry/editions

You can't be serious.

Perhaps the best way to workaround this, besides your hack in the OP. Is to update https://github.com/bevry/boundation to generate npm scripts and github actions to publish npm version tags for each edition, where it is the only edition in the bundle. Eg. textextensions@es2022 — this would also allow nested dep overrides.

I'm not sure, what does this mean to me? What do I do?

phil294 avatar Nov 03 '25 02:11 phil294