Adopt `esbuild` for `monaco-json`
parent
6bfac402fb
commit
a50081289e
@ -0,0 +1,36 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { removeDir, tsc, dts, buildESM, buildAMD } = require('../build/utils');
|
||||
|
||||
removeDir(`monaco-json/release`);
|
||||
removeDir(`monaco-json/out`);
|
||||
|
||||
tsc(`monaco-json/src/tsconfig.json`);
|
||||
|
||||
dts(
|
||||
`monaco-json/out/amd/monaco.contribution.d.ts`,
|
||||
`monaco-json/monaco.d.ts`,
|
||||
'monaco.languages.json'
|
||||
);
|
||||
|
||||
buildESM({
|
||||
entryPoints: ['src/monaco.contribution.ts', 'src/jsonMode.ts', 'src/json.worker.ts'],
|
||||
external: ['monaco-editor-core', '*/jsonMode'],
|
||||
});
|
||||
buildAMD({
|
||||
entryPoint: 'src/monaco.contribution.ts',
|
||||
banner: 'define("vs/language/json/monaco.contribution",["vs/editor/editor.api"],()=>{'
|
||||
});
|
||||
buildAMD({
|
||||
entryPoint: 'src/jsonMode.ts',
|
||||
banner: 'define("vs/language/json/jsonMode",["vs/editor/editor.api"],()=>{'
|
||||
});
|
||||
buildAMD({
|
||||
entryPoint: 'src/jsonWorker.ts',
|
||||
banner: 'define("vs/language/json/jsonWorker",[],()=>{'
|
||||
});
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"scripts": {
|
||||
"watch": "../node_modules/.bin/tsc -p ./src --watch",
|
||||
"prepublishOnly": "node ./scripts/build"
|
||||
"prepublishOnly": "node ./build"
|
||||
}
|
||||
}
|
||||
|
@ -1,49 +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 esbuild = require('esbuild');
|
||||
const alias = require('esbuild-plugin-alias');
|
||||
const path = require('path');
|
||||
const cp = require('child_process');
|
||||
const { removeDir, tsc, dts } = require('../../build/utils');
|
||||
|
||||
removeDir(`monaco-json/release`);
|
||||
removeDir(`monaco-json/out`);
|
||||
|
||||
tsc(`monaco-json/src/tsconfig.json`);
|
||||
|
||||
dts(
|
||||
`monaco-json/out/amd/monaco.contribution.d.ts`,
|
||||
`monaco-json/monaco.d.ts`,
|
||||
'monaco.languages.json'
|
||||
);
|
||||
|
||||
esbuild
|
||||
.build({
|
||||
entryPoints: ['src/jsonMode.ts', 'src/json.worker.ts', 'src/monaco.contribution.ts'],
|
||||
bundle: true,
|
||||
target: 'esnext',
|
||||
format: 'esm',
|
||||
external: ['monaco-editor-core', '*/jsonMode'],
|
||||
outdir: 'release/esm/',
|
||||
plugins: [
|
||||
alias({
|
||||
'vscode-nls': path.join(__dirname, '../src/fillers/vscode-nls.ts')
|
||||
})
|
||||
]
|
||||
})
|
||||
.then((result) => {
|
||||
if (result.errors.length > 0) {
|
||||
console.error(result.errors);
|
||||
}
|
||||
if (result.warnings.length > 0) {
|
||||
console.error(result.warnings);
|
||||
}
|
||||
});
|
||||
|
||||
cp.spawnSync(process.execPath, [path.join(__dirname, './bundle.js')], {
|
||||
stdio: 'inherit',
|
||||
stderr: 'inherit'
|
||||
});
|
@ -1,84 +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 { getBundledFileHeader } = require('../../build/utils');
|
||||
|
||||
const REPO_ROOT = path.resolve(__dirname, '..', '..');
|
||||
|
||||
const BUNDLED_FILE_HEADER = getBundledFileHeader();
|
||||
|
||||
bundleOne('monaco.contribution');
|
||||
bundleOne('jsonMode', ['vs/language/json/monaco.contribution']);
|
||||
bundleOne('jsonWorker');
|
||||
|
||||
function bundleOne(moduleId, exclude) {
|
||||
requirejs.optimize(
|
||||
{
|
||||
baseUrl: 'out/amd/',
|
||||
name: 'vs/language/json/' + moduleId,
|
||||
out: 'release/dev/' + moduleId + '.js',
|
||||
exclude: exclude,
|
||||
paths: {
|
||||
'vs/language/json': REPO_ROOT + '/monaco-json/out/amd',
|
||||
'vs/language/json/fillers/monaco-editor-core':
|
||||
REPO_ROOT + '/monaco-json/out/amd/fillers/monaco-editor-core-amd'
|
||||
},
|
||||
optimize: 'none',
|
||||
packages: [
|
||||
{
|
||||
name: 'vscode-json-languageservice',
|
||||
location: path.join(REPO_ROOT, 'node_modules/vscode-json-languageservice/lib/umd'),
|
||||
main: 'jsonLanguageService'
|
||||
},
|
||||
{
|
||||
name: 'vscode-languageserver-types',
|
||||
location: path.join(REPO_ROOT, 'node_modules/vscode-languageserver-types/lib/umd'),
|
||||
main: 'main'
|
||||
},
|
||||
{
|
||||
name: 'vscode-languageserver-textdocument',
|
||||
location: path.join(REPO_ROOT, 'node_modules/vscode-languageserver-textdocument/lib/umd'),
|
||||
main: 'main'
|
||||
},
|
||||
{
|
||||
name: 'jsonc-parser',
|
||||
location: path.join(REPO_ROOT, 'node_modules/jsonc-parser/lib/umd'),
|
||||
main: 'main'
|
||||
},
|
||||
{
|
||||
name: 'vscode-uri',
|
||||
location: path.join(REPO_ROOT, 'node_modules/vscode-uri/lib/umd'),
|
||||
main: 'index'
|
||||
},
|
||||
{
|
||||
name: 'vscode-nls',
|
||||
location: path.join(REPO_ROOT, 'monaco-json/out/amd/fillers'),
|
||||
main: 'vscode-nls'
|
||||
}
|
||||
]
|
||||
},
|
||||
async function (buildResponse) {
|
||||
const devFilePath = path.join(REPO_ROOT, 'monaco-json/release/dev/' + moduleId + '.js');
|
||||
const minFilePath = path.join(REPO_ROOT, 'monaco-json/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-json/release/min'));
|
||||
} catch (err) {}
|
||||
fs.writeFileSync(minFilePath, BUNDLED_FILE_HEADER + result.code);
|
||||
}
|
||||
);
|
||||
}
|
@ -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 var define;
|
||||
|
||||
define([], function () {
|
||||
return (<any>self).monaco;
|
||||
});
|
@ -1,46 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
export interface Options {
|
||||
locale?: string;
|
||||
cacheLanguageResolution?: boolean;
|
||||
}
|
||||
export interface LocalizeInfo {
|
||||
key: string;
|
||||
comment: string[];
|
||||
}
|
||||
export interface LocalizeFunc {
|
||||
(info: LocalizeInfo, message: string, ...args: any[]): string;
|
||||
(key: string, message: string, ...args: any[]): string;
|
||||
}
|
||||
export interface LoadFunc {
|
||||
(file?: string): LocalizeFunc;
|
||||
}
|
||||
|
||||
function format(message: string, args: any[]): string {
|
||||
let result: string;
|
||||
|
||||
if (args.length === 0) {
|
||||
result = message;
|
||||
} else {
|
||||
result = message.replace(/\{(\d+)\}/g, (match, rest) => {
|
||||
let index = rest[0];
|
||||
return typeof args[index] !== 'undefined' ? args[index] : match;
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function localize(key: string | LocalizeInfo, message: string, ...args: any[]): string {
|
||||
return format(message, args);
|
||||
}
|
||||
|
||||
export function loadMessageBundle(file?: string): LocalizeFunc {
|
||||
return localize;
|
||||
}
|
||||
|
||||
export function config(opt?: Options | string): LoadFunc {
|
||||
return loadMessageBundle;
|
||||
}
|
Loading…
Reference in New Issue