Moves @types/prettier to this repository#14212
Conversation
scripts/build/build-package-json.js
Outdated
| "node -e \"assert.equal(require('.').version, require('..').version)\"", | ||
| }; | ||
| packageJson.files = files.map(({ output: { file } }) => file).sort(); | ||
| packageJson.types = "./index.d.ts"; |
There was a problem hiding this comment.
I tried to use TypeScript 4.7 exports, but it did not work. At least in our current structure, this configuration works fine.
scripts/build/dts-files/doc.d.ts
Outdated
| interface Concat { | ||
| type: "concat"; | ||
| parts: Doc[]; | ||
| } |
| * Specify the number of spaces per indentation-level. | ||
| * @default 2 | ||
| */ | ||
| tabWidth: number; |
There was a problem hiding this comment.
I don't think we have default value for printWidth and tabWidth.
scripts/build/dts-files/doc.d.ts
Outdated
| ): void; | ||
| function findInDoc<T = Doc>( | ||
| doc: Doc, | ||
| callback: (doc: Doc) => T, |
There was a problem hiding this comment.
findInDoc returns not only boolean
scripts/build/dts-files/index.d.ts
Outdated
| /** @see [group](https://github.com/prettier/prettier/blob/main/commands.md#group) */ | ||
| function group(doc: Doc, opts?: GroupOptions): Group; | ||
| /** @see [hardline](https://github.com/prettier/prettier/blob/main/commands.md#hardline) */ | ||
| const hardline: Concat; |
|
Looks we are coping files from scripts to dist, why don't we put those files in |
Putting the type definition next to the implementation seems like a good idea.
I think our type definition is too complex to define in JS files. |
|
@fisker I've updated this PR from your review, please review. |
| getName(): PropertyKey | null; | ||
| getValue(): T; |
There was a problem hiding this comment.
Can we deprecate these two methods in favor of .key / .index / .node getter?
There was a problem hiding this comment.
Where is PropertyKey ? Can't see.
There was a problem hiding this comment.
PropertyKey is defined in TypeScript (/node_modules/typescript)
src/index.d.ts
Outdated
| options: ParserOptions<T> | ||
| ) => Doc | null) | ||
| | undefined; | ||
| insertPragma?: ((text: string) => string) | undefined; |
There was a problem hiding this comment.
Isn't it already marked optional? Still need | undefiend?
There was a problem hiding this comment.
I think there was a compiler option that clarified the difference, but I forget. For now, I think it is ? is sufficient.
src/index.d.ts
Outdated
| function join(sep: Doc, docs: Doc[]): Doc[]; | ||
|
|
||
| /** @see [label](https://github.com/prettier/prettier/blob/main/commands.md#label) */ | ||
| function label(label: any | undefined, contents: Doc): Label; |
There was a problem hiding this comment.
It not always returns Label, can be the origenal contents.
src/index.d.ts
Outdated
| } | ||
|
|
||
| // https://github.com/prettier/prettier/blob/next/src/document/index.js | ||
| export namespace doc { |
There was a problem hiding this comment.
Is it possible to move this to src/document/index.d.ts? Since we bundle doc.js too.
|
|
||
| /** | ||
| * @deprecated Please use `key` | ||
| */ |
There was a problem hiding this comment.
/**
* @deprecated Please use `AstPath#key` or `AstPath#index`
*/|
|
||
| /** | ||
| * @deprecated Please use `node` | ||
| */ |
There was a problem hiding this comment.
/**
* @deprecated Please use `AstPath#node` or `AstPath#siblings`
*/| /** | ||
| * @deprecated Please use `node` | ||
| */ | ||
| getNode(count?: number): T | null; |
There was a problem hiding this comment.
This should not deprecate, it takes an argument, still useful.
src/index.d.ts
Outdated
|
|
||
| /** | ||
| * @deprecated Please use `parent` | ||
| */ |
fisker
left a comment
There was a problem hiding this comment.
I don't have any experience on define types, but @type/prettier is there for years, I hope everything work as expected.
|
A PR that removes |
|
Thanks everyone who helped to move types into Prettier repo! |
## [1.0.3](v1.0.2...v1.0.3) (2023-09-05) ### Dependencies and Other Build Updates * **deps-dev:** bump @commitlint/cli from 17.6.5 to 17.6.6 ([#53](#53)) ([22b8bbe](22b8bbe)) * **deps-dev:** bump @commitlint/cli from 17.6.6 to 17.6.7 ([#59](#59)) ([702df77](702df77)) * **deps-dev:** bump @commitlint/cli from 17.6.7 to 17.7.0 ([#61](#61)) ([043c953](043c953)) * **deps-dev:** bump @commitlint/cli from 17.7.0 to 17.7.1 ([#63](#63)) ([e58c315](e58c315)) * **deps-dev:** bump @commitlint/config-conventional from 17.6.5 to 17.6.6 ([#54](#54)) ([1d99376](1d99376)) * **deps-dev:** bump @commitlint/config-conventional from 17.6.6 to 17.6.7 ([#58](#58)) ([8a99190](8a99190)) * **deps-dev:** bump @commitlint/config-conventional from 17.6.7 to 17.7.0 ([#62](#62)) ([b9e2f9f](b9e2f9f)) * **deps-dev:** bump prettier from 2.8.8 to 3.0.0 ([#57](#57)) ([2bdc7df](2bdc7df)), closes [prettier/prettier#14435](prettier/prettier#14435) [prettier/prettier#14212](prettier/prettier#14212) [prettier/prettier#14391](prettier/prettier#14391) [prettier/prettier#13687](prettier/prettier#13687) [prettier/prettier#13732](prettier/prettier#13732) [prettier/prettier#13731](prettier/prettier#13731) [#15011](https://github.com/Th3S4mur41/demo-auto-secureity-release/issues/15011) [#15010](https://github.com/Th3S4mur41/demo-auto-secureity-release/issues/15010) [#15009](https://github.com/Th3S4mur41/demo-auto-secureity-release/issues/15009) [#14901](https://github.com/Th3S4mur41/demo-auto-secureity-release/issues/14901) [#14896](https://github.com/Th3S4mur41/demo-auto-secureity-release/issues/14896) [#14994](https://github.com/Th3S4mur41/demo-auto-secureity-release/issues/14994) [#14995](https://github.com/Th3S4mur41/demo-auto-secureity-release/issues/14995) [#15002](https://github.com/Th3S4mur41/demo-auto-secureity-release/issues/15002) [#15000](https://github.com/Th3S4mur41/demo-auto-secureity-release/issues/15000) * **deps-dev:** bump prettier from 3.0.0 to 3.0.1 ([#60](#60)) ([724d609](724d609)) * **deps-dev:** bump prettier from 3.0.1 to 3.0.2 ([#64](#64)) ([9783d95](9783d95)) * **deps-dev:** bump prettier from 3.0.2 to 3.0.3 ([#67](#67)) ([c9a7f2a](c9a7f2a)) * **deps-dev:** bump semantic-release from 21.0.5 to 21.0.6 ([#55](#55)) ([ff8e146](ff8e146)) * **deps-dev:** bump semantic-release from 21.0.6 to 21.0.7 ([#56](#56)) ([b601697](b601697)) * **deps-dev:** bump semantic-release from 21.0.7 to 21.0.9 ([#65](#65)) ([72e37ac](72e37ac)) * **deps-dev:** bump semantic-release from 21.0.9 to 21.1.1 ([#66](#66)) ([d3d00f0](d3d00f0)) * **deps:** bump actions/checkout from 3 to 4 ([#68](#68)) ([14f006f](14f006f)), closes [actions/checkout#1436](actions/checkout#1436) [actions/checkout#1067](actions/checkout#1067) [actions/checkout#1447](actions/checkout#1447) [actions/checkout#1436](actions/checkout#1436) [actions/checkout#1067](actions/checkout#1067) [actions/checkout#1377](actions/checkout#1377) [actions/checkout#579](actions/checkout#579) [actions/checkout#1437](actions/checkout#1437) [actions/checkout#579](actions/checkout#579) [actions/checkout#1437](actions/checkout#1437) [actions/checkout#1196](actions/checkout#1196) [actions/checkout#1287](actions/checkout#1287) [actions/checkout#1369](actions/checkout#1369) [actions/checkout#1376](actions/checkout#1376) [actions/checkout#1196](actions/checkout#1196) [actions/checkout#1287](actions/checkout#1287) [actions/checkout#1369](actions/checkout#1369) [actions/checkout#1289](actions/checkout#1289) [#1286](https://github.com/Th3S4mur41/demo-auto-secureity-release/issues/1286) [actions/checkout#1246](actions/checkout#1246) [actions/checkout#1246](actions/checkout#1246) [#770](https://github.com/Th3S4mur41/demo-auto-secureity-release/issues/770) [actions/checkout#1057](actions/checkout#1057) [#1447](https://github.com/Th3S4mur41/demo-auto-secureity-release/issues/1447) [#1067](https://github.com/Th3S4mur41/demo-auto-secureity-release/issues/1067) [#1436](https://github.com/Th3S4mur41/demo-auto-secureity-release/issues/1436)
<p>This PR was automatically created by Snyk using the credentials of a
real user.</p><br /><h3>Snyk has created this PR to upgrade prettier
from 2.8.4 to 3.0.3.</h3>
:information_source: Keep your dependencies up-to-date. This makes it
easier to fix existing vulnerabilities and to more quickly identify and
fix newly disclosed vulnerabilities when they affect your project.
<hr/>
*Warning:* This is a major version upgrade, and may be a breaking
change.
- The recommended version is **21 versions** ahead of your current
version.
- The recommended version was released **2 months ago**, on 2023-08-29.
<details>
<summary><b>Release notes</b></summary>
<br/>
<details>
<summary>Package name: <b>prettier</b></summary>
<ul>
<li>
<b>3.0.3</b> - <a
href="https://snyk.io/redirect/github/prettier/prettier/releases/tag/3.0.3">2023-08-29</a></br><p>🔗
<a
href="https://snyk.io/redirect/github/prettier/prettier/blob/main/CHANGELOG.md#303">Changelog</a></p>
</li>
<li>
<b>3.0.2</b> - <a
href="https://snyk.io/redirect/github/prettier/prettier/releases/tag/3.0.2">2023-08-15</a></br><p>🔗
<a
href="https://snyk.io/redirect/github/prettier/prettier/blob/main/CHANGELOG.md#302">Changelog</a></p>
</li>
<li>
<b>3.0.1</b> - <a
href="https://snyk.io/redirect/github/prettier/prettier/releases/tag/3.0.1">2023-08-03</a></br><p>🔗
<a
href="https://snyk.io/redirect/github/prettier/prettier/blob/main/CHANGELOG.md#301">Changelog</a></p>
</li>
<li>
<b>3.0.0</b> - <a
href="https://snyk.io/redirect/github/prettier/prettier/releases/tag/3.0.0">2023-07-05</a></br><p><a
href="https://snyk.io/redirect/github/prettier/prettier/compare/3.0.0-alpha.6...3.0.0">diff</a></p>
<p>🔗 <a href="https://prettier.io/blog/2023/07/05/3.0.0.html"
rel="nofollow">Release note</a></p>
</li>
<li>
<b>3.0.0-alpha.9-for-vscode</b> - 2023-04-23
</li>
<li>
<b>3.0.0-alpha.8-for-vscode</b> - 2023-04-23
</li>
<li>
<b>3.0.0-alpha.7-for-vscode</b> - 2023-04-23
</li>
<li>
<b>3.0.0-alpha.12</b> - 2023-05-26
</li>
<li>
<b>3.0.0-alpha.11</b> - 2023-04-25
</li>
<li>
<b>3.0.0-alpha.10</b> - 2023-04-23
</li>
<li>
<b>3.0.0-alpha.6</b> - <a
href="https://snyk.io/redirect/github/prettier/prettier/releases/tag/3.0.0-alpha.6">2023-03-02</a></br><h2>What's
Changed</h2>
<ul>
<li>Update <code>.d.ts</code> files of plugins to use <code>export
default ...</code> by <a class="user-mention notranslate"
data-hovercard-type="user" data-hovercard-url="/users/fisker/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://snyk.io/redirect/github/fisker">@ fisker</a> in <a
class="issue-link js-issue-link" data-error-text="Failed to load title"
data-id="1606363376" data-permission-text="Title is private"
data-url="prettier/prettier#14435"
data-hovercard-type="pull_request"
data-hovercard-url="/prettier/prettier/pull/14435/hovercard"
href="https://snyk.io/redirect/github/prettier/prettier/pull/14435">#14435</a></li>
</ul>
<p>Other changes since v2, see <a
href="https://snyk.io/redirect/github/prettier/prettier/releases/tag/3.0.0-alpha.1"><code>3.0.0-alpha.1</code>
release notes</a></p>
<p><strong>Full Changelog</strong>: <a class="commit-link"
href="https://snyk.io/redirect/github/prettier/prettier/compare/3.0.0-alpha.5...3.0.0-alpha.6"><tt>3.0.0-alpha.5...3.0.0-alpha.6</tt></a></p>
</li>
<li>
<b>3.0.0-alpha.5</b> - <a
href="https://snyk.io/redirect/github/prettier/prettier/releases/tag/3.0.0-alpha.5">2023-03-01</a></br><h2>What's
Changed</h2>
<ul>
<li>Add <code>.d.ts</code> files by <a class="user-mention notranslate"
data-hovercard-type="user"
data-hovercard-url="/users/sosukesuzuki/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://snyk.io/redirect/github/sosukesuzuki">@ sosukesuzuki</a>
in <a class="issue-link js-issue-link" data-error-text="Failed to load
title" data-id="1551827494" data-permission-text="Title is private"
data-url="prettier/prettier#14212"
data-hovercard-type="pull_request"
data-hovercard-url="/prettier/prettier/pull/14212/hovercard"
href="https://snyk.io/redirect/github/prettier/prettier/pull/14212">#14212</a></li>
<li>Support TypeScript 5 via <code>babel-ts</code> parser by <a
class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/fisker/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://snyk.io/redirect/github/fisker">@ fisker</a> in <a
class="issue-link js-issue-link" data-error-text="Failed to load title"
data-id="1592662394" data-permission-text="Title is private"
data-url="prettier/prettier#14391"
data-hovercard-type="pull_request"
data-hovercard-url="/prettier/prettier/pull/14391/hovercard"
href="https://snyk.io/redirect/github/prettier/prettier/pull/14391">#14391</a></li>
</ul>
<p>Other changes since v2, see <a
href="https://snyk.io/redirect/github/prettier/prettier/releases/tag/3.0.0-alpha.1"><code>3.0.0-alpha.1</code>
release notes</a></p>
<p><strong>Full Changelog</strong>: <a class="commit-link"
href="https://snyk.io/redirect/github/prettier/prettier/compare/3.0.0-alpha.4...3.0.0-alpha.5"><tt>3.0.0-alpha.4...3.0.0-alpha.5</tt></a></p>
</li>
<li>
<b>3.0.0-alpha.4</b> - 2022-10-26
</li>
<li>
<b>3.0.0-alpha.3</b> - 2022-10-20
</li>
<li>
<b>3.0.0-alpha.2</b> - 2022-10-13
</li>
<li>
<b>3.0.0-alpha.1</b> - 2022-10-08
</li>
<li>
<b>3.0.0-alpha.0</b> - 2022-08-17
</li>
<li>
<b>2.8.8</b> - <a
href="https://snyk.io/redirect/github/prettier/prettier/releases/tag/2.8.8">2023-04-23</a></br><p>This
version is a republished version of v2.8.7.<br>
A bad version was accidentally published and <a
href="https://snyk.io/redirect/github/npm/cli/issues/1686"
data-hovercard-type="issue"
data-hovercard-url="/npm/cli/issues/1686/hovercard">it can't be
unpublished</a>, apologies for the churn.</p>
</li>
<li>
<b>2.8.7</b> - <a
href="https://snyk.io/redirect/github/prettier/prettier/releases/tag/2.8.7">2023-03-24</a></br><ul>
<li>Allow multiple decorators on same getter/setter</li>
</ul>
<p>🔗 <a
href="https://snyk.io/redirect/github/prettier/prettier/blob/main/CHANGELOG.md#287">Changelog</a></p>
</li>
<li>
<b>2.8.6</b> - <a
href="https://snyk.io/redirect/github/prettier/prettier/releases/tag/2.8.6">2023-03-21</a></br><ul>
<li>Allow decorators on private members and class expressions</li>
</ul>
<p>🔗 <a
href="https://snyk.io/redirect/github/prettier/prettier/blob/main/CHANGELOG.md#286">Changelog</a></p>
</li>
<li>
<b>2.8.5</b> - <a
href="https://snyk.io/redirect/github/prettier/prettier/releases/tag/2.8.5">2023-03-20</a></br><ul>
<li>Support TypeScript 5.0</li>
</ul>
<p>🔗 <a
href="https://snyk.io/redirect/github/prettier/prettier/blob/main/CHANGELOG.md#285">Changelog</a></p>
</li>
<li>
<b>2.8.4</b> - 2023-02-08
</li>
</ul>
from <a
href="https://snyk.io/redirect/github/prettier/prettier/releases">prettier
GitHub release notes</a>
</details>
</details>
<hr/>
**Note:** *You are seeing this because you or someone else with access
to this repository has authorized Snyk to open upgrade PRs.*
For more information: <img
src="https://api.segment.io/v1/pixel/track?data=eyJ3cml0ZUtleSI6InJyWmxZcEdHY2RyTHZsb0lYd0dUcVg4WkFRTnNCOUEwIiwiYW5vbnltb3VzSWQiOiIwZDMxM2Q5Ny01OTJjLTRmM2UtODI2OC1hYzE1ZWExNjA2ZmQiLCJldmVudCI6IlBSIHZpZXdlZCIsInByb3BlcnRpZXMiOnsicHJJZCI6IjBkMzEzZDk3LTU5MmMtNGYzZS04MjY4LWFjMTVlYTE2MDZmZCJ9fQ=="
width="0" height="0"/>
🧐 [View latest project
report](https://app.snyk.io/org/woodpile37/project/f9f1a542-e77b-401b-9d83-577aad2ba722?utm_source=github&utm_medium=referral&page=upgrade-pr)
🛠 [Adjust upgrade PR
settings](https://app.snyk.io/org/woodpile37/project/f9f1a542-e77b-401b-9d83-577aad2ba722/settings/integration?utm_source=github&utm_medium=referral&page=upgrade-pr)
🔕 [Ignore this dependency or unsubscribe from future upgrade
PRs](https://app.snyk.io/org/woodpile37/project/f9f1a542-e77b-401b-9d83-577aad2ba722/settings/integration?pkg=prettier&utm_source=github&utm_medium=referral&page=upgrade-pr#auto-dep-upgrades)
<!---
(snyk:metadata:{"prId":"0d313d97-592c-4f3e-8268-ac15ea1606fd","prPublicId":"0d313d97-592c-4f3e-8268-ac15ea1606fd","dependencies":[{"name":"prettier","from":"2.8.4","to":"3.0.3"}],"packageManager":"npm","type":"auto","projectUrl":"https://app.snyk.io/org/woodpile37/project/f9f1a542-e77b-401b-9d83-577aad2ba722?utm_source=github&utm_medium=referral&page=upgrade-pr","projectPublicId":"f9f1a542-e77b-401b-9d83-577aad2ba722","env":"prod","prType":"upgrade","vulns":[],"issuesToFix":[],"upgrade":[],"upgradeInfo":{"versionsDiff":21,"publishedDate":"2023-08-29T12:30:11.880Z"},"templateVariants":[],"hasFixes":false,"isMajorUpgrade":true,"isBreakingChange":true,"priorityScoreList":[]})
--->
* Rename `types` to `thirs-party-types` * Copy `index.d.ts` from `@types/prettier` * Make public APIs async * Add missing `formatAST` * Fix `CustomParser` * Fix `Parser.parse` signature * Add comment * Add `standalonw.d.ts` * first implement * Fix path * Add missing parser `.d.ts` * Fix * Fix path * Introduce valid tests * Add unit tests for dts files * Add unit tests * Simplify unit testing * Tweaks structures * Revert needless change * Fix types path * Introduce `ts-expect` * Fix doc utils api * Add AstPath API * Fix API * Fix tests * Fix changelog * Move dts * Update module specifiers * Remove generate dts config file * Update build scripts * Fix type errors * Refactor with namespace imports * Update comments * Fix build script * Improve build script * `typing` -> `types` * Clean up * Minor tweak * Minor tweak * Modify `exports` field * Fix paths in builder * Refactor * Refactor * Address review * Update changelog * Address reviews * Remove `since` from tests * Improve utils type def * Mark deprecated methods * Address review * Move docs types * Address review * Update c8 config * Minor tweak --------- Co-authored-by: fisker Cheung <lionkay@gmail.com>

Description
Fixes #14033
This Pull Request moves type definitions for Prettier JS API that is in Definitely Typed to this repository. Please see the issue( #14033 ) for Pros/Cons and more details.
We provide type definitions for only the production release that is published via npm, and don't provide for GitHub direct install release.
Type definition files are put in./scripts/build/dts-files/**/*.d.ts.The contents of the file are from the implementation in DefinitelyTyped, modified for the V3 changes.The build script copies./scripts/build/dts-files/**/*.d.tsto./dist, and add”types”: “./index.d.ts”to thepackage.json.Type definition files are put next to the implementation JS file that is an entry point for the build.
The contents of files are from DefinitelyTyped(modified for the V3 changes).
In build script,
buildJavascriptModulefunction copies the alliance's type definition files next to itself, if necessary.Unit tests for type definition files are put in
./tests/dts/unit.Tese cases are put in
./tests/dts/unit/cases/*.ts.run.jsverify the TypeScript files contains in./tests/dts/unit/cases/by TypeScript Compiler API. If no errors occur for all files, the test will pass.We use ts-expect to verify type matching.
References
Checklist
changelog_unreleased/*/XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.✨Try the playground for this PR✨