Skip to content
This repository has been archived by the owner on Nov 5, 2021. It is now read-only.

Commit

Permalink
Use the global monaco only in the AMD case (see microsoft/monaco-ed…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Sep 7, 2020
1 parent d089cc2 commit 1a46d23
Show file tree
Hide file tree
Showing 15 changed files with 370 additions and 250 deletions.
28 changes: 8 additions & 20 deletions src/monaco.d.ts → monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

declare module monaco.languages.html {
/// <reference path="node_modules/monaco-editor-core/monaco.d.ts" />

declare namespace monaco.languages.html {
export interface HTMLFormatConfiguration {
readonly tabSize: number;
readonly insertSpaces: boolean;
Expand All @@ -22,11 +24,9 @@ declare module monaco.languages.html {
| 'force-aligned'
| 'force-expand-multiline';
}

export interface CompletionConfiguration {
[provider: string]: boolean;
}

export interface Options {
/**
* If set, comments are tolerated. If set to false, syntax errors will be emitted for comments.
Expand All @@ -37,76 +37,64 @@ declare module monaco.languages.html {
*/
readonly suggest?: CompletionConfiguration;
}

export interface ModeConfiguration {
/**
* Defines whether the built-in completionItemProvider is enabled.
*/
readonly completionItems?: boolean;

/**
* Defines whether the built-in hoverProvider is enabled.
*/
readonly hovers?: boolean;

/**
* Defines whether the built-in documentSymbolProvider is enabled.
*/
readonly documentSymbols?: boolean;

/**
* Defines whether the built-in definitions provider is enabled.
*/
readonly links?: boolean;

/**
* Defines whether the built-in references provider is enabled.
*/
readonly documentHighlights?: boolean;

/**
* Defines whether the built-in rename provider is enabled.
*/
readonly rename?: boolean;

/**
* Defines whether the built-in color provider is enabled.
*/
readonly colors?: boolean;

/**
* Defines whether the built-in foldingRange provider is enabled.
*/
readonly foldingRanges?: boolean;

/**
* Defines whether the built-in diagnostic provider is enabled.
*/
readonly diagnostics?: boolean;

/**
* Defines whether the built-in selection range provider is enabled.
*/
readonly selectionRanges?: boolean;

/**
* Defines whether the built-in documentFormattingEdit provider is enabled.
*/
readonly documentFormattingEdits?: boolean;

/**
* Defines whether the built-in documentRangeFormattingEdit provider is enabled.
*/
readonly documentRangeFormattingEdits?: boolean;
}

export interface LanguageServiceDefaults {
readonly languageId: string;
readonly modeConfiguration: ModeConfiguration;
readonly onDidChange: IEvent<LanguageServiceDefaults>;
readonly options: Options;
setOptions(options: Options): void;
}

export var htmlDefaults: LanguageServiceDefaults;
export var handlebarDefaults: LanguageServiceDefaults;
export var razorDefaults: LanguageServiceDefaults;
export const htmlDefaults: LanguageServiceDefaults;
export const handlebarDefaults: LanguageServiceDefaults;
export const razorDefaults: LanguageServiceDefaults;
}
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "2.7.0",
"description": "HTML plugin for the Monaco Editor",
"scripts": {
"compile": "mrmdir ./out && tsc -p ./src/tsconfig.json && tsc -p ./src/tsconfig.esm.json",
"compile": "mrmdir ./out && tsc -p ./src/tsconfig.json && tsc -p ./src/tsconfig.esm.json && node ./scripts/dts && prettier --write ./monaco.d.ts",
"watch": "tsc -p ./src --watch",
"prepublishOnly": "mrmdir ./release && npm run compile && node ./scripts/release.js && node ./scripts/bundle && mcopy ./src/monaco.d.ts ./release/monaco.d.ts",
"prepublishOnly": "mrmdir ./release && npm run compile && node ./scripts/release.js && node ./scripts/bundle && mcopy ./monaco.d.ts ./release/monaco.d.ts && mcopy ./out/esm/monaco.contribution.d.ts ./release/esm/monaco.contribution.d.ts && mcopy ./out/esm/fillers/monaco-editor-core.d.ts ./release/esm/fillers/monaco-editor-core.d.ts",
"install-service-next": "npm install vscode-html-languageservice@next -f -D && npm install vscode-languageserver-types@next -f -D",
"install-service-local": "npm install ../vscode-html-languageservice -f -D && npm install ../vscode-languageserver-node/types -f -D",
"prettier": "prettier --write ."
Expand All @@ -19,16 +19,18 @@
"bugs": {
"url": "https://github.com/Microsoft/monaco-editor/issues"
},
"module": "./release/esm/monaco.contribution.js",
"typings": "./release/esm/monaco.contribution.d.ts",
"devDependencies": {
"husky": "^4.2.5",
"husky": "^4.3.0",
"monaco-editor-core": "0.20.0",
"monaco-languages": "^1.10.0",
"monaco-plugin-helpers": "^1.0.2",
"monaco-plugin-helpers": "^1.0.3",
"prettier": "^2.1.1",
"pretty-quick": "^3.0.0",
"requirejs": "^2.3.6",
"typescript": "^3.7.5",
"terser": "^4.6.3",
"typescript": "^4.0.2",
"terser": "^5.3.0",
"vscode-html-languageservice": "3.0.4-next.12",
"vscode-languageserver-types": "3.15.0-next.9",
"vscode-languageserver-textdocument": "^1.0.0-next.5"
Expand Down
12 changes: 7 additions & 5 deletions scripts/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const BUNDLED_FILE_HEADER = [
].join('\n');

bundleOne('monaco.contribution');
bundleOne('htmlMode');
bundleOne('htmlMode', ['vs/language/html/monaco.contribution']);
bundleOne('htmlWorker');

function bundleOne(moduleId, exclude) {
Expand All @@ -32,7 +32,9 @@ function bundleOne(moduleId, exclude) {
out: 'release/dev/' + moduleId + '.js',
exclude: exclude,
paths: {
'vs/language/html': REPO_ROOT + '/out/amd'
'vs/language/html': REPO_ROOT + '/out/amd',
'vs/language/html/fillers/monaco-editor-core':
REPO_ROOT + '/out/amd/fillers/monaco-editor-core-amd'
},
optimize: 'none',
packages: [
Expand Down Expand Up @@ -72,7 +74,7 @@ function bundleOne(moduleId, exclude) {
}
]
},
function (buildResponse) {
async function (buildResponse) {
const devFilePath = path.join(
REPO_ROOT,
'release/dev/' + moduleId + '.js'
Expand All @@ -84,12 +86,12 @@ function bundleOne(moduleId, exclude) {
const fileContents = fs.readFileSync(devFilePath).toString();
console.log();
console.log(`Minifying ${devFilePath}...`);
const result = terser.minify(fileContents, {
const result = await terser.minify(fileContents, {
output: {
comments: 'some'
}
});
console.log(`Done.`);
console.log(`Done minifying ${devFilePath}.`);
try {
fs.mkdirSync(path.join(REPO_ROOT, 'release/min'));
} catch (err) {}
Expand Down
41 changes: 41 additions & 0 deletions scripts/dts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

const path = require('path');
const fs = require('fs');

const REPO_ROOT = path.join(__dirname, '../');
const SRC_PATH = path.join(REPO_ROOT, 'out/amd/monaco.contribution.d.ts');
const DST_PATH = path.join(REPO_ROOT, 'monaco.d.ts');

const lines = fs
.readFileSync(SRC_PATH)
.toString()
.split(/\r\n|\r|\n/);
let result = [
`/*---------------------------------------------------------------------------------------------`,
` * Copyright (c) Microsoft Corporation. All rights reserved.`,
` * Licensed under the MIT License. See License.txt in the project root for license information.`,
` *--------------------------------------------------------------------------------------------*/`,
``,
`/// <reference path="node_modules/monaco-editor-core/monaco.d.ts" />`,
``,
`declare namespace monaco.languages.html {`
];
for (let line of lines) {
if (/^import/.test(line)) {
continue;
}
line = line.replace(/ /g, '\t');
line = line.replace(/export declare/g, 'export');
if (line.length > 0) {
line = `\t${line}`;
result.push(line);
}
}
result.push(`}`);
result.push(``);

fs.writeFileSync(DST_PATH, result.join('\n'));
12 changes: 12 additions & 0 deletions src/fillers/monaco-editor-core-amd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// Resolves with the global monaco API

declare var define;

define([], function () {
return (<any>self).monaco;
});
3 changes: 2 additions & 1 deletion src/typings/refs.d.ts → src/fillers/monaco-editor-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/// <reference path='../../node_modules/monaco-editor-core/monaco.d.ts'/>

export * from 'monaco-editor-core';
1 change: 0 additions & 1 deletion src/html.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';

import * as worker from 'monaco-editor-core/esm/vs/editor/editor.worker';
import { HTMLWorker } from './htmlWorker';
Expand Down
Loading

0 comments on commit 1a46d23

Please sign in to comment.