Skip to content

Commit

Permalink
detect ESM with sources
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli committed Sep 2, 2024
1 parent 2ee36ca commit 7f4fa50
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.vscode
.npmignore
.editorconfig
.eslintrc.js
.eslint.config.js
.prettierrc
.github/
build/
Expand Down
13 changes: 12 additions & 1 deletion src/server/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ export default function (config: IConfig): Router.Middleware {
if (config.build.type === 'sources') {
const builtInExtensions = await getScannedBuiltinExtensions(config.build.location);
const productOverrides = await getProductOverrides(config.build.location);
const esm = config.esm || await isESM(config.build.location);
console.log('Using ESM loader:', esm);
const devCSSModules = config.esm ? await getDevCssModules(config.build.location) : [];
ctx.state.workbench = new Workbench(`${ctx.protocol}://${ctx.host}/static/sources`, true, config.esm, devCSSModules, builtInExtensions, {
ctx.state.workbench = new Workbench(`${ctx.protocol}://${ctx.host}/static/sources`, true, esm, devCSSModules, builtInExtensions, {
...productOverrides,
webEndpointUrlTemplate: `${ctx.protocol}://{{uuid}}.${ctx.host}/static/sources`,
webviewContentExternalBaseUrlTemplate: `${ctx.protocol}://{{uuid}}.${ctx.host}/static/sources/out/vs/workbench/contrib/webview/browser/pre/`
Expand Down Expand Up @@ -183,3 +185,12 @@ async function getDevCssModules(vsCodeDevLocation: string): Promise<string[]> {
const glob = await import('glob')
return glob.glob('**/*.css', { cwd: path.join(vsCodeDevLocation, 'out') });
}

async function isESM(vsCodeDevLocation: string): Promise<boolean> {
try {
const packageJSON = await fs.readFile(path.join(vsCodeDevLocation, 'out', 'package.json'));
return JSON.parse(packageJSON.toString()).type === 'module';
} catch (e) {
return false;
}
}

0 comments on commit 7f4fa50

Please sign in to comment.