From 3201a51170a98f3bcc4f0e1435bf72a3c91049c9 Mon Sep 17 00:00:00 2001 From: merceyz Date: Mon, 21 Dec 2020 02:28:15 +0100 Subject: [PATCH] feat: add config to enable ESM loader --- packages/plugin-pnp/sources/PnpLinker.ts | 2 +- packages/plugin-pnp/sources/index.ts | 2 +- packages/yarnpkg-core/sources/Configuration.ts | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/plugin-pnp/sources/PnpLinker.ts b/packages/plugin-pnp/sources/PnpLinker.ts index 6405d7d86664..b8a6e4936c5e 100644 --- a/packages/plugin-pnp/sources/PnpLinker.ts +++ b/packages/plugin-pnp/sources/PnpLinker.ts @@ -264,7 +264,7 @@ export class PnpInstaller implements Installer { await xfs.removePromise(pnpPath.other); - if (this.opts.project.topLevelWorkspace.manifest.type !== `module`) + if (this.opts.project.configuration.get(`enableExperimentalESMLoader`) !== true || this.opts.project.topLevelWorkspace.manifest.type !== `module`) await xfs.removePromise(pnpPath.esmLoader); if (this.opts.project.configuration.get(`nodeLinker`) !== `pnp`) { diff --git a/packages/plugin-pnp/sources/index.ts b/packages/plugin-pnp/sources/index.ts index a38dccf658de..2f320e0bbeaf 100644 --- a/packages/plugin-pnp/sources/index.ts +++ b/packages/plugin-pnp/sources/index.ts @@ -16,7 +16,7 @@ export const getPnpPath = (project: Project) => { let mainFilename; let otherFilename; - if (project.topLevelWorkspace.manifest.type === `module`) { + if (project.configuration.get(`enableExperimentalESMLoader`) === true || project.topLevelWorkspace.manifest.type === `module`) { mainFilename = `.pnp.cjs`; otherFilename = `.pnp.js`; } else { diff --git a/packages/yarnpkg-core/sources/Configuration.ts b/packages/yarnpkg-core/sources/Configuration.ts index be0f046bd179..7e3817144af4 100644 --- a/packages/yarnpkg-core/sources/Configuration.ts +++ b/packages/yarnpkg-core/sources/Configuration.ts @@ -429,6 +429,12 @@ export const coreDefinitions: {[coreSettingName: string]: SettingsDefinition} = default: `throw`, }, + enableExperimentalESMLoader: { + description: `If true, an ESM loader will be added to the environment`, + type: SettingsType.BOOLEAN, + default: false, + }, + // Package patching - to fix incorrect definitions packageExtensions: { description: `Map of package corrections to apply on the dependency tree`, @@ -547,6 +553,8 @@ export interface ConfigurationValueMap { peerDependencies?: Map, peerDependenciesMeta?: Map>, }>>; + + enableExperimentalESMLoader: boolean } export type PackageExtensionData = miscUtils.MapValueToObjectValue>;