@harmoniclabs/monaco-editor 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +21 -0
- package/README.md +122 -0
- package/build/build-languages.ts +212 -0
- package/build/build-monaco-editor.ts +463 -0
- package/build/check-samples.ts +53 -0
- package/build/fillers/vscode-nls.ts +46 -0
- package/build/fs.ts +80 -0
- package/build/importTypescript.ts +192 -0
- package/build/npm/installAll.ts +44 -0
- package/build/npm/removeAll.ts +20 -0
- package/build/postinstall.ts +28 -0
- package/build/releaseMetadata.ts +280 -0
- package/build/simpleserver.ts +69 -0
- package/build/tsconfig.json +8 -0
- package/build/utils.ts +291 -0
- package/package.json +87 -0
package/build/utils.ts
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import * as cp from 'child_process';
|
|
9
|
+
import * as esbuild from 'esbuild';
|
|
10
|
+
import alias from 'esbuild-plugin-alias';
|
|
11
|
+
import * as glob from 'glob';
|
|
12
|
+
import { ensureDir } from './fs';
|
|
13
|
+
|
|
14
|
+
export const REPO_ROOT = path.join(__dirname, '../');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Launch the typescript compiler synchronously over a project.
|
|
18
|
+
*/
|
|
19
|
+
export function runTsc(_projectPath: string) {
|
|
20
|
+
const projectPath = path.join(REPO_ROOT, _projectPath);
|
|
21
|
+
console.log(`Launching compiler at ${_projectPath}...`);
|
|
22
|
+
const res = cp.spawnSync(
|
|
23
|
+
process.execPath,
|
|
24
|
+
[path.join(__dirname, '../node_modules/typescript/lib/tsc.js'), '-p', projectPath],
|
|
25
|
+
{ stdio: 'inherit' }
|
|
26
|
+
);
|
|
27
|
+
console.log(`Compiled ${_projectPath}`);
|
|
28
|
+
if (res.status !== 0) {
|
|
29
|
+
process.exit(res.status);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Launch prettier on a specific file.
|
|
35
|
+
*/
|
|
36
|
+
export function prettier(_filePath: string) {
|
|
37
|
+
const filePath = path.join(REPO_ROOT, _filePath);
|
|
38
|
+
cp.spawnSync(
|
|
39
|
+
process.execPath,
|
|
40
|
+
[path.join(__dirname, '../node_modules/prettier/bin-prettier.js'), '--write', filePath],
|
|
41
|
+
{ stdio: 'inherit' }
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
console.log(`Ran prettier over ${_filePath}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Transform an external .d.ts file to an internal .d.ts file
|
|
49
|
+
*/
|
|
50
|
+
export function massageAndCopyDts(source: string, destination: string, namespace: string) {
|
|
51
|
+
const absoluteSource = path.join(REPO_ROOT, source);
|
|
52
|
+
const absoluteDestination = path.join(REPO_ROOT, destination);
|
|
53
|
+
|
|
54
|
+
const lines = fs
|
|
55
|
+
.readFileSync(absoluteSource)
|
|
56
|
+
.toString()
|
|
57
|
+
.split(/\r\n|\r|\n/);
|
|
58
|
+
|
|
59
|
+
let result = [
|
|
60
|
+
`/*---------------------------------------------------------------------------------------------`,
|
|
61
|
+
` * Copyright (c) Microsoft Corporation. All rights reserved.`,
|
|
62
|
+
` * Licensed under the MIT License. See License.txt in the project root for license information.`,
|
|
63
|
+
` *--------------------------------------------------------------------------------------------*/`,
|
|
64
|
+
``,
|
|
65
|
+
`declare namespace ${namespace} {`
|
|
66
|
+
];
|
|
67
|
+
for (let line of lines) {
|
|
68
|
+
if (/^import/.test(line)) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (line === 'export {};') {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
line = line.replace(/ /g, '\t');
|
|
75
|
+
line = line.replace(/declare /g, '');
|
|
76
|
+
if (line.length > 0) {
|
|
77
|
+
line = `\t${line}`;
|
|
78
|
+
result.push(line);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
result.push(`}`);
|
|
82
|
+
result.push(``);
|
|
83
|
+
|
|
84
|
+
ensureDir(path.dirname(absoluteDestination));
|
|
85
|
+
fs.writeFileSync(absoluteDestination, result.join('\n'));
|
|
86
|
+
|
|
87
|
+
prettier(destination);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function build(options: import('esbuild').BuildOptions) {
|
|
91
|
+
esbuild.build(options).then((result) => {
|
|
92
|
+
if (result.errors.length > 0) {
|
|
93
|
+
console.error(result.errors);
|
|
94
|
+
}
|
|
95
|
+
if (result.warnings.length > 0) {
|
|
96
|
+
console.error(result.warnings);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function buildESM(options: { base: string; entryPoints: string[]; external: string[] }) {
|
|
102
|
+
build({
|
|
103
|
+
entryPoints: options.entryPoints,
|
|
104
|
+
bundle: true,
|
|
105
|
+
target: 'esnext',
|
|
106
|
+
format: 'esm',
|
|
107
|
+
drop: ['debugger'],
|
|
108
|
+
define: {
|
|
109
|
+
AMD: 'false'
|
|
110
|
+
},
|
|
111
|
+
banner: {
|
|
112
|
+
js: bundledFileHeader
|
|
113
|
+
},
|
|
114
|
+
external: options.external,
|
|
115
|
+
outbase: `src/${options.base}`,
|
|
116
|
+
outdir: `out/languages/bundled/esm/vs/${options.base}/`,
|
|
117
|
+
plugins: [
|
|
118
|
+
alias({
|
|
119
|
+
'vscode-nls': path.join(__dirname, 'fillers/vscode-nls.ts')
|
|
120
|
+
})
|
|
121
|
+
]
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function buildOneAMD(
|
|
126
|
+
type: 'dev' | 'min',
|
|
127
|
+
options: {
|
|
128
|
+
base: string;
|
|
129
|
+
entryPoint: string;
|
|
130
|
+
amdModuleId: string;
|
|
131
|
+
amdDependencies?: string[];
|
|
132
|
+
external?: string[];
|
|
133
|
+
}
|
|
134
|
+
) {
|
|
135
|
+
if (!options.amdDependencies) {
|
|
136
|
+
options.amdDependencies = [];
|
|
137
|
+
}
|
|
138
|
+
options.amdDependencies.unshift('require');
|
|
139
|
+
|
|
140
|
+
const opts: esbuild.BuildOptions = {
|
|
141
|
+
entryPoints: [options.entryPoint],
|
|
142
|
+
bundle: true,
|
|
143
|
+
target: 'esnext',
|
|
144
|
+
format: 'iife',
|
|
145
|
+
drop: ['debugger'],
|
|
146
|
+
define: {
|
|
147
|
+
AMD: 'true'
|
|
148
|
+
},
|
|
149
|
+
globalName: 'moduleExports',
|
|
150
|
+
banner: {
|
|
151
|
+
js: `${bundledFileHeader}define("${options.amdModuleId}", [${(options.amdDependencies || [])
|
|
152
|
+
.map((dep) => `"${dep}"`)
|
|
153
|
+
.join(',')}],(require)=>{`
|
|
154
|
+
},
|
|
155
|
+
footer: {
|
|
156
|
+
js: 'return moduleExports;\n});'
|
|
157
|
+
},
|
|
158
|
+
outbase: `src/${options.base}`,
|
|
159
|
+
outdir: `out/languages/bundled/amd-${type}/vs/${options.base}/`,
|
|
160
|
+
plugins: [
|
|
161
|
+
alias({
|
|
162
|
+
'vscode-nls': path.join(__dirname, '../build/fillers/vscode-nls.ts'),
|
|
163
|
+
'monaco-editor-core': path.join(__dirname, '../src/fillers/monaco-editor-core-amd.ts')
|
|
164
|
+
})
|
|
165
|
+
],
|
|
166
|
+
external: ['vs/editor/editor.api', ...(options.external || [])]
|
|
167
|
+
};
|
|
168
|
+
if (type === 'min') {
|
|
169
|
+
opts.minify = true;
|
|
170
|
+
}
|
|
171
|
+
build(opts);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function buildAMD(options: {
|
|
175
|
+
base: string;
|
|
176
|
+
entryPoint: string;
|
|
177
|
+
amdModuleId: string;
|
|
178
|
+
amdDependencies?: string[];
|
|
179
|
+
external?: string[];
|
|
180
|
+
}) {
|
|
181
|
+
buildOneAMD('dev', options);
|
|
182
|
+
buildOneAMD('min', options);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function getGitVersion() {
|
|
186
|
+
const git = path.join(REPO_ROOT, '.git');
|
|
187
|
+
const headPath = path.join(git, 'HEAD');
|
|
188
|
+
let head;
|
|
189
|
+
|
|
190
|
+
try {
|
|
191
|
+
head = fs.readFileSync(headPath, 'utf8').trim();
|
|
192
|
+
} catch (e) {
|
|
193
|
+
return void 0;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (/^[0-9a-f]{40}$/i.test(head)) {
|
|
197
|
+
return head;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const refMatch = /^ref: (.*)$/.exec(head);
|
|
201
|
+
|
|
202
|
+
if (!refMatch) {
|
|
203
|
+
return void 0;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const ref = refMatch[1];
|
|
207
|
+
const refPath = path.join(git, ref);
|
|
208
|
+
|
|
209
|
+
try {
|
|
210
|
+
return fs.readFileSync(refPath, 'utf8').trim();
|
|
211
|
+
} catch (e) {
|
|
212
|
+
// noop
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const packedRefsPath = path.join(git, 'packed-refs');
|
|
216
|
+
let refsRaw;
|
|
217
|
+
|
|
218
|
+
try {
|
|
219
|
+
refsRaw = fs.readFileSync(packedRefsPath, 'utf8').trim();
|
|
220
|
+
} catch (e) {
|
|
221
|
+
return void 0;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const refsRegex = /^([0-9a-f]{40})\s+(.+)$/gm;
|
|
225
|
+
let refsMatch;
|
|
226
|
+
const refs = {};
|
|
227
|
+
|
|
228
|
+
while ((refsMatch = refsRegex.exec(refsRaw))) {
|
|
229
|
+
refs[refsMatch[2]] = refsMatch[1];
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return refs[ref];
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export const bundledFileHeader = (() => {
|
|
236
|
+
const sha1 = getGitVersion();
|
|
237
|
+
const semver = require('../package.json').version;
|
|
238
|
+
const headerVersion = semver + '(' + sha1 + ')';
|
|
239
|
+
|
|
240
|
+
const BUNDLED_FILE_HEADER = [
|
|
241
|
+
'/*!-----------------------------------------------------------------------------',
|
|
242
|
+
' * Copyright (c) Microsoft Corporation. All rights reserved.',
|
|
243
|
+
' * Version: ' + headerVersion,
|
|
244
|
+
' * Released under the MIT license',
|
|
245
|
+
' * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt',
|
|
246
|
+
' *-----------------------------------------------------------------------------*/',
|
|
247
|
+
''
|
|
248
|
+
].join('\n');
|
|
249
|
+
|
|
250
|
+
return BUNDLED_FILE_HEADER;
|
|
251
|
+
})();
|
|
252
|
+
|
|
253
|
+
export interface IFile {
|
|
254
|
+
path: string;
|
|
255
|
+
contents: Buffer;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export function readFiles(
|
|
259
|
+
pattern: string,
|
|
260
|
+
options: { base: string; ignore?: string[]; dot?: boolean }
|
|
261
|
+
): IFile[] {
|
|
262
|
+
let files = glob.sync(pattern, { cwd: REPO_ROOT, ignore: options.ignore, dot: options.dot });
|
|
263
|
+
// remove dirs
|
|
264
|
+
files = files.filter((file) => {
|
|
265
|
+
const fullPath = path.join(REPO_ROOT, file);
|
|
266
|
+
const stats = fs.statSync(fullPath);
|
|
267
|
+
return stats.isFile();
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
const base = options.base;
|
|
271
|
+
return files.map((file) => readFile(file, base));
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export function readFile(file: string, base: string = '') {
|
|
275
|
+
const baseLength = base === '' ? 0 : base.endsWith('/') ? base.length : base.length + 1;
|
|
276
|
+
const fullPath = path.join(REPO_ROOT, file);
|
|
277
|
+
const contents = fs.readFileSync(fullPath);
|
|
278
|
+
const relativePath = file.substring(baseLength);
|
|
279
|
+
return {
|
|
280
|
+
path: relativePath,
|
|
281
|
+
contents
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export function writeFiles(files: IFile[], dest: string) {
|
|
286
|
+
for (const file of files) {
|
|
287
|
+
const fullPath = path.join(REPO_ROOT, dest, file.path);
|
|
288
|
+
ensureDir(path.dirname(fullPath));
|
|
289
|
+
fs.writeFileSync(fullPath, file.contents);
|
|
290
|
+
}
|
|
291
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@harmoniclabs/monaco-editor",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"vscodeRef": "493330cdc6475247184ea459c66776c3da12cd2d",
|
|
5
|
+
"description": "A browser based code editor",
|
|
6
|
+
"homepage": "https://github.com/HarmonicLabs/monaco-editor",
|
|
7
|
+
"author": "Microsoft Corporation",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"import-typescript": "tsx ./build/importTypescript",
|
|
11
|
+
"playwright-install": "node ./node_modules/playwright/install.js",
|
|
12
|
+
"playwright-install-deps": "playwright install-deps",
|
|
13
|
+
"postinstall": "tsx ./build/postinstall",
|
|
14
|
+
"prettier-check": "prettier --check .",
|
|
15
|
+
"prettier": "prettier --write .",
|
|
16
|
+
"pretty-quick": "pretty-quick --staged",
|
|
17
|
+
"simpleserver": "tsx ./build/simpleserver",
|
|
18
|
+
"package-for-smoketest-webpack": "tsx ./test/smoke/package-webpack",
|
|
19
|
+
"package-for-smoketest-webpack-cross-origin": "tsx ./test/smoke/package-webpack --cross-origin",
|
|
20
|
+
"package-for-smoketest-esbuild": "tsx ./test/smoke/package-esbuild",
|
|
21
|
+
"package-for-smoketest-vite": "tsx ./test/smoke/package-vite",
|
|
22
|
+
"smoketest": "node ./test/smoke/runner.js",
|
|
23
|
+
"smoketest-debug": "node ./test/smoke/runner.js --debug-tests",
|
|
24
|
+
"test": "mocha test/unit/all.js && tsx ./build/check-samples",
|
|
25
|
+
"deps-all-remove": "tsx ./build/npm/removeAll",
|
|
26
|
+
"deps-all-install": "tsx ./build/npm/installAll",
|
|
27
|
+
"update-actions": "pin-github-action ./.github/workflows/website.yml",
|
|
28
|
+
"watch": "tsc -w -p ./src",
|
|
29
|
+
"build": "tsx ./build/build-languages",
|
|
30
|
+
"build-monaco-editor": "npm run build && tsx ./build/build-monaco-editor"
|
|
31
|
+
},
|
|
32
|
+
"typings": "./esm/vs/editor/editor.api.d.ts",
|
|
33
|
+
"module": "./esm/vs/editor/editor.main.js",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/HarmonicLabs/monaco-editor"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"out/monaco-editor",
|
|
40
|
+
"build/"
|
|
41
|
+
],
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/mocha": "^9.1.0",
|
|
44
|
+
"@types/shelljs": "^0.8.11",
|
|
45
|
+
"@typescript/vfs": "^1.3.5",
|
|
46
|
+
"chai": "^4.3.6",
|
|
47
|
+
"clean-css": "^5.2.4",
|
|
48
|
+
"css-loader": "^6.7.1",
|
|
49
|
+
"esbuild": "^0.20.0",
|
|
50
|
+
"esbuild-plugin-alias": "^0.2.1",
|
|
51
|
+
"file-loader": "^6.2.0",
|
|
52
|
+
"glob": "^7.2.0",
|
|
53
|
+
"http-server": "^14.1.1",
|
|
54
|
+
"husky": "^9.1.7",
|
|
55
|
+
"jsdom": "^19.0.0",
|
|
56
|
+
"jsonc-parser": "^3.0.0",
|
|
57
|
+
"mocha": "^9.2.0",
|
|
58
|
+
"monaco-editor-core": "0.52.0-rc2",
|
|
59
|
+
"parcel": "^2.7.0",
|
|
60
|
+
"pin-github-action": "^1.8.0",
|
|
61
|
+
"playwright": "^1.32.2",
|
|
62
|
+
"prettier": "^2.5.1",
|
|
63
|
+
"pretty-quick": "^3.1.3",
|
|
64
|
+
"requirejs": "^2.3.7",
|
|
65
|
+
"shelljs": "^0.8.5",
|
|
66
|
+
"style-loader": "^3.3.1",
|
|
67
|
+
"terser": "^5.14.2",
|
|
68
|
+
"tsx": "^4.20.3",
|
|
69
|
+
"vite": "^3.2.8",
|
|
70
|
+
"vscode-css-languageservice": "6.2.14",
|
|
71
|
+
"vscode-html-languageservice": "5.2.0",
|
|
72
|
+
"vscode-json-languageservice": "5.3.11",
|
|
73
|
+
"vscode-languageserver-textdocument": "^1.0.11",
|
|
74
|
+
"vscode-languageserver-types": "3.17.5",
|
|
75
|
+
"vscode-uri": "3.0.8",
|
|
76
|
+
"webpack": "^5.76.0",
|
|
77
|
+
"yaserver": "^0.4.0"
|
|
78
|
+
},
|
|
79
|
+
"alias": {
|
|
80
|
+
"process": false,
|
|
81
|
+
"buffer": false
|
|
82
|
+
},
|
|
83
|
+
"dependencies": {
|
|
84
|
+
"typescript": "5.4.5",
|
|
85
|
+
"tsx": "^4.20.3"
|
|
86
|
+
}
|
|
87
|
+
}
|