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 798e312
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 7 deletions.
5 changes: 4 additions & 1 deletion build/gulpfile.editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ 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,
moduleKind: 1 /** CommonJS */, transformConstEnum: 1 }));

const optimizeEditorAMDTask = task.define('optimize-editor-amd', optimize.optimizeTask(
{
out: 'out-editor',
Expand Down Expand Up @@ -425,7 +428,7 @@ gulp.task('editor-distro',
),
task.series(
createESMSourcesAndResourcesTask,
compileEditorESMTask,
compileEditorESMTaskPipeline,
appendJSToESMImportsTask,
)
),
Expand Down
15 changes: 14 additions & 1 deletion build/lib/compilation.js

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

20 changes: 17 additions & 3 deletions build/lib/compilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ function getTypeScriptCompilerOptions(src: string): ts.CompilerOptions {
return options;
}

function createCompile(src: string, build: boolean, emitError: boolean, transpileOnly: boolean | { swc: boolean }) {
function createCompile(src: string, build: boolean, emitError: boolean, transpileOnly: boolean | { swc: boolean }, moduleKind?: ts.ModuleKind) {
const tsb = require('./tsb') as typeof import('./tsb');
const sourcemaps = require('gulp-sourcemaps') as typeof import('gulp-sourcemaps');


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

if (moduleKind) {
overrideOptions.module = moduleKind;
}
if (!build) {
overrideOptions.inlineSourceMap = true;
overrideOptions.noEmitOnError = false;
}

const compilation = tsb.create(projectPath, overrideOptions, {
Expand Down Expand Up @@ -114,7 +118,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; moduleKind?: ts.ModuleKind } = {}): task.StreamTask {

const task = () => {

Expand Down Expand Up @@ -156,6 +160,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 +345,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);
});
}
15 changes: 14 additions & 1 deletion build/lib/standalone.js

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

16 changes: 15 additions & 1 deletion build/lib/standalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,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 +215,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

0 comments on commit 798e312

Please sign in to comment.