@codingame/monaco-vscode-api 1.78.6 → 1.78.8
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/dist/monaco-treemending.js +41 -5
- package/monaco-editor-treemending.patch +531 -531
- package/package.json +2 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as fs from 'fs/promises';
|
|
2
2
|
import * as path from 'path';
|
|
3
|
+
import * as os from 'os';
|
|
3
4
|
import { createRequire } from 'node:module';
|
|
4
5
|
|
|
5
6
|
function Diff() {}
|
|
@@ -832,10 +833,35 @@ function applyPatches(uniDiff, options) {
|
|
|
832
833
|
|
|
833
834
|
const require = createRequire(import.meta.url);
|
|
834
835
|
async function run() {
|
|
836
|
+
const ownPackageJson = JSON.parse((await fs.readFile(require.resolve('../package.json'))).toString('utf-8'));
|
|
837
|
+
const expectedMonacoVersion = ownPackageJson.peerDependencies['monaco-editor'];
|
|
835
838
|
const patchContent = await fs.readFile(require.resolve('../monaco-editor-treemending.patch'));
|
|
836
|
-
const monacoDirectory = path.
|
|
839
|
+
const monacoDirectory = path.dirname(require.resolve('monaco-editor/monaco.d.ts', { paths: [process.cwd()] }));
|
|
840
|
+
const monacoEsmDirectory = path.resolve(monacoDirectory, 'esm');
|
|
841
|
+
const monacoPackageJsonFile = path.resolve(monacoDirectory, 'package.json');
|
|
842
|
+
const monacoPackageJson = JSON.parse((await fs.readFile(monacoPackageJsonFile)).toString('utf-8'));
|
|
843
|
+
const monacoVersion = monacoPackageJson.version;
|
|
844
|
+
if (expectedMonacoVersion !== monacoVersion) {
|
|
845
|
+
console.error(`Wrong monaco-editor version: expecting ${expectedMonacoVersion}, got ${monacoVersion}`);
|
|
846
|
+
process.exit(1);
|
|
847
|
+
}
|
|
848
|
+
const alreadyPatched = monacoPackageJson.treemended ?? false;
|
|
849
|
+
if (alreadyPatched) {
|
|
850
|
+
// eslint-disable-next-line no-console
|
|
851
|
+
console.info('Monaco-editor has already been tree-mended, ignoring');
|
|
852
|
+
process.exit(0);
|
|
853
|
+
}
|
|
854
|
+
// pnpm WA: copy files to a temp directory and patch files there. When finished copy back
|
|
855
|
+
let workingDir = monacoEsmDirectory;
|
|
856
|
+
let tmpDir;
|
|
857
|
+
const havePnpm = monacoEsmDirectory.includes('.pnpm');
|
|
858
|
+
if (havePnpm) {
|
|
859
|
+
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'esm-'));
|
|
860
|
+
workingDir = path.resolve(tmpDir, 'esm');
|
|
861
|
+
await fs.cp(monacoEsmDirectory, workingDir, { recursive: true });
|
|
862
|
+
}
|
|
837
863
|
function getMonacoFile(diff) {
|
|
838
|
-
return path.resolve(
|
|
864
|
+
return path.resolve(workingDir, diff.oldFileName.slice('a/'.length));
|
|
839
865
|
}
|
|
840
866
|
await new Promise((resolve, reject) => {
|
|
841
867
|
applyPatches(patchContent.toString('utf-8'), {
|
|
@@ -873,10 +899,20 @@ async function run() {
|
|
|
873
899
|
}
|
|
874
900
|
});
|
|
875
901
|
});
|
|
876
|
-
|
|
877
|
-
|
|
902
|
+
// in case of pnpm copy the temp esm back
|
|
903
|
+
if (havePnpm) {
|
|
904
|
+
await fs.cp(tmpDir, monacoDirectory, { recursive: true, force: true });
|
|
905
|
+
}
|
|
906
|
+
// Mark monaco as treemended
|
|
907
|
+
await fs.writeFile(monacoPackageJsonFile, JSON.stringify({
|
|
908
|
+
...monacoPackageJson,
|
|
909
|
+
treemended: true
|
|
910
|
+
}, null, 2));
|
|
878
911
|
// eslint-disable-next-line no-console
|
|
879
912
|
console.info('Monaco-editor was tree-mended');
|
|
880
|
-
|
|
913
|
+
process.exit(0);
|
|
914
|
+
}
|
|
915
|
+
run().catch(err => {
|
|
881
916
|
console.error(err);
|
|
917
|
+
process.exit(1);
|
|
882
918
|
});
|