jsonnext / codemirror-json-schema

A JSONSchema enabled mode for codemirror 6, for json4 and json5, inspired by monaco-json
https://codemirror-json-schema.netlify.app
MIT License
56 stars 9 forks source link

export YAML functionalities #107

Open vharny opened 1 month ago

vharny commented 1 month ago

Hello,

Thank you for this library, I am really interested in validation / autocompletion JSON Schema YAML.

Currently in the package the functionalities concerning the JSON Schema for YAML are not exported.

Is there a reason why this has not yet been done?

imolorhe commented 1 month ago

The library already exports the validation and autocompletion options for YAML. You can access them via the/yaml path. You can see how it's used in the example in the repo.

vharny commented 1 month ago

With the version 0.7.3

Screenshot 2024-05-31 at 17 44 15 Screenshot 2024-05-31 at 17 45 13

I think the YAML methods are not correctly exported :/

vharny commented 1 month ago

It's probably a typescript problem with moduleResolution in the tsconfig but for an Angular 17 project for example the moduleResolution is node.

vharny commented 1 month ago

In my Angular project, if I want the import to work, I have to set the moduleResolution to Bundler. I never have any problems with other libraries that have imports with a /

Cannot find module 'codemirror-json-schema/yaml' or its corresponding type declarations. There are types at '[...]/node_modules/codemirror-json-schema/dist/yaml/index.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.ts(2307)

acao commented 1 month ago

Yes I plan to take a look at and fix this this weekend!

acao commented 1 month ago

@vharny can you let me know if 0.7.5 works for you? it should match everything else in the cm6 ecosystem now in terms of bundling

vharny commented 1 month ago

Hello @acao, Thanks for you quick response!

Sorry, it doesn't work :/ This is my tsconfig file:

{
  "compileOnSave": false,
  "compilerOptions": {
    "downlevelIteration": true,
    "incremental": true,
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "resolveJsonModule": true,
    "allowSyntheticDefaultImports": true,
    "target": "ES2022",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2020",
      "dom"
    ],
    "module": "esnext",
    "baseUrl": "./src",
    "useDefineForClassFields": false
  }
}
vharny commented 1 month ago

It works when I define paths in the tsconfig file:

"compilerOptions": {
  "baseUrl": "./src",
  ...
  "paths": {
        "codemirror-json-schema/yaml": ["../node_modules/codemirror-json-schema/dist/yaml"],
        ...
   }
 }