Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exports field and worker bundles #435

Merged
merged 56 commits into from Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
04e06b5
feat(workers): add support for workers style environemnt. See #431
nicksrandall Dec 9, 2021
b0feebb
feat(exports): adds support for package exports
nicksrandall Dec 10, 2021
b25d523
fixing dev mode with package.exports
nicksrandall Dec 10, 2021
b548893
fixing error message for package exports
nicksrandall Dec 10, 2021
bf841d9
update docs for exports
nicksrandall Dec 10, 2021
7d49055
make config more clear
nicksrandall Dec 10, 2021
89300f3
adding support for production and development package exports conditi…
nicksrandall Dec 14, 2021
05f1cdd
make package exports support opt-in. Also add config for extra fields
nicksrandall Dec 16, 2021
a985105
move exports functionality behind global expirimental flag
nicksrandall Dec 17, 2021
008c8e0
remove extra config check
nicksrandall Dec 17, 2021
7522d55
add note to docs that exports feature is experimental
nicksrandall Dec 17, 2021
83b436e
add test to assert that order of conditions are correct
nicksrandall Feb 14, 2022
1d2620a
allow user to configure what conditionals they'd like to support
nicksrandall Feb 14, 2022
ea633db
make the type for conditions a little more strict
nicksrandall Feb 14, 2022
45e94c3
validate sorting of all fields
nicksrandall Feb 15, 2022
a575716
simplify snapshot test for exports ordering
nicksrandall Mar 6, 2022
e050e5c
default esm to use use dev build when prod or dev are not specified
nicksrandall Mar 13, 2022
68deb25
Remove prod esm builds
emmatown Jul 1, 2022
7a49579
WIP
emmatown Jul 1, 2022
69e6a78
Remove forceStrategy
emmatown Jul 1, 2022
ba08537
Things
emmatown Jul 1, 2022
edce3ae
Enforce alignment with browser and module fields and conditions
emmatown Jul 1, 2022
38c13f9
envConditions
emmatown Jul 1, 2022
7e31d4d
Some tests
emmatown Jul 1, 2022
dfe88ee
Fix dev
emmatown Jul 1, 2022
da2b000
Validate exports field config
emmatown Jul 3, 2022
85e49db
dev test
emmatown Jul 4, 2022
51e7b20
Build test
emmatown Jul 4, 2022
988438a
First pass at docs
emmatown Jul 5, 2022
be90e4e
GitHub Actions Windows
emmatown Jul 5, 2022
72e5df2
Test things
emmatown Jul 5, 2022
014821b
tests
emmatown Jul 5, 2022
8f95c67
Revert some changes
emmatown Jul 5, 2022
8391a30
Tests
emmatown Jul 5, 2022
c824e52
Revert another thing
emmatown Jul 5, 2022
3052d29
Remove CommonJS worker build
emmatown Jul 5, 2022
ca512ce
Tests
emmatown Jul 5, 2022
1c46107
Test TypeScript with moduleResolution: nodenext
emmatown Jul 5, 2022
92bb8bd
Windows test debugging
emmatown Jul 5, 2022
4274921
Sort entrypoints
emmatown Jul 5, 2022
04c0962
Only ESM browser builds when using the exports field
emmatown Jul 6, 2022
9560a5d
./package.json after entrypoints
emmatown Jul 6, 2022
28f5d48
thing for windows debugging again
emmatown Jul 6, 2022
f1f8e60
Try a different thing?
emmatown Jul 6, 2022
1c0f9e8
try realpath again?
emmatown Jul 6, 2022
3430e86
Try realpath again?
emmatown Jul 6, 2022
0956b9a
Another attempt
emmatown Jul 6, 2022
fe18282
Try a thing?
emmatown Jul 6, 2022
7be8e95
Try another thing?
emmatown Jul 6, 2022
374a0b4
more windows debugging
emmatown Jul 6, 2022
5558764
Try a different thing
emmatown Jul 6, 2022
803290f
Async
emmatown Jul 6, 2022
a57d57b
Docs
emmatown Jul 7, 2022
caebf9e
Update changeset
emmatown Jul 7, 2022
d1f5c6e
Update site/src/pages/configuration.mdx
emmatown Jul 7, 2022
e73af13
Project level exports field config
emmatown Jul 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/afraid-experts-attack.md
@@ -0,0 +1,5 @@
---
"@preconstruct/cli": patch
---

