Skip to content

Conversation

@brendankenny
Copy link
Contributor

part of #13231

adds structured warnings to inline-fs plugin. Type is a subset of the esbuild warning type, in case we ever want to move over to that :) More seriously, esbuild uses the location to do nice

fs.readFileSync(__filename, 'binary');
                            ^
Error: unsupported encoding
  at ...

logging, and we could maybe do the same if there's a nice library somewhere we could use, or we could just live with plain old filepath:line:column logging until we ever need something fancier.

All that's for later, though. This just keeps a list of encountered warnings.

Comment on lines +154 to +156
// @ts-expect-error - see https://github.com/acornjs/acorn/issues/946
return node;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a bit of noise that's mostly for the compiler, but the nice thing is that if/when acorn types are ever updated, the @ts-expect-error will throw type-check errors and hopefully it will be obvious this whole method can be dropped

return outputCode;
return {
code: outputCode,
warnings,
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it not awkward that warnings can be an empty array and missing? callers must then check for both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, probably. We could make it non-optional

return JSON.stringify(contents);
} catch (err) {
throw new Error(`could not inline fs.readdirSync call: ${err.message}`);
throw new Error(`could not inline fs.readdirSync contents: ${err.message}`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

could this error reference the node param?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it could but it's kind of a last ditch something broke check, so there's not much to say about it except the fs.readdirSync call failed, which it'll default to anyways. Explicit might be better, but it seems ok to rely on the default behavior since there's a lot of other possible thrown errors in here that also default to pointing to the fs.readdirSync as the culprit (e.g. the asserts, etc)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants