Skip to content

Commit 9e5c527

Browse files
committed
Enable using the ESM dependencies where possible
Issue: #5086 Signed-off-by: Victor Rubezhny <[email protected]>
1 parent 60659f3 commit 9e5c527

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1716
-1955
lines changed

.vscode/tasks.json

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,36 @@
44
"version": "2.0.0",
55
"tasks": [
66
{
7-
"label": "watch",
7+
"label": "watch:extension",
88
"type": "npm",
9-
"script": "watch",
9+
"script": "watch:extension",
10+
"isBackground": true,
11+
"problemMatcher": "$tsc-watch"
12+
},
13+
{
14+
"label": "watch:webviews",
15+
"type": "npm",
16+
"script": "watch:webviews",
1017
"isBackground": true,
1118
"problemMatcher": {
12-
"background": {
13-
"beginsPattern": "\\[[^\\]]+\\] File change detected. Compiling...",
14-
"endsPattern": "\\[[^\\]]+\\] Compilation complete. Found (?:no|some) errors. Watching for file changes.",
15-
"activeOnStart": false,
19+
"owner": "custom",
20+
"pattern": {
21+
"regexp": "."
1622
},
17-
"base": "$tsc-watch",
18-
},
19-
"presentation": {
20-
"reveal": "never",
21-
},
23+
"background": {
24+
"activeOnStart": true,
25+
"beginsPattern": ".*Building the webviews\\.\\.\\.",
26+
"endsPattern": ".*Watching the webviews\\.\\.\\."
27+
}
28+
}
29+
},
30+
{
31+
"label": "watch",
32+
"dependsOn": [
33+
"watch:extension",
34+
"watch:webviews"
35+
],
36+
"dependsOrder": "parallel"
2237
},
2338
{
2439
"label": "compile",

.vscodeignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ out/build**
1818
out/build/**
1919
out/coverage/**
2020
out/**/*.map
21+
out/esm/**
22+
out/shared/**
2123
out/src-orig/**
2224
out/test/**
2325
out/test-resources/**

build/bundle-tools.cjs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*-----------------------------------------------------------------------------------------------
2+
* Copyright (c) Red Hat, Inc. All rights reserved.
3+
* Licensed under the MIT License. See LICENSE file in the project root for license information.
4+
*-----------------------------------------------------------------------------------------------*/
5+
6+
/* eslint-disable guard-for-in */
7+
/* eslint-disable no-console */
8+
9+
const fs = require('fs');
10+
const path = require('path');
11+
const { exit } = require('process');
12+
const { esmAliasPlugin } = require('./esbuild.plugins.cjs');
13+
14+
require('esbuild').build({
15+
entryPoints: [path.resolve(__dirname, '..', 'src/downloadUtil/downloadBinaries.ts')],
16+
platform: 'node',
17+
target: 'node18',
18+
format: 'cjs',
19+
outfile: path.resolve(__dirname, '..', 'out/shared/downloadUtil.js'),
20+
bundle: true,
21+
plugins: [ esmAliasPlugin() ]
22+
}).then(() => {
23+
const { downloadFileAndCreateSha256 } = require(path.resolve(__dirname, '..', 'out/shared/downloadUtil.js'));
24+
const configData = require('../src/tools.json');
25+
26+
async function bundleTools() {
27+
if (process.env.REMOTE_CONTAINERS === 'true') {
28+
return;
29+
}
30+
const outFolder = path.resolve('.', 'out');
31+
const toolsCacheFolder = path.join(outFolder, 'tools-cache');
32+
let currentPlatform = process.env.TARGET;
33+
if (!currentPlatform) {
34+
currentPlatform = process.argv.find((arg) => arg === '--platform')
35+
? process.platform
36+
: 'all';
37+
}
38+
console.info(`Download tools to '${toolsCacheFolder}'`);
39+
for (const key in configData) {
40+
const tool = configData[key];
41+
for (const OS in tool.platform) {
42+
if (currentPlatform === 'all' || OS === currentPlatform) {
43+
console.log(`Bundle '${tool.description}' for ${OS}`);
44+
const osSpecificLocation = path.join(outFolder, 'tools', OS);
45+
// eslint-disable-next-line no-await-in-loop
46+
await downloadFileAndCreateSha256(toolsCacheFolder, osSpecificLocation, tool.platform[OS]);
47+
fs.chmodSync(path.join(osSpecificLocation, tool.platform[OS].cmdFileName), 0o765);
48+
}
49+
}
50+
}
51+
}
52+
53+
bundleTools().catch((error) => {
54+
console.log(error);
55+
exit(1);
56+
});
57+
58+
}).catch(err => {
59+
console.error(err);
60+
exit(1);
61+
});

build/bundle-tools.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.

build/esbuild.build.cjs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*-----------------------------------------------------------------------------------------------
2+
* Copyright (c) Red Hat, Inc. All rights reserved.
3+
* Licensed under the MIT License. See LICENSE file in the project root for license information.
4+
*-----------------------------------------------------------------------------------------------*/
5+
6+
const { execSync } = require('child_process');
7+
const esbuild = require('esbuild');
8+
const { esmAliasPlugin, esbuildProblemMatcherPlugin, nativeNodeModulesPlugin, svgrPlugin, verbosePlugin } = require('./esbuild.plugins.cjs');
9+
const { webviews, srcDir, outDir } = require('./esbuild.settings.cjs');
10+
const { sassPlugin } = require('esbuild-sass-plugin');
11+
const { cp, mkdir, stat } = require('node:fs/promises');
12+
const path = require('path');
13+
const { sync } = require('fast-glob');
14+
const { buildWebviews } = require('./esbuild.webviews.cjs');
15+
16+
const production = process.argv.includes('--production');
17+
18+
// eslint-disable no-console
19+
20+
// Run type-checking
21+
22+
/// Verify the extension
23+
try {
24+
// execSync('tsc --noEmit', { stdio: 'inherit' });
25+
execSync('tsc --noEmit -p tsconfig.json', { stdio: 'inherit' });
26+
} catch (err) {
27+
console.error('❌ TypeScript type-checking failed.');
28+
process.exit(1);
29+
}
30+
31+
console.log(`esbuild: building for production: ${production ? 'Yes' : 'No'}`);
32+
33+
const baseConfig = {
34+
bundle: true,
35+
target: 'chrome108',
36+
minify: production,
37+
sourcemap: !production,
38+
logLevel: 'warning',
39+
};
40+
41+
async function buildExtension() {
42+
console.log(`📦 Building the extension for ${ production ? 'Production' : 'Development'}...`);
43+
44+
if (production) {
45+
// Build the extension.js
46+
const extConfig = {
47+
...baseConfig,
48+
platform: 'node',
49+
format: 'cjs',
50+
entryPoints: [`./${srcDir}/extension.ts`],
51+
outfile: `${outDir}/${srcDir}/extension.js`,
52+
external: [ 'vscode', 'shelljs', 'jsonc-parser' ],
53+
plugins: [
54+
nativeNodeModulesPlugin(),
55+
esbuildProblemMatcherPlugin(production) // this one is to be added to the end of plugins array
56+
]
57+
};
58+
await esbuild.build(extConfig);
59+
console.log('✅ Extension build completed');
60+
} else {
61+
// Build the Extension for development
62+
const srcFiles = sync(`${srcDir}/**/*.{js,ts}`, { absolute: false });
63+
const devExtConfig = {
64+
...baseConfig,
65+
platform: 'node',
66+
format: 'cjs',
67+
entryPoints: srcFiles.map(f => `./${f}`),
68+
outbase: srcDir,
69+
outdir: `${outDir}/${srcDir}`,
70+
external: [ 'vscode', 'shelljs', 'jsonc-parser', '@aws-sdk/client-s3' ],
71+
plugins: [
72+
// verbosePlugin(),
73+
esmAliasPlugin(),
74+
nativeNodeModulesPlugin(),
75+
esbuildProblemMatcherPlugin(production) // this one is to be added to the end of plugins array
76+
]
77+
};
78+
79+
await esbuild.build(devExtConfig);
80+
81+
const jsonFiles = sync('src/**/*.json', { absolute: false });
82+
for (const file of jsonFiles) {
83+
const dest = path.join('out', file);
84+
await cp(file, dest, { recursive: false, force: true });
85+
}
86+
await cp('package.json', 'out/package.json');
87+
console.log('✅ Extension build completed');
88+
}
89+
}
90+
91+
async function buildAll() {
92+
await buildExtension();
93+
await buildWebviews();
94+
}
95+
96+
buildAll().catch(err => {
97+
console.error('❌ Build failed:', err);
98+
process.exit(1);
99+
});

0 commit comments

Comments
 (0)