Skip to content

Commit 8333c24

Browse files
committed
addressing suggestions by Omar
1 parent f6c9016 commit 8333c24

File tree

5 files changed

+64
-78
lines changed

5 files changed

+64
-78
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Install both `prettier` and `prettier-plugin-solidity`:
2626
npm install --save-dev prettier prettier-plugin-solidity
2727
```
2828

29+
> :package: ** Make sure `prettier`'s version is at least `3.0.0`**
30+
2931
Run prettier in your contracts:
3032

3133
```Bash
@@ -46,15 +48,18 @@ Or you can use it as part of your linting to check that all your code is prettif
4648

4749
> Prettier Solidity only works with valid code. If there is a syntax error, nothing will be done and a parser error will be thrown.
4850
49-
### ~~Using in the Browser~~ _Disabled during v2.0.0-beta_
51+
### Using in the Browser
5052

5153
_Added in v1.1.0_
5254

5355
To use this package in the browser, you need to load Prettier's standalone bundle before loading the build provided in this package.
5456

5557
```html
5658
<script src="https://unpkg.com/prettier@latest"></script>
57-
<script src="https://unpkg.com/prettier-plugin-solidity@latest"></script>
59+
<script
60+
type="module"
61+
src="https://unpkg.com/prettier-plugin-solidity@latest"
62+
></script>
5863
```
5964

6065
Prettier's unpkg field points to `https://unpkg.com/prettier/standalone.js`, in a similar way this plugin points to `https://unpkg.com/prettier-plugin-solidity/dist/standalone.js`.
@@ -79,7 +84,7 @@ We follow Prettier's strategy for populating their plugins in the object `pretti
7984

8085
For more details and please have a look at [Prettier's documentation](https://prettier.io/docs/en/browser.html).
8186

82-
### ~~Creating a package for the Browser~~ _Disabled during v2.0.0-beta_
87+
### Creating a package for the Browser
8388

8489
_Added in v1.2.0_
8590

package-lock.json

Lines changed: 44 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@
8787
"@types/jest": "^29.5.14",
8888
"@types/semver": "^7.5.8",
8989
"@types/strip-comments": "^2.0.4",
90-
"@typescript-eslint/eslint-plugin": "^8.12.1",
91-
"@typescript-eslint/parser": "^8.12.1",
90+
"@typescript-eslint/eslint-plugin": "^8.12.2",
91+
"@typescript-eslint/parser": "^8.12.2",
9292
"c8": "^9.1.0",
9393
"cross-env": "^7.0.3",
9494
"eslint": "^9.13.0",

tests/config/get-plugins.js

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
1-
import { createRequire } from "node:module";
21
import path from "node:path";
32
import createEsmUtils from "esm-utils";
4-
import { satisfies } from "semver";
5-
import getPrettier from "./get-prettier.js";
63

74
const { __dirname } = createEsmUtils(import.meta);
85

96
async function getPluginsInternal() {
10-
if (!process.env.TEST_STANDALONE) {
11-
return [path.join(__dirname, "../../src/index.ts")];
12-
}
13-
14-
const require = createRequire(import.meta.url);
15-
const prettier = await getPrettier();
16-
17-
const prettierPath = path.dirname(require.resolve("prettier"));
18-
const pluginPrefix = satisfies(prettier.version, "^2.3.0")
19-
? "parser-" // Prettier V2
20-
: "plugins/"; // Prettier V3
21-
const babel = path.join(prettierPath, `${pluginPrefix}babel.js`);
22-
const markdown = path.join(prettierPath, `${pluginPrefix}markdown.js`);
23-
const standalone = path.join(__dirname, "../../dist/standalone.js");
24-
25-
return [
26-
(await import(babel)).default,
27-
(await import(markdown)).default,
28-
(await import(standalone)).default,
29-
];
7+
return await Promise.all(
8+
process.env.TEST_STANDALONE
9+
? [
10+
import("prettier/plugins/babel"),
11+
import("prettier/plugins/markdown"),
12+
import(path.join(__dirname, "../../dist/standalone.js")),
13+
]
14+
: [path.join(__dirname, "../../src/index.ts")],
15+
).then((modules) => modules.map((module) => module.default ?? module));
3016
}
3117

3218
let promise;

tests/config/get-prettier.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import path from "node:path";
2-
import { createRequire } from "node:module";
3-
41
function getPrettierInternal() {
5-
const require = createRequire(import.meta.url);
6-
72
const entry = process.env.TEST_STANDALONE
8-
? path.join(path.dirname(require.resolve("prettier")), "standalone.js")
3+
? "prettier/standalone"
94
: "prettier";
105

116
return import(entry).then((module) => module.default);

0 commit comments

Comments
 (0)