mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 12:45:39 +01:00
Fix #2843
This commit is contained in:
parent
3ad48dbde4
commit
a8878c8cfe
8 changed files with 118 additions and 79 deletions
|
|
@ -6,7 +6,8 @@
|
|||
//@ts-check
|
||||
|
||||
const glob = require('glob');
|
||||
const { copyFile, removeDir, tsc, dts, buildESM, buildAMD } = require('../build/utils');
|
||||
const { tsc, dts, buildESM, buildAMD } = require('../build/utils');
|
||||
const { copyFile, removeDir } = require('../build/fs');
|
||||
|
||||
removeDir(`out`);
|
||||
|
||||
|
|
|
|||
98
build/fs.js
Normal file
98
build/fs.js
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const REPO_ROOT = path.join(__dirname, '../');
|
||||
|
||||
const existingDirCache = new Set();
|
||||
/**
|
||||
* @param {string} dirname
|
||||
*/
|
||||
function ensureDir(dirname) {
|
||||
/** @type {string[]} */
|
||||
const dirs = [];
|
||||
|
||||
while (dirname.length > REPO_ROOT.length) {
|
||||
dirs.push(dirname);
|
||||
dirname = path.dirname(dirname);
|
||||
}
|
||||
dirs.reverse();
|
||||
dirs.forEach((dir) => {
|
||||
if (!existingDirCache.has(dir)) {
|
||||
try {
|
||||
fs.mkdirSync(dir);
|
||||
} catch (err) {}
|
||||
existingDirCache.add(dir);
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.ensureDir = ensureDir;
|
||||
|
||||
/**
|
||||
* Copy a file.
|
||||
*
|
||||
* @param {string} _source
|
||||
* @param {string} _destination
|
||||
*/
|
||||
function copyFile(_source, _destination) {
|
||||
const source = path.join(REPO_ROOT, _source);
|
||||
const destination = path.join(REPO_ROOT, _destination);
|
||||
|
||||
ensureDir(path.dirname(destination));
|
||||
fs.writeFileSync(destination, fs.readFileSync(source));
|
||||
|
||||
console.log(`Copied ${_source} to ${_destination}`);
|
||||
}
|
||||
exports.copyFile = copyFile;
|
||||
|
||||
/**
|
||||
* Remove a directory and all its contents.
|
||||
*
|
||||
* @param {string} _dirPath
|
||||
* @param {((filename:string)=>boolean)} [keep]
|
||||
*/
|
||||
function removeDir(_dirPath, keep) {
|
||||
if (typeof keep === 'undefined') {
|
||||
keep = () => false;
|
||||
}
|
||||
const dirPath = path.join(REPO_ROOT, _dirPath);
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
return;
|
||||
}
|
||||
rmDir(dirPath, _dirPath);
|
||||
console.log(`Deleted ${_dirPath}`);
|
||||
|
||||
/**
|
||||
* @param {string} dirPath
|
||||
* @param {string} relativeDirPath
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function rmDir(dirPath, relativeDirPath) {
|
||||
let keepsFiles = false;
|
||||
const entries = fs.readdirSync(dirPath);
|
||||
for (const entry of entries) {
|
||||
const filePath = path.join(dirPath, entry);
|
||||
const relativeFilePath = path.join(relativeDirPath, entry);
|
||||
if (keep(relativeFilePath)) {
|
||||
keepsFiles = true;
|
||||
continue;
|
||||
}
|
||||
if (fs.statSync(filePath).isFile()) {
|
||||
fs.unlinkSync(filePath);
|
||||
} else {
|
||||
keepsFiles = rmDir(filePath, relativeFilePath) || keepsFiles;
|
||||
}
|
||||
}
|
||||
if (!keepsFiles) {
|
||||
fs.rmdirSync(dirPath);
|
||||
}
|
||||
return keepsFiles;
|
||||
}
|
||||
}
|
||||
exports.removeDir = removeDir;
|
||||
|
|
@ -15,7 +15,8 @@
|
|||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const { REPO_ROOT, removeDir, readFiles, writeFiles } = require('../build/utils');
|
||||
const { REPO_ROOT, readFiles, writeFiles } = require('../build/utils');
|
||||
const { removeDir } = require('../build/fs');
|
||||
const ts = require('typescript');
|
||||
/**@type { IMetadata } */
|
||||
const metadata = require('../metadata.js');
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@
|
|||
const glob = require('glob');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const { REPO_ROOT, prettier, ensureDir } = require('./utils');
|
||||
const { REPO_ROOT } = require('./utils');
|
||||
const { ensureDir } = require('./fs');
|
||||
|
||||
const customFeatureLabels = {
|
||||
'vs/editor/browser/controller/coreCommands': 'coreCommands',
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ const fs = require('fs');
|
|||
const path = require('path');
|
||||
const http = require('http');
|
||||
const yaserver = require('yaserver');
|
||||
const { REPO_ROOT, ensureDir } = require('./utils');
|
||||
const { REPO_ROOT } = require('./utils');
|
||||
const { ensureDir } = require('./fs');
|
||||
|
||||
const WEBSITE_GENERATED_PATH = path.join(REPO_ROOT, 'website/playground/new-samples');
|
||||
|
||||
|
|
|
|||
|
|
@ -12,82 +12,11 @@ const esbuild = require('esbuild');
|
|||
/** @type {any} */
|
||||
const alias = require('esbuild-plugin-alias');
|
||||
const glob = require('glob');
|
||||
const { ensureDir } = require('./fs');
|
||||
|
||||
const REPO_ROOT = path.join(__dirname, '../');
|
||||
exports.REPO_ROOT = REPO_ROOT;
|
||||
|
||||
const existingDirCache = new Set();
|
||||
/**
|
||||
* @param {string} dirname
|
||||
*/
|
||||
function ensureDir(dirname) {
|
||||
/** @type {string[]} */
|
||||
const dirs = [];
|
||||
|
||||
while (dirname.length > REPO_ROOT.length) {
|
||||
dirs.push(dirname);
|
||||
dirname = path.dirname(dirname);
|
||||
}
|
||||
dirs.reverse();
|
||||
dirs.forEach((dir) => {
|
||||
if (!existingDirCache.has(dir)) {
|
||||
try {
|
||||
fs.mkdirSync(dir);
|
||||
} catch (err) {}
|
||||
existingDirCache.add(dir);
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.ensureDir = ensureDir;
|
||||
|
||||
/**
|
||||
* Copy a file.
|
||||
*
|
||||
* @param {string} _source
|
||||
* @param {string} _destination
|
||||
*/
|
||||
function copyFile(_source, _destination) {
|
||||
const source = path.join(REPO_ROOT, _source);
|
||||
const destination = path.join(REPO_ROOT, _destination);
|
||||
|
||||
ensureDir(path.dirname(destination));
|
||||
fs.writeFileSync(destination, fs.readFileSync(source));
|
||||
|
||||
console.log(`Copied ${_source} to ${_destination}`);
|
||||
}
|
||||
exports.copyFile = copyFile;
|
||||
|
||||
/**
|
||||
* Remove a directory and all its contents.
|
||||
*
|
||||
* @param {string} _dirPath
|
||||
*/
|
||||
function removeDir(_dirPath) {
|
||||
const dirPath = path.join(REPO_ROOT, _dirPath);
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
return;
|
||||
}
|
||||
rmDir(dirPath);
|
||||
console.log(`Deleted ${_dirPath}`);
|
||||
|
||||
/**
|
||||
* @param {string} dirPath
|
||||
*/
|
||||
function rmDir(dirPath) {
|
||||
const entries = fs.readdirSync(dirPath);
|
||||
for (const entry of entries) {
|
||||
const filePath = path.join(dirPath, entry);
|
||||
if (fs.statSync(filePath).isFile()) {
|
||||
fs.unlinkSync(filePath);
|
||||
} else {
|
||||
rmDir(filePath);
|
||||
}
|
||||
}
|
||||
fs.rmdirSync(dirPath);
|
||||
}
|
||||
}
|
||||
exports.removeDir = removeDir;
|
||||
|
||||
/**
|
||||
* Launch the typescript compiler synchronously over a project.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ const path = require('path');
|
|||
const fs = require('fs');
|
||||
const cp = require('child_process');
|
||||
const CleanCSS = require('clean-css');
|
||||
const { REPO_ROOT, removeDir, readFiles, writeFiles } = require('./utils');
|
||||
const { REPO_ROOT, readFiles, writeFiles } = require('./utils');
|
||||
const { removeDir } = require('./fs');
|
||||
|
||||
/** @type {string} */
|
||||
const MONACO_EDITOR_VERSION = (() => {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,15 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 esbuild = require('esbuild');
|
||||
const path = require('path');
|
||||
const { removeDir } = require('../../build/utils');
|
||||
const { removeDir } = require('../../build/fs');
|
||||
|
||||
removeDir(path.join(__dirname, 'dist'));
|
||||
removeDir('samples/browser-esm-esbuild/dist', (entry) => /index.html$/.test(entry));
|
||||
|
||||
const workerEntryPoints = [
|
||||
'vs/language/json/json.worker.js',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue