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

Commit 61a0941

Browse files
authored
Merge pull request #57 from orta/bundle_libs
Ensure that the default es2015 libraries include dom, webworker, and scripthost
2 parents 6d49c51 + 35454d8 commit 61a0941

File tree

11 files changed

+40670
-30977
lines changed

11 files changed

+40670
-30977
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ jobs:
1111
with:
1212
node-version: '10.x'
1313
- run: npm install
14+
- run: npm run import-typescript
1415
- run: npm run compile
16+
- run: npm run prepublishOnly

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
"monaco-plugin-helpers": "^1.0.2",
2626
"requirejs": "^2.3.6",
2727
"terser": "^4.6.3",
28-
"typescript": "^3.7.5"
28+
"typescript": "^3.8.2"
2929
}
3030
}

scripts/importTypescript.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ const path = require('path');
77
const fs = require('fs');
88
const child_process = require('child_process');
99

10+
const generatedNote = `//
11+
// **NOTE**: Do not edit directly! This file is generated using \`npm run import-typescript\`
12+
//
13+
`;
14+
1015
const TYPESCRIPT_LIB_SOURCE = path.join(__dirname, '../node_modules/typescript/lib');
1116
const TYPESCRIPT_LIB_DESTINATION = path.join(__dirname, '../src/lib');
1217

@@ -23,7 +28,8 @@ const TYPESCRIPT_LIB_DESTINATION = path.join(__dirname, '../src/lib');
2328

2429
fs.writeFileSync(
2530
path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServicesMetadata.ts'),
26-
`export const typescriptVersion = "${typeScriptDependencyVersion}";\n`
31+
`${generatedNote}
32+
export const typescriptVersion = "${typeScriptDependencyVersion}";\n`
2733
);
2834

2935
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');
5763
const afterProcess = `// MONACOCHANGE\n ts.perfLogger.logInfoEvent("Starting TypeScript v" + ts.versionMajorMinor + " with command line: " + JSON.stringify([]));\n// END MONACOCHANGE`
5864
tsServices = tsServices.replace(beforeProcess, afterProcess);
5965

60-
var tsServices_amd = tsServices +
66+
var tsServices_amd = generatedNote + tsServices +
6167
`
6268
// MONACOCHANGE
6369
// 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
6773
`;
6874
fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServices-amd.js'), tsServices_amd);
6975

70-
var tsServices_esm = tsServices +
76+
var tsServices_esm = generatedNote + tsServices +
7177
`
7278
// MONACOCHANGE
7379
export var createClassifier = ts.createClassifier;
@@ -90,7 +96,7 @@ export var TokenClass = ts.TokenClass;
9096
export = ts;
9197
// END MONACOCHANGE
9298
`;
93-
fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServices.d.ts'), dtsServices);
99+
fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServices.d.ts'), generatedNote + dtsServices);
94100

95101
})();
96102

@@ -164,7 +170,7 @@ function importLibs() {
164170
* Copyright (c) Microsoft Corporation. All rights reserved.
165171
* Licensed under the MIT License. See License.txt in the project root for license information.
166172
*--------------------------------------------------------------------------------------------*/
167-
`;
173+
${generatedNote}`;
168174
// Do a topological sort
169175
while (result.length > 0) {
170176
for (let i = result.length - 1; i >= 0; i--) {
@@ -189,6 +195,14 @@ function importLibs() {
189195
}
190196
}
191197

198+
strResult += `
199+
/** This is the DTS which is used when the target is ES6 or below */
200+
export const lib_es5_bundled_dts = lib_dts;
201+
202+
/** This is the DTS which is used by default in monaco-typescript, and when the target is 2015 or above */
203+
export const lib_es2015_bundled_dts = lib_es2015_dts + "" + lib_dom_dts + "" + lib_webworker_importscripts_dts + "" + lib_scripthost_dts + "";
204+
`
205+
192206
var dstPath = path.join(TYPESCRIPT_LIB_DESTINATION, 'lib.ts');
193207
fs.writeFileSync(dstPath, strResult);
194208
}

src/languageFeatures.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ export class FormatOnTypeAdapter extends FormatHelper implements monaco.language
691691

692692
export class CodeActionAdaptor extends FormatHelper implements monaco.languages.CodeActionProvider {
693693

694-
public async provideCodeActions(model: monaco.editor.ITextModel, range: Range, context: monaco.languages.CodeActionContext, token: CancellationToken): Promise<monaco.languages.CodeActionList | undefined> {
694+
public async provideCodeActions(model: monaco.editor.ITextModel, range: Range, context: monaco.languages.CodeActionContext, token: CancellationToken): Promise<monaco.languages.CodeActionList> {
695695
const resource = model.uri;
696696
const start = model.getOffsetAt({ lineNumber: range.startLineNumber, column: range.startColumn });
697697
const end = model.getOffsetAt({ lineNumber: range.endLineNumber, column: range.endColumn });
@@ -701,7 +701,7 @@ export class CodeActionAdaptor extends FormatHelper implements monaco.languages.
701701
const codeFixes = await worker.getCodeFixesAtPosition(resource.toString(), start, end, errorCodes, formatOptions);
702702

703703
if (!codeFixes || model.isDisposed()) {
704-
return;
704+
return { actions: [], dispose:() => {} };
705705
}
706706

707707
const actions = codeFixes.filter(fix => {

src/lib/lib.ts

Lines changed: 11 additions & 2 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)