void/build/lib/amd.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2024-09-11 02:37:36 +00:00
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as path from 'path';
import * as fs from 'fs';
// TODO@esm remove this
const outDirectory = path.join(__dirname, '..', '..', 'out-build');
2024-09-24 04:46:08 +00:00
const amdMarkerFile = path.join(outDirectory, 'amd');
2024-09-11 02:37:36 +00:00
2024-09-24 04:46:08 +00:00
export function setAMD(enabled: boolean) {
2024-09-11 02:37:36 +00:00
const result = () => new Promise<void>((resolve, _) => {
if (enabled) {
fs.mkdirSync(outDirectory, { recursive: true });
2024-09-24 04:46:08 +00:00
fs.writeFileSync(amdMarkerFile, 'true', 'utf8');
console.warn(`Setting build to AMD: true`);
2024-09-11 02:37:36 +00:00
} else {
2024-09-24 04:46:08 +00:00
console.warn(`Setting build to AMD: false`);
2024-09-11 02:37:36 +00:00
}
resolve();
});
2024-09-24 04:46:08 +00:00
result.taskName = 'set-amd';
2024-09-11 02:37:36 +00:00
return result;
}
2024-09-24 04:46:08 +00:00
export function isAMD(logWarning?: string): boolean {
2024-09-11 02:37:36 +00:00
try {
2024-09-24 04:46:08 +00:00
const res = (typeof process.env.VSCODE_BUILD_AMD === 'string' && process.env.VSCODE_BUILD_AMD.toLowerCase() === 'true') || (fs.readFileSync(amdMarkerFile, 'utf8') === 'true');
2024-09-11 02:37:36 +00:00
if (res && logWarning) {
2024-09-24 04:46:08 +00:00
console.warn(`[amd] ${logWarning}`);
2024-09-11 02:37:36 +00:00
}
return res;
} catch (error) {
return false;
}
}