Adopt `esbuild` for `monaco-typescript`

pull/2766/head
Alexandru Dima 3 years ago
parent c0d4493bd9
commit dcbd8121d9
No known key found for this signature in database
GPG Key ID: 39563C1504FDD0C9

@ -142,6 +142,9 @@ function dts(_source, _destination, namespace) {
if (/^import/.test(line)) {
continue;
}
if (line === 'export {};') {
continue;
}
line = line.replace(/ /g, '\t');
line = line.replace(/declare /g, '');
if (line.length > 0) {

@ -347,8 +347,6 @@ function ESM_pluginStream(plugin, destinationPath) {
}
}
contents = contents.replace(/\/\/# sourceMappingURL=.*((\r?\n)|$)/g, '');
data.contents = Buffer.from(contents);
this.emit('data', data);
}

@ -1,120 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link
rel="stylesheet"
data-name="vs/editor/editor.main"
href="../node_modules/monaco-editor-core/dev/vs/editor/editor.main.css"
/>
</head>
<body>
<h2>Monaco Editor JSON test page</h2>
<div id="container" style="width: 800px; height: 600px; border: 1px solid grey"></div>
<script>
// Loading basic-languages to get the json language definition
var paths = {
'vs/basic-languages': '../node_modules/monaco-languages/release/dev',
'vs/language/json': '../release/dev',
vs: '../node_modules/monaco-editor-core/dev/vs'
};
if (document.location.protocol === 'http:') {
// Add support for running local http server
let testIndex = document.location.pathname.indexOf('/test/');
if (testIndex !== -1) {
let prefix = document.location.pathname.substr(0, testIndex);
paths['vs/language/json'] = prefix + '/release/dev';
}
}
var require = {
paths: paths
};
</script>
<script src="../node_modules/monaco-editor-core/dev/vs/loader.js"></script>
<script src="../node_modules/monaco-editor-core/dev/vs/editor/editor.main.nls.js"></script>
<script src="../node_modules/monaco-editor-core/dev/vs/editor/editor.main.js"></script>
<script>
require([
'vs/basic-languages/monaco.contribution',
'vs/language/json/monaco.contribution'
], function () {
var editor = monaco.editor.create(document.getElementById('container'), {
value: [
'{',
' "type": "team",',
' "test": {',
' "testPage": "tools/testing/run-tests.htm",',
' "enabled": true',
' },',
' "search": {',
' "excludeFolders": [',
' ".git",',
' "node_modules",',
' "tools/bin",',
' "tools/counts",',
' "tools/policheck",',
' "tools/tfs_build_extensions",',
' "tools/testing/jscoverage",',
' "tools/testing/qunit",',
' "tools/testing/chutzpah",',
' "server.net"',
' ]',
' },',
' "languages": {',
' "vs.languages.typescript": {',
' "validationSettings": [{',
' "scope":"/",',
' "noImplicitAny":true,',
' "noLib":false,',
' "extraLibs":[],',
' "semanticValidation":true,',
' "syntaxValidation":true,',
' "codeGenTarget":"ES5",',
' "moduleGenTarget":"",',
' "lint": {',
' "emptyBlocksWithoutComment": "warning",',
' "curlyBracketsMustNotBeOmitted": "warning",',
' "comparisonOperatorsNotStrict": "warning",',
' "missingSemicolon": "warning",',
' "unknownTypeOfResults": "warning",',
' "semicolonsInsteadOfBlocks": "warning",',
' "functionsInsideLoops": "warning",',
' "functionsWithoutReturnType": "warning",',
' "tripleSlashReferenceAlike": "warning",',
' "unusedImports": "warning",',
' "unusedVariables": "warning",',
' "unusedFunctions": "warning",',
' "unusedMembers": "warning"',
' }',
' },',
' {',
' "scope":"/client",',
' "baseUrl":"/client",',
' "moduleGenTarget":"amd"',
' },',
' {',
' "scope":"/server",',
' "moduleGenTarget":"commonjs"',
' },',
' {',
' "scope":"/build",',
' "moduleGenTarget":"commonjs"',
' },',
' {',
' "scope":"/node_modules/nake",',
' "moduleGenTarget":"commonjs"',
' }],',
' "allowMultipleWorkers": true',
' }',
' }',
'}'
].join('\n'),
language: 'json'
});
});
</script>
</body>
</html>

@ -1,23 +1,14 @@
# Monaco Languages [![Build Status](https://dev.azure.com/ms/monaco-languages/_apis/build/status/microsoft.monaco-languages?branchName=master)](https://dev.azure.com/ms/monaco-languages/_build/latest?definitionId=140&branchName=master)
# Monaco Languages
Colorization and configuration supports for multiple languages for the Monaco Editor:
![monaco-languages](https://cloud.githubusercontent.com/assets/5047891/15938606/1fd4bac6-2e74-11e6-8839-d455da8bc8a7.gif)
## Issues
## Development
Please file issues concerning `monaco-languages` in the [`monaco-editor`-repository](https://github.com/Microsoft/monaco-editor/issues).
## Installing
This npm module is bundled and distributed in the [monaco-editor](https://www.npmjs.com/package/monaco-editor) npm module.
## Dev: cheat sheet
- initial setup with `npm install .`
- compile with `npm run watch`
- watch with `npm run watch`
- compile with `npm run prepublishOnly`
- test with `npm run test`
- bundle with `npm run prepublishOnly`
## Dev: Adding a new language
@ -29,11 +20,3 @@ This npm module is bundled and distributed in the [monaco-editor](https://www.np
```js
import './myLang/myLang.contribution';
```
## Code of Conduct
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
## License
[MIT](https://github.com/Microsoft/monaco-languages/blob/master/LICENSE.md)

@ -6,21 +6,10 @@ Simple TypeScript and JavaScript language support for the Monaco Editor.
_Note_ that this project focuses on single-file scenarios and that things like project-isolation, cross-file-features like Rename etc. are _outside_ the scope of this project and not supported.
## Issues
Please file issues concerning `monaco-typescript` in the [`monaco-editor` repository](https://github.com/Microsoft/monaco-editor/issues).
## Installing
This npm module is bundled and distributed in the [monaco-editor](https://www.npmjs.com/package/monaco-editor) npm module.
## Development
- `git clone https://github.com/Microsoft/monaco-typescript`
- `cd monaco-typescript`
- `npm install .`
- `npm run compile`
- `npm run watch`
- watch with `npm run watch`
- compile with `npm run prepublishOnly`
- open `$/monaco-typescript/test/index.html` in your favorite browser.
## Updating TypeScript
@ -29,11 +18,3 @@ This npm module is bundled and distributed in the [monaco-editor](https://www.np
- execute `npm install .`
- execute `npm run import-typescript`
- adopt new APIs
## Code of Conduct
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
## License
[MIT](https://github.com/Microsoft/monaco-typescript/blob/master/LICENSE.md)

@ -0,0 +1,46 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
//@ts-check
const { copyFile, removeDir, tsc, dts, buildESM, buildAMD } = require('../build/utils');
removeDir(`monaco-typescript/release`);
removeDir(`monaco-typescript/out`);
copyFile(
`monaco-typescript/src/lib/typescriptServices-amd.js`,
`monaco-typescript/out/amd/lib/typescriptServices.js`
);
copyFile(
`monaco-typescript/src/lib/typescriptServices.js`,
`monaco-typescript/out/esm/lib/typescriptServices.js`
);
tsc(`monaco-typescript/src/tsconfig.json`);
dts(
`monaco-typescript/out/amd/monaco.contribution.d.ts`,
`monaco-typescript/monaco.d.ts`,
'monaco.languages.typescript'
);
buildESM({
entryPoints: ['src/monaco.contribution.ts', 'src/tsMode.ts', 'src/ts.worker.ts'],
external: ['monaco-editor-core', '*/tsMode']
});
buildAMD({
entryPoint: 'src/monaco.contribution.ts',
banner: 'define("vs/language/typescript/monaco.contribution",["vs/editor/editor.api"],()=>{'
});
buildAMD({
entryPoint: 'src/tsMode.ts',
banner: 'define("vs/language/typescript/tsMode",["vs/editor/editor.api"],()=>{'
});
buildAMD({
entryPoint: 'src/tsWorker.ts',
banner: 'define("vs/language/typescript/tsWorker",[],()=>{'
});

@ -1,10 +1,7 @@
{
"scripts": {
"compile-amd": "../node_modules/.bin/mcopy ./src/lib/typescriptServices-amd.js ./out/amd/lib/typescriptServices.js && ../node_modules/.bin/tsc -p ./src/tsconfig.json",
"compile-esm": "../node_modules/.bin/mcopy ./src/lib/typescriptServices.js ./out/esm/lib/typescriptServices.js && ../node_modules/.bin/tsc -p ./src/tsconfig.esm.json",
"compile": "../node_modules/.bin/mrmdir ./out && npm run compile-amd && npm run compile-esm && node ./scripts/dts && ../node_modules/.bin/prettier --write ./monaco.d.ts",
"watch": "../node_modules/.bin/tsc -p ./src --watch",
"prepublishOnly": "../node_modules/.bin/mrmdir ./release && npm run compile && node ./scripts/release.js && node ./scripts/bundle && ../node_modules/.bin/mcopy ./out/esm/monaco.contribution.d.ts ./release/esm/monaco.contribution.d.ts && ../node_modules/.bin/mcopy ./out/esm/fillers/monaco-editor-core.d.ts ./release/esm/fillers/monaco-editor-core.d.ts",
"prepublishOnly": "node ./build",
"import-typescript": "node ./scripts/importTypescript"
}
}

@ -1,64 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
const requirejs = require('requirejs');
const path = require('path');
const fs = require('fs');
const terser = require('terser');
const helpers = require('monaco-plugin-helpers');
const REPO_ROOT = path.resolve(__dirname, '..', '..');
const sha1 = helpers.getGitVersion(REPO_ROOT);
const semver = require('../../package.json').version;
const headerVersion = semver + '(' + sha1 + ')';
const BUNDLED_FILE_HEADER = [
'/*!-----------------------------------------------------------------------------',
' * Copyright (c) Microsoft Corporation. All rights reserved.',
' * monaco-typescript version: ' + headerVersion,
' * Released under the MIT license',
' * https://github.com/Microsoft/monaco-typescript/blob/master/LICENSE.md',
' *-----------------------------------------------------------------------------*/',
''
].join('\n');
bundleOne('monaco.contribution');
bundleOne('tsMode', ['vs/language/typescript/monaco.contribution']);
bundleOne('tsWorker');
function bundleOne(moduleId, exclude) {
requirejs.optimize(
{
baseUrl: 'out/amd/',
name: 'vs/language/typescript/' + moduleId,
out: 'release/dev/' + moduleId + '.js',
exclude: exclude,
paths: {
'vs/language/typescript': REPO_ROOT + '/monaco-typescript/out/amd',
'vs/language/typescript/fillers/monaco-editor-core':
REPO_ROOT + '/monaco-typescript/out/amd/fillers/monaco-editor-core-amd'
},
optimize: 'none'
},
async function (buildResponse) {
const devFilePath = path.join(REPO_ROOT, 'monaco-typescript/release/dev/' + moduleId + '.js');
const minFilePath = path.join(REPO_ROOT, 'monaco-typescript/release/min/' + moduleId + '.js');
const fileContents = fs.readFileSync(devFilePath).toString();
console.log();
console.log(`Minifying ${devFilePath}...`);
const result = await terser.minify(fileContents, {
output: {
comments: 'some'
}
});
console.log(`Done minifying ${devFilePath}.`);
try {
fs.mkdirSync(path.join(REPO_ROOT, 'monaco-typescript/release/min'));
} catch (err) {}
fs.writeFileSync(minFilePath, BUNDLED_FILE_HEADER + result.code);
}
);
}

@ -1,44 +0,0 @@
/*---------------------------------------------------------------------------------------------
* 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.typescript {`
];
for (let line of lines) {
if (/^import/.test(line)) {
continue;
}
if (line === 'export {};') {
continue;
}
line = line.replace(/ /g, '\t');
line = line.replace(/declare /g, '');
if (line.length > 0) {
line = `\t${line}`;
result.push(line);
}
}
result.push(`}`);
result.push(``);
fs.writeFileSync(DST_PATH, result.join('\n'));

@ -1,17 +0,0 @@
/*---------------------------------------------------------------------------------------------
* 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 helpers = require('monaco-plugin-helpers');
const REPO_ROOT = path.join(__dirname, '../../');
helpers.packageESM({
repoRoot: REPO_ROOT,
esmSource: 'monaco-typescript/out/esm',
esmDestination: 'monaco-typescript/release/esm',
entryPoints: ['monaco.contribution.js', 'tsMode.js', 'ts.worker.js'],
resolveSkip: ['monaco-editor-core']
});

@ -1,12 +0,0 @@
/*---------------------------------------------------------------------------------------------
* 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 const define: any;
define([], function () {
return (<any>self).monaco;
});

@ -693,8 +693,17 @@ export const getJavaScriptWorker = (): Promise<(...uris: Uri[]) => Promise<TypeS
// --- Registration to monaco editor ---
declare var AMD: any;
declare var require: any;
function getMode(): Promise<typeof mode> {
if (AMD) {
return new Promise((resolve, reject) => {
require(['vs/language/typescript/tsMode'], resolve, reject);
});
} else {
return import('./tsMode');
}
}
languages.onLanguage('typescript', () => {

@ -1,11 +0,0 @@
{
"compilerOptions": {
"module": "esnext",
"moduleResolution": "node",
"outDir": "../out/esm",
"declaration": true,
"target": "es5",
"lib": ["dom", "es5", "es2015.collection", "es2015.iterable", "es2015.promise"],
"strict": true
}
}

17
package-lock.json generated

@ -2991,23 +2991,6 @@
"integrity": "sha512-WNxfchYafMZXVfysqg/ESW4MtOpYLPaIKrzudNlgwYvfYID+O/nwSZI5X+KxW84roVzHsNgFGyOOesfHFZwYUA==",
"dev": true
},
"monaco-plugin-helpers": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/monaco-plugin-helpers/-/monaco-plugin-helpers-1.0.3.tgz",
"integrity": "sha512-6AYI3ONAy8ki74qG2JqtFrLdiJHQlgeO5l4Rwr0OMyIpGXhc94y5rZuFxOtgGkxgSrZfHSwOt/MulUNZ/mOQOw==",
"dev": true,
"requires": {
"typescript": "^2.7.2"
},
"dependencies": {
"typescript": {
"version": "2.9.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz",
"integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==",
"dev": true
}
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",

@ -38,7 +38,6 @@
"jsdom": "^17.0.0",
"jsonc-parser": "^3.0.0",
"monaco-editor-core": "0.30.1",
"monaco-plugin-helpers": "^1.0.3",
"prettier": "^2.4.1",
"requirejs": "^2.3.6",
"rimraf": "^3.0.2",

Loading…
Cancel
Save