Skip to content

Commit

Permalink
Use gulp to build esm version
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Mar 28, 2024
1 parent 1848939 commit 920c3b0
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 86 deletions.
21 changes: 7 additions & 14 deletions build/gulpfile.editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ const extractEditorSrcTask = task.define('extract-editor-src', () => {
// Disable mangling for the editor, as it complicates debugging & quite a few users rely on private/protected fields.
const compileEditorAMDTask = task.define('compile-editor-amd', compilation.compileTask('out-editor-src', 'out-editor-build', true, { disableMangle: true }));

const compileEditorESMTaskPipeline = task.define('compile-editor-esm', compilation.compileTask('out-editor-esm', 'out-monaco-editor-core/esm', true, { disableMangle: true, transformConstEnum: 1 }));

const optimizeEditorAMDTask = task.define('optimize-editor-amd', optimize.optimizeTask(
{
out: 'out-editor',
Expand Down Expand Up @@ -120,6 +122,8 @@ const createESMSourcesAndResourcesTask = task.define('extract-editor-esm', () =>
ignores: [
'inlineEntryPoint:0.ts',
'inlineEntryPoint:1.ts',
'inlineEntryPoint.0.ts',
'inlineEntryPoint.1.ts',
'vs/loader.js',
'vs/base/worker/workerMain.ts',
'vs/nls.ts',
Expand All @@ -136,29 +140,18 @@ const compileEditorESMTask = task.define('compile-editor-esm', () => {
console.log(`Launching the TS compiler at ${path.join(__dirname, '../out-editor-esm')}...`);
let result;
if (process.platform === 'win32') {
result = cp.spawnSync(`..\\node_modules\\.bin\\tspc.cmd`, {
result = cp.spawnSync(`..\\node_modules\\.bin\\tsc.cmd`, {
cwd: path.join(__dirname, '../out-editor-esm')
});
} else {
result = cp.spawnSync(`node`, [`../node_modules/.bin/tspc`], {
result = cp.spawnSync(`node`, [`../node_modules/.bin/tsc`], {
cwd: path.join(__dirname, '../out-editor-esm')
});
}

console.log(result.stdout.toString());
console.log(result.stderr.toString());

// cause here have a type resolve error, so we should ignore the error
// vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/ast.ts(9,28): error TS2307: Cannot find module '../..' or its corresponding type declarations.
// vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/bracketPairsTree.ts(9,28): error TS2307: Cannot find module '../..' or its corresponding type declarations.
// in the transpiled code, there is no type, so it is ok to ignore the error
const errors = result.stdout.toString().trim().split('\n');

if (errors.length === 2 && errors.every(line => line.includes('Cannot find module'))) {
console.log('The TS Compilation failed, but it is expected');
return;
}

if (FAIL_ON_PURPOSE || result.status !== 0) {
console.log(`The TS Compilation failed, preparing analysis folder...`);
const destPath = path.join(__dirname, '../../vscode-monaco-editor-esm-analysis');
Expand Down Expand Up @@ -425,7 +418,7 @@ gulp.task('editor-distro',
),
task.series(
createESMSourcesAndResourcesTask,
compileEditorESMTask,
compileEditorESMTaskPipeline,
appendJSToESMImportsTask,
)
),
Expand Down
9 changes: 9 additions & 0 deletions build/lib/compilation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion build/lib/compilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function createCompile(src: string, build: boolean, emitError: boolean, transpil

const projectPath = path.join(__dirname, '../../', src, 'tsconfig.json');
const overrideOptions = { ...getTypeScriptCompilerOptions(src), inlineSources: Boolean(build) };

if (!build) {
overrideOptions.inlineSourceMap = true;
}
Expand Down Expand Up @@ -114,7 +115,7 @@ export function transpileTask(src: string, out: string, swc: boolean): task.Stre
return task;
}

export function compileTask(src: string, out: string, build: boolean, options: { disableMangle?: boolean } = {}): task.StreamTask {
export function compileTask(src: string, out: string, build: boolean, options: { disableMangle?: boolean; transformConstEnum?: boolean } = {}): task.StreamTask {

const task = () => {

Expand Down Expand Up @@ -156,6 +157,7 @@ export function compileTask(src: string, out: string, build: boolean, options: {
.pipe(mangleStream)
.pipe(generator.stream)
.pipe(compile())
.pipe(options?.transformConstEnum ? transformConstEnum() : es.through())
.pipe(gulp.dest(out));
};

Expand Down Expand Up @@ -340,3 +342,12 @@ export const watchApiProposalNamesTask = task.define('watch-api-proposal-names',
.pipe(util.debounce(task))
.pipe(gulp.dest('src'));
});

function transformConstEnum() {
return es.map((file: File, cb: any) => {
if (/\.ts$/.test(file.path)) {
file.contents = Buffer.from(file.contents.toString().replace(/const enum/g, 'enum'));
}
cb(null, file);
});
}
21 changes: 15 additions & 6 deletions build/lib/standalone.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 16 additions & 6 deletions build/lib/standalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,10 @@ export function createESMSourcesAndResources2(options: IOptions2): void {
const tsConfig = JSON.parse(fs.readFileSync(path.join(SRC_FOLDER, file)).toString());
tsConfig.compilerOptions.module = 'commonjs';
tsConfig.compilerOptions.outDir = path.join(path.relative(OUT_FOLDER, OUT_RESOURCES_FOLDER), 'vs').replace(/\\/g, '/');
tsConfig.compilerOptions.preserveConstEnums = false;
tsConfig.compilerOptions.preserveConstEnums = true;
tsConfig.compilerOptions.declaration = true;
tsConfig.compilerOptions.noEmitOnError = false;

tsConfig.compilerOptions.plugins = [
{ transform: 'ts-transform-const-enum' }, // replaces 'compilerOptions.preserveConstEnums'
{ transform: 'ts-transform-const-enum', afterDeclarations: true }, // modifies declaration files
];
write(getDestAbsoluteFilePath(file), JSON.stringify(tsConfig, null, '\t'));
continue;
}
Expand All @@ -192,11 +188,19 @@ export function createESMSourcesAndResources2(options: IOptions2): void {
const end = info.importedFiles[i].end;

let importedFilepath: string;
let importedIsAFile = false;
if (/^vs\/css!/.test(importedFilename)) {
importedFilepath = importedFilename.substr('vs/css!'.length) + '.css';
} else {
importedFilepath = importedFilename;
}

// try to resolve the imported file path
const filePath = path.join(SRC_FOLDER, importedFilepath);
if (fs.existsSync(filePath + '.ts')) {
importedIsAFile= true;
}

if (/(^\.\/)|(^\.\.\/)/.test(importedFilepath)) {
importedFilepath = path.join(path.dirname(file), importedFilepath);
}
Expand All @@ -207,7 +211,13 @@ export function createESMSourcesAndResources2(options: IOptions2): void {
} else if (importedFilepath === path.dirname(path.dirname(file)).replace(/\\/g, '/')) {
relativePath = '../../' + path.basename(path.dirname(path.dirname(file)));
} else {
relativePath = path.relative(path.dirname(file), importedFilepath);
if (importedIsAFile) {
importedFilepath = importedFilepath + '.ts';
relativePath = path.relative(path.dirname(file), importedFilepath);
relativePath = relativePath.replace(/\.ts$/, '');
} else{
relativePath = path.relative(path.dirname(file), importedFilepath);
}
}
relativePath = relativePath.replace(/\\/g, '/');
if (!/(^\.\/)|(^\.\.\/)/.test(relativePath)) {
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
"native-watchdog": "^1.4.1",
"node-pty": "1.1.0-beta6",
"tas-client-umd": "0.1.8",
"ts-transform-const-enum": "^0.0.1",
"v8-inspect-profiler": "^0.1.0",
"vscode-oniguruma": "1.7.0",
"vscode-regexpp": "^3.1.0",
Expand Down Expand Up @@ -209,7 +208,6 @@
"style-loader": "^3.3.2",
"ts-loader": "^9.4.2",
"ts-node": "^10.9.1",
"ts-patch": "^3.1.2",
"tsec": "0.2.7",
"typescript": "^5.4.0-dev.20240206",
"typescript-formatter": "7.1.0",
Expand Down
60 changes: 3 additions & 57 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2553,7 +2553,7 @@ chalk@^4.0.0, chalk@^4.1.0:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

chalk@^4.1.2, chalk@^4.x:
chalk@^4.x:
version "4.1.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
Expand Down Expand Up @@ -4500,11 +4500,6 @@ function-bind@^1.1.1:
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d"
integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==

function-bind@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.2.tgz#2c02d864d97f3ea6c8830c464cbd11ab6eab7a1c"
integrity sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==

functional-red-black-tree@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327"
Expand Down Expand Up @@ -4731,15 +4726,6 @@ global-prefix@^1.0.1:
is-windows "^1.0.1"
which "^1.2.14"

global-prefix@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/global-prefix/-/global-prefix-3.0.0.tgz#fc85f73064df69f50421f47f883fe5b913ba9b97"
integrity sha512-awConJSVCHVGND6x3tmMaKcQvwXLhjdkmomy2W+Goaui8YPgYgXJZewhg3fWC+DlfqqQuWg8AwqjGTD2nAPVWg==
dependencies:
ini "^1.3.5"
kind-of "^6.0.2"
which "^1.3.1"

globals@^11.1.0, globals@^11.7.0:
version "11.12.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
Expand Down Expand Up @@ -5159,13 +5145,6 @@ has@^1.0.3:
dependencies:
function-bind "^1.1.1"

hasown@^2.0.0:
version "2.0.2"
resolved "https://registry.yarnpkg.com/hasown/-/hasown-2.0.2.tgz#003eaf91be7adc372e84ec59dc37252cedb80003"
integrity sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==
dependencies:
function-bind "^1.1.2"

[email protected]:
version "1.2.0"
resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
Expand Down Expand Up @@ -5365,7 +5344,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=

ini@^1.3.4, ini@^1.3.5, ini@~1.3.0:
ini@^1.3.4, ini@~1.3.0:
version "1.3.8"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==
Expand Down Expand Up @@ -5504,13 +5483,6 @@ is-core-module@^2.1.0:
dependencies:
has "^1.0.3"

is-core-module@^2.13.0:
version "2.13.1"
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.13.1.tgz#ad0d7532c6fea9da1ebdc82742d74525c6273384"
integrity sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==
dependencies:
hasown "^2.0.0"

is-core-module@^2.9.0:
version "2.11.0"
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.11.0.tgz#ad4cb3e3863e814523c96f3f58d26cc570ff0144"
Expand Down Expand Up @@ -8366,15 +8338,6 @@ resolve@^1.20.0:
path-parse "^1.0.7"
supports-preserve-symlinks-flag "^1.0.0"

resolve@^1.22.2:
version "1.22.8"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.8.tgz#b6c87a9f2aa06dfab52e3d70ac8cde321fa5a48d"
integrity sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==
dependencies:
is-core-module "^2.13.0"
path-parse "^1.0.7"
supports-preserve-symlinks-flag "^1.0.0"

responselike@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/responselike/-/responselike-2.0.1.tgz#9a0bc8fdc252f3fb1cca68b016591059ba1422bc"
Expand Down Expand Up @@ -9556,23 +9519,6 @@ ts-node@^10.9.1:
v8-compile-cache-lib "^3.0.1"
yn "3.1.1"

ts-patch@^3.1.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/ts-patch/-/ts-patch-3.1.2.tgz#9d4832eca34ed0b9eb1f8456cb00c941f50b442b"
integrity sha512-n58F5AqjUMdp9RAKq+E1YBkmONltPVbt1nN+wrmZXoYZek6QcvaTuqvKMhYhr5BxtC53kD/exxIPA1cP1RQxsA==
dependencies:
chalk "^4.1.2"
global-prefix "^3.0.0"
minimist "^1.2.8"
resolve "^1.22.2"
semver "^7.5.4"
strip-ansi "^6.0.1"

ts-transform-const-enum@^0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/ts-transform-const-enum/-/ts-transform-const-enum-0.0.1.tgz#eef558d993931967f29dcc776474177e41ad71a3"
integrity sha512-tsOxCy8XDEcYvG9lE5Yud2YN11F4rnr6taoNyRb0CYeKAa5WwvjY8RToIaTcLNbu7UO7KA1HajhPCeiuYDl0Hw==

[email protected]:
version "0.2.7"
resolved "https://registry.yarnpkg.com/tsec/-/tsec-0.2.7.tgz#be530025907037ed57f37fc7625b6a7e3658fe43"
Expand Down Expand Up @@ -10188,7 +10134,7 @@ which-typed-array@^1.1.11, which-typed-array@^1.1.2:
gopd "^1.0.1"
has-tostringtag "^1.0.0"

which@^1.2.14, which@^1.2.9, which@^1.3.1:
which@^1.2.14, which@^1.2.9:
version "1.3.1"
resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a"
integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==
Expand Down

0 comments on commit 920c3b0

Please sign in to comment.