google / zx

A tool for writing better scripts
https://google.github.io/zx/
Apache License 2.0
42.28k stars 1.07k forks source link

YAML.parseAllDocuments is no longer accessible #863

Open Gabswim opened 1 week ago

Gabswim commented 1 week ago

Expected Behavior

https://stackblitz.com/edit/zx7-2-3-yaml?file=src/main.ts&terminal=dev

import { YAML } from 'zx'
YAML.parseAllDocuments() // this function is accessible

Actual Behavior

https://stackblitz.com/edit/zx-8-1-3-yaml?file=src/main.ts&terminal=dev

import { YAML } from 'zx'
YAML.parseAllDocuments() // this function is not accessible

Steps to Reproduce

  1. Update from 7.2.3 to 8.1.3.

Specifications

antongolub commented 1 week ago

This is related to TS case, right? 1) The issue can be fixed, but it will also add ~50Kb to dts libdefs. 2) If we'd like to replace the current YAML engine with another one (smaller, faster, etc), no chance that it will also provide support for parseDocument/parseAllDocuments

CC @antonmedv

antonmedv commented 1 week ago

This is because we bundle yaml?

antongolub commented 1 week ago

Because we've omitted the API typings except parse and stringify.

antonmedv commented 1 week ago

But the parseAllDocuments code is still in the bundle?

Gabswim commented 1 week ago

I have a workaround: installing the yaml library directly if the goal is to restrain the API to a smaller footprint.

But the parseAllDocuments code is still in the bundle?

Yes, so right now the typing is not showing the reality of what is being accessible. Maybe what you can do is something like this

import { parse, stringify } from 'yaml'

export const YAML = {
  parse,
  stringify
}
antongolub commented 1 week ago

But the parseAllDocuments code is still in the bundle?

Correct. In js bundle.

antonmedv commented 1 week ago

But why ts def grows so much?

antongolub commented 6 days ago

External contracts are derived from internal ones. There are actually many many types. https://www.npmjs.com/package/yaml?activeTab=code