GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — app-vscode/build/gulpfile.editor.ts at main · code/app-vscode Expand file tree/ Copy pathgulpfile.editor.tsMore file actions 310 lines (270 loc) · 10.3 KB / Copy pathgulpfile.editor.tsFile metadata and controls310 lines (270 loc) · 10.3 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { gulp, filter } from './lib/gulp/facade.ts'; import path from 'path'; import * as util from './lib/util.ts'; import { getVersion } from './lib/getVersion.ts'; import * as task from './lib/gulp/task.ts'; import es from 'event-stream'; import File from 'vinyl'; import * as i18n from './lib/i18n.ts'; import * as standalone from './lib/standalone.ts'; import * as cp from 'child_process'; import * as compilation from './lib/compilation.ts'; import * as monacoapi from './lib/monaco-api.ts'; import * as fs from 'fs'; import { createReporter } from './lib/reporter.ts'; import monacoPackage from './monaco/package.json' with { type: 'json' }; const root = path.dirname(import.meta.dirname); const standaloneEnumsPath = path.join(root, 'src/vs/editor/common/standalone/standaloneEnums.ts'); const sha1 = getVersion(root); const semver = monacoPackage.version; const headerVersion = semver + '(' + sha1 + ')'; const BUNDLED_FILE_HEADER = [ '/*!-----------------------------------------------------------', ' * Copyright (c) Microsoft Corporation. All rights reserved.', ' * Version: ' + headerVersion, ' * Released under the MIT license', ' * https://github.com/microsoft/vscode/blob/main/LICENSE.txt', ' *-----------------------------------------------------------*/', '' ].join('\n'); const extractEditorSrcTask = task.define('extract-editor-src', () => { // Ensure codicon.ttf is copied from node_modules (needed when node_modules is cached and postinstall doesn't run) const codiconSource = path.join(root, 'node_modules', '@vscode', 'codicons', 'dist', 'codicon.ttf'); const codiconDest = path.join(root, 'src', 'vs', 'base', 'browser', 'ui', 'codicons', 'codicon', 'codicon.ttf'); if (fs.existsSync(codiconSource)) { fs.mkdirSync(path.dirname(codiconDest), { recursive: true }); fs.copyFileSync(codiconSource, codiconDest); } const apiusages = monacoapi.execute().usageContent; const extrausages = fs.readFileSync(path.join(root, 'build', 'monaco', 'monaco.usage.recipe')).toString(); standalone.extractEditor({ sourcesRoot: path.join(root, 'src'), entryPoints: [ 'vs/editor/editor.main.ts', 'vs/editor/editor.worker.start.ts', 'vs/editor/common/services/editorWebWorkerMain.ts', ], inlineEntryPoints: [ apiusages, extrausages ], typings: [], additionalFilesToCopyOut: [ 'vs/base/browser/dompurify/dompurify.js', 'vs/base/common/marked/marked.js', ], shakeLevel: 2, // 0-Files, 1-InnerFile, 2-ClassMembers importIgnorePattern: /\.css$/, destRoot: path.join(root, 'out-editor-src'), tsOutDir: '../out-monaco-editor-core/esm/vs', }); }); const compileEditorESMTask = task.define('compile-editor-esm', () => { const src = 'out-editor-src'; const out = 'out-monaco-editor-core/esm'; const compile = compilation.createCompile(src, { build: true, emitError: true, transpileOnly: false, preserveEnglish: true }); const srcPipe = gulp.src(`${src}/**`, { base: `${src}` }); return ( srcPipe .pipe(compile()) .pipe(i18n.processNlsFiles({ out, fileHeader: BUNDLED_FILE_HEADER, languages: [...i18n.defaultLanguages, ...i18n.extraLanguages], })) .pipe(filter(['**', '!**/inlineEntryPoint*', '!**/tsconfig.json'])) .pipe(gulp.dest(out)) ); }); function toExternalDTS(contents: string) { const lines = contents.split(/\r\n|\r|\n/); let killNextCloseCurlyBrace = false; for (let i = 0; i < lines.length; i++) { const line = lines[i]; if (killNextCloseCurlyBrace) { if ('}' === line) { lines[i] = ''; killNextCloseCurlyBrace = false; continue; } if (line.indexOf(' ') === 0) { lines[i] = line.substr(4); } else if (line.charAt(0) === '\t') { lines[i] = line.substr(1); } continue; } if ('declare namespace monaco {' === line) { lines[i] = ''; killNextCloseCurlyBrace = true; continue; } if (line.indexOf('declare namespace monaco.') === 0) { lines[i] = line.replace('declare namespace monaco.', 'export namespace '); } if (line.indexOf('declare var MonacoEnvironment') === 0) { lines[i] = `declare global {\n var MonacoEnvironment: Environment | undefined;\n}`; } } return lines.join('\n').replace(/\n\n\n+/g, '\n\n'); } const finalEditorResourcesTask = task.define('final-editor-resources', () => { return es.merge( // other assets es.merge( gulp.src('build/monaco/LICENSE'), gulp.src('build/monaco/ThirdPartyNotices.txt'), gulp.src('src/vs/monaco.d.ts') ).pipe(gulp.dest('out-monaco-editor-core')), // place the .d.ts in the esm folder gulp.src('src/vs/monaco.d.ts') .pipe(es.through(function (data) { this.emit('data', new File({ path: data.path.replace(/monaco\.d\.ts/, 'editor.api.d.ts'), base: data.base, contents: Buffer.from(toExternalDTS(data.contents.toString())) })); })) .pipe(gulp.dest('out-monaco-editor-core/esm/vs/editor')), // package.json gulp.src('build/monaco/package.json') .pipe(es.through(function (data) { const json = JSON.parse(data.contents.toString()); json.private = false; let markedVersion; let dompurifyVersion; try { const markedManifestPath = path.join(root, 'src/vs/base/common/marked/cgmanifest.json'); const dompurifyManifestPath = path.join(root, 'src/vs/base/browser/dompurify/cgmanifest.json'); const markedManifest = JSON.parse(fs.readFileSync(markedManifestPath, 'utf8')); const dompurifyManifest = JSON.parse(fs.readFileSync(dompurifyManifestPath, 'utf8')); markedVersion = markedManifest.registrations[0].version; dompurifyVersion = dompurifyManifest.registrations[0].version; if (!markedVersion || !dompurifyVersion) { throw new Error('Unable to read versions from cgmanifest.json files'); } } catch (error) { throw new Error(`Failed to read cgmanifest.json files for monaco-editor-core dependencies: ${error.message}`); } setUnsetField(json, 'dependencies', { 'marked': markedVersion, 'dompurify': dompurifyVersion }); data.contents = Buffer.from(JSON.stringify(json, null, ' ')); this.emit('data', data); })) .pipe(gulp.dest('out-monaco-editor-core')), // version.txt gulp.src('build/monaco/version.txt') .pipe(es.through(function (data) { data.contents = Buffer.from(`monaco-editor-core: https://github.com/microsoft/vscode/tree/${sha1}`); this.emit('data', data); })) .pipe(gulp.dest('out-monaco-editor-core')), // README.md gulp.src('build/monaco/README-npm.md') .pipe(es.through(function (data) { this.emit('data', new File({ path: data.path.replace(/README-npm\.md/, 'README.md'), base: data.base, contents: data.contents })); })) .pipe(gulp.dest('out-monaco-editor-core')), ); }); task.task('extract-editor-src', task.series( util.rimraf('out-editor-src'), extractEditorSrcTask ) ); task.task('editor-distro', task.series( task.parallel( util.rimraf('out-editor-src'), util.rimraf('out-monaco-editor-core'), ), extractEditorSrcTask, compileEditorESMTask, finalEditorResourcesTask ) ); task.task('monacodts', task.define('monacodts', () => { const result = monacoapi.execute(); fs.writeFileSync(result.filePath, result.content); fs.writeFileSync(standaloneEnumsPath, result.enums); return Promise.resolve(true); })); task.task('monacodts-check', task.define('monacodts-check', () => { const result = monacoapi.execute(); const currentEnums = fs.readFileSync(standaloneEnumsPath).toString(); const normalizedCurrentEnums = currentEnums.replace(/\r\n/g, '\n'); const normalizedGeneratedEnums = result.enums.replace(/\r\n/g, '\n'); if (!result.isTheSame || normalizedCurrentEnums !== normalizedGeneratedEnums) { throw new Error('Monaco declarations are no longer up to date. Run `npm run gulp monacodts` and commit the generated files.'); } return Promise.resolve(true); })); //#region monaco type checking function createTscCompileTask(watch: boolean) { return () => { return new Promise((resolve, reject) => { const args = ['./node_modules/.bin/tsc6', '-p', './src/tsconfig.monaco.json', '--noEmit']; if (watch) { args.push('-w'); } const child = cp.spawn(`node`, args, { cwd: path.join(import.meta.dirname, '..'), // stdio: [null, 'pipe', 'inherit'] }); const errors: string[] = []; const reporter = createReporter('monaco'); let report: NodeJS.ReadWriteStream | undefined; const magic = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; // https://stackoverflow.com/questions/25245716/remove-all-ansi-colors-styles-from-strings child.stdout.on('data', data => { let str = String(data); str = str.replace(magic, '').trim(); if (str.indexOf('Starting compilation') >= 0 || str.indexOf('File change detected') >= 0) { errors.length = 0; report = reporter.end(false); } else if (str.indexOf('Compilation complete') >= 0) { // @ts-ignore report.end(); } else if (str) { const match = /(.*\(\d+,\d+\): )(.*: )(.*)/.exec(str); if (match) { // trying to massage the message so that it matches the gulp-tsb error messages // e.g. src/vs/base/common/strings.ts(663,5): error TS2322: Type '1234' is not assignable to type 'string'. const fullpath = path.join(root, match[1]); const message = match[3]; reporter(fullpath + message); } else { reporter(str); } } }); child.on('exit', resolve); child.on('error', reject); }); }; } export const monacoTypecheckWatchTask = task.define('monaco-typecheck-watch', createTscCompileTask(true)); export const monacoTypecheckTask = task.define('monaco-typecheck', createTscCompileTask(false)); //#endregion /** * Sets a field on an object only if it's not already set, otherwise throws an error * @param obj The object to modify * @param field The field name to set * @param value The value to set */ function setUnsetField(obj: Record<string, unknown>, field: string, value: unknown) { if (obj[field] !== undefined) { throw new Error(`Field "${field}" is already set (but was expected to not be).`); } obj[field] = value; } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |