diff --git a/.yarn/versions/2be36fd1.yml b/.yarn/versions/2be36fd1.yml new file mode 100644 index 000000000000..f99982ebd2cf --- /dev/null +++ b/.yarn/versions/2be36fd1.yml @@ -0,0 +1,33 @@ +releases: + "@yarnpkg/cli": minor + "@yarnpkg/core": minor + "@yarnpkg/plugin-pack": minor + +declined: + - "@yarnpkg/plugin-compat" + - "@yarnpkg/plugin-constraints" + - "@yarnpkg/plugin-dlx" + - "@yarnpkg/plugin-essentials" + - "@yarnpkg/plugin-exec" + - "@yarnpkg/plugin-file" + - "@yarnpkg/plugin-git" + - "@yarnpkg/plugin-github" + - "@yarnpkg/plugin-http" + - "@yarnpkg/plugin-init" + - "@yarnpkg/plugin-interactive-tools" + - "@yarnpkg/plugin-link" + - "@yarnpkg/plugin-nm" + - "@yarnpkg/plugin-npm" + - "@yarnpkg/plugin-npm-cli" + - "@yarnpkg/plugin-patch" + - "@yarnpkg/plugin-pnp" + - "@yarnpkg/plugin-pnpm" + - "@yarnpkg/plugin-stage" + - "@yarnpkg/plugin-typescript" + - "@yarnpkg/plugin-version" + - "@yarnpkg/plugin-workspace-tools" + - "@yarnpkg/builder" + - "@yarnpkg/doctor" + - "@yarnpkg/nm" + - "@yarnpkg/pnpify" + - "@yarnpkg/sdks" diff --git a/packages/acceptance-tests/pkg-tests-specs/sources/commands/pack.test.js b/packages/acceptance-tests/pkg-tests-specs/sources/commands/pack.test.js index d41621735c35..e9d850a33673 100644 --- a/packages/acceptance-tests/pkg-tests-specs/sources/commands/pack.test.js +++ b/packages/acceptance-tests/pkg-tests-specs/sources/commands/pack.test.js @@ -298,13 +298,19 @@ describe(`Commands`, () => { ); test( - `it should override main and module in the packed manifest`, + `it should override fields in the packed manifest`, makeTemporaryEnv({ + type: `commonjs`, main: `./index.js`, module: `./index.mjs`, + browser: `./index.umd.js`, + exports: `./index.modern.js`, publishConfig: { + type: `module`, main: `./published.js`, module: `./published.mjs`, + browser: `./published.umd.js`, + exports: `./published.modern.js`, }, }, async ({path, run, source}) => { await run(`install`); @@ -314,13 +320,19 @@ describe(`Commands`, () => { const packedManifest = await fsUtils.readJson(`${path}/package/package.json`); + expect(packedManifest.type).toBe(`module`); expect(packedManifest.main).toBe(`./published.js`); expect(packedManifest.module).toBe(`./published.mjs`); + expect(packedManifest.browser).toBe(`./published.umd.js`); + expect(packedManifest.exports).toBe(`./published.modern.js`); const originalManifest = await fsUtils.readJson(`${path}/package.json`); + expect(originalManifest.type).toBe(`commonjs`); expect(originalManifest.main).toBe(`./index.js`); expect(originalManifest.module).toBe(`./index.mjs`); + expect(originalManifest.browser).toBe(`./index.umd.js`); + expect(originalManifest.exports).toBe(`./index.modern.js`); }), ); diff --git a/packages/gatsby/static/configuration/manifest.json b/packages/gatsby/static/configuration/manifest.json index 53d543307e8c..82d3c44210f4 100644 --- a/packages/gatsby/static/configuration/manifest.json +++ b/packages/gatsby/static/configuration/manifest.json @@ -324,6 +324,11 @@ "type": "string", "format": "uri", "examples": ["https://npm.pkg.github.com"] + }, + "type": { + "description": "Same principle as the `publishConfig.bin` property; this value will be used instead of the top-level `type` field when generating the workspace tarball.", + "type": "string", + "enum": ["commonjs", "module"] } }, "_exampleKeys": [ diff --git a/packages/plugin-pack/sources/index.ts b/packages/plugin-pack/sources/index.ts index 9bc8120d0992..0bd76598a8aa 100644 --- a/packages/plugin-pack/sources/index.ts +++ b/packages/plugin-pack/sources/index.ts @@ -23,6 +23,9 @@ const WORKSPACE_PROTOCOL = `workspace:`; const beforeWorkspacePacking = (workspace: Workspace, rawManifest: any) => { if (rawManifest.publishConfig) { + if (rawManifest.publishConfig.type) + rawManifest.type = rawManifest.publishConfig.type; + if (rawManifest.publishConfig.main) rawManifest.main = rawManifest.publishConfig.main; diff --git a/packages/yarnpkg-core/sources/Manifest.ts b/packages/yarnpkg-core/sources/Manifest.ts index 681a8fc47437..2e7055e80519 100644 --- a/packages/yarnpkg-core/sources/Manifest.ts +++ b/packages/yarnpkg-core/sources/Manifest.ts @@ -30,6 +30,7 @@ export interface PublishConfig { access?: string; main?: PortablePath; module?: PortablePath; + type?: string; browser?: PortablePath | Map; bin?: Map; registry?: string;