Skip to content

Commit

Permalink
changes for Theia consumption
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-grant-work committed Jul 11, 2022
1 parent c3511e6 commit a16ce8a
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 35 deletions.
39 changes: 25 additions & 14 deletions build/gulpfile.editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const extractEditorSrcTask = task.define('extract-editor-src', () => {
apiusages,
extrausages
],
shakeLevel: 2, // 0-Files, 1-InnerFile, 2-ClassMembers
shakeLevel: 0, // 0-Files, 1-InnerFile, 2-ClassMembers
importIgnorePattern: /(^vs\/css!)/,
destRoot: path.join(root, 'out-editor-src'),
redirects: []
Expand Down Expand Up @@ -103,7 +103,7 @@ const minifyEditorAMDTask = task.define('minify-editor-amd', common.minifyTask('
const createESMSourcesAndResourcesTask = task.define('extract-editor-esm', () => {
standalone.createESMSourcesAndResources2({
srcFolder: './out-editor-src',
outFolder: './out-editor-esm',
outFolder: './out-monaco-editor-core/src',
outResourcesFolder: './out-monaco-editor-core/esm',
ignores: [
'inlineEntryPoint:0.ts',
Expand All @@ -126,15 +126,15 @@ const createESMSourcesAndResourcesTask = task.define('extract-editor-esm', () =>
const compileEditorESMTask = task.define('compile-editor-esm', () => {
const KEEP_PREV_ANALYSIS = false;
const FAIL_ON_PURPOSE = false;
console.log(`Launching the TS compiler at ${path.join(__dirname, '../out-editor-esm')}...`);
console.log(`Launching the TS compiler at ${path.join(__dirname, '../out-monaco-editor-core/src')}...`);
let result;
if (process.platform === 'win32') {
result = cp.spawnSync(`..\\node_modules\\.bin\\tsc.cmd`, {
cwd: path.join(__dirname, '../out-editor-esm')
result = cp.spawnSync(`..\\..\\node_modules\\.bin\\tsc.cmd`, {
cwd: path.join(__dirname, '../out-monaco-editor-core/src')
});
} else {
result = cp.spawnSync(`node`, [`../node_modules/.bin/tsc`], {
cwd: path.join(__dirname, '../out-editor-esm')
result = cp.spawnSync(`node`, [`../../node_modules/.bin/tsc`], {
cwd: path.join(__dirname, '../out-monaco-editor-core/src')
});
}

Expand All @@ -148,7 +148,7 @@ const compileEditorESMTask = task.define('compile-editor-esm', () => {
const cleanDestPath = (keepPrevAnalysis ? Promise.resolve() : util.rimraf(destPath)());
return cleanDestPath.then(() => {
// build a list of files to copy
const files = util.rreddir(path.join(__dirname, '../out-editor-esm'));
const files = util.rreddir(path.join(__dirname, '../out-monaco-editor-core/src'));

if (!keepPrevAnalysis) {
fs.mkdirSync(destPath);
Expand Down Expand Up @@ -235,6 +235,16 @@ const appendJSToESMImportsTask = task.define('append-js-to-esm-imports', () => {
}
});

const deleteIrrelevantSourceFiles = task.define('delete-irrelevant-source-files', async () => {
SRC_DIR = path.join(__dirname, '../out-monaco-editor-core/src');
await Promise.all(fs.readdirSync(SRC_DIR).map(file => {
if (file !== 'vs') {
return util.rimraf(path.join(SRC_DIR, file))();
}
return undefined;
}));
});

/**
* @param {string} contents
*/
Expand Down Expand Up @@ -399,15 +409,16 @@ gulp.task('editor-distro',
),
extractEditorSrcTask,
task.parallel(
task.series(
compileEditorAMDTask,
optimizeEditorAMDTask,
minifyEditorAMDTask
),
// task.series(
// compileEditorAMDTask,
// optimizeEditorAMDTask,
// minifyEditorAMDTask
// ),
task.series(
createESMSourcesAndResourcesTask,
compileEditorESMTask,
appendJSToESMImportsTask
appendJSToESMImportsTask,
deleteIrrelevantSourceFiles
)
),
finalEditorResourcesTask
Expand Down
10 changes: 8 additions & 2 deletions build/lib/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ function extractEditor(options) {
compilerOptions.noEmit = false;
compilerOptions.noUnusedLocals = false;
compilerOptions.preserveConstEnums = false;
compilerOptions.declaration = false;
compilerOptions.declaration = true;
compilerOptions.sourceMap = true;
compilerOptions.declarationMap = true;
compilerOptions.moduleResolution = ts.ModuleResolutionKind.Classic;
options.compilerOptions = compilerOptions;
console.log(`Running tree shaker with shakeLevel ${tss.toStringShakeLevel(options.shakeLevel)}`);
Expand Down Expand Up @@ -135,7 +137,7 @@ function createESMSourcesAndResources2(options) {
}
if (file === 'tsconfig.json') {
const tsConfig = JSON.parse(fs.readFileSync(path.join(SRC_FOLDER, file)).toString());
tsConfig.compilerOptions.module = 'es6';
tsConfig.compilerOptions.module = 'commonjs';
tsConfig.compilerOptions.outDir = path.join(path.relative(OUT_FOLDER, OUT_RESOURCES_FOLDER), 'vs').replace(/\\/g, '/');
write(getDestAbsoluteFilePath(file), JSON.stringify(tsConfig, null, '\t'));
continue;
Expand Down Expand Up @@ -177,6 +179,10 @@ function createESMSourcesAndResources2(options) {
if (!/(^\.\/)|(^\.\.\/)/.test(relativePath)) {
relativePath = './' + relativePath;
}
// Added to handle imports from src/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/ast.ts to vs/editor/common/model.ts
if (!relativePath.match(/[^/.]/)) {
relativePath = `../` + relativePath + '/' + path.basename(importedFilename);
}
fileContents = (fileContents.substring(0, pos + 1)
+ relativePath
+ fileContents.substring(end + 1));
Expand Down
10 changes: 8 additions & 2 deletions build/lib/standalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export function extractEditor(options: tss.ITreeShakingOptions & { destRoot: str
compilerOptions.noEmit = false;
compilerOptions.noUnusedLocals = false;
compilerOptions.preserveConstEnums = false;
compilerOptions.declaration = false;
compilerOptions.declaration = true;
compilerOptions.sourceMap = true;
compilerOptions.declarationMap = true;
compilerOptions.moduleResolution = ts.ModuleResolutionKind.Classic;


Expand Down Expand Up @@ -161,7 +163,7 @@ export function createESMSourcesAndResources2(options: IOptions2): void {

if (file === 'tsconfig.json') {
const tsConfig = JSON.parse(fs.readFileSync(path.join(SRC_FOLDER, file)).toString());
tsConfig.compilerOptions.module = 'es6';
tsConfig.compilerOptions.module = 'commonjs';
tsConfig.compilerOptions.outDir = path.join(path.relative(OUT_FOLDER, OUT_RESOURCES_FOLDER), 'vs').replace(/\\/g, '/');
write(getDestAbsoluteFilePath(file), JSON.stringify(tsConfig, null, '\t'));
continue;
Expand Down Expand Up @@ -206,6 +208,10 @@ export function createESMSourcesAndResources2(options: IOptions2): void {
if (!/(^\.\/)|(^\.\.\/)/.test(relativePath)) {
relativePath = './' + relativePath;
}
// Added to handle imports from src/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/ast.ts to vs/editor/common/model.ts, which looks to this algorithm like it should be ../..
if (!relativePath.match(/[^/.]/)) {
relativePath = `../` + relativePath + '/' + path.basename(importedFilename);
}
fileContents = (
fileContents.substring(0, pos + 1)
+ relativePath
Expand Down
13 changes: 8 additions & 5 deletions build/monaco/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"name": "monaco-editor-core",
"private": true,
"version": "0.0.0",
"name": "@theia/monaco-editor-core",
"version": "1.67.2",
"description": "A browser based code editor",
"author": "Microsoft Corporation",
"license": "MIT",
"typings": "./esm/vs/editor/editor.api.d.ts",
"module": "./esm/vs/editor/editor.main.js",
"main": "./esm/vs/editor/editor.main.js",
"repository": {
"type": "git",
"url": "https://github.com/microsoft/vscode"
"url": "https://github.com/theia-ide/vscode"
},
"bugs": {
"url": "https://github.com/microsoft/vscode/issues"
"url": "https://github.com/eclipse-theia/theia/issues"
},
"publishConfig": {
"access": "public"
}
}
12 changes: 1 addition & 11 deletions src/vs/base/browser/dompurify/dompurify.js
Original file line number Diff line number Diff line change
Expand Up @@ -1370,15 +1370,5 @@ define(function () { return purify; });
// ESM-comment-end

// ESM-uncomment-begin
// export default purify;
// export const version = purify.version;
// export const isSupported = purify.isSupported;
// export const sanitize = purify.sanitize;
// export const setConfig = purify.setConfig;
// export const clearConfig = purify.clearConfig;
// export const isValidAttribute = purify.isValidAttribute;
// export const addHook = purify.addHook;
// export const removeHook = purify.removeHook;
// export const removeHooks = purify.removeHooks;
// export const removeAllHooks = purify.removeAllHooks;
// module.exports = purify;
// ESM-uncomment-end
1 change: 0 additions & 1 deletion src/vs/base/common/marked/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -2945,5 +2945,4 @@

// ESM-uncomment-begin
// })();
// export var marked = (__marked_exports || exports);
// ESM-uncomment-end

0 comments on commit a16ce8a

Please sign in to comment.