Added experimental `exports` flag. See the docs at the `exports` section of https://preconstruct.tools/configuration.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -67,7 +67,7 @@
"normalize-path": "^3.0.0",
"outdent": "^0.7.1",
"prettier": "^2.1.2",
"typescript": "^4.5.2"
"typescript": "^4.7.4"
},
"jest": {
"reporters": [
Expand Down
13 changes: 2 additions & 11 deletions packages/cli/package.json
Expand Up @@ -2,13 +2,7 @@
"name": "@preconstruct/cli",
"version": "2.1.7",
"description": "Dev and build your code painlessly in monorepos",
"files": [
"bin.js",
"cli",
"worker",
"!**/*.d.ts",
"dist"
],
"files": ["bin.js", "cli", "worker", "!**/*.d.ts", "dist"],
"bin": {
"preconstruct": "./bin.js"
},
Expand Down Expand Up @@ -54,10 +48,7 @@
"v8-compile-cache": "^2.1.1"
},
"preconstruct": {
"entrypoints": [
"cli",
"worker"
]
"entrypoints": ["cli", "worker"]
},
"devDependencies": {
"escape-string-regexp": "^4.0.0",
Expand Down
49 changes: 48 additions & 1 deletion packages/cli/src/__tests__/dev.ts
Expand Up @@ -2,7 +2,7 @@ import spawn from "spawndamnit";
import path from "path";
import * as fs from "fs-extra";
import * as realFs from "fs";
import { js, testdir, typescriptFixture } from "../../test-utils";
import { getFiles, js, testdir, typescriptFixture } from "../../test-utils";
import dev from "../dev";
import normalizePath from "normalize-path";
import escapeStringRegexp from "escape-string-regexp";
Expand Down Expand Up @@ -305,3 +305,50 @@ test("typescript with typeScriptProxyFileWithImportEqualsRequireAndExportEquals"
"
`);
});

test("exports field with worker condition", async () => {
let tmpPath = realFs.realpathSync.native(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: why do we use realpathSync.native here? some tests in this file do this and some dont

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests that read symlinks use realpathSync.native because (at least from my vague reading of things) realpath and realpath.native do subtly different things on Windows(like realpath seems to just not resolve some links and realpath.native does?) and that matters when getting the path that a symlink resolves to.

await testdir({
"package.json": JSON.stringify({
name: "@something/blah",
main: "dist/something-blah.cjs.js",
module: "dist/something-blah.esm.js",
exports: {
".": {
module: {
worker: "./dist/something-blah.worker.esm.js",
default: "./dist/something-blah.esm.js",
},
default: "./dist/something-blah.cjs.js",
},
"./package.json": "./package.json",
},
preconstruct: {
exports: {
envConditions: ["worker"],
},
___experimentalFlags_WILL_CHANGE_IN_PATCH: {
exports: true,
},
},
}),
"src/index.js": "console.log(1)",
})
);
await dev(tmpPath);
const files = await getFiles(tmpPath, [
"dist/**",
"!dist/something-blah.cjs.js",
]);
expect(files).toMatchInlineSnapshot(`
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ dist/something-blah.esm.js, dist/something-blah.worker.esm.js ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
console.log(1)
`);
await Promise.all(
Object.keys(files).map(async (filename) => {
expect(await fs.realpath(path.join(tmpPath, filename))).toEqual(
path.join(tmpPath, "src/index.js")
);
})
);
});