mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 15:05:39 +01:00
Merge pull request #57 from orta/bundle_libs
Ensure that the default es2015 libraries include dom, webworker, and scripthost
This commit is contained in:
commit
61a0941817
11 changed files with 34622 additions and 24929 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
|
@ -11,4 +11,6 @@ jobs:
|
|||
with:
|
||||
node-version: '10.x'
|
||||
- run: npm install
|
||||
- run: npm run import-typescript
|
||||
- run: npm run compile
|
||||
- run: npm run prepublishOnly
|
||||
|
|
|
|||
6
package-lock.json
generated
6
package-lock.json
generated
|
|
@ -79,9 +79,9 @@
|
|||
}
|
||||
},
|
||||
"typescript": {
|
||||
"version": "3.7.5",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.5.tgz",
|
||||
"integrity": "sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw==",
|
||||
"version": "3.8.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz",
|
||||
"integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,6 @@
|
|||
"monaco-plugin-helpers": "^1.0.2",
|
||||
"requirejs": "^2.3.6",
|
||||
"terser": "^4.6.3",
|
||||
"typescript": "^3.7.5"
|
||||
"typescript": "^3.8.2"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,11 @@ const path = require('path');
|
|||
const fs = require('fs');
|
||||
const child_process = require('child_process');
|
||||
|
||||
const generatedNote = `//
|
||||
// **NOTE**: Do not edit directly! This file is generated using \`npm run import-typescript\`
|
||||
//
|
||||
`;
|
||||
|
||||
const TYPESCRIPT_LIB_SOURCE = path.join(__dirname, '../node_modules/typescript/lib');
|
||||
const TYPESCRIPT_LIB_DESTINATION = path.join(__dirname, '../src/lib');
|
||||
|
||||
|
|
@ -23,7 +28,8 @@ const TYPESCRIPT_LIB_DESTINATION = path.join(__dirname, '../src/lib');
|
|||
|
||||
fs.writeFileSync(
|
||||
path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServicesMetadata.ts'),
|
||||
`export const typescriptVersion = "${typeScriptDependencyVersion}";\n`
|
||||
`${generatedNote}
|
||||
export const typescriptVersion = "${typeScriptDependencyVersion}";\n`
|
||||
);
|
||||
|
||||
var tsServices = fs.readFileSync(path.join(TYPESCRIPT_LIB_SOURCE, 'typescriptServices.js')).toString();
|
||||
|
|
@ -57,7 +63,7 @@ const TYPESCRIPT_LIB_DESTINATION = path.join(__dirname, '../src/lib');
|
|||
const afterProcess = `// MONACOCHANGE\n ts.perfLogger.logInfoEvent("Starting TypeScript v" + ts.versionMajorMinor + " with command line: " + JSON.stringify([]));\n// END MONACOCHANGE`
|
||||
tsServices = tsServices.replace(beforeProcess, afterProcess);
|
||||
|
||||
var tsServices_amd = tsServices +
|
||||
var tsServices_amd = generatedNote + tsServices +
|
||||
`
|
||||
// MONACOCHANGE
|
||||
// Defining the entire module name because r.js has an issue and cannot bundle this file
|
||||
|
|
@ -67,7 +73,7 @@ define("vs/language/typescript/lib/typescriptServices", [], function() { return
|
|||
`;
|
||||
fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServices-amd.js'), tsServices_amd);
|
||||
|
||||
var tsServices_esm = tsServices +
|
||||
var tsServices_esm = generatedNote + tsServices +
|
||||
`
|
||||
// MONACOCHANGE
|
||||
export var createClassifier = ts.createClassifier;
|
||||
|
|
@ -90,7 +96,7 @@ export var TokenClass = ts.TokenClass;
|
|||
export = ts;
|
||||
// END MONACOCHANGE
|
||||
`;
|
||||
fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServices.d.ts'), dtsServices);
|
||||
fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServices.d.ts'), generatedNote + dtsServices);
|
||||
|
||||
})();
|
||||
|
||||
|
|
@ -164,7 +170,7 @@ function importLibs() {
|
|||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
`;
|
||||
${generatedNote}`;
|
||||
// Do a topological sort
|
||||
while (result.length > 0) {
|
||||
for (let i = result.length - 1; i >= 0; i--) {
|
||||
|
|
@ -189,6 +195,14 @@ function importLibs() {
|
|||
}
|
||||
}
|
||||
|
||||
strResult += `
|
||||
/** This is the DTS which is used when the target is ES6 or below */
|
||||
export const lib_es5_bundled_dts = lib_dts;
|
||||
|
||||
/** This is the DTS which is used by default in monaco-typescript, and when the target is 2015 or above */
|
||||
export const lib_es2015_bundled_dts = lib_es2015_dts + "" + lib_dom_dts + "" + lib_webworker_importscripts_dts + "" + lib_scripthost_dts + "";
|
||||
`
|
||||
|
||||
var dstPath = path.join(TYPESCRIPT_LIB_DESTINATION, 'lib.ts');
|
||||
fs.writeFileSync(dstPath, strResult);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -691,7 +691,7 @@ export class FormatOnTypeAdapter extends FormatHelper implements monaco.language
|
|||
|
||||
export class CodeActionAdaptor extends FormatHelper implements monaco.languages.CodeActionProvider {
|
||||
|
||||
public async provideCodeActions(model: monaco.editor.ITextModel, range: Range, context: monaco.languages.CodeActionContext, token: CancellationToken): Promise<monaco.languages.CodeActionList | undefined> {
|
||||
public async provideCodeActions(model: monaco.editor.ITextModel, range: Range, context: monaco.languages.CodeActionContext, token: CancellationToken): Promise<monaco.languages.CodeActionList> {
|
||||
const resource = model.uri;
|
||||
const start = model.getOffsetAt({ lineNumber: range.startLineNumber, column: range.startColumn });
|
||||
const end = model.getOffsetAt({ lineNumber: range.endLineNumber, column: range.endColumn });
|
||||
|
|
@ -701,7 +701,7 @@ export class CodeActionAdaptor extends FormatHelper implements monaco.languages.
|
|||
const codeFixes = await worker.getCodeFixesAtPosition(resource.toString(), start, end, errorCodes, formatOptions);
|
||||
|
||||
if (!codeFixes || model.isDisposed()) {
|
||||
return;
|
||||
return { actions: [], dispose:() => {} };
|
||||
}
|
||||
|
||||
const actions = codeFixes.filter(fix => {
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load diff
756
src/lib/typescriptServices.d.ts
vendored
756
src/lib/typescriptServices.d.ts
vendored
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1 +1,5 @@
|
|||
export const typescriptVersion = "3.7.5";
|
||||
//
|
||||
// **NOTE**: Do not edit directly! This file is generated using `npm run import-typescript`
|
||||
//
|
||||
|
||||
export const typescriptVersion = "3.8.3";
|
||||
|
|
|
|||
|
|
@ -5,19 +5,19 @@
|
|||
'use strict';
|
||||
|
||||
import * as ts from './lib/typescriptServices';
|
||||
import { lib_dts, lib_es2015_dts } from './lib/lib';
|
||||
import { lib_es5_dts, lib_es2015_bundled_dts } from './lib/lib';
|
||||
import { IExtraLibs } from './monaco.contribution';
|
||||
|
||||
import IWorkerContext = monaco.worker.IWorkerContext;
|
||||
|
||||
const DEFAULT_LIB = {
|
||||
const DEFAULT_ES5_LIB = {
|
||||
NAME: 'defaultLib:lib.d.ts',
|
||||
CONTENTS: lib_dts
|
||||
CONTENTS: lib_es5_dts
|
||||
};
|
||||
|
||||
const ES2015_LIB = {
|
||||
NAME: 'defaultLib:lib.es2015.d.ts',
|
||||
CONTENTS: lib_es2015_dts
|
||||
CONTENTS: lib_es2015_bundled_dts
|
||||
};
|
||||
|
||||
export class TypeScriptWorker implements ts.LanguageServiceHost, monaco.languages.typescript.TypeScriptWorker {
|
||||
|
|
@ -84,8 +84,8 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, monaco.language
|
|||
// extra lib
|
||||
text = this._extraLibs[fileName].content;
|
||||
|
||||
} else if (fileName === DEFAULT_LIB.NAME) {
|
||||
text = DEFAULT_LIB.CONTENTS;
|
||||
} else if (fileName === DEFAULT_ES5_LIB.NAME) {
|
||||
text = DEFAULT_ES5_LIB.CONTENTS;
|
||||
} else if (fileName === ES2015_LIB.NAME) {
|
||||
text = ES2015_LIB.CONTENTS;
|
||||
} else {
|
||||
|
|
@ -127,7 +127,7 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, monaco.language
|
|||
|
||||
getDefaultLibFileName(options: ts.CompilerOptions): string {
|
||||
// TODO@joh support lib.es7.d.ts
|
||||
return (options.target || ts.ScriptTarget.ES2015) <= ts.ScriptTarget.ES2015 ? DEFAULT_LIB.NAME : ES2015_LIB.NAME;
|
||||
return (options.target || ts.ScriptTarget.ES2015) < ts.ScriptTarget.ES2015 ? DEFAULT_ES5_LIB.NAME : ES2015_LIB.NAME;
|
||||
}
|
||||
|
||||
isDefaultLibFileName(fileName: string): boolean {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue