build-monaco-editor-core-pkg.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { rm } from 'fs/promises';
  2. import { join } from 'path';
  3. import { PackageJson, group, gitShallowClone, run, writeJsonFile, getNightlyVersion } from '../lib';
  4. import { getNightlyEnv } from './env';
  5. const selfPath = __dirname;
  6. const rootPath = join(selfPath, '..', '..');
  7. const dependenciesPath = join(rootPath, 'dependencies');
  8. const vscodePath = join(dependenciesPath, 'vscode');
  9. const monacoEditorPackageJsonPath = join(rootPath, 'package.json');
  10. async function prepareMonacoEditorCoreReleaseStableOrNightly() {
  11. const monacoEditorPackageJson = require(monacoEditorPackageJsonPath) as {
  12. version: string;
  13. vscodeRef: string;
  14. };
  15. let version: string;
  16. let ref: string;
  17. const arg = process.argv[2];
  18. if (arg === 'stable') {
  19. version = monacoEditorPackageJson.version;
  20. ref = monacoEditorPackageJson.vscodeRef;
  21. } else if (arg === 'nightly') {
  22. version = getNightlyVersion(
  23. monacoEditorPackageJson.version,
  24. getNightlyEnv().PRERELEASE_VERSION
  25. );
  26. ref = getNightlyEnv().VSCODE_REF;
  27. } else {
  28. throw new Error('Invalid argument');
  29. }
  30. await prepareMonacoEditorCoreRelease(version, ref);
  31. // npm package is now in dependencies/vscode/out-monaco-editor-core, ready to be published
  32. }
  33. async function prepareMonacoEditorCoreRelease(version: string, vscodeRef: string) {
  34. await rm(dependenciesPath, { force: true, recursive: true });
  35. let vscodeCommitId: string;
  36. await group('Checkout vscode', async () => {
  37. const result = await gitShallowClone(
  38. vscodePath,
  39. 'https://github.com/microsoft/vscode.git',
  40. vscodeRef
  41. );
  42. vscodeCommitId = result.commitId;
  43. });
  44. await group('Checkout vscode-loc', async () => {
  45. await gitShallowClone(
  46. // Must be a sibling to the vscode repository
  47. 'dependencies/vscode-loc',
  48. 'https://github.com/microsoft/vscode-loc.git',
  49. 'main'
  50. );
  51. });
  52. await group('Set Version', async () => {
  53. const monacoEditorCorePackageJsonSourcePath = join(vscodePath, './build/monaco/package.json');
  54. const packageJson = require(monacoEditorCorePackageJsonSourcePath) as PackageJson;
  55. packageJson.version = version;
  56. // This ensures we can always figure out which commit monaco-editor-core was built from
  57. packageJson.vscodeCommitId = vscodeCommitId;
  58. await writeJsonFile(monacoEditorCorePackageJsonSourcePath, packageJson);
  59. });
  60. await group('Building & Testing', async () => {
  61. // Install dependencies
  62. await buildAndTest();
  63. });
  64. }
  65. async function buildAndTest() {
  66. await run('npm install', { cwd: vscodePath });
  67. await run('npm run playwright-install', { cwd: vscodePath });
  68. // Run checks and compilation
  69. await run('npm run gulp hygiene', { cwd: vscodePath });
  70. await run('npm run valid-layers-check', { cwd: vscodePath });
  71. await run('npm run compile', { cwd: join(vscodePath, 'build') });
  72. await run('npm run eslint', { cwd: vscodePath });
  73. await run('npm run monaco-compile-check', { cwd: vscodePath });
  74. await run('npm run --max_old_space_size=4095 compile', { cwd: vscodePath });
  75. // Build editor distribution
  76. await run('npm run gulp editor-distro', { cwd: vscodePath });
  77. return; // To save CI time.
  78. // Run browser tests
  79. await run('npm run test-browser --browser chromium', { cwd: vscodePath });
  80. // TypeScript typings test
  81. await run('mkdir typings-test', { cwd: vscodePath });
  82. const typingsTestDir = join(vscodePath, 'typings-test');
  83. await run('npm init -yp', { cwd: typingsTestDir });
  84. await run('../node_modules/.bin/tsc --init', { cwd: typingsTestDir });
  85. await run('echo "import \'../out-monaco-editor-core\';" > a.ts', { cwd: typingsTestDir });
  86. await run('../node_modules/.bin/tsc --noEmit', { cwd: typingsTestDir });
  87. // Monaco tests
  88. const testMonacoDir = join(vscodePath, 'test/monaco');
  89. await run('npm run esm-check', { cwd: testMonacoDir });
  90. await run('npm run bundle-webpack', { cwd: testMonacoDir });
  91. await run('npm run compile', { cwd: testMonacoDir });
  92. await run('npm test', { cwd: testMonacoDir });
  93. }
  94. //buildAndTest();
  95. //prepareMonacoEditorCoreRelease('0.99.0', 'main');
  96. prepareMonacoEditorCoreReleaseStableOrNightly();