Skip to content

Commit 721df02

Browse files
committed
Use gulp to build esm version
1 parent 1848939 commit 721df02

File tree

7 files changed

+62
-87
lines changed

7 files changed

+62
-87
lines changed

build/gulpfile.editor.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ const extractEditorSrcTask = task.define('extract-editor-src', () => {
8888
// Disable mangling for the editor, as it complicates debugging & quite a few users rely on private/protected fields.
8989
const compileEditorAMDTask = task.define('compile-editor-amd', compilation.compileTask('out-editor-src', 'out-editor-build', true, { disableMangle: true }));
9090

91+
const compileEditorESMTaskPipeline = task.define('compile-editor-esm', compilation.compileTask('out-editor-esm', 'out-monaco-editor-core/esm', true, { disableMangle: true, transformConstEnum: 1 }));
92+
9193
const optimizeEditorAMDTask = task.define('optimize-editor-amd', optimize.optimizeTask(
9294
{
9395
out: 'out-editor',
@@ -136,29 +138,18 @@ const compileEditorESMTask = task.define('compile-editor-esm', () => {
136138
console.log(`Launching the TS compiler at ${path.join(__dirname, '../out-editor-esm')}...`);
137139
let result;
138140
if (process.platform === 'win32') {
139-
result = cp.spawnSync(`..\\node_modules\\.bin\\tspc.cmd`, {
141+
result = cp.spawnSync(`..\\node_modules\\.bin\\tsc.cmd`, {
140142
cwd: path.join(__dirname, '../out-editor-esm')
141143
});
142144
} else {
143-
result = cp.spawnSync(`node`, [`../node_modules/.bin/tspc`], {
145+
result = cp.spawnSync(`node`, [`../node_modules/.bin/tsc`], {
144146
cwd: path.join(__dirname, '../out-editor-esm')
145147
});
146148
}
147149

148150
console.log(result.stdout.toString());
149151
console.log(result.stderr.toString());
150152

151-
// cause here have a type resolve error, so we should ignore the error
152-
// vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/ast.ts(9,28): error TS2307: Cannot find module '../..' or its corresponding type declarations.
153-
// vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/bracketPairsTree.ts(9,28): error TS2307: Cannot find module '../..' or its corresponding type declarations.
154-
// in the transpiled code, there is no type, so it is ok to ignore the error
155-
const errors = result.stdout.toString().trim().split('\n');
156-
157-
if (errors.length === 2 && errors.every(line => line.includes('Cannot find module'))) {
158-
console.log('The TS Compilation failed, but it is expected');
159-
return;
160-
}
161-
162153
if (FAIL_ON_PURPOSE || result.status !== 0) {
163154
console.log(`The TS Compilation failed, preparing analysis folder...`);
164155
const destPath = path.join(__dirname, '../../vscode-monaco-editor-esm-analysis');
@@ -425,7 +416,7 @@ gulp.task('editor-distro',
425416
),
426417
task.series(
427418
createESMSourcesAndResourcesTask,
428-
compileEditorESMTask,
419+
compileEditorESMTaskPipeline,
429420
appendJSToESMImportsTask,
430421
)
431422
),

build/lib/compilation.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/lib/compilation.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ function createCompile(src: string, build: boolean, emitError: boolean, transpil
4545
const tsb = require('./tsb') as typeof import('./tsb');
4646
const sourcemaps = require('gulp-sourcemaps') as typeof import('gulp-sourcemaps');
4747

48-
4948
const projectPath = path.join(__dirname, '../../', src, 'tsconfig.json');
5049
const overrideOptions = { ...getTypeScriptCompilerOptions(src), inlineSources: Boolean(build) };
50+
5151
if (!build) {
5252
overrideOptions.inlineSourceMap = true;
53+
overrideOptions.noEmitOnError = false;
5354
}
5455

5556
const compilation = tsb.create(projectPath, overrideOptions, {
@@ -114,7 +115,7 @@ export function transpileTask(src: string, out: string, swc: boolean): task.Stre
114115
return task;
115116
}
116117

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

119120
const task = () => {
120121

@@ -156,6 +157,7 @@ export function compileTask(src: string, out: string, build: boolean, options: {
156157
.pipe(mangleStream)
157158
.pipe(generator.stream)
158159
.pipe(compile())
160+
.pipe(options?.transformConstEnum ? transformConstEnum() : es.through())
159161
.pipe(gulp.dest(out));
160162
};
161163

@@ -340,3 +342,12 @@ export const watchApiProposalNamesTask = task.define('watch-api-proposal-names',
340342
.pipe(util.debounce(task))
341343
.pipe(gulp.dest('src'));
342344
});
345+
346+
function transformConstEnum() {
347+
return es.map((file: File, cb: any) => {
348+
if (/\.ts$/.test(file.path)) {
349+
file.contents = Buffer.from(file.contents.toString().replace(/const enum/g, 'enum'));
350+
}
351+
cb(null, file);
352+
});
353+
}

build/lib/standalone.js

Lines changed: 15 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/lib/standalone.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,10 @@ export function createESMSourcesAndResources2(options: IOptions2): void {
162162
const tsConfig = JSON.parse(fs.readFileSync(path.join(SRC_FOLDER, file)).toString());
163163
tsConfig.compilerOptions.module = 'commonjs';
164164
tsConfig.compilerOptions.outDir = path.join(path.relative(OUT_FOLDER, OUT_RESOURCES_FOLDER), 'vs').replace(/\\/g, '/');
165-
tsConfig.compilerOptions.preserveConstEnums = false;
165+
tsConfig.compilerOptions.preserveConstEnums = true;
166166
tsConfig.compilerOptions.declaration = true;
167167
tsConfig.compilerOptions.noEmitOnError = false;
168168

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

194190
let importedFilepath: string;
191+
let importedIsAFile = false;
195192
if (/^vs\/css!/.test(importedFilename)) {
196193
importedFilepath = importedFilename.substr('vs/css!'.length) + '.css';
197194
} else {
198195
importedFilepath = importedFilename;
199196
}
197+
198+
// try to resolve the imported file path
199+
const filePath = path.join(SRC_FOLDER, importedFilepath);
200+
if (fs.existsSync(filePath + '.ts')) {
201+
importedIsAFile= true;
202+
}
203+
200204
if (/(^\.\/)|(^\.\.\/)/.test(importedFilepath)) {
201205
importedFilepath = path.join(path.dirname(file), importedFilepath);
202206
}
@@ -207,7 +211,13 @@ export function createESMSourcesAndResources2(options: IOptions2): void {
207211
} else if (importedFilepath === path.dirname(path.dirname(file)).replace(/\\/g, '/')) {
208212
relativePath = '../../' + path.basename(path.dirname(path.dirname(file)));
209213
} else {
210-
relativePath = path.relative(path.dirname(file), importedFilepath);
214+
if (importedIsAFile) {
215+
importedFilepath = importedFilepath + '.ts';
216+
relativePath = path.relative(path.dirname(file), importedFilepath);
217+
relativePath = relativePath.replace(/\.ts$/, '');
218+
} else{
219+
relativePath = path.relative(path.dirname(file), importedFilepath);
220+
}
211221
}
212222
relativePath = relativePath.replace(/\\/g, '/');
213223
if (!/(^\.\/)|(^\.\.\/)/.test(relativePath)) {

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@
9999
"native-watchdog": "^1.4.1",
100100
"node-pty": "1.1.0-beta6",
101101
"tas-client-umd": "0.1.8",
102-
"ts-transform-const-enum": "^0.0.1",
103102
"v8-inspect-profiler": "^0.1.0",
104103
"vscode-oniguruma": "1.7.0",
105104
"vscode-regexpp": "^3.1.0",
@@ -209,7 +208,6 @@
209208
"style-loader": "^3.3.2",
210209
"ts-loader": "^9.4.2",
211210
"ts-node": "^10.9.1",
212-
"ts-patch": "^3.1.2",
213211
"tsec": "0.2.7",
214212
"typescript": "^5.4.0-dev.20240206",
215213
"typescript-formatter": "7.1.0",

yarn.lock

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,7 +2553,7 @@ chalk@^4.0.0, chalk@^4.1.0:
25532553
ansi-styles "^4.1.0"
25542554
supports-color "^7.1.0"
25552555

2556-
chalk@^4.1.2, chalk@^4.x:
2556+
chalk@^4.x:
25572557
version "4.1.2"
25582558
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
25592559
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
@@ -4500,11 +4500,6 @@ function-bind@^1.1.1:
45004500
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d"
45014501
integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==
45024502

4503-
function-bind@^1.1.2:
4504-
version "1.1.2"
4505-
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.2.tgz#2c02d864d97f3ea6c8830c464cbd11ab6eab7a1c"
4506-
integrity sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==
4507-
45084503
functional-red-black-tree@^1.0.1:
45094504
version "1.0.1"
45104505
resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327"
@@ -4731,15 +4726,6 @@ global-prefix@^1.0.1:
47314726
is-windows "^1.0.1"
47324727
which "^1.2.14"
47334728

4734-
global-prefix@^3.0.0:
4735-
version "3.0.0"
4736-
resolved "https://registry.yarnpkg.com/global-prefix/-/global-prefix-3.0.0.tgz#fc85f73064df69f50421f47f883fe5b913ba9b97"
4737-
integrity sha512-awConJSVCHVGND6x3tmMaKcQvwXLhjdkmomy2W+Goaui8YPgYgXJZewhg3fWC+DlfqqQuWg8AwqjGTD2nAPVWg==
4738-
dependencies:
4739-
ini "^1.3.5"
4740-
kind-of "^6.0.2"
4741-
which "^1.3.1"
4742-
47434729
globals@^11.1.0, globals@^11.7.0:
47444730
version "11.12.0"
47454731
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
@@ -5159,13 +5145,6 @@ has@^1.0.3:
51595145
dependencies:
51605146
function-bind "^1.1.1"
51615147

5162-
hasown@^2.0.0:
5163-
version "2.0.2"
5164-
resolved "https://registry.yarnpkg.com/hasown/-/hasown-2.0.2.tgz#003eaf91be7adc372e84ec59dc37252cedb80003"
5165-
integrity sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==
5166-
dependencies:
5167-
function-bind "^1.1.2"
5168-
51695148
51705149
version "1.2.0"
51715150
resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
@@ -5365,7 +5344,7 @@ [email protected]:
53655344
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
53665345
integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=
53675346

5368-
ini@^1.3.4, ini@^1.3.5, ini@~1.3.0:
5347+
ini@^1.3.4, ini@~1.3.0:
53695348
version "1.3.8"
53705349
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"
53715350
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==
@@ -5504,13 +5483,6 @@ is-core-module@^2.1.0:
55045483
dependencies:
55055484
has "^1.0.3"
55065485

5507-
is-core-module@^2.13.0:
5508-
version "2.13.1"
5509-
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.13.1.tgz#ad0d7532c6fea9da1ebdc82742d74525c6273384"
5510-
integrity sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==
5511-
dependencies:
5512-
hasown "^2.0.0"
5513-
55145486
is-core-module@^2.9.0:
55155487
version "2.11.0"
55165488
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.11.0.tgz#ad4cb3e3863e814523c96f3f58d26cc570ff0144"
@@ -8366,15 +8338,6 @@ resolve@^1.20.0:
83668338
path-parse "^1.0.7"
83678339
supports-preserve-symlinks-flag "^1.0.0"
83688340

8369-
resolve@^1.22.2:
8370-
version "1.22.8"
8371-
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.8.tgz#b6c87a9f2aa06dfab52e3d70ac8cde321fa5a48d"
8372-
integrity sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==
8373-
dependencies:
8374-
is-core-module "^2.13.0"
8375-
path-parse "^1.0.7"
8376-
supports-preserve-symlinks-flag "^1.0.0"
8377-
83788341
responselike@^2.0.0:
83798342
version "2.0.1"
83808343
resolved "https://registry.yarnpkg.com/responselike/-/responselike-2.0.1.tgz#9a0bc8fdc252f3fb1cca68b016591059ba1422bc"
@@ -9556,23 +9519,6 @@ ts-node@^10.9.1:
95569519
v8-compile-cache-lib "^3.0.1"
95579520
yn "3.1.1"
95589521

9559-
ts-patch@^3.1.2:
9560-
version "3.1.2"
9561-
resolved "https://registry.yarnpkg.com/ts-patch/-/ts-patch-3.1.2.tgz#9d4832eca34ed0b9eb1f8456cb00c941f50b442b"
9562-
integrity sha512-n58F5AqjUMdp9RAKq+E1YBkmONltPVbt1nN+wrmZXoYZek6QcvaTuqvKMhYhr5BxtC53kD/exxIPA1cP1RQxsA==
9563-
dependencies:
9564-
chalk "^4.1.2"
9565-
global-prefix "^3.0.0"
9566-
minimist "^1.2.8"
9567-
resolve "^1.22.2"
9568-
semver "^7.5.4"
9569-
strip-ansi "^6.0.1"
9570-
9571-
ts-transform-const-enum@^0.0.1:
9572-
version "0.0.1"
9573-
resolved "https://registry.yarnpkg.com/ts-transform-const-enum/-/ts-transform-const-enum-0.0.1.tgz#eef558d993931967f29dcc776474177e41ad71a3"
9574-
integrity sha512-tsOxCy8XDEcYvG9lE5Yud2YN11F4rnr6taoNyRb0CYeKAa5WwvjY8RToIaTcLNbu7UO7KA1HajhPCeiuYDl0Hw==
9575-
95769522
95779523
version "0.2.7"
95789524
resolved "https://registry.yarnpkg.com/tsec/-/tsec-0.2.7.tgz#be530025907037ed57f37fc7625b6a7e3658fe43"
@@ -10188,7 +10134,7 @@ which-typed-array@^1.1.11, which-typed-array@^1.1.2:
1018810134
gopd "^1.0.1"
1018910135
has-tostringtag "^1.0.0"
1019010136

10191-
which@^1.2.14, which@^1.2.9, which@^1.3.1:
10137+
which@^1.2.14, which@^1.2.9:
1019210138
version "1.3.1"
1019310139
resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a"
1019410140
integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==

0 commit comments

Comments
 (0)