mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 12:45:39 +01:00
Adopt esbuild for monaco-typescript
This commit is contained in:
parent
c0d4493bd9
commit
dcbd8121d9
15 changed files with 66 additions and 335 deletions
|
|
@ -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)
|
||||
|
|
|
|||
46
monaco-typescript/build.js
Normal file
46
monaco-typescript/build.js
Normal file
|
|
@ -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> {
|
||||
return import('./tsMode');
|
||||
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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue