Uh oh!
There was an error while loading. Please reload this page.
Export the files we publish - #2450
Merged
Merged
Conversation
`exports` was a bare string, and defining `exports` at all encapsulates every other subpath. Of the 360 files in the tarball, exactly one was reachable through Node resolution -- `package.json` included, which tooling routinely reads from a dependency. `files` and `exports` disagreed about what the public API is, and `files` is the field expressing the intent. `exports` now mirrors its shape, so what we ship and what a consumer can reach are the same set. The patterns are written per extension rather than as a blanket `./src/*`, which keeps stories and tests encapsulated for a consumer resolving against a working tree rather than an installed tarball. Also adds a `types` condition to the main entry: under node16/nodenext/ bundler resolution TypeScript reads types through `exports` and ignores the top-level `types` field, so those consumers were getting `any`. That was already broken before this change; it is fixed here because it is the same field and the same root cause. Runtime resolution of the main entry is unchanged. The published file list is byte-for-byte identical -- only reachability changes. Fixes#2078
✅ Deploy Preview for cloudfour-patterns ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
🦋 Changeset detectedLatest commit: f91cec3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
We publish 360 files — the compiled design tokens, the Sass partials, the Twig templates, the assets — and exactly one of them could be reached through Node resolution. Defining an
exportsfield at all encapsulates every subpath that isn't listed, and ours was a bare string pointing at the browser bundle, so requiring the design tokens failed withERR_PACKAGE_PATH_NOT_EXPORTED. So did reading our ownpackage.json, which tooling routinely does to a dependency.filesandexportsdisagreed about what our public API is, andfilesis the field expressing the intent — those files are deliberately published.exportsnow mirrors its shape, so what we ship and what a consumer can reach are the same set. Wideningexportscannot break an import that already worked, and the published file list is byte-for-byte unchanged; only reachability changes.This also adds a
typescondition to the main entry. Undernode16/nodenext/bundlermodule resolution, TypeScript reads types throughexportsand ignores the top-leveltypesfield, so consumers on those settings were silently gettingany. That was already true before this change — it is fixed here because it is the same field and the same root cause, and it seemed wrong to touchexportsand knowingly leave it broken. Runtime resolution of the main entry is unchanged. Happy to split it out if you'd rather keep this to the letter of the issue.Two things worth a reviewer's attention. First, this commits us to those paths as API, which is the real decision in the issue; the answer taken here is that
filesalready made that commitment andexportswas contradicting it. Second,mainstill points at the CommonJS build butexportssendsrequire()to the ESM one, exactly as it did before — that predates this change and is left alone rather than quietly folded in.Screenshots
Testing
Sass is unaffected in both directions, so there is nothing to check there — it compiles identically before and after, because neither the load-path route nor the
pkg:importer enforces the export map for stylesheets.npm run build, thennpm pack. A file namedcloudfour-patterns-17.1.0.tgzshould appear in the repo root.npm init -yfollowed bynpm install /full/path/to/cloudfour-patterns-17.1.0.tgz.check.jscontaining:js const tokens = require('@cloudfour/patterns/src/compiled/tokens/json/tokens.json'); console.log(Object.keys(tokens));node check.js. It should print a list of token group names. Onmainthis same step fails withERR_PACKAGE_PATH_NOT_EXPORTED.check-manifest.jscontainingconsole.log(require('@cloudfour/patterns/package.json').version);and run it. It should print17.1.0rather than an error — reading a dependency's manifest is something build tools do routinely.check-main.mjscontainingimport * as p from '@cloudfour/patterns'; console.log(Object.keys(p));and run it. It should list four component functions.npm i -D typescript, add atsconfig.jsonwith{"compilerOptions":{"moduleResolution":"bundler","module":"preserve","noEmit":true}}, createcheck.tscontainingimport { createElasticTextArea } from '@cloudfour/patterns';and pass it a string:createElasticTextArea('nope');. Runnpx tsc. You should get a complaint that a string isn't anHTMLTextAreaElement— meaning the type declarations were found. Onmainyou instead get "Could not find a declaration file for module".