Skip to content

Commit 798e312

Browse files
committed
Use gulp to build esm version
1 parent 1848939 commit 798e312

File tree

5 files changed

+64
-7
lines changed

5 files changed

+64
-7
lines changed

build/gulpfile.editor.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ 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,
92+
moduleKind: 1 /** CommonJS */, transformConstEnum: 1 }));
93+
9194
const optimizeEditorAMDTask = task.define('optimize-editor-amd', optimize.optimizeTask(
9295
{
9396
out: 'out-editor',
@@ -425,7 +428,7 @@ gulp.task('editor-distro',
425428
),
426429
task.series(
427430
createESMSourcesAndResourcesTask,
428-
compileEditorESMTask,
431+
compileEditorESMTaskPipeline,
429432
appendJSToESMImportsTask,
430433
)
431434
),

build/lib/compilation.js

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/lib/compilation.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,19 @@ function getTypeScriptCompilerOptions(src: string): ts.CompilerOptions {
4141
return options;
4242
}
4343

44-
function createCompile(src: string, build: boolean, emitError: boolean, transpileOnly: boolean | { swc: boolean }) {
44+
function createCompile(src: string, build: boolean, emitError: boolean, transpileOnly: boolean | { swc: boolean }, moduleKind?: ts.ModuleKind) {
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+
51+
if (moduleKind) {
52+
overrideOptions.module = moduleKind;
53+
}
5154
if (!build) {
5255
overrideOptions.inlineSourceMap = true;
56+
overrideOptions.noEmitOnError = false;
5357
}
5458

5559
const compilation = tsb.create(projectPath, overrideOptions, {
@@ -114,7 +118,7 @@ export function transpileTask(src: string, out: string, swc: boolean): task.Stre
114118
return task;
115119
}
116120

117-
export function compileTask(src: string, out: string, build: boolean, options: { disableMangle?: boolean } = {}): task.StreamTask {
121+
export function compileTask(src: string, out: string, build: boolean, options: { disableMangle?: boolean; transformConstEnum?: boolean; moduleKind?: ts.ModuleKind } = {}): task.StreamTask {
118122

119123
const task = () => {
120124

@@ -156,6 +160,7 @@ export function compileTask(src: string, out: string, build: boolean, options: {
156160
.pipe(mangleStream)
157161
.pipe(generator.stream)
158162
.pipe(compile())
163+
.pipe(options?.transformConstEnum ? transformConstEnum() : es.through())
159164
.pipe(gulp.dest(out));
160165
};
161166

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

build/lib/standalone.js

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/lib/standalone.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,19 @@ export function createESMSourcesAndResources2(options: IOptions2): void {
192192
const end = info.importedFiles[i].end;
193193

194194
let importedFilepath: string;
195+
let importedIsAFile = false;
195196
if (/^vs\/css!/.test(importedFilename)) {
196197
importedFilepath = importedFilename.substr('vs/css!'.length) + '.css';
197198
} else {
198199
importedFilepath = importedFilename;
199200
}
201+
202+
// try to resolve the imported file path
203+
const filePath = path.join(SRC_FOLDER, importedFilepath);
204+
if (fs.existsSync(filePath + '.ts')) {
205+
importedIsAFile= true;
206+
}
207+
200208
if (/(^\.\/)|(^\.\.\/)/.test(importedFilepath)) {
201209
importedFilepath = path.join(path.dirname(file), importedFilepath);
202210
}
@@ -207,7 +215,13 @@ export function createESMSourcesAndResources2(options: IOptions2): void {
207215
} else if (importedFilepath === path.dirname(path.dirname(file)).replace(/\\/g, '/')) {
208216
relativePath = '../../' + path.basename(path.dirname(path.dirname(file)));
209217
} else {
210-
relativePath = path.relative(path.dirname(file), importedFilepath);
218+
if (importedIsAFile) {
219+
importedFilepath = importedFilepath + '.ts';
220+
relativePath = path.relative(path.dirname(file), importedFilepath);
221+
relativePath = relativePath.replace(/\.ts$/, '');
222+
} else{
223+
relativePath = path.relative(path.dirname(file), importedFilepath);
224+
}
211225
}
212226
relativePath = relativePath.replace(/\\/g, '/');
213227
if (!/(^\.\/)|(^\.\.\/)/.test(relativePath)) {

0 commit comments

Comments
 (0)