From 30fd97533f1b73529438401eff2f4837b77b7e10 Mon Sep 17 00:00:00 2001
From: Egor Gorbachev <egor@magicsandbox.com>
Date: Thu, 19 Sep 2019 16:50:20 +0200
Subject: [PATCH] Fix the code to generate a proper ESM output

---
 package.json               | 7 ++++++-
 scripts/bundle-esm.js      | 2 +-
 src/monaco.contribution.ts | 9 +++------
 src/yaml.worker.ts         | 2 +-
 yarn.lock                  | 7 ++++++-
 5 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/package.json b/package.json
index 1560d0d..7a22c9f 100644
--- a/package.json
+++ b/package.json
@@ -34,12 +34,17 @@
   "bugs": {
     "url": "https://github.com/pengx17/monaco-yaml/issues"
   },
+  "dependencies": {
+    "js-yaml": "3.12.0"
+  },
+  "peerDependencies": {
+    "monaco-editor": "^0.16.2"
+  },
   "devDependencies": {
     "@types/jest": "^23.3.10",
     "@types/node": "^10.9.3",
     "husky": "^1.2.1",
     "jest": "^23.6.0",
-    "js-yaml": "^3.12.0",
     "jsonc-parser": "^2.0.2",
     "lint-staged": "^8.1.0",
     "monaco-editor-core": "0.15.5",
diff --git a/scripts/bundle-esm.js b/scripts/bundle-esm.js
index 19e42f1..0469db4 100644
--- a/scripts/bundle-esm.js
+++ b/scripts/bundle-esm.js
@@ -16,7 +16,7 @@ helpers.packageESM({
   resolveAlias: {
     "vscode-nls": path.join(REPO_ROOT, "out/esm/fillers/vscode-nls.js")
   },
-  resolveSkip: ["monaco-editor-core", "js-yaml"],
+  resolveSkip: ["monaco-editor", "monaco-editor-core", "js-yaml"],
   destinationFolderSimplification: {
     node_modules: "_deps",
     "jsonc-parser/lib/esm": "jsonc-parser",
diff --git a/src/monaco.contribution.ts b/src/monaco.contribution.ts
index 56fa44d..ccecedf 100644
--- a/src/monaco.contribution.ts
+++ b/src/monaco.contribution.ts
@@ -4,7 +4,7 @@
  *--------------------------------------------------------------------------------------------*/
 'use strict';
 
-import * as mode from './yamlMode';
+import { setupMode } from './yamlMode';
 
 import Emitter = monaco.Emitter;
 import IEvent = monaco.IEvent;
@@ -70,16 +70,13 @@ monaco.languages.yaml = createAPI();
 
 // --- Registration to monaco editor ---
 
-function withMode(callback: (module: typeof mode) => void): void {
-  require<typeof mode>(['vs/language/yaml/yamlMode'], callback);
-}
-
 monaco.languages.register({
   id: 'yaml',
   extensions: ['.yaml', '.yml'],
   aliases: ['YAML', 'yaml', 'YML', 'yml'],
   mimetypes: ['application/x-yaml'],
 });
+
 monaco.languages.onLanguage('yaml', () => {
-  withMode(mode => mode.setupMode(yamlDefaults));
+  setupMode(yamlDefaults);
 });
diff --git a/src/yaml.worker.ts b/src/yaml.worker.ts
index a964c85..06c5559 100644
--- a/src/yaml.worker.ts
+++ b/src/yaml.worker.ts
@@ -4,7 +4,7 @@
  *--------------------------------------------------------------------------------------------*/
 'use strict';
 
-import * as worker from 'monaco-editor-core/esm/vs/editor/editor.worker';
+import * as worker from 'monaco-editor/esm/vs/editor/editor.worker';
 import { YAMLWorker } from './yamlWorker';
 
 self.onmessage = () => {
diff --git a/yarn.lock b/yarn.lock
index 7486c91..648dc7b 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2341,7 +2341,7 @@ js-tokens@^3.0.2:
   resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
   integrity sha1-mGbfOVECEw449/mWvOtlRDIJwls=
 
-js-yaml@^3.12.0, js-yaml@^3.7.0, js-yaml@^3.9.0:
+js-yaml@3.12.0, js-yaml@^3.12.0, js-yaml@^3.7.0, js-yaml@^3.9.0:
   version "3.12.0"
   resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.12.0.tgz#eaed656ec8344f10f527c6bfa1b6e2244de167d1"
   dependencies:
@@ -2811,6 +2811,11 @@ monaco-editor-core@0.15.5:
   resolved "https://registry.yarnpkg.com/monaco-editor-core/-/monaco-editor-core-0.15.5.tgz#145f1953a8e319282d92502252d68ef3486b6875"
   integrity sha512-kM3KHRjj16cFdK5Z0EppKUu793JVMpsEesBSWlqdgrxcmjyDMXV6xK0oatPcAYp3eOfbbyjPhruxDXj85FKyIg==
 
+monaco-editor@^0.16.2:
+  version "0.16.2"
+  resolved "https://registry.yarnpkg.com/monaco-editor/-/monaco-editor-0.16.2.tgz#950084ed82eeaef1c8c9d3c1bcab849fe11b2415"
+  integrity sha512-NtGrFzf54jADe7qsWh3lazhS7Kj0XHkJUGBq9fA/Jbwc+sgVcyfsYF6z2AQ7hPqDC+JmdOt/OwFjBnRwqXtx6w==
+
 monaco-languages@1.6.0:
   version "1.6.0"
   resolved "https://registry.yarnpkg.com/monaco-languages/-/monaco-languages-1.6.0.tgz#54ec5510b31f3132939014f171ade235e84ef0bc"