Skip to content

Commit

Permalink
exports field and worker bundles (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksrandall committed Jul 11, 2022
1 parent 4e04c59 commit 014038b
Show file tree
Hide file tree
Showing 19 changed files with 1,473 additions and 65 deletions.
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(
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")
);
})
);
});

0 comments on commit 014038b

Please sign in to comment.