Skip to content

Commit

Permalink
Stabilise exports field support (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown committed Jan 6, 2023
1 parent c32a4de commit 36e3d51
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 111 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-socks-camp.md
@@ -0,0 +1,5 @@
---
"@preconstruct/cli": minor
---

[Support for the exports field](https://preconstruct.tools/configuration#exports) has been stabilised. If you were using the experimental flag, you should remove it.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -2,6 +2,7 @@
"name": "@preconstruct/monorepo",
"version": "0.0.65",
"description": "A smart build tool for libraries",
"packageManager": "yarn@1.22.19",
"scripts": {
"build": "yarn preconstruct build",
"test": "jest",
Expand Down
3 changes: 0 additions & 3 deletions packages/cli/src/__tests__/dev.ts
Expand Up @@ -327,9 +327,6 @@ test("exports field with worker condition", async () => {
exports: {
envConditions: ["worker"],
},
___experimentalFlags_WILL_CHANGE_IN_PATCH: {
exports: true,
},
},
}),
"src/index.js": "console.log(1)",
Expand Down
114 changes: 50 additions & 64 deletions packages/cli/src/__tests__/fix.ts
Expand Up @@ -81,9 +81,6 @@ test("set exports field when opt-in", async () => {
exports: {
envConditions: ["worker", "browser"],
},
___experimentalFlags_WILL_CHANGE_IN_PATCH: {
exports: true,
},
},
}),
"src/index.js": "",
Expand Down Expand Up @@ -117,9 +114,6 @@ test("set exports field when opt-in", async () => {
"worker",
"browser"
]
},
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
"exports": true
}
}
}
Expand All @@ -137,9 +131,6 @@ test("set exports field when opt-in", async () => {
exports: {
envConditions: ["worker", "browser"],
},
___experimentalFlags_WILL_CHANGE_IN_PATCH: {
exports: true,
},
},
}),
"src/index.js": "",
Expand Down Expand Up @@ -173,9 +164,6 @@ test("set exports field when opt-in", async () => {
"worker",
"browser"
]
},
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
"exports": true
}
}
}
Expand All @@ -191,9 +179,6 @@ test("set exports field when opt-in with no env conditions", async () => {
module: "dist/package-exports.esm.js",
preconstruct: {
exports: true,
___experimentalFlags_WILL_CHANGE_IN_PATCH: {
exports: true,
},
},
}),
"src/index.js": "",
Expand All @@ -215,10 +200,7 @@ test("set exports field when opt-in with no env conditions", async () => {
"./package.json": "./package.json"
},
"preconstruct": {
"exports": true,
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
"exports": true
}
"exports": true
}
}
Expand All @@ -236,9 +218,6 @@ test("set exports field with multiple entrypoints", async () => {
exports: {
envConditions: ["worker", "browser"],
},
___experimentalFlags_WILL_CHANGE_IN_PATCH: {
exports: true,
},
},
}),
"other/package.json": JSON.stringify({}),
Expand Down Expand Up @@ -315,9 +294,6 @@ test("set exports field with multiple entrypoints", async () => {
"worker",
"browser"
]
},
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
"exports": true
}
}
}
Expand All @@ -336,9 +312,6 @@ test("set exports field without root entrypoint", async () => {
exports: {
envConditions: ["worker", "browser"],
},
___experimentalFlags_WILL_CHANGE_IN_PATCH: {
exports: true,
},
},
},
null,
Expand Down Expand Up @@ -372,9 +345,6 @@ test("set exports field without root entrypoint", async () => {
"worker",
"browser"
]
},
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
"exports": true
}
},
"exports": {
Expand Down Expand Up @@ -751,9 +721,6 @@ test("no module field with exports field", async () => {
main: "dist/pkg-a.cjs.js",
preconstruct: {
exports: true,
___experimentalFlags_WILL_CHANGE_IN_PATCH: {
exports: true,
},
},
}),
"src/index.js": "",
Expand All @@ -773,10 +740,7 @@ test("no module field with exports field", async () => {
"./package.json": "./package.json"
},
"preconstruct": {
"exports": true,
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
"exports": true
}
"exports": true
}
}
Expand All @@ -795,9 +759,6 @@ test("has browser field but no browser condition", async () => {
},
preconstruct: {
exports: true,
___experimentalFlags_WILL_CHANGE_IN_PATCH: {
exports: true,
},
},
}),
"src/index.js": "",
Expand Down Expand Up @@ -827,9 +788,6 @@ test("has browser field but no browser condition", async () => {
"envConditions": [
"browser"
]
},
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
"exports": true
}
}
}
Expand All @@ -847,9 +805,6 @@ test("has browser condition but no browser field", async () => {
exports: {
envConditions: ["browser"],
},
___experimentalFlags_WILL_CHANGE_IN_PATCH: {
exports: true,
},
},
}),
"src/index.js": "",
Expand Down Expand Up @@ -880,9 +835,6 @@ test("has browser condition but no browser field", async () => {
"envConditions": [
"browser"
]
},
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
"exports": true
}
}
}
Expand All @@ -898,9 +850,6 @@ test("preconstruct.exports: true no exports field", async () => {
module: "dist/pkg-a.esm.js",
preconstruct: {
exports: true,
___experimentalFlags_WILL_CHANGE_IN_PATCH: {
exports: true,
},
},
}),
"src/index.js": "",
Expand All @@ -920,27 +869,66 @@ test("preconstruct.exports: true no exports field", async () => {
"./package.json": "./package.json"
},
"preconstruct": {
"exports": true,
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
"exports": true
}
"exports": true
}
}
`);
});

test("project level exports field config", async () => {
const tmpPath = await testdir({
"package.json": JSON.stringify(
{
name: "repo",
preconstruct: { packages: ["packages/*"], exports: true },
},
null,
2
),
"packages/pkg-a/package.json": JSON.stringify({
name: "pkg-a",
}),
"packages/pkg-a/src/index.js": "",
});
await fix(tmpPath);
expect(await getFiles(tmpPath, ["**/package.json"])).toMatchInlineSnapshot(`
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ package.json ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
{
"name": "repo",
"preconstruct": {
"packages": [
"packages/*"
],
"exports": true
}
}
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ packages/pkg-a/package.json ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
{
"name": "pkg-a",
"main": "dist/pkg-a.cjs.js",
"module": "dist/pkg-a.esm.js",
"exports": {
".": {
"module": "./dist/pkg-a.esm.js",
"default": "./dist/pkg-a.cjs.js"
},
"./package.json": "./package.json"
}
}
`);
});

test("experimental exports flag is removed", async () => {
const tmpPath = await testdir({
"package.json": JSON.stringify(
{
name: "repo",
preconstruct: {
packages: ["packages/*"],
exports: true,
___experimentalFlags_WILL_CHANGE_IN_PATCH: {
exports: true,
},
___experimentalFlags_WILL_CHANGE_IN_PATCH: { exports: true },
},
},
null,
Expand All @@ -960,12 +948,10 @@ test("project level exports field config", async () => {
"packages": [
"packages/*"
],
"exports": true,
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
"exports": true
}
"exports": true
}
}
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ packages/pkg-a/package.json ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
{
"name": "pkg-a",
Expand Down
51 changes: 33 additions & 18 deletions packages/cli/src/__tests__/validate.ts
Expand Up @@ -675,9 +675,6 @@ describe("exports field config", () => {
},
preconstruct: {
exports: config,
___experimentalFlags_WILL_CHANGE_IN_PATCH: {
exports: true,
},
},
}),
"src/index.js": "",
Expand Down Expand Up @@ -761,9 +758,6 @@ describe("exports field config", () => {
module: "dist/pkg-a.esm.js",
preconstruct: {
exports: config,
___experimentalFlags_WILL_CHANGE_IN_PATCH: {
exports: true,
},
},
}),
"src/index.js": "",
Expand All @@ -781,9 +775,6 @@ test("no module field with exports field", async () => {
main: "dist/pkg-a.cjs.js",
preconstruct: {
exports: true,
___experimentalFlags_WILL_CHANGE_IN_PATCH: {
exports: true,
},
},
}),
"src/index.js": "",
Expand All @@ -805,9 +796,6 @@ test("has browser field but no browser condition", async () => {
},
preconstruct: {
exports: true,
___experimentalFlags_WILL_CHANGE_IN_PATCH: {
exports: true,
},
},
}),
"src/index.js": "",
Expand All @@ -828,9 +816,6 @@ test("has browser condition but no browser field", async () => {
exports: {
envConditions: ["browser"],
},
___experimentalFlags_WILL_CHANGE_IN_PATCH: {
exports: true,
},
},
}),
"src/index.js": "",
Expand All @@ -848,9 +833,6 @@ test("preconstruct.exports: true no exports field", async () => {
module: "dist/pkg-a.esm.js",
preconstruct: {
exports: true,
___experimentalFlags_WILL_CHANGE_IN_PATCH: {
exports: true,
},
},
}),
"src/index.js": "",
Expand All @@ -859,3 +841,36 @@ test("preconstruct.exports: true no exports field", async () => {
`[Error: exports field was not found, expected \`{".":{"module":"./dist/pkg-a.esm.js","default":"./dist/pkg-a.cjs.js"},"./package.json":"./package.json"}\`]`
);
});

test("experimental exports flag is removed", async () => {
const tmpPath = await testdir({
"package.json": JSON.stringify(
{
name: "repo",
preconstruct: {
packages: ["packages/*"],
exports: true,
___experimentalFlags_WILL_CHANGE_IN_PATCH: { exports: true },
},
},
null,
2
),
"packages/pkg-a/package.json": JSON.stringify({
name: "pkg-a",
main: "dist/pkg-a.cjs.js",
module: "dist/pkg-a.esm.js",
exports: {
".": {
module: "./dist/pkg-a.esm.js",
default: "./dist/pkg-a.cjs.js",
},
"./package.json": "./package.json",
},
}),
"packages/pkg-a/src/index.js": "",
});
await expect(validate(tmpPath)).rejects.toMatchInlineSnapshot(
`[Error: The behaviour from the experimental flag "exports" is the current behaviour now, the flag should be removed]`
);
});

0 comments on commit 36e3d51

Please sign in to comment.