Skip to content

Commit

Permalink
Merge branch 'main' into #13017
Browse files Browse the repository at this point in the history
  • Loading branch information
solarized-fox committed Apr 25, 2023
2 parents d411464 + 1107ae6 commit d148a81
Show file tree
Hide file tree
Showing 50 changed files with 604 additions and 558 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# See https://git-scm.com/docs/git-blame#Documentation/git-blame.txt---ignore-revs-fileltfilegt

# Prettier bump after release
# 2.8.8
fe8fcb5f9888ddbe9c749da01439dbdc7d28e367
# 2.8.7
0e26a75ebf0cb5b436f6a2d26a7bb88d04f23b90
# 2.8.6
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Don't fill the form below manually! Let a program create a report for you:
-->

**Prettier 2.8.7**
**Prettier 2.8.8**
[Playground link](https://prettier.io/playground/#.....)

```sh
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ BEFORE SUBMITTING AN ISSUE:

**Environments:**

- Prettier Version: 2.8.7
- Prettier Version: 2.8.8
- Running Prettier via: <!-- CLI, Node.js API, Browser API, etc. -->
- Runtime: <!-- Node.js v14, Chrome v83, etc. -->
- Operating System: <!-- Windows, Linux, macOS, etc. -->
Expand Down
1 change: 1 addition & 0 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
baseBranches: ["main"],
schedule: ["after 01:00 on sunday"],
postUpdateOptions: ["yarnDedupeHighest"],
prHourlyLimit: 0,
packageRules: [
{
matchPackageNames: ["react", "react-dom"],
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 2.8.8

This version is a republished version of v2.8.7.
A bad version was accidentally published and [it can't be unpublished](https://github.com/npm/cli/issues/1686), apologies for the churn.

# 2.8.7

[diff](https://github.com/prettier/prettier/compare/2.8.6...2.8.7)
Expand Down
23 changes: 4 additions & 19 deletions changelog_unreleased/api/12740.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
#### [BREAKING] npm package file structures changed (#12740 by @fisker, #13530 by @fisker, #14570 by @fisker)

Export style changes:

The ESM version standalone entry has changed export style from default export to named export.

```diff
- import prettier from "https://unpkg.com/prettier@2.7.1/esm/standalone.mjs";
+ import * as prettier from "https://unpkg.com/prettier@3.0.0/standalone.mjs";
```

```diff
- import prettier from "https://unpkg.com/prettier@2.7.1/esm/standalone.mjs";
+ import { format } from "https://unpkg.com/prettier@3.0.0/standalone.mjs";
```

File structures changes:

- `bin-prettier.js` -> `bin/prettier.cjs`
Expand Down Expand Up @@ -54,15 +40,14 @@ A new plugin has been added:
If you use standalone version, this plugin should be loaded when printing JavaScript, TypeScript, Flow, or JSON.

```diff
- import prettier from "prettier/standalone";
+ import * as prettier from "prettier/standalone";
import { format } from "prettier/standalone";
- import prettierPluginBabel from "prettier/parser-babel";
+ import prettierPluginBabel from "prettier/plugins/babel";
+ import prettierPluginEstree from "prettier/plugins/estree";
+ import * as prettierPluginBabel from "prettier/plugins/babel";
+ import * as prettierPluginEstree from "prettier/plugins/estree";

console.log(
- format(code, {
+ await format(code, {
+ await format(code, {
parser: "babel",
- plugins: [prettierPluginBabel],
+ plugins: [prettierPluginBabel, prettierPluginEstree],
Expand Down
8 changes: 4 additions & 4 deletions changelog_unreleased/api/13268.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ function parse(text: string, options: object): Promise<AST> | AST;

The second argument `parsers` has been removed, if you still need other parser during parse process, you can:

1. Import the plugin yourself
1. Import the plugin yourself (recommended)

```js
import pluginBabel from "prettier/plugins/babel";
import * as pluginBabel from "prettier/plugins/babel";

const myCustomPlugin = {
parsers: {
Expand All @@ -37,8 +37,8 @@ The second argument `parsers` has been removed, if you still need other parser d

```js
function getParserFromOptions(options, parserName) {
const parserOrParserInitFunction = options.plugins.find((plugin) =>
Object.hasOwn(plugin.parsers, parserName)
const parserOrParserInitFunction = options.plugins.find(
(plugin) => plugin.parsers && Object.hasOwn(plugin.parsers, parserName)
)?.parsers[parserName];
return typeof parserOrParserInitFunction === "function"
? parserOrParserInitFunction()
Expand Down
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ format("lodash ( )", {

```js
import { format } from "prettier";
import pluginBabel from "prettier/plugins/babel";
import * as pluginBabel from "prettier/plugins/babel";

const myCustomPlugin = {
parsers: {
Expand Down
28 changes: 14 additions & 14 deletions docs/browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Required options:

- **[`parser`](options.md#parser) (or [`filepath`](options.md#file-path))**: One of these options has to be specified for Prettier to know which parser to use.

- **`plugins`**: Unlike the `format` function from the [Node.js-based API](api.md#prettierformatsource--options), this function doesn’t load plugins automatically. The `plugins` option is required because all the parsers included in the Prettier package come as plugins (for reasons of file size). These plugins are files in <https://unpkg.com/browse/prettier@2.8.7/plugins/>
- **`plugins`**: Unlike the `format` function from the [Node.js-based API](api.md#prettierformatsource--options), this function doesn’t load plugins automatically. The `plugins` option is required because all the parsers included in the Prettier package come as plugins (for reasons of file size). These plugins are files in <https://unpkg.com/browse/prettier@2.8.8/plugins/>

You need to load the ones that you’re going to use and pass them to `prettier.format` using the `plugins` option.

Expand All @@ -29,8 +29,8 @@ See below for examples.
### Global

```html
<script src="https://unpkg.com/prettier@2.8.7/standalone.js"></script>
<script src="https://unpkg.com/prettier@2.8.7/plugins/graphql.js"></script>
<script src="https://unpkg.com/prettier@2.8.8/standalone.js"></script>
<script src="https://unpkg.com/prettier@2.8.8/plugins/graphql.js"></script>
<script>
(async () => {
const formatted = await prettier.format("type Query { hello: String }", {
Expand All @@ -47,8 +47,8 @@ Note that the [`unpkg` field](https://unpkg.com/#examples) in Prettier’s `pack

```html
<script type="module">
import * as prettier from "https://unpkg.com/prettier@2.8.7/standalone.mjs";
import pluginGraphql from "https://unpkg.com/prettier@2.8.7/plugins/graphql.mjs";
import * as prettier from "https://unpkg.com/prettier@2.8.8/standalone.mjs";
import pluginGraphql from "https://unpkg.com/prettier@2.8.8/plugins/graphql.mjs";
const formatted = await prettier.format("type Query { hello: String }", {
parser: "graphql",
Expand All @@ -61,8 +61,8 @@ Note that the [`unpkg` field](https://unpkg.com/#examples) in Prettier’s `pack

```js
define([
"https://unpkg.com/prettier@2.8.7/standalone.js",
"https://unpkg.com/prettier@2.8.7/plugins/graphql.js",
"https://unpkg.com/prettier@2.8.8/standalone.js",
"https://unpkg.com/prettier@2.8.8/plugins/graphql.js",
], async (prettier, ...plugins) => {
const formatted = await prettier.format("type Query { hello: String }", {
parser: "graphql",
Expand All @@ -89,8 +89,8 @@ This syntax doesn’t necessarily work in the browser, but it can be used when b
### Worker

```js
importScripts("https://unpkg.com/prettier@2.8.7/standalone.js");
importScripts("https://unpkg.com/prettier@2.8.7/plugins/graphql.js");
importScripts("https://unpkg.com/prettier@2.8.8/standalone.js");
importScripts("https://unpkg.com/prettier@2.8.8/plugins/graphql.js");
(async () => {
const formatted = await prettier.format("type Query { hello: String }", {
parser: "graphql",
Expand All @@ -105,8 +105,8 @@ If you want to format [embedded code](options.md#embedded-language-formatting),

```html
<script type="module">
import * as prettier from "https://unpkg.com/prettier@2.8.7/standalone.mjs";
import pluginBabel from "https://unpkg.com/prettier@2.8.7/plugins/babel.mjs";
import * as prettier from "https://unpkg.com/prettier@2.8.8/standalone.mjs";
import pluginBabel from "https://unpkg.com/prettier@2.8.8/plugins/babel.mjs";
console.log(
await prettier.format("const html=/* HTML */ `<DIV> </DIV>`", {
Expand All @@ -122,9 +122,9 @@ The HTML code embedded in JavaScript stays unformatted because the `html` parser

```html
<script type="module">
import * as prettier from "https://unpkg.com/prettier@2.8.7/standalone.mjs";
import pluginBabel from "https://unpkg.com/prettier@2.8.7/plugins/babel.mjs";
import pluginHtml from "https://unpkg.com/prettier@2.8.7/plugins/html.mjs";
import * as prettier from "https://unpkg.com/prettier@2.8.8/standalone.mjs";
import pluginBabel from "https://unpkg.com/prettier@2.8.8/plugins/babel.mjs";
import pluginHtml from "https://unpkg.com/prettier@2.8.8/plugins/html.mjs";
console.log(
await prettier.format("const html=/* HTML */ `<DIV> </DIV>`", {
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"@iarna/toml": "2.2.5",
"@prettier/is-es5-identifier-name": "0.1.0",
"@prettier/parse-srcset": "3.0.0",
"@typescript-eslint/typescript-estree": "5.58.0",
"@typescript-eslint/visitor-keys": "5.58.0",
"@typescript-eslint/typescript-estree": "5.59.0",
"@typescript-eslint/visitor-keys": "5.59.0",
"acorn": "8.8.2",
"acorn-jsx": "5.3.2",
"angular-estree-parser": "6.2.0",
Expand All @@ -65,7 +65,7 @@
"flow-parser": "0.204.0",
"get-stdin": "9.0.0",
"graphql": "16.6.0",
"hermes-eslint": "0.10.1",
"hermes-parser": "0.10.1",
"html-element-attributes": "3.2.0",
"html-styles": "1.0.0",
"html-tag-names": "2.1.0",
Expand Down Expand Up @@ -112,7 +112,7 @@
"@types/file-entry-cache": "5.0.2",
"@types/find-cache-dir": "3.2.1",
"@types/jest": "29.5.1",
"@typescript-eslint/eslint-plugin": "5.58.0",
"@typescript-eslint/eslint-plugin": "5.59.0",
"benchmark": "2.1.4",
"browserslist-to-esbuild": "1.2.0",
"c8": "7.13.0",
Expand All @@ -121,7 +121,7 @@
"enquirer": "2.3.6",
"esbuild": "0.17.18",
"esbuild-visualizer": "0.4.0",
"eslint": "8.38.0",
"eslint": "8.39.0",
"eslint-config-prettier": "8.8.0",
"eslint-formatter-friendly": "7.0.0",
"eslint-plugin-compat": "4.1.4",
Expand All @@ -142,7 +142,7 @@
"magic-string": "0.30.0",
"npm-run-all": "4.1.5",
"path-browserify": "1.0.1",
"prettier": "2.8.7",
"prettier": "2.8.8",
"pretty-bytes": "6.1.0",
"rollup-plugin-license": "3.0.1",
"semver": "7.3.8",
Expand Down
2 changes: 1 addition & 1 deletion scripts/benchmark/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const [, , version, method, groupCountString = 100, groupSizeString = 10] =
process.argv;
const groupCount = Number(groupCountString);
const groupSize = Number(groupSizeString);
const { format } = await import(`./${version}/dist/index.js`);
const { format } = await import(`./${version}/dist/index.mjs`);

const sourceText = readFileSync(
process.env.PRETTIER_PERF_FILENAME || "../../src/language-js/utils/index.js",
Expand Down
2 changes: 2 additions & 0 deletions scripts/build/build-javascript-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import esbuildPluginStripNodeProtocol from "./esbuild-plugins/strip-node-protoco
import esbuildPluginThrowWarnings from "./esbuild-plugins/throw-warnings.js";
import esbuildPluginShimCommonjsObjects from "./esbuild-plugins/shim-commonjs-objects.js";
import esbuildPluginPrimitiveDefine from "./esbuild-plugins/primitive-define.js";
import esbuildPluginAddDefaultExport from "./esbuild-plugins/add-default-export.js";
import transform from "./transform/index.js";
import { getPackageFile } from "./utils.js";

Expand Down Expand Up @@ -209,6 +210,7 @@ function getEsbuildOptions({ file, files, shouldCollectLicenses, cliOptions }) {
allowDynamicRequire: file.platform === "node",
allowDynamicImport: file.platform === "node",
}),
buildOptions.addDefaultExport && esbuildPluginAddDefaultExport(),
].filter(Boolean),
minify: shouldMinify,
legalComments: "none",
Expand Down
7 changes: 6 additions & 1 deletion scripts/build/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function getTypesFileConfig({ input: jsFileInput, outputBaseName, isPlugin }) {
* @property {"node" | "universal"} platform - ESBuild platform
* @property {BuildOptions} buildOptions - ESBuild options
* @property {boolean?} isPlugin - file is a plugin
* @property {boolean?} addDefaultExport - add default export to bundle
*/

/*
Expand Down Expand Up @@ -434,7 +435,10 @@ const universalFiles = [...nonPluginUniversalFiles, ...pluginFiles].flatMap(
input,
output,
platform: "universal",
buildOptions,
buildOptions: {
addDefaultExport: output.format === "esm",
...buildOptions,
},
isPlugin,
build: buildJavascriptModule,
kind: "javascript",
Expand Down Expand Up @@ -472,6 +476,7 @@ const nodejsFiles = [
},
replaceDiffPackageEntry("lib/diff/array.js"),
],
addDefaultExport: true,
},
{
input: "src/index.cjs",
Expand Down
42 changes: 42 additions & 0 deletions scripts/build/esbuild-plugins/add-default-export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import path from "node:path";

const namespace = "with-default-export";
export default function esbuildPluginAddDefaultExport() {
return {
name: "addDefaultExport",
setup(build) {
const { initialOptions } = build;
if (initialOptions.format !== "esm") {
return;
}

let entry;

build.onResolve({ filter: /./ }, (module) => {
if (module.kind === "entry-point") {
const relativePath = module.path
.slice(module.resolveDir.length + 1)
.replaceAll("\\", "/");

entry = module.path;
return { path: relativePath, namespace };
}
});

build.onLoad({ filter: /./, namespace }, () => {
const directory = path.dirname(entry);
const source = `./${path.basename(entry)}`;

return {
contents: /* indent */ `
import * as namespace from "${source}";
export * from "${source}";
export default namespace;
`,
resolveDir: directory,
};
});
},
};
}
2 changes: 1 addition & 1 deletion scripts/release/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"enquirer": "2.3.6",
"execa": "7.1.1",
"outdent": "0.8.0",
"semver": "7.4.0",
"semver": "7.5.0",
"string-width": "5.1.2"
},
"engines": {
Expand Down
10 changes: 5 additions & 5 deletions scripts/release/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,19 @@ __metadata:
enquirer: 2.3.6
execa: 7.1.1
outdent: 0.8.0
semver: 7.4.0
semver: 7.5.0
string-width: 5.1.2
languageName: unknown
linkType: soft

"semver@npm:7.4.0":
version: 7.4.0
resolution: "semver@npm:7.4.0"
"semver@npm:7.5.0":
version: 7.5.0
resolution: "semver@npm:7.5.0"
dependencies:
lru-cache: ^6.0.0
bin:
semver: bin/semver.js
checksum: debf7f4d6fa36fdc5ef82bd7fc3603b6412165c8a3963a30be0c45a587be1a49e7681e80aa109da1875765741af24edc6e021cee1ba16ae96f649d06c5df296d
checksum: 2d266937756689a76f124ffb4c1ea3e1bbb2b263219f90ada8a11aebebe1280b13bb76cca2ca96bdee3dbc554cbc0b24752eb895b2a51577aa644427e9229f2b
languageName: node
linkType: hard

Expand Down
2 changes: 1 addition & 1 deletion scripts/tools/bundle-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"type": "module",
"devDependencies": {
"webpack": "5.79.0"
"webpack": "5.80.0"
},
"scripts": {
"test": "node ./index.js"
Expand Down

0 comments on commit d148a81

Please sign in to comment.