Skip to content

Commit

Permalink
feat: add config to enable ESM loader
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz committed Dec 21, 2020
1 parent d6a4dd4 commit 3201a51
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-pnp/sources/PnpLinker.ts
Expand Up @@ -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`) {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-pnp/sources/index.ts
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions packages/yarnpkg-core/sources/Configuration.ts
Expand Up @@ -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`,
Expand Down Expand Up @@ -547,6 +553,8 @@ export interface ConfigurationValueMap {
peerDependencies?: Map<string, string>,
peerDependenciesMeta?: Map<string, miscUtils.ToMapValue<{optional?: boolean}>>,
}>>;

enableExperimentalESMLoader: boolean
}

export type PackageExtensionData = miscUtils.MapValueToObjectValue<miscUtils.MapValue<ConfigurationValueMap['packageExtensions']>>;
Expand Down

0 comments on commit 3201a51

Please sign in to comment.